diff options
author | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-27 05:24:28 +0000 |
---|---|---|
committer | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-27 05:24:28 +0000 |
commit | f469f14e4e41e0bd009ca32389e2b4856818692a (patch) | |
tree | 9b2aeaad3ed216c71ab5b361386354b105656b28 /ui | |
parent | fa17327c4636f5a3caffb98e26d3bbeca040084a (diff) | |
download | chromium_src-f469f14e4e41e0bd009ca32389e2b4856818692a.zip chromium_src-f469f14e4e41e0bd009ca32389e2b4856818692a.tar.gz chromium_src-f469f14e4e41e0bd009ca32389e2b4856818692a.tar.bz2 |
Add AppsGridView unit test for folder ui tests. This cl add ui tests for:
1. Drag/drop items in top level to re-order items.
2. Drag/drop items to create a folder or add items into an existing folder.
3. Test the maximum number of items user can drag/drop into a folder.
BUG=354627
TBR=xiyuan@chromium.org
Review URL: https://codereview.chromium.org/213883002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259789 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/app_list_constants.cc | 6 | ||||
-rw-r--r-- | ui/app_list/app_list_constants.h | 3 | ||||
-rw-r--r-- | ui/app_list/test/app_list_test_model.cc | 11 | ||||
-rw-r--r-- | ui/app_list/test/app_list_test_model.h | 3 | ||||
-rw-r--r-- | ui/app_list/views/apps_grid_view.cc | 7 | ||||
-rw-r--r-- | ui/app_list/views/apps_grid_view_unittest.cc | 174 |
6 files changed, 198 insertions, 6 deletions
diff --git a/ui/app_list/app_list_constants.cc b/ui/app_list/app_list_constants.cc index 6c2ec45..6dd3eb4 100644 --- a/ui/app_list/app_list_constants.cc +++ b/ui/app_list/app_list_constants.cc @@ -64,6 +64,12 @@ const int kPreferredIconDimension = 48; const int kExperimentalPreferredCols = 6; const int kExperimentalPreferredRows = 3; +// Radius of the circle, in which if entered, show re-order preview. +const int kReorderDroppingCircleRadius = 35; + +// Max items allowed in a folder. +size_t kMaxFolderItems = 16; + // Number of the top items in a folder, which are shown inside the folder icon // and animated when opening and closing a folder. const size_t kNumFolderTopItems = 4; diff --git a/ui/app_list/app_list_constants.h b/ui/app_list/app_list_constants.h index 8245017..ed6fba8 100644 --- a/ui/app_list/app_list_constants.h +++ b/ui/app_list/app_list_constants.h @@ -49,6 +49,9 @@ APP_LIST_EXPORT extern const int kPreferredIconDimension; APP_LIST_EXPORT extern const int kExperimentalPreferredCols; APP_LIST_EXPORT extern const int kExperimentalPreferredRows; +APP_LIST_EXPORT extern const int kReorderDroppingCircleRadius; + +APP_LIST_EXPORT extern size_t kMaxFolderItems; APP_LIST_EXPORT extern const size_t kNumFolderTopItems; APP_LIST_EXPORT extern const ui::ResourceBundle::FontStyle kItemTextFontStyle; diff --git a/ui/app_list/test/app_list_test_model.cc b/ui/app_list/test/app_list_test_model.cc index 7a90812..527383e 100644 --- a/ui/app_list/test/app_list_test_model.cc +++ b/ui/app_list/test/app_list_test_model.cc @@ -69,6 +69,17 @@ void AppListTestModel::PopulateApps(int n) { CreateAndAddItem(GetItemName(start_index + i)); } +void AppListTestModel::CreateAndPopulateFolderWithApps(int n) { + DCHECK_GT(n, 1); + int start_index = static_cast<int>(top_level_item_list()->item_count()); + AppListTestItem* item = CreateAndAddItem(GetItemName(start_index)); + std::string merged_item_id = item->id(); + for (int i = 1; i < n; ++i) { + AppListTestItem* new_item = CreateAndAddItem(GetItemName(start_index + i)); + merged_item_id = AppListModel::MergeItems(merged_item_id, new_item->id()); + } +} + void AppListTestModel::PopulateAppWithId(int id) { CreateAndAddItem(GetItemName(id)); } diff --git a/ui/app_list/test/app_list_test_model.h b/ui/app_list/test/app_list_test_model.h index c7ef6fa..b39236c 100644 --- a/ui/app_list/test/app_list_test_model.h +++ b/ui/app_list/test/app_list_test_model.h @@ -47,6 +47,9 @@ class AppListTestModel : public AppListModel { // Populate the model with |n| items titled "Item #". void PopulateApps(int n); + // Creates and populate a folder with |n| test apps in it. + void CreateAndPopulateFolderWithApps(int n); + // Populate the model with an item titled "Item |id|". void PopulateAppWithId(int id); diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc index da22ef0..75c6359 100644 --- a/ui/app_list/views/apps_grid_view.cc +++ b/ui/app_list/views/apps_grid_view.cc @@ -95,11 +95,6 @@ const int kFolderItemReparentDealy = 50; // UI. const int kFolderDroppingCircleRadius = 15; -// Radius of the circle, in which if entered, show re-order preview. -const int kReorderDroppingCircleRadius = 35; - -// Max items allowed in a folder. -size_t kMaxFolderItems = 16; // RowMoveAnimationDelegate is used when moving an item into a different row. // Before running the animation, the item's layer is re-created and kept in @@ -2084,7 +2079,7 @@ views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { for (int i = 0; i < view_model_.view_size(); ++i) { views::View* view = view_model_.view_at(i); - if (view->bounds() == tile_rect) + if (view->bounds() == tile_rect && view != drag_view_) return view; } return NULL; diff --git a/ui/app_list/views/apps_grid_view_unittest.cc b/ui/app_list/views/apps_grid_view_unittest.cc index a519674..7daed0d 100644 --- a/ui/app_list/views/apps_grid_view_unittest.cc +++ b/ui/app_list/views/apps_grid_view_unittest.cc @@ -14,6 +14,8 @@ #include "base/strings/utf_string_conversions.h" #include "base/timer/timer.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/app_list/app_list_constants.h" +#include "ui/app_list/app_list_folder_item.h" #include "ui/app_list/app_list_item.h" #include "ui/app_list/app_list_model.h" #include "ui/app_list/app_list_switches.h" @@ -270,6 +272,178 @@ TEST_F(AppsGridViewTest, MouseDragWithFolderDisabled) { test_api_->LayoutToIdealBounds(); } +TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { + size_t kTotalItems = 3; + model_->PopulateApps(kTotalItems); + EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); + EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent()); + + gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); + gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); + + // Dragging item_1 over item_0 creates a folder. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(kTotalItems - 1, model_->top_level_item_list()->item_count()); + EXPECT_EQ(AppListFolderItem::kItemType, + model_->top_level_item_list()->item_at(0)->GetItemType()); + AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( + model_->top_level_item_list()->item_at(0)); + EXPECT_EQ(2u, folder_item->ChildItemCount()); + AppListItem* item_0 = model_->FindItem("Item 0"); + EXPECT_TRUE(item_0->IsInFolder()); + EXPECT_EQ(folder_item->id(), item_0->folder_id()); + AppListItem* item_1 = model_->FindItem("Item 1"); + EXPECT_TRUE(item_1->IsInFolder()); + EXPECT_EQ(folder_item->id(), item_1->folder_id()); + std::string expected_items = folder_item->id() + ",Item 2"; + EXPECT_EQ(expected_items, model_->GetModelContent()); + test_api_->LayoutToIdealBounds(); + + // Dragging item_2 to the folder adds item_2 to the folder. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + + EXPECT_EQ(kTotalItems - 2, model_->top_level_item_list()->item_count()); + EXPECT_EQ(folder_item->id(), model_->GetModelContent()); + EXPECT_EQ(3u, folder_item->ChildItemCount()); + item_0 = model_->FindItem("Item 0"); + EXPECT_TRUE(item_0->IsInFolder()); + EXPECT_EQ(folder_item->id(), item_0->folder_id()); + item_1 = model_->FindItem("Item 1"); + EXPECT_TRUE(item_1->IsInFolder()); + EXPECT_EQ(folder_item->id(), item_1->folder_id()); + AppListItem* item_2 = model_->FindItem("Item 2"); + EXPECT_TRUE(item_2->IsInFolder()); + EXPECT_EQ(folder_item->id(), item_2->folder_id()); + test_api_->LayoutToIdealBounds(); +} + +TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) { + // Create and add a folder with 15 items in it. + size_t kTotalItems = kMaxFolderItems - 1; + model_->CreateAndPopulateFolderWithApps(kTotalItems); + EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(AppListFolderItem::kItemType, + model_->top_level_item_list()->item_at(0)->GetItemType()); + AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( + model_->top_level_item_list()->item_at(0)); + EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); + + // Create and add another 2 items. + model_->PopulateAppWithId(kTotalItems); + model_->PopulateAppWithId(kTotalItems + 1); + EXPECT_EQ(3u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(0)->id()); + EXPECT_EQ(model_->GetItemName(kMaxFolderItems - 1), + model_->top_level_item_list()->item_at(1)->id()); + EXPECT_EQ(model_->GetItemName(kMaxFolderItems), + model_->top_level_item_list()->item_at(2)->id()); + + gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); + gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); + + // Dragging one item into the folder, the folder should accept the item. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(0)->id()); + EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); + EXPECT_EQ(model_->GetItemName(kMaxFolderItems), + model_->top_level_item_list()->item_at(1)->id()); + test_api_->LayoutToIdealBounds(); + + // Dragging the last item over the folder, the folder won't accept the new + // item, instead, it will re-order the items. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(model_->GetItemName(kMaxFolderItems), + model_->top_level_item_list()->item_at(0)->id()); + EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id()); + EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); + test_api_->LayoutToIdealBounds(); +} + +TEST_F(AppsGridViewTest, MouseDragItemReorder) { + size_t kTotalItems = 2; + model_->PopulateApps(kTotalItems); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent()); + + gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); + int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - + GetItemTileRectAt(0, 0).CenterPoint()).Length() - + kReorderDroppingCircleRadius - + kPreferredIconDimension / 2 + 5; + gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); + + // Dragging item_1 closing to item_0 should leads to re-ordering these two + // items. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent()); + test_api_->LayoutToIdealBounds(); +} + +TEST_F(AppsGridViewTest, MouseDragFolderReorder) { + size_t kTotalItems = 2; + model_->CreateAndPopulateFolderWithApps(kTotalItems); + model_->PopulateAppWithId(kTotalItems); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ(AppListFolderItem::kItemType, + model_->top_level_item_list()->item_at(0)->GetItemType()); + AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( + model_->top_level_item_list()->item_at(0)); + EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id()); + + gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); + gfx::Point to = GetItemTileRectAt(0, 1).CenterPoint(); + + // Dragging folder over item_1 should leads to re-ordering these two + // items. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); + EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(0)->id()); + EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id()); + test_api_->LayoutToIdealBounds(); +} + +TEST_F(AppsGridViewTest, MouseDragWithCancelDeleteAddItem) { + size_t kTotalItems = 4; + model_->PopulateApps(kTotalItems); + EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); + EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), + model_->GetModelContent()); + + gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); + gfx::Point to = GetItemTileRectAt(0, 1).CenterPoint(); + + // Canceling drag should keep existing order. + SimulateDrag(AppsGridView::MOUSE, from, to); + apps_grid_view_->EndDrag(true); + EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), + model_->GetModelContent()); + test_api_->LayoutToIdealBounds(); + + // Deleting an item keeps remaining intact. + SimulateDrag(AppsGridView::MOUSE, from, to); + model_->DeleteItem(model_->GetItemName(2)); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(std::string("Item 0,Item 1,Item 3"), model_->GetModelContent()); + test_api_->LayoutToIdealBounds(); + + // Adding a launcher item cancels the drag and respects the order. + SimulateDrag(AppsGridView::MOUSE, from, to); + model_->CreateAndAddItem("Extra"); + apps_grid_view_->EndDrag(false); + EXPECT_EQ(std::string("Item 0,Item 1,Item 3,Extra"), + model_->GetModelContent()); + test_api_->LayoutToIdealBounds(); +} + TEST_F(AppsGridViewTest, MouseDragFlipPage) { test_api_->SetPageFlipDelay(10); pagination_model_->SetTransitionDurations(10, 10); |