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

Side by Side Diff: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm

Issue 1644773003: Remove BrowserIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-desktop-1
Patch Set: . 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 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 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" 5 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/mac/foundation_util.h" 10 #import "base/mac/foundation_util.h"
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #import "base/mac/scoped_objc_class_swizzler.h" 12 #import "base/mac/scoped_objc_class_swizzler.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/apps/app_browsertest_util.h" 16 #include "chrome/browser/apps/app_browsertest_util.h"
17 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" 17 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
18 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/launch_util.h" 19 #include "chrome/browser/extensions/launch_util.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser_iterator.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "extensions/browser/app_window/app_window_registry.h" 24 #include "extensions/browser/app_window/app_window_registry.h"
25 #include "extensions/browser/app_window/native_app_window.h" 25 #include "extensions/browser/app_window/native_app_window.h"
26 #include "extensions/browser/uninstall_reason.h" 26 #include "extensions/browser/uninstall_reason.h"
27 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
28 #include "extensions/test/extension_test_message_listener.h" 28 #include "extensions/test/extension_test_message_listener.h"
29 #import "ui/base/test/scoped_fake_nswindow_focus.h" 29 #import "ui/base/test/scoped_fake_nswindow_focus.h"
30 30
31 namespace { 31 namespace {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // When another app is focused, the menu item for the app should change. 152 // When another app is focused, the menu item for the app should change.
153 extensions::AppWindow* app_2_app_window = FirstWindowForApp(app_2_); 153 extensions::AppWindow* app_2_app_window = FirstWindowForApp(app_2_);
154 [[NSNotificationCenter defaultCenter] 154 [[NSNotificationCenter defaultCenter]
155 postNotificationName:NSWindowDidBecomeMainNotification 155 postNotificationName:NSWindowDidBecomeMainNotification
156 object:app_2_app_window->GetNativeWindow()]; 156 object:app_2_app_window->GetNativeWindow()];
157 CheckHasAppMenus(app_2_); 157 CheckHasAppMenus(app_2_);
158 158
159 // When a browser window is focused, the menu items for the app should be 159 // When a browser window is focused, the menu items for the app should be
160 // removed. 160 // removed.
161 BrowserWindow* chrome_window = chrome::BrowserIterator()->window(); 161 BrowserWindow* chrome_window =
162 (*BrowserList::GetInstance()->begin())->window();
162 [[NSNotificationCenter defaultCenter] 163 [[NSNotificationCenter defaultCenter]
163 postNotificationName:NSWindowDidBecomeMainNotification 164 postNotificationName:NSWindowDidBecomeMainNotification
164 object:chrome_window->GetNativeWindow()]; 165 object:chrome_window->GetNativeWindow()];
165 CheckNoAppMenus(); 166 CheckNoAppMenus();
166 167
167 // When an app window is closed and there are no other app windows, the menu 168 // When an app window is closed and there are no other app windows, the menu
168 // items for the app should be removed. 169 // items for the app should be removed.
169 app_1_app_window->GetBaseWindow()->Close(); 170 app_1_app_window->GetBaseWindow()->Close();
170 chrome_window->Close(); 171 chrome_window->Close();
171 [[NSNotificationCenter defaultCenter] 172 [[NSNotificationCenter defaultCenter]
(...skipping 13 matching lines...) Expand all
185 // Start with app1 active. 186 // Start with app1 active.
186 SetUpApps(PACKAGED_1); 187 SetUpApps(PACKAGED_1);
187 extensions::AppWindow* app_1_app_window = FirstWindowForApp(app_1_); 188 extensions::AppWindow* app_1_app_window = FirstWindowForApp(app_1_);
188 189
189 { 190 {
190 ui::test::ScopedFakeNSWindowFocus fake_focus; 191 ui::test::ScopedFakeNSWindowFocus fake_focus;
191 [app_1_app_window->GetNativeWindow() makeMainWindow]; 192 [app_1_app_window->GetNativeWindow() makeMainWindow];
192 CheckHasAppMenus(app_1_); 193 CheckHasAppMenus(app_1_);
193 194
194 // Closing a background window without focusing it should not change menus. 195 // Closing a background window without focusing it should not change menus.
195 BrowserWindow* chrome_window = chrome::BrowserIterator()->window(); 196 BrowserWindow* chrome_window =
197 (*BrowserList::GetInstance()->begin())->window();
196 chrome_window->Close(); 198 chrome_window->Close();
197 [[NSNotificationCenter defaultCenter] 199 [[NSNotificationCenter defaultCenter]
198 postNotificationName:NSWindowWillCloseNotification 200 postNotificationName:NSWindowWillCloseNotification
199 object:chrome_window->GetNativeWindow()]; 201 object:chrome_window->GetNativeWindow()];
200 CheckHasAppMenus(app_1_); 202 CheckHasAppMenus(app_1_);
201 203
202 // |fake_focus| going out of scope sends NSWindowWillResignMainNotification. 204 // |fake_focus| going out of scope sends NSWindowWillResignMainNotification.
203 } 205 }
204 app_1_app_window->GetBaseWindow()->Close(); 206 app_1_app_window->GetBaseWindow()->Close();
205 CheckNoAppMenus(); 207 CheckNoAppMenus();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 object:FirstWindowForApp(app_1_)->GetNativeWindow()]; 240 object:FirstWindowForApp(app_1_)->GetNativeWindow()];
239 CheckEditMenu(app_1_); 241 CheckEditMenu(app_1_);
240 } 242 }
241 243
242 // Test that uninstalling an app restores the main menu. 244 // Test that uninstalling an app restores the main menu.
243 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, 245 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
244 ExtensionUninstallUpdatesMenuBar) { 246 ExtensionUninstallUpdatesMenuBar) {
245 SetUpApps(PACKAGED_1 | PACKAGED_2); 247 SetUpApps(PACKAGED_1 | PACKAGED_2);
246 248
247 FirstWindowForApp(app_2_)->GetBaseWindow()->Close(); 249 FirstWindowForApp(app_2_)->GetBaseWindow()->Close();
248 chrome::BrowserIterator()->window()->Close(); 250 (*BrowserList::GetInstance()->begin())->window()->Close();
249 NSWindow* app_1_window = FirstWindowForApp(app_1_)->GetNativeWindow(); 251 NSWindow* app_1_window = FirstWindowForApp(app_1_)->GetNativeWindow();
250 252
251 ui::test::ScopedFakeNSWindowFocus fake_focus; 253 ui::test::ScopedFakeNSWindowFocus fake_focus;
252 [app_1_window makeMainWindow]; 254 [app_1_window makeMainWindow];
253 255
254 CheckHasAppMenus(app_1_); 256 CheckHasAppMenus(app_1_);
255 ExtensionService::UninstallExtensionHelper( 257 ExtensionService::UninstallExtensionHelper(
256 extension_service(), 258 extension_service(),
257 app_1_->id(), 259 app_1_->id(),
258 extensions::UNINSTALL_REASON_FOR_TESTING); 260 extensions::UNINSTALL_REASON_FOR_TESTING);
259 261
260 // OSX will send NSWindowWillResignMainNotification when a main window is 262 // OSX will send NSWindowWillResignMainNotification when a main window is
261 // closed. 263 // closed.
262 [[NSNotificationCenter defaultCenter] 264 [[NSNotificationCenter defaultCenter]
263 postNotificationName:NSWindowDidResignMainNotification 265 postNotificationName:NSWindowDidResignMainNotification
264 object:app_1_window]; 266 object:app_1_window];
265 CheckNoAppMenus(); 267 CheckNoAppMenus();
266 } 268 }
267 269
268 } // namespace 270 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698