Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1662)

Unified Diff: content/browser/renderer_host/input/touch_event_queue_unittest.cc

Issue 997283002: Coalesce async touch move events until the ack back from render (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made changes based on comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bebbf8cc25d536c1f1b6bd6db8487784b8be01f6 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,10 @@ class TouchEventQueueTest : public testing::Test,
base::MessageLoop::current()->Run();
}
+ int sent_uncancelable_touch_move_count() const {
+ return queue_->SentUncancelableTouchMoveCount();
+ }
+
private:
void SendTouchEvent() {
SendTouchEvent(touch_event_);
@@ -1655,7 +1663,7 @@ TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
// The pending touchmove should be flushed with the the new touchmove if
// sufficient time has passed.
AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
- MoveTouchPoint(0, 0, 15);
+ SendUncancelableTouchMoveEventAck();
EXPECT_FALSE(HasPendingAsyncTouchMove());
EXPECT_FALSE(sent_event().cancelable);
EXPECT_EQ(1U, queued_event_count());
@@ -1664,10 +1672,10 @@ TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
- EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ // EXPECT_EQ(1U, GetAndResetAckedEventCount());
// Non-touchmove events should always flush any pending touchmove events.
- MoveTouchPoint(0, 0, 25);
+ MoveTouchPoint(0, 10, 25);
EXPECT_TRUE(HasPendingAsyncTouchMove());
EXPECT_EQ(0U, queued_event_count());
EXPECT_EQ(0U, GetAndResetSentEventCount());
@@ -1831,6 +1839,7 @@ TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
EXPECT_EQ(1U, GetAndResetAckedEventCount());
AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
+ SendUncancelableTouchMoveEventAck();
MoveTouchPoint(0, 5, 5);
EXPECT_FALSE(IsTimeoutRunning());
EXPECT_FALSE(HasPendingAsyncTouchMove());
@@ -1971,6 +1980,292 @@ TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) {
EXPECT_EQ(1U, GetAndResetAckedEventCount());
}
+// Ensure that even when the interval expires, we still need to wait for the
+// ack sent back from render to send the next async touchmove once the scroll
+// starts.
+TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
+ // 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, because
+ // we've now started scrolling, and we throttle the touchmoves.
+ MoveTouchPoint(0, 0, 20);
+ EXPECT_TRUE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+
+ // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
+ // dispatch it yet.
+ 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());
+
+ // We receive the fake ack for touchmove and clear the queue.
+ 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());
+}
+
+// Ensure that even when we receive the ack from render, we still need to wait
+// for the interval expires to send the next async touchmove once the scroll
+// starts.
+TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
+ // 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, because
+ // we've now started scrolling, and we throttle the touchmoves.
+ MoveTouchPoint(0, 0, 20);
+ EXPECT_TRUE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+
+ // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
+ // dispatch it yet.
+ 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());
+
+ // We receive the fake ack for touchmove and clear the queue.
+ SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+
+ // We receive an ack back from render but the time interval is not expired,
+ // so we do not dispatch the event.
+ SendUncancelableTouchMoveEventAck();
+ EXPECT_EQ(0, sent_uncancelable_touch_move_count());
+
+ MoveTouchPoint(0, 0, 50);
+ EXPECT_TRUE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+
+ AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
+ MoveTouchPoint(0, 0, 50);
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
+ 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());
+}
+
+TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
+ // 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, because
+ // we've now started scrolling, and we throttle the touchmoves.
+ MoveTouchPoint(0, 0, 20);
+ 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());
+
+ for (int i = 0; i < 3; ++i) {
+ MoveTouchPoint(0, 10+10*i, 10+10*i);
+ EXPECT_TRUE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ EXPECT_EQ(i+1, sent_uncancelable_touch_move_count());
+
+ // Send touchstart will flush pending_async_touch_move_, and increse the
tdresser 2015/03/26 15:25:29 increse -> increase
lanwei 2015/03/27 04:39:42 Done.
+ // count.
+ PressTouchPoint(30, 30);
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
+ EXPECT_FALSE(sent_event().cancelable);
+ EXPECT_EQ(10+10*i, sent_event().touches[0].position.x);
+ EXPECT_EQ(10+10*i, sent_event().touches[0].position.y);
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+ EXPECT_EQ(i+2, sent_uncancelable_touch_move_count());
tdresser 2015/03/26 15:25:29 Nice test, thanks!
+
+ // Touchstart is cancelable during async touch dispatch.
+ SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
+ EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
+ EXPECT_TRUE(sent_event().cancelable);
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+ EXPECT_EQ(0U, GetAndResetAckedEventCount());
+ EXPECT_EQ(i+2, sent_uncancelable_touch_move_count());
+
+ SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ }
+
+ EXPECT_EQ(4, sent_uncancelable_touch_move_count());
+ // When we receive an ack from render we decrease the count.
+ SendUncancelableTouchMoveEventAck();
+ EXPECT_EQ(3, sent_uncancelable_touch_move_count());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+
+ // Do not dispatch the next uncancelable touchmove when we have not recevied
+ // all the acks back from render.
+ AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
+ MoveTouchPoint(0, 20, 30);
+ EXPECT_TRUE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(0U, queued_event_count());
+ EXPECT_EQ(0U, GetAndResetSentEventCount());
+ EXPECT_EQ(1U, GetAndResetAckedEventCount());
+ EXPECT_EQ(3, sent_uncancelable_touch_move_count());
+
+ // Once we receive the ack from render, we will dispatch the
+ // pending_async_touchmove_.
+ SendUncancelableTouchMoveEventAck();
+ EXPECT_EQ(3, sent_uncancelable_touch_move_count());
+ EXPECT_EQ(1U, queued_event_count());
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
+ EXPECT_FALSE(sent_event().cancelable);
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+ EXPECT_EQ(0U, GetAndResetAckedEventCount());
+
+ SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ SendUncancelableTouchMoveEventAck();
+ SendUncancelableTouchMoveEventAck();
+ SendUncancelableTouchMoveEventAck();
+ EXPECT_EQ(0, sent_uncancelable_touch_move_count());
+
+ // Dispatch the next uncancelable touchmove when we have recevied all the
+ // acks back from render and time expires.
+ MoveTouchPoint(0, 30, 30);
+ EXPECT_FALSE(HasPendingAsyncTouchMove());
+ EXPECT_EQ(1U, queued_event_count());
+ EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
+ EXPECT_FALSE(sent_event().cancelable);
+ EXPECT_EQ(1U, GetAndResetSentEventCount());
+ EXPECT_EQ(0U, GetAndResetAckedEventCount());
+ EXPECT_EQ(1, sent_uncancelable_touch_move_count());
+}
+
TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
// Queue a TouchStart.
PressTouchPoint(0, 1);
@@ -2059,6 +2354,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);

Powered by Google App Engine
This is Rietveld 408576698