| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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> | |
| 8 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #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 | 16 |
| 20 namespace ui_test_utils { | 17 namespace ui_test_utils { |
| 21 | 18 |
| 22 namespace { | 19 namespace { |
| 23 | 20 |
| 24 void MoveMouseToNSViewCenterAndPress( | 21 void MoveMouseToNSViewCenterAndPress( |
| 25 NSView* view, | 22 NSView* view, |
| 26 ui_controls::MouseButton button, | 23 ui_controls::MouseButton button, |
| 27 int state, | 24 int state, |
| 28 const base::Closure& task) { | 25 const base::Closure& task) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 85 } |
| 89 | 86 |
| 90 void FocusView(const Browser* browser, ViewID vid) { | 87 void FocusView(const Browser* browser, ViewID vid) { |
| 91 NSWindow* window = browser->window()->GetNativeWindow(); | 88 NSWindow* window = browser->window()->GetNativeWindow(); |
| 92 DCHECK(window); | 89 DCHECK(window); |
| 93 NSView* view = view_id_util::GetView(window, vid); | 90 NSView* view = view_id_util::GetView(window, vid); |
| 94 DCHECK(view); | 91 DCHECK(view); |
| 95 [window makeFirstResponder:view]; | 92 [window makeFirstResponder:view]; |
| 96 } | 93 } |
| 97 | 94 |
| 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 | 95 } // namespace ui_test_utils |
| OLD | NEW |