From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- accessible/tests/browser/pivot/browser.toml | 10 ++ accessible/tests/browser/pivot/browser_pivot.js | 103 ++++++++++++++++++++ accessible/tests/browser/pivot/head.js | 122 ++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 accessible/tests/browser/pivot/browser.toml create mode 100644 accessible/tests/browser/pivot/browser_pivot.js create mode 100644 accessible/tests/browser/pivot/head.js (limited to 'accessible/tests/browser/pivot') 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( + ` +

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.

+ +

+ This is completely transparent +

+ +
Hide me
+ + + `, + 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}`); + } +} -- cgit v1.2.3