3 <script src=
"../../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../../http/tests/inspector/elements-test.js"></script>
6 function createShadowRootFromTemplate(root
, selector
, templateId
)
8 var shadowHost
= root
.querySelector(selector
);
9 var shadowRoot
= shadowHost
.createShadowRoot();
10 var template
= document
.querySelector(templateId
);
11 var clone
= document
.importNode(template
.content
, true);
12 shadowRoot
.appendChild(clone
);
16 function initOldestShadowRoot()
18 createShadowRootFromTemplate(document
, "#shadowHost", "#oldestShadowRootTemplate");
21 function initYoungestShadowRoot()
23 createShadowRootFromTemplate(document
, "#shadowHost", "#youngestShadowRootTemplate");
26 function initInnerShadowRoot()
28 var shadowHost
= document
.querySelector("#shadowHost");
29 var innerShadowHost
= createShadowRootFromTemplate(shadowHost
.shadowRoot
, ".innerShadowHost", "#innerShadowRootTemplate");
30 innerShadowHost
.id
= "innerShadowHost";
33 var lastDistributedNodeId
= 0;
35 function addDistributedNode(oldest
)
37 var node
= document
.createElement("div");
38 node
.classList
.add(oldest
? "distributeMeToOldest" : "distributeMeToYoungest");
39 node
.classList
.add("distributeMeAsWell_" + (++lastDistributedNodeId
));
40 var shadowHost
= document
.querySelector("#shadowHost");
41 shadowHost
.appendChild(node
);
44 function addDistributedNodeToOldest()
46 addDistributedNode(true);
53 var shadowHostTreeElement
;
54 var innerShadowHostNode
;
55 var innerShadowHostTreeElement
;
57 InspectorTest
.expandElementsTree(elementsTreeExpanded
);
59 function elementsTreeExpanded(node
)
61 treeOutline
= InspectorTest
.firstElementsTreeOutline();
62 shadowHostNode
= InspectorTest
.expandedNodeWithId("shadowHost");
63 shadowHostTreeElement
= treeOutline
.findTreeElement(shadowHostNode
)
64 expandAndDumpShadowHostNode("========= Original ========", originalElementsTreeDumped
);
67 function originalElementsTreeDumped(node
)
69 InspectorTest
.evaluateInPage("initOldestShadowRoot()", onOldestShadowRootInitialized
);
72 function onOldestShadowRootInitialized()
74 expandAndDumpShadowHostNode("========= After shadow root created ========", onOldestShadowRootDumped
);
77 function onOldestShadowRootDumped()
79 waitForModifiedNodesUpdate("After adding distributed node", distributedNodeChangedAfterFirstAdding
);
80 InspectorTest
.evaluateInPage("addDistributedNodeToOldest()");
83 function distributedNodeChangedAfterFirstAdding()
85 waitForModifiedNodesUpdate("After adding another distributed node", distributedNodeChangedAfterSecondAdding
);
86 InspectorTest
.evaluateInPage("addDistributedNodeToOldest()");
89 function distributedNodeChangedAfterSecondAdding()
91 waitForModifiedNodesUpdate("After adding youngest shadow root", distributedNodeChangedAfterAddingYoungestShadowRoot
);
92 InspectorTest
.evaluateInPage("initYoungestShadowRoot()");
95 function distributedNodeChangedAfterAddingYoungestShadowRoot()
97 waitForModifiedNodesUpdate("After adding inner shadow root node", distributedNodeChangedAfterAddingInnerShadowRoot
);
98 InspectorTest
.evaluateInPage("initInnerShadowRoot()");
101 function distributedNodeChangedAfterAddingInnerShadowRoot()
103 InspectorTest
.completeTest();
106 function waitForModifiedNodesUpdate(title
, next
)
108 InspectorTest
.addSniffer(WebInspector
.ElementsTreeOutline
.prototype, "_updateModifiedNodes", callback
);
112 expandAndDumpShadowHostNode("========= " + title
+ " ========", next
);
116 function expandAndDumpShadowHostNode(title
, next
)
118 InspectorTest
.addResult(title
);
119 InspectorTest
.expandElementsTree(callback
);
123 InspectorTest
.dumpElementsTree(shadowHostNode
);
130 <body onload=
"runTest()">
131 <p>Tests that distributed nodes and their updates are correctly shown in different shadow host display modes.
</p>
132 <template id=
"youngestShadowRootTemplate">
133 <div class=
"youngestShadowMain">
135 <content select=
".distributeMeToYoungest"><div id=
"fallbackYoungest"></div></content>
136 <div class=
"innerShadowHost">
137 <content in-youngest-shadow-root
select=
".distributeMeToInner"></content>
141 <template id=
"oldestShadowRootTemplate">
142 <div class=
"oldestShadowMain">
143 <content select=
".distributeMeToOldest"><div id=
"fallbackOldest"></div></content>
146 <template id=
"innerShadowRootTemplate">
147 <div class=
"innerShadowMain">
148 <content in-inner-shadow-root
select=
".distributeMeToInner"></content>
151 <div id=
"shadowHost">
152 <div class=
"distributeMeToYoungest original">
153 youngest distributed text
155 <div class=
"distributeMeToOldest original">
156 oldest distributed text
158 <div class=
"distributeMeToInner original">
159 oldest distributed text
161 <div class=
"distributeMeToInner original2">
162 oldest distributed text