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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm

Issue 2908983002: [reland] Bring up BrowserActionInteractiveTest on Mac. (Closed)
Patch Set: respond to comments Created 3 years, 6 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser/extensions/browser_action_test_util.h" 5 #include "chrome/browser/extensions/browser_action_test_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 16 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" 18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" 19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
20 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 20 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
21 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 21 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
23 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" 23 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
24 #import "chrome/browser/ui/cocoa/themed_window.h" 24 #import "chrome/browser/ui/cocoa/themed_window.h"
25 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 25 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
26 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 26 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
27 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 27 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
28 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
29 #import "ui/base/test/windowed_nsnotification_observer.h"
29 #include "ui/base/theme_provider.h" 30 #include "ui/base/theme_provider.h"
30 #include "ui/gfx/geometry/rect.h" 31 #include "ui/gfx/geometry/rect.h"
31 #include "ui/gfx/geometry/size.h" 32 #include "ui/gfx/geometry/size.h"
32 33
33 namespace { 34 namespace {
34 35
35 // The Cocoa implementation of the TestToolbarActionsBarHelper, which creates 36 // The Cocoa implementation of the TestToolbarActionsBarHelper, which creates
36 // (and owns) a BrowserActionsController and BrowserActionsContainerView for 37 // (and owns) a BrowserActionsController and BrowserActionsContainerView for
37 // testing purposes. 38 // testing purposes.
38 class TestToolbarActionsBarHelperCocoa : public TestToolbarActionsBarHelper { 39 class TestToolbarActionsBarHelperCocoa : public TestToolbarActionsBarHelper {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 NSString* tooltip = [GetButton(browser_, test_helper_.get(), index) toolTip]; 152 NSString* tooltip = [GetButton(browser_, test_helper_.get(), index) toolTip];
152 return base::SysNSStringToUTF8(tooltip); 153 return base::SysNSStringToUTF8(tooltip);
153 } 154 }
154 155
155 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() { 156 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() {
156 ToolbarActionViewController* popup_owner = 157 ToolbarActionViewController* popup_owner =
157 GetToolbarActionsBar()->popup_owner(); 158 GetToolbarActionsBar()->popup_owner();
158 return popup_owner ? popup_owner->GetPopupNativeView() : nil; 159 return popup_owner ? popup_owner->GetPopupNativeView() : nil;
159 } 160 }
160 161
162 bool BrowserActionTestUtil::WaitForPopup() {
163 NSWindow* window = [GetPopupNativeView() window];
164 if (!window)
165 return false;
166
167 if ([window isKeyWindow])
168 return true;
169
170 base::scoped_nsobject<WindowedNSNotificationObserver> waiter(
171 [[WindowedNSNotificationObserver alloc]
172 initForNotification:NSWindowDidBecomeKeyNotification
173 object:window]);
174
175 BOOL notification_observed = [waiter wait];
176 return notification_observed && [window isKeyWindow];
177 }
178
161 bool BrowserActionTestUtil::HasPopup() { 179 bool BrowserActionTestUtil::HasPopup() {
162 return GetPopupNativeView() != nil; 180 return GetPopupNativeView() != nil;
163 } 181 }
164 182
165 gfx::Size BrowserActionTestUtil::GetPopupSize() { 183 gfx::Size BrowserActionTestUtil::GetPopupSize() {
166 NSRect bounds = [[[ExtensionPopupController popup] view] bounds]; 184 NSRect bounds = [[[ExtensionPopupController popup] view] bounds];
167 return gfx::Size(NSSizeToCGSize(bounds.size)); 185 return gfx::Size(NSSizeToCGSize(bounds.size));
168 } 186 }
169 187
170 bool BrowserActionTestUtil::HidePopup() { 188 bool BrowserActionTestUtil::HidePopup() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { 223 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
206 return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize])); 224 return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize]));
207 } 225 }
208 226
209 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, 227 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser,
210 BrowserActionTestUtil* main_bar) 228 BrowserActionTestUtil* main_bar)
211 : browser_(browser), 229 : browser_(browser),
212 test_helper_(new TestToolbarActionsBarHelperCocoa( 230 test_helper_(new TestToolbarActionsBarHelperCocoa(
213 browser_, GetController(browser_, main_bar->test_helper_.get()))) { 231 browser_, GetController(browser_, main_bar->test_helper_.get()))) {
214 } 232 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698