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 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void TearDown() override { | 160 void TearDown() override { |
161 // Process all pending tasks to avoid leaks. | 161 // Process all pending tasks to avoid leaks. |
162 base::MessageLoop::current()->RunUntilIdle(); | 162 base::MessageLoop::current()->RunUntilIdle(); |
163 | 163 |
164 input_router_.reset(); | 164 input_router_.reset(); |
165 client_.reset(); | 165 client_.reset(); |
166 process_.reset(); | 166 process_.reset(); |
167 browser_context_.reset(); | 167 browser_context_.reset(); |
168 } | 168 } |
169 | 169 |
| 170 void SetUpForGestureBasedWheelScrolling(bool enabled) { |
| 171 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 172 switches::kDisableWheelGestures) && |
| 173 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 174 switches::kEnableWheelGestures)); |
| 175 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 176 enabled ? switches::kEnableWheelGestures |
| 177 : switches::kDisableWheelGestures); |
| 178 TearDown(); |
| 179 SetUp(); |
| 180 } |
| 181 |
170 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, | 182 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, |
171 int mobile_timeout_ms) { | 183 int mobile_timeout_ms) { |
172 config_.touch_config.desktop_touch_ack_timeout_delay = | 184 config_.touch_config.desktop_touch_ack_timeout_delay = |
173 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); | 185 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); |
174 config_.touch_config.mobile_touch_ack_timeout_delay = | 186 config_.touch_config.mobile_touch_ack_timeout_delay = |
175 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); | 187 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); |
176 config_.touch_config.touch_ack_timeout_supported = true; | 188 config_.touch_config.touch_ack_timeout_supported = true; |
177 TearDown(); | 189 TearDown(); |
178 SetUp(); | 190 SetUp(); |
179 input_router()->NotifySiteIsMobileOptimized(false); | 191 input_router()->NotifySiteIsMobileOptimized(false); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 expected_events.erase(expected_events.begin(), | 941 expected_events.erase(expected_events.begin(), |
930 expected_events.begin() + acked.size()); | 942 expected_events.begin() + acked.size()); |
931 } | 943 } |
932 | 944 |
933 EXPECT_TRUE(TouchEventQueueEmpty()); | 945 EXPECT_TRUE(TouchEventQueueEmpty()); |
934 EXPECT_EQ(0U, expected_events.size()); | 946 EXPECT_EQ(0U, expected_events.size()); |
935 } | 947 } |
936 #endif // defined(USE_AURA) | 948 #endif // defined(USE_AURA) |
937 | 949 |
938 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { | 950 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { |
| 951 SetUpForGestureBasedWheelScrolling(false); |
| 952 |
939 // Simulate wheel events. | 953 // Simulate wheel events. |
940 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly | 954 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly |
941 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued | 955 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued |
942 | 956 |
943 // Check that only the first event was sent. | 957 // Check that only the first event was sent. |
944 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 958 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
945 InputMsg_HandleInputEvent::ID)); | 959 InputMsg_HandleInputEvent::ID)); |
946 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 960 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
947 | 961 |
948 // Indicate that the wheel event was unhandled. | 962 // Indicate that the wheel event was unhandled. |
949 SendInputEventACK(WebInputEvent::MouseWheel, | 963 SendInputEventACK(WebInputEvent::MouseWheel, |
950 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 964 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
951 | 965 |
952 // Check that the correct unhandled wheel event was received. | 966 // Check that the correct unhandled wheel event was received. |
953 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 967 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
954 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); | 968 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
955 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 969 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
956 | 970 |
957 // Check that the second event was sent. | 971 // Check that the second event was sent. |
958 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 972 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
959 InputMsg_HandleInputEvent::ID)); | 973 InputMsg_HandleInputEvent::ID)); |
960 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 974 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
961 | 975 |
| 976 // Indicate that the wheel event was unhandled. |
| 977 SendInputEventACK(WebInputEvent::MouseWheel, |
| 978 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 979 |
962 // Check that the correct unhandled wheel event was received. | 980 // Check that the correct unhandled wheel event was received. |
| 981 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 982 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
| 983 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -10); |
| 984 } |
| 985 |
| 986 TEST_F(InputRouterImplTest, UnhandledWheelEventWithGestureScrolling) { |
| 987 SetUpForGestureBasedWheelScrolling(true); |
| 988 |
| 989 // Simulate wheel events. |
| 990 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly |
| 991 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued |
| 992 |
| 993 // Check that only the first event was sent. |
| 994 EXPECT_TRUE( |
| 995 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); |
| 996 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 997 |
| 998 // Indicate that the wheel event was unhandled. |
| 999 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1000 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1001 |
| 1002 // Check that the correct unhandled wheel event was received. |
| 1003 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); |
| 1004 |
963 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 1005 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 1006 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1007 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1008 |
| 1009 // Check that the second event was sent. |
| 1010 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); |
| 1011 |
| 1012 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1013 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1014 |
| 1015 // Check that the correct unhandled wheel event was received. |
| 1016 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); |
| 1017 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
| 1018 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -10); |
964 } | 1019 } |
965 | 1020 |
966 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { | 1021 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { |
967 OnHasTouchEventHandlers(true); | 1022 OnHasTouchEventHandlers(true); |
968 // Only acks for TouchCancel should always be ignored. | 1023 // Only acks for TouchCancel should always be ignored. |
969 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( | 1024 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
970 GetEventWithType(WebInputEvent::TouchStart))); | 1025 GetEventWithType(WebInputEvent::TouchStart))); |
971 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( | 1026 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
972 GetEventWithType(WebInputEvent::TouchMove))); | 1027 GetEventWithType(WebInputEvent::TouchMove))); |
973 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( | 1028 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2298 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
2244 | 2299 |
2245 const WebGestureEvent* filter_event = | 2300 const WebGestureEvent* filter_event = |
2246 GetFilterWebInputEvent<WebGestureEvent>(); | 2301 GetFilterWebInputEvent<WebGestureEvent>(); |
2247 TestLocationInFilterEvent(filter_event, orig); | 2302 TestLocationInFilterEvent(filter_event, orig); |
2248 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2303 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
2249 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2304 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
2250 } | 2305 } |
2251 | 2306 |
2252 } // namespace content | 2307 } // namespace content |
OLD | NEW |