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