Bug 1639399 - expose uniqueID property on the xpcAccessible. r=Jamie
authorYura Zenevich <yura.zenevich@gmail.com>
Wed, 20 May 2020 00:11:20 +0000
changeset 530933 d5cf77118989c0f40a5490b35ed6716ea689eb64
parent 530932 2924b52f3b3f620863d49f521b4a17d5b49be56b
child 530934 7646b27525be42e7cb39edcac3f9c79dd9763526
push id37434
push userabutkovits@mozilla.com
push dateWed, 20 May 2020 10:05:10 +0000
treeherdermozilla-central@005ef1c25992 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1639399
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639399 - expose uniqueID property on the xpcAccessible. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D76072
accessible/interfaces/nsIAccessible.idl
accessible/tests/browser/e10s/browser.ini
accessible/tests/browser/e10s/browser_caching_uniqueid.js
accessible/xpcom/xpcAccessible.cpp
accessible/xpcom/xpcAccessible.h
--- a/accessible/interfaces/nsIAccessible.idl
+++ b/accessible/interfaces/nsIAccessible.idl
@@ -70,16 +70,23 @@ interface nsIAccessible : nsISupports
 
   /**
    * The 0-based index of this accessible in its parent's list of children,
    * or -1 if this accessible does not have a parent.
    */
   readonly attribute long indexInParent;
 
   /**
+   * The unique identifier of the accessible. ID is only guaranteed to be unique
+   * per document (Windows IDs are unique even across documents, but that is
+   * Windows specific and not exposed to core).
+   */
+  readonly attribute long long uniqueID;
+
+  /**
    * The DOM node this nsIAccessible is associated with.
    */
   readonly attribute Node DOMNode;
 
   /**
     * For remote accessibles the id of the related DOM node.
     */
   readonly attribute AString id;
--- a/accessible/tests/browser/e10s/browser.ini
+++ b/accessible/tests/browser/e10s/browser.ini
@@ -16,16 +16,17 @@ support-files =
 # Caching tests
 [browser_caching_attributes.js]
 [browser_caching_description.js]
 [browser_caching_name.js]
 skip-if = (os == "linux" && bits == 64) || (debug && os == "mac") || (debug && os == "win") #Bug 1388256
 [browser_caching_relations.js]
 [browser_caching_states.js]
 [browser_caching_value.js]
+[browser_caching_uniqueid.js]
 
 # Events tests
 [browser_events_announcement.js]
 skip-if = e10s && os == 'win' # Bug 1288839
 [browser_events_caretmove.js]
 [browser_events_hide.js]
 [browser_events_show.js]
 [browser_events_statechange.js]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/e10s/browser_caching_uniqueid.js
@@ -0,0 +1,30 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Test UniqueID property.
+ */
+addAccessibleTask(
+  '<div id="div"></div>',
+  async function(browser, accDoc) {
+    const div = findAccessibleChildByID(accDoc, "div");
+    const accUniqueID = await invokeContentTask(browser, [], () => {
+      const accService = Cc["@mozilla.org/accessibilityService;1"].getService(
+        Ci.nsIAccessibilityService
+      );
+
+      return accService.getAccessibleFor(content.document.getElementById("div"))
+        .uniqueID;
+    });
+
+    is(
+      accUniqueID,
+      div.uniqueID,
+      "Both proxy and the accessible return correct unique ID."
+    );
+  },
+  { iframe: true, remoteIframe: true }
+);
--- a/accessible/xpcom/xpcAccessible.cpp
+++ b/accessible/xpcom/xpcAccessible.cpp
@@ -157,16 +157,31 @@ xpcAccessible::GetIndexInParent(int32_t*
   } else if (IntlGeneric().IsProxy()) {
     *aIndexInParent = IntlGeneric().AsProxy()->IndexInParent();
   }
 
   return *aIndexInParent != -1 ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
+xpcAccessible::GetUniqueID(int64_t* aUniqueID) {
+  NS_ENSURE_ARG_POINTER(aUniqueID);
+
+  if (IntlGeneric().IsNull()) return NS_ERROR_FAILURE;
+
+  if (IntlGeneric().IsAccessible()) {
+    *aUniqueID = reinterpret_cast<uintptr_t>(Intl()->UniqueID());
+  } else if (IntlGeneric().IsProxy()) {
+    *aUniqueID = IntlGeneric().AsProxy()->ID();
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 xpcAccessible::GetDOMNode(nsINode** aDOMNode) {
   NS_ENSURE_ARG_POINTER(aDOMNode);
   *aDOMNode = nullptr;
 
   if (!Intl()) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsINode> node = Intl()->GetNode();
   node.forget(aDOMNode);
--- a/accessible/xpcom/xpcAccessible.h
+++ b/accessible/xpcom/xpcAccessible.h
@@ -29,16 +29,17 @@ class xpcAccessible : public nsIAccessib
   NS_IMETHOD GetPreviousSibling(nsIAccessible** aPreviousSibling) final;
   NS_IMETHOD GetFirstChild(nsIAccessible** aFirstChild) final;
   NS_IMETHOD GetLastChild(nsIAccessible** aLastChild) final;
   NS_IMETHOD GetChildCount(int32_t* aChildCount) final;
   NS_IMETHOD GetChildAt(int32_t aChildIndex, nsIAccessible** aChild) final;
   NS_IMETHOD GetChildren(nsIArray** aChildren) final;
   NS_IMETHOD GetIndexInParent(int32_t* aIndexInParent) final;
 
+  NS_IMETHOD GetUniqueID(int64_t* aUniqueID) final;
   NS_IMETHOD GetDOMNode(nsINode** aDOMNode) final;
   NS_IMETHOD GetId(nsAString& aID) final;
   NS_IMETHOD GetDocument(nsIAccessibleDocument** aDocument) final;
   NS_IMETHOD GetRootDocument(nsIAccessibleDocument** aRootDocument) final;
 
   NS_IMETHOD GetRole(uint32_t* aRole) final;
   NS_IMETHOD GetState(uint32_t* aState, uint32_t* aExtraState) final;