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 "ash/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 return test_api_->GetButton(index); | 246 return test_api_->GetButton(index); |
247 } | 247 } |
248 | 248 |
249 LauncherItem GetItemByID(LauncherID id) { | 249 LauncherItem GetItemByID(LauncherID id) { |
250 LauncherItems::const_iterator items = model_->ItemByID(id); | 250 LauncherItems::const_iterator items = model_->ItemByID(id); |
251 return *items; | 251 return *items; |
252 } | 252 } |
253 | 253 |
254 void CheckModelIDs( | 254 void CheckModelIDs( |
255 const std::vector<std::pair<LauncherID, views::View*> >& id_map) { | 255 const std::vector<std::pair<LauncherID, views::View*> >& id_map) { |
256 ASSERT_EQ(static_cast<int>(id_map.size()), test_api_->GetButtonCount()); | 256 size_t map_index = 0; |
257 ASSERT_EQ(id_map.size(), model_->items().size()); | 257 for (size_t model_index = 0; |
258 for (size_t i = 0; i < id_map.size(); ++i) { | 258 model_index < model_->items().size(); |
259 EXPECT_EQ(id_map[i].first, model_->items()[i].id); | 259 ++model_index) { |
260 EXPECT_EQ(id_map[i].second, test_api_->GetButton(i)); | 260 ash::LauncherItem item = model_->items()[model_index]; |
261 if (item.type == ash::TYPE_APP_LIST) | |
262 continue; | |
Mattias Nissler (ping if slow)
2012/09/11 08:42:30
seems like this would be easier if we just had a N
DaveMoore
2012/09/11 17:07:00
Done.
Also refactored so it's easier to change whe
| |
263 ash::LauncherID id = item.id; | |
264 EXPECT_EQ(id_map[map_index].first, id); | |
265 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id)); | |
266 ++map_index; | |
261 } | 267 } |
268 ASSERT_EQ(map_index, id_map.size()); | |
262 } | 269 } |
263 | 270 |
264 views::View* SimulateDrag(internal::LauncherButtonHost::Pointer pointer, | 271 views::View* SimulateDrag(internal::LauncherButtonHost::Pointer pointer, |
265 int button_index, | 272 int button_index, |
266 int destination_index) { | 273 int destination_index) { |
274 // Add 1 to each button index to allow for app list. | |
267 internal::LauncherButtonHost* button_host = launcher_view_.get(); | 275 internal::LauncherButtonHost* button_host = launcher_view_.get(); |
268 | 276 |
269 // Mouse down. | 277 // Mouse down. |
270 views::View* button = test_api_->GetButton(button_index); | 278 views::View* button = test_api_->GetButton(button_index + 1); |
271 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, | 279 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, |
272 button->bounds().origin(), | 280 button->bounds().origin(), |
273 button->bounds().origin(), 0); | 281 button->bounds().origin(), 0); |
274 button_host->PointerPressedOnButton(button, pointer, click_event); | 282 button_host->PointerPressedOnButton(button, pointer, click_event); |
275 | 283 |
276 // Drag. | 284 // Drag. |
277 views::View* destination = test_api_->GetButton(destination_index); | 285 views::View* destination = test_api_->GetButton(destination_index + 1); |
278 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, | 286 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, |
279 destination->bounds().origin(), | 287 destination->bounds().origin(), |
280 destination->bounds().origin(), 0); | 288 destination->bounds().origin(), 0); |
281 button_host->PointerDraggedOnButton(button, pointer, drag_event); | 289 button_host->PointerDraggedOnButton(button, pointer, drag_event); |
282 return button; | 290 return button; |
283 } | 291 } |
284 | 292 |
285 void SetupForDragTest( | 293 void SetupForDragTest( |
286 std::vector<std::pair<LauncherID, views::View*> >* id_map) { | 294 std::vector<std::pair<LauncherID, views::View*> >* id_map) { |
287 // Initialize |id_map| with the automatically-created launcher buttons. | 295 // Initialize |id_map| with the automatically-created launcher buttons. |
288 for (size_t i = 0; i < model_->items().size(); ++i) { | 296 for (size_t i = 0; i < model_->items().size(); ++i) { |
289 id_map->push_back(std::make_pair(model_->items()[i].id, | 297 internal::LauncherButton* button = test_api_->GetButton(i); |
290 test_api_->GetButton(i))); | 298 if (!button) |
299 continue; | |
300 | |
301 id_map->push_back(std::make_pair(model_->items()[i].id, button)); | |
291 } | 302 } |
292 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 303 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
293 | 304 |
294 // Add 5 app launcher buttons for testing. | 305 // Add 5 app launcher buttons for testing. |
295 for (int i = 1; i <= 5; ++i) { | 306 for (int i = 0; i < 5; ++i) { |
296 LauncherID id = AddAppShortcut(); | 307 LauncherID id = AddAppShortcut(); |
297 id_map->insert(id_map->begin() + i, | 308 id_map->push_back(std::make_pair(id, GetButtonByID(id))); |
298 std::make_pair(id, test_api_->GetButton(i))); | |
299 } | 309 } |
300 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 310 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
301 } | 311 } |
302 | 312 |
303 views::View* GetTooltipAnchorView() { | 313 views::View* GetTooltipAnchorView() { |
304 return launcher_view_->tooltip_manager()->anchor_; | 314 return launcher_view_->tooltip_manager()->anchor_; |
305 } | 315 } |
306 | 316 |
307 void ShowTooltip() { | 317 void ShowTooltip() { |
308 launcher_view_->tooltip_manager()->ShowInternal(); | 318 launcher_view_->tooltip_manager()->ShowInternal(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 ++added_count; | 429 ++added_count; |
420 } | 430 } |
421 | 431 |
422 // LauncherView should be big enough to hold at least 3 new buttons. | 432 // LauncherView should be big enough to hold at least 3 new buttons. |
423 ASSERT_GE(added_count, 3); | 433 ASSERT_GE(added_count, 3); |
424 | 434 |
425 // Wait for the last animation to finish. | 435 // Wait for the last animation to finish. |
426 test_api_->RunMessageLoopUntilAnimationsDone(); | 436 test_api_->RunMessageLoopUntilAnimationsDone(); |
427 | 437 |
428 // Verifies non-overflow buttons are visible. | 438 // Verifies non-overflow buttons are visible. |
429 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { | 439 for (int i = 1; i <= test_api_->GetLastVisibleIndex(); ++i) { |
430 internal::LauncherButton* button = test_api_->GetButton(i); | 440 internal::LauncherButton* button = test_api_->GetButton(i); |
431 EXPECT_TRUE(button->visible()) << "button index=" << i; | 441 EXPECT_TRUE(button->visible()) << "button index=" << i; |
432 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; | 442 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; |
433 } | 443 } |
434 } | 444 } |
435 | 445 |
436 // Check that model changes are handled correctly while a launcher icon is being | 446 // Check that model changes are handled correctly while a launcher icon is being |
437 // dragged. | 447 // dragged. |
438 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { | 448 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { |
439 internal::LauncherButtonHost* button_host = launcher_view_.get(); | 449 internal::LauncherButtonHost* button_host = launcher_view_.get(); |
(...skipping 10 matching lines...) Expand all Loading... | |
450 // Cancelling the drag operation restores previous order. | 460 // Cancelling the drag operation restores previous order. |
451 button_host->PointerReleasedOnButton(dragged_button, | 461 button_host->PointerReleasedOnButton(dragged_button, |
452 internal::LauncherButtonHost::MOUSE, | 462 internal::LauncherButtonHost::MOUSE, |
453 true); | 463 true); |
454 std::rotate(id_map.begin() + 1, id_map.begin() + 3, id_map.begin() + 4); | 464 std::rotate(id_map.begin() + 1, id_map.begin() + 3, id_map.begin() + 4); |
455 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 465 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
456 | 466 |
457 // Deleting an item keeps the remaining intact. | 467 // Deleting an item keeps the remaining intact. |
458 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | 468 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); |
459 model_->RemoveItemAt(3); | 469 model_->RemoveItemAt(3); |
460 id_map.erase(id_map.begin() + 3); | 470 id_map.erase(id_map.begin() + 2); |
461 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 471 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
462 button_host->PointerReleasedOnButton(dragged_button, | 472 button_host->PointerReleasedOnButton(dragged_button, |
463 internal::LauncherButtonHost::MOUSE, | 473 internal::LauncherButtonHost::MOUSE, |
464 false); | 474 false); |
465 | 475 |
466 // Adding a launcher item cancels the drag and respects the order. | 476 // Adding a launcher item cancels the drag and respects the order. |
467 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | 477 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); |
468 LauncherID new_id = AddAppShortcut(); | 478 LauncherID new_id = AddAppShortcut(); |
469 id_map.insert(id_map.begin() + 5, | 479 id_map.push_back(std::make_pair(new_id, GetButtonByID(new_id))); |
470 std::make_pair(new_id, test_api_->GetButton(5))); | |
471 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 480 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
472 button_host->PointerReleasedOnButton(dragged_button, | 481 button_host->PointerReleasedOnButton(dragged_button, |
473 internal::LauncherButtonHost::MOUSE, | 482 internal::LauncherButtonHost::MOUSE, |
474 false); | 483 false); |
475 } | 484 } |
476 | 485 |
477 // Check that 2nd drag from the other pointer would be ignored. | 486 // Check that 2nd drag from the other pointer would be ignored. |
478 TEST_F(LauncherViewTest, SimultaneousDrag) { | 487 TEST_F(LauncherViewTest, SimultaneousDrag) { |
479 internal::LauncherButtonHost* button_host = launcher_view_.get(); | 488 internal::LauncherButtonHost* button_host = launcher_view_.get(); |
480 | 489 |
481 std::vector<std::pair<LauncherID, views::View*> > id_map; | 490 std::vector<std::pair<LauncherID, views::View*> > id_map; |
482 SetupForDragTest(&id_map); | 491 SetupForDragTest(&id_map); |
483 | 492 |
484 // Start a mouse drag. | 493 // Start a mouse drag. |
485 views::View* dragged_button_mouse = SimulateDrag( | 494 views::View* dragged_button_mouse = SimulateDrag( |
486 internal::LauncherButtonHost::MOUSE, 1, 3); | 495 internal::LauncherButtonHost::MOUSE, 1, 3); |
487 std::rotate(id_map.begin() + 1, id_map.begin() + 2, id_map.begin() + 4); | 496 std::rotate(id_map.begin() + 1, id_map.begin() + 2, id_map.begin() + 4); |
488 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 497 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
489 | |
490 // Attempt a touch drag before the mouse drag finishes. | 498 // Attempt a touch drag before the mouse drag finishes. |
491 views::View* dragged_button_touch = SimulateDrag( | 499 views::View* dragged_button_touch = SimulateDrag( |
492 internal::LauncherButtonHost::TOUCH, 4, 2); | 500 internal::LauncherButtonHost::TOUCH, 4, 2); |
493 | 501 |
494 // Nothing changes since 2nd drag is ignored. | 502 // Nothing changes since 2nd drag is ignored. |
495 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 503 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
496 | 504 |
497 // Finish the mouse drag. | 505 // Finish the mouse drag. |
498 button_host->PointerReleasedOnButton(dragged_button_mouse, | 506 button_host->PointerReleasedOnButton(dragged_button_mouse, |
499 internal::LauncherButtonHost::MOUSE, | 507 internal::LauncherButtonHost::MOUSE, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 button_host->MouseEnteredButton(tab_button); | 610 button_host->MouseEnteredButton(tab_button); |
603 EXPECT_FALSE(tooltip_manager->IsVisible()); | 611 EXPECT_FALSE(tooltip_manager->IsVisible()); |
604 EXPECT_EQ(tab_button, GetTooltipAnchorView()); | 612 EXPECT_EQ(tab_button, GetTooltipAnchorView()); |
605 } | 613 } |
606 | 614 |
607 TEST_F(LauncherViewTest, ShouldHideTooltipTest) { | 615 TEST_F(LauncherViewTest, ShouldHideTooltipTest) { |
608 LauncherID app_button_id = AddAppShortcut(); | 616 LauncherID app_button_id = AddAppShortcut(); |
609 LauncherID tab_button_id = AddTabbedBrowser(); | 617 LauncherID tab_button_id = AddTabbedBrowser(); |
610 | 618 |
611 // The tooltip shouldn't hide if the mouse is on normal buttons. | 619 // The tooltip shouldn't hide if the mouse is on normal buttons. |
612 for (int i = 0; i < test_api_->GetButtonCount() - 1; i++) { | 620 for (int i = 0; i < test_api_->GetButtonCount(); i++) { |
613 internal::LauncherButton* button = test_api_->GetButton(i); | 621 internal::LauncherButton* button = test_api_->GetButton(i); |
622 if (!button) | |
623 continue; | |
624 | |
614 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( | 625 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( |
615 button->GetMirroredBounds().CenterPoint())) | 626 button->GetMirroredBounds().CenterPoint())) |
616 << "LauncherView tries to hide on button " << i; | 627 << "LauncherView tries to hide on button " << i; |
617 } | 628 } |
618 | 629 |
619 // The tooltip should not hide on the app-list button. | 630 // The tooltip should not hide on the app-list button. |
620 views::View* app_list_button = launcher_view_->GetAppListButtonView(); | 631 views::View* app_list_button = launcher_view_->GetAppListButtonView(); |
621 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( | 632 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( |
622 app_list_button->GetMirroredBounds().CenterPoint())); | 633 app_list_button->GetMirroredBounds().CenterPoint())); |
623 | 634 |
624 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. | 635 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. |
625 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); | 636 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); |
626 gfx::Rect tab_button_rect = GetButtonByID(tab_button_id)->GetMirroredBounds(); | 637 gfx::Rect tab_button_rect = GetButtonByID(tab_button_id)->GetMirroredBounds(); |
627 ASSERT_FALSE(app_button_rect.Intersects(tab_button_rect)); | 638 ASSERT_FALSE(app_button_rect.Intersects(tab_button_rect)); |
628 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( | 639 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( |
629 app_button_rect.Union(tab_button_rect).CenterPoint())); | 640 app_button_rect.Union(tab_button_rect).CenterPoint())); |
630 | 641 |
631 // The tooltip should hide if it's outside of all buttons. | 642 // The tooltip should hide if it's outside of all buttons. |
632 gfx::Rect all_area; | 643 gfx::Rect all_area; |
633 for (int i = 0; i < test_api_->GetButtonCount() - 1; i++) { | 644 for (int i = 0; i < test_api_->GetButtonCount(); i++) { |
634 all_area = all_area.Union(test_api_->GetButton(i)->GetMirroredBounds()); | 645 internal::LauncherButton* button = test_api_->GetButton(i); |
646 if (!button) | |
647 continue; | |
648 | |
649 all_area = all_area.Union(button->GetMirroredBounds()); | |
635 } | 650 } |
636 all_area = all_area.Union( | 651 all_area = all_area.Union( |
637 launcher_view_->GetAppListButtonView()->GetMirroredBounds()); | 652 launcher_view_->GetAppListButtonView()->GetMirroredBounds()); |
638 EXPECT_FALSE(launcher_view_->ShouldHideTooltip(all_area.origin())); | 653 EXPECT_FALSE(launcher_view_->ShouldHideTooltip(all_area.origin())); |
639 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( | 654 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( |
640 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); | 655 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); |
641 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( | 656 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( |
642 gfx::Point(all_area.right(), all_area.y()))); | 657 gfx::Point(all_area.right(), all_area.y()))); |
643 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( | 658 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( |
644 gfx::Point(all_area.x() - 1, all_area.y()))); | 659 gfx::Point(all_area.x() - 1, all_area.y()))); |
645 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( | 660 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( |
646 gfx::Point(all_area.x(), all_area.y() - 1))); | 661 gfx::Point(all_area.x(), all_area.y() - 1))); |
647 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( | 662 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( |
648 gfx::Point(all_area.x(), all_area.bottom()))); | 663 gfx::Point(all_area.x(), all_area.bottom()))); |
649 } | 664 } |
650 | 665 |
651 TEST_F(LauncherViewTest, ShouldHideTooltipWithAppListWindowTest) { | 666 TEST_F(LauncherViewTest, ShouldHideTooltipWithAppListWindowTest) { |
652 Shell::GetInstance()->ToggleAppList(); | 667 Shell::GetInstance()->ToggleAppList(); |
653 ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow()); | 668 ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow()); |
654 | 669 |
655 // The tooltip shouldn't hide if the mouse is on normal buttons. | 670 // The tooltip shouldn't hide if the mouse is on normal buttons. |
656 for (int i = 0; i < test_api_->GetButtonCount() - 1; i++) { | 671 for (int i = 1; i < test_api_->GetButtonCount(); i++) { |
657 internal::LauncherButton* button = test_api_->GetButton(i); | 672 internal::LauncherButton* button = test_api_->GetButton(i); |
673 if (!button) | |
674 continue; | |
675 | |
658 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( | 676 EXPECT_FALSE(launcher_view_->ShouldHideTooltip( |
659 button->GetMirroredBounds().CenterPoint())) | 677 button->GetMirroredBounds().CenterPoint())) |
660 << "LauncherView tries to hide on button " << i; | 678 << "LauncherView tries to hide on button " << i; |
661 } | 679 } |
662 | 680 |
663 // The tooltip should hide on the app-list button. | 681 // The tooltip should hide on the app-list button. |
664 views::View* app_list_button = launcher_view_->GetAppListButtonView(); | 682 views::View* app_list_button = launcher_view_->GetAppListButtonView(); |
665 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( | 683 EXPECT_TRUE(launcher_view_->ShouldHideTooltip( |
666 app_list_button->GetMirroredBounds().CenterPoint())); | 684 app_list_button->GetMirroredBounds().CenterPoint())); |
667 } | 685 } |
(...skipping 27 matching lines...) Expand all Loading... | |
695 const int app_list_button_index = test_api_->GetButtonCount() - 1; | 713 const int app_list_button_index = test_api_->GetButtonCount() - 1; |
696 const gfx::Rect& app_list_ideal_bounds = | 714 const gfx::Rect& app_list_ideal_bounds = |
697 test_api_->GetIdealBoundsByIndex(app_list_button_index); | 715 test_api_->GetIdealBoundsByIndex(app_list_button_index); |
698 const gfx::Rect& app_list_bounds = | 716 const gfx::Rect& app_list_bounds = |
699 test_api_->GetBoundsByIndex(app_list_button_index); | 717 test_api_->GetBoundsByIndex(app_list_button_index); |
700 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); | 718 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); |
701 } | 719 } |
702 | 720 |
703 } // namespace test | 721 } // namespace test |
704 } // namespace ash | 722 } // namespace ash |
OLD | NEW |