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
;
37 double InSecondsF(const base::TimeTicks
& time
) {
38 return (time
- base::TimeTicks()).InSecondsF();
41 WebGestureEvent
CreateFling(base::TimeTicks timestamp
,
42 WebGestureDevice source_device
,
43 WebFloatPoint velocity
,
45 WebPoint global_point
,
47 WebGestureEvent fling
;
48 fling
.type
= WebInputEvent::GestureFlingStart
;
49 fling
.sourceDevice
= source_device
;
50 fling
.timeStampSeconds
= (timestamp
- base::TimeTicks()).InSecondsF();
51 fling
.data
.flingStart
.velocityX
= velocity
.x
;
52 fling
.data
.flingStart
.velocityY
= velocity
.y
;
55 fling
.globalX
= global_point
.x
;
56 fling
.globalY
= global_point
.y
;
57 fling
.modifiers
= modifiers
;
61 WebGestureEvent
CreateFling(WebGestureDevice source_device
,
62 WebFloatPoint velocity
,
64 WebPoint global_point
,
66 return CreateFling(base::TimeTicks(),
74 class MockInputHandler
: public cc::InputHandler
{
77 virtual ~MockInputHandler() {}
79 MOCK_METHOD0(PinchGestureBegin
, void());
80 MOCK_METHOD2(PinchGestureUpdate
,
81 void(float magnify_delta
, const gfx::Point
& anchor
));
82 MOCK_METHOD0(PinchGestureEnd
, void());
84 MOCK_METHOD0(SetNeedsAnimate
, void());
86 MOCK_METHOD2(ScrollBegin
,
87 ScrollStatus(const gfx::Point
& viewport_point
,
88 cc::InputHandler::ScrollInputType type
));
89 MOCK_METHOD2(ScrollAnimated
,
90 ScrollStatus(const gfx::Point
& viewport_point
,
91 const gfx::Vector2dF
& scroll_delta
));
92 MOCK_METHOD2(ScrollBy
,
93 cc::InputHandlerScrollResult(
94 const gfx::Point
& viewport_point
,
95 const gfx::Vector2dF
& scroll_delta
));
96 MOCK_METHOD2(ScrollVerticallyByPage
,
97 bool(const gfx::Point
& viewport_point
,
98 cc::ScrollDirection direction
));
99 MOCK_METHOD0(ScrollEnd
, void());
100 MOCK_METHOD0(FlingScrollBegin
, cc::InputHandler::ScrollStatus());
102 virtual scoped_ptr
<cc::SwapPromiseMonitor
>
103 CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo
* latency
) override
{
104 return scoped_ptr
<cc::SwapPromiseMonitor
>();
107 virtual void BindToClient(cc::InputHandlerClient
* client
) override
{}
109 virtual void MouseMoveAt(const gfx::Point
& mouse_position
) override
{}
111 MOCK_METHOD2(IsCurrentlyScrollingLayerAt
,
112 bool(const gfx::Point
& point
,
113 cc::InputHandler::ScrollInputType type
));
115 MOCK_METHOD1(HaveTouchEventHandlersAt
, bool(const gfx::Point
& point
));
117 virtual void SetRootLayerScrollOffsetDelegate(
118 cc::LayerScrollOffsetDelegate
* root_layer_scroll_offset_delegate
)
121 virtual void OnRootLayerDelegatedScrollOffsetChanged() override
{}
123 DISALLOW_COPY_AND_ASSIGN(MockInputHandler
);
126 // A simple WebGestureCurve implementation that flings at a constant velocity
128 class FakeWebGestureCurve
: public blink::WebGestureCurve
{
130 FakeWebGestureCurve(const blink::WebFloatSize
& velocity
,
131 const blink::WebFloatSize
& cumulative_scroll
)
132 : velocity_(velocity
), cumulative_scroll_(cumulative_scroll
) {}
134 virtual ~FakeWebGestureCurve() {}
136 // Returns false if curve has finished and can no longer be applied.
137 virtual bool apply(double time
, blink::WebGestureCurveTarget
* target
) {
138 blink::WebFloatSize
displacement(velocity_
.width
* time
,
139 velocity_
.height
* time
);
140 blink::WebFloatSize
increment(
141 displacement
.width
- cumulative_scroll_
.width
,
142 displacement
.height
- cumulative_scroll_
.height
);
143 cumulative_scroll_
= displacement
;
144 // scrollBy() could delete this curve if the animation is over, so don't
145 // touch any member variables after making that call.
146 return target
->scrollBy(increment
, velocity_
);
150 blink::WebFloatSize velocity_
;
151 blink::WebFloatSize cumulative_scroll_
;
153 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve
);
156 class MockInputHandlerProxyClient
157 : public content::InputHandlerProxyClient
{
159 MockInputHandlerProxyClient() {}
160 virtual ~MockInputHandlerProxyClient() {}
162 virtual void WillShutdown() override
{}
164 MOCK_METHOD1(TransferActiveWheelFlingAnimation
,
165 void(const WebActiveWheelFlingParameters
&));
167 virtual blink::WebGestureCurve
* CreateFlingAnimationCurve(
168 WebGestureDevice deviceSource
,
169 const WebFloatPoint
& velocity
,
170 const WebSize
& cumulative_scroll
) override
{
171 return new FakeWebGestureCurve(
172 blink::WebFloatSize(velocity
.x
, velocity
.y
),
173 blink::WebFloatSize(cumulative_scroll
.width
, cumulative_scroll
.height
));
176 MOCK_METHOD1(DidOverscroll
, void(const DidOverscrollParams
&));
177 virtual void DidStopFlinging() override
{}
178 virtual void DidReceiveInputEvent(blink::WebInputEvent::Type
) override
{}
179 virtual void DidAnimateForInput() override
{}
182 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient
);
185 class MockInputHandlerProxyClientWithDidReceiveInputEvent
186 : public MockInputHandlerProxyClient
{
188 MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
189 virtual ~MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
191 MOCK_METHOD1(DidReceiveInputEvent
, void(blink::WebInputEvent::Type type
));
192 MOCK_METHOD0(DidAnimateForInput
, void());
195 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClientWithDidReceiveInputEvent
);
198 WebTouchPoint
CreateWebTouchPoint(WebTouchPoint::State state
, float x
,
202 point
.screenPosition
= WebFloatPoint(x
, y
);
203 point
.position
= WebFloatPoint(x
, y
);
207 class InputHandlerProxyTest
: public testing::Test
{
209 InputHandlerProxyTest()
210 : expected_disposition_(InputHandlerProxy::DID_HANDLE
) {
211 input_handler_
.reset(
212 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client_
));
213 scroll_result_did_scroll_
.did_scroll
= true;
214 scroll_result_did_not_scroll_
.did_scroll
= false;
217 ~InputHandlerProxyTest() {
218 input_handler_
.reset();
221 // This is defined as a macro because when an expectation is not satisfied the
222 // only output you get
223 // out of gmock is the line number that set the expectation.
224 #define VERIFY_AND_RESET_MOCKS() \
226 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \
227 testing::Mock::VerifyAndClearExpectations(&mock_client_); \
230 void StartFling(base::TimeTicks timestamp
,
231 WebGestureDevice source_device
,
232 WebFloatPoint velocity
,
234 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
235 VERIFY_AND_RESET_MOCKS();
237 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
238 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
239 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
240 gesture_
.sourceDevice
= source_device
;
241 EXPECT_EQ(expected_disposition_
,
242 input_handler_
->HandleInputEvent(gesture_
));
244 VERIFY_AND_RESET_MOCKS();
246 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
247 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
248 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
251 CreateFling(timestamp
, source_device
, velocity
, position
, position
, 0);
252 EXPECT_EQ(expected_disposition_
,
253 input_handler_
->HandleInputEvent(gesture_
));
255 VERIFY_AND_RESET_MOCKS();
258 void CancelFling(base::TimeTicks timestamp
) {
259 gesture_
.timeStampSeconds
= InSecondsF(timestamp
);
260 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
261 EXPECT_EQ(expected_disposition_
,
262 input_handler_
->HandleInputEvent(gesture_
));
264 VERIFY_AND_RESET_MOCKS();
268 testing::StrictMock
<MockInputHandler
> mock_input_handler_
;
269 scoped_ptr
<content::InputHandlerProxy
> input_handler_
;
270 testing::StrictMock
<MockInputHandlerProxyClient
> mock_client_
;
271 WebGestureEvent gesture_
;
272 InputHandlerProxy::EventDisposition expected_disposition_
;
273 cc::InputHandlerScrollResult scroll_result_did_scroll_
;
274 cc::InputHandlerScrollResult scroll_result_did_not_scroll_
;
277 TEST_F(InputHandlerProxyTest
, MouseWheelByPageMainThread
) {
278 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
279 WebMouseWheelEvent wheel
;
280 wheel
.type
= WebInputEvent::MouseWheel
;
281 wheel
.scrollByPage
= true;
283 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(wheel
));
284 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
287 TEST_F(InputHandlerProxyTest
, MouseWheelWithCtrl
) {
288 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
289 WebMouseWheelEvent wheel
;
290 wheel
.type
= WebInputEvent::MouseWheel
;
291 wheel
.modifiers
= WebInputEvent::ControlKey
;
293 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(wheel
));
294 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
297 TEST_F(InputHandlerProxyTest
, GestureScrollStarted
) {
298 // We shouldn't send any events to the widget for this gesture.
299 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
300 VERIFY_AND_RESET_MOCKS();
302 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
303 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
305 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
306 EXPECT_EQ(expected_disposition_
,input_handler_
->HandleInputEvent(gesture_
));
308 // The event should not be marked as handled if scrolling is not possible.
309 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
310 VERIFY_AND_RESET_MOCKS();
312 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
313 gesture_
.data
.scrollUpdate
.deltaY
=
314 -40; // -Y means scroll down - i.e. in the +Y direction.
315 EXPECT_CALL(mock_input_handler_
,
317 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
318 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
319 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
321 // Mark the event as handled if scroll happens.
322 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
323 VERIFY_AND_RESET_MOCKS();
325 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
326 gesture_
.data
.scrollUpdate
.deltaY
=
327 -40; // -Y means scroll down - i.e. in the +Y direction.
328 EXPECT_CALL(mock_input_handler_
,
330 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
331 .WillOnce(testing::Return(scroll_result_did_scroll_
));
332 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
334 VERIFY_AND_RESET_MOCKS();
336 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
337 gesture_
.data
.scrollUpdate
.deltaY
= 0;
338 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
339 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
342 TEST_F(InputHandlerProxyTest
, GestureScrollOnMainThread
) {
343 // We should send all events to the widget for this gesture.
344 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
345 VERIFY_AND_RESET_MOCKS();
347 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
348 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
350 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
351 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
353 VERIFY_AND_RESET_MOCKS();
355 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
356 gesture_
.data
.scrollUpdate
.deltaY
= 40;
357 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
359 VERIFY_AND_RESET_MOCKS();
361 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
362 gesture_
.data
.scrollUpdate
.deltaY
= 0;
363 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
364 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
367 TEST_F(InputHandlerProxyTest
, GestureScrollIgnored
) {
368 // We shouldn't handle the GestureScrollBegin.
369 // Instead, we should get a DROP_EVENT result, indicating
370 // that we could determine that there's nothing that could scroll or otherwise
371 // react to this gesture sequence and thus we should drop the whole gesture
372 // sequence on the floor, except for the ScrollEnd.
373 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
374 VERIFY_AND_RESET_MOCKS();
376 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
377 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored
));
379 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
380 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
382 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
383 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
384 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).WillOnce(testing::Return());
385 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
388 TEST_F(InputHandlerProxyTest
, GesturePinch
) {
389 // We shouldn't send any events to the widget for this gesture.
390 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
391 VERIFY_AND_RESET_MOCKS();
393 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
394 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
395 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
397 VERIFY_AND_RESET_MOCKS();
399 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
400 gesture_
.data
.pinchUpdate
.scale
= 1.5;
403 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
404 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
406 VERIFY_AND_RESET_MOCKS();
408 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
409 gesture_
.data
.pinchUpdate
.scale
= 0.5;
412 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
413 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
415 VERIFY_AND_RESET_MOCKS();
417 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
418 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
419 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
422 TEST_F(InputHandlerProxyTest
, GesturePinchAfterScrollOnMainThread
) {
423 // Scrolls will start by being sent to the main thread.
424 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
425 VERIFY_AND_RESET_MOCKS();
427 EXPECT_CALL(mock_input_handler_
, ScrollBegin(::testing::_
, ::testing::_
))
428 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
430 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
431 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
433 VERIFY_AND_RESET_MOCKS();
435 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
436 gesture_
.data
.scrollUpdate
.deltaY
= 40;
437 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
439 // However, after the pinch gesture starts, they should go to the impl
441 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
442 VERIFY_AND_RESET_MOCKS();
444 gesture_
.type
= WebInputEvent::GesturePinchBegin
;
445 EXPECT_CALL(mock_input_handler_
, PinchGestureBegin());
446 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
448 VERIFY_AND_RESET_MOCKS();
450 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
451 gesture_
.data
.pinchUpdate
.scale
= 1.5;
454 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(1.5, gfx::Point(7, 13)));
455 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
457 VERIFY_AND_RESET_MOCKS();
459 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
460 gesture_
.data
.scrollUpdate
.deltaY
=
461 -40; // -Y means scroll down - i.e. in the +Y direction.
462 EXPECT_CALL(mock_input_handler_
,
464 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
465 .WillOnce(testing::Return(scroll_result_did_scroll_
));
466 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
468 VERIFY_AND_RESET_MOCKS();
470 gesture_
.type
= WebInputEvent::GesturePinchUpdate
;
471 gesture_
.data
.pinchUpdate
.scale
= 0.5;
474 EXPECT_CALL(mock_input_handler_
, PinchGestureUpdate(.5, gfx::Point(9, 6)));
475 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
477 VERIFY_AND_RESET_MOCKS();
479 gesture_
.type
= WebInputEvent::GesturePinchEnd
;
480 EXPECT_CALL(mock_input_handler_
, PinchGestureEnd());
481 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
483 // After the pinch gesture ends, they should go to back to the main
485 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
486 VERIFY_AND_RESET_MOCKS();
488 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
489 gesture_
.data
.scrollUpdate
.deltaY
= 0;
490 EXPECT_CALL(mock_input_handler_
, ScrollEnd())
491 .WillOnce(testing::Return());
492 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
495 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchpad
) {
496 // We shouldn't send any events to the widget for this gesture.
497 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
498 VERIFY_AND_RESET_MOCKS();
500 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
501 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
502 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
503 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
505 gesture_
.type
= WebInputEvent::GestureFlingStart
;
506 gesture_
.data
.flingStart
.velocityX
= 10;
507 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
508 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
510 VERIFY_AND_RESET_MOCKS();
512 // Verify that a GestureFlingCancel during an animation cancels it.
513 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
514 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
515 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
518 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchpad
) {
519 // We should send all events to the widget for this gesture.
520 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
521 VERIFY_AND_RESET_MOCKS();
523 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
524 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
526 gesture_
.type
= WebInputEvent::GestureFlingStart
;
527 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
528 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
530 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the
531 // input handler knows it's scrolling off the impl thread
532 ASSERT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
534 VERIFY_AND_RESET_MOCKS();
536 // Even if we didn't start a fling ourselves, we still need to send the cancel
537 // event to the widget.
538 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
539 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
540 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
543 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchpad
) {
544 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
545 VERIFY_AND_RESET_MOCKS();
547 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
548 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored
));
550 gesture_
.type
= WebInputEvent::GestureFlingStart
;
551 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
552 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
554 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
555 VERIFY_AND_RESET_MOCKS();
557 // Since the previous fling was ignored, we should also be dropping the next
559 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
560 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchpad
;
561 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
564 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchpad
) {
565 // We shouldn't send any events to the widget for this gesture.
566 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
567 VERIFY_AND_RESET_MOCKS();
569 // On the fling start, we should schedule an animation but not actually start
571 gesture_
.type
= WebInputEvent::GestureFlingStart
;
572 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
573 WebPoint fling_point
= WebPoint(7, 13);
574 WebPoint fling_global_point
= WebPoint(17, 23);
575 // Note that for trackpad, wheel events with the Control modifier are
576 // special (reserved for zoom), so don't set that here.
577 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
578 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
583 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
584 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
585 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
586 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
587 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
589 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
590 // The first animate call should let us pick up an animation start time, but
591 // we shouldn't actually move anywhere just yet. The first frame after the
592 // fling start will typically include the last scroll from the gesture that
593 // lead to the scroll (either wheel or gesture scroll), so there should be no
595 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
596 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
598 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
599 input_handler_
->Animate(time
);
601 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
603 // The second call should start scrolling in the -X direction.
604 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
605 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
606 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
607 EXPECT_CALL(mock_input_handler_
,
609 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
610 .WillOnce(testing::Return(scroll_result_did_scroll_
));
611 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
612 time
+= base::TimeDelta::FromMilliseconds(100);
613 input_handler_
->Animate(time
);
615 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
617 // Let's say on the third call we hit a non-scrollable region. We should abort
618 // the fling and not scroll.
619 // We also should pass the current fling parameters out to the client so the
620 // rest of the fling can be
621 // transferred to the main thread.
622 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
623 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
624 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
625 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
626 // Expected wheel fling animation parameters:
627 // *) fling_delta and fling_point should match the original GestureFlingStart
629 // *) startTime should be 10 to match the time parameter of the first
630 // Animate() call after the GestureFlingStart
631 // *) cumulativeScroll depends on the curve, but since we've animated in the
632 // -X direction the X value should be < 0
635 TransferActiveWheelFlingAnimation(testing::AllOf(
636 testing::Field(&WebActiveWheelFlingParameters::delta
,
637 testing::Eq(fling_delta
)),
638 testing::Field(&WebActiveWheelFlingParameters::point
,
639 testing::Eq(fling_point
)),
640 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
641 testing::Eq(fling_global_point
)),
642 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
643 testing::Eq(modifiers
)),
644 testing::Field(&WebActiveWheelFlingParameters::startTime
,
646 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
647 testing::Field(&WebSize::width
, testing::Gt(0))))));
648 time
+= base::TimeDelta::FromMilliseconds(100);
649 input_handler_
->Animate(time
);
651 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
652 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
654 // Since we've aborted the fling, the next animation should be a no-op and
655 // should not result in another
656 // frame being requested.
657 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
658 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
660 time
+= base::TimeDelta::FromMilliseconds(100);
661 input_handler_
->Animate(time
);
663 // Since we've transferred the fling to the main thread, we need to pass the
664 // next GestureFlingCancel to the main
666 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
667 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
668 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
671 TEST_F(InputHandlerProxyTest
, GestureFlingTransferResetsTouchpad
) {
672 // We shouldn't send any events to the widget for this gesture.
673 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
674 VERIFY_AND_RESET_MOCKS();
676 // Start a gesture fling in the -X direction with zero Y movement.
677 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
678 WebPoint fling_point
= WebPoint(7, 13);
679 WebPoint fling_global_point
= WebPoint(17, 23);
680 // Note that for trackpad, wheel events with the Control modifier are
681 // special (reserved for zoom), so don't set that here.
682 int modifiers
= WebInputEvent::ShiftKey
| WebInputEvent::AltKey
;
683 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
688 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
689 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
690 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
691 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
692 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
694 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
696 // Start the fling animation at time 10. This shouldn't actually scroll, just
697 // establish a start time.
698 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
699 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
701 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
702 input_handler_
->Animate(time
);
704 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
706 // The second call should start scrolling in the -X direction.
707 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
708 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
709 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
710 EXPECT_CALL(mock_input_handler_
,
712 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
713 .WillOnce(testing::Return(scroll_result_did_scroll_
));
714 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
715 time
+= base::TimeDelta::FromMilliseconds(100);
716 input_handler_
->Animate(time
);
718 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
720 // Let's say on the third call we hit a non-scrollable region. We should abort
721 // the fling and not scroll.
722 // We also should pass the current fling parameters out to the client so the
723 // rest of the fling can be
724 // transferred to the main thread.
725 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
726 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
727 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
728 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
730 // Expected wheel fling animation parameters:
731 // *) fling_delta and fling_point should match the original GestureFlingStart
733 // *) startTime should be 10 to match the time parameter of the first
734 // Animate() call after the GestureFlingStart
735 // *) cumulativeScroll depends on the curve, but since we've animated in the
736 // -X direction the X value should be < 0
739 TransferActiveWheelFlingAnimation(testing::AllOf(
740 testing::Field(&WebActiveWheelFlingParameters::delta
,
741 testing::Eq(fling_delta
)),
742 testing::Field(&WebActiveWheelFlingParameters::point
,
743 testing::Eq(fling_point
)),
744 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
745 testing::Eq(fling_global_point
)),
746 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
747 testing::Eq(modifiers
)),
748 testing::Field(&WebActiveWheelFlingParameters::startTime
,
750 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
751 testing::Field(&WebSize::width
, testing::Gt(0))))));
752 time
+= base::TimeDelta::FromMilliseconds(100);
753 input_handler_
->Animate(time
);
755 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
756 testing::Mock::VerifyAndClearExpectations(&mock_client_
);
758 // Since we've aborted the fling, the next animation should be a no-op and
759 // should not result in another
760 // frame being requested.
761 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
762 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
764 time
+= base::TimeDelta::FromMilliseconds(100);
765 input_handler_
->Animate(time
);
767 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
769 // Since we've transferred the fling to the main thread, we need to pass the
770 // next GestureFlingCancel to the main
772 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
773 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
774 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
776 VERIFY_AND_RESET_MOCKS();
777 input_handler_
->MainThreadHasStoppedFlinging();
779 // Start a second gesture fling, this time in the +Y direction with no X.
780 fling_delta
= WebFloatPoint(0, -1000);
781 fling_point
= WebPoint(95, 87);
782 fling_global_point
= WebPoint(32, 71);
783 modifiers
= WebInputEvent::AltKey
;
784 gesture_
= CreateFling(blink::WebGestureDeviceTouchpad
,
789 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
790 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
791 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
792 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
793 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
794 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
796 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
798 // Start the second fling animation at time 30.
799 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
800 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
802 time
= base::TimeTicks() + base::TimeDelta::FromSeconds(30);
803 input_handler_
->Animate(time
);
805 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
807 // Tick the second fling once normally.
808 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
809 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
810 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
811 EXPECT_CALL(mock_input_handler_
,
813 testing::Property(&gfx::Vector2dF::y
, testing::Gt(0))))
814 .WillOnce(testing::Return(scroll_result_did_scroll_
));
815 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
816 time
+= base::TimeDelta::FromMilliseconds(100);
817 input_handler_
->Animate(time
);
819 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
821 // Then abort the second fling.
822 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
823 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
824 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
825 EXPECT_CALL(mock_input_handler_
, ScrollEnd()).Times(0);
827 // We should get parameters from the second fling, nothing from the first
828 // fling should "leak".
831 TransferActiveWheelFlingAnimation(testing::AllOf(
832 testing::Field(&WebActiveWheelFlingParameters::delta
,
833 testing::Eq(fling_delta
)),
834 testing::Field(&WebActiveWheelFlingParameters::point
,
835 testing::Eq(fling_point
)),
836 testing::Field(&WebActiveWheelFlingParameters::globalPoint
,
837 testing::Eq(fling_global_point
)),
838 testing::Field(&WebActiveWheelFlingParameters::modifiers
,
839 testing::Eq(modifiers
)),
840 testing::Field(&WebActiveWheelFlingParameters::startTime
,
842 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll
,
843 testing::Field(&WebSize::height
, testing::Lt(0))))));
844 time
+= base::TimeDelta::FromMilliseconds(100);
845 input_handler_
->Animate(time
);
848 TEST_F(InputHandlerProxyTest
, GestureFlingStartedTouchscreen
) {
849 // We shouldn't send any events to the widget for this gesture.
850 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
851 VERIFY_AND_RESET_MOCKS();
853 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
854 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
855 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
856 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
857 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
859 VERIFY_AND_RESET_MOCKS();
861 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
862 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
863 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
865 gesture_
.type
= WebInputEvent::GestureFlingStart
;
866 gesture_
.data
.flingStart
.velocityX
= 10;
867 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
868 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
870 VERIFY_AND_RESET_MOCKS();
872 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
874 // Verify that a GestureFlingCancel during an animation cancels it.
875 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
876 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
877 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
880 TEST_F(InputHandlerProxyTest
, GestureFlingOnMainThreadTouchscreen
) {
881 // We should send all events to the widget for this gesture.
882 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
883 VERIFY_AND_RESET_MOCKS();
885 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
886 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread
));
888 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
889 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
891 VERIFY_AND_RESET_MOCKS();
893 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin()).Times(0);
895 gesture_
.type
= WebInputEvent::GestureFlingStart
;
896 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
897 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
899 VERIFY_AND_RESET_MOCKS();
901 // Even if we didn't start a fling ourselves, we still need to send the cancel
902 // event to the widget.
903 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
904 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
905 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
908 TEST_F(InputHandlerProxyTest
, GestureFlingIgnoredTouchscreen
) {
909 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
910 VERIFY_AND_RESET_MOCKS();
912 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
913 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
915 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
916 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
917 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
919 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
920 VERIFY_AND_RESET_MOCKS();
922 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
923 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored
));
925 gesture_
.type
= WebInputEvent::GestureFlingStart
;
926 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
927 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
929 VERIFY_AND_RESET_MOCKS();
931 // Even if we didn't start a fling ourselves, we still need to send the cancel
932 // event to the widget.
933 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
934 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
935 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
938 TEST_F(InputHandlerProxyTest
, GestureFlingAnimatesTouchscreen
) {
939 // We shouldn't send any events to the widget for this gesture.
940 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
941 VERIFY_AND_RESET_MOCKS();
943 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
944 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
946 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
947 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
948 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
950 VERIFY_AND_RESET_MOCKS();
952 // On the fling start, we should schedule an animation but not actually start
954 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
955 WebPoint fling_point
= WebPoint(7, 13);
956 WebPoint fling_global_point
= WebPoint(17, 23);
957 // Note that for touchscreen the control modifier is not special.
958 int modifiers
= WebInputEvent::ControlKey
;
959 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
964 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
965 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
966 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
967 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
969 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
970 // The first animate call should let us pick up an animation start time, but
971 // we shouldn't actually move anywhere just yet. The first frame after the
972 // fling start will typically include the last scroll from the gesture that
973 // lead to the scroll (either wheel or gesture scroll), so there should be no
975 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
976 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
977 input_handler_
->Animate(time
);
979 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
981 // The second call should start scrolling in the -X direction.
982 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
983 EXPECT_CALL(mock_input_handler_
,
985 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
986 .WillOnce(testing::Return(scroll_result_did_scroll_
));
987 time
+= base::TimeDelta::FromMilliseconds(100);
988 input_handler_
->Animate(time
);
990 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
992 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
993 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
994 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
997 TEST_F(InputHandlerProxyTest
, GestureFlingWithValidTimestamp
) {
998 // We shouldn't send any events to the widget for this gesture.
999 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1000 VERIFY_AND_RESET_MOCKS();
1002 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1003 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1005 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1006 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1007 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1009 VERIFY_AND_RESET_MOCKS();
1011 // On the fling start, we should schedule an animation but not actually start
1013 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1014 base::TimeTicks time
= base::TimeTicks() + dt
;
1015 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1016 WebPoint fling_point
= WebPoint(7, 13);
1017 WebPoint fling_global_point
= WebPoint(17, 23);
1018 int modifiers
= WebInputEvent::ControlKey
;
1019 gesture_
= CreateFling(time
,
1020 blink::WebGestureDeviceTouchscreen
,
1025 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1026 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1027 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1028 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1030 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1031 // With a valid time stamp, the first animate call should skip start time
1032 // initialization and immediately begin scroll update production. This reduces
1033 // the likelihood of a hitch between the scroll preceding the fling and
1034 // the first scroll generated by the fling.
1035 // Scrolling should start in the -X direction.
1036 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1037 EXPECT_CALL(mock_input_handler_
,
1038 ScrollBy(testing::_
,
1039 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1040 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1042 input_handler_
->Animate(time
);
1044 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1046 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1047 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1048 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1051 TEST_F(InputHandlerProxyTest
, GestureFlingWithInvalidTimestamp
) {
1052 // We shouldn't send any events to the widget for this gesture.
1053 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1054 VERIFY_AND_RESET_MOCKS();
1056 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1057 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1059 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1060 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1061 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1063 VERIFY_AND_RESET_MOCKS();
1065 // On the fling start, we should schedule an animation but not actually start
1067 base::TimeDelta start_time_offset
= base::TimeDelta::FromMilliseconds(10);
1068 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1069 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1070 WebPoint fling_point
= WebPoint(7, 13);
1071 WebPoint fling_global_point
= WebPoint(17, 23);
1072 int modifiers
= WebInputEvent::ControlKey
;
1073 gesture_
.timeStampSeconds
= start_time_offset
.InSecondsF();
1074 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1075 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1076 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1077 gesture_
.x
= fling_point
.x
;
1078 gesture_
.y
= fling_point
.y
;
1079 gesture_
.globalX
= fling_global_point
.x
;
1080 gesture_
.globalY
= fling_global_point
.y
;
1081 gesture_
.modifiers
= modifiers
;
1082 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1083 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1084 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1085 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1087 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1088 // Event though a time stamp was provided for the fling event, it will be
1089 // ignored as its too far in the past relative to the first animate call's
1091 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1092 base::TimeTicks time
=
1093 base::TimeTicks() + start_time_offset
+ base::TimeDelta::FromSeconds(1);
1094 input_handler_
->Animate(time
);
1096 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1098 // Further animation ticks should update the fling as usual.
1099 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1100 EXPECT_CALL(mock_input_handler_
,
1101 ScrollBy(testing::_
,
1102 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1103 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1104 time
+= base::TimeDelta::FromMilliseconds(10);
1105 input_handler_
->Animate(time
);
1107 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1109 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1110 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1111 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1114 TEST_F(InputHandlerProxyTest
,
1115 GestureScrollOnImplThreadFlagClearedAfterFling
) {
1116 // We shouldn't send any events to the widget for this gesture.
1117 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1118 VERIFY_AND_RESET_MOCKS();
1120 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1121 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1123 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1124 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1126 // After sending a GestureScrollBegin, the member variable
1127 // |gesture_scroll_on_impl_thread_| should be true.
1128 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1130 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1131 VERIFY_AND_RESET_MOCKS();
1133 // On the fling start, we should schedule an animation but not actually start
1135 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1136 WebPoint fling_point
= WebPoint(7, 13);
1137 WebPoint fling_global_point
= WebPoint(17, 23);
1138 int modifiers
= WebInputEvent::ControlKey
| WebInputEvent::AltKey
;
1139 gesture_
= CreateFling(blink::WebGestureDeviceTouchscreen
,
1144 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1145 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1146 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1147 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1149 // |gesture_scroll_on_impl_thread_| should still be true after
1150 // a GestureFlingStart is sent.
1151 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1153 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1154 // The first animate call should let us pick up an animation start time, but
1155 // we shouldn't actually move anywhere just yet. The first frame after the
1156 // fling start will typically include the last scroll from the gesture that
1157 // lead to the scroll (either wheel or gesture scroll), so there should be no
1159 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1160 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1161 input_handler_
->Animate(time
);
1163 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1165 // The second call should start scrolling in the -X direction.
1166 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1167 EXPECT_CALL(mock_input_handler_
,
1168 ScrollBy(testing::_
,
1169 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1170 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1171 time
+= base::TimeDelta::FromMilliseconds(100);
1172 input_handler_
->Animate(time
);
1174 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1176 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1177 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1178 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1180 // |gesture_scroll_on_impl_thread_| should be false once
1181 // the fling has finished (note no GestureScrollEnd has been sent).
1182 EXPECT_TRUE(!input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1185 TEST_F(InputHandlerProxyTest
, GestureFlingStopsAtContentEdge
) {
1186 // We shouldn't send any events to the widget for this gesture.
1187 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1188 VERIFY_AND_RESET_MOCKS();
1190 // On the fling start, we should schedule an animation but not actually start
1192 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1193 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1194 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1195 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1196 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1197 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1198 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1199 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1200 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1201 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1203 // The first animate doesn't cause any scrolling.
1204 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1205 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1206 input_handler_
->Animate(time
);
1207 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1209 // The second animate starts scrolling in the positive X and Y directions.
1210 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1211 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1212 EXPECT_CALL(mock_input_handler_
,
1213 ScrollBy(testing::_
,
1214 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1215 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1216 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1217 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1218 time
+= base::TimeDelta::FromMilliseconds(100);
1219 input_handler_
->Animate(time
);
1220 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1222 // The third animate overscrolls in the positive Y direction but scrolls
1224 cc::InputHandlerScrollResult overscroll
;
1225 overscroll
.did_scroll
= true;
1226 overscroll
.did_overscroll_root
= true;
1227 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1228 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 10);
1229 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1230 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1231 EXPECT_CALL(mock_input_handler_
,
1232 ScrollBy(testing::_
,
1233 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1234 .WillOnce(testing::Return(overscroll
));
1237 DidOverscroll(testing::AllOf(
1239 &DidOverscrollParams::accumulated_overscroll
,
1240 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1242 &DidOverscrollParams::latest_overscroll_delta
,
1243 testing::Eq(overscroll
.unused_scroll_delta
)),
1245 &DidOverscrollParams::current_fling_velocity
,
1246 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1247 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1248 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1249 time
+= base::TimeDelta::FromMilliseconds(100);
1250 input_handler_
->Animate(time
);
1251 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1253 // The next call to animate will no longer scroll vertically.
1254 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1255 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1256 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1257 EXPECT_CALL(mock_input_handler_
,
1258 ScrollBy(testing::_
,
1259 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1260 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1261 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1262 time
+= base::TimeDelta::FromMilliseconds(100);
1263 input_handler_
->Animate(time
);
1264 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1267 TEST_F(InputHandlerProxyTest
, GestureFlingNotCancelledBySmallTimeDelta
) {
1268 // We shouldn't send any events to the widget for this gesture.
1269 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1270 VERIFY_AND_RESET_MOCKS();
1272 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1273 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1275 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1276 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1277 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1279 VERIFY_AND_RESET_MOCKS();
1281 // On the fling start, we should schedule an animation but not actually start
1283 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1284 base::TimeTicks time
= base::TimeTicks() + dt
;
1285 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1286 WebPoint fling_point
= WebPoint(7, 13);
1287 WebPoint fling_global_point
= WebPoint(17, 23);
1288 int modifiers
= WebInputEvent::ControlKey
;
1289 gesture_
= CreateFling(time
,
1290 blink::WebGestureDeviceTouchscreen
,
1295 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1296 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1297 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1298 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1300 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1301 // With an animation timestamp equivalent to the starting timestamp, the
1302 // animation will simply be rescheduled.
1303 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1304 input_handler_
->Animate(time
);
1306 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1307 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1309 // A small time delta should not stop the fling, even if the client
1310 // reports no scrolling.
1311 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1312 EXPECT_CALL(mock_input_handler_
,
1313 ScrollBy(testing::_
,
1314 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1315 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1316 time
+= base::TimeDelta::FromMicroseconds(5);
1317 input_handler_
->Animate(time
);
1319 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1320 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1322 // A time delta of zero should not stop the fling, and neither should it
1323 // trigger scrolling on the client.
1324 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1325 input_handler_
->Animate(time
);
1327 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1328 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1330 // Lack of movement on the client, with a non-trivial scroll delta, should
1331 // terminate the fling.
1332 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1333 EXPECT_CALL(mock_input_handler_
,
1334 ScrollBy(testing::_
,
1335 testing::Property(&gfx::Vector2dF::x
, testing::Lt(1))))
1336 .WillOnce(testing::Return(scroll_result_did_not_scroll_
));
1337 time
+= base::TimeDelta::FromMilliseconds(100);
1338 input_handler_
->Animate(time
);
1340 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1341 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1344 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledAfterBothAxesStopScrolling
) {
1345 cc::InputHandlerScrollResult overscroll
;
1346 overscroll
.did_scroll
= true;
1347 overscroll
.did_overscroll_root
= true;
1349 // We shouldn't send any events to the widget for this gesture.
1350 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1351 VERIFY_AND_RESET_MOCKS();
1353 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1354 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1355 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1356 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1357 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1358 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1360 // On the fling start, we should schedule an animation but not actually start
1362 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1363 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1364 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1365 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1366 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1367 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1368 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1369 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1370 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1372 // The first animate doesn't cause any scrolling.
1373 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1374 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1375 input_handler_
->Animate(time
);
1376 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1378 // The second animate starts scrolling in the positive X and Y directions.
1379 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1380 EXPECT_CALL(mock_input_handler_
,
1381 ScrollBy(testing::_
,
1382 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1383 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1384 time
+= base::TimeDelta::FromMilliseconds(10);
1385 input_handler_
->Animate(time
);
1386 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1388 // The third animate hits the bottom content edge.
1389 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(0, 100);
1390 overscroll
.unused_scroll_delta
= gfx::Vector2dF(0, 100);
1391 EXPECT_CALL(mock_input_handler_
,
1392 ScrollBy(testing::_
,
1393 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))
1394 .WillOnce(testing::Return(overscroll
));
1397 DidOverscroll(testing::AllOf(
1399 &DidOverscrollParams::accumulated_overscroll
,
1400 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1402 &DidOverscrollParams::latest_overscroll_delta
,
1403 testing::Eq(overscroll
.unused_scroll_delta
)),
1405 &DidOverscrollParams::current_fling_velocity
,
1406 testing::Property(&gfx::Vector2dF::y
, testing::Lt(0))))));
1407 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1408 time
+= base::TimeDelta::FromMilliseconds(10);
1409 input_handler_
->Animate(time
);
1410 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1412 // The next call to animate will no longer scroll vertically.
1413 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1414 EXPECT_CALL(mock_input_handler_
,
1415 ScrollBy(testing::_
,
1416 testing::Property(&gfx::Vector2dF::y
, testing::Eq(0))))
1417 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1418 time
+= base::TimeDelta::FromMilliseconds(10);
1419 input_handler_
->Animate(time
);
1420 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1422 // The next call will hit the right edge.
1423 overscroll
.accumulated_root_overscroll
= gfx::Vector2dF(100, 100);
1424 overscroll
.unused_scroll_delta
= gfx::Vector2dF(100, 0);
1425 EXPECT_CALL(mock_input_handler_
,
1426 ScrollBy(testing::_
,
1427 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1428 .WillOnce(testing::Return(overscroll
));
1431 DidOverscroll(testing::AllOf(
1433 &DidOverscrollParams::accumulated_overscroll
,
1434 testing::Eq(overscroll
.accumulated_root_overscroll
)),
1436 &DidOverscrollParams::latest_overscroll_delta
,
1437 testing::Eq(overscroll
.unused_scroll_delta
)),
1439 &DidOverscrollParams::current_fling_velocity
,
1440 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))));
1441 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1442 time
+= base::TimeDelta::FromMilliseconds(10);
1443 input_handler_
->Animate(time
);
1444 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1446 // The next call to animate will no longer scroll horizontally or vertically,
1447 // and the fling should be cancelled.
1448 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate()).Times(0);
1449 EXPECT_CALL(mock_input_handler_
, ScrollBy(testing::_
, testing::_
)).Times(0);
1450 time
+= base::TimeDelta::FromMilliseconds(10);
1451 input_handler_
->Animate(time
);
1452 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1453 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1456 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestNegative
) {
1457 // None of the three touch points fall in the touch region. So the event
1458 // should be dropped.
1459 expected_disposition_
= InputHandlerProxy::DROP_EVENT
;
1460 VERIFY_AND_RESET_MOCKS();
1462 EXPECT_CALL(mock_input_handler_
,
1463 HaveTouchEventHandlersAt(
1464 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1465 .WillOnce(testing::Return(false));
1466 EXPECT_CALL(mock_input_handler_
,
1467 HaveTouchEventHandlersAt(
1468 testing::Property(&gfx::Point::x
, testing::Lt(0))))
1469 .WillOnce(testing::Return(false));
1471 WebTouchEvent touch
;
1472 touch
.type
= WebInputEvent::TouchStart
;
1474 touch
.touchesLength
= 3;
1475 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary
, 0, 0);
1476 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1477 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1478 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1481 TEST_F(InputHandlerProxyTest
, MultiTouchPointHitTestPositive
) {
1482 // One of the touch points is on a touch-region. So the event should be sent
1483 // to the main thread.
1484 expected_disposition_
= InputHandlerProxy::DID_NOT_HANDLE
;
1485 VERIFY_AND_RESET_MOCKS();
1487 EXPECT_CALL(mock_input_handler_
,
1488 HaveTouchEventHandlersAt(
1489 testing::Property(&gfx::Point::x
, testing::Eq(0))))
1490 .WillOnce(testing::Return(false));
1491 EXPECT_CALL(mock_input_handler_
,
1492 HaveTouchEventHandlersAt(
1493 testing::Property(&gfx::Point::x
, testing::Gt(0))))
1494 .WillOnce(testing::Return(true));
1495 // Since the second touch point hits a touch-region, there should be no
1496 // hit-testing for the third touch point.
1498 WebTouchEvent touch
;
1499 touch
.type
= WebInputEvent::TouchStart
;
1501 touch
.touchesLength
= 3;
1502 touch
.touches
[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 0, 0);
1503 touch
.touches
[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, 10, 10);
1504 touch
.touches
[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed
, -10, 10);
1505 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(touch
));
1508 TEST_F(InputHandlerProxyTest
, GestureFlingCancelledByKeyboardEvent
) {
1509 // We shouldn't send any events to the widget for this gesture.
1510 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1511 VERIFY_AND_RESET_MOCKS();
1513 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1514 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1515 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1516 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1517 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1518 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1519 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1521 // Keyboard events received during a scroll should have no effect.
1522 WebKeyboardEvent key_event
;
1523 key_event
.type
= WebInputEvent::KeyDown
;
1524 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1525 input_handler_
->HandleInputEvent(key_event
));
1526 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1527 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1529 // On the fling start, animation should be scheduled, but no scrolling occurs.
1530 gesture_
.type
= WebInputEvent::GestureFlingStart
;
1531 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
1532 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
1533 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
1534 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1535 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1536 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1537 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1538 EXPECT_TRUE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1539 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1541 // Keyboard events received during a fling should cancel the active fling.
1542 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1543 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE
,
1544 input_handler_
->HandleInputEvent(key_event
));
1545 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1546 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1548 // The call to animate should have no effect, as the fling was cancelled.
1549 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1550 input_handler_
->Animate(time
);
1551 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1553 // A fling cancel should be dropped, as there is nothing to cancel.
1554 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1555 EXPECT_EQ(InputHandlerProxy::DROP_EVENT
,
1556 input_handler_
->HandleInputEvent(gesture_
));
1557 EXPECT_FALSE(input_handler_
->gesture_scroll_on_impl_thread_for_testing());
1560 TEST_F(InputHandlerProxyTest
, GestureFlingWithNegativeTimeDelta
) {
1561 // We shouldn't send any events to the widget for this gesture.
1562 expected_disposition_
= InputHandlerProxy::DID_HANDLE
;
1563 VERIFY_AND_RESET_MOCKS();
1565 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1566 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1568 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1569 gesture_
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
1570 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1572 VERIFY_AND_RESET_MOCKS();
1574 // On the fling start, we should schedule an animation but not actually start
1576 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1577 base::TimeTicks time
= base::TimeTicks() + dt
;
1578 WebFloatPoint fling_delta
= WebFloatPoint(100, 0);
1579 WebPoint fling_point
= WebPoint(7, 13);
1580 WebPoint fling_global_point
= WebPoint(17, 23);
1581 int modifiers
= WebInputEvent::ControlKey
;
1582 gesture_
= CreateFling(time
,
1583 blink::WebGestureDeviceTouchscreen
,
1588 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1589 EXPECT_CALL(mock_input_handler_
, FlingScrollBegin())
1590 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1591 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1593 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1595 // If we get a negative time delta, that is, the Animation tick time happens
1596 // before the fling's start time then we should *not* try scrolling and
1597 // instead reset the fling start time.
1598 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1599 EXPECT_CALL(mock_input_handler_
,
1600 ScrollBy(testing::_
,
1601 testing::_
)).Times(0);
1602 time
-= base::TimeDelta::FromMilliseconds(5);
1603 input_handler_
->Animate(time
);
1605 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1607 // The first call should have reset the start time so subsequent calls should
1608 // generate scroll events.
1609 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1610 EXPECT_CALL(mock_input_handler_
,
1611 ScrollBy(testing::_
,
1612 testing::Property(&gfx::Vector2dF::x
, testing::Lt(0))))
1613 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1615 input_handler_
->Animate(time
+ base::TimeDelta::FromMilliseconds(1));
1617 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
1619 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1620 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1621 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1624 TEST_F(InputHandlerProxyTest
, FlingBoost
) {
1625 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1626 base::TimeTicks time
= base::TimeTicks() + dt
;
1627 base::TimeTicks last_animate_time
= time
;
1628 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1629 WebPoint fling_point
= WebPoint(7, 13);
1631 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1633 // Now cancel the fling. The fling cancellation should be deferred to allow
1634 // fling boosting events to arrive.
1638 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1640 EXPECT_CALL(mock_input_handler_
,
1641 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1642 .WillOnce(testing::Return(true));
1645 gesture_
.timeStampSeconds
= InSecondsF(time
);
1646 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1647 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1649 VERIFY_AND_RESET_MOCKS();
1651 // Animate calls within the deferred cancellation window should continue.
1653 float expected_delta
=
1654 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1655 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1656 EXPECT_CALL(mock_input_handler_
,
1657 ScrollBy(testing::_
,
1658 testing::Property(&gfx::Vector2dF::x
,
1659 testing::Eq(expected_delta
))))
1660 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1661 input_handler_
->Animate(time
);
1662 last_animate_time
= time
;
1664 VERIFY_AND_RESET_MOCKS();
1666 // GestureScrollUpdates in the same direction and at sufficient speed should
1667 // be swallowed by the fling.
1669 gesture_
.timeStampSeconds
= InSecondsF(time
);
1670 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
1671 gesture_
.data
.scrollUpdate
.deltaX
= fling_delta
.x
;
1672 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1674 VERIFY_AND_RESET_MOCKS();
1676 // Animate calls within the deferred cancellation window should continue.
1678 expected_delta
= (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1679 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1680 EXPECT_CALL(mock_input_handler_
,
1681 ScrollBy(testing::_
,
1682 testing::Property(&gfx::Vector2dF::x
,
1683 testing::Eq(expected_delta
))))
1684 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1685 input_handler_
->Animate(time
);
1686 last_animate_time
= time
;
1688 VERIFY_AND_RESET_MOCKS();
1690 // GestureFlingStart in the same direction and at sufficient speed should
1691 // boost the active fling.
1693 gesture_
= CreateFling(time
,
1694 blink::WebGestureDeviceTouchscreen
,
1699 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1700 VERIFY_AND_RESET_MOCKS();
1703 // Note we get *2x* as much delta because 2 flings have combined.
1704 expected_delta
= 2 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1705 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1706 EXPECT_CALL(mock_input_handler_
,
1707 ScrollBy(testing::_
,
1708 testing::Property(&gfx::Vector2dF::x
,
1709 testing::Eq(expected_delta
))))
1710 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1711 input_handler_
->Animate(time
);
1712 last_animate_time
= time
;
1714 VERIFY_AND_RESET_MOCKS();
1716 // Repeated GestureFlingStarts should accumulate.
1719 gesture_
= CreateFling(time
,
1720 blink::WebGestureDeviceTouchscreen
,
1725 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1726 VERIFY_AND_RESET_MOCKS();
1729 // Note we get *3x* as much delta because 3 flings have combined.
1730 expected_delta
= 3 * (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
1731 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1732 EXPECT_CALL(mock_input_handler_
,
1733 ScrollBy(testing::_
,
1734 testing::Property(&gfx::Vector2dF::x
,
1735 testing::Eq(expected_delta
))))
1736 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1737 input_handler_
->Animate(time
);
1738 last_animate_time
= time
;
1740 VERIFY_AND_RESET_MOCKS();
1742 // GestureFlingCancel should terminate the fling if no boosting gestures are
1743 // received within the timeout window.
1746 gesture_
.timeStampSeconds
= InSecondsF(time
);
1747 gesture_
.type
= WebInputEvent::GestureFlingCancel
;
1748 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1750 VERIFY_AND_RESET_MOCKS();
1752 time
+= base::TimeDelta::FromMilliseconds(100);
1753 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1754 input_handler_
->Animate(time
);
1756 VERIFY_AND_RESET_MOCKS();
1759 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollTargetsDifferentLayer
) {
1760 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1761 base::TimeTicks time
= base::TimeTicks() + dt
;
1762 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1763 WebPoint fling_point
= WebPoint(7, 13);
1765 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1767 // Cancel the fling. The fling cancellation should be deferred to allow
1768 // fling boosting events to arrive.
1772 // If the GestureScrollBegin targets a different layer, the fling should be
1773 // cancelled and the scroll should be handled as usual.
1774 EXPECT_CALL(mock_input_handler_
,
1775 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1776 .WillOnce(testing::Return(false));
1777 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1778 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1779 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1782 gesture_
.timeStampSeconds
= InSecondsF(time
);
1783 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1784 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1786 VERIFY_AND_RESET_MOCKS();
1789 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollDelayed
) {
1790 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1791 base::TimeTicks time
= base::TimeTicks() + dt
;
1792 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1793 WebPoint fling_point
= WebPoint(7, 13);
1795 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1797 // Cancel the fling. The fling cancellation should be deferred to allow
1798 // fling boosting events to arrive.
1802 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1804 EXPECT_CALL(mock_input_handler_
,
1805 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1806 .WillOnce(testing::Return(true));
1809 gesture_
.timeStampSeconds
= InSecondsF(time
);
1810 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1811 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1813 VERIFY_AND_RESET_MOCKS();
1815 // If no GestureScrollUpdate or GestureFlingStart is received within the
1816 // timeout window, the fling should be cancelled and scrolling should resume.
1817 time
+= base::TimeDelta::FromMilliseconds(100);
1818 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1819 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1820 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1821 input_handler_
->Animate(time
);
1823 VERIFY_AND_RESET_MOCKS();
1826 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingInDifferentDirection
) {
1827 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1828 base::TimeTicks time
= base::TimeTicks() + dt
;
1829 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1830 WebPoint fling_point
= WebPoint(7, 13);
1832 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1834 // Cancel the fling. The fling cancellation should be deferred to allow
1835 // fling boosting events to arrive.
1839 // If the new fling is orthogonal to the existing fling, no boosting should
1840 // take place, with the new fling replacing the old.
1841 WebFloatPoint orthogonal_fling_delta
=
1842 WebFloatPoint(fling_delta
.y
, -fling_delta
.x
);
1843 gesture_
= CreateFling(time
,
1844 blink::WebGestureDeviceTouchscreen
,
1845 orthogonal_fling_delta
,
1849 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1851 VERIFY_AND_RESET_MOCKS();
1853 // Note that the new fling delta uses the orthogonal, unboosted fling
1856 float expected_delta
= dt
.InSecondsF() * -orthogonal_fling_delta
.y
;
1857 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1858 EXPECT_CALL(mock_input_handler_
,
1859 ScrollBy(testing::_
,
1860 testing::Property(&gfx::Vector2dF::y
,
1861 testing::Eq(expected_delta
))))
1862 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1863 input_handler_
->Animate(time
);
1865 VERIFY_AND_RESET_MOCKS();
1868 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfScrollInDifferentDirection
) {
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 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1883 EXPECT_CALL(mock_input_handler_
,
1884 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1885 .WillOnce(testing::Return(true));
1888 gesture_
.timeStampSeconds
= InSecondsF(time
);
1889 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1890 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1892 VERIFY_AND_RESET_MOCKS();
1894 // If the GestureScrollUpdate is in a different direction than the fling,
1895 // the fling should be cancelled and scrolling should resume.
1897 gesture_
.timeStampSeconds
= InSecondsF(time
);
1898 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
1899 gesture_
.data
.scrollUpdate
.deltaX
= -fling_delta
.x
;
1900 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1901 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1902 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1903 EXPECT_CALL(mock_input_handler_
,
1904 ScrollBy(testing::_
,
1905 testing::Property(&gfx::Vector2dF::x
,
1906 testing::Eq(fling_delta
.x
))))
1907 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1908 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1910 VERIFY_AND_RESET_MOCKS();
1913 TEST_F(InputHandlerProxyTest
, NoFlingBoostIfFlingTooSlow
) {
1914 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1915 base::TimeTicks time
= base::TimeTicks() + dt
;
1916 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1917 WebPoint fling_point
= WebPoint(7, 13);
1919 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1921 // Cancel the fling. The fling cancellation should be deferred to allow
1922 // fling boosting events to arrive.
1926 // If the new fling is too slow, no boosting should take place, with the new
1927 // fling replacing the old.
1928 WebFloatPoint small_fling_delta
= WebFloatPoint(100, 0);
1929 gesture_
= CreateFling(time
,
1930 blink::WebGestureDeviceTouchscreen
,
1935 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1937 VERIFY_AND_RESET_MOCKS();
1939 // Note that the new fling delta uses the *slow*, unboosted fling velocity.
1941 float expected_delta
= dt
.InSecondsF() * -small_fling_delta
.x
;
1942 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
1943 EXPECT_CALL(mock_input_handler_
,
1944 ScrollBy(testing::_
,
1945 testing::Property(&gfx::Vector2dF::x
,
1946 testing::Eq(expected_delta
))))
1947 .WillOnce(testing::Return(scroll_result_did_scroll_
));
1948 input_handler_
->Animate(time
);
1950 VERIFY_AND_RESET_MOCKS();
1953 TEST_F(InputHandlerProxyTest
, FlingBoostTerminatedDuringScrollSequence
) {
1954 base::TimeDelta dt
= base::TimeDelta::FromMilliseconds(10);
1955 base::TimeTicks time
= base::TimeTicks() + dt
;
1956 base::TimeTicks last_animate_time
= time
;
1957 WebFloatPoint fling_delta
= WebFloatPoint(1000, 0);
1958 WebPoint fling_point
= WebPoint(7, 13);
1960 time
, blink::WebGestureDeviceTouchscreen
, fling_delta
, fling_point
);
1962 // Now cancel the fling. The fling cancellation should be deferred to allow
1963 // fling boosting events to arrive.
1967 // The GestureScrollBegin should be swallowed by the fling.
1969 gesture_
.timeStampSeconds
= InSecondsF(time
);
1970 gesture_
.type
= WebInputEvent::GestureScrollBegin
;
1971 EXPECT_CALL(mock_input_handler_
,
1972 IsCurrentlyScrollingLayerAt(testing::_
, testing::_
))
1973 .WillOnce(testing::Return(true));
1974 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
1976 VERIFY_AND_RESET_MOCKS();
1978 // Now animate the fling to completion (in this case, the fling should
1979 // terminate because the input handler reports a failed scroll). As the fling
1980 // was cancelled during an active scroll sequence, a synthetic
1981 // GestureScrollBegin should be processed, resuming the scroll.
1983 float expected_delta
=
1984 (time
- last_animate_time
).InSecondsF() * -fling_delta
.x
;
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_not_scroll_
));
1990 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
1991 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
1992 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
1993 input_handler_
->Animate(time
);
1995 VERIFY_AND_RESET_MOCKS();
1997 // Subsequent GestureScrollUpdates after the cancelled, boosted fling should
1998 // cause scrolling as usual.
2000 expected_delta
= 7.3f
;
2001 gesture_
.timeStampSeconds
= InSecondsF(time
);
2002 gesture_
.type
= WebInputEvent::GestureScrollUpdate
;
2003 gesture_
.data
.scrollUpdate
.deltaX
= -expected_delta
;
2004 EXPECT_CALL(mock_input_handler_
,
2005 ScrollBy(testing::_
,
2006 testing::Property(&gfx::Vector2dF::x
,
2007 testing::Eq(expected_delta
))))
2008 .WillOnce(testing::Return(scroll_result_did_scroll_
));
2009 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2011 VERIFY_AND_RESET_MOCKS();
2013 // GestureScrollEnd should terminate the resumed scroll properly.
2015 gesture_
.timeStampSeconds
= InSecondsF(time
);
2016 gesture_
.type
= WebInputEvent::GestureScrollEnd
;
2017 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2018 EXPECT_EQ(expected_disposition_
, input_handler_
->HandleInputEvent(gesture_
));
2020 VERIFY_AND_RESET_MOCKS();
2023 TEST_F(InputHandlerProxyTest
, DidReceiveInputEvent
) {
2024 testing::StrictMock
<
2025 MockInputHandlerProxyClientWithDidReceiveInputEvent
> mock_client
;
2026 input_handler_
.reset(
2027 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client
));
2029 // Note the type of input event isn't important.
2030 WebMouseWheelEvent wheel
;
2031 wheel
.type
= WebInputEvent::MouseWheel
;
2032 wheel
.scrollByPage
= true;
2034 EXPECT_CALL(mock_client
, DidReceiveInputEvent(WebInputEvent::MouseWheel
));
2036 input_handler_
->HandleInputEvent(wheel
);
2037 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2040 TEST_F(InputHandlerProxyTest
, DidReceiveInputEvent_ForFling
) {
2041 testing::StrictMock
<
2042 MockInputHandlerProxyClientWithDidReceiveInputEvent
> mock_client
;
2043 input_handler_
.reset(
2044 new content::InputHandlerProxy(&mock_input_handler_
, &mock_client
));
2046 gesture_
.type
= WebInputEvent::GestureFlingStart
;
2047 WebFloatPoint fling_delta
= WebFloatPoint(100, 100);
2048 gesture_
.data
.flingStart
.velocityX
= fling_delta
.x
;
2049 gesture_
.data
.flingStart
.velocityY
= fling_delta
.y
;
2050 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
2051 EXPECT_CALL(mock_input_handler_
, ScrollBegin(testing::_
, testing::_
))
2052 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted
));
2053 EXPECT_CALL(mock_input_handler_
, ScrollEnd());
2054 EXPECT_CALL(mock_client
,
2055 DidReceiveInputEvent(WebInputEvent::GestureFlingStart
));
2056 EXPECT_EQ(InputHandlerProxy::DID_HANDLE
,
2057 input_handler_
->HandleInputEvent(gesture_
));
2058 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_
);
2059 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2061 EXPECT_CALL(mock_input_handler_
, SetNeedsAnimate());
2062 EXPECT_CALL(mock_client
, DidAnimateForInput());
2063 base::TimeTicks time
= base::TimeTicks() + base::TimeDelta::FromSeconds(10);
2064 input_handler_
->Animate(time
);
2066 testing::Mock::VerifyAndClearExpectations(&mock_client
);
2070 } // namespace content