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 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 1868 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
1869 EXPECT_FALSE(sent_event().cancelable); | 1869 EXPECT_FALSE(sent_event().cancelable); |
1870 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | 1870 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
1871 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1871 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1872 EXPECT_EQ(2U, queued_event_count()); | 1872 EXPECT_EQ(2U, queued_event_count()); |
1873 | 1873 |
1874 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note | 1874 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note |
1875 // that the flushed touchmove's ack will not reach the client (its | 1875 // that the flushed touchmove's ack will not reach the client (its |
1876 // constituent events have already been ack'ed). | 1876 // constituent events have already been ack'ed). |
1877 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1877 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1878 EXPECT_FALSE(sent_event().cancelable); | 1878 EXPECT_TRUE(sent_event().cancelable); |
1879 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); | 1879 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); |
1880 EXPECT_EQ(1U, queued_event_count()); | 1880 EXPECT_EQ(1U, queued_event_count()); |
1881 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1881 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1882 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1882 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1883 | 1883 |
1884 // Ack the touchstart. | 1884 // Ack the touchstart. |
1885 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1885 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1886 EXPECT_EQ(0U, queued_event_count()); | 1886 EXPECT_EQ(0U, queued_event_count()); |
1887 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1887 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1888 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1888 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 EXPECT_TRUE(sent_event().cancelable); | 2149 EXPECT_TRUE(sent_event().cancelable); |
2150 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2150 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2151 | 2151 |
2152 // Touch move event is throttled. | 2152 // Touch move event is throttled. |
2153 MoveTouchPoint(0, 60, 5); | 2153 MoveTouchPoint(0, 60, 5); |
2154 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2154 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2155 EXPECT_EQ(0U, queued_event_count()); | 2155 EXPECT_EQ(0U, queued_event_count()); |
2156 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 2156 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
2157 } | 2157 } |
2158 | 2158 |
| 2159 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) { |
| 2160 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
| 2161 |
| 2162 // Queue a touchstart and touchmove that go unconsumed, transitioning to an |
| 2163 // active scroll sequence. |
| 2164 PressTouchPoint(0, 1); |
| 2165 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2166 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2167 EXPECT_TRUE(sent_event().cancelable); |
| 2168 |
| 2169 MoveTouchPoint(0, 20, 5); |
| 2170 EXPECT_TRUE(sent_event().cancelable); |
| 2171 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| 2172 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); |
| 2173 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2174 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2175 EXPECT_TRUE(sent_event().cancelable); |
| 2176 |
| 2177 // Even though scrolling has begun, touchstart events should be cancelable, |
| 2178 // allowing, for example, customized pinch processing. |
| 2179 PressTouchPoint(10, 11); |
| 2180 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2181 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2182 EXPECT_TRUE(sent_event().cancelable); |
| 2183 |
| 2184 // As the touch start was consumed, touchmoves should no longer be throttled. |
| 2185 MoveTouchPoint(1, 11, 11); |
| 2186 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2187 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2188 EXPECT_TRUE(sent_event().cancelable); |
| 2189 |
| 2190 // With throttling disabled, touchend and touchmove events should also be |
| 2191 // cancelable. |
| 2192 MoveTouchPoint(1, 12, 12); |
| 2193 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2194 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2195 EXPECT_TRUE(sent_event().cancelable); |
| 2196 ReleaseTouchPoint(1); |
| 2197 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2198 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2199 EXPECT_TRUE(sent_event().cancelable); |
| 2200 |
| 2201 // If subsequent touchmoves aren't consumed, the generated scroll events |
| 2202 // will restore async touch dispatch. |
| 2203 MoveTouchPoint(0, 25, 5); |
| 2204 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2205 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate); |
| 2206 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2207 EXPECT_TRUE(sent_event().cancelable); |
| 2208 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
| 2209 MoveTouchPoint(0, 30, 5); |
| 2210 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2211 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 2212 EXPECT_FALSE(sent_event().cancelable); |
| 2213 |
| 2214 // The touchend will be uncancelable during an active scroll sequence. |
| 2215 ReleaseTouchPoint(0); |
| 2216 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 2217 EXPECT_FALSE(sent_event().cancelable); |
| 2218 } |
| 2219 |
2159 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { | 2220 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { |
2160 SyntheticWebTouchEvent event; | 2221 SyntheticWebTouchEvent event; |
2161 event.PressPoint(0, 0); | 2222 event.PressPoint(0, 0); |
2162 SendTouchEvent(event); | 2223 SendTouchEvent(event); |
2163 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2224 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2164 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2225 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2165 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2226 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2166 | 2227 |
2167 // Give the touchmove a previously unseen pointer id; it should not be sent. | 2228 // Give the touchmove a previously unseen pointer id; it should not be sent. |
2168 int press_id = event.touches[0].id; | 2229 int press_id = event.touches[0].id; |
(...skipping 19 matching lines...) Expand all Loading... |
2188 | 2249 |
2189 // Give the touchmove a valid id; it should be sent. | 2250 // Give the touchmove a valid id; it should be sent. |
2190 event.touches[0].id = press_id; | 2251 event.touches[0].id = press_id; |
2191 SendTouchEvent(event); | 2252 SendTouchEvent(event); |
2192 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2253 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2193 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2194 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2255 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2195 } | 2256 } |
2196 | 2257 |
2197 } // namespace content | 2258 } // namespace content |
OLD | NEW |