File: test_CSSStyleRule_getScopeRootFor.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (215 lines) | stat: -rw-r--r-- 6,028 bytes parent folder | download | duplicates (3)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1894251
-->
<title>Test for CSSStyleRule::getScopeRootFor with @scope</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>

<main id=main></main>

<template id=test_unscoped>
  <style id=s>
    .a .b .c .d {
        color: green;
    }
  </style>
  <div class=a>
    <div class=b>
      <div id=notMatching class=c>
        <div id=matching class=d></div>
      </div>
    </div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_unscoped.content.cloneNode(true));

  const unscopedRule = s.sheet.cssRules[0];

  const scopeRootForNotMatching = unscopedRule.getScopeRootFor(0, notMatching);
  const scopeRootForMatching = unscopedRule.getScopeRootFor(0, matching);
  
  is(scopeRootForNotMatching, null, "Scope root for element not matching unscoped rule is null");
  is(scopeRootForMatching, null, "Scope root for element matching unscoped rule is null");
});
</script>

<template id=test_scoped_explicit_simple>
  <style id=s>
    @scope(.a) {
      > #b {
        color: green;
      }

      #c {
        color: red;
      }
    }
  </style>
  <div id=root class=a>
    <div id=b></div>
    <div><div><div id=c></div></div></div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_scoped_explicit_simple.content.cloneNode(true));

  const scopeRule = s.sheet.cssRules[0];
  const bRule = scopeRule.cssRules[0];
  const cRule = scopeRule.cssRules[1];

  const cScopeRootWithBRule = bRule.getScopeRootFor(0, c);
  const bScopeRootWithCRule = cRule.getScopeRootFor(0, b);
  
  is(cScopeRootWithBRule, null, "Scope root for #b scoped rule with #c is null");
  is(bScopeRootWithCRule, null, "Scope root for #c scoped rule with #b is null");

  const bScopeRoot = bRule.getScopeRootFor(0, b);
  const cScopeRoot = cRule.getScopeRootFor(0, c);

  is(bScopeRoot, root, "Scope root for #b is #root");
  is(cScopeRoot, root, "Scope root for #c is #root");
});
</script>

<template id=test_scoped_implicit>
  <div id=root>
    <style id=s>
      @scope {
        > #b {
          color: green;
        }

        #c {
          color: red;
        }
      }
    </style>
    <div id=b></div>
    <div><div><div id=c></div></div></div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_scoped_implicit.content.cloneNode(true));

  const scopeRule = s.sheet.cssRules[0];
  const bRule = scopeRule.cssRules[0];
  const cRule = scopeRule.cssRules[1];

  const cScopeRootWithBRule = bRule.getScopeRootFor(0, c);
  const bScopeRootWithCRule = cRule.getScopeRootFor(0, b);
  
  is(cScopeRootWithBRule, null, "Scope root for #b scoped rule with #c is null");
  is(bScopeRootWithCRule, null, "Scope root for #c scoped rule with #b is null");

  const bScopeRoot = bRule.getScopeRootFor(0, b);
  const cScopeRoot = cRule.getScopeRootFor(0, c);

  is(bScopeRoot, root, "Implicit scope root for #b is #root");
  is(cScopeRoot, root, "Implicit scope root for #c is #root");
});
</script>

<template id=test_scoped_explicit_with_end>
  <style id=s>
    @scope(.a) to (.b) {
      .c {
        color: green;
      }
    }
  </style>
  <div id=root class=a>
    <div id=inScope class=c></div>
    <div class=b>
      <div id=outOfScope class=c></div>
    </div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_scoped_explicit_with_end.content.cloneNode(true));

  const scopeRule = s.sheet.cssRules[0];
  const cRule = scopeRule.cssRules[0];

  const inScopeRoot = cRule.getScopeRootFor(0, inScope);
  const outOfScopeRoot = cRule.getScopeRootFor(0, outOfScope);

  is(inScopeRoot, root, "#inScope finds the root");
  is(outOfScopeRoot, null, "#outOfScope is out of scope due to scope-end selector");
});
</script>

<template id=test_scoped_different_roots>
  <style id=s>
    @scope(.a) {
      :scope:not(.b) > .c {
        color: green;
      }
      :scope.b .c {
        color: red;
      }
    }
  </style>
  <div id=root1 class=a>
    <div id=e1 class=c></div>
    <div id=root2 class="a b">
      <div id=e2 class=c></div>
    </div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_scoped_different_roots.content.cloneNode(true));

  const scopeRule = s.sheet.cssRules[0];
  const root1Rule = scopeRule.cssRules[0];
  const root2Rule = scopeRule.cssRules[1];

  const e1ScopeRoot = root1Rule.getScopeRootFor(0, e1);
  const e2ScopeRoot = root2Rule.getScopeRootFor(0, e2);

  is(e1ScopeRoot, root1, "Scope root of #e1 is #root1");
  is(e2ScopeRoot, root2, "Scope root of #e2 is #root2");
});
</script>

<template id=test_scoped_different_roots_different_selectors>
  <style id=s>
    @scope(.a) {
      :scope > .c, :scope > .b > .c  {
        color: green;
      }
    }
  </style>
  <div id=root2 class=a>
    <div id=root1 class="a b">
      <div id=e class=c></div>
    </div>
  </div>
</template>
<script>
add_task(async () => {
  SimpleTest.registerCurrentTaskCleanupFunction(async () => main.replaceChildren());
  main.append(test_scoped_different_roots_different_selectors.content.cloneNode(true));

  const scopeRule = s.sheet.cssRules[0];
  const styleRule = scopeRule.cssRules[0];

  const scopeRootForSelector0 = styleRule.getScopeRootFor(0, e);
  const scopeRootForSelector1 = styleRule.getScopeRootFor(1, e);

  is(scopeRootForSelector0, root1, "Scope root of #e given selector 0 is #root1");
  is(scopeRootForSelector1, root2, "Scope root of #e given selector 1 is #root1");

});
</script>