summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-job-queue/promise-job-entry-different-function-realm.html
blob: 71f03a4dcf80e9705dcf4d0bb7f22fce1da96331 (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
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
107
108
109
110
111
112
<!DOCTYPE html>
<meta charset="utf-8">
<title>Entry settings object for promise jobs when the function realm is different from the test realm</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- https://github.com/whatwg/html/pull/5212 -->
<!-- https://github.com/whatwg/html/issues/1426 -->

<!-- This is what would normally be considered the entry page. However, we use functions from the
     resources/function/function.html realm. So window.open() should resolve relative to that realm
     inside promise jobs. -->

<iframe src="resources/promise-job-entry-incumbent.html"></iframe>
<iframe src="resources/function/function.html" id="function-frame"></iframe>

<script>
setup({ explicit_done: true });

const relativeURL = "resources/window-to-open.html";
const expectedURL = (new URL(relativeURL, document.querySelector("#function-frame").src)).href;

const incumbentWindow = frames[0];
const functionWindow = frames[1];
const FunctionFromAnotherWindow = frames[1].Function;

window.onload = () => {
  async_test(t => {
    const func = FunctionFromAnotherWindow(`
      const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0];

      const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL);
      w.onload = t.step_func_done(() => {
        t.add_cleanup(() => w.close());
        assert_equals(w.location.href, expectedURL);
      });
    `);

    Promise.resolve([incumbentWindow, relativeURL, t, assert_equals, expectedURL]).then(func);
  }, "Fulfillment handler on fulfilled promise");

  async_test(t => {
    const func = FunctionFromAnotherWindow(`
      const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0];

      const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL);
      w.onload = t.step_func_done(() => {
        t.add_cleanup(() => w.close());
        assert_equals(w.location.href, expectedURL);
      });
    `);

    Promise.reject([incumbentWindow, relativeURL, t, assert_equals, expectedURL]).catch(func);
  }, "Rejection handler on rejected promise");

  async_test(t => {
    let resolve;
    const p = new Promise(r => { resolve = r; });

    const func = FunctionFromAnotherWindow(`
      const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0];

      const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL);
      w.onload = t.step_func_done(() => {
        t.add_cleanup(() => w.close());
        assert_equals(w.location.href, expectedURL);
      });
    `);

    p.then(func);
    t.step_timeout(() => resolve([incumbentWindow, relativeURL, t, assert_equals, expectedURL]), 0);
  }, "Fulfillment handler on pending-then-fulfilled promise");

  async_test(t => {
    let reject;
    const p = new Promise((_, r) => { reject = r; });

    const func = FunctionFromAnotherWindow(`
      const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0];

      const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL);
      w.onload = t.step_func_done(() => {
        t.add_cleanup(() => w.close());
        assert_equals(w.location.href, expectedURL);
      });
    `);

    p.catch(func);
    t.step_timeout(() => reject([incumbentWindow, relativeURL, t, assert_equals, expectedURL]), 0);
  }, "Rejection handler on pending-then-rejected promise");

  async_test(t => {
    t.add_cleanup(() => { delete frames[1].args; });
    frames[1].args = [incumbentWindow, relativeURL, t, assert_equals, expectedURL];

    const func = FunctionFromAnotherWindow(`
      const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = window.args;

      const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL);
      w.onload = t.step_func_done(() => {
        t.add_cleanup(() => w.close());
        assert_equals(w.location.href, expectedURL);
      });
    `);

    const thenable = { then: func };

    Promise.resolve(thenable);
  }, "Thenable resolution");

  done();
};
</script>