summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/windows/uia
diff options
context:
space:
mode:
Diffstat (limited to 'accessible/tests/browser/windows/uia')
-rw-r--r--accessible/tests/browser/windows/uia/browser.toml2
-rw-r--r--accessible/tests/browser/windows/uia/browser_controlType.js4
-rw-r--r--accessible/tests/browser/windows/uia/browser_elementFromPoint.js4
-rw-r--r--accessible/tests/browser/windows/uia/browser_tree.js104
-rw-r--r--accessible/tests/browser/windows/uia/head.js37
5 files changed, 147 insertions, 4 deletions
diff --git a/accessible/tests/browser/windows/uia/browser.toml b/accessible/tests/browser/windows/uia/browser.toml
index f7974d69c7..d1513c1822 100644
--- a/accessible/tests/browser/windows/uia/browser.toml
+++ b/accessible/tests/browser/windows/uia/browser.toml
@@ -9,3 +9,5 @@ support-files = ["head.js"]
["browser_controlType.js"]
["browser_elementFromPoint.js"]
+
+["browser_tree.js"]
diff --git a/accessible/tests/browser/windows/uia/browser_controlType.js b/accessible/tests/browser/windows/uia/browser_controlType.js
index 16db892581..3bb994f437 100644
--- a/accessible/tests/browser/windows/uia/browser_controlType.js
+++ b/accessible/tests/browser/windows/uia/browser_controlType.js
@@ -9,11 +9,11 @@ const UIA_ButtonControlTypeId = 50000;
const UIA_DocumentControlTypeId = 50030;
/* eslint-enable camelcase */
-addAccessibleTask(
+addUiaTask(
`
<button id="button">button</button>
`,
- async function (browser, docAcc) {
+ async function () {
let controlType = await runPython(`
global doc
doc = getDocUia()
diff --git a/accessible/tests/browser/windows/uia/browser_elementFromPoint.js b/accessible/tests/browser/windows/uia/browser_elementFromPoint.js
index e2fda4ab30..acf6fe91c7 100644
--- a/accessible/tests/browser/windows/uia/browser_elementFromPoint.js
+++ b/accessible/tests/browser/windows/uia/browser_elementFromPoint.js
@@ -4,12 +4,12 @@
"use strict";
-addAccessibleTask(
+addUiaTask(
`
<button id="button">button</p>
<a id="a" href="#">a</a>
`,
- async function (browser, docAcc) {
+ async function () {
ok(
await runPython(`
global doc
diff --git a/accessible/tests/browser/windows/uia/browser_tree.js b/accessible/tests/browser/windows/uia/browser_tree.js
new file mode 100644
index 0000000000..778609bedb
--- /dev/null
+++ b/accessible/tests/browser/windows/uia/browser_tree.js
@@ -0,0 +1,104 @@
+/* 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";
+
+async function testIsControl(pyVar, isControl) {
+ const result = await runPython(`bool(${pyVar}.CurrentIsControlElement)`);
+ if (isControl) {
+ ok(result, `${pyVar} is a control element`);
+ } else {
+ ok(!result, `${pyVar} isn't a control element`);
+ }
+}
+
+/**
+ * Define a global Python variable and assign it to a given Python expression.
+ */
+function definePyVar(varName, expression) {
+ return runPython(`
+ global ${varName}
+ ${varName} = ${expression}
+ `);
+}
+
+/**
+ * Get the UIA element with the given id and assign it to a global Python
+ * variable using the id as the variable name.
+ */
+function assignPyVarToUiaWithId(id) {
+ return definePyVar(id, `findUiaByDomId(doc, "${id}")`);
+}
+
+addUiaTask(
+ `
+<p id="p">paragraph</p>
+<div id="div">div</div>
+<!-- The spans are because the UIA -> IA2 proxy seems to remove a single text
+ leaf child from even the raw tree.
+ -->
+<a id="link" href="#">link<span> </span>></a>
+<h1 id="h1">h1<span> </span></h1>
+<h1 id="h1WithDiv"><div>h1 with div<span> </span></div></h1>
+<input id="range" type="range">
+<div onclick=";" id="clickable">clickable</div>
+<div id="editable" contenteditable>editable</div>
+<table id="table"><tr><th>th</th></tr></table>
+ `,
+ async function (browser, docAcc) {
+ await definePyVar("doc", `getDocUia()`);
+ await assignPyVarToUiaWithId("p");
+ await testIsControl("p", false);
+ await definePyVar(
+ "pTextLeaf",
+ `uiaClient.RawViewWalker.GetFirstChildElement(p)`
+ );
+ await testIsControl("pTextLeaf", true);
+ await assignPyVarToUiaWithId("div");
+ await testIsControl("div", false);
+ await definePyVar(
+ "divTextLeaf",
+ `uiaClient.RawViewWalker.GetFirstChildElement(div)`
+ );
+ await testIsControl("divTextLeaf", true);
+ await assignPyVarToUiaWithId("link");
+ await testIsControl("link", true);
+ await assignPyVarToUiaWithId("range");
+ await testIsControl("range", true);
+ await assignPyVarToUiaWithId("editable");
+ await testIsControl("editable", true);
+ await assignPyVarToUiaWithId("table");
+ await testIsControl("table", true);
+ if (!gIsUiaEnabled) {
+ // The remaining tests are broken with the UIA -> IA2 proxy.
+ return;
+ }
+ await definePyVar(
+ "linkTextLeaf",
+ `uiaClient.RawViewWalker.GetFirstChildElement(link)`
+ );
+ await testIsControl("linkTextLeaf", false);
+ await assignPyVarToUiaWithId("h1");
+ await testIsControl("h1", true);
+ await definePyVar(
+ "h1TextLeaf",
+ `uiaClient.RawViewWalker.GetFirstChildElement(h1)`
+ );
+ await testIsControl("h1TextLeaf", false);
+ await assignPyVarToUiaWithId("h1WithDiv");
+ await testIsControl("h1WithDiv", true);
+ // h1WithDiv's text leaf is its grandchild.
+ await definePyVar(
+ "h1WithDivTextLeaf",
+ `uiaClient.RawViewWalker.GetFirstChildElement(
+ uiaClient.RawViewWalker.GetFirstChildElement(
+ h1WithDiv
+ )
+ )`
+ );
+ await testIsControl("h1WithDivTextLeaf", false);
+ await assignPyVarToUiaWithId("clickable");
+ await testIsControl("clickable", true);
+ }
+);
diff --git a/accessible/tests/browser/windows/uia/head.js b/accessible/tests/browser/windows/uia/head.js
index afc50984bd..e659354c7c 100644
--- a/accessible/tests/browser/windows/uia/head.js
+++ b/accessible/tests/browser/windows/uia/head.js
@@ -4,6 +4,8 @@
"use strict";
+/* exported gIsUiaEnabled, addUiaTask */
+
// Load the shared-head file first.
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js",
@@ -16,3 +18,38 @@ loadScripts(
{ name: "common.js", dir: MOCHITESTS_DIR },
{ name: "promisified-events.js", dir: MOCHITESTS_DIR }
);
+
+let gIsUiaEnabled = false;
+
+/**
+ * This is like addAccessibleTask, but takes two additional boolean options:
+ * - uiaEnabled: Whether to run a variation of this test with Gecko UIA enabled.
+ * - uiaDisabled: Whether to run a variation of this test with UIA disabled. In
+ * this case, UIA will rely entirely on the IA2 -> UIA proxy.
+ * If both are set, the test will be run twice with different configurations.
+ * You can determine which variant is currently running using the gIsUiaEnabled
+ * variable. This is useful for conditional tests; e.g. if Gecko UIA supports
+ * something that the IA2 -> UIA proxy doesn't support.
+ */
+function addUiaTask(doc, task, options = {}) {
+ const { uiaEnabled = true, uiaDisabled = true } = options;
+
+ function addTask(shouldEnable) {
+ async function uiaTask(browser, docAcc, topDocAcc) {
+ await SpecialPowers.pushPrefEnv({
+ set: [["accessibility.uia.enable", shouldEnable]],
+ });
+ gIsUiaEnabled = shouldEnable;
+ info(shouldEnable ? "Gecko UIA enabled" : "Gecko UIA disabled");
+ await task(browser, docAcc, topDocAcc);
+ }
+ addAccessibleTask(doc, uiaTask, options);
+ }
+
+ if (uiaEnabled) {
+ addTask(true);
+ }
+ if (uiaDisabled) {
+ addTask(false);
+ }
+}