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_before(node, 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 = node.cloneNode(); |
| 22 parent.appendChild(child); |
| 23 child.before(); |
| 24 expected = innerHTML; |
| 25 assert_equals(parent.innerHTML, expected); |
| 26 }, nodeName + '.before() without any argument.'); |
| 27 |
| 28 test(function() { |
| 29 var parent = node.cloneNode(); |
| 30 parent.appendChild(child); |
| 31 child.before(null); |
| 32 expected = 'null' + innerHTML; |
| 33 assert_equals(parent.innerHTML, expected); |
| 34 }, nodeName + '.before() with null as an argument.'); |
| 35 |
| 36 test(function() { |
| 37 var parent = node.cloneNode(); |
| 38 parent.appendChild(child); |
| 39 child.before('text'); |
| 40 expected = 'text' + innerHTML; |
| 41 assert_equals(parent.innerHTML, expected); |
| 42 }, nodeName + '.before() with only text as an argument.'); |
| 43 |
| 44 test(function() { |
| 45 var parent = node.cloneNode(); |
| 46 var x = document.createElement('x'); |
| 47 parent.appendChild(child); |
| 48 child.before(x); |
| 49 expected = '<x></x>' + innerHTML; |
| 50 assert_equals(parent.innerHTML, expected); |
| 51 }, nodeName + '.before() with only one element as an argument.'); |
| 52 |
| 53 test(function() { |
| 54 var parent = node.cloneNode(); |
| 55 var x = document.createElement('x'); |
| 56 parent.appendChild(child); |
| 57 child.before(x, 'text'); |
| 58 expected = '<x></x>text' + innerHTML; |
| 59 assert_equals(parent.innerHTML, expected); |
| 60 }, nodeName + '.before() with one element and text as arguments.'); |
| 61 } |
| 62 |
| 63 test_before(document.createElement('div'), 'Comment'); |
| 64 test_before(document.createElement('div'), 'Element'); |
| 65 test_before(document.createElement('div'), 'Text'); |
| 66 |
| 67 </script> |
| 68 </html> |
OLD | NEW |