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 "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 void TearDown() override { | 163 void TearDown() override { |
164 // Process all pending tasks to avoid leaks. | 164 // Process all pending tasks to avoid leaks. |
165 base::MessageLoop::current()->RunUntilIdle(); | 165 base::MessageLoop::current()->RunUntilIdle(); |
166 | 166 |
167 input_router_.reset(); | 167 input_router_.reset(); |
168 client_.reset(); | 168 client_.reset(); |
169 process_.reset(); | 169 process_.reset(); |
170 browser_context_.reset(); | 170 browser_context_.reset(); |
171 } | 171 } |
172 | 172 |
| 173 void SetUpForGestureBasedWheelScrolling(bool enabled) { |
| 174 CHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 175 switches::kDisableWheelGestures) && |
| 176 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 177 switches::kEnableWheelGestures)); |
| 178 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 179 enabled ? switches::kEnableWheelGestures |
| 180 : switches::kDisableWheelGestures); |
| 181 TearDown(); |
| 182 SetUp(); |
| 183 } |
| 184 |
173 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, | 185 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, |
174 int mobile_timeout_ms) { | 186 int mobile_timeout_ms) { |
175 config_.touch_config.desktop_touch_ack_timeout_delay = | 187 config_.touch_config.desktop_touch_ack_timeout_delay = |
176 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); | 188 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); |
177 config_.touch_config.mobile_touch_ack_timeout_delay = | 189 config_.touch_config.mobile_touch_ack_timeout_delay = |
178 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); | 190 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); |
179 config_.touch_config.touch_ack_timeout_supported = true; | 191 config_.touch_config.touch_ack_timeout_supported = true; |
180 TearDown(); | 192 TearDown(); |
181 SetUp(); | 193 SetUp(); |
182 input_router()->NotifySiteIsMobileOptimized(false); | 194 input_router()->NotifySiteIsMobileOptimized(false); |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 expected_events.erase(expected_events.begin(), | 940 expected_events.erase(expected_events.begin(), |
929 expected_events.begin() + acked.size()); | 941 expected_events.begin() + acked.size()); |
930 } | 942 } |
931 | 943 |
932 EXPECT_TRUE(TouchEventQueueEmpty()); | 944 EXPECT_TRUE(TouchEventQueueEmpty()); |
933 EXPECT_EQ(0U, expected_events.size()); | 945 EXPECT_EQ(0U, expected_events.size()); |
934 } | 946 } |
935 #endif // defined(USE_AURA) | 947 #endif // defined(USE_AURA) |
936 | 948 |
937 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { | 949 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { |
| 950 SetUpForGestureBasedWheelScrolling(false); |
| 951 |
938 // Simulate wheel events. | 952 // Simulate wheel events. |
939 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly | 953 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly |
940 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued | 954 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued |
| 955 |
| 956 // Check that only the first event was sent. |
| 957 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 958 InputMsg_HandleInputEvent::ID)); |
| 959 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 960 |
| 961 // Indicate that the wheel event was unhandled. |
| 962 SendInputEventACK(WebInputEvent::MouseWheel, |
| 963 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 964 |
| 965 // Check that the correct unhandled wheel event was received. |
| 966 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 967 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
| 968 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 969 |
| 970 // Check that the second event was sent. |
| 971 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 972 InputMsg_HandleInputEvent::ID)); |
| 973 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 974 |
| 975 // Indicate that the wheel event was unhandled. |
| 976 SendInputEventACK(WebInputEvent::MouseWheel, |
| 977 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 978 |
| 979 // Check that the correct unhandled wheel event was received. |
| 980 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 981 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); |
| 982 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -10); |
| 983 } |
| 984 |
| 985 TEST_F(InputRouterImplTest, UnhandledWheelEventWithGestureScrolling) { |
| 986 SetUpForGestureBasedWheelScrolling(true); |
| 987 |
| 988 // Simulate wheel events. |
| 989 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly |
| 990 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued |
941 | 991 |
942 // Check that only the first event was sent. | 992 // Check that only the first event was sent. |
943 EXPECT_TRUE( | 993 EXPECT_TRUE( |
944 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); | 994 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); |
945 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 995 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
946 | 996 |
947 // Indicate that the wheel event was unhandled. | 997 // Indicate that the wheel event was unhandled. |
948 SendInputEventACK(WebInputEvent::MouseWheel, | 998 SendInputEventACK(WebInputEvent::MouseWheel, |
949 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 999 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
950 | 1000 |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2277 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2327 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
2278 | 2328 |
2279 const WebGestureEvent* filter_event = | 2329 const WebGestureEvent* filter_event = |
2280 GetFilterWebInputEvent<WebGestureEvent>(); | 2330 GetFilterWebInputEvent<WebGestureEvent>(); |
2281 TestLocationInFilterEvent(filter_event, orig); | 2331 TestLocationInFilterEvent(filter_event, orig); |
2282 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2332 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
2283 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2333 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
2284 } | 2334 } |
2285 | 2335 |
2286 } // namespace content | 2336 } // namespace content |
OLD | NEW |