@voila.dev/replay 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,670 @@
1
+ // The case suite. `html` is written into the site frame by the parser; `before` runs before the
2
+ // recorder starts, `run` after; `keys`, `clicks` and `select` are done by the test driver with
3
+ // real input events, then `after` runs. The functions are evaluated in the site's window with
4
+ // (document, window, wait): they must not reference anything outside themselves.
5
+ import type { Options } from "../record/index";
6
+
7
+ type Fn = (d: Document, w: Window & typeof globalThis, wait: (ms: number) => Promise<void>) => unknown;
8
+
9
+ export interface Case {
10
+ readonly name: string;
11
+ readonly group: string;
12
+ readonly html: string;
13
+ readonly o?: Pick<Options, "mask">;
14
+ readonly before?: Fn;
15
+ readonly run?: Fn;
16
+ readonly after?: Fn;
17
+ readonly keys?: ReadonlyArray<readonly [string, string]>;
18
+ readonly clicks?: ReadonlyArray<string>;
19
+ readonly select?: ReadonlyArray<readonly [string, string]>;
20
+ /** Strings that must never leave the page, in clear. */
21
+ readonly secrets?: ReadonlyArray<string>;
22
+ /** What the browser must offer for the case to mean anything; skipped otherwise. */
23
+ readonly needs?: { readonly what: string; readonly test: (w: Window & typeof globalThis) => boolean };
24
+ }
25
+
26
+ const D = (body: string, head = "") =>
27
+ `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><title>Cas</title>${head}</head><body>${body}</body></html>`;
28
+ const AB = D('<div id="a"></div><div id="b">avant</div>');
29
+
30
+ const hazards: Fn = (d) => {
31
+ const a = d.getElementById("a") as Element;
32
+ const t = d.createElement("table");
33
+ const tr = d.createElement("tr");
34
+ const td = d.createElement("td");
35
+ td.textContent = "cellule";
36
+ tr.append(td);
37
+ t.append(tr);
38
+ a.append(t);
39
+ const p = d.createElement("p");
40
+ const div = d.createElement("div");
41
+ div.textContent = "bloc";
42
+ p.append(div);
43
+ a.append(p);
44
+ const l1 = d.createElement("a");
45
+ const l2 = d.createElement("a");
46
+ l1.href = "/x";
47
+ l2.href = "/y";
48
+ l2.textContent = "lien";
49
+ l1.append(l2);
50
+ a.append(l1);
51
+ const ul = d.createElement("ul");
52
+ const li = d.createElement("li");
53
+ const li2 = d.createElement("li");
54
+ li2.textContent = "sous";
55
+ li.append(li2);
56
+ ul.append(li);
57
+ a.append(ul);
58
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
59
+ const h = d.createElement("div");
60
+ h.textContent = "html dans svg";
61
+ svg.append(h);
62
+ a.append(svg);
63
+ };
64
+
65
+ export const CASES: ReadonlyArray<Case> = [
66
+ {
67
+ name: "témoin",
68
+ group: "base",
69
+ html: D('<header><h1>Titre</h1></header><main><p id="p">Texte <b>gras</b></p><ul id="u"><li>un</li></ul></main>'),
70
+ run: (d) => {
71
+ d.getElementById("p")?.append(" ajouté");
72
+ const li = d.createElement("li");
73
+ li.textContent = "deux";
74
+ d.getElementById("u")?.append(li);
75
+ (d.querySelector("h1") as Element).className = "x";
76
+ },
77
+ },
78
+ {
79
+ name: "table sans tbody",
80
+ group: "parseur",
81
+ html: AB,
82
+ run: (d) => {
83
+ const t = d.createElement("table");
84
+ const tr = d.createElement("tr");
85
+ const td = d.createElement("td");
86
+ td.textContent = "c";
87
+ tr.append(td);
88
+ t.append(tr);
89
+ d.getElementById("a")?.append(t);
90
+ (d.getElementById("b") as Element).textContent = "après";
91
+ },
92
+ },
93
+ {
94
+ name: "div dans p",
95
+ group: "parseur",
96
+ html: AB,
97
+ run: (d) => {
98
+ const p = d.createElement("p");
99
+ const x = d.createElement("div");
100
+ x.textContent = "bloc";
101
+ p.append(x, "suite");
102
+ d.getElementById("a")?.append(p);
103
+ (d.getElementById("b") as Element).textContent = "après";
104
+ },
105
+ },
106
+ {
107
+ name: "a dans a",
108
+ group: "parseur",
109
+ html: AB,
110
+ run: (d) => {
111
+ const a = d.createElement("a");
112
+ const b = d.createElement("a");
113
+ a.href = "/x";
114
+ b.href = "/y";
115
+ b.textContent = "lien";
116
+ a.append(b, "fin");
117
+ d.getElementById("a")?.append(a);
118
+ (d.getElementById("b") as Element).textContent = "après";
119
+ },
120
+ },
121
+ {
122
+ name: "li dans li",
123
+ group: "parseur",
124
+ html: AB,
125
+ run: (d) => {
126
+ const ul = d.createElement("ul");
127
+ const li = d.createElement("li");
128
+ const x = d.createElement("li");
129
+ x.textContent = "sous";
130
+ li.append(x);
131
+ ul.append(li);
132
+ d.getElementById("a")?.append(ul);
133
+ (d.getElementById("b") as Element).textContent = "après";
134
+ },
135
+ },
136
+ {
137
+ name: "HTML créé par script dans SVG",
138
+ group: "parseur",
139
+ html: AB,
140
+ run: (d) => {
141
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
142
+ const x = d.createElement("div");
143
+ x.textContent = "html";
144
+ const g = d.createElementNS("http://www.w3.org/2000/svg", "g");
145
+ const s = d.createElement("span");
146
+ s.textContent = "s";
147
+ g.append(s);
148
+ svg.append(x, g);
149
+ d.getElementById("a")?.append(svg);
150
+ (d.getElementById("b") as Element).textContent = "après";
151
+ },
152
+ },
153
+ {
154
+ name: "les cinq pièges, présents dès le départ",
155
+ group: "parseur",
156
+ html: AB,
157
+ before: hazards,
158
+ run: (d) => {
159
+ (d.getElementById("b") as Element).textContent = "après";
160
+ },
161
+ },
162
+ {
163
+ name: "MathML",
164
+ group: "parseur",
165
+ html: D('<p id="p">x</p><math id="m"><mi>a</mi><mo>+</mo><mn>2</mn></math>'),
166
+ run: (d) => {
167
+ const mi = d.createElementNS("http://www.w3.org/1998/Math/MathML", "mi");
168
+ mi.textContent = "b";
169
+ d.getElementById("m")?.append(mi);
170
+ },
171
+ },
172
+ {
173
+ name: "détaché, modifié, réinséré",
174
+ group: "mutations",
175
+ html: D('<section id="s"><div id="x" class="a"><span>un</span><i>deux</i></div><p id="y">p</p></section>'),
176
+ run: async (d, _w, wait) => {
177
+ const s = d.getElementById("s") as Element;
178
+ const x = d.getElementById("x") as Element;
179
+ const y = d.getElementById("y") as HTMLElement;
180
+ x.remove();
181
+ x.setAttribute("data-away", "1");
182
+ (x.firstChild as Element).textContent = "changé";
183
+ x.append(d.createElement("em"));
184
+ await Promise.resolve();
185
+ (x.lastElementChild as Element).textContent = "nouveau";
186
+ await wait(40);
187
+ x.querySelector("i")?.remove();
188
+ s.append(x);
189
+ y.remove();
190
+ y.textContent = "même tâche";
191
+ y.title = "t";
192
+ s.prepend(y);
193
+ },
194
+ },
195
+ {
196
+ name: "déplacements",
197
+ group: "mutations",
198
+ html: D('<div id="a"><p>1</p><p>2</p><p>3</p></div><div id="b"><span>x</span><span>y</span></div>'),
199
+ run: async (d, _w, wait) => {
200
+ const a = d.getElementById("a") as Element;
201
+ const b = d.getElementById("b") as Element;
202
+ b.append(a.firstElementChild as Element);
203
+ a.append(a.firstElementChild as Element);
204
+ const box = d.createElement("div");
205
+ box.id = "box";
206
+ box.append(b.firstElementChild as Element);
207
+ await wait(40);
208
+ a.prepend(box);
209
+ const [p, q] = Array.from(b.children);
210
+ const ghost = d.createComment("");
211
+ p?.replaceWith(ghost);
212
+ if (p) q?.replaceWith(p);
213
+ if (q) ghost.replaceWith(q);
214
+ b.append(a);
215
+ await Promise.resolve();
216
+ d.body.prepend(box);
217
+ },
218
+ },
219
+ {
220
+ name: "innerHTML massif",
221
+ group: "mutations",
222
+ html: D('<main id="m"><p>avant</p></main><p id="z">z</p>'),
223
+ run: async (d, _w, wait) => {
224
+ const m = d.getElementById("m") as Element;
225
+ let h = "";
226
+ for (let i = 0; i < 1500; i++)
227
+ h += `<div class="r${i % 7}" data-i="${i}"><span>ligne ${i}</span> <b>${i}</b>${i % 50 ? "" : "<table><tr><td>t</td></tr></table>"}</div>`;
228
+ m.innerHTML = h;
229
+ await wait(40);
230
+ m.innerHTML = h.replace(/ligne/g, "rang");
231
+ (d.getElementById("z") as Element).textContent = "fin";
232
+ },
233
+ },
234
+ {
235
+ name: "shadow DOM attaché plus tard",
236
+ group: "mutations",
237
+ html: D('<div id="h"><span>clair</span></div><p id="q">déplacé</p>'),
238
+ run: async (d, _w, wait) => {
239
+ const r = (d.getElementById("h") as Element).attachShadow({ mode: "open" });
240
+ r.innerHTML = "<style>b{color:red}</style><b>ombre</b><slot></slot>";
241
+ await wait(40);
242
+ (r.querySelector("b") as Element).textContent = "ombre modifiée";
243
+ r.append(d.getElementById("q") as Element);
244
+ },
245
+ },
246
+ {
247
+ name: "shadow DOM présent au départ",
248
+ group: "mutations",
249
+ html: D('<div id="h"><span>clair</span></div>'),
250
+ before: (d) => {
251
+ (d.getElementById("h") as Element).attachShadow({ mode: "open" }).innerHTML = "<i>avant</i>";
252
+ },
253
+ run: (d) => {
254
+ const r = (d.getElementById("h") as Element).shadowRoot as ShadowRoot;
255
+ (r.querySelector("i") as Element).textContent = "après";
256
+ r.append(d.createElement("u"));
257
+ },
258
+ },
259
+ {
260
+ name: "shadow DOM attaché dans un <template>",
261
+ group: "mutations",
262
+ html: D('<template id="t"><p class="x">haie<span>1</span></p></template><p id="z">z</p>'),
263
+ run: (d) => {
264
+ const t = d.getElementById("t") as HTMLTemplateElement;
265
+ (t.content.querySelector("p") as Element).attachShadow({ mode: "open" }).append("ombre");
266
+ },
267
+ },
268
+ {
269
+ name: "shadow DOM attaché, élément créé par innerHTML",
270
+ group: "mutations",
271
+ html: D('<div id="a"></div>'),
272
+ run: async (_d, _w, wait) => {
273
+ const a = _d.getElementById("a") as Element;
274
+ a.innerHTML = "<p><span>6</span></p>";
275
+ await wait(80);
276
+ (a.querySelector("span") as Element).attachShadow({ mode: "open" }).append("ombre");
277
+ },
278
+ },
279
+ {
280
+ name: "accesseurs du DOM détournés par la page",
281
+ group: "robustesse",
282
+ html: D('<ul id="u"><li>un</li></ul>'),
283
+ before: (d, w) => {
284
+ // What zone.js and the like do: wrap a DOM accessor.
285
+ const P = w.Node.prototype;
286
+ const desc = Object.getOwnPropertyDescriptor(P, "firstChild") as PropertyDescriptor;
287
+ Object.defineProperty(P, "firstChild", { configurable: true, get() { return desc.get?.call(this); } });
288
+ },
289
+ run: async (d, w, wait) => {
290
+ const li = d.createElement("li");
291
+ li.textContent = "deux";
292
+ (d.getElementById("u") as Element).append(li);
293
+ await wait(120);
294
+ // The page's own nodes must keep the page's prototypes once the recorder read them.
295
+ const first = (d.getElementById("u") as Element).firstElementChild as Element;
296
+ if (!(first instanceof w.HTMLElement) || !(li instanceof w.HTMLElement)) throw new Error("prototypes étrangers");
297
+ },
298
+ },
299
+ {
300
+ name: "<template>",
301
+ group: "nouveaux",
302
+ html: D('<template id="t"><b>modèle</b><p>x</p></template><div id="a"></div>'),
303
+ run: (d) => {
304
+ const t = d.getElementById("t") as HTMLTemplateElement;
305
+ (t.content.querySelector("b") as Element).textContent = "changé";
306
+ t.content.append(d.createElement("hr"));
307
+ (d.getElementById("a") as Element).innerHTML = '<template id="t2"><i>nouveau</i></template>';
308
+ },
309
+ },
310
+ {
311
+ name: "<select> changé par script",
312
+ group: "nouveaux",
313
+ o: { mask: "none" },
314
+ html: D(
315
+ '<select id="s1"><option>a<option selected>b<option>c</select><select id="s2" multiple><option>x<option>y<option>z</select><select id="s3"><option>p<option>q</select>',
316
+ ),
317
+ run: (d) => {
318
+ (d.getElementById("s1") as HTMLSelectElement).value = "c";
319
+ const s2 = d.getElementById("s2") as HTMLSelectElement;
320
+ (s2.options[0] as HTMLOptionElement).selected = true;
321
+ (s2.options[2] as HTMLOptionElement).selected = true;
322
+ ((d.getElementById("s3") as HTMLSelectElement).options[1] as HTMLOptionElement).defaultSelected = true;
323
+ },
324
+ },
325
+ {
326
+ name: "<select> masqué",
327
+ group: "masquage",
328
+ html: D('<select id="s1"><option>a<option selected>b<option>c</select>'),
329
+ run: (d) => {
330
+ (d.getElementById("s1") as HTMLSelectElement).value = "c";
331
+ },
332
+ },
333
+ {
334
+ name: ".value changé sans événement",
335
+ group: "nouveaux",
336
+ o: { mask: "none" },
337
+ html: D('<input id="i" value="départ"><input id="c" type="checkbox"><textarea id="t">texte</textarea><input id="r" type="range" min="0" max="10" value="2">'),
338
+ run: (d) => {
339
+ (d.getElementById("i") as HTMLInputElement).value = "nouveau";
340
+ (d.getElementById("c") as HTMLInputElement).checked = true;
341
+ (d.getElementById("t") as HTMLTextAreaElement).value = "autre";
342
+ (d.getElementById("r") as HTMLInputElement).value = "8";
343
+ },
344
+ },
345
+ {
346
+ name: "valeurs changées avant le départ",
347
+ group: "nouveaux",
348
+ o: { mask: "none" },
349
+ html: D('<input id="i" value="départ"><input id="c" type="checkbox"><textarea id="t">texte</textarea><select id="s"><option>a<option>b</select>'),
350
+ before: (d) => {
351
+ (d.getElementById("i") as HTMLInputElement).value = "nouveau";
352
+ (d.getElementById("c") as HTMLInputElement).checked = true;
353
+ (d.getElementById("t") as HTMLTextAreaElement).value = "autre";
354
+ (d.getElementById("s") as HTMLSelectElement).value = "b";
355
+ },
356
+ run: (d) => {
357
+ d.body.dataset.x = "1";
358
+ },
359
+ },
360
+ {
361
+ name: "saisie au clavier, masquée",
362
+ group: "masquage",
363
+ html: D('<input id="i"><textarea id="t"></textarea><input id="c" type="checkbox"><select id="s"><option>a<option>b</select>'),
364
+ keys: [
365
+ ["#i", "Bonjour Camille"],
366
+ ["#t", "ligne\nsuite"],
367
+ ],
368
+ clicks: ["#c"],
369
+ select: [["#s", "b"]],
370
+ secrets: ["Bonjour", "Camille", "suite"],
371
+ },
372
+ {
373
+ name: "saisie au clavier, en clair",
374
+ group: "nouveaux",
375
+ o: { mask: "none" },
376
+ html: D('<input id="i"><textarea id="t"></textarea><input id="c" type="checkbox"><select id="s"><option>a<option>b</select>'),
377
+ keys: [
378
+ ["#i", "Bonjour"],
379
+ ["#t", "ligne\nsuite"],
380
+ ],
381
+ clicks: ["#c"],
382
+ select: [["#s", "b"]],
383
+ },
384
+ {
385
+ name: "mot de passe, carte, champ caché",
386
+ group: "masquage",
387
+ o: { mask: "none" },
388
+ html: D(
389
+ '<form><input id="p" type="password"><input id="cc" autocomplete="cc-number"><input type="hidden" name="csrf" value="jeton-secret-123"><input id="u" value="visible"></form>',
390
+ ),
391
+ keys: [
392
+ ["#p", "motdepasse42"],
393
+ ["#cc", "4970101010101010"],
394
+ ],
395
+ secrets: ["motdepasse42", "4970101010101010", "jeton-secret-123"],
396
+ },
397
+ {
398
+ name: "champ autorisé en clair",
399
+ group: "masquage",
400
+ html: D('<div data-va-unmask><input id="q" placeholder="Rechercher"></div><input id="n">'),
401
+ keys: [
402
+ ["#q", "taille de haie"],
403
+ ["#n", "Dupont"],
404
+ ],
405
+ secrets: ["Dupont"],
406
+ },
407
+ {
408
+ name: "zone masquée : texte et attributs",
409
+ group: "masquage",
410
+ html: D(
411
+ '<section data-va-mask><h2 title="Jeanne Martin">Jeanne Martin</h2><img alt="Photo de Jeanne" src="a.png"><p aria-label="adresse">12 rue des Lilas</p></section><p id="z">public</p>',
412
+ ),
413
+ run: (d) => {
414
+ (d.querySelector("h2") as Element).setAttribute("data-client", "Jeanne Martin");
415
+ (d.getElementById("z") as Element).textContent = "toujours public";
416
+ },
417
+ secrets: ["Jeanne", "Martin", "Lilas", "Photo"],
418
+ },
419
+ {
420
+ name: "tout le texte masqué",
421
+ group: "masquage",
422
+ o: { mask: "text" },
423
+ html: D('<h1>Bonjour Camille</h1><p id="p">Votre devis</p>'),
424
+ run: (d) => {
425
+ (d.getElementById("p") as Element).textContent = "Votre devis est prêt";
426
+ },
427
+ secrets: ["Camille", "devis"],
428
+ },
429
+ {
430
+ name: "bloqué après coup",
431
+ group: "masquage",
432
+ html: D('<div id="x"><p>avant</p></div><p id="z">z</p>'),
433
+ run: async (d, _w, wait) => {
434
+ const x = d.getElementById("x") as Element;
435
+ x.setAttribute("data-va-block", "");
436
+ await wait(80);
437
+ x.setAttribute("title", "Secret Durand");
438
+ (x.firstElementChild as Element).textContent = "Secret Durand";
439
+ },
440
+ secrets: ["Durand"],
441
+ },
442
+ {
443
+ // The fuzzer's WebKit seed 2, round 50, reduced: the zone change and the move arrive in the
444
+ // same batch, and forgetting the zone took the moved node along.
445
+ name: "bloqué, puis un nœud y entre",
446
+ group: "masquage",
447
+ html: D('<div id="a"><b>gras</b><i>reste</i></div><div id="x"><p>avant</p></div>'),
448
+ run: (d) => {
449
+ const x = d.getElementById("x") as Element;
450
+ x.setAttribute("data-va-block", "");
451
+ x.append(d.querySelector("b") as Element);
452
+ },
453
+ },
454
+ {
455
+ // The fuzzer's seed 16, round 22, reduced: a field changed by script keeps its value when
456
+ // its default goes; a copy that only got the attribute loses it.
457
+ name: "champ changé par script, puis son attribut retiré",
458
+ group: "mutations",
459
+ html: D('<input id="f" value="haie"><input id="c" type="checkbox" checked>'),
460
+ run: async (d, _w, wait) => {
461
+ const f = d.getElementById("f") as HTMLInputElement;
462
+ const c = d.getElementById("c") as HTMLInputElement;
463
+ f.value = "haie";
464
+ c.checked = true;
465
+ await wait(80);
466
+ f.removeAttribute("value");
467
+ c.removeAttribute("checked");
468
+ },
469
+ o: { mask: "none" },
470
+ },
471
+ {
472
+ name: "<select> : l'attribut selected retiré, puis vidé par script",
473
+ group: "mutations",
474
+ html: D('<div id="a"></div>'),
475
+ run: async (d, _w, wait) => {
476
+ (d.getElementById("a") as Element).innerHTML =
477
+ '<select id="s"><option>taille</option><option id="o" selected>serre</option></select>';
478
+ await wait(80);
479
+ // The browser picks the first option again, then the script unpicks it: the copy must
480
+ // learn that the first option is no longer chosen.
481
+ (d.getElementById("o") as Element).removeAttribute("selected");
482
+ (d.getElementById("s") as HTMLSelectElement).selectedIndex = -1;
483
+ },
484
+ o: { mask: "none" },
485
+ },
486
+ {
487
+ name: "débloqué après coup",
488
+ group: "masquage",
489
+ html: D('<div id="x" data-va-block><p>caché</p></div>'),
490
+ run: (d) => {
491
+ (d.getElementById("x") as Element).removeAttribute("data-va-block");
492
+ },
493
+ },
494
+ {
495
+ name: "<dialog open> dans le HTML",
496
+ group: "nouveaux",
497
+ html: D('<dialog id="d1" open><p>ouvert</p></dialog><p id="p">x</p>'),
498
+ run: (d) => {
499
+ (d.getElementById("p") as Element).textContent = "y";
500
+ },
501
+ },
502
+ {
503
+ name: "dialog.showModal()",
504
+ group: "nouveaux",
505
+ html: D('<dialog id="d2"><p>modale</p></dialog>'),
506
+ run: (d) => {
507
+ (d.getElementById("d2") as HTMLDialogElement).showModal();
508
+ },
509
+ },
510
+ {
511
+ name: "attributs : guillemets, caractères de contrôle",
512
+ group: "nouveaux",
513
+ html: D(`<div id="a" title='il a dit "oui" &amp; &lt;b&gt;' data-q="l'apostrophe" @click="go" :class="k" x.y="1"></div><p id="p">a</p>`),
514
+ run: (d) => {
515
+ const a = d.getElementById("a") as Element;
516
+ a.setAttribute("data-x", "a\"b'c<d>&e\u0001\u0007\t\n\u000b f");
517
+ a.setAttribute("data-cr", "x\r\ny\rz");
518
+ a.setAttribute("data-nul", "a\u0000b");
519
+ (d.getElementById("p") as Element).textContent = "texte\r\nretour\u0000nul\u0007";
520
+ },
521
+ },
522
+ {
523
+ name: "champs nommés localName et hasAttribute",
524
+ group: "nouveaux",
525
+ html: D('<form id="f"><input name="localName" value="x"><input name="hasAttribute"><input name="attributes"></form><p id="p">a</p>'),
526
+ run: (d) => {
527
+ (d.getElementById("p") as Element).textContent = "b";
528
+ (d.getElementById("f") as Element).setAttribute("data-k", "1");
529
+ },
530
+ },
531
+ {
532
+ name: "éléments personnalisés",
533
+ group: "nouveaux",
534
+ html: D('<x-carte id="c" titre="Bonjour"></x-carte><p>p</p>'),
535
+ run: async (d, w, wait) => {
536
+ w.customElements.define(
537
+ "x-carte",
538
+ class extends w.HTMLElement {
539
+ connectedCallback() {
540
+ if (this.shadowRoot) return;
541
+ const r = this.attachShadow({ mode: "open" });
542
+ r.innerHTML = `<h3>${this.getAttribute("titre")}</h3><slot></slot>`;
543
+ this.innerHTML = "<p>lumière</p>";
544
+ }
545
+ },
546
+ );
547
+ await wait(40);
548
+ const e = d.createElement("x-carte");
549
+ e.setAttribute("titre", "second");
550
+ d.body.append(e);
551
+ },
552
+ },
553
+ {
554
+ name: "contenteditable, en clair",
555
+ group: "contenteditable",
556
+ o: { mask: "none" },
557
+ html: D('<div id="e" contenteditable="true"><p>début</p></div>'),
558
+ keys: [["#e", " tapé\nligne deux"]],
559
+ },
560
+ {
561
+ name: "contenteditable, masqué par défaut",
562
+ group: "contenteditable",
563
+ html: D('<div id="e" contenteditable="true"><p>début</p></div><p id="z">z</p>'),
564
+ keys: [["#e", " Dupont"]],
565
+ after: (d) => {
566
+ (d.getElementById("z") as Element).textContent = "après la saisie";
567
+ },
568
+ secrets: ["Dupont"],
569
+ },
570
+ {
571
+ name: "contenteditable : gras, liste, collage",
572
+ group: "contenteditable",
573
+ html: D('<div id="e" contenteditable="true"><p>Bonjour</p></div>'),
574
+ run: async (d, _w, wait) => {
575
+ const e = d.getElementById("e") as Element;
576
+ const b = d.createElement("b");
577
+ b.textContent = "important";
578
+ (e.firstElementChild as Element).append(" ", b);
579
+ await wait(60);
580
+ e.insertAdjacentHTML("beforeend", "<ul><li>un</li><li>deux</li></ul>");
581
+ await wait(60);
582
+ (e.querySelector("li") as Element).remove();
583
+ },
584
+ },
585
+ {
586
+ name: "contenteditable, champ autorisé",
587
+ group: "contenteditable",
588
+ html: D('<div id="e" contenteditable="true" data-va-unmask><p>début</p></div>'),
589
+ keys: [["#e", " visible"]],
590
+ },
591
+ {
592
+ name: "srcset et <picture>",
593
+ group: "nouveaux",
594
+ html: D('<picture id="pi"><source srcset="a.webp 1x, b.webp 2x" type="image/webp"><img id="im" src="c.png" srcset="c.png 1x, d.png 2x" alt=""></picture>'),
595
+ run: (d) => {
596
+ const im = d.getElementById("im") as HTMLImageElement;
597
+ im.srcset = "e.png 1x, f.png 3x";
598
+ im.sizes = "50vw";
599
+ const s = d.createElement("source");
600
+ s.srcset = "g.avif";
601
+ s.type = "image/avif";
602
+ d.getElementById("pi")?.prepend(s);
603
+ },
604
+ },
605
+ {
606
+ name: "<noscript>",
607
+ group: "nouveaux",
608
+ html: D('<noscript><p id="n">Activez JavaScript</p></noscript><p>après</p>', "<noscript><style>body{background:red}</style></noscript>"),
609
+ run: (d) => {
610
+ const n = d.createElement("noscript");
611
+ n.innerHTML = "<b>vu sans script</b>";
612
+ d.body.append(n);
613
+ },
614
+ },
615
+ {
616
+ name: "document en mode quirks",
617
+ group: "nouveaux",
618
+ html: '<html><head><title>q</title></head><body><table id="t"><tr><td>quirks</td></tr></table><p id="p">x</p></body></html>',
619
+ run: (d) => {
620
+ (d.getElementById("p") as Element).textContent = "y";
621
+ },
622
+ },
623
+ {
624
+ name: "liens javascript: désarmés",
625
+ group: "nouveaux",
626
+ html: D('<a id="a" href="javascript:alert(1)" onclick="alert(2)" target="_top">x</a>'),
627
+ run: (d) => {
628
+ (d.getElementById("a") as Element).setAttribute("href", "javascript:alert(3)");
629
+ },
630
+ },
631
+ {
632
+ name: "CSSOM insertRule",
633
+ group: "styles",
634
+ html: D('<p class="a">a</p><p class="b">b</p>', '<style id="s">.a{color:red}</style>'),
635
+ run: async (d, _w, wait) => {
636
+ ((d.getElementById("s") as HTMLStyleElement).sheet as CSSStyleSheet).insertRule(".b { color: blue; }", 1);
637
+ const e = d.createElement("style");
638
+ d.head.append(e);
639
+ (e.sheet as CSSStyleSheet).insertRule(".a { font-weight: 700; }");
640
+ await wait(200);
641
+ ((d.getElementById("s") as HTMLStyleElement).sheet as CSSStyleSheet).deleteRule(0);
642
+ },
643
+ },
644
+ {
645
+ name: "adoptedStyleSheets",
646
+ group: "styles",
647
+ needs: { what: "feuilles constructibles (Safari 16.4)", test: (w) => "adoptedStyleSheets" in w.Document.prototype },
648
+ html: D('<p class="a">a</p><div id="h"></div>'),
649
+ run: async (d, w, wait) => {
650
+ const s1 = new w.CSSStyleSheet();
651
+ s1.replaceSync(".a { color: green; }");
652
+ d.adoptedStyleSheets = [s1];
653
+ const r = (d.getElementById("h") as Element).attachShadow({ mode: "open" });
654
+ const s2 = new w.CSSStyleSheet();
655
+ s2.replaceSync("b { color: red; }");
656
+ r.adoptedStyleSheets = [s2];
657
+ r.innerHTML = "<b>ombre</b>";
658
+ await wait(60);
659
+ s1.insertRule(".a { color: blue; }", 1);
660
+ },
661
+ },
662
+ {
663
+ name: "CSS-in-JS au départ",
664
+ group: "styles",
665
+ html: D('<p class="a">a</p>', '<style id="s"></style>'),
666
+ before: (d) => {
667
+ ((d.getElementById("s") as HTMLStyleElement).sheet as CSSStyleSheet).insertRule(".a { color: purple; }");
668
+ },
669
+ },
670
+ ];