diff --git a/frontend/src/v2/components/Player/StreamStage.test.ts b/frontend/src/v2/components/Player/StreamStage.test.ts index eb29d125a..614299268 100644 --- a/frontend/src/v2/components/Player/StreamStage.test.ts +++ b/frontend/src/v2/components/Player/StreamStage.test.ts @@ -1,7 +1,11 @@ -import { mount } from "@vue/test-utils"; -import { describe, expect, it } from "vitest"; +import { enableAutoUnmount, mount } from "@vue/test-utils"; +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 +// would answer the next test's events. +enableAutoUnmount(afterEach); + function mountStage(src: string) { return mount(StreamStage, { props: { src, frameTitle: "Stream" }, @@ -10,6 +14,14 @@ function mountStage(src: string) { } describe("StreamStage", () => { + 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( @@ -25,9 +37,26 @@ describe("StreamStage", () => { ); it("does not let the container steer the tab it sits in", () => { - const sandbox = mountStage("http://box:3010/room") - .find("iframe") - .attributes("sandbox"); - expect(sandbox).not.toContain("allow-top-navigation"); + expect(sandbox.join(" ")).not.toContain("allow-top-navigation"); }); + + it.each([ + "gamepad", + "fullscreen", + "autoplay", + "camera", + "microphone", + "clipboard-write", + ])("delegates %s to the container", (feature) => { + expect(allow).toContain(`${feature} *`); + }); + + // An opaque origin gets no media permission, so the room's webcam and mic + // need the container to keep its own origin. + it.each(["allow-scripts", "allow-same-origin"])( + "keeps %s so the room can run and ask for media", + (flag) => { + expect(sandbox).toContain(flag); + }, + ); }); diff --git a/frontend/src/v2/components/Player/StreamStage.vue b/frontend/src/v2/components/Player/StreamStage.vue index 7bad463d6..f2abcf124 100644 --- a/frontend/src/v2/components/Player/StreamStage.vue +++ b/frontend/src/v2/components/Player/StreamStage.vue @@ -304,7 +304,14 @@ defineExpose({ ref="streamFrame" :src="frameSrc" class="r-v2-stage__frame" - allow="gamepad *; fullscreen *; autoplay *" + allow=" + gamepad *; + fullscreen *; + autoplay *; + camera *; + microphone *; + clipboard-write *; + " allowfullscreen referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-modals allow-pointer-lock allow-downloads"