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
;
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 virtual ~MockInputHandler() {}
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(SetNeedsAnimate
, void());
87 MOCK_METHOD2(ScrollBegin
,
88 ScrollStatus(const gfx::Point
& viewport_point
,
89 cc::InputHandler::ScrollInputType type
));
90 MOCK_METHOD2(ScrollAnimated
,
91 ScrollStatus(const gfx::Point
& viewport_point
,
92 const gfx::Vector2dF
& scroll_delta
));
93 MOCK_METHOD2(ScrollBy
,
94 cc::InputHandlerScrollResult(
95 const gfx::Point
& viewport_point
,
96 const gfx::Vector2dF
& scroll_delta
));
97 MOCK_METHOD2(ScrollVerticallyByPage
,
98 bool(const gfx::Point
& viewport_point
,
99 cc::ScrollDirection direction
));
100 MOCK_METHOD0(ScrollEnd
, void());
101 MOCK_METHOD0(FlingScrollBegin
, cc::InputHandler::ScrollStatus());
103 virtual scoped_ptr
<cc::SwapPromiseMonitor
>
104 CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo
* latency
) override
{
105 return scoped_ptr
<cc::SwapPromiseMonitor
>();
108 cc::ScrollElasticityHelper
* CreateScrollElasticityHelper() override
{
112 virtual void BindToClient(cc::InputHandlerClient
* client
) override
{}
114 virtual void MouseMoveAt(const gfx::Point
& mouse_position
) override
{}
116 MOCK_METHOD2(IsCurrentlyScrollingLayerAt
,
117 bool(const gfx::Point
& point
,
118 cc::InputHandler::ScrollInputType type
));
120 MOCK_METHOD1(HaveWheelEventHandlersAt
, bool(const gfx::Point
& point
));
121 MOCK_METHOD1(DoTouchEventsBlockScrollAt
, bool(const gfx::Point
& point
));
123 virtual void SetRootLayerScrollOffsetDelegate(
124 cc::LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
)
127 virtual void OnRootLayerDelegatedScrollOffsetChanged() override
{}
129 DISALLOW_COPY_AND_ASSIGN(MockInputHandler
);
132 // A simple WebGestureCurve implementation that flings at a constant velocity
134 class FakeWebGestureCurve
: public blink::WebGestureCurve
{
136 FakeWebGestureCurve(const blink::WebFloatSize
& velocity
,
137 const blink::WebFloatSize
& cumulative_scroll
)
138 : velocity_(velocity
), cumulative_scroll_(cumulative_scroll
) {}
140 virtual ~FakeWebGestureCurve() {}
142 // Returns false if curve has finished and can no longer be applied.
143 virtual bool apply(double time
, blink::WebGestureCurveTarget
* target
) {
144 blink::WebFloatSize
displacement(velocity_
.width
* time
,
145 velocity_
.height
* time
);
146 blink::WebFloatSize
increment(
147 displacement
.width
- cumulative_scroll_
.width
,
148 displacement
.height
- cumulative_scroll_
.height
);
149 cumulative_scroll_
= displacement
;
150 // scrollBy() could delete this curve if the animation is over, so don't
151 // touch any member variables after making that call.
152 return target
->scrollBy(increment
, velocity_
);
156 blink::WebFloatSize velocity_
;
157 blink::WebFloatSize cumulative_scroll_
;
159 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve
);
162 class MockInputHandlerProxyClient
163 : public content::InputHandlerProxyClient
{
165 MockInputHandlerProxyClient() {}
166 virtual ~MockInputHandlerProxyClient() {}
168 virtual void WillShutdown() override
{}
170 MOCK_METHOD1(TransferActiveWheelFlingAnimation
,
171 void(const WebActiveWheelFlingParameters
&));
173 virtual blink::WebGestureCurve
* CreateFlingAnimationCurve(
174 WebGestureDevice deviceSource
,
175 const WebFloatPoint
& velocity
,
176 const WebSize
& cumulative_scroll
) override
{
177 return new FakeWebGestureCurve(
178 blink::WebFloatSize(velocity
.x
, velocity
.y
),
179 blink::WebFloatSize(cumulative_scroll
.width
, cumulative_scroll
.height
));
182 MOCK_METHOD1(DidOverscroll
, void(const DidOverscrollParams
&));
183 virtual void DidStopFlinging() override
{}
184 virtual void DidReceiveInputEvent(const blink::WebInputEvent
&) override
{}
185 virtual void DidAnimateForInput() override
{}
188 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient
);
191 class MockInputHandlerProxyClientWithDidReceiveInputEvent
192 : public MockInputHandlerProxyClient
{
194 MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
195 virtual ~MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
197 MOCK_METHOD1(DidReceiveInputEvent
, void(const blink::WebInputEvent
&));
198 MOCK_METHOD0(DidAnimateForInput
, void());
201 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClientWithDidReceiveInputEvent
);
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_
, SetNeedsAnimate());
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_
));
348 TEST_F(InputHandlerProxyTest
, GestureScrollOnMainThread
) {
349 // We should send all events to the widget for this gesture.
350 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
351 VERIFY_AND_RESET_MOCKS();
353 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
354 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
356 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
357 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
359 VERIFY_AND_RESET_MOCKS();
361 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
362 gesture_
.data
.scrollUpdate
.deltaY
= 40;
363 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
365 VERIFY_AND_RESET_MOCKS();
367 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
368 gesture_
.data
.scrollUpdate
.deltaY
= 0;
369 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
370 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
373 TEST_F(InputHandlerProxyTest
, GestureScrollIgnored
) {
374 // We shouldn't handle the GestureScrollBegin.
375 // Instead, we should get a DROP_EVENT result, indicating
376 // that we could determine that there's nothing that could scroll or otherwise
377 // react to this gesture sequence and thus we should drop the whole gesture
378 // sequence on the floor, except for the ScrollEnd.
379 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
380 VERIFY_AND_RESET_MOCKS();
382 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
383 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
385 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
386 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
388 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
389 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
390 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
391 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
394 TEST_F(InputHandlerProxyTest
, GesturePinch
) {
395 // We shouldn't send any events to the widget for this gesture.
396 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
397 VERIFY_AND_RESET_MOCKS();
399 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
400 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
401 .WillOnce(testing::Return(false));
402 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
403 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
405 VERIFY_AND_RESET_MOCKS();
407 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
408 gesture_
.data
.pinchUpdate
.scale
= 1.5;
411 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
412 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
414 VERIFY_AND_RESET_MOCKS();
416 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
417 gesture_
.data
.pinchUpdate
.scale
= 0.5;
420 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
421 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
423 VERIFY_AND_RESET_MOCKS();
425 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
426 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
427 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
430 TEST_F(InputHandlerProxyTest
, GesturePinchWithWheelHandler
) {
431 // We will send the synthetic wheel event to the widget.
432 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
433 VERIFY_AND_RESET_MOCKS();
435 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
436 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
437 .WillOnce(testing::Return(true));
438 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
440 VERIFY_AND_RESET_MOCKS();
442 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
443 gesture_
.data
.pinchUpdate
.scale
= 1.5;
446 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
448 VERIFY_AND_RESET_MOCKS();
450 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
451 gesture_
.data
.pinchUpdate
.scale
= 0.5;
454 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
456 VERIFY_AND_RESET_MOCKS();
458 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
459 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
462 TEST_F(InputHandlerProxyTest
, GesturePinchAfterScrollOnMainThread
) {
463 // Scrolls will start by being sent to the main thread.
464 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
465 VERIFY_AND_RESET_MOCKS();
467 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
468 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
470 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
471 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
473 VERIFY_AND_RESET_MOCKS();
475 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
476 gesture_
.data
.scrollUpdate
.deltaY
= 40;
477 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
479 // However, after the pinch gesture starts, they should go to the impl
481 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
482 VERIFY_AND_RESET_MOCKS();
484 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
485 EXPECT_CALL(mock_input_handler_
, HaveWheelEventHandlersAt(testing::_
))
486 .WillOnce(testing::Return(false));
487 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
488 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
490 VERIFY_AND_RESET_MOCKS();
492 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
493 gesture_
.data
.pinchUpdate
.scale
= 1.5;
496 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
497 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
499 VERIFY_AND_RESET_MOCKS();
501 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
502 gesture_
.data
.scrollUpdate
.deltaY
=
503 -40; // -Y means scroll down - i.e. in the +Y direction.
504 EXPECT_CALL(mock_input_handler_
,
506 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
507 .WillOnce(testing::Return(scroll_result_did_scroll_
));
508 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
510 VERIFY_AND_RESET_MOCKS();
512 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
513 gesture_
.data
.pinchUpdate
.scale
= 0.5;
516 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
517 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
519 VERIFY_AND_RESET_MOCKS();
521 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
522 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
523 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
525 // After the pinch gesture ends, they should go to back to the main
527 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
528 VERIFY_AND_RESET_MOCKS();
530 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
531 gesture_
.data
.scrollUpdate
.deltaY
= 0;
532 EXPECT_CALL(mock_input_handler_
, ScrollEnd())
533 .WillOnce(testing::Return());
534 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
537 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchpad
) {
538 // We shouldn't send any events to the widget for this gesture.
539 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
540 VERIFY_AND_RESET_MOCKS();
542 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
543 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
544 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
545 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
547 gesture_
.type
= WebInputEvent::GestureFlingStart
;
548 gesture_
.data
.flingStart
.velocityX
= 10;
549 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
550 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
552 VERIFY_AND_RESET_MOCKS();
554 // Verify that a GestureFlingCancel during an animation cancels it.
555 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
556 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
557 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
560 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchpad
) {
561 // We should send all events to the widget for this gesture.
562 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
563 VERIFY_AND_RESET_MOCKS();
565 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
566 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
568 gesture_
.type
= WebInputEvent::GestureFlingStart
;
569 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
570 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
572 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the
573 // input handler knows it's scrolling off the impl thread
574 ASSERT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
576 VERIFY_AND_RESET_MOCKS();
578 // Even if we didn't start a fling ourselves, we still need to send the cancel
579 // event to the widget.
580 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
581 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
582 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
585 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchpad
) {
586 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
587 VERIFY_AND_RESET_MOCKS();
589 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
590 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
592 gesture_
.type
= WebInputEvent::GestureFlingStart
;
593 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
594 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
596 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
597 VERIFY_AND_RESET_MOCKS();
599 // Since the previous fling was ignored, we should also be dropping the next
601 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
602 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
603 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
606 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchpad
) {
607 // We shouldn't send any events to the widget for this gesture.
608 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
609 VERIFY_AND_RESET_MOCKS();
611 // On the fling start, we should schedule an animation but not actually start
613 gesture_
.type
= WebInputEvent::GestureFlingStart
;
614 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
615 WebPoint fling_point
= WebPoint(7, 13);
616 WebPoint fling_global_point
= WebPoint(17, 23);
617 // Note that for trackpad, wheel events with the Control modifier are
618 // special (reserved for zoom), so don't set that here.
619 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
620 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
625 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
626 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
627 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
628 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
629 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
631 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
632 // The first animate call should let us pick up an animation start time, but
633 // we shouldn't actually move anywhere just yet. The first frame after the
634 // fling start will typically include the last scroll from the gesture that
635 // lead to the scroll (either wheel or gesture scroll), so there should be no
637 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
638 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
640 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
641 input_handler_
->Animate(time
);
643 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
645 // The second call should start scrolling in the -X direction.
646 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
647 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
648 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
649 EXPECT_CALL(mock_input_handler_
,
651 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
652 .WillOnce(testing::Return(scroll_result_did_scroll_
));
653 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
654 time
+= base::TimeDelta::FromMilliseconds(100);
655 input_handler_
->Animate(time
);
657 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
659 // Let's say on the third call we hit a non-scrollable region. We should abort
660 // the fling and not scroll.
661 // We also should pass the current fling parameters out to the client so the
662 // rest of the fling can be
663 // transferred to the main thread.
664 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
665 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
666 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
667 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
668 // Expected wheel fling animation parameters:
669 // *) fling_delta and fling_point should match the original GestureFlingStart
671 // *) startTime should be 10 to match the time parameter of the first
672 // Animate() call after the GestureFlingStart
673 // *) cumulativeScroll depends on the curve, but since we've animated in the
674 // -X direction the X value should be < 0
677 TransferActiveWheelFlingAnimation(testing::AllOf(
678 testing::Field(&WebActiveWheelFlingParameters::delta
,
679 testing::Eq(fling_delta
)),
680 testing::Field(&WebActiveWheelFlingParameters::point
,
681 testing::Eq(fling_point
)),
682 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
683 testing::Eq(fling_global_point
)),
684 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
685 testing::Eq(modifiers
)),
686 testing::Field(&WebActiveWheelFlingParameters::startTime
,
688 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
689 testing::Field(&WebSize::width
, testing::Gt(0))))));
690 time
+= base::TimeDelta::FromMilliseconds(100);
691 input_handler_
->Animate(time
);
693 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
694 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
696 // Since we've aborted the fling, the next animation should be a no-op and
697 // should not result in another
698 // frame being requested.
699 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
700 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
702 time
+= base::TimeDelta::FromMilliseconds(100);
703 input_handler_
->Animate(time
);
705 // Since we've transferred the fling to the main thread, we need to pass the
706 // next GestureFlingCancel to the main
708 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
709 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
710 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
713 TEST_F(InputHandlerProxyTest
, GestureFlingTransferResetsTouchpad
) {
714 // We shouldn't send any events to the widget for this gesture.
715 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
716 VERIFY_AND_RESET_MOCKS();
718 // Start a gesture fling in the -X direction with zero Y movement.
719 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
720 WebPoint fling_point
= WebPoint(7, 13);
721 WebPoint fling_global_point
= WebPoint(17, 23);
722 // Note that for trackpad, wheel events with the Control modifier are
723 // special (reserved for zoom), so don't set that here.
724 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
725 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
730 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
731 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
732 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
733 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
734 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
736 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
738 // Start the fling animation at time 10. This shouldn't actually scroll, just
739 // establish a start time.
740 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
741 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
743 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
744 input_handler_
->Animate(time
);
746 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
748 // The second call should start scrolling in the -X direction.
749 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
750 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
751 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
752 EXPECT_CALL(mock_input_handler_
,
754 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
755 .WillOnce(testing::Return(scroll_result_did_scroll_
));
756 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
757 time
+= base::TimeDelta::FromMilliseconds(100);
758 input_handler_
->Animate(time
);
760 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
762 // Let's say on the third call we hit a non-scrollable region. We should abort
763 // the fling and not scroll.
764 // We also should pass the current fling parameters out to the client so the
765 // rest of the fling can be
766 // transferred to the main thread.
767 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
768 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
769 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
770 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
772 // Expected wheel fling animation parameters:
773 // *) fling_delta and fling_point should match the original GestureFlingStart
775 // *) startTime should be 10 to match the time parameter of the first
776 // Animate() call after the GestureFlingStart
777 // *) cumulativeScroll depends on the curve, but since we've animated in the
778 // -X direction the X value should be < 0
781 TransferActiveWheelFlingAnimation(testing::AllOf(
782 testing::Field(&WebActiveWheelFlingParameters::delta
,
783 testing::Eq(fling_delta
)),
784 testing::Field(&WebActiveWheelFlingParameters::point
,
785 testing::Eq(fling_point
)),
786 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
787 testing::Eq(fling_global_point
)),
788 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
789 testing::Eq(modifiers
)),
790 testing::Field(&WebActiveWheelFlingParameters::startTime
,
792 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
793 testing::Field(&WebSize::width
, testing::Gt(0))))));
794 time
+= base::TimeDelta::FromMilliseconds(100);
795 input_handler_
->Animate(time
);
797 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
798 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
800 // Since we've aborted the fling, the next animation should be a no-op and
801 // should not result in another
802 // frame being requested.
803 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
804 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
806 time
+= base::TimeDelta::FromMilliseconds(100);
807 input_handler_
->Animate(time
);
809 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
811 // Since we've transferred the fling to the main thread, we need to pass the
812 // next GestureFlingCancel to the main
814 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
815 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
816 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
818 VERIFY_AND_RESET_MOCKS();
819 input_handler_
->MainThreadHasStoppedFlinging();
821 // Start a second gesture fling, this time in the +Y direction with no X.
822 fling_delta
= WebFloatPoint(0, -1000);
823 fling_point
= WebPoint(95, 87);
824 fling_global_point
= WebPoint(32, 71);
825 modifiers
= WebInputEvent::AltKey
;
826 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
831 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
832 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
833 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
834 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
835 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
836 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
838 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
840 // Start the second fling animation at time 30.
841 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
842 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
844 time
= base::TimeTicks() + base::TimeDelta::FromSeconds(30);
845 input_handler_
->Animate(time
);
847 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
849 // Tick the second fling once normally.
850 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
851 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
852 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
853 EXPECT_CALL(mock_input_handler_
,
855 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
856 .WillOnce(testing::Return(scroll_result_did_scroll_
));
857 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
858 time
+= base::TimeDelta::FromMilliseconds(100);
859 input_handler_
->Animate(time
);
861 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
863 // Then abort the second fling.
864 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
865 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
866 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
867 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
869 // We should get parameters from the second fling, nothing from the first
870 // fling should "leak".
873 TransferActiveWheelFlingAnimation(testing::AllOf(
874 testing::Field(&WebActiveWheelFlingParameters::delta
,
875 testing::Eq(fling_delta
)),
876 testing::Field(&WebActiveWheelFlingParameters::point
,
877 testing::Eq(fling_point
)),
878 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
879 testing::Eq(fling_global_point
)),
880 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
881 testing::Eq(modifiers
)),
882 testing::Field(&WebActiveWheelFlingParameters::startTime
,
884 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
885 testing::Field(&WebSize::height
, testing::Lt(0))))));
886 time
+= base::TimeDelta::FromMilliseconds(100);
887 input_handler_
->Animate(time
);
890 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchscreen
) {
891 // We shouldn't send any events to the widget for this gesture.
892 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
893 VERIFY_AND_RESET_MOCKS();
895 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
896 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
897 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
898 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
899 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
901 VERIFY_AND_RESET_MOCKS();
903 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
904 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
905 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
907 gesture_
.type
= WebInputEvent::GestureFlingStart
;
908 gesture_
.data
.flingStart
.velocityX
= 10;
909 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
910 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
912 VERIFY_AND_RESET_MOCKS();
914 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
916 // Verify that a GestureFlingCancel during an animation cancels it.
917 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
918 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
919 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
922 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchscreen
) {
923 // We should send all events to the widget for this gesture.
924 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
925 VERIFY_AND_RESET_MOCKS();
927 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
928 .WillOnce(testing::Return(cc::InputHandler::SCROLL_ON_MAIN_THREAD
));
930 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
931 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
933 VERIFY_AND_RESET_MOCKS();
935 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin()).Times(0);
937 gesture_
.type
= WebInputEvent::GestureFlingStart
;
938 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
939 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
941 VERIFY_AND_RESET_MOCKS();
943 // Even if we didn't start a fling ourselves, we still need to send the cancel
944 // event to the widget.
945 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
946 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
947 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
950 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchscreen
) {
951 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
952 VERIFY_AND_RESET_MOCKS();
954 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
955 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
957 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
958 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
959 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
961 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
962 VERIFY_AND_RESET_MOCKS();
964 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
965 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED
));
967 gesture_
.type
= WebInputEvent::GestureFlingStart
;
968 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
969 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
971 VERIFY_AND_RESET_MOCKS();
973 // Even if we didn't start a fling ourselves, we still need to send the cancel
974 // event to the widget.
975 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
976 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
977 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
980 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchscreen
) {
981 // We shouldn't send any events to the widget for this gesture.
982 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
983 VERIFY_AND_RESET_MOCKS();
985 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
986 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
988 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
989 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
990 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
992 VERIFY_AND_RESET_MOCKS();
994 // On the fling start, we should schedule an animation but not actually start
996 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
997 WebPoint fling_point
= WebPoint(7, 13);
998 WebPoint fling_global_point
= WebPoint(17, 23);
999 // Note that for touchscreen the control modifier is not special.
1000 int modifiers
= WebInputEvent::ControlKey
;
1001 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
1006 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1007 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1008 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1009 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1011 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1012 // The first animate call should let us pick up an animation start time, but
1013 // we shouldn't actually move anywhere just yet. The first frame after the
1014 // fling start will typically include the last scroll from the gesture that
1015 // lead to the scroll (either wheel or gesture scroll), so there should be no
1017 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1018 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1019 input_handler_
->Animate(time
);
1021 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1023 // The second call should start scrolling in the -X direction.
1024 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1025 EXPECT_CALL(mock_input_handler_
,
1026 ScrollBy(testing::_
,
1027 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1028 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1029 time
+= base::TimeDelta::FromMilliseconds(100);
1030 input_handler_
->Animate(time
);
1032 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1034 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1035 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1036 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1039 TEST_F(InputHandlerProxyTest
, GestureFlingWithValidTimestamp
) {
1040 // We shouldn't send any events to the widget for this gesture.
1041 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1042 VERIFY_AND_RESET_MOCKS();
1044 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1045 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1047 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1048 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1049 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1051 VERIFY_AND_RESET_MOCKS();
1053 // On the fling start, we should schedule an animation but not actually start
1055 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1056 base::TimeTicks time
= base::TimeTicks() + dt
;
1057 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1058 WebPoint fling_point
= WebPoint(7, 13);
1059 WebPoint fling_global_point
= WebPoint(17, 23);
1060 int modifiers
= WebInputEvent::ControlKey
;
1061 gesture_
= CreateFling(time
,
1062 blink::WebGestureDeviceTouchscreen
,
1067 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1068 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1069 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1070 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1072 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1073 // With a valid time stamp, the first animate call should skip start time
1074 // initialization and immediately begin scroll update production. This reduces
1075 // the likelihood of a hitch between the scroll preceding the fling and
1076 // the first scroll generated by the fling.
1077 // Scrolling should start in the -X direction.
1078 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1079 EXPECT_CALL(mock_input_handler_
,
1080 ScrollBy(testing::_
,
1081 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1082 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1084 input_handler_
->Animate(time
);
1086 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1088 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1089 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1090 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1093 TEST_F(InputHandlerProxyTest
, GestureFlingWithInvalidTimestamp
) {
1094 // We shouldn't send any events to the widget for this gesture.
1095 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1096 VERIFY_AND_RESET_MOCKS();
1098 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1099 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1101 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1102 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1103 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1105 VERIFY_AND_RESET_MOCKS();
1107 // On the fling start, we should schedule an animation but not actually start
1109 base::TimeDelta start_time_offset
= base::TimeDelta::FromMilliseconds(10);
1110 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1111 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1112 WebPoint fling_point
= WebPoint(7, 13);
1113 WebPoint fling_global_point
= WebPoint(17, 23);
1114 int modifiers
= WebInputEvent::ControlKey
;
1115 gesture_
.timeStampSeconds
= start_time_offset
.InSecondsF();
1116 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1117 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1118 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1119 gesture_
.x
= fling_point
.x
;
1120 gesture_
.y
= fling_point
.y
;
1121 gesture_
.globalX
= fling_global_point
.x
;
1122 gesture_
.globalY
= fling_global_point
.y
;
1123 gesture_
.modifiers
= modifiers
;
1124 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1125 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1126 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1127 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1129 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1130 // Event though a time stamp was provided for the fling event, it will be
1131 // ignored as its too far in the past relative to the first animate call's
1133 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1134 base::TimeTicks time
=
1135 base::TimeTicks() + start_time_offset
+ base::TimeDelta::FromSeconds(1);
1136 input_handler_
->Animate(time
);
1138 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1140 // Further animation ticks should update the fling as usual.
1141 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1142 EXPECT_CALL(mock_input_handler_
,
1143 ScrollBy(testing::_
,
1144 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1145 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1146 time
+= base::TimeDelta::FromMilliseconds(10);
1147 input_handler_
->Animate(time
);
1149 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1151 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1152 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1153 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1156 TEST_F(InputHandlerProxyTest
,
1157 GestureScrollOnImplThreadFlagClearedAfterFling
) {
1158 // We shouldn't send any events to the widget for this gesture.
1159 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1160 VERIFY_AND_RESET_MOCKS();
1162 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1163 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1165 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1166 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1168 // After sending a GestureScrollBegin, the member variable
1169 // |gesture_scroll_on_impl_thread_| should be true.
1170 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1172 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1173 VERIFY_AND_RESET_MOCKS();
1175 // On the fling start, we should schedule an animation but not actually start
1177 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1178 WebPoint fling_point
= WebPoint(7, 13);
1179 WebPoint fling_global_point
= WebPoint(17, 23);
1180 int modifiers
= WebInputEvent::ControlKey
| WebInputEvent::AltKey
;
1181 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
1186 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1187 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1188 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1189 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1191 // |gesture_scroll_on_impl_thread_| should still be true after
1192 // a GestureFlingStart is sent.
1193 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1195 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1196 // The first animate call should let us pick up an animation start time, but
1197 // we shouldn't actually move anywhere just yet. The first frame after the
1198 // fling start will typically include the last scroll from the gesture that
1199 // lead to the scroll (either wheel or gesture scroll), so there should be no
1201 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1202 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1203 input_handler_
->Animate(time
);
1205 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1207 // The second call should start scrolling in the -X direction.
1208 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1209 EXPECT_CALL(mock_input_handler_
,
1210 ScrollBy(testing::_
,
1211 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1212 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1213 time
+= base::TimeDelta::FromMilliseconds(100);
1214 input_handler_
->Animate(time
);
1216 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1218 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1219 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1220 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1222 // |gesture_scroll_on_impl_thread_| should be false once
1223 // the fling has finished (note no GestureScrollEnd has been sent).
1224 EXPECT_TRUE(!input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1227 TEST_F(InputHandlerProxyTest
, GestureFlingStopsAtContentEdge
) {
1228 // We shouldn't send any events to the widget for this gesture.
1229 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1230 VERIFY_AND_RESET_MOCKS();
1232 // On the fling start, we should schedule an animation but not actually start
1234 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1235 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1236 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1237 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1238 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1239 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1240 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1241 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1242 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1243 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1245 // The first animate doesn't cause any scrolling.
1246 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1247 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1248 input_handler_
->Animate(time
);
1249 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1251 // The second animate starts scrolling in the positive X and Y directions.
1252 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1253 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1254 EXPECT_CALL(mock_input_handler_
,
1255 ScrollBy(testing::_
,
1256 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1257 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1258 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1259 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1260 time
+= base::TimeDelta::FromMilliseconds(100);
1261 input_handler_
->Animate(time
);
1262 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1264 // The third animate overscrolls in the positive Y direction but scrolls
1266 cc::InputHandlerScrollResult overscroll
;
1267 overscroll
.did_scroll
= true;
1268 overscroll
.did_overscroll_root
= true;
1269 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1270 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 10);
1271 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1272 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1273 EXPECT_CALL(mock_input_handler_
,
1274 ScrollBy(testing::_
,
1275 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1276 .WillOnce(testing::Return(overscroll
));
1279 DidOverscroll(testing::AllOf(
1281 &DidOverscrollParams::accumulated_overscroll
,
1282 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1284 &DidOverscrollParams::latest_overscroll_delta
,
1285 testing::Eq(overscroll
.unused_scroll_delta
)),
1287 &DidOverscrollParams::current_fling_velocity
,
1288 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1289 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1290 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1291 time
+= base::TimeDelta::FromMilliseconds(100);
1292 input_handler_
->Animate(time
);
1293 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1295 // The next call to animate will no longer scroll vertically.
1296 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1297 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1298 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1299 EXPECT_CALL(mock_input_handler_
,
1300 ScrollBy(testing::_
,
1301 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1302 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1303 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1304 time
+= base::TimeDelta::FromMilliseconds(100);
1305 input_handler_
->Animate(time
);
1306 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1309 TEST_F(InputHandlerProxyTest
, GestureFlingNotCancelledBySmallTimeDelta
) {
1310 // We shouldn't send any events to the widget for this gesture.
1311 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1312 VERIFY_AND_RESET_MOCKS();
1314 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1315 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1317 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1318 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1319 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1321 VERIFY_AND_RESET_MOCKS();
1323 // On the fling start, we should schedule an animation but not actually start
1325 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1326 base::TimeTicks time
= base::TimeTicks() + dt
;
1327 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1328 WebPoint fling_point
= WebPoint(7, 13);
1329 WebPoint fling_global_point
= WebPoint(17, 23);
1330 int modifiers
= WebInputEvent::ControlKey
;
1331 gesture_
= CreateFling(time
,
1332 blink::WebGestureDeviceTouchscreen
,
1337 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1338 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1339 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1340 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1342 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1343 // With an animation timestamp equivalent to the starting timestamp, the
1344 // animation will simply be rescheduled.
1345 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1346 input_handler_
->Animate(time
);
1348 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1349 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1351 // A small time delta should not stop the fling, even if the client
1352 // reports no scrolling.
1353 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1354 EXPECT_CALL(mock_input_handler_
,
1355 ScrollBy(testing::_
,
1356 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1357 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1358 time
+= base::TimeDelta::FromMicroseconds(5);
1359 input_handler_
->Animate(time
);
1361 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1362 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1364 // A time delta of zero should not stop the fling, and neither should it
1365 // trigger scrolling on the client.
1366 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1367 input_handler_
->Animate(time
);
1369 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1370 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1372 // Lack of movement on the client, with a non-trivial scroll delta, should
1373 // terminate the fling.
1374 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1375 EXPECT_CALL(mock_input_handler_
,
1376 ScrollBy(testing::_
,
1377 testing::Property(&gfx::Vector2dF::x
, testing::Lt(1))))
1378 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1379 time
+= base::TimeDelta::FromMilliseconds(100);
1380 input_handler_
->Animate(time
);
1382 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1383 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1386 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledAfterBothAxesStopScrolling
) {
1387 cc::InputHandlerScrollResult overscroll
;
1388 overscroll
.did_scroll
= true;
1389 overscroll
.did_overscroll_root
= true;
1391 // We shouldn't send any events to the widget for this gesture.
1392 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1393 VERIFY_AND_RESET_MOCKS();
1395 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1396 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1397 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1398 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1399 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1400 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1402 // On the fling start, we should schedule an animation but not actually start
1404 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1405 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1406 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1407 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1408 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1409 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1410 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1411 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1412 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1414 // The first animate doesn't cause any scrolling.
1415 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1416 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1417 input_handler_
->Animate(time
);
1418 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1420 // The second animate starts scrolling in the positive X and Y directions.
1421 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1422 EXPECT_CALL(mock_input_handler_
,
1423 ScrollBy(testing::_
,
1424 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1425 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1426 time
+= base::TimeDelta::FromMilliseconds(10);
1427 input_handler_
->Animate(time
);
1428 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1430 // The third animate hits the bottom content edge.
1431 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1432 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 100);
1433 EXPECT_CALL(mock_input_handler_
,
1434 ScrollBy(testing::_
,
1435 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1436 .WillOnce(testing::Return(overscroll
));
1439 DidOverscroll(testing::AllOf(
1441 &DidOverscrollParams::accumulated_overscroll
,
1442 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1444 &DidOverscrollParams::latest_overscroll_delta
,
1445 testing::Eq(overscroll
.unused_scroll_delta
)),
1447 &DidOverscrollParams::current_fling_velocity
,
1448 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1449 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1450 time
+= base::TimeDelta::FromMilliseconds(10);
1451 input_handler_
->Animate(time
);
1452 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1454 // The next call to animate will no longer scroll vertically.
1455 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1456 EXPECT_CALL(mock_input_handler_
,
1457 ScrollBy(testing::_
,
1458 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1459 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1460 time
+= base::TimeDelta::FromMilliseconds(10);
1461 input_handler_
->Animate(time
);
1462 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1464 // The next call will hit the right edge.
1465 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(100, 100);
1466 overscroll
.unused_scroll_delta
= gfx::Vector2dF(100, 0);
1467 EXPECT_CALL(mock_input_handler_
,
1468 ScrollBy(testing::_
,
1469 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1470 .WillOnce(testing::Return(overscroll
));
1473 DidOverscroll(testing::AllOf(
1475 &DidOverscrollParams::accumulated_overscroll
,
1476 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1478 &DidOverscrollParams::latest_overscroll_delta
,
1479 testing::Eq(overscroll
.unused_scroll_delta
)),
1481 &DidOverscrollParams::current_fling_velocity
,
1482 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))));
1483 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1484 time
+= base::TimeDelta::FromMilliseconds(10);
1485 input_handler_
->Animate(time
);
1486 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1488 // The next call to animate will no longer scroll horizontally or vertically,
1489 // and the fling should be cancelled.
1490 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
1491 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
1492 time
+= base::TimeDelta::FromMilliseconds(10);
1493 input_handler_
->Animate(time
);
1494 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1495 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1498 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestNegative
) {
1499 // None of the three touch points fall in the touch region. So the event
1500 // should be dropped.
1501 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
1502 VERIFY_AND_RESET_MOCKS();
1504 EXPECT_CALL(mock_input_handler_
,
1505 DoTouchEventsBlockScrollAt(
1506 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1507 .WillOnce(testing::Return(false));
1508 EXPECT_CALL(mock_input_handler_
,
1509 DoTouchEventsBlockScrollAt(
1510 testing::Property(&gfx::Point::x
, testing::Lt(0))))
1511 .WillOnce(testing::Return(false));
1513 WebTouchEvent touch
;
1514 touch
.type
= WebInputEvent::TouchStart
;
1516 touch
.touchesLength
= 3;
1517 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary
, 0, 0);
1518 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1519 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1520 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1523 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestPositive
) {
1524 // One of the touch points is on a touch-region. So the event should be sent
1525 // to the main thread.
1526 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
1527 VERIFY_AND_RESET_MOCKS();
1529 EXPECT_CALL(mock_input_handler_
,
1530 DoTouchEventsBlockScrollAt(
1531 testing::Property(&gfx::Point::x
, testing::Eq(0))))
1532 .WillOnce(testing::Return(false));
1533 EXPECT_CALL(mock_input_handler_
,
1534 DoTouchEventsBlockScrollAt(
1535 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1536 .WillOnce(testing::Return(true));
1537 // Since the second touch point hits a touch-region, there should be no
1538 // hit-testing for the third touch point.
1540 WebTouchEvent touch
;
1541 touch
.type
= WebInputEvent::TouchStart
;
1543 touch
.touchesLength
= 3;
1544 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 0, 0);
1545 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1546 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1547 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1550 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledByKeyboardEvent
) {
1551 // We shouldn't send any events to the widget for this gesture.
1552 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1553 VERIFY_AND_RESET_MOCKS();
1555 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1556 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1557 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1558 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1559 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1560 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1561 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1563 // Keyboard events received during a scroll should have no effect.
1564 WebKeyboardEvent key_event
;
1565 key_event
.type
= WebInputEvent::KeyDown
;
1566 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1567 input_handler_
->HandleInputEvent(key_event
));
1568 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1569 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1571 // On the fling start, animation should be scheduled, but no scrolling occurs.
1572 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1573 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1574 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1575 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1576 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1577 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1578 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1579 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1580 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1581 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1583 // Keyboard events received during a fling should cancel the active fling.
1584 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1585 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1586 input_handler_
->HandleInputEvent(key_event
));
1587 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1588 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1590 // The call to animate should have no effect, as the fling was cancelled.
1591 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1592 input_handler_
->Animate(time
);
1593 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1595 // A fling cancel should be dropped, as there is nothing to cancel.
1596 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1597 EXPECT_EQ(InputHandlerProxy::DROP_EVENT
,
1598 input_handler_
->HandleInputEvent(gesture_
));
1599 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1602 TEST_F(InputHandlerProxyTest
, GestureFlingWithNegativeTimeDelta
) {
1603 // We shouldn't send any events to the widget for this gesture.
1604 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1605 VERIFY_AND_RESET_MOCKS();
1607 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1608 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1610 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1611 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1612 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1614 VERIFY_AND_RESET_MOCKS();
1616 // On the fling start, we should schedule an animation but not actually start
1618 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1619 base::TimeTicks time
= base::TimeTicks() + dt
;
1620 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1621 WebPoint fling_point
= WebPoint(7, 13);
1622 WebPoint fling_global_point
= WebPoint(17, 23);
1623 int modifiers
= WebInputEvent::ControlKey
;
1624 gesture_
= CreateFling(time
,
1625 blink::WebGestureDeviceTouchscreen
,
1630 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1631 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1632 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1633 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1635 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1637 // If we get a negative time delta, that is, the Animation tick time happens
1638 // before the fling's start time then we should *not* try scrolling and
1639 // instead reset the fling start time.
1640 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1641 EXPECT_CALL(mock_input_handler_
,
1642 ScrollBy(testing::_
,
1643 testing::_
)).Times(0);
1644 time
-= base::TimeDelta::FromMilliseconds(5);
1645 input_handler_
->Animate(time
);
1647 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1649 // The first call should have reset the start time so subsequent calls should
1650 // generate scroll events.
1651 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1652 EXPECT_CALL(mock_input_handler_
,
1653 ScrollBy(testing::_
,
1654 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1655 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1657 input_handler_
->Animate(time
+ base::TimeDelta::FromMilliseconds(1));
1659 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1661 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1662 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1663 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1666 TEST_F(InputHandlerProxyTest
, FlingBoost
) {
1667 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1668 base::TimeTicks time
= base::TimeTicks() + dt
;
1669 base::TimeTicks last_animate_time
= time
;
1670 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1671 WebPoint fling_point
= WebPoint(7, 13);
1673 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1675 // Now cancel the fling. The fling cancellation should be deferred to allow
1676 // fling boosting events to arrive.
1680 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1682 EXPECT_CALL(mock_input_handler_
,
1683 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1684 .WillOnce(testing::Return(true));
1687 gesture_
.timeStampSeconds
= InSecondsF(time
);
1688 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1689 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1691 VERIFY_AND_RESET_MOCKS();
1693 // Animate calls within the deferred cancellation window should continue.
1695 float expected_delta
=
1696 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1697 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1698 EXPECT_CALL(mock_input_handler_
,
1699 ScrollBy(testing::_
,
1700 testing::Property(&gfx::Vector2dF::x
,
1701 testing::Eq(expected_delta
))))
1702 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1703 input_handler_
->Animate(time
);
1704 last_animate_time
= time
;
1706 VERIFY_AND_RESET_MOCKS();
1708 // GestureScrollUpdates in the same direction and at sufficient speed should
1709 // be swallowed by the fling.
1711 gesture_
.timeStampSeconds
= InSecondsF(time
);
1712 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
1713 gesture_
.data
.scrollUpdate
.deltaX
= fling_delta
.x
;
1714 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1716 VERIFY_AND_RESET_MOCKS();
1718 // Animate calls within the deferred cancellation window should continue.
1720 expected_delta
= (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1721 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1722 EXPECT_CALL(mock_input_handler_
,
1723 ScrollBy(testing::_
,
1724 testing::Property(&gfx::Vector2dF::x
,
1725 testing::Eq(expected_delta
))))
1726 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1727 input_handler_
->Animate(time
);
1728 last_animate_time
= time
;
1730 VERIFY_AND_RESET_MOCKS();
1732 // GestureFlingStart in the same direction and at sufficient speed should
1733 // boost the active fling.
1735 gesture_
= CreateFling(time
,
1736 blink::WebGestureDeviceTouchscreen
,
1741 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1742 VERIFY_AND_RESET_MOCKS();
1745 // Note we get *2x* as much delta because 2 flings have combined.
1746 expected_delta
= 2 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1747 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1748 EXPECT_CALL(mock_input_handler_
,
1749 ScrollBy(testing::_
,
1750 testing::Property(&gfx::Vector2dF::x
,
1751 testing::Eq(expected_delta
))))
1752 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1753 input_handler_
->Animate(time
);
1754 last_animate_time
= time
;
1756 VERIFY_AND_RESET_MOCKS();
1758 // Repeated GestureFlingStarts should accumulate.
1761 gesture_
= CreateFling(time
,
1762 blink::WebGestureDeviceTouchscreen
,
1767 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1768 VERIFY_AND_RESET_MOCKS();
1771 // Note we get *3x* as much delta because 3 flings have combined.
1772 expected_delta
= 3 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1773 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1774 EXPECT_CALL(mock_input_handler_
,
1775 ScrollBy(testing::_
,
1776 testing::Property(&gfx::Vector2dF::x
,
1777 testing::Eq(expected_delta
))))
1778 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1779 input_handler_
->Animate(time
);
1780 last_animate_time
= time
;
1782 VERIFY_AND_RESET_MOCKS();
1784 // GestureFlingCancel should terminate the fling if no boosting gestures are
1785 // received within the timeout window.
1788 gesture_
.timeStampSeconds
= InSecondsF(time
);
1789 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1790 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1792 VERIFY_AND_RESET_MOCKS();
1794 time
+= base::TimeDelta::FromMilliseconds(100);
1795 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1796 input_handler_
->Animate(time
);
1798 VERIFY_AND_RESET_MOCKS();
1801 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollTargetsDifferentLayer
) {
1802 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1803 base::TimeTicks time
= base::TimeTicks() + dt
;
1804 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1805 WebPoint fling_point
= WebPoint(7, 13);
1807 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1809 // Cancel the fling. The fling cancellation should be deferred to allow
1810 // fling boosting events to arrive.
1814 // If the GestureScrollBegin targets a different layer, the fling should be
1815 // cancelled and the scroll should be handled as usual.
1816 EXPECT_CALL(mock_input_handler_
,
1817 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1818 .WillOnce(testing::Return(false));
1819 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1820 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1821 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1824 gesture_
.timeStampSeconds
= InSecondsF(time
);
1825 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1826 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1828 VERIFY_AND_RESET_MOCKS();
1831 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollDelayed
) {
1832 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1833 base::TimeTicks time
= base::TimeTicks() + dt
;
1834 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1835 WebPoint fling_point
= WebPoint(7, 13);
1837 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1839 // Cancel the fling. The fling cancellation should be deferred to allow
1840 // fling boosting events to arrive.
1844 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1846 EXPECT_CALL(mock_input_handler_
,
1847 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1848 .WillOnce(testing::Return(true));
1851 gesture_
.timeStampSeconds
= InSecondsF(time
);
1852 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1853 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1855 VERIFY_AND_RESET_MOCKS();
1857 // If no GestureScrollUpdate or GestureFlingStart is received within the
1858 // timeout window, the fling should be cancelled and scrolling should resume.
1859 time
+= base::TimeDelta::FromMilliseconds(100);
1860 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1861 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1862 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1863 input_handler_
->Animate(time
);
1865 VERIFY_AND_RESET_MOCKS();
1868 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingInDifferentDirection
) {
1869 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1870 base::TimeTicks time
= base::TimeTicks() + dt
;
1871 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1872 WebPoint fling_point
= WebPoint(7, 13);
1874 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1876 // Cancel the fling. The fling cancellation should be deferred to allow
1877 // fling boosting events to arrive.
1881 // If the new fling is orthogonal to the existing fling, no boosting should
1882 // take place, with the new fling replacing the old.
1883 WebFloatPoint orthogonal_fling_delta
=
1884 WebFloatPoint(fling_delta
.y
, -fling_delta
.x
);
1885 gesture_
= CreateFling(time
,
1886 blink::WebGestureDeviceTouchscreen
,
1887 orthogonal_fling_delta
,
1891 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1893 VERIFY_AND_RESET_MOCKS();
1895 // Note that the new fling delta uses the orthogonal, unboosted fling
1898 float expected_delta
= dt
.InSecondsF() * -orthogonal_fling_delta
.y
;
1899 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1900 EXPECT_CALL(mock_input_handler_
,
1901 ScrollBy(testing::_
,
1902 testing::Property(&gfx::Vector2dF::y
,
1903 testing::Eq(expected_delta
))))
1904 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1905 input_handler_
->Animate(time
);
1907 VERIFY_AND_RESET_MOCKS();
1910 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollInDifferentDirection
) {
1911 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1912 base::TimeTicks time
= base::TimeTicks() + dt
;
1913 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1914 WebPoint fling_point
= WebPoint(7, 13);
1916 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1918 // Cancel the fling. The fling cancellation should be deferred to allow
1919 // fling boosting events to arrive.
1923 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1925 EXPECT_CALL(mock_input_handler_
,
1926 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1927 .WillOnce(testing::Return(true));
1930 gesture_
.timeStampSeconds
= InSecondsF(time
);
1931 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1932 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1934 VERIFY_AND_RESET_MOCKS();
1936 // If the GestureScrollUpdate is in a different direction than the fling,
1937 // the fling should be cancelled and scrolling should resume.
1939 gesture_
.timeStampSeconds
= InSecondsF(time
);
1940 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
1941 gesture_
.data
.scrollUpdate
.deltaX
= -fling_delta
.x
;
1942 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1943 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1944 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
1945 EXPECT_CALL(mock_input_handler_
,
1946 ScrollBy(testing::_
,
1947 testing::Property(&gfx::Vector2dF::x
,
1948 testing::Eq(fling_delta
.x
))))
1949 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1950 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1952 VERIFY_AND_RESET_MOCKS();
1955 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingTooSlow
) {
1956 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1957 base::TimeTicks time
= base::TimeTicks() + dt
;
1958 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1959 WebPoint fling_point
= WebPoint(7, 13);
1961 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1963 // Cancel the fling. The fling cancellation should be deferred to allow
1964 // fling boosting events to arrive.
1968 // If the new fling is too slow, no boosting should take place, with the new
1969 // fling replacing the old.
1970 WebFloatPoint small_fling_delta
= WebFloatPoint(100, 0);
1971 gesture_
= CreateFling(time
,
1972 blink::WebGestureDeviceTouchscreen
,
1977 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1979 VERIFY_AND_RESET_MOCKS();
1981 // Note that the new fling delta uses the *slow*, unboosted fling velocity.
1983 float expected_delta
= dt
.InSecondsF() * -small_fling_delta
.x
;
1984 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1985 EXPECT_CALL(mock_input_handler_
,
1986 ScrollBy(testing::_
,
1987 testing::Property(&gfx::Vector2dF::x
,
1988 testing::Eq(expected_delta
))))
1989 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1990 input_handler_
->Animate(time
);
1992 VERIFY_AND_RESET_MOCKS();
1995 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfPreventBoostingFlagIsSet
) {
1996 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1997 base::TimeTicks time
= base::TimeTicks() + dt
;
1998 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1999 WebPoint fling_point
= WebPoint(7, 13);
2002 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2004 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2006 // Cancel the fling. The fling cancellation should not be deferred because of
2007 // prevent boosting flag set.
2008 gesture_
.data
.flingCancel
.preventBoosting
= true;
2012 // VERIFY_AND_RESET_MOCKS already called by CancelFling
2015 TEST_F(InputHandlerProxyTest
, FlingBoostTerminatedDuringScrollSequence
) {
2016 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
2017 base::TimeTicks time
= base::TimeTicks() + dt
;
2018 base::TimeTicks last_animate_time
= time
;
2019 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
2020 WebPoint fling_point
= WebPoint(7, 13);
2022 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
2024 // Now cancel the fling. The fling cancellation should be deferred to allow
2025 // fling boosting events to arrive.
2029 // The GestureScrollBegin should be swallowed by the fling.
2031 gesture_
.timeStampSeconds
= InSecondsF(time
);
2032 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
2033 EXPECT_CALL(mock_input_handler_
,
2034 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
2035 .WillOnce(testing::Return(true));
2036 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2038 VERIFY_AND_RESET_MOCKS();
2040 // Now animate the fling to completion (in this case, the fling should
2041 // terminate because the input handler reports a failed scroll). As the fling
2042 // was cancelled during an active scroll sequence, a synthetic
2043 // GestureScrollBegin should be processed, resuming the scroll.
2045 float expected_delta
=
2046 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
2047 EXPECT_CALL(mock_input_handler_
,
2048 ScrollBy(testing::_
,
2049 testing::Property(&gfx::Vector2dF::x
,
2050 testing::Eq(expected_delta
))))
2051 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
2052 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2053 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2054 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
2055 input_handler_
->Animate(time
);
2057 VERIFY_AND_RESET_MOCKS();
2059 // Subsequent GestureScrollUpdates after the cancelled, boosted fling should
2060 // cause scrolling as usual.
2062 expected_delta
= 7.3f
;
2063 gesture_
.timeStampSeconds
= InSecondsF(time
);
2064 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
2065 gesture_
.data
.scrollUpdate
.deltaX
= -expected_delta
;
2066 EXPECT_CALL(mock_input_handler_
,
2067 ScrollBy(testing::_
,
2068 testing::Property(&gfx::Vector2dF::x
,
2069 testing::Eq(expected_delta
))))
2070 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2071 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2073 VERIFY_AND_RESET_MOCKS();
2075 // GestureScrollEnd should terminate the resumed scroll properly.
2077 gesture_
.timeStampSeconds
= InSecondsF(time
);
2078 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
2079 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2080 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2082 VERIFY_AND_RESET_MOCKS();
2085 TEST_F(InputHandlerProxyTest
, DidReceiveInputEvent
) {
2086 testing::StrictMock
<
2087 MockInputHandlerProxyClientWithDidReceiveInputEvent
> mock_client
;
2088 input_handler_
.reset(
2089 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client
));
2091 // Note the type of input event isn't important.
2092 WebMouseWheelEvent wheel
;
2093 wheel
.type
= WebInputEvent::MouseWheel
;
2094 wheel
.scrollByPage
= true;
2096 EXPECT_CALL(mock_client
,
2097 DidReceiveInputEvent(
2098 Field(&WebInputEvent::type
, WebInputEvent::MouseWheel
)));
2100 input_handler_
->HandleInputEvent(wheel
);
2101 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2104 TEST_F(InputHandlerProxyTest
, DidReceiveInputEvent_ForFling
) {
2105 testing::StrictMock
<
2106 MockInputHandlerProxyClientWithDidReceiveInputEvent
> mock_client
;
2107 input_handler_
.reset(
2108 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client
));
2110 gesture_
.type
= WebInputEvent::GestureFlingStart
;
2111 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
2112 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
2113 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
2114 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
2115 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2116 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED
));
2117 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2118 EXPECT_CALL(mock_client
,
2119 DidReceiveInputEvent(Field(&WebInputEvent::type
,
2120 WebInputEvent::GestureFlingStart
)));
2121 EXPECT_EQ(InputHandlerProxy::DID_HANDLE
,
2122 input_handler_
->HandleInputEvent(gesture_
));
2123 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
2124 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2126 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
2127 EXPECT_CALL(mock_client
, DidAnimateForInput());
2128 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
2129 input_handler_
->Animate(time
);
2131 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2135 } // namespace content