Chromium Code Reviews| Index: LayoutTests/fast/dom/ChildNode/replace-with.html |
| diff --git a/LayoutTests/fast/dom/ChildNode/replace-with.html b/LayoutTests/fast/dom/ChildNode/replace-with.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0fa10a3fd1dfc5096bd00c8c23e7e796968132d0 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/ChildNode/replace-with.html |
| @@ -0,0 +1,96 @@ |
| +<!DOCTYPE html> |
| +<script src="../../../resources/testharness.js"></script> |
| +<script src="../../../resources/testharnessreport.js"></script> |
| +<script> |
| + |
| +function test_replaceWith(nodeName) { |
| + var child; |
| + var innerHTML; |
| + if (nodeName == 'Comment') { |
| + child = document.createComment('test'); |
| + innerHTML = '<!--test-->'; |
| + } else if (nodeName == 'Element') { |
| + child = document.createElement('test'); |
| + innerHTML = '<test></test>'; |
| + } else { |
| + child = document.createTextNode('test'); |
| + innerHTML = 'test'; |
| + } |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + parent.appendChild(child); |
| + child.replaceWith(); |
| + assert_equals(parent.innerHTML, ''); |
| + }, nodeName + '.replaceWith() without any argument.'); |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + parent.appendChild(child); |
| + child.replaceWith(null); |
| + assert_equals(parent.innerHTML, 'null'); |
| + }, nodeName + '.replaceWith() with null as an argument.'); |
|
philipj_slow
2015/07/03 21:52:05
Actually undefined might be worth testing too, bec
Paritosh Kumar
2015/07/06 09:02:27
Done.
|
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + parent.appendChild(child); |
| + child.replaceWith('text'); |
| + assert_equals(parent.innerHTML, 'text'); |
| + }, nodeName + '.replaceWith() with only text as an argument.'); |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + var x = document.createElement('x'); |
| + parent.appendChild(child); |
| + child.replaceWith(x); |
| + assert_equals(parent.innerHTML, '<x></x>'); |
| + }, nodeName + '.replaceWith() with only one element as an argument.'); |
| + |
| + 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.replaceWith(x, y, z); |
| + assert_equals(parent.innerHTML, '<x></x><y></y><z></z>'); |
| + }, nodeName + '.replaceWith() with sibling of child as arguments.'); |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + var x = document.createElement('x'); |
| + parent.appendChild(child); |
| + parent.appendChild(x); |
| + parent.appendChild(document.createTextNode('text')); |
| + child.replaceWith(x, 'text'); |
| + assert_equals(parent.innerHTML,'<x></x>texttext'); |
| + }, nodeName + '.replaceWith() with one sibling of child and text as arguments.'); |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + var x = document.createElement('x'); |
| + parent.appendChild(child); |
| + var innerHTML = parent.innerHTML; |
| + parent.appendChild(x); |
| + parent.appendChild(document.createTextNode('text')); |
| + child.replaceWith(x, child); |
| + assert_equals(parent.innerHTML,'<x></x>' + innerHTML + 'text'); |
| + }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.'); |
| + |
| + test(function() { |
| + var parent = document.createElement('div'); |
| + var x = document.createElement('x'); |
| + parent.appendChild(child); |
| + child.replaceWith(x, 'text'); |
| + assert_equals(parent.innerHTML, '<x></x>text'); |
| + }, nodeName + '.replaceWith() with one element and text as arguments.'); |
| +} |
| + |
| +test_replaceWith('Comment'); |
| +test_replaceWith('Element'); |
| +test_replaceWith('Text'); |
| + |
| +</script> |
| +</html> |