| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <div id="host-parent"> |
| 5 <div id="host"> |
| 6 </div> |
| 7 <div id="slotted"></div> |
| 8 </div> |
| 9 <div id="host-parent2"> |
| 10 <div id="host2"> |
| 11 </div> |
| 12 <div id="distributed" id="distributed"></div> |
| 13 </div> |
| 14 |
| 15 <script> |
| 16 var hostParent = document.getElementById('host-parent'); |
| 17 var host = document.getElementById('host'); |
| 18 var slotted = document.getElementById('slotted'); |
| 19 var root = host.attachShadow({mode: 'open'}); |
| 20 var child = document.createElement('div'); |
| 21 var grandchild = document.createElement('div'); |
| 22 var slot = document.createElement('slot'); |
| 23 slot.setAttribute('name', 'slot'); |
| 24 slotted.setAttribute('slot', 'slot'); |
| 25 child.setAttribute('id', 'child'); |
| 26 grandchild.setAttribute('id', 'grandchild'); |
| 27 root.appendChild(child); |
| 28 child.appendChild(grandchild); |
| 29 grandchild.appendChild(slot); |
| 30 |
| 31 test(function() { |
| 32 assert_equals(document.treeRoot, document); |
| 33 assert_equals(hostParent.treeRoot, document); |
| 34 assert_equals(host.treeRoot, document); |
| 35 assert_equals(root.treeRoot, root); |
| 36 assert_equals(child.treeRoot, root); |
| 37 assert_equals(grandchild.treeRoot, root); |
| 38 assert_equals(slot.treeRoot, root); |
| 39 assert_equals(slotted.treeRoot, document); |
| 40 }, 'Node.treeRoot returns a root of the tree that the node belongs to, or the sh
adow root if the tree is a shadow tree.'); |
| 41 |
| 42 test(function() { |
| 43 var nestedChild = document.createElement('div'); |
| 44 var nestedRoot = grandchild.attachShadow({mode: 'open'}); |
| 45 nestedRoot.appendChild(nestedChild); |
| 46 |
| 47 assert_equals(nestedRoot.treeRoot, nestedRoot); |
| 48 assert_equals(nestedChild.treeRoot, nestedRoot); |
| 49 }, 'Node.treeRoot works with a nested shadow tree.'); |
| 50 |
| 51 test(function() { |
| 52 var detached = document.createElement('div'); |
| 53 var detachedChild = document.createElement('div'); |
| 54 detached.appendChild(detachedChild); |
| 55 |
| 56 assert_equals(detached.treeRoot, detached); |
| 57 assert_equals(detachedChild.treeRoot, detached); |
| 58 }, 'Node.treeRoot works with a detached tree as well.'); |
| 59 |
| 60 test(function() { |
| 61 var hostParent2 = document.getElementById('host-parent2'); |
| 62 var host2 = document.getElementById('host2'); |
| 63 var distributed = document.getElementById('distributed'); |
| 64 var root2 = host2.createShadowRoot(); |
| 65 var child2 = document.createElement('div'); |
| 66 var grandchild2 = document.createElement('div'); |
| 67 var content = document.createElement('content'); |
| 68 content.setAttribute('select', '#distributed'); |
| 69 child2.setAttribute('id', 'child2'); |
| 70 grandchild2.setAttribute('id', 'grandchild2'); |
| 71 root2.appendChild(child2); |
| 72 child2.appendChild(grandchild2); |
| 73 grandchild2.appendChild(content); |
| 74 |
| 75 assert_equals(hostParent2.treeRoot, document); |
| 76 assert_equals(host2.treeRoot, document); |
| 77 assert_equals(root2.treeRoot, root2); |
| 78 assert_equals(child2.treeRoot, root2); |
| 79 assert_equals(grandchild2.treeRoot, root2); |
| 80 assert_equals(content.treeRoot, root2); |
| 81 assert_equals(distributed.treeRoot, document); |
| 82 }, 'Node.treeRoot works with a v0 shadow tree as well.'); |
| 83 |
| 84 </script> |
| OLD | NEW |