Bug 1639399 - expose uniqueID property on the xpcAccessible. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D76072
This commit is contained in:
Yura Zenevich 2020-05-20 00:11:20 +00:00
parent a49b6359dd
commit 5b6445cb0e
5 changed files with 54 additions and 0 deletions

View File

@ -74,6 +74,13 @@ interface nsIAccessible : nsISupports
*/
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.
*/

View File

@ -21,6 +21,7 @@ skip-if = (os == "linux" && bits == 64) || (debug && os == "mac") || (debug && o
[browser_caching_relations.js]
[browser_caching_states.js]
[browser_caching_value.js]
[browser_caching_uniqueid.js]
# Events tests
[browser_events_announcement.js]

View File

@ -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 }
);

View File

@ -161,6 +161,21 @@ xpcAccessible::GetIndexInParent(int32_t* aIndexInParent) {
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);

View File

@ -34,6 +34,7 @@ class xpcAccessible : public nsIAccessible {
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;