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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 internal::ShelfView* shelf_view_; | 575 internal::ShelfView* shelf_view_; |
576 int browser_index_; | 576 int browser_index_; |
577 ShelfItemDelegateManager* item_manager_; | 577 ShelfItemDelegateManager* item_manager_; |
578 | 578 |
579 scoped_ptr<ShelfViewTestAPI> test_api_; | 579 scoped_ptr<ShelfViewTestAPI> test_api_; |
580 | 580 |
581 private: | 581 private: |
582 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); | 582 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); |
583 }; | 583 }; |
584 | 584 |
585 class ShelfViewLegacyShelfLayoutTest : public ShelfViewTest { | |
586 public: | |
587 ShelfViewLegacyShelfLayoutTest() : ShelfViewTest() { | |
588 browser_index_ = 0; | |
589 } | |
590 | |
591 virtual ~ShelfViewLegacyShelfLayoutTest() {} | |
592 | |
593 virtual void SetUp() OVERRIDE { | |
594 CommandLine::ForCurrentProcess()->AppendSwitch( | |
595 ash::switches::kAshDisableAlternateShelfLayout); | |
596 ShelfViewTest::SetUp(); | |
597 } | |
598 | |
599 private: | |
600 DISALLOW_COPY_AND_ASSIGN(ShelfViewLegacyShelfLayoutTest); | |
601 }; | |
602 | |
603 class ScopedTextDirectionChange { | 585 class ScopedTextDirectionChange { |
604 public: | 586 public: |
605 ScopedTextDirectionChange(bool is_rtl) | 587 ScopedTextDirectionChange(bool is_rtl) |
606 : is_rtl_(is_rtl) { | 588 : is_rtl_(is_rtl) { |
607 original_locale_ = l10n_util::GetApplicationLocale(std::string()); | 589 original_locale_ = l10n_util::GetApplicationLocale(std::string()); |
608 if (is_rtl_) | 590 if (is_rtl_) |
609 base::i18n::SetICUDefaultLocale("he"); | 591 base::i18n::SetICUDefaultLocale("he"); |
610 CheckTextDirectionIsCorrect(); | 592 CheckTextDirectionIsCorrect(); |
611 } | 593 } |
612 | 594 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 720 |
739 last_added = AddAppShortcut(); | 721 last_added = AddAppShortcut(); |
740 ++items_added; | 722 ++items_added; |
741 ASSERT_LT(items_added, 10000); | 723 ASSERT_LT(items_added, 10000); |
742 } | 724 } |
743 | 725 |
744 // And the platform app button is invisible. | 726 // And the platform app button is invisible. |
745 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); | 727 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
746 } | 728 } |
747 | 729 |
748 TEST_F(ShelfViewLegacyShelfLayoutTest, | |
749 AddAppShortcutWithBrowserButtonUntilOverflow) { | |
750 // All buttons should be visible. | |
751 ASSERT_EQ(test_api_->GetButtonCount(), | |
752 test_api_->GetLastVisibleIndex() + 1); | |
753 | |
754 | |
755 LauncherID browser_button_id = AddPlatformApp(); | |
756 | |
757 // Add app shortcut until overflow. | |
758 int items_added = 0; | |
759 LauncherID last_added = AddAppShortcut(); | |
760 while (!test_api_->IsOverflowButtonVisible()) { | |
761 // Added button is visible after animation while in this loop. | |
762 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
763 | |
764 last_added = AddAppShortcut(); | |
765 ++items_added; | |
766 ASSERT_LT(items_added, 10000); | |
767 } | |
768 | |
769 // The last added app short button should be visible. | |
770 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | |
771 // And the platform app button is invisible. | |
772 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); | |
773 } | |
774 | |
775 TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) { | 730 TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) { |
776 // All buttons should be visible. | 731 // All buttons should be visible. |
777 ASSERT_EQ(test_api_->GetButtonCount(), | 732 ASSERT_EQ(test_api_->GetButtonCount(), |
778 test_api_->GetLastVisibleIndex() + 1); | 733 test_api_->GetLastVisibleIndex() + 1); |
779 | 734 |
780 // Add platform app button until overflow, remember last visible platform app | 735 // Add platform app button until overflow, remember last visible platform app |
781 // button. | 736 // button. |
782 int items_added = 0; | 737 int items_added = 0; |
783 LauncherID first_added = AddPlatformApp(); | 738 LauncherID first_added = AddPlatformApp(); |
784 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | 739 EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
785 while (true) { | 740 while (true) { |
786 LauncherID added = AddPlatformApp(); | 741 LauncherID added = AddPlatformApp(); |
787 if (test_api_->IsOverflowButtonVisible()) { | 742 if (test_api_->IsOverflowButtonVisible()) { |
788 EXPECT_FALSE(GetButtonByID(added)->visible()); | 743 EXPECT_FALSE(GetButtonByID(added)->visible()); |
789 RemoveByID(added); | 744 RemoveByID(added); |
790 break; | 745 break; |
791 } | 746 } |
792 ++items_added; | 747 ++items_added; |
793 ASSERT_LT(items_added, 10000); | 748 ASSERT_LT(items_added, 10000); |
794 } | 749 } |
795 | 750 |
796 LauncherID panel = AddPanel(); | 751 LauncherID panel = AddPanel(); |
797 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); | 752 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); |
798 | 753 |
799 RemoveByID(panel); | 754 RemoveByID(panel); |
800 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | 755 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
801 } | 756 } |
802 | 757 |
803 TEST_F(ShelfViewLegacyShelfLayoutTest, AddPanelHidesPlatformAppButton) { | |
804 // All buttons should be visible. | |
805 ASSERT_EQ(test_api_->GetButtonCount(), | |
806 test_api_->GetLastVisibleIndex() + 1); | |
807 | |
808 // Add platform app button until overflow, remember last visible platform app | |
809 // button. | |
810 int items_added = 0; | |
811 LauncherID first_added = AddPlatformApp(); | |
812 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | |
813 LauncherID last_visible = first_added; | |
814 while (true) { | |
815 LauncherID added = AddPlatformApp(); | |
816 if (test_api_->IsOverflowButtonVisible()) { | |
817 EXPECT_FALSE(GetButtonByID(added)->visible()); | |
818 break; | |
819 } | |
820 last_visible = added; | |
821 ++items_added; | |
822 ASSERT_LT(items_added, 10000); | |
823 } | |
824 | |
825 LauncherID panel = AddPanel(); | |
826 EXPECT_TRUE(GetButtonByID(panel)->visible()); | |
827 EXPECT_FALSE(GetButtonByID(last_visible)->visible()); | |
828 | |
829 RemoveByID(panel); | |
830 EXPECT_TRUE(GetButtonByID(last_visible)->visible()); | |
831 } | |
832 | |
833 // When there are more panels then platform app buttons we should hide panels | 758 // When there are more panels then platform app buttons we should hide panels |
834 // rather than platform apps. | 759 // rather than platform apps. |
835 TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) { | 760 TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) { |
836 // All buttons should be visible. | 761 // All buttons should be visible. |
837 ASSERT_EQ(test_api_->GetButtonCount(), | 762 ASSERT_EQ(test_api_->GetButtonCount(), |
838 test_api_->GetLastVisibleIndex() + 1); | 763 test_api_->GetLastVisibleIndex() + 1); |
839 | 764 |
840 // Add platform app button. | 765 // Add platform app button. |
841 LauncherID platform_app = AddPlatformApp(); | 766 LauncherID platform_app = AddPlatformApp(); |
842 LauncherID first_panel = AddPanel(); | 767 LauncherID first_panel = AddPanel(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 940 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
1016 new_id = AddPanel(); | 941 new_id = AddPanel(); |
1017 id_map.insert(id_map.begin() + 7, | 942 id_map.insert(id_map.begin() + 7, |
1018 std::make_pair(new_id, GetButtonByID(new_id))); | 943 std::make_pair(new_id, GetButtonByID(new_id))); |
1019 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 944 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1020 button_host->PointerReleasedOnButton(dragged_button, | 945 button_host->PointerReleasedOnButton(dragged_button, |
1021 internal::ShelfButtonHost::MOUSE, | 946 internal::ShelfButtonHost::MOUSE, |
1022 false); | 947 false); |
1023 } | 948 } |
1024 | 949 |
1025 TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { | |
1026 internal::ShelfButtonHost* button_host = shelf_view_; | |
1027 | |
1028 std::vector<std::pair<LauncherID, views::View*> > id_map; | |
1029 SetupForDragTest(&id_map); | |
1030 | |
1031 // Dragging browser shortcut at index 0. | |
1032 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | |
1033 views::View* dragged_button = SimulateDrag( | |
1034 internal::ShelfButtonHost::MOUSE, 0, 2); | |
1035 std::rotate(id_map.begin(), | |
1036 id_map.begin() + 1, | |
1037 id_map.begin() + 3); | |
1038 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1039 button_host->PointerReleasedOnButton(dragged_button, | |
1040 internal::ShelfButtonHost::MOUSE, | |
1041 false); | |
1042 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); | |
1043 | |
1044 // Dragging changes model order. | |
1045 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | |
1046 std::rotate(id_map.begin(), | |
1047 id_map.begin() + 1, | |
1048 id_map.begin() + 3); | |
1049 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1050 | |
1051 // Cancelling the drag operation restores previous order. | |
1052 button_host->PointerReleasedOnButton(dragged_button, | |
1053 internal::ShelfButtonHost::MOUSE, | |
1054 true); | |
1055 std::rotate(id_map.begin(), | |
1056 id_map.begin() + 2, | |
1057 id_map.begin() + 3); | |
1058 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1059 | |
1060 // Deleting an item keeps the remaining intact. | |
1061 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | |
1062 model_->RemoveItemAt(1); | |
1063 id_map.erase(id_map.begin() + 1); | |
1064 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1065 button_host->PointerReleasedOnButton(dragged_button, | |
1066 internal::ShelfButtonHost::MOUSE, | |
1067 false); | |
1068 | |
1069 // Adding a shelf item cancels the drag and respects the order. | |
1070 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | |
1071 LauncherID new_id = AddAppShortcut(); | |
1072 id_map.insert(id_map.begin() + 5, | |
1073 std::make_pair(new_id, GetButtonByID(new_id))); | |
1074 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1075 button_host->PointerReleasedOnButton(dragged_button, | |
1076 internal::ShelfButtonHost::MOUSE, | |
1077 false); | |
1078 | |
1079 // Adding a shelf item at the end (i.e. a panel) canels drag and respects | |
1080 // the order. | |
1081 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | |
1082 new_id = AddPanel(); | |
1083 id_map.insert(id_map.begin() + 7, | |
1084 std::make_pair(new_id, GetButtonByID(new_id))); | |
1085 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
1086 button_host->PointerReleasedOnButton(dragged_button, | |
1087 internal::ShelfButtonHost::MOUSE, | |
1088 false); | |
1089 } | |
1090 | |
1091 // Check that 2nd drag from the other pointer would be ignored. | 950 // Check that 2nd drag from the other pointer would be ignored. |
1092 TEST_F(ShelfViewTest, SimultaneousDrag) { | 951 TEST_F(ShelfViewTest, SimultaneousDrag) { |
1093 internal::ShelfButtonHost* button_host = shelf_view_; | 952 internal::ShelfButtonHost* button_host = shelf_view_; |
1094 | 953 |
1095 std::vector<std::pair<LauncherID, views::View*> > id_map; | 954 std::vector<std::pair<LauncherID, views::View*> > id_map; |
1096 SetupForDragTest(&id_map); | 955 SetupForDragTest(&id_map); |
1097 | 956 |
1098 // Start a mouse drag. | 957 // Start a mouse drag. |
1099 views::View* dragged_button_mouse = SimulateDrag( | 958 views::View* dragged_button_mouse = SimulateDrag( |
1100 internal::ShelfButtonHost::MOUSE, 1, 3); | 959 internal::ShelfButtonHost::MOUSE, 1, 3); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 internal::ShelfButton* button = GetButtonByID(last_added); | 1031 internal::ShelfButton* button = GetButtonByID(last_added); |
1173 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); | 1032 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); |
1174 item.status = STATUS_ACTIVE; | 1033 item.status = STATUS_ACTIVE; |
1175 model_->Set(index, item); | 1034 model_->Set(index, item); |
1176 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); | 1035 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); |
1177 item.status = STATUS_ATTENTION; | 1036 item.status = STATUS_ATTENTION; |
1178 model_->Set(index, item); | 1037 model_->Set(index, item); |
1179 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); | 1038 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); |
1180 } | 1039 } |
1181 | 1040 |
1182 TEST_F(ShelfViewLegacyShelfLayoutTest, | |
1183 ShelfItemPositionReflectedOnStateChanged) { | |
1184 // All buttons should be visible. | |
1185 ASSERT_EQ(test_api_->GetButtonCount(), | |
1186 test_api_->GetLastVisibleIndex() + 1); | |
1187 | |
1188 // Add 2 items to the shelf. | |
1189 LauncherID item1_id = AddPlatformApp(); | |
1190 LauncherID item2_id = AddPlatformAppNoWait(); | |
1191 internal::ShelfButton* item1_button = GetButtonByID(item1_id); | |
1192 internal::ShelfButton* item2_button = GetButtonByID(item2_id); | |
1193 | |
1194 internal::ShelfButton::State state_mask = | |
1195 static_cast<internal::ShelfButton::State>( | |
1196 internal::ShelfButton::STATE_NORMAL | | |
1197 internal::ShelfButton::STATE_HOVERED | | |
1198 internal::ShelfButton::STATE_RUNNING | | |
1199 internal::ShelfButton::STATE_ACTIVE | | |
1200 internal::ShelfButton::STATE_ATTENTION | | |
1201 internal::ShelfButton::STATE_FOCUSED); | |
1202 | |
1203 // Clear the button states. | |
1204 item1_button->ClearState(state_mask); | |
1205 item2_button->ClearState(state_mask); | |
1206 | |
1207 // Since default alignment in tests is bottom, state is reflected in y-axis. | |
1208 ASSERT_EQ(item1_button->GetIconBounds().y(), | |
1209 item2_button->GetIconBounds().y()); | |
1210 item1_button->AddState(internal::ShelfButton::STATE_HOVERED); | |
1211 ASSERT_NE(item1_button->GetIconBounds().y(), | |
1212 item2_button->GetIconBounds().y()); | |
1213 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); | |
1214 } | |
1215 | |
1216 // Confirm that item status changes are reflected in the buttons | 1041 // Confirm that item status changes are reflected in the buttons |
1217 // for platform apps. | 1042 // for platform apps. |
1218 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { | 1043 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { |
1219 // All buttons should be visible. | 1044 // All buttons should be visible. |
1220 ASSERT_EQ(test_api_->GetButtonCount(), | 1045 ASSERT_EQ(test_api_->GetButtonCount(), |
1221 test_api_->GetLastVisibleIndex() + 1); | 1046 test_api_->GetLastVisibleIndex() + 1); |
1222 | 1047 |
1223 // Add platform app button. | 1048 // Add platform app button. |
1224 LauncherID last_added = AddPlatformApp(); | 1049 LauncherID last_added = AddPlatformApp(); |
1225 LauncherItem item = GetItemByID(last_added); | 1050 LauncherItem item = GetItemByID(last_added); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); | 1365 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); |
1541 EXPECT_EQ(bubble_size.width(), | 1366 EXPECT_EQ(bubble_size.width(), |
1542 test_for_overflow_view.GetPreferredSize().width()); | 1367 test_for_overflow_view.GetPreferredSize().width()); |
1543 | 1368 |
1544 generator.ReleaseLeftButton(); | 1369 generator.ReleaseLeftButton(); |
1545 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); | 1370 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); |
1546 EXPECT_EQ(bubble_size.width(), | 1371 EXPECT_EQ(bubble_size.width(), |
1547 test_for_overflow_view.GetPreferredSize().width()); | 1372 test_for_overflow_view.GetPreferredSize().width()); |
1548 } | 1373 } |
1549 | 1374 |
1550 // Check that the first item in the list follows Fitt's law by including the | |
1551 // first pixel and being therefore bigger then the others. | |
1552 TEST_F(ShelfViewLegacyShelfLayoutTest, CheckFittsLaw) { | |
1553 // All buttons should be visible. | |
1554 ASSERT_EQ(test_api_->GetButtonCount(), | |
1555 test_api_->GetLastVisibleIndex() + 1); | |
1556 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); | |
1557 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); | |
1558 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); | |
1559 } | |
1560 | |
1561 // Check the drag insertion bounds of scrolled overflow bubble. | 1375 // Check the drag insertion bounds of scrolled overflow bubble. |
1562 TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) { | 1376 TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) { |
1563 UpdateDisplay("400x300"); | 1377 UpdateDisplay("400x300"); |
1564 | 1378 |
1565 EXPECT_EQ(2, model_->item_count()); | 1379 EXPECT_EQ(2, model_->item_count()); |
1566 | 1380 |
1567 AddButtonsUntilOverflow(); | 1381 AddButtonsUntilOverflow(); |
1568 | 1382 |
1569 // Show overflow bubble. | 1383 // Show overflow bubble. |
1570 test_api_->ShowOverflowBubble(); | 1384 test_api_->ShowOverflowBubble(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 test_api_->RunMessageLoopUntilAnimationsDone(); | 1591 test_api_->RunMessageLoopUntilAnimationsDone(); |
1778 CheckAllItemsAreInBounds(); | 1592 CheckAllItemsAreInBounds(); |
1779 } | 1593 } |
1780 | 1594 |
1781 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1595 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
1782 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1596 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
1783 testing::Bool()); | 1597 testing::Bool()); |
1784 | 1598 |
1785 } // namespace test | 1599 } // namespace test |
1786 } // namespace ash | 1600 } // namespace ash |
OLD | NEW |