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

Side by Side Diff: chrome/browser/app_controller_mac_browsertest.mm

Issue 18089012: Swap main menu with app-specific menu when app window focused. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 5 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
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
10 #import "chrome/browser/app_controller_mac.h" 11 #import "chrome/browser/app_controller_mac.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
14 #include "chrome/browser/extensions/shell_window_registry.h"
11 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/host_desktop.h" 18 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #import "chrome/common/chrome_switches.h" 20 #import "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
19 24
20 namespace { 25 namespace {
21 26
22 class AppControllerPlatformAppBrowserTest : public InProcessBrowserTest { 27 class AppControllerPlatformAppBrowserTest
28 : public extensions::PlatformAppBrowserTest {
23 protected: 29 protected:
24 AppControllerPlatformAppBrowserTest() 30 AppControllerPlatformAppBrowserTest()
25 : active_browser_list_(BrowserList::GetInstance( 31 : active_browser_list_(BrowserList::GetInstance(
26 chrome::GetActiveDesktop())) { 32 chrome::GetActiveDesktop())) {
27 } 33 }
28 34
29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 PlatformAppBrowserTest::SetUpCommandLine(command_line);
30 command_line->AppendSwitchASCII(switches::kAppId, 37 command_line->AppendSwitchASCII(switches::kAppId,
31 "1234"); 38 "1234");
32 } 39 }
33 40
34 const BrowserList* active_browser_list_; 41 const BrowserList* active_browser_list_;
35 }; 42 };
36 43
37 // Test that if only a platform app window is open and no browser windows are 44 // Test that if only a platform app window is open and no browser windows are
38 // open then a reopen event does nothing. 45 // open then a reopen event does nothing.
39 IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, 46 IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest,
40 PlatformAppReopenWithWindows) { 47 PlatformAppReopenWithWindows) {
41 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); 48 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
42 NSUInteger old_window_count = [[NSApp windows] count]; 49 NSUInteger old_window_count = [[NSApp windows] count];
43 EXPECT_EQ(1u, active_browser_list_->size()); 50 EXPECT_EQ(1u, active_browser_list_->size());
44 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES]; 51 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES];
45 52
46 EXPECT_TRUE(result); 53 EXPECT_TRUE(result);
47 EXPECT_EQ(old_window_count, [[NSApp windows] count]); 54 EXPECT_EQ(old_window_count, [[NSApp windows] count]);
48 EXPECT_EQ(1u, active_browser_list_->size()); 55 EXPECT_EQ(1u, active_browser_list_->size());
49 } 56 }
50 57
58 // Test that focusing an app window changes the menu bar.
59 IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest,
60 PlatformAppFocusUpdatesMenuBar) {
61 base::scoped_nsobject<AppController> app_controller(
62 [[AppController alloc] init]);
63
64 // Start two apps and wait for them to be launched.
65 ExtensionTestMessageListener listener_1("Launched", false);
66 const extensions::Extension* app_1 =
67 InstallAndLaunchPlatformApp("minimal_id");
68 ASSERT_TRUE(listener_1.WaitUntilSatisfied());
69 ExtensionTestMessageListener listener_2("Launched", false);
70 const extensions::Extension* app_2 =
71 InstallAndLaunchPlatformApp("minimal");
72 ASSERT_TRUE(listener_2.WaitUntilSatisfied());
73
74 NSMenu* main_menu = [NSApp mainMenu];
75 NSUInteger initial_menu_item_count = [[main_menu itemArray] count];
76
77 // When an app is focused, all Chrome menu items should be hidden, and a menu
78 // item for the app should be added.
79 apps::ShellWindow* app_1_shell_window =
80 extensions::ShellWindowRegistry::Get(profile())->
81 GetShellWindowsForApp(app_1->id()).front();
82 [[NSNotificationCenter defaultCenter]
83 postNotificationName:NSWindowDidBecomeMainNotification
84 object:app_1_shell_window->GetNativeWindow()];
85 NSArray* item_array = [main_menu itemArray];
86 EXPECT_EQ(initial_menu_item_count + 1, [item_array count]);
87 for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
88 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]);
89 NSMenuItem* last_item = [item_array lastObject];
90 EXPECT_EQ(app_1->id(), base::SysNSStringToUTF8([last_item title]));
91 EXPECT_EQ(app_1->name(),
92 base::SysNSStringToUTF8([[last_item submenu] title]));
93 EXPECT_FALSE([last_item isHidden]);
94
95 // When another app is focused, the menu item for the app should change.
96 apps::ShellWindow* app_2_shell_window =
97 extensions::ShellWindowRegistry::Get(profile())->
98 GetShellWindowsForApp(app_2->id()).front();
99 [[NSNotificationCenter defaultCenter]
100 postNotificationName:NSWindowDidBecomeMainNotification
101 object:app_2_shell_window->GetNativeWindow()];
102 item_array = [main_menu itemArray];
103 EXPECT_EQ(initial_menu_item_count + 1, [item_array count]);
104 for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
105 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]);
106 last_item = [item_array lastObject];
107 EXPECT_EQ(app_2->id(), base::SysNSStringToUTF8([last_item title]));
108 EXPECT_EQ(app_2->name(),
109 base::SysNSStringToUTF8([[last_item submenu] title]));
110 EXPECT_FALSE([last_item isHidden]);
111
112 // When Chrome is focused, the menu item for the app should be removed.
113 NSWindow* browser_native_window =
114 active_browser_list_->get(0)->window()->GetNativeWindow();
115 [[NSNotificationCenter defaultCenter]
116 postNotificationName:NSWindowDidBecomeMainNotification
117 object:browser_native_window];
118 item_array = [main_menu itemArray];
119 EXPECT_EQ(initial_menu_item_count, [item_array count]);
120 for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
121 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]);
122 }
123
51 class AppControllerWebAppBrowserTest : public InProcessBrowserTest { 124 class AppControllerWebAppBrowserTest : public InProcessBrowserTest {
52 protected: 125 protected:
53 AppControllerWebAppBrowserTest() 126 AppControllerWebAppBrowserTest()
54 : active_browser_list_(BrowserList::GetInstance( 127 : active_browser_list_(BrowserList::GetInstance(
55 chrome::GetActiveDesktop())) { 128 chrome::GetActiveDesktop())) {
56 } 129 }
57 130
58 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 131 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
59 command_line->AppendSwitchASCII(switches::kApp, GetAppURL()); 132 command_line->AppendSwitchASCII(switches::kApp, GetAppURL());
60 } 133 }
(...skipping 15 matching lines...) Expand all
76 EXPECT_FALSE(result); 149 EXPECT_FALSE(result);
77 EXPECT_EQ(2u, active_browser_list_->size()); 150 EXPECT_EQ(2u, active_browser_list_->size());
78 151
79 Browser* browser = active_browser_list_->get(0); 152 Browser* browser = active_browser_list_->get(0);
80 GURL current_url = 153 GURL current_url =
81 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); 154 browser->tab_strip_model()->GetActiveWebContents()->GetURL();
82 EXPECT_EQ(GetAppURL(), current_url.spec()); 155 EXPECT_EQ(GetAppURL(), current_url.spec());
83 } 156 }
84 157
85 } // namespace 158 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698