browser_accessibility_highlighter_infobar.js (2288B)
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/. */ 4 5 "use strict"; 6 7 // Test the accessible highlighter's infobar content. 8 9 const { truncateString } = require("resource://devtools/shared/string.js"); 10 const { 11 MAX_STRING_LENGTH, 12 } = require("resource://devtools/server/actors/highlighters/utils/accessibility.js"); 13 14 add_task(async function () { 15 const { target, walker, parentAccessibility, a11yWalker } = 16 await initAccessibilityFrontsForUrl( 17 MAIN_DOMAIN + "doc_accessibility_infobar.html" 18 ); 19 20 info("Button front checks"); 21 await checkNameAndRole(walker, "#button", a11yWalker, "Accessible Button"); 22 23 info("Front with long name checks"); 24 await checkNameAndRole( 25 walker, 26 "#h1", 27 a11yWalker, 28 "Lorem ipsum dolor sit ame" + "\u2026" + "e et dolore magna aliqua." 29 ); 30 31 await waitForA11yShutdown(parentAccessibility); 32 await target.destroy(); 33 gBrowser.removeCurrentTab(); 34 }); 35 36 /** 37 * A helper function for testing the accessible's displayed name and roles. 38 * 39 * @param {object} walker 40 * The DOM walker. 41 * @param {string} querySelector 42 * The selector for the node to retrieve accessible from. 43 * @param {object} a11yWalker 44 * The accessibility walker. 45 * @param {string} expectedName 46 * Expected string content for displaying the accessible's name. 47 * We are testing this in particular because name can be truncated. 48 */ 49 async function checkNameAndRole( 50 walker, 51 querySelector, 52 a11yWalker, 53 expectedName 54 ) { 55 const node = await walker.querySelector(walker.rootNode, querySelector); 56 const accessibleFront = await a11yWalker.getAccessibleFor(node); 57 58 const { name, role } = accessibleFront; 59 const onHighlightEvent = a11yWalker.once("highlighter-event"); 60 61 await a11yWalker.highlightAccessible(accessibleFront); 62 const { options } = await onHighlightEvent; 63 is(options.name, name, "Accessible highlight has correct name option"); 64 is(options.role, role, "Accessible highlight has correct role option"); 65 66 is( 67 `"${truncateString(name, MAX_STRING_LENGTH)}"`, 68 `"${expectedName}"`, 69 "Accessible has correct displayed name." 70 ); 71 }