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_prepend_on_Document() { |
| 7 |
| 8 var node = document.implementation.createDocument(null, null); |
| 9 test(function() { |
| 10 var parent = node.cloneNode(); |
| 11 parent.prepend(); |
| 12 assert_equals(parent.childNodes.length, 0); |
| 13 assert_array_equals(parent.childNodes, []); |
| 14 }, 'Document.prepend() without any argument, on a Document having no child.'
); |
| 15 |
| 16 test(function() { |
| 17 var parent = node.cloneNode(); |
| 18 var x = document.createElement('x'); |
| 19 parent.prepend(x); |
| 20 assert_equals(parent.childNodes.length, 1); |
| 21 assert_array_equals(parent.childNodes, [x]); |
| 22 }, 'Document.prepend() with only one element as an argument, on a Document h
aving no child.'); |
| 23 |
| 24 test(function() { |
| 25 var parent = node.cloneNode(); |
| 26 var x = document.createElement('x'); |
| 27 var y = document.createElement('y'); |
| 28 parent.appendChild(x); |
| 29 assert_throws('HierarchyRequestError', function() { parent.prepend(y); }
, 'Only one element on document allowed.'); |
| 30 assert_equals(parent.childNodes.length, 1); |
| 31 assert_array_equals(parent.childNodes, [x]); |
| 32 }, 'Document.append() with only one element as an argument, on a Document ha
ving one child.'); |
| 33 |
| 34 test(function() { |
| 35 var parent = node.cloneNode(); |
| 36 assert_throws('HierarchyRequestError', function() { parent.prepend('text
'); }, 'Nodes of type \'#text\' may not be inserted inside nodes of type \'#docu
ment\''); |
| 37 assert_equals(parent.childNodes.length, 0); |
| 38 assert_array_equals(parent.childNodes, []); |
| 39 }, 'Document.prepend() with text as an argument, on a Document having no ch
ild.'); |
| 40 |
| 41 test(function() { |
| 42 var parent = node.cloneNode(); |
| 43 var x = document.createElement('x'); |
| 44 var y = document.createElement('y'); |
| 45 assert_throws('HierarchyRequestError', function() { parent.prepend(x, y)
; }, 'Only one element on document allowed.'); |
| 46 assert_equals(parent.childNodes.length, 0); |
| 47 assert_array_equals(parent.childNodes, []); |
| 48 }, 'Document.prepend() with only one element as an argument, on a Document h
aving no child.'); |
| 49 |
| 50 } |
| 51 |
| 52 test_prepend_on_Document(); |
| 53 |
| 54 </script> |
| 55 </html> |
OLD | NEW |