313 gesture.type = WebKit::WebInputEvent::GestureScrollEnd;
314 gesture.deltaX = 2;
315 inputHandler->handleInputEvent(gesture);
316 EXPECT_TRUE(mockClient.handled());
317 EXPECT_FALSE(mockClient.sendToWidget());
318 ASSERT_TRUE(mockInputHandler.activeGestureAnimation());
319 EXPECT_FALSE(mockInputHandler.scrollByCalled());
320 mockInputHandler.activeGestureAnimation()->animate(0.001);
321 EXPECT_TRUE(mockInputHandler.scrollByCalled());
322 mockClient.reset();
323
324 // Verify that a GestureTapDown during an animation cancels it.
325 gesture.type = WebKit::WebInputEvent::GestureTapDown;
326 inputHandler->handleInputEvent(gesture);
327 EXPECT_FALSE(mockInputHandler.activeGestureAnimation());
328 mockClient.reset();
329
330 // Verify that a GestureTapDown when no animation is active is not handled.
331 gesture.type = WebKit::WebInputEvent::GestureTapDown;
332 inputHandler->handleInputEvent(gesture);
333 EXPECT_FALSE(mockClient.handled());
334 EXPECT_TRUE(mockClient.sendToWidget());
335
336 inputHandler->setClient(0);
337 WebKit::WebCompositor::shutdown();
278TEST_F(WebCompositorInputHandlerImplTest, gestureFlingAnimates)
279{
280 // We should handle the entire sequence ourselves.
281 EXPECT_CALL(m_mockClient, didNotHandleInputEvent(::testing::_)).Times(0);
282
283 // On the fling start, we should schedule an animation but not actually start
284 // scrolling.
285 gesture.type = WebKit::WebInputEvent::GestureFlingStart;
286 gesture.deltaX = -1000;
287 EXPECT_CALL(m_mockClient, didHandleInputEvent());
288 EXPECT_CALL(m_mockInputHandler, scheduleAnimation());
289 EXPECT_CALL(m_mockInputHandler, scrollBegin(testing::_, testing::_))
290 .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
291 m_inputHandler->handleInputEvent(gesture);
292
293 // The first animate call should let us pick up an animation start time, but we
294 // shouldn't actually move anywhere just yet. The first frame after the fling start
295 // will typically include the last scroll from the gesture that lead to the scroll
296 // (either wheel or gesture scroll), so there should be no visible hitch.
297 EXPECT_CALL(m_mockInputHandler, scheduleAnimation());
298 EXPECT_CALL(m_mockInputHandler, scrollBegin(testing::_, testing::_)).Times(0);
299 m_inputHandler->animate(10);
300
301 // The second call should start scrolling in the +X direction.
302 EXPECT_CALL(m_mockInputHandler, scheduleAnimation());
303 EXPECT_CALL(m_mockInputHandler, scrollBegin(testing::_, testing::_))
304 .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
305 EXPECT_CALL(m_mockInputHandler, scrollBy(testing::Property(&WebCore::IntSize::width, testing::Gt(0))));
306 EXPECT_CALL(m_mockInputHandler, scrollEnd());
307 m_inputHandler->animate(10.1);
308
309 // Let's say on the third call we hit a non-scrollable region. We should abort the fling and not scroll.
310 // FIXME: We also need to do some work to transfer the rest of this fling to the main thread.
311 // Add tests for this once it's implemented.
312 EXPECT_CALL(m_mockInputHandler, scheduleAnimation());
313 EXPECT_CALL(m_mockInputHandler, scrollBegin(testing::_, testing::_))
314 .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollIgnored));
315 EXPECT_CALL(m_mockInputHandler, scrollBy(testing::_)).Times(0);
316 EXPECT_CALL(m_mockInputHandler, scrollEnd()).Times(0);
317 m_inputHandler->animate(10.2);
318
319 // Since we've aborted the fling, the next animation should be a no-op and should not result in another
320 // frame being requested.
321 EXPECT_CALL(m_mockInputHandler, scheduleAnimation()).Times(0);
322 EXPECT_CALL(m_mockInputHandler, scrollBegin(testing::_, testing::_)).Times(0);
323 m_inputHandler->animate(10.3);