| OLD | NEW |
| (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('after' in child); | |
| 9 var after = 'mine'; | |
| 10 var getAttribute = 'mine'; | |
| 11 with (child) { | |
| 12 assert_true(after === '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.after); | |
| 18 }, 'ChildNode.after() unscopable'); | |
| 19 | |
| 20 function test_after(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.after(); | |
| 38 assert_equals(parent.innerHTML, innerHTML); | |
| 39 }, nodeName + '.after() without any argument.'); | |
| 40 | |
| 41 test(function() { | |
| 42 var parent = document.createElement('div'); | |
| 43 parent.appendChild(child); | |
| 44 child.after(null); | |
| 45 var expected = innerHTML + 'null'; | |
| 46 assert_equals(parent.innerHTML, expected); | |
| 47 }, nodeName + '.after() with null as an argument.'); | |
| 48 | |
| 49 test(function() { | |
| 50 var parent = document.createElement('div'); | |
| 51 parent.appendChild(child); | |
| 52 child.after(undefined); | |
| 53 var expected = innerHTML + 'undefined'; | |
| 54 assert_equals(parent.innerHTML, expected); | |
| 55 }, nodeName + '.after() with undefined as an argument.'); | |
| 56 | |
| 57 test(function() { | |
| 58 var parent = document.createElement('div'); | |
| 59 parent.appendChild(child); | |
| 60 child.after(''); | |
| 61 assert_equals(parent.lastChild.data, ''); | |
| 62 }, nodeName + '.after() with the empty string as an argument.'); | |
| 63 | |
| 64 test(function() { | |
| 65 var parent = document.createElement('div'); | |
| 66 parent.appendChild(child); | |
| 67 child.after('text'); | |
| 68 var expected = innerHTML + 'text'; | |
| 69 assert_equals(parent.innerHTML, expected); | |
| 70 }, nodeName + '.after() with only text as an argument.'); | |
| 71 | |
| 72 test(function() { | |
| 73 var parent = document.createElement('div'); | |
| 74 var x = document.createElement('x'); | |
| 75 parent.appendChild(child); | |
| 76 child.after(x); | |
| 77 var expected = innerHTML + '<x></x>'; | |
| 78 assert_equals(parent.innerHTML, expected); | |
| 79 }, nodeName + '.after() with only one element as an argument.'); | |
| 80 | |
| 81 test(function() { | |
| 82 var parent = document.createElement('div'); | |
| 83 var x = document.createElement('x'); | |
| 84 parent.appendChild(child); | |
| 85 child.after(x, 'text'); | |
| 86 var expected = innerHTML + '<x></x>text'; | |
| 87 assert_equals(parent.innerHTML, expected); | |
| 88 }, nodeName + '.after() with one element and text as arguments.'); | |
| 89 | |
| 90 test(function() { | |
| 91 var parent = document.createElement('div'); | |
| 92 parent.appendChild(child); | |
| 93 child.after('text', child); | |
| 94 var expected = 'text' + innerHTML; | |
| 95 assert_equals(parent.innerHTML, expected); | |
| 96 }, nodeName + '.after() with context object itself as the argument.'); | |
| 97 | |
| 98 test(function() { | |
| 99 var parent = document.createElement('div'); | |
| 100 var x = document.createElement('x'); | |
| 101 var y = document.createElement('y'); | |
| 102 var z = document.createElement('z'); | |
| 103 parent.appendChild(y); | |
| 104 parent.appendChild(child); | |
| 105 parent.appendChild(x); | |
| 106 child.after(x, y, z); | |
| 107 var expected = innerHTML + '<x></x><y></y><z></z>'; | |
| 108 assert_equals(parent.innerHTML, expected); | |
| 109 }, nodeName + '.after() with all siblings of child as arguments.'); | |
| 110 | |
| 111 test(function() { | |
| 112 var parent = document.createElement('div'); | |
| 113 var x = document.createElement('x'); | |
| 114 var y = document.createElement('y'); | |
| 115 parent.appendChild(child); | |
| 116 parent.appendChild(x); | |
| 117 parent.appendChild(y); | |
| 118 child.after(y, x); | |
| 119 var expected = innerHTML + '<y></y><x></x>'; | |
| 120 assert_equals(parent.innerHTML, expected); | |
| 121 }, nodeName + '.after() when pre-insert behaves like append.'); | |
| 122 | |
| 123 test(function() { | |
| 124 var parent = document.createElement('div'); | |
| 125 var x = document.createElement('x'); | |
| 126 var y = document.createElement('y'); | |
| 127 parent.appendChild(child); | |
| 128 parent.appendChild(x); | |
| 129 parent.appendChild(document.createTextNode('1')); | |
| 130 parent.appendChild(y); | |
| 131 child.after(x, '2'); | |
| 132 var expected = innerHTML + '<x></x>21<y></y>'; | |
| 133 assert_equals(parent.innerHTML, expected); | |
| 134 }, nodeName + '.after() with one sibling of child and text as arguments.'); | |
| 135 | |
| 136 test(function() { | |
| 137 var x = document.createElement('x'); | |
| 138 var y = document.createElement('y'); | |
| 139 x.after(y); | |
| 140 assert_equals(x.nextSibling, null); | |
| 141 }, nodeName + '.after() on a child without any parent.'); | |
| 142 | |
| 143 test(function() { | |
| 144 var parent = document.createElement('div'); | |
| 145 parent.appendChild(child); | |
| 146 var doc2 = document.implementation.createDocument("http://www.w3.org/199
9/xhtml", "html"); | |
| 147 assert_throws('HierarchyRequestError', () => { child.after(doc2, "foo")
}); | |
| 148 assert_equals(parent.firstChild, child); | |
| 149 }, nodeName + '.after() with a Document as an argument should throw.'); | |
| 150 } | |
| 151 | |
| 152 test_after('Comment'); | |
| 153 test_after('Element'); | |
| 154 test_after('Text'); | |
| 155 | |
| 156 </script> | |
| 157 </html> | |
| OLD | NEW |