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(node, nodeName) { | |
7 | |
8 test(function() { | |
9 var parent = node.cloneNode(); | |
10 parent.prepend(); | |
11 assert_equals(parent.childNodes.length, 0); | |
12 assert_array_equals(parent.childNodes, []); | |
13 }, nodeName + '.prepend() without any argument, on a parent having no child. '); | |
14 | |
15 test(function() { | |
16 if (nodeName != 'Document') { | |
17 var parent = node.cloneNode(); | |
18 parent.prepend(null); | |
19 assert_equals(parent.childNodes.length, 1); | |
20 assert_equals(parent.childNodes[0].textContent, 'null'); | |
21 } | |
22 }, nodeName + '.prepend() with null as an argument, on a parent having no ch ild.'); | |
23 | |
24 test(function() { | |
25 if (nodeName != 'Document') { | |
26 var parent = node.cloneNode(); | |
27 parent.prepend(undefined); | |
28 assert_equals(parent.childNodes.length, 1); | |
29 assert_equals(parent.childNodes[0].textContent, 'undefined'); | |
30 } | |
31 }, nodeName + '.prepend() with undefined as an argument, on a parent having no child.'); | |
32 | |
33 test(function() { | |
34 if (nodeName != 'Document') { | |
35 var parent = node.cloneNode(); | |
36 parent.prepend('text'); | |
37 assert_equals(parent.childNodes.length, 1); | |
38 assert_equals(parent.childNodes[0].textContent, 'text'); | |
39 } | |
40 }, nodeName + '.prepend() with only text as an argument, on a parent having no child.'); | |
41 | |
42 test(function() { | |
43 var parent = node.cloneNode(); | |
44 var x = document.createElement('x'); | |
45 parent.prepend(x); | |
46 assert_equals(parent.childNodes.length, 1); | |
47 assert_array_equals(parent.childNodes, [x]); | |
48 }, nodeName + '.prepend() with only one element as an argument, on a parent having no child.'); | |
49 | |
50 test(function() { | |
51 if (nodeName != 'Document') { | |
52 var parent = node.cloneNode(); | |
53 var child = document.createElement('test'); | |
54 parent.appendChild(child); | |
55 parent.prepend(null); | |
56 assert_equals(parent.childNodes.length, 2); | |
57 assert_equals(parent.childNodes[0].textContent, 'null'); | |
58 assert_equals(parent.childNodes[1], child); | |
59 } | |
60 }, nodeName + '.prepend() with null as an argument, on a parent having a chi ld.'); | |
61 | |
62 test(function() { | |
63 if (nodeName != 'Document') { | |
64 var parent = node.cloneNode(); | |
65 var child = document.createElement('test'); | |
66 parent.appendChild(child); | |
67 parent.prepend(undefined); | |
68 assert_equals(parent.childNodes.length, 2); | |
69 assert_equals(parent.childNodes[0].textContent, 'undefined'); | |
70 assert_equals(parent.childNodes[1], child); | |
71 } | |
72 }, nodeName + '.prepend() with undefined as an argument, on a parent having a child.'); | |
philipj_slow
2015/07/06 12:02:40
Ditto.
| |
73 | |
74 test(function() { | |
75 if (nodeName != 'Document') { | |
76 var parent = node.cloneNode(); | |
77 var x = document.createElement('x'); | |
78 var child = document.createElement('test'); | |
79 parent.appendChild(child); | |
80 parent.prepend(x, 'text'); | |
81 assert_equals(parent.childNodes.length, 3); | |
82 assert_equals(parent.childNodes[0], x); | |
83 assert_equals(parent.childNodes[1].textContent, 'text'); | |
84 assert_equals(parent.childNodes[2], child); | |
85 } | |
86 }, nodeName + '.prepend() with one element and text as argument, on a parent having a child.'); | |
87 } | |
88 | |
89 test_prepend(document.createElement('div'), 'Element'); | |
90 test_prepend(document, 'Document'); | |
91 test_prepend(document.createDocumentFragment(), 'DocumentFrgment'); | |
92 </script> | |
93 </html> | |
OLD | NEW |