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

Side by Side 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 5 years, 12 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/test/ui_controls.h" 5 #include "ui/base/test/ui_controls.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <mach/mach_time.h> 8 #include <mach/mach_time.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 213
214 // Returns the NSWindow located at |g_mouse_location|. NULL if there is no 214 // Returns the NSWindow located at |g_mouse_location|. NULL if there is no
215 // window there, or if the window located there is not owned by the application. 215 // window there, or if the window located there is not owned by the application.
216 // On Mac, unless dragging, mouse events are sent to the window under the 216 // On Mac, unless dragging, mouse events are sent to the window under the
217 // cursor. Note that the OS will ignore transparent windows and windows that 217 // cursor. Note that the OS will ignore transparent windows and windows that
218 // explicitly ignore mouse events. 218 // explicitly ignore mouse events.
219 NSWindow* WindowAtCurrentMouseLocation() { 219 NSWindow* WindowAtCurrentMouseLocation() {
220 NSInteger window_number = [NSWindow windowNumberAtPoint:g_mouse_location 220 NSInteger window_number = [NSWindow windowNumberAtPoint:g_mouse_location
221 belowWindowWithWindowNumber:0]; 221 belowWindowWithWindowNumber:0];
222 return 222 NSWindow* window =
223 [[NSApplication sharedApplication] windowWithWindowNumber:window_number]; 223 [[NSApplication sharedApplication] windowWithWindowNumber:window_number];
224 if (window)
225 return window;
226
227 // It's possible for a window owned by another application to be at that
228 // location. Cocoa won't provide an NSWindow* for those. Tests should not care
229 // about other applications, and raising windows in a headless application is
230 // flaky due to OS restrictions. For tests, hunt through all of this
231 // application's windows, top to bottom, looking for a good candidate.
232 NSArray* window_list = [[NSApplication sharedApplication] orderedWindows];
233 for (window in window_list) {
234 // Note this skips the extra checks (e.g. fully-transparent windows), that
235 // +[NSWindow windowNumberAtPoint:] performs. Tests that care about that
236 // should check separately (the goal here is to minimize flakiness).
237 if (NSPointInRect(g_mouse_location, [window frame]))
238 return window;
239 }
240
241 // Note that -[NSApplication orderedWindows] won't include NSPanels. If a test
242 // uses those, it will need to handle that itself.
243 return nil;
224 } 244 }
225 245
226 } // namespace 246 } // namespace
227 247
228 namespace ui_controls { 248 namespace ui_controls {
229 249
230 void EnableUIControls() { 250 void EnableUIControls() {
231 g_ui_controls_enabled = true; 251 g_ui_controls_enabled = true;
232 } 252 }
233 253
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { 407 void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
388 base::MessageLoop::current()->PostTask( 408 base::MessageLoop::current()->PostTask(
389 FROM_HERE, base::Bind(&EventQueueWatcher, closure)); 409 FROM_HERE, base::Bind(&EventQueueWatcher, closure));
390 } 410 }
391 411
392 bool IsFullKeyboardAccessEnabled() { 412 bool IsFullKeyboardAccessEnabled() {
393 return [NSApp isFullKeyboardAccessEnabled]; 413 return [NSApp isFullKeyboardAccessEnabled];
394 } 414 }
395 415
396 } // namespace ui_controls 416 } // namespace ui_controls
OLDNEW
« 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