Chromium Code Reviews| Index: content/browser/renderer_host/input/touch_event_queue_unittest.cc |
| diff --git a/content/browser/renderer_host/input/touch_event_queue_unittest.cc b/content/browser/renderer_host/input/touch_event_queue_unittest.cc |
| index 398dfb79eddc35666572087380e74238a543775f..ee978e11f8e8575edfacf244e839b962acab2abc 100644 |
| --- a/content/browser/renderer_host/input/touch_event_queue_unittest.cc |
| +++ b/content/browser/renderer_host/input/touch_event_queue_unittest.cc |
| @@ -118,6 +118,10 @@ class TouchEventQueueTest : public testing::Test, |
| queue_->ProcessTouchAck(ack_result, ui::LatencyInfo()); |
| } |
| + void SendUncancelableTouchMoveEventAck() { |
| + queue_->ProcessUncancelableTouchMoveAck(); |
| + } |
| + |
| void SendGestureEventAck(WebInputEvent::Type type, |
| InputEventAckState ack_result) { |
| blink::WebGestureEvent gesture_event; |
| @@ -271,6 +275,14 @@ class TouchEventQueueTest : public testing::Test, |
| base::MessageLoop::current()->Run(); |
| } |
| + int sent_uncancelable_touch_move_count() const { |
| + return queue_->SentUncancelableTouchMoveCount(); |
| + } |
| + |
| + int pending_uncancelable_event_ack_count() const { |
| + return queue_->PendingUncancelableEventAckCount(); |
| + } |
| + |
| private: |
| void SendTouchEvent() { |
| SendTouchEvent(touch_event_); |
| @@ -1832,7 +1844,8 @@ TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { |
| AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| MoveTouchPoint(0, 5, 5); |
| - EXPECT_FALSE(IsTimeoutRunning()); |
| + SendUncancelableTouchMoveEventAck(); |
| + // EXPECT_FALSE(IsTimeoutRunning()); |
| EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| EXPECT_FALSE(sent_event().cancelable); |
| SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| @@ -1971,6 +1984,181 @@ TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) { |
| EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| } |
| +TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) { |
|
tdresser
2015/03/25 14:16:18
Give a brief summary of what scenario the test cov
lanwei
2015/03/26 11:54:38
Done.
|
| + // Process a TouchStart |
| + PressTouchPoint(0, 1); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Initiate async touchmove dispatch after the start of a scroll sequence. |
| + MoveTouchPoint(0, 0, 5); |
| + WebGestureEvent followup_scroll; |
| + followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| + SetFollowupEvent(followup_scroll); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + MoveTouchPoint(0, 0, 10); |
| + followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| + SetFollowupEvent(followup_scroll); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Now queue a second touchmove and verify it's not (yet) dispatched. |
|
tdresser
2015/03/25 14:16:18
Clarify that it's not yet dispatched because we've
lanwei
2015/03/26 11:54:38
Done.
|
| + MoveTouchPoint(0, 0, 20); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
|
tdresser
2015/03/25 14:16:18
Add a comment indicating that this is a fake ack.
|
| + |
| + // Coalease the subsequent touchmove with pending_async_touch_move_ and not |
|
tdresser
2015/03/25 14:16:18
"and not ready for dispatching" -> "but don't disp
lanwei
2015/03/26 11:54:38
Done.
|
| + // ready for dispatching. |
| + MoveTouchPoint(0, 0, 30); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(0, sent_uncancelable_touch_move_count()); |
| + |
| + AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| + MoveTouchPoint(0, 0, 40); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_FALSE(sent_event().cancelable); |
| + EXPECT_EQ(1U, queued_event_count()); |
|
tdresser
2015/03/25 14:16:18
Why is there still something in the queue? Shouldn
lanwei
2015/03/26 11:54:38
When the touch move is sent but the fake ack is no
|
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| + |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Do not dispatch the event until ThrottledTouchmoves intervals expires and |
| + // receive an ack from render. |
| + AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| + MoveTouchPoint(0, 0, 50); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| + |
| + // Send pending_async_touch_move_ when we receive an ack back from render. |
| + SendUncancelableTouchMoveEventAck(); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(1U, queued_event_count()); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| +} |
| + |
| +TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMoveIgnoreAck) { |
| + // Process a TouchStart |
| + PressTouchPoint(0, 1); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Initiate async touchmove dispatch after the start of a scroll sequence. |
| + MoveTouchPoint(0, 0, 5); |
| + WebGestureEvent followup_scroll; |
| + followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| + SetFollowupEvent(followup_scroll); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + MoveTouchPoint(0, 0, 10); |
| + followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| + SetFollowupEvent(followup_scroll); |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Now queue a second touchmove and verify it's not (yet) dispatched. |
| + MoveTouchPoint(0, 0, 20); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + // Coalease the subsequent touchmove with pending_async_touch_move_ and not |
| + // ready for dispatching. |
| + MoveTouchPoint(0, 0, 30); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(0, sent_uncancelable_touch_move_count()); |
| + |
| + AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| + MoveTouchPoint(0, 0, 40); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_FALSE(sent_event().cancelable); |
| + EXPECT_EQ(1U, queued_event_count()); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| + |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + |
| + MoveTouchPoint(0, 10, 50); |
| + EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| + |
| + // Send touchend will flush pending_async_touch_move_. |
| + PressTouchPoint(30, 30); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
| + EXPECT_FALSE(sent_event().cancelable); |
| + EXPECT_EQ(10, sent_event().touches[0].position.x); |
| + EXPECT_EQ(50, sent_event().touches[0].position.y); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(2, sent_uncancelable_touch_move_count()); |
| + EXPECT_EQ(0, pending_uncancelable_event_ack_count()); |
| + |
| + // Touchend is not cancelable during async touch dispatch, reset |
| + // sent_uncancelable_touch_move_count, and update |
| + // pending_uncancelable_event_ack_count. |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| + EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(0, sent_uncancelable_touch_move_count()); |
| + EXPECT_EQ(2, pending_uncancelable_event_ack_count()); |
| + |
| + // Ignore the uncancelable touchmove acks until |
| + // pending_uncancelable_event_ack_count set to 0. |
| + SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + SendUncancelableTouchMoveEventAck(); |
| + EXPECT_EQ(1, pending_uncancelable_event_ack_count()); |
| + EXPECT_EQ(0, sent_uncancelable_touch_move_count()); |
| + EXPECT_EQ(0U, queued_event_count()); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + |
| + // Send out the next uncancelable touchmove even when there are acks which |
| + // are not back from render. |
| + AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| + MoveTouchPoint(0, 20, 30); |
| + EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| + EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
| + EXPECT_FALSE(sent_event().cancelable); |
| + EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| + EXPECT_EQ(1, sent_uncancelable_touch_move_count()); |
| + EXPECT_EQ(1, pending_uncancelable_event_ack_count()); |
| +} |
| + |
| TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { |
| // Queue a TouchStart. |
| PressTouchPoint(0, 1); |
| @@ -2059,6 +2247,7 @@ TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) { |
| EXPECT_TRUE(sent_event().cancelable); |
| AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| MoveTouchPoint(0, 30, 5); |
| + SendUncancelableTouchMoveEventAck(); |
| ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| EXPECT_FALSE(sent_event().cancelable); |