Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698