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.
+ // item.
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();
}
// This test assumes Folders are enabled.
EnsureFoldersEnabled();
- 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());
+ model_->PopulateApps(4);
+ EXPECT_EQ(4u, model_->top_level_item_list()->item_count());
+ EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
+ model_->GetModelContent());
- gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
- int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() -
- GetItemTileRectAt(0, 0).CenterPoint()).Length() -
- kReorderDroppingCircleRadius - kGridIconDimension / 2 +
- 5;
- gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y());
+ // Dragging an item towards its neighbours should not reorder until the drag
+ // is past the folder drop point.
+ gfx::Point top_right = GetItemTileRectAt(0, 1).CenterPoint();
+ gfx::Vector2d drag_vector;
+ int half_tile_width =
+ (GetItemTileRectAt(0, 1).x() - GetItemTileRectAt(0, 0).x()) / 2;
+ int tile_height = GetItemTileRectAt(1, 0).y() - GetItemTileRectAt(0, 0).y();
+
+ // Drag left but stop before the folder dropping circle.
+ drag_vector.set_x(-half_tile_width - 5);
+ SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
+ apps_grid_view_->EndDrag(false);
+ EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
+ model_->GetModelContent());
- // Dragging item_1 closing to item_0 should leads to re-ordering these two
- // items.
- SimulateDrag(AppsGridView::MOUSE, from, to);
+ // Drag left, past the folder dropping circle.
+ drag_vector.set_x(-3 * half_tile_width + 5);
+ SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
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();
+ EXPECT_EQ(std::string("Item 1,Item 0,Item 2,Item 3"),
+ model_->GetModelContent());
+
+ // Drag down, between apps 2 and 3. The gap should open up, making space for
+ // app 0 in the bottom left.
+ drag_vector.set_x(-half_tile_width);
+ drag_vector.set_y(tile_height);
+ SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
+ apps_grid_view_->EndDrag(false);
+ EXPECT_EQ(std::string("Item 1,Item 2,Item 0,Item 3"),
+ model_->GetModelContent());
+
+ // Drag up, between apps 1 and 2. The gap should open up, making space for app
+ // 0 in the top right.
+ gfx::Point bottom_left = GetItemTileRectAt(1, 0).CenterPoint();
+ drag_vector.set_x(half_tile_width);
+ drag_vector.set_y(-tile_height);
+ SimulateDrag(AppsGridView::MOUSE, bottom_left, bottom_left + drag_vector);
+ apps_grid_view_->EndDrag(false);
+ EXPECT_EQ(std::string("Item 1,Item 0,Item 2,Item 3"),
+ model_->GetModelContent());
+
+ // Dragging down past the last app should reorder to the last position.
+ drag_vector.set_x(half_tile_width);
+ drag_vector.set_y(2 * tile_height);
+ SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
+ apps_grid_view_->EndDrag(false);
+ EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Item 0"),
+ model_->GetModelContent());
}
TEST_F(AppsGridViewTest, MouseDragFolderReorder) {