Don't send a SHChangeNotify for creating an app icon when creating a shortcut.
[chromium-blink-merge.git] / content / renderer / input / input_handler_proxy_unittest.cc
blob382536687ff248b91db8eb698fbb57e64db3ca7c
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/input/input_handler_proxy.h"
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/trees/swap_promise_monitor.h"
10 #include "content/common/input/did_overscroll_params.h"
11 #include "content/renderer/input/input_handler_proxy_client.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
15 #include "third_party/WebKit/public/platform/WebFloatSize.h"
16 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
17 #include "third_party/WebKit/public/platform/WebPoint.h"
18 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 #include "ui/events/latency_info.h"
21 using blink::WebActiveWheelFlingParameters;
22 using blink::WebFloatPoint;
23 using blink::WebFloatSize;
24 using blink::WebGestureDevice;
25 using blink::WebGestureEvent;
26 using blink::WebInputEvent;
27 using blink::WebKeyboardEvent;
28 using blink::WebMouseWheelEvent;
29 using blink::WebPoint;
30 using blink::WebSize;
31 using blink::WebTouchEvent;
32 using blink::WebTouchPoint;
33 using testing::Field;
35 namespace content {
36 namespace {
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,
45 WebPoint point,
46 WebPoint global_point,
47 int modifiers) {
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;
54 fling.x = point.x;
55 fling.y = point.y;
56 fling.globalX = global_point.x;
57 fling.globalY = global_point.y;
58 fling.modifiers = modifiers;
59 return fling;
62 WebGestureEvent CreateFling(WebGestureDevice source_device,
63 WebFloatPoint velocity,
64 WebPoint point,
65 WebPoint global_point,
66 int modifiers) {
67 return CreateFling(base::TimeTicks(),
68 source_device,
69 velocity,
70 point,
71 global_point,
72 modifiers);
75 class MockInputHandler : public cc::InputHandler {
76 public:
77 MockInputHandler() {}
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 {
109 return NULL;
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)
125 override {}
127 virtual void OnRootLayerDelegatedScrollOffsetChanged() override {}
129 DISALLOW_COPY_AND_ASSIGN(MockInputHandler);
132 // A simple WebGestureCurve implementation that flings at a constant velocity
133 // indefinitely.
134 class FakeWebGestureCurve : public blink::WebGestureCurve {
135 public:
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_);
155 private:
156 blink::WebFloatSize velocity_;
157 blink::WebFloatSize cumulative_scroll_;
159 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve);
162 class MockInputHandlerProxyClient
163 : public content::InputHandlerProxyClient {
164 public:
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 {}
187 private:
188 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient);
191 class MockInputHandlerProxyClientWithDidReceiveInputEvent
192 : public MockInputHandlerProxyClient {
193 public:
194 MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
195 virtual ~MockInputHandlerProxyClientWithDidReceiveInputEvent() {}
197 MOCK_METHOD1(DidReceiveInputEvent, void(const blink::WebInputEvent&));
198 MOCK_METHOD0(DidAnimateForInput, void());
200 private:
201 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClientWithDidReceiveInputEvent);
204 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x,
205 float y) {
206 WebTouchPoint point;
207 point.state = state;
208 point.screenPosition = WebFloatPoint(x, y);
209 point.position = WebFloatPoint(x, y);
210 return point;
213 class InputHandlerProxyTest : public testing::Test {
214 public:
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() \
231 do { \
232 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \
233 testing::Mock::VerifyAndClearExpectations(&mock_client_); \
234 } while (false)
236 void StartFling(base::TimeTicks timestamp,
237 WebGestureDevice source_device,
238 WebFloatPoint velocity,
239 WebPoint position) {
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());
256 gesture_ =
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();
273 protected:
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_,
322 ScrollBy(testing::_,
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_,
335 ScrollBy(testing::_,
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;
409 gesture_.x = 7;
410 gesture_.y = 13;
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;
418 gesture_.x = 9;
419 gesture_.y = 6;
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;
444 gesture_.x = 7;
445 gesture_.y = 13;
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;
452 gesture_.x = 9;
453 gesture_.y = 6;
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
480 // thread.
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;
494 gesture_.x = 7;
495 gesture_.y = 13;
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_,
505 ScrollBy(testing::_,
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;
514 gesture_.x = 9;
515 gesture_.y = 6;
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
526 // thread.
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
600 // fling_cancel.
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
612 // scrolling.
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,
621 fling_delta,
622 fling_point,
623 fling_global_point,
624 modifiers);
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
636 // visible hitch.
637 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
638 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
639 .Times(0);
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_,
650 ScrollBy(testing::_,
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
670 // event
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
675 EXPECT_CALL(
676 mock_client_,
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,
687 testing::Eq(10)),
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::_))
701 .Times(0);
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
707 // thread as well.
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,
726 fling_delta,
727 fling_point,
728 fling_global_point,
729 modifiers);
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::_))
742 .Times(0);
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_,
753 ScrollBy(testing::_,
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
774 // event
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
779 EXPECT_CALL(
780 mock_client_,
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,
791 testing::Eq(10)),
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::_))
805 .Times(0);
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
813 // thread as well.
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,
827 fling_delta,
828 fling_point,
829 fling_global_point,
830 modifiers);
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::_))
843 .Times(0);
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_,
854 ScrollBy(testing::_,
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".
871 EXPECT_CALL(
872 mock_client_,
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,
883 testing::Eq(30)),
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 // Flings ignored by the InputHandler should be dropped, signalling the end
965 // of the touch scroll sequence.
966 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
967 .WillOnce(testing::Return(cc::InputHandler::SCROLL_IGNORED));
969 gesture_.type = WebInputEvent::GestureFlingStart;
970 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
971 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
973 VERIFY_AND_RESET_MOCKS();
975 // Subsequent scrolls should behave normally, even without an intervening
976 // GestureFlingCancel, as the original GestureFlingStart was dropped.
977 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
978 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
979 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
980 gesture_.type = WebInputEvent::GestureScrollBegin;
981 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
982 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
985 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchscreen) {
986 // We shouldn't send any events to the widget for this gesture.
987 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
988 VERIFY_AND_RESET_MOCKS();
990 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
991 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
993 gesture_.type = WebInputEvent::GestureScrollBegin;
994 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
995 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
997 VERIFY_AND_RESET_MOCKS();
999 // On the fling start, we should schedule an animation but not actually start
1000 // scrolling.
1001 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1002 WebPoint fling_point = WebPoint(7, 13);
1003 WebPoint fling_global_point = WebPoint(17, 23);
1004 // Note that for touchscreen the control modifier is not special.
1005 int modifiers = WebInputEvent::ControlKey;
1006 gesture_ = CreateFling(blink::WebGestureDeviceTouchscreen,
1007 fling_delta,
1008 fling_point,
1009 fling_global_point,
1010 modifiers);
1011 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1012 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1013 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1014 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1016 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1017 // The first animate call should let us pick up an animation start time, but
1018 // we shouldn't actually move anywhere just yet. The first frame after the
1019 // fling start will typically include the last scroll from the gesture that
1020 // lead to the scroll (either wheel or gesture scroll), so there should be no
1021 // visible hitch.
1022 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1023 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1024 input_handler_->Animate(time);
1026 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1028 // The second call should start scrolling in the -X direction.
1029 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1030 EXPECT_CALL(mock_input_handler_,
1031 ScrollBy(testing::_,
1032 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1033 .WillOnce(testing::Return(scroll_result_did_scroll_));
1034 time += base::TimeDelta::FromMilliseconds(100);
1035 input_handler_->Animate(time);
1037 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1039 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1040 gesture_.type = WebInputEvent::GestureFlingCancel;
1041 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1044 TEST_F(InputHandlerProxyTest, GestureFlingWithValidTimestamp) {
1045 // We shouldn't send any events to the widget for this gesture.
1046 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1047 VERIFY_AND_RESET_MOCKS();
1049 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1050 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1052 gesture_.type = WebInputEvent::GestureScrollBegin;
1053 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1054 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1056 VERIFY_AND_RESET_MOCKS();
1058 // On the fling start, we should schedule an animation but not actually start
1059 // scrolling.
1060 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1061 base::TimeTicks time = base::TimeTicks() + dt;
1062 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1063 WebPoint fling_point = WebPoint(7, 13);
1064 WebPoint fling_global_point = WebPoint(17, 23);
1065 int modifiers = WebInputEvent::ControlKey;
1066 gesture_ = CreateFling(time,
1067 blink::WebGestureDeviceTouchscreen,
1068 fling_delta,
1069 fling_point,
1070 fling_global_point,
1071 modifiers);
1072 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1073 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1074 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1075 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1077 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1078 // With a valid time stamp, the first animate call should skip start time
1079 // initialization and immediately begin scroll update production. This reduces
1080 // the likelihood of a hitch between the scroll preceding the fling and
1081 // the first scroll generated by the fling.
1082 // Scrolling should start in the -X direction.
1083 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1084 EXPECT_CALL(mock_input_handler_,
1085 ScrollBy(testing::_,
1086 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1087 .WillOnce(testing::Return(scroll_result_did_scroll_));
1088 time += dt;
1089 input_handler_->Animate(time);
1091 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1093 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1094 gesture_.type = WebInputEvent::GestureFlingCancel;
1095 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1098 TEST_F(InputHandlerProxyTest, GestureFlingWithInvalidTimestamp) {
1099 // We shouldn't send any events to the widget for this gesture.
1100 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1101 VERIFY_AND_RESET_MOCKS();
1103 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1104 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1106 gesture_.type = WebInputEvent::GestureScrollBegin;
1107 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1108 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1110 VERIFY_AND_RESET_MOCKS();
1112 // On the fling start, we should schedule an animation but not actually start
1113 // scrolling.
1114 base::TimeDelta start_time_offset = base::TimeDelta::FromMilliseconds(10);
1115 gesture_.type = WebInputEvent::GestureFlingStart;
1116 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1117 WebPoint fling_point = WebPoint(7, 13);
1118 WebPoint fling_global_point = WebPoint(17, 23);
1119 int modifiers = WebInputEvent::ControlKey;
1120 gesture_.timeStampSeconds = start_time_offset.InSecondsF();
1121 gesture_.data.flingStart.velocityX = fling_delta.x;
1122 gesture_.data.flingStart.velocityY = fling_delta.y;
1123 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1124 gesture_.x = fling_point.x;
1125 gesture_.y = fling_point.y;
1126 gesture_.globalX = fling_global_point.x;
1127 gesture_.globalY = fling_global_point.y;
1128 gesture_.modifiers = modifiers;
1129 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1130 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1131 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1132 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1134 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1135 // Event though a time stamp was provided for the fling event, it will be
1136 // ignored as its too far in the past relative to the first animate call's
1137 // timestamp.
1138 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1139 base::TimeTicks time =
1140 base::TimeTicks() + start_time_offset + base::TimeDelta::FromSeconds(1);
1141 input_handler_->Animate(time);
1143 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1145 // Further animation ticks should update the fling as usual.
1146 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1147 EXPECT_CALL(mock_input_handler_,
1148 ScrollBy(testing::_,
1149 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1150 .WillOnce(testing::Return(scroll_result_did_scroll_));
1151 time += base::TimeDelta::FromMilliseconds(10);
1152 input_handler_->Animate(time);
1154 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1156 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1157 gesture_.type = WebInputEvent::GestureFlingCancel;
1158 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1161 TEST_F(InputHandlerProxyTest,
1162 GestureScrollOnImplThreadFlagClearedAfterFling) {
1163 // We shouldn't send any events to the widget for this gesture.
1164 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1165 VERIFY_AND_RESET_MOCKS();
1167 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1168 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1170 gesture_.type = WebInputEvent::GestureScrollBegin;
1171 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1173 // After sending a GestureScrollBegin, the member variable
1174 // |gesture_scroll_on_impl_thread_| should be true.
1175 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1177 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1178 VERIFY_AND_RESET_MOCKS();
1180 // On the fling start, we should schedule an animation but not actually start
1181 // scrolling.
1182 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1183 WebPoint fling_point = WebPoint(7, 13);
1184 WebPoint fling_global_point = WebPoint(17, 23);
1185 int modifiers = WebInputEvent::ControlKey | WebInputEvent::AltKey;
1186 gesture_ = CreateFling(blink::WebGestureDeviceTouchscreen,
1187 fling_delta,
1188 fling_point,
1189 fling_global_point,
1190 modifiers);
1191 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1192 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1193 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1194 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1196 // |gesture_scroll_on_impl_thread_| should still be true after
1197 // a GestureFlingStart is sent.
1198 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1200 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1201 // The first animate call should let us pick up an animation start time, but
1202 // we shouldn't actually move anywhere just yet. The first frame after the
1203 // fling start will typically include the last scroll from the gesture that
1204 // lead to the scroll (either wheel or gesture scroll), so there should be no
1205 // visible hitch.
1206 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1207 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1208 input_handler_->Animate(time);
1210 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1212 // The second call should start scrolling in the -X direction.
1213 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1214 EXPECT_CALL(mock_input_handler_,
1215 ScrollBy(testing::_,
1216 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1217 .WillOnce(testing::Return(scroll_result_did_scroll_));
1218 time += base::TimeDelta::FromMilliseconds(100);
1219 input_handler_->Animate(time);
1221 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1223 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1224 gesture_.type = WebInputEvent::GestureFlingCancel;
1225 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1227 // |gesture_scroll_on_impl_thread_| should be false once
1228 // the fling has finished (note no GestureScrollEnd has been sent).
1229 EXPECT_TRUE(!input_handler_->gesture_scroll_on_impl_thread_for_testing());
1232 TEST_F(InputHandlerProxyTest, GestureFlingStopsAtContentEdge) {
1233 // We shouldn't send any events to the widget for this gesture.
1234 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1235 VERIFY_AND_RESET_MOCKS();
1237 // On the fling start, we should schedule an animation but not actually start
1238 // scrolling.
1239 gesture_.type = WebInputEvent::GestureFlingStart;
1240 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1241 gesture_.data.flingStart.velocityX = fling_delta.x;
1242 gesture_.data.flingStart.velocityY = fling_delta.y;
1243 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1244 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1245 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1246 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1247 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1248 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1250 // The first animate doesn't cause any scrolling.
1251 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1252 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1253 input_handler_->Animate(time);
1254 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1256 // The second animate starts scrolling in the positive X and Y directions.
1257 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1258 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1259 EXPECT_CALL(mock_input_handler_,
1260 ScrollBy(testing::_,
1261 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1262 .WillOnce(testing::Return(scroll_result_did_scroll_));
1263 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1264 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1265 time += base::TimeDelta::FromMilliseconds(100);
1266 input_handler_->Animate(time);
1267 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1269 // The third animate overscrolls in the positive Y direction but scrolls
1270 // somewhat.
1271 cc::InputHandlerScrollResult overscroll;
1272 overscroll.did_scroll = true;
1273 overscroll.did_overscroll_root = true;
1274 overscroll.accumulated_root_overscroll = gfx::Vector2dF(0, 100);
1275 overscroll.unused_scroll_delta = gfx::Vector2dF(0, 10);
1276 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1277 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1278 EXPECT_CALL(mock_input_handler_,
1279 ScrollBy(testing::_,
1280 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1281 .WillOnce(testing::Return(overscroll));
1282 EXPECT_CALL(
1283 mock_client_,
1284 DidOverscroll(testing::AllOf(
1285 testing::Field(
1286 &DidOverscrollParams::accumulated_overscroll,
1287 testing::Eq(overscroll.accumulated_root_overscroll)),
1288 testing::Field(
1289 &DidOverscrollParams::latest_overscroll_delta,
1290 testing::Eq(overscroll.unused_scroll_delta)),
1291 testing::Field(
1292 &DidOverscrollParams::current_fling_velocity,
1293 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))));
1294 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1295 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1296 time += base::TimeDelta::FromMilliseconds(100);
1297 input_handler_->Animate(time);
1298 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1300 // The next call to animate will no longer scroll vertically.
1301 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1302 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1303 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1304 EXPECT_CALL(mock_input_handler_,
1305 ScrollBy(testing::_,
1306 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1307 .WillOnce(testing::Return(scroll_result_did_scroll_));
1308 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1309 time += base::TimeDelta::FromMilliseconds(100);
1310 input_handler_->Animate(time);
1311 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1314 TEST_F(InputHandlerProxyTest, GestureFlingNotCancelledBySmallTimeDelta) {
1315 // We shouldn't send any events to the widget for this gesture.
1316 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1317 VERIFY_AND_RESET_MOCKS();
1319 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1320 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1322 gesture_.type = WebInputEvent::GestureScrollBegin;
1323 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1324 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1326 VERIFY_AND_RESET_MOCKS();
1328 // On the fling start, we should schedule an animation but not actually start
1329 // scrolling.
1330 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1331 base::TimeTicks time = base::TimeTicks() + dt;
1332 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1333 WebPoint fling_point = WebPoint(7, 13);
1334 WebPoint fling_global_point = WebPoint(17, 23);
1335 int modifiers = WebInputEvent::ControlKey;
1336 gesture_ = CreateFling(time,
1337 blink::WebGestureDeviceTouchscreen,
1338 fling_delta,
1339 fling_point,
1340 fling_global_point,
1341 modifiers);
1342 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1343 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1344 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1345 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1347 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1348 // With an animation timestamp equivalent to the starting timestamp, the
1349 // animation will simply be rescheduled.
1350 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1351 input_handler_->Animate(time);
1353 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1354 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1356 // A small time delta should not stop the fling, even if the client
1357 // reports no scrolling.
1358 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1359 EXPECT_CALL(mock_input_handler_,
1360 ScrollBy(testing::_,
1361 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1362 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1363 time += base::TimeDelta::FromMicroseconds(5);
1364 input_handler_->Animate(time);
1366 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1367 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1369 // A time delta of zero should not stop the fling, and neither should it
1370 // trigger scrolling on the client.
1371 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1372 input_handler_->Animate(time);
1374 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1375 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1377 // Lack of movement on the client, with a non-trivial scroll delta, should
1378 // terminate the fling.
1379 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1380 EXPECT_CALL(mock_input_handler_,
1381 ScrollBy(testing::_,
1382 testing::Property(&gfx::Vector2dF::x, testing::Lt(1))))
1383 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1384 time += base::TimeDelta::FromMilliseconds(100);
1385 input_handler_->Animate(time);
1387 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1388 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1391 TEST_F(InputHandlerProxyTest, GestureFlingCancelledAfterBothAxesStopScrolling) {
1392 cc::InputHandlerScrollResult overscroll;
1393 overscroll.did_scroll = true;
1394 overscroll.did_overscroll_root = true;
1396 // We shouldn't send any events to the widget for this gesture.
1397 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1398 VERIFY_AND_RESET_MOCKS();
1400 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1401 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1402 gesture_.type = WebInputEvent::GestureScrollBegin;
1403 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1404 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1405 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1407 // On the fling start, we should schedule an animation but not actually start
1408 // scrolling.
1409 gesture_.type = WebInputEvent::GestureFlingStart;
1410 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1411 gesture_.data.flingStart.velocityX = fling_delta.x;
1412 gesture_.data.flingStart.velocityY = fling_delta.y;
1413 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1414 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1415 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1416 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1417 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1419 // The first animate doesn't cause any scrolling.
1420 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1421 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1422 input_handler_->Animate(time);
1423 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1425 // The second animate starts scrolling in the positive X and Y directions.
1426 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1427 EXPECT_CALL(mock_input_handler_,
1428 ScrollBy(testing::_,
1429 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1430 .WillOnce(testing::Return(scroll_result_did_scroll_));
1431 time += base::TimeDelta::FromMilliseconds(10);
1432 input_handler_->Animate(time);
1433 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1435 // The third animate hits the bottom content edge.
1436 overscroll.accumulated_root_overscroll = gfx::Vector2dF(0, 100);
1437 overscroll.unused_scroll_delta = gfx::Vector2dF(0, 100);
1438 EXPECT_CALL(mock_input_handler_,
1439 ScrollBy(testing::_,
1440 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1441 .WillOnce(testing::Return(overscroll));
1442 EXPECT_CALL(
1443 mock_client_,
1444 DidOverscroll(testing::AllOf(
1445 testing::Field(
1446 &DidOverscrollParams::accumulated_overscroll,
1447 testing::Eq(overscroll.accumulated_root_overscroll)),
1448 testing::Field(
1449 &DidOverscrollParams::latest_overscroll_delta,
1450 testing::Eq(overscroll.unused_scroll_delta)),
1451 testing::Field(
1452 &DidOverscrollParams::current_fling_velocity,
1453 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))));
1454 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1455 time += base::TimeDelta::FromMilliseconds(10);
1456 input_handler_->Animate(time);
1457 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1459 // The next call to animate will no longer scroll vertically.
1460 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1461 EXPECT_CALL(mock_input_handler_,
1462 ScrollBy(testing::_,
1463 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1464 .WillOnce(testing::Return(scroll_result_did_scroll_));
1465 time += base::TimeDelta::FromMilliseconds(10);
1466 input_handler_->Animate(time);
1467 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1469 // The next call will hit the right edge.
1470 overscroll.accumulated_root_overscroll = gfx::Vector2dF(100, 100);
1471 overscroll.unused_scroll_delta = gfx::Vector2dF(100, 0);
1472 EXPECT_CALL(mock_input_handler_,
1473 ScrollBy(testing::_,
1474 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1475 .WillOnce(testing::Return(overscroll));
1476 EXPECT_CALL(
1477 mock_client_,
1478 DidOverscroll(testing::AllOf(
1479 testing::Field(
1480 &DidOverscrollParams::accumulated_overscroll,
1481 testing::Eq(overscroll.accumulated_root_overscroll)),
1482 testing::Field(
1483 &DidOverscrollParams::latest_overscroll_delta,
1484 testing::Eq(overscroll.unused_scroll_delta)),
1485 testing::Field(
1486 &DidOverscrollParams::current_fling_velocity,
1487 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))));
1488 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1489 time += base::TimeDelta::FromMilliseconds(10);
1490 input_handler_->Animate(time);
1491 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1493 // The next call to animate will no longer scroll horizontally or vertically,
1494 // and the fling should be cancelled.
1495 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate()).Times(0);
1496 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
1497 time += base::TimeDelta::FromMilliseconds(10);
1498 input_handler_->Animate(time);
1499 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1500 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1503 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestNegative) {
1504 // None of the three touch points fall in the touch region. So the event
1505 // should be dropped.
1506 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
1507 VERIFY_AND_RESET_MOCKS();
1509 EXPECT_CALL(mock_input_handler_,
1510 DoTouchEventsBlockScrollAt(
1511 testing::Property(&gfx::Point::x, testing::Gt(0))))
1512 .WillOnce(testing::Return(false));
1513 EXPECT_CALL(mock_input_handler_,
1514 DoTouchEventsBlockScrollAt(
1515 testing::Property(&gfx::Point::x, testing::Lt(0))))
1516 .WillOnce(testing::Return(false));
1518 WebTouchEvent touch;
1519 touch.type = WebInputEvent::TouchStart;
1521 touch.touchesLength = 3;
1522 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StateStationary, 0, 0);
1523 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10);
1524 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10);
1525 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch));
1528 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestPositive) {
1529 // One of the touch points is on a touch-region. So the event should be sent
1530 // to the main thread.
1531 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
1532 VERIFY_AND_RESET_MOCKS();
1534 EXPECT_CALL(mock_input_handler_,
1535 DoTouchEventsBlockScrollAt(
1536 testing::Property(&gfx::Point::x, testing::Eq(0))))
1537 .WillOnce(testing::Return(false));
1538 EXPECT_CALL(mock_input_handler_,
1539 DoTouchEventsBlockScrollAt(
1540 testing::Property(&gfx::Point::x, testing::Gt(0))))
1541 .WillOnce(testing::Return(true));
1542 // Since the second touch point hits a touch-region, there should be no
1543 // hit-testing for the third touch point.
1545 WebTouchEvent touch;
1546 touch.type = WebInputEvent::TouchStart;
1548 touch.touchesLength = 3;
1549 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0);
1550 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10);
1551 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10);
1552 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch));
1555 TEST_F(InputHandlerProxyTest, GestureFlingCancelledByKeyboardEvent) {
1556 // We shouldn't send any events to the widget for this gesture.
1557 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1558 VERIFY_AND_RESET_MOCKS();
1560 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1561 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1562 gesture_.type = WebInputEvent::GestureScrollBegin;
1563 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1564 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1565 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1566 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1568 // Keyboard events received during a scroll should have no effect.
1569 WebKeyboardEvent key_event;
1570 key_event.type = WebInputEvent::KeyDown;
1571 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
1572 input_handler_->HandleInputEvent(key_event));
1573 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1574 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1576 // On the fling start, animation should be scheduled, but no scrolling occurs.
1577 gesture_.type = WebInputEvent::GestureFlingStart;
1578 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
1579 gesture_.data.flingStart.velocityX = fling_delta.x;
1580 gesture_.data.flingStart.velocityY = fling_delta.y;
1581 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1582 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1583 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1584 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1585 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1586 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1588 // Keyboard events received during a fling should cancel the active fling.
1589 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1590 EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
1591 input_handler_->HandleInputEvent(key_event));
1592 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1593 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1595 // The call to animate should have no effect, as the fling was cancelled.
1596 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1597 input_handler_->Animate(time);
1598 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1600 // A fling cancel should be dropped, as there is nothing to cancel.
1601 gesture_.type = WebInputEvent::GestureFlingCancel;
1602 EXPECT_EQ(InputHandlerProxy::DROP_EVENT,
1603 input_handler_->HandleInputEvent(gesture_));
1604 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1607 TEST_F(InputHandlerProxyTest, GestureFlingWithNegativeTimeDelta) {
1608 // We shouldn't send any events to the widget for this gesture.
1609 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1610 VERIFY_AND_RESET_MOCKS();
1612 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1613 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1615 gesture_.type = WebInputEvent::GestureScrollBegin;
1616 gesture_.sourceDevice = blink::WebGestureDeviceTouchscreen;
1617 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1619 VERIFY_AND_RESET_MOCKS();
1621 // On the fling start, we should schedule an animation but not actually start
1622 // scrolling.
1623 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1624 base::TimeTicks time = base::TimeTicks() + dt;
1625 WebFloatPoint fling_delta = WebFloatPoint(100, 0);
1626 WebPoint fling_point = WebPoint(7, 13);
1627 WebPoint fling_global_point = WebPoint(17, 23);
1628 int modifiers = WebInputEvent::ControlKey;
1629 gesture_ = CreateFling(time,
1630 blink::WebGestureDeviceTouchscreen,
1631 fling_delta,
1632 fling_point,
1633 fling_global_point,
1634 modifiers);
1635 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1636 EXPECT_CALL(mock_input_handler_, FlingScrollBegin())
1637 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1638 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1640 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1642 // If we get a negative time delta, that is, the Animation tick time happens
1643 // before the fling's start time then we should *not* try scrolling and
1644 // instead reset the fling start time.
1645 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1646 EXPECT_CALL(mock_input_handler_,
1647 ScrollBy(testing::_,
1648 testing::_)).Times(0);
1649 time -= base::TimeDelta::FromMilliseconds(5);
1650 input_handler_->Animate(time);
1652 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1654 // The first call should have reset the start time so subsequent calls should
1655 // generate scroll events.
1656 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1657 EXPECT_CALL(mock_input_handler_,
1658 ScrollBy(testing::_,
1659 testing::Property(&gfx::Vector2dF::x, testing::Lt(0))))
1660 .WillOnce(testing::Return(scroll_result_did_scroll_));
1662 input_handler_->Animate(time + base::TimeDelta::FromMilliseconds(1));
1664 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1666 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1667 gesture_.type = WebInputEvent::GestureFlingCancel;
1668 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1671 TEST_F(InputHandlerProxyTest, FlingBoost) {
1672 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1673 base::TimeTicks time = base::TimeTicks() + dt;
1674 base::TimeTicks last_animate_time = time;
1675 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1676 WebPoint fling_point = WebPoint(7, 13);
1677 StartFling(
1678 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1680 // Now cancel the fling. The fling cancellation should be deferred to allow
1681 // fling boosting events to arrive.
1682 time += dt;
1683 CancelFling(time);
1685 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1686 // scrolling layer.
1687 EXPECT_CALL(mock_input_handler_,
1688 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1689 .WillOnce(testing::Return(true));
1691 time += dt;
1692 gesture_.timeStampSeconds = InSecondsF(time);
1693 gesture_.type = WebInputEvent::GestureScrollBegin;
1694 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1696 VERIFY_AND_RESET_MOCKS();
1698 // Animate calls within the deferred cancellation window should continue.
1699 time += dt;
1700 float expected_delta =
1701 (time - last_animate_time).InSecondsF() * -fling_delta.x;
1702 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1703 EXPECT_CALL(mock_input_handler_,
1704 ScrollBy(testing::_,
1705 testing::Property(&gfx::Vector2dF::x,
1706 testing::Eq(expected_delta))))
1707 .WillOnce(testing::Return(scroll_result_did_scroll_));
1708 input_handler_->Animate(time);
1709 last_animate_time = time;
1711 VERIFY_AND_RESET_MOCKS();
1713 // GestureScrollUpdates in the same direction and at sufficient speed should
1714 // be swallowed by the fling.
1715 time += dt;
1716 gesture_.timeStampSeconds = InSecondsF(time);
1717 gesture_.type = WebInputEvent::GestureScrollUpdate;
1718 gesture_.data.scrollUpdate.deltaX = fling_delta.x;
1719 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1721 VERIFY_AND_RESET_MOCKS();
1723 // Animate calls within the deferred cancellation window should continue.
1724 time += dt;
1725 expected_delta = (time - last_animate_time).InSecondsF() * -fling_delta.x;
1726 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1727 EXPECT_CALL(mock_input_handler_,
1728 ScrollBy(testing::_,
1729 testing::Property(&gfx::Vector2dF::x,
1730 testing::Eq(expected_delta))))
1731 .WillOnce(testing::Return(scroll_result_did_scroll_));
1732 input_handler_->Animate(time);
1733 last_animate_time = time;
1735 VERIFY_AND_RESET_MOCKS();
1737 // GestureFlingStart in the same direction and at sufficient speed should
1738 // boost the active fling.
1740 gesture_ = CreateFling(time,
1741 blink::WebGestureDeviceTouchscreen,
1742 fling_delta,
1743 fling_point,
1744 fling_point,
1746 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1747 VERIFY_AND_RESET_MOCKS();
1749 time += dt;
1750 // Note we get *2x* as much delta because 2 flings have combined.
1751 expected_delta = 2 * (time - last_animate_time).InSecondsF() * -fling_delta.x;
1752 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1753 EXPECT_CALL(mock_input_handler_,
1754 ScrollBy(testing::_,
1755 testing::Property(&gfx::Vector2dF::x,
1756 testing::Eq(expected_delta))))
1757 .WillOnce(testing::Return(scroll_result_did_scroll_));
1758 input_handler_->Animate(time);
1759 last_animate_time = time;
1761 VERIFY_AND_RESET_MOCKS();
1763 // Repeated GestureFlingStarts should accumulate.
1765 CancelFling(time);
1766 gesture_ = CreateFling(time,
1767 blink::WebGestureDeviceTouchscreen,
1768 fling_delta,
1769 fling_point,
1770 fling_point,
1772 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1773 VERIFY_AND_RESET_MOCKS();
1775 time += dt;
1776 // Note we get *3x* as much delta because 3 flings have combined.
1777 expected_delta = 3 * (time - last_animate_time).InSecondsF() * -fling_delta.x;
1778 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1779 EXPECT_CALL(mock_input_handler_,
1780 ScrollBy(testing::_,
1781 testing::Property(&gfx::Vector2dF::x,
1782 testing::Eq(expected_delta))))
1783 .WillOnce(testing::Return(scroll_result_did_scroll_));
1784 input_handler_->Animate(time);
1785 last_animate_time = time;
1787 VERIFY_AND_RESET_MOCKS();
1789 // GestureFlingCancel should terminate the fling if no boosting gestures are
1790 // received within the timeout window.
1792 time += dt;
1793 gesture_.timeStampSeconds = InSecondsF(time);
1794 gesture_.type = WebInputEvent::GestureFlingCancel;
1795 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1797 VERIFY_AND_RESET_MOCKS();
1799 time += base::TimeDelta::FromMilliseconds(100);
1800 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1801 input_handler_->Animate(time);
1803 VERIFY_AND_RESET_MOCKS();
1806 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollTargetsDifferentLayer) {
1807 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1808 base::TimeTicks time = base::TimeTicks() + dt;
1809 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1810 WebPoint fling_point = WebPoint(7, 13);
1811 StartFling(
1812 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1814 // Cancel the fling. The fling cancellation should be deferred to allow
1815 // fling boosting events to arrive.
1816 time += dt;
1817 CancelFling(time);
1819 // If the GestureScrollBegin targets a different layer, the fling should be
1820 // cancelled and the scroll should be handled as usual.
1821 EXPECT_CALL(mock_input_handler_,
1822 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1823 .WillOnce(testing::Return(false));
1824 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1825 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1826 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1828 time += dt;
1829 gesture_.timeStampSeconds = InSecondsF(time);
1830 gesture_.type = WebInputEvent::GestureScrollBegin;
1831 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1833 VERIFY_AND_RESET_MOCKS();
1836 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollDelayed) {
1837 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1838 base::TimeTicks time = base::TimeTicks() + dt;
1839 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1840 WebPoint fling_point = WebPoint(7, 13);
1841 StartFling(
1842 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1844 // Cancel the fling. The fling cancellation should be deferred to allow
1845 // fling boosting events to arrive.
1846 time += dt;
1847 CancelFling(time);
1849 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1850 // scrolling layer.
1851 EXPECT_CALL(mock_input_handler_,
1852 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1853 .WillOnce(testing::Return(true));
1855 time += dt;
1856 gesture_.timeStampSeconds = InSecondsF(time);
1857 gesture_.type = WebInputEvent::GestureScrollBegin;
1858 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1860 VERIFY_AND_RESET_MOCKS();
1862 // If no GestureScrollUpdate or GestureFlingStart is received within the
1863 // timeout window, the fling should be cancelled and scrolling should resume.
1864 time += base::TimeDelta::FromMilliseconds(100);
1865 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1866 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1867 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1868 input_handler_->Animate(time);
1870 VERIFY_AND_RESET_MOCKS();
1873 TEST_F(InputHandlerProxyTest, NoFlingBoostIfFlingInDifferentDirection) {
1874 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1875 base::TimeTicks time = base::TimeTicks() + dt;
1876 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1877 WebPoint fling_point = WebPoint(7, 13);
1878 StartFling(
1879 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1881 // Cancel the fling. The fling cancellation should be deferred to allow
1882 // fling boosting events to arrive.
1883 time += dt;
1884 CancelFling(time);
1886 // If the new fling is orthogonal to the existing fling, no boosting should
1887 // take place, with the new fling replacing the old.
1888 WebFloatPoint orthogonal_fling_delta =
1889 WebFloatPoint(fling_delta.y, -fling_delta.x);
1890 gesture_ = CreateFling(time,
1891 blink::WebGestureDeviceTouchscreen,
1892 orthogonal_fling_delta,
1893 fling_point,
1894 fling_point,
1896 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1898 VERIFY_AND_RESET_MOCKS();
1900 // Note that the new fling delta uses the orthogonal, unboosted fling
1901 // velocity.
1902 time += dt;
1903 float expected_delta = dt.InSecondsF() * -orthogonal_fling_delta.y;
1904 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1905 EXPECT_CALL(mock_input_handler_,
1906 ScrollBy(testing::_,
1907 testing::Property(&gfx::Vector2dF::y,
1908 testing::Eq(expected_delta))))
1909 .WillOnce(testing::Return(scroll_result_did_scroll_));
1910 input_handler_->Animate(time);
1912 VERIFY_AND_RESET_MOCKS();
1915 TEST_F(InputHandlerProxyTest, NoFlingBoostIfScrollInDifferentDirection) {
1916 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1917 base::TimeTicks time = base::TimeTicks() + dt;
1918 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1919 WebPoint fling_point = WebPoint(7, 13);
1920 StartFling(
1921 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1923 // Cancel the fling. The fling cancellation should be deferred to allow
1924 // fling boosting events to arrive.
1925 time += dt;
1926 CancelFling(time);
1928 // The GestureScrollBegin should be swallowed by the fling if it hits the same
1929 // scrolling layer.
1930 EXPECT_CALL(mock_input_handler_,
1931 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
1932 .WillOnce(testing::Return(true));
1934 time += dt;
1935 gesture_.timeStampSeconds = InSecondsF(time);
1936 gesture_.type = WebInputEvent::GestureScrollBegin;
1937 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1939 VERIFY_AND_RESET_MOCKS();
1941 // If the GestureScrollUpdate is in a different direction than the fling,
1942 // the fling should be cancelled and scrolling should resume.
1943 time += dt;
1944 gesture_.timeStampSeconds = InSecondsF(time);
1945 gesture_.type = WebInputEvent::GestureScrollUpdate;
1946 gesture_.data.scrollUpdate.deltaX = -fling_delta.x;
1947 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1948 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1949 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
1950 EXPECT_CALL(mock_input_handler_,
1951 ScrollBy(testing::_,
1952 testing::Property(&gfx::Vector2dF::x,
1953 testing::Eq(fling_delta.x))))
1954 .WillOnce(testing::Return(scroll_result_did_scroll_));
1955 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1957 VERIFY_AND_RESET_MOCKS();
1960 TEST_F(InputHandlerProxyTest, NoFlingBoostIfFlingTooSlow) {
1961 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
1962 base::TimeTicks time = base::TimeTicks() + dt;
1963 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
1964 WebPoint fling_point = WebPoint(7, 13);
1965 StartFling(
1966 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
1968 // Cancel the fling. The fling cancellation should be deferred to allow
1969 // fling boosting events to arrive.
1970 time += dt;
1971 CancelFling(time);
1973 // If the new fling is too slow, no boosting should take place, with the new
1974 // fling replacing the old.
1975 WebFloatPoint small_fling_delta = WebFloatPoint(100, 0);
1976 gesture_ = CreateFling(time,
1977 blink::WebGestureDeviceTouchscreen,
1978 small_fling_delta,
1979 fling_point,
1980 fling_point,
1982 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1984 VERIFY_AND_RESET_MOCKS();
1986 // Note that the new fling delta uses the *slow*, unboosted fling velocity.
1987 time += dt;
1988 float expected_delta = dt.InSecondsF() * -small_fling_delta.x;
1989 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
1990 EXPECT_CALL(mock_input_handler_,
1991 ScrollBy(testing::_,
1992 testing::Property(&gfx::Vector2dF::x,
1993 testing::Eq(expected_delta))))
1994 .WillOnce(testing::Return(scroll_result_did_scroll_));
1995 input_handler_->Animate(time);
1997 VERIFY_AND_RESET_MOCKS();
2000 TEST_F(InputHandlerProxyTest, NoFlingBoostIfPreventBoostingFlagIsSet) {
2001 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
2002 base::TimeTicks time = base::TimeTicks() + dt;
2003 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
2004 WebPoint fling_point = WebPoint(7, 13);
2006 StartFling(
2007 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
2009 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2011 // Cancel the fling. The fling cancellation should not be deferred because of
2012 // prevent boosting flag set.
2013 gesture_.data.flingCancel.preventBoosting = true;
2014 time += dt;
2015 CancelFling(time);
2017 // VERIFY_AND_RESET_MOCKS already called by CancelFling
2020 TEST_F(InputHandlerProxyTest, FlingBoostTerminatedDuringScrollSequence) {
2021 base::TimeDelta dt = base::TimeDelta::FromMilliseconds(10);
2022 base::TimeTicks time = base::TimeTicks() + dt;
2023 base::TimeTicks last_animate_time = time;
2024 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
2025 WebPoint fling_point = WebPoint(7, 13);
2026 StartFling(
2027 time, blink::WebGestureDeviceTouchscreen, fling_delta, fling_point);
2029 // Now cancel the fling. The fling cancellation should be deferred to allow
2030 // fling boosting events to arrive.
2031 time += dt;
2032 CancelFling(time);
2034 // The GestureScrollBegin should be swallowed by the fling.
2035 time += dt;
2036 gesture_.timeStampSeconds = InSecondsF(time);
2037 gesture_.type = WebInputEvent::GestureScrollBegin;
2038 EXPECT_CALL(mock_input_handler_,
2039 IsCurrentlyScrollingLayerAt(testing::_, testing::_))
2040 .WillOnce(testing::Return(true));
2041 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2043 VERIFY_AND_RESET_MOCKS();
2045 // Now animate the fling to completion (in this case, the fling should
2046 // terminate because the input handler reports a failed scroll). As the fling
2047 // was cancelled during an active scroll sequence, a synthetic
2048 // GestureScrollBegin should be processed, resuming the scroll.
2049 time += dt;
2050 float expected_delta =
2051 (time - last_animate_time).InSecondsF() * -fling_delta.x;
2052 EXPECT_CALL(mock_input_handler_,
2053 ScrollBy(testing::_,
2054 testing::Property(&gfx::Vector2dF::x,
2055 testing::Eq(expected_delta))))
2056 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
2057 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2058 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
2059 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
2060 input_handler_->Animate(time);
2062 VERIFY_AND_RESET_MOCKS();
2064 // Subsequent GestureScrollUpdates after the cancelled, boosted fling should
2065 // cause scrolling as usual.
2066 time += dt;
2067 expected_delta = 7.3f;
2068 gesture_.timeStampSeconds = InSecondsF(time);
2069 gesture_.type = WebInputEvent::GestureScrollUpdate;
2070 gesture_.data.scrollUpdate.deltaX = -expected_delta;
2071 EXPECT_CALL(mock_input_handler_,
2072 ScrollBy(testing::_,
2073 testing::Property(&gfx::Vector2dF::x,
2074 testing::Eq(expected_delta))))
2075 .WillOnce(testing::Return(scroll_result_did_scroll_));
2076 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2078 VERIFY_AND_RESET_MOCKS();
2080 // GestureScrollEnd should terminate the resumed scroll properly.
2081 time += dt;
2082 gesture_.timeStampSeconds = InSecondsF(time);
2083 gesture_.type = WebInputEvent::GestureScrollEnd;
2084 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2085 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
2087 VERIFY_AND_RESET_MOCKS();
2090 TEST_F(InputHandlerProxyTest, DidReceiveInputEvent) {
2091 testing::StrictMock<
2092 MockInputHandlerProxyClientWithDidReceiveInputEvent> mock_client;
2093 input_handler_.reset(
2094 new content::InputHandlerProxy(&mock_input_handler_, &mock_client));
2096 // Note the type of input event isn't important.
2097 WebMouseWheelEvent wheel;
2098 wheel.type = WebInputEvent::MouseWheel;
2099 wheel.scrollByPage = true;
2101 EXPECT_CALL(mock_client,
2102 DidReceiveInputEvent(
2103 Field(&WebInputEvent::type, WebInputEvent::MouseWheel)));
2105 input_handler_->HandleInputEvent(wheel);
2106 testing::Mock::VerifyAndClearExpectations(&mock_client);
2109 TEST_F(InputHandlerProxyTest, DidReceiveInputEvent_ForFling) {
2110 testing::StrictMock<
2111 MockInputHandlerProxyClientWithDidReceiveInputEvent> mock_client;
2112 input_handler_.reset(
2113 new content::InputHandlerProxy(&mock_input_handler_, &mock_client));
2115 gesture_.type = WebInputEvent::GestureFlingStart;
2116 WebFloatPoint fling_delta = WebFloatPoint(100, 100);
2117 gesture_.data.flingStart.velocityX = fling_delta.x;
2118 gesture_.data.flingStart.velocityY = fling_delta.y;
2119 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
2120 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
2121 .WillOnce(testing::Return(cc::InputHandler::SCROLL_STARTED));
2122 EXPECT_CALL(mock_input_handler_, ScrollEnd());
2123 EXPECT_CALL(mock_client,
2124 DidReceiveInputEvent(Field(&WebInputEvent::type,
2125 WebInputEvent::GestureFlingStart)));
2126 EXPECT_EQ(InputHandlerProxy::DID_HANDLE,
2127 input_handler_->HandleInputEvent(gesture_));
2128 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
2129 testing::Mock::VerifyAndClearExpectations(&mock_client);
2131 EXPECT_CALL(mock_input_handler_, SetNeedsAnimate());
2132 EXPECT_CALL(mock_client, DidAnimateForInput());
2133 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
2134 input_handler_->Animate(time);
2136 testing::Mock::VerifyAndClearExpectations(&mock_client);
2139 } // namespace
2140 } // namespace content