From b25e1a22ec11e3acc7b8e6beb423db13996bb069 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Fri, 20 Nov 2026 13:00:57 -0800 Subject: [PATCH 1/2] Host browser tests: choosing a mode in the menu waits for its focus to return modes.spec's "embedders can control the comparison mode and divider" failed on the mobile projects (webkit-mobile 3 times, once on main, and chromium-mobile): ArrowRight on the swipe divider left it at 50%. There the mode switch is a menu. Choosing Swipe closes it, and the popover gives focus back to its button only as it leaves, after its exit animation. The test had focused the divider by then, and the menu took the focus back before the key. chooseMode now returns once the menu is gone and its button has focus. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/host/core/browser/harness.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/host/core/browser/harness.ts b/packages/host/core/browser/harness.ts index 8e93f6f89..9323c94c5 100644 --- a/packages/host/core/browser/harness.ts +++ b/packages/host/core/browser/harness.ts @@ -110,9 +110,18 @@ export async function modeGroup(scope: Scope): Promise { await menu.waitFor() return menu.getByRole('radiogroup', {name: 'Comparison mode'}) } -/** Chooses a comparison mode (in the menu, choosing closes it). */ +/** + * Chooses a comparison mode. In the menu, choosing closes it, and this returns once the menu has given focus back to + * its button, which it does only as it leaves after its exit animation: a control the test focused before then would + * lose its focus, and the keys pressed next would go to the button. + */ export async function chooseMode(scope: Scope, name: string) { - await (await modeGroup(scope)).getByRole('radio', {name, exact: true}).click() + const group = await modeGroup(scope) + const inMenu = (await group.locator('xpath=ancestor::*[@role="dialog"]').count()) > 0 + await group.getByRole('radio', {name, exact: true}).click() + if (!inMenu) return + await settled(scope) + await expect(scope.getByRole('button', {name: /^Comparison mode: /}).first()).toBeFocused() } /** Asserts the checked mode, closing the menu again if it had to be opened. */ export async function expectMode(scope: Scope, name: string) { From b9516aef671858280dd9452164c0ea69f66c7502 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Fri, 20 Nov 2026 13:28:31 -0800 Subject: [PATCH 2/2] Host browser tests: wait for the closing mode menu's focus hand-off, wherever focus goes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/host/core/browser/harness.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/host/core/browser/harness.ts b/packages/host/core/browser/harness.ts index 9323c94c5..fdb9668f4 100644 --- a/packages/host/core/browser/harness.ts +++ b/packages/host/core/browser/harness.ts @@ -111,9 +111,9 @@ export async function modeGroup(scope: Scope): Promise { return menu.getByRole('radiogroup', {name: 'Comparison mode'}) } /** - * Chooses a comparison mode. In the menu, choosing closes it, and this returns once the menu has given focus back to - * its button, which it does only as it leaves after its exit animation: a control the test focused before then would - * lose its focus, and the keys pressed next would go to the button. + * Chooses a comparison mode. In the menu, choosing closes it, and this returns once the menu has handed focus on: it + * does so only as it unmounts, after its exit animation, so a control the test focused before then would lose its + * focus, and the keys pressed next would miss it. */ export async function chooseMode(scope: Scope, name: string) { const group = await modeGroup(scope) @@ -121,7 +121,8 @@ export async function chooseMode(scope: Scope, name: string) { await group.getByRole('radio', {name, exact: true}).click() if (!inMenu) return await settled(scope) - await expect(scope.getByRole('button', {name: /^Comparison mode: /}).first()).toBeFocused() + // The popover's focus scope hands focus on in a timer it starts as it unmounts; one started now runs after it. + await pageOf(scope).evaluate(() => new Promise(resolve => setTimeout(resolve, 0))) } /** Asserts the checked mode, closing the menu again if it had to be opened. */ export async function expectMode(scope: Scope, name: string) {