Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: ui/views/controls/menu/menu_controller_unittest.cc

Issue 2375663002: Replace MessageLoop::current()->task_runner() with ThreadTaskRunnerHandle::Get(). (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 9 #include "base/macros.h"
9 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h"
11 #include "build/build_config.h" 13 #include "build/build_config.h"
12 #include "ui/aura/scoped_window_targeter.h" 14 #include "ui/aura/scoped_window_targeter.h"
13 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
14 #include "ui/events/event.h" 16 #include "ui/events/event.h"
15 #include "ui/events/event_constants.h" 17 #include "ui/events/event_constants.h"
16 #include "ui/events/event_handler.h" 18 #include "ui/events/event_handler.h"
17 #include "ui/events/event_utils.h" 19 #include "ui/events/event_utils.h"
18 #include "ui/events/null_event_targeter.h" 20 #include "ui/events/null_event_targeter.h"
19 #include "ui/events/test/event_generator.h" 21 #include "ui/events/test/event_generator.h"
20 #include "ui/gfx/geometry/point.h" 22 #include "ui/gfx/geometry/point.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 public: 266 public:
265 MenuControllerTest() : menu_controller_(nullptr) { 267 MenuControllerTest() : menu_controller_(nullptr) {
266 } 268 }
267 269
268 ~MenuControllerTest() override {} 270 ~MenuControllerTest() override {}
269 271
270 // ViewsTestBase: 272 // ViewsTestBase:
271 void SetUp() override { 273 void SetUp() override {
272 ViewsTestBase::SetUp(); 274 ViewsTestBase::SetUp();
273 Init(); 275 Init();
276 ASSERT_TRUE(base::MessageLoopForUI::IsCurrent());
274 } 277 }
275 278
276 void TearDown() override { 279 void TearDown() override {
277 owner_->CloseNow(); 280 owner_->CloseNow();
278 DestroyMenuController(); 281 DestroyMenuController();
279 ViewsTestBase::TearDown(); 282 ViewsTestBase::TearDown();
280 } 283 }
281 284
282 void ReleaseTouchId(int id) { 285 void ReleaseTouchId(int id) {
283 event_generator_->ReleaseTouchId(id); 286 event_generator_->ReleaseTouchId(id);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 MenuController* menu_controller_; 608 MenuController* menu_controller_;
606 TestMenuMessageLoop* test_message_loop_; 609 TestMenuMessageLoop* test_message_loop_;
607 610
608 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest); 611 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest);
609 }; 612 };
610 613
611 #if defined(OS_LINUX) && defined(USE_X11) 614 #if defined(OS_LINUX) && defined(USE_X11)
612 // Tests that an event targeter which blocks events will be honored by the menu 615 // Tests that an event targeter which blocks events will be honored by the menu
613 // event dispatcher. 616 // event dispatcher.
614 TEST_F(MenuControllerTest, EventTargeter) { 617 TEST_F(MenuControllerTest, EventTargeter) {
615 base::MessageLoopForUI::current()->task_runner()->PostTask( 618 base::ThreadTaskRunnerHandle::Get()->PostTask(
616 FROM_HERE, base::Bind(&MenuControllerTest::TestEventTargeter, 619 FROM_HERE, base::Bind(&MenuControllerTest::TestEventTargeter,
617 base::Unretained(this))); 620 base::Unretained(this)));
618 RunMenu(); 621 RunMenu();
619 } 622 }
620 #endif // defined(OS_LINUX) && defined(USE_X11) 623 #endif // defined(OS_LINUX) && defined(USE_X11)
621 624
622 #if defined(USE_X11) 625 #if defined(USE_X11)
623 // Tests that touch event ids are released correctly. See crbug.com/439051 for 626 // Tests that touch event ids are released correctly. See crbug.com/439051 for
624 // details. When the ids aren't managed correctly, we get stuck down touches. 627 // details. When the ids aren't managed correctly, we get stuck down touches.
625 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) { 628 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) {
626 TestEventHandler test_event_handler; 629 TestEventHandler test_event_handler;
627 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler( 630 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler(
628 &test_event_handler); 631 &test_event_handler);
629 632
630 std::vector<int> devices; 633 std::vector<int> devices;
631 devices.push_back(1); 634 devices.push_back(1);
632 ui::SetUpTouchDevicesForTest(devices); 635 ui::SetUpTouchDevicesForTest(devices);
633 636
634 event_generator()->PressTouchId(0); 637 event_generator()->PressTouchId(0);
635 event_generator()->PressTouchId(1); 638 event_generator()->PressTouchId(1);
636 event_generator()->ReleaseTouchId(0); 639 event_generator()->ReleaseTouchId(0);
637 640
638 base::MessageLoopForUI::current()->task_runner()->PostTask( 641 base::ThreadTaskRunnerHandle::Get()->PostTask(
639 FROM_HERE, base::Bind(&MenuControllerTest::ReleaseTouchId, 642 FROM_HERE, base::Bind(&MenuControllerTest::ReleaseTouchId,
640 base::Unretained(this), 1)); 643 base::Unretained(this), 1));
641 644
642 base::MessageLoopForUI::current()->task_runner()->PostTask( 645 base::ThreadTaskRunnerHandle::Get()->PostTask(
643 FROM_HERE, base::Bind(&MenuControllerTest::PressKey, 646 FROM_HERE, base::Bind(&MenuControllerTest::PressKey,
644 base::Unretained(this), ui::VKEY_ESCAPE)); 647 base::Unretained(this), ui::VKEY_ESCAPE));
645 648
646 RunMenu(); 649 RunMenu();
647 650
648 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type()); 651 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type());
649 EXPECT_EQ(0, test_event_handler.outstanding_touches()); 652 EXPECT_EQ(0, test_event_handler.outstanding_touches());
650 653
651 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( 654 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler(
652 &test_event_handler); 655 &test_event_handler);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE, 1217 EXPECT_EQ(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
1215 delegate->on_menu_closed_notify_type()); 1218 delegate->on_menu_closed_notify_type());
1216 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type()); 1219 EXPECT_EQ(MenuController::EXIT_ALL, controller->exit_type());
1217 } 1220 }
1218 1221
1219 // Tests that if you exit all menus when an asynchrnous menu is nested within a 1222 // Tests that if you exit all menus when an asynchrnous menu is nested within a
1220 // synchronous menu, the message loop for the parent menu finishes running. 1223 // synchronous menu, the message loop for the parent menu finishes running.
1221 TEST_F(MenuControllerTest, AsynchronousNestedExitAll) { 1224 TEST_F(MenuControllerTest, AsynchronousNestedExitAll) {
1222 InstallTestMenuMessageLoop(); 1225 InstallTestMenuMessageLoop();
1223 1226
1224 base::MessageLoopForUI::current()->task_runner()->PostTask( 1227 base::ThreadTaskRunnerHandle::Get()->PostTask(
1225 FROM_HERE, base::Bind(&MenuControllerTest::TestAsynchronousNestedExitAll, 1228 FROM_HERE, base::Bind(&MenuControllerTest::TestAsynchronousNestedExitAll,
1226 base::Unretained(this))); 1229 base::Unretained(this)));
1227 1230
1228 RunMenu(); 1231 RunMenu();
1229 } 1232 }
1230 1233
1231 // Tests that if you exit the nested menu when an asynchrnous menu is nested 1234 // Tests that if you exit the nested menu when an asynchrnous menu is nested
1232 // within a synchronous menu, the message loop for the parent menu remains 1235 // within a synchronous menu, the message loop for the parent menu remains
1233 // running. 1236 // running.
1234 TEST_F(MenuControllerTest, AsynchronousNestedExitOutermost) { 1237 TEST_F(MenuControllerTest, AsynchronousNestedExitOutermost) {
1235 InstallTestMenuMessageLoop(); 1238 InstallTestMenuMessageLoop();
1236 1239
1237 base::MessageLoopForUI::current()->task_runner()->PostTask( 1240 base::ThreadTaskRunnerHandle::Get()->PostTask(
1238 FROM_HERE, 1241 FROM_HERE,
1239 base::Bind(&MenuControllerTest::TestAsynchronousNestedExitOutermost, 1242 base::Bind(&MenuControllerTest::TestAsynchronousNestedExitOutermost,
1240 base::Unretained(this))); 1243 base::Unretained(this)));
1241 1244
1242 RunMenu(); 1245 RunMenu();
1243 } 1246 }
1244 1247
1245 // Tests that having the MenuController deleted during RepostEvent does not 1248 // Tests that having the MenuController deleted during RepostEvent does not
1246 // cause a crash. ASAN bots should not detect use-after-free in MenuController. 1249 // cause a crash. ASAN bots should not detect use-after-free in MenuController.
1247 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) { 1250 TEST_F(MenuControllerTest, AsynchronousRepostEventDeletesController) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 1329
1327 // Tests that when an asynchronous menu is nested, and the nested message loop 1330 // Tests that when an asynchronous menu is nested, and the nested message loop
1328 // is kill not by the MenuController, that the nested menu is notified of 1331 // is kill not by the MenuController, that the nested menu is notified of
1329 // destruction. 1332 // destruction.
1330 TEST_F(MenuControllerTest, NestedMessageLoopDiesWithNestedMenu) { 1333 TEST_F(MenuControllerTest, NestedMessageLoopDiesWithNestedMenu) {
1331 menu_controller()->CancelAll(); 1334 menu_controller()->CancelAll();
1332 InstallTestMenuMessageLoop(); 1335 InstallTestMenuMessageLoop();
1333 std::unique_ptr<TestMenuControllerDelegate> nested_delegate( 1336 std::unique_ptr<TestMenuControllerDelegate> nested_delegate(
1334 new TestMenuControllerDelegate()); 1337 new TestMenuControllerDelegate());
1335 // This will nest an asynchronous menu, and then kill the nested message loop. 1338 // This will nest an asynchronous menu, and then kill the nested message loop.
1336 base::MessageLoopForUI::current()->task_runner()->PostTask( 1339 base::ThreadTaskRunnerHandle::Get()->PostTask(
1337 FROM_HERE, 1340 FROM_HERE,
1338 base::Bind(&MenuControllerTest::TestNestedMessageLoopKillsItself, 1341 base::Bind(&MenuControllerTest::TestNestedMessageLoopKillsItself,
1339 base::Unretained(this), nested_delegate.get())); 1342 base::Unretained(this), nested_delegate.get()));
1340 1343
1341 int result_event_flags = 0; 1344 int result_event_flags = 0;
1342 // This creates a nested message loop. 1345 // This creates a nested message loop.
1343 EXPECT_EQ(nullptr, menu_controller()->Run(owner(), nullptr, menu_item(), 1346 EXPECT_EQ(nullptr, menu_controller()->Run(owner(), nullptr, menu_item(),
1344 gfx::Rect(), MENU_ANCHOR_TOPLEFT, 1347 gfx::Rect(), MENU_ANCHOR_TOPLEFT,
1345 false, false, &result_event_flags)); 1348 false, false, &result_event_flags));
1346 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); 1349 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called());
1347 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); 1350 EXPECT_TRUE(nested_delegate->on_menu_closed_called());
1348 } 1351 }
1349 1352
1350 #if defined(USE_AURA) 1353 #if defined(USE_AURA)
1351 // Tests that when a synchronous menu receives a cancel event, that it closes. 1354 // Tests that when a synchronous menu receives a cancel event, that it closes.
1352 TEST_F(MenuControllerTest, SynchronousCancelEvent) { 1355 TEST_F(MenuControllerTest, SynchronousCancelEvent) {
1353 ExitMenuRun(); 1356 ExitMenuRun();
1354 // Post actual test to run once the menu has created a nested message loop. 1357 // Post actual test to run once the menu has created a nested message loop.
1355 base::MessageLoopForUI::current()->task_runner()->PostTask( 1358 base::ThreadTaskRunnerHandle::Get()->PostTask(
1356 FROM_HERE, 1359 FROM_HERE,
1357 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this))); 1360 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this)));
1358 int mouse_event_flags = 0; 1361 int mouse_event_flags = 0;
1359 MenuItemView* run_result = menu_controller()->Run( 1362 MenuItemView* run_result = menu_controller()->Run(
1360 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, 1363 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false,
1361 false, &mouse_event_flags); 1364 false, &mouse_event_flags);
1362 EXPECT_EQ(run_result, nullptr); 1365 EXPECT_EQ(run_result, nullptr);
1363 } 1366 }
1364 1367
1365 // Tests that when an asynchronous menu receives a cancel event, that it closes. 1368 // Tests that when an asynchronous menu receives a cancel event, that it closes.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), 1408 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(),
1406 &drag_drop_client); 1409 &drag_drop_client);
1407 AddButtonMenuItems(); 1410 AddButtonMenuItems();
1408 StartDrag(); 1411 StartDrag();
1409 } 1412 }
1410 1413
1411 #endif // defined(USE_AURA) 1414 #endif // defined(USE_AURA)
1412 1415
1413 } // namespace test 1416 } // namespace test
1414 } // namespace views 1417 } // namespace views
OLDNEW
« no previous file with comments | « ui/shell_dialogs/select_file_dialog_win.cc ('k') | ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698