| 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 | |
| 185 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, | 173 void SetUpForTouchAckTimeoutTest(int desktop_timeout_ms, |
| 186 int mobile_timeout_ms) { | 174 int mobile_timeout_ms) { |
| 187 config_.touch_config.desktop_touch_ack_timeout_delay = | 175 config_.touch_config.desktop_touch_ack_timeout_delay = |
| 188 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); | 176 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); |
| 189 config_.touch_config.mobile_touch_ack_timeout_delay = | 177 config_.touch_config.mobile_touch_ack_timeout_delay = |
| 190 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); | 178 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); |
| 191 config_.touch_config.touch_ack_timeout_supported = true; | 179 config_.touch_config.touch_ack_timeout_supported = true; |
| 192 TearDown(); | 180 TearDown(); |
| 193 SetUp(); | 181 SetUp(); |
| 194 input_router()->NotifySiteIsMobileOptimized(false); | 182 input_router()->NotifySiteIsMobileOptimized(false); |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 expected_events.erase(expected_events.begin(), | 928 expected_events.erase(expected_events.begin(), |
| 941 expected_events.begin() + acked.size()); | 929 expected_events.begin() + acked.size()); |
| 942 } | 930 } |
| 943 | 931 |
| 944 EXPECT_TRUE(TouchEventQueueEmpty()); | 932 EXPECT_TRUE(TouchEventQueueEmpty()); |
| 945 EXPECT_EQ(0U, expected_events.size()); | 933 EXPECT_EQ(0U, expected_events.size()); |
| 946 } | 934 } |
| 947 #endif // defined(USE_AURA) | 935 #endif // defined(USE_AURA) |
| 948 | 936 |
| 949 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { | 937 TEST_F(InputRouterImplTest, UnhandledWheelEvent) { |
| 950 SetUpForGestureBasedWheelScrolling(false); | |
| 951 | |
| 952 // Simulate wheel events. | 938 // Simulate wheel events. |
| 953 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly | 939 SimulateWheelEvent(0, 0, 0, -5, 0, false); // sent directly |
| 954 SimulateWheelEvent(0, 0, 0, -10, 0, false); // enqueued | 940 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 | |
| 991 | 941 |
| 992 // Check that only the first event was sent. | 942 // Check that only the first event was sent. |
| 993 EXPECT_TRUE( | 943 EXPECT_TRUE( |
| 994 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); | 944 process_->sink().GetUniqueMessageMatching(InputMsg_HandleInputEvent::ID)); |
| 995 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 945 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 996 | 946 |
| 997 // Indicate that the wheel event was unhandled. | 947 // Indicate that the wheel event was unhandled. |
| 998 SendInputEventACK(WebInputEvent::MouseWheel, | 948 SendInputEventACK(WebInputEvent::MouseWheel, |
| 999 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 949 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1000 | 950 |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2327 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2277 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
| 2328 | 2278 |
| 2329 const WebGestureEvent* filter_event = | 2279 const WebGestureEvent* filter_event = |
| 2330 GetFilterWebInputEvent<WebGestureEvent>(); | 2280 GetFilterWebInputEvent<WebGestureEvent>(); |
| 2331 TestLocationInFilterEvent(filter_event, orig); | 2281 TestLocationInFilterEvent(filter_event, orig); |
| 2332 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2282 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
| 2333 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2283 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
| 2334 } | 2284 } |
| 2335 | 2285 |
| 2336 } // namespace content | 2286 } // namespace content |
| OLD | NEW |