Skip to content

Commit

Permalink
Test inserting a script and a style where the script modifies the style
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Feb 12, 2019
1 parent da9bd77 commit b177352
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions dom/nodes/Node-appendChild-script-and-style-from-fragment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<meta charset=utf-8>
<title>Node.appendChild: inserting a script and a style from a fragment</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-appendChild">
<link rel=help href="https://dom.spec.whatwg.org/#concept-node-insert">
<link rel=help href="https:/whatwg/dom/issues/575">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body></body>
<div id="log"></div>
<script>
var style = document.createElement("style");
var styleSheet = null;
style.appendChild(new Text("body {}"));

var script = document.createElement("script");
var scriptRan = false;
script.textContent = `
assert_equals(style.sheet, null, "style sheet is created");
style.appendChild(new Text("body {}"));
assert_not_equals(style.sheet, null, "style sheet is not created");
assert_equals(style.sheet.cssRules.length, 2, "style sheet does not have two rules");
styleSheet = style.sheet;
scriptRan = true;
`;

var df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(style);

assert_false(scriptRan, "script ran");
document.body.appendChild(df);
assert_true(scriptRan, "script did not run");
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
done();
</script>
38 changes: 38 additions & 0 deletions dom/nodes/Node-appendChild-script-and-style.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<meta charset=utf-8>
<title>Node.appendChild: inserting a script and a style where the script modifies the style</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-appendChild">
<link rel=help href="https://dom.spec.whatwg.org/#concept-node-insert">
<link rel=help href="https:/whatwg/dom/issues/575">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body></body>
<div id="log"></div>
<script>
var style = document.createElement("style");
var styleSheet = null;
style.appendChild(new Text("body {}"));

var script = document.createElement("script");
var scriptRan = false;
script.textContent = `
assert_equals(style.sheet, null, "style sheet is created");
style.appendChild(new Text("body {}"));
assert_not_equals(style.sheet, null, "style sheet is not created");
assert_equals(style.sheet.cssRules.length, 2, "style sheet does not have two rules");
styleSheet = style.sheet;
scriptRan = true;
`;

var div = document.createElement("div");
div.appendChild(script);
div.appendChild(style);

assert_false(scriptRan, "script ran");
document.body.appendChild(div);
assert_true(scriptRan, "script did not run");
assert_not_equals(style.sheet, styleSheet, "style sheet was created only once");
done();
</script>

0 comments on commit b177352

Please sign in to comment.