browser_accessibility_simulation.js (3365B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* global openSimulationMenu, toggleSimulationOption */ 7 8 const TEST_URI = `<html> 9 <head> 10 <meta charset="utf-8"/> 11 <title>Accessibility Simulations Test</title> 12 </head> 13 <body> 14 <h1 style="color:blue; background-color:rgba(255,255,255,1);"> 15 Top level header 16 </h1> 17 <h2 style="color:green; background-color:rgba(255,255,255,1);"> 18 Second level header 19 </h2> 20 </body> 21 </html>`; 22 23 const { 24 simulation, 25 } = require("resource://devtools/server/actors/accessibility/constants.js"); 26 27 /** 28 * Test data has the format of: 29 * { 30 * desc {String} description for better logging 31 * setup {Function} An optional setup that needs to be performed before 32 * the state of the simulation components can be checked. 33 * expected {JSON} An expected states for the simulation components. 34 * } 35 */ 36 const tests = [ 37 { 38 desc: "Check that the menu button is inactivate and the menu is closed initially.", 39 expected: { 40 simulation: { 41 buttonActive: false, 42 colorMatrix: [], 43 }, 44 }, 45 }, 46 { 47 desc: "Clicking the menu button shows the menu with No Simulation selected.", 48 setup: async ({ doc, toolbox }) => { 49 await openSimulationMenu(doc, toolbox.doc); 50 }, 51 expected: { 52 simulation: { 53 buttonActive: false, 54 checkedOptionIndices: [0], 55 colorMatrix: [], 56 }, 57 }, 58 }, 59 { 60 desc: "Selecting an option renders the menu button active and closes the menu.", 61 setup: async ({ toolbox }) => { 62 await toggleSimulationOption(toolbox.doc, 2); 63 }, 64 expected: { 65 simulation: { 66 buttonActive: true, 67 checkedOptionIndices: [2], 68 colorMatrix: simulation.COLOR_TRANSFORMATION_MATRICES.DEUTERANOPIA, 69 }, 70 }, 71 }, 72 { 73 desc: "Reopening the menu preserves the previously selected option.", 74 setup: async ({ doc, toolbox }) => { 75 await openSimulationMenu(doc, toolbox.doc); 76 }, 77 expected: { 78 simulation: { 79 buttonActive: true, 80 checkedOptionIndices: [2], 81 colorMatrix: simulation.COLOR_TRANSFORMATION_MATRICES.DEUTERANOPIA, 82 }, 83 }, 84 }, 85 { 86 desc: "Reloading the page preserves the previously selected option.", 87 setup: async ({ panel }) => { 88 const onReloaded = panel.once("reloaded"); 89 panel.accessibilityProxy.commands.targetCommand.reloadTopLevelTarget(); 90 await onReloaded; 91 }, 92 expected: { 93 simulation: { 94 buttonActive: true, 95 checkedOptionIndices: [2], 96 colorMatrix: simulation.COLOR_TRANSFORMATION_MATRICES.DEUTERANOPIA, 97 }, 98 }, 99 }, 100 { 101 desc: "Unselecting the option renders the button inactive and closes the menu.", 102 setup: async ({ toolbox }) => { 103 await toggleSimulationOption(toolbox.doc, 2); 104 }, 105 expected: { 106 simulation: { 107 buttonActive: false, 108 checkedOptionIndices: [0], 109 colorMatrix: simulation.COLOR_TRANSFORMATION_MATRICES.NONE, 110 }, 111 }, 112 }, 113 ]; 114 115 /** 116 * Test that checks state of simulation button and menu when 117 * options are selected/unselected with web render enabled. 118 */ 119 addA11yPanelTestsTask( 120 tests, 121 TEST_URI, 122 "Test selecting and unselecting simulation options updates UI." 123 );