Chromium Code Reviews| 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/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/shelf/app_list_button.h" | 10 #include "ash/common/shelf/app_list_button.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 ~LauncherPlatformAppBrowserTest() override {} | 191 ~LauncherPlatformAppBrowserTest() override {} |
| 192 | 192 |
| 193 void RunTestOnMainThreadLoop() override { | 193 void RunTestOnMainThreadLoop() override { |
| 194 controller_ = GetChromeLauncherControllerImpl(); | 194 controller_ = GetChromeLauncherControllerImpl(); |
| 195 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | 195 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } | 198 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } |
| 199 | 199 |
| 200 ash::ShelfID CreateAppShortcutLauncherItem( | 200 ash::ShelfID CreateAppShortcutLauncherItem( |
| 201 const ash::launcher::AppLauncherId& app_launcher_id) { | 201 const ash::launcher::AppLauncherId& app_launcher_id, |
| 202 const std::string& title) { | |
| 202 return controller_->CreateAppShortcutLauncherItem( | 203 return controller_->CreateAppShortcutLauncherItem( |
| 203 app_launcher_id, shelf_model()->item_count()); | 204 app_launcher_id, title, shelf_model()->item_count()); |
| 204 } | 205 } |
| 205 | 206 |
| 206 const ash::ShelfItem& GetLastLauncherItem() { | 207 const ash::ShelfItem& GetLastLauncherItem() { |
| 207 // Unless there are any panels, the item at index [count - 1] will be | 208 // Unless there are any panels, the item at index [count - 1] will be |
| 208 // the desired item. | 209 // the desired item. |
| 209 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 210 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
| 210 } | 211 } |
| 211 | 212 |
| 212 const ash::ShelfItem& GetLastLauncherPanelItem() { | 213 const ash::ShelfItem& GetLastLauncherPanelItem() { |
| 213 // Panels show up on the right side of the shelf, so the desired item | 214 // Panels show up on the right side of the shelf, so the desired item |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 LoadExtension(test_data_dir_.AppendASCII(name)); | 298 LoadExtension(test_data_dir_.AppendASCII(name)); |
| 298 | 299 |
| 299 // First get app_id. | 300 // First get app_id. |
| 300 const Extension* extension = | 301 const Extension* extension = |
| 301 service->GetExtensionById(last_loaded_extension_id(), false); | 302 service->GetExtensionById(last_loaded_extension_id(), false); |
| 302 const std::string app_id = extension->id(); | 303 const std::string app_id = extension->id(); |
| 303 | 304 |
| 304 // Then create a shortcut. | 305 // Then create a shortcut. |
| 305 int item_count = model_->item_count(); | 306 int item_count = model_->item_count(); |
| 306 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( | 307 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( |
| 307 ash::launcher::AppLauncherId(app_id), item_count); | 308 ash::launcher::AppLauncherId(app_id), "", item_count); |
| 308 controller_->SyncPinPosition(shortcut_id); | 309 controller_->SyncPinPosition(shortcut_id); |
| 309 EXPECT_EQ(++item_count, model_->item_count()); | 310 EXPECT_EQ(++item_count, model_->item_count()); |
| 310 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); | 311 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); |
| 311 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 312 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 312 return item.id; | 313 return item.id; |
| 313 } | 314 } |
| 314 | 315 |
|
Mr4D (OOO till 08-26)
2017/01/06 16:37:57
I think it would be a good idea to add a test whic
| |
| 315 void RemoveShortcut(ash::ShelfID id) { | 316 void RemoveShortcut(ash::ShelfID id) { |
| 316 controller_->Unpin(id); | 317 controller_->Unpin(id); |
| 317 } | 318 } |
| 318 | 319 |
| 319 ash::ShelfID PinFakeApp(const std::string& app_id) { | 320 ash::ShelfID PinFakeApp(const std::string& app_id) { |
| 320 return controller_->CreateAppShortcutLauncherItem( | 321 return controller_->CreateAppShortcutLauncherItem( |
| 321 ash::launcher::AppLauncherId(app_id), model_->item_count()); | 322 ash::launcher::AppLauncherId(app_id), "", model_->item_count()); |
| 322 } | 323 } |
| 323 | 324 |
| 324 // Get the index of an item which has the given type. | 325 // Get the index of an item which has the given type. |
| 325 int GetIndexOfShelfItemType(ash::ShelfItemType type) { | 326 int GetIndexOfShelfItemType(ash::ShelfItemType type) { |
| 326 return model_->GetItemIndexForType(type); | 327 return model_->GetItemIndexForType(type); |
| 327 } | 328 } |
| 328 | 329 |
| 329 // Try to rip off |item_index|. | 330 // Try to rip off |item_index|. |
| 330 void RipOffItemIndex(int index, | 331 void RipOffItemIndex(int index, |
| 331 ui::test::EventGenerator* generator, | 332 ui::test::EventGenerator* generator, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 // Test that we can launch a platform app that already has a shortcut. | 419 // Test that we can launch a platform app that already has a shortcut. |
| 419 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { | 420 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { |
| 420 int item_count = shelf_model()->item_count(); | 421 int item_count = shelf_model()->item_count(); |
| 421 | 422 |
| 422 // First get app_id. | 423 // First get app_id. |
| 423 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 424 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 424 const std::string app_id = extension->id(); | 425 const std::string app_id = extension->id(); |
| 425 | 426 |
| 426 // Then create a shortcut. | 427 // Then create a shortcut. |
| 427 ash::ShelfID shortcut_id = | 428 ash::ShelfID shortcut_id = |
| 428 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id)); | 429 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id), ""); |
| 429 ++item_count; | 430 ++item_count; |
| 430 ASSERT_EQ(item_count, shelf_model()->item_count()); | 431 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 431 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 432 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 432 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 433 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 433 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 434 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 434 | 435 |
| 435 // Open a window. Confirm the item is now running. | 436 // Open a window. Confirm the item is now running. |
| 436 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 437 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 437 ash::wm::ActivateWindow(window->GetNativeWindow()); | 438 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 438 ASSERT_EQ(item_count, shelf_model()->item_count()); | 439 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 455 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 456 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 456 ++item_count; | 457 ++item_count; |
| 457 ASSERT_EQ(item_count, shelf_model()->item_count()); | 458 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 458 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 459 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 459 ash::ShelfID id = item1.id; | 460 ash::ShelfID id = item1.id; |
| 460 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); | 461 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); |
| 461 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 462 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 462 | 463 |
| 463 // Create a shortcut. The app item should be after it. | 464 // Create a shortcut. The app item should be after it. |
| 464 ash::ShelfID foo_id = | 465 ash::ShelfID foo_id = |
| 465 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo")); | 466 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo"), ""); |
| 466 ++item_count; | 467 ++item_count; |
| 467 ASSERT_EQ(item_count, shelf_model()->item_count()); | 468 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 468 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), | 469 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), |
| 469 shelf_model()->ItemIndexByID(id)); | 470 shelf_model()->ItemIndexByID(id)); |
| 470 | 471 |
| 471 // Pin the app. The item should remain. | 472 // Pin the app. The item should remain. |
| 472 controller_->Pin(id); | 473 controller_->Pin(id); |
| 473 ASSERT_EQ(item_count, shelf_model()->item_count()); | 474 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 474 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); | 475 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); |
| 475 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); | 476 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); |
| 476 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 477 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 477 | 478 |
| 478 // New shortcuts should come after the item. | 479 // New shortcuts should come after the item. |
| 479 ash::ShelfID bar_id = | 480 ash::ShelfID bar_id = |
| 480 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("bar")); | 481 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("bar"), ""); |
| 481 ++item_count; | 482 ++item_count; |
| 482 ASSERT_EQ(item_count, shelf_model()->item_count()); | 483 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 483 EXPECT_LT(shelf_model()->ItemIndexByID(id), | 484 EXPECT_LT(shelf_model()->ItemIndexByID(id), |
| 484 shelf_model()->ItemIndexByID(bar_id)); | 485 shelf_model()->ItemIndexByID(bar_id)); |
| 485 | 486 |
| 486 // Then close it, make sure the item remains. | 487 // Then close it, make sure the item remains. |
| 487 CloseAppWindow(window); | 488 CloseAppWindow(window); |
| 488 ASSERT_EQ(item_count, shelf_model()->item_count()); | 489 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 489 } | 490 } |
| 490 | 491 |
| 491 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { | 492 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { |
| 492 int item_count = shelf_model()->item_count(); | 493 int item_count = shelf_model()->item_count(); |
| 493 | 494 |
| 494 // First get app_id. | 495 // First get app_id. |
| 495 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 496 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 496 const std::string app_id = extension->id(); | 497 const std::string app_id = extension->id(); |
| 497 | 498 |
| 498 // Then create a shortcut. | 499 // Then create a shortcut. |
| 499 ash::ShelfID shortcut_id = | 500 ash::ShelfID shortcut_id = |
| 500 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id)); | 501 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id), ""); |
| 501 ++item_count; | 502 ++item_count; |
| 502 ASSERT_EQ(item_count, shelf_model()->item_count()); | 503 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 503 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 504 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 504 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 505 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
| 505 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 506 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 506 | 507 |
| 507 // Create a second shortcut. This will be needed to force the first one to | 508 // Create a second shortcut. This will be needed to force the first one to |
| 508 // move once it gets unpinned. | 509 // move once it gets unpinned. |
| 509 ash::ShelfID foo_id = | 510 ash::ShelfID foo_id = |
| 510 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo")); | 511 CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo"), ""); |
| 511 ++item_count; | 512 ++item_count; |
| 512 ASSERT_EQ(item_count, shelf_model()->item_count()); | 513 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 513 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), | 514 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), |
| 514 shelf_model()->ItemIndexByID(foo_id)); | 515 shelf_model()->ItemIndexByID(foo_id)); |
| 515 | 516 |
| 516 // Open a window. Confirm the item is now running. | 517 // Open a window. Confirm the item is now running. |
| 517 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 518 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 518 ash::wm::ActivateWindow(window->GetNativeWindow()); | 519 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 519 ASSERT_EQ(item_count, shelf_model()->item_count()); | 520 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 520 item = *shelf_model()->ItemByID(shortcut_id); | 521 item = *shelf_model()->ItemByID(shortcut_id); |
| (...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2418 | 2419 |
| 2419 // Close all windows via the menu item. | 2420 // Close all windows via the menu item. |
| 2420 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2421 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2421 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2422 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2422 | 2423 |
| 2423 // Check if "Close" is removed from the context menu. | 2424 // Check if "Close" is removed from the context menu. |
| 2424 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2425 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2425 ASSERT_FALSE( | 2426 ASSERT_FALSE( |
| 2426 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2427 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2427 } | 2428 } |
| OLD | NEW |