| Edgar Chen | 351e1ce | 2020-12-21 23:32:44 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>iframe activeElement after focusing out iframe</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 focusTopLevel(w) { |
| 19 | w.postMessage("focus", "*"); |
| 20 | } |
| 21 | |
| 22 | async function getLog(w) { |
| 23 | let log = ""; |
| 24 | step_timeout(function() { |
| 25 | w.postMessage("getlog", "*"); |
| 26 | }, 0); |
| 27 | await waitForEvent(window, "message", (e) => { |
| 28 | log = e.data; |
| 29 | return true; |
| 30 | }); |
| 31 | return log; |
| 32 | } |
| 33 | |
| 34 | async function runTest(t, url) { |
| 35 | let w = window.open(url); |
| 36 | t.add_cleanup(() => { w.close(); }); |
| 37 | await waitForEvent(window, "message", e => e.data === "ready"); |
| 38 | focusTopLevel(w); |
| 39 | assert_equals(await getLog(w), 'outerlog:willfocusinput,windowfocus,didfocusinput,innerlog:willfocusinput,windowfocus,didfocusinput,activeElement:INPUT,windowblur,activeElement:BODY,'); |
| 40 | } |
| 41 | |
| 42 | promise_test(async t => { |
| 43 | await runTest(t, "support/iframe-activeelement-after-focusing-out-different-site-iframes-outer.sub.html"); |
| 44 | }, "Check iframe activeElement after focusing out different site iframe"); |
| 45 | |
| 46 | promise_test(async t => { |
| 47 | await runTest(t, "support/iframe-activeelement-after-focusing-out-same-site-iframes-outer.html"); |
| 48 | }, "Check iframe activeElement after focusing out same site iframe"); |
| 49 | |
| 50 | </script> |