browser_link.js (5697B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from ../../mochitest/role.js */ 7 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); 8 9 /** 10 * Verify that an anchor element reports a generic role without an href 11 * attribute and reports a LINK role with it present. Verify that these roles 12 * change as the attribute appears and disappears. 13 */ 14 addAccessibleTask( 15 ` 16 <a id="link">test</a> 17 `, 18 async function (browser, accDoc) { 19 let link = findAccessibleChildByID(accDoc, "link"); 20 is(link.role, ROLE_TEXT, "Checking role of anchor element without href"); 21 22 let onHideAndShow = waitForEvents({ 23 expected: [ 24 [EVENT_HIDE, link], 25 [EVENT_SHOW, "link"], 26 ], 27 }); 28 info("Adding an href to the anchor element"); 29 await invokeContentTask(browser, [], () => { 30 content.document.getElementById("link").setAttribute("href", "#"); 31 }); 32 await onHideAndShow; 33 34 link = findAccessibleChildByID(accDoc, "link"); 35 is(link.role, ROLE_LINK, "Checking role of anchor element with href"); 36 37 onHideAndShow = waitForEvents({ 38 expected: [ 39 [EVENT_HIDE, link], 40 [EVENT_SHOW, "link"], 41 ], 42 }); 43 info("Removing the href from the anchor element"); 44 await invokeContentTask(browser, [], () => { 45 content.document.getElementById("link").removeAttribute("href"); 46 }); 47 await onHideAndShow; 48 link = findAccessibleChildByID(accDoc, "link"); 49 is(link.role, ROLE_TEXT, "Checking role of anchor element without href"); 50 }, 51 { 52 chrome: true, 53 topLevel: true, 54 iframe: true, 55 remoteIframe: true, 56 } 57 ); 58 59 /** 60 * Verify that an anchor element reports a generic role without a click listener 61 * and reports a LINK role with it present. Verify that these roles change as 62 * the click listener appears. 63 */ 64 addAccessibleTask( 65 ` 66 <a id="link">test</a> 67 `, 68 async function (browser, accDoc) { 69 let link = findAccessibleChildByID(accDoc, "link"); 70 is( 71 link.role, 72 ROLE_TEXT, 73 "Checking role of anchor element without click listener" 74 ); 75 76 let onHideAndShow = waitForEvents({ 77 expected: [ 78 [EVENT_HIDE, link], 79 [EVENT_SHOW, "link"], 80 ], 81 }); 82 info("Adding a click listener to the anchor element"); 83 await invokeContentTask(browser, [], () => { 84 content.document 85 .getElementById("link") 86 .addEventListener("click", () => {}); 87 }); 88 await onHideAndShow; 89 90 link = findAccessibleChildByID(accDoc, "link"); 91 is( 92 link.role, 93 ROLE_LINK, 94 "Checking role of anchor element with click listener" 95 ); 96 }, 97 { 98 chrome: true, 99 topLevel: true, 100 iframe: true, 101 remoteIframe: true, 102 } 103 ); 104 105 /** 106 * Verify that an area element reports a generic role without an href 107 * attribute and reports a LINK role with it present. Verify that these roles 108 * change as the attribute appears and disappears. 109 */ 110 addAccessibleTask( 111 ` 112 <map name="map"> 113 <area id="link"> 114 </map> 115 <img id="img" usemap="#map" src="http://example.com/a11y/accessible/tests/mochitest/letters.gif"> 116 `, 117 async function (browser, accDoc) { 118 let link = findAccessibleChildByID(accDoc, "link"); 119 is(link.role, ROLE_TEXT, "Checking role of area element without href"); 120 121 let img = findAccessibleChildByID(accDoc, "img"); 122 let onHideAndShow = waitForEvents({ 123 expected: [ 124 [EVENT_HIDE, img], 125 [EVENT_SHOW, "img"], 126 ], 127 }); 128 info("Adding an href to the area element"); 129 await invokeContentTask(browser, [], () => { 130 content.document.getElementById("link").setAttribute("href", "#"); 131 }); 132 await onHideAndShow; 133 134 link = findAccessibleChildByID(accDoc, "link"); 135 is(link.role, ROLE_LINK, "Checking role of area element with href"); 136 137 img = findAccessibleChildByID(accDoc, "img"); 138 onHideAndShow = waitForEvents({ 139 expected: [ 140 [EVENT_HIDE, img], 141 [EVENT_SHOW, "img"], 142 ], 143 }); 144 info("Removing the href from the area element"); 145 await invokeContentTask(browser, [], () => { 146 content.document.getElementById("link").removeAttribute("href"); 147 }); 148 await onHideAndShow; 149 link = findAccessibleChildByID(accDoc, "link"); 150 is(link.role, ROLE_TEXT, "Checking role of area element without href"); 151 }, 152 { 153 chrome: true, 154 topLevel: true, 155 iframe: true, 156 remoteIframe: true, 157 } 158 ); 159 160 /** 161 * Verify that an area element reports a generic role without a click listener 162 * and reports a LINK role with it present. Verify that these roles change as 163 * the click listener appears. 164 */ 165 addAccessibleTask( 166 ` 167 <map name="map"> 168 <area id="link"> 169 </map> 170 <img id="img" usemap="#map" src="http://example.com/a11y/accessible/tests/mochitest/letters.gif"> 171 `, 172 async function (browser, accDoc) { 173 let link = findAccessibleChildByID(accDoc, "link"); 174 is( 175 link.role, 176 ROLE_TEXT, 177 "Checking role of area element without click listener" 178 ); 179 180 let img = findAccessibleChildByID(accDoc, "img"); 181 let onHideAndShow = waitForEvents({ 182 expected: [ 183 [EVENT_HIDE, img], 184 [EVENT_SHOW, "img"], 185 ], 186 }); 187 info("Adding a click listener to the area element"); 188 await invokeContentTask(browser, [], () => { 189 content.document 190 .getElementById("link") 191 .addEventListener("click", () => {}); 192 }); 193 await onHideAndShow; 194 195 link = findAccessibleChildByID(accDoc, "link"); 196 is( 197 link.role, 198 ROLE_LINK, 199 "Checking role of area element with click listener" 200 ); 201 }, 202 { 203 chrome: true, 204 topLevel: true, 205 iframe: true, 206 remoteIframe: true, 207 } 208 );