OLD | NEW |
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // Adding a launcher item cancels the drag and respects the order. | 303 // Adding a launcher item cancels the drag and respects the order. |
304 SimulateDrag(AppsGridView::MOUSE, from, to); | 304 SimulateDrag(AppsGridView::MOUSE, from, to); |
305 model_->CreateAndAddItem("Extra"); | 305 model_->CreateAndAddItem("Extra"); |
306 apps_grid_view_->EndDrag(false); | 306 apps_grid_view_->EndDrag(false); |
307 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), | 307 EXPECT_EQ(std::string("Item 1,Item 2,Item 3,Extra"), |
308 model_->GetModelContent()); | 308 model_->GetModelContent()); |
309 test_api_->LayoutToIdealBounds(); | 309 test_api_->LayoutToIdealBounds(); |
310 } | 310 } |
311 | 311 |
312 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { | 312 TEST_F(AppsGridViewTest, MouseDragItemIntoFolder) { |
| 313 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFolderUI); |
313 size_t kTotalItems = 3; | 314 size_t kTotalItems = 3; |
314 model_->PopulateApps(kTotalItems); | 315 model_->PopulateApps(kTotalItems); |
315 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); | 316 EXPECT_EQ(model_->top_level_item_list()->item_count(), kTotalItems); |
316 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent()); | 317 EXPECT_EQ(std::string("Item 0,Item 1,Item 2"), model_->GetModelContent()); |
317 | 318 |
318 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); | 319 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); |
319 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); | 320 gfx::Point to = GetItemTileRectAt(0, 0).CenterPoint(); |
320 | 321 |
321 // Dragging item_1 over item_0 creates a folder. | 322 // Dragging item_1 over item_0 creates a folder. |
322 SimulateDrag(AppsGridView::MOUSE, from, to); | 323 SimulateDrag(AppsGridView::MOUSE, from, to); |
(...skipping 27 matching lines...) Expand all Loading... |
350 item_1 = model_->FindItem("Item 1"); | 351 item_1 = model_->FindItem("Item 1"); |
351 EXPECT_TRUE(item_1->IsInFolder()); | 352 EXPECT_TRUE(item_1->IsInFolder()); |
352 EXPECT_EQ(folder_item->id(), item_1->folder_id()); | 353 EXPECT_EQ(folder_item->id(), item_1->folder_id()); |
353 AppListItem* item_2 = model_->FindItem("Item 2"); | 354 AppListItem* item_2 = model_->FindItem("Item 2"); |
354 EXPECT_TRUE(item_2->IsInFolder()); | 355 EXPECT_TRUE(item_2->IsInFolder()); |
355 EXPECT_EQ(folder_item->id(), item_2->folder_id()); | 356 EXPECT_EQ(folder_item->id(), item_2->folder_id()); |
356 test_api_->LayoutToIdealBounds(); | 357 test_api_->LayoutToIdealBounds(); |
357 } | 358 } |
358 | 359 |
359 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) { | 360 TEST_F(AppsGridViewTest, MouseDragMaxItemsInFolder) { |
| 361 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFolderUI); |
360 // Create and add a folder with 15 items in it. | 362 // Create and add a folder with 15 items in it. |
361 size_t kTotalItems = kMaxFolderItems - 1; | 363 size_t kTotalItems = kMaxFolderItems - 1; |
362 model_->CreateAndPopulateFolderWithApps(kTotalItems); | 364 model_->CreateAndPopulateFolderWithApps(kTotalItems); |
363 EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); | 365 EXPECT_EQ(1u, model_->top_level_item_list()->item_count()); |
364 EXPECT_EQ(AppListFolderItem::kItemType, | 366 EXPECT_EQ(AppListFolderItem::kItemType, |
365 model_->top_level_item_list()->item_at(0)->GetItemType()); | 367 model_->top_level_item_list()->item_at(0)->GetItemType()); |
366 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( | 368 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( |
367 model_->top_level_item_list()->item_at(0)); | 369 model_->top_level_item_list()->item_at(0)); |
368 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); | 370 EXPECT_EQ(kTotalItems, folder_item->ChildItemCount()); |
369 | 371 |
(...skipping 26 matching lines...) Expand all Loading... |
396 apps_grid_view_->EndDrag(false); | 398 apps_grid_view_->EndDrag(false); |
397 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 399 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
398 EXPECT_EQ(model_->GetItemName(kMaxFolderItems), | 400 EXPECT_EQ(model_->GetItemName(kMaxFolderItems), |
399 model_->top_level_item_list()->item_at(0)->id()); | 401 model_->top_level_item_list()->item_at(0)->id()); |
400 EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id()); | 402 EXPECT_EQ(folder_item->id(), model_->top_level_item_list()->item_at(1)->id()); |
401 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); | 403 EXPECT_EQ(kMaxFolderItems, folder_item->ChildItemCount()); |
402 test_api_->LayoutToIdealBounds(); | 404 test_api_->LayoutToIdealBounds(); |
403 } | 405 } |
404 | 406 |
405 TEST_F(AppsGridViewTest, MouseDragItemReorder) { | 407 TEST_F(AppsGridViewTest, MouseDragItemReorder) { |
| 408 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFolderUI); |
406 size_t kTotalItems = 2; | 409 size_t kTotalItems = 2; |
407 model_->PopulateApps(kTotalItems); | 410 model_->PopulateApps(kTotalItems); |
408 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 411 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
409 EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent()); | 412 EXPECT_EQ(std::string("Item 0,Item 1"), model_->GetModelContent()); |
410 | 413 |
411 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); | 414 gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); |
412 int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - | 415 int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - |
413 GetItemTileRectAt(0, 0).CenterPoint()).Length() - | 416 GetItemTileRectAt(0, 0).CenterPoint()).Length() - |
414 kReorderDroppingCircleRadius - | 417 kReorderDroppingCircleRadius - |
415 kPreferredIconDimension / 2 + 5; | 418 kPreferredIconDimension / 2 + 5; |
416 gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); | 419 gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); |
417 | 420 |
418 // Dragging item_1 closing to item_0 should leads to re-ordering these two | 421 // Dragging item_1 closing to item_0 should leads to re-ordering these two |
419 // items. | 422 // items. |
420 SimulateDrag(AppsGridView::MOUSE, from, to); | 423 SimulateDrag(AppsGridView::MOUSE, from, to); |
421 apps_grid_view_->EndDrag(false); | 424 apps_grid_view_->EndDrag(false); |
422 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 425 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
423 EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent()); | 426 EXPECT_EQ(std::string("Item 1,Item 0"), model_->GetModelContent()); |
424 test_api_->LayoutToIdealBounds(); | 427 test_api_->LayoutToIdealBounds(); |
425 } | 428 } |
426 | 429 |
427 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { | 430 TEST_F(AppsGridViewTest, MouseDragFolderReorder) { |
| 431 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFolderUI); |
428 size_t kTotalItems = 2; | 432 size_t kTotalItems = 2; |
429 model_->CreateAndPopulateFolderWithApps(kTotalItems); | 433 model_->CreateAndPopulateFolderWithApps(kTotalItems); |
430 model_->PopulateAppWithId(kTotalItems); | 434 model_->PopulateAppWithId(kTotalItems); |
431 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); | 435 EXPECT_EQ(2u, model_->top_level_item_list()->item_count()); |
432 EXPECT_EQ(AppListFolderItem::kItemType, | 436 EXPECT_EQ(AppListFolderItem::kItemType, |
433 model_->top_level_item_list()->item_at(0)->GetItemType()); | 437 model_->top_level_item_list()->item_at(0)->GetItemType()); |
434 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( | 438 AppListFolderItem* folder_item = static_cast<AppListFolderItem*>( |
435 model_->top_level_item_list()->item_at(0)); | 439 model_->top_level_item_list()->item_at(0)); |
436 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id()); | 440 EXPECT_EQ("Item 2", model_->top_level_item_list()->item_at(1)->id()); |
437 | 441 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 AppListItemView* item_view = GetItemViewAt(0); | 695 AppListItemView* item_view = GetItemViewAt(0); |
692 ASSERT_TRUE(item_view); | 696 ASSERT_TRUE(item_view); |
693 const views::Label* title_label = item_view->title(); | 697 const views::Label* title_label = item_view->title(); |
694 EXPECT_FALSE(title_label->GetTooltipText( | 698 EXPECT_FALSE(title_label->GetTooltipText( |
695 title_label->bounds().CenterPoint(), &actual_tooltip)); | 699 title_label->bounds().CenterPoint(), &actual_tooltip)); |
696 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 700 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
697 } | 701 } |
698 | 702 |
699 } // namespace test | 703 } // namespace test |
700 } // namespace app_list | 704 } // namespace app_list |
OLD | NEW |