OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset=utf-8> |
| 5 <title>Node.prototype.getRootNode()</title> |
| 6 <link rel="help" href="https://dom.spec.whatwg.org/#dom-node-getrootnode"> |
| 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.getRootNode(), element, 'getRootNode() on an element w
ithout a parent must return the element itself'); |
| 16 |
| 17 var text = document.createTextNode(''); |
| 18 assert_equals(text.getRootNode(), text, 'getRootNode() on a text node withou
t a parent must return the text node itself'); |
| 19 |
| 20 var processingInstruction = document.createProcessingInstruction('target', '
data'); |
| 21 assert_equals(processingInstruction.getRootNode(), processingInstruction, 'g
etRootNode() on a processing instruction node without a parent must return the p
rocessing instruction node itself'); |
| 22 |
| 23 assert_equals(document.getRootNode(), document, 'getRootNode() on a document
node must return the document itself'); |
| 24 |
| 25 }, 'getRootNode() must return the context object when it does not have any paren
t'); |
| 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.getRootNode(), parent, 'getRootNode() on an element wi
th a single ancestor must return the parent node'); |
| 33 |
| 34 var text = document.createTextNode(''); |
| 35 parent.appendChild(text); |
| 36 assert_equals(text.getRootNode(), parent, 'getRootNode() 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.getRootNode(), parent, 'getRootNode() on
a processing instruction node with a single ancestor must return the parent nod
e'); |
| 41 |
| 42 }, 'getRootNode() must return the parent node of the context object when the con
text 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.getRootNode(), document, 'getRootNode() on an element
inside a document must return the document'); |
| 51 |
| 52 var text = document.createTextNode(''); |
| 53 parent.appendChild(text); |
| 54 assert_equals(text.getRootNode(), document, 'getRootNode() on a text node in
side a document must return the document'); |
| 55 |
| 56 var processingInstruction = document.createProcessingInstruction('target', '
data'); |
| 57 parent.appendChild(processingInstruction) |
| 58 assert_equals(processingInstruction.getRootNode(), document, 'getRootNode()
on a processing instruction node inside a document must return the document'); |
| 59 }, 'getRootNode() 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.getRootNode(), fragment, 'getRootNode() on an element
inside a document fragment must return the fragment'); |
| 69 |
| 70 var text = document.createTextNode(''); |
| 71 parent.appendChild(text); |
| 72 assert_equals(text.getRootNode(), fragment, 'getRootNode() on a text node in
side a document fragment must return the fragment'); |
| 73 |
| 74 var processingInstruction = document.createProcessingInstruction('target', '
data'); |
| 75 parent.appendChild(processingInstruction) |
| 76 assert_equals(processingInstruction.getRootNode(), fragment, |
| 77 'getRootNode() on a processing instruction node inside a document fragme
nt must return the fragment'); |
| 78 }, 'getRootNode() must return a document fragment when a node is in the fragment
'); |
| 79 |
| 80 </script> |
| 81 </body> |
| 82 </html> |
OLD | NEW |