OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
5 <script src="resources/shadow-dom.js"></script> | 5 <script src="resources/shadow-dom.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 | 8 |
9 <div id="container"></div> | 9 <div id="container"></div> |
10 <pre id="console"></pre> | 10 <pre id="console"></pre> |
11 | 11 |
12 <script> | 12 <script> |
13 description("getDistributedNodes() shouldn't work unless it is inDocument"); | 13 description("getDistributedNodes() should work out of Document"); |
14 | 14 |
15 function assertNodeList(nodeList, expectedNodes) | 15 function assertNodeList(nodeList, expectedNodes) |
16 { | 16 { |
17 window.nodeList = nodeList; | 17 window.nodeList = nodeList; |
18 window.expectedNodes = expectedNodes; | 18 window.expectedNodes = expectedNodes; |
19 shouldBe("nodeList.length", "expectedNodes.length"); | 19 shouldBe("nodeList.length", "expectedNodes.length"); |
20 for (var i = 0; i < nodeList.length; ++i) { | 20 for (var i = 0; i < nodeList.length; ++i) { |
21 shouldBe("nodeList.item(" + i + ")", "expectedNodes[" + i + "]"); | 21 shouldBe("nodeList.item(" + i + ")", "expectedNodes[" + i + "]"); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 var host = document.createElement('div'); | 25 var host = document.createElement('div'); |
26 var shadowRoot = host.createShadowRoot(); | 26 var shadowRoot = host.createShadowRoot(); |
27 var child = document.createElement('div'); | 27 var child = document.createElement('div'); |
28 var rootChild = document.createElement('div'); | 28 var rootChild = document.createElement('div'); |
29 var content = document.createElement('content'); | 29 var content = document.createElement('content'); |
30 | 30 |
31 host.appendChild(child); | 31 host.appendChild(child); |
32 rootChild.appendChild(content); | 32 rootChild.appendChild(content); |
33 shadowRoot.appendChild(rootChild); | 33 shadowRoot.appendChild(rootChild); |
34 | 34 |
| 35 debug('getDistributedNodes() should work out of Document'); |
| 36 assertNodeList(content.getDistributedNodes(), [child]); |
| 37 debug(''); |
| 38 |
| 39 debug('When a content element is disconnected from ShadowRoot, it should not wor
k.'); |
| 40 shadowRoot.removeChild(rootChild); |
35 assertNodeList(content.getDistributedNodes(), []); | 41 assertNodeList(content.getDistributedNodes(), []); |
36 debug(''); | 42 debug(''); |
| 43 |
| 44 debug('Reprojection case'); |
| 45 shadowRoot.appendChild(rootChild); |
| 46 var shadowRoot2 = rootChild.createShadowRoot(); |
| 47 var content2 = document.createElement('content'); |
| 48 var rootChildChild = document.createElement('div'); |
| 49 shadowRoot2.appendChild(content2); |
| 50 rootChild.appendChild(rootChildChild); |
| 51 |
| 52 assertNodeList(content.getDistributedNodes(), [child]); |
| 53 assertNodeList(content2.getDistributedNodes(), [child, rootChildChild]); |
| 54 debug(''); |
| 55 |
| 56 debug('rootChild is disconnected. Now content became inactive, so content elemen
t itself should be distributed.'); |
| 57 shadowRoot.removeChild(rootChild); |
| 58 assertNodeList(content.getDistributedNodes(), []); |
| 59 assertNodeList(content2.getDistributedNodes(), [content, rootChildChild]); |
| 60 debug(''); |
37 </script> | 61 </script> |
38 </body> | 62 </body> |
39 </html> | 63 </html> |
OLD | NEW |