OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <meta charset=utf-8> | |
5 <title>Node.prototype.rootNode</title> | |
6 <link rel="help" href="https://dom.spec.whatwg.org/#dom-node-rootnode"> | |
7 <script src="/resources/testharness.js"></script> | |
8 <script src="/resources/testharnessreport.js"></script> | |
9 </head> | |
10 <body> | |
11 <script> | |
12 | |
13 test(function () { | |
14 var element = document.createElement('div'); | |
15 assert_equals(element.rootNode, element, 'rootNode on an element without a p
arent must return the element itself'); | |
16 | |
17 var text = document.createTextNode(''); | |
18 assert_equals(text.rootNode, text, 'rootNode on a text node without a parent
must return the text node itself'); | |
19 | |
20 var processingInstruction = document.createProcessingInstruction('target', '
data'); | |
21 assert_equals(processingInstruction.rootNode, processingInstruction, 'rootNo
de on a processing instruction node without a parent must return the processing
instruction node itself'); | |
22 | |
23 assert_equals(document.rootNode, document, 'rootNode on a document node must
return the document itself'); | |
24 | |
25 }, 'rootNode attribute must return the context object when it does not have any
parent'); | |
26 | |
27 test(function () { | |
28 var parent = document.createElement('div'); | |
29 | |
30 var element = document.createElement('div'); | |
31 parent.appendChild(element); | |
32 assert_equals(element.rootNode, parent, 'rootNode on an element with a singl
e ancestor must return the parent node'); | |
33 | |
34 var text = document.createTextNode(''); | |
35 parent.appendChild(text); | |
36 assert_equals(text.rootNode, parent, 'rootNode on a text node with a single
ancestor must return the parent node'); | |
37 | |
38 var processingInstruction = document.createProcessingInstruction('target', '
data'); | |
39 parent.appendChild(processingInstruction) | |
40 assert_equals(processingInstruction.rootNode, parent, 'rootNode on a process
ing instruction node with a single ancestor must return the parent node'); | |
41 | |
42 }, 'rootNode attribute must return the parent node of the context object when th
e context object has a single ancestor not in a document'); | |
43 | |
44 test(function () { | |
45 var parent = document.createElement('div'); | |
46 document.body.appendChild(parent); | |
47 | |
48 var element = document.createElement('div'); | |
49 parent.appendChild(element); | |
50 assert_equals(element.rootNode, document, 'rootNode on an element inside a d
ocument must return the document'); | |
51 | |
52 var text = document.createTextNode(''); | |
53 parent.appendChild(text); | |
54 assert_equals(text.rootNode, document, 'rootNode on a text node inside a doc
ument must return the document'); | |
55 | |
56 var processingInstruction = document.createProcessingInstruction('target', '
data'); | |
57 parent.appendChild(processingInstruction) | |
58 assert_equals(processingInstruction.rootNode, document, 'rootNode on a proce
ssing instruction node inside a document must return the document'); | |
59 }, 'rootNode attribute must return the document when a node is in document'); | |
60 | |
61 test(function () { | |
62 var fragment = document.createDocumentFragment(); | |
63 var parent = document.createElement('div'); | |
64 fragment.appendChild(parent); | |
65 | |
66 var element = document.createElement('div'); | |
67 parent.appendChild(element); | |
68 assert_equals(element.rootNode, fragment, 'rootNode on an element inside a d
ocument fragment must return the fragment'); | |
69 | |
70 var text = document.createTextNode(''); | |
71 parent.appendChild(text); | |
72 assert_equals(text.rootNode, fragment, 'rootNode on a text node inside a doc
ument fragment must return the fragment'); | |
73 | |
74 var processingInstruction = document.createProcessingInstruction('target', '
data'); | |
75 parent.appendChild(processingInstruction) | |
76 assert_equals(processingInstruction.rootNode, fragment, | |
77 'rootNode on a processing instruction node inside a document fragment mu
st return the fragment'); | |
78 }, 'rootNode attribute must return a document fragment when a node is in the fra
gment'); | |
79 | |
80 </script> | |
81 </body> | |
82 </html> | |
OLD | NEW |