OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Node.parentElement</title> |
| 3 <link rel="stylesheet" href="../../../../resources/testharness.css"> |
| 4 <script src="../../../../resources/testharness.js"></script> |
| 5 <script src="../../../../resources/testharnessreport.js"></script> |
| 6 <div id="log"></div> |
| 7 <script> |
| 8 test(function() { |
| 9 assert_equals(document.parentElement, null) |
| 10 }, "When the parent is null, parentElement should be null") |
| 11 test(function() { |
| 12 assert_equals(document.doctype.parentElement, null) |
| 13 }, "When the parent is a document, parentElement should be null (doctype)") |
| 14 test(function() { |
| 15 assert_equals(document.documentElement.parentElement, null) |
| 16 }, "When the parent is a document, parentElement should be null (element)") |
| 17 test(function() { |
| 18 var comment = document.appendChild(document.createComment("foo")) |
| 19 assert_equals(comment.parentElement, null) |
| 20 }, "When the parent is a document, parentElement should be null (comment)") |
| 21 test(function() { |
| 22 var df = document.createDocumentFragment() |
| 23 assert_equals(df.parentElement, null) |
| 24 var el = document.createElement("div") |
| 25 assert_equals(el.parentElement, null) |
| 26 df.appendChild(el) |
| 27 assert_equals(el.parentNode, df) |
| 28 assert_equals(el.parentElement, null) |
| 29 }, "parentElement should return null for children of DocumentFragments (element)
") |
| 30 test(function() { |
| 31 var df = document.createDocumentFragment() |
| 32 assert_equals(df.parentElement, null) |
| 33 var text = document.createTextNode("bar") |
| 34 assert_equals(text.parentElement, null) |
| 35 df.appendChild(text) |
| 36 assert_equals(text.parentNode, df) |
| 37 assert_equals(text.parentElement, null) |
| 38 }, "parentElement should return null for children of DocumentFragments (text)") |
| 39 test(function() { |
| 40 var df = document.createDocumentFragment() |
| 41 var parent = document.createElement("div") |
| 42 df.appendChild(parent) |
| 43 var el = document.createElement("div") |
| 44 assert_equals(el.parentElement, null) |
| 45 parent.appendChild(el) |
| 46 assert_equals(el.parentElement, parent) |
| 47 }, "parentElement should work correctly with DocumentFragments (element)") |
| 48 test(function() { |
| 49 var df = document.createDocumentFragment() |
| 50 var parent = document.createElement("div") |
| 51 df.appendChild(parent) |
| 52 var text = document.createTextNode("bar") |
| 53 assert_equals(text.parentElement, null) |
| 54 parent.appendChild(text) |
| 55 assert_equals(text.parentElement, parent) |
| 56 }, "parentElement should work correctly with DocumentFragments (text)") |
| 57 test(function() { |
| 58 var parent = document.createElement("div") |
| 59 var el = document.createElement("div") |
| 60 assert_equals(el.parentElement, null) |
| 61 parent.appendChild(el) |
| 62 assert_equals(el.parentElement, parent) |
| 63 }, "parentElement should work correctly in disconnected subtrees (element)") |
| 64 test(function() { |
| 65 var parent = document.createElement("div") |
| 66 var text = document.createTextNode("bar") |
| 67 assert_equals(text.parentElement, null) |
| 68 parent.appendChild(text) |
| 69 assert_equals(text.parentElement, parent) |
| 70 }, "parentElement should work correctly in disconnected subtrees (text)") |
| 71 test(function() { |
| 72 var el = document.createElement("div") |
| 73 assert_equals(el.parentElement, null) |
| 74 document.body.appendChild(el) |
| 75 assert_equals(el.parentElement, document.body) |
| 76 }, "parentElement should work correctly in a document (element)") |
| 77 test(function() { |
| 78 var text = document.createElement("div") |
| 79 assert_equals(text.parentElement, null) |
| 80 document.body.appendChild(text) |
| 81 assert_equals(text.parentElement, document.body) |
| 82 }, "parentElement should work correctly in a document (text)") |
| 83 </script> |
OLD | NEW |