| 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_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/common/shelf/app_list_button.h" | 9 #include "ash/common/shelf/app_list_button.h" |
| 10 #include "ash/common/shelf/shelf_button.h" | 10 #include "ash/common/shelf/shelf_button.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 SessionControllerClient::FlushForTesting(); | 197 SessionControllerClient::FlushForTesting(); |
| 198 | 198 |
| 199 controller_ = GetChromeLauncherControllerImpl(); | 199 controller_ = GetChromeLauncherControllerImpl(); |
| 200 ASSERT_TRUE(controller_); | 200 ASSERT_TRUE(controller_); |
| 201 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | 201 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } | 204 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } |
| 205 | 205 |
| 206 ash::ShelfID CreateAppShortcutLauncherItem( | 206 ash::ShelfID CreateAppShortcutLauncherItem( |
| 207 const ash::launcher::AppLauncherId& app_launcher_id) { | 207 const ash::AppLauncherId& app_launcher_id) { |
| 208 return controller_->CreateAppShortcutLauncherItem( | 208 return controller_->CreateAppShortcutLauncherItem( |
| 209 app_launcher_id, shelf_model()->item_count()); | 209 app_launcher_id, shelf_model()->item_count()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 const ash::ShelfItem& GetLastLauncherItem() { | 212 const ash::ShelfItem& GetLastLauncherItem() { |
| 213 // Unless there are any panels, the item at index [count - 1] will be | 213 // Unless there are any panels, the item at index [count - 1] will be |
| 214 // the desired item. | 214 // the desired item. |
| 215 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 215 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
| 216 } | 216 } |
| 217 | 217 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 LoadExtension(test_data_dir_.AppendASCII(name)); | 292 LoadExtension(test_data_dir_.AppendASCII(name)); |
| 293 | 293 |
| 294 // First get app_id. | 294 // First get app_id. |
| 295 const Extension* extension = | 295 const Extension* extension = |
| 296 service->GetExtensionById(last_loaded_extension_id(), false); | 296 service->GetExtensionById(last_loaded_extension_id(), false); |
| 297 const std::string app_id = extension->id(); | 297 const std::string app_id = extension->id(); |
| 298 | 298 |
| 299 // Then create a shortcut. | 299 // Then create a shortcut. |
| 300 int item_count = model_->item_count(); | 300 int item_count = model_->item_count(); |
| 301 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( | 301 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( |
| 302 ash::launcher::AppLauncherId(app_id), item_count); | 302 ash::AppLauncherId(app_id), item_count); |
| 303 controller_->SyncPinPosition(shortcut_id); | 303 controller_->SyncPinPosition(shortcut_id); |
| 304 EXPECT_EQ(++item_count, model_->item_count()); | 304 EXPECT_EQ(++item_count, model_->item_count()); |
| 305 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); | 305 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); |
| 306 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 306 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 307 return item.id; | 307 return item.id; |
| 308 } | 308 } |
| 309 | 309 |
| 310 void RemoveShortcut(ash::ShelfID id) { | 310 void RemoveShortcut(ash::ShelfID id) { |
| 311 controller_->Unpin(id); | 311 controller_->Unpin(id); |
| 312 } | 312 } |
| 313 | 313 |
| 314 ash::ShelfID PinFakeApp(const std::string& app_id) { | 314 ash::ShelfID PinFakeApp(const std::string& app_id) { |
| 315 return controller_->CreateAppShortcutLauncherItem( | 315 return controller_->CreateAppShortcutLauncherItem( |
| 316 ash::launcher::AppLauncherId(app_id), model_->item_count()); | 316 ash::AppLauncherId(app_id), model_->item_count()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Get the index of an item which has the given type. | 319 // Get the index of an item which has the given type. |
| 320 int GetIndexOfShelfItemType(ash::ShelfItemType type) { | 320 int GetIndexOfShelfItemType(ash::ShelfItemType type) { |
| 321 return model_->GetItemIndexForType(type); | 321 return model_->GetItemIndexForType(type); |
| 322 } | 322 } |
| 323 | 323 |
| 324 // Try to rip off |item_index|. | 324 // Try to rip off |item_index|. |
| 325 void RipOffItemIndex(int index, | 325 void RipOffItemIndex(int index, |
| 326 ui::test::EventGenerator* generator, | 326 ui::test::EventGenerator* generator, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // Test that we can launch a platform app that already has a shortcut. | 413 // Test that we can launch a platform app that already has a shortcut. |
| 414 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { | 414 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { |
| 415 int item_count = shelf_model()->item_count(); | 415 int item_count = shelf_model()->item_count(); |
| 416 | 416 |
| 417 // First get app_id. | 417 // First get app_id. |
| 418 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 418 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 419 const std::string app_id = extension->id(); | 419 const std::string app_id = extension->id(); |
| 420 | 420 |
| 421 // Then create a shortcut. | 421 // Then create a shortcut. |
| 422 ash::ShelfID shortcut_id = | 422 ash::ShelfID shortcut_id = |
| 423 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id)); | 423 CreateAppShortcutLauncherItem(ash::AppLauncherId(app_id)); |
| 424 ++item_count; | 424 ++item_count; |
| 425 ASSERT_EQ(item_count, shelf_model()->item_count()); | 425 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 426 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 426 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 427 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 427 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 428 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 428 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 429 | 429 |
| 430 // Open a window. Confirm the item is now running. | 430 // Open a window. Confirm the item is now running. |
| 431 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 431 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 432 ash::wm::ActivateWindow(window->GetNativeWindow()); | 432 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 433 ASSERT_EQ(item_count, shelf_model()->item_count()); | 433 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 450 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 450 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 451 ++item_count; | 451 ++item_count; |
| 452 ASSERT_EQ(item_count, shelf_model()->item_count()); | 452 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 453 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 453 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 454 ash::ShelfID id = item1.id; | 454 ash::ShelfID id = item1.id; |
| 455 EXPECT_EQ(ash::TYPE_APP, item1.type); | 455 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 456 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 456 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 457 | 457 |
| 458 // Create a shortcut. The app item should be after it. | 458 // Create a shortcut. The app item should be after it. |
| 459 ash::ShelfID foo_id = | 459 ash::ShelfID foo_id = |
| 460 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo")); | 460 CreateAppShortcutLauncherItem(ash::AppLauncherId("foo")); |
| 461 ++item_count; | 461 ++item_count; |
| 462 ASSERT_EQ(item_count, shelf_model()->item_count()); | 462 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 463 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), | 463 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), |
| 464 shelf_model()->ItemIndexByID(id)); | 464 shelf_model()->ItemIndexByID(id)); |
| 465 | 465 |
| 466 // Pin the app. The item should remain. | 466 // Pin the app. The item should remain. |
| 467 controller_->Pin(id); | 467 controller_->Pin(id); |
| 468 ASSERT_EQ(item_count, shelf_model()->item_count()); | 468 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 469 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); | 469 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); |
| 470 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); | 470 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); |
| 471 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 471 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 472 | 472 |
| 473 // New shortcuts should come after the item. | 473 // New shortcuts should come after the item. |
| 474 ash::ShelfID bar_id = | 474 ash::ShelfID bar_id = |
| 475 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("bar")); | 475 CreateAppShortcutLauncherItem(ash::AppLauncherId("bar")); |
| 476 ++item_count; | 476 ++item_count; |
| 477 ASSERT_EQ(item_count, shelf_model()->item_count()); | 477 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 478 EXPECT_LT(shelf_model()->ItemIndexByID(id), | 478 EXPECT_LT(shelf_model()->ItemIndexByID(id), |
| 479 shelf_model()->ItemIndexByID(bar_id)); | 479 shelf_model()->ItemIndexByID(bar_id)); |
| 480 | 480 |
| 481 // Then close it, make sure the item remains. | 481 // Then close it, make sure the item remains. |
| 482 CloseAppWindow(window); | 482 CloseAppWindow(window); |
| 483 ASSERT_EQ(item_count, shelf_model()->item_count()); | 483 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 484 } | 484 } |
| 485 | 485 |
| 486 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { | 486 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { |
| 487 int item_count = shelf_model()->item_count(); | 487 int item_count = shelf_model()->item_count(); |
| 488 | 488 |
| 489 // First get app_id. | 489 // First get app_id. |
| 490 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 490 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 491 const std::string app_id = extension->id(); | 491 const std::string app_id = extension->id(); |
| 492 | 492 |
| 493 // Then create a shortcut. | 493 // Then create a shortcut. |
| 494 ash::ShelfID shortcut_id = | 494 ash::ShelfID shortcut_id = |
| 495 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id)); | 495 CreateAppShortcutLauncherItem(ash::AppLauncherId(app_id)); |
| 496 ++item_count; | 496 ++item_count; |
| 497 ASSERT_EQ(item_count, shelf_model()->item_count()); | 497 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 498 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 498 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 499 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 499 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 500 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 500 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 501 | 501 |
| 502 // Create a second shortcut. This will be needed to force the first one to | 502 // Create a second shortcut. This will be needed to force the first one to |
| 503 // move once it gets unpinned. | 503 // move once it gets unpinned. |
| 504 ash::ShelfID foo_id = | 504 ash::ShelfID foo_id = |
| 505 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo")); | 505 CreateAppShortcutLauncherItem(ash::AppLauncherId("foo")); |
| 506 ++item_count; | 506 ++item_count; |
| 507 ASSERT_EQ(item_count, shelf_model()->item_count()); | 507 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 508 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), | 508 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), |
| 509 shelf_model()->ItemIndexByID(foo_id)); | 509 shelf_model()->ItemIndexByID(foo_id)); |
| 510 | 510 |
| 511 // Open a window. Confirm the item is now running. | 511 // Open a window. Confirm the item is now running. |
| 512 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 512 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 513 ash::wm::ActivateWindow(window->GetNativeWindow()); | 513 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 514 ASSERT_EQ(item_count, shelf_model()->item_count()); | 514 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 515 item = *shelf_model()->ItemByID(shortcut_id); | 515 item = *shelf_model()->ItemByID(shortcut_id); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 } | 919 } |
| 920 | 920 |
| 921 // Launches an app in the background and then tries to open it. This is test for | 921 // Launches an app in the background and then tries to open it. This is test for |
| 922 // a crash we had. | 922 // a crash we had. |
| 923 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) { | 923 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) { |
| 924 TabStripModel* tab_strip = browser()->tab_strip_model(); | 924 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 925 int tab_count = tab_strip->count(); | 925 int tab_count = tab_strip->count(); |
| 926 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, | 926 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, |
| 927 WindowOpenDisposition::NEW_BACKGROUND_TAB); | 927 WindowOpenDisposition::NEW_BACKGROUND_TAB); |
| 928 EXPECT_EQ(++tab_count, tab_strip->count()); | 928 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 929 controller_->LaunchApp( | 929 controller_->LaunchApp(ash::AppLauncherId(last_loaded_extension_id()), |
| 930 ash::launcher::AppLauncherId(last_loaded_extension_id()), | 930 ash::LAUNCH_FROM_UNKNOWN, 0); |
| 931 ash::LAUNCH_FROM_UNKNOWN, 0); | |
| 932 } | 931 } |
| 933 | 932 |
| 934 // Confirm that clicking a icon for an app running in one of 2 maxmized windows | 933 // Confirm that clicking a icon for an app running in one of 2 maxmized windows |
| 935 // activates the right window. | 934 // activates the right window. |
| 936 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) { | 935 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) { |
| 937 aura::Window* window1 = browser()->window()->GetNativeWindow(); | 936 aura::Window* window1 = browser()->window()->GetNativeWindow(); |
| 938 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); | 937 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); |
| 939 window1_state->Maximize(); | 938 window1_state->Maximize(); |
| 940 content::WindowedNotificationObserver open_observer( | 939 content::WindowedNotificationObserver open_observer( |
| 941 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 940 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 971 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0); | 970 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0); |
| 972 EXPECT_EQ(++tab_count, tab_strip->count()); | 971 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 973 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0); | 972 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0); |
| 974 EXPECT_EQ(tab_count, tab_strip->count()); | 973 EXPECT_EQ(tab_count, tab_strip->count()); |
| 975 } | 974 } |
| 976 | 975 |
| 977 // Launching the same app multiple times should launch a copy for each call. | 976 // Launching the same app multiple times should launch a copy for each call. |
| 978 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) { | 977 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) { |
| 979 TabStripModel* tab_strip = browser()->tab_strip_model(); | 978 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 980 int tab_count = tab_strip->count(); | 979 int tab_count = tab_strip->count(); |
| 981 ash::launcher::AppLauncherId id( | 980 ash::AppLauncherId id( |
| 982 LoadExtension(test_data_dir_.AppendASCII("app1"))->id()); | 981 LoadExtension(test_data_dir_.AppendASCII("app1"))->id()); |
| 983 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); | 982 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); |
| 984 EXPECT_EQ(++tab_count, tab_strip->count()); | 983 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 985 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); | 984 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); |
| 986 EXPECT_EQ(++tab_count, tab_strip->count()); | 985 EXPECT_EQ(++tab_count, tab_strip->count()); |
| 987 } | 986 } |
| 988 | 987 |
| 989 // Launch 2 apps and toggle which is active. | 988 // Launch 2 apps and toggle which is active. |
| 990 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) { | 989 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) { |
| 991 int item_count = model_->item_count(); | 990 int item_count = model_->item_count(); |
| (...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2391 | 2390 |
| 2392 // Close all windows via the menu item. | 2391 // Close all windows via the menu item. |
| 2393 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2392 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2394 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2393 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2395 | 2394 |
| 2396 // Check if "Close" is removed from the context menu. | 2395 // Check if "Close" is removed from the context menu. |
| 2397 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2396 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2398 ASSERT_FALSE( | 2397 ASSERT_FALSE( |
| 2399 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2398 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2400 } | 2399 } |
| OLD | NEW |