Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> ac([[AppController alloc] init]); | |
|
tapted
2013/07/19 03:33:23
nit: .. although this is used in an existing test,
jackhou1
2013/07/19 07:47:16
Done.
| |
| 62 | |
| 63 // Start two apps and wait for them to be launched. | |
| 64 ExtensionTestMessageListener listener_1("Launched", false); | |
| 65 const extensions::Extension* app_1 = | |
|
tapted
2013/07/19 03:33:23
Do you need the ExtensionTestMessageListener ? Ins
jackhou1
2013/07/19 07:47:16
I think there's a race somewhere. The first app an
tapted
2013/07/19 08:00:41
Ah, yes. I think there might be two LOAD_COMPLETED
| |
| 66 InstallAndLaunchPlatformApp("minimal_id"); | |
| 67 ASSERT_TRUE(listener_1.WaitUntilSatisfied()); | |
| 68 ExtensionTestMessageListener listener_2("Launched", false); | |
| 69 const extensions::Extension* app_2 = | |
| 70 InstallAndLaunchPlatformApp("minimal"); | |
| 71 ASSERT_TRUE(listener_2.WaitUntilSatisfied()); | |
| 72 | |
| 73 NSMenu* main_menu = [NSApp mainMenu]; | |
| 74 NSUInteger initial_menu_item_count = [[main_menu itemArray] count]; | |
| 75 | |
| 76 // When an app is focused, all Chrome menu items should be hidden, and a menu | |
| 77 // item for the app should be added. | |
| 78 apps::ShellWindow* app_1_shell_window = | |
| 79 extensions::ShellWindowRegistry::Get(profile())-> | |
| 80 GetShellWindowsForApp(app_1->id()).front(); | |
| 81 [[NSNotificationCenter defaultCenter] | |
| 82 postNotificationName:NSWindowDidBecomeMainNotification | |
| 83 object:app_1_shell_window->GetNativeWindow()]; | |
| 84 NSArray* item_array = [main_menu itemArray]; | |
| 85 EXPECT_EQ(initial_menu_item_count + 1, [item_array count]); | |
| 86 for (NSUInteger i = 0; i < initial_menu_item_count; ++i) | |
| 87 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]); | |
| 88 NSMenuItem* last_item = [item_array objectAtIndex:[item_array count] - 1]; | |
|
tapted
2013/07/19 03:33:23
Maybe [item_array lastObject]
jackhou1
2013/07/19 07:47:16
Done.
| |
| 89 EXPECT_EQ(app_1->id(), base::SysNSStringToUTF8([last_item title])); | |
| 90 EXPECT_EQ(app_1->name(), | |
| 91 base::SysNSStringToUTF8([[last_item submenu] title])); | |
| 92 EXPECT_FALSE([last_item isHidden]); | |
| 93 | |
| 94 // When another app is focused, the menu item for the app should change. | |
| 95 apps::ShellWindow* app_2_shell_window = | |
| 96 extensions::ShellWindowRegistry::Get(profile())-> | |
| 97 GetShellWindowsForApp(app_2->id()).front(); | |
| 98 [[NSNotificationCenter defaultCenter] | |
| 99 postNotificationName:NSWindowDidBecomeMainNotification | |
| 100 object:app_2_shell_window->GetNativeWindow()]; | |
| 101 item_array = [main_menu itemArray]; | |
| 102 EXPECT_EQ(initial_menu_item_count + 1, [item_array count]); | |
| 103 for (NSUInteger i = 0; i < initial_menu_item_count; ++i) | |
| 104 EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]); | |
| 105 last_item = [item_array objectAtIndex:[item_array count] - 1]; | |
| 106 EXPECT_EQ(app_2->id(), base::SysNSStringToUTF8([last_item title])); | |
| 107 EXPECT_EQ(app_2->name(), | |
| 108 base::SysNSStringToUTF8([[last_item submenu] title])); | |
| 109 EXPECT_FALSE([last_item isHidden]); | |
| 110 | |
| 111 // When Chrome is focused, the menu item for the app should be removed. | |
| 112 NSWindow* browser_native_window = | |
| 113 active_browser_list_->get(0)->window()->GetNativeWindow(); | |
| 114 [[NSNotificationCenter defaultCenter] | |
| 115 postNotificationName:NSWindowDidBecomeMainNotification | |
| 116 object:browser_native_window]; | |
| 117 item_array = [main_menu itemArray]; | |
| 118 EXPECT_EQ(initial_menu_item_count, [item_array count]); | |
| 119 for (NSUInteger i = 0; i < initial_menu_item_count; ++i) | |
| 120 EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]); | |
| 121 } | |
| 122 | |
| 51 class AppControllerWebAppBrowserTest : public InProcessBrowserTest { | 123 class AppControllerWebAppBrowserTest : public InProcessBrowserTest { |
| 52 protected: | 124 protected: |
| 53 AppControllerWebAppBrowserTest() | 125 AppControllerWebAppBrowserTest() |
| 54 : active_browser_list_(BrowserList::GetInstance( | 126 : active_browser_list_(BrowserList::GetInstance( |
| 55 chrome::GetActiveDesktop())) { | 127 chrome::GetActiveDesktop())) { |
| 56 } | 128 } |
| 57 | 129 |
| 58 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 130 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 59 command_line->AppendSwitchASCII(switches::kApp, GetAppURL()); | 131 command_line->AppendSwitchASCII(switches::kApp, GetAppURL()); |
| 60 } | 132 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 76 EXPECT_FALSE(result); | 148 EXPECT_FALSE(result); |
| 77 EXPECT_EQ(2u, active_browser_list_->size()); | 149 EXPECT_EQ(2u, active_browser_list_->size()); |
| 78 | 150 |
| 79 Browser* browser = active_browser_list_->get(0); | 151 Browser* browser = active_browser_list_->get(0); |
| 80 GURL current_url = | 152 GURL current_url = |
| 81 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); | 153 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); |
| 82 EXPECT_EQ(GetAppURL(), current_url.spec()); | 154 EXPECT_EQ(GetAppURL(), current_url.spec()); |
| 83 } | 155 } |
| 84 | 156 |
| 85 } // namespace | 157 } // namespace |
| OLD | NEW |