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