Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: ui/base/test/ui_controls_mac.mm

Issue 821883002: Mac: More robust "window under location" for interactive_ui_tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/test/ui_controls_mac.mm
diff --git a/ui/base/test/ui_controls_mac.mm b/ui/base/test/ui_controls_mac.mm
index cf2c239de39e9595434a014e32b9e6f62b9f41bd..89858d01c079080b26b2416abc6c905f133db9a3 100644
--- a/ui/base/test/ui_controls_mac.mm
+++ b/ui/base/test/ui_controls_mac.mm
@@ -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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698