OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/menu/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 &test_event_handler); | 591 &test_event_handler); |
592 | 592 |
593 std::vector<int> devices; | 593 std::vector<int> devices; |
594 devices.push_back(1); | 594 devices.push_back(1); |
595 ui::SetUpTouchDevicesForTest(devices); | 595 ui::SetUpTouchDevicesForTest(devices); |
596 | 596 |
597 event_generator()->PressTouchId(0); | 597 event_generator()->PressTouchId(0); |
598 event_generator()->PressTouchId(1); | 598 event_generator()->PressTouchId(1); |
599 event_generator()->ReleaseTouchId(0); | 599 event_generator()->ReleaseTouchId(0); |
600 | 600 |
601 int mouse_event_flags = 0; | 601 menu_controller()->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
602 MenuItemView* run_result = menu_controller()->Run( | 602 MENU_ANCHOR_TOPLEFT, false, false); |
603 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, | |
604 false, &mouse_event_flags); | |
605 EXPECT_EQ(run_result, nullptr); | |
606 | 603 |
607 MenuControllerTest::ReleaseTouchId(1); | 604 MenuControllerTest::ReleaseTouchId(1); |
608 TestAsyncEscapeKey(); | 605 TestAsyncEscapeKey(); |
609 | 606 |
610 EXPECT_EQ(MenuController::EXIT_ALL, menu_exit_type()); | 607 EXPECT_EQ(MenuController::EXIT_ALL, menu_exit_type()); |
611 EXPECT_EQ(0, test_event_handler.outstanding_touches()); | 608 EXPECT_EQ(0, test_event_handler.outstanding_touches()); |
612 | 609 |
613 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( | 610 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( |
614 &test_event_handler); | 611 &test_event_handler); |
615 } | 612 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 // Increment twice to move selection to |button2|. | 903 // Increment twice to move selection to |button2|. |
907 IncrementSelection(); | 904 IncrementSelection(); |
908 IncrementSelection(); | 905 IncrementSelection(); |
909 EXPECT_EQ(5, pending_state_item()->GetCommand()); | 906 EXPECT_EQ(5, pending_state_item()->GetCommand()); |
910 EXPECT_FALSE(button1->IsHotTracked()); | 907 EXPECT_FALSE(button1->IsHotTracked()); |
911 EXPECT_TRUE(button2->IsHotTracked()); | 908 EXPECT_TRUE(button2->IsHotTracked()); |
912 EXPECT_FALSE(button3->IsHotTracked()); | 909 EXPECT_FALSE(button3->IsHotTracked()); |
913 EXPECT_EQ(button2, GetHotButton()); | 910 EXPECT_EQ(button2, GetHotButton()); |
914 | 911 |
915 MenuController* controller = menu_controller(); | 912 MenuController* controller = menu_controller(); |
916 int mouse_event_flags = 0; | 913 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
917 MenuItemView* run_result = | 914 MENU_ANCHOR_TOPLEFT, false, false); |
918 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
919 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
920 EXPECT_EQ(run_result, nullptr); | |
921 | 915 |
922 // |button2| should stay in hot-tracked state but menu controller should not | 916 // |button2| should stay in hot-tracked state but menu controller should not |
923 // track it anymore (preventing resetting hot-tracked state when changing | 917 // track it anymore (preventing resetting hot-tracked state when changing |
924 // selection while a nested run is active). | 918 // selection while a nested run is active). |
925 EXPECT_TRUE(button2->IsHotTracked()); | 919 EXPECT_TRUE(button2->IsHotTracked()); |
926 EXPECT_EQ(nullptr, GetHotButton()); | 920 EXPECT_EQ(nullptr, GetHotButton()); |
927 | 921 |
928 // Setting hot-tracked button while nested should get reverted when nested | 922 // Setting hot-tracked button while nested should get reverted when nested |
929 // menu run ends. | 923 // menu run ends. |
930 SetHotTrackedButton(button1); | 924 SetHotTrackedButton(button1); |
931 EXPECT_TRUE(button1->IsHotTracked()); | 925 EXPECT_TRUE(button1->IsHotTracked()); |
932 EXPECT_EQ(button1, GetHotButton()); | 926 EXPECT_EQ(button1, GetHotButton()); |
933 | 927 |
934 ExitMenuRun(); | 928 ExitMenuRun(); |
935 EXPECT_FALSE(button1->IsHotTracked()); | 929 EXPECT_FALSE(button1->IsHotTracked()); |
936 EXPECT_TRUE(button2->IsHotTracked()); | 930 EXPECT_TRUE(button2->IsHotTracked()); |
937 EXPECT_EQ(button2, GetHotButton()); | 931 EXPECT_EQ(button2, GetHotButton()); |
938 } | 932 } |
939 | 933 |
940 // Tests that a menu opened asynchronously, will notify its | 934 // Tests that a menu opened asynchronously, will notify its |
941 // MenuControllerDelegate when Accept is called. | 935 // MenuControllerDelegate when Accept is called. |
942 TEST_F(MenuControllerTest, AsynchronousAccept) { | 936 TEST_F(MenuControllerTest, AsynchronousAccept) { |
943 MenuController* controller = menu_controller(); | 937 MenuController* controller = menu_controller(); |
944 | 938 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
945 int mouse_event_flags = 0; | 939 MENU_ANCHOR_TOPLEFT, false, false); |
946 MenuItemView* run_result = | |
947 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
948 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
949 EXPECT_EQ(run_result, nullptr); | |
950 TestMenuControllerDelegate* delegate = menu_controller_delegate(); | 940 TestMenuControllerDelegate* delegate = menu_controller_delegate(); |
951 EXPECT_EQ(0, delegate->on_menu_closed_called()); | 941 EXPECT_EQ(0, delegate->on_menu_closed_called()); |
952 | 942 |
953 MenuItemView* accepted = menu_item()->GetSubmenu()->GetMenuItemAt(0); | 943 MenuItemView* accepted = menu_item()->GetSubmenu()->GetMenuItemAt(0); |
954 const int kEventFlags = 42; | 944 const int kEventFlags = 42; |
955 Accept(accepted, kEventFlags); | 945 Accept(accepted, kEventFlags); |
956 | 946 |
957 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 947 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
958 EXPECT_EQ(accepted, delegate->on_menu_closed_menu()); | 948 EXPECT_EQ(accepted, delegate->on_menu_closed_menu()); |
959 EXPECT_EQ(kEventFlags, delegate->on_menu_closed_mouse_event_flags()); | 949 EXPECT_EQ(kEventFlags, delegate->on_menu_closed_mouse_event_flags()); |
960 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 950 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
961 delegate->on_menu_closed_notify_type()); | 951 delegate->on_menu_closed_notify_type()); |
962 } | 952 } |
963 | 953 |
964 // Tests that a menu opened asynchronously, will notify its | 954 // Tests that a menu opened asynchronously, will notify its |
965 // MenuControllerDelegate when CancelAll is called. | 955 // MenuControllerDelegate when CancelAll is called. |
966 TEST_F(MenuControllerTest, AsynchronousCancelAll) { | 956 TEST_F(MenuControllerTest, AsynchronousCancelAll) { |
967 MenuController* controller = menu_controller(); | 957 MenuController* controller = menu_controller(); |
968 | 958 |
969 int mouse_event_flags = 0; | 959 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
970 MenuItemView* run_result = | 960 MENU_ANCHOR_TOPLEFT, false, false); |
971 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
972 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
973 EXPECT_EQ(run_result, nullptr); | |
974 TestMenuControllerDelegate* delegate = menu_controller_delegate(); | 961 TestMenuControllerDelegate* delegate = menu_controller_delegate(); |
975 EXPECT_EQ(0, delegate->on_menu_closed_called()); | 962 EXPECT_EQ(0, delegate->on_menu_closed_called()); |
976 | 963 |
977 controller->CancelAll(); | 964 controller->CancelAll(); |
978 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 965 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
979 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); | 966 EXPECT_EQ(nullptr, delegate->on_menu_closed_menu()); |
980 EXPECT_EQ(0, delegate->on_menu_closed_mouse_event_flags()); | 967 EXPECT_EQ(0, delegate->on_menu_closed_mouse_event_flags()); |
981 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 968 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
982 delegate->on_menu_closed_notify_type()); | 969 delegate->on_menu_closed_notify_type()); |
983 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); | 970 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); |
984 } | 971 } |
985 | 972 |
986 // Tests that canceling a nested menu restores the previous | 973 // Tests that canceling a nested menu restores the previous |
987 // MenuControllerDelegate, and notifies each delegate. | 974 // MenuControllerDelegate, and notifies each delegate. |
988 TEST_F(MenuControllerTest, AsynchronousNestedDelegate) { | 975 TEST_F(MenuControllerTest, AsynchronousNestedDelegate) { |
989 MenuController* controller = menu_controller(); | 976 MenuController* controller = menu_controller(); |
990 TestMenuControllerDelegate* delegate = menu_controller_delegate(); | 977 TestMenuControllerDelegate* delegate = menu_controller_delegate(); |
991 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 978 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
992 new TestMenuControllerDelegate()); | 979 new TestMenuControllerDelegate()); |
993 | 980 |
994 controller->AddNestedDelegate(nested_delegate.get()); | 981 controller->AddNestedDelegate(nested_delegate.get()); |
995 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 982 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
996 | 983 |
997 int mouse_event_flags = 0; | 984 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
998 MenuItemView* run_result = | 985 MENU_ANCHOR_TOPLEFT, false, false); |
999 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
1000 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
1001 EXPECT_EQ(run_result, nullptr); | |
1002 | 986 |
1003 controller->CancelAll(); | 987 controller->CancelAll(); |
1004 EXPECT_EQ(delegate, GetCurrentDelegate()); | 988 EXPECT_EQ(delegate, GetCurrentDelegate()); |
1005 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 989 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
1006 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); | 990 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); |
1007 EXPECT_EQ(nullptr, nested_delegate->on_menu_closed_menu()); | 991 EXPECT_EQ(nullptr, nested_delegate->on_menu_closed_menu()); |
1008 EXPECT_EQ(0, nested_delegate->on_menu_closed_mouse_event_flags()); | 992 EXPECT_EQ(0, nested_delegate->on_menu_closed_mouse_event_flags()); |
1009 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 993 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
1010 nested_delegate->on_menu_closed_notify_type()); | 994 nested_delegate->on_menu_closed_notify_type()); |
1011 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); | 995 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 // Tets that an asynchronous menu nested within an asynchronous menu closes both | 1090 // Tets that an asynchronous menu nested within an asynchronous menu closes both |
1107 // menus, and notifies both delegates. | 1091 // menus, and notifies both delegates. |
1108 TEST_F(MenuControllerTest, DoubleAsynchronousNested) { | 1092 TEST_F(MenuControllerTest, DoubleAsynchronousNested) { |
1109 MenuController* controller = menu_controller(); | 1093 MenuController* controller = menu_controller(); |
1110 TestMenuControllerDelegate* delegate = menu_controller_delegate(); | 1094 TestMenuControllerDelegate* delegate = menu_controller_delegate(); |
1111 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 1095 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
1112 new TestMenuControllerDelegate()); | 1096 new TestMenuControllerDelegate()); |
1113 | 1097 |
1114 // Nested run | 1098 // Nested run |
1115 controller->AddNestedDelegate(nested_delegate.get()); | 1099 controller->AddNestedDelegate(nested_delegate.get()); |
1116 int mouse_event_flags = 0; | 1100 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
1117 MenuItemView* run_result = | 1101 MENU_ANCHOR_TOPLEFT, false, false); |
1118 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
1119 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
1120 EXPECT_EQ(run_result, nullptr); | |
1121 | 1102 |
1122 controller->CancelAll(); | 1103 controller->CancelAll(); |
1123 EXPECT_EQ(1, delegate->on_menu_closed_called()); | 1104 EXPECT_EQ(1, delegate->on_menu_closed_called()); |
1124 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); | 1105 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); |
1125 } | 1106 } |
1126 | 1107 |
1127 // Tests that a nested menu does not crash when trying to repost events that | 1108 // Tests that a nested menu does not crash when trying to repost events that |
1128 // occur outside of the bounds of the menu. Instead a proper shutdown should | 1109 // occur outside of the bounds of the menu. Instead a proper shutdown should |
1129 // occur. | 1110 // occur. |
1130 TEST_F(MenuControllerTest, AsynchronousRepostEvent) { | 1111 TEST_F(MenuControllerTest, AsynchronousRepostEvent) { |
1131 MenuController* controller = menu_controller(); | 1112 MenuController* controller = menu_controller(); |
1132 TestMenuControllerDelegate* delegate = menu_controller_delegate(); | 1113 TestMenuControllerDelegate* delegate = menu_controller_delegate(); |
1133 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 1114 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
1134 new TestMenuControllerDelegate()); | 1115 new TestMenuControllerDelegate()); |
1135 | 1116 |
1136 controller->AddNestedDelegate(nested_delegate.get()); | 1117 controller->AddNestedDelegate(nested_delegate.get()); |
1137 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 1118 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
1138 | 1119 |
1139 MenuItemView* item = menu_item(); | 1120 MenuItemView* item = menu_item(); |
1140 int mouse_event_flags = 0; | 1121 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
1141 MenuItemView* run_result = | 1122 false, false); |
1142 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, | |
1143 false, false, &mouse_event_flags); | |
1144 EXPECT_EQ(run_result, nullptr); | |
1145 | 1123 |
1146 // Show a sub menu to target with a pointer selection. However have the event | 1124 // Show a sub menu to target with a pointer selection. However have the event |
1147 // occur outside of the bounds of the entire menu. | 1125 // occur outside of the bounds of the entire menu. |
1148 SubmenuView* sub_menu = item->GetSubmenu(); | 1126 SubmenuView* sub_menu = item->GetSubmenu(); |
1149 sub_menu->ShowAt(owner(), item->bounds(), false); | 1127 sub_menu->ShowAt(owner(), item->bounds(), false); |
1150 gfx::Point location(sub_menu->bounds().bottom_right()); | 1128 gfx::Point location(sub_menu->bounds().bottom_right()); |
1151 location.Offset(1, 1); | 1129 location.Offset(1, 1); |
1152 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, | 1130 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, |
1153 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 1131 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
1154 | 1132 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 // cause a crash. ASAN bots should not detect use-after-free in MenuController. | 1175 // cause a crash. ASAN bots should not detect use-after-free in MenuController. |
1198 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) { | 1176 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) { |
1199 MenuController* controller = menu_controller(); | 1177 MenuController* controller = menu_controller(); |
1200 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 1178 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
1201 new TestMenuControllerDelegate()); | 1179 new TestMenuControllerDelegate()); |
1202 | 1180 |
1203 controller->AddNestedDelegate(nested_delegate.get()); | 1181 controller->AddNestedDelegate(nested_delegate.get()); |
1204 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 1182 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
1205 | 1183 |
1206 MenuItemView* item = menu_item(); | 1184 MenuItemView* item = menu_item(); |
1207 int mouse_event_flags = 0; | 1185 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
1208 MenuItemView* run_result = | 1186 false, false); |
1209 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, | |
1210 false, false, &mouse_event_flags); | |
1211 EXPECT_EQ(run_result, nullptr); | |
1212 | 1187 |
1213 // Show a sub menu to target with a pointer selection. However have the event | 1188 // Show a sub menu to target with a pointer selection. However have the event |
1214 // occur outside of the bounds of the entire menu. | 1189 // occur outside of the bounds of the entire menu. |
1215 SubmenuView* sub_menu = item->GetSubmenu(); | 1190 SubmenuView* sub_menu = item->GetSubmenu(); |
1216 sub_menu->ShowAt(owner(), item->bounds(), true); | 1191 sub_menu->ShowAt(owner(), item->bounds(), true); |
1217 gfx::Point location(sub_menu->bounds().bottom_right()); | 1192 gfx::Point location(sub_menu->bounds().bottom_right()); |
1218 location.Offset(1, 1); | 1193 location.Offset(1, 1); |
1219 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, | 1194 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, |
1220 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 1195 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
1221 | 1196 |
(...skipping 13 matching lines...) Expand all Loading... |
1235 // cause a crash. ASAN bots should not detect use-after-free in MenuController. | 1210 // cause a crash. ASAN bots should not detect use-after-free in MenuController. |
1236 TEST_F(MenuControllerTest, AsynchronousGestureDeletesController) { | 1211 TEST_F(MenuControllerTest, AsynchronousGestureDeletesController) { |
1237 MenuController* controller = menu_controller(); | 1212 MenuController* controller = menu_controller(); |
1238 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 1213 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
1239 new TestMenuControllerDelegate()); | 1214 new TestMenuControllerDelegate()); |
1240 | 1215 |
1241 controller->AddNestedDelegate(nested_delegate.get()); | 1216 controller->AddNestedDelegate(nested_delegate.get()); |
1242 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 1217 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
1243 | 1218 |
1244 MenuItemView* item = menu_item(); | 1219 MenuItemView* item = menu_item(); |
1245 int mouse_event_flags = 0; | 1220 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
1246 MenuItemView* run_result = | 1221 false, false); |
1247 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, | |
1248 false, false, &mouse_event_flags); | |
1249 EXPECT_EQ(run_result, nullptr); | |
1250 | 1222 |
1251 // Show a sub menu to target with a tap event. | 1223 // Show a sub menu to target with a tap event. |
1252 SubmenuView* sub_menu = item->GetSubmenu(); | 1224 SubmenuView* sub_menu = item->GetSubmenu(); |
1253 sub_menu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), true); | 1225 sub_menu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), true); |
1254 | 1226 |
1255 gfx::Point location(sub_menu->bounds().CenterPoint()); | 1227 gfx::Point location(sub_menu->bounds().CenterPoint()); |
1256 ui::GestureEvent event(location.x(), location.y(), 0, ui::EventTimeForNow(), | 1228 ui::GestureEvent event(location.x(), location.y(), 0, ui::EventTimeForNow(), |
1257 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 1229 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
1258 | 1230 |
1259 // This will lead to MenuController being deleted during the processing of the | 1231 // This will lead to MenuController being deleted during the processing of the |
1260 // gesture event. The remainder of this test, and TearDown should not crash. | 1232 // gesture event. The remainder of this test, and TearDown should not crash. |
1261 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); | 1233 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); |
1262 controller->OnGestureEvent(sub_menu, &event); | 1234 controller->OnGestureEvent(sub_menu, &event); |
1263 | 1235 |
1264 // Close to remove observers before test TearDown | 1236 // Close to remove observers before test TearDown |
1265 sub_menu->Close(); | 1237 sub_menu->Close(); |
1266 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); | 1238 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); |
1267 } | 1239 } |
1268 | 1240 |
1269 #if defined(USE_AURA) | 1241 #if defined(USE_AURA) |
1270 // Tests that when an asynchronous menu receives a cancel event, that it closes. | 1242 // Tests that when an asynchronous menu receives a cancel event, that it closes. |
1271 TEST_F(MenuControllerTest, AsynchronousCancelEvent) { | 1243 TEST_F(MenuControllerTest, AsynchronousCancelEvent) { |
1272 ExitMenuRun(); | 1244 ExitMenuRun(); |
1273 MenuController* controller = menu_controller(); | 1245 MenuController* controller = menu_controller(); |
1274 | 1246 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
1275 int mouse_event_flags = 0; | 1247 MENU_ANCHOR_TOPLEFT, false, false); |
1276 MenuItemView* run_result = | |
1277 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
1278 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
1279 EXPECT_EQ(run_result, nullptr); | |
1280 EXPECT_EQ(MenuController::EXIT_NONE, controller->exit_type()); | 1248 EXPECT_EQ(MenuController::EXIT_NONE, controller->exit_type()); |
1281 ui::CancelModeEvent cancel_event; | 1249 ui::CancelModeEvent cancel_event; |
1282 event_generator()->Dispatch(&cancel_event); | 1250 event_generator()->Dispatch(&cancel_event); |
1283 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); | 1251 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); |
1284 } | 1252 } |
1285 | 1253 |
1286 // Tests that if a menu is ran without a widget, that MenuPreTargetHandler does | 1254 // Tests that if a menu is ran without a widget, that MenuPreTargetHandler does |
1287 // not cause a crash. | 1255 // not cause a crash. |
1288 TEST_F(MenuControllerTest, RunWithoutWidgetDoesntCrash) { | 1256 TEST_F(MenuControllerTest, RunWithoutWidgetDoesntCrash) { |
1289 ExitMenuRun(); | 1257 ExitMenuRun(); |
1290 MenuController* controller = menu_controller(); | 1258 MenuController* controller = menu_controller(); |
1291 int mouse_event_flags = 0; | 1259 controller->Run(nullptr, nullptr, menu_item(), gfx::Rect(), |
1292 MenuItemView* run_result = | 1260 MENU_ANCHOR_TOPLEFT, false, false); |
1293 controller->Run(nullptr, nullptr, menu_item(), gfx::Rect(), | |
1294 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
1295 EXPECT_EQ(run_result, nullptr); | |
1296 } | 1261 } |
1297 | 1262 |
1298 // Tests that if a MenuController is destroying during drag/drop, and another | 1263 // Tests that if a MenuController is destroying during drag/drop, and another |
1299 // MenuController becomes active, that the exiting of drag does not cause a | 1264 // MenuController becomes active, that the exiting of drag does not cause a |
1300 // crash. | 1265 // crash. |
1301 TEST_F(MenuControllerTest, MenuControllerReplacedDuringDrag) { | 1266 TEST_F(MenuControllerTest, MenuControllerReplacedDuringDrag) { |
1302 // Build the menu so that the appropriate root window is available to set the | 1267 // Build the menu so that the appropriate root window is available to set the |
1303 // drag drop client on. | 1268 // drag drop client on. |
1304 AddButtonMenuItems(); | 1269 AddButtonMenuItems(); |
1305 TestDragDropClient drag_drop_client( | 1270 TestDragDropClient drag_drop_client( |
(...skipping 24 matching lines...) Expand all Loading... |
1330 ->GetRootWindow(), | 1295 ->GetRootWindow(), |
1331 &drag_drop_client); | 1296 &drag_drop_client); |
1332 StartDrag(); | 1297 StartDrag(); |
1333 } | 1298 } |
1334 | 1299 |
1335 // Tests that when releasing the ref on ViewsDelegate and MenuController is | 1300 // Tests that when releasing the ref on ViewsDelegate and MenuController is |
1336 // deleted, that shutdown occurs without crashing. | 1301 // deleted, that shutdown occurs without crashing. |
1337 TEST_F(MenuControllerTest, DestroyedDuringViewsRelease) { | 1302 TEST_F(MenuControllerTest, DestroyedDuringViewsRelease) { |
1338 ExitMenuRun(); | 1303 ExitMenuRun(); |
1339 MenuController* controller = menu_controller(); | 1304 MenuController* controller = menu_controller(); |
1340 | 1305 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), |
1341 int mouse_event_flags = 0; | 1306 MENU_ANCHOR_TOPLEFT, false, false); |
1342 MenuItemView* run_result = | |
1343 controller->Run(owner(), nullptr, menu_item(), gfx::Rect(), | |
1344 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | |
1345 EXPECT_EQ(run_result, nullptr); | |
1346 TestDestroyedDuringViewsRelease(); | 1307 TestDestroyedDuringViewsRelease(); |
1347 } | 1308 } |
1348 | 1309 |
1349 // Tests that when a context menu is opened above an empty menu item, and a | 1310 // Tests that when a context menu is opened above an empty menu item, and a |
1350 // right-click occurs over the empty item, that the bottom menu is not hidden, | 1311 // right-click occurs over the empty item, that the bottom menu is not hidden, |
1351 // that a request to relaunch the context menu is received, and that | 1312 // that a request to relaunch the context menu is received, and that |
1352 // subsequently pressing ESC does not crash the browser. | 1313 // subsequently pressing ESC does not crash the browser. |
1353 TEST_F(MenuControllerTest, RepostEventToEmptyMenuItem) { | 1314 TEST_F(MenuControllerTest, RepostEventToEmptyMenuItem) { |
1354 // Setup a submenu. Additionally hook up appropriate Widget and View | 1315 // Setup a submenu. Additionally hook up appropriate Widget and View |
1355 // containers, with bounds, so that hit testing works. | 1316 // containers, with bounds, so that hit testing works. |
(...skipping 30 matching lines...) Expand all Loading... |
1386 // Nest a context menu. | 1347 // Nest a context menu. |
1387 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_1 = | 1348 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_1 = |
1388 base::MakeUnique<TestMenuDelegate>(); | 1349 base::MakeUnique<TestMenuDelegate>(); |
1389 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_1 = | 1350 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_1 = |
1390 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_1.get()); | 1351 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_1.get()); |
1391 nested_menu_item_1->SetBounds(0, 0, 100, 100); | 1352 nested_menu_item_1->SetBounds(0, 0, 100, 100); |
1392 nested_menu_item_1->SetController(controller); | 1353 nested_menu_item_1->SetController(controller); |
1393 std::unique_ptr<TestMenuControllerDelegate> nested_controller_delegate_1 = | 1354 std::unique_ptr<TestMenuControllerDelegate> nested_controller_delegate_1 = |
1394 base::MakeUnique<TestMenuControllerDelegate>(); | 1355 base::MakeUnique<TestMenuControllerDelegate>(); |
1395 controller->AddNestedDelegate(nested_controller_delegate_1.get()); | 1356 controller->AddNestedDelegate(nested_controller_delegate_1.get()); |
1396 int mouse_event_flags = 0; | 1357 controller->Run(owner(), nullptr, nested_menu_item_1.get(), |
1397 MenuItemView* run_result = controller->Run( | 1358 gfx::Rect(150, 50, 100, 100), MENU_ANCHOR_TOPLEFT, true, |
1398 owner(), nullptr, nested_menu_item_1.get(), gfx::Rect(150, 50, 100, 100), | 1359 false); |
1399 MENU_ANCHOR_TOPLEFT, true, false, &mouse_event_flags); | |
1400 EXPECT_EQ(run_result, nullptr); | |
1401 | 1360 |
1402 SubmenuView* nested_menu_submenu = nested_menu_item_1->GetSubmenu(); | 1361 SubmenuView* nested_menu_submenu = nested_menu_item_1->GetSubmenu(); |
1403 nested_menu_submenu->SetBounds(0, 0, 100, 100); | 1362 nested_menu_submenu->SetBounds(0, 0, 100, 100); |
1404 nested_menu_submenu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), false); | 1363 nested_menu_submenu->ShowAt(owner(), gfx::Rect(0, 0, 100, 100), false); |
1405 GetMenuHost(nested_menu_submenu) | 1364 GetMenuHost(nested_menu_submenu) |
1406 ->SetContentsView(nested_menu_submenu->GetScrollViewContainer()); | 1365 ->SetContentsView(nested_menu_submenu->GetScrollViewContainer()); |
1407 | 1366 |
1408 // Press down outside of the context menu, and within the empty menu item. | 1367 // Press down outside of the context menu, and within the empty menu item. |
1409 // This should close the first context menu. | 1368 // This should close the first context menu. |
1410 gfx::Point press_location(sub_menu_view->bounds().CenterPoint()); | 1369 gfx::Point press_location(sub_menu_view->bounds().CenterPoint()); |
(...skipping 28 matching lines...) Expand all Loading... |
1439 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_2 = | 1398 std::unique_ptr<TestMenuDelegate> nested_menu_delegate_2 = |
1440 base::MakeUnique<TestMenuDelegate>(); | 1399 base::MakeUnique<TestMenuDelegate>(); |
1441 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_2 = | 1400 std::unique_ptr<TestMenuItemViewShown> nested_menu_item_2 = |
1442 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_2.get()); | 1401 base::MakeUnique<TestMenuItemViewShown>(nested_menu_delegate_2.get()); |
1443 nested_menu_item_2->SetBounds(0, 0, 100, 100); | 1402 nested_menu_item_2->SetBounds(0, 0, 100, 100); |
1444 nested_menu_item_2->SetController(controller); | 1403 nested_menu_item_2->SetController(controller); |
1445 | 1404 |
1446 std::unique_ptr<TestMenuControllerDelegate> nested_controller_delegate_2 = | 1405 std::unique_ptr<TestMenuControllerDelegate> nested_controller_delegate_2 = |
1447 base::MakeUnique<TestMenuControllerDelegate>(); | 1406 base::MakeUnique<TestMenuControllerDelegate>(); |
1448 controller->AddNestedDelegate(nested_controller_delegate_2.get()); | 1407 controller->AddNestedDelegate(nested_controller_delegate_2.get()); |
1449 run_result = controller->Run( | 1408 controller->Run(owner(), nullptr, nested_menu_item_2.get(), |
1450 owner(), nullptr, nested_menu_item_2.get(), gfx::Rect(150, 50, 100, 100), | 1409 gfx::Rect(150, 50, 100, 100), MENU_ANCHOR_TOPLEFT, true, |
1451 MENU_ANCHOR_TOPLEFT, true, false, &mouse_event_flags); | 1410 false); |
1452 EXPECT_EQ(run_result, nullptr); | |
1453 | 1411 |
1454 // The escapce key should only close the nested menu. SelectByChar should not | 1412 // The escapce key should only close the nested menu. SelectByChar should not |
1455 // crash. | 1413 // crash. |
1456 TestAsyncEscapeKey(); | 1414 TestAsyncEscapeKey(); |
1457 EXPECT_EQ(nested_controller_delegate_2->on_menu_closed_called(), 1); | 1415 EXPECT_EQ(nested_controller_delegate_2->on_menu_closed_called(), 1); |
1458 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate()); | 1416 EXPECT_EQ(menu_controller_delegate(), GetCurrentDelegate()); |
1459 } | 1417 } |
1460 | 1418 |
1461 #endif // defined(USE_AURA) | 1419 #endif // defined(USE_AURA) |
1462 | 1420 |
1463 } // namespace test | 1421 } // namespace test |
1464 } // namespace views | 1422 } // namespace views |
OLD | NEW |