commit 2484e4c9ae4e2342590ef1d02e3c109d05d44ef0
parent 6a788c4a95dffaa2eacad36c81398991bd5a5e0c
Author: Eitan Isaacson <eitan@monotonous.org>
Date: Thu, 13 Nov 2025 00:57:04 +0000
Bug 1998201 - Normalize returned string from DocAccessible::Name. r=morgan
An empty string should be set to null.
Differential Revision: https://phabricator.services.mozilla.com/D271803
Diffstat:
3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp
@@ -183,6 +183,10 @@ ENameValueFlag DocAccessible::Name(nsString& aName) const {
URL(aName);
}
+ if (aName.IsEmpty()) {
+ aName.SetIsVoid(true);
+ }
+
return eNameOK;
}
diff --git a/accessible/tests/browser/e10s/browser_caching_name.js b/accessible/tests/browser/e10s/browser_caching_name.js
@@ -6,7 +6,11 @@
requestLongerTimeout(2);
/* import-globals-from ../../mochitest/name.js */
-loadScripts({ name: "name.js", dir: MOCHITESTS_DIR });
+/* import-globals-from ../../mochitest/attributes.js */
+loadScripts(
+ { name: "name.js", dir: MOCHITESTS_DIR },
+ { name: "attributes.js", dir: MOCHITESTS_DIR }
+);
/**
* Rules for name tests that are inspired by
@@ -642,3 +646,35 @@ addAccessibleTask(
},
{ chrome: true, topLevel: true }
);
+
+/**
+ * Test consistent doc name for remote and local docs.
+ */
+addAccessibleTask(
+ `<iframe id="iframe"></iframe>`,
+ async function testDocName(browser, docAcc) {
+ const iframe = findAccessibleChildByID(docAcc, "iframe");
+ info("Setting iframe src");
+ // This iframe won't finish loading. Thus, it will get the stale state and
+ // won't fire a document load complete event. We use the reorder event on
+ // the iframe to know when the document has been created.
+ let reordered = waitForEvent(EVENT_REORDER, iframe);
+ await invokeContentTask(browser, [], () => {
+ content.document.getElementById("iframe").src =
+ `data:text/html,<html><body>hey</body></html>`;
+ });
+ let iframeDoc = (await reordered).accessible.firstChild;
+ is(iframeDoc.name, null, "Doc should have 'null' name");
+ testAbsentAttrs(iframeDoc, { "explicit-name": "true" });
+
+ reordered = waitForEvent(EVENT_REORDER, iframe);
+ await invokeContentTask(browser, [], () => {
+ content.document.getElementById("iframe").src =
+ `data:text/html,<html><title>hello</title><body>hey</body></html>`;
+ });
+ iframeDoc = (await reordered).accessible.firstChild;
+ is(iframeDoc.name, "hello", "Doc should have name");
+ testAttrs(iframeDoc, { "explicit-name": "true" }, true);
+ },
+ { topLevel: true, chrome: true }
+);
diff --git a/accessible/tests/mochitest/aom/test_general.html b/accessible/tests/mochitest/aom/test_general.html
@@ -34,7 +34,7 @@
function createIframe() {
return new Promise((resolve) => {
let iframe = document.createElement("iframe");
- iframe.src = `data:text/html,<html><body>hey</body></html>`;
+ iframe.src = `data:text/html,<html><title>hello</title><body>hey</body></html>`;
iframe.onload = () => resolve(iframe.contentDocument);
document.body.appendChild(iframe);
document.body.offsetTop; // We rely on the a11y tree being created