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/shell_window_registry.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 ExtensionTestMessageListener listener_1("Launched", false); | 38 ExtensionTestMessageListener listener_1("Launched", false); |
39 app_1_ = InstallAndLaunchPlatformApp("minimal_id"); | 39 app_1_ = InstallAndLaunchPlatformApp("minimal_id"); |
40 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); | 40 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); |
41 ExtensionTestMessageListener listener_2("Launched", false); | 41 ExtensionTestMessageListener listener_2("Launched", false); |
42 app_2_ = InstallAndLaunchPlatformApp("minimal"); | 42 app_2_ = InstallAndLaunchPlatformApp("minimal"); |
43 ASSERT_TRUE(listener_2.WaitUntilSatisfied()); | 43 ASSERT_TRUE(listener_2.WaitUntilSatisfied()); |
44 | 44 |
45 initial_menu_item_count_ = [[[NSApp mainMenu] itemArray] count]; | 45 initial_menu_item_count_ = [[[NSApp mainMenu] itemArray] count]; |
46 } | 46 } |
47 | 47 |
48 void CheckHasAppMenu(const extensions::Extension* app) const { | 48 void CheckHasAppMenus(const extensions::Extension* app) const { |
49 NSUInteger extra_top_level_items = 4; | |
tapted
2013/08/29 06:06:19
nit: const?
But, I can't decide between int or NS
jackhou1
2013/08/29 06:30:03
Done.
| |
49 NSArray* item_array = [[NSApp mainMenu] itemArray]; | 50 NSArray* item_array = [[NSApp mainMenu] itemArray]; |
50 EXPECT_EQ(initial_menu_item_count_ + 1, [item_array count]); | 51 EXPECT_EQ(initial_menu_item_count_ + extra_top_level_items, |
52 [item_array count]); | |
51 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) | 53 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) |
52 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]); | 54 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]); |
53 NSMenuItem* last_item = [item_array lastObject]; | 55 NSMenuItem* app_menu = [item_array objectAtIndex:initial_menu_item_count_]; |
54 EXPECT_EQ(app->id(), base::SysNSStringToUTF8([last_item title])); | 56 EXPECT_EQ(app->id(), base::SysNSStringToUTF8([app_menu title])); |
55 EXPECT_EQ(app->name(), | 57 EXPECT_EQ(app->name(), |
56 base::SysNSStringToUTF8([[last_item submenu] title])); | 58 base::SysNSStringToUTF8([[app_menu submenu] title])); |
57 EXPECT_FALSE([last_item isHidden]); | 59 for (NSUInteger i = initial_menu_item_count_; |
60 i < initial_menu_item_count_ + extra_top_level_items; | |
61 ++i) { | |
62 NSMenuItem* menu = [item_array objectAtIndex:i]; | |
63 EXPECT_GT([[[menu submenu] itemArray] count], 0u); | |
tapted
2013/08/29 06:06:19
there's also [NSMenu numberOfItems] - maybe that's
jackhou1
2013/08/29 06:30:03
Done.
| |
64 EXPECT_FALSE([menu isHidden]); | |
65 } | |
58 } | 66 } |
59 | 67 |
60 void CheckNoAppMenu() const { | 68 void CheckNoAppMenus() const { |
61 NSArray* item_array = [[NSApp mainMenu] itemArray]; | 69 NSArray* item_array = [[NSApp mainMenu] itemArray]; |
62 EXPECT_EQ(initial_menu_item_count_, [item_array count]); | 70 EXPECT_EQ(initial_menu_item_count_, [item_array count]); |
63 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) | 71 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) |
64 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]); | 72 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]); |
65 } | 73 } |
66 | 74 |
67 const extensions::Extension* app_1_; | 75 const extensions::Extension* app_1_; |
68 const extensions::Extension* app_2_; | 76 const extensions::Extension* app_2_; |
69 NSUInteger initial_menu_item_count_; | 77 NSUInteger initial_menu_item_count_; |
70 | 78 |
71 private: | 79 private: |
72 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); | 80 DISALLOW_COPY_AND_ASSIGN(AppShimMenuControllerBrowserTest); |
73 }; | 81 }; |
74 | 82 |
75 // Test that focusing an app window changes the menu bar. | 83 // Test that focusing an app window changes the menu bar. |
76 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, | 84 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, |
77 PlatformAppFocusUpdatesMenuBar) { | 85 PlatformAppFocusUpdatesMenuBar) { |
78 SetUpApps(); | 86 SetUpApps(); |
79 // When an app is focused, all Chrome menu items should be hidden, and a menu | 87 // When an app is focused, all Chrome menu items should be hidden, and a menu |
80 // item for the app should be added. | 88 // item for the app should be added. |
81 apps::ShellWindow* app_1_shell_window = | 89 apps::ShellWindow* app_1_shell_window = |
82 apps::ShellWindowRegistry::Get(profile())-> | 90 apps::ShellWindowRegistry::Get(profile())-> |
83 GetShellWindowsForApp(app_1_->id()).front(); | 91 GetShellWindowsForApp(app_1_->id()).front(); |
84 [[NSNotificationCenter defaultCenter] | 92 [[NSNotificationCenter defaultCenter] |
85 postNotificationName:NSWindowDidBecomeMainNotification | 93 postNotificationName:NSWindowDidBecomeMainNotification |
86 object:app_1_shell_window->GetNativeWindow()]; | 94 object:app_1_shell_window->GetNativeWindow()]; |
87 CheckHasAppMenu(app_1_); | 95 CheckHasAppMenus(app_1_); |
88 | 96 |
89 // When another app is focused, the menu item for the app should change. | 97 // When another app is focused, the menu item for the app should change. |
90 apps::ShellWindow* app_2_shell_window = | 98 apps::ShellWindow* app_2_shell_window = |
91 apps::ShellWindowRegistry::Get(profile())-> | 99 apps::ShellWindowRegistry::Get(profile())-> |
92 GetShellWindowsForApp(app_2_->id()).front(); | 100 GetShellWindowsForApp(app_2_->id()).front(); |
93 [[NSNotificationCenter defaultCenter] | 101 [[NSNotificationCenter defaultCenter] |
94 postNotificationName:NSWindowDidBecomeMainNotification | 102 postNotificationName:NSWindowDidBecomeMainNotification |
95 object:app_2_shell_window->GetNativeWindow()]; | 103 object:app_2_shell_window->GetNativeWindow()]; |
96 CheckHasAppMenu(app_2_); | 104 CheckHasAppMenus(app_2_); |
97 | 105 |
98 // When the app window loses focus, the menu items for the app should be | 106 // When the app window loses focus, the menu items for the app should be |
99 // removed. | 107 // removed. |
100 [[NSNotificationCenter defaultCenter] | 108 [[NSNotificationCenter defaultCenter] |
101 postNotificationName:NSWindowDidResignMainNotification | 109 postNotificationName:NSWindowDidResignMainNotification |
102 object:app_2_shell_window->GetNativeWindow()]; | 110 object:app_2_shell_window->GetNativeWindow()]; |
103 CheckNoAppMenu(); | 111 CheckNoAppMenus(); |
104 | 112 |
105 // When an app window is closed, the menu items for the app should be removed. | 113 // When an app window is closed, the menu items for the app should be removed. |
106 [[NSNotificationCenter defaultCenter] | 114 [[NSNotificationCenter defaultCenter] |
107 postNotificationName:NSWindowDidBecomeMainNotification | 115 postNotificationName:NSWindowDidBecomeMainNotification |
108 object:app_2_shell_window->GetNativeWindow()]; | 116 object:app_2_shell_window->GetNativeWindow()]; |
109 CheckHasAppMenu(app_2_); | 117 CheckHasAppMenus(app_2_); |
110 [[NSNotificationCenter defaultCenter] | 118 [[NSNotificationCenter defaultCenter] |
111 postNotificationName:NSWindowWillCloseNotification | 119 postNotificationName:NSWindowWillCloseNotification |
112 object:app_2_shell_window->GetNativeWindow()]; | 120 object:app_2_shell_window->GetNativeWindow()]; |
113 CheckNoAppMenu(); | 121 CheckNoAppMenus(); |
114 } | 122 } |
115 | 123 |
116 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, | 124 IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest, |
117 ExtensionUninstallUpdatesMenuBar) { | 125 ExtensionUninstallUpdatesMenuBar) { |
118 SetUpApps(); | 126 SetUpApps(); |
119 | 127 |
120 apps::ShellWindow* app_1_shell_window = | 128 apps::ShellWindow* app_1_shell_window = |
121 apps::ShellWindowRegistry::Get(profile())-> | 129 apps::ShellWindowRegistry::Get(profile())-> |
122 GetShellWindowsForApp(app_1_->id()).front(); | 130 GetShellWindowsForApp(app_1_->id()).front(); |
123 [[NSNotificationCenter defaultCenter] | 131 [[NSNotificationCenter defaultCenter] |
124 postNotificationName:NSWindowDidBecomeMainNotification | 132 postNotificationName:NSWindowDidBecomeMainNotification |
125 object:app_1_shell_window->GetNativeWindow()]; | 133 object:app_1_shell_window->GetNativeWindow()]; |
126 | 134 |
127 CheckHasAppMenu(app_1_); | 135 CheckHasAppMenus(app_1_); |
128 ExtensionService::UninstallExtensionHelper(extension_service(), app_1_->id()); | 136 ExtensionService::UninstallExtensionHelper(extension_service(), app_1_->id()); |
129 CheckNoAppMenu(); | 137 CheckNoAppMenus(); |
130 } | 138 } |
131 | 139 |
132 } // namespace | 140 } // namespace |
OLD | NEW |