{{ message }}
Repository navigation
Expand file tree
/
Copy pathkeyboard.spec.js
More file actions
612 lines (523 loc) · 24.1 KB
/
Copy pathkeyboard.spec.js
File metadata and controls
612 lines (523 loc) · 24.1 KB
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
import { test, expect } from "@playwright/test";
/**
* Keyboard operability checks for the initialized player — the half of
* accessibility testing axe cannot do. axe inspects the static accessibility
* tree; it cannot prove the player is reachable by Tab, that play/pause is
* operable with a keyboard, or that focus stays visible.
*
* Deliberately small scope for a first suite: reachability, operability of
* the primary control, and a visible focus indicator. It does not attempt to
* cover Able Player's full keyboard model (modifier hotkeys, seekbar arrows,
* preference dialogs) — those deserve dedicated specs over time.
*
* Runs at all four viewports (playwright.config.js): a control that falls out
* of the tab order or loses its focus ring at one breakpoint still fails.
*/
const DEMO = "/demos/video1.html";
/** Read the active element's identity synchronously (never auto-waits). */
async function activeInfo(page) {
return page.evaluate(() => {
const el = document.activeElement;
if (!el || el === document.body) return { tag: "body", cls: "", label: "" };
return {
tag: el.tagName.toLowerCase(),
cls: el.className || "",
label: el.getAttribute("aria-label") || (el.textContent || "").trim(),
};
});
}
/** True when the focused element shows a rendered outline or box-shadow ring. */
async function focusedHasVisibleRing(page) {
return page.evaluate(() => {
const el = document.activeElement;
if (!el || el === document.body) return false;
const style = getComputedStyle(el);
const outlineVisible =
style.outlineStyle !== "none" &&
parseFloat(style.outlineWidth) > 0 &&
// A fully transparent outline is not a visible indicator. Able Player's
// own :focus rule paints a solid var(--able-focus-outline), so this
// guards against a theme that overrides the color to transparent.
!/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0\s*\)$/.test(style.outlineColor) &&
style.outlineColor !== "transparent";
const shadowVisible = style.boxShadow !== "none" && style.boxShadow !== "";
return outlineVisible || shadowVisible;
});
}
test.beforeEach(async ({ page }) => {
await page.goto(DEMO);
await page.waitForSelector(".able-controller", { timeout: 20_000 });
});
test("player controls are reachable by Tab from the top of the document", async ({ page }) => {
// Walk the tab ring from the document start. The page has a small nav
// (2 links) before the player; 40 stops is a generous ceiling that still
// fails fast if the player is unreachable.
let reachedPlayer = false;
for (let i = 0; i < 40; i++) {
await page.keyboard.press("Tab");
const info = await activeInfo(page);
if (info.tag === "body") break; // wrapped: end of ring, player never seen
if (/able-/.test(info.cls) || (await page.evaluate(() =>
Boolean(document.activeElement?.closest(".able-wrapper")),
))) {
reachedPlayer = true;
break;
}
}
expect(reachedPlayer, "tabbing must reach the Able Player UI").toBe(true);
});
test("play/pause is keyboard-operable and announces its state", async ({ page }) => {
const playButton = page.locator(".able-button-handler-play").first();
await playButton.focus();
const before = await playButton.getAttribute("aria-label");
expect(before, "play/pause control must have an accessible name").toBeTruthy();
await page.keyboard.press("Enter");
// Media playback must actually start (paused flips false) — the control is
// operable, not merely focusable.
await expect
.poll(async () => page.evaluate(() => document.querySelector("video, audio")?.paused), {
timeout: 10_000,
message: "pressing Enter on the play control must start playback",
})
.toBe(false);
// And the accessible name must flip to reflect the new state (Play → Pause
// family — exact string is locale/config dependent, so assert change only).
await expect
.poll(async () => playButton.getAttribute("aria-label"), {
timeout: 10_000,
message: "the control's accessible name must update after activation",
})
.not.toBe(before);
// Enter again pauses — round trip proves both directions are operable.
await page.keyboard.press("Enter");
await expect
.poll(async () => page.evaluate(() => document.querySelector("video, audio")?.paused), {
timeout: 10_000,
message: "pressing Enter again must pause playback",
})
.toBe(true);
});
test("focused player controls show a visible focus indicator", async ({ page }) => {
const playButton = page.locator(".able-button-handler-play").first();
await playButton.focus();
expect(
await focusedHasVisibleRing(page),
"the focused play control must render a visible focus ring",
).toBe(true);
});
/* ---------- Full control coverage for video1.html ---------- */
const mediaState = (page) =>
page.evaluate(() => {
const v = document.querySelector("video");
return { t: v.currentTime, paused: v.paused, rate: v.playbackRate, volume: v.volume };
});
/** Pause and seek the media to a known position before a control test. */
async function seedTime(page, seconds) {
await page.evaluate(async (s) => {
const v = document.querySelector("video");
v.pause();
await new Promise((resolve) => {
v.addEventListener("seeked", resolve, { once: true });
v.currentTime = s;
});
}, seconds);
}
const btn = (page, name) => page.locator(`.able-controller button.able-button-handler-${name}`);
test("restart returns to the beginning and starts playback", async ({ page }) => {
await seedTime(page, 20);
await btn(page, "restart").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).paused, { timeout: 10_000 }).toBe(false);
// Playback began from the start, not from 20s.
expect((await mediaState(page)).t).toBeLessThan(5);
});
test("rewind and forward move the playhead by the seek interval", async ({ page }) => {
await seedTime(page, 20);
const interval = await page.evaluate(() => {
const m = document.querySelector(".able-button-handler-forward").getAttribute("aria-label");
return Number(m.match(/\d+/)[0]);
});
expect(interval).toBeGreaterThan(0);
await btn(page, "forward").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).t).toBeCloseTo(20 + interval, 0);
// Able Player tracks elapsed time from timeupdate; wait for its display to catch up.
await expect(page.locator(".able-elapsedTime")).toHaveText(`00:${20 + interval}`);
await btn(page, "rewind").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).t).toBeCloseTo(20, 0);
});
test("rewind does not go below zero", async ({ page }) => {
await seedTime(page, 3);
await btn(page, "rewind").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).t).toBeLessThan(0.5);
});
test("faster and slower adjust the playback rate in 0.25 steps", async ({ page }) => {
expect((await mediaState(page)).rate).toBe(1);
await btn(page, "faster").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).rate).toBe(1.25);
await expect(page.locator(".able-speed")).toContainText("1.25");
await btn(page, "slower").focus();
await page.keyboard.press("Enter");
await page.keyboard.press("Enter");
await expect.poll(async () => (await mediaState(page)).rate).toBe(0.75);
await expect(page.locator(".able-speed")).toContainText("0.75");
});
test("able-popup menus contain the expected items", async ({ page }) => {
const items = async (idSuffix) =>
page.evaluate(
(s) =>
[...document.querySelectorAll(`.able-popup[id$="${s}"] > li`)].map((li) => ({
text: li.textContent.trim(),
role: li.getAttribute("role"),
})),
idSuffix,
);
expect(await items("-prefs-menu")).toEqual([
{ text: "Captions", role: "menuitem" },
{ text: "Keyboard", role: "menuitem" },
{ text: "Transcript", role: "menuitem" },
]);
expect(await items("-captions-menu")).toEqual([
{ text: "English captions", role: "menuitemradio" },
{ text: "Captions off", role: "menuitemradio" },
]);
expect(await items("-transcript-window-menu")).toEqual([
{ text: "Move", role: "menuitem" },
{ text: "Resize", role: "menuitem" },
{ text: "Close", role: "menuitem" },
]);
});
test("preferences menu opens, focuses its first item, and arrows move focus", async ({ page }) => {
const prefs = btn(page, "preferences");
await prefs.focus();
await page.keyboard.press("Enter");
await expect(prefs).toHaveAttribute("aria-expanded", "true");
const menuItems = page.locator('.able-popup[id$="-prefs-menu"] > li');
await expect(menuItems.nth(0)).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(menuItems.nth(1)).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(menuItems.nth(2)).toBeFocused();
await page.keyboard.press("ArrowUp");
await expect(menuItems.nth(1)).toBeFocused();
await page.keyboard.press("Escape");
await expect(prefs).toHaveAttribute("aria-expanded", "false");
await expect(prefs).toBeFocused();
});
test("volume slider sets the expected volume", async ({ page }) => {
const volume = btn(page, "volume");
await volume.focus();
await page.keyboard.press("Enter");
await expect(volume).toHaveAttribute("aria-expanded", "true");
const range = page.locator(".able-volume-slider input[type=range]");
await expect(range).toBeFocused();
await range.fill("3");
await expect.poll(async () => (await mediaState(page)).volume).toBeCloseTo(0.3, 2);
await expect(volume).toHaveAttribute("aria-label", /30%/);
await page.keyboard.press("ArrowUp");
await expect.poll(async () => (await mediaState(page)).volume).toBeCloseTo(0.4, 2);
await expect(volume).toHaveAttribute("aria-label", /40%/);
});
test("captions button toggles captions on and off", async ({ page }) => {
const captions = btn(page, "captions");
const labelBefore = await captions.getAttribute("aria-label");
await captions.focus();
await page.keyboard.press("Enter");
await expect(captions).not.toHaveAttribute("aria-label", labelBefore);
const labelOff = await captions.getAttribute("aria-label");
await page.keyboard.press("Enter");
await expect(captions).toHaveAttribute("aria-label", labelBefore);
expect(labelOff).not.toBe(labelBefore);
});
test("transcript button opens the transcript and moves focus into it", async ({ page }) => {
const toggle = btn(page, "transcript");
const area = page.locator(".able-transcript-area");
await expect(area).toBeHidden();
await toggle.focus();
await page.keyboard.press("Enter");
await expect(area).toBeVisible();
await expect
.poll(() => page.evaluate(() => Boolean(document.activeElement?.closest(".able-transcript-area"))))
.toBe(true);
// The window menu moves focus between Move / Resize / Close. Able Player
// ignores keys on the window button for ~100ms after it takes focus.
await page.waitForTimeout(250);
await page.keyboard.press("Enter");
const windowItems = page.locator('.able-popup[id$="-transcript-window-menu"] > li');
await expect(windowItems.nth(0)).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(windowItems.nth(1)).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(windowItems.nth(2)).toBeFocused();
});
test("fullscreen toggles on and off without losing focus", async ({ page }) => {
const fs = btn(page, "fullscreen");
const state = () =>
page.evaluate(() => ({
full: Boolean(document.fullscreenElement),
inPlayer: Boolean(document.activeElement?.closest(".able-wrapper")),
}));
await fs.focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await state()).full, { timeout: 10_000 }).toBe(true);
expect((await state()).inPlayer, "focus stays in the player in fullscreen").toBe(true);
await page.keyboard.press("Enter");
await expect.poll(async () => (await state()).full, { timeout: 10_000 }).toBe(false);
expect((await state()).inPlayer, "focus stays in the player after exit").toBe(true);
});
test("clicking a transcript line seeks to that line and plays", async ({ page }) => {
await btn(page, "transcript").click();
const area = page.locator(".able-transcript-area");
await expect(area).toBeVisible();
const target = area.locator("span.able-transcript-seekpoint[data-start]").nth(3);
const start = Number(await target.getAttribute("data-start"));
expect(start).toBeGreaterThan(0);
await target.click();
await expect.poll(async () => (await mediaState(page)).paused, { timeout: 10_000 }).toBe(false);
const { t } = await mediaState(page);
expect(t).toBeGreaterThanOrEqual(start - 0.5);
expect(t).toBeLessThan(start + 3);
});
/* ---------- Chapters (video3), sign language (video5), playlist (playlist2) ---------- */
async function openDemo(page, name) {
await page.goto(`/demos/${name}.html`);
await page.waitForSelector(".able-controller", { timeout: 20_000 });
}
test("video3: selecting a chapter seeks to it and starts playback", async ({ page }) => {
await openDemo(page, "video3");
const chapters = btn(page, "chapters");
const menu = page.locator('.able-popup[id$="-chapters-menu"]');
const items = menu.locator("> li");
await expect(items).toHaveCount(2);
await chapters.focus();
await page.keyboard.press("Enter");
await expect(menu).toBeVisible();
await expect(items.nth(0)).toBeFocused();
await page.keyboard.press("ArrowDown");
await expect(items.nth(1)).toBeFocused();
const start = await page.evaluate(() => {
const m = document.querySelector('.able-popup[id$="-chapters-menu"] > li:nth-child(2)').textContent;
const [mm, ss] = m.split(" - ")[1].split(":").map(Number);
return mm * 60 + ss;
});
expect(start).toBe(37);
await page.keyboard.press("Enter");
await expect(menu).toBeHidden();
await expect(chapters).toBeFocused();
await expect.poll(async () => (await mediaState(page)).t).toBeGreaterThanOrEqual(start - 0.5);
expect((await mediaState(page)).t).toBeLessThan(start + 3);
await expect.poll(async () => (await mediaState(page)).paused, {
message: "selecting a chapter must start playback",
}).toBe(false);
});
test("video5: sign language window opens and both videos play in sync", async ({ page }) => {
await openDemo(page, "video5");
const sign = page.locator(".able-sign-window");
await expect(sign).toBeHidden();
await btn(page, "sign").focus();
await page.keyboard.press("Enter");
await expect(sign).toBeVisible();
const signVideo = sign.locator("video");
await expect(signVideo).toHaveCount(1);
const times = () =>
page.evaluate(() => {
const [main, sign] = document.querySelectorAll("video");
return { main: main.currentTime, sign: sign.currentTime, mp: main.paused, sp: sign.paused };
});
await btn(page, "play").click();
await expect
.poll(async () => {
const s = await times();
return !s.mp && !s.sp && s.main > 1;
}, { timeout: 15_000, message: "both videos must be playing" })
.toBe(true);
const s = await times();
expect(Math.abs(s.main - s.sign)).toBeLessThan(1);
// Seeking the main video re-syncs the sign video.
await btn(page, "forward").click();
await expect
.poll(async () => {
const t = await times();
return Math.abs(t.main - t.sign);
}, { timeout: 10_000 })
.toBeLessThan(1);
await btn(page, "play").click();
await expect.poll(async () => {
const t = await times();
return t.mp && t.sp;
}).toBe(true);
});
test.describe("playlist2", () => {
const current = (page) =>
page.evaluate(() => {
const lis = [...document.querySelectorAll(".able-playlist > li")];
return {
index: lis.findIndex((li) => li.classList.contains("able-current")),
src: document.querySelector("video").currentSrc.split("/").pop(),
};
});
// A track change rebuilds the player; further presses are ignored until it settles.
const settle = async (page) => {
await page.waitForFunction(() => document.querySelector(".able-wrapper video")?.readyState >= 3);
await page.waitForTimeout(1000);
};
test.beforeEach(async ({ page }) => {
await openDemo(page, "playlist2");
await expect(page.locator(".able-playlist > li")).toHaveCount(3);
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(0);
await settle(page);
});
test("playlist items take focus and start playback when activated", async ({ page }) => {
const itemButton = page.locator(".able-playlist > li button").nth(2);
await itemButton.focus();
await expect(itemButton).toBeFocused();
await page.keyboard.press("Enter");
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(2);
await expect.poll(async () => (await current(page)).src).toBe("deadline.mp4");
await expect(itemButton).toHaveAttribute("aria-current", "true");
await expect.poll(async () => (await mediaState(page)).paused, { timeout: 15_000 }).toBe(false);
});
test("next and previous track buttons navigate the playlist", async ({ page }) => {
await btn(page, "next").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(1);
await expect.poll(async () => (await current(page)).src).toBe("itaccess-excerpt.mp4");
await settle(page);
await btn(page, "previous").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(0);
await expect.poll(async () => (await current(page)).src).toBe("wwa.mp4");
await settle(page);
// Previous on the first track wraps to the last.
await btn(page, "previous").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(2);
await expect.poll(async () => (await current(page)).src).toBe("deadline.mp4");
await settle(page);
// Next on the last track wraps to the first.
await btn(page, "next").focus();
await page.keyboard.press("Enter");
await expect.poll(async () => (await current(page)).index, { timeout: 15_000 }).toBe(0);
await settle(page);
});
});
/* ---------- Keyboard shortcuts (default modifiers: Alt + Control) ---------- */
const SHORTCUT = "Alt+Control+";
/** Snapshot of one player's media state; `i` is the player's index on the page (sign-language videos are excluded). */
const playerState = (page, i = 0) =>
page.evaluate((idx) => {
const v = document.querySelectorAll("video[data-able-player]")[idx];
const w = v.closest(".able-wrapper");
return {
paused: v.paused,
muted: v.muted,
volume: v.volume,
// Players with several caption tracks open a menu (aria-expanded) instead of toggling.
captions: ["aria-label", "aria-expanded"]
.map((a) => w.querySelector(".able-button-handler-captions").getAttribute(a))
.join("|"),
volumeOpen: w.querySelector(".able-button-handler-volume").getAttribute("aria-expanded"),
};
}, i);
test.describe("keyboard shortcuts: single player (video1)", () => {
test.beforeEach(async ({ page }) => {
await page.locator(".able-button-handler-restart").first().focus();
});
test("Alt+Ctrl+P toggles play/pause", async ({ page }) => {
await page.keyboard.press(`${SHORTCUT}p`);
await expect.poll(async () => (await playerState(page)).paused, { timeout: 10_000 }).toBe(false);
// The player toggles on its own paused flag, which updates on the media's
// play event; wait for the button to reflect it before pressing again.
await expect(page.locator(".able-button-handler-play").first()).toHaveAttribute("aria-label", /pause/i);
await page.keyboard.press(`${SHORTCUT}p`);
await expect.poll(async () => (await playerState(page)).paused).toBe(true);
});
test("Alt+Ctrl+M toggles mute", async ({ page }) => {
await page.keyboard.press(`${SHORTCUT}m`);
await expect.poll(async () => (await playerState(page)).muted).toBe(true);
await page.keyboard.press(`${SHORTCUT}m`);
await expect.poll(async () => (await playerState(page)).muted).toBe(false);
});
test("Alt+Ctrl+C toggles captions", async ({ page }) => {
const before = (await playerState(page)).captions;
await page.keyboard.press(`${SHORTCUT}c`);
await expect.poll(async () => (await playerState(page)).captions).not.toBe(before);
await page.keyboard.press(`${SHORTCUT}c`);
await expect.poll(async () => (await playerState(page)).captions).toBe(before);
});
test("Alt+Ctrl+V opens the volume slider", async ({ page }) => {
await page.keyboard.press(`${SHORTCUT}v`);
await expect.poll(async () => (await playerState(page)).volumeOpen).toBe("true");
await expect(page.locator(".able-volume-slider")).toBeVisible();
});
test("Alt+Ctrl+1 through 9 set the volume", async ({ page }) => {
for (const n of [1, 2, 3, 4, 5, 6, 7, 8, 9]) {
await page.keyboard.press(`${SHORTCUT}${n}`);
await expect.poll(async () => (await playerState(page)).volume).toBeCloseTo(n / 10, 2);
await expect(page.locator(".able-button-handler-volume")).toHaveAttribute(
"aria-label",
new RegExp(`${n * 10}%`),
);
}
});
test("shortcuts do not fire without the modifier keys", async ({ page }) => {
await page.keyboard.press("p");
await page.keyboard.press("m");
await page.keyboard.press("5");
await page.waitForTimeout(500);
const s = await playerState(page);
expect(s.paused).toBe(true);
expect(s.muted).toBe(false);
expect(s.volume).toBeCloseTo(0.7, 2);
});
});
test.describe("keyboard shortcuts: multiple players (multi3)", () => {
const players = (page) => page.locator(".able-wrapper");
test.beforeEach(async ({ page }) => {
await page.goto("/demos/multi3.html");
await expect(players(page)).toHaveCount(2);
await page.waitForSelector(".able-controller", { timeout: 20_000 });
await page.waitForFunction(() =>
[...document.querySelectorAll("video[data-able-player]")].every((v) => v.readyState >= 1),
);
});
const focusPlayer = (page, i) => players(page).nth(i).locator(".able-button-handler-restart").focus();
for (const i of [0, 1]) {
const other = 1 - i;
test(`play/pause and mute affect only player ${i + 1} when it is focused`, async ({ page }) => {
await focusPlayer(page, i);
await page.keyboard.press(`${SHORTCUT}p`);
await expect.poll(async () => (await playerState(page, i)).paused, { timeout: 10_000 }).toBe(false);
expect((await playerState(page, other)).paused).toBe(true);
await page.keyboard.press(`${SHORTCUT}m`);
await expect.poll(async () => (await playerState(page, i)).muted).toBe(true);
expect((await playerState(page, other)).muted).toBe(false);
});
test(`captions and volume affect only player ${i + 1} when it is focused`, async ({ page }) => {
const otherBefore = await playerState(page, other);
const before = await playerState(page, i);
await focusPlayer(page, i);
await page.keyboard.press(`${SHORTCUT}c`);
await expect.poll(async () => (await playerState(page, i)).captions).not.toBe(before.captions);
expect((await playerState(page, other)).captions).toBe(otherBefore.captions);
await page.keyboard.press(`${SHORTCUT}3`);
await expect.poll(async () => (await playerState(page, i)).volume).toBeCloseTo(0.3, 2);
expect((await playerState(page, other)).volume).toBeCloseTo(otherBefore.volume, 2);
await page.keyboard.press(`${SHORTCUT}v`);
await expect.poll(async () => (await playerState(page, i)).volumeOpen).toBe("true");
expect((await playerState(page, other)).volumeOpen).toBe("false");
});
}
test("shortcuts do nothing when focus is outside every player", async ({ page }) => {
const before = [await playerState(page, 0), await playerState(page, 1)];
await page.evaluate(() => document.activeElement?.blur());
for (const key of ["p", "m", "c", "5", "v"]) {
await page.keyboard.press(`${SHORTCUT}${key}`);
}
await page.waitForTimeout(500);
expect([await playerState(page, 0), await playerState(page, 1)]).toEqual(before);
});
});
You can’t perform that action at this time.
