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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
<!DOCTYPE html>
<html>
<head>
<title>Test shadow roots with slots</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../promisified-events.js"></script>
<script type="application/javascript">
async function _dynamicShadowTest(name, mutationFunc, expectedTree, reorder_targets) {
info(name);
let container = getNode(name);
let host = container.querySelector('.host');
document.body.offsetTop;
let event = reorder_targets ?
waitForEvents(reorder_targets.map(target => [EVENT_REORDER, target, name])) :
waitForEvent(EVENT_REORDER, host, name);
mutationFunc(container, host);
await event;
testAccessibleTree(container, expectedTree);
return true;
}
async function attachFlatShadow() {
await _dynamicShadowTest("attachFlatShadow",
(container, host) => {
host.attachShadow({ mode: "open" })
.appendChild(container.querySelector('.shadowtree').content.cloneNode(true));
}, { SECTION: [{ SECTION: [{ name: "red"} ] }] });
}
async function attachOneDeepShadow() {
await _dynamicShadowTest("attachOneDeepShadow",
(container, host) => {
host.attachShadow({ mode: "open" })
.appendChild(container.querySelector('.shadowtree').content.cloneNode(true));
}, { SECTION: [{ SECTION: [{ SECTION: [{ name: "red"} ] }] }] });
}
async function changeSlotFlat() {
await _dynamicShadowTest("changeSlotFlat",
(container, host) => {
container.querySelector('.red').removeAttribute('slot');
container.querySelector('.green').setAttribute('slot', 'myslot');
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
async function changeSlotOneDeep() {
await _dynamicShadowTest("changeSlotOneDeep",
(container, host) => {
container.querySelector('.red').removeAttribute('slot');
container.querySelector('.green').setAttribute('slot', 'myslot');
}, { SECTION: [{ SECTION: [{ SECTION: [{ name: "green"} ] }] }] }, ["shadowdiv"]);
}
// Nested roots and slots
async function changeSlotNested() {
await _dynamicShadowTest("changeSlotNested",
(container, host) => {
testAccessibleTree(getNode("changeSlotNested"),
{ SECTION: [{ SECTION: [{ SECTION: [{ name: "red"} ] }] }] });
container.querySelector('.red').removeAttribute('slot');
container.querySelector('.green').setAttribute('slot', 'myslot');
}, { SECTION: [{ SECTION: [{ SECTION: [{ name: "green"} ] }] }] }, ["shadowdiv"]);
}
// Dynamic mutations to both shadow root and shadow host subtrees
// testing/web-platform/tests/css/css-scoping/shadow-assign-dynamic-001.html
async function assignSlotDynamic() {
await _dynamicShadowTest("assignSlotDynamic",
(container, host) => {
host.shadowRoot.appendChild(container.querySelector('.shadowtree').content.cloneNode(true));
host.appendChild(container.querySelector('.lighttree').content.cloneNode(true));
}, { SECTION: [{ SECTION: [{ name: "slot1"}, { name: "slot2" } ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-001.html
async function shadowFallbackDynamic_1() {
await _dynamicShadowTest("shadowFallbackDynamic_1",
(container, host) => {
host.firstElementChild.remove();
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-002.html
async function shadowFallbackDynamic_2() {
await _dynamicShadowTest("shadowFallbackDynamic_2",
(container, host) => {
host.firstElementChild.removeAttribute("slot");
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-003.html
async function shadowFallbackDynamic_3() {
await _dynamicShadowTest("shadowFallbackDynamic_3",
(container, host) => {
host.appendChild(container.querySelector(".lighttree").content.cloneNode(true));
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-004.html
async function shadowFallbackDynamic_4() {
await _dynamicShadowTest("shadowFallbackDynamic_4",
(container, host) => {
host.shadowRoot.insertBefore(
container.querySelector(".moreshadowtree").
content.cloneNode(true), host.shadowRoot.firstChild);
}, { SECTION: [{ SECTION: [{ name: "slotparent2", children: [{ name: "green"} ] }, { name: "slotparent1" } ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-004.html
// This tests a case when the the slotted element would remain in the same accessible container
async function shadowFallbackDynamic_4_1() {
await _dynamicShadowTest("shadowFallbackDynamic_4_1",
(container, host) => {
host.shadowRoot.insertBefore(
container.querySelector(".moreshadowtree").
content.cloneNode(true), host.shadowRoot.firstChild);
}, { SECTION: [{ SECTION: [ { name: "green"}, { SEPARATOR: [] } ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-fallback-dynamic-005.html
async function shadowFallbackDynamic_5() {
await _dynamicShadowTest("shadowFallbackDynamic_5",
(container, host) => {
host.firstElementChild.setAttribute("slot", "myotherslot");
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-reassign-dynamic-002.html
async function shadowReassignDynamic_2() {
await _dynamicShadowTest("shadowReassignDynamic_2",
(container, host) => {
host.shadowRoot.querySelector("slot").setAttribute("name", "myslot");
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
// testing/web-platform/tests/css/css-scoping/shadow-reassign-dynamic-003.html
async function shadowReassignDynamic_3() {
await _dynamicShadowTest("shadowReassignDynamic_3",
(container, host) => {
testAccessibleTree(container, { SECTION: [{ SECTION: [{ name: "green"}, { name: "red", children: [ { PUSHBUTTON: [] }]} ] }] });
host.shadowRoot.querySelector("slot[name]").removeAttribute("name");
}, { SECTION: [{ SECTION: [{ name: "green", children: [ { PUSHBUTTON: [] }]}, { name: "red"} ] }] },
[evt => evt.accessible.name == "green", evt => evt.accessible.name == "red"]);
}
// testing/web-platform/tests/css/css-scoping/shadow-reassign-dynamic-004.html
async function shadowReassignDynamic_4() {
await _dynamicShadowTest("shadowReassignDynamic_4",
(container, host) => {
host.shadowRoot.getElementById("slot").remove();
}, { SECTION: [{ SECTION: [{ name: "green"} ] }] });
}
async function doTest() {
await attachFlatShadow();
await attachOneDeepShadow();
await changeSlotFlat();
await changeSlotOneDeep();
await changeSlotNested();
await assignSlotDynamic();
await shadowFallbackDynamic_1();
await shadowFallbackDynamic_2();
await shadowFallbackDynamic_3();
await shadowFallbackDynamic_4();
await shadowFallbackDynamic_4_1();
await shadowFallbackDynamic_5();
await shadowReassignDynamic_2();
await shadowReassignDynamic_3();
await shadowReassignDynamic_4();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="attachFlatShadow">
<template class="shadowtree">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<slot name="myslot">FAIL</slot>
</template>
<section class="host">
<div style="background: green" aria-label="green"></div>
<div style="background: red" aria-label="red" slot="myslot"></div>
</section>
</div>
<div id="attachOneDeepShadow">
<template class="shadowtree">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<div id="shadowdiv">
<slot name="myslot">FAIL</slot>
</div>
</template>
<section class="host">
<div style="background: green" aria-label="green"></div>
<div style="background: red" aria-label="red" slot="myslot"></div>
</section>
</div>
<div id="changeSlotFlat">
<template class="shadowtree">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<slot name="myslot">FAIL</slot>
</template>
<section class="host">
<div class="green" style="background: green" aria-label="green"></div>
<div class="red" style="background: red" aria-label="red" slot="myslot"></div>
</section>
<script>
document.querySelector("#changeSlotFlat > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#changeSlotFlat > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="changeSlotOneDeep">
<template class="shadowtree">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<div id="shadowdiv">
<slot name="myslot">FAIL</slot>
</div>
</template>
<section class="host">
<div class="green" style="background: green" aria-label="green"></div>
<div class="red" style="background: red" aria-label="red" slot="myslot"></div>
</section>
<script>
document.querySelector("#changeSlotOneDeep > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#changeSlotOneDeep > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="changeSlotNested">
<template class="shadowtree outer">
<div id="shadowdiv">
<slot name="myslot">FAIL</slot>
</div>
</template>
<template class="shadowtree inner">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<slot>FAIL</slot>
</template>
<section class="host">
<div class="green" style="background: green" aria-label="green"></div>
<div class="red" style="background: red" aria-label="red" slot="myslot"></div>
</section>
<script>
(function foo() {
let outerShadow =
document.querySelector("#changeSlotNested > .host").
attachShadow({ mode: "open" });
outerShadow.appendChild(
document.querySelector("#changeSlotNested > .shadowtree.outer").
content.cloneNode(true));
let innerShadow =
outerShadow.querySelector("#shadowdiv").
attachShadow({ mode: "open" });
innerShadow.appendChild(
document.querySelector("#changeSlotNested > .shadowtree.inner").
content.cloneNode(true));
})();
</script>
</div>
<div id="assignSlotDynamic">
<template class="shadowtree">
<style>::slotted(div) { width: 50px; height: 100px }</style>
<slot name="slot1">FAIL</slot>
<slot name="slot2">FAIL</slot>
</template>
<template class="lighttree">
<div aria-label="slot1" slot="slot1"></div>
<div aria-label="slot2" slot="slot2"></div>
</template>
<section class="host"></section>
<script>
document.querySelector("#assignSlotDynamic > .host").attachShadow({ mode: "open" });
</script>
</div>
<div id="shadowFallbackDynamic_1">
<template class="shadowtree">
<slot name="myslot">
<div aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</slot>
</template>
<section class="host"><span slot="myslot">FAIL</span></section>
<script>
document.querySelector("#shadowFallbackDynamic_1 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_1 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowFallbackDynamic_2">
<template class="shadowtree">
<slot name="myslot">
<div aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</slot>
</template>
<section class="host"><span slot="myslot">FAIL</span></section>
<script>
document.querySelector("#shadowFallbackDynamic_2 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_2 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowFallbackDynamic_3">
<template class="shadowtree">
<slot name="myslot">FAIL</slot>
</template>
<template class="lighttree">
<div aria-label="green" slot="myslot" style="width: 100px; height: 100px; background: green"></div>
</template>
<section class="host"></section>
<script>
document.querySelector("#shadowFallbackDynamic_3 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_3 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowFallbackDynamic_4">
<template class="shadowtree">
<div aria-label="slotparent1"><slot name="myslot"></slot></div>
</template>
<template class="moreshadowtree">
<div aria-label="slotparent2"><slot name="myslot">FAIL</slot></div>
</template>
<section class="host">
<div slot="myslot" aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</section>
<script>
document.querySelector("#shadowFallbackDynamic_4 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_4 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowFallbackDynamic_4_1">
<template class="shadowtree">
<hr>
<slot name="myslot"></slot>
</template>
<template class="moreshadowtree">
<slot name="myslot">FAIL</slot>
</template>
<section class="host">
<div slot="myslot" aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</section>
<script>
document.querySelector("#shadowFallbackDynamic_4_1 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_4_1 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowFallbackDynamic_5">
<template class="shadowtree">
<slot name="myslot"></slot>
<slot name="myotherslot">FAIL</slot>
</template>
<section class="host">
<div slot="myslot" aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</section>
<script>
document.querySelector("#shadowFallbackDynamic_5 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowFallbackDynamic_5 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowReassignDynamic_2">
<template class="shadowtree">
<style>::slotted(div) { width: 100px; height: 100px }</style>
<slot>FAIL</slot>
</template>
<section class="host">
<div slot="myslot" aria-label="green" style="width: 100px; height: 100px; background: green"></div>
</section>
<script>
document.querySelector("#shadowReassignDynamic_2 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowReassignDynamic_2 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowReassignDynamic_3">
<template class="shadowtree">
<div aria-label="green"><slot name="nomatch"></slot></div>
<div aria-label="red"><slot></slot></div>
</template>
<section class="host">
<div role="button"></div>
</section>
<script>
document.querySelector("#shadowReassignDynamic_3 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowReassignDynamic_3 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="shadowReassignDynamic_4">
<template class="shadowtree">
<style>::slotted(div),div { width: 100px; height: 100px }</style>
<slot id="slot"></slot>
<slot>
<div aria-label="red" style="background: red"></div>
</slot>
</template>
<section class="host">
<div aria-label="green" style="background: green"></div>
</section>
<script>
document.querySelector("#shadowReassignDynamic_4 > .host")
.attachShadow({ mode: "open" })
.appendChild(document.querySelector("#shadowReassignDynamic_4 > .shadowtree").content.cloneNode(true));
</script>
</div>
<div id="eventdump"></div>
</body>
</html>
|