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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
<!DOCTYPE HTML>
<meta charset="UTF-8">
<title>CSS Toggles: creation of toggles</title>
<link rel="author" title="L. David Baron" href="https://dbaron.org/">
<link rel="author" title="Google" href="http://www.google.com/">
<link rel="help" href="https://tabatkins.github.io/css-toggle/#checked-pseudoclass">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/parsing-testcommon.js"></script>
<script src="support/toggle-helpers.js"></script>
<body>
<div id="container"></div>
<script>
test_valid_selector(":toggle(my-toggle)");
test_valid_selector(":toggle(my-toggle 0)");
test_valid_selector(":toggle(my-toggle 1)");
test_valid_selector(":toggle( my-toggle 1 )", ":toggle(my-toggle 1)");
test_valid_selector(":toggle(my-toggle named-state)");
test_valid_selector(":toggle( my-toggle named-state )", ":toggle(my-toggle named-state)");
test_invalid_selector(":toggle(my-toggle, 0)");
test_invalid_selector(":toggle(my-toggle, named-state)");
test_invalid_selector(":toggle(my-toggle named-state 0)");
// In these tests, the following class attributes lead to markup creation:
// class=toggle, class=toggle-self, class=variant-toggle,
// class=variant-toggle-self. These all lead to the creation of a toggle
// called "markup-test". If "-self" is present then the toggle has narrow
// scope (otherwise wide scope). If "variant-" is present then the toggle has
// a value different from what the primary test assertions target (otherwise
// it is what the test assertions target).
//
// The following class attributes lead to test assertions:
// class=assert-match: Assert the :toggle() selector matches the toggle
// class=assert-no-match: Assert the :toggle() selector does not match the
// toggle.
// class=assert-variant-match: Assert the :toggle() selector matches the
// variant toggle.
let scope_search_tests = [
`
<div>
<div class="assert-no-match"></div>
<div class="toggle assert-match">
<div class="assert-match"></div>
</div>
<div class="assert-match"></div>
</div>
<div class="assert-no-match"></div>
`,
`
<div>
<div class="assert-no-match"></div>
<div class="toggle-self assert-match">
<div class="assert-match"></div>
</div>
<div class="assert-no-match"></div>
</div>
<div class="assert-no-match"></div>
`,
`
<div class="toggle"></div>
<div class="variant-toggle-self">
<div class="assert-variant-match"></div>
</div>
<div class="assert-match"></div>
`,
`
<div class="toggle"></div>
<div class="assert-match"></div>
<div class="variant-toggle">
<div class="assert-variant-match"></div>
</div>
<div class="assert-variant-match"></div>
`,
];
for (let t of scope_search_tests) {
promise_test(async function() {
container.innerHTML = t;
for (let e of container.querySelectorAll(".toggle")) {
e.style.toggleRoot = "scope-test 10 at 3";
}
for (let e of container.querySelectorAll(".toggle-self")) {
e.style.toggleRoot = "scope-test 10 at 3 self";
}
for (let e of container.querySelectorAll(".variant-toggle")) {
e.style.toggleRoot = "scope-test 10 at 8";
}
for (let e of container.querySelectorAll(".variant-toggle-self")) {
e.style.toggleRoot = "scope-test 10 at 8 self";
}
for (let e of container.querySelectorAll(
".toggle, .toggle-self, .variant-toggle, .variant-toggle-self")) {
await wait_for_toggle_creation(e);
}
let assert_match = (e, selector) => {
assert_true(e.matches(selector),
`matches ${selector} (class ${e.className})`);
};
let assert_nomatch = (e, selector) => {
assert_false(e.matches(selector),
`does not match ${selector} (class ${e.className})`);
};
for (let e of container.querySelectorAll(".assert-match")) {
assert_match(e, ":toggle(scope-test)");
assert_match(e, ":toggle(scope-test 3)");
assert_nomatch(e, ":toggle(scope-test 8)");
}
for (let e of container.querySelectorAll(".assert-variant-match")) {
assert_match(e, ":toggle(scope-test)");
assert_nomatch(e, ":toggle(scope-test 3)");
assert_match(e, ":toggle(scope-test 8)");
}
for (let e of container.querySelectorAll(".assert-no-match")) {
assert_nomatch(e, ":toggle(scope-test)");
assert_nomatch(e, ":toggle(scope-test 3)");
assert_nomatch(e, ":toggle(scope-test 8)");
}
}, `scope search test for markup ${t}`);
}
let selector_match_tests = [
{
specifier: [ "my-toggle 2 at 1" ],
matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle 1)",
],
not_matching_selectors: [
":toggle(my-toggle 0)",
":toggle(my-toggle 2)",
":toggle(my-toggle named-state)",
],
},
{
specifier: [ "my-toggle 2 at 0" ],
matching_selectors: [
":toggle(my-toggle 0)",
],
not_matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle 1)",
":toggle(my-toggle 2)",
":toggle(my-toggle named-state)",
],
},
{
specifier: [ "my-toggle 2 at named-state" ],
matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle named-state)",
],
not_matching_selectors: [
":toggle(my-toggle 0)",
":toggle(my-toggle 1)",
":toggle(my-toggle 2)",
":toggle(my-toggle infinite)",
":toggle(my-toggle infinity)",
],
},
{
specifier: [
"my-toggle [a b c d] at 0",
"my-toggle [a b c d] at a",
],
matching_selectors: [
":toggle(my-toggle 0)",
":toggle(my-toggle a)",
],
not_matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle 1)",
":toggle(my-toggle 2)",
":toggle(my-toggle b)",
":toggle(my-toggle d)",
":toggle(my-toggle named-state)",
],
},
{
specifier: [
"my-toggle [a b c d] at 1",
"my-toggle [a b c d] at b",
],
matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle 1)",
":toggle(my-toggle b)",
],
not_matching_selectors: [
":toggle(my-toggle 0)",
":toggle(my-toggle a)",
":toggle(my-toggle 2)",
":toggle(my-toggle d)",
":toggle(my-toggle named-state)",
],
},
{
specifier: [
"my-toggle [a b c d] at unnamed-state",
],
matching_selectors: [
":toggle(my-toggle)",
":toggle(my-toggle unnamed-state)",
],
not_matching_selectors: [
":toggle(my-toggle 0)",
":toggle(my-toggle a)",
":toggle(my-toggle 1)",
":toggle(my-toggle c)",
":toggle(my-toggle 3)",
],
},
];
for (let t of selector_match_tests) {
for (let specifier of t.specifier) {
promise_test(async function() {
container.innerHTML = `<div style="toggle-root: ${specifier}"></div>`;
let e = container.firstChild;
await wait_for_toggle_creation(e);
for (let sel of t.matching_selectors) {
assert_true(e.matches(sel), `${sel} matches`);
}
for (let sel of t.not_matching_selectors) {
assert_false(e.matches(sel), `${sel} does not match`);
}
}, `:toggle() selector matching tests for ${specifier}`);
}
}
</script>
|