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

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

Issue 1934123002: Implement DOM methods: prepend, append, after, before and replaceWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync test expectations Created 4 years, 7 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <meta charset=utf-8> 2 <script src="../../../resources/testharness.js"></script>
3 <title>ChildNode.replaceWith</title> 3 <script src="../../../resources/testharnessreport.js"></script>
4 <link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-replaceWith">
5 <script src="../../../../resources/testharness.js"></script>
6 <script src="../../../../resources/testharnessreport.js"></script>
7 <script> 4 <script>
8 5
9 function test_replaceWith(child, nodeName, innerHTML) { 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() unscopeable');
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 }
10 33
11 test(function() { 34 test(function() {
12 var parent = document.createElement('div'); 35 var parent = document.createElement('div');
13 parent.appendChild(child); 36 parent.appendChild(child);
14 child.replaceWith(); 37 child.replaceWith();
15 assert_equals(parent.innerHTML, ''); 38 assert_equals(parent.innerHTML, '');
16 }, nodeName + '.replaceWith() without any argument.'); 39 }, nodeName + '.replaceWith() without any argument.');
17 40
18 test(function() { 41 test(function() {
19 var parent = document.createElement('div'); 42 var parent = document.createElement('div');
20 parent.appendChild(child); 43 parent.appendChild(child);
21 child.replaceWith(null); 44 child.replaceWith(null);
22 assert_equals(parent.innerHTML, 'null'); 45 assert_equals(parent.innerHTML, 'null');
23 }, nodeName + '.replaceWith() with null as an argument.'); 46 }, nodeName + '.replaceWith() with null as an argument.');
24 47
25 test(function() { 48 test(function() {
26 var parent = document.createElement('div'); 49 var parent = document.createElement('div');
27 parent.appendChild(child); 50 parent.appendChild(child);
28 child.replaceWith(undefined); 51 child.replaceWith(undefined);
29 assert_equals(parent.innerHTML, 'undefined'); 52 assert_equals(parent.innerHTML, 'undefined');
30 }, nodeName + '.replaceWith() with undefined as an argument.'); 53 }, nodeName + '.replaceWith() with undefined as an argument.');
31 54
32 test(function() { 55 test(function() {
33 var parent = document.createElement('div'); 56 var parent = document.createElement('div');
34 parent.appendChild(child); 57 parent.appendChild(child);
35 child.replaceWith(''); 58 child.replaceWith('');
36 assert_equals(parent.innerHTML, ''); 59 assert_equals(parent.innerHTML, '');
37 }, nodeName + '.replaceWith() with empty string as an argument.'); 60 }, nodeName + '.replaceWith() with an empty string as an argument.');
38 61
39 test(function() { 62 test(function() {
40 var parent = document.createElement('div'); 63 var parent = document.createElement('div');
41 parent.appendChild(child); 64 parent.appendChild(child);
42 child.replaceWith('text'); 65 child.replaceWith('text');
43 assert_equals(parent.innerHTML, 'text'); 66 assert_equals(parent.innerHTML, 'text');
44 }, nodeName + '.replaceWith() with only text as an argument.'); 67 }, nodeName + '.replaceWith() with only text as an argument.');
45 68
46 test(function() { 69 test(function() {
47 var parent = document.createElement('div'); 70 var parent = document.createElement('div');
(...skipping 15 matching lines...) Expand all
63 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>'); 86 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>');
64 }, nodeName + '.replaceWith() with sibling of child as arguments.'); 87 }, nodeName + '.replaceWith() with sibling of child as arguments.');
65 88
66 test(function() { 89 test(function() {
67 var parent = document.createElement('div'); 90 var parent = document.createElement('div');
68 var x = document.createElement('x'); 91 var x = document.createElement('x');
69 parent.appendChild(child); 92 parent.appendChild(child);
70 parent.appendChild(x); 93 parent.appendChild(x);
71 parent.appendChild(document.createTextNode('1')); 94 parent.appendChild(document.createTextNode('1'));
72 child.replaceWith(x, '2'); 95 child.replaceWith(x, '2');
73 assert_equals(parent.innerHTML, '<x></x>21'); 96 assert_equals(parent.innerHTML,'<x></x>21');
74 }, nodeName + '.replaceWith() with one sibling of child and text as argument s.'); 97 }, nodeName + '.replaceWith() with one sibling of child and text as argument s.');
75 98
76 test(function() { 99 test(function() {
77 var parent = document.createElement('div'); 100 var parent = document.createElement('div');
78 var x = document.createElement('x'); 101 var x = document.createElement('x');
79 parent.appendChild(child); 102 parent.appendChild(child);
103 var innerHTML = parent.innerHTML;
80 parent.appendChild(x); 104 parent.appendChild(x);
81 parent.appendChild(document.createTextNode('text')); 105 parent.appendChild(document.createTextNode('text'));
82 child.replaceWith(x, child); 106 child.replaceWith(x, child);
83 assert_equals(parent.innerHTML, '<x></x>' + innerHTML + 'text'); 107 assert_equals(parent.innerHTML,'<x></x>' + innerHTML + 'text');
84 }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.'); 108 }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.');
85 109
86 test(function() { 110 test(function() {
87 var parent = document.createElement('div'); 111 var parent = document.createElement('div');
88 var x = document.createElement('x'); 112 var x = document.createElement('x');
89 parent.appendChild(child); 113 parent.appendChild(child);
90 child.replaceWith(x, 'text'); 114 child.replaceWith(x, 'text');
91 assert_equals(parent.innerHTML, '<x></x>text'); 115 assert_equals(parent.innerHTML, '<x></x>text');
92 }, nodeName + '.replaceWith() with one element and text as arguments.'); 116 }, nodeName + '.replaceWith() with one element and text as arguments.');
93 117
94 test(function() { 118 test(function() {
95 var parent = document.createElement('div'); 119 var parent = document.createElement('div');
96 var x = document.createElement('x'); 120 var x = document.createElement('x');
97 var y = document.createElement('y'); 121 var y = document.createElement('y');
98 parent.appendChild(x); 122 parent.appendChild(x);
99 parent.appendChild(y); 123 parent.appendChild(y);
100 child.replaceWith(x, y); 124 child.replaceWith(x, y);
101 assert_equals(parent.innerHTML, '<x></x><y></y>'); 125 assert_equals(parent.innerHTML, '<x></x><y></y>');
102 }, nodeName + '.replaceWith() on a parentless child with two elements as arg uments.'); 126 }, nodeName + '.replaceWith() on a parenless child with two elements as argu ments.');
103 } 127 }
104 128
105 test_replaceWith(document.createComment('test'), 'Comment', '<!--test-->'); 129 test_replaceWith('Comment');
106 test_replaceWith(document.createElement('test'), 'Element', '<test></test>'); 130 test_replaceWith('Element');
107 test_replaceWith(document.createTextNode('test'), 'Text', 'test'); 131 test_replaceWith('Text');
108 132
109 </script> 133 </script>
110 </html> 134 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698