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
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Node.appendChild: inserting script and iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<script>
const kScriptContent = `
state = iframe.contentWindow ? "iframe with content window" : "contentWindow is null";
`;
// This test ensures that a later-inserted script can observe an
// earlier-inserted iframe's contentWindow.
test(t => {
window.state = "script not run yet";
window.iframe = document.createElement("iframe");
t.add_cleanup(() => window.iframe.remove());
const script = document.createElement("script");
script.textContent = kScriptContent;
const div = document.createElement("div");
div.appendChild(iframe);
div.appendChild(script);
assert_equals(state, "script not run yet");
document.body.appendChild(div);
assert_equals(state, "iframe with content window");
}, "Script inserted after an iframe in the same appendChild() call can " +
"observe the iframe's non-null contentWindow");
// The below tests assert that an earlier-inserted script does not observe a
// later-inserted iframe's contentWindow.
test(t => {
window.state = "script not run yet";
window.iframe = document.createElement("iframe");
t.add_cleanup(() => window.iframe.remove());
const script = document.createElement("script");
script.textContent = kScriptContent;
const div = document.createElement("div");
div.appendChild(script);
div.appendChild(iframe);
assert_equals(state, "script not run yet");
document.body.appendChild(div);
assert_equals(state, "contentWindow is null");
}, "A script inserted atomically before an iframe (using a div) does not " +
"observe the iframe's contentWindow, since the 'script running' and " +
"'iframe setup' both happen in order, after DOM insertion completes");
test(t => {
window.state = "script not run yet";
window.iframe = document.createElement("iframe");
t.add_cleanup(() => window.iframe.remove());
const script = document.createElement("script");
script.textContent = kScriptContent;
const df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(iframe);
assert_equals(state, "script not run yet");
document.body.appendChild(df);
assert_equals(state, "contentWindow is null");
}, "A script inserted atomically before an iframe (using a DocumentFragment) " +
"does not observe the iframe's contentWindow, since the 'script running' " +
"and 'iframe setup' both happen in order, after DOM insertion completes");
test(t => {
window.state = "script not run yet";
window.iframe = document.createElement("iframe");
t.add_cleanup(() => window.iframe.remove());
const script = document.createElement("script");
script.textContent = kScriptContent;
assert_equals(state, "script not run yet");
document.body.append(script, iframe);
assert_equals(state, "contentWindow is null");
}, "A script inserted atomically before an iframe (using a append() with " +
"multiple arguments) does not observe the iframe's contentWindow, since " +
"the 'script running' and 'iframe setup' both happen in order, after DOM " +
"insertion completes");
</script>
|