Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ui/app_list/views/apps_grid_view_unittest.cc

Issue 806883004: Revert "Fix crash after Launcher drag/drop" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/apps_grid_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 GetPaginationModel()->SetTransitionDurations(10, 10);
486 PageFlipWaiter page_flip_waiter(message_loop(), GetPaginationModel());
487
488 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint();
489 gfx::Point to =
490 gfx::Point(apps_grid_view_->width(), apps_grid_view_->height() / 2);
491
492 // Drag to right edge, page should flip
493 page_flip_waiter.Reset();
494 AppListItemView* view = SimulateDrag(AppsGridView::MOUSE, from, to);
495 while (test_api_->HasPendingPageFlip()) {
496 page_flip_waiter.Wait();
497 }
498 EXPECT_EQ(1, GetPaginationModel()->selected_page());
499
500 // Continue drag to lonely folder, then drop
501 to = GetItemTileRectAt(0, 0).CenterPoint();
502 AppListItemView* folder = GetItemViewForPoint(to);
503 EXPECT_EQ(AppListFolderItem::kItemType, folder->item()->GetItemType());
504 SimulateContinueDrag(AppsGridView::MOUSE, view, to);
505 apps_grid_view_->EndDrag(false);
506
507 // Moving item from first page to folder should shift folder to first page
508 EXPECT_EQ(1, GetPaginationModel()->total_pages());
509 EXPECT_EQ(0, GetPaginationModel()->selected_page());
510 EXPECT_EQ(kTotalItems - 1, model_->top_level_item_list()->item_count());
511 EXPECT_EQ(
512 AppListFolderItem::kItemType,
513 model_->top_level_item_list()->item_at(kTilesPerPage - 1)->GetItemType());
514 test_api_->LayoutToIdealBounds();
515 }
516
517 TEST_F(AppsGridViewTest, MouseDragItemReorder) { 461 TEST_F(AppsGridViewTest, MouseDragItemReorder) {
518 // This test assumes Folders are enabled. 462 // This test assumes Folders are enabled.
519 EnsureFoldersEnabled(); 463 EnsureFoldersEnabled();
520 464
521 model_->PopulateApps(4); 465 model_->PopulateApps(4);
522 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); 466 EXPECT_EQ(4u, model_->top_level_item_list()->item_count());
523 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"),
524 model_->GetModelContent()); 468 model_->GetModelContent());
525 469
526 // 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
838 AppListItemView* item_view = GetItemViewAt(0); 782 AppListItemView* item_view = GetItemViewAt(0);
839 ASSERT_TRUE(item_view); 783 ASSERT_TRUE(item_view);
840 const views::Label* title_label = item_view->title(); 784 const views::Label* title_label = item_view->title();
841 EXPECT_FALSE(title_label->GetTooltipText( 785 EXPECT_FALSE(title_label->GetTooltipText(
842 title_label->bounds().CenterPoint(), &actual_tooltip)); 786 title_label->bounds().CenterPoint(), &actual_tooltip));
843 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 787 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
844 } 788 }
845 789
846 } // namespace test 790 } // namespace test
847 } // namespace app_list 791 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_grid_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698