forked from web-platform-tests/wpt
/
moving-between-documents.html
138 lines (110 loc) · 4.53 KB
/
moving-between-documents.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<meta charset="utf-8">
<title>Moving script elements between documents</title>
<link rel="author" href="mailto:d@domenic.me" title="Domenic Denicola">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!-- Background:
- https://www.w3.org/Bugs/Public/show_bug.cgi?id=11323
- https://github.com/whatwg/html/issues/2137
- https://github.com/whatwg/html/issues/2469
- https://github.com/whatwg/html/pull/2673
-->
<body>
<script>
"use strict";
window.didExecute = false;
async_test(t => {
t.add_cleanup(() => {
window.didExecute = false;
});
const iframe = document.createElement("iframe");
iframe.onload = t.step_func_done(() => {
iframe.contentWindow.didExecute = false;
iframe.contentDocument.write("<streaming-element>");
document.body.appendChild(iframe.contentDocument.querySelector("streaming-element"));
iframe.contentDocument.write(`<script id="s1">window.didExecute = true;<` + "/script>");
iframe.contentDocument.write("</streaming-element>");
const s = document.querySelector("#s1");
s.onload = t.unreached_func("onload");
s.onerror = t.unreached_func("onerror");
iframe.contentDocument.close();
assert_false(window.didExecute, "The script must not have executed in this window");
assert_equals(iframe.contentWindow.didExecute, undefined,
"The script must not have executed in the iframe window");
});
document.body.appendChild(iframe);
}, "Moving to another document during parsing, inline script");
async_test(t => {
t.add_cleanup(() => {
window.didExecute = false;
});
const iframe = document.createElement("iframe");
iframe.onload = t.step_func(() => {
iframe.contentWindow.didExecute = false;
iframe.contentDocument.write("<streaming-element>");
document.body.appendChild(iframe.contentDocument.querySelector("streaming-element"));
iframe.contentDocument.write(`<script id="s2" src="resources/flag-setter.js"><` + "/script>");
iframe.contentDocument.write("</streaming-element>");
const s = document.querySelector("#s2");
s.onload = t.unreached_func("onload");
s.onerror = t.unreached_func("onerror");
iframe.contentDocument.close();
t.step_timeout(() => {
assert_false(window.didExecute, "The script must not have executed in this window");
assert_equals(iframe.contentWindow.didExecute, undefined,
"The script must not have executed in the iframe window");
t.done();
}, 3000);
});
document.body.appendChild(iframe);
}, "Moving to another document during parsing, external script");
async_test(t => {
t.add_cleanup(() => {
window.didExecute = false;
});
const iframe = document.createElement("iframe");
iframe.onload = t.step_func(() => {
const s = document.createElement("script");
s.src = "resources/slow-flag-setter.py";
s.onload = t.unreached_func("onload");
s.onerror = t.unreached_func("onerror");
// Start the fetch
document.body.appendChild(s);
// Need to delay since the "prepare a script" algorithm also contains related checks; we want to
// test the "execute a script block" algorithm for when the fetch comes back.
t.step_timeout(() => {
iframe.contentDocument.body.appendChild(s);
}, 0);
t.step_timeout(() => {
assert_false(window.didExecute, "The script must not have executed in this window");
assert_equals(iframe.contentWindow.didExecute, undefined,
"The script must not have executed in the iframe window");
t.done();
}, 3000);
});
document.body.appendChild(iframe);
}, "Moving to another Window's document during fetching");
async_test(t => {
t.add_cleanup(() => {
window.didExecute = false;
});
const s = document.createElement("script");
s.src = "resources/slow-flag-setter.py";
s.onload = t.unreached_func("onload");
s.onerror = t.unreached_func("onerror");
// Start the fetch
document.body.appendChild(s);
// Need to delay since the "prepare a script" algorithm also contains related checks; we want to
// test the "execute a script block" algorithm for when the fetch comes back.
t.step_timeout(() => {
const doc2 = document.implementation.createHTMLDocument("title");
doc2.body.appendChild(s);
}, 0);
t.step_timeout(() => {
assert_false(window.didExecute, "The script must not have executed in this window");
t.done();
}, 3000);
}, "Moving to a document where scripting is disabled during fetching");
</script>