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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>ChildNode.after</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-after">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function test_after(child, nodeName, innerHTML) {
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after();
assert_equals(parent.innerHTML, innerHTML);
}, nodeName + '.after() without any argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after(null);
var expected = innerHTML + 'null';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with null as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after(undefined);
var expected = innerHTML + 'undefined';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with undefined as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('');
assert_equals(parent.lastChild.data, '');
}, nodeName + '.after() with the empty string as an argument.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('text');
var expected = innerHTML + 'text';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with only text as an argument.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
parent.appendChild(child);
child.after(x);
var expected = innerHTML + '<x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with only one element as an argument.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
parent.appendChild(child);
child.after(x, 'text');
var expected = innerHTML + '<x></x>text';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with one element and text as arguments.');
test(function() {
var parent = document.createElement('div');
parent.appendChild(child);
child.after('text', child);
var expected = 'text' + innerHTML;
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with context object itself as the argument.');
test(function() {
var parent = document.createElement('div')
var x = document.createElement('x');
parent.appendChild(x);
parent.appendChild(child);
child.after(child, x);
var expected = innerHTML + '<x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with context object itself and node as the arguments, switching positions.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(y);
parent.appendChild(child);
parent.appendChild(x);
child.after(x, y, z);
var expected = innerHTML + '<x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with all siblings of child as arguments.');
test(function() {
var parent = document.createElement('div')
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(y);
parent.appendChild(z);
child.after(x, y);
var expected = innerHTML + '<x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.before() with some siblings of child as arguments; no changes in tree; viable sibling is first child.');
test(function() {
var parent = document.createElement('div')
var v = document.createElement('v');
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(child);
parent.appendChild(v);
parent.appendChild(x);
parent.appendChild(y);
parent.appendChild(z);
child.after(v, x);
var expected = innerHTML + '<v></v><x></x><y></y><z></z>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with some siblings of child as arguments; no changes in tree.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(y);
child.after(y, x);
var expected = innerHTML + '<y></y><x></x>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() when pre-insert behaves like append.');
test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
var y = document.createElement('y');
parent.appendChild(child);
parent.appendChild(x);
parent.appendChild(document.createTextNode('1'));
parent.appendChild(y);
child.after(x, '2');
var expected = innerHTML + '<x></x>21<y></y>';
assert_equals(parent.innerHTML, expected);
}, nodeName + '.after() with one sibling of child and text as arguments.');
test(function() {
var x = document.createElement('x');
var y = document.createElement('y');
x.after(y);
assert_equals(x.nextSibling, null);
}, nodeName + '.after() on a child without any parent.');
}
test_after(document.createComment('test'), 'Comment', '<!--test-->');
test_after(document.createElement('test'), 'Element', '<test></test>');
test_after(document.createTextNode('test'), 'Text', 'test');
</script>
</html>
|