blob: c77dd0811fa5b90671798995a63d703d205d7d86 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.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.webkitCreateShadowRoot();
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.webkitCreateShadowRoot();
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>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>