1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/test_bug409604.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,393 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=409604 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 409604</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 +</head> 1.14 +<body id="body"> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=409604">Mozilla Bug 409604</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript"> 1.22 + 1.23 + /** Test for Bug 409604 **/ 1.24 + 1.25 + var modifier = SpecialPowers.Ci.nsIDOMEvent.ALT_MASK | 1.26 + SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK; 1.27 + var expectedFocus = "a,c,d,e,f,g,h,i,j,k,l,m,n,p,x,y"; 1.28 + // XXX the "map" test is causing trouble, see bug 433089 1.29 + var focusArray = expectedFocus.split(","); 1.30 + var unfocusableElementId = "invalid"; 1.31 + var unfocusableTags = [ 1.32 + {tag: "abbr", content: "text", attribs: {title: "something"}}, 1.33 + {tag: "acronym", content: "text", attribs: {title: "something"}}, 1.34 + {tag: "address", content: "text"}, 1.35 + {tag: "b", content: "text"}, 1.36 + {tag: "bdo", content: "text"}, 1.37 + {tag: "big", content: "text"}, 1.38 + {tag: "blockquote", content: "text"}, 1.39 + {tag: "caption", content: "text", parent: "table", where: "first"}, 1.40 + {tag: "cite", content: "text"}, 1.41 + {tag: "code", content: "text"}, 1.42 + {tag: "dd", content: "text", parent: "dl"}, 1.43 + {tag: "del", content: "text"}, 1.44 + {tag: "dfn", content: "text", attribs: {title: "something"}}, 1.45 + {tag: "div", content: "text"}, 1.46 + {tag: "dl", content: "<dd>text</dd>", parent: "dl"}, 1.47 + {tag: "dt", content: "text", parent: "dl"}, 1.48 + {tag: "em", content: "text"}, 1.49 + {tag: "fieldset", content: "text"}, 1.50 + {tag: "form", content: "text", attribs: {action: "any.html"}}, 1.51 + {tag: "h1", content: "text"}, 1.52 + {tag: "h2", content: "text"}, 1.53 + {tag: "h3", content: "text"}, 1.54 + {tag: "h4", content: "text"}, 1.55 + {tag: "h5", content: "text"}, 1.56 + {tag: "h6", content: "text"}, 1.57 + {tag: "hr"}, 1.58 + {tag: "i", content: "text"}, 1.59 + {tag: "img", attribs: {src: "any.png", alt: "image"}}, 1.60 + {tag: "ins", content: "text"}, 1.61 + {tag: "kbd", content: "text"}, 1.62 + {tag: "li", content: "text", parent: "ol"}, 1.63 + {tag: "li", content: "text", parent: "ul"}, 1.64 + {tag: "noscript", content: "text"}, 1.65 + {tag: "ol", content: "<li>text</li>"}, 1.66 + {tag: "optgroup", content: "<option>text</option>", attribs: {label: "some label"}, parent: "select"}, 1.67 + {tag: "option", content: "text", parent: "select"}, 1.68 + {tag: "p", content: "text"}, 1.69 + {tag: "pre", content: "text"}, 1.70 + {tag: "q", content: "text"}, 1.71 + {tag: "samp", content: "text"}, 1.72 + {tag: "small", content: "text"}, 1.73 + {tag: "span", content: "text"}, 1.74 + {tag: "strong", content: "text"}, 1.75 + {tag: "sub", content: "text"}, 1.76 + {tag: "sup", content: "text"}, 1.77 + {tag: "tt", content: "text"}, 1.78 + {tag: "ul", content: "<li>text</li>"}, 1.79 + {tag: "var", content: "text"} 1.80 + ]; 1.81 + var invalidElements = [ 1.82 + "body", 1.83 + "col", 1.84 + "colgroup", 1.85 +// XXX the "map" test is causing trouble, see bug 433089 1.86 +// "map", 1.87 + "table", 1.88 + "tbody", 1.89 + "td", 1.90 + "tfoot", 1.91 + "th", 1.92 + "thead", 1.93 + "tr" 1.94 + ]; 1.95 + 1.96 + // ui.key.contentAccess must be set to value 5 before running the test. 1.97 + function setOrRestoreContentAccess(newValue) { 1.98 + if (!newValue) { 1.99 + SpecialPowers.clearUserPref("ui.key.contentAccess"); 1.100 + } else { 1.101 + SpecialPowers.setIntPref("ui.key.contentAccess", newValue); 1.102 + } 1.103 + } 1.104 + 1.105 + function handleFocus(e) { 1.106 + ok("accessKey" in e, "(focus) accesskey property not found on element"); 1.107 + var expected = focusArray.shift(); 1.108 + // "k" and "n" are a special cases because the element receiving the focus 1.109 + // is not the element which has the accesskey. 1.110 + if (expected == "k" || expected == "n") { 1.111 + ok(e.value == "test for label", "(focus) unexpected element: " + e.value + 1.112 + " expected: " + "test for label"); 1.113 + // "l" is a special case because the element receiving the focus is not 1.114 + // the element which has the accesskey. 1.115 + } else if (expected == "l") { 1.116 + ok(e.value == "test for legend", "(focus) unexpected element: " + e.value + 1.117 + " expected: " + "test for legend"); 1.118 + } else { 1.119 + ok(expected == e.accessKey, "(focus) unexpected element: " + e.accessKey + 1.120 + " expected: " + expected); 1.121 + } 1.122 + } 1.123 + 1.124 + function handleClick(e) { 1.125 + ok("accessKey" in e, "(click) accesskey property not found on element"); 1.126 + } 1.127 + 1.128 + function handleInvalid(e) { 1.129 + ok("accessKey" in e, "(invalid) accesskey property not found on element"); 1.130 + ok(false, "(invalid) accesskey should not have any effect on this element: " + 1.131 + e.localName); 1.132 + } 1.133 + 1.134 + function pressAccessKey(key) { 1.135 + var utils = SpecialPowers.DOMWindowUtils; 1.136 + utils.sendKeyEvent("keydown", key, key, modifier); 1.137 + utils.sendKeyEvent("keypress", key, key, modifier); 1.138 + utils.sendKeyEvent("keyup", key, key, modifier); 1.139 + } 1.140 + 1.141 + function testFocusableElements() { 1.142 + for (var code = "a".charCodeAt(0); code <= "y".charCodeAt(0); ++ code) { 1.143 + // XXX the "map" test is causing trouble, see bug 433089 1.144 + if (code == "b".charCodeAt(0)) 1.145 + continue; 1.146 + pressAccessKey(code); 1.147 + } 1.148 + ok(focusArray.length == 0, "(focus) unhandled elements remaining: " + focusArray.join(",")); 1.149 + } 1.150 + 1.151 + function createUnfocusableElement(elem, accesskey) { 1.152 + ok("tag" in elem, "invalid object passed to createUnfocusableElement: " + elem.toString()); 1.153 + var e = document.createElement(elem.tag); 1.154 + if ("content" in elem) { 1.155 + e.innerHTML = elem.content; 1.156 + } 1.157 + if ("attribs" in elem) { 1.158 + for (var attr in elem.attribs) { 1.159 + e.setAttribute(attr, elem.attribs[attr]); 1.160 + } 1.161 + } 1.162 + e.setAttribute("accesskey", accesskey); 1.163 + e.setAttribute("onclick", "handleClick(event.target); event.preventDefault();"); 1.164 + e.setAttribute("onfocus", "handleInvalid(event.target);"); 1.165 + var parent = null; 1.166 + var elementToInsert = null; 1.167 + if ("parent" in elem) { 1.168 + parent = document.getElementById(elem.parent); 1.169 + elementToInsert = e; 1.170 + } else { 1.171 + parent = document.getElementById("tbody"); 1.172 + elementToInsert = document.createElement("tr"); 1.173 + var td = document.createElement("td"); 1.174 + td.textContent = elem.tag; 1.175 + elementToInsert.appendChild(td); 1.176 + td = document.createElement("td"); 1.177 + td.appendChild(e); 1.178 + elementToInsert.appendChild(td); 1.179 + } 1.180 + ok(parent != null, "parent element not specified for element: " + elem.tag); 1.181 + ok(elementToInsert != null, "elementToInsert not specified for element: " + elem.tag); 1.182 + elementToInsert.setAttribute("id", unfocusableElementId); 1.183 + if ("where" in elem) { 1.184 + if (elem.where == "first") { 1.185 + parent.insertBefore(elementToInsert, parent.firstChild); 1.186 + } else { 1.187 + ok(false, "invalid where value specified for element: " + elem.tag); 1.188 + } 1.189 + } else { 1.190 + parent.appendChild(elementToInsert); 1.191 + } 1.192 + } 1.193 + 1.194 + function destroyUnfocusableElement() { 1.195 + var el = document.getElementById(unfocusableElementId); 1.196 + ok(el != null, "unfocusable element not found"); 1.197 + el.parentNode.removeChild(el); 1.198 + ok(document.getElementById(unfocusableElementId) == null, "unfocusable element not properly removed"); 1.199 + } 1.200 + 1.201 + function testUnfocusableElements() { 1.202 + var i, e; 1.203 + for (i = 0; i < unfocusableTags.length; ++ i) { 1.204 + createUnfocusableElement(unfocusableTags[i], "z"); 1.205 + pressAccessKey("z".charCodeAt(0)); 1.206 + destroyUnfocusableElement(); 1.207 + } 1.208 + for (i = 0; i < invalidElements.length; ++ i) { 1.209 + e = document.getElementById(invalidElements[i]); 1.210 + ok(e != null, "element with ID " + invalidElements[i] + " not found"); 1.211 + e.setAttribute("accesskey", "z"); 1.212 + e.setAttribute("onclick", "handleClick(event.target); event.preventDefault();"); 1.213 + e.setAttribute("onfocus", "handleInvalid(event.target);"); 1.214 + pressAccessKey("z".charCodeAt(0)); 1.215 + e.removeAttribute("accesskey"); 1.216 + e.removeAttribute("onclick"); 1.217 + e.removeAttribute("onfocus"); 1.218 + } 1.219 + } 1.220 + 1.221 + function start() { 1.222 + testFocusableElements(); 1.223 + testUnfocusableElements(); 1.224 + setOrRestoreContentAccess(0); 1.225 + SimpleTest.finish(); 1.226 + } 1.227 + 1.228 + function doTest() { 1.229 + setOrRestoreContentAccess(5); 1.230 + setTimeout(start, 100); 1.231 + } 1.232 + 1.233 + SimpleTest.waitForExplicitFinish(); 1.234 + addLoadEvent(doTest); 1.235 + 1.236 +</script> 1.237 +</pre> 1.238 + <table id="table"> 1.239 + <thead id="thead"> 1.240 + <tr id="tr"><th id="th">Test header</th><th></th></tr> 1.241 + </thead> 1.242 + <tfoot id="tfoot"> 1.243 + <tr><td id="td">Test footer</td><td></td></tr> 1.244 + </tfoot> 1.245 + <tbody id="tbody"> 1.246 + <colgroup id="colgroup"> 1.247 + <col id="col"></col> 1.248 + <col></col> 1.249 + </colgroup> 1.250 + <tr> 1.251 + <td>a</td><td><a href="#" onclick="handleClick(event.target); return false;" accesskey="a" onfocus="handleFocus(event.target);">test link"</a></td> 1.252 + </tr> 1.253 +<!-- the "map" test is causing trouble, see bug 433089 1.254 + <tr> 1.255 + <td>area</td><td><img src="about:logo" width="300" height="236" usemap="#map"> 1.256 + <map id="map" name="map"><area shape="rect" coords="0,0,82,126" href="#" 1.257 + onclick="handleClick(event.target); return false;" accesskey="b"></map> 1.258 + </td> 1.259 + </tr> 1.260 +--> 1.261 + <tr> 1.262 + <td>button</td><td><button onclick="handleClick(event.target);" accesskey="c" onfocus="handleFocus(event.target);">test button"</button></td> 1.263 + </tr> 1.264 + <tr> 1.265 + <td>input type="text"</td><td><input type="text" value="" onclick="handleClick(event.target);" onfocus="handleFocus(event.target);" accesskey="d"></td> 1.266 + </tr> 1.267 + <tr> 1.268 + <td>input type="button"</td><td><input type="button" value="type='button'" onclick="handleClick(event.target);" onfocus="handleFocus(event.target);" accesskey="e"></td> 1.269 + </tr> 1.270 + <tr> 1.271 + <td>input type="checkbox"</td><td><input type="checkbox" onclick="handleClick(event.target);" onfocus="handleFocus(event.target)" accesskey="f"></td> 1.272 + </tr> 1.273 + <tr> 1.274 + <td>input type="radio"</td><td><input type="radio" name="radio" onclick="handleClick(event.target);" onfocus="handleFocus(event.target);" accesskey="g"></td> 1.275 + </tr> 1.276 + <tr> 1.277 + <td>input type="password"</td><td><input type="password" onclick="handleClick(event.target);" onfocus="handleFocus(event.target);" accesskey="h"></td> 1.278 + </tr> 1.279 + <tr> 1.280 + <td>input type="submit"</td><td><input type="submit" value="type='submit'" onclick="handleClick(event.target); return false;" 1.281 + onfocus="handleFocus(event.target);" accesskey="i"></td> 1.282 + </tr> 1.283 + <tr> 1.284 + <td>input type="reset"</td><td><input type="submit" value="type='reset'" onclick="handleClick(event.target);" 1.285 + onfocus="handleFocus(event.target);" accesskey="j"></td> 1.286 + </tr> 1.287 + <tr> 1.288 + <td>label</td><td><label accesskey="k" onclick="handleClick(event.target);" onfocus="handleInvalid(event.target);">test label 1.289 + <input type="text" value="test for label" onfocus="handleFocus(event.target);" onclick="handleClick(event.target);"></label></td> 1.290 + </tr> 1.291 + <tr> 1.292 + <td>legend</td><td><fieldset><legend accesskey="l">test legend</legend> 1.293 + <input type="text" value="test for legend" onfocus="handleFocus(event.target);" onclick="handleClick(event.target);" ></fieldset></td> 1.294 + </tr> 1.295 + <tr> 1.296 + <td>textarea</td><td><textarea onfocus="handleFocus(event.target);" onclick="handleClick(event.target);" accesskey="m">test text</textarea></td> 1.297 + </tr> 1.298 + <tr> 1.299 + <td>label (label invisible)</td><td><label for="txt1" accesskey="n" style="display:none" 1.300 + onclick="handleClick(event.target);" onfocus="handleInvalid(event.target);">test label</label> 1.301 + <input type="text" id="txt1" value="test for label" onclick="handleClick(event.target);" onfocus="handleFocus(event.target);"></td> 1.302 + </tr> 1.303 + <tr> 1.304 + <td>label (control invisible)</td><td><label for="txt2" accesskey="o" 1.305 + onclick="handleClick(event.target);" onfocus="handleInvalid(event.target);">test label</label> 1.306 + <input type="text" id="txt2" value="test for label" onclick="handleClick(event.target);" 1.307 + onfocus="handleInvalid(event.target);" style="display:none"></td> 1.308 + </tr> 1.309 + <tr> 1.310 + <td>select</td> 1.311 + <td> 1.312 + <select onclick="handleClick(event.target);" onfocus="handleFocus(event.target)" accesskey="p"><option>option</option></select> 1.313 + </td> 1.314 + </tr> 1.315 + <tr> 1.316 + <td>object</td> 1.317 + <td> 1.318 + <object onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="q">an object</object> 1.319 + </td> 1.320 + </tr> 1.321 + <tr> 1.322 + <td>a without href</td> 1.323 + <td> 1.324 + <a onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="r">an object</object> 1.325 + </td> 1.326 + </tr> 1.327 + <tr> 1.328 + <td>disabled button</td> 1.329 + <td> 1.330 + <button disabled="" onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="s">disabled</button> 1.331 + </td> 1.332 + </tr> 1.333 + <tr> 1.334 + <td>disabled input</td> 1.335 + <td> 1.336 + <input disabled="" onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="t"></input> 1.337 + </td> 1.338 + </tr> 1.339 + <tr> 1.340 + <td>hidden input</td> 1.341 + <td> 1.342 + <input type="hidden" onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="u">disabled</input> 1.343 + </td> 1.344 + </tr> 1.345 + <tr> 1.346 + <td>disabled select</td> 1.347 + <td> 1.348 + <select disabled onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="v"> 1.349 + <option>disabled</option> 1.350 + </select> 1.351 + </td> 1.352 + </tr> 1.353 + <tr> 1.354 + <td>disabled textarea</td> 1.355 + <td> 1.356 + <textarea disabled onclick="handleClick(event.target);" onfocus="handleInvalid(event.target)" accesskey="w">disabled</textarea> 1.357 + </td> 1.358 + </tr> 1.359 + <tr> 1.360 + <td>scrollable div(focusable)</td> 1.361 + <td> 1.362 + <div onclick="handleClick(event.target);" onfocus="handleFocus(event.target)" accesskey="x" style="height: 50px; overflow: auto;"> 1.363 + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy 1.364 + 1.365 + dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the 1.366 + 1.367 + lazy dog. The quick brown fox jumps over the lazy dog. 1.368 + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy 1.369 + 1.370 + dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the 1.371 + 1.372 + lazy dog. The quick brown fox jumps over the lazy dog. 1.373 + The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy 1.374 + 1.375 + dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the 1.376 + 1.377 + lazy dog. The quick brown fox jumps over the lazy dog. 1.378 + </div> 1.379 + </td> 1.380 + </tr> 1.381 + <tr> 1.382 + <td>contenteditable div(focusable)</td> 1.383 + <td> 1.384 + <div onclick="handleClick(event.target);" onfocus="handleFocus(event.target)" accesskey="y" contenteditable="true"> 1.385 + Test text..... 1.386 + </div> 1.387 + </td> 1.388 + </tr> 1.389 + </tbody> 1.390 + </table> 1.391 + <dl id="dl"></dl> 1.392 + <ul id="ul"></ul> 1.393 + <ol id="ol"></ol> 1.394 + <select id="select"></select> 1.395 +</body> 1.396 +</html>