From 5740fd345122f1f8d671c70ded79f043871d19ea Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Fri, 20 Nov 2026 15:40:03 +0100 Subject: [PATCH] Describe what the late device tests do Co-Authored-By: Claude Fable 5.2 --- playwright/widget/late-device.spec.ts | 20 +++++++++++++++ src/state/MuteStates.test.ts | 35 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/playwright/widget/late-device.spec.ts b/playwright/widget/late-device.spec.ts index 4b919b0dc..5f7a0ab58 100644 --- a/playwright/widget/late-device.spec.ts +++ b/playwright/widget/late-device.spec.ts @@ -12,6 +12,21 @@ import { TestHelpers } from "./test-helpers.ts"; widgetTest.use({ callType: "dm" }); +// The bug from issue #4403, in a real call between two users in Element Web. +// 1. Brooks' browser is made slow: it lists its camera and microphone only +// after the call is on screen. +// 2. Brooks starts a video call in a DM. A DM call has no lobby. +// 3. Whistler picks up. +// 4. Brooks' camera button shows "on". +// 5. Whistler must see two videos: their own and the one brooks sends. +// Before the fix whistler saw only their own video. +// +// What it guards: the unit tests only check the mute button's own logic. This +// test checks the whole chain: button, call, SFU, and what the other person +// really sees. The bug depends on timing (camera listed before or after the +// call opens), so the normal DM call tests pass by luck most of the time. +// This test forces the bad timing every run, so a regression shows up always +// and not only sometimes. widgetTest( "Publishes a camera the browser lists only once the call is on screen", async ({ asWidget, browserName }) => { @@ -53,6 +68,11 @@ widgetTest( /** * Holds the device list back in the widget until the call view shows a tile, * as a browser that is slow to answer does. Call before the widget loads. + * + * How: it replaces the browser's `enumerateDevices` with one that waits. It + * checks every 50ms whether a video tile is on the page, waits half a second + * more, and only then gives the real list. Element Web itself (the outer + * page) is left alone; only the call inside the iframe is slowed down. */ async function listDevicesOnlyInTheCall(page: Page): Promise { await page.addInitScript(() => { diff --git a/src/state/MuteStates.test.ts b/src/state/MuteStates.test.ts index 98b2f22ee..37ae4848b 100644 --- a/src/state/MuteStates.test.ts +++ b/src/state/MuteStates.test.ts @@ -170,6 +170,18 @@ describe("MuteState", () => { expect(syncingValues.at(-1)).toBe(false); }); + // The bug from issue #4403: we join a call without a lobby, and the browser + // tells us about the camera only after the call has started. + // 1. Start with no camera, with the camera set to be on by default. + // 2. Set a handler, like the call does when it starts. + // 3. The camera shows up. + // The handler must be called with "on", so the call publishes the camera, + // and the button must show "on" only after the handler is done. + // + // What it guards: the button and the real camera must never disagree. In + // the bug the button jumped to "on" by itself and nobody told the call, so + // the other side saw "Waiting for media". If someone changes how the + // default is applied and forgets the handler again, this test fails. test("asks the handler for the default of a device listed after it was set", async () => { const available$ = new BehaviorSubject(new Map()); const muteState = new MuteState( @@ -192,6 +204,18 @@ describe("MuteState", () => { expect(muteState.syncing$.value).toBe(false); }); + // A camera that is unplugged and plugged back in during a call. + // 1. Start with a camera, on by default, and set a handler. + // 2. The camera goes away, then comes back. + // The handler is told "off" when the camera goes away and is not called + // again. The camera stays off: we must not turn on a camera that the user + // may have turned off before. + // + // What it guards: a privacy problem the fix for #4403 could cause. The fix + // sends the default "on" to the handler. If it did that every time a + // camera shows up, replugging a camera (or leaving earpiece mode) would + // start sending video without the user asking. This test fails if the + // default is ever applied a second time during a call. test("leaves a device that comes back under a handler off", async () => { const available$ = new BehaviorSubject(aCamera); const muteState = new MuteState( @@ -212,6 +236,15 @@ describe("MuteState", () => { expect(muteState.enabled$.value).toBe(false); }); + // The lobby case, which must keep working as before: no handler is set. + // 1. Start with no camera, with the camera set to be on by default. + // 2. The camera shows up. + // The button shows "on" right away, with no waiting. + // + // What it guards: the lobby and the join read the button's value at once + // to decide which devices to open. If the fix for #4403 made the default + // wait for a handler here too, the value would be "off" for a moment and + // the lobby would open no camera. This test fails if that happens. test("assumes the default at once where no handler is set", () => { const available$ = new BehaviorSubject(new Map()); const muteState = new MuteState( @@ -226,10 +259,12 @@ describe("MuteState", () => { expect(muteState.enabled$.value).toBe(true); }); + // A device list with one camera in it. const aCamera = new Map([ ["fbac11", { type: "name", name: "HD Camera" }], ]); + // A fake camera whose device list the test can change while it runs. function aDevice( available$: BehaviorSubject>, ): MediaDevice {