| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 ShelfViewTest() | 296 ShelfViewTest() |
| 297 : model_(NULL), | 297 : model_(NULL), |
| 298 shelf_view_(NULL), | 298 shelf_view_(NULL), |
| 299 browser_index_(1), | 299 browser_index_(1), |
| 300 item_manager_(NULL) {} | 300 item_manager_(NULL) {} |
| 301 ~ShelfViewTest() override {} | 301 ~ShelfViewTest() override {} |
| 302 | 302 |
| 303 void SetUp() override { | 303 void SetUp() override { |
| 304 AshTestBase::SetUp(); | 304 AshTestBase::SetUp(); |
| 305 test::ShellTestApi test_api(Shell::GetInstance()); | 305 ShellTestApi test_api(Shell::GetInstance()); |
| 306 model_ = test_api.shelf_model(); | 306 model_ = test_api.shelf_model(); |
| 307 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 307 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 308 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); | 308 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
| 309 | 309 |
| 310 // The bounds should be big enough for 4 buttons + overflow chevron. | 310 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 311 shelf_view_->SetBounds(0, 0, 500, kShelfSize); | 311 shelf_view_->SetBounds(0, 0, 500, kShelfSize); |
| 312 | 312 |
| 313 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 313 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
| 314 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 314 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| 315 | 315 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 ++items_added; | 568 ++items_added; |
| 569 ASSERT_LT(items_added, 10000); | 569 ASSERT_LT(items_added, 10000); |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 | 572 |
| 573 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { | 573 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { |
| 574 test_api_->ShowOverflowBubble(); | 574 test_api_->ShowOverflowBubble(); |
| 575 ASSERT_TRUE(test_api_->overflow_bubble() && | 575 ASSERT_TRUE(test_api_->overflow_bubble() && |
| 576 test_api_->overflow_bubble()->IsShowing()); | 576 test_api_->overflow_bubble()->IsShowing()); |
| 577 | 577 |
| 578 ash::test::ShelfViewTestAPI test_api_for_overflow( | 578 ShelfViewTestAPI test_api_for_overflow( |
| 579 test_api_->overflow_bubble()->shelf_view()); | 579 test_api_->overflow_bubble()->shelf_view()); |
| 580 | 580 |
| 581 int total_item_count = model_->item_count(); | 581 int total_item_count = model_->item_count(); |
| 582 | 582 |
| 583 int last_visible_item_id_in_shelf = | 583 int last_visible_item_id_in_shelf = |
| 584 GetItemId(test_api_->GetLastVisibleIndex()); | 584 GetItemId(test_api_->GetLastVisibleIndex()); |
| 585 int second_last_visible_item_id_in_shelf = | 585 int second_last_visible_item_id_in_shelf = |
| 586 GetItemId(test_api_->GetLastVisibleIndex() - 1); | 586 GetItemId(test_api_->GetLastVisibleIndex() - 1); |
| 587 int first_visible_item_id_in_overflow = | 587 int first_visible_item_id_in_overflow = |
| 588 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); | 588 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); |
| 589 int second_last_visible_item_id_in_overflow = | 589 int second_last_visible_item_id_in_overflow = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 657 } |
| 658 | 658 |
| 659 // Returns the item's ShelfID at |index|. | 659 // Returns the item's ShelfID at |index|. |
| 660 ShelfID GetItemId(int index) { | 660 ShelfID GetItemId(int index) { |
| 661 DCHECK_GE(index, 0); | 661 DCHECK_GE(index, 0); |
| 662 return model_->items()[index].id; | 662 return model_->items()[index].id; |
| 663 } | 663 } |
| 664 | 664 |
| 665 void ReplaceShelfDelegate() { | 665 void ReplaceShelfDelegate() { |
| 666 // Replace ShelfDelegate. | 666 // Replace ShelfDelegate. |
| 667 test::ShellTestApi shell_test_api(Shell::GetInstance()); | 667 ShellTestApi shell_test_api(Shell::GetInstance()); |
| 668 shell_test_api.SetShelfDelegate(NULL); | 668 shell_test_api.SetShelfDelegate(NULL); |
| 669 shelf_delegate_ = new TestShelfDelegateForShelfView(); | 669 shelf_delegate_ = new TestShelfDelegateForShelfView(); |
| 670 shell_test_api.SetShelfDelegate(shelf_delegate_); | 670 shell_test_api.SetShelfDelegate(shelf_delegate_); |
| 671 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()) | 671 ShelfTestAPI(Shelf::ForPrimaryDisplay()).set_delegate(shelf_delegate_); |
| 672 .SetShelfDelegate(shelf_delegate_); | |
| 673 test_api_->SetShelfDelegate(shelf_delegate_); | 672 test_api_->SetShelfDelegate(shelf_delegate_); |
| 674 } | 673 } |
| 675 | 674 |
| 676 ShelfModel* model_; | 675 ShelfModel* model_; |
| 677 ShelfView* shelf_view_; | 676 ShelfView* shelf_view_; |
| 678 int browser_index_; | 677 int browser_index_; |
| 679 ShelfItemDelegateManager* item_manager_; | 678 ShelfItemDelegateManager* item_manager_; |
| 680 | 679 |
| 681 // Owned by ash::Shell. | 680 // Owned by ash::Shell. |
| 682 TestShelfDelegateForShelfView* shelf_delegate_; | 681 TestShelfDelegateForShelfView* shelf_delegate_; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 for (int i = 0; i < 20; ++i) { | 954 for (int i = 0; i < 20; ++i) { |
| 956 ShelfID id = AddPanel(); | 955 ShelfID id = AddPanel(); |
| 957 button_ids.push_back(id); | 956 button_ids.push_back(id); |
| 958 } | 957 } |
| 959 ASSERT_LT(button_ids.size(), 10000U); | 958 ASSERT_LT(button_ids.size(), 10000U); |
| 960 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); | 959 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); |
| 961 | 960 |
| 962 // Test that any two successive visible icons never overlap in all shelf | 961 // Test that any two successive visible icons never overlap in all shelf |
| 963 // alignment types. | 962 // alignment types. |
| 964 const ShelfAlignment kAlignments[] = { | 963 const ShelfAlignment kAlignments[] = { |
| 965 SHELF_ALIGNMENT_LEFT, | 964 SHELF_ALIGNMENT_LEFT, SHELF_ALIGNMENT_RIGHT, SHELF_ALIGNMENT_BOTTOM, |
| 966 SHELF_ALIGNMENT_RIGHT, | 965 SHELF_ALIGNMENT_BOTTOM_LOCKED, |
| 967 SHELF_ALIGNMENT_BOTTOM | |
| 968 }; | 966 }; |
| 969 | 967 |
| 970 for (ShelfAlignment alignment : kAlignments) { | 968 for (ShelfAlignment alignment : kAlignments) { |
| 971 shelf_view_->shelf()->SetAlignment(alignment); | 969 shelf_view_->shelf()->SetAlignment(alignment); |
| 972 // For every 2 successive visible icons, expect that their bounds don't | 970 // For every 2 successive visible icons, expect that their bounds don't |
| 973 // intersect. | 971 // intersect. |
| 974 for (int i = 1; i < test_api_->GetButtonCount() - 1; ++i) { | 972 for (int i = 1; i < test_api_->GetButtonCount() - 1; ++i) { |
| 975 if (!(test_api_->GetButton(i)->visible() && | 973 if (!(test_api_->GetButton(i)->visible() && |
| 976 test_api_->GetButton(i + 1)->visible())) { | 974 test_api_->GetButton(i + 1)->visible())) { |
| 977 continue; | 975 continue; |
| 978 } | 976 } |
| 979 | 977 |
| 980 const gfx::Rect& bounds1 = test_api_->GetBoundsByIndex(i); | 978 const gfx::Rect& bounds1 = test_api_->GetBoundsByIndex(i); |
| 981 const gfx::Rect& bounds2 = test_api_->GetBoundsByIndex(i + 1); | 979 const gfx::Rect& bounds2 = test_api_->GetBoundsByIndex(i + 1); |
| 982 EXPECT_FALSE(bounds1.Intersects(bounds2)); | 980 EXPECT_FALSE(bounds1.Intersects(bounds2)); |
| 983 } | 981 } |
| 984 } | 982 } |
| 985 } | 983 } |
| 986 | 984 |
| 987 // Making sure the overflow bubble arrow correctly tracks with shelf position. | 985 // Making sure the overflow bubble arrow correctly tracks with shelf position. |
| 988 TEST_F(ShelfViewTest, OverflowArrowForShelfPosition) { | 986 TEST_F(ShelfViewTest, OverflowArrowForShelfPosition) { |
| 989 const ShelfAlignment kAlignments[] = { | 987 const ShelfAlignment kAlignments[] = { |
| 990 SHELF_ALIGNMENT_BOTTOM, SHELF_ALIGNMENT_LEFT, SHELF_ALIGNMENT_RIGHT}; | 988 SHELF_ALIGNMENT_BOTTOM, SHELF_ALIGNMENT_LEFT, SHELF_ALIGNMENT_RIGHT, |
| 989 SHELF_ALIGNMENT_BOTTOM_LOCKED, |
| 990 }; |
| 991 | 991 |
| 992 // These must match what is expected for each alignment above. | 992 // These must match what is expected for each alignment above. |
| 993 const views::BubbleBorder::Arrow kArrows[] = { | 993 const views::BubbleBorder::Arrow kArrows[] = { |
| 994 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP, | 994 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP, |
| 995 views::BubbleBorder::RIGHT_TOP}; | 995 views::BubbleBorder::RIGHT_TOP, views::BubbleBorder::BOTTOM_LEFT, |
| 996 }; |
| 996 | 997 |
| 997 for (size_t i = 0; i < arraysize(kAlignments); i++) { | 998 for (size_t i = 0; i < arraysize(kAlignments); i++) { |
| 998 shelf_view_->shelf()->SetAlignment(kAlignments[i]); | 999 shelf_view_->shelf()->SetAlignment(kAlignments[i]); |
| 999 | 1000 |
| 1000 // Make sure there are enough icons to trigger the overflow in new | 1001 // Make sure there are enough icons to trigger the overflow in new |
| 1001 // orientation. | 1002 // orientation. |
| 1002 AddButtonsUntilOverflow(); | 1003 AddButtonsUntilOverflow(); |
| 1003 test_api_->ShowOverflowBubble(); | 1004 test_api_->ShowOverflowBubble(); |
| 1004 ASSERT_TRUE(test_api_->overflow_bubble() && | 1005 ASSERT_TRUE(test_api_->overflow_bubble() && |
| 1005 test_api_->overflow_bubble()->IsShowing()); | 1006 test_api_->overflow_bubble()->IsShowing()); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 | 1647 |
| 1647 AddButtonsUntilOverflow(); | 1648 AddButtonsUntilOverflow(); |
| 1648 | 1649 |
| 1649 // Show overflow bubble. | 1650 // Show overflow bubble. |
| 1650 test_api_->ShowOverflowBubble(); | 1651 test_api_->ShowOverflowBubble(); |
| 1651 ASSERT_TRUE(test_api_->overflow_bubble() && | 1652 ASSERT_TRUE(test_api_->overflow_bubble() && |
| 1652 test_api_->overflow_bubble()->IsShowing()); | 1653 test_api_->overflow_bubble()->IsShowing()); |
| 1653 | 1654 |
| 1654 int item_width = test_api_->GetButtonSize() + test_api_->GetButtonSpacing(); | 1655 int item_width = test_api_->GetButtonSize() + test_api_->GetButtonSpacing(); |
| 1655 OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view(); | 1656 OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view(); |
| 1656 test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view); | 1657 OverflowBubbleViewTestAPI bubble_view_api(bubble_view); |
| 1657 | 1658 |
| 1658 // Add more buttons until OverflowBubble is scrollable and it has 3 invisible | 1659 // Add more buttons until OverflowBubble is scrollable and it has 3 invisible |
| 1659 // items. | 1660 // items. |
| 1660 while (bubble_view_api.GetContentsSize().width() < | 1661 while (bubble_view_api.GetContentsSize().width() < |
| 1661 (bubble_view->GetContentsBounds().width() + 3 * item_width)) | 1662 (bubble_view->GetContentsBounds().width() + 3 * item_width)) |
| 1662 AddAppShortcut(); | 1663 AddAppShortcut(); |
| 1663 | 1664 |
| 1664 ASSERT_TRUE(test_api_->overflow_bubble() && | 1665 ASSERT_TRUE(test_api_->overflow_bubble() && |
| 1665 test_api_->overflow_bubble()->IsShowing()); | 1666 test_api_->overflow_bubble()->IsShowing()); |
| 1666 | 1667 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 test_api_->RunMessageLoopUntilAnimationsDone(); | 1950 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1950 CheckAllItemsAreInBounds(); | 1951 CheckAllItemsAreInBounds(); |
| 1951 } | 1952 } |
| 1952 | 1953 |
| 1953 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1954 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
| 1954 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1955 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
| 1955 testing::Bool()); | 1956 testing::Bool()); |
| 1956 | 1957 |
| 1957 } // namespace test | 1958 } // namespace test |
| 1958 } // namespace ash | 1959 } // namespace ash |
| OLD | NEW |