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/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 EXPECT_TRUE(IsAsyncRun()); | 869 EXPECT_TRUE(IsAsyncRun()); |
870 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 870 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
871 | 871 |
872 MenuItemView* item = menu_item(); | 872 MenuItemView* item = menu_item(); |
873 int mouse_event_flags = 0; | 873 int mouse_event_flags = 0; |
874 MenuItemView* run_result = | 874 MenuItemView* run_result = |
875 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, | 875 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
876 false, false, &mouse_event_flags); | 876 false, false, &mouse_event_flags); |
877 EXPECT_EQ(run_result, nullptr); | 877 EXPECT_EQ(run_result, nullptr); |
878 | 878 |
879 // Show a sub menu to targert with a pointer selection. However have the event | 879 // Show a sub menu to target with a pointer selection. However have the event |
880 // occur outside of the bounds of the entire menu. | 880 // occur outside of the bounds of the entire menu. |
881 SubmenuView* sub_menu = item->GetSubmenu(); | 881 SubmenuView* sub_menu = item->GetSubmenu(); |
882 sub_menu->ShowAt(owner(), item->bounds(), false); | 882 sub_menu->ShowAt(owner(), item->bounds(), false); |
883 gfx::Point location(sub_menu->bounds().bottom_right()); | 883 gfx::Point location(sub_menu->bounds().bottom_right()); |
884 location.Offset(1, 1); | 884 location.Offset(1, 1); |
885 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, | 885 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, |
886 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 886 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
887 | 887 |
888 // When attempting to select outside of all menus this should lead to a | 888 // When attempting to select outside of all menus this should lead to a |
889 // shutdown. This should not crash while attempting to repost the event. | 889 // shutdown. This should not crash while attempting to repost the event. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 EXPECT_TRUE(IsAsyncRun()); | 968 EXPECT_TRUE(IsAsyncRun()); |
969 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); | 969 EXPECT_EQ(nested_delegate.get(), GetCurrentDelegate()); |
970 | 970 |
971 MenuItemView* item = menu_item(); | 971 MenuItemView* item = menu_item(); |
972 int mouse_event_flags = 0; | 972 int mouse_event_flags = 0; |
973 MenuItemView* run_result = | 973 MenuItemView* run_result = |
974 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, | 974 controller->Run(owner(), nullptr, item, gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
975 false, false, &mouse_event_flags); | 975 false, false, &mouse_event_flags); |
976 EXPECT_EQ(run_result, nullptr); | 976 EXPECT_EQ(run_result, nullptr); |
977 | 977 |
978 // Show a sub menu to targert with a pointer selection. However have the event | 978 // Show a sub menu to target with a pointer selection. However have the event |
979 // occur outside of the bounds of the entire menu. | 979 // occur outside of the bounds of the entire menu. |
980 SubmenuView* sub_menu = item->GetSubmenu(); | 980 SubmenuView* sub_menu = item->GetSubmenu(); |
981 sub_menu->ShowAt(owner(), item->bounds(), true); | 981 sub_menu->ShowAt(owner(), item->bounds(), true); |
982 gfx::Point location(sub_menu->bounds().bottom_right()); | 982 gfx::Point location(sub_menu->bounds().bottom_right()); |
983 location.Offset(1, 1); | 983 location.Offset(1, 1); |
984 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, | 984 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, location, location, |
985 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 985 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
986 | 986 |
987 // This will lead to MenuController being deleted during the event repost. | 987 // This will lead to MenuController being deleted during the event repost. |
988 // The remainder of this test, and TearDown should not crash. | 988 // The remainder of this test, and TearDown should not crash. |
989 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); | 989 DestroyMenuControllerOnMenuClosed(nested_delegate.get()); |
990 // When attempting to select outside of all menus this should lead to a | 990 // When attempting to select outside of all menus this should lead to a |
991 // shutdown. This should not crash while attempting to repost the event. | 991 // shutdown. This should not crash while attempting to repost the event. |
992 SetSelectionOnPointerDown(sub_menu, &event); | 992 SetSelectionOnPointerDown(sub_menu, &event); |
993 | 993 |
994 // Close to remove observers before test TearDown | 994 // Close to remove observers before test TearDown |
995 sub_menu->Close(); | 995 sub_menu->Close(); |
996 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); | 996 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); |
997 } | 997 } |
998 | 998 |
999 } // namespace test | 999 } // namespace test |
1000 } // namespace views | 1000 } // namespace views |
OLD | NEW |