| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 gfx::Rect rect(gfx::Point(insets.left(), insets.top()), | 133 gfx::Rect rect(gfx::Point(insets.left(), insets.top()), |
| 134 AppsGridView::GetTotalTileSize()); | 134 AppsGridView::GetTotalTileSize()); |
| 135 rect.Offset(col * rect.width(), row * rect.height()); | 135 rect.Offset(col * rect.width(), row * rect.height()); |
| 136 return rect; | 136 return rect; |
| 137 } | 137 } |
| 138 | 138 |
| 139 PaginationModel* GetPaginationModel() { | 139 PaginationModel* GetPaginationModel() { |
| 140 return apps_grid_view_->pagination_model(); | 140 return apps_grid_view_->pagination_model(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Point is in |apps_grid_view_|'s coordinates. | |
| 144 void SimulateContinueDrag(AppsGridView::Pointer pointer, | |
| 145 const AppListItemView* view, | |
| 146 const gfx::Point& to) { | |
| 147 DCHECK(view); | |
| 148 | |
| 149 gfx::Point translated_to = | |
| 150 gfx::PointAtOffsetFromOrigin(to - view->bounds().origin()); | |
| 151 | |
| 152 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, 0, 0); | |
| 153 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); | |
| 154 } | |
| 155 | |
| 156 // Points are in |apps_grid_view_|'s coordinates. | 143 // Points are in |apps_grid_view_|'s coordinates. |
| 157 AppListItemView* SimulateDrag(AppsGridView::Pointer pointer, | 144 AppListItemView* SimulateDrag(AppsGridView::Pointer pointer, |
| 158 const gfx::Point& from, | 145 const gfx::Point& from, |
| 159 const gfx::Point& to) { | 146 const gfx::Point& to) { |
| 160 AppListItemView* view = GetItemViewForPoint(from); | 147 AppListItemView* view = GetItemViewForPoint(from); |
| 161 DCHECK(view); | 148 DCHECK(view); |
| 162 | 149 |
| 163 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( | 150 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( |
| 164 from - view->bounds().origin()); | 151 from - view->bounds().origin()); |
| 152 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin( |
| 153 to - view->bounds().origin()); |
| 165 | 154 |
| 166 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, | 155 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, |
| 167 translated_from, from, 0, 0); | 156 translated_from, from, 0, 0); |
| 168 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); | 157 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); |
| 169 | 158 |
| 170 SimulateContinueDrag(pointer, view, to); | 159 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, |
| 160 translated_to, to, 0, 0); |
| 161 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); |
| 171 return view; | 162 return view; |
| 172 } | 163 } |
| 173 | 164 |
| 174 void SimulateKeyPress(ui::KeyboardCode key_code) { | 165 void SimulateKeyPress(ui::KeyboardCode key_code) { |
| 175 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); | 166 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); |
| 176 apps_grid_view_->OnKeyPressed(key_event); | 167 apps_grid_view_->OnKeyPressed(key_event); |
| 177 } | 168 } |
| 178 | 169 |
| 179 scoped_ptr<AppListTestModel> model_; | 170 scoped_ptr<AppListTestModel> model_; |
| 180 scoped_ptr<AppsGridView> apps_grid_view_; | 171 scoped_ptr<AppsGridView> apps_grid_view_; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 AppListItemView* dragged_view = SimulateDrag(AppsGridView::MOUSE, from, to); | 439 AppListItemView* dragged_view = SimulateDrag(AppsGridView::MOUSE, from, to); |
| 449 test_api_->LayoutToIdealBounds(); | 440 test_api_->LayoutToIdealBounds(); |
| 450 | 441 |
| 451 // The grid now looks like | blank | folder |. | 442 // The grid now looks like | blank | folder |. |
| 452 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint())); | 443 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint())); |
| 453 EXPECT_EQ(folder_view, | 444 EXPECT_EQ(folder_view, |
| 454 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint())); | 445 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint())); |
| 455 | 446 |
| 456 // Move onto the folder and end the drag. | 447 // Move onto the folder and end the drag. |
| 457 to = GetItemTileRectAt(0, 1).CenterPoint(); | 448 to = GetItemTileRectAt(0, 1).CenterPoint(); |
| 458 SimulateContinueDrag(AppsGridView::MOUSE, dragged_view, to); | 449 gfx::Point translated_to = |
| 450 gfx::PointAtOffsetFromOrigin(to - dragged_view->bounds().origin()); |
| 451 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, 0, 0); |
| 452 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); |
| 459 apps_grid_view_->EndDrag(false); | 453 apps_grid_view_->EndDrag(false); |
| 460 | 454 |
| 461 // The item should not have moved into the folder. | 455 // The item should not have moved into the folder. |
| 462 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 456 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
| 463 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); | 457 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); |
| 464 test_api_->LayoutToIdealBounds(); | 458 test_api_->LayoutToIdealBounds(); |
| 465 } | 459 } |
| 466 | 460 |
| 467 // Drag item into solitary folder on 2nd page. This fails to test Issue 439055, | |
| 468 // because there's no |drag_and_drop_host_| to enter the offending code block in | |
| 469 // AppsGridView::EndDrag(), but we'll keep it as a useful edge case test. | |
| 470 TEST_F(AppsGridViewTest, MouseDragItemIntoLonelyFolder) { | |
| 471 EnsureFoldersEnabled(); | |
| 472 | |
| 473 size_t kTotalItems = kTilesPerPage + 1; | |
| 474 model_->PopulateApps(kTilesPerPage); | |
| 475 model_->CreateAndPopulateFolderWithApps(2); | |
| 476 EXPECT_EQ(kTotalItems, model_->top_level_item_list()->item_count()); | |
| 477 EXPECT_EQ(2, GetPaginationModel()->total_pages()); | |
| 478 EXPECT_EQ( | |
| 479 AppListFolderItem::kItemType, | |
| 480 model_->top_level_item_list()->item_at(kTilesPerPage)->GetItemType()); | |
| 481 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | |
| 482 | |
| 483 // Set up page switching | |
| 484 test_api_->SetPageFlipDelay(10); | |
| 485 // NOTE: We lower |duration_ms| arg to 0. During slow valgrind tests, the | |
| 486 // drag-and-hover would push the target folder into the empty space on the | |
| 487 // first page, leaving nothing to drop the item on, and foiling the test. | |
| 488 GetPaginationModel()->SetTransitionDurations(0, 10); | |
| 489 PageFlipWaiter page_flip_waiter(message_loop(), GetPaginationModel()); | |
| 490 | |
| 491 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); | |
| 492 gfx::Point to = | |
| 493 gfx::Point(apps_grid_view_->width(), apps_grid_view_->height() / 2); | |
| 494 | |
| 495 // Drag to right edge, page should flip | |
| 496 page_flip_waiter.Reset(); | |
| 497 AppListItemView* view = SimulateDrag(AppsGridView::MOUSE, from, to); | |
| 498 while (test_api_->HasPendingPageFlip()) { | |
| 499 page_flip_waiter.Wait(); | |
| 500 } | |
| 501 EXPECT_EQ(1, GetPaginationModel()->selected_page()); | |
| 502 | |
| 503 // Continue drag to lonely folder, then drop | |
| 504 to = GetItemTileRectAt(0, 0).CenterPoint(); | |
| 505 AppListItemView* folder = GetItemViewForPoint(to); | |
| 506 EXPECT_NE(nullptr, folder); | |
| 507 if (folder) { | |
| 508 EXPECT_EQ(AppListFolderItem::kItemType, folder->item()->GetItemType()); | |
| 509 SimulateContinueDrag(AppsGridView::MOUSE, view, to); | |
| 510 } | |
| 511 apps_grid_view_->EndDrag(false); | |
| 512 | |
| 513 // Moving item from first page to folder should shift folder to first page | |
| 514 EXPECT_EQ(1, GetPaginationModel()->total_pages()); | |
| 515 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | |
| 516 EXPECT_EQ(kTotalItems - 1, model_->top_level_item_list()->item_count()); | |
| 517 EXPECT_EQ( | |
| 518 AppListFolderItem::kItemType, | |
| 519 model_->top_level_item_list()->item_at(kTilesPerPage - 1)->GetItemType()); | |
| 520 test_api_->LayoutToIdealBounds(); | |
| 521 } | |
| 522 | |
| 523 TEST_F(AppsGridViewTest, MouseDragItemReorder) { | 461 TEST_F(AppsGridViewTest, MouseDragItemReorder) { |
| 524 // This test assumes Folders are enabled. | 462 // This test assumes Folders are enabled. |
| 525 EnsureFoldersEnabled(); | 463 EnsureFoldersEnabled(); |
| 526 | 464 |
| 527 model_->PopulateApps(4); | 465 model_->PopulateApps(4); |
| 528 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); | 466 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); |
| 529 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), | 467 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
| 530 model_->GetModelContent()); | 468 model_->GetModelContent()); |
| 531 | 469 |
| 532 // Dragging an item towards its neighbours should not reorder until the drag | 470 // Dragging an item towards its neighbours should not reorder until the drag |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 AppListItemView* item_view = GetItemViewAt(0); | 782 AppListItemView* item_view = GetItemViewAt(0); |
| 845 ASSERT_TRUE(item_view); | 783 ASSERT_TRUE(item_view); |
| 846 const views::Label* title_label = item_view->title(); | 784 const views::Label* title_label = item_view->title(); |
| 847 EXPECT_FALSE(title_label->GetTooltipText( | 785 EXPECT_FALSE(title_label->GetTooltipText( |
| 848 title_label->bounds().CenterPoint(), &actual_tooltip)); | 786 title_label->bounds().CenterPoint(), &actual_tooltip)); |
| 849 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 787 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
| 850 } | 788 } |
| 851 | 789 |
| 852 } // namespace test | 790 } // namespace test |
| 853 } // namespace app_list | 791 } // namespace app_list |
| OLD | NEW |