summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/javascript-url-task-queuing.html
blob: 1bb05bfb190d2e69576a13dcd8cbddd8f3903037 (plain)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>javascript: URL task queuing</title>
<link rel="help" href="https://github.com/whatwg/html/issues/3730">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
"use strict";

testIsAsync(() => {
  const iframe = document.createElement("iframe");
  document.body.append(iframe);
  iframe.contentWindow.location.href = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
}, `Navigating an iframe via location.href to a javascript: URL must queue a task`);

testIsAsync(() => {
  const iframe = document.createElement("iframe");
  iframe.src = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
  document.body.append(iframe);
}, `Navigating an iframe via src="" to a javascript: URL before insertion must queue a task`);

testIsAsync(() => {
  const iframe = document.createElement("iframe");
  document.body.append(iframe);
  iframe.src = "javascript:window.top.javascriptURLRan = true; window.top.resolveTestPromise();";
}, `Navigating an iframe via src="" to a javascript: URL after insertion must queue a task`);

testIsAsync(() => {
  const w = window.open();
  w.location.href = "javascript:window.opener.javascriptURLRan = true; window.opener.resolveTestPromise();";
}, `Navigating an opened window via location.href to a javascript: URL must queue a task`);

testIsAsync(() => {
  window.open("javascript:window.opener.javascriptURLRan = true; window.opener.resolveTestPromise();");
}, `Navigating an opened window as part of creation to a javascript: URL must queue a task`);

function testIsAsync(setupFunc, description) {
  promise_test(async t => {
    t.add_cleanup(() => {
      delete window.resolveTestPromise;
      delete window.javascriptURLRan;
    });

    const ranPromise = new Promise(resolve => {
      window.resolveTestPromise = resolve;
    });

    setupFunc();

    assert_equals(window.javascriptURLRan, undefined, "Must not run sync");

    // Ensure that we do actually run the code, though.
    await ranPromise;
  }, description);
}
</script>