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" |
| 9 #include "content/browser/renderer_host/input/timeout_monitor.h" |
8 #include "content/browser/renderer_host/input/touch_event_queue.h" | 10 #include "content/browser/renderer_host/input/touch_event_queue.h" |
9 #include "content/common/input/synthetic_web_input_event_builders.h" | 11 #include "content/common/input/synthetic_web_input_event_builders.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/public/web/WebInputEvent.h" | 13 #include "third_party/WebKit/public/web/WebInputEvent.h" |
12 | 14 |
13 using blink::WebGestureEvent; | 15 using blink::WebGestureEvent; |
14 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
15 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
16 using blink::WebTouchPoint; | 18 using blink::WebTouchPoint; |
17 | 19 |
18 namespace content { | 20 namespace content { |
| 21 namespace { |
| 22 const size_t kDefaultTouchTimeoutDelayMs = 10; |
| 23 } |
19 | 24 |
20 class TouchEventQueueTest : public testing::Test, | 25 class TouchEventQueueTest : public testing::Test, |
21 public TouchEventQueueClient { | 26 public TouchEventQueueClient { |
22 public: | 27 public: |
23 TouchEventQueueTest() | 28 TouchEventQueueTest() |
24 : sent_event_count_(0), | 29 : sent_event_count_(0), |
25 acked_event_count_(0), | 30 acked_event_count_(0), |
26 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {} | 31 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {} |
27 | 32 |
28 virtual ~TouchEventQueueTest() {} | 33 virtual ~TouchEventQueueTest() {} |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 scoped_ptr<WebGestureEvent> followup_gesture_event = | 65 scoped_ptr<WebGestureEvent> followup_gesture_event = |
61 followup_gesture_event_.Pass(); | 66 followup_gesture_event_.Pass(); |
62 queue_->OnGestureScrollEvent( | 67 queue_->OnGestureScrollEvent( |
63 GestureEventWithLatencyInfo(*followup_gesture_event, | 68 GestureEventWithLatencyInfo(*followup_gesture_event, |
64 ui::LatencyInfo())); | 69 ui::LatencyInfo())); |
65 } | 70 } |
66 } | 71 } |
67 | 72 |
68 protected: | 73 protected: |
69 | 74 |
| 75 void SetUpForTimeoutTesting(size_t timeout_delay_ms) { |
| 76 queue_->SetAckTimeoutEnabled(true, timeout_delay_ms); |
| 77 } |
| 78 |
70 void SendTouchEvent(const WebTouchEvent& event) { | 79 void SendTouchEvent(const WebTouchEvent& event) { |
71 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); | 80 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); |
72 } | 81 } |
73 | 82 |
74 void SendTouchEvent() { | 83 void SendTouchEvent() { |
75 SendTouchEvent(touch_event_); | 84 SendTouchEvent(touch_event_); |
76 touch_event_.ResetPoints(); | 85 touch_event_.ResetPoints(); |
77 } | 86 } |
78 | 87 |
79 void SendGestureEvent(WebInputEvent::Type type) { | 88 void SendGestureEvent(WebInputEvent::Type type) { |
(...skipping 12 matching lines...) Expand all Loading... |
92 } | 101 } |
93 | 102 |
94 void SetFollowupEvent(const WebGestureEvent& event) { | 103 void SetFollowupEvent(const WebGestureEvent& event) { |
95 followup_gesture_event_.reset(new WebGestureEvent(event)); | 104 followup_gesture_event_.reset(new WebGestureEvent(event)); |
96 } | 105 } |
97 | 106 |
98 void SetSyncAckResult(InputEventAckState sync_ack_result) { | 107 void SetSyncAckResult(InputEventAckState sync_ack_result) { |
99 sync_ack_result_.reset(new InputEventAckState(sync_ack_result)); | 108 sync_ack_result_.reset(new InputEventAckState(sync_ack_result)); |
100 } | 109 } |
101 | 110 |
102 int PressTouchPoint(int x, int y) { | 111 void PressTouchPoint(int x, int y) { |
103 return touch_event_.PressPoint(x, y); | 112 touch_event_.PressPoint(x, y); |
| 113 SendTouchEvent(); |
104 } | 114 } |
105 | 115 |
106 void MoveTouchPoint(int index, int x, int y) { | 116 void MoveTouchPoint(int index, int x, int y) { |
107 touch_event_.MovePoint(index, x, y); | 117 touch_event_.MovePoint(index, x, y); |
| 118 SendTouchEvent(); |
| 119 } |
| 120 |
| 121 void MoveTouchPoints(int index0, int x0, int y0, int index1, int x1, int y1) { |
| 122 touch_event_.MovePoint(index0, x0, y0); |
| 123 touch_event_.MovePoint(index1, x1, y1); |
| 124 SendTouchEvent(); |
108 } | 125 } |
109 | 126 |
110 void ReleaseTouchPoint(int index) { | 127 void ReleaseTouchPoint(int index) { |
111 touch_event_.ReleasePoint(index); | 128 touch_event_.ReleasePoint(index); |
| 129 SendTouchEvent(); |
112 } | 130 } |
113 | 131 |
114 void CancelTouchPoint(int index) { | 132 void CancelTouchPoint(int index) { |
115 touch_event_.CancelPoint(index); | 133 touch_event_.CancelPoint(index); |
| 134 SendTouchEvent(); |
116 } | 135 } |
117 | 136 |
118 size_t GetAndResetAckedEventCount() { | 137 size_t GetAndResetAckedEventCount() { |
119 size_t count = acked_event_count_; | 138 size_t count = acked_event_count_; |
120 acked_event_count_ = 0; | 139 acked_event_count_ = 0; |
121 return count; | 140 return count; |
122 } | 141 } |
123 | 142 |
124 size_t GetAndResetSentEventCount() { | 143 size_t GetAndResetSentEventCount() { |
125 size_t count = sent_event_count_; | 144 size_t count = sent_event_count_; |
126 sent_event_count_ = 0; | 145 sent_event_count_ = 0; |
127 return count; | 146 return count; |
128 } | 147 } |
129 | 148 |
130 void Flush() { | 149 void Flush() { |
131 queue_->FlushQueue(); | 150 queue_->FlushQueue(); |
132 } | 151 } |
133 | 152 |
| 153 void SetEnableTouchForwarding(bool enabled) { |
| 154 queue_->no_touch_to_renderer_ = !enabled; |
| 155 } |
| 156 |
| 157 bool WillForwardTouchEvents() { |
| 158 return !queue_->no_touch_to_renderer_ && !queue_->HasTimeoutEvent(); |
| 159 } |
| 160 |
| 161 bool IsTimeoutRunning() { |
| 162 return queue_->IsTimeoutRunningForTesting(); |
| 163 } |
| 164 |
134 size_t queued_event_count() const { | 165 size_t queued_event_count() const { |
135 return queue_->GetQueueSize(); | 166 return queue_->size(); |
136 } | 167 } |
137 | 168 |
138 const WebTouchEvent& latest_event() const { | 169 const WebTouchEvent& latest_event() const { |
139 return queue_->GetLatestEvent().event; | 170 return queue_->GetLatestEventForTesting().event; |
140 } | 171 } |
141 | 172 |
142 const WebTouchEvent& acked_event() const { | 173 const WebTouchEvent& acked_event() const { |
143 return last_acked_event_; | 174 return last_acked_event_; |
144 } | 175 } |
145 | 176 |
146 const WebTouchEvent& sent_event() const { | 177 const WebTouchEvent& sent_event() const { |
147 return last_sent_event_; | 178 return last_sent_event_; |
148 } | 179 } |
149 | 180 |
(...skipping 13 matching lines...) Expand all Loading... |
163 scoped_ptr<TouchEventQueue> queue_; | 194 scoped_ptr<TouchEventQueue> queue_; |
164 size_t sent_event_count_; | 195 size_t sent_event_count_; |
165 size_t acked_event_count_; | 196 size_t acked_event_count_; |
166 WebTouchEvent last_sent_event_; | 197 WebTouchEvent last_sent_event_; |
167 WebTouchEvent last_acked_event_; | 198 WebTouchEvent last_acked_event_; |
168 InputEventAckState last_acked_event_state_; | 199 InputEventAckState last_acked_event_state_; |
169 SyntheticWebTouchEvent touch_event_; | 200 SyntheticWebTouchEvent touch_event_; |
170 scoped_ptr<WebTouchEvent> followup_touch_event_; | 201 scoped_ptr<WebTouchEvent> followup_touch_event_; |
171 scoped_ptr<WebGestureEvent> followup_gesture_event_; | 202 scoped_ptr<WebGestureEvent> followup_gesture_event_; |
172 scoped_ptr<InputEventAckState> sync_ack_result_; | 203 scoped_ptr<InputEventAckState> sync_ack_result_; |
| 204 base::MessageLoopForUI message_loop_; |
173 }; | 205 }; |
174 | 206 |
175 | 207 |
176 // Tests that touch-events are queued properly. | 208 // Tests that touch-events are queued properly. |
177 TEST_F(TouchEventQueueTest, Basic) { | 209 TEST_F(TouchEventQueueTest, Basic) { |
178 PressTouchPoint(1, 1); | 210 PressTouchPoint(1, 1); |
179 SendTouchEvent(); | |
180 EXPECT_EQ(1U, queued_event_count()); | 211 EXPECT_EQ(1U, queued_event_count()); |
181 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 212 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
182 | 213 |
183 // The second touch should not be sent since one is already in queue. | 214 // The second touch should not be sent since one is already in queue. |
184 MoveTouchPoint(0, 5, 5); | 215 MoveTouchPoint(0, 5, 5); |
185 SendTouchEvent(); | |
186 EXPECT_EQ(2U, queued_event_count()); | 216 EXPECT_EQ(2U, queued_event_count()); |
187 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 217 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
188 | 218 |
189 // Receive an ACK for the first touch-event. | 219 // Receive an ACK for the first touch-event. |
190 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 220 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
191 EXPECT_EQ(1U, queued_event_count()); | 221 EXPECT_EQ(1U, queued_event_count()); |
192 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 222 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
193 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 223 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
194 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 224 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
195 | 225 |
196 // Receive an ACK for the second touch-event. | 226 // Receive an ACK for the second touch-event. |
197 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 227 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
198 EXPECT_EQ(0U, queued_event_count()); | 228 EXPECT_EQ(0U, queued_event_count()); |
199 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 229 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
200 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 230 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
201 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 231 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
202 } | 232 } |
203 | 233 |
204 // Tests that the touch-queue is emptied if a page stops listening for touch | 234 // Tests that the touch-queue is emptied if a page stops listening for touch |
205 // events. | 235 // events. |
206 TEST_F(TouchEventQueueTest, Flush) { | 236 TEST_F(TouchEventQueueTest, Flush) { |
207 Flush(); | 237 Flush(); |
208 EXPECT_EQ(0U, queued_event_count()); | 238 EXPECT_EQ(0U, queued_event_count()); |
209 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 239 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
210 | 240 |
211 // Send a touch-press event. | 241 // Send a touch-press event. |
212 PressTouchPoint(1, 1); | 242 PressTouchPoint(1, 1); |
213 SendTouchEvent(); | |
214 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 243 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
215 | 244 |
216 ReleaseTouchPoint(0); | 245 ReleaseTouchPoint(0); |
217 SendTouchEvent(); | |
218 | 246 |
219 // Events will be queued until the first sent event is ack'ed. | 247 // Events will be queued until the first sent event is ack'ed. |
220 for (int i = 5; i < 15; ++i) { | 248 for (int i = 5; i < 15; ++i) { |
221 PressTouchPoint(1, 1); | 249 PressTouchPoint(1, 1); |
222 SendTouchEvent(); | |
223 MoveTouchPoint(0, i, i); | 250 MoveTouchPoint(0, i, i); |
224 SendTouchEvent(); | |
225 ReleaseTouchPoint(0); | 251 ReleaseTouchPoint(0); |
226 SendTouchEvent(); | |
227 } | 252 } |
228 EXPECT_EQ(32U, queued_event_count()); | 253 EXPECT_EQ(32U, queued_event_count()); |
229 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 254 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
230 | 255 |
231 // Receive an ACK for the first touch-event. One of the queued touch-event | 256 // Receive an ACK for the first touch-event. One of the queued touch-event |
232 // should be forwarded. | 257 // should be forwarded. |
233 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 258 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
234 EXPECT_EQ(31U, queued_event_count()); | 259 EXPECT_EQ(31U, queued_event_count()); |
235 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 260 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
236 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 261 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
237 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 262 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
238 | 263 |
239 // Flush the queue. The touch-event queue should now be emptied, but none of | 264 // Flush the queue. The touch-event queue should now be emptied, but none of |
240 // the queued touch-events should be sent to the renderer. | 265 // the queued touch-events should be sent to the renderer. |
241 Flush(); | 266 Flush(); |
242 EXPECT_EQ(0U, queued_event_count()); | 267 EXPECT_EQ(0U, queued_event_count()); |
243 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 268 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
244 EXPECT_EQ(31U, GetAndResetAckedEventCount()); | 269 EXPECT_EQ(31U, GetAndResetAckedEventCount()); |
245 } | 270 } |
246 | 271 |
247 // Tests that touch-events are coalesced properly in the queue. | 272 // Tests that touch-events are coalesced properly in the queue. |
248 TEST_F(TouchEventQueueTest, Coalesce) { | 273 TEST_F(TouchEventQueueTest, Coalesce) { |
249 // Send a touch-press event. | 274 // Send a touch-press event. |
250 PressTouchPoint(1, 1); | 275 PressTouchPoint(1, 1); |
251 SendTouchEvent(); | |
252 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 276 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
253 | 277 |
254 // Send a few touch-move events, followed by a touch-release event. All the | 278 // Send a few touch-move events, followed by a touch-release event. All the |
255 // touch-move events should be coalesced into a single event. | 279 // touch-move events should be coalesced into a single event. |
256 for (int i = 5; i < 15; ++i) { | 280 for (int i = 5; i < 15; ++i) |
257 MoveTouchPoint(0, i, i); | 281 MoveTouchPoint(0, i, i); |
258 SendTouchEvent(); | 282 |
259 } | |
260 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 283 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
261 ReleaseTouchPoint(0); | 284 ReleaseTouchPoint(0); |
262 SendTouchEvent(); | |
263 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 285 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
264 EXPECT_EQ(3U, queued_event_count()); | 286 EXPECT_EQ(3U, queued_event_count()); |
265 | 287 |
266 // ACK the press. Coalesced touch-move events should be sent. | 288 // ACK the press. Coalesced touch-move events should be sent. |
267 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 289 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
268 EXPECT_EQ(2U, queued_event_count()); | 290 EXPECT_EQ(2U, queued_event_count()); |
269 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 291 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
270 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 292 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
271 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 293 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
272 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 294 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
(...skipping 11 matching lines...) Expand all Loading... |
284 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 306 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
285 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 307 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
286 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 308 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
287 } | 309 } |
288 | 310 |
289 // Tests that an event that has already been sent but hasn't been ack'ed yet | 311 // Tests that an event that has already been sent but hasn't been ack'ed yet |
290 // doesn't get coalesced with newer events. | 312 // doesn't get coalesced with newer events. |
291 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { | 313 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { |
292 // Send a touch-press event. | 314 // Send a touch-press event. |
293 PressTouchPoint(1, 1); | 315 PressTouchPoint(1, 1); |
294 SendTouchEvent(); | |
295 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 316 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
296 | 317 |
297 // Send a few touch-move events, followed by a touch-release event. All the | 318 // Send a few touch-move events, followed by a touch-release event. All the |
298 // touch-move events should be coalesced into a single event. | 319 // touch-move events should be coalesced into a single event. |
299 for (int i = 5; i < 15; ++i) { | 320 for (int i = 5; i < 15; ++i) |
300 MoveTouchPoint(0, i, i); | 321 MoveTouchPoint(0, i, i); |
301 SendTouchEvent(); | 322 |
302 } | |
303 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 323 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
304 EXPECT_EQ(2U, queued_event_count()); | 324 EXPECT_EQ(2U, queued_event_count()); |
305 | 325 |
306 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 326 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
307 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 327 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
308 EXPECT_EQ(1U, queued_event_count()); | 328 EXPECT_EQ(1U, queued_event_count()); |
309 | 329 |
310 // The coalesced touch-move event has been sent to the renderer. Any new | 330 // The coalesced touch-move event has been sent to the renderer. Any new |
311 // touch-move event should not be coalesced with the sent event. | 331 // touch-move event should not be coalesced with the sent event. |
312 MoveTouchPoint(0, 5, 5); | 332 MoveTouchPoint(0, 5, 5); |
313 SendTouchEvent(); | |
314 EXPECT_EQ(2U, queued_event_count()); | 333 EXPECT_EQ(2U, queued_event_count()); |
315 | 334 |
316 MoveTouchPoint(0, 7, 7); | 335 MoveTouchPoint(0, 7, 7); |
317 SendTouchEvent(); | |
318 EXPECT_EQ(2U, queued_event_count()); | 336 EXPECT_EQ(2U, queued_event_count()); |
319 } | 337 } |
320 | 338 |
321 // Tests that coalescing works correctly for multi-touch events. | 339 // Tests that coalescing works correctly for multi-touch events. |
322 TEST_F(TouchEventQueueTest, MultiTouch) { | 340 TEST_F(TouchEventQueueTest, MultiTouch) { |
323 // Press the first finger. | 341 // Press the first finger. |
324 PressTouchPoint(1, 1); | 342 PressTouchPoint(1, 1); |
325 SendTouchEvent(); | |
326 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 343 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
327 | 344 |
328 // Move the finger. | 345 // Move the finger. |
329 MoveTouchPoint(0, 5, 5); | 346 MoveTouchPoint(0, 5, 5); |
330 SendTouchEvent(); | |
331 EXPECT_EQ(2U, queued_event_count()); | 347 EXPECT_EQ(2U, queued_event_count()); |
332 | 348 |
333 // Now press a second finger. | 349 // Now press a second finger. |
334 PressTouchPoint(2, 2); | 350 PressTouchPoint(2, 2); |
335 SendTouchEvent(); | |
336 EXPECT_EQ(3U, queued_event_count()); | 351 EXPECT_EQ(3U, queued_event_count()); |
337 | 352 |
338 // Move both fingers. | 353 // Move both fingers. |
339 MoveTouchPoint(0, 10, 10); | 354 MoveTouchPoints(0, 10, 10, 1, 20, 20); |
340 MoveTouchPoint(1, 20, 20); | 355 MoveTouchPoint(1, 20, 20); |
341 SendTouchEvent(); | |
342 EXPECT_EQ(4U, queued_event_count()); | 356 EXPECT_EQ(4U, queued_event_count()); |
343 | 357 |
344 // Move only one finger now. | 358 // Move only one finger now. |
345 MoveTouchPoint(0, 15, 15); | 359 MoveTouchPoint(0, 15, 15); |
346 SendTouchEvent(); | |
347 EXPECT_EQ(4U, queued_event_count()); | 360 EXPECT_EQ(4U, queued_event_count()); |
348 | 361 |
349 // Move the other finger. | 362 // Move the other finger. |
350 MoveTouchPoint(1, 25, 25); | 363 MoveTouchPoint(1, 25, 25); |
351 SendTouchEvent(); | |
352 EXPECT_EQ(4U, queued_event_count()); | 364 EXPECT_EQ(4U, queued_event_count()); |
353 | 365 |
354 // Make sure both fingers are marked as having been moved in the coalesced | 366 // Make sure both fingers are marked as having been moved in the coalesced |
355 // event. | 367 // event. |
356 const WebTouchEvent& event = latest_event(); | 368 const WebTouchEvent& event = latest_event(); |
357 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); | 369 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); |
358 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); | 370 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); |
359 } | 371 } |
360 | 372 |
361 // Tests that if a touch-event queue is destroyed in response to a touch-event | 373 // Tests that if a touch-event queue is destroyed in response to a touch-event |
362 // in the renderer, then there is no crash when the ACK for that touch-event | 374 // in the renderer, then there is no crash when the ACK for that touch-event |
363 // comes back. | 375 // comes back. |
364 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) { | 376 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) { |
365 // Send some touch-events to the renderer. | 377 // Send some touch-events to the renderer. |
366 PressTouchPoint(1, 1); | 378 PressTouchPoint(1, 1); |
367 SendTouchEvent(); | |
368 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 379 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
369 EXPECT_EQ(1U, queued_event_count()); | 380 EXPECT_EQ(1U, queued_event_count()); |
370 | 381 |
371 MoveTouchPoint(0, 10, 10); | 382 MoveTouchPoint(0, 10, 10); |
372 SendTouchEvent(); | |
373 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 383 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
374 EXPECT_EQ(2U, queued_event_count()); | 384 EXPECT_EQ(2U, queued_event_count()); |
375 | 385 |
376 // Receive an ACK for the press. This should cause the queued touch-move to | 386 // Receive an ACK for the press. This should cause the queued touch-move to |
377 // be sent to the renderer. | 387 // be sent to the renderer. |
378 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 388 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
379 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 389 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
380 EXPECT_EQ(1U, queued_event_count()); | 390 EXPECT_EQ(1U, queued_event_count()); |
381 | 391 |
382 Flush(); | 392 Flush(); |
383 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 393 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
384 EXPECT_EQ(0U, queued_event_count()); | 394 EXPECT_EQ(0U, queued_event_count()); |
385 | 395 |
386 // Now receive an ACK for the move. | 396 // Now receive an ACK for the move. |
387 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 397 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
388 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 398 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
389 EXPECT_EQ(0U, queued_event_count()); | 399 EXPECT_EQ(0U, queued_event_count()); |
390 } | 400 } |
391 | 401 |
392 // Tests that touch-move events are not sent to the renderer if the preceding | 402 // Tests that touch-move events are not sent to the renderer if the preceding |
393 // touch-press event did not have a consumer (and consequently, did not hit the | 403 // touch-press event did not have a consumer (and consequently, did not hit the |
394 // main thread in the renderer). Also tests that all queued/coalesced touch | 404 // main thread in the renderer). Also tests that all queued/coalesced touch |
395 // events are flushed immediately when the ACK for the touch-press comes back | 405 // events are flushed immediately when the ACK for the touch-press comes back |
396 // with NO_CONSUMER status. | 406 // with NO_CONSUMER status. |
397 TEST_F(TouchEventQueueTest, NoConsumer) { | 407 TEST_F(TouchEventQueueTest, NoConsumer) { |
398 // The first touch-press should reach the renderer. | 408 // The first touch-press should reach the renderer. |
399 PressTouchPoint(1, 1); | 409 PressTouchPoint(1, 1); |
400 SendTouchEvent(); | |
401 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 410 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
402 | 411 |
403 // The second touch should not be sent since one is already in queue. | 412 // The second touch should not be sent since one is already in queue. |
404 MoveTouchPoint(0, 5, 5); | 413 MoveTouchPoint(0, 5, 5); |
405 SendTouchEvent(); | |
406 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 414 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
407 EXPECT_EQ(2U, queued_event_count()); | 415 EXPECT_EQ(2U, queued_event_count()); |
408 | 416 |
409 // Receive an ACK for the first touch-event. This should release the queued | 417 // Receive an ACK for the first touch-event. This should release the queued |
410 // touch-event, but it should not be sent to the renderer. | 418 // touch-event, but it should not be sent to the renderer. |
411 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 419 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
412 EXPECT_EQ(0U, queued_event_count()); | 420 EXPECT_EQ(0U, queued_event_count()); |
413 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 421 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
414 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 422 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
415 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 423 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
416 | 424 |
417 // Send a release event. This should not reach the renderer. | 425 // Send a release event. This should not reach the renderer. |
418 ReleaseTouchPoint(0); | 426 ReleaseTouchPoint(0); |
419 SendTouchEvent(); | |
420 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 427 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
421 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 428 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
422 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 429 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
423 | 430 |
424 // Send a press-event, followed by move and release events, and another press | 431 // Send a press-event, followed by move and release events, and another press |
425 // event, before the ACK for the first press event comes back. All of the | 432 // event, before the ACK for the first press event comes back. All of the |
426 // events should be queued first. After the NO_CONSUMER ack for the first | 433 // events should be queued first. After the NO_CONSUMER ack for the first |
427 // touch-press, all events upto the second touch-press should be flushed. | 434 // touch-press, all events upto the second touch-press should be flushed. |
428 PressTouchPoint(10, 10); | 435 PressTouchPoint(10, 10); |
429 SendTouchEvent(); | |
430 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 436 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
431 | 437 |
432 MoveTouchPoint(0, 5, 5); | 438 MoveTouchPoint(0, 5, 5); |
433 SendTouchEvent(); | |
434 MoveTouchPoint(0, 6, 5); | 439 MoveTouchPoint(0, 6, 5); |
435 SendTouchEvent(); | |
436 ReleaseTouchPoint(0); | 440 ReleaseTouchPoint(0); |
437 SendTouchEvent(); | |
438 | 441 |
439 PressTouchPoint(6, 5); | 442 PressTouchPoint(6, 5); |
440 SendTouchEvent(); | |
441 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 443 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
442 // The queue should hold the first sent touch-press event, the coalesced | 444 // The queue should hold the first sent touch-press event, the coalesced |
443 // touch-move event, the touch-end event and the second touch-press event. | 445 // touch-move event, the touch-end event and the second touch-press event. |
444 EXPECT_EQ(4U, queued_event_count()); | 446 EXPECT_EQ(4U, queued_event_count()); |
445 | 447 |
446 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 448 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
447 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 449 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
448 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 450 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
449 EXPECT_EQ(4U, GetAndResetAckedEventCount()); | 451 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
450 EXPECT_EQ(1U, queued_event_count()); | 452 EXPECT_EQ(1U, queued_event_count()); |
451 | 453 |
452 // ACK the second press event as NO_CONSUMER too. | 454 // ACK the second press event as NO_CONSUMER too. |
453 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 455 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
454 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 456 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
455 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 457 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
456 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 458 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
457 EXPECT_EQ(0U, queued_event_count()); | 459 EXPECT_EQ(0U, queued_event_count()); |
458 | 460 |
459 // Send a second press event. Even though the first touch had NO_CONSUMER, | 461 // Send a second press event. Even though the first touch had NO_CONSUMER, |
460 // this press event should reach the renderer. | 462 // this press event should reach the renderer. |
461 PressTouchPoint(1, 1); | 463 PressTouchPoint(1, 1); |
462 SendTouchEvent(); | |
463 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 464 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
464 EXPECT_EQ(1U, queued_event_count()); | 465 EXPECT_EQ(1U, queued_event_count()); |
465 } | 466 } |
466 | 467 |
467 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { | 468 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { |
468 // Press two touch points and move them around a bit. The renderer consumes | 469 // Press two touch points and move them around a bit. The renderer consumes |
469 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for | 470 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for |
470 // the second touch point. | 471 // the second touch point. |
471 | 472 |
472 PressTouchPoint(1, 1); | 473 PressTouchPoint(1, 1); |
473 SendTouchEvent(); | |
474 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 474 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
475 | 475 |
476 MoveTouchPoint(0, 5, 5); | 476 MoveTouchPoint(0, 5, 5); |
477 SendTouchEvent(); | |
478 | 477 |
479 PressTouchPoint(10, 10); | 478 PressTouchPoint(10, 10); |
480 SendTouchEvent(); | |
481 | 479 |
482 MoveTouchPoint(0, 2, 2); | 480 MoveTouchPoint(0, 2, 2); |
483 SendTouchEvent(); | |
484 | 481 |
485 MoveTouchPoint(1, 4, 10); | 482 MoveTouchPoint(1, 4, 10); |
486 SendTouchEvent(); | |
487 | 483 |
488 MoveTouchPoint(0, 10, 10); | 484 MoveTouchPoints(0, 10, 10, 1, 20, 20); |
489 MoveTouchPoint(1, 20, 20); | |
490 SendTouchEvent(); | |
491 | 485 |
492 // Since the first touch-press is still pending ACK, no other event should | 486 // Since the first touch-press is still pending ACK, no other event should |
493 // have been sent to the renderer. | 487 // have been sent to the renderer. |
494 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 488 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
495 // The queue includes the two presses, the first touch-move of the first | 489 // The queue includes the two presses, the first touch-move of the first |
496 // point, and a coalesced touch-move of both points. | 490 // point, and a coalesced touch-move of both points. |
497 EXPECT_EQ(4U, queued_event_count()); | 491 EXPECT_EQ(4U, queued_event_count()); |
498 | 492 |
499 // ACK the first press as CONSUMED. This should cause the first touch-move of | 493 // ACK the first press as CONSUMED. This should cause the first touch-move of |
500 // the first touch-point to be dispatched. | 494 // the first touch-point to be dispatched. |
(...skipping 15 matching lines...) Expand all Loading... |
516 EXPECT_EQ(1U, queued_event_count()); | 510 EXPECT_EQ(1U, queued_event_count()); |
517 | 511 |
518 // ACK the coalesced move as NOT_CONSUMED. | 512 // ACK the coalesced move as NOT_CONSUMED. |
519 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 513 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
520 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 514 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
521 EXPECT_EQ(0U, queued_event_count()); | 515 EXPECT_EQ(0U, queued_event_count()); |
522 | 516 |
523 // Move just the second touch point. Because the first touch point did not | 517 // Move just the second touch point. Because the first touch point did not |
524 // move, this event should not reach the renderer. | 518 // move, this event should not reach the renderer. |
525 MoveTouchPoint(1, 30, 30); | 519 MoveTouchPoint(1, 30, 30); |
526 SendTouchEvent(); | |
527 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 520 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
528 EXPECT_EQ(0U, queued_event_count()); | 521 EXPECT_EQ(0U, queued_event_count()); |
529 | 522 |
530 // Move just the first touch point. This should reach the renderer. | 523 // Move just the first touch point. This should reach the renderer. |
531 MoveTouchPoint(0, 10, 10); | 524 MoveTouchPoint(0, 10, 10); |
532 SendTouchEvent(); | |
533 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 525 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
534 EXPECT_EQ(1U, queued_event_count()); | 526 EXPECT_EQ(1U, queued_event_count()); |
535 | 527 |
536 // Move both fingers. This event should reach the renderer (after the ACK of | 528 // Move both fingers. This event should reach the renderer (after the ACK of |
537 // the previous move event is received), because the first touch point did | 529 // the previous move event is received), because the first touch point did |
538 // move. | 530 // move. |
539 MoveTouchPoint(0, 15, 15); | 531 MoveTouchPoints(0, 15, 15, 1, 25, 25); |
540 MoveTouchPoint(1, 25, 25); | |
541 SendTouchEvent(); | |
542 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 532 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
543 | 533 |
544 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 534 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
545 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 535 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
546 EXPECT_EQ(1U, queued_event_count()); | 536 EXPECT_EQ(1U, queued_event_count()); |
547 | 537 |
548 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 538 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
549 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 539 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
550 EXPECT_EQ(0U, queued_event_count()); | 540 EXPECT_EQ(0U, queued_event_count()); |
551 | 541 |
552 // Release the first finger. Then move the second finger around some, then | 542 // Release the first finger. Then move the second finger around some, then |
553 // press another finger. Once the release event is ACKed, the move events of | 543 // press another finger. Once the release event is ACKed, the move events of |
554 // the second finger should be immediately released to the view, and the | 544 // the second finger should be immediately released to the view, and the |
555 // touch-press event should be dispatched to the renderer. | 545 // touch-press event should be dispatched to the renderer. |
556 ReleaseTouchPoint(0); | 546 ReleaseTouchPoint(0); |
557 SendTouchEvent(); | |
558 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 547 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
559 EXPECT_EQ(1U, queued_event_count()); | 548 EXPECT_EQ(1U, queued_event_count()); |
560 | 549 |
561 MoveTouchPoint(1, 40, 40); | 550 MoveTouchPoint(1, 40, 40); |
562 SendTouchEvent(); | |
563 | 551 |
564 MoveTouchPoint(1, 50, 50); | 552 MoveTouchPoint(1, 50, 50); |
565 SendTouchEvent(); | |
566 | 553 |
567 PressTouchPoint(1, 1); | 554 PressTouchPoint(1, 1); |
568 SendTouchEvent(); | |
569 | 555 |
570 MoveTouchPoint(1, 30, 30); | 556 MoveTouchPoint(1, 30, 30); |
571 SendTouchEvent(); | |
572 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 557 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
573 EXPECT_EQ(4U, queued_event_count()); | 558 EXPECT_EQ(4U, queued_event_count()); |
574 | 559 |
575 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 560 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
576 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 561 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
577 EXPECT_EQ(2U, queued_event_count()); | 562 EXPECT_EQ(2U, queued_event_count()); |
578 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 563 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
579 | 564 |
580 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued | 565 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued |
581 // touch-move events to the view. | 566 // touch-move events to the view. |
582 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 567 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
583 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 568 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
584 EXPECT_EQ(0U, queued_event_count()); | 569 EXPECT_EQ(0U, queued_event_count()); |
585 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 570 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
586 | 571 |
587 ReleaseTouchPoint(2); | 572 ReleaseTouchPoint(2); |
588 ReleaseTouchPoint(1); | 573 ReleaseTouchPoint(1); |
589 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 574 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
590 EXPECT_EQ(0U, queued_event_count()); | 575 EXPECT_EQ(0U, queued_event_count()); |
591 } | 576 } |
592 | 577 |
593 // Tests that touch-event's enqueued via a touch ack are properly handled. | 578 // Tests that touch-event's enqueued via a touch ack are properly handled. |
594 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { | 579 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { |
595 // Queue a touch down. | 580 // Queue a touch down. |
596 PressTouchPoint(1, 1); | 581 PressTouchPoint(1, 1); |
597 SendTouchEvent(); | |
598 EXPECT_EQ(1U, queued_event_count()); | 582 EXPECT_EQ(1U, queued_event_count()); |
599 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 583 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
600 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 584 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
601 | 585 |
602 // Create a touch event that will be queued synchronously by a touch ack. | 586 // Create a touch event that will be queued synchronously by a touch ack. |
603 // Note, this will be triggered by all subsequent touch acks. | 587 // Note, this will be triggered by all subsequent touch acks. |
604 WebTouchEvent followup_event; | 588 WebTouchEvent followup_event; |
605 followup_event.type = WebInputEvent::TouchStart; | 589 followup_event.type = WebInputEvent::TouchStart; |
606 followup_event.touchesLength = 1; | 590 followup_event.touchesLength = 1; |
607 followup_event.touches[0].id = 1; | 591 followup_event.touches[0].id = 1; |
608 followup_event.touches[0].state = WebTouchPoint::StatePressed; | 592 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
609 SetFollowupEvent(followup_event); | 593 SetFollowupEvent(followup_event); |
610 | 594 |
611 // Receive an ACK for the press. This should cause the followup touch-move to | 595 // Receive an ACK for the press. This should cause the followup touch-move to |
612 // be sent to the renderer. | 596 // be sent to the renderer. |
613 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 597 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
614 EXPECT_EQ(1U, queued_event_count()); | 598 EXPECT_EQ(1U, queued_event_count()); |
615 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 599 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
616 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 600 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
617 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 601 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
618 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 602 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
619 | 603 |
620 // Queue another event. | 604 // Queue another event. |
621 PressTouchPoint(1, 1); | |
622 MoveTouchPoint(0, 2, 2); | 605 MoveTouchPoint(0, 2, 2); |
623 SendTouchEvent(); | |
624 EXPECT_EQ(2U, queued_event_count()); | 606 EXPECT_EQ(2U, queued_event_count()); |
625 | 607 |
626 // Receive an ACK for the touch-move followup event. This should cause the | 608 // Receive an ACK for the touch-move followup event. This should cause the |
627 // subsequent touch move event be sent to the renderer. | 609 // subsequent touch move event be sent to the renderer. |
628 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 610 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
629 EXPECT_EQ(1U, queued_event_count()); | 611 EXPECT_EQ(1U, queued_event_count()); |
630 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 612 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
631 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 613 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
632 } | 614 } |
633 | 615 |
634 // Tests that touch-events can be synchronously ack'ed. | 616 // Tests that touch-events can be synchronously ack'ed. |
635 TEST_F(TouchEventQueueTest, SynchronousAcks) { | 617 TEST_F(TouchEventQueueTest, SynchronousAcks) { |
636 // TouchStart | 618 // TouchStart |
637 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 619 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
638 PressTouchPoint(1, 1); | 620 PressTouchPoint(1, 1); |
639 SendTouchEvent(); | |
640 EXPECT_EQ(0U, queued_event_count()); | 621 EXPECT_EQ(0U, queued_event_count()); |
641 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 622 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
642 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 623 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
643 | 624 |
644 // TouchMove | 625 // TouchMove |
645 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 626 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
646 PressTouchPoint(1, 1); | |
647 MoveTouchPoint(0, 2, 2); | 627 MoveTouchPoint(0, 2, 2); |
648 SendTouchEvent(); | |
649 EXPECT_EQ(0U, queued_event_count()); | 628 EXPECT_EQ(0U, queued_event_count()); |
650 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 629 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
651 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 630 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
652 | 631 |
653 // TouchEnd | 632 // TouchEnd |
654 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 633 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
655 PressTouchPoint(1, 1); | |
656 ReleaseTouchPoint(0); | 634 ReleaseTouchPoint(0); |
657 SendTouchEvent(); | |
658 EXPECT_EQ(0U, queued_event_count()); | 635 EXPECT_EQ(0U, queued_event_count()); |
659 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 636 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
660 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 637 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
661 | 638 |
662 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent) | 639 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent) |
663 PressTouchPoint(1, 1); | 640 PressTouchPoint(1, 1); |
664 SendTouchEvent(); | |
665 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 641 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
666 EXPECT_EQ(0U, queued_event_count()); | 642 EXPECT_EQ(0U, queued_event_count()); |
667 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 643 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
668 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 644 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
669 | 645 |
670 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 646 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
671 PressTouchPoint(1, 1); | |
672 CancelTouchPoint(0); | 647 CancelTouchPoint(0); |
673 SendTouchEvent(); | |
674 EXPECT_EQ(0U, queued_event_count()); | 648 EXPECT_EQ(0U, queued_event_count()); |
675 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 649 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
676 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 650 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
677 } | 651 } |
678 | 652 |
679 // Tests that followup events triggered by an immediate ack from | 653 // Tests that followup events triggered by an immediate ack from |
680 // TouchEventQueue::QueueEvent() are properly handled. | 654 // TouchEventQueue::QueueEvent() are properly handled. |
681 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { | 655 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { |
682 // Create a touch event that will be queued synchronously by a touch ack. | 656 // Create a touch event that will be queued synchronously by a touch ack. |
683 WebTouchEvent followup_event; | 657 WebTouchEvent followup_event; |
(...skipping 16 matching lines...) Expand all Loading... |
700 EXPECT_EQ(1U, queued_event_count()); | 674 EXPECT_EQ(1U, queued_event_count()); |
701 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 675 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
702 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 676 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
703 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 677 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
704 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 678 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
705 } | 679 } |
706 | 680 |
707 // Tests basic TouchEvent forwarding suppression. | 681 // Tests basic TouchEvent forwarding suppression. |
708 TEST_F(TouchEventQueueTest, NoTouchBasic) { | 682 TEST_F(TouchEventQueueTest, NoTouchBasic) { |
709 // Disable TouchEvent forwarding. | 683 // Disable TouchEvent forwarding. |
710 set_no_touch_to_renderer(true); | 684 SetEnableTouchForwarding(false); |
711 MoveTouchPoint(0, 30, 5); | 685 MoveTouchPoint(0, 30, 5); |
712 SendTouchEvent(); | |
713 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 686 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
714 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 687 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
715 | 688 |
716 // TouchMove should not be sent to renderer. | 689 // TouchMove should not be sent to renderer. |
717 MoveTouchPoint(0, 65, 10); | 690 MoveTouchPoint(0, 65, 10); |
718 SendTouchEvent(); | |
719 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 691 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
720 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 692 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
721 | 693 |
722 // TouchEnd should not be sent to renderer. | 694 // TouchEnd should not be sent to renderer. |
723 ReleaseTouchPoint(0); | 695 ReleaseTouchPoint(0); |
724 SendTouchEvent(); | |
725 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 696 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
726 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 697 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
727 | 698 |
728 // TouchStart should not be sent to renderer. | 699 // TouchStart should not be sent to renderer. |
729 PressTouchPoint(5, 5); | 700 PressTouchPoint(5, 5); |
730 SendTouchEvent(); | |
731 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 701 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
732 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 702 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
733 | 703 |
734 // Enable TouchEvent forwarding. | 704 // Enable TouchEvent forwarding. |
735 set_no_touch_to_renderer(false); | 705 SetEnableTouchForwarding(true); |
736 | 706 |
737 PressTouchPoint(80, 10); | 707 PressTouchPoint(80, 10); |
738 SendTouchEvent(); | |
739 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 708 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
740 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 709 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
741 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 710 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
742 | 711 |
743 MoveTouchPoint(0, 80, 20); | 712 MoveTouchPoint(0, 80, 20); |
744 SendTouchEvent(); | |
745 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 713 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
746 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 714 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
747 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 715 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
748 | 716 |
749 ReleaseTouchPoint(0); | 717 ReleaseTouchPoint(0); |
750 SendTouchEvent(); | |
751 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 718 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
752 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 719 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
753 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 720 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
754 } | 721 } |
755 | 722 |
756 // Tests that no TouchEvents are sent to renderer during scrolling. | 723 // Tests that no TouchEvents are sent to renderer during scrolling. |
757 TEST_F(TouchEventQueueTest, NoTouchOnScroll) { | 724 TEST_F(TouchEventQueueTest, NoTouchOnScroll) { |
758 // Queue a TouchStart. | 725 // Queue a TouchStart. |
759 PressTouchPoint(0, 1); | 726 PressTouchPoint(0, 1); |
760 SendTouchEvent(); | |
761 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 727 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
762 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 728 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
763 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 729 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
764 | 730 |
765 MoveTouchPoint(0, 20, 5); | 731 MoveTouchPoint(0, 20, 5); |
766 SendTouchEvent(); | |
767 EXPECT_EQ(1U, queued_event_count()); | 732 EXPECT_EQ(1U, queued_event_count()); |
768 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 733 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
769 | 734 |
770 // Queue another TouchStart. | 735 // Queue another TouchStart. |
771 PressTouchPoint(20, 20); | 736 PressTouchPoint(20, 20); |
772 SendTouchEvent(); | |
773 EXPECT_EQ(2U, queued_event_count()); | 737 EXPECT_EQ(2U, queued_event_count()); |
774 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 738 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
775 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 739 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
776 | 740 |
777 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. | 741 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. |
778 WebGestureEvent followup_scroll; | 742 WebGestureEvent followup_scroll; |
779 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 743 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
780 SetFollowupEvent(followup_scroll); | 744 SetFollowupEvent(followup_scroll); |
781 ASSERT_FALSE(no_touch_to_renderer()); | 745 ASSERT_TRUE(WillForwardTouchEvents()); |
782 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 746 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
783 EXPECT_TRUE(no_touch_to_renderer()); | 747 EXPECT_FALSE(WillForwardTouchEvents()); |
784 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 748 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
785 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 749 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
786 EXPECT_EQ(2U, queued_event_count()); | 750 EXPECT_EQ(2U, queued_event_count()); |
787 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 751 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
788 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 752 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
789 | 753 |
790 // Acking the TouchCancel will result in dispatch of the next TouchStart. | 754 // Acking the TouchCancel will result in dispatch of the next TouchStart. |
791 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 755 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
792 // The synthetic TouchCancel should not reach client, only the TouchStart. | 756 // The synthetic TouchCancel should not reach client, only the TouchStart. |
793 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 757 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
794 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 758 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
795 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 759 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
796 | 760 |
797 // TouchMove should not be sent to renderer. | 761 // TouchMove should not be sent to the renderer. |
798 MoveTouchPoint(0, 30, 5); | 762 MoveTouchPoint(0, 30, 5); |
799 SendTouchEvent(); | |
800 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 763 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
801 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 764 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
802 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 765 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
803 | 766 |
804 // GestureScrollUpdates should not change affect touch forwarding. | 767 // GestureScrollUpdates should not change affect touch forwarding. |
805 SendGestureEvent(WebInputEvent::GestureScrollUpdate); | 768 SendGestureEvent(WebInputEvent::GestureScrollUpdate); |
806 EXPECT_TRUE(no_touch_to_renderer()); | 769 EXPECT_FALSE(WillForwardTouchEvents()); |
807 | 770 |
808 // TouchEnd should not be sent to renderer. | 771 // TouchEnd should not be sent to the renderer. |
809 ReleaseTouchPoint(0); | 772 ReleaseTouchPoint(0); |
810 SendTouchEvent(); | |
811 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 773 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
812 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 774 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
813 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 775 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
814 | 776 |
815 // GestureScrollEnd will resume the sending of TouchEvents to renderer. | 777 // GestureScrollEnd will resume the sending of TouchEvents to renderer. |
816 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 778 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
817 EXPECT_FALSE(no_touch_to_renderer()); | 779 EXPECT_TRUE(WillForwardTouchEvents()); |
818 | 780 |
819 // Now TouchEvents should be forwarded normally. | 781 // Now TouchEvents should be forwarded normally. |
820 PressTouchPoint(80, 10); | 782 PressTouchPoint(80, 10); |
| 783 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 784 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 785 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 786 |
| 787 MoveTouchPoint(0, 80, 20); |
| 788 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 789 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 790 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 791 |
| 792 ReleaseTouchPoint(0); |
| 793 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 794 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 795 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 796 } |
| 797 |
| 798 // Tests that the touch timeout is started when sending certain touch types. |
| 799 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) { |
| 800 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 801 |
| 802 // Sending a TouchStart will start the timeout. |
| 803 PressTouchPoint(0, 1); |
821 SendTouchEvent(); | 804 SendTouchEvent(); |
822 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 805 EXPECT_TRUE(IsTimeoutRunning()); |
823 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 806 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
824 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 807 EXPECT_FALSE(IsTimeoutRunning()); |
825 | 808 |
826 MoveTouchPoint(0, 80, 20); | 809 // A TouchMove should start the timeout. |
827 SendTouchEvent(); | 810 MoveTouchPoint(0, 5, 5); |
828 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 811 EXPECT_TRUE(IsTimeoutRunning()); |
829 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 812 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
830 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 813 EXPECT_FALSE(IsTimeoutRunning()); |
831 | 814 |
| 815 // A TouchEnd should not start the timeout. |
832 ReleaseTouchPoint(0); | 816 ReleaseTouchPoint(0); |
833 SendTouchEvent(); | 817 EXPECT_FALSE(IsTimeoutRunning()); |
834 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 818 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
835 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 819 EXPECT_FALSE(IsTimeoutRunning()); |
836 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 820 |
837 } | 821 // A TouchCancel should not start the timeout. |
838 | 822 PressTouchPoint(0, 1); |
| 823 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 824 ASSERT_FALSE(IsTimeoutRunning()); |
| 825 CancelTouchPoint(0); |
| 826 EXPECT_FALSE(IsTimeoutRunning()); |
| 827 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 828 EXPECT_FALSE(IsTimeoutRunning()); |
| 829 } |
| 830 |
| 831 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout, |
| 832 // disabling touch forwarding until the next TouchStart is received after |
| 833 // the timeout events are ack'ed. |
| 834 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { |
| 835 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 836 |
| 837 // Queue a TouchStart. |
| 838 GetAndResetSentEventCount(); |
| 839 GetAndResetAckedEventCount(); |
| 840 PressTouchPoint(0, 1); |
| 841 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 842 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 843 EXPECT_TRUE(IsTimeoutRunning()); |
| 844 EXPECT_TRUE(WillForwardTouchEvents()); |
| 845 |
| 846 // Delay the ack. |
| 847 base::MessageLoop::current()->PostDelayedTask( |
| 848 FROM_HERE, |
| 849 base::MessageLoop::QuitClosure(), |
| 850 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 851 base::MessageLoop::current()->Run(); |
| 852 |
| 853 // The timeout should have fired, synthetically ack'ing the timed-out event. |
| 854 // TouchEvent forwarding is disabled until the ack is received for the |
| 855 // timed-out event and the future cancel event. |
| 856 EXPECT_FALSE(IsTimeoutRunning()); |
| 857 EXPECT_FALSE(WillForwardTouchEvents()); |
| 858 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 859 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 860 |
| 861 // Ack'ing the original event should trigger a cancel event. |
| 862 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 863 EXPECT_FALSE(IsTimeoutRunning()); |
| 864 EXPECT_FALSE(WillForwardTouchEvents()); |
| 865 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 866 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 867 |
| 868 // Touch events should not be forwarded until we receive the cancel acks. |
| 869 PressTouchPoint(0, 1); |
| 870 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 871 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 872 |
| 873 // The synthetic TouchCancel ack should not reach the client, but should |
| 874 // resume touch forwarding. |
| 875 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 876 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 877 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 878 EXPECT_TRUE(WillForwardTouchEvents()); |
| 879 |
| 880 // Subsequent events should be handled normally. |
| 881 PressTouchPoint(0, 1); |
| 882 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 883 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 884 } |
| 885 |
| 886 // Tests that the timeout is never started if the renderer consumes |
| 887 // a TouchEvent from the current touch sequence. |
| 888 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { |
| 889 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 890 |
| 891 // Queue a TouchStart. |
| 892 PressTouchPoint(0, 1); |
| 893 ASSERT_TRUE(IsTimeoutRunning()); |
| 894 |
| 895 // Mark the event as consumed. This should prevent the timeout from |
| 896 // being activated on subsequent TouchEvents in this gesture. |
| 897 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 898 EXPECT_FALSE(IsTimeoutRunning()); |
| 899 |
| 900 // A TouchMove should not start the timeout. |
| 901 MoveTouchPoint(0, 5, 5); |
| 902 EXPECT_FALSE(IsTimeoutRunning()); |
| 903 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 904 |
| 905 // A TouchCancel should not start the timeout. |
| 906 CancelTouchPoint(0); |
| 907 EXPECT_FALSE(IsTimeoutRunning()); |
| 908 } |
| 909 |
| 910 // Tests that the timeout is never started if the ack is synchronous. |
| 911 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { |
| 912 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 913 |
| 914 // Queue a TouchStart. |
| 915 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 916 ASSERT_FALSE(IsTimeoutRunning()); |
| 917 PressTouchPoint(0, 1); |
| 918 EXPECT_FALSE(IsTimeoutRunning()); |
| 919 } |
| 920 |
| 921 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 922 // turns into a scroll gesture sequence. |
| 923 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { |
| 924 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 925 |
| 926 // Queue a TouchStart. |
| 927 PressTouchPoint(0, 1); |
| 928 EXPECT_TRUE(IsTimeoutRunning()); |
| 929 EXPECT_TRUE(WillForwardTouchEvents()); |
| 930 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 931 |
| 932 // The cancelled sequence may turn into a scroll gesture. |
| 933 WebGestureEvent followup_scroll; |
| 934 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 935 SetFollowupEvent(followup_scroll); |
| 936 |
| 937 // Delay the ack. |
| 938 base::MessageLoop::current()->PostDelayedTask( |
| 939 FROM_HERE, |
| 940 base::MessageLoop::QuitClosure(), |
| 941 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 942 base::MessageLoop::current()->Run(); |
| 943 |
| 944 // The timeout should have fired, disabling touch forwarding until both acks |
| 945 // are received, acking the timed out event. |
| 946 EXPECT_FALSE(IsTimeoutRunning()); |
| 947 EXPECT_FALSE(WillForwardTouchEvents()); |
| 948 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 949 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 950 |
| 951 // Ack the original event, triggering a TouchCancel. |
| 952 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 953 EXPECT_FALSE(IsTimeoutRunning()); |
| 954 EXPECT_FALSE(WillForwardTouchEvents()); |
| 955 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 956 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 957 |
| 958 // Ack the cancel event. Normally, this would resume touch forwarding, |
| 959 // but we're still within a scroll gesture so it remains disabled. |
| 960 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 961 EXPECT_FALSE(IsTimeoutRunning()); |
| 962 EXPECT_FALSE(WillForwardTouchEvents()); |
| 963 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 964 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 965 |
| 966 // Try to forward a touch event. |
| 967 GetAndResetSentEventCount(); |
| 968 GetAndResetAckedEventCount(); |
| 969 PressTouchPoint(0, 1); |
| 970 EXPECT_FALSE(IsTimeoutRunning()); |
| 971 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 972 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 973 |
| 974 // Now end the scroll sequence, resuming touch handling. |
| 975 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 976 EXPECT_TRUE(WillForwardTouchEvents()); |
| 977 PressTouchPoint(0, 1); |
| 978 EXPECT_TRUE(IsTimeoutRunning()); |
| 979 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 980 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 981 } |
| 982 |
| 983 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 984 // turns into a scroll gesture sequence, but the original event acks are |
| 985 // significantly delayed. |
| 986 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { |
| 987 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 988 |
| 989 // Queue a TouchStart. |
| 990 PressTouchPoint(0, 1); |
| 991 EXPECT_TRUE(IsTimeoutRunning()); |
| 992 EXPECT_TRUE(WillForwardTouchEvents()); |
| 993 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 994 |
| 995 // The cancelled sequence may turn into a scroll gesture. |
| 996 WebGestureEvent followup_scroll; |
| 997 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 998 SetFollowupEvent(followup_scroll); |
| 999 |
| 1000 // Delay the ack. |
| 1001 base::MessageLoop::current()->PostDelayedTask( |
| 1002 FROM_HERE, |
| 1003 base::MessageLoop::QuitClosure(), |
| 1004 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1005 base::MessageLoop::current()->Run(); |
| 1006 |
| 1007 // The timeout should have fired, disabling touch forwarding until both acks |
| 1008 // are received and acking the timed out event. |
| 1009 EXPECT_FALSE(IsTimeoutRunning()); |
| 1010 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1011 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1012 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1013 |
| 1014 // Try to forward a touch event. |
| 1015 GetAndResetSentEventCount(); |
| 1016 GetAndResetAckedEventCount(); |
| 1017 PressTouchPoint(0, 1); |
| 1018 EXPECT_FALSE(IsTimeoutRunning()); |
| 1019 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1020 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1021 |
| 1022 // Now end the scroll sequence. Events will not be forwarded until the two |
| 1023 // outstanding touch acks are received. |
| 1024 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1025 PressTouchPoint(0, 1); |
| 1026 EXPECT_FALSE(IsTimeoutRunning()); |
| 1027 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1028 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1029 |
| 1030 // Ack the original event, triggering a cancel. |
| 1031 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1032 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1033 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1034 |
| 1035 // Ack the cancel event, resuming touch forwarding. |
| 1036 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1037 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1038 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1039 |
| 1040 PressTouchPoint(0, 1); |
| 1041 EXPECT_TRUE(IsTimeoutRunning()); |
| 1042 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1043 } |
| 1044 |
| 1045 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if |
| 1046 // the timed-out event had no consumer. |
| 1047 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { |
| 1048 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1049 |
| 1050 // Queue a TouchStart. |
| 1051 PressTouchPoint(0, 1); |
| 1052 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1053 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1054 EXPECT_TRUE(IsTimeoutRunning()); |
| 1055 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1056 |
| 1057 // Delay the ack. |
| 1058 base::MessageLoop::current()->PostDelayedTask( |
| 1059 FROM_HERE, |
| 1060 base::MessageLoop::QuitClosure(), |
| 1061 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1062 base::MessageLoop::current()->Run(); |
| 1063 |
| 1064 // The timeout should have fired, synthetically ack'ing the timed out event. |
| 1065 // TouchEvent forwarding is disabled until the original ack is received. |
| 1066 EXPECT_FALSE(IsTimeoutRunning()); |
| 1067 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1068 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1069 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1070 |
| 1071 // Touch events should not be forwarded until we receive the original ack. |
| 1072 PressTouchPoint(0, 1); |
| 1073 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 1074 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1075 |
| 1076 // Ack'ing the original event should not trigger a cancel event, as the |
| 1077 // TouchStart had no consumer. However, it should re-enable touch forwarding. |
| 1078 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1079 EXPECT_FALSE(IsTimeoutRunning()); |
| 1080 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1081 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1082 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1083 |
| 1084 // Subsequent events should be handled normally. |
| 1085 PressTouchPoint(0, 1); |
| 1086 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1087 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1088 } |
839 } // namespace content | 1089 } // namespace content |
OLD | NEW |