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

Side by Side Diff: content/browser/renderer_host/input/touch_disposition_gesture_filter_unittest.cc

Issue 156783006: Consuming a touch move prevents only the next scroll update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke's comments. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "content/browser/renderer_host/input/touch_disposition_gesture_filter.h " 7 #include "content/browser/renderer_host/input/touch_disposition_gesture_filter.h "
8 #include "content/common/input/synthetic_web_input_event_builders.h" 8 #include "content/common/input/synthetic_web_input_event_builders.h"
9 #include "content/common/input/web_input_event_traits.h" 9 #include "content/common/input/web_input_event_traits.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 PushGesture(WebInputEvent::GestureScrollBegin); 204 PushGesture(WebInputEvent::GestureScrollBegin);
205 PressTouchPoint(1, 1); 205 PressTouchPoint(1, 1);
206 EXPECT_FALSE(GesturesSent()); 206 EXPECT_FALSE(GesturesSent());
207 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 207 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
208 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin), 208 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
209 GetAndResetSentGestures())); 209 GetAndResetSentGestures()));
210 210
211 // Multiple gestures can be queued for a single event. 211 // Multiple gestures can be queued for a single event.
212 PushGesture(WebInputEvent::GestureFlingStart); 212 PushGesture(WebInputEvent::GestureFlingStart);
213 PushGesture(WebInputEvent::GestureFlingCancel); 213 PushGesture(WebInputEvent::GestureFlingCancel);
214 MoveTouchPoint(0, 1, 1); 214 ReleaseTouchPoint(0);
215 EXPECT_FALSE(GesturesSent()); 215 EXPECT_FALSE(GesturesSent());
216 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 216 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
217 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, 217 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart,
218 WebInputEvent::GestureFlingCancel), 218 WebInputEvent::GestureFlingCancel),
219 GetAndResetSentGestures())); 219 GetAndResetSentGestures()));
220 }
220 221
222 TEST_F(TouchDispositionGestureFilterTest, BasicGesturesConsumed) {
221 // A consumed touch's gesture should not be sent. 223 // A consumed touch's gesture should not be sent.
224 PushGesture(WebInputEvent::GestureScrollBegin);
225 PressTouchPoint(1, 1);
226 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
227 EXPECT_FALSE(GesturesSent());
228
222 PushGesture(WebInputEvent::GestureFlingStart); 229 PushGesture(WebInputEvent::GestureFlingStart);
223 PushGesture(WebInputEvent::GestureFlingCancel); 230 PushGesture(WebInputEvent::GestureFlingCancel);
224 ReleaseTouchPoint(0); 231 ReleaseTouchPoint(0);
225 EXPECT_FALSE(GesturesSent());
226 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 232 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
227 EXPECT_FALSE(GesturesSent()); 233 EXPECT_FALSE(GesturesSent());
228 } 234 }
229 235
230 TEST_F(TouchDispositionGestureFilterTest, ConsumedThenNotConsumed) { 236 TEST_F(TouchDispositionGestureFilterTest, ConsumedThenNotConsumed) {
231 // A consumed touch's gesture should not be sent. 237 // A consumed touch's gesture should not be sent.
232 PushGesture(WebInputEvent::GestureScrollBegin); 238 PushGesture(WebInputEvent::GestureScrollBegin);
233 PressTouchPoint(1, 1); 239 PressTouchPoint(1, 1);
234 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 240 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
235 EXPECT_FALSE(GesturesSent()); 241 EXPECT_FALSE(GesturesSent());
236 242
237 // Even if the subsequent touch is not consumed, continue dropping gestures. 243 // Even if the subsequent touch is not consumed, continue dropping gestures.
238 PushGesture(WebInputEvent::GestureScrollUpdate); 244 PushGesture(WebInputEvent::GestureScrollUpdate);
239 MoveTouchPoint(0, 2, 2); 245 MoveTouchPoint(0, 2, 2);
240 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 246 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
241 EXPECT_FALSE(GesturesSent()); 247 EXPECT_FALSE(GesturesSent());
242 248
243 // Even if the subsequent touch had no consumer, continue dropping gestures. 249 // Even if the subsequent touch had no consumer, continue dropping gestures.
244 PushGesture(WebInputEvent::GestureFlingStart); 250 PushGesture(WebInputEvent::GestureFlingStart);
245 ReleaseTouchPoint(0); 251 ReleaseTouchPoint(0);
246 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 252 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
jdduke (slow) 2014/02/13 19:40:00 Why this change?
tdresser 2014/02/13 20:34:31 It must have made sense to me at one point, but it
247 EXPECT_FALSE(GesturesSent()); 253 EXPECT_FALSE(GesturesSent());
248 } 254 }
249 255
256 TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenConsumed) {
257 // A not consumed touch's gesture should be sent.
258 PushGesture(WebInputEvent::GestureScrollBegin);
259 PressTouchPoint(1, 1);
260 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
261 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
262 GetAndResetSentGestures()));
263
264 // A newly consumed gesture should not be sent.
265 PushGesture(WebInputEvent::GesturePinchBegin);
266 PressTouchPoint(10, 10);
267 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
268 EXPECT_FALSE(GesturesSent());
269
270 // And subsequent non-consumed pinch updates should not be sent.
271 PushGesture(WebInputEvent::GestureScrollUpdate);
272 PushGesture(WebInputEvent::GesturePinchUpdate);
273 MoveTouchPoint(0, 2, 2);
274 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
275 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
276 GetAndResetSentGestures()));
277
278 // End events dispatched only when their start events were.
279 PushGesture(WebInputEvent::GesturePinchEnd);
280 ReleaseTouchPoint(1);
281 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
282 EXPECT_FALSE(GesturesSent());
283
284 PushGesture(WebInputEvent::GestureScrollEnd);
285 ReleaseTouchPoint(0);
286 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
287 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
288 GetAndResetSentGestures()));
289 }
290
291 TEST_F(TouchDispositionGestureFilterTest, ScrollAlternatelyConsumed) {
292 // A consumed touch's gesture should not be sent.
293 PushGesture(WebInputEvent::GestureScrollBegin);
294 PressTouchPoint(1, 1);
295 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
296 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
297 GetAndResetSentGestures()));
298
299 for (size_t i = 0; i < 3; ++i) {
300 PushGesture(WebInputEvent::GestureScrollUpdate);
jdduke (slow) 2014/02/13 19:40:00 Nice.
301 MoveTouchPoint(0, 2, 2);
302 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
303 EXPECT_FALSE(GesturesSent());
304
305 PushGesture(WebInputEvent::GestureScrollUpdate);
306 MoveTouchPoint(0, 3, 3);
307 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
308 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
309 GetAndResetSentGestures()));
310 }
jdduke (slow) 2014/02/13 19:40:00 For completeness, could we add a final TouchEnd an
tdresser 2014/02/13 20:34:31 Done.
311 }
312
250 TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenNoConsumer) { 313 TEST_F(TouchDispositionGestureFilterTest, NotConsumedThenNoConsumer) {
251 // An unconsumed touch's gesture should be sent. 314 // An unconsumed touch's gesture should be sent.
252 PushGesture(WebInputEvent::GestureScrollBegin); 315 PushGesture(WebInputEvent::GestureScrollBegin);
253 PressTouchPoint(1, 1); 316 PressTouchPoint(1, 1);
254 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 317 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
255 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin), 318 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
256 GetAndResetSentGestures())); 319 GetAndResetSentGestures()));
257 320
258 // If the subsequent touch has no consumer (e.g., a secondary pointer is 321 // If the subsequent touch has no consumer (e.g., a secondary pointer is
259 // pressed but not on a touch handling rect), send the gesture. 322 // pressed but not on a touch handling rect), send the gesture.
260 PushGesture(WebInputEvent::GesturePinchBegin); 323 PushGesture(WebInputEvent::GesturePinchBegin);
261 PressTouchPoint(2, 2); 324 PressTouchPoint(2, 2);
262 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 325 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
263 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin), 326 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
264 GetAndResetSentGestures())); 327 GetAndResetSentGestures()));
265 328
266 // If the subsequent touch is consumed, then the remaining gesture sequence 329 // End events should be dispatched when their start events were, independent
267 // should be dropped, regardless of subsequent touch ack disposition. 330 // of the ack state.
331 PushGesture(WebInputEvent::GesturePinchEnd);
332 ReleaseTouchPoint(1);
333 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
334 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
335 GetAndResetSentGestures()));
336
337 PushGesture(WebInputEvent::GestureScrollEnd);
338 ReleaseTouchPoint(0);
339 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
340 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
341 GetAndResetSentGestures()));
342 }
343
344 TEST_F(TouchDispositionGestureFilterTest, EndingEventsSent) {
345 PushGesture(WebInputEvent::GestureScrollBegin);
346 PressTouchPoint(1, 1);
347 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
348 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
349 GetAndResetSentGestures()));
350
351 PushGesture(WebInputEvent::GesturePinchBegin);
352 PressTouchPoint(2, 2);
353 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
354 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
355 GetAndResetSentGestures()));
356
357 // Consuming the touchend event can't suppress the match end gesture.
358 PushGesture(WebInputEvent::GesturePinchEnd);
359 ReleaseTouchPoint(1);
360 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
361 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
362 GetAndResetSentGestures()));
363
364 // But other events in the same packet are still suppressed.
268 PushGesture(WebInputEvent::GestureScrollUpdate); 365 PushGesture(WebInputEvent::GestureScrollUpdate);
269 PushGesture(WebInputEvent::GesturePinchUpdate); 366 PushGesture(WebInputEvent::GestureScrollEnd);
367 ReleaseTouchPoint(0);
368 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
369 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
370 GetAndResetSentGestures()));
371
372 // GestureScrollEnd and GestureFlingStart behave the same in this regard.
373 PushGesture(WebInputEvent::GestureScrollBegin);
374 PressTouchPoint(1, 1);
375 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
376 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
377 GetAndResetSentGestures()));
378
379 PushGesture(WebInputEvent::GestureFlingStart);
380 ReleaseTouchPoint(0);
381 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
382 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart),
383 GetAndResetSentGestures()));
384 }
385
386 TEST_F(TouchDispositionGestureFilterTest, EndingEventsNotSent) {
387 // Consuming a begin event ensures no end events are sent.
388 PushGesture(WebInputEvent::GestureScrollBegin);
389 PressTouchPoint(1, 1);
390 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
391 EXPECT_FALSE(GesturesSent());
392
393 PushGesture(WebInputEvent::GesturePinchBegin);
394 PressTouchPoint(2, 2);
395 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
396 EXPECT_FALSE(GesturesSent());
397
398 PushGesture(WebInputEvent::GesturePinchEnd);
399 ReleaseTouchPoint(1);
400 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
401 EXPECT_FALSE(GesturesSent());
402
403 PushGesture(WebInputEvent::GestureScrollEnd);
404 ReleaseTouchPoint(0);
405 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
406 EXPECT_FALSE(GesturesSent());
407 }
408
409 TEST_F(TouchDispositionGestureFilterTest, UpdateEventsSuppressedPerEvent) {
410 PushGesture(WebInputEvent::GestureScrollBegin);
411 PressTouchPoint(1, 1);
412 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
413 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
414 GetAndResetSentGestures()));
415
416 // Consuming a single scroll or pinch update should suppress only that event.
417 PushGesture(WebInputEvent::GestureScrollUpdate);
270 MoveTouchPoint(0, 2, 2); 418 MoveTouchPoint(0, 2, 2);
271 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 419 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
272 EXPECT_FALSE(GesturesSent()); 420 EXPECT_FALSE(GesturesSent());
273 421
422 PushGesture(WebInputEvent::GesturePinchBegin);
423 PressTouchPoint(2, 2);
424 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
425 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin),
426 GetAndResetSentGestures()));
427
428 PushGesture(WebInputEvent::GesturePinchUpdate);
429 MoveTouchPoint(1, 2, 3);
430 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
431 EXPECT_FALSE(GesturesSent());
432
433 // Subsequent updates should not be affected.
434 PushGesture(WebInputEvent::GestureScrollUpdate);
435 MoveTouchPoint(0, 4, 4);
436 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
437 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollUpdate),
438 GetAndResetSentGestures()));
439
440 PushGesture(WebInputEvent::GesturePinchUpdate);
441 MoveTouchPoint(0, 4, 5);
442 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
443 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchUpdate),
444 GetAndResetSentGestures()));
445
446 PushGesture(WebInputEvent::GesturePinchEnd);
447 ReleaseTouchPoint(1);
448 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
449 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchEnd),
450 GetAndResetSentGestures()));
451
452 PushGesture(WebInputEvent::GestureScrollEnd);
453 ReleaseTouchPoint(0);
454 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
455 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollEnd),
456 GetAndResetSentGestures()));
457 }
458
459 TEST_F(TouchDispositionGestureFilterTest, UpdateEventsDependOnBeginEvents) {
460 PushGesture(WebInputEvent::GestureScrollBegin);
461 PressTouchPoint(1, 1);
462 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
463 EXPECT_FALSE(GesturesSent());
464
465 // Independent packets are never sent when the global state is to drop.
466 PushGesture(WebInputEvent::GestureScrollUpdate);
467 MoveTouchPoint(0, 2, 2);
468 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
469 EXPECT_FALSE(GesturesSent());
470
471 PushGesture(WebInputEvent::GesturePinchBegin);
472 PressTouchPoint(2, 2);
473 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
474 EXPECT_FALSE(GesturesSent());
475
476 PushGesture(WebInputEvent::GesturePinchUpdate);
477 MoveTouchPoint(1, 2, 3);
478 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
479 EXPECT_FALSE(GesturesSent());
480
274 PushGesture(WebInputEvent::GesturePinchEnd); 481 PushGesture(WebInputEvent::GesturePinchEnd);
275 ReleaseTouchPoint(1); 482 ReleaseTouchPoint(1);
276 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 483 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
277 EXPECT_FALSE(GesturesSent()); 484 EXPECT_FALSE(GesturesSent());
278 485
279 PushGesture(WebInputEvent::GestureScrollEnd); 486 PushGesture(WebInputEvent::GestureScrollEnd);
280 ReleaseTouchPoint(0); 487 ReleaseTouchPoint(0);
281 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 488 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
282 EXPECT_FALSE(GesturesSent()); 489 EXPECT_FALSE(GesturesSent());
283 } 490 }
284 491
285 TEST_F(TouchDispositionGestureFilterTest, MultipleTouchSequences) { 492 TEST_F(TouchDispositionGestureFilterTest, MultipleTouchSequences) {
286 // Queue two touch-to-gestures sequences. 493 // Queue two touch-to-gestures sequences.
287 PushGesture(WebInputEvent::GestureFlingStart); 494 PushGesture(WebInputEvent::GestureTapDown);
288 PressTouchPoint(1, 1); 495 PressTouchPoint(1, 1);
289 PushGesture(WebInputEvent::GestureFlingCancel); 496 PushGesture(WebInputEvent::GestureTap);
290 ReleaseTouchPoint(0); 497 ReleaseTouchPoint(0);
291 PushGesture(WebInputEvent::GestureFlingStart); 498 PushGesture(WebInputEvent::GestureScrollBegin);
292 PressTouchPoint(1, 1); 499 PressTouchPoint(1, 1);
293 PushGesture(WebInputEvent::GestureFlingCancel); 500 PushGesture(WebInputEvent::GestureScrollEnd);
294 ReleaseTouchPoint(0); 501 ReleaseTouchPoint(0);
295 502
296 // The first gesture sequence should not be allowed. 503 // The first gesture sequence should not be allowed.
297 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 504 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
298 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 505 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
299 EXPECT_FALSE(GesturesSent()); 506 EXPECT_FALSE(GesturesSent());
300 507
301 // The subsequent sequence should "reset" allowance. 508 // The subsequent sequence should "reset" allowance.
302 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 509 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
303 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 510 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
304 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, 511 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
305 WebInputEvent::GestureFlingCancel), 512 WebInputEvent::GestureScrollEnd),
306 GetAndResetSentGestures())); 513 GetAndResetSentGestures()));
307 } 514 }
308 515
309 TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) { 516 TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) {
310 // Simulate a fling. 517 // Simulate a fling.
518 PushGesture(WebInputEvent::GestureScrollBegin);
311 PressTouchPoint(1, 1); 519 PressTouchPoint(1, 1);
312 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 520 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
521 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin),
522 GetAndResetSentGestures()));
313 PushGesture(WebInputEvent::GestureFlingStart); 523 PushGesture(WebInputEvent::GestureFlingStart);
314 ReleaseTouchPoint(0); 524 ReleaseTouchPoint(0);
315 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 525 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
316 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart), 526 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart),
317 GetAndResetSentGestures())); 527 GetAndResetSentGestures()));
318 528
319 // A new touch seqeuence should cancel the outstanding fling. 529 // A new touch seqeuence should cancel the outstanding fling.
320 PressTouchPoint(1, 1); 530 PressTouchPoint(1, 1);
321 ReleaseTouchPoint(0);
322 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 531 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
323 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel), 532 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel),
324 GetAndResetSentGestures())); 533 GetAndResetSentGestures()));
534 ReleaseTouchPoint(0);
535 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
536 EXPECT_FALSE(GesturesSent());
325 } 537 }
326 538
327 TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnScrollBegin) { 539 TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnScrollBegin) {
328 // Simulate a fling sequence. 540 // Simulate a fling sequence.
329 PushGesture(WebInputEvent::GestureScrollBegin); 541 PushGesture(WebInputEvent::GestureScrollBegin);
330 PushGesture(WebInputEvent::GestureFlingStart); 542 PushGesture(WebInputEvent::GestureFlingStart);
331 PressTouchPoint(1, 1); 543 PressTouchPoint(1, 1);
332 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 544 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
333 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin, 545 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
334 WebInputEvent::GestureFlingStart), 546 WebInputEvent::GestureFlingStart),
335 GetAndResetSentGestures())); 547 GetAndResetSentGestures()));
336 548
337 // The new fling should cancel the preceding one. 549 // The new fling should cancel the preceding one.
338 PushGesture(WebInputEvent::GestureScrollBegin); 550 PushGesture(WebInputEvent::GestureScrollBegin);
339 PushGesture(WebInputEvent::GestureFlingStart); 551 PushGesture(WebInputEvent::GestureFlingStart);
340 ReleaseTouchPoint(0); 552 ReleaseTouchPoint(0);
341 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 553 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
342 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel, 554 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel,
343 WebInputEvent::GestureScrollBegin, 555 WebInputEvent::GestureScrollBegin,
344 WebInputEvent::GestureFlingStart), 556 WebInputEvent::GestureFlingStart),
345 GetAndResetSentGestures())); 557 GetAndResetSentGestures()));
346 } 558 }
347 559
348 TEST_F(TouchDispositionGestureFilterTest, FlingNotCancelledIfGFCEventReceived) { 560 TEST_F(TouchDispositionGestureFilterTest, FlingNotCancelledIfGFCEventReceived) {
349 // Simulate a fling that is started then cancelled. 561 // Simulate a fling that is started then cancelled.
562 PushGesture(WebInputEvent::GestureScrollBegin);
563 PressTouchPoint(1, 1);
564 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
350 PushGesture(WebInputEvent::GestureFlingStart); 565 PushGesture(WebInputEvent::GestureFlingStart);
351 PressTouchPoint(1, 1); 566 MoveTouchPoint(0, 1, 1);
352 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 567 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
353 PushGesture(WebInputEvent::GestureFlingCancel); 568 PushGesture(WebInputEvent::GestureFlingCancel);
354 ReleaseTouchPoint(0); 569 ReleaseTouchPoint(0);
355 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 570 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
356 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, 571 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
572 WebInputEvent::GestureFlingStart,
357 WebInputEvent::GestureFlingCancel), 573 WebInputEvent::GestureFlingCancel),
358 GetAndResetSentGestures())); 574 GetAndResetSentGestures()));
359 575
360 // A new touch sequence will not inject a GestureFlingCancel, as the fling 576 // A new touch sequence will not inject a GestureFlingCancel, as the fling
361 // has already been cancelled. 577 // has already been cancelled.
362 PressTouchPoint(1, 1); 578 PressTouchPoint(1, 1);
579 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
363 ReleaseTouchPoint(0); 580 ReleaseTouchPoint(0);
364 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 581 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
365 EXPECT_FALSE(GesturesSent()); 582 EXPECT_FALSE(GesturesSent());
366 } 583 }
367 584
368 TEST_F(TouchDispositionGestureFilterTest, TapCancelledWhenScrollBegins) { 585 TEST_F(TouchDispositionGestureFilterTest, TapCancelledWhenScrollBegins) {
369 PushGesture(WebInputEvent::GestureTapDown); 586 PushGesture(WebInputEvent::GestureTapDown);
370 PressTouchPoint(1, 1); 587 PressTouchPoint(1, 1);
371 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 588 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
372 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown), 589 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 678 }
462 679
463 TEST_F(TouchDispositionGestureFilterTest, SpuriousAcksIgnored) { 680 TEST_F(TouchDispositionGestureFilterTest, SpuriousAcksIgnored) {
464 // Acks received when the queue is empty will be safely ignored. 681 // Acks received when the queue is empty will be safely ignored.
465 ASSERT_TRUE(IsEmpty()); 682 ASSERT_TRUE(IsEmpty());
466 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 683 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
467 EXPECT_FALSE(GesturesSent()); 684 EXPECT_FALSE(GesturesSent());
468 685
469 PushGesture(WebInputEvent::GestureScrollBegin); 686 PushGesture(WebInputEvent::GestureScrollBegin);
470 PressTouchPoint(1, 1); 687 PressTouchPoint(1, 1);
471 PushGesture(WebInputEvent::GestureScrollEnd); 688 PushGesture(WebInputEvent::GestureScrollUpdate);
472 ReleaseTouchPoint(0); 689 MoveTouchPoint(0, 3,3);
473 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 690 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
474 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 691 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
475 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin, 692 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin,
476 WebInputEvent::GestureScrollEnd), 693 WebInputEvent::GestureScrollUpdate),
477 GetAndResetSentGestures())); 694 GetAndResetSentGestures()));
478 695
479 // Even if all packets have been dispatched, the filter may not be empty as 696 // Even if all packets have been dispatched, the filter may not be empty as
480 // there could be follow-up timeout events. Spurious acks in such cases 697 // there could be follow-up timeout events. Spurious acks in such cases
481 // should also be safely ignored. 698 // should also be safely ignored.
482 ASSERT_FALSE(IsEmpty()); 699 ASSERT_FALSE(IsEmpty());
483 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); 700 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
484 EXPECT_FALSE(GesturesSent()); 701 EXPECT_FALSE(GesturesSent());
485 } 702 }
486 703
(...skipping 10 matching lines...) Expand all
497 EXPECT_TRUE(IsEmpty()); 714 EXPECT_TRUE(IsEmpty());
498 715
499 WebTouchEvent touch; 716 WebTouchEvent touch;
500 touch.type = WebInputEvent::TouchCancel; 717 touch.type = WebInputEvent::TouchCancel;
501 EXPECT_EQ(TouchDispositionGestureFilter::INVALID_PACKET_ORDER, 718 EXPECT_EQ(TouchDispositionGestureFilter::INVALID_PACKET_ORDER,
502 SendTouchGestures(WebInputEvent::GestureShowPress, 719 SendTouchGestures(WebInputEvent::GestureShowPress,
503 GestureEventPacket())); 720 GestureEventPacket()));
504 EXPECT_TRUE(IsEmpty()); 721 EXPECT_TRUE(IsEmpty());
505 } 722 }
506 723
724 TEST_F(TouchDispositionGestureFilterTest, ConsumedTouchCancel) {
725 // An unconsumed touch's gesture should be sent.
726 PushGesture(WebInputEvent::GestureTapDown);
727 PressTouchPoint(1, 1);
728 EXPECT_FALSE(GesturesSent());
729 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
730 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown),
731 GetAndResetSentGestures()));
732
733 PushGesture(WebInputEvent::GestureTapCancel);
734 PushGesture(WebInputEvent::GestureScrollEnd);
735 CancelTouchPoint(0);
736 EXPECT_FALSE(GesturesSent());
737 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
738 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapCancel,
739 WebInputEvent::GestureScrollEnd),
740 GetAndResetSentGestures()));
741 }
742
743 TEST_F(TouchDispositionGestureFilterTest, TimeoutEventAfterRelease) {
jdduke (slow) 2014/02/13 19:40:00 Awesome, thanks!
744 PressTouchPoint(1, 1);
745 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
746 EXPECT_FALSE(GesturesSent());
747 PushGesture(WebInputEvent::GestureTapUnconfirmed);
748 ReleaseTouchPoint(0);
749 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
750 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapUnconfirmed),
751 GetAndResetSentGestures()));
752
753 SendTimeoutGesture(WebInputEvent::GestureTap);
754 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTap),
755 GetAndResetSentGestures()));
756 }
757
507 } // namespace content 758 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698