focus-method-delegatesFocus-nested-browsing-context.html (1417B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTML Test: focus() on shadow host within an iframe with delegatesFocus</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <body> 9 <script> 10 test(() => { 11 const iframe = document.createElement("iframe"); 12 document.body.appendChild(iframe); 13 iframe.addEventListener("load", () => { 14 iframe.contentDocument.body.innerHTML = 15 `<div id="host"></div>`; 16 const host = iframe.contentDocument.getElementById("host"); 17 const firstInput = iframe.contentDocument.createElement("input"); 18 const secondInput = iframe.contentDocument.createElement("input"); 19 20 host.attachShadow({mode: 'open', delegatesFocus: true}); 21 host.shadowRoot.appendChild(firstInput); 22 host.shadowRoot.appendChild(secondInput); 23 24 iframe.contentDocument.body.appendChild(host); 25 26 secondInput.focus(); 27 assert_equals(host.shadowRoot.activeElement, secondInput); 28 29 // host is a shadow-including-ancestor of secondInput, so 30 // the focus should remain secondInput. 31 host.focus(); 32 assert_equals(host.shadowRoot.activeElement, secondInput); 33 }); 34 }, "focus delegate step should not be run when the focus target is a shadow-including inclusive ancestor of the current focus."); 35 </script> 36 </body>