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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/views/apps_grid_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/views/apps_grid_view_unittest.cc
diff --git a/ui/app_list/views/apps_grid_view_unittest.cc b/ui/app_list/views/apps_grid_view_unittest.cc
index e7edc45a51cc7dcf32d3b9dbe1b0116772153f64..41bf0944d475426f68e45287a0a6b0cb92a41ba2 100644
--- a/ui/app_list/views/apps_grid_view_unittest.cc
+++ b/ui/app_list/views/apps_grid_view_unittest.cc
@@ -140,6 +140,19 @@ class AppsGridViewTest : public views::ViewsTestBase {
return apps_grid_view_->pagination_model();
}
+ // Point is in |apps_grid_view_|'s coordinates.
+ void SimulateContinueDrag(AppsGridView::Pointer pointer,
+ const AppListItemView* view,
+ const gfx::Point& to) {
+ DCHECK(view);
+
+ gfx::Point translated_to =
+ gfx::PointAtOffsetFromOrigin(to - view->bounds().origin());
+
+ ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, 0, 0);
+ apps_grid_view_->UpdateDragFromItem(pointer, drag_event);
+ }
+
// Points are in |apps_grid_view_|'s coordinates.
AppListItemView* SimulateDrag(AppsGridView::Pointer pointer,
const gfx::Point& from,
@@ -149,16 +162,12 @@ class AppsGridViewTest : public views::ViewsTestBase {
gfx::Point translated_from = gfx::PointAtOffsetFromOrigin(
from - view->bounds().origin());
- gfx::Point translated_to = gfx::PointAtOffsetFromOrigin(
- to - view->bounds().origin());
ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED,
translated_from, from, 0, 0);
apps_grid_view_->InitiateDrag(view, pointer, pressed_event);
- ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
- translated_to, to, 0, 0);
- apps_grid_view_->UpdateDragFromItem(pointer, drag_event);
+ SimulateContinueDrag(pointer, view, to);
return view;
}
@@ -446,10 +455,7 @@ TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolderWithMovement) {
// Move onto the folder and end the drag.
to = GetItemTileRectAt(0, 1).CenterPoint();
- gfx::Point translated_to =
- gfx::PointAtOffsetFromOrigin(to - dragged_view->bounds().origin());
- ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, 0, 0);
- apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event);
+ SimulateContinueDrag(AppsGridView::MOUSE, dragged_view, to);
apps_grid_view_->EndDrag(false);
// The item should not have moved into the folder.
@@ -458,6 +464,62 @@ TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolderWithMovement) {
test_api_->LayoutToIdealBounds();
}
+// Drag item into solitary folder on 2nd page. This fails to test Issue 439055,
+// because there's no |drag_and_drop_host_| to enter the offending code block in
+// AppsGridView::EndDrag(), but we'll keep it as a useful edge case test.
+TEST_F(AppsGridViewTest, MouseDragItemIntoLonelyFolder) {
+ EnsureFoldersEnabled();
+
+ size_t kTotalItems = kTilesPerPage + 1;
+ model_->PopulateApps(kTilesPerPage);
+ model_->CreateAndPopulateFolderWithApps(2);
+ EXPECT_EQ(kTotalItems, model_->top_level_item_list()->item_count());
+ EXPECT_EQ(2, GetPaginationModel()->total_pages());
+ EXPECT_EQ(
+ AppListFolderItem::kItemType,
+ model_->top_level_item_list()->item_at(kTilesPerPage)->GetItemType());
+ EXPECT_EQ(0, GetPaginationModel()->selected_page());
+
+ // Set up page switching
+ test_api_->SetPageFlipDelay(10);
+ // NOTE: We lower |duration_ms| arg to 0. During slow valgrind tests, the
+ // drag-and-hover would push the target folder into the empty space on the
+ // first page, leaving nothing to drop the item on, and foiling the test.
+ GetPaginationModel()->SetTransitionDurations(0, 10);
+ PageFlipWaiter page_flip_waiter(message_loop(), GetPaginationModel());
+
+ gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint();
+ gfx::Point to =
+ gfx::Point(apps_grid_view_->width(), apps_grid_view_->height() / 2);
+
+ // Drag to right edge, page should flip
+ page_flip_waiter.Reset();
+ AppListItemView* view = SimulateDrag(AppsGridView::MOUSE, from, to);
+ while (test_api_->HasPendingPageFlip()) {
+ page_flip_waiter.Wait();
+ }
+ EXPECT_EQ(1, GetPaginationModel()->selected_page());
+
+ // Continue drag to lonely folder, then drop
+ to = GetItemTileRectAt(0, 0).CenterPoint();
+ AppListItemView* folder = GetItemViewForPoint(to);
+ EXPECT_NE(nullptr, folder);
+ if (folder) {
+ EXPECT_EQ(AppListFolderItem::kItemType, folder->item()->GetItemType());
+ SimulateContinueDrag(AppsGridView::MOUSE, view, to);
+ }
+ apps_grid_view_->EndDrag(false);
+
+ // Moving item from first page to folder should shift folder to first page
+ EXPECT_EQ(1, GetPaginationModel()->total_pages());
+ EXPECT_EQ(0, GetPaginationModel()->selected_page());
+ EXPECT_EQ(kTotalItems - 1, model_->top_level_item_list()->item_count());
+ EXPECT_EQ(
+ AppListFolderItem::kItemType,
+ model_->top_level_item_list()->item_at(kTilesPerPage - 1)->GetItemType());
+ test_api_->LayoutToIdealBounds();
+}
+
TEST_F(AppsGridViewTest, MouseDragItemReorder) {
// This test assumes Folders are enabled.
EnsureFoldersEnabled();
« 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