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

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

Issue 2771663002: mash: Refactor ChromeLauncherController's ShelfDelegate code. (Closed)
Patch Set: Address comments. Created 3 years, 9 months 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/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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 int item_count = model_->item_count(); 332 int item_count = model_->item_count();
333 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( 333 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem(
334 ash::AppLaunchId(app_id), item_count); 334 ash::AppLaunchId(app_id), item_count);
335 controller_->SyncPinPosition(shortcut_id); 335 controller_->SyncPinPosition(shortcut_id);
336 EXPECT_EQ(++item_count, model_->item_count()); 336 EXPECT_EQ(++item_count, model_->item_count());
337 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); 337 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id);
338 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type); 338 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type);
339 return item.id; 339 return item.id;
340 } 340 }
341 341
342 void RemoveShortcut(ash::ShelfID id) {
343 controller_->Unpin(id);
344 }
345
346 ash::ShelfID PinFakeApp(const std::string& app_id) { 342 ash::ShelfID PinFakeApp(const std::string& app_id) {
347 return controller_->CreateAppShortcutLauncherItem(ash::AppLaunchId(app_id), 343 return controller_->CreateAppShortcutLauncherItem(ash::AppLaunchId(app_id),
348 model_->item_count()); 344 model_->item_count());
349 } 345 }
350 346
351 // Get the index of an item which has the given type. 347 // Get the index of an item which has the given type.
352 int GetIndexOfShelfItemType(ash::ShelfItemType type) { 348 int GetIndexOfShelfItemType(ash::ShelfItemType type) {
353 return model_->GetItemIndexForType(type); 349 return model_->GetItemIndexForType(type);
354 } 350 }
355 351
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 484 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
489 485
490 // Create a shortcut. The app item should be after it. 486 // Create a shortcut. The app item should be after it.
491 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::AppLaunchId("foo")); 487 ash::ShelfID foo_id = CreateAppShortcutLauncherItem(ash::AppLaunchId("foo"));
492 ++item_count; 488 ++item_count;
493 ASSERT_EQ(item_count, shelf_model()->item_count()); 489 ASSERT_EQ(item_count, shelf_model()->item_count());
494 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id), 490 EXPECT_LT(shelf_model()->ItemIndexByID(foo_id),
495 shelf_model()->ItemIndexByID(id)); 491 shelf_model()->ItemIndexByID(id));
496 492
497 // Pin the app. The item should remain. 493 // Pin the app. The item should remain.
498 controller_->Pin(id); 494 controller_->PinAppWithID(extension->id());
499 ASSERT_EQ(item_count, shelf_model()->item_count()); 495 ASSERT_EQ(item_count, shelf_model()->item_count());
500 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id); 496 const ash::ShelfItem& item2 = *shelf_model()->ItemByID(id);
501 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type); 497 EXPECT_EQ(ash::TYPE_PINNED_APP, item2.type);
502 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 498 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
503 499
504 // New shortcuts should come after the item. 500 // New shortcuts should come after the item.
505 ash::ShelfID bar_id = CreateAppShortcutLauncherItem(ash::AppLaunchId("bar")); 501 ash::ShelfID bar_id = CreateAppShortcutLauncherItem(ash::AppLaunchId("bar"));
506 ++item_count; 502 ++item_count;
507 ASSERT_EQ(item_count, shelf_model()->item_count()); 503 ASSERT_EQ(item_count, shelf_model()->item_count());
508 EXPECT_LT(shelf_model()->ItemIndexByID(id), 504 EXPECT_LT(shelf_model()->ItemIndexByID(id),
(...skipping 30 matching lines...) Expand all
539 535
540 // Open a window. Confirm the item is now running. 536 // Open a window. Confirm the item is now running.
541 AppWindow* window = CreateAppWindow(browser()->profile(), extension); 537 AppWindow* window = CreateAppWindow(browser()->profile(), extension);
542 ash::wm::ActivateWindow(window->GetNativeWindow()); 538 ash::wm::ActivateWindow(window->GetNativeWindow());
543 ASSERT_EQ(item_count, shelf_model()->item_count()); 539 ASSERT_EQ(item_count, shelf_model()->item_count());
544 item = *shelf_model()->ItemByID(shortcut_id); 540 item = *shelf_model()->ItemByID(shortcut_id);
545 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type); 541 EXPECT_EQ(ash::TYPE_PINNED_APP, item.type);
546 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 542 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
547 543
548 // Unpin the app. The item should remain. 544 // Unpin the app. The item should remain.
549 controller_->Unpin(shortcut_id); 545 controller_->UnpinAppWithID(app_id);
550 ASSERT_EQ(item_count, shelf_model()->item_count()); 546 ASSERT_EQ(item_count, shelf_model()->item_count());
551 item = *shelf_model()->ItemByID(shortcut_id); 547 item = *shelf_model()->ItemByID(shortcut_id);
552 EXPECT_EQ(ash::TYPE_APP, item.type); 548 EXPECT_EQ(ash::TYPE_APP, item.type);
553 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 549 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
554 // The item should have moved after the other shortcuts. 550 // The item should have moved after the other shortcuts.
555 EXPECT_GT(shelf_model()->ItemIndexByID(shortcut_id), 551 EXPECT_GT(shelf_model()->ItemIndexByID(shortcut_id),
556 shelf_model()->ItemIndexByID(foo_id)); 552 shelf_model()->ItemIndexByID(foo_id));
557 553
558 // Then close it, make sure the item's gone. 554 // Then close it, make sure the item's gone.
559 CloseAppWindow(window); 555 CloseAppWindow(window);
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); 2031 app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP);
2036 2032
2037 // Test #4: Ripping out the application should remove the item. 2033 // Test #4: Ripping out the application should remove the item.
2038 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM); 2034 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM);
2039 // => It should not have been removed and the location should be unchanged. 2035 // => It should not have been removed and the location should be unchanged.
2040 EXPECT_EQ(2, model_->item_count()); 2036 EXPECT_EQ(2, model_->item_count());
2041 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); 2037 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP));
2042 2038
2043 // Test #5: Uninstalling an application while it is being ripped off should 2039 // Test #5: Uninstalling an application while it is being ripped off should
2044 // not crash. 2040 // not crash.
2045 ash::ShelfID app_id = CreateShortcut("app2"); 2041 CreateShortcut("app2");
2046 test.RunMessageLoopUntilAnimationsDone(); 2042 test.RunMessageLoopUntilAnimationsDone();
2047 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); 2043 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP);
2048 EXPECT_EQ(3, model_->item_count()); // And it remains that way. 2044 EXPECT_EQ(3, model_->item_count()); // And it remains that way.
2049 RipOffItemIndex(app2_index, 2045 RipOffItemIndex(app2_index,
2050 &generator, 2046 &generator,
2051 &test, 2047 &test,
2052 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE); 2048 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE);
2053 RemoveShortcut(app_id); 2049 controller_->UnpinAppWithID("app2");
2054 test.RunMessageLoopUntilAnimationsDone(); 2050 test.RunMessageLoopUntilAnimationsDone();
2055 EXPECT_EQ(2, model_->item_count()); // The item should now be gone. 2051 EXPECT_EQ(2, model_->item_count()); // The item should now be gone.
2056 generator.ReleaseLeftButton(); 2052 generator.ReleaseLeftButton();
2057 base::RunLoop().RunUntilIdle(); 2053 base::RunLoop().RunUntilIdle();
2058 EXPECT_EQ(2, model_->item_count()); // And it remains that way. 2054 EXPECT_EQ(2, model_->item_count()); // And it remains that way.
2059 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); 2055 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP));
2060 2056
2061 // Test #6: Ripping out the application when the overflow button exists. 2057 // Test #6: Ripping out the application when the overflow button exists.
2062 // After ripping out, overflow button should be removed. 2058 // After ripping out, overflow button should be removed.
2063 int items_added = 0; 2059 int items_added = 0;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 2213
2218 ++items_added; 2214 ++items_added;
2219 ASSERT_LT(items_added, 10000); 2215 ASSERT_LT(items_added, 10000);
2220 } 2216 }
2221 2217
2222 // Now show overflow bubble. 2218 // Now show overflow bubble.
2223 test.ShowOverflowBubble(); 2219 test.ShowOverflowBubble();
2224 EXPECT_TRUE(shelf_->shelf_widget()->IsShowingOverflowBubble()); 2220 EXPECT_TRUE(shelf_->shelf_widget()->IsShowingOverflowBubble());
2225 2221
2226 // Unpin first pinned app and there should be no crash. 2222 // Unpin first pinned app and there should be no crash.
2227 controller_->UnpinAppWithID(std::string("fake_app_0")); 2223 controller_->UnpinAppWithID("fake_app_0");
2228 2224
2229 test.RunMessageLoopUntilAnimationsDone(); 2225 test.RunMessageLoopUntilAnimationsDone();
2230 EXPECT_FALSE(shelf_->shelf_widget()->IsShowingOverflowBubble()); 2226 EXPECT_FALSE(shelf_->shelf_widget()->IsShowingOverflowBubble());
2231 } 2227 }
2232 2228
2233 // Check that a windowed V1 application can navigate away from its domain, but 2229 // Check that a windowed V1 application can navigate away from its domain, but
2234 // still gets detected properly. 2230 // still gets detected properly.
2235 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, V1AppNavigation) { 2231 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, V1AppNavigation) {
2236 // We assume that the web store is always there (which it apparently is). 2232 // We assume that the web store is always there (which it apparently is).
2237 controller_->PinAppWithID(extensions::kWebStoreAppId); 2233 controller_->PinAppWithID(extensions::kWebStoreAppId);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 2406
2411 // Close all windows via the menu item. 2407 // Close all windows via the menu item.
2412 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2408 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2413 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2409 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2414 2410
2415 // Check if "Close" is removed from the context menu. 2411 // Check if "Close" is removed from the context menu.
2416 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2412 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2417 ASSERT_FALSE( 2413 ASSERT_FALSE(
2418 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2414 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2419 } 2415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698