4 <title>DOM: 4.4. Interface Node</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="Node interface must have rootNode attribute">
7 <link rel="help" href="https://dom.spec.whatwg.org/#dom-node-rootnode">
8 <script src="../../../resources/testharness.js"></script>
9 <script src="../../../resources/testharnessreport.js"></script>
10 <link rel='stylesheet' href='../../../resources/testharness.css'>
17 assert_true('rootNode' in Node.prototype, 'rootNode must be defined on Node.prototype');
18 assert_true('rootNode' in document.createElement('div'), 'rootNode must be defined on a div element');
19 assert_true('rootNode' in document.createTextNode(''), 'rootNode must be defined on a text node');
20 assert_true('rootNode' in document.createComment(''), 'rootNode must be defined on a comment node');
21 assert_true('rootNode' in document.createProcessingInstruction('target', 'data'), 'rootNode must be defined on a processing instruction node');
22 assert_true('rootNode' in document, 'rootNode must be defined on a document node');
23 }, 'rootNode attribute must be defined on Node interface');
26 var element = document.createElement('div');
27 assert_equals(element.rootNode, element, 'rootNode on an element without a parent must return the element itself');
29 var text = document.createTextNode('');
30 assert_equals(text.rootNode, text, 'rootNode on a text node without a parent must return the text node itself');
32 var processingInstruction = document.createProcessingInstruction('target', 'data');
33 assert_equals(processingInstruction.rootNode, processingInstruction, 'rootNode on a processing instruction node without a parent must return the processing instruction node itself');
35 assert_equals(document.rootNode, document, 'rootNode on a document node must return the document itself');
37 }, 'rootNode attribute must return the context object when it does not have any parent');
40 var parent = document.createElement('div');
42 var element = document.createElement('div');
43 parent.appendChild(element);
44 assert_equals(element.rootNode, parent, 'rootNode on an element with a single ancestor must return the parent node');
46 var text = document.createTextNode('');
47 parent.appendChild(text);
48 assert_equals(text.rootNode, parent, 'rootNode on a text node with a single ancestor must return the parent node');
50 var processingInstruction = document.createProcessingInstruction('target', 'data');
51 parent.appendChild(processingInstruction)
52 assert_equals(processingInstruction.rootNode, parent, 'rootNode on a processing instruction node with a single ancestor must return the parent node');
54 }, 'rootNode attribute must return the parent node of the context object when the context object has a single ancestor not in a document');
57 var parent = document.createElement('div');
58 document.body.appendChild(parent);
60 var element = document.createElement('div');
61 parent.appendChild(element);
62 assert_equals(element.rootNode, document, 'rootNode on an element inside a document must return the document');
64 var text = document.createTextNode('');
65 parent.appendChild(text);
66 assert_equals(text.rootNode, document, 'rootNode on a text node inside a document must return the document');
68 var processingInstruction = document.createProcessingInstruction('target', 'data');
69 parent.appendChild(processingInstruction)
70 assert_equals(processingInstruction.rootNode, document, 'rootNode on a processing instruction node inside a document must return the document');
71 }, 'rootNode attribute must return the document when a node is in document');
74 var fragment = document.createDocumentFragment();
75 var parent = document.createElement('div');
76 fragment.appendChild(parent);
78 var element = document.createElement('div');
79 parent.appendChild(element);
80 assert_equals(element.rootNode, fragment, 'rootNode on an element inside a document fragment must return the fragment');
82 var text = document.createTextNode('');
83 parent.appendChild(text);
84 assert_equals(text.rootNode, fragment, 'rootNode on a text node inside a document fragment must return the fragment');
86 var processingInstruction = document.createProcessingInstruction('target', 'data');
87 parent.appendChild(processingInstruction)
88 assert_equals(processingInstruction.rootNode, fragment,
89 'rootNode on a processing instruction node inside a document fragment must return the fragment');
90 }, 'rootNode attribute must return a document fragment when a node is in the fragment');