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

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: 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 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 sent_uncancelable_touch_move_count() const {
279 return queue_->SentUncancelableTouchMoveCount();
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 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 // Subsequent touchmove's should be deferred. 1656 // Subsequent touchmove's should be deferred.
1649 MoveTouchPoint(0, 0, 25); 1657 MoveTouchPoint(0, 0, 25);
1650 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1658 EXPECT_TRUE(HasPendingAsyncTouchMove());
1651 EXPECT_EQ(0U, queued_event_count()); 1659 EXPECT_EQ(0U, queued_event_count());
1652 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1660 EXPECT_EQ(0U, GetAndResetSentEventCount());
1653 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1661 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1654 1662
1655 // The pending touchmove should be flushed with the the new touchmove if 1663 // The pending touchmove should be flushed with the the new touchmove if
1656 // sufficient time has passed. 1664 // sufficient time has passed.
1657 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 1665 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1658 MoveTouchPoint(0, 0, 15); 1666 SendUncancelableTouchMoveEventAck();
1659 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1667 EXPECT_FALSE(HasPendingAsyncTouchMove());
1660 EXPECT_FALSE(sent_event().cancelable); 1668 EXPECT_FALSE(sent_event().cancelable);
1661 EXPECT_EQ(1U, queued_event_count()); 1669 EXPECT_EQ(1U, queued_event_count());
1662 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1670 EXPECT_EQ(1U, GetAndResetSentEventCount());
1663 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1671 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1672 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1665 EXPECT_EQ(0U, queued_event_count()); 1673 EXPECT_EQ(0U, queued_event_count());
1666 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1674 EXPECT_EQ(0U, GetAndResetSentEventCount());
1667 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1675 // EXPECT_EQ(1U, GetAndResetAckedEventCount());
1668 1676
1669 // Non-touchmove events should always flush any pending touchmove events. 1677 // Non-touchmove events should always flush any pending touchmove events.
1670 MoveTouchPoint(0, 0, 25); 1678 MoveTouchPoint(0, 10, 25);
1671 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1679 EXPECT_TRUE(HasPendingAsyncTouchMove());
1672 EXPECT_EQ(0U, queued_event_count()); 1680 EXPECT_EQ(0U, queued_event_count());
1673 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1681 EXPECT_EQ(0U, GetAndResetSentEventCount());
1674 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1682 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1675 PressTouchPoint(30, 30); 1683 PressTouchPoint(30, 30);
1676 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1684 EXPECT_FALSE(HasPendingAsyncTouchMove());
1677 EXPECT_FALSE(sent_event().cancelable); 1685 EXPECT_FALSE(sent_event().cancelable);
1678 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); 1686 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1679 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1687 EXPECT_EQ(1U, GetAndResetSentEventCount());
1680 EXPECT_EQ(2U, queued_event_count()); 1688 EXPECT_EQ(2U, queued_event_count());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1832 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1825 INPUT_EVENT_ACK_STATE_CONSUMED); 1833 INPUT_EVENT_ACK_STATE_CONSUMED);
1826 1834
1827 // An async touch should fire after the throttling interval has expired, but 1835 // An async touch should fire after the throttling interval has expired, but
1828 // it should not start the touch ack timeout. 1836 // it should not start the touch ack timeout.
1829 MoveTouchPoint(0, 5, 5); 1837 MoveTouchPoint(0, 5, 5);
1830 EXPECT_TRUE(HasPendingAsyncTouchMove()); 1838 EXPECT_TRUE(HasPendingAsyncTouchMove());
1831 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1839 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1832 1840
1833 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 1841 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1842 SendUncancelableTouchMoveEventAck();
1834 MoveTouchPoint(0, 5, 5); 1843 MoveTouchPoint(0, 5, 5);
1835 EXPECT_FALSE(IsTimeoutRunning()); 1844 EXPECT_FALSE(IsTimeoutRunning());
1836 EXPECT_FALSE(HasPendingAsyncTouchMove()); 1845 EXPECT_FALSE(HasPendingAsyncTouchMove());
1837 EXPECT_FALSE(sent_event().cancelable); 1846 EXPECT_FALSE(sent_event().cancelable);
1838 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1847 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1839 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1848 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1840 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1849 EXPECT_EQ(1U, GetAndResetSentEventCount());
1841 1850
1842 // An unconsumed scroll event will resume synchronous touchmoves, which are 1851 // An unconsumed scroll event will resume synchronous touchmoves, which are
1843 // subject to the ack timeout. 1852 // subject to the ack timeout.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 SendGestureEvent(WebInputEvent::GestureScrollEnd); 1973 SendGestureEvent(WebInputEvent::GestureScrollEnd);
1965 ResetTouchEvent(); 1974 ResetTouchEvent();
1966 1975
1967 PressTouchPoint(0, 0); 1976 PressTouchPoint(0, 0);
1968 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1977 EXPECT_EQ(1U, GetAndResetSentEventCount());
1969 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); 1978 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1970 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1979 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1971 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1980 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1972 } 1981 }
1973 1982
1983 // Ensure that even when the interval expires, we still need to wait for the
1984 // ack sent back from render to send the next async touchmove once the scroll
1985 // starts.
1986 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
1987 // Process a TouchStart
1988 PressTouchPoint(0, 1);
1989 EXPECT_EQ(1U, GetAndResetSentEventCount());
1990 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1991 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1992
1993 // Initiate async touchmove dispatch after the start of a scroll sequence.
1994 MoveTouchPoint(0, 0, 5);
1995 WebGestureEvent followup_scroll;
1996 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1997 SetFollowupEvent(followup_scroll);
1998 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1999 EXPECT_EQ(1U, GetAndResetSentEventCount());
2000 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2001
2002 MoveTouchPoint(0, 0, 10);
2003 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2004 SetFollowupEvent(followup_scroll);
2005 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2006 EXPECT_FALSE(HasPendingAsyncTouchMove());
2007 EXPECT_EQ(1U, GetAndResetSentEventCount());
2008 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2009
2010 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2011 // we've now started scrolling, and we throttle the touchmoves.
2012 MoveTouchPoint(0, 0, 20);
2013 EXPECT_TRUE(HasPendingAsyncTouchMove());
2014 EXPECT_EQ(0U, queued_event_count());
2015 EXPECT_EQ(0U, GetAndResetSentEventCount());
2016 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2017
2018 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
2019 // dispatch it yet.
2020 MoveTouchPoint(0, 0, 30);
2021 EXPECT_TRUE(HasPendingAsyncTouchMove());
2022 EXPECT_EQ(0U, queued_event_count());
2023 EXPECT_EQ(0U, GetAndResetSentEventCount());
2024 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2025 EXPECT_EQ(0, sent_uncancelable_touch_move_count());
2026
2027 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2028 MoveTouchPoint(0, 0, 40);
2029 EXPECT_FALSE(HasPendingAsyncTouchMove());
2030 EXPECT_FALSE(sent_event().cancelable);
2031 EXPECT_EQ(1U, queued_event_count());
2032 EXPECT_EQ(1U, GetAndResetSentEventCount());
2033 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2034 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2035
2036 // We receive the fake ack for touchmove and clear the queue.
2037 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2038 EXPECT_EQ(0U, queued_event_count());
2039 EXPECT_EQ(0U, GetAndResetSentEventCount());
2040 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2041
2042 // Do not dispatch the event until ThrottledTouchmoves intervals expires and
2043 // receive an ack from render.
2044 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2045 MoveTouchPoint(0, 0, 50);
2046 EXPECT_TRUE(HasPendingAsyncTouchMove());
2047 EXPECT_EQ(0U, queued_event_count());
2048 EXPECT_EQ(0U, GetAndResetSentEventCount());
2049 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2050 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2051
2052 // Send pending_async_touch_move_ when we receive an ack back from render.
2053 SendUncancelableTouchMoveEventAck();
2054 EXPECT_FALSE(HasPendingAsyncTouchMove());
2055 EXPECT_EQ(1U, queued_event_count());
2056 EXPECT_EQ(1U, GetAndResetSentEventCount());
2057 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2058 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2059 }
2060
2061 // Ensure that even when we receive the ack from render, we still need to wait
2062 // for the interval expires to send the next async touchmove once the scroll
2063 // starts.
2064 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
2065 // Process a TouchStart
2066 PressTouchPoint(0, 1);
2067 EXPECT_EQ(1U, GetAndResetSentEventCount());
2068 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2069 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2070
2071 // Initiate async touchmove dispatch after the start of a scroll sequence.
2072 MoveTouchPoint(0, 0, 5);
2073 WebGestureEvent followup_scroll;
2074 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2075 SetFollowupEvent(followup_scroll);
2076 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2077 EXPECT_EQ(1U, GetAndResetSentEventCount());
2078 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2079
2080 MoveTouchPoint(0, 0, 10);
2081 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2082 SetFollowupEvent(followup_scroll);
2083 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2084 EXPECT_FALSE(HasPendingAsyncTouchMove());
2085 EXPECT_EQ(1U, GetAndResetSentEventCount());
2086 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2087
2088 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2089 // we've now started scrolling, and we throttle the touchmoves.
2090 MoveTouchPoint(0, 0, 20);
2091 EXPECT_TRUE(HasPendingAsyncTouchMove());
2092 EXPECT_EQ(0U, queued_event_count());
2093 EXPECT_EQ(0U, GetAndResetSentEventCount());
2094 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2095
2096 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't
2097 // dispatch it yet.
2098 MoveTouchPoint(0, 0, 30);
2099 EXPECT_TRUE(HasPendingAsyncTouchMove());
2100 EXPECT_EQ(0U, queued_event_count());
2101 EXPECT_EQ(0U, GetAndResetSentEventCount());
2102 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2103 EXPECT_EQ(0, sent_uncancelable_touch_move_count());
2104
2105 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2106 MoveTouchPoint(0, 0, 40);
2107 EXPECT_FALSE(HasPendingAsyncTouchMove());
2108 EXPECT_FALSE(sent_event().cancelable);
2109 EXPECT_EQ(1U, queued_event_count());
2110 EXPECT_EQ(1U, GetAndResetSentEventCount());
2111 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2112 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2113
2114 // We receive the fake ack for touchmove and clear the queue.
2115 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2116 EXPECT_EQ(0U, queued_event_count());
2117 EXPECT_EQ(0U, GetAndResetSentEventCount());
2118 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2119
2120 // We receive an ack back from render but the time interval is not expired,
2121 // so we do not dispatch the event.
2122 SendUncancelableTouchMoveEventAck();
2123 EXPECT_EQ(0, sent_uncancelable_touch_move_count());
2124
2125 MoveTouchPoint(0, 0, 50);
2126 EXPECT_TRUE(HasPendingAsyncTouchMove());
2127 EXPECT_EQ(0U, queued_event_count());
2128 EXPECT_EQ(0U, GetAndResetSentEventCount());
2129 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2130
2131 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2132 MoveTouchPoint(0, 0, 50);
2133 EXPECT_FALSE(HasPendingAsyncTouchMove());
2134 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2135 EXPECT_FALSE(sent_event().cancelable);
2136 EXPECT_EQ(1U, queued_event_count());
2137 EXPECT_EQ(1U, GetAndResetSentEventCount());
2138 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2139 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2140 }
2141
2142 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
2143 // Process a TouchStart
2144 PressTouchPoint(0, 1);
2145 EXPECT_EQ(1U, GetAndResetSentEventCount());
2146 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2147 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2148
2149 // Initiate async touchmove dispatch after the start of a scroll sequence.
2150 MoveTouchPoint(0, 0, 5);
2151 WebGestureEvent followup_scroll;
2152 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2153 SetFollowupEvent(followup_scroll);
2154 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2155 EXPECT_EQ(1U, GetAndResetSentEventCount());
2156 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2157
2158 MoveTouchPoint(0, 0, 10);
2159 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2160 SetFollowupEvent(followup_scroll);
2161 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2162 EXPECT_FALSE(HasPendingAsyncTouchMove());
2163 EXPECT_EQ(1U, GetAndResetSentEventCount());
2164 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2165
2166 // Now queue a second touchmove and verify it's not (yet) dispatched, because
2167 // we've now started scrolling, and we throttle the touchmoves.
2168 MoveTouchPoint(0, 0, 20);
2169 EXPECT_TRUE(HasPendingAsyncTouchMove());
2170 EXPECT_EQ(0U, queued_event_count());
2171 EXPECT_EQ(0U, GetAndResetSentEventCount());
2172 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2173 EXPECT_EQ(0, sent_uncancelable_touch_move_count());
2174
2175 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2176 MoveTouchPoint(0, 0, 40);
2177 EXPECT_FALSE(HasPendingAsyncTouchMove());
2178 EXPECT_FALSE(sent_event().cancelable);
2179 EXPECT_EQ(1U, queued_event_count());
2180 EXPECT_EQ(1U, GetAndResetSentEventCount());
2181 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2182 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2183
2184 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2185 EXPECT_EQ(0U, queued_event_count());
2186 EXPECT_EQ(0U, GetAndResetSentEventCount());
2187 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2188
2189 for (int i = 0; i < 3; ++i) {
2190 MoveTouchPoint(0, 10+10*i, 10+10*i);
2191 EXPECT_TRUE(HasPendingAsyncTouchMove());
2192 EXPECT_EQ(0U, queued_event_count());
2193 EXPECT_EQ(0U, GetAndResetSentEventCount());
2194 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2195 EXPECT_EQ(i+1, sent_uncancelable_touch_move_count());
2196
2197 // 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.
2198 // count.
2199 PressTouchPoint(30, 30);
2200 EXPECT_FALSE(HasPendingAsyncTouchMove());
2201 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2202 EXPECT_FALSE(sent_event().cancelable);
2203 EXPECT_EQ(10+10*i, sent_event().touches[0].position.x);
2204 EXPECT_EQ(10+10*i, sent_event().touches[0].position.y);
2205 EXPECT_EQ(1U, GetAndResetSentEventCount());
2206 EXPECT_EQ(i+2, sent_uncancelable_touch_move_count());
tdresser 2015/03/26 15:25:29 Nice test, thanks!
2207
2208 // Touchstart is cancelable during async touch dispatch.
2209 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2210 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
2211 EXPECT_TRUE(sent_event().cancelable);
2212 EXPECT_EQ(1U, GetAndResetSentEventCount());
2213 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2214 EXPECT_EQ(i+2, sent_uncancelable_touch_move_count());
2215
2216 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2217 EXPECT_EQ(0U, queued_event_count());
2218 EXPECT_FALSE(HasPendingAsyncTouchMove());
2219 EXPECT_EQ(0U, GetAndResetSentEventCount());
2220 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2221 }
2222
2223 EXPECT_EQ(4, sent_uncancelable_touch_move_count());
2224 // When we receive an ack from render we decrease the count.
2225 SendUncancelableTouchMoveEventAck();
2226 EXPECT_EQ(3, sent_uncancelable_touch_move_count());
2227 EXPECT_EQ(0U, queued_event_count());
2228 EXPECT_FALSE(HasPendingAsyncTouchMove());
2229
2230 // Do not dispatch the next uncancelable touchmove when we have not recevied
2231 // all the acks back from render.
2232 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2233 MoveTouchPoint(0, 20, 30);
2234 EXPECT_TRUE(HasPendingAsyncTouchMove());
2235 EXPECT_EQ(0U, queued_event_count());
2236 EXPECT_EQ(0U, GetAndResetSentEventCount());
2237 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2238 EXPECT_EQ(3, sent_uncancelable_touch_move_count());
2239
2240 // Once we receive the ack from render, we will dispatch the
2241 // pending_async_touchmove_.
2242 SendUncancelableTouchMoveEventAck();
2243 EXPECT_EQ(3, sent_uncancelable_touch_move_count());
2244 EXPECT_EQ(1U, queued_event_count());
2245 EXPECT_FALSE(HasPendingAsyncTouchMove());
2246 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2247 EXPECT_FALSE(sent_event().cancelable);
2248 EXPECT_EQ(1U, GetAndResetSentEventCount());
2249 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2250
2251 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2252 SendUncancelableTouchMoveEventAck();
2253 SendUncancelableTouchMoveEventAck();
2254 SendUncancelableTouchMoveEventAck();
2255 EXPECT_EQ(0, sent_uncancelable_touch_move_count());
2256
2257 // Dispatch the next uncancelable touchmove when we have recevied all the
2258 // acks back from render and time expires.
2259 MoveTouchPoint(0, 30, 30);
2260 EXPECT_FALSE(HasPendingAsyncTouchMove());
2261 EXPECT_EQ(1U, queued_event_count());
2262 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2263 EXPECT_FALSE(sent_event().cancelable);
2264 EXPECT_EQ(1U, GetAndResetSentEventCount());
2265 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2266 EXPECT_EQ(1, sent_uncancelable_touch_move_count());
2267 }
2268
1974 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { 2269 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
1975 // Queue a TouchStart. 2270 // Queue a TouchStart.
1976 PressTouchPoint(0, 1); 2271 PressTouchPoint(0, 1);
1977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2272 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1978 EXPECT_EQ(0U, queued_event_count()); 2273 EXPECT_EQ(0U, queued_event_count());
1979 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2274 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1980 2275
1981 MoveTouchPoint(0, 20, 5); 2276 MoveTouchPoint(0, 20, 5);
1982 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); 2277 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 2278 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 2347
2053 // If subsequent touchmoves aren't consumed, the generated scroll events 2348 // If subsequent touchmoves aren't consumed, the generated scroll events
2054 // will restore async touch dispatch. 2349 // will restore async touch dispatch.
2055 MoveTouchPoint(0, 25, 5); 2350 MoveTouchPoint(0, 25, 5);
2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 2351 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2057 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); 2352 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2058 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2353 ASSERT_EQ(1U, GetAndResetSentEventCount());
2059 EXPECT_TRUE(sent_event().cancelable); 2354 EXPECT_TRUE(sent_event().cancelable);
2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); 2355 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2061 MoveTouchPoint(0, 30, 5); 2356 MoveTouchPoint(0, 30, 5);
2357 SendUncancelableTouchMoveEventAck();
2062 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2358 ASSERT_EQ(1U, GetAndResetSentEventCount());
2063 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); 2359 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2064 EXPECT_FALSE(sent_event().cancelable); 2360 EXPECT_FALSE(sent_event().cancelable);
2065 2361
2066 // The touchend will be uncancelable during an active scroll sequence. 2362 // The touchend will be uncancelable during an active scroll sequence.
2067 ReleaseTouchPoint(0); 2363 ReleaseTouchPoint(0);
2068 ASSERT_EQ(1U, GetAndResetSentEventCount()); 2364 ASSERT_EQ(1U, GetAndResetSentEventCount());
2069 EXPECT_FALSE(sent_event().cancelable); 2365 EXPECT_FALSE(sent_event().cancelable);
2070 } 2366 }
2071 2367
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 2548 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2253 2549
2254 // TouchMove should be allowed and test for touches state. 2550 // TouchMove should be allowed and test for touches state.
2255 const WebTouchEvent& event2 = sent_event(); 2551 const WebTouchEvent& event2 = sent_event();
2256 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); 2552 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2257 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); 2553 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state);
2258 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); 2554 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2259 } 2555 }
2260 2556
2261 } // namespace content 2557 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698