test_accesskey.xhtml (2335B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=1699284 6 --> 7 <window title="Mozilla Bug 1699284" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 11 <body> 12 <label id="label1" accesskey="a">Label 1</label><button id="button1" accesskey="a">Button 1</button> 13 <label id="label2" accesskey="a" tabindex="0">Label 2</label><button id="button2">Button 2</button> 14 <label id="label3">Label 3</label><button id="button3" accesskey="a">Button 3</button> 15 <label id="label4" accesskey="a" control="button4">Label 4</label><button id="button4" disabled="true">Button 4</button> 16 <label id="label5" accesskey="a" control="button5">Label 5</label><button id="button5">Button 5</button> 17 <!-- Tests code --> 18 <script type="application/javascript"> 19 <![CDATA[ 20 21 /** Test for Bug 1699284 */ 22 23 function PerformAccessKey(aKey) { 24 synthesizeKey(aKey, navigator.platform.includes("Mac") ? { altKey: true, ctrlKey: true } 25 : { altKey: true, shiftKey: true }); 26 }; 27 28 add_task(async function test_accesskey() { 29 let [label1, label2, label3, label4, label5] = document.querySelectorAll("label"); 30 let [button1, button2, button3, button4, button5] = document.querySelectorAll("button"); 31 32 [ 33 label1, label2, label3, label4, label5, button1, button2, button3, button4, button5 34 ].forEach(function(ele) { 35 ele.addEventListener("click", function(e) { 36 ok(false, `${e.target.id} should not receive click event`); 37 }); 38 }); 39 40 PerformAccessKey("a"); 41 is(document.activeElement.id, button1.id, `focus should move to ${button1.id}`); 42 43 PerformAccessKey("a"); 44 is(document.activeElement.id, button3.id, `focus should move to ${button3.id}`); 45 46 PerformAccessKey("a"); 47 is(document.activeElement.id, button5.id, `focus should move to ${button5.id}`); 48 49 // Cycle back to first element 50 PerformAccessKey("a"); 51 is(document.activeElement.id, button1.id, `focus should move to ${button1.id}`); 52 }); 53 54 ]]> 55 </script> 56 </body> 57 </window>