summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/shadow/content-element-includer.html
blob: 84676e4fbab3589df9ae4cafa1af73aceee81161 (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
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<pre id="console">
This tests the correctness of includers of forwarded children.
Note that this test needs internals object thus cannot run outside DRT.
</pre>
<div id="container"></div>
<script>
function includerFor(element) {
    var insertionPoints = element.getDestinationInsertionPoints();
    if (insertionPoints.length == 0)
        return null;
    return insertionPoints.item(insertionPoints.length - 1);
}
var container = document.getElementById("container");

var shadowRoot = null;

var elementWithoutShadow = document.createElement("div");
container.appendChild(elementWithoutShadow);
var childOfElementWithoutShadow = document.createElement("span");
elementWithoutShadow.appendChild(childOfElementWithoutShadow);
container.offsetLeft;
shouldBe("includerFor(childOfElementWithoutShadow)", "null");

var elementWithShadow = document.createElement("div");
container.appendChild(elementWithShadow);
var shadowRootOfElementWithShadow = elementWithShadow.createShadowRoot();
shadowRootOfElementWithShadow.appendChild(document.createElement("div")); // Gives non-content child.
var childOfElementWithShadow = document.createElement("span");
elementWithShadow.appendChild(childOfElementWithShadow);
container.offsetLeft;
shouldBe("includerFor(childOfElementWithShadow)", "null");

var elementWithShadowContent = document.createElement("div");
container.appendChild(elementWithShadowContent);
var shadowRootOfElementWithShadowContent = elementWithShadowContent.createShadowRoot();
var shadowContentOfElementWithShadowContent = document.createElement('content');
shadowRootOfElementWithShadowContent.appendChild(shadowContentOfElementWithShadowContent);
var childOfElementWithShadowContent = document.createElement("span");
elementWithShadowContent.appendChild(childOfElementWithShadowContent);
container.offsetLeft;
shouldBe("includerFor(childOfElementWithShadowContent)", "shadowContentOfElementWithShadowContent");

//
// Testing dynamic change
//
var movingChild = childOfElementWithShadowContent;

// Removing
elementWithShadowContent.removeChild(movingChild);
shouldBe("includerFor(movingChild)", "null");

// Moving to content-less tree
elementWithShadow.appendChild(movingChild);
shouldBe("includerFor(movingChild)", "null");
elementWithShadow.removeChild(movingChild);

// Moving to another content-full tree
var anotherElementWithShadowContent = document.createElement("div");
container.appendChild(anotherElementWithShadowContent);
var anotherShadowRootOfElementWithShadowContent = anotherElementWithShadowContent.createShadowRoot();
var anotherShadowContentOfElementWithShadowContent = document.createElement('content');
anotherShadowRootOfElementWithShadowContent.appendChild(anotherShadowContentOfElementWithShadowContent);

anotherElementWithShadowContent.appendChild(movingChild);
container.offsetLeft;
shouldBe("includerFor(movingChild)", "anotherShadowContentOfElementWithShadowContent");
</script>
</body>
</html>