Debian Codegraph @

testing/web-platform/mozilla/tests/focus/iframe-focus-event-after-iframe-gets-focus.html

raw
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 waitForMessage(target, checkFn) {
8 return new Promise(resolve => {
9 target.addEventListener("message", 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 // This will send message to outer frame and also inner frame to ask them
23 // send the log they collect back, the logs of outer and inner will be
24 // concatenated.
25 async function getLog(w) {
26 let log = "";
27 step_timeout(function() {
28 w.postMessage("getlog", "*");
29 }, 0);
30 await waitForMessage(window, (e) => {
31 log = e.data;
32 return true;
33 });
34 return log;
35 }
36
37 function runSingleTest(url, focusIframeFunction, expectedResult, description) {
38 promise_test(async t => {
39 let w = window.open(url);
40 t.add_cleanup(() => { w.close(); });
41 await waitForMessage(window, e => e.data === "ready");
42 start(w);
43 focusIframeFunction(w);
44 assert_equals(await getLog(w), expectedResult);
45 }, description);
46 }
47
48 function runTests(url, description) {
49 // Test calling iframe.focus();
50 runSingleTest(url, (w) => {
51 w.postMessage("iframefocus", "*");
52 }, "outerlog:windowblur,innerlog:windowfocus,",
53 description + " via calling iframe.focus()");
54
55 // Test calling iframe.contentWindow.focus();
56 runSingleTest(url, (w) => {
57 w.postMessage("iframecontentWindowfocus", "*");
58 }, "outerlog:windowblur,innerlog:windowfocus,",
59 description + " via calling iframe.contentWindow.focus()");
60
61 // Test calling window.focus() in iframe;
62 runSingleTest(url, (w) => {
63 w.postMessage("windowfocus", "*");
64 }, "outerlog:windowblur,innerlog:willfocuswindow,windowfocus,didfocuswindow,",
65 description + " via calling window.focus() in iframe");
66 }
67
68 // Test same site iframe
69 runTests("support/iframe-focus-event-after-same-site-iframe-gets-focus-outer.html",
70 "Check iframe focus event after same site iframe gets focus");
71
72 // Test different site iframe
73 runTests("support/iframe-focus-event-after-different-site-iframe-gets-focus-outer.sub.html",
74 "Check iframe focus event after different site iframe gets focus");
75 </script>