| 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 "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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 422 } |
| 423 | 423 |
| 424 // Test runtime updates: adding items, removing items, and moving items (e.g. in | 424 // Test runtime updates: adding items, removing items, and moving items (e.g. in |
| 425 // response to app install, uninstall, and chrome sync changes. Also test | 425 // response to app install, uninstall, and chrome sync changes. Also test |
| 426 // changing titles and icons. | 426 // changing titles and icons. |
| 427 TEST_F(AppsGridControllerTest, ModelUpdates) { | 427 TEST_F(AppsGridControllerTest, ModelUpdates) { |
| 428 model()->PopulateApps(2); | 428 model()->PopulateApps(2); |
| 429 EXPECT_EQ(2u, [[GetPageAt(0) content] count]); | 429 EXPECT_EQ(2u, [[GetPageAt(0) content] count]); |
| 430 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent()); | 430 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent()); |
| 431 | 431 |
| 432 // Add an item (PopulateApps will create a duplicate "Item 0"). | 432 // Add an item (PopulateApps will create a new "Item 2"). |
| 433 model()->PopulateApps(1); | 433 model()->PopulateApps(1); |
| 434 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); | 434 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); |
| 435 NSButton* button = GetItemViewAt(2); | 435 NSButton* button = GetItemViewAt(2); |
| 436 EXPECT_NSEQ(@"Item 0", [button title]); | 436 EXPECT_NSEQ(@"Item 2", [button title]); |
| 437 EXPECT_EQ(std::string("|Item 0,Item 1,Item 0|"), GetViewContent()); | 437 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); |
| 438 | 438 |
| 439 // Update the title via the ItemModelObserver. | 439 // Update the title via the ItemModelObserver. |
| 440 app_list::AppListItemModel* item_model = model()->apps()->GetItemAt(2); | 440 app_list::AppListItemModel* item_model = model()->GetItemAt(0, 2); |
| 441 item_model->SetTitleAndFullName("UpdatedItem", "UpdatedItem"); | 441 item_model->SetTitleAndFullName("UpdatedItem", "UpdatedItem"); |
| 442 EXPECT_NSEQ(@"UpdatedItem", [button title]); | 442 EXPECT_NSEQ(@"UpdatedItem", [button title]); |
| 443 EXPECT_EQ(std::string("|Item 0,Item 1,UpdatedItem|"), GetViewContent()); | 443 EXPECT_EQ(std::string("|Item 0,Item 1,UpdatedItem|"), GetViewContent()); |
| 444 | 444 |
| 445 // Test icon updates through the model observer by ensuring the icon changes. | 445 // Test icon updates through the model observer by ensuring the icon changes. |
| 446 NSSize icon_size = [[button image] size]; | 446 NSSize icon_size = [[button image] size]; |
| 447 EXPECT_EQ(0, icon_size.width); | 447 EXPECT_EQ(0, icon_size.width); |
| 448 EXPECT_EQ(0, icon_size.height); | 448 EXPECT_EQ(0, icon_size.height); |
| 449 | 449 |
| 450 SkBitmap bitmap; | 450 SkBitmap bitmap; |
| 451 const int kTestImageSize = 10; | 451 const int kTestImageSize = 10; |
| 452 const int kTargetImageSize = 48; | 452 const int kTargetImageSize = 48; |
| 453 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kTestImageSize, kTestImageSize); | 453 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kTestImageSize, kTestImageSize); |
| 454 item_model->SetIcon(gfx::ImageSkia::CreateFrom1xBitmap(bitmap), false); | 454 item_model->SetIcon(gfx::ImageSkia::CreateFrom1xBitmap(bitmap), false); |
| 455 icon_size = [[button image] size]; | 455 icon_size = [[button image] size]; |
| 456 // Icon should always be resized to 48x48. | 456 // Icon should always be resized to 48x48. |
| 457 EXPECT_EQ(kTargetImageSize, icon_size.width); | 457 EXPECT_EQ(kTargetImageSize, icon_size.width); |
| 458 EXPECT_EQ(kTargetImageSize, icon_size.height); | 458 EXPECT_EQ(kTargetImageSize, icon_size.height); |
| 459 | 459 |
| 460 // Test removing an item at the end. | 460 // Test removing an item at the end. |
| 461 model()->apps()->DeleteAt(2); | 461 model()->DeleteItemAt(0, 2); |
| 462 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); | 462 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); |
| 463 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent()); | 463 EXPECT_EQ(std::string("|Item 0,Item 1|"), GetViewContent()); |
| 464 | 464 |
| 465 // Test removing in the middle. | 465 // Test removing in the middle. |
| 466 model()->AddItem("Item 2"); | 466 model()->CreateAndAddItem("Item 2"); |
| 467 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); | 467 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); |
| 468 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); | 468 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); |
| 469 model()->apps()->DeleteAt(1); | 469 model()->DeleteItemAt(0, 1); |
| 470 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); | 470 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); |
| 471 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent()); | 471 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent()); |
| 472 | 472 |
| 473 // Test inserting in the middle. | 473 // Test adding an item at the end. |
| 474 model()->apps()->AddAt(1, model()->CreateItem("Item One", "Item One")); | 474 model()->CreateAndAddItem("Item Three"); |
| 475 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); | 475 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); |
| 476 EXPECT_EQ(std::string("|Item 0,Item One,Item 2|"), GetViewContent()); | 476 EXPECT_EQ(std::string("|Item 0,Item 2,Item Three|"), GetViewContent()); |
| 477 | 477 |
| 478 // Test swapping items (e.g. rearranging via sync). | 478 // Test swapping items (e.g. rearranging via sync). |
| 479 model()->apps()->Move(1, 2); | 479 model()->MoveItem(0, 1, 0, 2); |
| 480 EXPECT_EQ(std::string("|Item 0,Item 2,Item One|"), GetViewContent()); | 480 EXPECT_EQ(std::string("|Item 0,Item Three,Item 2|"), GetViewContent()); |
| 481 | |
| 482 // Test removing multiple items via the model. | |
| 483 model()->apps()->DeleteAll(); | |
| 484 EXPECT_EQ(0u, [apps_grid_controller_ itemCount]); | |
| 485 EXPECT_EQ(std::string("||"), GetViewContent()); | |
| 486 | 481 |
| 487 // Test removing the last item when there is one item on the second page. | 482 // Test removing the last item when there is one item on the second page. |
| 488 ReplaceTestModel(kItemsPerPage + 1); | 483 ReplaceTestModel(kItemsPerPage + 1); |
| 489 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ itemCount]); | 484 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ itemCount]); |
| 490 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); | 485 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); |
| 491 model()->apps()->DeleteAt(kItemsPerPage); | 486 model()->DeleteItemAt(1, 0); |
| 492 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ itemCount]); | 487 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ itemCount]); |
| 493 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); | 488 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); |
| 494 } | 489 } |
| 495 | 490 |
| 496 // Test install progress bars, and install flow with item highlighting. | 491 // Test install progress bars, and install flow with item highlighting. |
| 497 TEST_F(AppsGridControllerTest, ItemInstallProgress) { | 492 TEST_F(AppsGridControllerTest, ItemInstallProgress) { |
| 498 ReplaceTestModel(kItemsPerPage + 1); | 493 ReplaceTestModel(kItemsPerPage + 1); |
| 499 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); | 494 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); |
| 500 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 495 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
| 501 app_list::AppListItemModel* item_model = | 496 app_list::AppListItemModel* item_model = model()->GetItemAt(1, 0); |
| 502 model()->apps()->GetItemAt(kItemsPerPage); | |
| 503 | 497 |
| 504 // Highlighting an item should activate the page it is on. | 498 // Highlighting an item should activate the page it is on. |
| 505 item_model->SetHighlighted(true); | 499 item_model->SetHighlighted(true); |
| 506 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | 500 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); |
| 507 | 501 |
| 508 // Clearing a highlight stays on the current page. | 502 // Clearing a highlight stays on the current page. |
| 509 [apps_grid_controller_ scrollToPage:0]; | 503 [apps_grid_controller_ scrollToPage:0]; |
| 510 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 504 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
| 511 item_model->SetHighlighted(false); | 505 item_model->SetHighlighted(false); |
| 512 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 506 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 528 EXPECT_FALSE([progressIndicator isIndeterminate]); | 522 EXPECT_FALSE([progressIndicator isIndeterminate]); |
| 529 EXPECT_EQ(0.0, [progressIndicator doubleValue]); | 523 EXPECT_EQ(0.0, [progressIndicator doubleValue]); |
| 530 | 524 |
| 531 // Updating the progress in the model should update the progress bar. | 525 // Updating the progress in the model should update the progress bar. |
| 532 item_model->SetPercentDownloaded(50); | 526 item_model->SetPercentDownloaded(50); |
| 533 EXPECT_EQ(50.0, [progressIndicator doubleValue]); | 527 EXPECT_EQ(50.0, [progressIndicator doubleValue]); |
| 534 | 528 |
| 535 // Two things can be installing simultaneously. When one starts or completes | 529 // Two things can be installing simultaneously. When one starts or completes |
| 536 // the model builder will ask for the item to be highlighted. | 530 // the model builder will ask for the item to be highlighted. |
| 537 app_list::AppListItemModel* alternate_item_model = | 531 app_list::AppListItemModel* alternate_item_model = |
| 538 model()->apps()->GetItemAt(0); | 532 model()->GetItemAt(0, 0); |
| 539 item_model->SetHighlighted(false); | 533 item_model->SetHighlighted(false); |
| 540 alternate_item_model->SetHighlighted(true); | 534 alternate_item_model->SetHighlighted(true); |
| 541 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 535 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
| 542 | 536 |
| 543 // Update the first item (page doesn't change on updates). | 537 // Update the first item (page doesn't change on updates). |
| 544 item_model->SetPercentDownloaded(100); | 538 item_model->SetPercentDownloaded(100); |
| 545 EXPECT_EQ(100.0, [progressIndicator doubleValue]); | 539 EXPECT_EQ(100.0, [progressIndicator doubleValue]); |
| 546 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 540 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
| 547 | 541 |
| 548 // A percent of -1 indicates the download is complete and the unpack/install | 542 // A percent of -1 indicates the download is complete and the unpack/install |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 model()->PopulateApps(kItemsPerPage); | 589 model()->PopulateApps(kItemsPerPage); |
| 596 EXPECT_EQ(0, [observer totalPagesChangedCount]); | 590 EXPECT_EQ(0, [observer totalPagesChangedCount]); |
| 597 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); | 591 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); |
| 598 model()->PopulateApps(1); | 592 model()->PopulateApps(1); |
| 599 EXPECT_EQ(1, [observer totalPagesChangedCount]); | 593 EXPECT_EQ(1, [observer totalPagesChangedCount]); |
| 600 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); | 594 EXPECT_EQ(2u, [apps_grid_controller_ pageCount]); |
| 601 ReplaceTestModel(0); | 595 ReplaceTestModel(0); |
| 602 EXPECT_EQ(2, [observer totalPagesChangedCount]); | 596 EXPECT_EQ(2, [observer totalPagesChangedCount]); |
| 603 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); | 597 EXPECT_EQ(1u, [apps_grid_controller_ pageCount]); |
| 604 ReplaceTestModel(kItemsPerPage * 3 + 1); | 598 ReplaceTestModel(kItemsPerPage * 3 + 1); |
| 605 EXPECT_EQ(3, [observer totalPagesChangedCount]); | 599 // 4 pages = 3 additional page changes |
| 600 EXPECT_EQ(5, [observer totalPagesChangedCount]); |
| 606 EXPECT_EQ(4u, [apps_grid_controller_ pageCount]); | 601 EXPECT_EQ(4u, [apps_grid_controller_ pageCount]); |
| 607 | 602 |
| 608 EXPECT_FALSE([observer readVisibilityDidChange]); | 603 EXPECT_FALSE([observer readVisibilityDidChange]); |
| 609 EXPECT_EQ(0, [observer selectedPageChangedCount]); | 604 EXPECT_EQ(0, [observer selectedPageChangedCount]); |
| 610 | 605 |
| 611 [apps_grid_controller_ setPaginationObserver:nil]; | 606 [apps_grid_controller_ setPaginationObserver:nil]; |
| 612 } | 607 } |
| 613 | 608 |
| 614 // Test AppsGridPaginationObserver selectedPageChanged(). | 609 // Test AppsGridPaginationObserver selectedPageChanged(). |
| 615 TEST_F(AppsGridControllerTest, PaginationObserverSelectedPageChanged) { | 610 TEST_F(AppsGridControllerTest, PaginationObserverSelectedPageChanged) { |
| 616 base::scoped_nsobject<TestPaginationObserver> observer( | 611 base::scoped_nsobject<TestPaginationObserver> observer( |
| 617 [[TestPaginationObserver alloc] init]); | 612 [[TestPaginationObserver alloc] init]); |
| 618 [apps_grid_controller_ setPaginationObserver:observer]; | 613 [apps_grid_controller_ setPaginationObserver:observer]; |
| 619 EXPECT_EQ(0, [[NSAnimationContext currentContext] duration]); | 614 EXPECT_EQ(0, [[NSAnimationContext currentContext] duration]); |
| 620 | 615 |
| 621 ReplaceTestModel(kItemsPerPage * 3 + 1); | 616 ReplaceTestModel(kItemsPerPage * 3 + 1); |
| 622 EXPECT_EQ(1, [observer totalPagesChangedCount]); | 617 // 4 pages = 3 page changes |
| 618 EXPECT_EQ(3, [observer totalPagesChangedCount]); |
| 623 EXPECT_EQ(4u, [apps_grid_controller_ pageCount]); | 619 EXPECT_EQ(4u, [apps_grid_controller_ pageCount]); |
| 624 | 620 |
| 625 EXPECT_FALSE([observer readVisibilityDidChange]); | 621 EXPECT_FALSE([observer readVisibilityDidChange]); |
| 626 EXPECT_EQ(0, [observer selectedPageChangedCount]); | 622 EXPECT_EQ(0, [observer selectedPageChangedCount]); |
| 627 | 623 |
| 628 [apps_grid_controller_ scrollToPage:1]; | 624 [apps_grid_controller_ scrollToPage:1]; |
| 629 EXPECT_EQ(1, [observer selectedPageChangedCount]); | 625 EXPECT_EQ(1, [observer selectedPageChangedCount]); |
| 630 EXPECT_EQ(1, [observer lastNewSelectedPage]); | 626 EXPECT_EQ(1, [observer lastNewSelectedPage]); |
| 631 EXPECT_TRUE([observer readVisibilityDidChange]); | 627 EXPECT_TRUE([observer readVisibilityDidChange]); |
| 632 EXPECT_FALSE([observer readVisibilityDidChange]); // Testing test behaviour. | 628 EXPECT_FALSE([observer readVisibilityDidChange]); // Testing test behaviour. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]); | 895 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]); |
| 900 [drag_manager onMouseUp:at_center]; | 896 [drag_manager onMouseUp:at_center]; |
| 901 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]); | 897 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]); |
| 902 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]); | 898 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]); |
| 903 | 899 |
| 904 [apps_grid_controller_ setPaginationObserver:nil]; | 900 [apps_grid_controller_ setPaginationObserver:nil]; |
| 905 } | 901 } |
| 906 | 902 |
| 907 TEST_F(AppsGridControllerTest, ContextMenus) { | 903 TEST_F(AppsGridControllerTest, ContextMenus) { |
| 908 AppListItemWithMenu* item_two_model = new AppListItemWithMenu("Item Two"); | 904 AppListItemWithMenu* item_two_model = new AppListItemWithMenu("Item Two"); |
| 909 model()->apps()->AddAt(0, new AppListItemWithMenu("Item One")); | 905 model()->AddItem(new AppListItemWithMenu("Item One")); |
| 910 model()->apps()->AddAt(1, item_two_model); | 906 model()->AddItem(item_two_model); |
| 911 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); | 907 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); |
| 912 | 908 |
| 913 NSCollectionView* page = [apps_grid_controller_ collectionViewAtPageIndex:0]; | 909 NSCollectionView* page = [apps_grid_controller_ collectionViewAtPageIndex:0]; |
| 914 NSEvent* mouse_at_cell_0 = MouseEventInCell(page, 0); | 910 NSEvent* mouse_at_cell_0 = MouseEventInCell(page, 0); |
| 915 NSEvent* mouse_at_cell_1 = MouseEventInCell(page, 1); | 911 NSEvent* mouse_at_cell_1 = MouseEventInCell(page, 1); |
| 916 | 912 |
| 917 NSMenu* menu = [page menuForEvent:mouse_at_cell_0]; | 913 NSMenu* menu = [page menuForEvent:mouse_at_cell_0]; |
| 918 EXPECT_EQ(1, [menu numberOfItems]); | 914 EXPECT_EQ(1, [menu numberOfItems]); |
| 919 EXPECT_NSEQ(@"Menu For: Item One", [[menu itemAtIndex:0] title]); | 915 EXPECT_NSEQ(@"Menu For: Item One", [[menu itemAtIndex:0] title]); |
| 920 | 916 |
| 921 // Test a context menu request while the item is still installing. | 917 // Test a context menu request while the item is still installing. |
| 922 item_two_model->SetMenuReadyForTesting(false); | 918 item_two_model->SetMenuReadyForTesting(false); |
| 923 menu = [page menuForEvent:mouse_at_cell_1]; | 919 menu = [page menuForEvent:mouse_at_cell_1]; |
| 924 EXPECT_EQ(nil, menu); | 920 EXPECT_EQ(nil, menu); |
| 925 | 921 |
| 926 item_two_model->SetMenuReadyForTesting(true); | 922 item_two_model->SetMenuReadyForTesting(true); |
| 927 menu = [page menuForEvent:mouse_at_cell_1]; | 923 menu = [page menuForEvent:mouse_at_cell_1]; |
| 928 EXPECT_EQ(1, [menu numberOfItems]); | 924 EXPECT_EQ(1, [menu numberOfItems]); |
| 929 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); | 925 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); |
| 930 } | 926 } |
| 931 | 927 |
| 932 } // namespace test | 928 } // namespace test |
| 933 } // namespace app_list | 929 } // namespace app_list |
| OLD | NEW |