browser_accessibility_tree_audit.js (3305B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* global toggleRow, 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: "Expand first and second tree nodes.", 35 setup: async ({ doc }) => { 36 await toggleRow(doc, 0); 37 await toggleRow(doc, 1); 38 }, 39 expected: { 40 tree: [ 41 { 42 role: "document", 43 name: `"Accessibility Panel Test"`, 44 level: 1, 45 }, 46 { 47 role: "heading", 48 name: `"Top level header"`, 49 level: 2, 50 }, 51 { 52 role: "text leaf", 53 name: `"Top level header "contrast`, 54 badges: ["contrast"], 55 level: 3, 56 }, 57 { 58 role: "heading", 59 name: `"Second level header"`, 60 level: 2, 61 }, 62 ], 63 }, 64 }, 65 { 66 desc: "Click on the all filter.", 67 setup: async ({ doc, toolbox }) => { 68 await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1); 69 }, 70 expected: { 71 tree: [ 72 { 73 role: "text leaf", 74 name: `"Top level header "contrast`, 75 badges: ["contrast"], 76 level: 1, 77 }, 78 { 79 role: "text leaf", 80 name: `"Second level header "contrast`, 81 badges: ["contrast"], 82 selected: true, 83 level: 1, 84 }, 85 ], 86 }, 87 }, 88 { 89 desc: "Click on the all filter again.", 90 setup: async ({ doc, toolbox }) => { 91 await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1); 92 }, 93 expected: { 94 tree: [ 95 { 96 role: "document", 97 name: `"Accessibility Panel Test"`, 98 level: 1, 99 }, 100 { 101 role: "heading", 102 name: `"Top level header"`, 103 level: 2, 104 }, 105 { 106 role: "text leaf", 107 name: `"Top level header "contrast`, 108 badges: ["contrast"], 109 level: 3, 110 }, 111 { 112 role: "heading", 113 name: `"Second level header"`, 114 level: 2, 115 }, 116 { 117 role: "text leaf", 118 name: `"Second level header "contrast`, 119 badges: ["contrast"], 120 selected: true, 121 level: 3, 122 }, 123 ], 124 }, 125 }, 126 ]; 127 128 /** 129 * Simple test that checks content of the Accessibility panel tree when one of 130 * the tree rows has a "contrast" badge and auditing is activated via toolbar 131 * filter. 132 */ 133 addA11yPanelTestsTask( 134 tests, 135 TEST_URI, 136 "Test Accessibility panel tree with contrast badge present." 137 );