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