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

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

Issue 22867009: Swap main menu with app-specific menu when app window focused. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gypi Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "apps/shell_window_registry.h"
10 #include "base/command_line.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/strings/sys_string_conversions.h"
13 #include "chrome/browser/apps/app_browsertest_util.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_test_message_listener.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/extensions/extension.h"
18
19 namespace {
20
21 class AppShimMenuControllerBrowserTest
22 : public extensions::PlatformAppBrowserTest {
23 protected:
24 AppShimMenuControllerBrowserTest()
25 : app_1_(NULL),
26 app_2_(NULL),
27 initial_menu_item_count_(0) {}
28
29 virtual ~AppShimMenuControllerBrowserTest() {}
30
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32 PlatformAppBrowserTest::SetUpCommandLine(command_line);
33 command_line->AppendSwitch(switches::kEnableAppShims);
34 }
35
36 // Start two apps and wait for them to be launched.
37 void SetUpApps() {
38 ExtensionTestMessageListener listener_1("Launched", false);
39 app_1_ = InstallAndLaunchPlatformApp("minimal_id");
40 ASSERT_TRUE(listener_1.WaitUntilSatisfied());
41 ExtensionTestMessageListener listener_2("Launched", false);
42 app_2_ = InstallAndLaunchPlatformApp("minimal");
43 ASSERT_TRUE(listener_2.WaitUntilSatisfied());
44
45 initial_menu_item_count_ = [[[NSApp mainMenu] itemArray] count];
46 }
47
48 void CheckHasAppMenu(const extensions::Extension* app) const {
49 NSArray* item_array = [[NSApp mainMenu] itemArray];
50 EXPECT_EQ(initial_menu_item_count_ + 1, [item_array count]);
51 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i)
52 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]);
53 NSMenuItem* last_item = [item_array lastObject];
54 EXPECT_EQ(app->id(), base::SysNSStringToUTF8([last_item title]));
55 EXPECT_EQ(app->name(),
56 base::SysNSStringToUTF8([[last_item submenu] title]));
57 EXPECT_FALSE([last_item isHidden]);
58 }
59
60 void CheckNoAppMenu() const {
61 NSArray* item_array = [[NSApp mainMenu] itemArray];
62 EXPECT_EQ(initial_menu_item_count_, [item_array count]);
63 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i)
64 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]);
65 }
66
67 const extensions::Extension* app_1_;
68 const extensions::Extension* app_2_;
69 NSUInteger initial_menu_item_count_;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest);
73 };
74
75 // Test that focusing an app window changes the menu bar.
76 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
77 PlatformAppFocusUpdatesMenuBar) {
78 SetUpApps();
79 // When an app is focused, all Chrome menu items should be hidden, and a menu
80 // item for the app should be added.
81 apps::ShellWindow* app_1_shell_window =
82 apps::ShellWindowRegistry::Get(profile())->
83 GetShellWindowsForApp(app_1_->id()).front();
84 [[NSNotificationCenter defaultCenter]
85 postNotificationName:NSWindowDidBecomeMainNotification
86 object:app_1_shell_window->GetNativeWindow()];
87 CheckHasAppMenu(app_1_);
88
89 // When another app is focused, the menu item for the app should change.
90 apps::ShellWindow* app_2_shell_window =
91 apps::ShellWindowRegistry::Get(profile())->
92 GetShellWindowsForApp(app_2_->id()).front();
93 [[NSNotificationCenter defaultCenter]
94 postNotificationName:NSWindowDidBecomeMainNotification
95 object:app_2_shell_window->GetNativeWindow()];
96 CheckHasAppMenu(app_2_);
97
98 // When the app window loses focus, the menu items for the app should be
99 // removed.
100 [[NSNotificationCenter defaultCenter]
101 postNotificationName:NSWindowDidResignMainNotification
102 object:app_2_shell_window->GetNativeWindow()];
103 CheckNoAppMenu();
104
105 // When an app window is closed, the menu items for the app should be removed.
106 [[NSNotificationCenter defaultCenter]
107 postNotificationName:NSWindowDidBecomeMainNotification
108 object:app_2_shell_window->GetNativeWindow()];
109 CheckHasAppMenu(app_2_);
110 [[NSNotificationCenter defaultCenter]
111 postNotificationName:NSWindowWillCloseNotification
112 object:app_2_shell_window->GetNativeWindow()];
113 CheckNoAppMenu();
114 }
115
116 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
117 ExtensionUninstallUpdatesMenuBar) {
118 SetUpApps();
119
120 apps::ShellWindow* app_1_shell_window =
121 apps::ShellWindowRegistry::Get(profile())->
122 GetShellWindowsForApp(app_1_->id()).front();
123 [[NSNotificationCenter defaultCenter]
124 postNotificationName:NSWindowDidBecomeMainNotification
125 object:app_1_shell_window->GetNativeWindow()];
126
127 CheckHasAppMenu(app_1_);
128 ExtensionService::UninstallExtensionHelper(extension_service(), app_1_->id());
129 CheckNoAppMenu();
130 }
131
132 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698