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_replaceWith(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.replaceWith(); | |
24 assert_equals(parent.innerHTML, ''); | |
25 }, nodeName + '.replaceWith() without any argument.'); | |
26 | |
27 test(function() { | |
28 var parent = document.createElement('div'); | |
29 parent.appendChild(child); | |
30 child.replaceWith(null); | |
31 assert_equals(parent.innerHTML, 'null'); | |
32 }, nodeName + '.replaceWith() with null as an argument.'); | |
33 | |
34 test(function() { | |
35 var parent = document.createElement('div'); | |
36 parent.appendChild(child); | |
37 child.replaceWith(undefined); | |
38 assert_equals(parent.innerHTML, 'undefined'); | |
39 }, nodeName + '.replaceWith() with undefined as an argument.'); | |
40 | |
41 test(function() { | |
42 var parent = document.createElement('div'); | |
43 parent.appendChild(child); | |
44 child.replaceWith(''); | |
45 assert_equals(parent.innerHTML, ''); | |
46 }, nodeName + '.replaceWith() with an empty string as an argument.'); | |
47 | |
48 test(function() { | |
49 var parent = document.createElement('div'); | |
50 parent.appendChild(child); | |
51 child.replaceWith('text'); | |
52 assert_equals(parent.innerHTML, 'text'); | |
53 }, nodeName + '.replaceWith() with only text as an argument.'); | |
54 | |
55 test(function() { | |
56 var parent = document.createElement('div'); | |
57 var x = document.createElement('x'); | |
58 parent.appendChild(child); | |
59 child.replaceWith(x); | |
60 assert_equals(parent.innerHTML, '<x></x>'); | |
61 }, nodeName + '.replaceWith() with only one element as an argument.'); | |
62 | |
63 test(function() { | |
64 var parent = document.createElement('div'); | |
65 var x = document.createElement('x'); | |
66 var y = document.createElement('y'); | |
67 var z = document.createElement('z'); | |
68 parent.appendChild(y); | |
69 parent.appendChild(child); | |
70 parent.appendChild(x); | |
71 child.replaceWith(x, y, z); | |
72 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>'); | |
73 }, nodeName + '.replaceWith() with sibling of child as arguments.'); | |
74 | |
75 test(function() { | |
76 var parent = document.createElement('div'); | |
77 var x = document.createElement('x'); | |
78 parent.appendChild(child); | |
79 parent.appendChild(x); | |
80 parent.appendChild(document.createTextNode('1')); | |
81 child.replaceWith(x, '2'); | |
82 assert_equals(parent.innerHTML,'<x></x>21'); | |
83 }, nodeName + '.replaceWith() with one sibling of child and text as argument
s.'); | |
84 | |
85 test(function() { | |
86 var parent = document.createElement('div'); | |
87 var x = document.createElement('x'); | |
88 parent.appendChild(child); | |
89 var innerHTML = parent.innerHTML; | |
90 parent.appendChild(x); | |
91 parent.appendChild(document.createTextNode('text')); | |
92 child.replaceWith(x, child); | |
93 assert_equals(parent.innerHTML,'<x></x>' + innerHTML + 'text'); | |
94 }, nodeName + '.replaceWith() with one sibling of child and child itself as
arguments.'); | |
95 | |
96 test(function() { | |
97 var parent = document.createElement('div'); | |
98 var x = document.createElement('x'); | |
99 parent.appendChild(child); | |
100 child.replaceWith(x, 'text'); | |
101 assert_equals(parent.innerHTML, '<x></x>text'); | |
102 }, nodeName + '.replaceWith() with one element and text as arguments.'); | |
103 | |
104 test(function() { | |
105 var parent = document.createElement('div'); | |
106 var x = document.createElement('x'); | |
107 var y = document.createElement('y'); | |
108 parent.appendChild(x); | |
109 parent.appendChild(y); | |
110 child.replaceWith(x, y); | |
111 assert_equals(parent.innerHTML, '<x></x><y></y>'); | |
112 }, nodeName + '.replaceWith() on a parenless child with two elements as argu
ments.'); | |
113 } | |
114 | |
115 test_replaceWith('Comment'); | |
116 test_replaceWith('Element'); | |
117 test_replaceWith('Text'); | |
118 | |
119 </script> | |
120 </html> | |
OLD | NEW |