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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); | 329 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); |
330 EXPECT_TRUE(item_bounds.x() >= 0); | 330 EXPECT_TRUE(item_bounds.x() >= 0); |
331 EXPECT_TRUE(item_bounds.y() >= 0); | 331 EXPECT_TRUE(item_bounds.y() >= 0); |
332 EXPECT_TRUE(item_bounds.right() <= shelf_view_bounds.width()); | 332 EXPECT_TRUE(item_bounds.right() <= shelf_view_bounds.width()); |
333 EXPECT_TRUE(item_bounds.bottom() <= shelf_view_bounds.height()); | 333 EXPECT_TRUE(item_bounds.bottom() <= shelf_view_bounds.height()); |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 views::View* SimulateButtonPressed( | 338 views::View* SimulateButtonPressed( |
339 internal::LauncherButtonHost::Pointer pointer, | 339 internal::ShelfButtonHost::Pointer pointer, |
340 int button_index) { | 340 int button_index) { |
341 internal::LauncherButtonHost* button_host = shelf_view_; | 341 internal::ShelfButtonHost* button_host = shelf_view_; |
342 views::View* button = test_api_->GetButton(button_index); | 342 views::View* button = test_api_->GetButton(button_index); |
343 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, | 343 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, |
344 button->bounds().origin(), | 344 button->bounds().origin(), |
345 button->GetBoundsInScreen().origin(), 0); | 345 button->GetBoundsInScreen().origin(), 0); |
346 button_host->PointerPressedOnButton(button, pointer, click_event); | 346 button_host->PointerPressedOnButton(button, pointer, click_event); |
347 return button; | 347 return button; |
348 } | 348 } |
349 | 349 |
350 views::View* SimulateClick(internal::LauncherButtonHost::Pointer pointer, | 350 views::View* SimulateClick(internal::ShelfButtonHost::Pointer pointer, |
351 int button_index) { | 351 int button_index) { |
352 internal::LauncherButtonHost* button_host = shelf_view_; | 352 internal::ShelfButtonHost* button_host = shelf_view_; |
353 views::View* button = SimulateButtonPressed(pointer, button_index); | 353 views::View* button = SimulateButtonPressed(pointer, button_index); |
354 button_host->PointerReleasedOnButton(button, | 354 button_host->PointerReleasedOnButton(button, |
355 internal::LauncherButtonHost::MOUSE, | 355 internal::ShelfButtonHost::MOUSE, |
356 false); | 356 false); |
357 return button; | 357 return button; |
358 } | 358 } |
359 | 359 |
360 views::View* SimulateDrag(internal::LauncherButtonHost::Pointer pointer, | 360 views::View* SimulateDrag(internal::ShelfButtonHost::Pointer pointer, |
361 int button_index, | 361 int button_index, |
362 int destination_index) { | 362 int destination_index) { |
363 internal::LauncherButtonHost* button_host = shelf_view_; | 363 internal::ShelfButtonHost* button_host = shelf_view_; |
364 views::View* button = SimulateButtonPressed(pointer, button_index); | 364 views::View* button = SimulateButtonPressed(pointer, button_index); |
365 | 365 |
366 // Drag. | 366 // Drag. |
367 views::View* destination = test_api_->GetButton(destination_index); | 367 views::View* destination = test_api_->GetButton(destination_index); |
368 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, | 368 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, |
369 destination->bounds().origin(), | 369 destination->bounds().origin(), |
370 destination->GetBoundsInScreen().origin(), 0); | 370 destination->GetBoundsInScreen().origin(), 0); |
371 button_host->PointerDraggedOnButton(button, pointer, drag_event); | 371 button_host->PointerDraggedOnButton(button, pointer, drag_event); |
372 return button; | 372 return button; |
373 } | 373 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 if (button) { | 775 if (button) { |
776 EXPECT_TRUE(button->visible()) << "button index=" << i; | 776 EXPECT_TRUE(button->visible()) << "button index=" << i; |
777 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; | 777 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; |
778 } | 778 } |
779 } | 779 } |
780 } | 780 } |
781 | 781 |
782 // Check that model changes are handled correctly while a launcher icon is being | 782 // Check that model changes are handled correctly while a launcher icon is being |
783 // dragged. | 783 // dragged. |
784 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { | 784 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { |
785 internal::LauncherButtonHost* button_host = shelf_view_; | 785 internal::ShelfButtonHost* button_host = shelf_view_; |
786 | 786 |
787 std::vector<std::pair<LauncherID, views::View*> > id_map; | 787 std::vector<std::pair<LauncherID, views::View*> > id_map; |
788 SetupForDragTest(&id_map); | 788 SetupForDragTest(&id_map); |
789 | 789 |
790 // Dragging browser shortcut at index 1. | 790 // Dragging browser shortcut at index 1. |
791 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | 791 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
792 views::View* dragged_button = SimulateDrag( | 792 views::View* dragged_button = SimulateDrag( |
793 internal::LauncherButtonHost::MOUSE, 1, 3); | 793 internal::ShelfButtonHost::MOUSE, 1, 3); |
794 std::rotate(id_map.begin() + 1, | 794 std::rotate(id_map.begin() + 1, |
795 id_map.begin() + 2, | 795 id_map.begin() + 2, |
796 id_map.begin() + 4); | 796 id_map.begin() + 4); |
797 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 797 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
798 button_host->PointerReleasedOnButton(dragged_button, | 798 button_host->PointerReleasedOnButton(dragged_button, |
799 internal::LauncherButtonHost::MOUSE, | 799 internal::ShelfButtonHost::MOUSE, |
800 false); | 800 false); |
801 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 801 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
802 | 802 |
803 // Dragging changes model order. | 803 // Dragging changes model order. |
804 dragged_button = SimulateDrag( | 804 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
805 internal::LauncherButtonHost::MOUSE, 1, 3); | |
806 std::rotate(id_map.begin() + 1, | 805 std::rotate(id_map.begin() + 1, |
807 id_map.begin() + 2, | 806 id_map.begin() + 2, |
808 id_map.begin() + 4); | 807 id_map.begin() + 4); |
809 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 808 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
810 | 809 |
811 // Cancelling the drag operation restores previous order. | 810 // Cancelling the drag operation restores previous order. |
812 button_host->PointerReleasedOnButton(dragged_button, | 811 button_host->PointerReleasedOnButton(dragged_button, |
813 internal::LauncherButtonHost::MOUSE, | 812 internal::ShelfButtonHost::MOUSE, |
814 true); | 813 true); |
815 std::rotate(id_map.begin() + 1, | 814 std::rotate(id_map.begin() + 1, |
816 id_map.begin() + 3, | 815 id_map.begin() + 3, |
817 id_map.begin() + 4); | 816 id_map.begin() + 4); |
818 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 817 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
819 | 818 |
820 // Deleting an item keeps the remaining intact. | 819 // Deleting an item keeps the remaining intact. |
821 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | 820 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
822 model_->RemoveItemAt(1); | 821 model_->RemoveItemAt(1); |
823 id_map.erase(id_map.begin() + 1); | 822 id_map.erase(id_map.begin() + 1); |
824 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 823 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
825 button_host->PointerReleasedOnButton(dragged_button, | 824 button_host->PointerReleasedOnButton(dragged_button, |
826 internal::LauncherButtonHost::MOUSE, | 825 internal::ShelfButtonHost::MOUSE, |
827 false); | 826 false); |
828 | 827 |
829 // Adding a launcher item cancels the drag and respects the order. | 828 // Adding a launcher item cancels the drag and respects the order. |
830 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | 829 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
831 LauncherID new_id = AddAppShortcut(); | 830 LauncherID new_id = AddAppShortcut(); |
832 id_map.insert(id_map.begin() + 6, | 831 id_map.insert(id_map.begin() + 6, |
833 std::make_pair(new_id, GetButtonByID(new_id))); | 832 std::make_pair(new_id, GetButtonByID(new_id))); |
834 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 833 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
835 button_host->PointerReleasedOnButton(dragged_button, | 834 button_host->PointerReleasedOnButton(dragged_button, |
836 internal::LauncherButtonHost::MOUSE, | 835 internal::ShelfButtonHost::MOUSE, |
837 false); | 836 false); |
838 | 837 |
839 // Adding a launcher item at the end (i.e. a panel) canels drag and respects | 838 // Adding a launcher item at the end (i.e. a panel) canels drag and respects |
840 // the order. | 839 // the order. |
841 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | 840 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
842 new_id = AddPanel(); | 841 new_id = AddPanel(); |
843 id_map.insert(id_map.begin() + 7, | 842 id_map.insert(id_map.begin() + 7, |
844 std::make_pair(new_id, GetButtonByID(new_id))); | 843 std::make_pair(new_id, GetButtonByID(new_id))); |
845 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 844 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
846 button_host->PointerReleasedOnButton(dragged_button, | 845 button_host->PointerReleasedOnButton(dragged_button, |
847 internal::LauncherButtonHost::MOUSE, | 846 internal::ShelfButtonHost::MOUSE, |
848 false); | 847 false); |
849 } | 848 } |
850 | 849 |
851 TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { | 850 TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { |
852 internal::LauncherButtonHost* button_host = shelf_view_; | 851 internal::ShelfButtonHost* button_host = shelf_view_; |
853 | 852 |
854 std::vector<std::pair<LauncherID, views::View*> > id_map; | 853 std::vector<std::pair<LauncherID, views::View*> > id_map; |
855 SetupForDragTest(&id_map); | 854 SetupForDragTest(&id_map); |
856 | 855 |
857 // Dragging browser shortcut at index 0. | 856 // Dragging browser shortcut at index 0. |
858 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | 857 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); |
859 views::View* dragged_button = SimulateDrag( | 858 views::View* dragged_button = SimulateDrag( |
860 internal::LauncherButtonHost::MOUSE, 0, 2); | 859 internal::ShelfButtonHost::MOUSE, 0, 2); |
861 std::rotate(id_map.begin(), | 860 std::rotate(id_map.begin(), |
862 id_map.begin() + 1, | 861 id_map.begin() + 1, |
863 id_map.begin() + 3); | 862 id_map.begin() + 3); |
864 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 863 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
865 button_host->PointerReleasedOnButton(dragged_button, | 864 button_host->PointerReleasedOnButton(dragged_button, |
866 internal::LauncherButtonHost::MOUSE, | 865 internal::ShelfButtonHost::MOUSE, |
867 false); | 866 false); |
868 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); | 867 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); |
869 | 868 |
870 // Dragging changes model order. | 869 // Dragging changes model order. |
871 dragged_button = SimulateDrag( | 870 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
872 internal::LauncherButtonHost::MOUSE, 0, 2); | |
873 std::rotate(id_map.begin(), | 871 std::rotate(id_map.begin(), |
874 id_map.begin() + 1, | 872 id_map.begin() + 1, |
875 id_map.begin() + 3); | 873 id_map.begin() + 3); |
876 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 874 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
877 | 875 |
878 // Cancelling the drag operation restores previous order. | 876 // Cancelling the drag operation restores previous order. |
879 button_host->PointerReleasedOnButton(dragged_button, | 877 button_host->PointerReleasedOnButton(dragged_button, |
880 internal::LauncherButtonHost::MOUSE, | 878 internal::ShelfButtonHost::MOUSE, |
881 true); | 879 true); |
882 std::rotate(id_map.begin(), | 880 std::rotate(id_map.begin(), |
883 id_map.begin() + 2, | 881 id_map.begin() + 2, |
884 id_map.begin() + 3); | 882 id_map.begin() + 3); |
885 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 883 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
886 | 884 |
887 // Deleting an item keeps the remaining intact. | 885 // Deleting an item keeps the remaining intact. |
888 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2); | 886 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
889 model_->RemoveItemAt(1); | 887 model_->RemoveItemAt(1); |
890 id_map.erase(id_map.begin() + 1); | 888 id_map.erase(id_map.begin() + 1); |
891 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 889 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
892 button_host->PointerReleasedOnButton(dragged_button, | 890 button_host->PointerReleasedOnButton(dragged_button, |
893 internal::LauncherButtonHost::MOUSE, | 891 internal::ShelfButtonHost::MOUSE, |
894 false); | 892 false); |
895 | 893 |
896 // Adding a launcher item cancels the drag and respects the order. | 894 // Adding a launcher item cancels the drag and respects the order. |
897 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2); | 895 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
898 LauncherID new_id = AddAppShortcut(); | 896 LauncherID new_id = AddAppShortcut(); |
899 id_map.insert(id_map.begin() + 5, | 897 id_map.insert(id_map.begin() + 5, |
900 std::make_pair(new_id, GetButtonByID(new_id))); | 898 std::make_pair(new_id, GetButtonByID(new_id))); |
901 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 899 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
902 button_host->PointerReleasedOnButton(dragged_button, | 900 button_host->PointerReleasedOnButton(dragged_button, |
903 internal::LauncherButtonHost::MOUSE, | 901 internal::ShelfButtonHost::MOUSE, |
904 false); | 902 false); |
905 | 903 |
906 // Adding a launcher item at the end (i.e. a panel) canels drag and respects | 904 // Adding a launcher item at the end (i.e. a panel) canels drag and respects |
907 // the order. | 905 // the order. |
908 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2); | 906 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
909 new_id = AddPanel(); | 907 new_id = AddPanel(); |
910 id_map.insert(id_map.begin() + 7, | 908 id_map.insert(id_map.begin() + 7, |
911 std::make_pair(new_id, GetButtonByID(new_id))); | 909 std::make_pair(new_id, GetButtonByID(new_id))); |
912 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 910 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
913 button_host->PointerReleasedOnButton(dragged_button, | 911 button_host->PointerReleasedOnButton(dragged_button, |
914 internal::LauncherButtonHost::MOUSE, | 912 internal::ShelfButtonHost::MOUSE, |
915 false); | 913 false); |
916 } | 914 } |
917 | 915 |
918 // Check that 2nd drag from the other pointer would be ignored. | 916 // Check that 2nd drag from the other pointer would be ignored. |
919 TEST_F(ShelfViewTest, SimultaneousDrag) { | 917 TEST_F(ShelfViewTest, SimultaneousDrag) { |
920 internal::LauncherButtonHost* button_host = shelf_view_; | 918 internal::ShelfButtonHost* button_host = shelf_view_; |
921 | 919 |
922 std::vector<std::pair<LauncherID, views::View*> > id_map; | 920 std::vector<std::pair<LauncherID, views::View*> > id_map; |
923 SetupForDragTest(&id_map); | 921 SetupForDragTest(&id_map); |
924 | 922 |
925 // Start a mouse drag. | 923 // Start a mouse drag. |
926 views::View* dragged_button_mouse = SimulateDrag( | 924 views::View* dragged_button_mouse = SimulateDrag( |
927 internal::LauncherButtonHost::MOUSE, 1, 3); | 925 internal::ShelfButtonHost::MOUSE, 1, 3); |
928 std::rotate(id_map.begin() + 1, | 926 std::rotate(id_map.begin() + 1, |
929 id_map.begin() + 2, | 927 id_map.begin() + 2, |
930 id_map.begin() + 4); | 928 id_map.begin() + 4); |
931 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 929 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
932 // Attempt a touch drag before the mouse drag finishes. | 930 // Attempt a touch drag before the mouse drag finishes. |
933 views::View* dragged_button_touch = SimulateDrag( | 931 views::View* dragged_button_touch = SimulateDrag( |
934 internal::LauncherButtonHost::TOUCH, 4, 2); | 932 internal::ShelfButtonHost::TOUCH, 4, 2); |
935 | 933 |
936 // Nothing changes since 2nd drag is ignored. | 934 // Nothing changes since 2nd drag is ignored. |
937 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 935 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
938 | 936 |
939 // Finish the mouse drag. | 937 // Finish the mouse drag. |
940 button_host->PointerReleasedOnButton(dragged_button_mouse, | 938 button_host->PointerReleasedOnButton(dragged_button_mouse, |
941 internal::LauncherButtonHost::MOUSE, | 939 internal::ShelfButtonHost::MOUSE, |
942 false); | 940 false); |
943 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 941 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
944 | 942 |
945 // Now start a touch drag. | 943 // Now start a touch drag. |
946 dragged_button_touch = SimulateDrag( | 944 dragged_button_touch = SimulateDrag(internal::ShelfButtonHost::TOUCH, 4, 2); |
947 internal::LauncherButtonHost::TOUCH, 4, 2); | |
948 std::rotate(id_map.begin() + 3, | 945 std::rotate(id_map.begin() + 3, |
949 id_map.begin() + 4, | 946 id_map.begin() + 4, |
950 id_map.begin() + 5); | 947 id_map.begin() + 5); |
951 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 948 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
952 | 949 |
953 // And attempt a mouse drag before the touch drag finishes. | 950 // And attempt a mouse drag before the touch drag finishes. |
954 dragged_button_mouse = SimulateDrag( | 951 dragged_button_mouse = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 2); |
955 internal::LauncherButtonHost::MOUSE, 1, 2); | |
956 | 952 |
957 // Nothing changes since 2nd drag is ignored. | 953 // Nothing changes since 2nd drag is ignored. |
958 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 954 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
959 | 955 |
960 button_host->PointerReleasedOnButton(dragged_button_touch, | 956 button_host->PointerReleasedOnButton(dragged_button_touch, |
961 internal::LauncherButtonHost::TOUCH, | 957 internal::ShelfButtonHost::TOUCH, |
962 false); | 958 false); |
963 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 959 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
964 } | 960 } |
965 | 961 |
966 // Check that clicking first on one item and then dragging another works as | 962 // Check that clicking first on one item and then dragging another works as |
967 // expected. | 963 // expected. |
968 TEST_F(ShelfViewTest, ClickOneDragAnother) { | 964 TEST_F(ShelfViewTest, ClickOneDragAnother) { |
969 internal::LauncherButtonHost* button_host = shelf_view_; | 965 internal::ShelfButtonHost* button_host = shelf_view_; |
970 | 966 |
971 std::vector<std::pair<LauncherID, views::View*> > id_map; | 967 std::vector<std::pair<LauncherID, views::View*> > id_map; |
972 SetupForDragTest(&id_map); | 968 SetupForDragTest(&id_map); |
973 | 969 |
974 // A click on item 1 is simulated. | 970 // A click on item 1 is simulated. |
975 SimulateClick(internal::LauncherButtonHost::MOUSE, 1); | 971 SimulateClick(internal::ShelfButtonHost::MOUSE, 1); |
976 | 972 |
977 // Dragging browser index at 0 should change the model order correctly. | 973 // Dragging browser index at 0 should change the model order correctly. |
978 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | 974 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
979 views::View* dragged_button = SimulateDrag( | 975 views::View* dragged_button = SimulateDrag( |
980 internal::LauncherButtonHost::MOUSE, 1, 3); | 976 internal::ShelfButtonHost::MOUSE, 1, 3); |
981 std::rotate(id_map.begin() + 1, | 977 std::rotate(id_map.begin() + 1, |
982 id_map.begin() + 2, | 978 id_map.begin() + 2, |
983 id_map.begin() + 4); | 979 id_map.begin() + 4); |
984 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 980 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
985 button_host->PointerReleasedOnButton(dragged_button, | 981 button_host->PointerReleasedOnButton(dragged_button, |
986 internal::LauncherButtonHost::MOUSE, | 982 internal::ShelfButtonHost::MOUSE, |
987 false); | 983 false); |
988 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 984 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
989 } | 985 } |
990 | 986 |
991 // Confirm that item status changes are reflected in the buttons. | 987 // Confirm that item status changes are reflected in the buttons. |
992 TEST_F(ShelfViewTest, LauncherItemStatus) { | 988 TEST_F(ShelfViewTest, LauncherItemStatus) { |
993 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 989 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
994 test_api_->GetButtonCount()); | 990 test_api_->GetButtonCount()); |
995 | 991 |
996 // Add platform app button. | 992 // Add platform app button. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 1073 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
1078 test_api_->GetButtonCount()); | 1074 test_api_->GetButtonCount()); |
1079 | 1075 |
1080 // Prepare some items to the launcher. | 1076 // Prepare some items to the launcher. |
1081 LauncherID app_button_id = AddAppShortcut(); | 1077 LauncherID app_button_id = AddAppShortcut(); |
1082 LauncherID platform_button_id = AddPlatformApp(); | 1078 LauncherID platform_button_id = AddPlatformApp(); |
1083 | 1079 |
1084 internal::LauncherButton* app_button = GetButtonByID(app_button_id); | 1080 internal::LauncherButton* app_button = GetButtonByID(app_button_id); |
1085 internal::LauncherButton* platform_button = GetButtonByID(platform_button_id); | 1081 internal::LauncherButton* platform_button = GetButtonByID(platform_button_id); |
1086 | 1082 |
1087 internal::LauncherButtonHost* button_host = shelf_view_; | 1083 internal::ShelfButtonHost* button_host = shelf_view_; |
1088 internal::ShelfTooltipManager* tooltip_manager = | 1084 internal::ShelfTooltipManager* tooltip_manager = |
1089 shelf_view_->tooltip_manager(); | 1085 shelf_view_->tooltip_manager(); |
1090 | 1086 |
1091 button_host->MouseEnteredButton(app_button); | 1087 button_host->MouseEnteredButton(app_button); |
1092 // There's a delay to show the tooltip, so it's not visible yet. | 1088 // There's a delay to show the tooltip, so it's not visible yet. |
1093 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1089 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1094 EXPECT_EQ(app_button, GetTooltipAnchorView()); | 1090 EXPECT_EQ(app_button, GetTooltipAnchorView()); |
1095 | 1091 |
1096 ShowTooltip(); | 1092 ShowTooltip(); |
1097 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1093 EXPECT_TRUE(tooltip_manager->IsVisible()); |
(...skipping 17 matching lines...) Expand all Loading... |
1115 button_host->MouseEnteredButton(app_button); | 1111 button_host->MouseEnteredButton(app_button); |
1116 button_host->MouseExitedButton(app_button); | 1112 button_host->MouseExitedButton(app_button); |
1117 button_host->MouseEnteredButton(platform_button); | 1113 button_host->MouseEnteredButton(platform_button); |
1118 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1114 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1119 EXPECT_EQ(platform_button, GetTooltipAnchorView()); | 1115 EXPECT_EQ(platform_button, GetTooltipAnchorView()); |
1120 } | 1116 } |
1121 | 1117 |
1122 // Verify a fix for crash caused by a tooltip update for a deleted launcher | 1118 // Verify a fix for crash caused by a tooltip update for a deleted launcher |
1123 // button, see crbug.com/288838. | 1119 // button, see crbug.com/288838. |
1124 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { | 1120 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { |
1125 internal::LauncherButtonHost* button_host = shelf_view_; | 1121 internal::ShelfButtonHost* button_host = shelf_view_; |
1126 internal::ShelfTooltipManager* tooltip_manager = | 1122 internal::ShelfTooltipManager* tooltip_manager = |
1127 shelf_view_->tooltip_manager(); | 1123 shelf_view_->tooltip_manager(); |
1128 | 1124 |
1129 // Add an item to the launcher. | 1125 // Add an item to the launcher. |
1130 LauncherID app_button_id = AddAppShortcut(); | 1126 LauncherID app_button_id = AddAppShortcut(); |
1131 internal::LauncherButton* app_button = GetButtonByID(app_button_id); | 1127 internal::LauncherButton* app_button = GetButtonByID(app_button_id); |
1132 | 1128 |
1133 // Spawn a tooltip on that item. | 1129 // Spawn a tooltip on that item. |
1134 button_host->MouseEnteredButton(app_button); | 1130 button_host->MouseEnteredButton(app_button); |
1135 ShowTooltip(); | 1131 ShowTooltip(); |
1136 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1132 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1137 | 1133 |
1138 // Remove the app shortcut while the tooltip is open. The tooltip should be | 1134 // Remove the app shortcut while the tooltip is open. The tooltip should be |
1139 // closed. | 1135 // closed. |
1140 RemoveByID(app_button_id); | 1136 RemoveByID(app_button_id); |
1141 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1137 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1142 | 1138 |
1143 // Change the shelf layout. This should not crash. | 1139 // Change the shelf layout. This should not crash. |
1144 ash::Shell::GetInstance()->SetShelfAlignment( | 1140 ash::Shell::GetInstance()->SetShelfAlignment( |
1145 ash::SHELF_ALIGNMENT_LEFT, | 1141 ash::SHELF_ALIGNMENT_LEFT, |
1146 ash::Shell::GetPrimaryRootWindow()); | 1142 ash::Shell::GetPrimaryRootWindow()); |
1147 } | 1143 } |
1148 | 1144 |
1149 // Changing the shelf alignment closes any open tooltip. | 1145 // Changing the shelf alignment closes any open tooltip. |
1150 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { | 1146 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { |
1151 internal::LauncherButtonHost* button_host = shelf_view_; | 1147 internal::ShelfButtonHost* button_host = shelf_view_; |
1152 internal::ShelfTooltipManager* tooltip_manager = | 1148 internal::ShelfTooltipManager* tooltip_manager = |
1153 shelf_view_->tooltip_manager(); | 1149 shelf_view_->tooltip_manager(); |
1154 | 1150 |
1155 // Add an item to the launcher. | 1151 // Add an item to the launcher. |
1156 LauncherID app_button_id = AddAppShortcut(); | 1152 LauncherID app_button_id = AddAppShortcut(); |
1157 internal::LauncherButton* app_button = GetButtonByID(app_button_id); | 1153 internal::LauncherButton* app_button = GetButtonByID(app_button_id); |
1158 | 1154 |
1159 // Spawn a tooltip on the item. | 1155 // Spawn a tooltip on the item. |
1160 button_host->MouseEnteredButton(app_button); | 1156 button_host->MouseEnteredButton(app_button); |
1161 ShowTooltip(); | 1157 ShowTooltip(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 test_api_->RunMessageLoopUntilAnimationsDone(); | 1368 test_api_->RunMessageLoopUntilAnimationsDone(); |
1373 CheckAllItemsAreInBounds(); | 1369 CheckAllItemsAreInBounds(); |
1374 } | 1370 } |
1375 | 1371 |
1376 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1372 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
1377 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1373 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
1378 testing::Bool()); | 1374 testing::Bool()); |
1379 | 1375 |
1380 } // namespace test | 1376 } // namespace test |
1381 } // namespace ash | 1377 } // namespace ash |
OLD | NEW |