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.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/public/cpp/shelf_item_delegate.h" | 9 #include "ash/public/cpp/shelf_item_delegate.h" |
| 10 #include "ash/public/cpp/window_properties.h" | 10 #include "ash/public/cpp/window_properties.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 #include "ui/events/event_constants.h" | 82 #include "ui/events/event_constants.h" |
| 83 #include "ui/events/test/event_generator.h" | 83 #include "ui/events/test/event_generator.h" |
| 84 | 84 |
| 85 using ash::WmShelf; | 85 using ash::WmShelf; |
| 86 using extensions::AppWindow; | 86 using extensions::AppWindow; |
| 87 using extensions::Extension; | 87 using extensions::Extension; |
| 88 using content::WebContents; | 88 using content::WebContents; |
| 89 | 89 |
| 90 namespace { | 90 namespace { |
| 91 | 91 |
| 92 constexpr char kFooShelfId[] = "mjemblieefldeffoklbbmkhihdblgaaa"; | |
|
msw
2017/05/05 21:45:04
Could we use something like kDummyAppId? It seems
khmel
2017/05/05 22:45:12
Good point, no need to have special id here.
| |
| 93 constexpr char kBarShelfId[] = "mjemblieefldeffoklbbmkhihdblgaab"; | |
| 94 | |
| 92 // A callback that records the action taken when a shelf item is selected. | 95 // A callback that records the action taken when a shelf item is selected. |
| 93 void SelectItemCallback(ash::ShelfAction* action_taken, | 96 void SelectItemCallback(ash::ShelfAction* action_taken, |
| 94 base::RunLoop* run_loop, | 97 base::RunLoop* run_loop, |
| 95 ash::ShelfAction action, | 98 ash::ShelfAction action, |
| 96 base::Optional<ash::MenuItemList>) { | 99 base::Optional<ash::MenuItemList>) { |
| 97 *action_taken = action; | 100 *action_taken = action; |
| 98 run_loop->Quit(); | 101 run_loop->Quit(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments. | 104 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments. |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 471 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 469 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 472 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 470 ++item_count; | 473 ++item_count; |
| 471 ASSERT_EQ(item_count, shelf_model()->item_count()); | 474 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 472 const ash::ShelfItem& item1 = GetLastLauncherItem(); | 475 const ash::ShelfItem& item1 = GetLastLauncherItem(); |
| 473 ash::ShelfID id = item1.id; | 476 ash::ShelfID id = item1.id; |
| 474 EXPECT_EQ(ash::TYPE_APP, item1.type); | 477 EXPECT_EQ(ash::TYPE_APP, item1.type); |
| 475 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 478 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 476 | 479 |
| 477 // Create a shortcut. The app item should be after it. | 480 // Create a shortcut. The app item should be after it. |
| 478 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::ShelfID("foo")); | 481 ash::ShelfID foo_id = |
| 482 CreateAppShortcutLauncherItem(ash::ShelfID(kFooShelfId)); | |
| 479 ++item_count; | 483 ++item_count; |
| 480 ASSERT_EQ(item_count, shelf_model()->item_count()); | 484 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 481 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), | 485 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), |
| 482 shelf_model()->ItemIndexByID(id)); | 486 shelf_model()->ItemIndexByID(id)); |
| 483 | 487 |
| 484 // Pin the app. The item should remain. | 488 // Pin the app. The item should remain. |
| 485 controller_->PinAppWithID(extension->id()); | 489 controller_->PinAppWithID(extension->id()); |
| 486 ASSERT_EQ(item_count, shelf_model()->item_count()); | 490 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 487 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); | 491 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); |
| 488 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type); | 492 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type); |
| 489 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); | 493 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); |
| 490 | 494 |
| 491 // New shortcuts should come after the item. | 495 // New shortcuts should come after the item. |
| 492 ash::ShelfID bar_id = CreateAppShortcutLauncherItem(ash::ShelfID("bar")); | 496 ash::ShelfID bar_id = |
| 497 CreateAppShortcutLauncherItem(ash::ShelfID(kBarShelfId)); | |
| 493 ++item_count; | 498 ++item_count; |
| 494 ASSERT_EQ(item_count, shelf_model()->item_count()); | 499 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 495 EXPECT_LT(shelf_model()->ItemIndexByID(id), | 500 EXPECT_LT(shelf_model()->ItemIndexByID(id), |
| 496 shelf_model()->ItemIndexByID(bar_id)); | 501 shelf_model()->ItemIndexByID(bar_id)); |
| 497 | 502 |
| 498 // Then close it, make sure the item remains. | 503 // Then close it, make sure the item remains. |
| 499 CloseAppWindow(window); | 504 CloseAppWindow(window); |
| 500 ASSERT_EQ(item_count, shelf_model()->item_count()); | 505 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 501 } | 506 } |
| 502 | 507 |
| 503 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { | 508 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { |
| 504 int item_count = shelf_model()->item_count(); | 509 int item_count = shelf_model()->item_count(); |
| 505 | 510 |
| 506 // First get app_id. | 511 // First get app_id. |
| 507 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 512 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 508 const std::string app_id = extension->id(); | 513 const std::string app_id = extension->id(); |
| 509 | 514 |
| 510 // Then create a shortcut. | 515 // Then create a shortcut. |
| 511 ash::ShelfID shortcut_id = | 516 ash::ShelfID shortcut_id = |
| 512 CreateAppShortcutLauncherItem(ash::ShelfID(app_id)); | 517 CreateAppShortcutLauncherItem(ash::ShelfID(app_id)); |
| 513 ++item_count; | 518 ++item_count; |
| 514 ASSERT_EQ(item_count, shelf_model()->item_count()); | 519 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 515 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); | 520 ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id); |
| 516 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type); | 521 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type); |
| 517 EXPECT_EQ(ash::STATUS_CLOSED, item.status); | 522 EXPECT_EQ(ash::STATUS_CLOSED, item.status); |
| 518 | 523 |
| 519 // Create a second shortcut. This will be needed to force the first one to | 524 // Create a second shortcut. This will be needed to force the first one to |
| 520 // move once it gets unpinned. | 525 // move once it gets unpinned. |
| 521 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::ShelfID("foo")); | 526 ash::ShelfID foo_id = |
| 527 CreateAppShortcutLauncherItem(ash::ShelfID(kFooShelfId)); | |
| 522 ++item_count; | 528 ++item_count; |
| 523 ASSERT_EQ(item_count, shelf_model()->item_count()); | 529 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 524 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), | 530 EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id), |
| 525 shelf_model()->ItemIndexByID(foo_id)); | 531 shelf_model()->ItemIndexByID(foo_id)); |
| 526 | 532 |
| 527 // Open a window. Confirm the item is now running. | 533 // Open a window. Confirm the item is now running. |
| 528 AppWindow* window = CreateAppWindow(browser()->profile(), extension); | 534 AppWindow* window = CreateAppWindow(browser()->profile(), extension); |
| 529 ash::wm::ActivateWindow(window->GetNativeWindow()); | 535 ash::wm::ActivateWindow(window->GetNativeWindow()); |
| 530 ASSERT_EQ(item_count, shelf_model()->item_count()); | 536 ASSERT_EQ(item_count, shelf_model()->item_count()); |
| 531 item = *shelf_model()->ItemByID(shortcut_id); | 537 item = *shelf_model()->ItemByID(shortcut_id); |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2397 | 2403 |
| 2398 // Close all windows via the menu item. | 2404 // Close all windows via the menu item. |
| 2399 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2405 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2400 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2406 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2401 | 2407 |
| 2402 // Check if "Close" is removed from the context menu. | 2408 // Check if "Close" is removed from the context menu. |
| 2403 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2409 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2404 ASSERT_FALSE( | 2410 ASSERT_FALSE( |
| 2405 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2411 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2406 } | 2412 } |
| OLD | NEW |