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

Side by Side Diff: ui/app_list/cocoa/apps_grid_controller_unittest.mm

Issue 148403007: Protect AppListItemList Add/Remove and fix sync bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 | Annotate | Revision Log
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 "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 #include "base/mac/scoped_nsobject.h" 6 #include "base/mac/scoped_nsobject.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "skia/ext/skia_utils_mac.h" 8 #include "skia/ext/skia_utils_mac.h"
9 #import "testing/gtest_mac.h" 9 #import "testing/gtest_mac.h"
10 #include "ui/app_list/app_list_constants.h" 10 #include "ui/app_list/app_list_constants.h"
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 model()->CreateAndAddItem("Item 2"); 479 model()->CreateAndAddItem("Item 2");
480 ASSERT_EQ(3u, item_list->item_count()); 480 ASSERT_EQ(3u, item_list->item_count());
481 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); 481 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]);
482 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); 482 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent());
483 483
484 // Test adding an item whose position is in the middle. 484 // Test adding an item whose position is in the middle.
485 app_list::AppListItem* item0 = item_list->item_at(0); 485 app_list::AppListItem* item0 = item_list->item_at(0);
486 app_list::AppListItem* item1 = item_list->item_at(1); 486 app_list::AppListItem* item1 = item_list->item_at(1);
487 app_list::AppListItem* item3 = 487 app_list::AppListItem* item3 =
488 model()->CreateItem("Item Three", "Item Three"); 488 model()->CreateItem("Item Three", "Item Three");
489 item_list->AddItem(item3); 489 model()->AddItem(item3);
490 item_list->SetItemPosition( 490 item_list->SetItemPosition(
491 item3, item0->position().CreateBetween(item1->position())); 491 item3, item0->position().CreateBetween(item1->position()));
492 EXPECT_EQ(4u, [apps_grid_controller_ itemCount]); 492 EXPECT_EQ(4u, [apps_grid_controller_ itemCount]);
493 EXPECT_EQ(std::string("|Item 0,Item Three,Item 1,Item 2|"), GetViewContent()); 493 EXPECT_EQ(std::string("|Item 0,Item Three,Item 1,Item 2|"), GetViewContent());
494 } 494 }
495 495
496 TEST_F(AppsGridControllerTest, ModelMove) { 496 TEST_F(AppsGridControllerTest, ModelMove) {
497 model()->PopulateApps(3); 497 model()->PopulateApps(3);
498 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); 498 EXPECT_EQ(3u, [[GetPageAt(0) content] count]);
499 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); 499 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent());
500 500
501 // Test swapping items (e.g. rearranging via sync). 501 // Test swapping items (e.g. rearranging via sync).
502 model()->item_list()->MoveItem(1, 2); 502 model()->item_list()->MoveItem(1, 2);
503 EXPECT_EQ(std::string("|Item 0,Item 2,Item 1|"), GetViewContent()); 503 EXPECT_EQ(std::string("|Item 0,Item 2,Item 1|"), GetViewContent());
504 } 504 }
505 505
506 TEST_F(AppsGridControllerTest, ModelRemove) { 506 TEST_F(AppsGridControllerTest, ModelRemove) {
507 model()->PopulateApps(3); 507 model()->PopulateApps(3);
508 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); 508 EXPECT_EQ(3u, [[GetPageAt(0) content] count]);
509 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); 509 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent());
510 510
511 // Test removing an item at the end. 511 // Test removing an item at the end.
512 model()->item_list()->DeleteItem("Item 2"); 512 model()->DeleteItem("Item 2");
513 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); 513 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]);
514 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent()); 514 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent());
515 515
516 // Test removing in the middle. 516 // Test removing in the middle.
517 model()->CreateAndAddItem("Item 2"); 517 model()->CreateAndAddItem("Item 2");
518 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); 518 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]);
519 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); 519 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent());
520 model()->item_list()->DeleteItem("Item 1"); 520 model()->DeleteItem("Item 1");
521 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); 521 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]);
522 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent()); 522 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent());
523 } 523 }
524 524
525 TEST_F(AppsGridControllerTest, ModelRemoveAlll) { 525 TEST_F(AppsGridControllerTest, ModelRemoveSeveral) {
tapted 2014/01/28 23:33:54 Just a note, this test case initially existed to e
526 model()->PopulateApps(3); 526 model()->PopulateApps(3);
527 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); 527 EXPECT_EQ(3u, [[GetPageAt(0) content] count]);
528 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); 528 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent());
529 529
530 // Test removing multiple items via the model. 530 // Test removing multiple items via the model.
531 model()->item_list()->DeleteItemsByType(NULL /* all items */); 531 model()->DeleteItem("Item 0");
532 model()->DeleteItem("Item 1");
533 model()->DeleteItem("Item 2");
532 EXPECT_EQ(0u, [apps_grid_controller_ itemCount]); 534 EXPECT_EQ(0u, [apps_grid_controller_ itemCount]);
533 EXPECT_EQ(std::string("||"), GetViewContent()); 535 EXPECT_EQ(std::string("||"), GetViewContent());
534 } 536 }
535 537
536 TEST_F(AppsGridControllerTest, ModelRemovePage) { 538 TEST_F(AppsGridControllerTest, ModelRemovePage) {
537 app_list::AppListItemList* item_list = model()->item_list(); 539 app_list::AppListItemList* item_list = model()->item_list();
538 540
539 model()->PopulateApps(kItemsPerPage + 1); 541 model()->PopulateApps(kItemsPerPage + 1);
540 ASSERT_EQ(kItemsPerPage + 1, item_list->item_count()); 542 ASSERT_EQ(kItemsPerPage + 1, item_list->item_count());
541 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ itemCount]); 543 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ itemCount]);
542 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); 544 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]);
543 545
544 // Test removing the last item when there is one item on the second page. 546 // Test removing the last item when there is one item on the second page.
545 app_list::AppListItem* last_item = item_list->item_at(kItemsPerPage); 547 app_list::AppListItem* last_item = item_list->item_at(kItemsPerPage);
546 item_list->DeleteItem(last_item->id()); 548 model()->DeleteItem(last_item->id());
547 EXPECT_EQ(kItemsPerPage, item_list->item_count()); 549 EXPECT_EQ(kItemsPerPage, item_list->item_count());
548 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ itemCount]); 550 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ itemCount]);
549 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); 551 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]);
550 } 552 }
551 553
552 // Test install progress bars, and install flow with item highlighting. 554 // Test install progress bars, and install flow with item highlighting.
553 TEST_F(AppsGridControllerTest, ItemInstallProgress) { 555 TEST_F(AppsGridControllerTest, ItemInstallProgress) {
554 ReplaceTestModel(kItemsPerPage + 1); 556 ReplaceTestModel(kItemsPerPage + 1);
555 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); 557 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]);
556 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); 558 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]); 957 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]);
956 [drag_manager onMouseUp:at_center]; 958 [drag_manager onMouseUp:at_center];
957 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]); 959 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]);
958 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]); 960 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]);
959 961
960 [apps_grid_controller_ setPaginationObserver:nil]; 962 [apps_grid_controller_ setPaginationObserver:nil];
961 } 963 }
962 964
963 TEST_F(AppsGridControllerTest, ContextMenus) { 965 TEST_F(AppsGridControllerTest, ContextMenus) {
964 AppListItemWithMenu* item_two_model = new AppListItemWithMenu("Item Two"); 966 AppListItemWithMenu* item_two_model = new AppListItemWithMenu("Item Two");
965 model()->item_list()->AddItem(new AppListItemWithMenu("Item One")); 967 model()->AddItem(new AppListItemWithMenu("Item One"));
966 model()->item_list()->AddItem(item_two_model); 968 model()->AddItem(item_two_model);
967 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); 969 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]);
968 970
969 NSCollectionView* page = [apps_grid_controller_ collectionViewAtPageIndex:0]; 971 NSCollectionView* page = [apps_grid_controller_ collectionViewAtPageIndex:0];
970 NSEvent* mouse_at_cell_0 = MouseEventInCell(page, 0); 972 NSEvent* mouse_at_cell_0 = MouseEventInCell(page, 0);
971 NSEvent* mouse_at_cell_1 = MouseEventInCell(page, 1); 973 NSEvent* mouse_at_cell_1 = MouseEventInCell(page, 1);
972 974
973 NSMenu* menu = [page menuForEvent:mouse_at_cell_0]; 975 NSMenu* menu = [page menuForEvent:mouse_at_cell_0];
974 EXPECT_EQ(1, [menu numberOfItems]); 976 EXPECT_EQ(1, [menu numberOfItems]);
975 EXPECT_NSEQ(@"Menu For: Item One", [[menu itemAtIndex:0] title]); 977 EXPECT_NSEQ(@"Menu For: Item One", [[menu itemAtIndex:0] title]);
976 978
(...skipping 10 matching lines...) Expand all
987 // Test that a button being held down with the left button does not also show 989 // Test that a button being held down with the left button does not also show
988 // a context menu. 990 // a context menu.
989 [GetItemViewAt(0) highlight:YES]; 991 [GetItemViewAt(0) highlight:YES];
990 EXPECT_FALSE([page menuForEvent:mouse_at_cell_0]); 992 EXPECT_FALSE([page menuForEvent:mouse_at_cell_0]);
991 [GetItemViewAt(0) highlight:NO]; 993 [GetItemViewAt(0) highlight:NO];
992 EXPECT_TRUE([page menuForEvent:mouse_at_cell_0]); 994 EXPECT_TRUE([page menuForEvent:mouse_at_cell_0]);
993 } 995 }
994 996
995 } // namespace test 997 } // namespace test
996 } // namespace app_list 998 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698