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

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

Issue 792883006: Fix crash after Launcher drag/drop (take 2) (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
143 // Points are in |apps_grid_view_|'s coordinates. 156 // Points are in |apps_grid_view_|'s coordinates.
144 AppListItemView* SimulateDrag(AppsGridView::Pointer pointer, 157 AppListItemView* SimulateDrag(AppsGridView::Pointer pointer,
145 const gfx::Point& from, 158 const gfx::Point& from,
146 const gfx::Point& to) { 159 const gfx::Point& to) {
147 AppListItemView* view = GetItemViewForPoint(from); 160 AppListItemView* view = GetItemViewForPoint(from);
148 DCHECK(view); 161 DCHECK(view);
149 162
150 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( 163 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin(
151 from - view->bounds().origin()); 164 from - view->bounds().origin());
152 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin(
153 to - view->bounds().origin());
154 165
155 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, 166 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED,
156 translated_from, from, 0, 0); 167 translated_from, from, 0, 0);
157 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); 168 apps_grid_view_->InitiateDrag(view, pointer, pressed_event);
158 169
159 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 170 SimulateContinueDrag(pointer, view, to);
160 translated_to, to, 0, 0);
161 apps_grid_view_->UpdateDragFromItem(pointer, drag_event);
162 return view; 171 return view;
163 } 172 }
164 173
165 void SimulateKeyPress(ui::KeyboardCode key_code) { 174 void SimulateKeyPress(ui::KeyboardCode key_code) {
166 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 175 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
167 apps_grid_view_->OnKeyPressed(key_event); 176 apps_grid_view_->OnKeyPressed(key_event);
168 } 177 }
169 178
170 scoped_ptr<AppListTestModel> model_; 179 scoped_ptr<AppListTestModel> model_;
171 scoped_ptr<AppsGridView> apps_grid_view_; 180 scoped_ptr<AppsGridView> apps_grid_view_;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 AppListItemView* dragged_view = SimulateDrag(AppsGridView::MOUSE, from, to); 448 AppListItemView* dragged_view = SimulateDrag(AppsGridView::MOUSE, from, to);
440 test_api_->LayoutToIdealBounds(); 449 test_api_->LayoutToIdealBounds();
441 450
442 // The grid now looks like | blank | folder |. 451 // The grid now looks like | blank | folder |.
443 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint())); 452 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint()));
444 EXPECT_EQ(folder_view, 453 EXPECT_EQ(folder_view,
445 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint())); 454 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint()));
446 455
447 // Move onto the folder and end the drag. 456 // Move onto the folder and end the drag.
448 to = GetItemTileRectAt(0, 1).CenterPoint(); 457 to = GetItemTileRectAt(0, 1).CenterPoint();
449 gfx::Point translated_to = 458 SimulateContinueDrag(AppsGridView::MOUSE, dragged_view, 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);
453 apps_grid_view_->EndDrag(false); 459 apps_grid_view_->EndDrag(false);
454 460
455 // The item should not have moved into the folder. 461 // The item should not have moved into the folder.
456 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 462 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
457 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); 463 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
458 test_api_->LayoutToIdealBounds(); 464 test_api_->LayoutToIdealBounds();
459 } 465 }
460 466
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
461 TEST_F(AppsGridViewTest, MouseDragItemReorder) { 523 TEST_F(AppsGridViewTest, MouseDragItemReorder) {
462 // This test assumes Folders are enabled. 524 // This test assumes Folders are enabled.
463 EnsureFoldersEnabled(); 525 EnsureFoldersEnabled();
464 526
465 model_->PopulateApps(4); 527 model_->PopulateApps(4);
466 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); 528 EXPECT_EQ(4u, model_->top_level_item_list()->item_count());
467 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 529 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
468 model_->GetModelContent()); 530 model_->GetModelContent());
469 531
470 // Dragging an item towards its neighbours should not reorder until the drag 532 // Dragging an item towards its neighbours should not reorder until the drag
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 AppListItemView* item_view = GetItemViewAt(0); 844 AppListItemView* item_view = GetItemViewAt(0);
783 ASSERT_TRUE(item_view); 845 ASSERT_TRUE(item_view);
784 const views::Label* title_label = item_view->title(); 846 const views::Label* title_label = item_view->title();
785 EXPECT_FALSE(title_label->GetTooltipText( 847 EXPECT_FALSE(title_label->GetTooltipText(
786 title_label->bounds().CenterPoint(), &actual_tooltip)); 848 title_label->bounds().CenterPoint(), &actual_tooltip));
787 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 849 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
788 } 850 }
789 851
790 } // namespace test 852 } // namespace test
791 } // namespace app_list 853 } // 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