Commit 1285ca09 authored by tapted's avatar tapted Committed by Commit bot

Mac: More robust "window under location" for interactive_ui_tests

The interactive_ui_tests for toolkit-views' custom menus (e.g. for combo
boxes) would work fine when running tests locally, but refuse pass when
run on a trybot.

Tracing narrowed the discrepancy down to the
"WindowAtCurrentMouseLocation()" function in ui_controls_mac.mm. This
was working for windows at some positions on the screen, but not others,
and attempting to add a [NSApp activateIgnoringOtherApps:YES] call at
the appropriate place (e.g. ShowAndFocusNativeWindow() in
interactive_test_utils_mac.mm) had no effect.

This CL makes WindowAtCurrentMouseLocation more robust by effectively
ignoring the influence of windows in other applications that may be on
top of windows created in the test. Instead, iterate through [NSApp
orderedWindows] and use NSPointInRect. This allows all the toolkit-views
menu interactive_ui_tests to pass (except drag & drop - still working on
that).

Note that, historically, Mac's SendMouseMoveNotifyWhenDone would just
use the keyWindow, but that doesn't work for menus (it's also "wrong"
for mouse events).

I suspect this will also allow me to de-flake a bunch of disabled, Cocoa
interactive_ui_tests that have been accumulating.

BUG=403679

Review URL: https://codereview.chromium.org/821883002

Cr-Commit-Position: refs/heads/master@{#309620}
parent b3fb9477
......@@ -219,8 +219,28 @@ void EventQueueWatcher(const base::Closure& task) {
NSWindow* WindowAtCurrentMouseLocation() {
NSInteger window_number = [NSWindow windowNumberAtPoint:g_mouse_location
belowWindowWithWindowNumber:0];
return
NSWindow* window =
[[NSApplication sharedApplication] windowWithWindowNumber:window_number];
if (window)
return window;
// It's possible for a window owned by another application to be at that
// location. Cocoa won't provide an NSWindow* for those. Tests should not care
// about other applications, and raising windows in a headless application is
// flaky due to OS restrictions. For tests, hunt through all of this
// application's windows, top to bottom, looking for a good candidate.
NSArray* window_list = [[NSApplication sharedApplication] orderedWindows];
for (window in window_list) {
// Note this skips the extra checks (e.g. fully-transparent windows), that
// +[NSWindow windowNumberAtPoint:] performs. Tests that care about that
// should check separately (the goal here is to minimize flakiness).
if (NSPointInRect(g_mouse_location, [window frame]))
return window;
}
// Note that -[NSApplication orderedWindows] won't include NSPanels. If a test
// uses those, it will need to handle that itself.
return nil;
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment