diff options
Diffstat (limited to 'accessible/tests/browser/pivot')
-rw-r--r-- | accessible/tests/browser/pivot/browser.toml | 10 | ||||
-rw-r--r-- | accessible/tests/browser/pivot/browser_pivot.js | 103 | ||||
-rw-r--r-- | accessible/tests/browser/pivot/head.js | 122 |
3 files changed, 235 insertions, 0 deletions
diff --git a/accessible/tests/browser/pivot/browser.toml b/accessible/tests/browser/pivot/browser.toml new file mode 100644 index 0000000000..f6552741e5 --- /dev/null +++ b/accessible/tests/browser/pivot/browser.toml @@ -0,0 +1,10 @@ +[DEFAULT] +subsuite = "a11y" +support-files = [ + "!/accessible/tests/browser/shared-head.js", + "head.js", + "!/accessible/tests/mochitest/*.js", +] +prefs = ["javascript.options.asyncstack_capture_debuggee_only=false"] + +["browser_pivot.js"] diff --git a/accessible/tests/browser/pivot/browser_pivot.js b/accessible/tests/browser/pivot/browser_pivot.js new file mode 100644 index 0000000000..bd46ae4933 --- /dev/null +++ b/accessible/tests/browser/pivot/browser_pivot.js @@ -0,0 +1,103 @@ +/* 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"; + +/** + * Tests Pivot API + */ +addAccessibleTask( + ` + <h1 id="heading-1-1">Main Title</h1> + <h2 id="heading-2-1" aria-hidden="true">First Section Title</h2> + <p id="paragraph-1"> + Lorem ipsum <strong>dolor</strong> sit amet. Integer vitae urna + leo, id <a href="#">semper</a> nulla. + </p> + <h2 id="heading-2-2" aria-hidden="undefined">Second Section Title</h2> + <p id="paragraph-2" aria-hidden=""> + Sed accumsan luctus lacus, vitae mollis arcu tristique vulputate.</p> + <p id="paragraph-3" aria-hidden="true"> + <a href="#" id="hidden-link">Maybe</a> it was the other <i>George Michael</i>. + You know, the <a href="#">singer-songwriter</a>. + </p> + <p style="opacity: 0;" id="paragraph-4"> + This is completely transparent + </p> + <iframe + src="data:text/html,<html><body>An <i>embedded</i> document.</body></html>"> + </iframe> + <div id="hide-me">Hide me</div> + <p id="links" aria-hidden="false"> + <a href="http://mozilla.org" title="Link 1 title">Link 1</a> + <a href="http://mozilla.org" title="Link 2 title">Link 2</a> + <a href="http://mozilla.org" title="Link 3 title">Link 3</a> + </p> + <ul> + <li>Hello<span> </span></li> + <li>World</li> + </ul> + `, + async function (browser, docAcc) { + let pivot = gAccService.createAccessiblePivot(docAcc); + testPivotSequence(pivot, HeadersTraversalRule, [ + "heading-1-1", + "heading-2-2", + ]); + + testPivotSequence(pivot, ObjectTraversalRule, [ + "Main Title", + "Lorem ipsum ", + "dolor", + " sit amet. Integer vitae urna leo, id ", + "semper", + " nulla. ", + "Second Section Title", + "Sed accumsan luctus lacus, vitae mollis arcu tristique vulputate.", + "An ", + "embedded", + " document.", + "Hide me", + "Link 1", + "Link 2", + "Link 3", + "Hello", + "World", + ]); + + let hideMeAcc = findAccessibleChildByID(docAcc, "hide-me"); + let onHide = waitForEvent(EVENT_HIDE, hideMeAcc); + invokeContentTask(browser, [], () => { + content.document.getElementById("hide-me").remove(); + }); + + await onHide; + testFailsWithNotInTree( + () => pivot.next(hideMeAcc, ObjectTraversalRule), + "moveNext from defunct accessible should fail" + ); + + let linksAcc = findAccessibleChildByID(docAcc, "links"); + + let removedRootPivot = gAccService.createAccessiblePivot(linksAcc); + onHide = waitForEvent(EVENT_HIDE, linksAcc); + invokeContentTask(browser, [], () => { + content.document.getElementById("links").remove(); + }); + + await onHide; + testFailsWithNotInTree( + () => removedRootPivot.last(ObjectTraversalRule), + "moveLast with pivot with defunct root should fail" + ); + + let [x, y] = getBounds(findAccessibleChildByID(docAcc, "heading-1-1")); + let hitacc = pivot.atPoint(x + 1, y + 1, HeadersTraversalRule); + is(getIdOrName(hitacc), "heading-1-1", "Matching accessible at point"); + + hitacc = pivot.atPoint(x - 1, y - 1, HeadersTraversalRule); + ok(!hitacc, "No heading at given point"); + }, + { iframe: true, remoteIframe: true, topLevel: true, chrome: true } +); diff --git a/accessible/tests/browser/pivot/head.js b/accessible/tests/browser/pivot/head.js new file mode 100644 index 0000000000..8389190a69 --- /dev/null +++ b/accessible/tests/browser/pivot/head.js @@ -0,0 +1,122 @@ +/* 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"; + +/* exported HeadersTraversalRule, ObjectTraversalRule, testPivotSequence, testFailsWithNotInTree */ + +// Load the shared-head file first. +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js", + this +); + +/* import-globals-from ../../mochitest/layout.js */ +/* import-globals-from ../../mochitest/role.js */ +/* import-globals-from ../../mochitest/states.js */ +loadScripts( + { name: "common.js", dir: MOCHITESTS_DIR }, + { name: "promisified-events.js", dir: MOCHITESTS_DIR }, + { name: "states.js", dir: MOCHITESTS_DIR }, + { name: "role.js", dir: MOCHITESTS_DIR }, + { name: "layout.js", dir: MOCHITESTS_DIR } +); + +const FILTER_MATCH = nsIAccessibleTraversalRule.FILTER_MATCH; +const FILTER_IGNORE = nsIAccessibleTraversalRule.FILTER_IGNORE; +const FILTER_IGNORE_SUBTREE = nsIAccessibleTraversalRule.FILTER_IGNORE_SUBTREE; + +const NS_ERROR_NOT_IN_TREE = 0x80780026; + +// ////////////////////////////////////////////////////////////////////////////// +// Traversal rules + +/** + * Rule object to traverse all focusable nodes and text nodes. + */ +const HeadersTraversalRule = { + match(acc) { + return acc.role == ROLE_HEADING ? FILTER_MATCH : FILTER_IGNORE; + }, + + QueryInterface: ChromeUtils.generateQI([nsIAccessibleTraversalRule]), +}; + +/** + * Traversal rule for all focusable nodes or leafs. + */ +const ObjectTraversalRule = { + match(acc) { + let [state, extstate] = getStates(acc); + if (state & STATE_INVISIBLE) { + return FILTER_IGNORE; + } + + if ((extstate & EXT_STATE_OPAQUE) == 0) { + return FILTER_IGNORE | FILTER_IGNORE_SUBTREE; + } + + let rv = FILTER_IGNORE; + let role = acc.role; + if ( + hasState(acc, STATE_FOCUSABLE) && + role != ROLE_DOCUMENT && + role != ROLE_INTERNAL_FRAME + ) { + rv = FILTER_IGNORE_SUBTREE | FILTER_MATCH; + } else if ( + acc.childCount == 0 && + role != ROLE_LISTITEM_MARKER && + acc.name.trim() + ) { + rv = FILTER_MATCH; + } + + return rv; + }, + + QueryInterface: ChromeUtils.generateQI([nsIAccessibleTraversalRule]), +}; + +function getIdOrName(acc) { + let id = getAccessibleDOMNodeID(acc); + if (id) { + return id; + } + return acc.name; +} + +function* pivotNextGenerator(pivot, rule) { + for (let acc = pivot.first(rule); acc; acc = pivot.next(acc, rule)) { + yield acc; + } +} + +function* pivotPreviousGenerator(pivot, rule) { + for (let acc = pivot.last(rule); acc; acc = pivot.prev(acc, rule)) { + yield acc; + } +} + +function testPivotSequence(pivot, rule, expectedSequence) { + is( + JSON.stringify([...pivotNextGenerator(pivot, rule)].map(getIdOrName)), + JSON.stringify(expectedSequence), + "Forward pivot sequence is correct" + ); + is( + JSON.stringify([...pivotPreviousGenerator(pivot, rule)].map(getIdOrName)), + JSON.stringify([...expectedSequence].reverse()), + "Reverse pivot sequence is correct" + ); +} + +function testFailsWithNotInTree(func, msg) { + try { + func(); + ok(false, msg); + } catch (x) { + is(x.result, NS_ERROR_NOT_IN_TREE, `Expecting NOT_IN_TREE: ${msg}`); + } +} |