summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/shadow/get-distributed-nodes-orphan.html
blob: 428e724ac80ac8d7bd0863857d768f43fd4b899d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/shadow-dom.js"></script>
</head>
<body>

<div id="container"></div>
<pre id="console"></pre>

<script>
description("getDistributedNodes() should work out of Document");

function assertNodeList(nodeList, expectedNodes)
{
    window.nodeList = nodeList;
    window.expectedNodes = expectedNodes;
    shouldBe("nodeList.length", "expectedNodes.length");
    for (var i = 0; i < nodeList.length; ++i) {
        shouldBe("nodeList.item(" + i + ")", "expectedNodes[" + i + "]");
    }
}

var host = document.createElement('div');
var shadowRoot = host.createShadowRoot();
var child = document.createElement('div');
var rootChild = document.createElement('div');
var content = document.createElement('content');

host.appendChild(child);
rootChild.appendChild(content);
shadowRoot.appendChild(rootChild);

debug('getDistributedNodes() should work out of Document');
assertNodeList(content.getDistributedNodes(), [child]);
debug('');

debug('When a content element is disconnected from ShadowRoot, it should not work.');
shadowRoot.removeChild(rootChild);
assertNodeList(content.getDistributedNodes(), []);
debug('');

debug('Reprojection case');
shadowRoot.appendChild(rootChild);
var shadowRoot2 = rootChild.createShadowRoot();
var content2 = document.createElement('content');
var rootChildChild = document.createElement('div');
shadowRoot2.appendChild(content2);
rootChild.appendChild(rootChildChild);

assertNodeList(content.getDistributedNodes(), [child]);
assertNodeList(content2.getDistributedNodes(), [child, rootChildChild]);
debug('');

debug('rootChild is disconnected. Now content became inactive, so content element itself should be distributed.');
shadowRoot.removeChild(rootChild);
assertNodeList(content.getDistributedNodes(), []);
assertNodeList(content2.getDistributedNodes(), [content, rootChildChild]);
debug('');
</script>
</body>
</html>