focus-event-after-iframe-gets-focus.html (2062B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Test focus event after iframe gets focus</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <script> 7 function waitForEvent(target, event, checkFn) { 8 return new Promise(resolve => { 9 target.addEventListener(event, e => { 10 if (checkFn && !checkFn(e)) { 11 return; 12 } 13 resolve(); 14 }, { once: true }); 15 }); 16 } 17 18 function start(w) { 19 w.postMessage("start", "*"); 20 } 21 22 function focusIframe(w) { 23 w.postMessage("focus", "*"); 24 } 25 26 // This will send message to outer frame and also inner frame to ask them 27 // send the log they collect back, the logs of outer and inner will be 28 // concatenated. 29 async function getLog(w) { 30 let log = ""; 31 step_timeout(function() { 32 w.postMessage("getlog", "*"); 33 }, 0); 34 await waitForEvent(window, "message", (e) => { 35 log = e.data; 36 return true; 37 }); 38 return log; 39 } 40 41 async function runTest(t, url, expectResult) { 42 let w = window.open(url); 43 t.add_cleanup(() => { w.close(); }); 44 await waitForEvent(window, "message", e => e.data === "ready"); 45 start(w); 46 focusIframe(w); 47 assert_equals(await getLog(w), expectResult); 48 } 49 50 promise_test(async t => { 51 await runTest(t, "support/focus-event-after-same-site-iframe-gets-focus-outer.html", 52 "outerlog:windowblur,innerlog:willfocuswindow,windowfocus,didfocuswindow,"); 53 }, "Check focus event after same site iframe gets focus"); 54 55 promise_test(async t => { 56 await runTest(t, "support/focus-event-after-different-site-iframe-gets-focus-outer.sub.html", 57 "outerlog:windowblur,innerlog:willfocuswindow,windowfocus,didfocuswindow,"); 58 }, "Check focus event after different site iframe gets focus"); 59 60 promise_test(async t => { 61 await runTest(t, "support/focus-event-after-innermost-different-site-iframe-gets-focus-outer.sub.html", 62 "outerlog:windowblur,middlelog:innerlog:willfocuswindow,windowfocus,didfocuswindow,"); 63 }, "Check focus event after innermost different site iframe gets focus"); 64 65 </script>