| 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 "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 "base/test/scoped_feature_list.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/apps/app_browsertest_util.h" | 17 #include "chrome/browser/apps/app_browsertest_util.h" |
| 17 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" | 18 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/launch_util.h" | 20 #include "chrome/browser/extensions/launch_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_features.h" |
| 24 #include "extensions/browser/app_window/app_window_registry.h" | 25 #include "extensions/browser/app_window/app_window_registry.h" |
| 25 #include "extensions/browser/app_window/native_app_window.h" | 26 #include "extensions/browser/app_window/native_app_window.h" |
| 26 #include "extensions/browser/uninstall_reason.h" | 27 #include "extensions/browser/uninstall_reason.h" |
| 27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 28 #include "extensions/test/extension_test_message_listener.h" | 29 #include "extensions/test/extension_test_message_listener.h" |
| 29 #import "ui/base/test/scoped_fake_nswindow_focus.h" | 30 #import "ui/base/test/scoped_fake_nswindow_focus.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 class AppShimMenuControllerBrowserTest | 34 class AppShimMenuControllerBrowserTest |
| 34 : public extensions::PlatformAppBrowserTest { | 35 : public extensions::PlatformAppBrowserTest { |
| 35 protected: | 36 protected: |
| 36 // The apps that can be installed and launched by SetUpApps(). | 37 // The apps that can be installed and launched by SetUpApps(). |
| 37 enum AvailableApps { PACKAGED_1 = 0x1, PACKAGED_2 = 0x2, HOSTED = 0x4 }; | 38 enum AvailableApps { PACKAGED_1 = 0x1, PACKAGED_2 = 0x2, HOSTED = 0x4 }; |
| 38 | 39 |
| 39 AppShimMenuControllerBrowserTest() | 40 AppShimMenuControllerBrowserTest() |
| 40 : app_1_(nullptr), | 41 : app_1_(nullptr), |
| 41 app_2_(nullptr), | 42 app_2_(nullptr), |
| 42 hosted_app_(nullptr), | 43 hosted_app_(nullptr), |
| 43 initial_menu_item_count_(0) {} | 44 initial_menu_item_count_(0) {} |
| 44 | 45 |
| 45 void SetUpCommandLine(base::CommandLine* command_line) override { | 46 // testing::Test: |
| 46 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 47 void SetUp() override { |
| 47 command_line->AppendSwitch(switches::kEnableNewBookmarkApps); | 48 PlatformAppBrowserTest::SetUp(); |
| 49 scoped_feature_list_.InitAndEnableFeature(features::kBookmarkApps); |
| 48 } | 50 } |
| 49 | 51 |
| 50 // Start testing apps and wait for them to launch. |flags| is a bitmask of | 52 // Start testing apps and wait for them to launch. |flags| is a bitmask of |
| 51 // AvailableApps. | 53 // AvailableApps. |
| 52 void SetUpApps(int flags) { | 54 void SetUpApps(int flags) { |
| 53 | 55 |
| 54 if (flags & PACKAGED_1) { | 56 if (flags & PACKAGED_1) { |
| 55 ExtensionTestMessageListener listener_1("Launched", false); | 57 ExtensionTestMessageListener listener_1("Launched", false); |
| 56 app_1_ = InstallAndLaunchPlatformApp("minimal_id"); | 58 app_1_ = InstallAndLaunchPlatformApp("minimal_id"); |
| 57 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); | 59 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 EXPECT_FALSE(window_list.empty()); | 129 EXPECT_FALSE(window_list.empty()); |
| 128 return window_list.front(); | 130 return window_list.front(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 const extensions::Extension* app_1_; | 133 const extensions::Extension* app_1_; |
| 132 const extensions::Extension* app_2_; | 134 const extensions::Extension* app_2_; |
| 133 const extensions::Extension* hosted_app_; | 135 const extensions::Extension* hosted_app_; |
| 134 NSUInteger initial_menu_item_count_; | 136 NSUInteger initial_menu_item_count_; |
| 135 | 137 |
| 136 private: | 138 private: |
| 139 base::test::ScopedFeatureList scoped_feature_list_; |
| 140 |
| 137 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); | 141 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); |
| 138 }; | 142 }; |
| 139 | 143 |
| 140 // Test that focusing an app window changes the menu bar. | 144 // Test that focusing an app window changes the menu bar. |
| 141 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, | 145 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, |
| 142 PlatformAppFocusUpdatesMenuBar) { | 146 PlatformAppFocusUpdatesMenuBar) { |
| 143 SetUpApps(PACKAGED_1 | PACKAGED_2); | 147 SetUpApps(PACKAGED_1 | PACKAGED_2); |
| 144 // When an app is focused, all Chrome menu items should be hidden, and a menu | 148 // When an app is focused, all Chrome menu items should be hidden, and a menu |
| 145 // item for the app should be added. | 149 // item for the app should be added. |
| 146 extensions::AppWindow* app_1_app_window = FirstWindowForApp(app_1_); | 150 extensions::AppWindow* app_1_app_window = FirstWindowForApp(app_1_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 265 |
| 262 // OSX will send NSWindowWillResignMainNotification when a main window is | 266 // OSX will send NSWindowWillResignMainNotification when a main window is |
| 263 // closed. | 267 // closed. |
| 264 [[NSNotificationCenter defaultCenter] | 268 [[NSNotificationCenter defaultCenter] |
| 265 postNotificationName:NSWindowDidResignMainNotification | 269 postNotificationName:NSWindowDidResignMainNotification |
| 266 object:app_1_window]; | 270 object:app_1_window]; |
| 267 CheckNoAppMenus(); | 271 CheckNoAppMenus(); |
| 268 } | 272 } |
| 269 | 273 |
| 270 } // namespace | 274 } // namespace |
| OLD | NEW |