Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 | |
|
tdresser
2015/03/31 14:44:07
nit: a second -> another
It's not actually the s
lanwei
2015/04/01 13:14:21
Done.
| |
| 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 // Even though we do not dispatch this touchmove, we still send a fake ack for | |
| 2018 // this event. | |
| 2019 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2020 | |
| 2021 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't | |
| 2022 // dispatch it yet. | |
|
tdresser
2015/03/31 14:44:07
I think we can make this test more focused, and mo
lanwei
2015/04/01 13:14:21
Done.
| |
| 2023 MoveTouchPoint(0, 0, 30); | |
| 2024 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2025 EXPECT_EQ(0U, queued_event_count()); | |
| 2026 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2027 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2028 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count()); | |
| 2029 | |
| 2030 // We set the next touch event time to be after the throttled interval. | |
| 2031 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
|
tdresser
2015/03/31 14:44:07
Oops, I completely misinterpreted what this method
| |
| 2032 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2033 EXPECT_EQ(0U, queued_event_count()); | |
| 2034 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2035 | |
| 2036 // Dispatch the pending_async_touch_move_ when sufficient time has passed. | |
| 2037 MoveTouchPoint(0, 0, 40); | |
| 2038 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2039 EXPECT_FALSE(sent_event().cancelable); | |
| 2040 EXPECT_EQ(1U, queued_event_count()); | |
| 2041 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2042 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2043 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2044 | |
| 2045 // We receive the fake ack for the above touchmove and clear the queue. | |
| 2046 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2047 EXPECT_EQ(0U, queued_event_count()); | |
| 2048 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2049 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2050 | |
| 2051 // Do not dispatch the event until throttledTouchmoves intervals expires and | |
| 2052 // receive an ack from render. | |
| 2053 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2054 MoveTouchPoint(0, 0, 50); | |
| 2055 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2056 EXPECT_EQ(0U, queued_event_count()); | |
| 2057 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2058 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2059 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2060 | |
| 2061 // Send pending_async_touch_move_ when we receive an ack back from render. | |
| 2062 SendUncancelableTouchMoveEventAck(); | |
| 2063 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2064 EXPECT_EQ(1U, queued_event_count()); | |
| 2065 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2066 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2067 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2068 } | |
| 2069 | |
| 2070 // Ensure that even when we receive the ack from render, we still need to wait | |
| 2071 // for the interval expires to send the next async touchmove once the scroll | |
| 2072 // starts. | |
| 2073 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) { | |
| 2074 // Process a TouchStart | |
| 2075 PressTouchPoint(0, 1); | |
| 2076 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2077 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2078 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2079 | |
| 2080 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 2081 MoveTouchPoint(0, 0, 5); | |
| 2082 WebGestureEvent followup_scroll; | |
| 2083 followup_scroll.type = WebInputEvent::GestureScrollBegin; | |
| 2084 SetFollowupEvent(followup_scroll); | |
| 2085 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2086 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2087 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2088 | |
| 2089 MoveTouchPoint(0, 0, 10); | |
| 2090 followup_scroll.type = WebInputEvent::GestureScrollUpdate; | |
| 2091 SetFollowupEvent(followup_scroll); | |
| 2092 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2093 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2094 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2095 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2096 | |
| 2097 // Now queue a second touchmove and verify it's not (yet) dispatched, because | |
| 2098 // we've now started scrolling, and we throttle the touchmoves. | |
| 2099 MoveTouchPoint(0, 0, 20); | |
|
tdresser
2015/03/31 14:44:07
Same as above: I think you can get rid of this tou
| |
| 2100 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2101 EXPECT_EQ(0U, queued_event_count()); | |
| 2102 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2103 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2104 | |
| 2105 // Coalesce the subsequent touchmove with pending_async_touch_move_ but don't | |
| 2106 // dispatch it yet. | |
| 2107 MoveTouchPoint(0, 0, 30); | |
| 2108 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2109 EXPECT_EQ(0U, queued_event_count()); | |
| 2110 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2111 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2112 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count()); | |
| 2113 | |
| 2114 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2115 MoveTouchPoint(0, 0, 40); | |
| 2116 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2117 EXPECT_FALSE(sent_event().cancelable); | |
| 2118 EXPECT_EQ(1U, queued_event_count()); | |
| 2119 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2120 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2121 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2122 | |
| 2123 // We receive the fake ack for touchmove and clear the queue. | |
| 2124 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2125 EXPECT_EQ(0U, queued_event_count()); | |
| 2126 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2127 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2128 | |
| 2129 // We receive an ack back from render but the time interval is not expired, | |
| 2130 // so we do not dispatch the event. | |
| 2131 SendUncancelableTouchMoveEventAck(); | |
| 2132 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count()); | |
| 2133 | |
| 2134 MoveTouchPoint(0, 0, 50); | |
| 2135 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2136 EXPECT_EQ(0U, queued_event_count()); | |
| 2137 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2138 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2139 | |
| 2140 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2141 MoveTouchPoint(0, 0, 50); | |
| 2142 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2143 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 2144 EXPECT_FALSE(sent_event().cancelable); | |
| 2145 EXPECT_EQ(1U, queued_event_count()); | |
| 2146 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2147 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2148 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2149 } | |
| 2150 | |
| 2151 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) { | |
| 2152 // Process a TouchStart | |
| 2153 PressTouchPoint(0, 1); | |
| 2154 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2155 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2156 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2157 | |
| 2158 // Initiate async touchmove dispatch after the start of a scroll sequence. | |
| 2159 MoveTouchPoint(0, 0, 5); | |
| 2160 WebGestureEvent followup_scroll; | |
| 2161 followup_scroll.type = WebInputEvent::GestureScrollBegin; | |
| 2162 SetFollowupEvent(followup_scroll); | |
| 2163 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2164 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2165 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2166 | |
| 2167 MoveTouchPoint(0, 0, 10); | |
| 2168 followup_scroll.type = WebInputEvent::GestureScrollUpdate; | |
| 2169 SetFollowupEvent(followup_scroll); | |
| 2170 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2171 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2172 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2173 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2174 | |
| 2175 // Now queue a second touchmove and verify it's not (yet) dispatched, because | |
| 2176 // we've now started scrolling, and we throttle the touchmoves. | |
| 2177 MoveTouchPoint(0, 0, 20); | |
|
tdresser
2015/03/31 14:44:07
We should be able to get rid of this touchmove.
| |
| 2178 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2179 EXPECT_EQ(0U, queued_event_count()); | |
| 2180 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2181 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2182 EXPECT_EQ(0, uncancelable_touch_moves_pending_ack_count()); | |
| 2183 | |
| 2184 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2185 MoveTouchPoint(0, 0, 40); | |
| 2186 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2187 EXPECT_FALSE(sent_event().cancelable); | |
| 2188 EXPECT_EQ(1U, queued_event_count()); | |
| 2189 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2190 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2191 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2192 | |
| 2193 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2194 EXPECT_EQ(0U, queued_event_count()); | |
| 2195 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2196 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2197 | |
| 2198 for (int i = 0; i < 3; ++i) { | |
| 2199 MoveTouchPoint(0, 10 + 10 * i, 10 + 10 * i); | |
| 2200 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2201 EXPECT_EQ(0U, queued_event_count()); | |
| 2202 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2203 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2204 EXPECT_EQ(i + 1, uncancelable_touch_moves_pending_ack_count()); | |
| 2205 | |
| 2206 // Send touchstart will flush pending_async_touch_move_, and increase the | |
| 2207 // count. | |
| 2208 PressTouchPoint(30, 30); | |
| 2209 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2210 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 2211 EXPECT_FALSE(sent_event().cancelable); | |
| 2212 EXPECT_EQ(10 + 10 * i, sent_event().touches[0].position.x); | |
| 2213 EXPECT_EQ(10 + 10 * i, sent_event().touches[0].position.y); | |
| 2214 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2215 EXPECT_EQ(i + 2, uncancelable_touch_moves_pending_ack_count()); | |
| 2216 | |
| 2217 // Touchstart is cancelable during async touch dispatch. | |
| 2218 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); | |
| 2219 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); | |
| 2220 EXPECT_TRUE(sent_event().cancelable); | |
| 2221 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2222 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2223 EXPECT_EQ(i + 2, uncancelable_touch_moves_pending_ack_count()); | |
| 2224 | |
| 2225 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 2226 EXPECT_EQ(0U, queued_event_count()); | |
| 2227 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2228 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2229 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2230 } | |
| 2231 | |
| 2232 EXPECT_EQ(4, uncancelable_touch_moves_pending_ack_count()); | |
| 2233 // When we receive an ack from render we decrease the count. | |
| 2234 SendUncancelableTouchMoveEventAck(); | |
| 2235 EXPECT_EQ(3, uncancelable_touch_moves_pending_ack_count()); | |
| 2236 EXPECT_EQ(0U, queued_event_count()); | |
| 2237 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2238 | |
| 2239 // Do not dispatch the next uncancelable touchmove when we have not recevied | |
| 2240 // all the acks back from render. | |
| 2241 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 2242 MoveTouchPoint(0, 20, 30); | |
| 2243 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2244 EXPECT_EQ(0U, queued_event_count()); | |
| 2245 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 2246 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 2247 EXPECT_EQ(3, uncancelable_touch_moves_pending_ack_count()); | |
| 2248 | |
| 2249 // Once we receive the ack from render, we do not dispatch the | |
| 2250 // pending_async_touchmove_ until the count is 0. | |
| 2251 SendUncancelableTouchMoveEventAck(); | |
| 2252 EXPECT_EQ(2, uncancelable_touch_moves_pending_ack_count()); | |
| 2253 EXPECT_EQ(0U, queued_event_count()); | |
| 2254 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 2255 | |
| 2256 SendUncancelableTouchMoveEventAck(); | |
| 2257 | |
| 2258 // When we receive this ack from render, and the count is 0, so we can | |
| 2259 // dispatch the pending_async_touchmove_. | |
| 2260 SendUncancelableTouchMoveEventAck(); | |
| 2261 EXPECT_EQ(1, uncancelable_touch_moves_pending_ack_count()); | |
| 2262 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 2263 EXPECT_EQ(1U, queued_event_count()); | |
| 2264 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 2265 EXPECT_FALSE(sent_event().cancelable); | |
| 2266 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 2267 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 2268 } | |
| 2269 | |
| 1974 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { | 2270 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { |
| 1975 // Queue a TouchStart. | 2271 // Queue a TouchStart. |
| 1976 PressTouchPoint(0, 1); | 2272 PressTouchPoint(0, 1); |
| 1977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2273 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1978 EXPECT_EQ(0U, queued_event_count()); | 2274 EXPECT_EQ(0U, queued_event_count()); |
| 1979 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2275 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1980 | 2276 |
| 1981 MoveTouchPoint(0, 20, 5); | 2277 MoveTouchPoint(0, 20, 5); |
| 1982 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); | 2278 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| 1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2279 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2052 | 2348 |
| 2053 // If subsequent touchmoves aren't consumed, the generated scroll events | 2349 // If subsequent touchmoves aren't consumed, the generated scroll events |
| 2054 // will restore async touch dispatch. | 2350 // will restore async touch dispatch. |
| 2055 MoveTouchPoint(0, 25, 5); | 2351 MoveTouchPoint(0, 25, 5); |
| 2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2352 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2057 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); | 2353 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); |
| 2058 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 2354 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2059 EXPECT_TRUE(sent_event().cancelable); | 2355 EXPECT_TRUE(sent_event().cancelable); |
| 2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | 2356 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| 2061 MoveTouchPoint(0, 30, 5); | 2357 MoveTouchPoint(0, 30, 5); |
| 2358 SendUncancelableTouchMoveEventAck(); | |
| 2062 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 2359 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2063 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); | 2360 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 2064 EXPECT_FALSE(sent_event().cancelable); | 2361 EXPECT_FALSE(sent_event().cancelable); |
| 2065 | 2362 |
| 2066 // The touchend will be uncancelable during an active scroll sequence. | 2363 // The touchend will be uncancelable during an active scroll sequence. |
| 2067 ReleaseTouchPoint(0); | 2364 ReleaseTouchPoint(0); |
| 2068 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 2365 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2069 EXPECT_FALSE(sent_event().cancelable); | 2366 EXPECT_FALSE(sent_event().cancelable); |
| 2070 } | 2367 } |
| 2071 | 2368 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2252 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2549 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2253 | 2550 |
| 2254 // TouchMove should be allowed and test for touches state. | 2551 // TouchMove should be allowed and test for touches state. |
| 2255 const WebTouchEvent& event2 = sent_event(); | 2552 const WebTouchEvent& event2 = sent_event(); |
| 2256 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); | 2553 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); |
| 2257 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); | 2554 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); |
| 2258 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); | 2555 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
| 2259 } | 2556 } |
| 2260 | 2557 |
| 2261 } // namespace content | 2558 } // namespace content |
| OLD | NEW |