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

Side by Side Diff: chrome/test/base/interactive_test_utils_cocoa.mm

Issue 1669793002: mac_views_browser: fixed interactive_ui_tests compilation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "chrome/test/base/interactive_test_utils.h" 5 #include "chrome/test/base/interactive_test_utils.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #import "chrome/browser/ui/cocoa/view_id_util.h" 16 #import "chrome/browser/ui/cocoa/view_id_util.h"
17 #include "ui/base/test/ui_controls.h"
18 #import "ui/base/test/windowed_nsnotification_observer.h"
19 17
20 namespace ui_test_utils { 18 namespace ui_test_utils {
21 19
22 namespace { 20 namespace {
23 21
24 void MoveMouseToNSViewCenterAndPress( 22 void MoveMouseToNSViewCenterAndPress(
25 NSView* view, 23 NSView* view,
26 ui_controls::MouseButton button, 24 ui_controls::MouseButton button,
27 int state, 25 int state,
28 const base::Closure& task) { 26 const base::Closure& task) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 86 }
89 87
90 void FocusView(const Browser* browser, ViewID vid) { 88 void FocusView(const Browser* browser, ViewID vid) {
91 NSWindow* window = browser->window()->GetNativeWindow(); 89 NSWindow* window = browser->window()->GetNativeWindow();
92 DCHECK(window); 90 DCHECK(window);
93 NSView* view = view_id_util::GetView(window, vid); 91 NSView* view = view_id_util::GetView(window, vid);
94 DCHECK(view); 92 DCHECK(view);
95 [window makeFirstResponder:view]; 93 [window makeFirstResponder:view];
96 } 94 }
97 95
98 void HideNativeWindow(gfx::NativeWindow window) {
99 [window orderOut:nil];
100 }
101
102 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
103 // Make sure an unbundled program can get the input focus.
104 ProcessSerialNumber psn = { 0, kCurrentProcess };
105 TransformProcessType(&psn,kProcessTransformToForegroundApplication);
106 SetFrontProcess(&psn);
107
108 base::scoped_nsobject<WindowedNSNotificationObserver> async_waiter;
109 if (![window isKeyWindow]) {
110 // Only wait when expecting a change to actually occur.
111 async_waiter.reset([[WindowedNSNotificationObserver alloc]
112 initForNotification:NSWindowDidBecomeKeyNotification
113 object:window]);
114 }
115 [window makeKeyAndOrderFront:nil];
116
117 // Wait until |window| becomes key window, then make sure the shortcuts for
118 // "Close Window" and "Close Tab" are updated.
119 // This is because normal AppKit menu updating does not get invoked when
120 // events are sent via ui_test_utils::SendKeyPressSync.
121 BOOL notification_observed = [async_waiter wait];
122 base::RunLoop().RunUntilIdle(); // There may be other events queued. Flush.
123 NSMenu* file_menu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu];
124 [[file_menu delegate] menuNeedsUpdate:file_menu];
125
126 return !async_waiter || notification_observed;
127 }
128
129 } // namespace ui_test_utils 96 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698