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

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

Issue 1861233003: Prepare for building with enable_app_list=0 on Desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: drop patchset dependency, rebase to master Created 4 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 apps_grid_view_->SetItemList(model_->top_level_item_list()); 103 apps_grid_view_->SetItemList(model_->top_level_item_list());
104 104
105 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get())); 105 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get()));
106 } 106 }
107 void TearDown() override { 107 void TearDown() override {
108 apps_grid_view_.reset(); // Release apps grid view before models. 108 apps_grid_view_.reset(); // Release apps grid view before models.
109 views::ViewsTestBase::TearDown(); 109 views::ViewsTestBase::TearDown();
110 } 110 }
111 111
112 protected: 112 protected:
113 void EnsureFoldersEnabled() {
114 #if defined(OS_MACOSX)
115 // Folders require toolkit-views app list to be enabled.
116 base::CommandLine::ForCurrentProcess()->AppendSwitch(
117 switches::kEnableMacViewsAppList);
118 #endif
119 }
120
121 AppListItemView* GetItemViewAt(int index) { 113 AppListItemView* GetItemViewAt(int index) {
122 return static_cast<AppListItemView*>( 114 return static_cast<AppListItemView*>(
123 test_api_->GetViewAtModelIndex(index)); 115 test_api_->GetViewAtModelIndex(index));
124 } 116 }
125 117
126 AppListItemView* GetItemViewForPoint(const gfx::Point& point) { 118 AppListItemView* GetItemViewForPoint(const gfx::Point& point) {
127 for (size_t i = 0; i < model_->top_level_item_list()->item_count(); ++i) { 119 for (size_t i = 0; i < model_->top_level_item_list()->item_count(); ++i) {
128 AppListItemView* view = GetItemViewAt(i); 120 AppListItemView* view = GetItemViewAt(i);
129 if (view->bounds().Contains(point)) 121 if (view->bounds().Contains(point))
130 return view; 122 return view;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 gfx::Point(2, 2), ui::EventTimeForNow(), 0, 0); 305 gfx::Point(2, 2), ui::EventTimeForNow(), 0, 0);
314 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); 306 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event);
315 EXPECT_FALSE(apps_grid_view_->has_dragged_view()); 307 EXPECT_FALSE(apps_grid_view_->has_dragged_view());
316 308
317 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), 309 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"),
318 model_->GetModelContent()); 310 model_->GetModelContent());
319 test_api_->LayoutToIdealBounds(); 311 test_api_->LayoutToIdealBounds();
320 } 312 }
321 313
322 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { 314 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) {
323 EnsureFoldersEnabled();
324
325 size_t kTotalItems = 3; 315 size_t kTotalItems = 3;
326 model_->PopulateApps(kTotalItems); 316 model_->PopulateApps(kTotalItems);
327 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); 317 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems);
328 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent()); 318 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent());
329 319
330 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); 320 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
331 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); 321 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint();
332 322
333 // Dragging item_1 over item_0 creates a folder. 323 // Dragging item_1 over item_0 creates a folder.
334 SimulateDrag(AppsGridView::MOUSE, from, to); 324 SimulateDrag(AppsGridView::MOUSE, from, to);
(...skipping 27 matching lines...) Expand all
362 item_1 = model_->FindItem("Item 1"); 352 item_1 = model_->FindItem("Item 1");
363 EXPECT_TRUE(item_1->IsInFolder()); 353 EXPECT_TRUE(item_1->IsInFolder());
364 EXPECT_EQ(folder_item->id(), item_1->folder_id()); 354 EXPECT_EQ(folder_item->id(), item_1->folder_id());
365 AppListItem* item_2 = model_->FindItem("Item 2"); 355 AppListItem* item_2 = model_->FindItem("Item 2");
366 EXPECT_TRUE(item_2->IsInFolder()); 356 EXPECT_TRUE(item_2->IsInFolder());
367 EXPECT_EQ(folder_item->id(), item_2->folder_id()); 357 EXPECT_EQ(folder_item->id(), item_2->folder_id());
368 test_api_->LayoutToIdealBounds(); 358 test_api_->LayoutToIdealBounds();
369 } 359 }
370 360
371 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) { 361 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) {
372 EnsureFoldersEnabled();
373
374 // Create and add a folder with 15 items in it. 362 // Create and add a folder with 15 items in it.
375 size_t kTotalItems = kMaxFolderItems - 1; 363 size_t kTotalItems = kMaxFolderItems - 1;
376 model_->CreateAndPopulateFolderWithApps(kTotalItems); 364 model_->CreateAndPopulateFolderWithApps(kTotalItems);
377 EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); 365 EXPECT_EQ(1u, model_->top_level_item_list()->item_count());
378 EXPECT_EQ(AppListFolderItem::kItemType, 366 EXPECT_EQ(AppListFolderItem::kItemType,
379 model_->top_level_item_list()->item_at(0)->GetItemType()); 367 model_->top_level_item_list()->item_at(0)->GetItemType());
380 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( 368 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
381 model_->top_level_item_list()->item_at(0)); 369 model_->top_level_item_list()->item_at(0));
382 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); 370 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount());
383 371
(...skipping 25 matching lines...) Expand all
409 SimulateDrag(AppsGridView::MOUSE, from, to); 397 SimulateDrag(AppsGridView::MOUSE, from, to);
410 apps_grid_view_->EndDrag(false); 398 apps_grid_view_->EndDrag(false);
411 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 399 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
412 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); 400 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
413 test_api_->LayoutToIdealBounds(); 401 test_api_->LayoutToIdealBounds();
414 } 402 }
415 403
416 // Check that moving items around doesn't allow a drop to happen into a full 404 // Check that moving items around doesn't allow a drop to happen into a full
417 // folder. 405 // folder.
418 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolderWithMovement) { 406 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolderWithMovement) {
419 EnsureFoldersEnabled();
420
421 // Create and add a folder with 16 items in it. 407 // Create and add a folder with 16 items in it.
422 size_t kTotalItems = kMaxFolderItems; 408 size_t kTotalItems = kMaxFolderItems;
423 model_->CreateAndPopulateFolderWithApps(kTotalItems); 409 model_->CreateAndPopulateFolderWithApps(kTotalItems);
424 EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); 410 EXPECT_EQ(1u, model_->top_level_item_list()->item_count());
425 EXPECT_EQ(AppListFolderItem::kItemType, 411 EXPECT_EQ(AppListFolderItem::kItemType,
426 model_->top_level_item_list()->item_at(0)->GetItemType()); 412 model_->top_level_item_list()->item_at(0)->GetItemType());
427 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( 413 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
428 model_->top_level_item_list()->item_at(0)); 414 model_->top_level_item_list()->item_at(0));
429 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); 415 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount());
430 416
(...skipping 28 matching lines...) Expand all
459 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event); 445 apps_grid_view_->UpdateDragFromItem(AppsGridView::MOUSE, drag_event);
460 apps_grid_view_->EndDrag(false); 446 apps_grid_view_->EndDrag(false);
461 447
462 // The item should not have moved into the folder. 448 // The item should not have moved into the folder.
463 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 449 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
464 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); 450 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
465 test_api_->LayoutToIdealBounds(); 451 test_api_->LayoutToIdealBounds();
466 } 452 }
467 453
468 TEST_F(AppsGridViewTest, MouseDragItemReorder) { 454 TEST_F(AppsGridViewTest, MouseDragItemReorder) {
469 // This test assumes Folders are enabled.
470 EnsureFoldersEnabled();
471
472 model_->PopulateApps(4); 455 model_->PopulateApps(4);
473 EXPECT_EQ(4u, model_->top_level_item_list()->item_count()); 456 EXPECT_EQ(4u, model_->top_level_item_list()->item_count());
474 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 457 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
475 model_->GetModelContent()); 458 model_->GetModelContent());
476 459
477 // Dragging an item towards its neighbours should not reorder until the drag 460 // Dragging an item towards its neighbours should not reorder until the drag
478 // is past the folder drop point. 461 // is past the folder drop point.
479 gfx::Point top_right = GetItemTileRectAt(0, 1).CenterPoint(); 462 gfx::Point top_right = GetItemTileRectAt(0, 1).CenterPoint();
480 gfx::Vector2d drag_vector; 463 gfx::Vector2d drag_vector;
481 int half_tile_width = 464 int half_tile_width =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Dragging down past the last app should reorder to the last position. 501 // Dragging down past the last app should reorder to the last position.
519 drag_vector.set_x(half_tile_width); 502 drag_vector.set_x(half_tile_width);
520 drag_vector.set_y(2 * tile_height); 503 drag_vector.set_y(2 * tile_height);
521 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector); 504 SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
522 apps_grid_view_->EndDrag(false); 505 apps_grid_view_->EndDrag(false);
523 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Item 0"), 506 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Item 0"),
524 model_->GetModelContent()); 507 model_->GetModelContent());
525 } 508 }
526 509
527 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { 510 TEST_F(AppsGridViewTest, MouseDragFolderReorder) {
528 EnsureFoldersEnabled();
529
530 size_t kTotalItems = 2; 511 size_t kTotalItems = 2;
531 model_->CreateAndPopulateFolderWithApps(kTotalItems); 512 model_->CreateAndPopulateFolderWithApps(kTotalItems);
532 model_->PopulateAppWithId(kTotalItems); 513 model_->PopulateAppWithId(kTotalItems);
533 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 514 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
534 EXPECT_EQ(AppListFolderItem::kItemType, 515 EXPECT_EQ(AppListFolderItem::kItemType,
535 model_->top_level_item_list()->item_at(0)->GetItemType()); 516 model_->top_level_item_list()->item_at(0)->GetItemType());
536 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( 517 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
537 model_->top_level_item_list()->item_at(0)); 518 model_->top_level_item_list()->item_at(0));
538 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id()); 519 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id());
539 520
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to); 633 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to);
653 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); 634 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to);
654 // Finishes the drag and touch drag wins. 635 // Finishes the drag and touch drag wins.
655 apps_grid_view_->EndDrag(false); 636 apps_grid_view_->EndDrag(false);
656 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"), 637 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"),
657 model_->GetModelContent()); 638 model_->GetModelContent());
658 test_api_->LayoutToIdealBounds(); 639 test_api_->LayoutToIdealBounds();
659 } 640 }
660 641
661 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) { 642 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) {
662 EnsureFoldersEnabled();
663
664 const int kTotalItems = 4; 643 const int kTotalItems = 4;
665 TestAppsGridViewFolderDelegate folder_delegate; 644 TestAppsGridViewFolderDelegate folder_delegate;
666 apps_grid_view_->set_folder_delegate(&folder_delegate); 645 apps_grid_view_->set_folder_delegate(&folder_delegate);
667 model_->PopulateApps(kTotalItems); 646 model_->PopulateApps(kTotalItems);
668 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 647 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
669 model_->GetModelContent()); 648 model_->GetModelContent());
670 649
671 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint(); 650 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint();
672 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint(); 651 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint();
673 652
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 AppListItemView* item_view = GetItemViewAt(0); 766 AppListItemView* item_view = GetItemViewAt(0);
788 ASSERT_TRUE(item_view); 767 ASSERT_TRUE(item_view);
789 const views::Label* title_label = item_view->title(); 768 const views::Label* title_label = item_view->title();
790 EXPECT_FALSE(title_label->GetTooltipText( 769 EXPECT_FALSE(title_label->GetTooltipText(
791 title_label->bounds().CenterPoint(), &actual_tooltip)); 770 title_label->bounds().CenterPoint(), &actual_tooltip));
792 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 771 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
793 } 772 }
794 773
795 } // namespace test 774 } // namespace test
796 } // namespace app_list 775 } // namespace app_list
OLDNEW
« ui/app_list/app_list_switches.cc ('K') | « ui/app_list/app_list_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698