[ServiceWorker] Implement WebServiceWorkerContextClient::openWindow().
[chromium-blink-merge.git] / content / renderer / input / input_handler_proxy_unittest.cc
blobafb7c5162b31a1c8b37019fc4df245afc535378b
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
3 // found in the LICENSE file.
5 #include "content/renderer/input/input_handler_proxy.h"
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/base/swap_promise_monitor.h"
10 #include "content/common/input/did_overscroll_params.h"
11 #include "content/renderer/input/input_handler_proxy_client.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
15 #include "third_party/WebKit/public/platform/WebFloatSize.h"
16 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
17 #include "third_party/WebKit/public/platform/WebPoint.h"
18 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 #include "ui/events/latency_info.h"
21 using blink::WebActiveWheelFlingParameters;
22 using blink::WebFloatPoint;
23 using blink::WebFloatSize;
24 using blink::WebGestureDevice;
25 using blink::WebGestureEvent;
26 using blink::WebInputEvent;
27 using blink::WebKeyboardEvent;
28 using blink::WebMouseWheelEvent;
29 using blink::WebPoint;
30 using blink::WebSize;
31 using blink::WebTouchEvent;
32 using blink::WebTouchPoint;
34 namespace content {
35 namespace {
37 double InSecondsF(const base::TimeTicks& time) {
38 return (time - base::TimeTicks()).InSecondsF();
41 WebGestureEvent CreateFling(base::TimeTicks timestamp,
42 WebGestureDevice source_device,
43 WebFloatPoint velocity,
44 WebPoint point,
45 WebPoint global_point,
46 int modifiers) {
47 WebGestureEvent fling;
48 fling.type = WebInputEvent::GestureFlingStart;
49 fling.sourceDevice = source_device;
50 fling.timeStampSeconds = (timestamp - base::TimeTicks()).InSecondsF();
51 fling.data.flingStart.velocityX = velocity.x;
52 fling.data.flingStart.velocityY = velocity.y;
53 fling.x = point.x;
54 fling.y = point.y;
55 fling.globalX = global_point.x;
56 fling.globalY = global_point.y;
57 fling.modifiers = modifiers;
58 return fling;
61 WebGestureEvent CreateFling(WebGestureDevice source_device,
62 WebFloatPoint velocity,
63 WebPoint point,
64 WebPoint global_point,
65 int modifiers) {
66 return CreateFling(base::TimeTicks(),
67 source_device,
68 velocity,
69 point,
70 global_point,
71 modifiers);
74 class MockInputHandler : public cc::InputHandler {
75 public:
76 MockInputHandler() {}
77 virtual ~MockInputHandler() {}
79 MOCK_METHOD0(PinchGestureBegin, void());
80 MOCK_METHOD2(PinchGestureUpdate,
81 void(float magnify_delta, const gfx::Point& anchor));
82 MOCK_METHOD0(PinchGestureEnd, void());
84 MOCK_METHOD0(SetNeedsAnimate, void());
86 MOCK_METHOD2(ScrollBegin,
87 ScrollStatus(const gfx::Point& viewport_point,
88 cc::InputHandler::ScrollInputType type));
89 MOCK_METHOD2(ScrollAnimated,
90 ScrollStatus(const gfx::Point& viewport_point,
91 const gfx::Vector2dF& scroll_delta));
92 MOCK_METHOD2(ScrollBy,
93 cc::InputHandlerScrollResult(
94 const gfx::Point& viewport_point,
95 const gfx::Vector2dF& scroll_delta));
96 MOCK_METHOD2(ScrollVerticallyByPage,
97 bool(const gfx::Point& viewport_point,
98 cc::ScrollDirection direction));
99 MOCK_METHOD0(ScrollEnd, void());
100 MOCK_METHOD0(FlingScrollBegin, cc::InputHandler::ScrollStatus());
102 virtual scoped_ptr<cc::SwapPromiseMonitor>
103 CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency) override {
104 return scoped_ptr<cc::SwapPromiseMonitor>();
107 cc::ScrollElasticityHelper* CreateScrollElasticityHelper() override {
108 return NULL;
111 virtual void BindToClient(cc::InputHandlerClient* client) override {}
113 virtual void MouseMoveAt(const gfx::Point& mouse_position) override {}
115 MOCK_METHOD2(IsCurrentlyScrollingLayerAt,
116 bool(const gfx::Point& point,
117 cc::InputHandler::ScrollInputType type));
119 MOCK_METHOD1(HaveWheelEventHandlersAt, bool(const gfx::Point& point));
120 MOCK_METHOD1(HaveTouchEventHandlersAt, bool(const gfx::Point& point));
122 virtual void SetRootLayerScrollOffsetDelegate(
123 cc::LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate)
124 override {}
126 virtual void OnRootLayerDelegatedScrollOffsetChanged() override {}
128 DISALLOW_COPY_AND_ASSIGN(MockInputHandler);
131 // A simple WebGestureCurve implementation that flings at a constant velocity
132 // indefinitely.
133 class FakeWebGestureCurve : public blink::WebGestureCurve {
134 public:
135 FakeWebGestureCurve(const blink::WebFloatSize& velocity,
136 const blink::WebFloatSize& cumulative_scroll)
137 : velocity_(velocity), cumulative_scroll_(cumulative_scroll) {}
139 virtual ~FakeWebGestureCurve() {}
141 // Returns false if curve has finished and can no longer be applied.
142 virtual bool apply(double time, blink::WebGestureCurveTarget* target) {
143 blink::WebFloatSize displacement(velocity_.width * time,
144 velocity_.height * time);
145 blink::WebFloatSize increment(
146 displacement.width - cumulative_scroll_.width,
147 displacement.height - cumulative_scroll_.height);
148 cumulative_scroll_ = displacement;
149 // scrollBy() could delete this curve if the animation is over, so don't
150 // touch any member variables after making that call.
151 return target->scrollBy(increment, velocity_);
154 private:
155 blink::WebFloatSize velocity_;
156 blink::WebFloatSize cumulative_scroll_;
158 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve);
161 class MockInputHandlerProxyClient
162 : public content::InputHandlerProxyClient {
163 public:
164 MockInputHandlerProxyClient() {}
165 virtual ~MockInputHandlerProxyClient() {}
167 virtual void WillShutdown() override {}
169 MOCK_METHOD1(TransferActiveWheelFlingAnimation,
170 void(const WebActiveWheelFlingParameters&));
172 virtual blink::WebGestureCurve* CreateFlingAnimationCurve(
173 WebGestureDevice deviceSource,
174 const WebFloatPoint& velocity,
175 const WebSize& cumulative_scroll) override {
176 return new FakeWebGestureCurve(
177 blink::WebFloatSize(velocity.x, velocity.y),
178 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height));
181 MOCK_METHOD1(DidOverscroll, void(const DidOverscrollParams&));
182 virtual void DidStopFlinging() override {}
183 virtual void DidReceiveInputEvent(blink::WebInputEvent::Type) override {}
184 virtual void DidAnimateForInput() override {}
186 private:
187 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient);
190 class MockInputHandlerProxyClientWithDidReceiveInputEvent
191 : public MockInputHandlerProxyClient {
192 public:
193 MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
194 virtual ~MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
196 MOCK_METHOD1(DidReceiveInputEvent, void(blink::WebInputEvent::Type type));
197 MOCK_METHOD0(DidAnimateForInput, void());
199 private:
200 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClientWithDidReceiveInputEvent);
203 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x,
204 float y) {
205 WebTouchPoint point;
206 point.state = state;
207 point.screenPosition = WebFloatPoint(x, y);
208 point.position = WebFloatPoint(x, y);
209 return point;
212 class InputHandlerProxyTest : public testing::Test {
213 public:
214 InputHandlerProxyTest()
215 : expected_disposition_(InputHandlerProxy::DID_HANDLE) {
216 input_handler_.reset(
217 new content::InputHandlerProxy(&mock_input_handler_, &mock_client_));
218 scroll_result_did_scroll_.did_scroll = true;
219 scroll_result_did_not_scroll_.did_scroll = false;
222 ~InputHandlerProxyTest() {
223 input_handler_.reset();
226 // This is defined as a macro because when an expectation is not satisfied the
227 // only output you get
228 // out of gmock is the line number that set the expectation.
229 #define VERIFY_AND_RESET_MOCKS() \
230 do { \
231 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \
232 testing::Mock::VerifyAndClearExpectations(&mock_client_); \
233 } while (false)
235 void StartFling(base::TimeTicks timestamp,
236 WebGestureDevice source_device,
237 WebFloatPoint velocity,
238 WebPoint position) {
239 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
240 VERIFY_AND_RESET_MOCKS();
242 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
243 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
244 gesture_.type = WebInputEvent::GestureScrollBegin;
245 gesture_.sourceDevice = source_device;
246 EXPECT_EQ(expected_disposition_,
247 input_handler_->HandleInputEvent(gesture_));
249 VERIFY_AND_RESET_MOCKS();
251 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
252 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
253 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
255 gesture_ =
256 CreateFling(timestamp, source_device, velocity, position, position, 0);
257 EXPECT_EQ(expected_disposition_,
258 input_handler_->HandleInputEvent(gesture_));
260 VERIFY_AND_RESET_MOCKS();
263 void CancelFling(base::TimeTicks timestamp) {
264 gesture_.timeStampSeconds = InSecondsF(timestamp);
265 gesture_.type = WebInputEvent::GestureFlingCancel;
266 EXPECT_EQ(expected_disposition_,
267 input_handler_->HandleInputEvent(gesture_));
269 VERIFY_AND_RESET_MOCKS();
272 protected:
273 testing::StrictMock<MockInputHandler> mock_input_handler_;
274 scoped_ptr<content::InputHandlerProxy> input_handler_;
275 testing::StrictMock<MockInputHandlerProxyClient> mock_client_;
276 WebGestureEvent gesture_;
277 InputHandlerProxy::EventDisposition expected_disposition_;
278 cc::InputHandlerScrollResult scroll_result_did_scroll_;
279 cc::InputHandlerScrollResult scroll_result_did_not_scroll_;
282 TEST_F(InputHandlerProxyTest, MouseWheelByPageMainThread) {
283 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
284 WebMouseWheelEvent wheel;
285 wheel.type = WebInputEvent::MouseWheel;
286 wheel.scrollByPage = true;
288 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(wheel));
289 testing::Mock::VerifyAndClearExpectations(&mock_client_);
292 TEST_F(InputHandlerProxyTest, MouseWheelWithCtrlNotScroll) {
293 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
294 WebMouseWheelEvent wheel;
295 wheel.type = WebInputEvent::MouseWheel;
296 wheel.modifiers = WebInputEvent::ControlKey;
297 wheel.canScroll = false;
298 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(wheel));
299 testing::Mock::VerifyAndClearExpectations(&mock_client_);
302 TEST_F(InputHandlerProxyTest, GestureScrollStarted) {
303 // We shouldn't send any events to the widget for this gesture.
304 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
305 VERIFY_AND_RESET_MOCKS();
307 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
308 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
310 gesture_.type = WebInputEvent::GestureScrollBegin;
311 EXPECT_EQ(expected_disposition_,input_handler_->HandleInputEvent(gesture_));
313 // The event should not be marked as handled if scrolling is not possible.
314 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
315 VERIFY_AND_RESET_MOCKS();
317 gesture_.type = WebInputEvent::GestureScrollUpdate;
318 gesture_.data.scrollUpdate.deltaY =
319 -40; // -Y means scroll down - i.e. in the +Y direction.
320 EXPECT_CALL(mock_input_handler_,
321 ScrollBy(testing::_,
322 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))
323 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
324 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
326 // Mark the event as handled if scroll happens.
327 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
328 VERIFY_AND_RESET_MOCKS();
330 gesture_.type = WebInputEvent::GestureScrollUpdate;
331 gesture_.data.scrollUpdate.deltaY =
332 -40; // -Y means scroll down - i.e. in the +Y direction.
333 EXPECT_CALL(mock_input_handler_,
334 ScrollBy(testing::_,
335 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))
336 .WillOnce(testing::Return(scroll_result_did_scroll_));
337 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
339 VERIFY_AND_RESET_MOCKS();
341 gesture_.type = WebInputEvent::GestureScrollEnd;
342 gesture_.data.scrollUpdate.deltaY = 0;
343 EXPECT_CALL(mock_input_handler_, ScrollEnd());
344 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
347 TEST_F(InputHandlerProxyTest, GestureScrollOnMainThread) {
348 // We should send all events to the widget for this gesture.
349 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
350 VERIFY_AND_RESET_MOCKS();
352 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_))
353 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
355 gesture_.type = WebInputEvent::GestureScrollBegin;
356 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
358 VERIFY_AND_RESET_MOCKS();
360 gesture_.type = WebInputEvent::GestureScrollUpdate;
361 gesture_.data.scrollUpdate.deltaY = 40;
362 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
364 VERIFY_AND_RESET_MOCKS();
366 gesture_.type = WebInputEvent::GestureScrollEnd;
367 gesture_.data.scrollUpdate.deltaY = 0;
368 EXPECT_CALL(mock_input_handler_, ScrollEnd()).WillOnce(testing::Return());
369 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
372 TEST_F(InputHandlerProxyTest, GestureScrollIgnored) {
373 // We shouldn't handle the GestureScrollBegin.
374 // Instead, we should get a DROP_EVENT result, indicating
375 // that we could determine that there's nothing that could scroll or otherwise
376 // react to this gesture sequence and thus we should drop the whole gesture
377 // sequence on the floor, except for the ScrollEnd.
378 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
379 VERIFY_AND_RESET_MOCKS();
381 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
382 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored));
384 gesture_.type = WebInputEvent::GestureScrollBegin;
385 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
387 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
388 gesture_.type = WebInputEvent::GestureScrollEnd;
389 EXPECT_CALL(mock_input_handler_, ScrollEnd()).WillOnce(testing::Return());
390 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
393 TEST_F(InputHandlerProxyTest, GesturePinch) {
394 // We shouldn't send any events to the widget for this gesture.
395 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
396 VERIFY_AND_RESET_MOCKS();
398 gesture_.type = WebInputEvent::GesturePinchBegin;
399 EXPECT_CALL(mock_input_handler_, HaveWheelEventHandlersAt(testing::_))
400 .WillOnce(testing::Return(false));
401 EXPECT_CALL(mock_input_handler_, PinchGestureBegin());
402 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
404 VERIFY_AND_RESET_MOCKS();
406 gesture_.type = WebInputEvent::GesturePinchUpdate;
407 gesture_.data.pinchUpdate.scale = 1.5;
408 gesture_.x = 7;
409 gesture_.y = 13;
410 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
411 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
413 VERIFY_AND_RESET_MOCKS();
415 gesture_.type = WebInputEvent::GesturePinchUpdate;
416 gesture_.data.pinchUpdate.scale = 0.5;
417 gesture_.x = 9;
418 gesture_.y = 6;
419 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6)));
420 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
422 VERIFY_AND_RESET_MOCKS();
424 gesture_.type = WebInputEvent::GesturePinchEnd;
425 EXPECT_CALL(mock_input_handler_, PinchGestureEnd());
426 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
429 TEST_F(InputHandlerProxyTest, GesturePinchWithWheelHandler) {
430 // We will send the synthetic wheel event to the widget.
431 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
432 VERIFY_AND_RESET_MOCKS();
434 gesture_.type = WebInputEvent::GesturePinchBegin;
435 EXPECT_CALL(mock_input_handler_, HaveWheelEventHandlersAt(testing::_))
436 .WillOnce(testing::Return(true));
437 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
439 VERIFY_AND_RESET_MOCKS();
441 gesture_.type = WebInputEvent::GesturePinchUpdate;
442 gesture_.data.pinchUpdate.scale = 1.5;
443 gesture_.x = 7;
444 gesture_.y = 13;
445 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
447 VERIFY_AND_RESET_MOCKS();
449 gesture_.type = WebInputEvent::GesturePinchUpdate;
450 gesture_.data.pinchUpdate.scale = 0.5;
451 gesture_.x = 9;
452 gesture_.y = 6;
453 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
455 VERIFY_AND_RESET_MOCKS();
457 gesture_.type = WebInputEvent::GesturePinchEnd;
458 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
461 TEST_F(InputHandlerProxyTest, GesturePinchAfterScrollOnMainThread) {
462 // Scrolls will start by being sent to the main thread.
463 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
464 VERIFY_AND_RESET_MOCKS();
466 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_))
467 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
469 gesture_.type = WebInputEvent::GestureScrollBegin;
470 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
472 VERIFY_AND_RESET_MOCKS();
474 gesture_.type = WebInputEvent::GestureScrollUpdate;
475 gesture_.data.scrollUpdate.deltaY = 40;
476 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
478 // However, after the pinch gesture starts, they should go to the impl
479 // thread.
480 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
481 VERIFY_AND_RESET_MOCKS();
483 gesture_.type = WebInputEvent::GesturePinchBegin;
484 EXPECT_CALL(mock_input_handler_, HaveWheelEventHandlersAt(testing::_))
485 .WillOnce(testing::Return(false));
486 EXPECT_CALL(mock_input_handler_, PinchGestureBegin());
487 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
489 VERIFY_AND_RESET_MOCKS();
491 gesture_.type = WebInputEvent::GesturePinchUpdate;
492 gesture_.data.pinchUpdate.scale = 1.5;
493 gesture_.x = 7;
494 gesture_.y = 13;
495 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
496 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
498 VERIFY_AND_RESET_MOCKS();
500 gesture_.type = WebInputEvent::GestureScrollUpdate;
501 gesture_.data.scrollUpdate.deltaY =
502 -40; // -Y means scroll down - i.e. in the +Y direction.
503 EXPECT_CALL(mock_input_handler_,
504 ScrollBy(testing::_,
505 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))
506 .WillOnce(testing::Return(scroll_result_did_scroll_));
507 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
509 VERIFY_AND_RESET_MOCKS();
511 gesture_.type = WebInputEvent::GesturePinchUpdate;
512 gesture_.data.pinchUpdate.scale = 0.5;
513 gesture_.x = 9;
514 gesture_.y = 6;
515 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6)));
516 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
518 VERIFY_AND_RESET_MOCKS();
520 gesture_.type = WebInputEvent::GesturePinchEnd;
521 EXPECT_CALL(mock_input_handler_, PinchGestureEnd());
522 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
524 // After the pinch gesture ends, they should go to back to the main
525 // thread.
526 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
527 VERIFY_AND_RESET_MOCKS();
529 gesture_.type = WebInputEvent::GestureScrollEnd;
530 gesture_.data.scrollUpdate.deltaY = 0;
531 EXPECT_CALL(mock_input_handler_, ScrollEnd())
532 .WillOnce(testing::Return());
533 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
536 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchpad) {
537 // We shouldn't send any events to the widget for this gesture.
538 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
539 VERIFY_AND_RESET_MOCKS();
541 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
542 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
543 EXPECT_CALL(mock_input_handler_, ScrollEnd());
544 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
546 gesture_.type = WebInputEvent::GestureFlingStart;
547 gesture_.data.flingStart.velocityX = 10;
548 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
549 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
551 VERIFY_AND_RESET_MOCKS();
553 // Verify that a GestureFlingCancel during an animation cancels it.
554 gesture_.type = WebInputEvent::GestureFlingCancel;
555 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
556 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
559 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) {
560 // We should send all events to the widget for this gesture.
561 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
562 VERIFY_AND_RESET_MOCKS();
564 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
565 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
567 gesture_.type = WebInputEvent::GestureFlingStart;
568 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
569 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
571 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the
572 // input handler knows it's scrolling off the impl thread
573 ASSERT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
575 VERIFY_AND_RESET_MOCKS();
577 // Even if we didn't start a fling ourselves, we still need to send the cancel
578 // event to the widget.
579 gesture_.type = WebInputEvent::GestureFlingCancel;
580 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
581 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
584 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchpad) {
585 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
586 VERIFY_AND_RESET_MOCKS();
588 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
589 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored));
591 gesture_.type = WebInputEvent::GestureFlingStart;
592 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
593 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
595 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
596 VERIFY_AND_RESET_MOCKS();
598 // Since the previous fling was ignored, we should also be dropping the next
599 // fling_cancel.
600 gesture_.type = WebInputEvent::GestureFlingCancel;
601 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
602 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
605 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchpad) {
606 // We shouldn't send any events to the widget for this gesture.
607 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
608 VERIFY_AND_RESET_MOCKS();
610 // On the fling start, we should schedule an animation but not actually start
611 // scrolling.
612 gesture_.type = WebInputEvent::GestureFlingStart;
613 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
614 WebPoint fling_point = WebPoint(7, 13);
615 WebPoint fling_global_point = WebPoint(17, 23);
616 // Note that for trackpad, wheel events with the Control modifier are
617 // special (reserved for zoom), so don't set that here.
618 int modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
619 gesture_ = CreateFling(blink::WebGestureDeviceTouchpad,
620 fling_delta,
621 fling_point,
622 fling_global_point,
623 modifiers);
624 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
625 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
626 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
627 EXPECT_CALL(mock_input_handler_, ScrollEnd());
628 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
630 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
631 // The first animate call should let us pick up an animation start time, but
632 // we shouldn't actually move anywhere just yet. The first frame after the
633 // fling start will typically include the last scroll from the gesture that
634 // lead to the scroll (either wheel or gesture scroll), so there should be no
635 // visible hitch.
636 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
637 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
638 .Times(0);
639 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
640 input_handler_->Animate(time);
642 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
644 // The second call should start scrolling in the -X direction.
645 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
646 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
647 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
648 EXPECT_CALL(mock_input_handler_,
649 ScrollBy(testing::_,
650 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
651 .WillOnce(testing::Return(scroll_result_did_scroll_));
652 EXPECT_CALL(mock_input_handler_, ScrollEnd());
653 time += base::TimeDelta::FromMilliseconds(100);
654 input_handler_->Animate(time);
656 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
658 // Let's say on the third call we hit a non-scrollable region. We should abort
659 // the fling and not scroll.
660 // We also should pass the current fling parameters out to the client so the
661 // rest of the fling can be
662 // transferred to the main thread.
663 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
664 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
665 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
666 EXPECT_CALL(mock_input_handler_, ScrollEnd()).Times(0);
667 // Expected wheel fling animation parameters:
668 // *) fling_delta and fling_point should match the original GestureFlingStart
669 // event
670 // *) startTime should be 10 to match the time parameter of the first
671 // Animate() call after the GestureFlingStart
672 // *) cumulativeScroll depends on the curve, but since we've animated in the
673 // -X direction the X value should be < 0
674 EXPECT_CALL(
675 mock_client_,
676 TransferActiveWheelFlingAnimation(testing::AllOf(
677 testing::Field(&WebActiveWheelFlingParameters::delta,
678 testing::Eq(fling_delta)),
679 testing::Field(&WebActiveWheelFlingParameters::point,
680 testing::Eq(fling_point)),
681 testing::Field(&WebActiveWheelFlingParameters::globalPoint,
682 testing::Eq(fling_global_point)),
683 testing::Field(&WebActiveWheelFlingParameters::modifiers,
684 testing::Eq(modifiers)),
685 testing::Field(&WebActiveWheelFlingParameters::startTime,
686 testing::Eq(10)),
687 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll,
688 testing::Field(&WebSize::width, testing::Gt(0))))));
689 time += base::TimeDelta::FromMilliseconds(100);
690 input_handler_->Animate(time);
692 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
693 testing::Mock::VerifyAndClearExpectations(&mock_client_);
695 // Since we've aborted the fling, the next animation should be a no-op and
696 // should not result in another
697 // frame being requested.
698 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate()).Times(0);
699 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
700 .Times(0);
701 time += base::TimeDelta::FromMilliseconds(100);
702 input_handler_->Animate(time);
704 // Since we've transferred the fling to the main thread, we need to pass the
705 // next GestureFlingCancel to the main
706 // thread as well.
707 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
708 gesture_.type = WebInputEvent::GestureFlingCancel;
709 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
712 TEST_F(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) {
713 // We shouldn't send any events to the widget for this gesture.
714 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
715 VERIFY_AND_RESET_MOCKS();
717 // Start a gesture fling in the -X direction with zero Y movement.
718 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
719 WebPoint fling_point = WebPoint(7, 13);
720 WebPoint fling_global_point = WebPoint(17, 23);
721 // Note that for trackpad, wheel events with the Control modifier are
722 // special (reserved for zoom), so don't set that here.
723 int modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
724 gesture_ = CreateFling(blink::WebGestureDeviceTouchpad,
725 fling_delta,
726 fling_point,
727 fling_global_point,
728 modifiers);
729 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
730 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
731 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
732 EXPECT_CALL(mock_input_handler_, ScrollEnd());
733 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
735 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
737 // Start the fling animation at time 10. This shouldn't actually scroll, just
738 // establish a start time.
739 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
740 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
741 .Times(0);
742 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
743 input_handler_->Animate(time);
745 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
747 // The second call should start scrolling in the -X direction.
748 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
749 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
750 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
751 EXPECT_CALL(mock_input_handler_,
752 ScrollBy(testing::_,
753 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
754 .WillOnce(testing::Return(scroll_result_did_scroll_));
755 EXPECT_CALL(mock_input_handler_, ScrollEnd());
756 time += base::TimeDelta::FromMilliseconds(100);
757 input_handler_->Animate(time);
759 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
761 // Let's say on the third call we hit a non-scrollable region. We should abort
762 // the fling and not scroll.
763 // We also should pass the current fling parameters out to the client so the
764 // rest of the fling can be
765 // transferred to the main thread.
766 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
767 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
768 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
769 EXPECT_CALL(mock_input_handler_, ScrollEnd()).Times(0);
771 // Expected wheel fling animation parameters:
772 // *) fling_delta and fling_point should match the original GestureFlingStart
773 // event
774 // *) startTime should be 10 to match the time parameter of the first
775 // Animate() call after the GestureFlingStart
776 // *) cumulativeScroll depends on the curve, but since we've animated in the
777 // -X direction the X value should be < 0
778 EXPECT_CALL(
779 mock_client_,
780 TransferActiveWheelFlingAnimation(testing::AllOf(
781 testing::Field(&WebActiveWheelFlingParameters::delta,
782 testing::Eq(fling_delta)),
783 testing::Field(&WebActiveWheelFlingParameters::point,
784 testing::Eq(fling_point)),
785 testing::Field(&WebActiveWheelFlingParameters::globalPoint,
786 testing::Eq(fling_global_point)),
787 testing::Field(&WebActiveWheelFlingParameters::modifiers,
788 testing::Eq(modifiers)),
789 testing::Field(&WebActiveWheelFlingParameters::startTime,
790 testing::Eq(10)),
791 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll,
792 testing::Field(&WebSize::width, testing::Gt(0))))));
793 time += base::TimeDelta::FromMilliseconds(100);
794 input_handler_->Animate(time);
796 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
797 testing::Mock::VerifyAndClearExpectations(&mock_client_);
799 // Since we've aborted the fling, the next animation should be a no-op and
800 // should not result in another
801 // frame being requested.
802 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate()).Times(0);
803 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
804 .Times(0);
805 time += base::TimeDelta::FromMilliseconds(100);
806 input_handler_->Animate(time);
808 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
810 // Since we've transferred the fling to the main thread, we need to pass the
811 // next GestureFlingCancel to the main
812 // thread as well.
813 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
814 gesture_.type = WebInputEvent::GestureFlingCancel;
815 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
817 VERIFY_AND_RESET_MOCKS();
818 input_handler_->MainThreadHasStoppedFlinging();
820 // Start a second gesture fling, this time in the +Y direction with no X.
821 fling_delta = WebFloatPoint(0, -1000);
822 fling_point = WebPoint(95, 87);
823 fling_global_point = WebPoint(32, 71);
824 modifiers = WebInputEvent::AltKey;
825 gesture_ = CreateFling(blink::WebGestureDeviceTouchpad,
826 fling_delta,
827 fling_point,
828 fling_global_point,
829 modifiers);
830 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
831 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
832 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
833 EXPECT_CALL(mock_input_handler_, ScrollEnd());
834 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
835 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
837 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
839 // Start the second fling animation at time 30.
840 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
841 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
842 .Times(0);
843 time = base::TimeTicks() + base::TimeDelta::FromSeconds(30);
844 input_handler_->Animate(time);
846 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
848 // Tick the second fling once normally.
849 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
850 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
851 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
852 EXPECT_CALL(mock_input_handler_,
853 ScrollBy(testing::_,
854 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))
855 .WillOnce(testing::Return(scroll_result_did_scroll_));
856 EXPECT_CALL(mock_input_handler_, ScrollEnd());
857 time += base::TimeDelta::FromMilliseconds(100);
858 input_handler_->Animate(time);
860 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
862 // Then abort the second fling.
863 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
864 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
865 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
866 EXPECT_CALL(mock_input_handler_, ScrollEnd()).Times(0);
868 // We should get parameters from the second fling, nothing from the first
869 // fling should "leak".
870 EXPECT_CALL(
871 mock_client_,
872 TransferActiveWheelFlingAnimation(testing::AllOf(
873 testing::Field(&WebActiveWheelFlingParameters::delta,
874 testing::Eq(fling_delta)),
875 testing::Field(&WebActiveWheelFlingParameters::point,
876 testing::Eq(fling_point)),
877 testing::Field(&WebActiveWheelFlingParameters::globalPoint,
878 testing::Eq(fling_global_point)),
879 testing::Field(&WebActiveWheelFlingParameters::modifiers,
880 testing::Eq(modifiers)),
881 testing::Field(&WebActiveWheelFlingParameters::startTime,
882 testing::Eq(30)),
883 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll,
884 testing::Field(&WebSize::height, testing::Lt(0))))));
885 time += base::TimeDelta::FromMilliseconds(100);
886 input_handler_->Animate(time);
889 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchscreen) {
890 // We shouldn't send any events to the widget for this gesture.
891 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
892 VERIFY_AND_RESET_MOCKS();
894 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
895 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
896 gesture_.type = WebInputEvent::GestureScrollBegin;
897 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
898 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
900 VERIFY_AND_RESET_MOCKS();
902 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
903 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
904 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
906 gesture_.type = WebInputEvent::GestureFlingStart;
907 gesture_.data.flingStart.velocityX = 10;
908 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
909 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
911 VERIFY_AND_RESET_MOCKS();
913 EXPECT_CALL(mock_input_handler_, ScrollEnd());
915 // Verify that a GestureFlingCancel during an animation cancels it.
916 gesture_.type = WebInputEvent::GestureFlingCancel;
917 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
918 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
921 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchscreen) {
922 // We should send all events to the widget for this gesture.
923 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
924 VERIFY_AND_RESET_MOCKS();
926 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
927 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread));
929 gesture_.type = WebInputEvent::GestureScrollBegin;
930 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
932 VERIFY_AND_RESET_MOCKS();
934 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()).Times(0);
936 gesture_.type = WebInputEvent::GestureFlingStart;
937 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
938 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
940 VERIFY_AND_RESET_MOCKS();
942 // Even if we didn't start a fling ourselves, we still need to send the cancel
943 // event to the widget.
944 gesture_.type = WebInputEvent::GestureFlingCancel;
945 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
946 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
949 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchscreen) {
950 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
951 VERIFY_AND_RESET_MOCKS();
953 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
954 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
956 gesture_.type = WebInputEvent::GestureScrollBegin;
957 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
958 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
960 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
961 VERIFY_AND_RESET_MOCKS();
963 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
964 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored));
966 gesture_.type = WebInputEvent::GestureFlingStart;
967 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
968 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
970 VERIFY_AND_RESET_MOCKS();
972 // Even if we didn't start a fling ourselves, we still need to send the cancel
973 // event to the widget.
974 gesture_.type = WebInputEvent::GestureFlingCancel;
975 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
976 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
979 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchscreen) {
980 // We shouldn't send any events to the widget for this gesture.
981 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
982 VERIFY_AND_RESET_MOCKS();
984 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
985 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
987 gesture_.type = WebInputEvent::GestureScrollBegin;
988 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
989 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
991 VERIFY_AND_RESET_MOCKS();
993 // On the fling start, we should schedule an animation but not actually start
994 // scrolling.
995 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
996 WebPoint fling_point = WebPoint(7, 13);
997 WebPoint fling_global_point = WebPoint(17, 23);
998 // Note that for touchscreen the control modifier is not special.
999 int modifiers = WebInputEvent::ControlKey;
1000 gesture_ = CreateFling(blink::WebGestureDeviceTouchscreen,
1001 fling_delta,
1002 fling_point,
1003 fling_global_point,
1004 modifiers);
1005 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1006 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1007 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1008 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1010 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1011 // The first animate call should let us pick up an animation start time, but
1012 // we shouldn't actually move anywhere just yet. The first frame after the
1013 // fling start will typically include the last scroll from the gesture that
1014 // lead to the scroll (either wheel or gesture scroll), so there should be no
1015 // visible hitch.
1016 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1017 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1018 input_handler_->Animate(time);
1020 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1022 // The second call should start scrolling in the -X direction.
1023 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1024 EXPECT_CALL(mock_input_handler_,
1025 ScrollBy(testing::_,
1026 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1027 .WillOnce(testing::Return(scroll_result_did_scroll_));
1028 time += base::TimeDelta::FromMilliseconds(100);
1029 input_handler_->Animate(time);
1031 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1033 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1034 gesture_.type = WebInputEvent::GestureFlingCancel;
1035 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1038 TEST_F(InputHandlerProxyTest, GestureFlingWithValidTimestamp) {
1039 // We shouldn't send any events to the widget for this gesture.
1040 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1041 VERIFY_AND_RESET_MOCKS();
1043 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1044 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1046 gesture_.type = WebInputEvent::GestureScrollBegin;
1047 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1048 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1050 VERIFY_AND_RESET_MOCKS();
1052 // On the fling start, we should schedule an animation but not actually start
1053 // scrolling.
1054 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1055 base::TimeTicks time = base::TimeTicks() + dt;
1056 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1057 WebPoint fling_point = WebPoint(7, 13);
1058 WebPoint fling_global_point = WebPoint(17, 23);
1059 int modifiers = WebInputEvent::ControlKey;
1060 gesture_ = CreateFling(time,
1061 blink::WebGestureDeviceTouchscreen,
1062 fling_delta,
1063 fling_point,
1064 fling_global_point,
1065 modifiers);
1066 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1067 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1068 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1069 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1071 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1072 // With a valid time stamp, the first animate call should skip start time
1073 // initialization and immediately begin scroll update production. This reduces
1074 // the likelihood of a hitch between the scroll preceding the fling and
1075 // the first scroll generated by the fling.
1076 // Scrolling should start in the -X direction.
1077 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1078 EXPECT_CALL(mock_input_handler_,
1079 ScrollBy(testing::_,
1080 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1081 .WillOnce(testing::Return(scroll_result_did_scroll_));
1082 time += dt;
1083 input_handler_->Animate(time);
1085 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1087 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1088 gesture_.type = WebInputEvent::GestureFlingCancel;
1089 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1092 TEST_F(InputHandlerProxyTest, GestureFlingWithInvalidTimestamp) {
1093 // We shouldn't send any events to the widget for this gesture.
1094 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1095 VERIFY_AND_RESET_MOCKS();
1097 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1098 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1100 gesture_.type = WebInputEvent::GestureScrollBegin;
1101 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1102 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1104 VERIFY_AND_RESET_MOCKS();
1106 // On the fling start, we should schedule an animation but not actually start
1107 // scrolling.
1108 base::TimeDelta start_time_offset = base::TimeDelta::FromMilliseconds(10);
1109 gesture_.type = WebInputEvent::GestureFlingStart;
1110 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1111 WebPoint fling_point = WebPoint(7, 13);
1112 WebPoint fling_global_point = WebPoint(17, 23);
1113 int modifiers = WebInputEvent::ControlKey;
1114 gesture_.timeStampSeconds = start_time_offset.InSecondsF();
1115 gesture_.data.flingStart.velocityX = fling_delta.x;
1116 gesture_.data.flingStart.velocityY = fling_delta.y;
1117 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1118 gesture_.x = fling_point.x;
1119 gesture_.y = fling_point.y;
1120 gesture_.globalX = fling_global_point.x;
1121 gesture_.globalY = fling_global_point.y;
1122 gesture_.modifiers = modifiers;
1123 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1124 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1125 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1126 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1128 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1129 // Event though a time stamp was provided for the fling event, it will be
1130 // ignored as its too far in the past relative to the first animate call's
1131 // timestamp.
1132 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1133 base::TimeTicks time =
1134 base::TimeTicks() + start_time_offset + base::TimeDelta::FromSeconds(1);
1135 input_handler_->Animate(time);
1137 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1139 // Further animation ticks should update the fling as usual.
1140 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1141 EXPECT_CALL(mock_input_handler_,
1142 ScrollBy(testing::_,
1143 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1144 .WillOnce(testing::Return(scroll_result_did_scroll_));
1145 time += base::TimeDelta::FromMilliseconds(10);
1146 input_handler_->Animate(time);
1148 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1150 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1151 gesture_.type = WebInputEvent::GestureFlingCancel;
1152 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1155 TEST_F(InputHandlerProxyTest,
1156 GestureScrollOnImplThreadFlagClearedAfterFling) {
1157 // We shouldn't send any events to the widget for this gesture.
1158 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1159 VERIFY_AND_RESET_MOCKS();
1161 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1162 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1164 gesture_.type = WebInputEvent::GestureScrollBegin;
1165 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1167 // After sending a GestureScrollBegin, the member variable
1168 // |gesture_scroll_on_impl_thread_| should be true.
1169 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1171 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1172 VERIFY_AND_RESET_MOCKS();
1174 // On the fling start, we should schedule an animation but not actually start
1175 // scrolling.
1176 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1177 WebPoint fling_point = WebPoint(7, 13);
1178 WebPoint fling_global_point = WebPoint(17, 23);
1179 int modifiers = WebInputEvent::ControlKey | WebInputEvent::AltKey;
1180 gesture_ = CreateFling(blink::WebGestureDeviceTouchscreen,
1181 fling_delta,
1182 fling_point,
1183 fling_global_point,
1184 modifiers);
1185 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1186 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1187 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1188 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1190 // |gesture_scroll_on_impl_thread_| should still be true after
1191 // a GestureFlingStart is sent.
1192 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1194 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1195 // The first animate call should let us pick up an animation start time, but
1196 // we shouldn't actually move anywhere just yet. The first frame after the
1197 // fling start will typically include the last scroll from the gesture that
1198 // lead to the scroll (either wheel or gesture scroll), so there should be no
1199 // visible hitch.
1200 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1201 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1202 input_handler_->Animate(time);
1204 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1206 // The second call should start scrolling in the -X direction.
1207 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1208 EXPECT_CALL(mock_input_handler_,
1209 ScrollBy(testing::_,
1210 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1211 .WillOnce(testing::Return(scroll_result_did_scroll_));
1212 time += base::TimeDelta::FromMilliseconds(100);
1213 input_handler_->Animate(time);
1215 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1217 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1218 gesture_.type = WebInputEvent::GestureFlingCancel;
1219 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1221 // |gesture_scroll_on_impl_thread_| should be false once
1222 // the fling has finished (note no GestureScrollEnd has been sent).
1223 EXPECT_TRUE(!input_handler_->gesture_scroll_on_impl_thread_for_testing());
1226 TEST_F(InputHandlerProxyTest, GestureFlingStopsAtContentEdge) {
1227 // We shouldn't send any events to the widget for this gesture.
1228 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1229 VERIFY_AND_RESET_MOCKS();
1231 // On the fling start, we should schedule an animation but not actually start
1232 // scrolling.
1233 gesture_.type = WebInputEvent::GestureFlingStart;
1234 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1235 gesture_.data.flingStart.velocityX = fling_delta.x;
1236 gesture_.data.flingStart.velocityY = fling_delta.y;
1237 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1238 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1239 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1240 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1241 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1242 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1244 // The first animate doesn't cause any scrolling.
1245 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1246 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1247 input_handler_->Animate(time);
1248 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1250 // The second animate starts scrolling in the positive X and Y directions.
1251 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1252 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1253 EXPECT_CALL(mock_input_handler_,
1254 ScrollBy(testing::_,
1255 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1256 .WillOnce(testing::Return(scroll_result_did_scroll_));
1257 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1258 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1259 time += base::TimeDelta::FromMilliseconds(100);
1260 input_handler_->Animate(time);
1261 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1263 // The third animate overscrolls in the positive Y direction but scrolls
1264 // somewhat.
1265 cc::InputHandlerScrollResult overscroll;
1266 overscroll.did_scroll = true;
1267 overscroll.did_overscroll_root = true;
1268 overscroll.accumulated_root_overscroll = gfx::Vector2dF(0, 100);
1269 overscroll.unused_scroll_delta = gfx::Vector2dF(0, 10);
1270 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1271 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1272 EXPECT_CALL(mock_input_handler_,
1273 ScrollBy(testing::_,
1274 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1275 .WillOnce(testing::Return(overscroll));
1276 EXPECT_CALL(
1277 mock_client_,
1278 DidOverscroll(testing::AllOf(
1279 testing::Field(
1280 &DidOverscrollParams::accumulated_overscroll,
1281 testing::Eq(overscroll.accumulated_root_overscroll)),
1282 testing::Field(
1283 &DidOverscrollParams::latest_overscroll_delta,
1284 testing::Eq(overscroll.unused_scroll_delta)),
1285 testing::Field(
1286 &DidOverscrollParams::current_fling_velocity,
1287 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))));
1288 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1289 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1290 time += base::TimeDelta::FromMilliseconds(100);
1291 input_handler_->Animate(time);
1292 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1294 // The next call to animate will no longer scroll vertically.
1295 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1296 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1297 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1298 EXPECT_CALL(mock_input_handler_,
1299 ScrollBy(testing::_,
1300 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1301 .WillOnce(testing::Return(scroll_result_did_scroll_));
1302 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1303 time += base::TimeDelta::FromMilliseconds(100);
1304 input_handler_->Animate(time);
1305 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1308 TEST_F(InputHandlerProxyTest, GestureFlingNotCancelledBySmallTimeDelta) {
1309 // We shouldn't send any events to the widget for this gesture.
1310 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1311 VERIFY_AND_RESET_MOCKS();
1313 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1314 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1316 gesture_.type = WebInputEvent::GestureScrollBegin;
1317 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1318 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1320 VERIFY_AND_RESET_MOCKS();
1322 // On the fling start, we should schedule an animation but not actually start
1323 // scrolling.
1324 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1325 base::TimeTicks time = base::TimeTicks() + dt;
1326 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1327 WebPoint fling_point = WebPoint(7, 13);
1328 WebPoint fling_global_point = WebPoint(17, 23);
1329 int modifiers = WebInputEvent::ControlKey;
1330 gesture_ = CreateFling(time,
1331 blink::WebGestureDeviceTouchscreen,
1332 fling_delta,
1333 fling_point,
1334 fling_global_point,
1335 modifiers);
1336 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1337 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1338 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1339 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1341 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1342 // With an animation timestamp equivalent to the starting timestamp, the
1343 // animation will simply be rescheduled.
1344 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1345 input_handler_->Animate(time);
1347 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1348 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1350 // A small time delta should not stop the fling, even if the client
1351 // reports no scrolling.
1352 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1353 EXPECT_CALL(mock_input_handler_,
1354 ScrollBy(testing::_,
1355 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1356 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1357 time += base::TimeDelta::FromMicroseconds(5);
1358 input_handler_->Animate(time);
1360 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1361 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1363 // A time delta of zero should not stop the fling, and neither should it
1364 // trigger scrolling on the client.
1365 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1366 input_handler_->Animate(time);
1368 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1369 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1371 // Lack of movement on the client, with a non-trivial scroll delta, should
1372 // terminate the fling.
1373 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1374 EXPECT_CALL(mock_input_handler_,
1375 ScrollBy(testing::_,
1376 testing::Property(&gfx::Vector2dF::x, testing::Lt(1))))
1377 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1378 time += base::TimeDelta::FromMilliseconds(100);
1379 input_handler_->Animate(time);
1381 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1382 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1385 TEST_F(InputHandlerProxyTest, GestureFlingCancelledAfterBothAxesStopScrolling) {
1386 cc::InputHandlerScrollResult overscroll;
1387 overscroll.did_scroll = true;
1388 overscroll.did_overscroll_root = true;
1390 // We shouldn't send any events to the widget for this gesture.
1391 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1392 VERIFY_AND_RESET_MOCKS();
1394 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1395 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1396 gesture_.type = WebInputEvent::GestureScrollBegin;
1397 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1398 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1399 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1401 // On the fling start, we should schedule an animation but not actually start
1402 // scrolling.
1403 gesture_.type = WebInputEvent::GestureFlingStart;
1404 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1405 gesture_.data.flingStart.velocityX = fling_delta.x;
1406 gesture_.data.flingStart.velocityY = fling_delta.y;
1407 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1408 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1409 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1410 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1411 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1413 // The first animate doesn't cause any scrolling.
1414 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1415 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1416 input_handler_->Animate(time);
1417 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1419 // The second animate starts scrolling in the positive X and Y directions.
1420 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1421 EXPECT_CALL(mock_input_handler_,
1422 ScrollBy(testing::_,
1423 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1424 .WillOnce(testing::Return(scroll_result_did_scroll_));
1425 time += base::TimeDelta::FromMilliseconds(10);
1426 input_handler_->Animate(time);
1427 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1429 // The third animate hits the bottom content edge.
1430 overscroll.accumulated_root_overscroll = gfx::Vector2dF(0, 100);
1431 overscroll.unused_scroll_delta = gfx::Vector2dF(0, 100);
1432 EXPECT_CALL(mock_input_handler_,
1433 ScrollBy(testing::_,
1434 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1435 .WillOnce(testing::Return(overscroll));
1436 EXPECT_CALL(
1437 mock_client_,
1438 DidOverscroll(testing::AllOf(
1439 testing::Field(
1440 &DidOverscrollParams::accumulated_overscroll,
1441 testing::Eq(overscroll.accumulated_root_overscroll)),
1442 testing::Field(
1443 &DidOverscrollParams::latest_overscroll_delta,
1444 testing::Eq(overscroll.unused_scroll_delta)),
1445 testing::Field(
1446 &DidOverscrollParams::current_fling_velocity,
1447 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))));
1448 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1449 time += base::TimeDelta::FromMilliseconds(10);
1450 input_handler_->Animate(time);
1451 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1453 // The next call to animate will no longer scroll vertically.
1454 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1455 EXPECT_CALL(mock_input_handler_,
1456 ScrollBy(testing::_,
1457 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1458 .WillOnce(testing::Return(scroll_result_did_scroll_));
1459 time += base::TimeDelta::FromMilliseconds(10);
1460 input_handler_->Animate(time);
1461 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1463 // The next call will hit the right edge.
1464 overscroll.accumulated_root_overscroll = gfx::Vector2dF(100, 100);
1465 overscroll.unused_scroll_delta = gfx::Vector2dF(100, 0);
1466 EXPECT_CALL(mock_input_handler_,
1467 ScrollBy(testing::_,
1468 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1469 .WillOnce(testing::Return(overscroll));
1470 EXPECT_CALL(
1471 mock_client_,
1472 DidOverscroll(testing::AllOf(
1473 testing::Field(
1474 &DidOverscrollParams::accumulated_overscroll,
1475 testing::Eq(overscroll.accumulated_root_overscroll)),
1476 testing::Field(
1477 &DidOverscrollParams::latest_overscroll_delta,
1478 testing::Eq(overscroll.unused_scroll_delta)),
1479 testing::Field(
1480 &DidOverscrollParams::current_fling_velocity,
1481 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))));
1482 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1483 time += base::TimeDelta::FromMilliseconds(10);
1484 input_handler_->Animate(time);
1485 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1487 // The next call to animate will no longer scroll horizontally or vertically,
1488 // and the fling should be cancelled.
1489 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate()).Times(0);
1490 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
1491 time += base::TimeDelta::FromMilliseconds(10);
1492 input_handler_->Animate(time);
1493 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1494 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1497 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestNegative) {
1498 // None of the three touch points fall in the touch region. So the event
1499 // should be dropped.
1500 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
1501 VERIFY_AND_RESET_MOCKS();
1503 EXPECT_CALL(mock_input_handler_,
1504 HaveTouchEventHandlersAt(
1505 testing::Property(&gfx::Point::x, testing::Gt(0))))
1506 .WillOnce(testing::Return(false));
1507 EXPECT_CALL(mock_input_handler_,
1508 HaveTouchEventHandlersAt(
1509 testing::Property(&gfx::Point::x, testing::Lt(0))))
1510 .WillOnce(testing::Return(false));
1512 WebTouchEvent touch;
1513 touch.type = WebInputEvent::TouchStart;
1515 touch.touchesLength = 3;
1516 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary, 0, 0);
1517 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10);
1518 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10);
1519 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch));
1522 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestPositive) {
1523 // One of the touch points is on a touch-region. So the event should be sent
1524 // to the main thread.
1525 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
1526 VERIFY_AND_RESET_MOCKS();
1528 EXPECT_CALL(mock_input_handler_,
1529 HaveTouchEventHandlersAt(
1530 testing::Property(&gfx::Point::x, testing::Eq(0))))
1531 .WillOnce(testing::Return(false));
1532 EXPECT_CALL(mock_input_handler_,
1533 HaveTouchEventHandlersAt(
1534 testing::Property(&gfx::Point::x, testing::Gt(0))))
1535 .WillOnce(testing::Return(true));
1536 // Since the second touch point hits a touch-region, there should be no
1537 // hit-testing for the third touch point.
1539 WebTouchEvent touch;
1540 touch.type = WebInputEvent::TouchStart;
1542 touch.touchesLength = 3;
1543 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0);
1544 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10);
1545 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10);
1546 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch));
1549 TEST_F(InputHandlerProxyTest, GestureFlingCancelledByKeyboardEvent) {
1550 // We shouldn't send any events to the widget for this gesture.
1551 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1552 VERIFY_AND_RESET_MOCKS();
1554 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1555 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1556 gesture_.type = WebInputEvent::GestureScrollBegin;
1557 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1558 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1559 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1560 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1562 // Keyboard events received during a scroll should have no effect.
1563 WebKeyboardEvent key_event;
1564 key_event.type = WebInputEvent::KeyDown;
1565 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
1566 input_handler_->HandleInputEvent(key_event));
1567 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1568 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1570 // On the fling start, animation should be scheduled, but no scrolling occurs.
1571 gesture_.type = WebInputEvent::GestureFlingStart;
1572 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1573 gesture_.data.flingStart.velocityX = fling_delta.x;
1574 gesture_.data.flingStart.velocityY = fling_delta.y;
1575 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1576 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1577 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1578 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1579 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1580 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1582 // Keyboard events received during a fling should cancel the active fling.
1583 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1584 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
1585 input_handler_->HandleInputEvent(key_event));
1586 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1587 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1589 // The call to animate should have no effect, as the fling was cancelled.
1590 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1591 input_handler_->Animate(time);
1592 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1594 // A fling cancel should be dropped, as there is nothing to cancel.
1595 gesture_.type = WebInputEvent::GestureFlingCancel;
1596 EXPECT_EQ(InputHandlerProxy::DROP_EVENT,
1597 input_handler_->HandleInputEvent(gesture_));
1598 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1601 TEST_F(InputHandlerProxyTest, GestureFlingWithNegativeTimeDelta) {
1602 // We shouldn't send any events to the widget for this gesture.
1603 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1604 VERIFY_AND_RESET_MOCKS();
1606 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1607 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1609 gesture_.type = WebInputEvent::GestureScrollBegin;
1610 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1611 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1613 VERIFY_AND_RESET_MOCKS();
1615 // On the fling start, we should schedule an animation but not actually start
1616 // scrolling.
1617 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1618 base::TimeTicks time = base::TimeTicks() + dt;
1619 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1620 WebPoint fling_point = WebPoint(7, 13);
1621 WebPoint fling_global_point = WebPoint(17, 23);
1622 int modifiers = WebInputEvent::ControlKey;
1623 gesture_ = CreateFling(time,
1624 blink::WebGestureDeviceTouchscreen,
1625 fling_delta,
1626 fling_point,
1627 fling_global_point,
1628 modifiers);
1629 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1630 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1631 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1632 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1634 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1636 // If we get a negative time delta, that is, the Animation tick time happens
1637 // before the fling's start time then we should *not* try scrolling and
1638 // instead reset the fling start time.
1639 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1640 EXPECT_CALL(mock_input_handler_,
1641 ScrollBy(testing::_,
1642 testing::_)).Times(0);
1643 time -= base::TimeDelta::FromMilliseconds(5);
1644 input_handler_->Animate(time);
1646 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1648 // The first call should have reset the start time so subsequent calls should
1649 // generate scroll events.
1650 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1651 EXPECT_CALL(mock_input_handler_,
1652 ScrollBy(testing::_,
1653 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1654 .WillOnce(testing::Return(scroll_result_did_scroll_));
1656 input_handler_->Animate(time + base::TimeDelta::FromMilliseconds(1));
1658 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1660 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1661 gesture_.type = WebInputEvent::GestureFlingCancel;
1662 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1665 TEST_F(InputHandlerProxyTest, FlingBoost) {
1666 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1667 base::TimeTicks time = base::TimeTicks() + dt;
1668 base::TimeTicks last_animate_time = time;
1669 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1670 WebPoint fling_point = WebPoint(7, 13);
1671 StartFling(
1672 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1674 // Now cancel the fling. The fling cancellation should be deferred to allow
1675 // fling boosting events to arrive.
1676 time += dt;
1677 CancelFling(time);
1679 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1680 // scrolling layer.
1681 EXPECT_CALL(mock_input_handler_,
1682 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1683 .WillOnce(testing::Return(true));
1685 time += dt;
1686 gesture_.timeStampSeconds = InSecondsF(time);
1687 gesture_.type = WebInputEvent::GestureScrollBegin;
1688 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1690 VERIFY_AND_RESET_MOCKS();
1692 // Animate calls within the deferred cancellation window should continue.
1693 time += dt;
1694 float expected_delta =
1695 (time - last_animate_time).InSecondsF() * -fling_delta.x;
1696 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1697 EXPECT_CALL(mock_input_handler_,
1698 ScrollBy(testing::_,
1699 testing::Property(&gfx::Vector2dF::x,
1700 testing::Eq(expected_delta))))
1701 .WillOnce(testing::Return(scroll_result_did_scroll_));
1702 input_handler_->Animate(time);
1703 last_animate_time = time;
1705 VERIFY_AND_RESET_MOCKS();
1707 // GestureScrollUpdates in the same direction and at sufficient speed should
1708 // be swallowed by the fling.
1709 time += dt;
1710 gesture_.timeStampSeconds = InSecondsF(time);
1711 gesture_.type = WebInputEvent::GestureScrollUpdate;
1712 gesture_.data.scrollUpdate.deltaX = fling_delta.x;
1713 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1715 VERIFY_AND_RESET_MOCKS();
1717 // Animate calls within the deferred cancellation window should continue.
1718 time += dt;
1719 expected_delta = (time - last_animate_time).InSecondsF() * -fling_delta.x;
1720 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1721 EXPECT_CALL(mock_input_handler_,
1722 ScrollBy(testing::_,
1723 testing::Property(&gfx::Vector2dF::x,
1724 testing::Eq(expected_delta))))
1725 .WillOnce(testing::Return(scroll_result_did_scroll_));
1726 input_handler_->Animate(time);
1727 last_animate_time = time;
1729 VERIFY_AND_RESET_MOCKS();
1731 // GestureFlingStart in the same direction and at sufficient speed should
1732 // boost the active fling.
1734 gesture_ = CreateFling(time,
1735 blink::WebGestureDeviceTouchscreen,
1736 fling_delta,
1737 fling_point,
1738 fling_point,
1740 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1741 VERIFY_AND_RESET_MOCKS();
1743 time += dt;
1744 // Note we get *2x* as much delta because 2 flings have combined.
1745 expected_delta = 2 * (time - last_animate_time).InSecondsF() * -fling_delta.x;
1746 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1747 EXPECT_CALL(mock_input_handler_,
1748 ScrollBy(testing::_,
1749 testing::Property(&gfx::Vector2dF::x,
1750 testing::Eq(expected_delta))))
1751 .WillOnce(testing::Return(scroll_result_did_scroll_));
1752 input_handler_->Animate(time);
1753 last_animate_time = time;
1755 VERIFY_AND_RESET_MOCKS();
1757 // Repeated GestureFlingStarts should accumulate.
1759 CancelFling(time);
1760 gesture_ = CreateFling(time,
1761 blink::WebGestureDeviceTouchscreen,
1762 fling_delta,
1763 fling_point,
1764 fling_point,
1766 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1767 VERIFY_AND_RESET_MOCKS();
1769 time += dt;
1770 // Note we get *3x* as much delta because 3 flings have combined.
1771 expected_delta = 3 * (time - last_animate_time).InSecondsF() * -fling_delta.x;
1772 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1773 EXPECT_CALL(mock_input_handler_,
1774 ScrollBy(testing::_,
1775 testing::Property(&gfx::Vector2dF::x,
1776 testing::Eq(expected_delta))))
1777 .WillOnce(testing::Return(scroll_result_did_scroll_));
1778 input_handler_->Animate(time);
1779 last_animate_time = time;
1781 VERIFY_AND_RESET_MOCKS();
1783 // GestureFlingCancel should terminate the fling if no boosting gestures are
1784 // received within the timeout window.
1786 time += dt;
1787 gesture_.timeStampSeconds = InSecondsF(time);
1788 gesture_.type = WebInputEvent::GestureFlingCancel;
1789 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1791 VERIFY_AND_RESET_MOCKS();
1793 time += base::TimeDelta::FromMilliseconds(100);
1794 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1795 input_handler_->Animate(time);
1797 VERIFY_AND_RESET_MOCKS();
1800 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollTargetsDifferentLayer) {
1801 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1802 base::TimeTicks time = base::TimeTicks() + dt;
1803 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1804 WebPoint fling_point = WebPoint(7, 13);
1805 StartFling(
1806 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1808 // Cancel the fling. The fling cancellation should be deferred to allow
1809 // fling boosting events to arrive.
1810 time += dt;
1811 CancelFling(time);
1813 // If the GestureScrollBegin targets a different layer, the fling should be
1814 // cancelled and the scroll should be handled as usual.
1815 EXPECT_CALL(mock_input_handler_,
1816 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1817 .WillOnce(testing::Return(false));
1818 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1819 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1820 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1822 time += dt;
1823 gesture_.timeStampSeconds = InSecondsF(time);
1824 gesture_.type = WebInputEvent::GestureScrollBegin;
1825 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1827 VERIFY_AND_RESET_MOCKS();
1830 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollDelayed) {
1831 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1832 base::TimeTicks time = base::TimeTicks() + dt;
1833 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1834 WebPoint fling_point = WebPoint(7, 13);
1835 StartFling(
1836 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1838 // Cancel the fling. The fling cancellation should be deferred to allow
1839 // fling boosting events to arrive.
1840 time += dt;
1841 CancelFling(time);
1843 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1844 // scrolling layer.
1845 EXPECT_CALL(mock_input_handler_,
1846 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1847 .WillOnce(testing::Return(true));
1849 time += dt;
1850 gesture_.timeStampSeconds = InSecondsF(time);
1851 gesture_.type = WebInputEvent::GestureScrollBegin;
1852 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1854 VERIFY_AND_RESET_MOCKS();
1856 // If no GestureScrollUpdate or GestureFlingStart is received within the
1857 // timeout window, the fling should be cancelled and scrolling should resume.
1858 time += base::TimeDelta::FromMilliseconds(100);
1859 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1860 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1861 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1862 input_handler_->Animate(time);
1864 VERIFY_AND_RESET_MOCKS();
1867 TEST_F(InputHandlerProxyTest, NoFlingBoostIfFlingInDifferentDirection) {
1868 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1869 base::TimeTicks time = base::TimeTicks() + dt;
1870 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1871 WebPoint fling_point = WebPoint(7, 13);
1872 StartFling(
1873 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1875 // Cancel the fling. The fling cancellation should be deferred to allow
1876 // fling boosting events to arrive.
1877 time += dt;
1878 CancelFling(time);
1880 // If the new fling is orthogonal to the existing fling, no boosting should
1881 // take place, with the new fling replacing the old.
1882 WebFloatPoint orthogonal_fling_delta =
1883 WebFloatPoint(fling_delta.y, -fling_delta.x);
1884 gesture_ = CreateFling(time,
1885 blink::WebGestureDeviceTouchscreen,
1886 orthogonal_fling_delta,
1887 fling_point,
1888 fling_point,
1890 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1892 VERIFY_AND_RESET_MOCKS();
1894 // Note that the new fling delta uses the orthogonal, unboosted fling
1895 // velocity.
1896 time += dt;
1897 float expected_delta = dt.InSecondsF() * -orthogonal_fling_delta.y;
1898 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1899 EXPECT_CALL(mock_input_handler_,
1900 ScrollBy(testing::_,
1901 testing::Property(&gfx::Vector2dF::y,
1902 testing::Eq(expected_delta))))
1903 .WillOnce(testing::Return(scroll_result_did_scroll_));
1904 input_handler_->Animate(time);
1906 VERIFY_AND_RESET_MOCKS();
1909 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollInDifferentDirection) {
1910 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1911 base::TimeTicks time = base::TimeTicks() + dt;
1912 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1913 WebPoint fling_point = WebPoint(7, 13);
1914 StartFling(
1915 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1917 // Cancel the fling. The fling cancellation should be deferred to allow
1918 // fling boosting events to arrive.
1919 time += dt;
1920 CancelFling(time);
1922 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1923 // scrolling layer.
1924 EXPECT_CALL(mock_input_handler_,
1925 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1926 .WillOnce(testing::Return(true));
1928 time += dt;
1929 gesture_.timeStampSeconds = InSecondsF(time);
1930 gesture_.type = WebInputEvent::GestureScrollBegin;
1931 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1933 VERIFY_AND_RESET_MOCKS();
1935 // If the GestureScrollUpdate is in a different direction than the fling,
1936 // the fling should be cancelled and scrolling should resume.
1937 time += dt;
1938 gesture_.timeStampSeconds = InSecondsF(time);
1939 gesture_.type = WebInputEvent::GestureScrollUpdate;
1940 gesture_.data.scrollUpdate.deltaX = -fling_delta.x;
1941 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1942 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1943 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1944 EXPECT_CALL(mock_input_handler_,
1945 ScrollBy(testing::_,
1946 testing::Property(&gfx::Vector2dF::x,
1947 testing::Eq(fling_delta.x))))
1948 .WillOnce(testing::Return(scroll_result_did_scroll_));
1949 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1951 VERIFY_AND_RESET_MOCKS();
1954 TEST_F(InputHandlerProxyTest, NoFlingBoostIfFlingTooSlow) {
1955 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1956 base::TimeTicks time = base::TimeTicks() + dt;
1957 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1958 WebPoint fling_point = WebPoint(7, 13);
1959 StartFling(
1960 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1962 // Cancel the fling. The fling cancellation should be deferred to allow
1963 // fling boosting events to arrive.
1964 time += dt;
1965 CancelFling(time);
1967 // If the new fling is too slow, no boosting should take place, with the new
1968 // fling replacing the old.
1969 WebFloatPoint small_fling_delta = WebFloatPoint(100, 0);
1970 gesture_ = CreateFling(time,
1971 blink::WebGestureDeviceTouchscreen,
1972 small_fling_delta,
1973 fling_point,
1974 fling_point,
1976 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1978 VERIFY_AND_RESET_MOCKS();
1980 // Note that the new fling delta uses the *slow*, unboosted fling velocity.
1981 time += dt;
1982 float expected_delta = dt.InSecondsF() * -small_fling_delta.x;
1983 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1984 EXPECT_CALL(mock_input_handler_,
1985 ScrollBy(testing::_,
1986 testing::Property(&gfx::Vector2dF::x,
1987 testing::Eq(expected_delta))))
1988 .WillOnce(testing::Return(scroll_result_did_scroll_));
1989 input_handler_->Animate(time);
1991 VERIFY_AND_RESET_MOCKS();
1994 TEST_F(InputHandlerProxyTest, NoFlingBoostIfPreventBoostingFlagIsSet) {
1995 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1996 base::TimeTicks time = base::TimeTicks() + dt;
1997 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1998 WebPoint fling_point = WebPoint(7, 13);
2000 StartFling(
2001 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
2003 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2005 // Cancel the fling. The fling cancellation should not be deferred because of
2006 // prevent boosting flag set.
2007 gesture_.data.flingCancel.preventBoosting = true;
2008 time += dt;
2009 CancelFling(time);
2011 // VERIFY_AND_RESET_MOCKS already called by CancelFling
2014 TEST_F(InputHandlerProxyTest, FlingBoostTerminatedDuringScrollSequence) {
2015 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
2016 base::TimeTicks time = base::TimeTicks() + dt;
2017 base::TimeTicks last_animate_time = time;
2018 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
2019 WebPoint fling_point = WebPoint(7, 13);
2020 StartFling(
2021 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
2023 // Now cancel the fling. The fling cancellation should be deferred to allow
2024 // fling boosting events to arrive.
2025 time += dt;
2026 CancelFling(time);
2028 // The GestureScrollBegin should be swallowed by the fling.
2029 time += dt;
2030 gesture_.timeStampSeconds = InSecondsF(time);
2031 gesture_.type = WebInputEvent::GestureScrollBegin;
2032 EXPECT_CALL(mock_input_handler_,
2033 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
2034 .WillOnce(testing::Return(true));
2035 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2037 VERIFY_AND_RESET_MOCKS();
2039 // Now animate the fling to completion (in this case, the fling should
2040 // terminate because the input handler reports a failed scroll). As the fling
2041 // was cancelled during an active scroll sequence, a synthetic
2042 // GestureScrollBegin should be processed, resuming the scroll.
2043 time += dt;
2044 float expected_delta =
2045 (time - last_animate_time).InSecondsF() * -fling_delta.x;
2046 EXPECT_CALL(mock_input_handler_,
2047 ScrollBy(testing::_,
2048 testing::Property(&gfx::Vector2dF::x,
2049 testing::Eq(expected_delta))))
2050 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
2051 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2052 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
2053 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
2054 input_handler_->Animate(time);
2056 VERIFY_AND_RESET_MOCKS();
2058 // Subsequent GestureScrollUpdates after the cancelled, boosted fling should
2059 // cause scrolling as usual.
2060 time += dt;
2061 expected_delta = 7.3f;
2062 gesture_.timeStampSeconds = InSecondsF(time);
2063 gesture_.type = WebInputEvent::GestureScrollUpdate;
2064 gesture_.data.scrollUpdate.deltaX = -expected_delta;
2065 EXPECT_CALL(mock_input_handler_,
2066 ScrollBy(testing::_,
2067 testing::Property(&gfx::Vector2dF::x,
2068 testing::Eq(expected_delta))))
2069 .WillOnce(testing::Return(scroll_result_did_scroll_));
2070 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2072 VERIFY_AND_RESET_MOCKS();
2074 // GestureScrollEnd should terminate the resumed scroll properly.
2075 time += dt;
2076 gesture_.timeStampSeconds = InSecondsF(time);
2077 gesture_.type = WebInputEvent::GestureScrollEnd;
2078 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2079 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2081 VERIFY_AND_RESET_MOCKS();
2084 TEST_F(InputHandlerProxyTest, DidReceiveInputEvent) {
2085 testing::StrictMock<
2086 MockInputHandlerProxyClientWithDidReceiveInputEvent> mock_client;
2087 input_handler_.reset(
2088 new content::InputHandlerProxy(&mock_input_handler_, &mock_client));
2090 // Note the type of input event isn't important.
2091 WebMouseWheelEvent wheel;
2092 wheel.type = WebInputEvent::MouseWheel;
2093 wheel.scrollByPage = true;
2095 EXPECT_CALL(mock_client, DidReceiveInputEvent(WebInputEvent::MouseWheel));
2097 input_handler_->HandleInputEvent(wheel);
2098 testing::Mock::VerifyAndClearExpectations(&mock_client);
2101 TEST_F(InputHandlerProxyTest, DidReceiveInputEvent_ForFling) {
2102 testing::StrictMock<
2103 MockInputHandlerProxyClientWithDidReceiveInputEvent> mock_client;
2104 input_handler_.reset(
2105 new content::InputHandlerProxy(&mock_input_handler_, &mock_client));
2107 gesture_.type = WebInputEvent::GestureFlingStart;
2108 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
2109 gesture_.data.flingStart.velocityX = fling_delta.x;
2110 gesture_.data.flingStart.velocityY = fling_delta.y;
2111 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
2112 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
2113 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
2114 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2115 EXPECT_CALL(mock_client,
2116 DidReceiveInputEvent(WebInputEvent::GestureFlingStart));
2117 EXPECT_EQ(InputHandlerProxy::DID_HANDLE,
2118 input_handler_->HandleInputEvent(gesture_));
2119 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
2120 testing::Mock::VerifyAndClearExpectations(&mock_client);
2122 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
2123 EXPECT_CALL(mock_client, DidAnimateForInput());
2124 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
2125 input_handler_->Animate(time);
2127 testing::Mock::VerifyAndClearExpectations(&mock_client);
2130 } // namespace
2131 } // namespace content