1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* exported HeadersTraversalRule, ObjectTraversalRule, testPivotSequence, testFailsWithNotInTree */
9 // Load the shared-head file first.
10 Services.scriptloader.loadSubScript(
11 "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js",
15 /* import-globals-from ../../mochitest/layout.js */
16 /* import-globals-from ../../mochitest/role.js */
17 /* import-globals-from ../../mochitest/states.js */
19 { name: "common.js", dir: MOCHITESTS_DIR },
20 { name: "promisified-events.js", dir: MOCHITESTS_DIR },
21 { name: "states.js", dir: MOCHITESTS_DIR },
22 { name: "role.js", dir: MOCHITESTS_DIR },
23 { name: "layout.js", dir: MOCHITESTS_DIR }
26 const FILTER_MATCH = nsIAccessibleTraversalRule.FILTER_MATCH;
27 const FILTER_IGNORE = nsIAccessibleTraversalRule.FILTER_IGNORE;
28 const FILTER_IGNORE_SUBTREE = nsIAccessibleTraversalRule.FILTER_IGNORE_SUBTREE;
30 const NS_ERROR_NOT_IN_TREE = 0x80780026;
32 // //////////////////////////////////////////////////////////////////////////////
36 * Rule object to traverse all focusable nodes and text nodes.
38 const HeadersTraversalRule = {
40 return acc.role == ROLE_HEADING ? FILTER_MATCH : FILTER_IGNORE;
43 QueryInterface: ChromeUtils.generateQI([nsIAccessibleTraversalRule]),
47 * Traversal rule for all focusable nodes or leafs.
49 const ObjectTraversalRule = {
51 let [state, extstate] = getStates(acc);
52 if (state & STATE_INVISIBLE) {
56 if ((extstate & EXT_STATE_OPAQUE) == 0) {
57 return FILTER_IGNORE | FILTER_IGNORE_SUBTREE;
60 let rv = FILTER_IGNORE;
63 hasState(acc, STATE_FOCUSABLE) &&
64 role != ROLE_DOCUMENT &&
65 role != ROLE_INTERNAL_FRAME
67 rv = FILTER_IGNORE_SUBTREE | FILTER_MATCH;
69 acc.childCount == 0 &&
70 role != ROLE_LISTITEM_MARKER &&
79 QueryInterface: ChromeUtils.generateQI([nsIAccessibleTraversalRule]),
82 function getIdOrName(acc) {
83 let id = getAccessibleDOMNodeID(acc);
90 function* pivotNextGenerator(pivot, rule) {
91 for (let acc = pivot.first(rule); acc; acc = pivot.next(acc, rule)) {
96 function* pivotPreviousGenerator(pivot, rule) {
97 for (let acc = pivot.last(rule); acc; acc = pivot.prev(acc, rule)) {
102 function testPivotSequence(pivot, rule, expectedSequence) {
104 JSON.stringify([...pivotNextGenerator(pivot, rule)].map(getIdOrName)),
105 JSON.stringify(expectedSequence),
106 "Forward pivot sequence is correct"
109 JSON.stringify([...pivotPreviousGenerator(pivot, rule)].map(getIdOrName)),
110 JSON.stringify([...expectedSequence].reverse()),
111 "Reverse pivot sequence is correct"
115 function testFailsWithNotInTree(func, msg) {
120 is(x.result, NS_ERROR_NOT_IN_TREE, `Expecting NOT_IN_TREE: ${msg}`);