4 <script src="../../../resources/js-test.js"></script>
8 This tests the correctness of includers of forwarded children.
9 Note that this test needs internals object thus cannot run outside DRT.
11 <div id="container"></div>
13 function includerFor(element) {
14 var insertionPoints = element.getDestinationInsertionPoints();
15 if (insertionPoints.length == 0)
17 return insertionPoints.item(insertionPoints.length - 1);
19 var container = document.getElementById("container");
21 var shadowRoot = null;
23 var elementWithoutShadow = document.createElement("div");
24 container.appendChild(elementWithoutShadow);
25 var childOfElementWithoutShadow = document.createElement("span");
26 elementWithoutShadow.appendChild(childOfElementWithoutShadow);
28 shouldBe("includerFor(childOfElementWithoutShadow)", "null");
30 var elementWithShadow = document.createElement("div");
31 container.appendChild(elementWithShadow);
32 var shadowRootOfElementWithShadow = elementWithShadow.createShadowRoot();
33 shadowRootOfElementWithShadow.appendChild(document.createElement("div")); // Gives non-content child.
34 var childOfElementWithShadow = document.createElement("span");
35 elementWithShadow.appendChild(childOfElementWithShadow);
37 shouldBe("includerFor(childOfElementWithShadow)", "null");
39 var elementWithShadowContent = document.createElement("div");
40 container.appendChild(elementWithShadowContent);
41 var shadowRootOfElementWithShadowContent = elementWithShadowContent.createShadowRoot();
42 var shadowContentOfElementWithShadowContent = document.createElement('content');
43 shadowRootOfElementWithShadowContent.appendChild(shadowContentOfElementWithShadowContent);
44 var childOfElementWithShadowContent = document.createElement("span");
45 elementWithShadowContent.appendChild(childOfElementWithShadowContent);
47 shouldBe("includerFor(childOfElementWithShadowContent)", "shadowContentOfElementWithShadowContent");
50 // Testing dynamic change
52 var movingChild = childOfElementWithShadowContent;
55 elementWithShadowContent.removeChild(movingChild);
56 shouldBe("includerFor(movingChild)", "null");
58 // Moving to content-less tree
59 elementWithShadow.appendChild(movingChild);
60 shouldBe("includerFor(movingChild)", "null");
61 elementWithShadow.removeChild(movingChild);
63 // Moving to another content-full tree
64 var anotherElementWithShadowContent = document.createElement("div");
65 container.appendChild(anotherElementWithShadowContent);
66 var anotherShadowRootOfElementWithShadowContent = anotherElementWithShadowContent.createShadowRoot();
67 var anotherShadowContentOfElementWithShadowContent = document.createElement('content');
68 anotherShadowRootOfElementWithShadowContent.appendChild(anotherShadowContentOfElementWithShadowContent);
70 anotherElementWithShadowContent.appendChild(movingChild);
72 shouldBe("includerFor(movingChild)", "anotherShadowContentOfElementWithShadowContent");