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/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 MenuController* menu_controller_; | 529 MenuController* menu_controller_; |
530 TestMenuMessageLoop* test_message_loop_; | 530 TestMenuMessageLoop* test_message_loop_; |
531 | 531 |
532 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest); | 532 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest); |
533 }; | 533 }; |
534 | 534 |
535 #if defined(OS_LINUX) && defined(USE_X11) | 535 #if defined(OS_LINUX) && defined(USE_X11) |
536 // Tests that an event targeter which blocks events will be honored by the menu | 536 // Tests that an event targeter which blocks events will be honored by the menu |
537 // event dispatcher. | 537 // event dispatcher. |
538 TEST_F(MenuControllerTest, EventTargeter) { | 538 TEST_F(MenuControllerTest, EventTargeter) { |
539 base::MessageLoopForUI::current()->PostTask( | 539 base::MessageLoopForUI::current()->task_runner()->PostTask( |
540 FROM_HERE, | 540 FROM_HERE, base::Bind(&MenuControllerTest::TestEventTargeter, |
541 base::Bind(&MenuControllerTest::TestEventTargeter, | 541 base::Unretained(this))); |
542 base::Unretained(this))); | |
543 RunMenu(); | 542 RunMenu(); |
544 } | 543 } |
545 #endif // defined(OS_LINUX) && defined(USE_X11) | 544 #endif // defined(OS_LINUX) && defined(USE_X11) |
546 | 545 |
547 #if defined(USE_X11) | 546 #if defined(USE_X11) |
548 // Tests that touch event ids are released correctly. See crbug.com/439051 for | 547 // Tests that touch event ids are released correctly. See crbug.com/439051 for |
549 // details. When the ids aren't managed correctly, we get stuck down touches. | 548 // details. When the ids aren't managed correctly, we get stuck down touches. |
550 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) { | 549 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) { |
551 TestEventHandler test_event_handler; | 550 TestEventHandler test_event_handler; |
552 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler( | 551 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler( |
553 &test_event_handler); | 552 &test_event_handler); |
554 | 553 |
555 std::vector<int> devices; | 554 std::vector<int> devices; |
556 devices.push_back(1); | 555 devices.push_back(1); |
557 ui::SetUpTouchDevicesForTest(devices); | 556 ui::SetUpTouchDevicesForTest(devices); |
558 | 557 |
559 event_generator()->PressTouchId(0); | 558 event_generator()->PressTouchId(0); |
560 event_generator()->PressTouchId(1); | 559 event_generator()->PressTouchId(1); |
561 event_generator()->ReleaseTouchId(0); | 560 event_generator()->ReleaseTouchId(0); |
562 | 561 |
563 base::MessageLoopForUI::current()->PostTask( | 562 base::MessageLoopForUI::current()->task_runner()->PostTask( |
564 FROM_HERE, | 563 FROM_HERE, base::Bind(&MenuControllerTest::ReleaseTouchId, |
565 base::Bind(&MenuControllerTest::ReleaseTouchId, | 564 base::Unretained(this), 1)); |
566 base::Unretained(this), | |
567 1)); | |
568 | 565 |
569 base::MessageLoopForUI::current()->PostTask( | 566 base::MessageLoopForUI::current()->task_runner()->PostTask( |
570 FROM_HERE, | 567 FROM_HERE, base::Bind(&MenuControllerTest::PressKey, |
571 base::Bind(&MenuControllerTest::PressKey, | 568 base::Unretained(this), ui::VKEY_ESCAPE)); |
572 base::Unretained(this), | |
573 ui::VKEY_ESCAPE)); | |
574 | 569 |
575 RunMenu(); | 570 RunMenu(); |
576 | 571 |
577 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type()); | 572 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type()); |
578 EXPECT_EQ(0, test_event_handler.outstanding_touches()); | 573 EXPECT_EQ(0, test_event_handler.outstanding_touches()); |
579 | 574 |
580 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( | 575 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( |
581 &test_event_handler); | 576 &test_event_handler); |
582 } | 577 } |
583 #endif // defined(USE_X11) | 578 #endif // defined(USE_X11) |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 false, false, &result_event_flags)); | 1269 false, false, &result_event_flags)); |
1275 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); | 1270 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); |
1276 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); | 1271 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); |
1277 } | 1272 } |
1278 | 1273 |
1279 #if defined(USE_AURA) | 1274 #if defined(USE_AURA) |
1280 // Tests that when a synchronous menu receives a cancel event, that it closes. | 1275 // Tests that when a synchronous menu receives a cancel event, that it closes. |
1281 TEST_F(MenuControllerTest, SynchronousCancelEvent) { | 1276 TEST_F(MenuControllerTest, SynchronousCancelEvent) { |
1282 ExitMenuRun(); | 1277 ExitMenuRun(); |
1283 // Post actual test to run once the menu has created a nested message loop. | 1278 // Post actual test to run once the menu has created a nested message loop. |
1284 base::MessageLoopForUI::current()->PostTask( | 1279 base::MessageLoopForUI::current()->task_runner()->PostTask( |
1285 FROM_HERE, | 1280 FROM_HERE, |
1286 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this))); | 1281 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this))); |
1287 int mouse_event_flags = 0; | 1282 int mouse_event_flags = 0; |
1288 MenuItemView* run_result = menu_controller()->Run( | 1283 MenuItemView* run_result = menu_controller()->Run( |
1289 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, | 1284 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, |
1290 false, &mouse_event_flags); | 1285 false, &mouse_event_flags); |
1291 EXPECT_EQ(run_result, nullptr); | 1286 EXPECT_EQ(run_result, nullptr); |
1292 } | 1287 } |
1293 | 1288 |
1294 // Tests that when an asynchronous menu receives a cancel event, that it closes. | 1289 // Tests that when an asynchronous menu receives a cancel event, that it closes. |
(...skipping 20 matching lines...) Expand all Loading... |
1315 MenuItemView* run_result = | 1310 MenuItemView* run_result = |
1316 controller->Run(nullptr, nullptr, menu_item(), gfx::Rect(), | 1311 controller->Run(nullptr, nullptr, menu_item(), gfx::Rect(), |
1317 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); | 1312 MENU_ANCHOR_TOPLEFT, false, false, &mouse_event_flags); |
1318 EXPECT_EQ(run_result, nullptr); | 1313 EXPECT_EQ(run_result, nullptr); |
1319 } | 1314 } |
1320 | 1315 |
1321 #endif // defined(USE_AURA) | 1316 #endif // defined(USE_AURA) |
1322 | 1317 |
1323 } // namespace test | 1318 } // namespace test |
1324 } // namespace views | 1319 } // namespace views |
OLD | NEW |