| OLD | NEW |
| 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 "apps/app_window_registry.h" | |
| 10 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 13 #include "chrome/browser/apps/app_browsertest_util.h" | 12 #include "chrome/browser/apps/app_browsertest_util.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser_iterator.h" | 16 #include "chrome/browser/ui/browser_iterator.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "extensions/browser/app_window/app_window_registry.h" |
| 20 #include "extensions/browser/app_window/native_app_window.h" | 20 #include "extensions/browser/app_window/native_app_window.h" |
| 21 #include "extensions/browser/uninstall_reason.h" | 21 #include "extensions/browser/uninstall_reason.h" |
| 22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class AppShimMenuControllerBrowserTest | 26 class AppShimMenuControllerBrowserTest |
| 27 : public extensions::PlatformAppBrowserTest { | 27 : public extensions::PlatformAppBrowserTest { |
| 28 protected: | 28 protected: |
| 29 AppShimMenuControllerBrowserTest() | 29 AppShimMenuControllerBrowserTest() |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); | 84 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // Test that focusing an app window changes the menu bar. | 87 // Test that focusing an app window changes the menu bar. |
| 88 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, | 88 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, |
| 89 PlatformAppFocusUpdatesMenuBar) { | 89 PlatformAppFocusUpdatesMenuBar) { |
| 90 SetUpApps(); | 90 SetUpApps(); |
| 91 // When an app is focused, all Chrome menu items should be hidden, and a menu | 91 // When an app is focused, all Chrome menu items should be hidden, and a menu |
| 92 // item for the app should be added. | 92 // item for the app should be added. |
| 93 apps::AppWindow* app_1_app_window = apps::AppWindowRegistry::Get(profile()) | 93 extensions::AppWindow* app_1_app_window = |
| 94 ->GetAppWindowsForApp(app_1_->id()) | 94 extensions::AppWindowRegistry::Get(profile()) |
| 95 .front(); | 95 ->GetAppWindowsForApp(app_1_->id()).front(); |
| 96 [[NSNotificationCenter defaultCenter] | 96 [[NSNotificationCenter defaultCenter] |
| 97 postNotificationName:NSWindowDidBecomeMainNotification | 97 postNotificationName:NSWindowDidBecomeMainNotification |
| 98 object:app_1_app_window->GetNativeWindow()]; | 98 object:app_1_app_window->GetNativeWindow()]; |
| 99 CheckHasAppMenus(app_1_); | 99 CheckHasAppMenus(app_1_); |
| 100 | 100 |
| 101 // When another app is focused, the menu item for the app should change. | 101 // When another app is focused, the menu item for the app should change. |
| 102 apps::AppWindow* app_2_app_window = apps::AppWindowRegistry::Get(profile()) | 102 extensions::AppWindow* app_2_app_window = |
| 103 ->GetAppWindowsForApp(app_2_->id()) | 103 extensions::AppWindowRegistry::Get(profile()) |
| 104 .front(); | 104 ->GetAppWindowsForApp(app_2_->id()).front(); |
| 105 [[NSNotificationCenter defaultCenter] | 105 [[NSNotificationCenter defaultCenter] |
| 106 postNotificationName:NSWindowDidBecomeMainNotification | 106 postNotificationName:NSWindowDidBecomeMainNotification |
| 107 object:app_2_app_window->GetNativeWindow()]; | 107 object:app_2_app_window->GetNativeWindow()]; |
| 108 CheckHasAppMenus(app_2_); | 108 CheckHasAppMenus(app_2_); |
| 109 | 109 |
| 110 // When a browser window is focused, the menu items for the app should be | 110 // When a browser window is focused, the menu items for the app should be |
| 111 // removed. | 111 // removed. |
| 112 BrowserWindow* chrome_window = chrome::BrowserIterator()->window(); | 112 BrowserWindow* chrome_window = chrome::BrowserIterator()->window(); |
| 113 [[NSNotificationCenter defaultCenter] | 113 [[NSNotificationCenter defaultCenter] |
| 114 postNotificationName:NSWindowDidBecomeMainNotification | 114 postNotificationName:NSWindowDidBecomeMainNotification |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, | 128 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, |
| 129 ExtensionUninstallUpdatesMenuBar) { | 129 ExtensionUninstallUpdatesMenuBar) { |
| 130 SetUpApps(); | 130 SetUpApps(); |
| 131 | 131 |
| 132 // This essentially tests that a NSWindowWillCloseNotification gets fired when | 132 // This essentially tests that a NSWindowWillCloseNotification gets fired when |
| 133 // an app is uninstalled. We need to close the other windows first since the | 133 // an app is uninstalled. We need to close the other windows first since the |
| 134 // menu only changes on a NSWindowWillCloseNotification if there are no other | 134 // menu only changes on a NSWindowWillCloseNotification if there are no other |
| 135 // windows. | 135 // windows. |
| 136 apps::AppWindow* app_2_app_window = apps::AppWindowRegistry::Get(profile()) | 136 extensions::AppWindow* app_2_app_window = |
| 137 ->GetAppWindowsForApp(app_2_->id()) | 137 extensions::AppWindowRegistry::Get(profile()) |
| 138 .front(); | 138 ->GetAppWindowsForApp(app_2_->id()).front(); |
| 139 app_2_app_window->GetBaseWindow()->Close(); | 139 app_2_app_window->GetBaseWindow()->Close(); |
| 140 | 140 |
| 141 chrome::BrowserIterator()->window()->Close(); | 141 chrome::BrowserIterator()->window()->Close(); |
| 142 | 142 |
| 143 apps::AppWindow* app_1_app_window = apps::AppWindowRegistry::Get(profile()) | 143 extensions::AppWindow* app_1_app_window = |
| 144 ->GetAppWindowsForApp(app_1_->id()) | 144 extensions::AppWindowRegistry::Get(profile()) |
| 145 .front(); | 145 ->GetAppWindowsForApp(app_1_->id()).front(); |
| 146 [[NSNotificationCenter defaultCenter] | 146 [[NSNotificationCenter defaultCenter] |
| 147 postNotificationName:NSWindowDidBecomeMainNotification | 147 postNotificationName:NSWindowDidBecomeMainNotification |
| 148 object:app_1_app_window->GetNativeWindow()]; | 148 object:app_1_app_window->GetNativeWindow()]; |
| 149 | 149 |
| 150 CheckHasAppMenus(app_1_); | 150 CheckHasAppMenus(app_1_); |
| 151 ExtensionService::UninstallExtensionHelper( | 151 ExtensionService::UninstallExtensionHelper( |
| 152 extension_service(), | 152 extension_service(), |
| 153 app_1_->id(), | 153 app_1_->id(), |
| 154 extensions::UNINSTALL_REASON_FOR_TESTING); | 154 extensions::UNINSTALL_REASON_FOR_TESTING); |
| 155 CheckNoAppMenus(); | 155 CheckNoAppMenus(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| OLD | NEW |