| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <script src="../../../resources/testharness.js"></script> |
| 3 <title>ChildNode.before</title> | 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-childnode-before"> | |
| 5 <script src="../../../../resources/testharness.js"></script> | |
| 6 <script src="../../../../resources/testharnessreport.js"></script> | |
| 7 <script> | 4 <script> |
| 8 | 5 |
| 9 function test_before(child, nodeName, innerHTML) { | 6 test(function () { |
| 7 var child = document.createElement('p'); |
| 8 assert_true('before' in child); |
| 9 var before = 'mine'; |
| 10 var getAttribute = 'mine'; |
| 11 with (child) { |
| 12 assert_true(before === '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.before); |
| 18 }, 'ChildNode.before() unscopeable'); |
| 19 |
| 20 function test_before(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.before(); | 37 child.before(); |
| 15 assert_equals(parent.innerHTML, innerHTML); | 38 assert_equals(parent.innerHTML, innerHTML); |
| 16 }, nodeName + '.before() without any argument.'); | 39 }, nodeName + '.before() without any argument.'); |
| 17 | 40 |
| 18 test(function() { | 41 test(function() { |
| 19 var parent = document.createElement('div'); | 42 var parent = document.createElement('div'); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 89 |
| 67 test(function() { | 90 test(function() { |
| 68 var parent = document.createElement('div'); | 91 var parent = document.createElement('div'); |
| 69 parent.appendChild(child); | 92 parent.appendChild(child); |
| 70 child.before('text', child); | 93 child.before('text', child); |
| 71 var expected = 'text' + innerHTML; | 94 var expected = 'text' + innerHTML; |
| 72 assert_equals(parent.innerHTML, expected); | 95 assert_equals(parent.innerHTML, expected); |
| 73 }, nodeName + '.before() with context object itself as the argument.'); | 96 }, nodeName + '.before() with context object itself as the argument.'); |
| 74 | 97 |
| 75 test(function() { | 98 test(function() { |
| 76 var parent = document.createElement('div') | |
| 77 var x = document.createElement('x'); | |
| 78 parent.appendChild(child); | |
| 79 parent.appendChild(x); | |
| 80 child.before(x, child); | |
| 81 var expected = '<x></x>' + innerHTML; | |
| 82 assert_equals(parent.innerHTML, expected); | |
| 83 }, nodeName + '.before() with context object itself and node as the argument
s, switching positions.'); | |
| 84 | |
| 85 test(function() { | |
| 86 var parent = document.createElement('div'); | 99 var parent = document.createElement('div'); |
| 87 var x = document.createElement('x'); | 100 var x = document.createElement('x'); |
| 88 var y = document.createElement('y'); | 101 var y = document.createElement('y'); |
| 89 var z = document.createElement('z'); | 102 var z = document.createElement('z'); |
| 90 parent.appendChild(y); | 103 parent.appendChild(y); |
| 91 parent.appendChild(child); | 104 parent.appendChild(child); |
| 92 parent.appendChild(x); | 105 parent.appendChild(x); |
| 93 child.before(x, y, z); | 106 child.before(x, y, z); |
| 94 var expected = '<x></x><y></y><z></z>' + innerHTML; | 107 var expected = '<x></x><y></y><z></z>' + innerHTML; |
| 95 assert_equals(parent.innerHTML, expected); | 108 assert_equals(parent.innerHTML, expected); |
| 96 }, nodeName + '.before() with all siblings of child as arguments.'); | 109 }, nodeName + '.before() with all siblings of child as arguments.'); |
| 97 | 110 |
| 98 test(function() { | 111 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(x); | |
| 104 parent.appendChild(y); | |
| 105 parent.appendChild(z); | |
| 106 parent.appendChild(child); | |
| 107 child.before(y, z); | |
| 108 var expected = '<x></x><y></y><z></z>' + innerHTML; | |
| 109 assert_equals(parent.innerHTML, expected); | |
| 110 }, nodeName + '.before() with some siblings of child as arguments; no change
s in tree; viable sibling is first child.'); | |
| 111 | |
| 112 test(function() { | |
| 113 var parent = document.createElement('div') | |
| 114 var v = document.createElement('v'); | |
| 115 var x = document.createElement('x'); | |
| 116 var y = document.createElement('y'); | |
| 117 var z = document.createElement('z'); | |
| 118 parent.appendChild(v); | |
| 119 parent.appendChild(x); | |
| 120 parent.appendChild(y); | |
| 121 parent.appendChild(z); | |
| 122 parent.appendChild(child); | |
| 123 child.before(y, z); | |
| 124 var expected = '<v></v><x></x><y></y><z></z>' + innerHTML; | |
| 125 assert_equals(parent.innerHTML, expected); | |
| 126 }, nodeName + '.before() with some siblings of child as arguments; no change
s in tree.'); | |
| 127 | |
| 128 test(function() { | |
| 129 var parent = document.createElement('div'); | 112 var parent = document.createElement('div'); |
| 130 var x = document.createElement('x'); | 113 var x = document.createElement('x'); |
| 131 var y = document.createElement('y'); | 114 var y = document.createElement('y'); |
| 132 parent.appendChild(x); | 115 parent.appendChild(x); |
| 133 parent.appendChild(y); | 116 parent.appendChild(y); |
| 134 parent.appendChild(child); | 117 parent.appendChild(child); |
| 135 child.before(y, x); | 118 child.before(y, x); |
| 136 var expected = '<y></y><x></x>' + innerHTML; | 119 var expected = '<y></y><x></x>' + innerHTML; |
| 137 assert_equals(parent.innerHTML, expected); | 120 assert_equals(parent.innerHTML, expected); |
| 138 }, nodeName + '.before() when pre-insert behaves like prepend.'); | 121 }, nodeName + '.before() when pre-insert behaves like prepend.'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 151 }, nodeName + '.before() with one sibling of child and text as arguments.'); | 134 }, nodeName + '.before() with one sibling of child and text as arguments.'); |
| 152 | 135 |
| 153 test(function() { | 136 test(function() { |
| 154 var x = document.createElement('x'); | 137 var x = document.createElement('x'); |
| 155 var y = document.createElement('y'); | 138 var y = document.createElement('y'); |
| 156 x.before(y); | 139 x.before(y); |
| 157 assert_equals(x.previousSibling, null); | 140 assert_equals(x.previousSibling, null); |
| 158 }, nodeName + '.before() on a child without any parent.'); | 141 }, nodeName + '.before() on a child without any parent.'); |
| 159 } | 142 } |
| 160 | 143 |
| 161 test_before(document.createComment('test'), 'Comment', '<!--test-->'); | 144 test_before('Comment'); |
| 162 test_before(document.createElement('test'), 'Element', '<test></test>'); | 145 test_before('Element'); |
| 163 test_before(document.createTextNode('test'), 'Text', 'test'); | 146 test_before('Text'); |
| 164 | 147 |
| 165 </script> | 148 </script> |
| 166 </html> | 149 </html> |
| OLD | NEW |