From 2801303a470c6410ba3c226d76d6b5719a2d31dc Mon Sep 17 00:00:00 2001 From: KingKDot Date: Thu, 30 Jul 2026 15:12:16 -0500 Subject: [PATCH] fix tests --- .../e2e/remotedesktop-canvas-presentation.e2e.ts | 7 +++++-- Overlord-Server/test/e2e/remotedesktop-input.e2e.ts | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Overlord-Server/test/e2e/remotedesktop-canvas-presentation.e2e.ts b/Overlord-Server/test/e2e/remotedesktop-canvas-presentation.e2e.ts index a777338..b0ad85a 100644 --- a/Overlord-Server/test/e2e/remotedesktop-canvas-presentation.e2e.ts +++ b/Overlord-Server/test/e2e/remotedesktop-canvas-presentation.e2e.ts @@ -20,9 +20,12 @@ test("Canvas presents only the latest decoded video frame per browser refresh", bufferedAmount = 0; binaryType: BinaryType = "blob"; - constructor(_url: string | URL) { + constructor(url: string | URL) { super(); - Object.defineProperty(window, "__rdSocket", { value: this, configurable: true }); + const isRemoteDesktopControl = new URL(String(url), window.location.href).pathname.endsWith("/rd/ws"); + if (isRemoteDesktopControl) { + Object.defineProperty(window, "__rdSocket", { value: this, configurable: true }); + } queueMicrotask(() => this.dispatchEvent(new Event("open"))); } diff --git a/Overlord-Server/test/e2e/remotedesktop-input.e2e.ts b/Overlord-Server/test/e2e/remotedesktop-input.e2e.ts index a1ce7b1..3d69fd9 100644 --- a/Overlord-Server/test/e2e/remotedesktop-input.e2e.ts +++ b/Overlord-Server/test/e2e/remotedesktop-input.e2e.ts @@ -19,14 +19,19 @@ test("WebRTC input stays inactive until start and then forwards mouse and keyboa readyState = FakeWebSocket.OPEN; bufferedAmount = 0; binaryType: BinaryType = "blob"; + private readonly isRemoteDesktopControl: boolean; - constructor(_url: string | URL) { + constructor(url: string | URL) { super(); - Object.defineProperty(window, "__rdSocket", { value: this, configurable: true }); + this.isRemoteDesktopControl = new URL(String(url), window.location.href).pathname.endsWith("/rd/ws"); + if (this.isRemoteDesktopControl) { + Object.defineProperty(window, "__rdSocket", { value: this, configurable: true }); + } queueMicrotask(() => this.dispatchEvent(new Event("open"))); } send(data: ArrayBuffer | ArrayBufferView | Blob | string) { + if (!this.isRemoteDesktopControl) return; if (data instanceof ArrayBuffer) sent.push(data); else if (ArrayBuffer.isView(data)) { sent.push(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength) as ArrayBuffer); @@ -67,6 +72,9 @@ test("WebRTC input stays inactive until start and then forwards mouse and keyboa await expect(page.locator("#requestKeyframeBtn")).toBeDisabled(); await page.evaluate(() => { + // Other page features may open sockets after the RD control connection. + // They must not replace the socket used for injected control messages. + new WebSocket("/api/clients/webrtc-input-test/desktop-audio/ws"); const sent = (window as typeof window & { __rdSent: ArrayBuffer[] }).__rdSent; sent.length = 0; const mouseCtrl = document.querySelector("#mouseCtrl")!;