Skip to content

Commit 075a5e4

Browse files
test(studio): the player pixel test waits for a decoded frame before it reads (#9094)
* test(studio): the player pixel test waits for a decoded frame before it reads * test(studio): a refused pixel read fails at once with the browser's reason
1 parent 9ea9a2c commit 075a5e4

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

‎packages/studio/src/player/playerFilms.browser.test.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,31 @@ it.each(MODES)("a %s player keeps a video's pixels readable for effects", async
240240
),
241241
);
242242
await play(page);
243-
await frame.waitForFunction(
244-
() => (document.getElementById("clip") as HTMLVideoElement).readyState >= 2,
245-
{
246-
timeout: 20_000,
247-
},
248-
);
249-
const read = await frame.evaluate(() => {
250-
const canvas = document.createElement("canvas");
251-
canvas.width = canvas.height = 8;
252-
const context = canvas.getContext("2d")!;
253-
context.drawImage(document.getElementById("clip") as HTMLVideoElement, 0, 0, 8, 8);
254-
try {
255-
return { pixel: [...context.getImageData(4, 4, 1, 1).data] };
256-
} catch (error) {
257-
return { refused: String(error) };
258-
}
259-
});
243+
const read = () =>
244+
frame.evaluate(() => {
245+
const canvas = document.createElement("canvas");
246+
canvas.width = canvas.height = 8;
247+
const context = canvas.getContext("2d")!;
248+
context.drawImage(document.getElementById("clip") as HTMLVideoElement, 0, 0, 8, 8);
249+
try {
250+
return { pixel: [...context.getImageData(4, 4, 1, 1).data] };
251+
} catch (error) {
252+
return { refused: String(error) };
253+
}
254+
});
255+
// Until a frame is decoded the draw reads transparent. A refused read is final, so it ends the wait.
256+
let last: Awaited<ReturnType<typeof read>> | undefined;
257+
await expect
258+
.poll(
259+
async () => {
260+
last = await read();
261+
return "refused" in last || last.pixel[3] !== 0;
262+
},
263+
{ timeout: 10_000, message: "the video never drew a frame" },
264+
)
265+
.toBe(true);
260266
// A decoded h.264 red lands within about 16 of pure red per channel.
261-
expect(read).toEqual({
267+
expect(last).toEqual({
262268
pixel: [expect.closeTo(255, -1.5), expect.closeTo(0, -1.5), expect.closeTo(0, -1.5), 255],
263269
});
264270
});

0 commit comments

Comments
 (0)