test_focus_shadow_dom_root.html (1591B)
1 <!doctype html> 2 <title>Test for bug 1544826</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <script src="/tests/SimpleTest/EventUtils.js"></script> 5 <div id="host"><a href="#" id="slotted">This is focusable too</a></div> 6 <script> 7 const host = document.getElementById("host"); 8 const shadow = host.attachShadow({ mode: "open" }); 9 shadow.innerHTML = ` 10 <a id="shadow-1" href="#">This is focusable</a> 11 <slot></slot> 12 <a id="shadow-2" href="#">So is this</a> 13 `; 14 document.documentElement.remove(); 15 document.appendChild(host); 16 17 SimpleTest.waitForExplicitFinish(); 18 SimpleTest.waitForFocus(async function() { 19 // Enable Full Keyboard Access emulation on Mac. 20 if (navigator.platform.indexOf("Mac") === 0) { 21 await SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]}); 22 } 23 24 is(document.documentElement, host, "Host is the document element"); 25 host.offsetTop; 26 synthesizeKey("KEY_Tab"); 27 is(shadow.activeElement.id, "shadow-1", "First link in Shadow DOM is focused"); 28 synthesizeKey("KEY_Tab"); 29 is(document.activeElement.id, "slotted", "Slotted link is focused"); 30 synthesizeKey("KEY_Tab"); 31 is(shadow.activeElement.id, "shadow-2", "Second link in Shadow DOM is focused"); 32 33 // Now backwards. 34 synthesizeKey("KEY_Tab", {shiftKey: true}); 35 is(document.activeElement.id, "slotted", "Backwards: Slotted link is focused"); 36 synthesizeKey("KEY_Tab", {shiftKey: true}); 37 is(shadow.activeElement.id, "shadow-1", "Backwards: First slotted link is focused"); 38 39 SimpleTest.finish(); 40 }); 41 </script>