| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 float velocity_y, | 240 float velocity_y, |
| 241 WebGestureDevice source_device) { | 241 WebGestureDevice source_device) { |
| 242 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling( | 242 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildFling( |
| 243 velocity_x, velocity_y, source_device)); | 243 velocity_x, velocity_y, source_device)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void SetTouchTimestamp(base::TimeDelta timestamp) { | 246 void SetTouchTimestamp(base::TimeDelta timestamp) { |
| 247 touch_event_.SetTimestamp(timestamp); | 247 touch_event_.SetTimestamp(timestamp); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void SendTouchEvent() { | 250 uint32 SendTouchEvent() { |
| 251 uint32 touch_event_id = touch_event_.uniqueTouchEventId; |
| 251 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); | 252 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); |
| 252 touch_event_.ResetPoints(); | 253 touch_event_.ResetPoints(); |
| 254 return touch_event_id; |
| 253 } | 255 } |
| 254 | 256 |
| 255 int PressTouchPoint(int x, int y) { | 257 int PressTouchPoint(int x, int y) { |
| 256 return touch_event_.PressPoint(x, y); | 258 return touch_event_.PressPoint(x, y); |
| 257 } | 259 } |
| 258 | 260 |
| 259 void MoveTouchPoint(int index, int x, int y) { | 261 void MoveTouchPoint(int index, int x, int y) { |
| 260 touch_event_.MovePoint(index, x, y); | 262 touch_event_.MovePoint(index, x, y); |
| 261 } | 263 } |
| 262 | 264 |
| 263 void ReleaseTouchPoint(int index) { | 265 void ReleaseTouchPoint(int index) { |
| 264 touch_event_.ReleasePoint(index); | 266 touch_event_.ReleasePoint(index); |
| 265 } | 267 } |
| 266 | 268 |
| 267 void CancelTouchPoint(int index) { | 269 void CancelTouchPoint(int index) { |
| 268 touch_event_.CancelPoint(index); | 270 touch_event_.CancelPoint(index); |
| 269 } | 271 } |
| 270 | 272 |
| 271 void SendInputEventACK(blink::WebInputEvent::Type type, | 273 void SendInputEventACK(blink::WebInputEvent::Type type, |
| 272 InputEventAckState ack_result) { | 274 InputEventAckState ack_result) { |
| 273 InputHostMsg_HandleInputEvent_ACK_Params ack; | 275 DCHECK(!WebInputEvent::isTouchEventType(type)); |
| 274 ack.type = type; | 276 InputEventAck ack(type, ack_result); |
| 275 ack.state = ack_result; | |
| 276 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); | 277 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
| 277 } | 278 } |
| 278 | 279 |
| 280 void SendTouchEventACK(blink::WebInputEvent::Type type, |
| 281 InputEventAckState ack_result, |
| 282 uint32 touch_event_id) { |
| 283 DCHECK(WebInputEvent::isTouchEventType(type)); |
| 284 InputEventAck ack(type, ack_result, touch_event_id); |
| 285 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
| 286 } |
| 287 |
| 279 InputRouterImpl* input_router() const { | 288 InputRouterImpl* input_router() const { |
| 280 return input_router_.get(); | 289 return input_router_.get(); |
| 281 } | 290 } |
| 282 | 291 |
| 283 bool TouchEventQueueEmpty() const { | 292 bool TouchEventQueueEmpty() const { |
| 284 return input_router()->touch_event_queue_.empty(); | 293 return input_router()->touch_event_queue_.empty(); |
| 285 } | 294 } |
| 286 | 295 |
| 287 bool TouchEventTimeoutEnabled() const { | 296 bool TouchEventTimeoutEnabled() const { |
| 288 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); | 297 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 base::MessageLoop::current()->RunUntilIdle(); | 782 base::MessageLoop::current()->RunUntilIdle(); |
| 774 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 783 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 775 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 784 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 776 } | 785 } |
| 777 | 786 |
| 778 // Tests that touch-events are queued properly. | 787 // Tests that touch-events are queued properly. |
| 779 TEST_F(InputRouterImplTest, TouchEventQueue) { | 788 TEST_F(InputRouterImplTest, TouchEventQueue) { |
| 780 OnHasTouchEventHandlers(true); | 789 OnHasTouchEventHandlers(true); |
| 781 | 790 |
| 782 PressTouchPoint(1, 1); | 791 PressTouchPoint(1, 1); |
| 783 SendTouchEvent(); | 792 uint32 touch_press_event_id = SendTouchEvent(); |
| 784 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); | 793 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); |
| 785 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 794 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 786 EXPECT_FALSE(TouchEventQueueEmpty()); | 795 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 787 | 796 |
| 788 // The second touch should not be sent since one is already in queue. | 797 // The second touch should not be sent since one is already in queue. |
| 789 MoveTouchPoint(0, 5, 5); | 798 MoveTouchPoint(0, 5, 5); |
| 790 SendTouchEvent(); | 799 uint32 touch_move_event_id = SendTouchEvent(); |
| 791 EXPECT_FALSE(client_->GetAndResetFilterEventCalled()); | 800 EXPECT_FALSE(client_->GetAndResetFilterEventCalled()); |
| 792 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 801 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 793 EXPECT_FALSE(TouchEventQueueEmpty()); | 802 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 794 | 803 |
| 795 // Receive an ACK for the first touch-event. | 804 // Receive an ACK for the first touch-event. |
| 796 SendInputEventACK(WebInputEvent::TouchStart, | 805 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 797 INPUT_EVENT_ACK_STATE_CONSUMED); | 806 touch_press_event_id); |
| 798 EXPECT_FALSE(TouchEventQueueEmpty()); | 807 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 799 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 808 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 800 EXPECT_EQ(WebInputEvent::TouchStart, | 809 EXPECT_EQ(WebInputEvent::TouchStart, |
| 801 ack_handler_->acked_touch_event().event.type); | 810 ack_handler_->acked_touch_event().event.type); |
| 802 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 811 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 803 | 812 |
| 804 SendInputEventACK(WebInputEvent::TouchMove, | 813 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 805 INPUT_EVENT_ACK_STATE_CONSUMED); | 814 touch_move_event_id); |
| 806 EXPECT_TRUE(TouchEventQueueEmpty()); | 815 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 807 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 816 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 808 EXPECT_EQ(WebInputEvent::TouchMove, | 817 EXPECT_EQ(WebInputEvent::TouchMove, |
| 809 ack_handler_->acked_touch_event().event.type); | 818 ack_handler_->acked_touch_event().event.type); |
| 810 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 819 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 811 } | 820 } |
| 812 | 821 |
| 813 // Tests that the touch-queue is emptied after a page stops listening for touch | 822 // Tests that the touch-queue is emptied after a page stops listening for touch |
| 814 // events and the outstanding ack is received. | 823 // events and the outstanding ack is received. |
| 815 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { | 824 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { |
| 816 OnHasTouchEventHandlers(true); | 825 OnHasTouchEventHandlers(true); |
| 817 EXPECT_TRUE(client_->has_touch_handler()); | 826 EXPECT_TRUE(client_->has_touch_handler()); |
| 818 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 827 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 819 EXPECT_TRUE(TouchEventQueueEmpty()); | 828 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 820 | 829 |
| 821 // Send a touch-press event. | 830 // Send a touch-press event. |
| 822 PressTouchPoint(1, 1); | 831 PressTouchPoint(1, 1); |
| 823 SendTouchEvent(); | 832 uint32 touch_press_event_id = SendTouchEvent(); |
| 824 MoveTouchPoint(0, 2, 2); | 833 MoveTouchPoint(0, 2, 2); |
| 825 MoveTouchPoint(0, 3, 3); | 834 MoveTouchPoint(0, 3, 3); |
| 826 EXPECT_FALSE(TouchEventQueueEmpty()); | 835 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 827 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 836 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 828 | 837 |
| 829 // The page stops listening for touch-events. Note that flushing is deferred | 838 // The page stops listening for touch-events. Note that flushing is deferred |
| 830 // until the outstanding ack is received. | 839 // until the outstanding ack is received. |
| 831 OnHasTouchEventHandlers(false); | 840 OnHasTouchEventHandlers(false); |
| 832 EXPECT_FALSE(client_->has_touch_handler()); | 841 EXPECT_FALSE(client_->has_touch_handler()); |
| 833 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 842 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 834 EXPECT_FALSE(TouchEventQueueEmpty()); | 843 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 835 | 844 |
| 836 // After the ack, the touch-event queue should be empty, and none of the | 845 // After the ack, the touch-event queue should be empty, and none of the |
| 837 // flushed touch-events should have been sent to the renderer. | 846 // flushed touch-events should have been sent to the renderer. |
| 838 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 847 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 848 touch_press_event_id); |
| 839 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 849 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 840 EXPECT_TRUE(TouchEventQueueEmpty()); | 850 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 841 } | 851 } |
| 842 | 852 |
| 843 #if defined(USE_AURA) | 853 #if defined(USE_AURA) |
| 844 // Tests that the acked events have correct state. (ui::Events are used only on | 854 // Tests that the acked events have correct state. (ui::Events are used only on |
| 845 // windows and aura) | 855 // windows and aura) |
| 846 TEST_F(InputRouterImplTest, AckedTouchEventState) { | 856 TEST_F(InputRouterImplTest, AckedTouchEventState) { |
| 847 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 857 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 848 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 858 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 849 EXPECT_TRUE(TouchEventQueueEmpty()); | 859 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 850 | 860 |
| 851 // Send a bunch of events, and make sure the ACKed events are correct. | 861 // Send a bunch of events, and make sure the ACKed events are correct. |
| 852 ScopedVector<ui::TouchEvent> expected_events; | 862 ScopedVector<ui::TouchEvent> expected_events; |
| 853 | 863 |
| 854 // Use a custom timestamp for all the events to test that the acked events | 864 // Use a custom timestamp for all the events to test that the acked events |
| 855 // have the same timestamp; | 865 // have the same timestamp; |
| 856 base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time(); | 866 base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time(); |
| 857 timestamp -= base::TimeDelta::FromSeconds(600); | 867 timestamp -= base::TimeDelta::FromSeconds(600); |
| 858 | 868 |
| 859 // Press the first finger. | 869 // Press the first finger. |
| 860 PressTouchPoint(1, 1); | 870 PressTouchPoint(1, 1); |
| 861 SetTouchTimestamp(timestamp); | 871 SetTouchTimestamp(timestamp); |
| 862 SendTouchEvent(); | 872 uint32 touch_press_event_id1 = SendTouchEvent(); |
| 863 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 873 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 864 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, | 874 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, |
| 865 gfx::Point(1, 1), 0, timestamp)); | 875 gfx::Point(1, 1), 0, timestamp)); |
| 866 | 876 |
| 867 // Move the finger. | 877 // Move the finger. |
| 868 timestamp += base::TimeDelta::FromSeconds(10); | 878 timestamp += base::TimeDelta::FromSeconds(10); |
| 869 MoveTouchPoint(0, 500, 500); | 879 MoveTouchPoint(0, 500, 500); |
| 870 SetTouchTimestamp(timestamp); | 880 SetTouchTimestamp(timestamp); |
| 871 SendTouchEvent(); | 881 uint32 touch_move_event_id1 = SendTouchEvent(); |
| 872 EXPECT_FALSE(TouchEventQueueEmpty()); | 882 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 873 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, | 883 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, |
| 874 gfx::Point(500, 500), 0, timestamp)); | 884 gfx::Point(500, 500), 0, timestamp)); |
| 875 | 885 |
| 876 // Now press a second finger. | 886 // Now press a second finger. |
| 877 timestamp += base::TimeDelta::FromSeconds(10); | 887 timestamp += base::TimeDelta::FromSeconds(10); |
| 878 PressTouchPoint(2, 2); | 888 PressTouchPoint(2, 2); |
| 879 SetTouchTimestamp(timestamp); | 889 SetTouchTimestamp(timestamp); |
| 880 SendTouchEvent(); | 890 uint32 touch_press_event_id2 = SendTouchEvent(); |
| 881 EXPECT_FALSE(TouchEventQueueEmpty()); | 891 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 882 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, | 892 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, |
| 883 gfx::Point(2, 2), 1, timestamp)); | 893 gfx::Point(2, 2), 1, timestamp)); |
| 884 | 894 |
| 885 // Move both fingers. | 895 // Move both fingers. |
| 886 timestamp += base::TimeDelta::FromSeconds(10); | 896 timestamp += base::TimeDelta::FromSeconds(10); |
| 887 MoveTouchPoint(0, 10, 10); | 897 MoveTouchPoint(0, 10, 10); |
| 888 MoveTouchPoint(1, 20, 20); | 898 MoveTouchPoint(1, 20, 20); |
| 889 SetTouchTimestamp(timestamp); | 899 SetTouchTimestamp(timestamp); |
| 890 SendTouchEvent(); | 900 uint32 touch_move_event_id2 = SendTouchEvent(); |
| 891 EXPECT_FALSE(TouchEventQueueEmpty()); | 901 EXPECT_FALSE(TouchEventQueueEmpty()); |
| 892 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, | 902 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, |
| 893 gfx::Point(10, 10), 0, timestamp)); | 903 gfx::Point(10, 10), 0, timestamp)); |
| 894 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, | 904 expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, |
| 895 gfx::Point(20, 20), 1, timestamp)); | 905 gfx::Point(20, 20), 1, timestamp)); |
| 896 | 906 |
| 897 // Receive the ACKs and make sure the generated events from the acked events | 907 // Receive the ACKs and make sure the generated events from the acked events |
| 898 // are correct. | 908 // are correct. |
| 899 WebInputEvent::Type acks[] = { WebInputEvent::TouchStart, | 909 WebInputEvent::Type acks[] = { WebInputEvent::TouchStart, |
| 900 WebInputEvent::TouchMove, | 910 WebInputEvent::TouchMove, |
| 901 WebInputEvent::TouchStart, | 911 WebInputEvent::TouchStart, |
| 902 WebInputEvent::TouchMove }; | 912 WebInputEvent::TouchMove }; |
| 903 | 913 |
| 914 uint32 touch_event_ids[] = {touch_press_event_id1, |
| 915 touch_move_event_id1, |
| 916 touch_press_event_id2, |
| 917 touch_move_event_id2}; |
| 918 |
| 904 TouchEventCoordinateSystem coordinate_system = LOCAL_COORDINATES; | 919 TouchEventCoordinateSystem coordinate_system = LOCAL_COORDINATES; |
| 905 #if !defined(OS_WIN) | 920 #if !defined(OS_WIN) |
| 906 coordinate_system = SCREEN_COORDINATES; | 921 coordinate_system = SCREEN_COORDINATES; |
| 907 #endif | 922 #endif |
| 908 for (size_t i = 0; i < arraysize(acks); ++i) { | 923 for (size_t i = 0; i < arraysize(acks); ++i) { |
| 909 SendInputEventACK(acks[i], | 924 SendTouchEventACK(acks[i], INPUT_EVENT_ACK_STATE_NOT_CONSUMED, |
| 910 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 925 touch_event_ids[i]); |
| 911 EXPECT_EQ(acks[i], ack_handler_->acked_touch_event().event.type); | 926 EXPECT_EQ(acks[i], ack_handler_->acked_touch_event().event.type); |
| 912 ScopedVector<ui::TouchEvent> acked; | 927 ScopedVector<ui::TouchEvent> acked; |
| 913 | 928 |
| 914 MakeUITouchEventsFromWebTouchEvents( | 929 MakeUITouchEventsFromWebTouchEvents( |
| 915 ack_handler_->acked_touch_event(), &acked, coordinate_system); | 930 ack_handler_->acked_touch_event(), &acked, coordinate_system); |
| 916 bool success = EventListIsSubset(acked, expected_events); | 931 bool success = EventListIsSubset(acked, expected_events); |
| 917 EXPECT_TRUE(success) << "Failed on step: " << i; | 932 EXPECT_TRUE(success) << "Failed on step: " << i; |
| 918 if (!success) | 933 if (!success) |
| 919 break; | 934 break; |
| 920 expected_events.erase(expected_events.begin(), | 935 expected_events.erase(expected_events.begin(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 950 InputMsg_HandleInputEvent::ID)); | 965 InputMsg_HandleInputEvent::ID)); |
| 951 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 966 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 952 | 967 |
| 953 // Check that the correct unhandled wheel event was received. | 968 // Check that the correct unhandled wheel event was received. |
| 954 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 969 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 955 } | 970 } |
| 956 | 971 |
| 957 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { | 972 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { |
| 958 OnHasTouchEventHandlers(true); | 973 OnHasTouchEventHandlers(true); |
| 959 // Only acks for TouchCancel should always be ignored. | 974 // Only acks for TouchCancel should always be ignored. |
| 960 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 975 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 961 GetEventWithType(WebInputEvent::TouchStart))); | 976 GetEventWithType(WebInputEvent::TouchStart))); |
| 962 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 977 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 963 GetEventWithType(WebInputEvent::TouchMove))); | 978 GetEventWithType(WebInputEvent::TouchMove))); |
| 964 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 979 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 965 GetEventWithType(WebInputEvent::TouchEnd))); | 980 GetEventWithType(WebInputEvent::TouchEnd))); |
| 966 | 981 |
| 967 // Precede the TouchCancel with an appropriate TouchStart; | 982 // Precede the TouchCancel with an appropriate TouchStart; |
| 968 PressTouchPoint(1, 1); | 983 PressTouchPoint(1, 1); |
| 969 SendTouchEvent(); | 984 uint32 touch_press_event_id = SendTouchEvent(); |
| 970 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 985 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 986 touch_press_event_id); |
| 971 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 987 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 972 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 988 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 973 ASSERT_EQ(0, client_->in_flight_event_count()); | 989 ASSERT_EQ(0, client_->in_flight_event_count()); |
| 974 | 990 |
| 975 // The TouchCancel ack is always ignored. | 991 // The TouchCancel ack is always ignored. |
| 976 CancelTouchPoint(0); | 992 CancelTouchPoint(0); |
| 977 SendTouchEvent(); | 993 uint32 touch_cancel_event_id = SendTouchEvent(); |
| 978 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 994 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 979 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 995 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 980 EXPECT_EQ(0, client_->in_flight_event_count()); | 996 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 981 EXPECT_FALSE(HasPendingEvents()); | 997 EXPECT_FALSE(HasPendingEvents()); |
| 982 SendInputEventACK(WebInputEvent::TouchCancel, | 998 SendTouchEventACK(WebInputEvent::TouchCancel, |
| 983 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 999 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_cancel_event_id); |
| 984 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1000 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 985 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1001 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 986 EXPECT_FALSE(HasPendingEvents()); | 1002 EXPECT_FALSE(HasPendingEvents()); |
| 987 } | 1003 } |
| 988 | 1004 |
| 989 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { | 1005 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { |
| 990 // We test every gesture type, ensuring that the stream of gestures is valid. | 1006 // We test every gesture type, ensuring that the stream of gestures is valid. |
| 991 const WebInputEvent::Type eventTypes[] = { | 1007 const WebInputEvent::Type eventTypes[] = { |
| 992 WebInputEvent::GestureTapDown, | 1008 WebInputEvent::GestureTapDown, |
| 993 WebInputEvent::GestureShowPress, | 1009 WebInputEvent::GestureShowPress, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1012 WebInputEvent::GestureTapDown, | 1028 WebInputEvent::GestureTapDown, |
| 1013 WebInputEvent::GestureTapCancel, | 1029 WebInputEvent::GestureTapCancel, |
| 1014 WebInputEvent::GestureScrollBegin, | 1030 WebInputEvent::GestureScrollBegin, |
| 1015 WebInputEvent::GestureScrollUpdate, | 1031 WebInputEvent::GestureScrollUpdate, |
| 1016 WebInputEvent::GesturePinchBegin, | 1032 WebInputEvent::GesturePinchBegin, |
| 1017 WebInputEvent::GesturePinchUpdate, | 1033 WebInputEvent::GesturePinchUpdate, |
| 1018 WebInputEvent::GesturePinchEnd, | 1034 WebInputEvent::GesturePinchEnd, |
| 1019 WebInputEvent::GestureScrollEnd}; | 1035 WebInputEvent::GestureScrollEnd}; |
| 1020 for (size_t i = 0; i < arraysize(eventTypes); ++i) { | 1036 for (size_t i = 0; i < arraysize(eventTypes); ++i) { |
| 1021 WebInputEvent::Type type = eventTypes[i]; | 1037 WebInputEvent::Type type = eventTypes[i]; |
| 1022 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { | 1038 if (WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1039 GetEventWithType(type))) { |
| 1023 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1040 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1024 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1041 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1025 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1042 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1026 EXPECT_EQ(1, client_->in_flight_event_count()); | 1043 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1027 EXPECT_TRUE(HasPendingEvents()); | 1044 EXPECT_TRUE(HasPendingEvents()); |
| 1028 | 1045 |
| 1029 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1046 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1030 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1047 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1031 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1048 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1032 EXPECT_EQ(0, client_->in_flight_event_count()); | 1049 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1033 EXPECT_FALSE(HasPendingEvents()); | 1050 EXPECT_FALSE(HasPendingEvents()); |
| 1034 continue; | 1051 continue; |
| 1035 } | 1052 } |
| 1036 | 1053 |
| 1037 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1054 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1038 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1055 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1039 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1056 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1040 EXPECT_EQ(0, client_->in_flight_event_count()); | 1057 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1041 EXPECT_FALSE(HasPendingEvents()); | 1058 EXPECT_FALSE(HasPendingEvents()); |
| 1042 } | 1059 } |
| 1043 } | 1060 } |
| 1044 | 1061 |
| 1045 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { | 1062 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { |
| 1046 int start_type = static_cast<int>(WebInputEvent::MouseDown); | 1063 int start_type = static_cast<int>(WebInputEvent::MouseDown); |
| 1047 int end_type = static_cast<int>(WebInputEvent::ContextMenu); | 1064 int end_type = static_cast<int>(WebInputEvent::ContextMenu); |
| 1048 ASSERT_LT(start_type, end_type); | 1065 ASSERT_LT(start_type, end_type); |
| 1049 for (int i = start_type; i <= end_type; ++i) { | 1066 for (int i = start_type; i <= end_type; ++i) { |
| 1050 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); | 1067 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); |
| 1051 int expected_in_flight_event_count = | 1068 int expected_in_flight_event_count = |
| 1052 WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type)) ? 0 | 1069 !WebInputEventTraits::WillReceiveAckFromRenderer(GetEventWithType(type)) |
| 1053 : 1; | 1070 ? 0 |
| 1071 : 1; |
| 1054 | 1072 |
| 1055 // Note: Mouse event acks are never forwarded to the ack handler, so the key | 1073 // Note: Mouse event acks are never forwarded to the ack handler, so the key |
| 1056 // result here is that ignored ack types don't affect the in-flight count. | 1074 // result here is that ignored ack types don't affect the in-flight count. |
| 1057 SimulateMouseEvent(type, 0, 0); | 1075 SimulateMouseEvent(type, 0, 0); |
| 1058 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1076 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1059 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1077 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1060 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count()); | 1078 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count()); |
| 1061 if (expected_in_flight_event_count) { | 1079 if (expected_in_flight_event_count) { |
| 1062 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1080 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1063 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1081 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1064 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1082 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1065 EXPECT_EQ(0, client_->in_flight_event_count()); | 1083 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1066 } | 1084 } |
| 1067 } | 1085 } |
| 1068 } | 1086 } |
| 1069 | 1087 |
| 1070 // Guard against breaking changes to the list of ignored event ack types in | 1088 // Guard against breaking changes to the list of ignored event ack types in |
| 1071 // |WebInputEventTraits::IgnoresAckDisposition|. | 1089 // |WebInputEventTraits::WillReceiveAckFromRenderer|. |
| 1072 TEST_F(InputRouterImplTest, RequiredEventAckTypes) { | 1090 TEST_F(InputRouterImplTest, RequiredEventAckTypes) { |
| 1073 const WebInputEvent::Type kRequiredEventAckTypes[] = { | 1091 const WebInputEvent::Type kRequiredEventAckTypes[] = { |
| 1074 WebInputEvent::MouseMove, | 1092 WebInputEvent::MouseMove, |
| 1075 WebInputEvent::MouseWheel, | 1093 WebInputEvent::MouseWheel, |
| 1076 WebInputEvent::RawKeyDown, | 1094 WebInputEvent::RawKeyDown, |
| 1077 WebInputEvent::KeyDown, | 1095 WebInputEvent::KeyDown, |
| 1078 WebInputEvent::KeyUp, | 1096 WebInputEvent::KeyUp, |
| 1079 WebInputEvent::Char, | 1097 WebInputEvent::Char, |
| 1080 WebInputEvent::GestureScrollUpdate, | 1098 WebInputEvent::GestureScrollUpdate, |
| 1081 WebInputEvent::GestureFlingStart, | 1099 WebInputEvent::GestureFlingStart, |
| 1082 WebInputEvent::GestureFlingCancel, | 1100 WebInputEvent::GestureFlingCancel, |
| 1083 WebInputEvent::GesturePinchUpdate, | 1101 WebInputEvent::GesturePinchUpdate, |
| 1084 WebInputEvent::TouchStart, | 1102 WebInputEvent::TouchStart, |
| 1085 WebInputEvent::TouchMove | 1103 WebInputEvent::TouchMove |
| 1086 }; | 1104 }; |
| 1087 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) { | 1105 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) { |
| 1088 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i]; | 1106 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i]; |
| 1089 EXPECT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1107 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1090 GetEventWithType(required_ack_type))); | 1108 GetEventWithType(required_ack_type))); |
| 1091 } | 1109 } |
| 1092 } | 1110 } |
| 1093 | 1111 |
| 1094 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't | 1112 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't |
| 1095 // wait for ACKs. | 1113 // wait for ACKs. |
| 1096 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) { | 1114 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) { |
| 1097 // Interleave a few events that do and do not ignore acks, ensuring that | 1115 // Interleave a few events that do and do not ignore acks, ensuring that |
| 1098 // ack-ignoring events aren't dispatched until all prior events which observe | 1116 // ack-ignoring events aren't dispatched until all prior events which observe |
| 1099 // their ack disposition have been dispatched. | 1117 // their ack disposition have been dispatched. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 | 1223 |
| 1206 // Test that touch ack timeout behavior is properly toggled by view update flags | 1224 // Test that touch ack timeout behavior is properly toggled by view update flags |
| 1207 // and allowed touch actions. | 1225 // and allowed touch actions. |
| 1208 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { | 1226 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { |
| 1209 const int timeout_ms = 1; | 1227 const int timeout_ms = 1; |
| 1210 SetUpForTouchAckTimeoutTest(timeout_ms); | 1228 SetUpForTouchAckTimeoutTest(timeout_ms); |
| 1211 ASSERT_TRUE(TouchEventTimeoutEnabled()); | 1229 ASSERT_TRUE(TouchEventTimeoutEnabled()); |
| 1212 | 1230 |
| 1213 // Verify that the touch ack timeout fires upon the delayed ack. | 1231 // Verify that the touch ack timeout fires upon the delayed ack. |
| 1214 PressTouchPoint(1, 1); | 1232 PressTouchPoint(1, 1); |
| 1215 SendTouchEvent(); | 1233 uint32 touch_press_event_id1 = SendTouchEvent(); |
| 1216 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1234 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1217 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1235 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1218 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); | 1236 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
| 1219 | 1237 |
| 1220 // The timed-out event should have been ack'ed. | 1238 // The timed-out event should have been ack'ed. |
| 1221 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1239 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1222 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1240 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1223 | 1241 |
| 1224 // Ack'ing the timed-out event should fire a TouchCancel. | 1242 // Ack'ing the timed-out event should fire a TouchCancel. |
| 1225 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1243 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1244 touch_press_event_id1); |
| 1226 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1245 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1227 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1246 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1228 | 1247 |
| 1229 // The remainder of the touch sequence should be dropped. | 1248 // The remainder of the touch sequence should be dropped. |
| 1230 ReleaseTouchPoint(0); | 1249 ReleaseTouchPoint(0); |
| 1231 SendTouchEvent(); | 1250 SendTouchEvent(); |
| 1232 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1251 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1233 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1252 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1234 ASSERT_TRUE(TouchEventTimeoutEnabled()); | 1253 ASSERT_TRUE(TouchEventTimeoutEnabled()); |
| 1235 | 1254 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1246 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | | 1265 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | |
| 1247 InputRouter::FIXED_PAGE_SCALE); | 1266 InputRouter::FIXED_PAGE_SCALE); |
| 1248 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1267 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
| 1249 | 1268 |
| 1250 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); | 1269 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); |
| 1251 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1270 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1252 | 1271 |
| 1253 // TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout. | 1272 // TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout. |
| 1254 OnHasTouchEventHandlers(true); | 1273 OnHasTouchEventHandlers(true); |
| 1255 PressTouchPoint(1, 1); | 1274 PressTouchPoint(1, 1); |
| 1256 SendTouchEvent(); | 1275 uint32 touch_press_event_id2 = SendTouchEvent(); |
| 1257 OnSetTouchAction(TOUCH_ACTION_PAN_Y); | 1276 OnSetTouchAction(TOUCH_ACTION_PAN_Y); |
| 1258 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1277 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1259 ReleaseTouchPoint(0); | 1278 ReleaseTouchPoint(0); |
| 1260 SendTouchEvent(); | 1279 uint32 touch_release_event_id2 = SendTouchEvent(); |
| 1261 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1280 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1262 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1281 touch_press_event_id2); |
| 1282 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1283 touch_release_event_id2); |
| 1263 | 1284 |
| 1264 PressTouchPoint(1, 1); | 1285 PressTouchPoint(1, 1); |
| 1265 SendTouchEvent(); | 1286 uint32 touch_press_event_id3 = SendTouchEvent(); |
| 1266 OnSetTouchAction(TOUCH_ACTION_NONE); | 1287 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1267 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1288 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
| 1268 ReleaseTouchPoint(0); | 1289 ReleaseTouchPoint(0); |
| 1269 SendTouchEvent(); | 1290 uint32 touch_release_event_id3 = SendTouchEvent(); |
| 1270 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1291 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1271 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1292 touch_press_event_id3); |
| 1293 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1294 touch_release_event_id3); |
| 1272 | 1295 |
| 1273 // As the touch-action is reset by a new touch sequence, the timeout behavior | 1296 // As the touch-action is reset by a new touch sequence, the timeout behavior |
| 1274 // should be restored. | 1297 // should be restored. |
| 1275 PressTouchPoint(1, 1); | 1298 PressTouchPoint(1, 1); |
| 1276 SendTouchEvent(); | 1299 SendTouchEvent(); |
| 1277 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1300 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1278 } | 1301 } |
| 1279 | 1302 |
| 1280 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by | 1303 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by |
| 1281 // the touch timeout. | 1304 // the touch timeout. |
| 1282 TEST_F(InputRouterImplTest, | 1305 TEST_F(InputRouterImplTest, |
| 1283 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { | 1306 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { |
| 1284 const int timeout_ms = 1; | 1307 const int timeout_ms = 1; |
| 1285 SetUpForTouchAckTimeoutTest(timeout_ms); | 1308 SetUpForTouchAckTimeoutTest(timeout_ms); |
| 1286 ASSERT_TRUE(TouchEventTimeoutEnabled()); | 1309 ASSERT_TRUE(TouchEventTimeoutEnabled()); |
| 1287 OnHasTouchEventHandlers(true); | 1310 OnHasTouchEventHandlers(true); |
| 1288 | 1311 |
| 1289 // Start a touch sequence. | 1312 // Start a touch sequence. |
| 1290 PressTouchPoint(1, 1); | 1313 PressTouchPoint(1, 1); |
| 1291 SendTouchEvent(); | 1314 uint32 touch_press_event_id = SendTouchEvent(); |
| 1292 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1315 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1293 | 1316 |
| 1294 // TOUCH_ACTION_NONE should disable the timeout. | 1317 // TOUCH_ACTION_NONE should disable the timeout. |
| 1295 OnSetTouchAction(TOUCH_ACTION_NONE); | 1318 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1296 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1319 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1320 touch_press_event_id); |
| 1297 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1321 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1298 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1322 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
| 1299 | 1323 |
| 1300 MoveTouchPoint(0, 1, 2); | 1324 MoveTouchPoint(0, 1, 2); |
| 1301 SendTouchEvent(); | 1325 uint32 touch_move_event_id = SendTouchEvent(); |
| 1302 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1326 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
| 1303 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1327 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1304 | 1328 |
| 1305 // Delay the move ack. The timeout should not fire. | 1329 // Delay the move ack. The timeout should not fire. |
| 1306 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); | 1330 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
| 1307 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1331 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1308 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1332 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1309 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1333 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1334 touch_move_event_id); |
| 1310 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1335 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1311 | 1336 |
| 1312 // End the touch sequence. | 1337 // End the touch sequence. |
| 1313 ReleaseTouchPoint(0); | 1338 ReleaseTouchPoint(0); |
| 1314 SendTouchEvent(); | 1339 uint32 touch_release_event_id = SendTouchEvent(); |
| 1315 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1340 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1341 touch_release_event_id); |
| 1316 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1342 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
| 1317 ack_handler_->GetAndResetAckCount(); | 1343 ack_handler_->GetAndResetAckCount(); |
| 1318 GetSentMessageCountAndResetSink(); | 1344 GetSentMessageCountAndResetSink(); |
| 1319 | 1345 |
| 1320 // Start another touch sequence. This should restore the touch timeout. | 1346 // Start another touch sequence. This should restore the touch timeout. |
| 1321 PressTouchPoint(1, 1); | 1347 PressTouchPoint(1, 1); |
| 1322 SendTouchEvent(); | 1348 SendTouchEvent(); |
| 1323 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1349 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
| 1324 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1350 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1325 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1351 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1326 | 1352 |
| 1327 // Wait for the touch ack timeout to fire. | 1353 // Wait for the touch ack timeout to fire. |
| 1328 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); | 1354 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
| 1329 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1355 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1330 } | 1356 } |
| 1331 | 1357 |
| 1332 // Test that TouchActionFilter::ResetTouchAction is called before the | 1358 // Test that TouchActionFilter::ResetTouchAction is called before the |
| 1333 // first touch event for a touch sequence reaches the renderer. | 1359 // first touch event for a touch sequence reaches the renderer. |
| 1334 TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) { | 1360 TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) { |
| 1335 OnHasTouchEventHandlers(true); | 1361 OnHasTouchEventHandlers(true); |
| 1336 | 1362 |
| 1337 // Sequence 1. | 1363 // Sequence 1. |
| 1338 PressTouchPoint(1, 1); | 1364 PressTouchPoint(1, 1); |
| 1339 SendTouchEvent(); | 1365 uint32 touch_press_event_id1 = SendTouchEvent(); |
| 1340 OnSetTouchAction(TOUCH_ACTION_NONE); | 1366 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1341 MoveTouchPoint(0, 50, 50); | 1367 MoveTouchPoint(0, 50, 50); |
| 1342 SendTouchEvent(); | 1368 uint32 touch_move_event_id1 = SendTouchEvent(); |
| 1343 ReleaseTouchPoint(0); | 1369 ReleaseTouchPoint(0); |
| 1344 SendTouchEvent(); | 1370 uint32 touch_release_event_id1 = SendTouchEvent(); |
| 1345 | 1371 |
| 1346 // Sequence 2. | 1372 // Sequence 2. |
| 1347 PressTouchPoint(1, 1); | 1373 PressTouchPoint(1, 1); |
| 1348 SendTouchEvent(); | 1374 uint32 touch_press_event_id2 = SendTouchEvent(); |
| 1349 MoveTouchPoint(0, 50, 50); | 1375 MoveTouchPoint(0, 50, 50); |
| 1350 SendTouchEvent(); | 1376 uint32 touch_move_event_id2 = SendTouchEvent(); |
| 1351 ReleaseTouchPoint(0); | 1377 ReleaseTouchPoint(0); |
| 1352 SendTouchEvent(); | 1378 uint32 touch_release_event_id2 = SendTouchEvent(); |
| 1353 | 1379 |
| 1354 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1380 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1355 SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED); | 1381 touch_press_event_id1); |
| 1382 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1383 touch_move_event_id1); |
| 1356 | 1384 |
| 1357 // Ensure touch action is still none, as the next touch start hasn't been | 1385 // Ensure touch action is still none, as the next touch start hasn't been |
| 1358 // acked yet. ScrollBegin and ScrollEnd don't require acks. | 1386 // acked yet. ScrollBegin and ScrollEnd don't require acks. |
| 1359 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1387 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1360 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1388 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1361 blink::WebGestureDeviceTouchscreen); | 1389 blink::WebGestureDeviceTouchscreen); |
| 1362 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1390 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1363 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1391 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1364 blink::WebGestureDeviceTouchscreen); | 1392 blink::WebGestureDeviceTouchscreen); |
| 1365 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1393 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1366 | 1394 |
| 1367 // This allows the next touch sequence to start. | 1395 // This allows the next touch sequence to start. |
| 1368 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1396 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1397 touch_release_event_id1); |
| 1369 | 1398 |
| 1370 // Ensure touch action has been set to auto, as a new touch sequence has | 1399 // Ensure touch action has been set to auto, as a new touch sequence has |
| 1371 // started. | 1400 // started. |
| 1372 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1401 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1373 SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED); | 1402 touch_press_event_id2); |
| 1403 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1404 touch_move_event_id2); |
| 1374 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1405 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1375 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1406 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1376 blink::WebGestureDeviceTouchscreen); | 1407 blink::WebGestureDeviceTouchscreen); |
| 1377 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1408 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1378 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1409 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1379 blink::WebGestureDeviceTouchscreen); | 1410 blink::WebGestureDeviceTouchscreen); |
| 1380 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1411 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1381 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1412 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1413 touch_release_event_id2); |
| 1382 } | 1414 } |
| 1383 | 1415 |
| 1384 // Test that TouchActionFilter::ResetTouchAction is called when a new touch | 1416 // Test that TouchActionFilter::ResetTouchAction is called when a new touch |
| 1385 // sequence has no consumer. | 1417 // sequence has no consumer. |
| 1386 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) { | 1418 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) { |
| 1387 OnHasTouchEventHandlers(true); | 1419 OnHasTouchEventHandlers(true); |
| 1388 | 1420 |
| 1389 // Sequence 1. | 1421 // Sequence 1. |
| 1390 PressTouchPoint(1, 1); | 1422 PressTouchPoint(1, 1); |
| 1391 SendTouchEvent(); | 1423 uint32 touch_press_event_id1 = SendTouchEvent(); |
| 1392 MoveTouchPoint(0, 50, 50); | 1424 MoveTouchPoint(0, 50, 50); |
| 1393 SendTouchEvent(); | 1425 uint32 touch_move_event_id1 = SendTouchEvent(); |
| 1394 OnSetTouchAction(TOUCH_ACTION_NONE); | 1426 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1395 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1427 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1396 SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED); | 1428 touch_press_event_id1); |
| 1429 SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1430 touch_move_event_id1); |
| 1397 | 1431 |
| 1398 ReleaseTouchPoint(0); | 1432 ReleaseTouchPoint(0); |
| 1399 SendTouchEvent(); | 1433 uint32 touch_release_event_id1 = SendTouchEvent(); |
| 1400 | 1434 |
| 1401 // Sequence 2 | 1435 // Sequence 2 |
| 1402 PressTouchPoint(1, 1); | 1436 PressTouchPoint(1, 1); |
| 1403 SendTouchEvent(); | 1437 uint32 touch_press_event_id2 = SendTouchEvent(); |
| 1404 MoveTouchPoint(0, 50, 50); | 1438 MoveTouchPoint(0, 50, 50); |
| 1405 SendTouchEvent(); | 1439 SendTouchEvent(); |
| 1406 ReleaseTouchPoint(0); | 1440 ReleaseTouchPoint(0); |
| 1407 SendTouchEvent(); | 1441 SendTouchEvent(); |
| 1408 | 1442 |
| 1409 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require | 1443 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require |
| 1410 // acks. | 1444 // acks. |
| 1411 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | 1445 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1412 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1446 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1413 blink::WebGestureDeviceTouchscreen); | 1447 blink::WebGestureDeviceTouchscreen); |
| 1414 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1448 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1415 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1449 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1416 blink::WebGestureDeviceTouchscreen); | 1450 blink::WebGestureDeviceTouchscreen); |
| 1417 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1451 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1418 | 1452 |
| 1419 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1453 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1420 SendInputEventACK(WebInputEvent::TouchStart, | 1454 touch_release_event_id1); |
| 1421 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1455 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1456 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1457 touch_press_event_id2); |
| 1422 | 1458 |
| 1423 // Ensure touch action has been set to auto, as the touch had no consumer. | 1459 // Ensure touch action has been set to auto, as the touch had no consumer. |
| 1424 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1460 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1425 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1461 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1426 blink::WebGestureDeviceTouchscreen); | 1462 blink::WebGestureDeviceTouchscreen); |
| 1427 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1463 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1428 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1464 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1429 blink::WebGestureDeviceTouchscreen); | 1465 blink::WebGestureDeviceTouchscreen); |
| 1430 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1466 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1431 } | 1467 } |
| 1432 | 1468 |
| 1433 // Test that TouchActionFilter::ResetTouchAction is called when the touch | 1469 // Test that TouchActionFilter::ResetTouchAction is called when the touch |
| 1434 // handler is removed. | 1470 // handler is removed. |
| 1435 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) { | 1471 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) { |
| 1436 // Touch sequence with touch handler. | 1472 // Touch sequence with touch handler. |
| 1437 OnHasTouchEventHandlers(true); | 1473 OnHasTouchEventHandlers(true); |
| 1438 PressTouchPoint(1, 1); | 1474 PressTouchPoint(1, 1); |
| 1439 SendTouchEvent(); | 1475 uint32 touch_press_event_id = SendTouchEvent(); |
| 1440 MoveTouchPoint(0, 50, 50); | 1476 MoveTouchPoint(0, 50, 50); |
| 1441 SendTouchEvent(); | 1477 uint32 touch_move_event_id = SendTouchEvent(); |
| 1442 OnSetTouchAction(TOUCH_ACTION_NONE); | 1478 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1443 ReleaseTouchPoint(0); | 1479 ReleaseTouchPoint(0); |
| 1444 SendTouchEvent(); | 1480 uint32 touch_release_event_id = SendTouchEvent(); |
| 1445 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1481 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1446 | 1482 |
| 1447 // Ensure we have touch-action:none, suppressing scroll events. | 1483 // Ensure we have touch-action:none, suppressing scroll events. |
| 1448 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1484 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1485 touch_press_event_id); |
| 1449 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1486 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1450 SendInputEventACK(WebInputEvent::TouchMove, | 1487 SendTouchEventACK(WebInputEvent::TouchMove, |
| 1451 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1488 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); |
| 1452 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1489 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1453 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1490 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1454 blink::WebGestureDeviceTouchscreen); | 1491 blink::WebGestureDeviceTouchscreen); |
| 1455 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1492 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1456 | 1493 |
| 1457 SendInputEventACK(WebInputEvent::TouchEnd, | 1494 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_NOT_CONSUMED, |
| 1458 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1495 touch_release_event_id); |
| 1459 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1496 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1460 blink::WebGestureDeviceTouchscreen); | 1497 blink::WebGestureDeviceTouchscreen); |
| 1461 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1498 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1462 | 1499 |
| 1463 // Sequence without a touch handler. Note that in this case, the view may not | 1500 // Sequence without a touch handler. Note that in this case, the view may not |
| 1464 // necessarily forward touches to the router (as no touch handler exists). | 1501 // necessarily forward touches to the router (as no touch handler exists). |
| 1465 OnHasTouchEventHandlers(false); | 1502 OnHasTouchEventHandlers(false); |
| 1466 | 1503 |
| 1467 // Ensure touch action has been set to auto, as the touch handler has been | 1504 // Ensure touch action has been set to auto, as the touch handler has been |
| 1468 // removed. | 1505 // removed. |
| 1469 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1506 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1470 blink::WebGestureDeviceTouchscreen); | 1507 blink::WebGestureDeviceTouchscreen); |
| 1471 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1508 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1472 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 1509 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 1473 blink::WebGestureDeviceTouchscreen); | 1510 blink::WebGestureDeviceTouchscreen); |
| 1474 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1511 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1475 } | 1512 } |
| 1476 | 1513 |
| 1477 // Test that the double tap gesture depends on the touch action of the first | 1514 // Test that the double tap gesture depends on the touch action of the first |
| 1478 // tap. | 1515 // tap. |
| 1479 TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) { | 1516 TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) { |
| 1480 OnHasTouchEventHandlers(true); | 1517 OnHasTouchEventHandlers(true); |
| 1481 | 1518 |
| 1482 // Sequence 1. | 1519 // Sequence 1. |
| 1483 PressTouchPoint(1, 1); | 1520 PressTouchPoint(1, 1); |
| 1484 SendTouchEvent(); | 1521 uint32 touch_press_event_id1 = SendTouchEvent(); |
| 1485 OnSetTouchAction(TOUCH_ACTION_NONE); | 1522 OnSetTouchAction(TOUCH_ACTION_NONE); |
| 1486 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1523 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1524 touch_press_event_id1); |
| 1487 | 1525 |
| 1488 ReleaseTouchPoint(0); | 1526 ReleaseTouchPoint(0); |
| 1489 SendTouchEvent(); | 1527 uint32 touch_release_event_id = SendTouchEvent(); |
| 1490 | 1528 |
| 1491 // Sequence 2 | 1529 // Sequence 2 |
| 1492 PressTouchPoint(1, 1); | 1530 PressTouchPoint(1, 1); |
| 1493 SendTouchEvent(); | 1531 uint32 touch_press_event_id2 = SendTouchEvent(); |
| 1494 | 1532 |
| 1495 // First tap. | 1533 // First tap. |
| 1496 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); | 1534 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); |
| 1497 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1535 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1498 blink::WebGestureDeviceTouchscreen); | 1536 blink::WebGestureDeviceTouchscreen); |
| 1499 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1537 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1500 | 1538 |
| 1501 // The GestureTapUnconfirmed is converted into a tap, as the touch action is | 1539 // The GestureTapUnconfirmed is converted into a tap, as the touch action is |
| 1502 // none. | 1540 // none. |
| 1503 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, | 1541 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, |
| 1504 blink::WebGestureDeviceTouchscreen); | 1542 blink::WebGestureDeviceTouchscreen); |
| 1505 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1543 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1506 // This test will become invalid if GestureTap stops requiring an ack. | 1544 // This test will become invalid if GestureTap stops requiring an ack. |
| 1507 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1545 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1508 GetEventWithType(WebInputEvent::GestureTap))); | 1546 GetEventWithType(WebInputEvent::GestureTap))); |
| 1509 EXPECT_EQ(2, client_->in_flight_event_count()); | 1547 EXPECT_EQ(2, client_->in_flight_event_count()); |
| 1510 SendInputEventACK(WebInputEvent::GestureTap, | 1548 SendInputEventACK(WebInputEvent::GestureTap, |
| 1511 INPUT_EVENT_ACK_STATE_CONSUMED); | 1549 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1512 EXPECT_EQ(1, client_->in_flight_event_count()); | 1550 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1513 | 1551 |
| 1514 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned | 1552 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned |
| 1515 // into a tap. | 1553 // into a tap. |
| 1516 SimulateGestureEvent(WebInputEvent::GestureTap, | 1554 SimulateGestureEvent(WebInputEvent::GestureTap, |
| 1517 blink::WebGestureDeviceTouchscreen); | 1555 blink::WebGestureDeviceTouchscreen); |
| 1518 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1556 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1519 | 1557 |
| 1520 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1558 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, |
| 1521 SendInputEventACK(WebInputEvent::TouchStart, | 1559 touch_release_event_id); |
| 1522 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1560 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1561 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1562 touch_press_event_id2); |
| 1523 | 1563 |
| 1524 // Second Tap. | 1564 // Second Tap. |
| 1525 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1565 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1526 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1566 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1527 blink::WebGestureDeviceTouchscreen); | 1567 blink::WebGestureDeviceTouchscreen); |
| 1528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1568 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1529 | 1569 |
| 1530 // Although the touch-action is now auto, the double tap still won't be | 1570 // Although the touch-action is now auto, the double tap still won't be |
| 1531 // dispatched, because the first tap occured when the touch-action was none. | 1571 // dispatched, because the first tap occured when the touch-action was none. |
| 1532 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, | 1572 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, |
| 1533 blink::WebGestureDeviceTouchscreen); | 1573 blink::WebGestureDeviceTouchscreen); |
| 1534 // This test will become invalid if GestureDoubleTap stops requiring an ack. | 1574 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
| 1535 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1575 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1536 GetEventWithType(WebInputEvent::GestureDoubleTap))); | 1576 GetEventWithType(WebInputEvent::GestureDoubleTap))); |
| 1537 EXPECT_EQ(1, client_->in_flight_event_count()); | 1577 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1538 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1578 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1539 EXPECT_EQ(0, client_->in_flight_event_count()); | 1579 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1540 } | 1580 } |
| 1541 | 1581 |
| 1542 // Test that the router will call the client's |DidFlush| after all events have | 1582 // Test that the router will call the client's |DidFlush| after all events have |
| 1543 // been dispatched following a call to |Flush|. | 1583 // been dispatched following a call to |Flush|. |
| 1544 TEST_F(InputRouterImplTest, InputFlush) { | 1584 TEST_F(InputRouterImplTest, InputFlush) { |
| 1545 EXPECT_FALSE(HasPendingEvents()); | 1585 EXPECT_FALSE(HasPendingEvents()); |
| 1546 | 1586 |
| 1547 // Flushing an empty router should immediately trigger DidFlush. | 1587 // Flushing an empty router should immediately trigger DidFlush. |
| 1548 RequestNotificationWhenFlushed(); | 1588 RequestNotificationWhenFlushed(); |
| 1549 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1589 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1550 EXPECT_FALSE(HasPendingEvents()); | 1590 EXPECT_FALSE(HasPendingEvents()); |
| 1551 | 1591 |
| 1552 // Queue a TouchStart. | 1592 // Queue a TouchStart. |
| 1553 OnHasTouchEventHandlers(true); | 1593 OnHasTouchEventHandlers(true); |
| 1554 PressTouchPoint(1, 1); | 1594 PressTouchPoint(1, 1); |
| 1555 SendTouchEvent(); | 1595 uint32 touch_press_event_id = SendTouchEvent(); |
| 1556 EXPECT_TRUE(HasPendingEvents()); | 1596 EXPECT_TRUE(HasPendingEvents()); |
| 1557 | 1597 |
| 1558 // DidFlush should be called only after the event is ack'ed. | 1598 // DidFlush should be called only after the event is ack'ed. |
| 1559 RequestNotificationWhenFlushed(); | 1599 RequestNotificationWhenFlushed(); |
| 1560 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1600 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1561 SendInputEventACK(WebInputEvent::TouchStart, | 1601 SendTouchEventACK(WebInputEvent::TouchStart, |
| 1562 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1602 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_press_event_id); |
| 1563 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1603 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1564 | 1604 |
| 1565 // Ensure different types of enqueued events will prevent the DidFlush call | 1605 // Ensure different types of enqueued events will prevent the DidFlush call |
| 1566 // until all such events have been fully dispatched. | 1606 // until all such events have been fully dispatched. |
| 1567 MoveTouchPoint(0, 50, 50); | 1607 MoveTouchPoint(0, 50, 50); |
| 1568 SendTouchEvent(); | 1608 uint32 touch_move_event_id = SendTouchEvent(); |
| 1569 ASSERT_TRUE(HasPendingEvents()); | 1609 ASSERT_TRUE(HasPendingEvents()); |
| 1570 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1610 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1571 blink::WebGestureDeviceTouchscreen); | 1611 blink::WebGestureDeviceTouchscreen); |
| 1572 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1612 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1573 blink::WebGestureDeviceTouchscreen); | 1613 blink::WebGestureDeviceTouchscreen); |
| 1574 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 1614 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 1575 blink::WebGestureDeviceTouchscreen); | 1615 blink::WebGestureDeviceTouchscreen); |
| 1576 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1616 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 1577 blink::WebGestureDeviceTouchscreen); | 1617 blink::WebGestureDeviceTouchscreen); |
| 1578 RequestNotificationWhenFlushed(); | 1618 RequestNotificationWhenFlushed(); |
| 1579 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1619 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1580 | 1620 |
| 1581 // Repeated flush calls should have no effect. | 1621 // Repeated flush calls should have no effect. |
| 1582 RequestNotificationWhenFlushed(); | 1622 RequestNotificationWhenFlushed(); |
| 1583 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1623 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1584 | 1624 |
| 1585 // There are still pending gestures. | 1625 // There are still pending gestures. |
| 1586 SendInputEventACK(WebInputEvent::TouchMove, | 1626 SendTouchEventACK(WebInputEvent::TouchMove, |
| 1587 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1627 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); |
| 1588 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1628 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1589 EXPECT_TRUE(HasPendingEvents()); | 1629 EXPECT_TRUE(HasPendingEvents()); |
| 1590 | 1630 |
| 1591 // One more gesture to go. | 1631 // One more gesture to go. |
| 1592 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1632 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1593 INPUT_EVENT_ACK_STATE_CONSUMED); | 1633 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1594 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1634 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1595 EXPECT_TRUE(HasPendingEvents()); | 1635 EXPECT_TRUE(HasPendingEvents()); |
| 1596 | 1636 |
| 1597 // The final ack'ed gesture should trigger the DidFlush. | 1637 // The final ack'ed gesture should trigger the DidFlush. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 client_overscroll.latest_overscroll_delta); | 1804 client_overscroll.latest_overscroll_delta); |
| 1765 EXPECT_EQ(overscroll.current_fling_velocity, | 1805 EXPECT_EQ(overscroll.current_fling_velocity, |
| 1766 client_overscroll.current_fling_velocity); | 1806 client_overscroll.current_fling_velocity); |
| 1767 | 1807 |
| 1768 DidOverscrollParams wheel_overscroll; | 1808 DidOverscrollParams wheel_overscroll; |
| 1769 wheel_overscroll.accumulated_overscroll = gfx::Vector2dF(7, -7); | 1809 wheel_overscroll.accumulated_overscroll = gfx::Vector2dF(7, -7); |
| 1770 wheel_overscroll.latest_overscroll_delta = gfx::Vector2dF(3, 0); | 1810 wheel_overscroll.latest_overscroll_delta = gfx::Vector2dF(3, 0); |
| 1771 wheel_overscroll.current_fling_velocity = gfx::Vector2dF(1, 0); | 1811 wheel_overscroll.current_fling_velocity = gfx::Vector2dF(1, 0); |
| 1772 | 1812 |
| 1773 SimulateWheelEvent(3, 0, 0, false); | 1813 SimulateWheelEvent(3, 0, 0, false); |
| 1774 InputHostMsg_HandleInputEvent_ACK_Params ack; | 1814 InputEventAck ack(WebInputEvent::MouseWheel, |
| 1775 ack.type = WebInputEvent::MouseWheel; | 1815 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1776 ack.state = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | |
| 1777 ack.overscroll.reset(new DidOverscrollParams(wheel_overscroll)); | 1816 ack.overscroll.reset(new DidOverscrollParams(wheel_overscroll)); |
| 1778 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); | 1817 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
| 1779 | 1818 |
| 1780 client_overscroll = client_->GetAndResetOverscroll(); | 1819 client_overscroll = client_->GetAndResetOverscroll(); |
| 1781 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1820 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
| 1782 client_overscroll.accumulated_overscroll); | 1821 client_overscroll.accumulated_overscroll); |
| 1783 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1822 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
| 1784 client_overscroll.latest_overscroll_delta); | 1823 client_overscroll.latest_overscroll_delta); |
| 1785 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1824 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
| 1786 client_overscroll.current_fling_velocity); | 1825 client_overscroll.current_fling_velocity); |
| 1787 } | 1826 } |
| 1788 | 1827 |
| 1789 } // namespace content | 1828 } // namespace content |
| OLD | NEW |