commit 5f91e21037b5034a26d8f99cc5232f534eb31fef
parent a87c66f07e06758428c3ce00b317c03daf79753d
Author: Morgan Rae Reschenberg <mreschenberg@berkeley.edu>
Date: Thu, 2 Oct 2025 18:14:11 +0000
Bug 1982467: Update hittesting js function to deal with accessibles constructed from ::details-content r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D266927
Diffstat:
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/accessible/tests/browser/Common.sys.mjs b/accessible/tests/browser/Common.sys.mjs
@@ -128,7 +128,8 @@ export const CommonUtils = {
/**
* Obtain DOMNode id from an accessible. This simply queries the .id property
* on the accessible, but it catches exceptions which might occur if the
- * accessible has died.
+ * accessible has died or was constructed from a pseudoelement
+ * like ::details-content.
* @param {nsIAccessible} accessible accessible
* @return {String?} DOMNode id if available
*/
@@ -136,7 +137,9 @@ export const CommonUtils = {
try {
return accessible.id;
} catch (e) {
- // This will fail if the accessible has died.
+ // This will fail if the accessible has died, or if
+ // the accessible was constructed from a pseudoelement
+ // like ::details-content.
}
return null;
},
diff --git a/accessible/tests/browser/hittest/browser_test_general.js b/accessible/tests/browser/hittest/browser_test_general.js
@@ -488,14 +488,6 @@ addAccessibleTask(
p {
font-family: monospace;
}
-
- #detailsOpen::details-content {
- /* TODO(dholbert): In bug 1982467, remove this style-rule and fix up the
- * test expectations instead. This is a hackaround to mimic the
- * pre-"::details-content" setup, so that the test's expectations from
- * that time will still hold up. */
- display: contents;
- }
</style>
<details id="detailsOpen" open>
<summary>summary</summary>
@@ -515,7 +507,15 @@ addAccessibleTask(
async function testChangeDisplayContents(browser, docAcc) {
const detailsOpen = findAccessibleChildByID(docAcc, "detailsOpen");
const detailsOpenP = findAccessibleChildByID(docAcc, "detailsOpenP");
- await hitTest(browser, detailsOpen, detailsOpenP, detailsOpenP.firstChild);
+ // Between the details element and its <p> exists
+ // a pseudoelement, ::details-content. Use this as
+ // our expected target for direct-child hittesting.
+ await hitTest(
+ browser,
+ detailsOpen,
+ detailsOpenP.parent,
+ detailsOpenP.firstChild
+ );
info("Opening details");
let shown = waitForEvent(EVENT_SHOW, "detailsP");
diff --git a/accessible/tests/browser/hittest/head.js b/accessible/tests/browser/hittest/head.js
@@ -12,11 +12,14 @@ Services.scriptloader.loadSubScript(
this
);
+/* import-globals-from ../../mochitest/role.js */
+
// Loading and common.js from accessible/tests/mochitest/ for all tests, as
-// well as promisified-events.js.
+// well as promisified-events.js and role.js.
loadScripts(
{ name: "common.js", dir: MOCHITESTS_DIR },
- { name: "promisified-events.js", dir: MOCHITESTS_DIR }
+ { name: "promisified-events.js", dir: MOCHITESTS_DIR },
+ { name: "role.js", dir: MOCHITESTS_DIR }
);
const { CommonUtils } = ChromeUtils.importESModule(
@@ -78,10 +81,18 @@ async function testChildAtPoint(dpr, x, y, container, child, grandChild) {
* at coordinates of child accessible (direct and deep hit test).
*/
async function hitTest(browser, container, child, grandChild) {
- const [childX, childY] = await getContentBoundsForDOMElm(
- browser,
- getAccessibleDOMNodeID(child)
- );
+ let domEl = getAccessibleDOMNodeID(child);
+ if (!domEl) {
+ // It is possible this accessible has died, but it is also
+ // possible we are dealing with an accessible constructed
+ // from a pseudoelement, like ::details-content
+ if (child.parent.role == ROLE_DETAILS) {
+ // In the ::details-content case, attempt to use the
+ // inner content to construct our hittesting point.
+ domEl = getAccessibleDOMNodeID(child.firstChild);
+ }
+ }
+ const [childX, childY] = await getContentBoundsForDOMElm(browser, domEl);
const x = childX + 1;
const y = childY + 1;