Skip to content

Commit 5082ab6

Browse files
committed
Test inserting a script and a style where the script modifies the style
1 parent ba85065 commit 5082ab6

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>Node.appendChild: inserting a script and a style from a fragment</title>
4+
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-appendChild">
5+
<link rel=help href="https://dom.spec.whatwg.org/#concept-node-insert">
6+
<link rel=help href="https://github.com/whatwg/dom/issues/575">
7+
<script src=/resources/testharness.js></script>
8+
<script src=/resources/testharnessreport.js></script>
9+
<body></body>
10+
<div id="log"></div>
11+
<script>
12+
var style = document.createElement("style");
13+
var styleSheet = null;
14+
style.appendChild(new Text("body {}"));
15+
16+
var script = document.createElement("script");
17+
var scriptRan = false;
18+
script.textContent = `
19+
assert_equals(style.sheet, null, "style sheet is created");
20+
21+
style.appendChild(new Text("body {}"));
22+
assert_not_equals(style.sheet, null, "style sheet is not created");
23+
assert_equals(style.sheet.cssRules.length, 2, "style sheet does not have two rules");
24+
styleSheet = style.sheet;
25+
26+
scriptRan = true;
27+
`;
28+
29+
var df = document.createDocumentFragment();
30+
df.appendChild(script);
31+
df.appendChild(style);
32+
33+
assert_false(scriptRan, "script ran");
34+
document.body.appendChild(df);
35+
assert_true(scriptRan, "script did not run");
36+
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
37+
done();
38+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>Node.appendChild: inserting a script and a style where the script modifies the style</title>
4+
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-appendChild">
5+
<link rel=help href="https://dom.spec.whatwg.org/#concept-node-insert">
6+
<link rel=help href="https://github.com/whatwg/dom/issues/575">
7+
<script src=/resources/testharness.js></script>
8+
<script src=/resources/testharnessreport.js></script>
9+
<body></body>
10+
<div id="log"></div>
11+
<script>
12+
var style = document.createElement("style");
13+
var styleSheet = null;
14+
style.appendChild(new Text("body {}"));
15+
16+
var script = document.createElement("script");
17+
var scriptRan = false;
18+
script.textContent = `
19+
assert_equals(style.sheet, null, "style sheet is created");
20+
21+
style.appendChild(new Text("body {}"));
22+
assert_not_equals(style.sheet, null, "style sheet is not created");
23+
assert_equals(style.sheet.cssRules.length, 2, "style sheet does not have two rules");
24+
styleSheet = style.sheet;
25+
26+
scriptRan = true;
27+
`;
28+
29+
var div = document.createElement("div");
30+
div.appendChild(script);
31+
div.appendChild(style);
32+
33+
assert_false(scriptRan, "script ran");
34+
document.body.appendChild(div);
35+
assert_true(scriptRan, "script did not run");
36+
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
37+
done();
38+
</script>

0 commit comments

Comments
 (0)