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