| 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 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" |
| 8 #include "apps/shell_window.h" | 8 #include "apps/shell_window.h" |
| 9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 protected: | 111 protected: |
| 112 LauncherPlatformPerAppAppBrowserTest() | 112 LauncherPlatformPerAppAppBrowserTest() |
| 113 : launcher_(NULL), | 113 : launcher_(NULL), |
| 114 controller_(NULL) { | 114 controller_(NULL) { |
| 115 } | 115 } |
| 116 | 116 |
| 117 virtual ~LauncherPlatformPerAppAppBrowserTest() {} | 117 virtual ~LauncherPlatformPerAppAppBrowserTest() {} |
| 118 | 118 |
| 119 virtual void RunTestOnMainThreadLoop() OVERRIDE { | 119 virtual void RunTestOnMainThreadLoop() OVERRIDE { |
| 120 launcher_ = ash::Launcher::ForPrimaryDisplay(); | 120 launcher_ = ash::Launcher::ForPrimaryDisplay(); |
| 121 controller_ = | 121 controller_ = static_cast<ChromeLauncherControllerPerApp*> |
| 122 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); | 122 (ChromeLauncherController::instance()); |
| 123 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | 123 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 ash::LauncherModel* launcher_model() { | 126 ash::LauncherModel* launcher_model() { |
| 127 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); | 127 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { | 130 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { |
| 131 return controller_->CreateAppShortcutLauncherItem( | 131 return controller_->CreateAppShortcutLauncherItem( |
| 132 name, controller_->model()->item_count()); | 132 name, controller_->model()->item_count()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 : launcher_(NULL), | 182 : launcher_(NULL), |
| 183 model_(NULL) { | 183 model_(NULL) { |
| 184 } | 184 } |
| 185 | 185 |
| 186 virtual ~LauncherPerAppAppBrowserTest() {} | 186 virtual ~LauncherPerAppAppBrowserTest() {} |
| 187 | 187 |
| 188 virtual void RunTestOnMainThreadLoop() OVERRIDE { | 188 virtual void RunTestOnMainThreadLoop() OVERRIDE { |
| 189 launcher_ = ash::Launcher::ForPrimaryDisplay(); | 189 launcher_ = ash::Launcher::ForPrimaryDisplay(); |
| 190 model_ = | 190 model_ = |
| 191 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); | 191 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); |
| 192 controller_ = static_cast<ChromeLauncherControllerPerApp*> |
| 193 (ChromeLauncherController::instance()); |
| 194 |
| 192 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); | 195 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { | 198 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { |
| 196 ChromeLauncherControllerPerApp* controller = | |
| 197 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); | |
| 198 LauncherItemController* item_controller = | 199 LauncherItemController* item_controller = |
| 199 controller->GetBrowserShortcutLauncherItemController(); | 200 controller_->GetBrowserShortcutLauncherItemController(); |
| 200 int items = item_controller->GetApplicationList( | 201 int items = item_controller->GetApplicationList( |
| 201 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); | 202 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); |
| 202 // If we have at least one item, we have also a title which we remove here. | 203 // If we have at least one item, we have also a title which we remove here. |
| 203 return items ? (items - 1) : 0; | 204 return items ? (items - 1) : 0; |
| 204 } | 205 } |
| 205 | 206 |
| 206 const Extension* LoadAndLaunchExtension( | 207 const Extension* LoadAndLaunchExtension( |
| 207 const char* name, | 208 const char* name, |
| 208 extension_misc::LaunchContainer container, | 209 extension_misc::LaunchContainer container, |
| 209 WindowOpenDisposition disposition) { | 210 WindowOpenDisposition disposition) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 226 ExtensionService* service = extensions::ExtensionSystem::Get( | 227 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 227 profile())->extension_service(); | 228 profile())->extension_service(); |
| 228 LoadExtension(test_data_dir_.AppendASCII(name)); | 229 LoadExtension(test_data_dir_.AppendASCII(name)); |
| 229 | 230 |
| 230 // First get app_id. | 231 // First get app_id. |
| 231 const Extension* extension = | 232 const Extension* extension = |
| 232 service->GetExtensionById(last_loaded_extension_id_, false); | 233 service->GetExtensionById(last_loaded_extension_id_, false); |
| 233 const std::string app_id = extension->id(); | 234 const std::string app_id = extension->id(); |
| 234 | 235 |
| 235 // Then create a shortcut. | 236 // Then create a shortcut. |
| 236 ChromeLauncherController* controller = | |
| 237 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 238 int item_count = model_->item_count(); | 237 int item_count = model_->item_count(); |
| 239 ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( | 238 ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem( |
| 240 app_id, | 239 app_id, |
| 241 item_count); | 240 item_count); |
| 242 controller->PersistPinnedState(); | 241 controller_->PersistPinnedState(); |
| 243 EXPECT_EQ(++item_count, model_->item_count()); | 242 EXPECT_EQ(++item_count, model_->item_count()); |
| 244 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); | 243 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); |
| 245 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 244 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 246 return item.id; | 245 return item.id; |
| 247 } | 246 } |
| 248 | 247 |
| 249 // Activate the launcher item with the given |id|. | 248 // Activate the launcher item with the given |id|. |
| 250 void ActivateLauncherItem(int id) { | 249 void ActivateLauncherItem(int id) { |
| 251 launcher_->ActivateLauncherItem(id); | 250 launcher_->ActivateLauncherItem(id); |
| 252 } | 251 } |
| 253 | 252 |
| 254 ash::Launcher* launcher_; | 253 ash::Launcher* launcher_; |
| 255 ash::LauncherModel* model_; | 254 ash::LauncherModel* model_; |
| 255 ChromeLauncherControllerPerApp* controller_; |
| 256 | 256 |
| 257 private: | 257 private: |
| 258 | 258 |
| 259 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); | 259 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 // TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the | 262 // TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the |
| 263 // old launcher gets ripped out. | 263 // old launcher gets ripped out. |
| 264 class LauncherPerAppAppBrowserTestNoDefaultBrowser | 264 class LauncherPerAppAppBrowserTestNoDefaultBrowser |
| 265 : public LauncherPerAppAppBrowserTest { | 265 : public LauncherPerAppAppBrowserTest { |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 } | 832 } |
| 833 | 833 |
| 834 // Launches an app in the background and then tries to open it. This is test for | 834 // Launches an app in the background and then tries to open it. This is test for |
| 835 // a crash we had. | 835 // a crash we had. |
| 836 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) { | 836 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) { |
| 837 TabStripModel* tab_strip = browser()->tab_strip_model(); | 837 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 838 int tab_count = tab_strip->count(); | 838 int tab_count = tab_strip->count(); |
| 839 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, | 839 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, |
| 840 NEW_BACKGROUND_TAB); | 840 NEW_BACKGROUND_TAB); |
| 841 EXPECT_EQ(++tab_count, tab_strip->count()); | 841 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 842 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0); | 842 controller_->LaunchApp(last_loaded_extension_id_, 0); |
| 843 } | 843 } |
| 844 | 844 |
| 845 // Confirm that clicking a icon for an app running in one of 2 maxmized windows | 845 // Confirm that clicking a icon for an app running in one of 2 maxmized windows |
| 846 // activates the right window. | 846 // activates the right window. |
| 847 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) { | 847 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) { |
| 848 aura::Window* window1 = browser()->window()->GetNativeWindow(); | 848 aura::Window* window1 = browser()->window()->GetNativeWindow(); |
| 849 ash::wm::MaximizeWindow(window1); | 849 ash::wm::MaximizeWindow(window1); |
| 850 content::WindowedNotificationObserver open_observer( | 850 content::WindowedNotificationObserver open_observer( |
| 851 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 851 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 852 content::NotificationService::AllSources()); | 852 content::NotificationService::AllSources()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 871 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 871 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 872 } | 872 } |
| 873 | 873 |
| 874 // Activating the same app multiple times should launch only a single copy. | 874 // Activating the same app multiple times should launch only a single copy. |
| 875 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) { | 875 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) { |
| 876 TabStripModel* tab_strip = browser()->tab_strip_model(); | 876 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 877 int tab_count = tab_strip->count(); | 877 int tab_count = tab_strip->count(); |
| 878 const Extension* extension = | 878 const Extension* extension = |
| 879 LoadExtension(test_data_dir_.AppendASCII("app1")); | 879 LoadExtension(test_data_dir_.AppendASCII("app1")); |
| 880 | 880 |
| 881 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); | 881 controller_->ActivateApp(extension->id(), 0); |
| 882 EXPECT_EQ(++tab_count, tab_strip->count()); | 882 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 883 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); | 883 controller_->ActivateApp(extension->id(), 0); |
| 884 EXPECT_EQ(tab_count, tab_strip->count()); | 884 EXPECT_EQ(tab_count, tab_strip->count()); |
| 885 } | 885 } |
| 886 | 886 |
| 887 // Launching the same app multiple times should launch a copy for each call. | 887 // Launching the same app multiple times should launch a copy for each call. |
| 888 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) { | 888 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) { |
| 889 TabStripModel* tab_strip = browser()->tab_strip_model(); | 889 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 890 int tab_count = tab_strip->count(); | 890 int tab_count = tab_strip->count(); |
| 891 const Extension* extension = | 891 const Extension* extension = |
| 892 LoadExtension(test_data_dir_.AppendASCII("app1")); | 892 LoadExtension(test_data_dir_.AppendASCII("app1")); |
| 893 | 893 |
| 894 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); | 894 controller_->LaunchApp(extension->id(), 0); |
| 895 EXPECT_EQ(++tab_count, tab_strip->count()); | 895 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 896 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); | 896 controller_->LaunchApp(extension->id(), 0); |
| 897 EXPECT_EQ(++tab_count, tab_strip->count()); | 897 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 898 } | 898 } |
| 899 | 899 |
| 900 // Launch 2 apps and toggle which is active. | 900 // Launch 2 apps and toggle which is active. |
| 901 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) { | 901 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) { |
| 902 int item_count = model_->item_count(); | 902 int item_count = model_->item_count(); |
| 903 TabStripModel* tab_strip = browser()->tab_strip_model(); | 903 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 904 int tab_count = tab_strip->count(); | 904 int tab_count = tab_strip->count(); |
| 905 ash::LauncherID shortcut1 = CreateShortcut("app1"); | 905 ash::LauncherID shortcut1 = CreateShortcut("app1"); |
| 906 EXPECT_EQ(++item_count, model_->item_count()); | 906 EXPECT_EQ(++item_count, model_->item_count()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 // No longer active. | 1001 // No longer active. |
| 1002 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); | 1002 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); |
| 1003 | 1003 |
| 1004 // Activating app makes first tab active again. | 1004 // Activating app makes first tab active again. |
| 1005 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1005 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 1006 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1006 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 1007 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); | 1007 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { | 1010 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { |
| 1011 ChromeLauncherController* controller = | |
| 1012 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1013 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1011 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1014 int tab_count = tab_strip->count(); | 1012 int tab_count = tab_strip->count(); |
| 1015 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1013 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 1016 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1014 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 1017 EXPECT_EQ(++tab_count, tab_strip->count()); | 1015 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 1018 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1016 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 1019 WebContents* first_tab = tab_strip->GetActiveWebContents(); | 1017 WebContents* first_tab = tab_strip->GetActiveWebContents(); |
| 1020 | 1018 |
| 1021 controller->SetRefocusURLPatternForTest( | 1019 controller_->SetRefocusURLPatternForTest( |
| 1022 shortcut_id, GURL("http://www.example.com/path1/*")); | 1020 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 1023 // Create new tab owned by app. | 1021 // Create new tab owned by app. |
| 1024 ui_test_utils::NavigateToURLWithDisposition( | 1022 ui_test_utils::NavigateToURLWithDisposition( |
| 1025 browser(), | 1023 browser(), |
| 1026 GURL("http://www.example.com/path2/bar.html"), | 1024 GURL("http://www.example.com/path2/bar.html"), |
| 1027 NEW_FOREGROUND_TAB, | 1025 NEW_FOREGROUND_TAB, |
| 1028 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1026 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1029 EXPECT_EQ(++tab_count, tab_strip->count()); | 1027 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 1030 // Confirm app is still active. | 1028 // Confirm app is still active. |
| 1031 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1029 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 1032 | 1030 |
| 1033 // Create new tab not owned by app. | 1031 // Create new tab not owned by app. |
| 1034 ui_test_utils::NavigateToURLWithDisposition( | 1032 ui_test_utils::NavigateToURLWithDisposition( |
| 1035 browser(), | 1033 browser(), |
| 1036 GURL("http://www.example.com/path3/foo.html"), | 1034 GURL("http://www.example.com/path3/foo.html"), |
| 1037 NEW_FOREGROUND_TAB, | 1035 NEW_FOREGROUND_TAB, |
| 1038 0); | 1036 0); |
| 1039 EXPECT_EQ(++tab_count, tab_strip->count()); | 1037 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 1040 // No longer active. | 1038 // No longer active. |
| 1041 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); | 1039 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); |
| 1042 | 1040 |
| 1043 // Activating app makes first tab active again, because second tab isn't | 1041 // Activating app makes first tab active again, because second tab isn't |
| 1044 // in its refocus url path. | 1042 // in its refocus url path. |
| 1045 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1043 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 1046 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1044 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 1047 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); | 1045 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); |
| 1048 } | 1046 } |
| 1049 | 1047 |
| 1050 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) { | 1048 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) { |
| 1051 ChromeLauncherController* controller = | |
| 1052 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1053 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1049 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1054 int tab_count = tab_strip->count(); | 1050 int tab_count = tab_strip->count(); |
| 1055 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1051 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 1056 controller->SetRefocusURLPatternForTest( | 1052 controller_->SetRefocusURLPatternForTest( |
| 1057 shortcut_id, GURL("http://www.example.com/path1/*")); | 1053 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 1058 | 1054 |
| 1059 // Create new tab. | 1055 // Create new tab. |
| 1060 ui_test_utils::NavigateToURLWithDisposition( | 1056 ui_test_utils::NavigateToURLWithDisposition( |
| 1061 browser(), | 1057 browser(), |
| 1062 GURL("http://www.example2.com/path2/bar.html"), | 1058 GURL("http://www.example2.com/path2/bar.html"), |
| 1063 NEW_FOREGROUND_TAB, | 1059 NEW_FOREGROUND_TAB, |
| 1064 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1060 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1065 EXPECT_EQ(++tab_count, tab_strip->count()); | 1061 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 1066 WebContents* first_tab = tab_strip->GetActiveWebContents(); | 1062 WebContents* first_tab = tab_strip->GetActiveWebContents(); |
| 1067 // Confirm app is not active. | 1063 // Confirm app is not active. |
| 1068 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | 1064 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
| 1069 | 1065 |
| 1070 // Activating app should launch new tab, because second tab isn't | 1066 // Activating app should launch new tab, because second tab isn't |
| 1071 // in its refocus url path. | 1067 // in its refocus url path. |
| 1072 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); | 1068 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); |
| 1073 EXPECT_EQ(++tab_count, tab_strip->count()); | 1069 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 1074 WebContents* second_tab = tab_strip->GetActiveWebContents(); | 1070 WebContents* second_tab = tab_strip->GetActiveWebContents(); |
| 1075 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); | 1071 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); |
| 1076 EXPECT_NE(first_tab, second_tab); | 1072 EXPECT_NE(first_tab, second_tab); |
| 1077 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); | 1073 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); |
| 1078 } | 1074 } |
| 1079 | 1075 |
| 1080 // Check the launcher activation state for applications and browser. | 1076 // Check the launcher activation state for applications and browser. |
| 1081 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) { | 1077 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) { |
| 1082 ChromeLauncherController* controller = | |
| 1083 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1084 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1078 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1085 // Get the browser item index | 1079 // Get the browser item index |
| 1086 int browser_index = ash::launcher::GetBrowserItemIndex(*controller->model()); | 1080 int browser_index = ash::launcher::GetBrowserItemIndex(*controller_->model()); |
| 1087 EXPECT_TRUE(browser_index >= 0); | 1081 EXPECT_TRUE(browser_index >= 0); |
| 1088 | 1082 |
| 1089 // Even though we are just comming up, the browser should be active. | 1083 // Even though we are just comming up, the browser should be active. |
| 1090 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | 1084 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); |
| 1091 | 1085 |
| 1092 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1086 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 1093 controller->SetRefocusURLPatternForTest( | 1087 controller_->SetRefocusURLPatternForTest( |
| 1094 shortcut_id, GURL("http://www.example.com/path1/*")); | 1088 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 1095 | 1089 |
| 1096 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | 1090 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
| 1097 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); | 1091 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); |
| 1098 | 1092 |
| 1099 // Create new tab which would be the running app. | 1093 // Create new tab which would be the running app. |
| 1100 ui_test_utils::NavigateToURLWithDisposition( | 1094 ui_test_utils::NavigateToURLWithDisposition( |
| 1101 browser(), | 1095 browser(), |
| 1102 GURL("http://www.example.com/path1/bar.html"), | 1096 GURL("http://www.example.com/path1/bar.html"), |
| 1103 NEW_FOREGROUND_TAB, | 1097 NEW_FOREGROUND_TAB, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1118 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow()); | 1112 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow()); |
| 1119 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | 1113 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
| 1120 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); | 1114 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); |
| 1121 } | 1115 } |
| 1122 | 1116 |
| 1123 // Check that the launcher activation state for a V1 application stays closed | 1117 // Check that the launcher activation state for a V1 application stays closed |
| 1124 // even after an asynchronous browser event comes in after the tab got | 1118 // even after an asynchronous browser event comes in after the tab got |
| 1125 // destroyed. | 1119 // destroyed. |
| 1126 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, | 1120 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, |
| 1127 AsyncActivationStateCheck) { | 1121 AsyncActivationStateCheck) { |
| 1128 ChromeLauncherController* controller = | |
| 1129 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1130 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1122 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1131 | 1123 |
| 1132 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1124 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 1133 controller->SetRefocusURLPatternForTest( | 1125 controller_->SetRefocusURLPatternForTest( |
| 1134 shortcut_id, GURL("http://www.example.com/path1/*")); | 1126 shortcut_id, GURL("http://www.example.com/path1/*")); |
| 1135 | 1127 |
| 1136 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | 1128 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
| 1137 | 1129 |
| 1138 // Create new tab which would be the running app. | 1130 // Create new tab which would be the running app. |
| 1139 ui_test_utils::NavigateToURLWithDisposition( | 1131 ui_test_utils::NavigateToURLWithDisposition( |
| 1140 browser(), | 1132 browser(), |
| 1141 GURL("http://www.example.com/path1/bar.html"), | 1133 GURL("http://www.example.com/path1/bar.html"), |
| 1142 NEW_FOREGROUND_TAB, | 1134 NEW_FOREGROUND_TAB, |
| 1143 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1135 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 NEW_FOREGROUND_TAB); | 1188 NEW_FOREGROUND_TAB); |
| 1197 | 1189 |
| 1198 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); | 1190 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); |
| 1199 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); | 1191 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); |
| 1200 } | 1192 } |
| 1201 | 1193 |
| 1202 // Check that the keyboard activation of a launcher item tabs properly through | 1194 // Check that the keyboard activation of a launcher item tabs properly through |
| 1203 // the items at hand. | 1195 // the items at hand. |
| 1204 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, AltNumberTabsTabbing) { | 1196 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, AltNumberTabsTabbing) { |
| 1205 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1197 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1206 ChromeLauncherController* controller = | |
| 1207 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1208 | 1198 |
| 1209 ash::LauncherID shortcut_id = CreateShortcut("app"); | 1199 ash::LauncherID shortcut_id = CreateShortcut("app"); |
| 1210 controller->SetRefocusURLPatternForTest( | 1200 controller_->SetRefocusURLPatternForTest( |
| 1211 shortcut_id, GURL("http://www.example.com/path/*")); | 1201 shortcut_id, GURL("http://www.example.com/path/*")); |
| 1212 std::string url = "http://www.example.com/path/bla"; | 1202 std::string url = "http://www.example.com/path/bla"; |
| 1213 | 1203 |
| 1214 int shortcut_index = model_->ItemIndexByID(shortcut_id); | 1204 int shortcut_index = model_->ItemIndexByID(shortcut_id); |
| 1215 | 1205 |
| 1216 // Create an application handled browser tab. | 1206 // Create an application handled browser tab. |
| 1217 ui_test_utils::NavigateToURLWithDisposition( | 1207 ui_test_utils::NavigateToURLWithDisposition( |
| 1218 browser(), | 1208 browser(), |
| 1219 GURL(url), | 1209 GURL(url), |
| 1220 NEW_FOREGROUND_TAB, | 1210 NEW_FOREGROUND_TAB, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1335 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1346 } | 1336 } |
| 1347 | 1337 |
| 1348 // Checks that after a session restore, we do not start applications on an | 1338 // Checks that after a session restore, we do not start applications on an |
| 1349 // activation. | 1339 // activation. |
| 1350 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, | 1340 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, |
| 1351 ActivateAfterSessionRestore) { | 1341 ActivateAfterSessionRestore) { |
| 1352 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1342 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1353 | 1343 |
| 1354 // Create a known application. | 1344 // Create a known application. |
| 1355 ChromeLauncherController* controller = | |
| 1356 static_cast<ChromeLauncherController*>(launcher_->delegate()); | |
| 1357 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1345 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 1358 | 1346 |
| 1359 // Create a new browser - without activating it - and load an "app" into it. | 1347 // Create a new browser - without activating it - and load an "app" into it. |
| 1360 Browser::CreateParams params = | 1348 Browser::CreateParams params = |
| 1361 Browser::CreateParams(profile(), chrome::GetActiveDesktop()); | 1349 Browser::CreateParams(profile(), chrome::GetActiveDesktop()); |
| 1362 params.initial_show_state = ui::SHOW_STATE_INACTIVE; | 1350 params.initial_show_state = ui::SHOW_STATE_INACTIVE; |
| 1363 Browser* browser2 = new Browser(params); | 1351 Browser* browser2 = new Browser(params); |
| 1364 controller->SetRefocusURLPatternForTest( | 1352 controller_->SetRefocusURLPatternForTest( |
| 1365 shortcut_id, GURL("http://www.example.com/path/*")); | 1353 shortcut_id, GURL("http://www.example.com/path/*")); |
| 1366 std::string url = "http://www.example.com/path/bla"; | 1354 std::string url = "http://www.example.com/path/bla"; |
| 1367 ui_test_utils::NavigateToURLWithDisposition( | 1355 ui_test_utils::NavigateToURLWithDisposition( |
| 1368 browser2, | 1356 browser2, |
| 1369 GURL(url), | 1357 GURL(url), |
| 1370 NEW_FOREGROUND_TAB, | 1358 NEW_FOREGROUND_TAB, |
| 1371 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1359 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1372 | 1360 |
| 1373 // Remember the number of tabs for each browser. | 1361 // Remember the number of tabs for each browser. |
| 1374 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1362 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1375 int tab_count1 = tab_strip->count(); | 1363 int tab_count1 = tab_strip->count(); |
| 1376 TabStripModel* tab_strip2 = browser2->tab_strip_model(); | 1364 TabStripModel* tab_strip2 = browser2->tab_strip_model(); |
| 1377 int tab_count2 = tab_strip2->count(); | 1365 int tab_count2 = tab_strip2->count(); |
| 1378 | 1366 |
| 1379 // Check that we have two browsers and the inactive browser remained inactive. | 1367 // Check that we have two browsers and the inactive browser remained inactive. |
| 1380 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | 1368 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 1381 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), | 1369 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), |
| 1382 browser()); | 1370 browser()); |
| 1383 // Check that the LRU browser list does only contain the original browser. | 1371 // Check that the LRU browser list does only contain the original browser. |
| 1384 BrowserList* ash_browser_list = | 1372 BrowserList* ash_browser_list = |
| 1385 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 1373 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 1386 BrowserList::const_reverse_iterator it = | 1374 BrowserList::const_reverse_iterator it = |
| 1387 ash_browser_list->begin_last_active(); | 1375 ash_browser_list->begin_last_active(); |
| 1388 EXPECT_EQ(*it, browser()); | 1376 EXPECT_EQ(*it, browser()); |
| 1389 ++it; | 1377 ++it; |
| 1390 EXPECT_EQ(it, ash_browser_list->end_last_active()); | 1378 EXPECT_EQ(it, ash_browser_list->end_last_active()); |
| 1391 | 1379 |
| 1392 // Now request to either activate an existing app or create a new one. | 1380 // Now request to either activate an existing app or create a new one. |
| 1393 controller->ItemSelected(*model_->ItemByID(shortcut_id), | 1381 controller_->ItemSelected(*model_->ItemByID(shortcut_id), |
| 1394 ui::KeyEvent(ui::ET_KEY_RELEASED, | 1382 ui::KeyEvent(ui::ET_KEY_RELEASED, |
| 1395 ui::VKEY_RETURN, | 1383 ui::VKEY_RETURN, |
| 1396 0, | 1384 0, |
| 1397 false)); | 1385 false)); |
| 1398 | 1386 |
| 1399 // Check that we have set focus on the existing application and nothing new | 1387 // Check that we have set focus on the existing application and nothing new |
| 1400 // was created. | 1388 // was created. |
| 1401 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | 1389 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 1402 EXPECT_EQ(tab_count1, tab_strip->count()); | 1390 EXPECT_EQ(tab_count1, tab_strip->count()); |
| 1403 EXPECT_EQ(tab_count2, tab_strip2->count()); | 1391 EXPECT_EQ(tab_count2, tab_strip2->count()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 // Test now that a click does create a new application tab. | 1528 // Test now that a click does create a new application tab. |
| 1541 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1529 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1542 int tab_count = tab_strip->count(); | 1530 int tab_count = tab_strip->count(); |
| 1543 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | 1531 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), |
| 1544 bounds_grid_1.CenterPoint().y()); | 1532 bounds_grid_1.CenterPoint().y()); |
| 1545 generator.ClickLeftButton(); | 1533 generator.ClickLeftButton(); |
| 1546 base::MessageLoop::current()->RunUntilIdle(); | 1534 base::MessageLoop::current()->RunUntilIdle(); |
| 1547 EXPECT_EQ(tab_count + 1, tab_strip->count()); | 1535 EXPECT_EQ(tab_count + 1, tab_strip->count()); |
| 1548 } | 1536 } |
| 1549 | 1537 |
| 1550 // Check LauncherItemController of Browser Shortcut functionality. | 1538 // Check LauncherItemController of Browser Shortcut functionality and its |
| 1539 // status. |
| 1551 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, | 1540 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, |
| 1552 BrowserShortcutLauncherItemController) { | 1541 BrowserShortcutLauncherItemTest) { |
| 1553 ChromeLauncherControllerPerApp* controller = | |
| 1554 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); | |
| 1555 LauncherItemController* item_controller = | 1542 LauncherItemController* item_controller = |
| 1556 controller->GetBrowserShortcutLauncherItemController(); | 1543 controller_->GetBrowserShortcutLauncherItemController(); |
| 1557 | 1544 |
| 1558 // Get the number of browsers. | 1545 // Get the number of browsers. |
| 1559 size_t running_browser = chrome::GetTotalBrowserCount(); | 1546 size_t running_browser = chrome::GetTotalBrowserCount(); |
| 1560 EXPECT_EQ(0u, running_browser); | 1547 EXPECT_EQ(0u, running_browser); |
| 1561 EXPECT_FALSE(item_controller->IsOpen()); | 1548 EXPECT_FALSE(item_controller->IsOpen()); |
| 1562 | 1549 |
| 1563 // Activate. This creates new browser | 1550 // Activate. This creates new browser |
| 1564 item_controller->Activate(); | 1551 item_controller->Activate(); |
| 1565 // New Window is created. | 1552 // New Window is created. |
| 1566 running_browser = chrome::GetTotalBrowserCount(); | 1553 running_browser = chrome::GetTotalBrowserCount(); |
| 1567 EXPECT_EQ(1u, running_browser); | 1554 EXPECT_EQ(1u, running_browser); |
| 1568 EXPECT_TRUE(item_controller->IsOpen()); | 1555 EXPECT_TRUE(item_controller->IsOpen()); |
| 1569 | 1556 |
| 1570 // Minimize Window. | 1557 // Minimize Window. |
| 1571 aura::Window* window = ash::wm::GetActiveWindow(); | 1558 aura::Window* window = ash::wm::GetActiveWindow(); |
| 1572 ash::wm::MinimizeWindow(window); | 1559 ash::wm::MinimizeWindow(window); |
| 1573 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); | 1560 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); |
| 1574 | 1561 |
| 1575 // Activate again. This doesn't create new browser. | 1562 // Activate again. This doesn't create new browser. |
| 1576 // It activates window. | 1563 // It activates window. |
| 1577 item_controller->Activate(); | 1564 item_controller->Activate(); |
| 1578 running_browser = chrome::GetTotalBrowserCount(); | 1565 running_browser = chrome::GetTotalBrowserCount(); |
| 1579 EXPECT_EQ(1u, running_browser); | 1566 EXPECT_EQ(1u, running_browser); |
| 1580 EXPECT_TRUE(item_controller->IsOpen()); | 1567 EXPECT_TRUE(item_controller->IsOpen()); |
| 1581 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); | 1568 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); |
| 1582 } | 1569 } |
| OLD | NEW |