From 96e05ffbec2e522dbc1a7814dfb271baa6aaded3 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:30:57 +0000 Subject: [PATCH] test(browser): name the foreground window in Windows holder replies --- .../browser-agent-input-focus-isolation-native.spec.ts | 7 +++---- tests/e2e/helpers/windows-foreground-holder.ps1 | 6 +++++- tests/e2e/helpers/windows-foreground-holder.ts | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/e2e/browser-agent-input-focus-isolation-native.spec.ts b/tests/e2e/browser-agent-input-focus-isolation-native.spec.ts index f55eaa1ac3c..244f9714a0b 100644 --- a/tests/e2e/browser-agent-input-focus-isolation-native.spec.ts +++ b/tests/e2e/browser-agent-input-focus-isolation-native.spec.ts @@ -86,12 +86,11 @@ for (const [name, run] of scenarios) { await holder.take() await run(orcaPage, async (pageId) => { // Why: a guest press that activates Orca's window pulls it over the app the user is in. - expect(await holder.foreground()).toEqual({ holder: true, pid: expect.any(Number) }) + expect(await holder.foreground()).toMatchObject({ holder: true }) // The same check must see Orca once it really is activated, or the one above proves nothing. + const orcaPid = await electronApp.evaluate(() => process.pid) await ownedWindow.evaluate((window) => window.focus()) - await expect - .poll(() => holder.foreground()) - .toEqual({ holder: false, pid: electronApp.process().pid }) + await expect.poll(() => holder.foreground()).toMatchObject({ holder: false, pid: orcaPid }) await realKeystrokeReachesTerminal(orcaPage, electronApp, holder.press)(pageId) }) } finally { diff --git a/tests/e2e/helpers/windows-foreground-holder.ps1 b/tests/e2e/helpers/windows-foreground-holder.ps1 index 492454219e9..98eca1b1b0c 100644 --- a/tests/e2e/helpers/windows-foreground-holder.ps1 +++ b/tests/e2e/helpers/windows-foreground-holder.ps1 @@ -5,6 +5,7 @@ Add-Type -ReferencedAssemblies System.Windows.Forms -TypeDefinition @' using System; using System.Collections.Concurrent; using System.Runtime.InteropServices; +using System.Text; using System.Threading; using System.Windows.Forms; @@ -15,6 +16,7 @@ public static class OrcaForegroundHolder { [DllImport("user32.dll")] static extern bool BringWindowToTop(IntPtr hwnd); [DllImport("user32.dll")] static extern bool AllowSetForegroundWindow(int processId); [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint processId); + [DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowText(IntPtr hwnd, StringBuilder text, int count); [DllImport("user32.dll")] static extern bool AttachThreadInput(uint attach, uint attachTo, bool enable); [DllImport("kernel32.dll")] static extern uint GetCurrentThreadId(); [DllImport("user32.dll")] static extern short VkKeyScan(char ch); @@ -76,7 +78,9 @@ public static class OrcaForegroundHolder { IntPtr foreground = GetForegroundWindow(); uint processId; GetWindowThreadProcessId(foreground, out processId); - return (foreground == form.Handle ? "holder " : "other ") + processId; + StringBuilder title = new StringBuilder(256); + GetWindowText(foreground, title, title.Capacity); + return (foreground == form.Handle ? "holder " : "other ") + processId + " " + title; } static bool Take() { diff --git a/tests/e2e/helpers/windows-foreground-holder.ts b/tests/e2e/helpers/windows-foreground-holder.ts index d2420acfee1..4e503d3d98e 100644 --- a/tests/e2e/helpers/windows-foreground-holder.ts +++ b/tests/e2e/helpers/windows-foreground-holder.ts @@ -12,8 +12,8 @@ const REPLY_TIMEOUT_MS = 15_000 export type WindowsForegroundHolder = { /** Activates the holder and lifts the foreground lock, so an Orca activation attempt would succeed. */ take: () => Promise - /** Which window has the real foreground: the holder, or another process by pid. */ - foreground: () => Promise<{ holder: boolean; pid: number }> + /** Which window has the real foreground: the holder, or another process's window. */ + foreground: () => Promise<{ holder: boolean; pid: number; title: string }> /** Presses one key through the OS input queue, so it reaches whichever window is in front. */ press: (key: string) => Promise close: () => Promise @@ -96,8 +96,8 @@ export async function startWindowsForegroundHolder(): Promise { - const [owner, pid] = (await send('foreground')).split(' ') - return { holder: owner === 'holder', pid: Number(pid) } + const [owner, pid, ...title] = (await send('foreground')).split(' ') + return { holder: owner === 'holder', pid: Number(pid), title: title.join(' ') } }, press: async (key) => { await send(`key ${key}`)