This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
insert_adjacent_html.html
92 lines (79 loc) · 3.62 KB
/
insert_adjacent_html.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
<!DOCTYPE HTML>
<html>
<head>
<title>insertAdjacentHTML</title>
<script src="support/testharness.js"></script>
<script src="support/testharnessreport.js"></script>
<script src="insert_adjacent_html.js"></script>
</head>
<body>
<p id="display"></p><div id="content" style="display: none"></div><div id="content2" style="display: none"></div>
<script>
var script_ran = false;
function testPositions(node) {
test(function() {
script_ran = false;
node.insertAdjacentHTML("beforeBegin", "\u003Cscript>script_ran = true;\u003C/script><i></i>");
assert_equals(node.previousSibling.localName, "i", "Should have had <i> as previous sibling");
assert_equals(node.previousSibling.previousSibling.localName, "script", "Should have had <script> as second previous child");
assert_false(script_ran, "script should not have run");
}, "beforeBegin " + node)
test(function() {
script_ran = false;
node.insertAdjacentHTML("Afterbegin", "<b></b>\u003Cscript>script_ran = true;\u003C/script>");
assert_equals(node.firstChild.localName, "b", "Should have had <b> as first child");
assert_equals(node.firstChild.nextSibling.localName, "script", "Should have had <script> as second child");
assert_false(script_ran, "script should not have run");
}, "Afterbegin " + node);
test(function() {
script_ran = false;
node.insertAdjacentHTML("BeforeEnd", "\u003Cscript>script_ran = true;\u003C/script><u></u>");
assert_equals(node.lastChild.localName, "u", "Should have had <u> as last child");
assert_equals(node.lastChild.previousSibling.localName, "script", "Should have had <script> as penultimate child");
assert_false(script_ran, "script should not have run");
}, "BeforeEnd " + node)
test(function() {
script_ran = false;
node.insertAdjacentHTML("afterend", "<a></a>\u003Cscript>script_ran = true;\u003C/script>");
assert_equals(node.nextSibling.localName, "a", "Should have had <a> as next sibling");
assert_equals(node.nextSibling.nextSibling.localName, "script", "Should have had <script> as second next sibling");
assert_false(script_ran, "script should not have run");
}, "afterend " + node)
}
var content = document.getElementById("content");
testPositions(content); // without next sibling
testPositions(content); // test again when there's next sibling
test(function() {
assert_throws("SYNTAX_ERR", function() {content.insertAdjacentHTML("bar", "foo")});
assert_throws("SYNTAX_ERR", function() {content.insertAdjacentHTML("beforebegİn", "foo")});
});
var parent = document.createElement("div");
var child = document.createElement("div");
testThrowingNoParent(child, "null");
testThrowingNoParent(document.documentElement, "a document");
test(function() {
child.insertAdjacentHTML("afterBegin", "foo");
child.insertAdjacentHTML("beforeend", "bar");
assert_equals(child.textContent, "foobar");
parent.appendChild(child);
});
testPositions(child); // node not in tree but has parent
test(function() {
script_ran = false;
content.appendChild(parent); // must not run scripts
assert_false(script_ran, "script should not have run");
});
var content2 = document.getElementById("content2");
testPositions(content2); // without next sibling
testPositions(content2); // test again when there's next sibling
// HTML only
test(function() {
document.body.insertAdjacentHTML("afterend", "<p>");
document.head.insertAdjacentHTML("beforebegin", "<p>");
assert_equals(document.getElementsByTagName("head").length, 1, "Should still have one head");
assert_equals(document.getElementsByTagName("body").length, 1, "Should still have one body");
})
</script>
<div id="log"></div>
</body>
</html>