| 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/single_thread_task_runner.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "ui/aura/scoped_window_targeter.h" | 12 #include "ui/aura/scoped_window_targeter.h" |
| 12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 14 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_handler.h" | 16 #include "ui/events/event_handler.h" |
| 16 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 17 #include "ui/events/null_event_targeter.h" | 18 #include "ui/events/null_event_targeter.h" |
| 18 #include "ui/events/test/event_generator.h" | 19 #include "ui/events/test/event_generator.h" |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, | 1118 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, |
| 1118 delegate->on_menu_closed_notify_type()); | 1119 delegate->on_menu_closed_notify_type()); |
| 1119 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); | 1120 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); |
| 1120 } | 1121 } |
| 1121 | 1122 |
| 1122 // Tests that if you exit all menus when an asynchrnous menu is nested within a | 1123 // Tests that if you exit all menus when an asynchrnous menu is nested within a |
| 1123 // synchronous menu, the message loop for the parent menu finishes running. | 1124 // synchronous menu, the message loop for the parent menu finishes running. |
| 1124 TEST_F(MenuControllerTest, AsynchronousNestedExitAll) { | 1125 TEST_F(MenuControllerTest, AsynchronousNestedExitAll) { |
| 1125 InstallTestMenuMessageLoop(); | 1126 InstallTestMenuMessageLoop(); |
| 1126 | 1127 |
| 1127 base::MessageLoopForUI::current()->PostTask( | 1128 base::MessageLoopForUI::current()->task_runner()->PostTask( |
| 1128 FROM_HERE, base::Bind(&MenuControllerTest::TestAsynchronousNestedExitAll, | 1129 FROM_HERE, base::Bind(&MenuControllerTest::TestAsynchronousNestedExitAll, |
| 1129 base::Unretained(this))); | 1130 base::Unretained(this))); |
| 1130 | 1131 |
| 1131 RunMenu(); | 1132 RunMenu(); |
| 1132 } | 1133 } |
| 1133 | 1134 |
| 1134 // Tests that if you exit the nested menu when an asynchrnous menu is nested | 1135 // Tests that if you exit the nested menu when an asynchrnous menu is nested |
| 1135 // within a synchronous menu, the message loop for the parent menu remains | 1136 // within a synchronous menu, the message loop for the parent menu remains |
| 1136 // running. | 1137 // running. |
| 1137 TEST_F(MenuControllerTest, AsynchronousNestedExitOutermost) { | 1138 TEST_F(MenuControllerTest, AsynchronousNestedExitOutermost) { |
| 1138 InstallTestMenuMessageLoop(); | 1139 InstallTestMenuMessageLoop(); |
| 1139 | 1140 |
| 1140 base::MessageLoopForUI::current()->PostTask( | 1141 base::MessageLoopForUI::current()->task_runner()->PostTask( |
| 1141 FROM_HERE, | 1142 FROM_HERE, |
| 1142 base::Bind(&MenuControllerTest::TestAsynchronousNestedExitOutermost, | 1143 base::Bind(&MenuControllerTest::TestAsynchronousNestedExitOutermost, |
| 1143 base::Unretained(this))); | 1144 base::Unretained(this))); |
| 1144 | 1145 |
| 1145 RunMenu(); | 1146 RunMenu(); |
| 1146 } | 1147 } |
| 1147 | 1148 |
| 1148 // Tests that having the MenuController deleted during RepostEvent does not | 1149 // Tests that having the MenuController deleted during RepostEvent does not |
| 1149 // cause a crash. ASAN bots should not detect use-after-free in MenuController. | 1150 // cause a crash. ASAN bots should not detect use-after-free in MenuController. |
| 1150 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) { | 1151 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 | 1230 |
| 1230 // Tests that when an asynchronous menu is nested, and the nested message loop | 1231 // Tests that when an asynchronous menu is nested, and the nested message loop |
| 1231 // is kill not by the MenuController, that the nested menu is notified of | 1232 // is kill not by the MenuController, that the nested menu is notified of |
| 1232 // destruction. | 1233 // destruction. |
| 1233 TEST_F(MenuControllerTest, NestedMessageLoopDiesWithNestedMenu) { | 1234 TEST_F(MenuControllerTest, NestedMessageLoopDiesWithNestedMenu) { |
| 1234 menu_controller()->CancelAll(); | 1235 menu_controller()->CancelAll(); |
| 1235 InstallTestMenuMessageLoop(); | 1236 InstallTestMenuMessageLoop(); |
| 1236 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( | 1237 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( |
| 1237 new TestMenuControllerDelegate()); | 1238 new TestMenuControllerDelegate()); |
| 1238 // This will nest an asynchronous menu, and then kill the nested message loop. | 1239 // This will nest an asynchronous menu, and then kill the nested message loop. |
| 1239 base::MessageLoopForUI::current()->PostTask( | 1240 base::MessageLoopForUI::current()->task_runner()->PostTask( |
| 1240 FROM_HERE, | 1241 FROM_HERE, |
| 1241 base::Bind(&MenuControllerTest::TestNestedMessageLoopKillsItself, | 1242 base::Bind(&MenuControllerTest::TestNestedMessageLoopKillsItself, |
| 1242 base::Unretained(this), nested_delegate.get())); | 1243 base::Unretained(this), nested_delegate.get())); |
| 1243 | 1244 |
| 1244 int result_event_flags = 0; | 1245 int result_event_flags = 0; |
| 1245 // This creates a nested message loop. | 1246 // This creates a nested message loop. |
| 1246 EXPECT_EQ(nullptr, menu_controller()->Run(owner(), nullptr, menu_item(), | 1247 EXPECT_EQ(nullptr, menu_controller()->Run(owner(), nullptr, menu_item(), |
| 1247 gfx::Rect(), MENU_ANCHOR_TOPLEFT, | 1248 gfx::Rect(), MENU_ANCHOR_TOPLEFT, |
| 1248 false, false, &result_event_flags)); | 1249 false, false, &result_event_flags)); |
| 1249 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); | 1250 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); |
| 1250 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); | 1251 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); |
| 1251 } | 1252 } |
| 1252 | 1253 |
| 1253 } // namespace test | 1254 } // namespace test |
| 1254 } // namespace views | 1255 } // namespace views |
| OLD | NEW |