Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/ChildNode/replace-with.html

Issue 2783813003: Move tests for ChildNode and ParentNode to dom/child_node/ and dom/parent_node/. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../../resources/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <script>
5
6 test(function () {
7 var child = document.createElement('p');
8 assert_true('replaceWith' in child);
9 var replaceWith = 'mine';
10 var getAttribute = 'mine';
11 with (child) {
12 assert_true(replaceWith === 'mine');
13 assert_false(getAttribute === 'mine');
14 }
15 assert_true('Symbol' in window);
16 var unscopables = Object.getPrototypeOf(child)[Symbol.unscopables];
17 assert_true(unscopables.replaceWith);
18 }, 'ChildNode.replaceWith() unscopable');
19
20 function test_replaceWith(nodeName) {
21 var child;
22 var innerHTML;
23 if (nodeName == 'Comment') {
24 child = document.createComment('test');
25 innerHTML = '<!--test-->';
26 } else if (nodeName == 'Element') {
27 child = document.createElement('test');
28 innerHTML = '<test></test>';
29 } else {
30 child = document.createTextNode('test');
31 innerHTML = 'test';
32 }
33
34 test(function() {
35 var parent = document.createElement('div');
36 parent.appendChild(child);
37 child.replaceWith();
38 assert_equals(parent.innerHTML, '');
39 }, nodeName + '.replaceWith() without any argument.');
40
41 test(function() {
42 var parent = document.createElement('div');
43 parent.appendChild(child);
44 child.replaceWith(null);
45 assert_equals(parent.innerHTML, 'null');
46 }, nodeName + '.replaceWith() with null as an argument.');
47
48 test(function() {
49 var parent = document.createElement('div');
50 parent.appendChild(child);
51 child.replaceWith(undefined);
52 assert_equals(parent.innerHTML, 'undefined');
53 }, nodeName + '.replaceWith() with undefined as an argument.');
54
55 test(function() {
56 var parent = document.createElement('div');
57 parent.appendChild(child);
58 child.replaceWith('');
59 assert_equals(parent.innerHTML, '');
60 }, nodeName + '.replaceWith() with an empty string as an argument.');
61
62 test(function() {
63 var parent = document.createElement('div');
64 parent.appendChild(child);
65 child.replaceWith('text');
66 assert_equals(parent.innerHTML, 'text');
67 }, nodeName + '.replaceWith() with only text as an argument.');
68
69 test(function() {
70 var parent = document.createElement('div');
71 var x = document.createElement('x');
72 parent.appendChild(child);
73 child.replaceWith(x);
74 assert_equals(parent.innerHTML, '<x></x>');
75 }, nodeName + '.replaceWith() with only one element as an argument.');
76
77 test(function() {
78 var parent = document.createElement('div');
79 var x = document.createElement('x');
80 var y = document.createElement('y');
81 var z = document.createElement('z');
82 parent.appendChild(y);
83 parent.appendChild(child);
84 parent.appendChild(x);
85 child.replaceWith(x, y, z);
86 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>');
87 }, nodeName + '.replaceWith() with sibling of child as arguments.');
88
89 test(function() {
90 var parent = document.createElement('div');
91 var x = document.createElement('x');
92 parent.appendChild(child);
93 parent.appendChild(x);
94 parent.appendChild(document.createTextNode('1'));
95 child.replaceWith(x, '2');
96 assert_equals(parent.innerHTML,'<x></x>21');
97 }, nodeName + '.replaceWith() with one sibling of child and text as argument s.');
98
99 test(function() {
100 var parent = document.createElement('div');
101 var x = document.createElement('x');
102 parent.appendChild(child);
103 var innerHTML = parent.innerHTML;
104 parent.appendChild(x);
105 parent.appendChild(document.createTextNode('text'));
106 child.replaceWith(x, child);
107 assert_equals(parent.innerHTML,'<x></x>' + innerHTML + 'text');
108 }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.');
109
110 test(function() {
111 var parent = document.createElement('div');
112 var x = document.createElement('x');
113 parent.appendChild(child);
114 child.replaceWith(x, 'text');
115 assert_equals(parent.innerHTML, '<x></x>text');
116 }, nodeName + '.replaceWith() with one element and text as arguments.');
117
118 test(function() {
119 var parent = document.createElement('div');
120 var x = document.createElement('x');
121 var y = document.createElement('y');
122 parent.appendChild(x);
123 parent.appendChild(y);
124 child.replaceWith(x, y);
125 assert_equals(parent.innerHTML, '<x></x><y></y>');
126 }, nodeName + '.replaceWith() on a parenless child with two elements as argu ments.');
127
128 test(function() {
129 var parent = document.createElement('div');
130 parent.appendChild(child);
131 var doc2 = document.implementation.createDocument("http://www.w3.org/199 9/xhtml", "html");
132 assert_throws('HierarchyRequestError', () => { child.replaceWith(doc2, " foo") });
133 assert_equals(parent.firstChild, child);
134 }, nodeName + '.replaceWith() with a Document as an argument should throw.') ;
135 }
136
137 test_replaceWith('Comment');
138 test_replaceWith('Element');
139 test_replaceWith('Text');
140
141 </script>
142 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698