OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../../../resources/testharness.js"></script> | |
3 <script src="../../../resources/testharnessreport.js"></script> | |
4 <script> | |
5 | |
6 function test_after(nodeName) { | |
7 var child; | |
8 var innerHTML; | |
9 if (nodeName == 'Comment') { | |
10 child = document.createComment('test'); | |
11 innerHTML = '<!--test-->'; | |
12 } else if (nodeName == 'Element') { | |
13 child = document.createElement('test'); | |
14 innerHTML = '<test></test>'; | |
15 } else { | |
16 child = document.createTextNode('test'); | |
17 innerHTML = 'test'; | |
18 } | |
19 | |
20 test(function() { | |
21 var parent = document.createElement('div'); | |
22 parent.appendChild(child); | |
23 child.after(); | |
24 assert_equals(parent.innerHTML, innerHTML); | |
25 }, nodeName + '.after() without any argument.'); | |
26 | |
27 test(function() { | |
28 var parent = document.createElement('div'); | |
29 parent.appendChild(child); | |
30 child.after(null); | |
31 var expected = innerHTML + 'null'; | |
32 assert_equals(parent.innerHTML, expected); | |
33 }, nodeName + '.after() with null as an argument.'); | |
34 | |
35 test(function() { | |
36 var parent = document.createElement('div'); | |
37 parent.appendChild(child); | |
38 child.after(undefined); | |
39 var expected = innerHTML + 'undefined'; | |
40 assert_equals(parent.innerHTML, expected); | |
41 }, nodeName + '.after() with undefined as an argument.'); | |
42 | |
43 test(function() { | |
44 var parent = document.createElement('div'); | |
45 parent.appendChild(child); | |
46 child.after(''); | |
47 assert_equals(parent.lastChild.data, ''); | |
48 }, nodeName + '.after() with the empty string as an argument.'); | |
49 | |
50 test(function() { | |
51 var parent = document.createElement('div'); | |
52 parent.appendChild(child); | |
53 child.after('text'); | |
54 var expected = innerHTML + 'text'; | |
55 assert_equals(parent.innerHTML, expected); | |
56 }, nodeName + '.after() with only text as an argument.'); | |
57 | |
58 test(function() { | |
59 var parent = document.createElement('div'); | |
60 var x = document.createElement('x'); | |
61 parent.appendChild(child); | |
62 child.after(x); | |
63 var expected = innerHTML + '<x></x>'; | |
64 assert_equals(parent.innerHTML, expected); | |
65 }, nodeName + '.after() with only one element as an argument.'); | |
66 | |
67 test(function() { | |
68 var parent = document.createElement('div'); | |
69 var x = document.createElement('x'); | |
70 parent.appendChild(child); | |
71 child.after(x, 'text'); | |
72 var expected = innerHTML + '<x></x>text'; | |
73 assert_equals(parent.innerHTML, expected); | |
74 }, nodeName + '.after() with one element and text as arguments.'); | |
75 | |
76 test(function() { | |
77 var parent = document.createElement('div'); | |
78 parent.appendChild(child); | |
79 child.after('text', child); | |
80 var expected = 'text' + innerHTML; | |
81 assert_equals(parent.innerHTML, expected); | |
82 }, nodeName + '.after() with context object itself as the argument.'); | |
83 | |
84 test(function() { | |
85 var parent = document.createElement('div'); | |
86 var x = document.createElement('x'); | |
87 var y = document.createElement('y'); | |
88 var z = document.createElement('z'); | |
89 parent.appendChild(y); | |
90 parent.appendChild(child); | |
91 parent.appendChild(x); | |
92 child.after(x, y, z); | |
93 var expected = innerHTML + '<x></x><y></y><z></z>'; | |
94 assert_equals(parent.innerHTML, expected); | |
95 }, nodeName + '.after() with all siblings of child as arguments.'); | |
96 | |
97 test(function() { | |
98 var parent = document.createElement('div'); | |
99 var x = document.createElement('x'); | |
100 var y = document.createElement('y'); | |
101 parent.appendChild(child); | |
102 parent.appendChild(x); | |
103 parent.appendChild(y); | |
104 child.after(y, x); | |
105 var expected = innerHTML + '<y></y><x></x>'; | |
106 assert_equals(parent.innerHTML, expected); | |
107 }, nodeName + '.after() when pre-insert behaves like append.'); | |
108 | |
109 test(function() { | |
110 var parent = document.createElement('div'); | |
111 var x = document.createElement('x'); | |
112 var y = document.createElement('y'); | |
113 parent.appendChild(child); | |
114 parent.appendChild(x); | |
115 parent.appendChild(document.createTextNode('1')); | |
116 parent.appendChild(y); | |
117 child.after(x, '2'); | |
118 var expected = innerHTML + '<x></x>21<y></y>'; | |
119 assert_equals(parent.innerHTML, expected); | |
120 }, nodeName + '.after() with one sibling of child and text as arguments.'); | |
121 | |
122 test(function() { | |
123 var x = document.createElement('x'); | |
124 var y = document.createElement('y'); | |
125 x.after(y); | |
126 assert_equals(x.nextSibling, null); | |
127 }, nodeName + '.after() on a child without any parent.'); | |
128 } | |
129 | |
130 test_after('Comment'); | |
131 test_after('Element'); | |
132 test_after('Text'); | |
133 | |
134 </script> | |
135 </html> | |
OLD | NEW |