OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
tapted
2013/08/15 04:39:23
nit: no (c)
jackhou1
2013/08/16 02:50:41
Done.
| |
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_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/extensions/extension_test_message_listener.h" | |
14 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | |
15 #import "chrome/common/chrome_switches.h" | |
tapted
2013/08/15 04:39:23
nit: #include
jackhou1
2013/08/16 02:50:41
Done.
| |
16 #include "chrome/common/extensions/extension.h" | |
17 | |
18 namespace { | |
19 | |
20 class AppMenuControllerBrowserTest | |
21 : public extensions::PlatformAppBrowserTest { | |
22 protected: | |
23 AppMenuControllerBrowserTest() {} | |
tapted
2013/08/15 04:39:23
Since we're C++, you need to initialize data membe
jackhou1
2013/08/16 02:50:41
Done.
| |
24 | |
25 void SetUpApps() { | |
26 // Start two apps and wait for them to be launched. | |
tapted
2013/08/15 04:39:23
nit: comment before declaration?
jackhou1
2013/08/16 02:50:41
Done.
| |
27 ExtensionTestMessageListener listener_1("Launched", false); | |
28 app_1_ = InstallAndLaunchPlatformApp("minimal_id"); | |
29 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); | |
30 ExtensionTestMessageListener listener_2("Launched", false); | |
31 app_2_ = InstallAndLaunchPlatformApp("minimal"); | |
32 ASSERT_TRUE(listener_2.WaitUntilSatisfied()); | |
33 | |
34 main_menu_ = [NSApp mainMenu]; | |
35 initial_menu_item_count_ = [[main_menu_ itemArray] count]; | |
36 } | |
37 | |
38 void CheckAppMenu(const extensions::Extension* app) { | |
tapted
2013/08/15 04:39:23
nit: CheckHasAppMenu? You could declare these func
jackhou1
2013/08/16 02:50:41
Done.
| |
39 NSArray* item_array = [main_menu_ itemArray]; | |
40 EXPECT_EQ(initial_menu_item_count_ + 1, [item_array count]); | |
41 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) | |
42 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]); | |
43 NSMenuItem* last_item = [item_array lastObject]; | |
44 EXPECT_EQ(app->id(), base::SysNSStringToUTF8([last_item title])); | |
45 EXPECT_EQ(app->name(), | |
46 base::SysNSStringToUTF8([[last_item submenu] title])); | |
47 EXPECT_FALSE([last_item isHidden]); | |
48 } | |
49 | |
50 void CheckNoAppMenu() { | |
51 NSArray* item_array = [main_menu_ itemArray]; | |
52 EXPECT_EQ(initial_menu_item_count_, [item_array count]); | |
53 for (NSUInteger i = 0; i < initial_menu_item_count_; ++i) | |
54 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]); | |
55 } | |
56 | |
57 const extensions::Extension* app_1_; | |
58 const extensions::Extension* app_2_; | |
59 NSMenu* main_menu_; | |
tapted
2013/08/15 04:39:23
Maybe better without this data member, since it ra
jackhou1
2013/08/16 02:50:41
Done.
| |
60 NSUInteger initial_menu_item_count_; | |
61 }; | |
tapted
2013/08/15 04:39:23
nit: private: DISALLOW_COPY_AND_ASSIGN(..) (+ des
jackhou1
2013/08/16 02:50:41
Done.
| |
62 | |
63 // Test that focusing an app window changes the menu bar. | |
64 IN_PROC_BROWSER_TEST_F(AppMenuControllerBrowserTest, | |
65 PlatformAppFocusUpdatesMenuBar) { | |
66 SetUpApps(); | |
67 | |
68 // When an app is focused, all Chrome menu items should be hidden, and a menu | |
69 // item for the app should be added. | |
70 apps::ShellWindow* app_1_shell_window = | |
71 apps::ShellWindowRegistry::Get(profile())-> | |
72 GetShellWindowsForApp(app_1_->id()).front(); | |
73 [[NSNotificationCenter defaultCenter] | |
74 postNotificationName:NSWindowDidBecomeMainNotification | |
75 object:app_1_shell_window->GetNativeWindow()]; | |
76 CheckAppMenu(app_1_); | |
77 | |
78 // When another app is focused, the menu item for the app should change. | |
79 apps::ShellWindow* app_2_shell_window = | |
80 apps::ShellWindowRegistry::Get(profile())-> | |
81 GetShellWindowsForApp(app_2_->id()).front(); | |
82 [[NSNotificationCenter defaultCenter] | |
83 postNotificationName:NSWindowDidBecomeMainNotification | |
84 object:app_2_shell_window->GetNativeWindow()]; | |
85 CheckAppMenu(app_2_); | |
86 | |
87 // When the app window loses focus, the menu items for the app should be | |
88 // removed. | |
89 [[NSNotificationCenter defaultCenter] | |
90 postNotificationName:NSWindowDidResignMainNotification | |
91 object:app_2_shell_window->GetNativeWindow()]; | |
92 CheckNoAppMenu(); | |
93 | |
94 // When an app window is closed, the menu items for the app should be removed. | |
95 [[NSNotificationCenter defaultCenter] | |
96 postNotificationName:NSWindowDidBecomeMainNotification | |
97 object:app_2_shell_window->GetNativeWindow()]; | |
98 CheckAppMenu(app_2_); | |
99 [[NSNotificationCenter defaultCenter] | |
100 postNotificationName:NSWindowWillCloseNotification | |
101 object:app_2_shell_window->GetNativeWindow()]; | |
102 CheckNoAppMenu(); | |
103 } | |
tapted
2013/08/15 04:39:23
Maybe a test for unloading/uninstalling an extensi
jackhou1
2013/08/16 02:50:41
Done.
| |
104 | |
105 } // namespace | |
OLD | NEW |