test_xul_shadowdom_accesskey.xhtml (2010B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 4 5 <window title="XUL ShadowDOM accesskey" 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 7 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 8 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 9 <body xmlns="http://www.w3.org/1999/xhtml"> 10 <a target="_blank" rel="opener" 11 href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037709" 12 title="XUL ShadowDOM accesskey"> 13 Mozilla Bug 1037709 14 </a> 15 <div id="container" style="position: relative"></div> 16 </body> 17 <!-- Tests code --> 18 <script type="application/javascript"> 19 <![CDATA[ 20 21 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; 22 const container = document.getElementById("container"); 23 24 function pressAccessKey(accessKey){ 25 synthesizeKey(accessKey, navigator.platform.includes("Mac") ? { altKey: true, ctrlKey: true } 26 : { altKey: true, shiftKey: true }); 27 } 28 29 function testAccesskeyInShadowTree(mode) { 30 add_task(async () => { 31 const host = document.createXULElement("div"); 32 container.appendChild(host); 33 34 const shadowRoot = host.attachShadow({mode}) 35 const button = document.createXULElement("button"); 36 button.innerText = "Click Me"; 37 button.setAttribute("accesskey", "g"); 38 shadowRoot.appendChild(button); 39 40 // Trigger frame construction which is constructed lazily on XUL Element. 41 button.getBoundingClientRect(); 42 43 let isClickFired = false; 44 button.addEventListener("click", function(e) { 45 isClickFired = true; 46 }, { once: true }); 47 48 pressAccessKey("g"); 49 ok(isClickFired, `button element with accesskey in the shadow tree of ${mode} mode`); 50 51 host.remove(); 52 }); 53 } 54 55 testAccesskeyInShadowTree("open"); 56 testAccesskeyInShadowTree("closed"); 57 58 ]]> 59 </script> 60 </window>