browser_accessibility_tree_audit_toolbar.js (2869B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* global toggleMenuItem, TREE_FILTERS_MENU_ID */ 7 8 const TEST_URI = `<html> 9 <head> 10 <meta charset="utf-8"/> 11 <title>Accessibility Panel Test</title> 12 </head> 13 <body> 14 <h1 style="color:rgba(255,0,0,0.1); background-color:rgba(255,255,255,1);"> 15 Top level header 16 </h1> 17 <h2 style="color:rgba(0,255,0,0.1); background-color:rgba(255,255,255,1);"> 18 Second level header 19 </h2> 20 </body> 21 </html>`; 22 23 /** 24 * Test data has the format of: 25 * { 26 * desc {String} description for better logging 27 * setup {Function} An optional setup that needs to be performed before 28 * the state of the tree and the sidebar can be checked. 29 * expected {JSON} An expected states for the tree and the sidebar. 30 * } 31 */ 32 const tests = [ 33 { 34 desc: "Check initial state.", 35 expected: { 36 tree: [ 37 { 38 role: "document", 39 name: `"Accessibility Panel Test"`, 40 selected: true, 41 }, 42 ], 43 activeToolbarFilters: [true, false, false, false, false], 44 }, 45 }, 46 { 47 desc: "Run an audit (all) from a11y panel toolbar by activating a filter.", 48 setup: async ({ doc, toolbox }) => { 49 await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1); 50 }, 51 expected: { 52 tree: [ 53 { 54 role: "text leaf", 55 name: `"Top level header "contrast`, 56 badges: ["contrast"], 57 selected: true, 58 }, 59 { 60 role: "text leaf", 61 name: `"Second level header "contrast`, 62 badges: ["contrast"], 63 }, 64 ], 65 activeToolbarFilters: [false, true, true, true, true], 66 }, 67 }, 68 { 69 desc: "Click on the filter again.", 70 setup: async ({ doc, toolbox }) => { 71 await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1); 72 }, 73 expected: { 74 tree: [ 75 { 76 role: "document", 77 name: `"Accessibility Panel Test"`, 78 }, 79 { 80 role: "heading", 81 name: `"Top level header"`, 82 }, 83 { 84 role: "text leaf", 85 name: `"Top level header "contrast`, 86 badges: ["contrast"], 87 selected: true, 88 }, 89 { 90 role: "heading", 91 name: `"Second level header"`, 92 }, 93 { 94 role: "text leaf", 95 name: `"Second level header "contrast`, 96 badges: ["contrast"], 97 }, 98 ], 99 activeToolbarFilters: [true, false, false, false, false], 100 }, 101 }, 102 ]; 103 104 /** 105 * Simple test that checks content of the Accessibility panel tree when the 106 * audit is activated via the panel's toolbar. 107 */ 108 addA11yPanelTestsTask( 109 tests, 110 TEST_URI, 111 "Test Accessibility panel tree with 'all' filter audit activation." 112 );