OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 } | 730 } |
731 | 731 |
732 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { | 732 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { |
733 EventFilterRecorder recorder; | 733 EventFilterRecorder recorder; |
734 root_window()->AddPreTargetHandler(&recorder); | 734 root_window()->AddPreTargetHandler(&recorder); |
735 | 735 |
736 test::TestWindowDelegate delegate; | 736 test::TestWindowDelegate delegate; |
737 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 737 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
738 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 738 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
739 | 739 |
740 const gfx::Point touch_location(60, 60); | |
741 // Starting the touch and throwing out the first few events, since the system | 740 // Starting the touch and throwing out the first few events, since the system |
742 // is going to generate synthetic mouse events that are not relevant to the | 741 // is going to generate synthetic mouse events that are not relevant to the |
743 // test. | 742 // test. |
744 ui::TouchEvent touch_pressed_event( | 743 ui::TouchEvent touch_pressed_event( |
745 ui::ET_TOUCH_PRESSED, touch_location, 0, ui::EventTimeForNow()); | 744 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); |
746 DispatchEventUsingWindowDispatcher(&touch_pressed_event); | 745 DispatchEventUsingWindowDispatcher(&touch_pressed_event); |
747 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); | 746 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); |
748 recorder.Reset(); | 747 recorder.Reset(); |
749 | 748 |
750 host()->dispatcher()->HoldPointerMoves(); | 749 host()->dispatcher()->HoldPointerMoves(); |
751 | 750 |
752 // Check that we don't immediately dispatch the TOUCH_MOVED event. | 751 // Check that we don't immediately dispatch the TOUCH_MOVED event. |
753 ui::TouchEvent touch_moved_event( | 752 ui::TouchEvent touch_moved_event( |
754 ui::ET_TOUCH_MOVED, touch_location, 0, ui::EventTimeForNow()); | 753 ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); |
755 ui::TouchEvent touch_moved_event2 = touch_moved_event; | 754 ui::TouchEvent touch_moved_event2( |
756 ui::TouchEvent touch_moved_event3 = touch_moved_event; | 755 ui::ET_TOUCH_MOVED, gfx::Point(11, 10), 0, ui::EventTimeForNow()); |
| 756 ui::TouchEvent touch_moved_event3( |
| 757 ui::ET_TOUCH_MOVED, gfx::Point(12, 10), 0, ui::EventTimeForNow()); |
757 | 758 |
758 DispatchEventUsingWindowDispatcher(&touch_moved_event); | 759 DispatchEventUsingWindowDispatcher(&touch_moved_event); |
759 EXPECT_TRUE(recorder.events().empty()); | 760 EXPECT_TRUE(recorder.events().empty()); |
760 | 761 |
761 // Check that on ReleasePointerMoves, held events are not dispatched | 762 // Check that on ReleasePointerMoves, held events are not dispatched |
762 // immediately, but posted instead. | 763 // immediately, but posted instead. |
763 DispatchEventUsingWindowDispatcher(&touch_moved_event2); | 764 DispatchEventUsingWindowDispatcher(&touch_moved_event2); |
764 host()->dispatcher()->ReleasePointerMoves(); | 765 host()->dispatcher()->ReleasePointerMoves(); |
765 EXPECT_TRUE(recorder.events().empty()); | 766 EXPECT_TRUE(recorder.events().empty()); |
766 | 767 |
767 RunAllPendingInMessageLoop(); | 768 RunAllPendingInMessageLoop(); |
768 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); | 769 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(recorder.events())); |
769 recorder.Reset(); | 770 recorder.Reset(); |
770 | 771 |
771 // If another touch event occurs then the held touch should be dispatched | 772 // If another touch event occurs then the held touch should be dispatched |
772 // immediately before it. | 773 // immediately before it. |
773 ui::TouchEvent touch_released_event( | 774 ui::TouchEvent touch_released_event( |
774 ui::ET_TOUCH_RELEASED, touch_location, 0, ui::EventTimeForNow()); | 775 ui::ET_TOUCH_RELEASED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); |
775 recorder.Reset(); | 776 recorder.Reset(); |
776 host()->dispatcher()->HoldPointerMoves(); | 777 host()->dispatcher()->HoldPointerMoves(); |
777 DispatchEventUsingWindowDispatcher(&touch_moved_event3); | 778 DispatchEventUsingWindowDispatcher(&touch_moved_event3); |
778 DispatchEventUsingWindowDispatcher(&touch_released_event); | 779 DispatchEventUsingWindowDispatcher(&touch_released_event); |
779 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END", | 780 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END", |
780 EventTypesToString(recorder.events())); | 781 EventTypesToString(recorder.events())); |
781 recorder.Reset(); | 782 recorder.Reset(); |
782 host()->dispatcher()->ReleasePointerMoves(); | 783 host()->dispatcher()->ReleasePointerMoves(); |
783 RunAllPendingInMessageLoop(); | 784 RunAllPendingInMessageLoop(); |
784 EXPECT_TRUE(recorder.events().empty()); | 785 EXPECT_TRUE(recorder.events().empty()); |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 | 1714 |
1714 std::string events_string = EventTypesToString(recorder.GetAndResetEvents()); | 1715 std::string events_string = EventTypesToString(recorder.GetAndResetEvents()); |
1715 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string)); | 1716 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string)); |
1716 | 1717 |
1717 window->Hide(); | 1718 window->Hide(); |
1718 | 1719 |
1719 expected = | 1720 expected = |
1720 "TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " | 1721 "TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " |
1721 "GESTURE_SCROLL_END GESTURE_END"; | 1722 "GESTURE_SCROLL_END GESTURE_END"; |
1722 expected_ugr = | 1723 expected_ugr = |
1723 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END GESTURE_END " | 1724 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END TOUCH_CANCELLED " |
1724 "TOUCH_CANCELLED"; | 1725 "GESTURE_END"; |
1725 | 1726 |
1726 events_string = EventTypesToString(recorder.GetAndResetEvents()); | 1727 events_string = EventTypesToString(recorder.GetAndResetEvents()); |
1727 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string)); | 1728 EXPECT_TRUE((expected == events_string) || (expected_ugr == events_string)); |
1728 | 1729 |
1729 root_window()->RemovePreTargetHandler(&recorder); | 1730 root_window()->RemovePreTargetHandler(&recorder); |
1730 } | 1731 } |
1731 | 1732 |
1732 // Places two windows side by side. Presses down on one window, and starts a | 1733 // Places two windows side by side. Presses down on one window, and starts a |
1733 // scroll. Sets capture on the other window and ensures that the "ending" events | 1734 // scroll. Sets capture on the other window and ensures that the "ending" events |
1734 // aren't sent to the window which gained capture. | 1735 // aren't sent to the window which gained capture. |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2263 ui::EF_LEFT_MOUSE_BUTTON); | 2264 ui::EF_LEFT_MOUSE_BUTTON); |
2264 DispatchEventUsingWindowDispatcher(&mouse); | 2265 DispatchEventUsingWindowDispatcher(&mouse); |
2265 EXPECT_TRUE(recorder_first.events().empty()); | 2266 EXPECT_TRUE(recorder_first.events().empty()); |
2266 ASSERT_EQ(1u, recorder_second.events().size()); | 2267 ASSERT_EQ(1u, recorder_second.events().size()); |
2267 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); | 2268 EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); |
2268 EXPECT_EQ(event_location.ToString(), | 2269 EXPECT_EQ(event_location.ToString(), |
2269 recorder_second.mouse_locations()[0].ToString()); | 2270 recorder_second.mouse_locations()[0].ToString()); |
2270 } | 2271 } |
2271 | 2272 |
2272 } // namespace aura | 2273 } // namespace aura |
OLD | NEW |