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

Side by Side 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: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/renderer_host/input/timeout_monitor.h" 9 #include "content/browser/renderer_host/input/timeout_monitor.h"
10 #include "content/browser/renderer_host/input/touch_event_queue.h" 10 #include "content/browser/renderer_host/input/touch_event_queue.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 WebGestureEvent event; 111 WebGestureEvent event;
112 event.type = type; 112 event.type = type;
113 queue_->OnGestureScrollEvent( 113 queue_->OnGestureScrollEvent(
114 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); 114 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
115 } 115 }
116 116
117 void SendTouchEventAck(InputEventAckState ack_result) { 117 void SendTouchEventAck(InputEventAckState ack_result) {
118 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo()); 118 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo());
119 } 119 }
120 120
121 void SendUncancelableTouchMoveEventAck() {
122 queue_->ProcessUncancelableTouchMoveAck();
123 }
124
121 void SendGestureEventAck(WebInputEvent::Type type, 125 void SendGestureEventAck(WebInputEvent::Type type,
122 InputEventAckState ack_result) { 126 InputEventAckState ack_result) {
123 blink::WebGestureEvent gesture_event; 127 blink::WebGestureEvent gesture_event;
124 gesture_event.type = type; 128 gesture_event.type = type;
125 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo()); 129 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo());
126 queue_->OnGestureEventAck(event, ack_result); 130 queue_->OnGestureEventAck(event, ack_result);
127 } 131 }
128 132
129 void SetFollowupEvent(const WebTouchEvent& event) { 133 void SetFollowupEvent(const WebTouchEvent& event) {
130 followup_touch_event_.reset(new WebTouchEvent(event)); 134 followup_touch_event_.reset(new WebTouchEvent(event));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 InputEventAckState acked_event_state() const { 268 InputEventAckState acked_event_state() const {
265 return last_acked_event_state_; 269 return last_acked_event_state_;
266 } 270 }
267 271
268 static void RunTasksAndWait(base::TimeDelta delay) { 272 static void RunTasksAndWait(base::TimeDelta delay) {
269 base::MessageLoop::current()->PostDelayedTask( 273 base::MessageLoop::current()->PostDelayedTask(
270 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 274 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
271 base::MessageLoop::current()->Run(); 275 base::MessageLoop::current()->Run();
272 } 276 }
273 277
278 int uncancelable_touch_moves_pending_ack_count() const {
279 return queue_->UncancelableTouchMovesPendingAckCount();
280 }
281
274 private: 282 private:
275 void SendTouchEvent() { 283 void SendTouchEvent() {
276 SendTouchEvent(touch_event_); 284 SendTouchEvent(touch_event_);
277 touch_event_.ResetPoints(); 285 touch_event_.ResetPoints();
278 } 286 }
279 287
280 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { 288 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
281 queue_.reset(new TouchEventQueue(this, config)); 289 queue_.reset(new TouchEventQueue(this, config));
282 queue_->OnHasTouchEventHandlers(true); 290 queue_->OnHasTouchEventHandlers(true);
283 } 291 }
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 followup_scroll.type = WebInputEvent::GestureScrollBegin; 1635 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1628 SetFollowupEvent(followup_scroll); 1636 SetFollowupEvent(followup_scroll);
1629 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1637 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1630 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1638 EXPECT_EQ(1U, GetAndResetSentEventCount());
1631 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1639 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1632 1640
1633 MoveTouchPoint(0, 0, 6); 1641 MoveTouchPoint(0, 0, 6);
1634 followup_scroll.type = WebInputEvent::GestureScrollUpdate; 1642 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1635 SetFollowupEvent(followup_scroll); 1643 SetFollowupEvent(followup_scroll);
1636 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1644 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1645 SendUncancelableTouchMoveEventAck();
1637 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1646 EXPECT_FALSE(HasPendingAsyncTouchMove());
1638 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1647 EXPECT_EQ(1U, GetAndResetSentEventCount());
1639 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1648 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1640 1649
1641 MoveTouchPoint(0, 0, 10); 1650 MoveTouchPoint(0, 0, 10);
1642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1651 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1643 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1652 EXPECT_TRUE(HasPendingAsyncTouchMove());
1644 EXPECT_EQ(0U, queued_event_count()); 1653 EXPECT_EQ(0U, queued_event_count());
1645 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1654 EXPECT_EQ(0U, GetAndResetSentEventCount());
1646 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1655 EXPECT_EQ(1U, GetAndResetAckedEventCount());
(...skipping 13 matching lines...) Expand all
1660 EXPECT_FALSE(sent_event().cancelable); 1669 EXPECT_FALSE(sent_event().cancelable);
1661 EXPECT_EQ(1U, queued_event_count()); 1670 EXPECT_EQ(1U, queued_event_count());
1662 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1671 EXPECT_EQ(1U, GetAndResetSentEventCount());
1663 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1672 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1673 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1665 EXPECT_EQ(0U, queued_event_count()); 1674 EXPECT_EQ(0U, queued_event_count());
1666 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1675 EXPECT_EQ(0U, GetAndResetSentEventCount());
1667 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1676 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1668 1677
1669 // Non-touchmove events should always flush any pending touchmove events. 1678 // Non-touchmove events should always flush any pending touchmove events.
1670 MoveTouchPoint(0, 0, 25); 1679 MoveTouchPoint(0, 10, 25);
tdresser 2015/03/27 13:34:44 Why the change in location?
lanwei 2015/03/31 13:07:49 Done.
1671 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1680 EXPECT_TRUE(HasPendingAsyncTouchMove());
1672 EXPECT_EQ(0U, queued_event_count()); 1681 EXPECT_EQ(0U, queued_event_count());
1673 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1682 EXPECT_EQ(0U, GetAndResetSentEventCount());
1674 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1683 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1675 PressTouchPoint(30, 30); 1684 PressTouchPoint(30, 30);
1676 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1685 EXPECT_FALSE(HasPendingAsyncTouchMove());
1677 EXPECT_FALSE(sent_event().cancelable); 1686 EXPECT_FALSE(sent_event().cancelable);
1678 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1687 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1679 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1688 EXPECT_EQ(1U, GetAndResetSentEventCount());
1680 EXPECT_EQ(2U, queued_event_count()); 1689 EXPECT_EQ(2U, queued_event_count());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1833 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1825 INPUT_EVENT_ACK_STATE_CONSUMED); 1834 INPUT_EVENT_ACK_STATE_CONSUMED);
1826 1835
1827 // An async touch should fire after the throttling interval has expired, but 1836 // An async touch should fire after the throttling interval has expired, but
1828 // it should not start the touch ack timeout. 1837 // it should not start the touch ack timeout.
1829 MoveTouchPoint(0, 5, 5); 1838 MoveTouchPoint(0, 5, 5);
1830 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1839 EXPECT_TRUE(HasPendingAsyncTouchMove());
1831 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1840 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1832 1841
1833 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 1842 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1843 SendUncancelableTouchMoveEventAck();
1834 MoveTouchPoint(0, 5, 5); 1844 MoveTouchPoint(0, 5, 5);
1835 EXPECT_FALSE(IsTimeoutRunning()); 1845 EXPECT_FALSE(IsTimeoutRunning());
1836 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1846 EXPECT_FALSE(HasPendingAsyncTouchMove());
1837 EXPECT_FALSE(sent_event().cancelable); 1847 EXPECT_FALSE(sent_event().cancelable);
1838 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1848 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1839 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1849 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1840 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1850 EXPECT_EQ(1U, GetAndResetSentEventCount());
1841 1851
1842 // An unconsumed scroll event will resume synchronous touchmoves, which are 1852 // An unconsumed scroll event will resume synchronous touchmoves, which are
1843 // subject to the ack timeout. 1853 // subject to the ack timeout.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 SendGestureEvent(WebInputEvent::GestureScrollEnd); 1974 SendGestureEvent(WebInputEvent::GestureScrollEnd);
1965 ResetTouchEvent(); 1975 ResetTouchEvent();
1966 1976
1967 PressTouchPoint(0, 0); 1977 PressTouchPoint(0, 0);
1968 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1978 EXPECT_EQ(1U, GetAndResetSentEventCount());
1969 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); 1979 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1970 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1980 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1971 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1981 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1972 } 1982 }
1973 1983
1984 // Ensure that even when the interval expires, we still need to wait for the
1985 // ack sent back from render to send the next async touchmove once the scroll
1986 // starts.
1987 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
1988 // Process a TouchStart
1989 PressTouchPoint(0, 1);
1990 EXPECT_EQ(1U, GetAndResetSentEventCount());
1991 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1992 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1993
1994 // Initiate async touchmove dispatch after the start of a scroll sequence.
1995 MoveTouchPoint(0, 0, 5);
1996 WebGestureEvent followup_scroll;
1997 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1998 SetFollowupEvent(followup_scroll);
1999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2000 EXPECT_EQ(1U, GetAndResetSentEventCount());
2001 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2002
2003 MoveTouchPoint(0, 0, 10);
2004 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2005 SetFollowupEvent(followup_scroll);
2006 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2007 EXPECT_FALSE(HasPendingAsyncTouchMove());
2008 EXPECT_EQ(1U, GetAndResetSentEventCount());
2009 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2010
2011 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2012 // we've now started scrolling, and we throttle the touchmoves.
2013 MoveTouchPoint(0, 0, 20);
2014 EXPECT_TRUE(HasPendingAsyncTouchMove());
2015 EXPECT_EQ(0U, queued_event_count());
2016 EXPECT_EQ(0U, GetAndResetSentEventCount());
2017 EXPECT_EQ(1U, GetAndResetAckedEventCount());
tdresser 2015/03/27 13:34:44 Add a comment that this was a fake ack. It's proba
lanwei 2015/03/31 13:07:49 Done.
2018
2019 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
2020 // dispatch it yet.
2021 MoveTouchPoint(0, 0, 30);
2022 EXPECT_TRUE(HasPendingAsyncTouchMove());
2023 EXPECT_EQ(0U, queued_event_count());
2024 EXPECT_EQ(0U, GetAndResetSentEventCount());
2025 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2026 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count());
2027
tdresser 2015/03/27 13:34:44 Add a comment describing what happens below.
lanwei 2015/03/31 13:07:49 Done.
2028 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
tdresser 2015/03/27 13:34:44 It might be clearer what's happening if we had a s
lanwei 2015/03/31 13:07:49 Done.
lanwei 2015/03/31 13:07:49 Done.
2029 MoveTouchPoint(0, 0, 40);
2030 EXPECT_FALSE(HasPendingAsyncTouchMove());
2031 EXPECT_FALSE(sent_event().cancelable);
2032 EXPECT_EQ(1U, queued_event_count());
2033 EXPECT_EQ(1U, GetAndResetSentEventCount());
2034 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2035 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2036
2037 // We receive the fake ack for touchmove and clear the queue.
tdresser 2015/03/27 13:34:44 Which touchmove is this the fake ack for? The fake
2038 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2039 EXPECT_EQ(0U, queued_event_count());
2040 EXPECT_EQ(0U, GetAndResetSentEventCount());
2041 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2042
2043 // Do not dispatch the event until ThrottledTouchmoves intervals expires and
2044 // receive an ack from render.
2045 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2046 MoveTouchPoint(0, 0, 50);
2047 EXPECT_TRUE(HasPendingAsyncTouchMove());
2048 EXPECT_EQ(0U, queued_event_count());
2049 EXPECT_EQ(0U, GetAndResetSentEventCount());
2050 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2051 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2052
2053 // Send pending_async_touch_move_ when we receive an ack back from render.
2054 SendUncancelableTouchMoveEventAck();
2055 EXPECT_FALSE(HasPendingAsyncTouchMove());
2056 EXPECT_EQ(1U, queued_event_count());
2057 EXPECT_EQ(1U, GetAndResetSentEventCount());
2058 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2059 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2060 }
2061
2062 // Ensure that even when we receive the ack from render, we still need to wait
2063 // for the interval expires to send the next async touchmove once the scroll
2064 // starts.
2065 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
2066 // Process a TouchStart
2067 PressTouchPoint(0, 1);
2068 EXPECT_EQ(1U, GetAndResetSentEventCount());
2069 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2070 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2071
2072 // Initiate async touchmove dispatch after the start of a scroll sequence.
2073 MoveTouchPoint(0, 0, 5);
2074 WebGestureEvent followup_scroll;
2075 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2076 SetFollowupEvent(followup_scroll);
2077 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2078 EXPECT_EQ(1U, GetAndResetSentEventCount());
2079 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2080
2081 MoveTouchPoint(0, 0, 10);
2082 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2083 SetFollowupEvent(followup_scroll);
2084 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2085 EXPECT_FALSE(HasPendingAsyncTouchMove());
2086 EXPECT_EQ(1U, GetAndResetSentEventCount());
2087 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2088
2089 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2090 // we've now started scrolling, and we throttle the touchmoves.
2091 MoveTouchPoint(0, 0, 20);
2092 EXPECT_TRUE(HasPendingAsyncTouchMove());
2093 EXPECT_EQ(0U, queued_event_count());
2094 EXPECT_EQ(0U, GetAndResetSentEventCount());
2095 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2096
2097 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
2098 // dispatch it yet.
2099 MoveTouchPoint(0, 0, 30);
2100 EXPECT_TRUE(HasPendingAsyncTouchMove());
2101 EXPECT_EQ(0U, queued_event_count());
2102 EXPECT_EQ(0U, GetAndResetSentEventCount());
2103 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2104 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count());
2105
2106 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2107 MoveTouchPoint(0, 0, 40);
2108 EXPECT_FALSE(HasPendingAsyncTouchMove());
2109 EXPECT_FALSE(sent_event().cancelable);
2110 EXPECT_EQ(1U, queued_event_count());
2111 EXPECT_EQ(1U, GetAndResetSentEventCount());
2112 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2113 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2114
2115 // We receive the fake ack for touchmove and clear the queue.
2116 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2117 EXPECT_EQ(0U, queued_event_count());
2118 EXPECT_EQ(0U, GetAndResetSentEventCount());
2119 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2120
2121 // We receive an ack back from render but the time interval is not expired,
2122 // so we do not dispatch the event.
2123 SendUncancelableTouchMoveEventAck();
2124 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count());
2125
2126 MoveTouchPoint(0, 0, 50);
2127 EXPECT_TRUE(HasPendingAsyncTouchMove());
2128 EXPECT_EQ(0U, queued_event_count());
2129 EXPECT_EQ(0U, GetAndResetSentEventCount());
2130 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2131
2132 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2133 MoveTouchPoint(0, 0, 50);
2134 EXPECT_FALSE(HasPendingAsyncTouchMove());
2135 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2136 EXPECT_FALSE(sent_event().cancelable);
2137 EXPECT_EQ(1U, queued_event_count());
2138 EXPECT_EQ(1U, GetAndResetSentEventCount());
2139 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2140 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2141 }
2142
2143 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
2144 // Process a TouchStart
2145 PressTouchPoint(0, 1);
2146 EXPECT_EQ(1U, GetAndResetSentEventCount());
2147 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2148 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2149
2150 // Initiate async touchmove dispatch after the start of a scroll sequence.
2151 MoveTouchPoint(0, 0, 5);
2152 WebGestureEvent followup_scroll;
2153 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2154 SetFollowupEvent(followup_scroll);
2155 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2156 EXPECT_EQ(1U, GetAndResetSentEventCount());
2157 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2158
2159 MoveTouchPoint(0, 0, 10);
2160 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2161 SetFollowupEvent(followup_scroll);
2162 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2163 EXPECT_FALSE(HasPendingAsyncTouchMove());
2164 EXPECT_EQ(1U, GetAndResetSentEventCount());
2165 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2166
2167 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2168 // we've now started scrolling, and we throttle the touchmoves.
2169 MoveTouchPoint(0, 0, 20);
2170 EXPECT_TRUE(HasPendingAsyncTouchMove());
2171 EXPECT_EQ(0U, queued_event_count());
2172 EXPECT_EQ(0U, GetAndResetSentEventCount());
2173 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2174 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count());
2175
2176 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2177 MoveTouchPoint(0, 0, 40);
2178 EXPECT_FALSE(HasPendingAsyncTouchMove());
2179 EXPECT_FALSE(sent_event().cancelable);
2180 EXPECT_EQ(1U, queued_event_count());
2181 EXPECT_EQ(1U, GetAndResetSentEventCount());
2182 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2183 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2184
2185 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2186 EXPECT_EQ(0U, queued_event_count());
2187 EXPECT_EQ(0U, GetAndResetSentEventCount());
2188 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2189
2190 for (int i = 0; i < 3; ++i) {
2191 MoveTouchPoint(0, 10+10*i, 10+10*i);
2192 EXPECT_TRUE(HasPendingAsyncTouchMove());
2193 EXPECT_EQ(0U, queued_event_count());
2194 EXPECT_EQ(0U, GetAndResetSentEventCount());
2195 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2196 EXPECT_EQ(i+1, uncancelable_touch_moves_pending_ack_count());
2197
2198 // Send touchstart will flush pending_async_touch_move_, and increase the
2199 // count.
2200 PressTouchPoint(30, 30);
2201 EXPECT_FALSE(HasPendingAsyncTouchMove());
2202 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2203 EXPECT_FALSE(sent_event().cancelable);
2204 EXPECT_EQ(10+10*i, sent_event().touches[0].position.x);
2205 EXPECT_EQ(10+10*i, sent_event().touches[0].position.y);
2206 EXPECT_EQ(1U, GetAndResetSentEventCount());
2207 EXPECT_EQ(i+2, uncancelable_touch_moves_pending_ack_count());
2208
2209 // Touchstart is cancelable during async touch dispatch.
2210 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2211 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
2212 EXPECT_TRUE(sent_event().cancelable);
2213 EXPECT_EQ(1U, GetAndResetSentEventCount());
2214 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2215 EXPECT_EQ(i+2, uncancelable_touch_moves_pending_ack_count());
2216
2217 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2218 EXPECT_EQ(0U, queued_event_count());
2219 EXPECT_FALSE(HasPendingAsyncTouchMove());
2220 EXPECT_EQ(0U, GetAndResetSentEventCount());
2221 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2222 }
2223
2224 EXPECT_EQ(4, uncancelable_touch_moves_pending_ack_count());
2225 // When we receive an ack from render we decrease the count.
2226 SendUncancelableTouchMoveEventAck();
2227 EXPECT_EQ(3, uncancelable_touch_moves_pending_ack_count());
2228 EXPECT_EQ(0U, queued_event_count());
2229 EXPECT_FALSE(HasPendingAsyncTouchMove());
2230
2231 // Do not dispatch the next uncancelable touchmove when we have not recevied
2232 // all the acks back from render.
2233 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2234 MoveTouchPoint(0, 20, 30);
2235 EXPECT_TRUE(HasPendingAsyncTouchMove());
2236 EXPECT_EQ(0U, queued_event_count());
2237 EXPECT_EQ(0U, GetAndResetSentEventCount());
2238 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2239 EXPECT_EQ(3, uncancelable_touch_moves_pending_ack_count());
2240
2241 // Once we receive the ack from render, we do not dispatch the
2242 // pending_async_touchmove_ until the count is 0.
2243 SendUncancelableTouchMoveEventAck();
2244 EXPECT_EQ(2, uncancelable_touch_moves_pending_ack_count());
2245 EXPECT_EQ(0U, queued_event_count());
2246 EXPECT_TRUE(HasPendingAsyncTouchMove());
2247
2248 SendUncancelableTouchMoveEventAck();
2249
2250 // When we receive this ack from render, and the count is 0, so we can
2251 // dispatch the pending_async_touchmove_.
2252 SendUncancelableTouchMoveEventAck();
2253 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count());
2254 EXPECT_FALSE(HasPendingAsyncTouchMove());
2255 EXPECT_EQ(1U, queued_event_count());
2256 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2257 EXPECT_FALSE(sent_event().cancelable);
2258 EXPECT_EQ(1U, GetAndResetSentEventCount());
2259 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2260 }
2261
1974 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { 2262 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
1975 // Queue a TouchStart. 2263 // Queue a TouchStart.
1976 PressTouchPoint(0, 1); 2264 PressTouchPoint(0, 1);
1977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2265 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1978 EXPECT_EQ(0U, queued_event_count()); 2266 EXPECT_EQ(0U, queued_event_count());
1979 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2267 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1980 2268
1981 MoveTouchPoint(0, 20, 5); 2269 MoveTouchPoint(0, 20, 5);
1982 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); 2270 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2271 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 2340
2053 // If subsequent touchmoves aren't consumed, the generated scroll events 2341 // If subsequent touchmoves aren't consumed, the generated scroll events
2054 // will restore async touch dispatch. 2342 // will restore async touch dispatch.
2055 MoveTouchPoint(0, 25, 5); 2343 MoveTouchPoint(0, 25, 5);
2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2344 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2057 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); 2345 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2058 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2346 ASSERT_EQ(1U, GetAndResetSentEventCount());
2059 EXPECT_TRUE(sent_event().cancelable); 2347 EXPECT_TRUE(sent_event().cancelable);
2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 2348 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2061 MoveTouchPoint(0, 30, 5); 2349 MoveTouchPoint(0, 30, 5);
2350 SendUncancelableTouchMoveEventAck();
2062 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2351 ASSERT_EQ(1U, GetAndResetSentEventCount());
2063 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); 2352 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2064 EXPECT_FALSE(sent_event().cancelable); 2353 EXPECT_FALSE(sent_event().cancelable);
2065 2354
2066 // The touchend will be uncancelable during an active scroll sequence. 2355 // The touchend will be uncancelable during an active scroll sequence.
2067 ReleaseTouchPoint(0); 2356 ReleaseTouchPoint(0);
2068 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2357 ASSERT_EQ(1U, GetAndResetSentEventCount());
2069 EXPECT_FALSE(sent_event().cancelable); 2358 EXPECT_FALSE(sent_event().cancelable);
2070 } 2359 }
2071 2360
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2541 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2253 2542
2254 // TouchMove should be allowed and test for touches state. 2543 // TouchMove should be allowed and test for touches state.
2255 const WebTouchEvent& event2 = sent_event(); 2544 const WebTouchEvent& event2 = sent_event();
2256 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); 2545 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2257 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); 2546 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state);
2258 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); 2547 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2259 } 2548 }
2260 2549
2261 } // namespace content 2550 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698