Chromium Code Reviews| 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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 | 585 |
| 586 void AddButtonsUntilOverflow() { | 586 void AddButtonsUntilOverflow() { |
| 587 int items_added = 0; | 587 int items_added = 0; |
| 588 while (!test_api_->IsOverflowButtonVisible()) { | 588 while (!test_api_->IsOverflowButtonVisible()) { |
| 589 AddAppShortcut(); | 589 AddAppShortcut(); |
| 590 ++items_added; | 590 ++items_added; |
| 591 ASSERT_LT(items_added, 10000); | 591 ASSERT_LT(items_added, 10000); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { | 595 // Helper function for testing dragging an item off one shelf to another |
| 596 // shelf. |main_to_overflow| is true if we are moving the item from the main | |
| 597 // shelf to the overflow shelf; it is false if we are moving the item from the | |
| 598 // overflow shelf to the main shelf. |cancel| is true if we want to cancel the | |
| 599 // dragging halfway through. | |
| 600 void TestDraggingAnItemFromShelfToOtherShelf(bool main_to_overflow, | |
| 601 bool cancel) { | |
| 596 test_api_->ShowOverflowBubble(); | 602 test_api_->ShowOverflowBubble(); |
| 597 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 603 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 598 | 604 |
| 599 ShelfViewTestAPI test_api_for_overflow( | 605 ShelfViewTestAPI test_api_for_overflow( |
| 600 test_api_->overflow_bubble()->shelf_view()); | 606 test_api_->overflow_bubble()->shelf_view()); |
| 601 | 607 |
| 602 int total_item_count = model_->item_count(); | 608 int total_item_count = model_->item_count(); |
| 603 | 609 |
| 610 // Intialize some ids to test after the drag operation is canceled or | |
| 611 // completed. These ids are set assuming the both the main shelf and | |
| 612 // overflow shelf has more than 3 items. | |
| 604 ShelfID last_visible_item_id_in_shelf = | 613 ShelfID last_visible_item_id_in_shelf = |
| 605 GetItemId(test_api_->GetLastVisibleIndex()); | 614 GetItemId(test_api_->GetLastVisibleIndex()); |
| 606 ShelfID second_last_visible_item_id_in_shelf = | 615 ShelfID second_last_visible_item_id_in_shelf = |
| 607 GetItemId(test_api_->GetLastVisibleIndex() - 1); | 616 GetItemId(test_api_->GetLastVisibleIndex() - 1); |
| 608 ShelfID first_visible_item_id_in_overflow = | 617 ShelfID first_visible_item_id_in_overflow = |
| 609 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); | 618 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); |
| 610 ShelfID second_last_visible_item_id_in_overflow = | 619 ShelfID second_last_visible_item_id_in_overflow = |
| 611 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); | 620 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); |
| 612 | 621 |
| 613 int drag_item_index = test_api_for_overflow.GetLastVisibleIndex(); | 622 // |src_api| represents the test api of the shelf we are moving the item |
| 623 // from. |dest_api| represents the test api of the shelf we are moving the | |
| 624 // item too. | |
| 625 ShelfViewTestAPI* src_api = | |
| 626 main_to_overflow ? test_api_.get() : &test_api_for_overflow; | |
| 627 ShelfViewTestAPI* dest_api = | |
| 628 main_to_overflow ? &test_api_for_overflow : test_api_.get(); | |
| 629 | |
| 630 // Set the item to be dragged depending on |main_to_overflow|. | |
| 631 int drag_item_index = main_to_overflow ? 1 : src_api->GetLastVisibleIndex(); | |
| 614 ShelfID drag_item_id = GetItemId(drag_item_index); | 632 ShelfID drag_item_id = GetItemId(drag_item_index); |
| 615 ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index); | 633 ShelfButton* drag_button = src_api->GetButton(drag_item_index); |
| 616 gfx::Point center_point_of_drag_item = | 634 gfx::Point center_point_of_drag_item = GetButtonCenter(drag_button); |
| 617 drag_button->GetBoundsInScreen().CenterPoint(); | |
| 618 | 635 |
| 619 ui::test::EventGenerator& generator = GetEventGenerator(); | 636 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 620 generator.set_current_location(center_point_of_drag_item); | 637 generator.set_current_location(center_point_of_drag_item); |
| 621 // Rip an item off to OverflowBubble. | 638 // Rip an item off this source shelf. |
| 622 generator.PressLeftButton(); | 639 generator.PressLeftButton(); |
| 623 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); | 640 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); |
| 624 generator.MoveMouseTo(rip_off_point); | 641 generator.MoveMouseTo(rip_off_point); |
| 625 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 642 src_api->RunMessageLoopUntilAnimationsDone(); |
| 626 ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf()); | 643 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 627 ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 644 ASSERT_TRUE(src_api->IsRippedOffFromShelf()); |
| 645 ASSERT_FALSE(src_api->DraggedItemFromShelfToOtherShelf()); | |
| 628 | 646 |
| 629 // Move a dragged item into Shelf at |drop_index|. | 647 // Move a dragged item into the destination shelf at |drop_index|. |
| 630 int drop_index = 1; | 648 int drop_index = main_to_overflow ? dest_api->GetLastVisibleIndex() : 1; |
| 631 gfx::Point drop_point = | 649 ShelfButton* drop_button = dest_api->GetButton(drop_index); |
| 632 test_api_->GetButton(drop_index)->GetBoundsInScreen().CenterPoint(); | 650 gfx::Point drop_point = GetButtonCenter(drop_button); |
| 633 // To insert at |drop_index|, more smaller x-axis value of |drop_point| | 651 // To insert at |drop_index|, more smaller x-axis value of |drop_point| |
|
msw
2017/04/17 19:29:10
nit: s/more/a/ here and below "a smaller" and "a l
sammiequon
2017/04/17 23:42:29
Done.
| |
| 634 // should be used. | 652 // should be used. If |drop_index| is the last item, more larger x-axis |
| 635 gfx::Point modified_drop_point(drop_point.x() - kShelfButtonSize / 4, | 653 // value of |drop_point| should be used. |
| 654 int drop_point_x_shift = | |
| 655 main_to_overflow ? kShelfButtonSize / 4 : -kShelfButtonSize / 4; | |
| 656 gfx::Point modified_drop_point(drop_point.x() + drop_point_x_shift, | |
| 636 drop_point.y()); | 657 drop_point.y()); |
| 637 generator.MoveMouseTo(modified_drop_point); | 658 generator.MoveMouseTo(modified_drop_point); |
| 638 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 659 src_api->RunMessageLoopUntilAnimationsDone(); |
| 639 test_api_->RunMessageLoopUntilAnimationsDone(); | 660 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 640 ASSERT_TRUE(test_api_for_overflow.IsRippedOffFromShelf()); | 661 ASSERT_TRUE(src_api->IsRippedOffFromShelf()); |
| 641 ASSERT_TRUE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 662 ASSERT_TRUE(src_api->DraggedItemFromShelfToOtherShelf()); |
| 642 | 663 |
| 643 if (cancel) | 664 if (cancel) |
| 644 drag_button->OnMouseCaptureLost(); | 665 drag_button->OnMouseCaptureLost(); |
| 645 else | |
| 646 generator.ReleaseLeftButton(); | |
| 647 | 666 |
| 648 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 667 generator.ReleaseLeftButton(); |
| 649 test_api_->RunMessageLoopUntilAnimationsDone(); | 668 |
| 650 ASSERT_FALSE(test_api_for_overflow.IsRippedOffFromShelf()); | 669 src_api->RunMessageLoopUntilAnimationsDone(); |
| 651 ASSERT_FALSE(test_api_for_overflow.DraggedItemFromOverflowToShelf()); | 670 dest_api->RunMessageLoopUntilAnimationsDone(); |
| 671 ASSERT_FALSE(src_api->IsRippedOffFromShelf()); | |
| 672 ASSERT_FALSE(src_api->DraggedItemFromShelfToOtherShelf()); | |
| 652 | 673 |
| 653 // Compare pre-stored items' id with newly positioned items' after dragging | 674 // Compare pre-stored items' id with newly positioned items' after dragging |
| 654 // is canceled or finished. | 675 // is canceled or finished. |
| 655 if (cancel) { | 676 if (cancel) { |
| 677 // Item ids should remain unchanged if operation was canceled. | |
| 656 EXPECT_EQ(last_visible_item_id_in_shelf, | 678 EXPECT_EQ(last_visible_item_id_in_shelf, |
| 657 GetItemId(test_api_->GetLastVisibleIndex())); | 679 GetItemId(test_api_->GetLastVisibleIndex())); |
| 658 EXPECT_EQ(second_last_visible_item_id_in_shelf, | 680 EXPECT_EQ(second_last_visible_item_id_in_shelf, |
| 659 GetItemId(test_api_->GetLastVisibleIndex() - 1)); | 681 GetItemId(test_api_->GetLastVisibleIndex() - 1)); |
| 660 EXPECT_EQ(first_visible_item_id_in_overflow, | 682 EXPECT_EQ(first_visible_item_id_in_overflow, |
| 661 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); | 683 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); |
| 662 EXPECT_EQ(second_last_visible_item_id_in_overflow, | 684 EXPECT_EQ(second_last_visible_item_id_in_overflow, |
| 663 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1)); | 685 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1)); |
| 664 } else { | 686 } else { |
| 665 EXPECT_EQ(drag_item_id, GetItemId(drop_index)); | 687 EXPECT_EQ(drag_item_id, GetItemId(drop_index)); |
| 666 EXPECT_EQ(total_item_count, model_->item_count()); | 688 EXPECT_EQ(total_item_count, model_->item_count()); |
| 667 EXPECT_EQ(last_visible_item_id_in_shelf, | 689 |
| 668 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); | 690 if (main_to_overflow) { |
| 669 EXPECT_EQ(second_last_visible_item_id_in_shelf, | 691 // If we move an item from the main shelf to the overflow shelf, the |
| 670 GetItemId(test_api_->GetLastVisibleIndex())); | 692 // following should happen: |
| 671 EXPECT_EQ(first_visible_item_id_in_overflow, | 693 // 1) The former last item on the main shelf should now be the second |
| 672 GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1)); | 694 // last item on the main shelf. |
| 673 EXPECT_EQ(second_last_visible_item_id_in_overflow, | 695 // 2) The former first item on the overflow shelf should now be the last |
| 674 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); | 696 // item on the main shelf. |
| 697 // 3) The dragged item should now be the last item on the main shelf. | |
| 698 EXPECT_EQ(last_visible_item_id_in_shelf, | |
| 699 GetItemId(test_api_->GetLastVisibleIndex() - 1)); | |
| 700 EXPECT_EQ(first_visible_item_id_in_overflow, | |
| 701 GetItemId(test_api_->GetLastVisibleIndex())); | |
| 702 EXPECT_EQ(drag_item_id, | |
| 703 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); | |
| 704 } else { | |
| 705 // If we move an item from the overflow shelf to the main shelf, the | |
| 706 // following should happen: | |
| 707 // 1) The former last item on the main shelf should now be the first | |
| 708 // item on the overflow shelf. | |
| 709 // 2) The former second last item on the main shelf should now be the | |
| 710 // last item on the main shelf. | |
| 711 // 3) The former first item on the overflow shelf should now be the | |
| 712 // second item on the overflow shelf. | |
| 713 // 4) The former second item on the overflow shelf should now be the | |
| 714 // last item on the overflow shelf (since there are 3 items on the | |
| 715 // overflow shelf). | |
| 716 EXPECT_EQ(last_visible_item_id_in_shelf, | |
| 717 GetItemId(test_api_for_overflow.GetFirstVisibleIndex())); | |
| 718 EXPECT_EQ(second_last_visible_item_id_in_shelf, | |
| 719 GetItemId(test_api_->GetLastVisibleIndex())); | |
| 720 EXPECT_EQ(first_visible_item_id_in_overflow, | |
| 721 GetItemId(test_api_for_overflow.GetFirstVisibleIndex() + 1)); | |
| 722 EXPECT_EQ(second_last_visible_item_id_in_overflow, | |
| 723 GetItemId(test_api_for_overflow.GetLastVisibleIndex())); | |
| 724 } | |
| 675 } | 725 } |
| 676 test_api_->HideOverflowBubble(); | 726 test_api_->HideOverflowBubble(); |
| 677 } | 727 } |
| 678 | 728 |
| 679 // Returns the item's ShelfID at |index|. | 729 // Returns the item's ShelfID at |index|. |
| 680 ShelfID GetItemId(int index) { | 730 ShelfID GetItemId(int index) { |
| 681 DCHECK_GE(index, 0); | 731 DCHECK_GE(index, 0); |
| 682 return model_->items()[index].id; | 732 return model_->items()[index].id; |
| 683 } | 733 } |
| 684 | 734 |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1747 ui::test::EventGenerator generator(Shell::GetAllRootWindows()[1], | 1797 ui::test::EventGenerator generator(Shell::GetAllRootWindows()[1], |
| 1748 start_point); | 1798 start_point); |
| 1749 | 1799 |
| 1750 // Rip off the browser item. | 1800 // Rip off the browser item. |
| 1751 generator.PressLeftButton(); | 1801 generator.PressLeftButton(); |
| 1752 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); | 1802 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); |
| 1753 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone(); | 1803 test_api_for_secondary_shelf_view.RunMessageLoopUntilAnimationsDone(); |
| 1754 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf()); | 1804 EXPECT_TRUE(test_api_for_secondary_shelf_view.IsRippedOffFromShelf()); |
| 1755 } | 1805 } |
| 1756 | 1806 |
| 1757 // Checks various drag and drop operations from OverflowBubble to Shelf. | 1807 // Checks various drag and drop operations from OverflowBubble to Shelf, and |
| 1758 TEST_F(ShelfViewTest, CheckDragAndDropFromOverflowBubbleToShelf) { | 1808 // vice versa. |
| 1809 TEST_F(ShelfViewTest, CheckDragAndDropFromShelfToOtherShelf) { | |
| 1759 AddButtonsUntilOverflow(); | 1810 AddButtonsUntilOverflow(); |
| 1760 // Add one more button to prevent the overflow bubble to disappear upon | 1811 // Add one more button to prevent the overflow bubble to disappear upon |
| 1761 // dragging an item out on windows (flakiness, see crbug.com/425097). | 1812 // dragging an item out on windows (flakiness, see crbug.com/425097). |
| 1762 AddAppShortcut(); | 1813 AddAppShortcut(); |
| 1763 | 1814 |
| 1764 TestDraggingAnItemFromOverflowToShelf(false); | 1815 TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */, |
| 1765 TestDraggingAnItemFromOverflowToShelf(true); | 1816 false /* cancel */); |
| 1817 TestDraggingAnItemFromShelfToOtherShelf(false /* main_to_overflow */, | |
| 1818 true /* cancel */); | |
| 1819 | |
| 1820 TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */, | |
| 1821 false /* cancel */); | |
| 1822 TestDraggingAnItemFromShelfToOtherShelf(true /* main_to_overflow */, | |
| 1823 true /* cancel */); | |
| 1766 } | 1824 } |
| 1767 | 1825 |
| 1768 // Checks creating app shortcut for an opened platform app in overflow bubble | 1826 // Checks creating app shortcut for an opened platform app in overflow bubble |
| 1769 // should be invisible to the shelf. See crbug.com/605793. | 1827 // should be invisible to the shelf. See crbug.com/605793. |
| 1770 TEST_F(ShelfViewTest, CheckOverflowStatusPinOpenedAppToShelf) { | 1828 TEST_F(ShelfViewTest, CheckOverflowStatusPinOpenedAppToShelf) { |
| 1771 AddButtonsUntilOverflow(); | 1829 AddButtonsUntilOverflow(); |
| 1772 | 1830 |
| 1773 // Add a running Platform app. | 1831 // Add a running Platform app. |
| 1774 ShelfID platform_app_id = AddApp(); | 1832 ShelfID platform_app_id = AddApp(); |
| 1775 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); | 1833 EXPECT_FALSE(GetButtonByID(platform_app_id)->visible()); |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3137 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3195 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3138 overflow_button_ink_drop_->GetTargetInkDropState()); | 3196 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3139 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3197 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3140 IsEmpty()); | 3198 IsEmpty()); |
| 3141 | 3199 |
| 3142 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3200 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3143 } | 3201 } |
| 3144 | 3202 |
| 3145 } // namespace test | 3203 } // namespace test |
| 3146 } // namespace ash | 3204 } // namespace ash |
| OLD | NEW |