diff --git a/frontend/src/v2/components/Player/StreamStage.test.ts b/frontend/src/v2/components/Player/StreamStage.test.ts index d3603fcf4..38f6cdfa1 100644 --- a/frontend/src/v2/components/Player/StreamStage.test.ts +++ b/frontend/src/v2/components/Player/StreamStage.test.ts @@ -1,5 +1,5 @@ import { enableAutoUnmount, mount } from "@vue/test-utils"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, beforeAll, describe, expect, it } from "vitest"; import StreamStage from "./StreamStage.vue"; // The stage listens on window and runs attach timers, so a mount left standing @@ -13,13 +13,17 @@ function mountStage(src: string) { }); } -function frameAttr(name: string): string { - return ( - mountStage("http://box:3010/room").find("iframe").attributes(name) ?? "" - ); -} - describe("StreamStage", () => { + // The frame's allow and sandbox lists are static, so one mount serves every + // case that reads them. + let allow: string[] = []; + let sandbox: string[] = []; + beforeAll(() => { + const frame = mountStage("http://box:3010/room").find("iframe"); + allow = (frame.attributes("allow") ?? "").split(";").map((d) => d.trim()); + sandbox = (frame.attributes("sandbox") ?? "").split(/\s+/); + }); + it("renders a container URL the broker answered with", () => { const wrapper = mountStage("http://192.168.1.10:3000/streaming/room/abc"); expect(wrapper.find("iframe").attributes("src")).toBe( @@ -35,7 +39,7 @@ describe("StreamStage", () => { ); it("does not let the container steer the tab it sits in", () => { - expect(frameAttr("sandbox")).not.toContain("allow-top-navigation"); + expect(sandbox.join(" ")).not.toContain("allow-top-navigation"); }); it.each([ @@ -46,10 +50,7 @@ describe("StreamStage", () => { "microphone", "clipboard-write", ])("delegates %s to the container", (feature) => { - const directives = frameAttr("allow") - .split(";") - .map((d) => d.trim()); - expect(directives).toContain(`${feature} *`); + expect(allow).toContain(`${feature} *`); }); // An opaque origin gets no media permission, so the room's webcam and mic @@ -57,7 +58,7 @@ describe("StreamStage", () => { it.each(["allow-scripts", "allow-same-origin"])( "keeps %s so the room can run and ask for media", (flag) => { - expect(frameAttr("sandbox").split(/\s+/)).toContain(flag); + expect(sandbox).toContain(flag); }, ); });