File: focus-event-after-switching-iframes.sub.html

package info (click to toggle)
firefox-esr 140.5.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,538,920 kB
  • sloc: cpp: 7,381,527; javascript: 6,388,905; ansic: 3,710,087; python: 1,393,776; xml: 628,165; asm: 426,916; java: 184,004; sh: 65,744; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (106 lines) | stat: -rw-r--r-- 3,800 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!doctype html>
<meta charset=utf-8>
<title>Test focus and blur event after switching focus from an iframe to another iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body></body>
<script>
function waitForBothIFramesLoaded() {
  let count = 0;
  return new Promise(resolve => {
    window.addEventListener("message", function handler(e) {
      if (e.data == "ready") {
        count += 1;
      }
      if (count == 2) {
        window.removeEventListener("message", handler);
        resolve();
      }
    });
  });
}

function waitForIframeFocus(w) {
  return new Promise(resolve => {
    window.addEventListener("message", function handler(e) {
      if (e.data == "focus" &&
          e.source == w) {
        window.removeEventListener("message", handler);
        resolve();
      }
    });
  });
}

function clickFocusIFrame(w) {
  w.postMessage("focus", "*");
}

// This will send message to the inner frame to ask it
// send the log they collect back.
async function getLog(w) {
  w.postMessage("getlog", "*");
  let log = await new Promise( r=> {
    window.addEventListener("message", function handler(e) {
      window.removeEventListener("message", handler);
      r(e.data);
    });
  });
  return log;
}

async function runTest(t, urlForFrame1, urlForFrame2) {
  const iframe1 = document.createElement("iframe");
  iframe1.src = urlForFrame1;
  const iframe2 = document.createElement("iframe");
  iframe2.src = urlForFrame2;
  document.body.appendChild(iframe1);
  document.body.appendChild(iframe2);

  t.add_cleanup(() => { iframe1.remove(); iframe2.remove() });

  await waitForBothIFramesLoaded();
  iframe1.focus();
  await waitForIframeFocus(iframe1.contentWindow);
  // Ask the iframe2 to be focused by using test_driver to simulate
  // a click.
  clickFocusIFrame(iframe2.contentWindow);
  await waitForIframeFocus(iframe2.contentWindow);
  assert_equals(await getLog(iframe1.contentWindow), 'innerlog:windowfocus,windowblur,');
}

// Both inner frames are different sites.
promise_test(async t => {
  await runTest(
    t,
    "http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-switching-iframes-inner.html",
    "http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-switching-iframes-inner.html");
}, "Check focus and blur events after switching from a different site iframe to a different site iframe");

// The one that expects to focus and blur is same site, the other one is different site.
promise_test(async t => {
  await runTest(
    t,
    "/focus/support/focus-event-after-switching-iframes-inner.html",
    "http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-switching-iframes-inner.html");
}, "Check focus and blur events after switching from a same site iframe to a different site iframe");

// Both inner frames are same site
promise_test(async t => {
  await runTest(
    t,
    "/focus/support/focus-event-after-switching-iframes-inner.html",
    "/focus/support/focus-event-after-switching-iframes-inner.html");
}, "Check focus and blur events after switching from a same site iframe to a same site iframe");

// The one that expects to focus and blur is different site, the other one is same site
promise_test(async t => {
  await runTest(
    t,
    "http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-switching-iframes-inner.html",
    "/focus/support/focus-event-after-switching-iframes-inner.html");
}, "Check focus and blur events after switching from a different site iframe to a same site iframe");
</script>