diff --git a/scripts/test-server-ws.mjs b/scripts/test-server-ws.mjs index f85d2e5..7515e14 100644 --- a/scripts/test-server-ws.mjs +++ b/scripts/test-server-ws.mjs @@ -521,6 +521,7 @@ try { s(msgHost, 'leave_room', {}); s(msgGuest, 'leave_room', {}); + s(msgLateJoiner, 'leave_room', {}); await delay(80); assert.equal(mod.rooms.has(msgateRid), false, 'empty-room cleanup removes canonical state with the room'); // --- Terminal room timeout: coded error + complete membership cleanup --- diff --git a/tests/e2e/extension.spec.mjs b/tests/e2e/extension.spec.mjs index bf0a60f..9753ec2 100644 --- a/tests/e2e/extension.spec.mjs +++ b/tests/e2e/extension.spec.mjs @@ -406,21 +406,30 @@ test('recovers relay ROOM_DATA through background retries into the packed player const page = await context.newPage(); await page.goto(url); await page.waitForFunction(() => window.__fixtureReady === true); - await selectTargetTab(context, extensionId, url); - await page.locator('#player').evaluate(video => { - const nativePlay = video.play.bind(video); - window.__koalaCanonicalPlayAttempts = 0; - Object.defineProperty(video, 'play', { - configurable: true, - value: () => { - window.__koalaCanonicalPlayAttempts++; - if (window.__koalaCanonicalPlayAttempts === 1) { - return Promise.reject(new DOMException('audit autoplay rejection', 'NotAllowedError')); - } - return nativePlay(); + const { tabId } = await selectTargetTab(context, extensionId, url); + await withExtensionPage(context, extensionId, extensionPage => extensionPage.evaluate(async selectedTabId => { + await chrome.scripting.executeScript({ + target: { tabId: selectedTabId }, + world: 'ISOLATED', + func: () => { + const video = document.querySelector('#player'); + if (!video) throw new Error('canonical recovery fixture video missing'); + const nativePlay = video.play.bind(video); + video.dataset.koalaCanonicalPlayAttempts = '0'; + Object.defineProperty(video, 'play', { + configurable: true, + value: () => { + const attempts = Number(video.dataset.koalaCanonicalPlayAttempts || '0') + 1; + video.dataset.koalaCanonicalPlayAttempts = String(attempts); + if (attempts === 1) { + return Promise.reject(new DOMException('audit autoplay rejection', 'NotAllowedError')); + } + return nativePlay(); + } + }); } }); - }); + }, tabId)); legacy.messages.length = 0; await withExtensionPage(context, extensionId, extensionPage => extensionPage.evaluate(async settings => { @@ -436,7 +445,8 @@ test('recovers relay ROOM_DATA through background retries into the packed player await expect.poll(() => getExtensionState(context, extensionId, { type: 'GET_STATUS' })) .toMatchObject({ status: 'connected', roomId, queuedLogicalEvents: 0 }); - await expect.poll(() => page.evaluate(() => window.__koalaCanonicalPlayAttempts)) + await expect.poll(() => page.locator('#player').evaluate(video => + Number(video.dataset.koalaCanonicalPlayAttempts || '0'))) .toBeGreaterThanOrEqual(2); await expect.poll(() => page.locator('#player').evaluate(video => ({ paused: video.paused,