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

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

Issue 614213004: Refactor app list max folder logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 GetItemViewAt(0)->bounds().size()); 142 GetItemViewAt(0)->bounds().size());
143 rect.Offset(col * rect.width(), row * rect.height()); 143 rect.Offset(col * rect.width(), row * rect.height());
144 return rect; 144 return rect;
145 } 145 }
146 146
147 PaginationModel* GetPaginationModel() { 147 PaginationModel* GetPaginationModel() {
148 return apps_grid_view_->pagination_model(); 148 return apps_grid_view_->pagination_model();
149 } 149 }
150 150
151 // Points are in |apps_grid_view_|'s coordinates. 151 // Points are in |apps_grid_view_|'s coordinates.
152 void SimulateDrag(AppsGridView::Pointer pointer, 152 AppListItemView* SimulateDrag(AppsGridView::Pointer pointer,
153 const gfx::Point& from, 153 const gfx::Point& from,
154 const gfx::Point& to) { 154 const gfx::Point& to) {
155 AppListItemView* view = GetItemViewForPoint(from); 155 AppListItemView* view = GetItemViewForPoint(from);
156 DCHECK(view); 156 DCHECK(view);
157 157
158 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( 158 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin(
159 from - view->bounds().origin()); 159 from - view->bounds().origin());
160 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin( 160 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin(
161 to - view->bounds().origin()); 161 to - view->bounds().origin());
162 162
163 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, 163 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED,
164 translated_from, from, 0, 0); 164 translated_from, from, 0, 0);
165 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); 165 apps_grid_view_->InitiateDrag(view, pointer, pressed_event);
166 166
167 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 167 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
168 translated_to, to, 0, 0); 168 translated_to, to, 0, 0);
169 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); 169 apps_grid_view_->UpdateDragFromItem(pointer, drag_event);
170 return view;
170 } 171 }
171 172
172 void SimulateKeyPress(ui::KeyboardCode key_code) { 173 void SimulateKeyPress(ui::KeyboardCode key_code) {
173 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE); 174 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, ui::EF_NONE);
174 apps_grid_view_->OnKeyPressed(key_event); 175 apps_grid_view_->OnKeyPressed(key_event);
175 } 176 }
176 177
177 scoped_ptr<AppListTestModel> model_; 178 scoped_ptr<AppListTestModel> model_;
178 scoped_ptr<AppsGridView> apps_grid_view_; 179 scoped_ptr<AppsGridView> apps_grid_view_;
179 scoped_ptr<AppsGridViewTestApi> test_api_; 180 scoped_ptr<AppsGridViewTestApi> test_api_;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 410
410 // Dragging the last item over the folder, the folder won't accept the new 411 // Dragging the last item over the folder, the folder won't accept the new
411 // item. 412 // item.
412 SimulateDrag(AppsGridView::MOUSE, from, to); 413 SimulateDrag(AppsGridView::MOUSE, from, to);
413 apps_grid_view_->EndDrag(false); 414 apps_grid_view_->EndDrag(false);
414 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 415 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
415 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); 416 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
416 test_api_->LayoutToIdealBounds(); 417 test_api_->LayoutToIdealBounds();
417 } 418 }
418 419
420 // Check that moving items around doesn't allow a drop to happen into a full
421 // folder.
422 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolderWithMovement) {
423 EnsureFoldersEnabled();
424
425 // Create and add a folder with 16 items in it.
426 size_t kTotalItems = kMaxFolderItems;
427 model_->CreateAndPopulateFolderWithApps(kTotalItems);
428 EXPECT_EQ(1u, model_->top_level_item_list()->item_count());
429 EXPECT_EQ(AppListFolderItem::kItemType,
430 model_->top_level_item_list()->item_at(0)->GetItemType());
431 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
432 model_->top_level_item_list()->item_at(0));
433 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount());
434
435 // Create and add another item.
436 model_->PopulateAppWithId(kTotalItems);
437 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
438 EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(0)->id());
439 EXPECT_EQ(model_->GetItemName(kMaxFolderItems),
440 model_->top_level_item_list()->item_at(1)->id());
441
442 AppListItemView* folder_view =
443 GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint());
444
445 // Drag the new item to the left so that the grid reorders.
446 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
447 gfx::Point to = GetItemTileRectAt(0, 0).bottom_left();
448 AppListItemView* dragged_view = SimulateDrag(AppsGridView::MOUSE, from, to);
449 test_api_->LayoutToIdealBounds();
450
451 // The grid now looks like | blank | folder |.
452 EXPECT_EQ(NULL, GetItemViewForPoint(GetItemTileRectAt(0, 0).CenterPoint()));
453 EXPECT_EQ(folder_view,
454 GetItemViewForPoint(GetItemTileRectAt(0, 1).CenterPoint()));
455
456 // Move onto the folder and end the drag.
457 to = GetItemTileRectAt(0, 1).CenterPoint();
458 gfx::Point translated_to =
459 gfx::PointAtOffsetFromOrigin(to - dragged_view->bounds().origin());
460 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, translated_to, to, 0, 0);
461 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event);
462 apps_grid_view_->EndDrag(false);
463
464 // The item should not have moved into the folder.
465 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
466 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
467 test_api_->LayoutToIdealBounds();
468 }
469
419 TEST_F(AppsGridViewTest, MouseDragItemReorder) { 470 TEST_F(AppsGridViewTest, MouseDragItemReorder) {
420 // This test assumes Folders are enabled. 471 // This test assumes Folders are enabled.
421 EnsureFoldersEnabled(); 472 EnsureFoldersEnabled();
422 473
423 model_->PopulateApps(4); 474 model_->PopulateApps(4);
424 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); 475 EXPECT_EQ(4u, model_->top_level_item_list()->item_count());
425 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 476 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
426 model_->GetModelContent()); 477 model_->GetModelContent());
427 478
428 // Dragging an item towards its neighbours should not reorder until the drag 479 // Dragging an item towards its neighbours should not reorder until the drag
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 AppListItemView* item_view = GetItemViewAt(0); 791 AppListItemView* item_view = GetItemViewAt(0);
741 ASSERT_TRUE(item_view); 792 ASSERT_TRUE(item_view);
742 const views::Label* title_label = item_view->title(); 793 const views::Label* title_label = item_view->title();
743 EXPECT_FALSE(title_label->GetTooltipText( 794 EXPECT_FALSE(title_label->GetTooltipText(
744 title_label->bounds().CenterPoint(), &actual_tooltip)); 795 title_label->bounds().CenterPoint(), &actual_tooltip));
745 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 796 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
746 } 797 }
747 798
748 } // namespace test 799 } // namespace test
749 } // namespace app_list 800 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698