| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell_window.h" | 7 #include "apps/shell_window.h" |
| 8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
| 9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 browser()->tab_strip_model()->CloseSelectedTabs(); | 843 browser()->tab_strip_model()->CloseSelectedTabs(); |
| 844 destroyed_watcher.Wait(); | 844 destroyed_watcher.Wait(); |
| 845 EXPECT_EQ(--tab_count, tab_strip->count()); | 845 EXPECT_EQ(--tab_count, tab_strip->count()); |
| 846 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 846 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 847 } | 847 } |
| 848 | 848 |
| 849 // Launch the app first and then create the shortcut. | 849 // Launch the app first and then create the shortcut. |
| 850 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) { | 850 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) { |
| 851 TabStripModel* tab_strip = browser()->tab_strip_model(); | 851 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 852 int tab_count = tab_strip->count(); | 852 int tab_count = tab_strip->count(); |
| 853 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_FOREGROUND_TAB); | 853 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, |
| 854 NEW_FOREGROUND_TAB); |
| 854 EXPECT_EQ(++tab_count, tab_strip->count()); | 855 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 855 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 856 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| 856 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); | 857 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); |
| 857 WebContents* tab = tab_strip->GetActiveWebContents(); | 858 WebContents* tab = tab_strip->GetActiveWebContents(); |
| 858 content::WebContentsDestroyedWatcher destroyed_watcher(tab); | 859 content::WebContentsDestroyedWatcher destroyed_watcher(tab); |
| 859 browser()->tab_strip_model()->CloseSelectedTabs(); | 860 browser()->tab_strip_model()->CloseSelectedTabs(); |
| 860 destroyed_watcher.Wait(); | 861 destroyed_watcher.Wait(); |
| 861 EXPECT_EQ(--tab_count, tab_strip->count()); | 862 EXPECT_EQ(--tab_count, tab_strip->count()); |
| 862 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); | 863 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); |
| 863 } | 864 } |
| 864 | 865 |
| 865 // Launches an app in the background and then tries to open it. This is test for | 866 // Launches an app in the background and then tries to open it. This is test for |
| 866 // a crash we had. | 867 // a crash we had. |
| 867 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { | 868 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { |
| 868 TabStripModel* tab_strip = browser()->tab_strip_model(); | 869 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 869 int tab_count = tab_strip->count(); | 870 int tab_count = tab_strip->count(); |
| 870 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_BACKGROUND_TAB); | 871 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, |
| 872 NEW_BACKGROUND_TAB); |
| 871 EXPECT_EQ(++tab_count, tab_strip->count()); | 873 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 872 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id(), | 874 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id(), |
| 873 ash::LAUNCH_FROM_UNKNOWN, | 875 ash::LAUNCH_FROM_UNKNOWN, |
| 874 0); | 876 0); |
| 875 } | 877 } |
| 876 | 878 |
| 877 // Confirm that clicking a icon for an app running in one of 2 maxmized windows | 879 // Confirm that clicking a icon for an app running in one of 2 maxmized windows |
| 878 // activates the right window. | 880 // activates the right window. |
| 879 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { | 881 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { |
| 880 aura::Window* window1 = browser()->window()->GetNativeWindow(); | 882 aura::Window* window1 = browser()->window()->GetNativeWindow(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 | 1233 |
| 1232 // Checks that a windowed application does not add an item to the browser list. | 1234 // Checks that a windowed application does not add an item to the browser list. |
| 1233 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | 1235 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, |
| 1234 WindowedAppDoesNotAddToBrowser) { | 1236 WindowedAppDoesNotAddToBrowser) { |
| 1235 // Get the number of items in the browser menu. | 1237 // Get the number of items in the browser menu. |
| 1236 size_t items = NumberOfDetectedLauncherBrowsers(false); | 1238 size_t items = NumberOfDetectedLauncherBrowsers(false); |
| 1237 size_t running_browser = chrome::GetTotalBrowserCount(); | 1239 size_t running_browser = chrome::GetTotalBrowserCount(); |
| 1238 EXPECT_EQ(0u, items); | 1240 EXPECT_EQ(0u, items); |
| 1239 EXPECT_EQ(0u, running_browser); | 1241 EXPECT_EQ(0u, running_browser); |
| 1240 | 1242 |
| 1241 LoadAndLaunchExtension("app1", extensions::LAUNCH_WINDOW, NEW_WINDOW); | 1243 LoadAndLaunchExtension( |
| 1244 "app1", extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW); |
| 1242 | 1245 |
| 1243 // No new browser should get detected, even though one more is running. | 1246 // No new browser should get detected, even though one more is running. |
| 1244 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false)); | 1247 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false)); |
| 1245 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); | 1248 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); |
| 1246 | 1249 |
| 1247 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_WINDOW); | 1250 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); |
| 1248 | 1251 |
| 1249 // A new browser should get detected and one more should be running. | 1252 // A new browser should get detected and one more should be running. |
| 1250 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u); | 1253 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u); |
| 1251 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); | 1254 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); |
| 1252 } | 1255 } |
| 1253 | 1256 |
| 1254 // Checks the functionality to enumerate all browsers vs. all tabs. | 1257 // Checks the functionality to enumerate all browsers vs. all tabs. |
| 1255 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | 1258 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, |
| 1256 EnumerateALlBrowsersAndTabs) { | 1259 EnumerateALlBrowsersAndTabs) { |
| 1257 // Create at least one browser. | 1260 // Create at least one browser. |
| 1258 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_WINDOW); | 1261 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); |
| 1259 size_t browsers = NumberOfDetectedLauncherBrowsers(false); | 1262 size_t browsers = NumberOfDetectedLauncherBrowsers(false); |
| 1260 size_t tabs = NumberOfDetectedLauncherBrowsers(true); | 1263 size_t tabs = NumberOfDetectedLauncherBrowsers(true); |
| 1261 | 1264 |
| 1262 // Create a second browser. | 1265 // Create a second browser. |
| 1263 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_WINDOW); | 1266 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); |
| 1264 | 1267 |
| 1265 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false)); | 1268 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false)); |
| 1266 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); | 1269 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); |
| 1267 | 1270 |
| 1268 // Create only a tab. | 1271 // Create only a tab. |
| 1269 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_FOREGROUND_TAB); | 1272 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, |
| 1273 NEW_FOREGROUND_TAB); |
| 1270 | 1274 |
| 1271 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); | 1275 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); |
| 1272 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); | 1276 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); |
| 1273 } | 1277 } |
| 1274 | 1278 |
| 1275 // Check that the keyboard activation of a launcher item tabs properly through | 1279 // Check that the keyboard activation of a launcher item tabs properly through |
| 1276 // the items at hand. | 1280 // the items at hand. |
| 1277 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) { | 1281 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) { |
| 1278 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1282 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 1279 | 1283 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 launcher_->ActivateLauncherItem(1); | 1455 launcher_->ActivateLauncherItem(1); |
| 1452 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1456 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1453 launcher_->ActivateLauncherItem(1); | 1457 launcher_->ActivateLauncherItem(1); |
| 1454 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1458 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
| 1455 launcher_->ActivateLauncherItem(1); | 1459 launcher_->ActivateLauncherItem(1); |
| 1456 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | 1460 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); |
| 1457 launcher_->ActivateLauncherItem(1); | 1461 launcher_->ActivateLauncherItem(1); |
| 1458 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1462 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1459 | 1463 |
| 1460 // Create anther app and make sure that none of our browsers is active. | 1464 // Create anther app and make sure that none of our browsers is active. |
| 1461 LoadAndLaunchExtension("app1", extensions::LAUNCH_TAB, NEW_WINDOW); | 1465 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); |
| 1462 EXPECT_NE(window1, ash::wm::GetActiveWindow()); | 1466 EXPECT_NE(window1, ash::wm::GetActiveWindow()); |
| 1463 EXPECT_NE(window2, ash::wm::GetActiveWindow()); | 1467 EXPECT_NE(window2, ash::wm::GetActiveWindow()); |
| 1464 | 1468 |
| 1465 // After activation our browser should be active again. | 1469 // After activation our browser should be active again. |
| 1466 launcher_->ActivateLauncherItem(1); | 1470 launcher_->ActivateLauncherItem(1); |
| 1467 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1471 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1468 } | 1472 } |
| 1469 | 1473 |
| 1470 // Checks that after a session restore, we do not start applications on an | 1474 // Checks that after a session restore, we do not start applications on an |
| 1471 // activation. | 1475 // activation. |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 extension_misc::kWebStoreAppId); | 1998 extension_misc::kWebStoreAppId); |
| 1995 ASSERT_NE(0, id); | 1999 ASSERT_NE(0, id); |
| 1996 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); | 2000 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); |
| 1997 | 2001 |
| 1998 // Create a windowed application. | 2002 // Create a windowed application. |
| 1999 AppLaunchParams params( | 2003 AppLaunchParams params( |
| 2000 profile(), | 2004 profile(), |
| 2001 controller_->GetExtensionForAppID(extension_misc::kWebStoreAppId), | 2005 controller_->GetExtensionForAppID(extension_misc::kWebStoreAppId), |
| 2002 0, | 2006 0, |
| 2003 chrome::HOST_DESKTOP_TYPE_ASH); | 2007 chrome::HOST_DESKTOP_TYPE_ASH); |
| 2004 params.container = extensions::LAUNCH_WINDOW; | 2008 params.container = extensions::LAUNCH_CONTAINER_WINDOW; |
| 2005 OpenApplication(params); | 2009 OpenApplication(params); |
| 2006 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); | 2010 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); |
| 2007 | 2011 |
| 2008 // Find the browser which holds our app. | 2012 // Find the browser which holds our app. |
| 2009 Browser* app_browser = NULL; | 2013 Browser* app_browser = NULL; |
| 2010 const BrowserList* ash_browser_list = | 2014 const BrowserList* ash_browser_list = |
| 2011 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 2015 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 2012 for (BrowserList::const_reverse_iterator it = | 2016 for (BrowserList::const_reverse_iterator it = |
| 2013 ash_browser_list->begin_last_active(); | 2017 ash_browser_list->begin_last_active(); |
| 2014 it != ash_browser_list->end_last_active() && !app_browser; ++it) { | 2018 it != ash_browser_list->end_last_active() && !app_browser; ++it) { |
| 2015 if ((*it)->is_app()) { | 2019 if ((*it)->is_app()) { |
| 2016 app_browser = *it; | 2020 app_browser = *it; |
| 2017 break; | 2021 break; |
| 2018 } | 2022 } |
| 2019 } | 2023 } |
| 2020 ASSERT_TRUE(app_browser); | 2024 ASSERT_TRUE(app_browser); |
| 2021 | 2025 |
| 2022 // After navigating away in the app, we should still be active. | 2026 // After navigating away in the app, we should still be active. |
| 2023 ui_test_utils::NavigateToURL(app_browser, | 2027 ui_test_utils::NavigateToURL(app_browser, |
| 2024 GURL("http://www.foo.com/bar.html")); | 2028 GURL("http://www.foo.com/bar.html")); |
| 2025 // Make sure the navigation was entirely performed. | 2029 // Make sure the navigation was entirely performed. |
| 2026 base::MessageLoop::current()->RunUntilIdle(); | 2030 base::MessageLoop::current()->RunUntilIdle(); |
| 2027 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); | 2031 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(id)->status); |
| 2028 app_browser->tab_strip_model()->CloseWebContentsAt(0, | 2032 app_browser->tab_strip_model()->CloseWebContentsAt(0, |
| 2029 TabStripModel::CLOSE_NONE); | 2033 TabStripModel::CLOSE_NONE); |
| 2030 // Make sure that the app is really gone. | 2034 // Make sure that the app is really gone. |
| 2031 base::MessageLoop::current()->RunUntilIdle(); | 2035 base::MessageLoop::current()->RunUntilIdle(); |
| 2032 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); | 2036 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status); |
| 2033 } | 2037 } |
| OLD | NEW |