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/trees/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
;
31 using blink::WebTouchEvent
;
32 using blink::WebTouchPoint
;
38 double InSecondsF(const base::TimeTicks
& time
) {
39 return (time
- base::TimeTicks()).InSecondsF();
42 WebGestureEvent
CreateFling(base::TimeTicks timestamp
,
43 WebGestureDevice source_device
,
44 WebFloatPoint velocity
,
46 WebPoint global_point
,
48 WebGestureEvent fling
;
49 fling
.type
= WebInputEvent::GestureFlingStart
;
50 fling
.sourceDevice
= source_device
;
51 fling
.timeStampSeconds
= (timestamp
- base::TimeTicks()).InSecondsF();
52 fling
.data
.flingStart
.velocityX
= velocity
.x
;
53 fling
.data
.flingStart
.velocityY
= velocity
.y
;
56 fling
.globalX
= global_point
.x
;
57 fling
.globalY
= global_point
.y
;
58 fling
.modifiers
= modifiers
;
62 WebGestureEvent
CreateFling(WebGestureDevice source_device
,
63 WebFloatPoint velocity
,
65 WebPoint global_point
,
67 return CreateFling(base::TimeTicks(),
75 class MockInputHandler
: public cc::InputHandler
{
78 ~MockInputHandler() override
{}
80 MOCK_METHOD0(PinchGestureBegin
, void());
81 MOCK_METHOD2(PinchGestureUpdate
,
82 void(float magnify_delta
, const gfx::Point
& anchor
));
83 MOCK_METHOD0(PinchGestureEnd
, void());
85 MOCK_METHOD0(SetNeedsAnimateInput
, void());
87 MOCK_METHOD2(ScrollBegin
,
88 ScrollStatus(const gfx::Point
& viewport_point
,
89 cc::InputHandler::ScrollInputType type
));
90 MOCK_METHOD1(RootScrollBegin
,
91 ScrollStatus(cc::InputHandler::ScrollInputType type
));
92 MOCK_METHOD2(ScrollAnimated
,
93 ScrollStatus(const gfx::Point
& viewport_point
,
94 const gfx::Vector2dF
& scroll_delta
));
95 MOCK_METHOD2(ScrollBy
,
96 cc::InputHandlerScrollResult(
97 const gfx::Point
& viewport_point
,
98 const gfx::Vector2dF
& scroll_delta
));
99 MOCK_METHOD2(ScrollVerticallyByPage
,
100 bool(const gfx::Point
& viewport_point
,
101 cc::ScrollDirection direction
));
102 MOCK_METHOD0(ScrollEnd
, void());
103 MOCK_METHOD0(FlingScrollBegin
, cc::InputHandler::ScrollStatus());
105 scoped_ptr
<cc::SwapPromiseMonitor
> CreateLatencyInfoSwapPromiseMonitor(
106 ui::LatencyInfo
* latency
) override
{
107 return scoped_ptr
<cc::SwapPromiseMonitor
>();
110 cc::ScrollElasticityHelper
* CreateScrollElasticityHelper() override
{
114 void BindToClient(cc::InputHandlerClient
* client
) override
{}
116 void MouseMoveAt(const gfx::Point
& mouse_position
) override
{}
118 MOCK_METHOD2(IsCurrentlyScrollingLayerAt
,
119 bool(const gfx::Point
& point
,
120 cc::InputHandler::ScrollInputType type
));
122 MOCK_METHOD1(HaveWheelEventHandlersAt
, bool(const gfx::Point
& point
));
123 MOCK_METHOD1(DoTouchEventsBlockScrollAt
, bool(const gfx::Point
& point
));
125 void SetRootLayerScrollOffsetDelegate(
126 cc::LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
)
129 void OnRootLayerDelegatedScrollOffsetChanged() override
{}
131 DISALLOW_COPY_AND_ASSIGN(MockInputHandler
);
134 // A simple WebGestureCurve implementation that flings at a constant velocity
136 class FakeWebGestureCurve
: public blink::WebGestureCurve
{
138 FakeWebGestureCurve(const blink::WebFloatSize
& velocity
,
139 const blink::WebFloatSize
& cumulative_scroll
)
140 : velocity_(velocity
), cumulative_scroll_(cumulative_scroll
) {}
142 virtual ~FakeWebGestureCurve() {}
144 // Returns false if curve has finished and can no longer be applied.
145 virtual bool apply(double time
, blink::WebGestureCurveTarget
* target
) {
146 blink::WebFloatSize
displacement(velocity_
.width
* time
,
147 velocity_
.height
* time
);
148 blink::WebFloatSize
increment(
149 displacement
.width
- cumulative_scroll_
.width
,
150 displacement
.height
- cumulative_scroll_
.height
);
151 cumulative_scroll_
= displacement
;
152 // scrollBy() could delete this curve if the animation is over, so don't
153 // touch any member variables after making that call.
154 return target
->scrollBy(increment
, velocity_
);
158 blink::WebFloatSize velocity_
;
159 blink::WebFloatSize cumulative_scroll_
;
161 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve
);
164 class MockInputHandlerProxyClient
165 : public content::InputHandlerProxyClient
{
167 MockInputHandlerProxyClient() {}
168 ~MockInputHandlerProxyClient() override
{}
170 void WillShutdown() override
{}
172 MOCK_METHOD1(TransferActiveWheelFlingAnimation
,
173 void(const WebActiveWheelFlingParameters
&));
175 blink::WebGestureCurve
* CreateFlingAnimationCurve(
176 WebGestureDevice deviceSource
,
177 const WebFloatPoint
& velocity
,
178 const WebSize
& cumulative_scroll
) override
{
179 return new FakeWebGestureCurve(
180 blink::WebFloatSize(velocity
.x
, velocity
.y
),
181 blink::WebFloatSize(cumulative_scroll
.width
, cumulative_scroll
.height
));
184 MOCK_METHOD1(DidOverscroll
, void(const DidOverscrollParams
&));
185 void DidStopFlinging() override
{}
186 void DidAnimateForInput() override
{}
189 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient
);
192 class MockInputHandlerProxyClientWithDidAnimateForInput
193 : public MockInputHandlerProxyClient
{
195 MockInputHandlerProxyClientWithDidAnimateForInput() {}
196 ~MockInputHandlerProxyClientWithDidAnimateForInput() override
{}
198 MOCK_METHOD0(DidAnimateForInput
, void());
201 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClientWithDidAnimateForInput
);
204 WebTouchPoint
CreateWebTouchPoint(WebTouchPoint::State state
, float x
,
208 point
.screenPosition
= WebFloatPoint(x
, y
);
209 point
.position
= WebFloatPoint(x
, y
);
213 class InputHandlerProxyTest
: public testing::Test
{
215 InputHandlerProxyTest()
216 : expected_disposition_(InputHandlerProxy::DID_HANDLE
) {
217 input_handler_
.reset(
218 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client_
));
219 scroll_result_did_scroll_
.did_scroll
= true;
220 scroll_result_did_not_scroll_
.did_scroll
= false;
223 ~InputHandlerProxyTest() {
224 input_handler_
.reset();
227 // This is defined as a macro because when an expectation is not satisfied the
228 // only output you get
229 // out of gmock is the line number that set the expectation.
230 #define VERIFY_AND_RESET_MOCKS() \
232 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \
233 testing::Mock::VerifyAndClearExpectations(&mock_client_); \
236 void StartFling(base::TimeTicks timestamp
,
237 WebGestureDevice source_device
,
238 WebFloatPoint velocity
,
240 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
241 VERIFY_AND_RESET_MOCKS();
243 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
244 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
245 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
246 gesture_
.sourceDevice
= source_device
;
247 EXPECT_EQ(expected_disposition_
,
248 input_handler_
->HandleInputEvent(gesture_
));
250 VERIFY_AND_RESET_MOCKS();
252 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
253 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
254 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
257 CreateFling(timestamp
, source_device
, velocity
, position
, position
, 0);
258 EXPECT_EQ(expected_disposition_
,
259 input_handler_
->HandleInputEvent(gesture_
));
261 VERIFY_AND_RESET_MOCKS();
264 void CancelFling(base::TimeTicks timestamp
) {
265 gesture_
.timeStampSeconds
= InSecondsF(timestamp
);
266 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
267 EXPECT_EQ(expected_disposition_
,
268 input_handler_
->HandleInputEvent(gesture_
));
270 VERIFY_AND_RESET_MOCKS();
274 testing::StrictMock
<MockInputHandler
> mock_input_handler_
;
275 scoped_ptr
<content::InputHandlerProxy
> input_handler_
;
276 testing::StrictMock
<MockInputHandlerProxyClient
> mock_client_
;
277 WebGestureEvent gesture_
;
278 InputHandlerProxy::EventDisposition expected_disposition_
;
279 cc::InputHandlerScrollResult scroll_result_did_scroll_
;
280 cc::InputHandlerScrollResult scroll_result_did_not_scroll_
;
283 TEST_F(InputHandlerProxyTest
, MouseWheelByPageMainThread
) {
284 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
285 WebMouseWheelEvent wheel
;
286 wheel
.type
= WebInputEvent::MouseWheel
;
287 wheel
.scrollByPage
= true;
289 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(wheel
));
290 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
293 TEST_F(InputHandlerProxyTest
, MouseWheelWithCtrlNotScroll
) {
294 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
295 WebMouseWheelEvent wheel
;
296 wheel
.type
= WebInputEvent::MouseWheel
;
297 wheel
.modifiers
= WebInputEvent::ControlKey
;
298 wheel
.canScroll
= false;
299 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(wheel
));
300 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
303 TEST_F(InputHandlerProxyTest
, GestureScrollStarted
) {
304 // We shouldn't send any events to the widget for this gesture.
305 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
306 VERIFY_AND_RESET_MOCKS();
308 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
309 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
311 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
312 EXPECT_EQ(expected_disposition_
,input_handler_
->HandleInputEvent(gesture_
));
314 // The event should not be marked as handled if scrolling is not possible.
315 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
316 VERIFY_AND_RESET_MOCKS();
318 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
319 gesture_
.data
.scrollUpdate
.deltaY
=
320 -40; // -Y means scroll down - i.e. in the +Y direction.
321 EXPECT_CALL(mock_input_handler_
,
323 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
324 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
325 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
327 // Mark the event as handled if scroll happens.
328 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
329 VERIFY_AND_RESET_MOCKS();
331 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
332 gesture_
.data
.scrollUpdate
.deltaY
=
333 -40; // -Y means scroll down - i.e. in the +Y direction.
334 EXPECT_CALL(mock_input_handler_
,
336 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
337 .WillOnce(testing::Return(scroll_result_did_scroll_
));
338 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
340 VERIFY_AND_RESET_MOCKS();
342 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
343 gesture_
.data
.scrollUpdate
.deltaY
= 0;
344 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
345 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
347 VERIFY_AND_RESET_MOCKS();
350 TEST_F(InputHandlerProxyTest
, GestureScrollOnMainThread
) {
351 // We should send all events to the widget for this gesture.
352 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
353 VERIFY_AND_RESET_MOCKS();
355 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
356 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
358 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
359 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
361 VERIFY_AND_RESET_MOCKS();
363 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
364 gesture_
.data
.scrollUpdate
.deltaY
= 40;
365 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
367 VERIFY_AND_RESET_MOCKS();
369 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
370 gesture_
.data
.scrollUpdate
.deltaY
= 0;
371 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
372 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
374 VERIFY_AND_RESET_MOCKS();
377 TEST_F(InputHandlerProxyTest
, GestureScrollIgnored
) {
378 // We shouldn't handle the GestureScrollBegin.
379 // Instead, we should get a DROP_EVENT result, indicating
380 // that we could determine that there's nothing that could scroll or otherwise
381 // react to this gesture sequence and thus we should drop the whole gesture
382 // sequence on the floor, except for the ScrollEnd.
383 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
384 VERIFY_AND_RESET_MOCKS();
386 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
387 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
389 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
390 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
392 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
393 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
394 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
395 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
397 VERIFY_AND_RESET_MOCKS();
400 TEST_F(InputHandlerProxyTest
, GestureScrollBeginThatTargetViewport
) {
401 // We shouldn't send any events to the widget for this gesture.
402 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
403 VERIFY_AND_RESET_MOCKS();
405 EXPECT_CALL(mock_input_handler_
, RootScrollBegin(testing::_
))
406 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
408 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
409 gesture_
.data
.scrollBegin
.targetViewport
= true;
410 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
412 VERIFY_AND_RESET_MOCKS();
415 TEST_F(InputHandlerProxyTest
, GesturePinch
) {
416 // We shouldn't send any events to the widget for this gesture.
417 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
418 VERIFY_AND_RESET_MOCKS();
420 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
421 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
422 .WillOnce(testing::Return(false));
423 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
424 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
426 VERIFY_AND_RESET_MOCKS();
428 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
429 gesture_
.data
.pinchUpdate
.scale
= 1.5;
432 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
433 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
435 VERIFY_AND_RESET_MOCKS();
437 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
438 gesture_
.data
.pinchUpdate
.scale
= 0.5;
439 gesture_
.data
.pinchUpdate
.zoomDisabled
= true;
442 EXPECT_EQ(InputHandlerProxy::DROP_EVENT
,
443 input_handler_
->HandleInputEvent(gesture_
));
444 gesture_
.data
.pinchUpdate
.zoomDisabled
= false;
446 VERIFY_AND_RESET_MOCKS();
448 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
449 gesture_
.data
.pinchUpdate
.scale
= 0.5;
452 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
453 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
455 VERIFY_AND_RESET_MOCKS();
457 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
458 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
459 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
461 VERIFY_AND_RESET_MOCKS();
464 TEST_F(InputHandlerProxyTest
, GesturePinchWithWheelHandler
) {
465 // We will send the synthetic wheel event to the widget.
466 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
467 VERIFY_AND_RESET_MOCKS();
469 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
470 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
471 .WillOnce(testing::Return(true));
472 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
474 VERIFY_AND_RESET_MOCKS();
476 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
477 gesture_
.data
.pinchUpdate
.scale
= 1.5;
480 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
482 VERIFY_AND_RESET_MOCKS();
484 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
485 gesture_
.data
.pinchUpdate
.scale
= 0.5;
488 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
490 VERIFY_AND_RESET_MOCKS();
492 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
493 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
496 TEST_F(InputHandlerProxyTest
, GesturePinchAfterScrollOnMainThread
) {
497 // Scrolls will start by being sent to the main thread.
498 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
499 VERIFY_AND_RESET_MOCKS();
501 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
502 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
504 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
505 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
507 VERIFY_AND_RESET_MOCKS();
509 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
510 gesture_
.data
.scrollUpdate
.deltaY
= 40;
511 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
513 // However, after the pinch gesture starts, they should go to the impl
515 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
516 VERIFY_AND_RESET_MOCKS();
518 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
519 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
520 .WillOnce(testing::Return(false));
521 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
522 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
524 VERIFY_AND_RESET_MOCKS();
526 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
527 gesture_
.data
.pinchUpdate
.scale
= 1.5;
530 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
531 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
533 VERIFY_AND_RESET_MOCKS();
535 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
536 gesture_
.data
.scrollUpdate
.deltaY
=
537 -40; // -Y means scroll down - i.e. in the +Y direction.
538 EXPECT_CALL(mock_input_handler_
,
540 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
541 .WillOnce(testing::Return(scroll_result_did_scroll_
));
542 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
544 VERIFY_AND_RESET_MOCKS();
546 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
547 gesture_
.data
.pinchUpdate
.scale
= 0.5;
550 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
551 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
553 VERIFY_AND_RESET_MOCKS();
555 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
556 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
557 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
559 // After the pinch gesture ends, they should go to back to the main
561 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
562 VERIFY_AND_RESET_MOCKS();
564 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
565 gesture_
.data
.scrollUpdate
.deltaY
= 0;
566 EXPECT_CALL(mock_input_handler_
, ScrollEnd())
567 .WillOnce(testing::Return());
568 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
570 VERIFY_AND_RESET_MOCKS();
573 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchpad
) {
574 // We shouldn't send any events to the widget for this gesture.
575 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
576 VERIFY_AND_RESET_MOCKS();
578 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
579 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
580 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
581 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
583 gesture_
.type
= WebInputEvent::GestureFlingStart
;
584 gesture_
.data
.flingStart
.velocityX
= 10;
585 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
586 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
588 VERIFY_AND_RESET_MOCKS();
590 // Verify that a GestureFlingCancel during an animation cancels it.
591 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
592 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
593 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
596 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchpad
) {
597 // We should send all events to the widget for this gesture.
598 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
599 VERIFY_AND_RESET_MOCKS();
601 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
602 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
604 gesture_
.type
= WebInputEvent::GestureFlingStart
;
605 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
606 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
608 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the
609 // input handler knows it's scrolling off the impl thread
610 ASSERT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
612 VERIFY_AND_RESET_MOCKS();
614 // Even if we didn't start a fling ourselves, we still need to send the cancel
615 // event to the widget.
616 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
617 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
618 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
621 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchpad
) {
622 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
623 VERIFY_AND_RESET_MOCKS();
625 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
626 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
628 gesture_
.type
= WebInputEvent::GestureFlingStart
;
629 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
630 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
632 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
633 VERIFY_AND_RESET_MOCKS();
635 // Since the previous fling was ignored, we should also be dropping the next
637 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
638 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
639 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
642 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchpad
) {
643 // We shouldn't send any events to the widget for this gesture.
644 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
645 VERIFY_AND_RESET_MOCKS();
647 // On the fling start, we should schedule an animation but not actually start
649 gesture_
.type
= WebInputEvent::GestureFlingStart
;
650 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
651 WebPoint fling_point
= WebPoint(7, 13);
652 WebPoint fling_global_point
= WebPoint(17, 23);
653 // Note that for trackpad, wheel events with the Control modifier are
654 // special (reserved for zoom), so don't set that here.
655 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
656 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
661 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
662 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
663 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
664 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
665 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
667 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
668 // The first animate call should let us pick up an animation start time, but
669 // we shouldn't actually move anywhere just yet. The first frame after the
670 // fling start will typically include the last scroll from the gesture that
671 // lead to the scroll (either wheel or gesture scroll), so there should be no
673 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
674 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
676 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
677 input_handler_
->Animate(time
);
679 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
681 // The second call should start scrolling in the -X direction.
682 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
683 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
684 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
685 EXPECT_CALL(mock_input_handler_
,
687 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
688 .WillOnce(testing::Return(scroll_result_did_scroll_
));
689 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
690 time
+= base::TimeDelta::FromMilliseconds(100);
691 input_handler_
->Animate(time
);
693 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
695 // Let's say on the third call we hit a non-scrollable region. We should abort
696 // the fling and not scroll.
697 // We also should pass the current fling parameters out to the client so the
698 // rest of the fling can be
699 // transferred to the main thread.
700 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
701 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
702 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
703 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
704 // Expected wheel fling animation parameters:
705 // *) fling_delta and fling_point should match the original GestureFlingStart
707 // *) startTime should be 10 to match the time parameter of the first
708 // Animate() call after the GestureFlingStart
709 // *) cumulativeScroll depends on the curve, but since we've animated in the
710 // -X direction the X value should be < 0
713 TransferActiveWheelFlingAnimation(testing::AllOf(
714 testing::Field(&WebActiveWheelFlingParameters::delta
,
715 testing::Eq(fling_delta
)),
716 testing::Field(&WebActiveWheelFlingParameters::point
,
717 testing::Eq(fling_point
)),
718 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
719 testing::Eq(fling_global_point
)),
720 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
721 testing::Eq(modifiers
)),
722 testing::Field(&WebActiveWheelFlingParameters::startTime
,
724 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
725 testing::Field(&WebSize::width
, testing::Gt(0))))));
726 time
+= base::TimeDelta::FromMilliseconds(100);
727 input_handler_
->Animate(time
);
729 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
730 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
732 // Since we've aborted the fling, the next animation should be a no-op and
733 // should not result in another
734 // frame being requested.
735 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput()).Times(0);
736 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
738 time
+= base::TimeDelta::FromMilliseconds(100);
739 input_handler_
->Animate(time
);
741 // Since we've transferred the fling to the main thread, we need to pass the
742 // next GestureFlingCancel to the main
744 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
745 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
746 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
748 VERIFY_AND_RESET_MOCKS();
751 TEST_F(InputHandlerProxyTest
, GestureFlingTransferResetsTouchpad
) {
752 // We shouldn't send any events to the widget for this gesture.
753 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
754 VERIFY_AND_RESET_MOCKS();
756 // Start a gesture fling in the -X direction with zero Y movement.
757 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
758 WebPoint fling_point
= WebPoint(7, 13);
759 WebPoint fling_global_point
= WebPoint(17, 23);
760 // Note that for trackpad, wheel events with the Control modifier are
761 // special (reserved for zoom), so don't set that here.
762 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
763 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
768 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
769 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
770 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
771 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
772 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
774 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
776 // Start the fling animation at time 10. This shouldn't actually scroll, just
777 // establish a start time.
778 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
779 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
781 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
782 input_handler_
->Animate(time
);
784 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
786 // The second call should start scrolling in the -X direction.
787 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
788 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
789 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
790 EXPECT_CALL(mock_input_handler_
,
792 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
793 .WillOnce(testing::Return(scroll_result_did_scroll_
));
794 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
795 time
+= base::TimeDelta::FromMilliseconds(100);
796 input_handler_
->Animate(time
);
798 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
800 // Let's say on the third call we hit a non-scrollable region. We should abort
801 // the fling and not scroll.
802 // We also should pass the current fling parameters out to the client so the
803 // rest of the fling can be
804 // transferred to the main thread.
805 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
806 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
807 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
808 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
810 // Expected wheel fling animation parameters:
811 // *) fling_delta and fling_point should match the original GestureFlingStart
813 // *) startTime should be 10 to match the time parameter of the first
814 // Animate() call after the GestureFlingStart
815 // *) cumulativeScroll depends on the curve, but since we've animated in the
816 // -X direction the X value should be < 0
819 TransferActiveWheelFlingAnimation(testing::AllOf(
820 testing::Field(&WebActiveWheelFlingParameters::delta
,
821 testing::Eq(fling_delta
)),
822 testing::Field(&WebActiveWheelFlingParameters::point
,
823 testing::Eq(fling_point
)),
824 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
825 testing::Eq(fling_global_point
)),
826 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
827 testing::Eq(modifiers
)),
828 testing::Field(&WebActiveWheelFlingParameters::startTime
,
830 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
831 testing::Field(&WebSize::width
, testing::Gt(0))))));
832 time
+= base::TimeDelta::FromMilliseconds(100);
833 input_handler_
->Animate(time
);
835 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
836 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
838 // Since we've aborted the fling, the next animation should be a no-op and
839 // should not result in another
840 // frame being requested.
841 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput()).Times(0);
842 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
844 time
+= base::TimeDelta::FromMilliseconds(100);
845 input_handler_
->Animate(time
);
847 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
849 // Since we've transferred the fling to the main thread, we need to pass the
850 // next GestureFlingCancel to the main
852 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
853 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
854 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
856 VERIFY_AND_RESET_MOCKS();
857 input_handler_
->MainThreadHasStoppedFlinging();
859 // Start a second gesture fling, this time in the +Y direction with no X.
860 fling_delta
= WebFloatPoint(0, -1000);
861 fling_point
= WebPoint(95, 87);
862 fling_global_point
= WebPoint(32, 71);
863 modifiers
= WebInputEvent::AltKey
;
864 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
869 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
870 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
871 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
872 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
873 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
874 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
876 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
878 // Start the second fling animation at time 30.
879 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
880 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
882 time
= base::TimeTicks() + base::TimeDelta::FromSeconds(30);
883 input_handler_
->Animate(time
);
885 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
887 // Tick the second fling once normally.
888 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
889 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
890 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
891 EXPECT_CALL(mock_input_handler_
,
893 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
894 .WillOnce(testing::Return(scroll_result_did_scroll_
));
895 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
896 time
+= base::TimeDelta::FromMilliseconds(100);
897 input_handler_
->Animate(time
);
899 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
901 // Then abort the second fling.
902 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
903 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
904 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
905 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
907 // We should get parameters from the second fling, nothing from the first
908 // fling should "leak".
911 TransferActiveWheelFlingAnimation(testing::AllOf(
912 testing::Field(&WebActiveWheelFlingParameters::delta
,
913 testing::Eq(fling_delta
)),
914 testing::Field(&WebActiveWheelFlingParameters::point
,
915 testing::Eq(fling_point
)),
916 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
917 testing::Eq(fling_global_point
)),
918 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
919 testing::Eq(modifiers
)),
920 testing::Field(&WebActiveWheelFlingParameters::startTime
,
922 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
923 testing::Field(&WebSize::height
, testing::Lt(0))))));
924 time
+= base::TimeDelta::FromMilliseconds(100);
925 input_handler_
->Animate(time
);
927 VERIFY_AND_RESET_MOCKS();
930 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchscreen
) {
931 // We shouldn't send any events to the widget for this gesture.
932 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
933 VERIFY_AND_RESET_MOCKS();
935 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
936 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
937 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
938 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
939 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
941 VERIFY_AND_RESET_MOCKS();
943 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
944 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
945 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
947 gesture_
.type
= WebInputEvent::GestureFlingStart
;
948 gesture_
.data
.flingStart
.velocityX
= 10;
949 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
950 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
952 VERIFY_AND_RESET_MOCKS();
954 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
956 // Verify that a GestureFlingCancel during an animation cancels it.
957 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
958 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
959 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
961 VERIFY_AND_RESET_MOCKS();
964 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchscreen
) {
965 // We should send all events to the widget for this gesture.
966 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
967 VERIFY_AND_RESET_MOCKS();
969 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
970 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
972 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
973 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
975 VERIFY_AND_RESET_MOCKS();
977 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin()).Times(0);
979 gesture_
.type
= WebInputEvent::GestureFlingStart
;
980 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
981 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
983 VERIFY_AND_RESET_MOCKS();
985 // Even if we didn't start a fling ourselves, we still need to send the cancel
986 // event to the widget.
987 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
988 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
989 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
992 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchscreen
) {
993 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
994 VERIFY_AND_RESET_MOCKS();
996 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
997 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
999 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1000 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1001 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1003 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
1004 VERIFY_AND_RESET_MOCKS();
1006 // Flings ignored by the InputHandler should be dropped, signalling the end
1007 // of the touch scroll sequence.
1008 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1009 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
1011 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1012 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1013 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1015 VERIFY_AND_RESET_MOCKS();
1017 // Subsequent scrolls should behave normally, even without an intervening
1018 // GestureFlingCancel, as the original GestureFlingStart was dropped.
1019 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1020 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1021 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1022 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1023 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1024 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1026 VERIFY_AND_RESET_MOCKS();
1029 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchscreen
) {
1030 // We shouldn't send any events to the widget for this gesture.
1031 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1032 VERIFY_AND_RESET_MOCKS();
1034 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1035 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1037 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1038 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1039 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1041 VERIFY_AND_RESET_MOCKS();
1043 // On the fling start, we should schedule an animation but not actually start
1045 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1046 WebPoint fling_point
= WebPoint(7, 13);
1047 WebPoint fling_global_point
= WebPoint(17, 23);
1048 // Note that for touchscreen the control modifier is not special.
1049 int modifiers
= WebInputEvent::ControlKey
;
1050 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
1055 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1056 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1057 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1058 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1060 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1061 // The first animate call should let us pick up an animation start time, but
1062 // we shouldn't actually move anywhere just yet. The first frame after the
1063 // fling start will typically include the last scroll from the gesture that
1064 // lead to the scroll (either wheel or gesture scroll), so there should be no
1066 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1067 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1068 input_handler_
->Animate(time
);
1070 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1072 // The second call should start scrolling in the -X direction.
1073 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1074 EXPECT_CALL(mock_input_handler_
,
1075 ScrollBy(testing::_
,
1076 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1077 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1078 time
+= base::TimeDelta::FromMilliseconds(100);
1079 input_handler_
->Animate(time
);
1081 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1083 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1084 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1085 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1087 VERIFY_AND_RESET_MOCKS();
1090 TEST_F(InputHandlerProxyTest
, GestureFlingWithValidTimestamp
) {
1091 // We shouldn't send any events to the widget for this gesture.
1092 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1093 VERIFY_AND_RESET_MOCKS();
1095 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1096 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1098 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1099 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1100 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1102 VERIFY_AND_RESET_MOCKS();
1104 // On the fling start, we should schedule an animation but not actually start
1106 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1107 base::TimeTicks time
= base::TimeTicks() + dt
;
1108 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1109 WebPoint fling_point
= WebPoint(7, 13);
1110 WebPoint fling_global_point
= WebPoint(17, 23);
1111 int modifiers
= WebInputEvent::ControlKey
;
1112 gesture_
= CreateFling(time
,
1113 blink::WebGestureDeviceTouchscreen
,
1118 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1119 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1120 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1121 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1123 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1124 // With a valid time stamp, the first animate call should skip start time
1125 // initialization and immediately begin scroll update production. This reduces
1126 // the likelihood of a hitch between the scroll preceding the fling and
1127 // the first scroll generated by the fling.
1128 // Scrolling should start in the -X direction.
1129 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1130 EXPECT_CALL(mock_input_handler_
,
1131 ScrollBy(testing::_
,
1132 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1133 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1135 input_handler_
->Animate(time
);
1137 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1139 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1140 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1141 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1143 VERIFY_AND_RESET_MOCKS();
1146 TEST_F(InputHandlerProxyTest
, GestureFlingWithInvalidTimestamp
) {
1147 // We shouldn't send any events to the widget for this gesture.
1148 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1149 VERIFY_AND_RESET_MOCKS();
1151 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1152 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1154 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1155 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1156 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1158 VERIFY_AND_RESET_MOCKS();
1160 // On the fling start, we should schedule an animation but not actually start
1162 base::TimeDelta start_time_offset
= base::TimeDelta::FromMilliseconds(10);
1163 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1164 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1165 WebPoint fling_point
= WebPoint(7, 13);
1166 WebPoint fling_global_point
= WebPoint(17, 23);
1167 int modifiers
= WebInputEvent::ControlKey
;
1168 gesture_
.timeStampSeconds
= start_time_offset
.InSecondsF();
1169 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1170 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1171 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1172 gesture_
.x
= fling_point
.x
;
1173 gesture_
.y
= fling_point
.y
;
1174 gesture_
.globalX
= fling_global_point
.x
;
1175 gesture_
.globalY
= fling_global_point
.y
;
1176 gesture_
.modifiers
= modifiers
;
1177 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1178 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1179 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1180 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1182 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1183 // Event though a time stamp was provided for the fling event, it will be
1184 // ignored as its too far in the past relative to the first animate call's
1186 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1187 base::TimeTicks time
=
1188 base::TimeTicks() + start_time_offset
+ base::TimeDelta::FromSeconds(1);
1189 input_handler_
->Animate(time
);
1191 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1193 // Further animation ticks should update the fling as usual.
1194 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1195 EXPECT_CALL(mock_input_handler_
,
1196 ScrollBy(testing::_
,
1197 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1198 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1199 time
+= base::TimeDelta::FromMilliseconds(10);
1200 input_handler_
->Animate(time
);
1202 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1204 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1205 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1206 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1208 VERIFY_AND_RESET_MOCKS();
1211 TEST_F(InputHandlerProxyTest
,
1212 GestureScrollOnImplThreadFlagClearedAfterFling
) {
1213 // We shouldn't send any events to the widget for this gesture.
1214 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1215 VERIFY_AND_RESET_MOCKS();
1217 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1218 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1220 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1221 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1223 // After sending a GestureScrollBegin, the member variable
1224 // |gesture_scroll_on_impl_thread_| should be true.
1225 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1227 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1228 VERIFY_AND_RESET_MOCKS();
1230 // On the fling start, we should schedule an animation but not actually start
1232 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1233 WebPoint fling_point
= WebPoint(7, 13);
1234 WebPoint fling_global_point
= WebPoint(17, 23);
1235 int modifiers
= WebInputEvent::ControlKey
| WebInputEvent::AltKey
;
1236 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
1241 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1242 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1243 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1244 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1246 // |gesture_scroll_on_impl_thread_| should still be true after
1247 // a GestureFlingStart is sent.
1248 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1250 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1251 // The first animate call should let us pick up an animation start time, but
1252 // we shouldn't actually move anywhere just yet. The first frame after the
1253 // fling start will typically include the last scroll from the gesture that
1254 // lead to the scroll (either wheel or gesture scroll), so there should be no
1256 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1257 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1258 input_handler_
->Animate(time
);
1260 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1262 // The second call should start scrolling in the -X direction.
1263 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1264 EXPECT_CALL(mock_input_handler_
,
1265 ScrollBy(testing::_
,
1266 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1267 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1268 time
+= base::TimeDelta::FromMilliseconds(100);
1269 input_handler_
->Animate(time
);
1271 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1273 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1274 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1275 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1277 // |gesture_scroll_on_impl_thread_| should be false once
1278 // the fling has finished (note no GestureScrollEnd has been sent).
1279 EXPECT_TRUE(!input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1281 VERIFY_AND_RESET_MOCKS();
1284 TEST_F(InputHandlerProxyTest
,
1285 BeginScrollWhenGestureScrollOnImplThreadFlagIsSet
) {
1286 // We shouldn't send any events to the widget for this gesture.
1287 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1288 VERIFY_AND_RESET_MOCKS();
1290 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1291 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1293 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1294 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1296 // After sending a GestureScrollBegin, the member variable
1297 // |gesture_scroll_on_impl_thread_| should be true.
1298 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1300 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1301 VERIFY_AND_RESET_MOCKS();
1303 // On the fling start, we should schedule an animation but not actually start
1305 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1306 WebPoint fling_point
= WebPoint(7, 13);
1307 WebPoint fling_global_point
= WebPoint(17, 23);
1308 int modifiers
= WebInputEvent::ControlKey
| WebInputEvent::AltKey
;
1309 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
, fling_delta
,
1310 fling_point
, fling_global_point
, modifiers
);
1311 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1312 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1313 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1314 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1316 // |gesture_scroll_on_impl_thread_| should still be true after
1317 // a GestureFlingStart is sent.
1318 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1320 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1322 // gesture_scroll_on_impl_thread_ is still true when this scroll begins. As a
1323 // result, this scroll begin will cancel the previous fling.
1324 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1325 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1326 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1328 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1329 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1331 // After sending a GestureScrollBegin, the member variable
1332 // |gesture_scroll_on_impl_thread_| should be true.
1333 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1334 VERIFY_AND_RESET_MOCKS();
1337 TEST_F(InputHandlerProxyTest
, GestureFlingStopsAtContentEdge
) {
1338 // We shouldn't send any events to the widget for this gesture.
1339 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1340 VERIFY_AND_RESET_MOCKS();
1342 // On the fling start, we should schedule an animation but not actually start
1344 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1345 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1346 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1347 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1348 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1349 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1350 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1351 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1352 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1353 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1355 // The first animate doesn't cause any scrolling.
1356 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1357 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1358 input_handler_
->Animate(time
);
1359 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1361 // The second animate starts scrolling in the positive X and Y directions.
1362 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1363 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1364 EXPECT_CALL(mock_input_handler_
,
1365 ScrollBy(testing::_
,
1366 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1367 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1368 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1369 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1370 time
+= base::TimeDelta::FromMilliseconds(100);
1371 input_handler_
->Animate(time
);
1372 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1374 // The third animate overscrolls in the positive Y direction but scrolls
1376 cc::InputHandlerScrollResult overscroll
;
1377 overscroll
.did_scroll
= true;
1378 overscroll
.did_overscroll_root
= true;
1379 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1380 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 10);
1381 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1382 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1383 EXPECT_CALL(mock_input_handler_
,
1384 ScrollBy(testing::_
,
1385 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1386 .WillOnce(testing::Return(overscroll
));
1389 DidOverscroll(testing::AllOf(
1391 &DidOverscrollParams::accumulated_overscroll
,
1392 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1394 &DidOverscrollParams::latest_overscroll_delta
,
1395 testing::Eq(overscroll
.unused_scroll_delta
)),
1397 &DidOverscrollParams::current_fling_velocity
,
1398 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1399 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1400 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1401 time
+= base::TimeDelta::FromMilliseconds(100);
1402 input_handler_
->Animate(time
);
1403 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1405 // The next call to animate will no longer scroll vertically.
1406 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1407 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1408 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1409 EXPECT_CALL(mock_input_handler_
,
1410 ScrollBy(testing::_
,
1411 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1412 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1413 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1414 time
+= base::TimeDelta::FromMilliseconds(100);
1415 input_handler_
->Animate(time
);
1416 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1419 TEST_F(InputHandlerProxyTest
, GestureFlingNotCancelledBySmallTimeDelta
) {
1420 // We shouldn't send any events to the widget for this gesture.
1421 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1422 VERIFY_AND_RESET_MOCKS();
1424 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1425 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1427 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1428 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1429 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1431 VERIFY_AND_RESET_MOCKS();
1433 // On the fling start, we should schedule an animation but not actually start
1435 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1436 base::TimeTicks time
= base::TimeTicks() + dt
;
1437 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1438 WebPoint fling_point
= WebPoint(7, 13);
1439 WebPoint fling_global_point
= WebPoint(17, 23);
1440 int modifiers
= WebInputEvent::ControlKey
;
1441 gesture_
= CreateFling(time
,
1442 blink::WebGestureDeviceTouchscreen
,
1447 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1448 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1449 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1450 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1452 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1453 // With an animation timestamp equivalent to the starting timestamp, the
1454 // animation will simply be rescheduled.
1455 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1456 input_handler_
->Animate(time
);
1458 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1459 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1461 // A small time delta should not stop the fling, even if the client
1462 // reports no scrolling.
1463 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1464 EXPECT_CALL(mock_input_handler_
,
1465 ScrollBy(testing::_
,
1466 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1467 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1468 time
+= base::TimeDelta::FromMicroseconds(5);
1469 input_handler_
->Animate(time
);
1471 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1472 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1474 // A time delta of zero should not stop the fling, and neither should it
1475 // trigger scrolling on the client.
1476 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1477 input_handler_
->Animate(time
);
1479 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1480 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1482 // Lack of movement on the client, with a non-trivial scroll delta, should
1483 // terminate the fling.
1484 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1485 EXPECT_CALL(mock_input_handler_
,
1486 ScrollBy(testing::_
,
1487 testing::Property(&gfx::Vector2dF::x
, testing::Lt(1))))
1488 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1489 time
+= base::TimeDelta::FromMilliseconds(100);
1490 input_handler_
->Animate(time
);
1492 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1493 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1496 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledAfterBothAxesStopScrolling
) {
1497 cc::InputHandlerScrollResult overscroll
;
1498 overscroll
.did_scroll
= true;
1499 overscroll
.did_overscroll_root
= true;
1501 // We shouldn't send any events to the widget for this gesture.
1502 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1503 VERIFY_AND_RESET_MOCKS();
1505 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1506 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1507 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1508 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1509 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1510 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1512 // On the fling start, we should schedule an animation but not actually start
1514 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1515 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1516 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1517 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1518 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1519 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1520 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1521 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1522 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1524 // The first animate doesn't cause any scrolling.
1525 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1526 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1527 input_handler_
->Animate(time
);
1528 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1530 // The second animate starts scrolling in the positive X and Y directions.
1531 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1532 EXPECT_CALL(mock_input_handler_
,
1533 ScrollBy(testing::_
,
1534 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1535 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1536 time
+= base::TimeDelta::FromMilliseconds(10);
1537 input_handler_
->Animate(time
);
1538 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1540 // The third animate hits the bottom content edge.
1541 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1542 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 100);
1543 EXPECT_CALL(mock_input_handler_
,
1544 ScrollBy(testing::_
,
1545 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1546 .WillOnce(testing::Return(overscroll
));
1549 DidOverscroll(testing::AllOf(
1551 &DidOverscrollParams::accumulated_overscroll
,
1552 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1554 &DidOverscrollParams::latest_overscroll_delta
,
1555 testing::Eq(overscroll
.unused_scroll_delta
)),
1557 &DidOverscrollParams::current_fling_velocity
,
1558 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1559 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1560 time
+= base::TimeDelta::FromMilliseconds(10);
1561 input_handler_
->Animate(time
);
1562 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1564 // The next call to animate will no longer scroll vertically.
1565 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1566 EXPECT_CALL(mock_input_handler_
,
1567 ScrollBy(testing::_
,
1568 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1569 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1570 time
+= base::TimeDelta::FromMilliseconds(10);
1571 input_handler_
->Animate(time
);
1572 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1574 // The next call will hit the right edge.
1575 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(100, 100);
1576 overscroll
.unused_scroll_delta
= gfx::Vector2dF(100, 0);
1577 EXPECT_CALL(mock_input_handler_
,
1578 ScrollBy(testing::_
,
1579 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1580 .WillOnce(testing::Return(overscroll
));
1583 DidOverscroll(testing::AllOf(
1585 &DidOverscrollParams::accumulated_overscroll
,
1586 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1588 &DidOverscrollParams::latest_overscroll_delta
,
1589 testing::Eq(overscroll
.unused_scroll_delta
)),
1591 &DidOverscrollParams::current_fling_velocity
,
1592 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))));
1593 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1594 time
+= base::TimeDelta::FromMilliseconds(10);
1595 input_handler_
->Animate(time
);
1596 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1598 // The next call to animate will no longer scroll horizontally or vertically,
1599 // and the fling should be cancelled.
1600 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput()).Times(0);
1601 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
1602 time
+= base::TimeDelta::FromMilliseconds(10);
1603 input_handler_
->Animate(time
);
1604 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1605 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1608 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestNegative
) {
1609 // None of the three touch points fall in the touch region. So the event
1610 // should be dropped.
1611 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
1612 VERIFY_AND_RESET_MOCKS();
1614 EXPECT_CALL(mock_input_handler_
,
1615 DoTouchEventsBlockScrollAt(
1616 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1617 .WillOnce(testing::Return(false));
1618 EXPECT_CALL(mock_input_handler_
,
1619 DoTouchEventsBlockScrollAt(
1620 testing::Property(&gfx::Point::x
, testing::Lt(0))))
1621 .WillOnce(testing::Return(false));
1623 WebTouchEvent touch
;
1624 touch
.type
= WebInputEvent::TouchStart
;
1626 touch
.touchesLength
= 3;
1627 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary
, 0, 0);
1628 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1629 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1630 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1632 VERIFY_AND_RESET_MOCKS();
1635 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestPositive
) {
1636 // One of the touch points is on a touch-region. So the event should be sent
1637 // to the main thread.
1638 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
1639 VERIFY_AND_RESET_MOCKS();
1641 EXPECT_CALL(mock_input_handler_
,
1642 DoTouchEventsBlockScrollAt(
1643 testing::Property(&gfx::Point::x
, testing::Eq(0))))
1644 .WillOnce(testing::Return(false));
1645 EXPECT_CALL(mock_input_handler_
,
1646 DoTouchEventsBlockScrollAt(
1647 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1648 .WillOnce(testing::Return(true));
1649 // Since the second touch point hits a touch-region, there should be no
1650 // hit-testing for the third touch point.
1652 WebTouchEvent touch
;
1653 touch
.type
= WebInputEvent::TouchStart
;
1655 touch
.touchesLength
= 3;
1656 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 0, 0);
1657 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1658 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1659 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1661 VERIFY_AND_RESET_MOCKS();
1664 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledByKeyboardEvent
) {
1665 // We shouldn't send any events to the widget for this gesture.
1666 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1667 VERIFY_AND_RESET_MOCKS();
1669 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1670 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1671 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1672 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1673 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1674 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1675 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1677 // Keyboard events received during a scroll should have no effect.
1678 WebKeyboardEvent key_event
;
1679 key_event
.type
= WebInputEvent::KeyDown
;
1680 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1681 input_handler_
->HandleInputEvent(key_event
));
1682 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1683 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1685 // On the fling start, animation should be scheduled, but no scrolling occurs.
1686 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1687 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1688 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1689 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1690 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1691 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1692 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1693 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1694 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1695 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1697 // Keyboard events received during a fling should cancel the active fling.
1698 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1699 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1700 input_handler_
->HandleInputEvent(key_event
));
1701 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1702 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1704 // The call to animate should have no effect, as the fling was cancelled.
1705 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1706 input_handler_
->Animate(time
);
1707 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1709 // A fling cancel should be dropped, as there is nothing to cancel.
1710 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1711 EXPECT_EQ(InputHandlerProxy::DROP_EVENT
,
1712 input_handler_
->HandleInputEvent(gesture_
));
1713 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1716 TEST_F(InputHandlerProxyTest
, GestureFlingWithNegativeTimeDelta
) {
1717 // We shouldn't send any events to the widget for this gesture.
1718 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1719 VERIFY_AND_RESET_MOCKS();
1721 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1722 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1724 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1725 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1726 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1728 VERIFY_AND_RESET_MOCKS();
1730 // On the fling start, we should schedule an animation but not actually start
1732 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1733 base::TimeTicks time
= base::TimeTicks() + dt
;
1734 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1735 WebPoint fling_point
= WebPoint(7, 13);
1736 WebPoint fling_global_point
= WebPoint(17, 23);
1737 int modifiers
= WebInputEvent::ControlKey
;
1738 gesture_
= CreateFling(time
,
1739 blink::WebGestureDeviceTouchscreen
,
1744 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1745 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1746 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1747 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1749 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1751 // If we get a negative time delta, that is, the Animation tick time happens
1752 // before the fling's start time then we should *not* try scrolling and
1753 // instead reset the fling start time.
1754 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1755 EXPECT_CALL(mock_input_handler_
,
1756 ScrollBy(testing::_
,
1757 testing::_
)).Times(0);
1758 time
-= base::TimeDelta::FromMilliseconds(5);
1759 input_handler_
->Animate(time
);
1761 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1763 // The first call should have reset the start time so subsequent calls should
1764 // generate scroll events.
1765 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1766 EXPECT_CALL(mock_input_handler_
,
1767 ScrollBy(testing::_
,
1768 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1769 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1771 input_handler_
->Animate(time
+ base::TimeDelta::FromMilliseconds(1));
1773 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1775 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1776 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1777 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1779 VERIFY_AND_RESET_MOCKS();
1782 TEST_F(InputHandlerProxyTest
, FlingBoost
) {
1783 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1784 base::TimeTicks time
= base::TimeTicks() + dt
;
1785 base::TimeTicks last_animate_time
= time
;
1786 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1787 WebPoint fling_point
= WebPoint(7, 13);
1789 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1791 // Now cancel the fling. The fling cancellation should be deferred to allow
1792 // fling boosting events to arrive.
1796 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1798 EXPECT_CALL(mock_input_handler_
,
1799 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1800 .WillOnce(testing::Return(true));
1803 gesture_
.timeStampSeconds
= InSecondsF(time
);
1804 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1805 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1807 VERIFY_AND_RESET_MOCKS();
1809 // Animate calls within the deferred cancellation window should continue.
1811 float expected_delta
=
1812 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1813 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1814 EXPECT_CALL(mock_input_handler_
,
1815 ScrollBy(testing::_
,
1816 testing::Property(&gfx::Vector2dF::x
,
1817 testing::Eq(expected_delta
))))
1818 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1819 input_handler_
->Animate(time
);
1820 last_animate_time
= time
;
1822 VERIFY_AND_RESET_MOCKS();
1824 // GestureScrollUpdates in the same direction and at sufficient speed should
1825 // be swallowed by the fling.
1827 gesture_
.timeStampSeconds
= InSecondsF(time
);
1828 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
1829 gesture_
.data
.scrollUpdate
.deltaX
= fling_delta
.x
;
1830 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1832 VERIFY_AND_RESET_MOCKS();
1834 // Animate calls within the deferred cancellation window should continue.
1836 expected_delta
= (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1837 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1838 EXPECT_CALL(mock_input_handler_
,
1839 ScrollBy(testing::_
,
1840 testing::Property(&gfx::Vector2dF::x
,
1841 testing::Eq(expected_delta
))))
1842 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1843 input_handler_
->Animate(time
);
1844 last_animate_time
= time
;
1846 VERIFY_AND_RESET_MOCKS();
1848 // GestureFlingStart in the same direction and at sufficient speed should
1849 // boost the active fling.
1851 gesture_
= CreateFling(time
,
1852 blink::WebGestureDeviceTouchscreen
,
1857 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1858 VERIFY_AND_RESET_MOCKS();
1861 // Note we get *2x* as much delta because 2 flings have combined.
1862 expected_delta
= 2 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1863 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1864 EXPECT_CALL(mock_input_handler_
,
1865 ScrollBy(testing::_
,
1866 testing::Property(&gfx::Vector2dF::x
,
1867 testing::Eq(expected_delta
))))
1868 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1869 input_handler_
->Animate(time
);
1870 last_animate_time
= time
;
1872 VERIFY_AND_RESET_MOCKS();
1874 // Repeated GestureFlingStarts should accumulate.
1877 gesture_
= CreateFling(time
,
1878 blink::WebGestureDeviceTouchscreen
,
1883 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1884 VERIFY_AND_RESET_MOCKS();
1887 // Note we get *3x* as much delta because 3 flings have combined.
1888 expected_delta
= 3 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1889 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
1890 EXPECT_CALL(mock_input_handler_
,
1891 ScrollBy(testing::_
,
1892 testing::Property(&gfx::Vector2dF::x
,
1893 testing::Eq(expected_delta
))))
1894 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1895 input_handler_
->Animate(time
);
1896 last_animate_time
= time
;
1898 VERIFY_AND_RESET_MOCKS();
1900 // GestureFlingCancel should terminate the fling if no boosting gestures are
1901 // received within the timeout window.
1904 gesture_
.timeStampSeconds
= InSecondsF(time
);
1905 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1906 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1908 VERIFY_AND_RESET_MOCKS();
1910 time
+= base::TimeDelta::FromMilliseconds(100);
1911 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1912 input_handler_
->Animate(time
);
1914 VERIFY_AND_RESET_MOCKS();
1917 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollTargetsDifferentLayer
) {
1918 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1919 base::TimeTicks time
= base::TimeTicks() + dt
;
1920 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1921 WebPoint fling_point
= WebPoint(7, 13);
1923 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1925 // Cancel the fling. The fling cancellation should be deferred to allow
1926 // fling boosting events to arrive.
1930 // If the GestureScrollBegin targets a different layer, the fling should be
1931 // cancelled and the scroll should be handled as usual.
1932 EXPECT_CALL(mock_input_handler_
,
1933 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1934 .WillOnce(testing::Return(false));
1935 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1936 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1937 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1940 gesture_
.timeStampSeconds
= InSecondsF(time
);
1941 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1942 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1944 VERIFY_AND_RESET_MOCKS();
1947 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollDelayed
) {
1948 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1949 base::TimeTicks time
= base::TimeTicks() + dt
;
1950 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1951 WebPoint fling_point
= WebPoint(7, 13);
1953 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1955 // Cancel the fling. The fling cancellation should be deferred to allow
1956 // fling boosting events to arrive.
1960 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1962 EXPECT_CALL(mock_input_handler_
,
1963 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1964 .WillOnce(testing::Return(true));
1967 gesture_
.timeStampSeconds
= InSecondsF(time
);
1968 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1969 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1971 VERIFY_AND_RESET_MOCKS();
1973 // If no GestureScrollUpdate or GestureFlingStart is received within the
1974 // timeout window, the fling should be cancelled and scrolling should resume.
1975 time
+= base::TimeDelta::FromMilliseconds(100);
1976 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1977 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1978 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1979 input_handler_
->Animate(time
);
1981 VERIFY_AND_RESET_MOCKS();
1984 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingInDifferentDirection
) {
1985 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1986 base::TimeTicks time
= base::TimeTicks() + dt
;
1987 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1988 WebPoint fling_point
= WebPoint(7, 13);
1990 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1992 // Cancel the fling. The fling cancellation should be deferred to allow
1993 // fling boosting events to arrive.
1997 // If the new fling is orthogonal to the existing fling, no boosting should
1998 // take place, with the new fling replacing the old.
1999 WebFloatPoint orthogonal_fling_delta
=
2000 WebFloatPoint(fling_delta
.y
, -fling_delta
.x
);
2001 gesture_
= CreateFling(time
,
2002 blink::WebGestureDeviceTouchscreen
,
2003 orthogonal_fling_delta
,
2007 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2009 VERIFY_AND_RESET_MOCKS();
2011 // Note that the new fling delta uses the orthogonal, unboosted fling
2014 float expected_delta
= dt
.InSecondsF() * -orthogonal_fling_delta
.y
;
2015 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
2016 EXPECT_CALL(mock_input_handler_
,
2017 ScrollBy(testing::_
,
2018 testing::Property(&gfx::Vector2dF::y
,
2019 testing::Eq(expected_delta
))))
2020 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2021 input_handler_
->Animate(time
);
2023 VERIFY_AND_RESET_MOCKS();
2026 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollInDifferentDirection
) {
2027 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
2028 base::TimeTicks time
= base::TimeTicks() + dt
;
2029 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
2030 WebPoint fling_point
= WebPoint(7, 13);
2032 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2034 // Cancel the fling. The fling cancellation should be deferred to allow
2035 // fling boosting events to arrive.
2039 // The GestureScrollBegin should be swallowed by the fling if it hits the same
2041 EXPECT_CALL(mock_input_handler_
,
2042 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
2043 .WillOnce(testing::Return(true));
2046 gesture_
.timeStampSeconds
= InSecondsF(time
);
2047 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
2048 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2050 VERIFY_AND_RESET_MOCKS();
2052 // If the GestureScrollUpdate is in a different direction than the fling,
2053 // the fling should be cancelled and scrolling should resume.
2055 gesture_
.timeStampSeconds
= InSecondsF(time
);
2056 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
2057 gesture_
.data
.scrollUpdate
.deltaX
= -fling_delta
.x
;
2058 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2059 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2060 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
2061 EXPECT_CALL(mock_input_handler_
,
2062 ScrollBy(testing::_
,
2063 testing::Property(&gfx::Vector2dF::x
,
2064 testing::Eq(fling_delta
.x
))))
2065 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2066 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2068 VERIFY_AND_RESET_MOCKS();
2071 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingTooSlow
) {
2072 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
2073 base::TimeTicks time
= base::TimeTicks() + dt
;
2074 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
2075 WebPoint fling_point
= WebPoint(7, 13);
2077 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2079 // Cancel the fling. The fling cancellation should be deferred to allow
2080 // fling boosting events to arrive.
2084 // If the new fling is too slow, no boosting should take place, with the new
2085 // fling replacing the old.
2086 WebFloatPoint small_fling_delta
= WebFloatPoint(100, 0);
2087 gesture_
= CreateFling(time
,
2088 blink::WebGestureDeviceTouchscreen
,
2093 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2095 VERIFY_AND_RESET_MOCKS();
2097 // Note that the new fling delta uses the *slow*, unboosted fling velocity.
2099 float expected_delta
= dt
.InSecondsF() * -small_fling_delta
.x
;
2100 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
2101 EXPECT_CALL(mock_input_handler_
,
2102 ScrollBy(testing::_
,
2103 testing::Property(&gfx::Vector2dF::x
,
2104 testing::Eq(expected_delta
))))
2105 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2106 input_handler_
->Animate(time
);
2108 VERIFY_AND_RESET_MOCKS();
2111 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfPreventBoostingFlagIsSet
) {
2112 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
2113 base::TimeTicks time
= base::TimeTicks() + dt
;
2114 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
2115 WebPoint fling_point
= WebPoint(7, 13);
2118 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2120 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2122 // Cancel the fling. The fling cancellation should not be deferred because of
2123 // prevent boosting flag set.
2124 gesture_
.data
.flingCancel
.preventBoosting
= true;
2128 // VERIFY_AND_RESET_MOCKS already called by CancelFling
2131 TEST_F(InputHandlerProxyTest
, FlingBoostTerminatedDuringScrollSequence
) {
2132 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
2133 base::TimeTicks time
= base::TimeTicks() + dt
;
2134 base::TimeTicks last_animate_time
= time
;
2135 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
2136 WebPoint fling_point
= WebPoint(7, 13);
2138 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2140 // Now cancel the fling. The fling cancellation should be deferred to allow
2141 // fling boosting events to arrive.
2145 // The GestureScrollBegin should be swallowed by the fling.
2147 gesture_
.timeStampSeconds
= InSecondsF(time
);
2148 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
2149 EXPECT_CALL(mock_input_handler_
,
2150 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
2151 .WillOnce(testing::Return(true));
2152 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2154 VERIFY_AND_RESET_MOCKS();
2156 // Now animate the fling to completion (in this case, the fling should
2157 // terminate because the input handler reports a failed scroll). As the fling
2158 // was cancelled during an active scroll sequence, a synthetic
2159 // GestureScrollBegin should be processed, resuming the scroll.
2161 float expected_delta
=
2162 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
2163 EXPECT_CALL(mock_input_handler_
,
2164 ScrollBy(testing::_
,
2165 testing::Property(&gfx::Vector2dF::x
,
2166 testing::Eq(expected_delta
))))
2167 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
2168 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2169 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2170 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
2171 input_handler_
->Animate(time
);
2173 VERIFY_AND_RESET_MOCKS();
2175 // Subsequent GestureScrollUpdates after the cancelled, boosted fling should
2176 // cause scrolling as usual.
2178 expected_delta
= 7.3f
;
2179 gesture_
.timeStampSeconds
= InSecondsF(time
);
2180 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
2181 gesture_
.data
.scrollUpdate
.deltaX
= -expected_delta
;
2182 EXPECT_CALL(mock_input_handler_
,
2183 ScrollBy(testing::_
,
2184 testing::Property(&gfx::Vector2dF::x
,
2185 testing::Eq(expected_delta
))))
2186 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2187 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2189 VERIFY_AND_RESET_MOCKS();
2191 // GestureScrollEnd should terminate the resumed scroll properly.
2193 gesture_
.timeStampSeconds
= InSecondsF(time
);
2194 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
2195 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2196 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2198 VERIFY_AND_RESET_MOCKS();
2201 TEST_F(InputHandlerProxyTest
, DidReceiveInputEvent_ForFling
) {
2202 testing::StrictMock
<MockInputHandlerProxyClientWithDidAnimateForInput
>
2204 input_handler_
.reset(
2205 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client
));
2207 gesture_
.type
= WebInputEvent::GestureFlingStart
;
2208 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
2209 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
2210 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
2211 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
2212 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2213 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
2214 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2215 EXPECT_EQ(InputHandlerProxy::DID_HANDLE
,
2216 input_handler_
->HandleInputEvent(gesture_
));
2217 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
2218 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2220 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimateInput());
2221 EXPECT_CALL(mock_client
, DidAnimateForInput());
2222 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
2223 input_handler_
->Animate(time
);
2225 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2229 } // namespace content