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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 MenuController* menu_controller_; | 605 MenuController* menu_controller_; |
606 TestMenuMessageLoop* test_message_loop_; | 606 TestMenuMessageLoop* test_message_loop_; |
607 | 607 |
608 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest); | 608 DISALLOW_COPY_AND_ASSIGN(MenuControllerTest); |
609 }; | 609 }; |
610 | 610 |
611 #if defined(OS_LINUX) && defined(USE_X11) | 611 #if defined(OS_LINUX) && defined(USE_X11) |
612 // Tests that an event targeter which blocks events will be honored by the menu | 612 // Tests that an event targeter which blocks events will be honored by the menu |
613 // event dispatcher. | 613 // event dispatcher. |
614 TEST_F(MenuControllerTest, EventTargeter) { | 614 TEST_F(MenuControllerTest, EventTargeter) { |
615 base::MessageLoopForUI::current()->PostTask( | 615 base::MessageLoopForUI::current()->task_runner()->PostTask( |
616 FROM_HERE, | 616 FROM_HERE, base::Bind(&MenuControllerTest::TestEventTargeter, |
617 base::Bind(&MenuControllerTest::TestEventTargeter, | 617 base::Unretained(this))); |
618 base::Unretained(this))); | |
619 RunMenu(); | 618 RunMenu(); |
620 } | 619 } |
621 #endif // defined(OS_LINUX) && defined(USE_X11) | 620 #endif // defined(OS_LINUX) && defined(USE_X11) |
622 | 621 |
623 #if defined(USE_X11) | 622 #if defined(USE_X11) |
624 // Tests that touch event ids are released correctly. See crbug.com/439051 for | 623 // Tests that touch event ids are released correctly. See crbug.com/439051 for |
625 // details. When the ids aren't managed correctly, we get stuck down touches. | 624 // details. When the ids aren't managed correctly, we get stuck down touches. |
626 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) { | 625 TEST_F(MenuControllerTest, TouchIdsReleasedCorrectly) { |
627 TestEventHandler test_event_handler; | 626 TestEventHandler test_event_handler; |
628 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler( | 627 owner()->GetNativeWindow()->GetRootWindow()->AddPreTargetHandler( |
629 &test_event_handler); | 628 &test_event_handler); |
630 | 629 |
631 std::vector<int> devices; | 630 std::vector<int> devices; |
632 devices.push_back(1); | 631 devices.push_back(1); |
633 ui::SetUpTouchDevicesForTest(devices); | 632 ui::SetUpTouchDevicesForTest(devices); |
634 | 633 |
635 event_generator()->PressTouchId(0); | 634 event_generator()->PressTouchId(0); |
636 event_generator()->PressTouchId(1); | 635 event_generator()->PressTouchId(1); |
637 event_generator()->ReleaseTouchId(0); | 636 event_generator()->ReleaseTouchId(0); |
638 | 637 |
639 base::MessageLoopForUI::current()->PostTask( | 638 base::MessageLoopForUI::current()->task_runner()->PostTask( |
640 FROM_HERE, | 639 FROM_HERE, base::Bind(&MenuControllerTest::ReleaseTouchId, |
641 base::Bind(&MenuControllerTest::ReleaseTouchId, | 640 base::Unretained(this), 1)); |
642 base::Unretained(this), | |
643 1)); | |
644 | 641 |
645 base::MessageLoopForUI::current()->PostTask( | 642 base::MessageLoopForUI::current()->task_runner()->PostTask( |
646 FROM_HERE, | 643 FROM_HERE, base::Bind(&MenuControllerTest::PressKey, |
647 base::Bind(&MenuControllerTest::PressKey, | 644 base::Unretained(this), ui::VKEY_ESCAPE)); |
648 base::Unretained(this), | |
649 ui::VKEY_ESCAPE)); | |
650 | 645 |
651 RunMenu(); | 646 RunMenu(); |
652 | 647 |
653 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type()); | 648 EXPECT_EQ(MenuController::EXIT_OUTERMOST, menu_exit_type()); |
654 EXPECT_EQ(0, test_event_handler.outstanding_touches()); | 649 EXPECT_EQ(0, test_event_handler.outstanding_touches()); |
655 | 650 |
656 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( | 651 owner()->GetNativeWindow()->GetRootWindow()->RemovePreTargetHandler( |
657 &test_event_handler); | 652 &test_event_handler); |
658 } | 653 } |
659 #endif // defined(USE_X11) | 654 #endif // defined(USE_X11) |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 false, false, &result_event_flags)); | 1345 false, false, &result_event_flags)); |
1351 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); | 1346 EXPECT_FALSE(menu_controller_delegate()->on_menu_closed_called()); |
1352 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); | 1347 EXPECT_TRUE(nested_delegate->on_menu_closed_called()); |
1353 } | 1348 } |
1354 | 1349 |
1355 #if defined(USE_AURA) | 1350 #if defined(USE_AURA) |
1356 // Tests that when a synchronous menu receives a cancel event, that it closes. | 1351 // Tests that when a synchronous menu receives a cancel event, that it closes. |
1357 TEST_F(MenuControllerTest, SynchronousCancelEvent) { | 1352 TEST_F(MenuControllerTest, SynchronousCancelEvent) { |
1358 ExitMenuRun(); | 1353 ExitMenuRun(); |
1359 // Post actual test to run once the menu has created a nested message loop. | 1354 // Post actual test to run once the menu has created a nested message loop. |
1360 base::MessageLoopForUI::current()->PostTask( | 1355 base::MessageLoopForUI::current()->task_runner()->PostTask( |
1361 FROM_HERE, | 1356 FROM_HERE, |
1362 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this))); | 1357 base::Bind(&MenuControllerTest::TestCancelEvent, base::Unretained(this))); |
1363 int mouse_event_flags = 0; | 1358 int mouse_event_flags = 0; |
1364 MenuItemView* run_result = menu_controller()->Run( | 1359 MenuItemView* run_result = menu_controller()->Run( |
1365 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, | 1360 owner(), nullptr, menu_item(), gfx::Rect(), MENU_ANCHOR_TOPLEFT, false, |
1366 false, &mouse_event_flags); | 1361 false, &mouse_event_flags); |
1367 EXPECT_EQ(run_result, nullptr); | 1362 EXPECT_EQ(run_result, nullptr); |
1368 } | 1363 } |
1369 | 1364 |
1370 // Tests that when an asynchronous menu receives a cancel event, that it closes. | 1365 // Tests that when an asynchronous menu receives a cancel event, that it closes. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), | 1399 aura::client::SetDragDropClient(owner()->GetNativeWindow()->GetRootWindow(), |
1405 &drag_drop_client); | 1400 &drag_drop_client); |
1406 AddButtonMenuItems(); | 1401 AddButtonMenuItems(); |
1407 StartDrag(); | 1402 StartDrag(); |
1408 } | 1403 } |
1409 | 1404 |
1410 #endif // defined(USE_AURA) | 1405 #endif // defined(USE_AURA) |
1411 | 1406 |
1412 } // namespace test | 1407 } // namespace test |
1413 } // namespace views | 1408 } // namespace views |
OLD | NEW |