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

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

Issue 222553003: Disable AppList sync by default on non Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/app_list_switches.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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 apps_grid_view_->SetItemList(model_->top_level_item_list()); 115 apps_grid_view_->SetItemList(model_->top_level_item_list());
116 116
117 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get())); 117 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get()));
118 } 118 }
119 virtual void TearDown() OVERRIDE { 119 virtual void TearDown() OVERRIDE {
120 apps_grid_view_.reset(); // Release apps grid view before models. 120 apps_grid_view_.reset(); // Release apps grid view before models.
121 views::ViewsTestBase::TearDown(); 121 views::ViewsTestBase::TearDown();
122 } 122 }
123 123
124 protected: 124 protected:
125 void EnsureFoldersEnabled() {
126 // Folders require AppList sync to be enabled.
127 CommandLine::ForCurrentProcess()->AppendSwitch(
128 switches::kEnableSyncAppList);
129 }
130
125 AppListItemView* GetItemViewAt(int index) { 131 AppListItemView* GetItemViewAt(int index) {
126 return static_cast<AppListItemView*>( 132 return static_cast<AppListItemView*>(
127 test_api_->GetViewAtModelIndex(index)); 133 test_api_->GetViewAtModelIndex(index));
128 } 134 }
129 135
130 AppListItemView* GetItemViewForPoint(const gfx::Point& point) { 136 AppListItemView* GetItemViewForPoint(const gfx::Point& point) {
131 for (size_t i = 0; i < model_->top_level_item_list()->item_count(); ++i) { 137 for (size_t i = 0; i < model_->top_level_item_list()->item_count(); ++i) {
132 AppListItemView* view = GetItemViewAt(i); 138 AppListItemView* view = GetItemViewAt(i);
133 if (view->bounds().Contains(point)) 139 if (view->bounds().Contains(point))
134 return view; 140 return view;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 268
263 EXPECT_FALSE(apps_grid_view_->IsSelectedView(last_view)); 269 EXPECT_FALSE(apps_grid_view_->IsSelectedView(last_view));
264 270
265 // No crash happens. 271 // No crash happens.
266 AppListItemView* view = GetItemViewAt(0); 272 AppListItemView* view = GetItemViewAt(0);
267 apps_grid_view_->SetSelectedView(view); 273 apps_grid_view_->SetSelectedView(view);
268 EXPECT_TRUE(apps_grid_view_->IsSelectedView(view)); 274 EXPECT_TRUE(apps_grid_view_->IsSelectedView(view));
269 } 275 }
270 276
271 TEST_F(AppsGridViewTest, MouseDragWithFolderDisabled) { 277 TEST_F(AppsGridViewTest, MouseDragWithFolderDisabled) {
272 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableFolderUI); 278 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSyncAppList);
273 const int kTotalItems = 4; 279 const int kTotalItems = 4;
274 model_->PopulateApps(kTotalItems); 280 model_->PopulateApps(kTotalItems);
275 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 281 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
276 model_->GetModelContent()); 282 model_->GetModelContent());
277 283
278 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); 284 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint();
279 gfx::Point to = GetItemTileRectAt(0, 1).CenterPoint(); 285 gfx::Point to = GetItemTileRectAt(0, 1).CenterPoint();
280 286
281 // Dragging changes model order. 287 // Dragging changes model order.
282 SimulateDrag(AppsGridView::MOUSE, from, to); 288 SimulateDrag(AppsGridView::MOUSE, from, to);
(...skipping 20 matching lines...) Expand all
303 // Adding a launcher item cancels the drag and respects the order. 309 // Adding a launcher item cancels the drag and respects the order.
304 SimulateDrag(AppsGridView::MOUSE, from, to); 310 SimulateDrag(AppsGridView::MOUSE, from, to);
305 model_->CreateAndAddItem("Extra"); 311 model_->CreateAndAddItem("Extra");
306 apps_grid_view_->EndDrag(false); 312 apps_grid_view_->EndDrag(false);
307 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), 313 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"),
308 model_->GetModelContent()); 314 model_->GetModelContent());
309 test_api_->LayoutToIdealBounds(); 315 test_api_->LayoutToIdealBounds();
310 } 316 }
311 317
312 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { 318 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) {
319 EnsureFoldersEnabled();
320
313 size_t kTotalItems = 3; 321 size_t kTotalItems = 3;
314 model_->PopulateApps(kTotalItems); 322 model_->PopulateApps(kTotalItems);
315 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); 323 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems);
316 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent()); 324 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent());
317 325
318 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); 326 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
319 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); 327 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint();
320 328
321 // Dragging item_1 over item_0 creates a folder. 329 // Dragging item_1 over item_0 creates a folder.
322 SimulateDrag(AppsGridView::MOUSE, from, to); 330 SimulateDrag(AppsGridView::MOUSE, from, to);
(...skipping 27 matching lines...) Expand all
350 item_1 = model_->FindItem("Item 1"); 358 item_1 = model_->FindItem("Item 1");
351 EXPECT_TRUE(item_1->IsInFolder()); 359 EXPECT_TRUE(item_1->IsInFolder());
352 EXPECT_EQ(folder_item->id(), item_1->folder_id()); 360 EXPECT_EQ(folder_item->id(), item_1->folder_id());
353 AppListItem* item_2 = model_->FindItem("Item 2"); 361 AppListItem* item_2 = model_->FindItem("Item 2");
354 EXPECT_TRUE(item_2->IsInFolder()); 362 EXPECT_TRUE(item_2->IsInFolder());
355 EXPECT_EQ(folder_item->id(), item_2->folder_id()); 363 EXPECT_EQ(folder_item->id(), item_2->folder_id());
356 test_api_->LayoutToIdealBounds(); 364 test_api_->LayoutToIdealBounds();
357 } 365 }
358 366
359 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) { 367 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) {
368 EnsureFoldersEnabled();
369
360 // Create and add a folder with 15 items in it. 370 // Create and add a folder with 15 items in it.
361 size_t kTotalItems = kMaxFolderItems - 1; 371 size_t kTotalItems = kMaxFolderItems - 1;
362 model_->CreateAndPopulateFolderWithApps(kTotalItems); 372 model_->CreateAndPopulateFolderWithApps(kTotalItems);
363 EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); 373 EXPECT_EQ(1u, model_->top_level_item_list()->item_count());
364 EXPECT_EQ(AppListFolderItem::kItemType, 374 EXPECT_EQ(AppListFolderItem::kItemType,
365 model_->top_level_item_list()->item_at(0)->GetItemType()); 375 model_->top_level_item_list()->item_at(0)->GetItemType());
366 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( 376 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
367 model_->top_level_item_list()->item_at(0)); 377 model_->top_level_item_list()->item_at(0));
368 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); 378 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount());
369 379
(...skipping 26 matching lines...) Expand all
396 apps_grid_view_->EndDrag(false); 406 apps_grid_view_->EndDrag(false);
397 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 407 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
398 EXPECT_EQ(model_->GetItemName(kMaxFolderItems), 408 EXPECT_EQ(model_->GetItemName(kMaxFolderItems),
399 model_->top_level_item_list()->item_at(0)->id()); 409 model_->top_level_item_list()->item_at(0)->id());
400 EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id()); 410 EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id());
401 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); 411 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount());
402 test_api_->LayoutToIdealBounds(); 412 test_api_->LayoutToIdealBounds();
403 } 413 }
404 414
405 TEST_F(AppsGridViewTest, MouseDragItemReorder) { 415 TEST_F(AppsGridViewTest, MouseDragItemReorder) {
416 // This test assumes Folders are enabled.
417 EnsureFoldersEnabled();
418
406 size_t kTotalItems = 2; 419 size_t kTotalItems = 2;
407 model_->PopulateApps(kTotalItems); 420 model_->PopulateApps(kTotalItems);
408 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 421 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
409 EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent()); 422 EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent());
410 423
411 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); 424 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
412 int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - 425 int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() -
413 GetItemTileRectAt(0, 0).CenterPoint()).Length() - 426 GetItemTileRectAt(0, 0).CenterPoint()).Length() -
414 kReorderDroppingCircleRadius - 427 kReorderDroppingCircleRadius -
415 kPreferredIconDimension / 2 + 5; 428 kPreferredIconDimension / 2 + 5;
416 gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); 429 gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y());
417 430
418 // Dragging item_1 closing to item_0 should leads to re-ordering these two 431 // Dragging item_1 closing to item_0 should leads to re-ordering these two
419 // items. 432 // items.
420 SimulateDrag(AppsGridView::MOUSE, from, to); 433 SimulateDrag(AppsGridView::MOUSE, from, to);
421 apps_grid_view_->EndDrag(false); 434 apps_grid_view_->EndDrag(false);
422 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 435 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
423 EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent()); 436 EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent());
424 test_api_->LayoutToIdealBounds(); 437 test_api_->LayoutToIdealBounds();
425 } 438 }
426 439
427 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { 440 TEST_F(AppsGridViewTest, MouseDragFolderReorder) {
441 EnsureFoldersEnabled();
442
428 size_t kTotalItems = 2; 443 size_t kTotalItems = 2;
429 model_->CreateAndPopulateFolderWithApps(kTotalItems); 444 model_->CreateAndPopulateFolderWithApps(kTotalItems);
430 model_->PopulateAppWithId(kTotalItems); 445 model_->PopulateAppWithId(kTotalItems);
431 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); 446 EXPECT_EQ(2u, model_->top_level_item_list()->item_count());
432 EXPECT_EQ(AppListFolderItem::kItemType, 447 EXPECT_EQ(AppListFolderItem::kItemType,
433 model_->top_level_item_list()->item_at(0)->GetItemType()); 448 model_->top_level_item_list()->item_at(0)->GetItemType());
434 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( 449 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>(
435 model_->top_level_item_list()->item_at(0)); 450 model_->top_level_item_list()->item_at(0));
436 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id()); 451 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id());
437 452
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 539
525 EXPECT_TRUE(page_flip_waiter.Wait(0)); 540 EXPECT_TRUE(page_flip_waiter.Wait(0));
526 EXPECT_EQ(0, pagination_model_->selected_page()); 541 EXPECT_EQ(0, pagination_model_->selected_page());
527 542
528 EXPECT_FALSE(page_flip_waiter.Wait(100)); 543 EXPECT_FALSE(page_flip_waiter.Wait(100));
529 EXPECT_EQ(0, pagination_model_->selected_page()); 544 EXPECT_EQ(0, pagination_model_->selected_page());
530 apps_grid_view_->EndDrag(true); 545 apps_grid_view_->EndDrag(true);
531 } 546 }
532 547
533 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) { 548 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) {
534 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableFolderUI); 549 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSyncAppList);
535 const int kTotalItems = 4; 550 const int kTotalItems = 4;
536 model_->PopulateApps(kTotalItems); 551 model_->PopulateApps(kTotalItems);
537 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 552 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
538 model_->GetModelContent()); 553 model_->GetModelContent());
539 554
540 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint(); 555 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint();
541 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint(); 556 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint();
542 557
543 gfx::Point touch_from = GetItemTileRectAt(1, 0).CenterPoint(); 558 gfx::Point touch_from = GetItemTileRectAt(1, 0).CenterPoint();
544 gfx::Point touch_to = GetItemTileRectAt(1, 1).CenterPoint(); 559 gfx::Point touch_to = GetItemTileRectAt(1, 1).CenterPoint();
(...skipping 11 matching lines...) Expand all
556 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to); 571 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to);
557 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); 572 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to);
558 // Finishes the drag and touch drag wins. 573 // Finishes the drag and touch drag wins.
559 apps_grid_view_->EndDrag(false); 574 apps_grid_view_->EndDrag(false);
560 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"), 575 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"),
561 model_->GetModelContent()); 576 model_->GetModelContent());
562 test_api_->LayoutToIdealBounds(); 577 test_api_->LayoutToIdealBounds();
563 } 578 }
564 579
565 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) { 580 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) {
581 EnsureFoldersEnabled();
582
566 const int kTotalItems = 4; 583 const int kTotalItems = 4;
567 TestAppsGridViewFolderDelegate folder_delegate; 584 TestAppsGridViewFolderDelegate folder_delegate;
568 apps_grid_view_->set_folder_delegate(&folder_delegate); 585 apps_grid_view_->set_folder_delegate(&folder_delegate);
569 model_->PopulateApps(kTotalItems); 586 model_->PopulateApps(kTotalItems);
570 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 587 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
571 model_->GetModelContent()); 588 model_->GetModelContent());
572 589
573 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint(); 590 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint();
574 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint(); 591 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint();
575 592
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 AppListItemView* item_view = GetItemViewAt(0); 708 AppListItemView* item_view = GetItemViewAt(0);
692 ASSERT_TRUE(item_view); 709 ASSERT_TRUE(item_view);
693 const views::Label* title_label = item_view->title(); 710 const views::Label* title_label = item_view->title();
694 EXPECT_FALSE(title_label->GetTooltipText( 711 EXPECT_FALSE(title_label->GetTooltipText(
695 title_label->bounds().CenterPoint(), &actual_tooltip)); 712 title_label->bounds().CenterPoint(), &actual_tooltip));
696 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 713 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
697 } 714 }
698 715
699 } // namespace test 716 } // namespace test
700 } // namespace app_list 717 } // namespace app_list
OLDNEW
« no previous file with comments | « 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