no-cross-origin-autofocus.html (1487B)
1 <!DOCTYPE html> 2 <html> 3 <head> 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 <script src="/common/get-host-info.sub.js"></script> 9 </head> 10 <body> 11 <h1>Autofocus shouldn't work in cross-origin iframe.</h1> 12 <iframe id="child" width="200" height="100"></iframe> 13 14 <script> 15 let parent_loaded = false; 16 let child_loaded = false; 17 18 async_test(function(t) { 19 function pingChildIfBothFramesLoaded() { 20 if (parent_loaded && child_loaded) 21 frames[0].postMessage("report_focus_state", "*"); 22 } 23 24 window.addEventListener("load", t.step_func(event => { 25 parent_loaded = true; 26 pingChildIfBothFramesLoaded(); 27 })); 28 29 window.addEventListener("message", t.step_func(event => { 30 if (event.data == "child_loaded") { 31 child_loaded = true; 32 pingChildIfBothFramesLoaded(); 33 } else if (event.data == "child_is_focused") { 34 assert_unreached("The iframe shouldn't get focus"); 35 } else if (event.data == "child_is_not_focused") { 36 t.done(); 37 } 38 })); 39 document.getElementById("child").src = 40 get_host_info().HTTP_REMOTE_ORIGIN + "/html/interaction/focus/the-autofocus-attribute/resources/child-autofocus.html"; 41 }, "Autofocus shouldn't work in cross-origin iframe"); 42 </script> 43 </body> 44 </html>