summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/shadow/olderShadowRoot-in-shadowelement.html
blob: 8ad1ddc5717d5a944e06e388d895f98b0945b261 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<body>
<script src="../../js/resources/js-test-pre.js"></script>

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

<script>
description('Confirms shadow.olderShadowRoot returns correct ShadowRoot');

function testCase(f)
{
    host = document.createElement('div');
    oldestShadowRoot = host.createShadowRoot();
    youngerShadowRoot = host.createShadowRoot();

    container.appendChild(host);

    f();

    container.innerHTML = "";
    debug('');
}

testCase(function()
{
    debug('shadow in younger ShadowDOM');
    shadow = document.createElement('shadow');
    youngerShadowRoot.appendChild(shadow);

    shouldBe('shadow.olderShadowRoot', 'oldestShadowRoot');
});

testCase(function()
{
    debug('shadow in the oldest ShadowDOM');
    shadow = document.createElement('shadow');
    oldestShadowRoot.appendChild(shadow);

    shouldBe('shadow.olderShadowRoot', 'null');
});

testCase(function()
{
    debug('2 active shadows');
    shadow1 = document.createElement('shadow');
    shadow2 = document.createElement('shadow');
    youngerShadowRoot.appendChild(shadow1);
    youngerShadowRoot.appendChild(shadow2);

    shouldBe('shadow1.olderShadowRoot', 'oldestShadowRoot');
    shouldBe('shadow2.olderShadowRoot', 'null');
});

testCase(function()
{
    debug('the first shadow is not active');
    shadow1 = document.createElement('shadow');
    shadow2 = document.createElement('shadow');

    var content = document.createElement('content');
    content.appendChild(shadow1);

    youngerShadowRoot.appendChild(content);
    youngerShadowRoot.appendChild(shadow2);

    shouldBe('shadow1.olderShadowRoot', 'null');
    shouldBe('shadow2.olderShadowRoot', 'oldestShadowRoot');
});

testCase(function()
{
    debug('nested ShadowDOM case');
    nestedHost = document.createElement('div');
    nestedOldestShadowRoot = nestedHost.createShadowRoot();
    nestedYoungerShadowRoot = nestedHost.createShadowRoot();
    oldestShadowRoot.appendChild(nestedHost);

    shadow1 = document.createElement('shadow');
    shadow2 = document.createElement('shadow');
    nestedOldestShadowRoot.appendChild(shadow1);
    nestedYoungerShadowRoot.appendChild(shadow2);

    shouldBe('shadow1.olderShadowRoot', 'null');
    shouldBe('shadow2.olderShadowRoot', 'nestedOldestShadowRoot');
});

testCase(function()
{
    debug('orphan shadow');
    shadow = document.createElement('shadow');
    shouldBe('shadow.olderShadowRoot', 'null');
});

testCase(function()
{
    debug('orphan Shadow DOM');
    shadow = document.createElement('shadow');
    youngerShadowRoot.appendChild(shadow);

    container.removeChild(host);

    shouldBe('shadow.olderShadowRoot', 'oldestShadowRoot');
});

container.innerHTML = '';
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>