Chromium Code Reviews| 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.'); | |
|
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.
| |
| 33 | |
| 34 test(function() { | |
| 35 var parent = document.createElement('div'); | |
| 36 parent.appendChild(child); | |
| 37 child.replaceWith('text'); | |
| 38 assert_equals(parent.innerHTML, 'text'); | |
| 39 }, nodeName + '.replaceWith() with only text as an argument.'); | |
| 40 | |
| 41 test(function() { | |
| 42 var parent = document.createElement('div'); | |
| 43 var x = document.createElement('x'); | |
| 44 parent.appendChild(child); | |
| 45 child.replaceWith(x); | |
| 46 assert_equals(parent.innerHTML, '<x></x>'); | |
| 47 }, nodeName + '.replaceWith() with only one element as an argument.'); | |
| 48 | |
| 49 test(function() { | |
| 50 var parent = document.createElement('div'); | |
| 51 var x = document.createElement('x'); | |
| 52 var y = document.createElement('y'); | |
| 53 var z = document.createElement('z'); | |
| 54 parent.appendChild(y); | |
| 55 parent.appendChild(child); | |
| 56 parent.appendChild(x); | |
| 57 child.replaceWith(x, y, z); | |
| 58 assert_equals(parent.innerHTML, '<x></x><y></y><z></z>'); | |
| 59 }, nodeName + '.replaceWith() with sibling of child as arguments.'); | |
| 60 | |
| 61 test(function() { | |
| 62 var parent = document.createElement('div'); | |
| 63 var x = document.createElement('x'); | |
| 64 parent.appendChild(child); | |
| 65 parent.appendChild(x); | |
| 66 parent.appendChild(document.createTextNode('text')); | |
| 67 child.replaceWith(x, 'text'); | |
| 68 assert_equals(parent.innerHTML,'<x></x>texttext'); | |
| 69 }, nodeName + '.replaceWith() with one sibling of child and text as argument s.'); | |
| 70 | |
| 71 test(function() { | |
| 72 var parent = document.createElement('div'); | |
| 73 var x = document.createElement('x'); | |
| 74 parent.appendChild(child); | |
| 75 var innerHTML = parent.innerHTML; | |
| 76 parent.appendChild(x); | |
| 77 parent.appendChild(document.createTextNode('text')); | |
| 78 child.replaceWith(x, child); | |
| 79 assert_equals(parent.innerHTML,'<x></x>' + innerHTML + 'text'); | |
| 80 }, nodeName + '.replaceWith() with one sibling of child and child itself as arguments.'); | |
| 81 | |
| 82 test(function() { | |
| 83 var parent = document.createElement('div'); | |
| 84 var x = document.createElement('x'); | |
| 85 parent.appendChild(child); | |
| 86 child.replaceWith(x, 'text'); | |
| 87 assert_equals(parent.innerHTML, '<x></x>text'); | |
| 88 }, nodeName + '.replaceWith() with one element and text as arguments.'); | |
| 89 } | |
| 90 | |
| 91 test_replaceWith('Comment'); | |
| 92 test_replaceWith('Element'); | |
| 93 test_replaceWith('Text'); | |
| 94 | |
| 95 </script> | |
| 96 </html> | |
| OLD | NEW |