summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-cascade/scope-implicit.html
blob: c49abb0a389b76977c36e947ef63edaa8cf47672 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<title>@scope - implicit scope root</title>
<link rel="help" href="https://drafts.csswg.org/css-cascade-6/#scope-atrule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<main id=main></main>

<template id=test_basic>
  <div>
    <style>
      @scope {
        .a { z-index:1; }
      }
    </style>
    <div id=inner class=a></div>
  </div>
  <div id=outer class=a></div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_basic.content.cloneNode(true));

  assert_equals(getComputedStyle(inner).zIndex, '1');
  assert_equals(getComputedStyle(outer).zIndex, 'auto');
}, '@scope without prelude implicitly scopes to parent of owner node');
</script>

<template id=test_scope_pseudo>
  <div>
    <div></div>
  </div>
  <div>
    <div id=root>
      <style>
        @scope {
          :scope { z-index:1; }
        }
      </style>
      <div>
        <div></div>
      </div>
    </div>
  </div>
  <div>
    <div></div>
  </div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_scope_pseudo.content.cloneNode(true));

  assert_equals(getComputedStyle(root).zIndex, '1');

  // Only #root should be affected.
  for (let div of main.querySelectorAll('div:not(#root)')) {
    assert_equals(getComputedStyle(div).zIndex, 'auto');
  }
}, ':scope can style implicit root');
</script>

<template id=test_duplicate>
  <div>
    <style>
      @scope {
        .a { z-index:1; }
      }
    </style>
    <div id=first class=a></div>
  </div>
  <div>
    <style>
      @scope {
        .a { z-index:1; }
      }
    </style>
    <div id=second class=a></div>
  </div>
  <div id=outer class=a></div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_duplicate.content.cloneNode(true));

  assert_equals(getComputedStyle(first).zIndex, '1');
  assert_equals(getComputedStyle(second).zIndex, '1');
  assert_equals(getComputedStyle(outer).zIndex, 'auto');
}, '@scope works with two identical stylesheets');
</script>


<template id=test_forgiving>
  <div>
    <style>
      @scope ($invalid) {
        #a { z-index:1; }
      }
    </style>
    <div id=a></div>
  </div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_forgiving.content.cloneNode(true));

  assert_equals(getComputedStyle(a).zIndex, 'auto');
}, '@scope with effectively empty :is() must not match anything');
</script>

<template id=test_implicit_descendant>
  <div id=div>
    <style>
      @scope {
        #div { z-index:1; }
      }
    </style>
  </div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_implicit_descendant.content.cloneNode(true));

  assert_equals(getComputedStyle(div).zIndex, 'auto');
}, 'Implicit @scope has implicitly added :scope descendant combinator');
</script>

<template id=test_implicit_relative>
  <div id=outer>
    <style>
      @scope {
        > div { z-index:1; }
      }
    </style>
    <div id=child>
      <div id=inner></div>
    </div>
  </div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_implicit_relative.content.cloneNode(true));

  assert_equals(getComputedStyle(outer).zIndex, 'auto');
  assert_equals(getComputedStyle(child).zIndex, '1');
  assert_equals(getComputedStyle(inner).zIndex, 'auto');
}, 'Implicit @scope with inner relative selector');
</script>

<template id=test_implicit_descendant_nesting_selector>
  <div id=div>
    <style>
      @scope {
        /* Behaves like :scope */
        & { z-index:1; }
      }
    </style>
    <div id=inner></div>
  </div>
</template>
<script>
test((t) => {
  t.add_cleanup(() => main.replaceChildren());
  main.append(test_implicit_descendant_nesting_selector.content.cloneNode(true));

  assert_equals(getComputedStyle(div).zIndex, '1');
  assert_equals(getComputedStyle(inner).zIndex, 'auto');
}, 'Implicit @scope with inner nesting selector');
</script>