| 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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 485 |
| 486 void AddButtonsUntilOverflow() { | 486 void AddButtonsUntilOverflow() { |
| 487 int items_added = 0; | 487 int items_added = 0; |
| 488 while (!test_api_->IsOverflowButtonVisible()) { | 488 while (!test_api_->IsOverflowButtonVisible()) { |
| 489 AddAppShortcut(); | 489 AddAppShortcut(); |
| 490 ++items_added; | 490 ++items_added; |
| 491 ASSERT_LT(items_added, 10000); | 491 ASSERT_LT(items_added, 10000); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| 495 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { | 495 // Helper function for testing dragging an item off one shelf to another |
| 496 // shelf. |main_to_overflow| is true if we are moving the item from the main |
| 497 // shelf to the overflow shelf; it is false if we are moving the item from the |
| 498 // overflow shelf to the main shelf. |cancel| is true if we want to cancel the |
| 499 // dragging halfway through. |
| 500 void TestDraggingAnItemFromShelfToOtherShelf(bool main_to_overflow, |
| 501 bool cancel) { |
| 496 test_api_->ShowOverflowBubble(); | 502 test_api_->ShowOverflowBubble(); |
| 497 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 503 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 498 | 504 |
| 499 ShelfViewTestAPI test_api_for_overflow( | 505 ShelfViewTestAPI test_api_for_overflow( |
| 500 test_api_->overflow_bubble()->shelf_view()); | 506 test_api_->overflow_bubble()->shelf_view()); |
| 501 | 507 |
| 502 int total_item_count = model_->item_count(); | 508 int total_item_count = model_->item_count(); |
| 503 | 509 |
| 510 // Intialize some ids to test after the drag operation is canceled or |
| 511 // completed. These ids are set assuming the both the main shelf and |
| 512 // overflow shelf has more than 3 items. |
| 504 ShelfID last_visible_item_id_in_shelf = | 513 ShelfID last_visible_item_id_in_shelf = |
| 505 GetItemId(test_api_->GetLastVisibleIndex()); | 514 GetItemId(test_api_->GetLastVisibleIndex()); |
| 506 ShelfID second_last_visible_item_id_in_shelf = | 515 ShelfID second_last_visible_item_id_in_shelf = |
| 507 GetItemId(test_api_->GetLastVisibleIndex() - 1); | 516 GetItemId(test_api_->GetLastVisibleIndex() - 1); |
| 508 ShelfID first_visible_item_id_in_overflow = | 517 ShelfID first_visible_item_id_in_overflow = |
| 509 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); | 518 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); |
| 510 ShelfID second_last_visible_item_id_in_overflow = | 519 ShelfID second_last_visible_item_id_in_overflow = |
| 511 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); | 520 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); |
| 512 | 521 |
| 513 int drag_item_index = test_api_for_overflow.GetLastVisibleIndex(); | 522 // |src_api| represents the test api of the shelf we are moving the item |
| 523 // from. |dest_api| represents the test api of the shelf we are moving the |
| 524 // item too. |
| 525 ShelfViewTestAPI* src_api = |
| 526 main_to_overflow ? test_api_.get() : &test_api_for_overflow; |
| 527 ShelfViewTestAPI* dest_api = |
| 528 main_to_overflow ? &test_api_for_overflow : test_api_.get(); |
| 529 |
| 530 // Set the item to be dragged depending on |main_to_overflow|. |
| 531 int drag_item_index = main_to_overflow ? 1 : src_api->GetLastVisibleIndex(); |
| 514 ShelfID drag_item_id = GetItemId(drag_item_index); | 532 ShelfID drag_item_id = GetItemId(drag_item_index); |
| 515 ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index); | 533 ShelfButton* drag_button = src_api->GetButton(drag_item_index); |
| 516 gfx::Point center_point_of_drag_item = | 534 gfx::Point center_point_of_drag_item = GetButtonCenter(drag_button); |
| 517 drag_button->GetBoundsInScreen().CenterPoint(); | |
| 518 | 535 |
| 519 ui::test::EventGenerator& generator = GetEventGenerator(); | 536 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 520 generator.set_current_location(center_point_of_drag_item); | 537 generator.set_current_location(center_point_of_drag_item); |
| 521 // Rip an item off to OverflowBubble. | 538 // Rip an item off this source shelf. |
| 522 generator.PressLeftButton(); | 539 generator.PressLeftButton(); |
| 523 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); | 540 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); |
| 524 generator.MoveMouseTo(rip_off_point); | 541 generator.MoveMouseTo(rip_off_point); |
| 525 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 542 src_api->RunMessageLoopUntilAnimationsDone(); |
| 526 ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf()); | 543 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 527 ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 544 ASSERT_TRUE(src_api->IsRippedOffFromShelf()); |
| 545 ASSERT_FALSE(src_api->DraggedItemToAnotherShelf()); |
| 528 | 546 |
| 529 // Move a dragged item into Shelf at |drop_index|. | 547 // Move a dragged item into the destination shelf at |drop_index|. |
| 530 int drop_index = 1; | 548 int drop_index = main_to_overflow ? dest_api->GetLastVisibleIndex() : 1; |
| 531 gfx::Point drop_point = | 549 ShelfButton* drop_button = dest_api->GetButton(drop_index); |
| 532 test_api_->GetButton(drop_index)->GetBoundsInScreen().CenterPoint(); | 550 gfx::Point drop_point = GetButtonCenter(drop_button); |
| 533 // To insert at |drop_index|, more smaller x-axis value of |drop_point| | 551 // To insert at |drop_index|, a smaller x-axis value of |drop_point| |
| 534 // should be used. | 552 // should be used. If |drop_index| is the last item, a larger x-axis |
| 535 gfx::Point modified_drop_point(drop_point.x() - kShelfButtonSize / 4, | 553 // value of |drop_point| should be used. |
| 554 int drop_point_x_shift = |
| 555 main_to_overflow ? kShelfButtonSize / 4 : -kShelfButtonSize / 4; |
| 556 gfx::Point modified_drop_point(drop_point.x() + drop_point_x_shift, |
| 536 drop_point.y()); | 557 drop_point.y()); |
| 537 generator.MoveMouseTo(modified_drop_point); | 558 generator.MoveMouseTo(modified_drop_point); |
| 538 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 559 src_api->RunMessageLoopUntilAnimationsDone(); |
| 539 test_api_->RunMessageLoopUntilAnimationsDone(); | 560 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 540 ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf()); | 561 ASSERT_TRUE(src_api->IsRippedOffFromShelf()); |
| 541 ASSERT_TRUE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 562 ASSERT_TRUE(src_api->DraggedItemToAnotherShelf()); |
| 542 | 563 |
| 543 if (cancel) | 564 if (cancel) |
| 544 drag_button->OnMouseCaptureLost(); | 565 drag_button->OnMouseCaptureLost(); |
| 545 else | |
| 546 generator.ReleaseLeftButton(); | |
| 547 | 566 |
| 548 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 567 generator.ReleaseLeftButton(); |
| 549 test_api_->RunMessageLoopUntilAnimationsDone(); | 568 |
| 550 ASSERT_FALSE(test_api_for_overflow.IsRippedOffFromShelf()); | 569 src_api->RunMessageLoopUntilAnimationsDone(); |
| 551 ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 570 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 571 ASSERT_FALSE(src_api->IsRippedOffFromShelf()); |
| 572 ASSERT_FALSE(src_api->DraggedItemToAnotherShelf()); |
| 552 | 573 |
| 553 // Compare pre-stored items' id with newly positioned items' after dragging | 574 // Compare pre-stored items' id with newly positioned items' after dragging |
| 554 // is canceled or finished. | 575 // is canceled or finished. |
| 555 if (cancel) { | 576 if (cancel) { |
| 577 // Item ids should remain unchanged if operation was canceled. |
| 556 EXPECT_EQ(last_visible_item_id_in_shelf, | 578 EXPECT_EQ(last_visible_item_id_in_shelf, |
| 557 GetItemId(test_api_->GetLastVisibleIndex())); | 579 GetItemId(test_api_->GetLastVisibleIndex())); |
| 558 EXPECT_EQ(second_last_visible_item_id_in_shelf, | 580 EXPECT_EQ(second_last_visible_item_id_in_shelf, |
| 559 GetItemId(test_api_->GetLastVisibleIndex() - 1)); | 581 GetItemId(test_api_->GetLastVisibleIndex() - 1)); |
| 560 EXPECT_EQ(first_visible_item_id_in_overflow, | 582 EXPECT_EQ(first_visible_item_id_in_overflow, |
| 561 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); | 583 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); |
| 562 EXPECT_EQ(second_last_visible_item_id_in_overflow, | 584 EXPECT_EQ(second_last_visible_item_id_in_overflow, |
| 563 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1)); | 585 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1)); |
| 564 } else { | 586 } else { |
| 565 EXPECT_EQ(drag_item_id, GetItemId(drop_index)); | 587 EXPECT_EQ(drag_item_id, GetItemId(drop_index)); |
| 566 EXPECT_EQ(total_item_count, model_->item_count()); | 588 EXPECT_EQ(total_item_count, model_->item_count()); |
| 567 EXPECT_EQ(last_visible_item_id_in_shelf, | 589 |
| 568 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); | 590 if (main_to_overflow) { |
| 569 EXPECT_EQ(second_last_visible_item_id_in_shelf, | 591 // If we move an item from the main shelf to the overflow shelf, the |
| 570 GetItemId(test_api_->GetLastVisibleIndex())); | 592 // following should happen: |
| 571 EXPECT_EQ(first_visible_item_id_in_overflow, | 593 // 1) The former last item on the main shelf should now be the second |
| 572 GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1)); | 594 // last item on the main shelf. |
| 573 EXPECT_EQ(second_last_visible_item_id_in_overflow, | 595 // 2) The former first item on the overflow shelf should now be the last |
| 574 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); | 596 // item on the main shelf. |
| 597 // 3) The dragged item should now be the last item on the main shelf. |
| 598 EXPECT_EQ(last_visible_item_id_in_shelf, |
| 599 GetItemId(test_api_->GetLastVisibleIndex() - 1)); |
| 600 EXPECT_EQ(first_visible_item_id_in_overflow, |
| 601 GetItemId(test_api_->GetLastVisibleIndex())); |
| 602 EXPECT_EQ(drag_item_id, |
| 603 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); |
| 604 } else { |
| 605 // If we move an item from the overflow shelf to the main shelf, the |
| 606 // following should happen: |
| 607 // 1) The former last item on the main shelf should now be the first |
| 608 // item on the overflow shelf. |
| 609 // 2) The former second last item on the main shelf should now be the |
| 610 // last item on the main shelf. |
| 611 // 3) The former first item on the overflow shelf should now be the |
| 612 // second item on the overflow shelf. |
| 613 // 4) The former second item on the overflow shelf should now be the |
| 614 // last item on the overflow shelf (since there are 3 items on the |
| 615 // overflow shelf). |
| 616 EXPECT_EQ(last_visible_item_id_in_shelf, |
| 617 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); |
| 618 EXPECT_EQ(second_last_visible_item_id_in_shelf, |
| 619 GetItemId(test_api_->GetLastVisibleIndex())); |
| 620 EXPECT_EQ(first_visible_item_id_in_overflow, |
| 621 GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1)); |
| 622 EXPECT_EQ(second_last_visible_item_id_in_overflow, |
| 623 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); |
| 624 } |
| 575 } | 625 } |
| 576 test_api_->HideOverflowBubble(); | 626 test_api_->HideOverflowBubble(); |
| 577 } | 627 } |
| 578 | 628 |
| 579 // Returns the item's ShelfID at |index|. | 629 // Returns the item's ShelfID at |index|. |
| 580 ShelfID GetItemId(int index) { | 630 ShelfID GetItemId(int index) { |
| 581 DCHECK_GE(index, 0); | 631 DCHECK_GE(index, 0); |
| 582 return model_->items()[index].id; | 632 return model_->items()[index].id; |
| 583 } | 633 } |
| 584 | 634 |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 ui::test::EventGenerator generator(Shell::GetAllRootWindows()[1], | 1722 ui::test::EventGenerator generator(Shell::GetAllRootWindows()[1], |
| 1673 start_point); | 1723 start_point); |
| 1674 | 1724 |
| 1675 // Rip off the browser item. | 1725 // Rip off the browser item. |
| 1676 generator.PressLeftButton(); | 1726 generator.PressLeftButton(); |
| 1677 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); | 1727 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); |
| 1678 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone(); | 1728 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone(); |
| 1679 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf()); | 1729 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf()); |
| 1680 } | 1730 } |
| 1681 | 1731 |
| 1682 // Checks various drag and drop operations from OverflowBubble to Shelf. | 1732 // Checks various drag and drop operations from OverflowBubble to Shelf, and |
| 1683 TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) { | 1733 // vice versa. |
| 1734 TEST_F(ShelfViewTest, CheckDragAndDropFromShelfToOtherShelf) { |
| 1684 AddButtonsUntilOverflow(); | 1735 AddButtonsUntilOverflow(); |
| 1685 // Add one more button to prevent the overflow bubble to disappear upon | 1736 // Add one more button to prevent the overflow bubble to disappear upon |
| 1686 // dragging an item out on windows (flakiness, see crbug.com/425097). | 1737 // dragging an item out on windows (flakiness, see crbug.com/425097). |
| 1687 AddAppShortcut(); | 1738 AddAppShortcut(); |
| 1688 | 1739 |
| 1689 TestDraggingAnItemFromOverflowToShelf(false); | 1740 TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */, |
| 1690 TestDraggingAnItemFromOverflowToShelf(true); | 1741 false /* cancel */); |
| 1742 TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */, |
| 1743 true /* cancel */); |
| 1744 |
| 1745 TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */, |
| 1746 false /* cancel */); |
| 1747 TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */, |
| 1748 true /* cancel */); |
| 1691 } | 1749 } |
| 1692 | 1750 |
| 1693 // Checks creating app shortcut for an opened platform app in overflow bubble | 1751 // Checks creating app shortcut for an opened platform app in overflow bubble |
| 1694 // should be invisible to the shelf. See crbug.com/605793. | 1752 // should be invisible to the shelf. See crbug.com/605793. |
| 1695 TEST_F(ShelfViewTest, CheckOverflowStatusPinOpenedAppToShelf) { | 1753 TEST_F(ShelfViewTest, CheckOverflowStatusPinOpenedAppToShelf) { |
| 1696 AddButtonsUntilOverflow(); | 1754 AddButtonsUntilOverflow(); |
| 1697 | 1755 |
| 1698 // Add a running Platform app. | 1756 // Add a running Platform app. |
| 1699 ShelfID platform_app_id = AddApp(); | 1757 ShelfID platform_app_id = AddApp(); |
| 1700 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); | 1758 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3057 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3115 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3058 overflow_button_ink_drop_->GetTargetInkDropState()); | 3116 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3059 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3117 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3060 IsEmpty()); | 3118 IsEmpty()); |
| 3061 | 3119 |
| 3062 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3120 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3063 } | 3121 } |
| 3064 | 3122 |
| 3065 } // namespace test | 3123 } // namespace test |
| 3066 } // namespace ash | 3124 } // namespace ash |
| OLD | NEW |