browser_accessibility_sidebar_checks.js (2064B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { 7 accessibility: { SCORES }, 8 } = require("resource://devtools/shared/constants.js"); 9 10 const TEST_URI = `<html> 11 <head> 12 <meta charset="utf-8"/> 13 <title>Accessibility Panel Test</title> 14 </head> 15 <body> 16 <p style="color: red;">Red</p> 17 <p style="color: blue;">Blue</p> 18 <p style="color: gray; background: linear-gradient(#e66465, #9198e5);">Gray</p> 19 </body> 20 </html>`; 21 22 /** 23 * Test data has the format of: 24 * { 25 * desc {String} description for better logging 26 * setup {Function} An optional setup that needs to be performed before 27 * the state of the tree and the sidebar can be checked. 28 * expected {JSON} An expected states for the tree and the sidebar. 29 * } 30 */ 31 const tests = [ 32 { 33 desc: "Test the initial accessibility audit state.", 34 setup: async ({ doc }) => { 35 await selectRow(doc, 0); 36 }, 37 expected: { 38 audit: { CONTRAST: null }, 39 }, 40 }, 41 { 42 desc: "Check accessible representing text node in red.", 43 setup: async ({ doc }) => { 44 await toggleRow(doc, 0); 45 await toggleRow(doc, 1); 46 await selectRow(doc, 2); 47 }, 48 expected: { 49 audit: { 50 CONTRAST: { 51 value: 4.0, 52 color: [255, 0, 0, 1], 53 backgroundColor: [255, 255, 255, 1], 54 isLargeText: false, 55 score: SCORES.FAIL, 56 }, 57 }, 58 }, 59 }, 60 { 61 desc: "Check accessible representing text node in blue.", 62 setup: async ({ doc }) => { 63 await toggleRow(doc, 3); 64 await selectRow(doc, 4); 65 }, 66 expected: { 67 audit: { 68 CONTRAST: { 69 value: 8.59, 70 color: [0, 0, 255, 1], 71 backgroundColor: [255, 255, 255, 1], 72 isLargeText: false, 73 score: SCORES.AAA, 74 }, 75 }, 76 }, 77 }, 78 ]; 79 80 /** 81 * Test that checks the Accessibility panel sidebar. 82 */ 83 addA11yPanelTestsTask(tests, TEST_URI, "Test Accessibility panel sidebar.");