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
|
<!doctype html>
<meta charset=utf-8>
<title>Node.appendChild: inserting a script and a style where the script modifies the style</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<script>
// <script> & <style> element tests.
test(() => {
window.happened = [];
window.style = document.createElement("style");
let styleSheet = null;
style.appendChild(new Text("body {}"));
const script = document.createElement("script");
script.textContent = `
styleSheet = style.sheet;
happened.push(style.sheet ? "sheet" : null);
style.appendChild(new Text("body {}"));
happened.push(style.sheet?.cssRules.length);
`;
const div = document.createElement("div");
div.appendChild(script);
div.appendChild(style);
assert_array_equals(happened, []);
document.body.appendChild(div);
assert_array_equals(happened, ["sheet", 2]);
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
}, "An earlier-inserted <script> synchronously observes a later-inserted " +
"<style> (via a div) being applied");
test(() => {
window.happened = [];
window.style = document.createElement("style");
let styleSheet = null;
style.appendChild(new Text("body {}"));
const script = document.createElement("script");
script.textContent = `
styleSheet = style.sheet;
happened.push(style.sheet ? "sheet" : null);
style.appendChild(new Text("body {}"));
happened.push(style.sheet?.cssRules.length);
`;
const df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(style);
assert_array_equals(happened, []);
document.body.appendChild(df);
assert_array_equals(happened, ["sheet", 2]);
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
}, "An earlier-inserted <script> synchronously observes a later-inserted " +
"<style> (via a DocumentFragment) being applied");
// <script> & <link rel=stylesheet> element tests.
test(() => {
window.happened = [];
window.link = document.createElement("link");
link.rel = "stylesheet";
link.href = "data:text/css,";
const script = document.createElement("script");
script.textContent = `
happened.push(link.sheet ? "sheet" : null);
`;
const df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(link);
assert_array_equals(happened, []);
document.body.appendChild(df);
assert_array_equals(happened, ["sheet"]);
}, "Earlier-inserted <script> (via a DocumentFragment) synchronously " +
"observes a later-inserted <link rel=stylesheet>'s CSSStyleSheet creation");
test(() => {
window.happened = [];
window.link = document.createElement("link");
link.rel = "stylesheet";
link.href = "data:text/css,";
const script = document.createElement("script");
script.textContent = `
happened.push(link.sheet ? "sheet" : null);
`;
const div = document.createElement("div");
div.appendChild(script);
div.appendChild(link);
assert_array_equals(happened, []);
document.body.appendChild(div);
assert_array_equals(happened, ["sheet"]);
}, "Earlier-inserted <script> (via a div) synchronously observes a " +
"later-inserted <link rel=stylesheet>'s CSSStyleSheet creation");
test(() => {
window.happened = [];
window.link = document.createElement("link");
link.rel = "stylesheet";
link.href = "data:text/css,";
const script = document.createElement("script");
script.textContent = `
happened.push(link.sheet ? "sheet" : null);
`;
assert_array_equals(happened, []);
document.body.append(script, link);
assert_array_equals(happened, ["sheet"]);
}, "Earlier-inserted <script> (via a append()) synchronously observes a " +
"later-inserted <link rel=stylesheet>'s CSSStyleSheet creation");
</script>
|