Skip to content

Commit c10baa5

Browse files
authored
fix: qualify Windows activation and Win32 secondary content windows (#4498)
1 parent 5ee3dc7 commit c10baa5

42 files changed

Lines changed: 2301 additions & 88 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/brave-popup-listings.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/desktop-driver': patch
3+
---
4+
5+
Keep Windows and Win32 window listings available when a secondary window closes between discovery and native geometry serialization, without hiding failures for live windows.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/native-core': patch
3+
---
4+
5+
Give the legacy Callout window-command story's focus and blur buttons stable test identities for unique secondary-window input qualification.

‎.changeset/quiet-menu-windows.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@fluentui-react-native/desktop-driver': patch
3+
---
4+
5+
Add a session-scoped, non-activating window tree query so consumers can distinguish legitimate secondary menus from unexpected dialogs without dismissing the menu.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@fluentui-react-native/desktop-driver": patch
3+
"@fluentui-react-native/desktop-driver-mcp": patch
4+
"@fluentui-react-native/desktop-test": patch
5+
"@fluentui-react-native/storybook-desktop": patch
6+
---
7+
8+
Record Windows Fabric and Win32 Paper connected-session qualification,
9+
physical MCP click costs, explicit untested display scenarios, and the
10+
remaining secondary-window semantic activation and registration gaps.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@fluentui-react-native/desktop-driver': patch
3+
---
4+
5+
Refuse Windows legacy-only semantic activation before dispatch, preserving machine-readable reasons without recording a delivery or implicitly retrying with physical input.
6+
7+
Register untitled Windows secondary tool popups only when their exact-process ownership and bounded UIA content are verified, retaining helper-window exclusions.
8+
9+
Keep admitted popups listable through transient provider failures, share one bounded discovery deadline across new candidates, and include admitted popups in publication diagnostics.

‎apps/E2E/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ Native setup retains initial
138138
window bounds: it does **not** emulate the old maximize hook. Popup lookup
139139
remains scoped to the selected window.
140140

141+
On Windows and Win32, the assertion-dialog safety check inspects each secondary
142+
window without selecting or activating it, so it cannot dismiss an open menu.
143+
Only a single accessibility `menu` root without nested dialogs or windows is
144+
recognized as an expected popup. A tree read reporting `no such window` is
145+
treated as a closed popup. Empty or unrecognized roots fail the check only
146+
when a fresh window listing still includes that handle, avoiding false
147+
assertions while a menu closes. Every other tree-read error still fails the
148+
test rather than being treated as no assertion.
149+
The native-task-library bypass, Android page check, and other runners' existing
150+
window-count check are unchanged.
151+
141152
WebdriverIO 10 throws a `StrictSelectorError` when a selector matches several
142153
elements, where WebdriverIO 9 took the first match. A native tree can expose
143154
several elements for one `testID` (a container and its children), and the page

‎apps/E2E/desktop-adapters.test.cjs‎

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,162 @@
11
const assert = require('node:assert/strict');
2-
const { afterEach, test } = require('node:test');
2+
const { afterEach, mock, test } = require('node:test');
33
const { BasePage } = require('./lib/common/BasePage.js');
44
const { Keys } = require('./lib/common/consts.js');
55
const { installLegacyDesktopAttributes, scrollNativeDesktopElement, sendNativeDesktopKeys } = require('./lib/common/nativeDesktop.js');
66

77
afterEach(() => {
8+
mock.restoreAll();
89
delete globalThis.browser;
910
});
1011

12+
test('Windows assertion checks inspect menu windows without selecting or activating them', async () => {
13+
const reads = [];
14+
globalThis.browser = {
15+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'win32' },
16+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
17+
sessionId: 'session',
18+
getWindowHandles: async () => ['main', 'menu'],
19+
getWindowHandle: async () => 'main',
20+
switchToWindow: () => assert.fail('an assertion check must not change native focus'),
21+
};
22+
mock.method(globalThis, 'fetch', async (url, init) => {
23+
reads.push(String(url));
24+
assert.equal(init.method, 'GET');
25+
return new Response(JSON.stringify({ value: [{ role: 'menu', children: [{ role: 'menuitem', children: [] }] }] }));
26+
});
27+
assert.equal(await new BasePage().didAssertPopup(), false);
28+
// eslint-disable-next-line @microsoft/sdl/no-insecure-url -- mocked loopback transport; no service is contacted
29+
assert.deepEqual(reads, ['http://127.0.0.1:1/session/session/furn/window/menu/tree']);
30+
browser.getWindowHandles = async () => ['main'];
31+
browser.getWindowHandle = () => assert.fail('one window needs no further inspection');
32+
assert.equal(await new BasePage().didAssertPopup(), false);
33+
assert.equal(reads.length, 1);
34+
});
35+
36+
test('Windows assertion checks fail closed for dialogs, unrecognized roots, and unreadable windows', async () => {
37+
globalThis.browser = {
38+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'windows' },
39+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
40+
sessionId: 'session',
41+
getWindowHandles: async () => ['main', 'other'],
42+
getWindowHandle: async () => 'main',
43+
switchToWindow: () => assert.fail('an assertion check must not change native focus'),
44+
};
45+
let value;
46+
const reader = mock.method(globalThis, 'fetch', async () => new Response(JSON.stringify({ value })));
47+
const page = new BasePage();
48+
for (const roots of [
49+
[{ role: 'window', name: 'Assertion failed', children: [] }],
50+
[{ role: 'group', children: [] }],
51+
[],
52+
[{ role: 'menu', children: [{ role: 'dialog', children: [] }] }],
53+
[{ role: 'menu', children: [{ role: 'window', children: [] }] }],
54+
[
55+
{ role: 'menu', children: [] },
56+
{ role: 'dialog', children: [] },
57+
],
58+
]) {
59+
value = roots;
60+
assert.equal(await page.didAssertPopup(), true);
61+
}
62+
reader.mock.mockImplementation(async () => {
63+
throw new Error('provider is unavailable');
64+
});
65+
await assert.rejects(page.didAssertPopup(), /provider is unavailable/);
66+
});
67+
68+
test('Windows assertion checks do not let an open menu hide another unexpected window', async () => {
69+
globalThis.browser = {
70+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'win32' },
71+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
72+
sessionId: 'session',
73+
getWindowHandles: async () => ['main', 'menu', 'assert'],
74+
getWindowHandle: async () => 'main',
75+
};
76+
mock.method(
77+
globalThis,
78+
'fetch',
79+
async (url) =>
80+
new Response(
81+
JSON.stringify({
82+
value: [{ role: String(url).endsWith('/menu/tree') ? 'menu' : 'window', children: [] }],
83+
}),
84+
),
85+
);
86+
assert.equal(await new BasePage().didAssertPopup(), true);
87+
});
88+
89+
test('Windows assertion checks skip a vanished menu and continue checking other windows', async () => {
90+
let handles = ['main', 'closing-menu'];
91+
globalThis.browser = {
92+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'win32' },
93+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
94+
sessionId: 'session',
95+
getWindowHandles: async () => handles,
96+
getWindowHandle: async () => 'main',
97+
switchToWindow: () => assert.fail('an assertion check must not change native focus'),
98+
};
99+
mock.method(globalThis, 'fetch', async (url) =>
100+
String(url).endsWith('/closing-menu/tree')
101+
? new Response(JSON.stringify({ value: { error: 'no such window', message: 'The menu closed.' } }), { status: 404 })
102+
: new Response(JSON.stringify({ value: [{ role: 'window', name: 'Assertion failed', children: [] }] })),
103+
);
104+
const page = new BasePage();
105+
assert.equal(await page.didAssertPopup(), false);
106+
handles = ['main', 'closing-menu', 'assert'];
107+
assert.equal(await page.didAssertPopup(), true);
108+
});
109+
110+
test('Windows assertion checks recheck an empty or unrecognized root before reporting an assertion', async () => {
111+
let lists = 0;
112+
globalThis.browser = {
113+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'win32' },
114+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
115+
sessionId: 'session',
116+
getWindowHandles: async () => (++lists === 1 ? ['main', 'closing-menu'] : ['main']),
117+
getWindowHandle: async () => 'main',
118+
switchToWindow: () => assert.fail('an assertion check must not change native focus'),
119+
};
120+
let value;
121+
mock.method(globalThis, 'fetch', async () => new Response(JSON.stringify({ value })));
122+
const page = new BasePage();
123+
for (const roots of [[], [{ role: 'group', children: [] }], [{ role: 'menu', children: [{ role: 'dialog', children: [] }] }]]) {
124+
lists = 0;
125+
value = roots;
126+
assert.equal(await page.didAssertPopup(), false);
127+
}
128+
});
129+
130+
test('Windows assertion checks do not treat other provider errors as closed windows', async () => {
131+
globalThis.browser = {
132+
capabilities: { browserName: 'furn-native-desktop', platformName: 'windows', 'furn:endpoint': 'win32' },
133+
options: { protocol: 'http', hostname: '127.0.0.1', port: 1, path: '/' },
134+
sessionId: 'session',
135+
getWindowHandles: async () => ['main', 'unreadable-menu'],
136+
getWindowHandle: async () => 'main',
137+
};
138+
let code;
139+
mock.method(
140+
globalThis,
141+
'fetch',
142+
async () => new Response(JSON.stringify({ value: { error: code, message: 'The provider could not read the tree.' } }), { status: 500 }),
143+
);
144+
for (const error of ['unknown error', 'stale element reference']) {
145+
code = error;
146+
await assert.rejects(new BasePage().didAssertPopup(), { code: error });
147+
}
148+
});
149+
150+
test('assertion checks retain non-native and macOS window-count behavior', async () => {
151+
for (const capabilities of [
152+
{ browserName: 'non-native' },
153+
{ browserName: 'furn-native-desktop', platformName: 'macos', 'furn:endpoint': 'macos' },
154+
]) {
155+
globalThis.browser = { capabilities, getWindowHandles: async () => ['main', 'other'] };
156+
assert.equal(await new BasePage().didAssertPopup(), true);
157+
}
158+
});
159+
11160
test('native checkbox and switch state never falls back to selected', async () => {
12161
const page = new BasePage();
13162
const element = { elementId: 'toggle', isSelected: () => assert.fail('checked is not selected') };

‎apps/E2E/src/common/BasePage.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
TESTPAGE_BUTTONS_SCROLLVIEWER,
1313
TESTPAGE_CONTENT_SCROLLVIEWER,
1414
} from './consts.js';
15-
import { isNativeDesktop, scrollNativeDesktopElement, sendNativeDesktopKeys } from './nativeDesktop.js';
15+
import { hasUnexpectedNativeDesktopWindow, isNativeDesktop, scrollNativeDesktopElement, sendNativeDesktopKeys } from './nativeDesktop.js';
1616
import type { PageElement } from './nativeDesktop.js';
1717

1818
const DUMMY_CHAR = '';
@@ -440,9 +440,9 @@ export abstract class BasePage {
440440
* WHY/HOW: Unfortunately, some Asserts don't take focus away from the test app. Because of this, the test execution is able
441441
* to continue without realizing an assert as popped up (unless the assert is a crashing one).
442442
*
443-
* In order to detect an assert, this function gets the number of window handles currently open within the test app.
444-
* Only one instance SHOULD be open at a time (the app itself). If another instance of the app is open, we know an assert dialogue
445-
* has popped up. With this information, we know to fail the test.
443+
* Unexpected secondary windows can indicate a non-focusing assert. Windows native menus are legitimate secondary
444+
* windows, so inspect their accessibility roots without changing focus. Unrecognized windows still fail the check,
445+
* and an unreadable window fails the test rather than silently claiming no assert.
446446
*
447447
* Additionally, you might think it's logical to simply place this in the afterEach() hook so it's called after every test (rather than duplicating this call in every test).
448448
* Unfortunately, afterEach() is designed for setup/teardown - not for determining if a test should fail or not.
@@ -456,8 +456,10 @@ export abstract class BasePage {
456456
if (PLATFORM === 'android') {
457457
return !(await this.isPageLoaded());
458458
}
459-
// If more than 1 instance of the app is open, we know an assert dialogue popped up.
460459
const windowHandles = await browser.getWindowHandles();
460+
if (isNativeDesktop() && browser.capabilities.platformName === 'windows') {
461+
return hasUnexpectedNativeDesktopWindow(windowHandles);
462+
}
461463
return windowHandles.length > 1;
462464
}
463465

‎apps/E2E/src/common/nativeDesktop.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createDesktopDriverClient, DesktopSessionClient, WebDriverError } from '@fluentui-react-native/desktop-driver';
2+
import type { DesktopTreeNode } from '@fluentui-react-native/desktop-driver';
13
import { Keys } from './consts.js';
24

35
/** A page object getter, or the element it has already resolved to. */
@@ -7,6 +9,42 @@ export function isNativeDesktop(): boolean {
79
return browser.capabilities.browserName === 'furn-native-desktop';
810
}
911

12+
export async function hasUnexpectedNativeDesktopWindow(handles: readonly string[]): Promise<boolean> {
13+
if (handles.length <= 1) return false;
14+
const current = await browser.getWindowHandle();
15+
const url = `${browser.options.protocol}://${browser.options.hostname}:${browser.options.port}${browser.options.path}`;
16+
const session = new DesktopSessionClient(
17+
createDesktopDriverClient({ url }),
18+
browser.sessionId,
19+
Object.fromEntries(Object.entries(browser.capabilities)),
20+
);
21+
for (const handle of handles) {
22+
if (handle === current) continue;
23+
// Switching windows would activate the target and can dismiss the menu being tested.
24+
let roots: DesktopTreeNode[];
25+
try {
26+
roots = await session.getWindowTree(handle);
27+
} catch (error) {
28+
if (error instanceof WebDriverError && error.code === 'no such window') continue;
29+
throw error;
30+
}
31+
// A closing popup can lose its content before its window disappears.
32+
if (!isExpectedMenuTree(roots) && (await browser.getWindowHandles()).includes(handle)) return true;
33+
}
34+
return false;
35+
}
36+
37+
function isExpectedMenuTree(roots: readonly DesktopTreeNode[]): boolean {
38+
if (roots.length !== 1 || roots[0].role !== 'menu') return false;
39+
const pending = [...roots];
40+
while (pending.length > 0) {
41+
const node = pending.pop()!;
42+
if (node.role === 'dialog' || node.role === 'window') return false;
43+
pending.push(...node.children);
44+
}
45+
return true;
46+
}
47+
1048
export async function sendNativeDesktopKeys(element: PageElement, keys: readonly Keys[]): Promise<void> {
1149
const target = await element;
1250
await browser.elementSendKeys(await target.elementId, '');

0 commit comments

Comments
 (0)