| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/app_list/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 apps_grid_view_->EndDrag(false); | 413 apps_grid_view_->EndDrag(false); |
| 414 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 414 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
| 415 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); | 415 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); |
| 416 test_api_->LayoutToIdealBounds(); | 416 test_api_->LayoutToIdealBounds(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 TEST_F(AppsGridViewTest, MouseDragItemReorder) { | 419 TEST_F(AppsGridViewTest, MouseDragItemReorder) { |
| 420 // This test assumes Folders are enabled. | 420 // This test assumes Folders are enabled. |
| 421 EnsureFoldersEnabled(); | 421 EnsureFoldersEnabled(); |
| 422 | 422 |
| 423 size_t kTotalItems = 2; | 423 model_->PopulateApps(4); |
| 424 model_->PopulateApps(kTotalItems); | 424 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); |
| 425 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 425 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
| 426 EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent()); | 426 model_->GetModelContent()); |
| 427 | 427 |
| 428 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); | 428 // Dragging an item towards its neighbours should not reorder until the drag |
| 429 int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - | 429 // is past the folder drop point. |
| 430 GetItemTileRectAt(0, 0).CenterPoint()).Length() - | 430 gfx::Point top_right = GetItemTileRectAt(0, 1).CenterPoint(); |
| 431 kReorderDroppingCircleRadius - kGridIconDimension / 2 + | 431 gfx::Vector2d drag_vector; |
| 432 5; | 432 int half_tile_width = |
| 433 gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); | 433 (GetItemTileRectAt(0, 1).x() - GetItemTileRectAt(0, 0).x()) / 2; |
| 434 int tile_height = GetItemTileRectAt(1, 0).y() - GetItemTileRectAt(0, 0).y(); |
| 434 | 435 |
| 435 // Dragging item_1 closing to item_0 should leads to re-ordering these two | 436 // Drag left but stop before the folder dropping circle. |
| 436 // items. | 437 drag_vector.set_x(-half_tile_width - 5); |
| 437 SimulateDrag(AppsGridView::MOUSE, from, to); | 438 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector); |
| 438 apps_grid_view_->EndDrag(false); | 439 apps_grid_view_->EndDrag(false); |
| 439 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 440 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
| 440 EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent()); | 441 model_->GetModelContent()); |
| 441 test_api_->LayoutToIdealBounds(); | 442 |
| 443 // Drag left, past the folder dropping circle. |
| 444 drag_vector.set_x(-3 * half_tile_width + 5); |
| 445 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector); |
| 446 apps_grid_view_->EndDrag(false); |
| 447 EXPECT_EQ(std::string("Item 1,Item 0,Item 2,Item 3"), |
| 448 model_->GetModelContent()); |
| 449 |
| 450 // Drag down, between apps 2 and 3. The gap should open up, making space for |
| 451 // app 0 in the bottom left. |
| 452 drag_vector.set_x(-half_tile_width); |
| 453 drag_vector.set_y(tile_height); |
| 454 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector); |
| 455 apps_grid_view_->EndDrag(false); |
| 456 EXPECT_EQ(std::string("Item 1,Item 2,Item 0,Item 3"), |
| 457 model_->GetModelContent()); |
| 458 |
| 459 // Drag up, between apps 1 and 2. The gap should open up, making space for app |
| 460 // 0 in the top right. |
| 461 gfx::Point bottom_left = GetItemTileRectAt(1, 0).CenterPoint(); |
| 462 drag_vector.set_x(half_tile_width); |
| 463 drag_vector.set_y(-tile_height); |
| 464 SimulateDrag(AppsGridView::MOUSE, bottom_left, bottom_left + drag_vector); |
| 465 apps_grid_view_->EndDrag(false); |
| 466 EXPECT_EQ(std::string("Item 1,Item 0,Item 2,Item 3"), |
| 467 model_->GetModelContent()); |
| 468 |
| 469 // Dragging down past the last app should reorder to the last position. |
| 470 drag_vector.set_x(half_tile_width); |
| 471 drag_vector.set_y(2 * tile_height); |
| 472 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector); |
| 473 apps_grid_view_->EndDrag(false); |
| 474 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Item 0"), |
| 475 model_->GetModelContent()); |
| 442 } | 476 } |
| 443 | 477 |
| 444 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { | 478 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { |
| 445 EnsureFoldersEnabled(); | 479 EnsureFoldersEnabled(); |
| 446 | 480 |
| 447 size_t kTotalItems = 2; | 481 size_t kTotalItems = 2; |
| 448 model_->CreateAndPopulateFolderWithApps(kTotalItems); | 482 model_->CreateAndPopulateFolderWithApps(kTotalItems); |
| 449 model_->PopulateAppWithId(kTotalItems); | 483 model_->PopulateAppWithId(kTotalItems); |
| 450 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 484 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
| 451 EXPECT_EQ(AppListFolderItem::kItemType, | 485 EXPECT_EQ(AppListFolderItem::kItemType, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 AppListItemView* item_view = GetItemViewAt(0); | 740 AppListItemView* item_view = GetItemViewAt(0); |
| 707 ASSERT_TRUE(item_view); | 741 ASSERT_TRUE(item_view); |
| 708 const views::Label* title_label = item_view->title(); | 742 const views::Label* title_label = item_view->title(); |
| 709 EXPECT_FALSE(title_label->GetTooltipText( | 743 EXPECT_FALSE(title_label->GetTooltipText( |
| 710 title_label->bounds().CenterPoint(), &actual_tooltip)); | 744 title_label->bounds().CenterPoint(), &actual_tooltip)); |
| 711 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 745 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
| 712 } | 746 } |
| 713 | 747 |
| 714 } // namespace test | 748 } // namespace test |
| 715 } // namespace app_list | 749 } // namespace app_list |
| OLD | NEW |