diff options
Diffstat (limited to 'accessible/tests/browser/atk')
-rw-r--r-- | accessible/tests/browser/atk/a11y_setup.py | 64 | ||||
-rw-r--r-- | accessible/tests/browser/atk/browser.toml | 16 | ||||
-rw-r--r-- | accessible/tests/browser/atk/browser_role.js | 33 | ||||
-rw-r--r-- | accessible/tests/browser/atk/browser_table.js | 54 | ||||
-rw-r--r-- | accessible/tests/browser/atk/head.js | 18 |
5 files changed, 185 insertions, 0 deletions
diff --git a/accessible/tests/browser/atk/a11y_setup.py b/accessible/tests/browser/atk/a11y_setup.py new file mode 100644 index 0000000000..c5fe3481ff --- /dev/null +++ b/accessible/tests/browser/atk/a11y_setup.py @@ -0,0 +1,64 @@ +# 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/. + +"""Python environment for ATK a11y browser tests. +""" + +import os +import subprocess +import sys + +import psutil + +# pyatspi can't be installed using pip. Rely on the system installation. +# Get the path to the system installation of pyatspi. +pyatspiFile = subprocess.check_output( + ( + os.path.join(sys.base_prefix, "bin", "python3"), + "-c", + "import pyatspi; print(pyatspi.__file__)", + ), + encoding="utf-8", +).rstrip() +sys.path.append(os.path.dirname(os.path.dirname(pyatspiFile))) +import pyatspi + +sys.path.pop() +del pyatspiFile + + +def getDoc(): + """Get the Accessible for the document being tested.""" + # We can compare the parent process ids to find the Firefox started by the + # test harness. + commonPid = psutil.Process().ppid() + for app in pyatspi.Registry.getDesktop(0): + if ( + app.name == "Firefox" + and psutil.Process(app.get_process_id()).ppid() == commonPid + ): + break + else: + raise LookupError("Couldn't find Firefox application Accessible") + root = app[0] + for embeds in root.getRelationSet(): + if embeds.getRelationType() == pyatspi.RELATION_EMBEDS: + break + else: + raise LookupError("Firefox root doesn't have RELATION_EMBEDS") + doc = embeds.getTarget(0) + child = doc[0] + if child.get_attributes().get("id") == "default-iframe-id": + # This is an iframe or remoteIframe test. + doc = child[0] + return doc + + +def findByDomId(root, id): + for child in root: + if child.get_attributes().get("id") == id: + return child + descendant = findByDomId(child, id) + if descendant: + return descendant diff --git a/accessible/tests/browser/atk/browser.toml b/accessible/tests/browser/atk/browser.toml new file mode 100644 index 0000000000..99cdba4ca2 --- /dev/null +++ b/accessible/tests/browser/atk/browser.toml @@ -0,0 +1,16 @@ +[DEFAULT] +subsuite = "a11y" +skip-if = [ + "os != 'linux'", + "headless", +] +support-files = ["head.js"] +prefs = [ + # Enabling the a11y service from XPCOM doesn't seem to be enough to get ATK + # working correctly. Force enable it before the test starts. + "accessibility.force_disabled=-1", + "javascript.options.asyncstack_capture_debuggee_only=false", +] + +["browser_role.js"] +["browser_table.js"] diff --git a/accessible/tests/browser/atk/browser_role.js b/accessible/tests/browser/atk/browser_role.js new file mode 100644 index 0000000000..7b870b3337 --- /dev/null +++ b/accessible/tests/browser/atk/browser_role.js @@ -0,0 +1,33 @@ +/* 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"; + +const ATSPI_ROLE_DOCUMENT_WEB = 95; +const ATSPI_ROLE_PARAGRAPH = 73; + +addAccessibleTask( + ` +<p id="p">p</p> + `, + async function (browser, docAcc) { + let role = await runPython(` + global doc + doc = getDoc() + return doc.getRole() + `); + is(role, ATSPI_ROLE_DOCUMENT_WEB, "doc has correct ATSPI role"); + ok( + await runPython(` + global p + p = findByDomId(doc, "p") + return p == doc[0] + `), + "doc's first child is p" + ); + role = await runPython(`p.getRole()`); + is(role, ATSPI_ROLE_PARAGRAPH, "p has correct ATSPI role"); + }, + { chrome: true, topLevel: true, iframe: true, remoteIframe: true } +); diff --git a/accessible/tests/browser/atk/browser_table.js b/accessible/tests/browser/atk/browser_table.js new file mode 100644 index 0000000000..98b3270465 --- /dev/null +++ b/accessible/tests/browser/atk/browser_table.js @@ -0,0 +1,54 @@ +/* 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 getRowColumnSpan. + */ +addAccessibleTask( + ` +<table> + <tr> + <th id="ab" colspan="2">ab</th> + <td id="cf" rowspan="2">cf</td> + </tr> + <tr> + <td id="d">d</td> + <td>e</td> + </tr> +</table> + `, + async function (browser, docAcc) { + let result = await runPython(` + global doc + doc = getDoc() + ab = findByDomId(doc, "ab") + return str(ab.queryTableCell().getRowColumnSpan()) + `); + is( + result, + "(row=0, column=0, row_span=1, column_span=2)", + "ab getColumnRowSpan correct" + ); + result = await runPython(` + cf = findByDomId(doc, "cf") + return str(cf.queryTableCell().getRowColumnSpan()) + `); + is( + result, + "(row=0, column=2, row_span=2, column_span=1)", + "cf getColumnRowSpan correct" + ); + result = await runPython(` + d = findByDomId(doc, "d") + return str(d.queryTableCell().getRowColumnSpan()) + `); + is( + result, + "(row=1, column=0, row_span=1, column_span=1)", + "d getColumnRowSpan correct" + ); + } +); diff --git a/accessible/tests/browser/atk/head.js b/accessible/tests/browser/atk/head.js new file mode 100644 index 0000000000..afc50984bd --- /dev/null +++ b/accessible/tests/browser/atk/head.js @@ -0,0 +1,18 @@ +/* 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"; + +// Load the shared-head file first. +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js", + this +); + +// Loading and common.js from accessible/tests/mochitest/ for all tests, as +// well as promisified-events.js. +loadScripts( + { name: "common.js", dir: MOCHITESTS_DIR }, + { name: "promisified-events.js", dir: MOCHITESTS_DIR } +); |