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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/logging.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"
10 #include "content/browser/renderer_host/input/touch_event_queue.h"
11 #include "content/common/input/synthetic_web_input_event_builders.h"
12 #include "content/common/input/web_touch_event_traits.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 using blink::WebGestureEvent
;
17 using blink::WebInputEvent
;
18 using blink::WebTouchEvent
;
19 using blink::WebTouchPoint
;
24 const double kMinSecondsBetweenThrottledTouchmoves
= 0.2;
25 const float kSlopLengthDips
= 10;
26 const float kHalfSlopLengthDips
= kSlopLengthDips
/ 2;
28 base::TimeDelta
DefaultTouchTimeoutDelay() {
29 return base::TimeDelta::FromMilliseconds(1);
33 class TouchEventQueueTest
: public testing::Test
,
34 public TouchEventQueueClient
{
37 : sent_event_count_(0),
38 acked_event_count_(0),
39 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN
),
40 slop_length_dips_(0) {}
42 ~TouchEventQueueTest() override
{}
45 void SetUp() override
{
46 ResetQueueWithConfig(TouchEventQueue::Config());
49 void TearDown() override
{ queue_
.reset(); }
51 // TouchEventQueueClient
52 void SendTouchEventImmediately(
53 const TouchEventWithLatencyInfo
& event
) override
{
55 last_sent_event_
= event
.event
;
56 if (sync_ack_result_
) {
57 auto sync_ack_result
= sync_ack_result_
.Pass();
58 SendTouchEventAck(*sync_ack_result
);
62 void OnTouchEventAck(const TouchEventWithLatencyInfo
& event
,
63 InputEventAckState ack_result
) override
{
65 last_acked_event_
= event
.event
;
66 last_acked_event_state_
= ack_result
;
67 if (followup_touch_event_
) {
68 scoped_ptr
<WebTouchEvent
> followup_touch_event
=
69 followup_touch_event_
.Pass();
70 SendTouchEvent(*followup_touch_event
);
72 if (followup_gesture_event_
) {
73 scoped_ptr
<WebGestureEvent
> followup_gesture_event
=
74 followup_gesture_event_
.Pass();
75 queue_
->OnGestureScrollEvent(
76 GestureEventWithLatencyInfo(*followup_gesture_event
,
82 void SetUpForTouchMoveSlopTesting(double slop_length_dips
) {
83 slop_length_dips_
= slop_length_dips
;
86 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay
) {
87 TouchEventQueue::Config config
;
88 config
.touch_ack_timeout_delay
= timeout_delay
;
89 config
.touch_ack_timeout_supported
= true;
90 ResetQueueWithConfig(config
);
93 void SendTouchEvent(WebTouchEvent event
) {
94 if (slop_length_dips_
) {
95 event
.causesScrollingIfUncanceled
= false;
96 if (WebTouchEventTraits::IsTouchSequenceStart(event
))
97 anchor_
= event
.touches
[0].position
;
98 if (event
.type
== WebInputEvent::TouchMove
) {
99 gfx::Vector2dF delta
= anchor_
- event
.touches
[0].position
;
100 if (delta
.LengthSquared() > slop_length_dips_
* slop_length_dips_
)
101 event
.causesScrollingIfUncanceled
= true;
104 event
.causesScrollingIfUncanceled
=
105 event
.type
== WebInputEvent::TouchMove
;
107 queue_
->QueueEvent(TouchEventWithLatencyInfo(event
, ui::LatencyInfo()));
110 void SendGestureEvent(WebInputEvent::Type type
) {
111 WebGestureEvent event
;
113 queue_
->OnGestureScrollEvent(
114 GestureEventWithLatencyInfo(event
, ui::LatencyInfo()));
117 void SendTouchEventAck(InputEventAckState ack_result
) {
118 queue_
->ProcessTouchAck(ack_result
, ui::LatencyInfo());
121 void SendGestureEventAck(WebInputEvent::Type type
,
122 InputEventAckState ack_result
) {
123 blink::WebGestureEvent gesture_event
;
124 gesture_event
.type
= type
;
125 GestureEventWithLatencyInfo
event(gesture_event
, ui::LatencyInfo());
126 queue_
->OnGestureEventAck(event
, ack_result
);
129 void SetFollowupEvent(const WebTouchEvent
& event
) {
130 followup_touch_event_
.reset(new WebTouchEvent(event
));
133 void SetFollowupEvent(const WebGestureEvent
& event
) {
134 followup_gesture_event_
.reset(new WebGestureEvent(event
));
137 void SetSyncAckResult(InputEventAckState sync_ack_result
) {
138 sync_ack_result_
.reset(new InputEventAckState(sync_ack_result
));
141 void PressTouchPoint(float x
, float y
) {
142 touch_event_
.PressPoint(x
, y
);
146 void MoveTouchPoint(int index
, float x
, float y
) {
147 touch_event_
.MovePoint(index
, x
, y
);
151 void MoveTouchPoints(int index0
,
157 touch_event_
.MovePoint(index0
, x0
, y0
);
158 touch_event_
.MovePoint(index1
, x1
, y1
);
162 void ChangeTouchPointRadius(int index
, float radius_x
, float radius_y
) {
164 CHECK_LT(index
, touch_event_
.touchesLengthCap
);
165 WebTouchPoint
& point
= touch_event_
.touches
[index
];
166 point
.radiusX
= radius_x
;
167 point
.radiusY
= radius_y
;
168 touch_event_
.touches
[index
].state
= WebTouchPoint::StateMoved
;
169 touch_event_
.causesScrollingIfUncanceled
= true;
170 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove
,
171 touch_event_
.timeStampSeconds
,
176 void ChangeTouchPointRotationAngle(int index
, float rotation_angle
) {
178 CHECK_LT(index
, touch_event_
.touchesLengthCap
);
179 WebTouchPoint
& point
= touch_event_
.touches
[index
];
180 point
.rotationAngle
= rotation_angle
;
181 touch_event_
.touches
[index
].state
= WebTouchPoint::StateMoved
;
182 touch_event_
.causesScrollingIfUncanceled
= true;
183 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove
,
184 touch_event_
.timeStampSeconds
,
189 void ChangeTouchPointForce(int index
, float force
) {
191 CHECK_LT(index
, touch_event_
.touchesLengthCap
);
192 WebTouchPoint
& point
= touch_event_
.touches
[index
];
194 touch_event_
.touches
[index
].state
= WebTouchPoint::StateMoved
;
195 touch_event_
.causesScrollingIfUncanceled
= true;
196 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove
,
197 touch_event_
.timeStampSeconds
,
202 void ReleaseTouchPoint(int index
) {
203 touch_event_
.ReleasePoint(index
);
207 void CancelTouchPoint(int index
) {
208 touch_event_
.CancelPoint(index
);
212 void AdvanceTouchTime(double seconds
) {
213 touch_event_
.timeStampSeconds
+= seconds
;
216 void ResetTouchEvent() {
217 touch_event_
= SyntheticWebTouchEvent();
220 size_t GetAndResetAckedEventCount() {
221 size_t count
= acked_event_count_
;
222 acked_event_count_
= 0;
226 size_t GetAndResetSentEventCount() {
227 size_t count
= sent_event_count_
;
228 sent_event_count_
= 0;
232 bool IsPendingAckTouchStart() const {
233 return queue_
->IsPendingAckTouchStart();
236 void OnHasTouchEventHandlers(bool has_handlers
) {
237 queue_
->OnHasTouchEventHandlers(has_handlers
);
240 void SetAckTimeoutDisabled() { queue_
->SetAckTimeoutEnabled(false); }
242 bool IsTimeoutRunning() const { return queue_
->IsTimeoutRunningForTesting(); }
244 bool HasPendingAsyncTouchMove() const {
245 return queue_
->HasPendingAsyncTouchMoveForTesting();
248 size_t queued_event_count() const {
249 return queue_
->size();
252 const WebTouchEvent
& latest_event() const {
253 return queue_
->GetLatestEventForTesting().event
;
256 const WebTouchEvent
& acked_event() const {
257 return last_acked_event_
;
260 const WebTouchEvent
& sent_event() const {
261 return last_sent_event_
;
264 InputEventAckState
acked_event_state() const {
265 return last_acked_event_state_
;
268 static void RunTasksAndWait(base::TimeDelta delay
) {
269 base::MessageLoop::current()->PostDelayedTask(
270 FROM_HERE
, base::MessageLoop::QuitClosure(), delay
);
271 base::MessageLoop::current()->Run();
275 void SendTouchEvent() {
276 SendTouchEvent(touch_event_
);
277 touch_event_
.ResetPoints();
280 void ResetQueueWithConfig(const TouchEventQueue::Config
& config
) {
281 queue_
.reset(new TouchEventQueue(this, config
));
282 queue_
->OnHasTouchEventHandlers(true);
285 scoped_ptr
<TouchEventQueue
> queue_
;
286 size_t sent_event_count_
;
287 size_t acked_event_count_
;
288 WebTouchEvent last_sent_event_
;
289 WebTouchEvent last_acked_event_
;
290 InputEventAckState last_acked_event_state_
;
291 SyntheticWebTouchEvent touch_event_
;
292 scoped_ptr
<WebTouchEvent
> followup_touch_event_
;
293 scoped_ptr
<WebGestureEvent
> followup_gesture_event_
;
294 scoped_ptr
<InputEventAckState
> sync_ack_result_
;
295 double slop_length_dips_
;
297 base::MessageLoopForUI message_loop_
;
301 // Tests that touch-events are queued properly.
302 TEST_F(TouchEventQueueTest
, Basic
) {
303 PressTouchPoint(1, 1);
304 EXPECT_EQ(1U, queued_event_count());
305 EXPECT_EQ(1U, GetAndResetSentEventCount());
307 // The second touch should not be sent since one is already in queue.
308 MoveTouchPoint(0, 5, 5);
309 EXPECT_EQ(2U, queued_event_count());
310 EXPECT_EQ(0U, GetAndResetSentEventCount());
312 // Receive an ACK for the first touch-event.
313 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
314 EXPECT_EQ(1U, queued_event_count());
315 EXPECT_EQ(1U, GetAndResetSentEventCount());
316 EXPECT_EQ(1U, GetAndResetAckedEventCount());
317 EXPECT_EQ(WebInputEvent::TouchStart
, acked_event().type
);
318 EXPECT_TRUE(acked_event().cancelable
);
320 // Receive an ACK for the second touch-event.
321 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
322 EXPECT_EQ(0U, queued_event_count());
323 EXPECT_EQ(0U, GetAndResetSentEventCount());
324 EXPECT_EQ(1U, GetAndResetAckedEventCount());
325 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
326 EXPECT_TRUE(acked_event().cancelable
);
329 // Tests that touch-events with multiple points are queued properly.
330 TEST_F(TouchEventQueueTest
, BasicMultiTouch
) {
331 const size_t kPointerCount
= 10;
332 for (float i
= 0; i
< kPointerCount
; ++i
)
333 PressTouchPoint(i
, i
);
335 EXPECT_EQ(1U, GetAndResetSentEventCount());
336 EXPECT_EQ(0U, GetAndResetAckedEventCount());
337 EXPECT_EQ(kPointerCount
, queued_event_count());
339 for (int i
= 0; i
< static_cast<int>(kPointerCount
); ++i
)
340 MoveTouchPoint(i
, 1.f
+ i
, 2.f
+ i
);
342 EXPECT_EQ(0U, GetAndResetSentEventCount());
343 EXPECT_EQ(0U, GetAndResetAckedEventCount());
344 // All moves should coalesce.
345 EXPECT_EQ(kPointerCount
+ 1, queued_event_count());
347 for (int i
= 0; i
< static_cast<int>(kPointerCount
); ++i
)
348 ReleaseTouchPoint(kPointerCount
- 1 - i
);
350 EXPECT_EQ(0U, GetAndResetSentEventCount());
351 EXPECT_EQ(0U, GetAndResetAckedEventCount());
352 EXPECT_EQ(kPointerCount
* 2 + 1, queued_event_count());
355 for (size_t i
= 0; i
< kPointerCount
; ++i
)
356 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
358 EXPECT_EQ(kPointerCount
, GetAndResetAckedEventCount());
359 EXPECT_EQ(kPointerCount
, GetAndResetSentEventCount());
361 // Ack the coalesced move.
362 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
363 EXPECT_EQ(kPointerCount
, GetAndResetAckedEventCount());
364 EXPECT_EQ(1U, GetAndResetSentEventCount());
367 for (size_t i
= 0; i
< kPointerCount
; ++i
)
368 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
370 EXPECT_EQ(kPointerCount
, GetAndResetAckedEventCount());
371 EXPECT_EQ(kPointerCount
- 1, GetAndResetSentEventCount());
374 // Tests that the touch-queue continues delivering events for an active touch
375 // sequence after all handlers are removed.
376 TEST_F(TouchEventQueueTest
, TouchesForwardedIfHandlerRemovedDuringSequence
) {
377 OnHasTouchEventHandlers(true);
378 EXPECT_EQ(0U, queued_event_count());
379 EXPECT_EQ(0U, GetAndResetSentEventCount());
381 // Send a touch-press event.
382 PressTouchPoint(1, 1);
383 EXPECT_EQ(1U, GetAndResetSentEventCount());
384 EXPECT_EQ(1U, queued_event_count());
386 // Signal that all touch handlers have been removed.
387 OnHasTouchEventHandlers(false);
388 EXPECT_EQ(0U, GetAndResetAckedEventCount());
389 EXPECT_EQ(1U, queued_event_count());
391 // Process the ack for the sent touch, ensuring that it is honored (despite
392 // the touch handler having been removed).
393 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
394 EXPECT_EQ(1U, GetAndResetAckedEventCount());
395 EXPECT_EQ(0U, queued_event_count());
396 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, acked_event_state());
398 // Try forwarding a new pointer. It should be forwarded as usual.
399 PressTouchPoint(2, 2);
400 EXPECT_EQ(1U, GetAndResetSentEventCount());
401 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
402 EXPECT_EQ(1U, GetAndResetAckedEventCount());
403 EXPECT_EQ(0U, queued_event_count());
405 // Further events for any pointer should be forwarded, even for pointers that
406 // reported no consumer.
407 MoveTouchPoint(1, 3, 3);
408 ReleaseTouchPoint(1);
409 EXPECT_EQ(1U, GetAndResetSentEventCount());
410 EXPECT_EQ(0U, GetAndResetAckedEventCount());
411 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
412 EXPECT_EQ(1U, GetAndResetSentEventCount());
413 EXPECT_EQ(1U, GetAndResetAckedEventCount());
414 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
415 EXPECT_EQ(0U, GetAndResetSentEventCount());
416 EXPECT_EQ(1U, GetAndResetAckedEventCount());
418 // Events for the first pointer, that had a handler, should be forwarded.
419 MoveTouchPoint(0, 4, 4);
420 ReleaseTouchPoint(0);
421 EXPECT_EQ(1U, GetAndResetSentEventCount());
422 EXPECT_EQ(2U, queued_event_count());
424 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
425 EXPECT_EQ(1U, GetAndResetAckedEventCount());
426 EXPECT_EQ(1U, GetAndResetSentEventCount());
427 EXPECT_EQ(1U, queued_event_count());
428 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, acked_event_state());
430 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
431 EXPECT_EQ(1U, GetAndResetAckedEventCount());
432 EXPECT_EQ(0U, GetAndResetSentEventCount());
433 EXPECT_EQ(0U, queued_event_count());
434 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, acked_event_state());
437 // Tests that addition of a touch handler during a touch sequence will not cause
438 // the remaining sequence to be forwarded.
439 TEST_F(TouchEventQueueTest
, ActiveSequenceNotForwardedWhenHandlersAdded
) {
440 OnHasTouchEventHandlers(false);
442 // Send a touch-press event while there is no handler.
443 PressTouchPoint(1, 1);
444 EXPECT_EQ(1U, GetAndResetAckedEventCount());
445 EXPECT_EQ(0U, GetAndResetSentEventCount());
446 EXPECT_EQ(0U, queued_event_count());
448 OnHasTouchEventHandlers(true);
450 // The remaining touch sequence should not be forwarded.
451 MoveTouchPoint(0, 5, 5);
452 ReleaseTouchPoint(0);
453 EXPECT_EQ(2U, GetAndResetAckedEventCount());
454 EXPECT_EQ(0U, GetAndResetSentEventCount());
455 EXPECT_EQ(0U, queued_event_count());
457 // A new touch sequence should resume forwarding.
458 PressTouchPoint(1, 1);
459 EXPECT_EQ(1U, queued_event_count());
460 EXPECT_EQ(1U, GetAndResetSentEventCount());
463 // Tests that removal of a touch handler during a touch sequence will prevent
464 // the remaining sequence from being forwarded, even if another touch handler is
465 // registered during the same touch sequence.
466 TEST_F(TouchEventQueueTest
, ActiveSequenceDroppedWhenHandlersRemoved
) {
467 // Send a touch-press event.
468 PressTouchPoint(1, 1);
469 EXPECT_EQ(1U, GetAndResetSentEventCount());
470 EXPECT_EQ(1U, queued_event_count());
472 // Queue a touch-move event.
473 MoveTouchPoint(0, 5, 5);
474 EXPECT_EQ(2U, queued_event_count());
475 EXPECT_EQ(0U, GetAndResetAckedEventCount());
476 EXPECT_EQ(0U, GetAndResetSentEventCount());
478 // Unregister all touch handlers.
479 OnHasTouchEventHandlers(false);
480 EXPECT_EQ(0U, GetAndResetAckedEventCount());
481 EXPECT_EQ(2U, queued_event_count());
483 // Repeated registration/unregstration of handlers should have no effect as
484 // we're still awaiting the ack arrival.
485 OnHasTouchEventHandlers(true);
486 EXPECT_EQ(0U, GetAndResetAckedEventCount());
487 EXPECT_EQ(2U, queued_event_count());
488 OnHasTouchEventHandlers(false);
489 EXPECT_EQ(0U, GetAndResetAckedEventCount());
490 EXPECT_EQ(2U, queued_event_count());
492 // The ack should be flush the queue.
493 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
494 EXPECT_EQ(2U, GetAndResetAckedEventCount());
495 EXPECT_EQ(0U, queued_event_count());
497 // Events should be dropped while there is no touch handler.
498 MoveTouchPoint(0, 10, 10);
499 EXPECT_EQ(0U, queued_event_count());
500 EXPECT_EQ(1U, GetAndResetAckedEventCount());
501 EXPECT_EQ(0U, GetAndResetSentEventCount());
503 // Simulate touch handler registration in the middle of a touch sequence.
504 OnHasTouchEventHandlers(true);
506 // The touch end for the interrupted sequence should be dropped.
507 ReleaseTouchPoint(0);
508 EXPECT_EQ(0U, queued_event_count());
509 EXPECT_EQ(1U, GetAndResetAckedEventCount());
510 EXPECT_EQ(0U, GetAndResetSentEventCount());
512 // A new touch sequence should be forwarded properly.
513 PressTouchPoint(1, 1);
514 EXPECT_EQ(1U, queued_event_count());
515 EXPECT_EQ(1U, GetAndResetSentEventCount());
518 // Tests that removal/addition of a touch handler without any intervening
519 // touch activity has no affect on touch forwarding.
520 TEST_F(TouchEventQueueTest
,
521 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition
) {
522 // Send a touch-press event.
523 PressTouchPoint(1, 1);
524 EXPECT_EQ(1U, GetAndResetSentEventCount());
525 EXPECT_EQ(1U, queued_event_count());
527 // Simulate the case where the touchstart handler removes itself, and adds a
528 // touchmove handler.
529 OnHasTouchEventHandlers(false);
530 OnHasTouchEventHandlers(true);
532 // Queue a touch-move event.
533 MoveTouchPoint(0, 5, 5);
534 EXPECT_EQ(2U, queued_event_count());
535 EXPECT_EQ(0U, GetAndResetAckedEventCount());
536 EXPECT_EQ(0U, GetAndResetSentEventCount());
538 // The ack should trigger forwarding of the touchmove, as if no touch
539 // handler registration changes have occurred.
540 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
541 EXPECT_EQ(1U, GetAndResetAckedEventCount());
542 EXPECT_EQ(1U, GetAndResetSentEventCount());
543 EXPECT_EQ(1U, queued_event_count());
546 // Tests that touch-events are coalesced properly in the queue.
547 TEST_F(TouchEventQueueTest
, Coalesce
) {
548 // Send a touch-press event.
549 PressTouchPoint(1, 1);
550 EXPECT_EQ(1U, GetAndResetSentEventCount());
552 // Send a few touch-move events, followed by a touch-release event. All the
553 // touch-move events should be coalesced into a single event.
554 for (float i
= 5; i
< 15; ++i
)
555 MoveTouchPoint(0, i
, i
);
557 EXPECT_EQ(0U, GetAndResetSentEventCount());
558 ReleaseTouchPoint(0);
559 EXPECT_EQ(0U, GetAndResetSentEventCount());
560 EXPECT_EQ(3U, queued_event_count());
562 // ACK the press. Coalesced touch-move events should be sent.
563 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
564 EXPECT_EQ(2U, queued_event_count());
565 EXPECT_EQ(1U, GetAndResetSentEventCount());
566 EXPECT_EQ(1U, GetAndResetAckedEventCount());
567 EXPECT_EQ(WebInputEvent::TouchStart
, acked_event().type
);
568 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, acked_event_state());
571 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
572 EXPECT_EQ(1U, queued_event_count());
573 EXPECT_EQ(1U, GetAndResetSentEventCount());
574 EXPECT_EQ(10U, GetAndResetAckedEventCount());
575 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
578 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
579 EXPECT_EQ(0U, queued_event_count());
580 EXPECT_EQ(0U, GetAndResetSentEventCount());
581 EXPECT_EQ(1U, GetAndResetAckedEventCount());
582 EXPECT_EQ(WebInputEvent::TouchEnd
, acked_event().type
);
585 // Tests that an event that has already been sent but hasn't been ack'ed yet
586 // doesn't get coalesced with newer events.
587 TEST_F(TouchEventQueueTest
, SentTouchEventDoesNotCoalesce
) {
588 // Send a touch-press event.
589 PressTouchPoint(1, 1);
590 EXPECT_EQ(1U, GetAndResetSentEventCount());
592 // Send a few touch-move events, followed by a touch-release event. All the
593 // touch-move events should be coalesced into a single event.
594 for (float i
= 5; i
< 15; ++i
)
595 MoveTouchPoint(0, i
, i
);
597 EXPECT_EQ(0U, GetAndResetSentEventCount());
598 EXPECT_EQ(2U, queued_event_count());
600 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
601 EXPECT_EQ(1U, GetAndResetSentEventCount());
602 EXPECT_EQ(1U, queued_event_count());
604 // The coalesced touch-move event has been sent to the renderer. Any new
605 // touch-move event should not be coalesced with the sent event.
606 MoveTouchPoint(0, 5, 5);
607 EXPECT_EQ(2U, queued_event_count());
609 MoveTouchPoint(0, 7, 7);
610 EXPECT_EQ(2U, queued_event_count());
613 // Tests that coalescing works correctly for multi-touch events.
614 TEST_F(TouchEventQueueTest
, MultiTouch
) {
615 // Press the first finger.
616 PressTouchPoint(1, 1);
617 EXPECT_EQ(1U, GetAndResetSentEventCount());
620 MoveTouchPoint(0, 5, 5);
621 EXPECT_EQ(2U, queued_event_count());
623 // Now press a second finger.
624 PressTouchPoint(2, 2);
625 EXPECT_EQ(3U, queued_event_count());
627 // Move both fingers.
628 MoveTouchPoints(0, 10, 10, 1, 20, 20);
629 MoveTouchPoint(1, 20, 20);
630 EXPECT_EQ(4U, queued_event_count());
632 // Move only one finger now.
633 MoveTouchPoint(0, 15, 15);
634 EXPECT_EQ(4U, queued_event_count());
636 // Move the other finger.
637 MoveTouchPoint(1, 25, 25);
638 EXPECT_EQ(4U, queued_event_count());
640 // Make sure both fingers are marked as having been moved in the coalesced
642 const WebTouchEvent
& event
= latest_event();
643 EXPECT_EQ(WebTouchPoint::StateMoved
, event
.touches
[0].state
);
644 EXPECT_EQ(WebTouchPoint::StateMoved
, event
.touches
[1].state
);
647 // Tests that the touch-event queue is robust to redundant acks.
648 TEST_F(TouchEventQueueTest
, SpuriousAcksIgnored
) {
649 // Trigger a spurious ack.
650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
651 EXPECT_EQ(0U, GetAndResetAckedEventCount());
653 // Send and ack a touch press.
654 PressTouchPoint(1, 1);
655 EXPECT_EQ(1U, GetAndResetSentEventCount());
656 EXPECT_EQ(1U, queued_event_count());
657 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
658 EXPECT_EQ(1U, GetAndResetAckedEventCount());
659 EXPECT_EQ(0U, queued_event_count());
661 // Trigger a spurious ack.
662 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
663 EXPECT_EQ(0U, GetAndResetAckedEventCount());
666 // Tests that touch-move events are not sent to the renderer if the preceding
667 // touch-press event did not have a consumer (and consequently, did not hit the
668 // main thread in the renderer). Also tests that all queued/coalesced touch
669 // events are flushed immediately when the ACK for the touch-press comes back
670 // with NO_CONSUMER status.
671 TEST_F(TouchEventQueueTest
, NoConsumer
) {
672 // The first touch-press should reach the renderer.
673 PressTouchPoint(1, 1);
674 EXPECT_EQ(1U, GetAndResetSentEventCount());
676 // The second touch should not be sent since one is already in queue.
677 MoveTouchPoint(0, 5, 5);
678 EXPECT_EQ(0U, GetAndResetSentEventCount());
679 EXPECT_EQ(2U, queued_event_count());
681 // Receive an ACK for the first touch-event. This should release the queued
682 // touch-event, but it should not be sent to the renderer.
683 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
684 EXPECT_EQ(0U, queued_event_count());
685 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
686 EXPECT_EQ(2U, GetAndResetAckedEventCount());
687 EXPECT_EQ(0U, GetAndResetSentEventCount());
689 // Send a release event. This should not reach the renderer.
690 ReleaseTouchPoint(0);
691 EXPECT_EQ(0U, GetAndResetSentEventCount());
692 EXPECT_EQ(WebInputEvent::TouchEnd
, acked_event().type
);
693 EXPECT_EQ(1U, GetAndResetAckedEventCount());
695 // Send a press-event, followed by move and release events, and another press
696 // event, before the ACK for the first press event comes back. All of the
697 // events should be queued first. After the NO_CONSUMER ack for the first
698 // touch-press, all events upto the second touch-press should be flushed.
699 PressTouchPoint(10, 10);
700 EXPECT_EQ(1U, GetAndResetSentEventCount());
702 MoveTouchPoint(0, 5, 5);
703 MoveTouchPoint(0, 6, 5);
704 ReleaseTouchPoint(0);
706 PressTouchPoint(6, 5);
707 EXPECT_EQ(0U, GetAndResetSentEventCount());
708 // The queue should hold the first sent touch-press event, the coalesced
709 // touch-move event, the touch-end event and the second touch-press event.
710 EXPECT_EQ(4U, queued_event_count());
712 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
713 EXPECT_EQ(1U, GetAndResetSentEventCount());
714 EXPECT_EQ(WebInputEvent::TouchEnd
, acked_event().type
);
715 EXPECT_EQ(4U, GetAndResetAckedEventCount());
716 EXPECT_EQ(1U, queued_event_count());
718 // ACK the second press event as NO_CONSUMER too.
719 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
720 EXPECT_EQ(0U, GetAndResetSentEventCount());
721 EXPECT_EQ(WebInputEvent::TouchStart
, acked_event().type
);
722 EXPECT_EQ(1U, GetAndResetAckedEventCount());
723 EXPECT_EQ(0U, queued_event_count());
725 // Send a second press event. Even though the first touch press had
726 // NO_CONSUMER, this press event should reach the renderer.
727 PressTouchPoint(1, 1);
728 EXPECT_EQ(1U, GetAndResetSentEventCount());
729 EXPECT_EQ(1U, queued_event_count());
730 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
731 EXPECT_EQ(WebInputEvent::TouchStart
, acked_event().type
);
732 EXPECT_EQ(1U, GetAndResetAckedEventCount());
735 TEST_F(TouchEventQueueTest
, ConsumerIgnoreMultiFinger
) {
736 // Interleave three pointer press, move and release events.
737 PressTouchPoint(1, 1);
738 MoveTouchPoint(0, 5, 5);
739 PressTouchPoint(10, 10);
740 MoveTouchPoint(1, 15, 15);
741 PressTouchPoint(20, 20);
742 MoveTouchPoint(2, 25, 25);
743 ReleaseTouchPoint(2);
744 MoveTouchPoint(1, 20, 20);
745 ReleaseTouchPoint(1);
746 MoveTouchPoint(0, 10, 10);
747 ReleaseTouchPoint(0);
749 // Since the first touch-press is still pending ACK, no other event should
750 // have been sent to the renderer.
751 EXPECT_EQ(1U, GetAndResetSentEventCount());
752 EXPECT_EQ(0U, GetAndResetSentEventCount());
753 EXPECT_EQ(11U, queued_event_count());
755 // ACK the first press as CONSUMED. This should cause the first touch-move of
756 // the first touch-point to be dispatched.
757 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
758 EXPECT_EQ(1U, GetAndResetSentEventCount());
759 EXPECT_EQ(10U, queued_event_count());
761 // ACK the first move as CONSUMED.
762 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
763 EXPECT_EQ(1U, GetAndResetSentEventCount());
764 EXPECT_EQ(9U, queued_event_count());
766 // ACK the second press as NO_CONSUMER_EXISTS. The second pointer's touchmove
767 // should still be forwarded, despite lacking a direct consumer.
768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
769 EXPECT_EQ(1U, GetAndResetSentEventCount());
770 EXPECT_EQ(8U, queued_event_count());
772 // ACK the coalesced move as NOT_CONSUMED.
773 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
774 EXPECT_EQ(1U, GetAndResetSentEventCount());
775 EXPECT_EQ(7U, queued_event_count());
777 // All remaining touch events should be forwarded, even if the third pointer
778 // press also reports no consumer.
779 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
780 EXPECT_EQ(6U, queued_event_count());
782 while (queued_event_count())
783 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
785 EXPECT_EQ(6U, GetAndResetSentEventCount());
788 // Tests that touch-event's enqueued via a touch ack are properly handled.
789 TEST_F(TouchEventQueueTest
, AckWithFollowupEvents
) {
790 // Queue a touch down.
791 PressTouchPoint(1, 1);
792 EXPECT_EQ(1U, queued_event_count());
793 EXPECT_EQ(1U, GetAndResetSentEventCount());
794 EXPECT_EQ(0U, GetAndResetAckedEventCount());
796 // Create a touch event that will be queued synchronously by a touch ack.
797 // Note, this will be triggered by all subsequent touch acks.
798 WebTouchEvent followup_event
;
799 followup_event
.type
= WebInputEvent::TouchMove
;
800 followup_event
.touchesLength
= 1;
801 followup_event
.touches
[0].id
= 0;
802 followup_event
.touches
[0].state
= WebTouchPoint::StateMoved
;
803 SetFollowupEvent(followup_event
);
805 // Receive an ACK for the press. This should cause the followup touch-move to
806 // be sent to the renderer.
807 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
808 EXPECT_EQ(1U, queued_event_count());
809 EXPECT_EQ(1U, GetAndResetSentEventCount());
810 EXPECT_EQ(1U, GetAndResetAckedEventCount());
811 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED
, acked_event_state());
812 EXPECT_EQ(WebInputEvent::TouchStart
, acked_event().type
);
814 // Queue another event.
815 MoveTouchPoint(0, 2, 2);
816 EXPECT_EQ(2U, queued_event_count());
818 // Receive an ACK for the touch-move followup event. This should cause the
819 // subsequent touch move event be sent to the renderer.
820 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
821 EXPECT_EQ(1U, queued_event_count());
822 EXPECT_EQ(1U, GetAndResetSentEventCount());
823 EXPECT_EQ(1U, GetAndResetAckedEventCount());
826 // Tests that touch-events can be synchronously ack'ed.
827 TEST_F(TouchEventQueueTest
, SynchronousAcks
) {
829 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED
);
830 PressTouchPoint(1, 1);
831 EXPECT_EQ(0U, queued_event_count());
832 EXPECT_EQ(1U, GetAndResetSentEventCount());
833 EXPECT_EQ(1U, GetAndResetAckedEventCount());
836 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED
);
837 MoveTouchPoint(0, 2, 2);
838 EXPECT_EQ(0U, queued_event_count());
839 EXPECT_EQ(1U, GetAndResetSentEventCount());
840 EXPECT_EQ(1U, GetAndResetAckedEventCount());
843 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED
);
844 ReleaseTouchPoint(0);
845 EXPECT_EQ(0U, queued_event_count());
846 EXPECT_EQ(1U, GetAndResetSentEventCount());
847 EXPECT_EQ(1U, GetAndResetAckedEventCount());
849 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
850 PressTouchPoint(1, 1);
851 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
852 EXPECT_EQ(0U, queued_event_count());
853 EXPECT_EQ(1U, GetAndResetSentEventCount());
854 EXPECT_EQ(1U, GetAndResetAckedEventCount());
856 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED
);
858 EXPECT_EQ(0U, queued_event_count());
859 EXPECT_EQ(1U, GetAndResetSentEventCount());
860 EXPECT_EQ(1U, GetAndResetAckedEventCount());
863 // Tests that followup events triggered by an immediate ack from
864 // TouchEventQueue::QueueEvent() are properly handled.
865 TEST_F(TouchEventQueueTest
, ImmediateAckWithFollowupEvents
) {
866 // Create a touch event that will be queued synchronously by a touch ack.
867 WebTouchEvent followup_event
;
868 followup_event
.type
= WebInputEvent::TouchStart
;
869 followup_event
.touchesLength
= 1;
870 followup_event
.touches
[0].id
= 1;
871 followup_event
.touches
[0].state
= WebTouchPoint::StatePressed
;
872 SetFollowupEvent(followup_event
);
874 // Now, enqueue a stationary touch that will not be forwarded. This should be
875 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
876 // then be enqueued and immediately sent to the renderer.
877 WebTouchEvent stationary_event
;
878 stationary_event
.touchesLength
= 1;
879 stationary_event
.type
= WebInputEvent::TouchMove
;
880 stationary_event
.touches
[0].id
= 1;
881 stationary_event
.touches
[0].state
= WebTouchPoint::StateStationary
;
882 SendTouchEvent(stationary_event
);
884 EXPECT_EQ(1U, queued_event_count());
885 EXPECT_EQ(1U, GetAndResetSentEventCount());
886 EXPECT_EQ(1U, GetAndResetAckedEventCount());
887 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
, acked_event_state());
888 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
891 // Tests basic TouchEvent forwarding suppression.
892 TEST_F(TouchEventQueueTest
, NoTouchBasic
) {
893 // Disable TouchEvent forwarding.
894 OnHasTouchEventHandlers(false);
895 PressTouchPoint(30, 5);
896 EXPECT_EQ(0U, GetAndResetSentEventCount());
897 EXPECT_EQ(1U, GetAndResetAckedEventCount());
899 // TouchMove should not be sent to renderer.
900 MoveTouchPoint(0, 65, 10);
901 EXPECT_EQ(0U, GetAndResetSentEventCount());
902 EXPECT_EQ(1U, GetAndResetAckedEventCount());
904 // TouchEnd should not be sent to renderer.
905 ReleaseTouchPoint(0);
906 EXPECT_EQ(0U, GetAndResetSentEventCount());
907 EXPECT_EQ(1U, GetAndResetAckedEventCount());
909 // Enable TouchEvent forwarding.
910 OnHasTouchEventHandlers(true);
912 PressTouchPoint(80, 10);
913 EXPECT_EQ(1U, GetAndResetSentEventCount());
914 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
915 EXPECT_EQ(1U, GetAndResetAckedEventCount());
917 MoveTouchPoint(0, 80, 20);
918 EXPECT_EQ(1U, GetAndResetSentEventCount());
919 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
920 EXPECT_EQ(1U, GetAndResetAckedEventCount());
922 ReleaseTouchPoint(0);
923 EXPECT_EQ(1U, GetAndResetSentEventCount());
924 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
925 EXPECT_EQ(1U, GetAndResetAckedEventCount());
928 // Tests that IsTouchStartPendingAck works correctly.
929 TEST_F(TouchEventQueueTest
, PendingStart
) {
931 EXPECT_FALSE(IsPendingAckTouchStart());
933 // Send the touchstart for one point (#1).
934 PressTouchPoint(1, 1);
935 EXPECT_EQ(1U, queued_event_count());
936 EXPECT_TRUE(IsPendingAckTouchStart());
938 // Send a touchmove for that point (#2).
939 MoveTouchPoint(0, 5, 5);
940 EXPECT_EQ(2U, queued_event_count());
941 EXPECT_TRUE(IsPendingAckTouchStart());
943 // Ack the touchstart (#1).
944 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
945 EXPECT_EQ(1U, queued_event_count());
946 EXPECT_FALSE(IsPendingAckTouchStart());
948 // Send a touchstart for another point (#3).
949 PressTouchPoint(10, 10);
950 EXPECT_EQ(2U, queued_event_count());
951 EXPECT_FALSE(IsPendingAckTouchStart());
953 // Ack the touchmove (#2).
954 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
955 EXPECT_EQ(1U, queued_event_count());
956 EXPECT_TRUE(IsPendingAckTouchStart());
958 // Send a touchstart for a third point (#4).
959 PressTouchPoint(15, 15);
960 EXPECT_EQ(2U, queued_event_count());
961 EXPECT_TRUE(IsPendingAckTouchStart());
963 // Ack the touchstart for the second point (#3).
964 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
965 EXPECT_EQ(1U, queued_event_count());
966 EXPECT_TRUE(IsPendingAckTouchStart());
968 // Ack the touchstart for the third point (#4).
969 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
970 EXPECT_EQ(0U, queued_event_count());
971 EXPECT_FALSE(IsPendingAckTouchStart());
974 // Tests that the touch timeout is started when sending certain touch types.
975 TEST_F(TouchEventQueueTest
, TouchTimeoutTypes
) {
976 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
978 // Sending a TouchStart will start the timeout.
979 PressTouchPoint(0, 1);
980 EXPECT_TRUE(IsTimeoutRunning());
981 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
982 EXPECT_FALSE(IsTimeoutRunning());
984 // A TouchMove should start the timeout.
985 MoveTouchPoint(0, 5, 5);
986 EXPECT_TRUE(IsTimeoutRunning());
987 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
988 EXPECT_FALSE(IsTimeoutRunning());
990 // A TouchEnd should not start the timeout.
991 ReleaseTouchPoint(0);
992 EXPECT_FALSE(IsTimeoutRunning());
993 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
994 EXPECT_FALSE(IsTimeoutRunning());
996 // A TouchCancel should not start the timeout.
997 PressTouchPoint(0, 1);
998 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
999 ASSERT_FALSE(IsTimeoutRunning());
1000 CancelTouchPoint(0);
1001 EXPECT_FALSE(IsTimeoutRunning());
1002 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1003 EXPECT_FALSE(IsTimeoutRunning());
1006 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
1007 // disabling touch forwarding until the next TouchStart is received after
1008 // the timeout events are ack'ed.
1009 TEST_F(TouchEventQueueTest
, TouchTimeoutBasic
) {
1010 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1012 // Queue a TouchStart.
1013 GetAndResetSentEventCount();
1014 GetAndResetAckedEventCount();
1015 PressTouchPoint(0, 1);
1016 ASSERT_EQ(1U, GetAndResetSentEventCount());
1017 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1018 EXPECT_TRUE(IsTimeoutRunning());
1021 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1023 // The timeout should have fired, synthetically ack'ing the timed-out event.
1024 // TouchEvent forwarding is disabled until the ack is received for the
1025 // timed-out event and the future cancel event.
1026 EXPECT_FALSE(IsTimeoutRunning());
1027 EXPECT_EQ(0U, GetAndResetSentEventCount());
1028 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1030 // Ack'ing the original event should trigger a cancel event.
1031 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1032 EXPECT_FALSE(IsTimeoutRunning());
1033 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1034 EXPECT_EQ(1U, GetAndResetSentEventCount());
1035 EXPECT_EQ(WebInputEvent::TouchCancel
, sent_event().type
);
1036 EXPECT_FALSE(sent_event().cancelable
);
1038 // Touch events should not be forwarded until we receive the cancel acks.
1039 MoveTouchPoint(0, 1, 1);
1040 ASSERT_EQ(0U, GetAndResetSentEventCount());
1041 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1043 ReleaseTouchPoint(0);
1044 ASSERT_EQ(0U, GetAndResetSentEventCount());
1045 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1047 // The synthetic TouchCancel ack should not reach the client, but should
1048 // resume touch forwarding.
1049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1050 EXPECT_EQ(0U, GetAndResetSentEventCount());
1051 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1053 // Subsequent events should be handled normally.
1054 PressTouchPoint(0, 1);
1055 EXPECT_EQ(1U, GetAndResetSentEventCount());
1056 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1057 EXPECT_EQ(WebInputEvent::TouchStart
, sent_event().type
);
1058 EXPECT_TRUE(sent_event().cancelable
);
1061 // Tests that the timeout is never started if the renderer consumes
1062 // a TouchEvent from the current touch sequence.
1063 TEST_F(TouchEventQueueTest
, NoTouchTimeoutIfRendererIsConsumingGesture
) {
1064 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1066 // Queue a TouchStart.
1067 PressTouchPoint(0, 1);
1068 ASSERT_TRUE(IsTimeoutRunning());
1070 // Mark the event as consumed. This should prevent the timeout from
1071 // being activated on subsequent TouchEvents in this gesture.
1072 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1073 EXPECT_FALSE(IsTimeoutRunning());
1075 // A TouchMove should not start the timeout.
1076 MoveTouchPoint(0, 5, 5);
1077 EXPECT_FALSE(IsTimeoutRunning());
1078 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1080 // A secondary TouchStart should not start the timeout.
1081 PressTouchPoint(1, 0);
1082 EXPECT_FALSE(IsTimeoutRunning());
1083 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1085 // A TouchEnd should not start the timeout.
1086 ReleaseTouchPoint(1);
1087 EXPECT_FALSE(IsTimeoutRunning());
1088 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1090 // A TouchCancel should not start the timeout.
1091 CancelTouchPoint(0);
1092 EXPECT_FALSE(IsTimeoutRunning());
1095 // Tests that the timeout is never started if the renderer consumes
1096 // a TouchEvent from the current touch sequence.
1097 TEST_F(TouchEventQueueTest
, NoTouchTimeoutIfDisabledAfterTouchStart
) {
1098 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1100 // Queue a TouchStart.
1101 PressTouchPoint(0, 1);
1102 ASSERT_TRUE(IsTimeoutRunning());
1104 // Send the ack immediately. The timeout should not have fired.
1105 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1106 EXPECT_FALSE(IsTimeoutRunning());
1107 EXPECT_EQ(1U, GetAndResetSentEventCount());
1108 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1110 // Now explicitly disable the timeout.
1111 SetAckTimeoutDisabled();
1112 EXPECT_FALSE(IsTimeoutRunning());
1114 // A TouchMove should not start or trigger the timeout.
1115 MoveTouchPoint(0, 5, 5);
1116 EXPECT_FALSE(IsTimeoutRunning());
1117 EXPECT_EQ(1U, GetAndResetSentEventCount());
1118 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1119 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1122 // Tests that the timeout is never started if the ack is synchronous.
1123 TEST_F(TouchEventQueueTest
, NoTouchTimeoutIfAckIsSynchronous
) {
1124 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1126 // Queue a TouchStart.
1127 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED
);
1128 ASSERT_FALSE(IsTimeoutRunning());
1129 PressTouchPoint(0, 1);
1130 EXPECT_FALSE(IsTimeoutRunning());
1133 // Tests that the timeout does not fire if explicitly disabled while an event
1135 TEST_F(TouchEventQueueTest
, NoTouchTimeoutIfDisabledWhileTimerIsActive
) {
1136 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1138 // Queue a TouchStart.
1139 PressTouchPoint(0, 1);
1140 ASSERT_TRUE(IsTimeoutRunning());
1142 // Verify that disabling the timeout also turns off the timer.
1143 SetAckTimeoutDisabled();
1144 EXPECT_FALSE(IsTimeoutRunning());
1145 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1146 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1149 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1150 // turns into a scroll gesture sequence.
1151 TEST_F(TouchEventQueueTest
, TouchTimeoutWithFollowupGesture
) {
1152 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1154 // Queue a TouchStart.
1155 PressTouchPoint(0, 1);
1156 EXPECT_TRUE(IsTimeoutRunning());
1157 EXPECT_EQ(1U, GetAndResetSentEventCount());
1159 // The cancelled sequence may turn into a scroll gesture.
1160 WebGestureEvent followup_scroll
;
1161 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1162 SetFollowupEvent(followup_scroll
);
1165 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1167 // The timeout should have fired, disabling touch forwarding until both acks
1168 // are received, acking the timed out event.
1169 EXPECT_FALSE(IsTimeoutRunning());
1170 EXPECT_EQ(0U, GetAndResetSentEventCount());
1171 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1173 // Ack the original event, triggering a TouchCancel.
1174 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1175 EXPECT_FALSE(IsTimeoutRunning());
1176 EXPECT_EQ(1U, GetAndResetSentEventCount());
1177 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1179 // Ack the cancel event. Normally, this would resume touch forwarding,
1180 // but we're still within a scroll gesture so it remains disabled.
1181 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1182 EXPECT_FALSE(IsTimeoutRunning());
1183 EXPECT_EQ(0U, GetAndResetSentEventCount());
1184 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1186 // Try to forward touch events for the current sequence.
1187 GetAndResetSentEventCount();
1188 GetAndResetAckedEventCount();
1189 MoveTouchPoint(0, 1, 1);
1190 ReleaseTouchPoint(0);
1191 EXPECT_FALSE(IsTimeoutRunning());
1192 EXPECT_EQ(0U, GetAndResetSentEventCount());
1193 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1195 // Now end the scroll sequence, resuming touch handling.
1196 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd
);
1197 PressTouchPoint(0, 1);
1198 EXPECT_TRUE(IsTimeoutRunning());
1199 EXPECT_EQ(1U, GetAndResetSentEventCount());
1200 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1203 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1204 // turns into a scroll gesture sequence, but the original event acks are
1205 // significantly delayed.
1206 TEST_F(TouchEventQueueTest
, TouchTimeoutWithFollowupGestureAndDelayedAck
) {
1207 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1209 // Queue a TouchStart.
1210 PressTouchPoint(0, 1);
1211 EXPECT_TRUE(IsTimeoutRunning());
1212 EXPECT_EQ(1U, GetAndResetSentEventCount());
1214 // The cancelled sequence may turn into a scroll gesture.
1215 WebGestureEvent followup_scroll
;
1216 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1217 SetFollowupEvent(followup_scroll
);
1220 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1222 // The timeout should have fired, disabling touch forwarding until both acks
1223 // are received and acking the timed out event.
1224 EXPECT_FALSE(IsTimeoutRunning());
1225 EXPECT_EQ(0U, GetAndResetSentEventCount());
1226 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1228 // Try to forward a touch event.
1229 GetAndResetSentEventCount();
1230 GetAndResetAckedEventCount();
1231 MoveTouchPoint(0, 1, 1);
1232 EXPECT_FALSE(IsTimeoutRunning());
1233 EXPECT_EQ(0U, GetAndResetSentEventCount());
1234 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1236 // Now end the scroll sequence. Events will not be forwarded until the two
1237 // outstanding touch acks are received.
1238 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd
);
1239 MoveTouchPoint(0, 2, 2);
1240 ReleaseTouchPoint(0);
1241 EXPECT_FALSE(IsTimeoutRunning());
1242 EXPECT_EQ(0U, GetAndResetSentEventCount());
1243 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1245 // Ack the original event, triggering a cancel.
1246 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1247 EXPECT_EQ(1U, GetAndResetSentEventCount());
1248 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1250 // Ack the cancel event, resuming touch forwarding.
1251 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1252 EXPECT_EQ(0U, GetAndResetSentEventCount());
1253 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1255 PressTouchPoint(0, 1);
1256 EXPECT_TRUE(IsTimeoutRunning());
1257 EXPECT_EQ(1U, GetAndResetSentEventCount());
1260 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1261 // the timed-out event had no consumer.
1262 TEST_F(TouchEventQueueTest
, NoCancelOnTouchTimeoutWithoutConsumer
) {
1263 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1265 // Queue a TouchStart.
1266 PressTouchPoint(0, 1);
1267 ASSERT_EQ(1U, GetAndResetSentEventCount());
1268 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1269 EXPECT_TRUE(IsTimeoutRunning());
1272 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1274 // The timeout should have fired, synthetically ack'ing the timed out event.
1275 // TouchEvent forwarding is disabled until the original ack is received.
1276 EXPECT_FALSE(IsTimeoutRunning());
1277 EXPECT_EQ(0U, GetAndResetSentEventCount());
1278 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1280 // Touch events should not be forwarded until we receive the original ack.
1281 MoveTouchPoint(0, 1, 1);
1282 ReleaseTouchPoint(0);
1283 ASSERT_EQ(0U, GetAndResetSentEventCount());
1284 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1286 // Ack'ing the original event should not trigger a cancel event, as the
1287 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1288 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1289 EXPECT_FALSE(IsTimeoutRunning());
1290 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1291 EXPECT_EQ(0U, GetAndResetSentEventCount());
1293 // Subsequent events should be handled normally.
1294 PressTouchPoint(0, 1);
1295 EXPECT_EQ(1U, GetAndResetSentEventCount());
1296 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1299 // Tests that TouchMove's are dropped if within the boundary-inclusive slop
1300 // suppression region for an unconsumed TouchStart.
1301 TEST_F(TouchEventQueueTest
, TouchMoveSuppressionIncludingSlopBoundary
) {
1302 SetUpForTouchMoveSlopTesting(kSlopLengthDips
);
1304 // Queue a TouchStart.
1305 PressTouchPoint(0, 0);
1306 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1307 ASSERT_EQ(1U, GetAndResetSentEventCount());
1308 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1310 // TouchMove's within the region should be suppressed.
1311 MoveTouchPoint(0, 0, kHalfSlopLengthDips
);
1312 EXPECT_EQ(0U, queued_event_count());
1313 EXPECT_EQ(0U, GetAndResetSentEventCount());
1314 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1315 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, acked_event_state());
1317 MoveTouchPoint(0, kHalfSlopLengthDips
, 0);
1318 EXPECT_EQ(0U, queued_event_count());
1319 EXPECT_EQ(0U, GetAndResetSentEventCount());
1320 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1321 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, acked_event_state());
1323 MoveTouchPoint(0, -kHalfSlopLengthDips
, 0);
1324 EXPECT_EQ(0U, queued_event_count());
1325 EXPECT_EQ(0U, GetAndResetSentEventCount());
1326 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1327 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, acked_event_state());
1329 MoveTouchPoint(0, -kSlopLengthDips
, 0);
1330 EXPECT_EQ(0U, queued_event_count());
1331 EXPECT_EQ(0U, GetAndResetSentEventCount());
1332 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1333 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, acked_event_state());
1335 MoveTouchPoint(0, 0, kSlopLengthDips
);
1336 EXPECT_EQ(0U, queued_event_count());
1337 EXPECT_EQ(0U, GetAndResetSentEventCount());
1338 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1339 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
, acked_event_state());
1341 // As soon as a TouchMove exceeds the (Euclidean) distance, no more
1342 // TouchMove's should be suppressed.
1343 const float kFortyFiveDegreeSlopLengthXY
=
1344 kSlopLengthDips
* std::sqrt(2.f
) / 2;
1345 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY
+ .2f
,
1346 kFortyFiveDegreeSlopLengthXY
+ .2f
);
1347 EXPECT_EQ(1U, queued_event_count());
1348 EXPECT_EQ(1U, GetAndResetSentEventCount());
1349 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1350 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1351 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1353 // Even TouchMove's within the original slop region should now be forwarded.
1354 MoveTouchPoint(0, 0, 0);
1355 EXPECT_EQ(1U, queued_event_count());
1356 EXPECT_EQ(1U, GetAndResetSentEventCount());
1357 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1358 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1359 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1361 // A new touch sequence should reset suppression.
1362 ReleaseTouchPoint(0);
1363 PressTouchPoint(0, 0);
1364 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1365 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1366 ASSERT_EQ(2U, GetAndResetSentEventCount());
1367 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1368 ASSERT_EQ(0U, queued_event_count());
1370 // The slop region is boundary-inclusive.
1371 MoveTouchPoint(0, kSlopLengthDips
- 1, 0);
1372 EXPECT_EQ(0U, queued_event_count());
1373 EXPECT_EQ(0U, GetAndResetSentEventCount());
1374 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1376 MoveTouchPoint(0, kSlopLengthDips
, 0);
1377 EXPECT_EQ(0U, queued_event_count());
1378 EXPECT_EQ(0U, GetAndResetSentEventCount());
1379 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1382 // Tests that TouchMove's are not dropped within the slop suppression region if
1383 // the touchstart was consumed.
1384 TEST_F(TouchEventQueueTest
, NoTouchMoveSuppressionAfterTouchConsumed
) {
1385 SetUpForTouchMoveSlopTesting(kSlopLengthDips
);
1387 // Queue a TouchStart.
1388 PressTouchPoint(0, 0);
1389 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1390 ASSERT_EQ(1U, GetAndResetSentEventCount());
1391 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1393 // TouchMove's within the region should not be suppressed, as a touch was
1395 MoveTouchPoint(0, 0, kHalfSlopLengthDips
);
1396 EXPECT_EQ(1U, queued_event_count());
1397 EXPECT_EQ(1U, GetAndResetSentEventCount());
1398 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1401 // Tests that even very small TouchMove's are not suppressed when suppression is
1403 TEST_F(TouchEventQueueTest
, NoTouchMoveSuppressionIfDisabled
) {
1404 // Queue a TouchStart.
1405 PressTouchPoint(0, 0);
1406 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1407 ASSERT_EQ(1U, GetAndResetSentEventCount());
1408 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1410 // Small TouchMove's should not be suppressed.
1411 MoveTouchPoint(0, 0.001f
, 0.001f
);
1412 EXPECT_EQ(1U, queued_event_count());
1413 EXPECT_EQ(1U, GetAndResetSentEventCount());
1414 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1417 // Tests that TouchMove's are not dropped if a secondary pointer is present
1418 // during any movement.
1419 TEST_F(TouchEventQueueTest
, NoTouchMoveSuppressionAfterMultiTouch
) {
1420 SetUpForTouchMoveSlopTesting(kSlopLengthDips
);
1422 // Queue a TouchStart.
1423 PressTouchPoint(0, 0);
1424 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1425 ASSERT_EQ(1U, GetAndResetSentEventCount());
1426 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1428 // TouchMove's within the region should be suppressed.
1429 MoveTouchPoint(0, 0, kHalfSlopLengthDips
);
1430 EXPECT_EQ(0U, queued_event_count());
1431 EXPECT_EQ(0U, GetAndResetSentEventCount());
1432 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1434 // Simulate a secondary pointer press.
1435 PressTouchPoint(kSlopLengthDips
, 0);
1436 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1437 EXPECT_EQ(1U, GetAndResetSentEventCount());
1438 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1440 // TouchMove with a secondary pointer should not be suppressed.
1441 MoveTouchPoint(1, kSlopLengthDips
+1, 0);
1442 EXPECT_EQ(1U, queued_event_count());
1443 EXPECT_EQ(1U, GetAndResetSentEventCount());
1444 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1445 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1447 // Release the secondary pointer.
1448 ReleaseTouchPoint(0);
1449 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1450 EXPECT_EQ(1U, GetAndResetSentEventCount());
1451 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1453 // TouchMove's should not should be suppressed, even with the original
1455 MoveTouchPoint(0, 0, 0);
1456 EXPECT_EQ(1U, queued_event_count());
1457 EXPECT_EQ(1U, GetAndResetSentEventCount());
1458 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1461 // Tests that secondary touch points can be forwarded even if the primary touch
1462 // point had no consumer.
1463 TEST_F(TouchEventQueueTest
, SecondaryTouchForwardedAfterPrimaryHadNoConsumer
) {
1464 // Queue a TouchStart.
1465 PressTouchPoint(0, 0);
1466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1467 ASSERT_EQ(1U, GetAndResetSentEventCount());
1468 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1470 // Events should not be forwarded, as the point had no consumer.
1471 MoveTouchPoint(0, 0, 15);
1472 EXPECT_EQ(0U, queued_event_count());
1473 EXPECT_EQ(0U, GetAndResetSentEventCount());
1474 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1476 // Simulate a secondary pointer press.
1477 PressTouchPoint(20, 0);
1478 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1479 EXPECT_EQ(1U, GetAndResetSentEventCount());
1480 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1482 // TouchMove with a secondary pointer should not be suppressed.
1483 MoveTouchPoint(1, 25, 0);
1484 EXPECT_EQ(1U, queued_event_count());
1485 EXPECT_EQ(1U, GetAndResetSentEventCount());
1486 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1487 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1490 // Tests that secondary touch points can be forwarded after scrolling begins
1491 // while first touch point has no consumer.
1492 TEST_F(TouchEventQueueTest
, NoForwardingAfterScrollWithNoTouchConsumers
) {
1493 // Queue a TouchStart.
1494 PressTouchPoint(0, 0);
1495 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
);
1496 ASSERT_EQ(1U, GetAndResetSentEventCount());
1497 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1499 WebGestureEvent followup_scroll
;
1500 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1501 SetFollowupEvent(followup_scroll
);
1502 MoveTouchPoint(0, 20, 5);
1503 EXPECT_EQ(0U, GetAndResetSentEventCount());
1504 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1505 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
, acked_event_state());
1507 // The secondary pointer press should be forwarded.
1508 PressTouchPoint(20, 0);
1509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1510 EXPECT_EQ(1U, GetAndResetSentEventCount());
1511 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1513 // TouchMove with a secondary pointer should also be forwarded.
1514 MoveTouchPoint(1, 25, 0);
1515 EXPECT_EQ(1U, queued_event_count());
1516 EXPECT_EQ(1U, GetAndResetSentEventCount());
1517 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1518 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1521 TEST_F(TouchEventQueueTest
, AsyncTouch
) {
1522 // Queue a TouchStart.
1523 PressTouchPoint(0, 1);
1524 EXPECT_EQ(1U, GetAndResetSentEventCount());
1525 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1526 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1528 for (int i
= 0; i
< 3; ++i
) {
1529 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1530 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1532 MoveTouchPoint(0, 10, 5+i
);
1533 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1534 EXPECT_FALSE(HasPendingAsyncTouchMove());
1535 EXPECT_TRUE(sent_event().cancelable
);
1536 EXPECT_EQ(0U, queued_event_count());
1537 EXPECT_EQ(1U, GetAndResetSentEventCount());
1539 // Consuming a scroll event will throttle subsequent touchmoves.
1540 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1541 INPUT_EVENT_ACK_STATE_CONSUMED
);
1542 MoveTouchPoint(0, 10, 7+i
);
1543 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1544 EXPECT_TRUE(HasPendingAsyncTouchMove());
1545 EXPECT_EQ(0U, queued_event_count());
1546 EXPECT_EQ(0U, GetAndResetSentEventCount());
1550 // Ensure that touchmove's are appropriately throttled during a typical
1551 // scroll sequences that transitions between scrolls consumed and unconsumed.
1552 TEST_F(TouchEventQueueTest
, AsyncTouchThrottledAfterScroll
) {
1553 // Process a TouchStart
1554 PressTouchPoint(0, 1);
1555 EXPECT_EQ(1U, GetAndResetSentEventCount());
1556 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1557 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1559 // Now send the first touch move and associated GestureScrollBegin.
1560 MoveTouchPoint(0, 0, 5);
1561 WebGestureEvent followup_scroll
;
1562 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1563 SetFollowupEvent(followup_scroll
);
1564 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1565 EXPECT_EQ(1U, GetAndResetSentEventCount());
1566 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1567 SendGestureEventAck(WebInputEvent::GestureScrollBegin
,
1568 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1570 // Send the second touch move and associated GestureScrollUpdate, but don't
1571 // ACK the gesture event yet.
1572 MoveTouchPoint(0, 0, 50);
1573 followup_scroll
.type
= WebInputEvent::GestureScrollUpdate
;
1574 SetFollowupEvent(followup_scroll
);
1575 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1576 EXPECT_EQ(1U, GetAndResetSentEventCount());
1577 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1579 // Now queue a second touchmove and verify it's not (yet) dispatched.
1580 MoveTouchPoint(0, 0, 100);
1581 SetFollowupEvent(followup_scroll
);
1582 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1583 EXPECT_TRUE(HasPendingAsyncTouchMove());
1584 EXPECT_EQ(0U, queued_event_count());
1585 EXPECT_EQ(0U, GetAndResetSentEventCount());
1586 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1588 // Queuing the final touchend should flush the pending, async touchmove.
1589 ReleaseTouchPoint(0);
1590 followup_scroll
.type
= WebInputEvent::GestureScrollEnd
;
1591 SetFollowupEvent(followup_scroll
);
1592 EXPECT_EQ(WebInputEvent::TouchMove
, sent_event().type
);
1593 EXPECT_FALSE(HasPendingAsyncTouchMove());
1594 EXPECT_FALSE(sent_event().cancelable
);
1595 EXPECT_EQ(1U, GetAndResetSentEventCount());
1596 EXPECT_EQ(2U, queued_event_count());
1598 // Ack the flushed, async touchmove. The ack should not reach the client, but
1599 // it should trigger sending of the (now non-cancelable) touchend.
1600 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1601 EXPECT_EQ(WebInputEvent::TouchEnd
, sent_event().type
);
1602 EXPECT_FALSE(sent_event().cancelable
);
1603 EXPECT_EQ(1U, GetAndResetSentEventCount());
1604 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1605 EXPECT_EQ(1U, queued_event_count());
1607 // Ack the touchend.
1608 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1609 EXPECT_EQ(0U, queued_event_count());
1610 EXPECT_EQ(0U, GetAndResetSentEventCount());
1611 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1613 // Now mark the scrolls as not consumed (which would cause future touchmoves
1614 // in the active sequence to be sent if there was one).
1615 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1616 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1617 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1618 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1620 // Start a new touch sequence and verify that throttling has been reset.
1621 // Touch moves after the start of scrolling will again be throttled.
1622 PressTouchPoint(0, 0);
1623 EXPECT_EQ(1U, GetAndResetSentEventCount());
1624 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1625 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1626 MoveTouchPoint(0, 0, 5);
1627 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1628 SetFollowupEvent(followup_scroll
);
1629 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1630 EXPECT_EQ(1U, GetAndResetSentEventCount());
1631 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1633 MoveTouchPoint(0, 0, 6);
1634 followup_scroll
.type
= WebInputEvent::GestureScrollUpdate
;
1635 SetFollowupEvent(followup_scroll
);
1636 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1637 EXPECT_FALSE(HasPendingAsyncTouchMove());
1638 EXPECT_EQ(1U, GetAndResetSentEventCount());
1639 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1641 MoveTouchPoint(0, 0, 10);
1642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1643 EXPECT_TRUE(HasPendingAsyncTouchMove());
1644 EXPECT_EQ(0U, queued_event_count());
1645 EXPECT_EQ(0U, GetAndResetSentEventCount());
1646 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1648 // Subsequent touchmove's should be deferred.
1649 MoveTouchPoint(0, 0, 25);
1650 EXPECT_TRUE(HasPendingAsyncTouchMove());
1651 EXPECT_EQ(0U, queued_event_count());
1652 EXPECT_EQ(0U, GetAndResetSentEventCount());
1653 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1655 // The pending touchmove should be flushed with the the new touchmove if
1656 // sufficient time has passed.
1657 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves
+ 0.1);
1658 MoveTouchPoint(0, 0, 15);
1659 EXPECT_FALSE(HasPendingAsyncTouchMove());
1660 EXPECT_FALSE(sent_event().cancelable
);
1661 EXPECT_EQ(1U, queued_event_count());
1662 EXPECT_EQ(1U, GetAndResetSentEventCount());
1663 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1665 EXPECT_EQ(0U, queued_event_count());
1666 EXPECT_EQ(0U, GetAndResetSentEventCount());
1667 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1669 // Non-touchmove events should always flush any pending touchmove events.
1670 MoveTouchPoint(0, 0, 25);
1671 EXPECT_TRUE(HasPendingAsyncTouchMove());
1672 EXPECT_EQ(0U, queued_event_count());
1673 EXPECT_EQ(0U, GetAndResetSentEventCount());
1674 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1675 PressTouchPoint(30, 30);
1676 EXPECT_FALSE(HasPendingAsyncTouchMove());
1677 EXPECT_FALSE(sent_event().cancelable
);
1678 EXPECT_EQ(WebInputEvent::TouchMove
, sent_event().type
);
1679 EXPECT_EQ(1U, GetAndResetSentEventCount());
1680 EXPECT_EQ(2U, queued_event_count());
1682 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note
1683 // that the flushed touchmove's ack will not reach the client (its
1684 // constituent events have already been ack'ed).
1685 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1686 EXPECT_TRUE(sent_event().cancelable
);
1687 EXPECT_EQ(WebInputEvent::TouchStart
, sent_event().type
);
1688 EXPECT_EQ(1U, queued_event_count());
1689 EXPECT_EQ(1U, GetAndResetSentEventCount());
1690 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1692 // Ack the touchstart.
1693 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1694 EXPECT_EQ(0U, queued_event_count());
1695 EXPECT_EQ(0U, GetAndResetSentEventCount());
1696 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1698 // Send a secondary touchmove.
1699 MoveTouchPoint(1, 0, 25);
1700 EXPECT_TRUE(HasPendingAsyncTouchMove());
1701 EXPECT_EQ(0U, queued_event_count());
1702 EXPECT_EQ(0U, GetAndResetSentEventCount());
1703 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1705 // An unconsumed scroll should resume synchronous touch handling.
1706 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1707 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1709 // The pending touchmove should be coalesced with the next (now synchronous)
1711 MoveTouchPoint(0, 0, 26);
1712 EXPECT_TRUE(sent_event().cancelable
);
1713 EXPECT_FALSE(HasPendingAsyncTouchMove());
1714 EXPECT_EQ(WebInputEvent::TouchMove
, sent_event().type
);
1715 EXPECT_EQ(WebTouchPoint::StateMoved
, sent_event().touches
[0].state
);
1716 EXPECT_EQ(WebTouchPoint::StateMoved
, sent_event().touches
[1].state
);
1717 EXPECT_EQ(1U, queued_event_count());
1718 EXPECT_EQ(1U, GetAndResetSentEventCount());
1719 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1721 // Subsequent touches will queue until the preceding, synchronous touches are
1723 ReleaseTouchPoint(1);
1724 EXPECT_EQ(2U, queued_event_count());
1725 ReleaseTouchPoint(0);
1726 EXPECT_EQ(3U, queued_event_count());
1727 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1728 EXPECT_TRUE(sent_event().cancelable
);
1729 EXPECT_EQ(WebInputEvent::TouchEnd
, sent_event().type
);
1730 EXPECT_EQ(2U, queued_event_count());
1731 EXPECT_EQ(1U, GetAndResetSentEventCount());
1732 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1734 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1735 EXPECT_TRUE(sent_event().cancelable
);
1736 EXPECT_EQ(WebInputEvent::TouchEnd
, sent_event().type
);
1737 EXPECT_EQ(1U, queued_event_count());
1738 EXPECT_EQ(1U, GetAndResetSentEventCount());
1739 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1741 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1742 EXPECT_EQ(0U, queued_event_count());
1743 EXPECT_EQ(0U, GetAndResetSentEventCount());
1744 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1747 TEST_F(TouchEventQueueTest
, AsyncTouchFlushedByTouchEnd
) {
1748 PressTouchPoint(0, 0);
1749 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1750 EXPECT_EQ(1U, GetAndResetSentEventCount());
1751 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1753 // Initiate async touchmove dispatch after the start of a scroll sequence.
1754 MoveTouchPoint(0, 0, 5);
1755 WebGestureEvent followup_scroll
;
1756 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1757 SetFollowupEvent(followup_scroll
);
1758 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1759 EXPECT_EQ(1U, GetAndResetSentEventCount());
1760 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1762 MoveTouchPoint(0, 0, 10);
1763 followup_scroll
.type
= WebInputEvent::GestureScrollUpdate
;
1764 SetFollowupEvent(followup_scroll
);
1765 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1766 EXPECT_EQ(1U, GetAndResetSentEventCount());
1767 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1769 // Now queue a second touchmove and verify it's not (yet) dispatched.
1770 MoveTouchPoint(0, 0, 100);
1771 EXPECT_TRUE(HasPendingAsyncTouchMove());
1772 EXPECT_EQ(0U, queued_event_count());
1773 EXPECT_EQ(0U, GetAndResetSentEventCount());
1774 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1776 // Return the touch sequence to the original touchstart position. Note that
1777 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove.
1778 MoveTouchPoint(0, 0, 0);
1779 EXPECT_TRUE(HasPendingAsyncTouchMove());
1780 EXPECT_EQ(0U, queued_event_count());
1781 EXPECT_EQ(0U, GetAndResetSentEventCount());
1782 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1784 // Queuing the final touchend should flush the pending, async touchmove.
1785 ReleaseTouchPoint(0);
1786 EXPECT_FALSE(HasPendingAsyncTouchMove());
1787 EXPECT_EQ(WebInputEvent::TouchMove
, sent_event().type
);
1788 EXPECT_FALSE(sent_event().cancelable
);
1789 EXPECT_EQ(0, sent_event().touches
[0].position
.x
);
1790 EXPECT_EQ(0, sent_event().touches
[0].position
.y
);
1791 EXPECT_EQ(1U, GetAndResetSentEventCount());
1793 // Touchend is not cancelable during async touch dispatch.
1794 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED
);
1795 EXPECT_EQ(WebInputEvent::TouchEnd
, sent_event().type
);
1796 EXPECT_FALSE(sent_event().cancelable
);
1797 EXPECT_EQ(1U, GetAndResetSentEventCount());
1800 // Ensure that async touch dispatch and touch ack timeout interactions work
1802 TEST_F(TouchEventQueueTest
, AsyncTouchWithAckTimeout
) {
1803 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1805 // The touchstart should start the timeout.
1806 PressTouchPoint(0, 0);
1807 EXPECT_EQ(1U, GetAndResetSentEventCount());
1808 EXPECT_TRUE(IsTimeoutRunning());
1809 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1810 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1811 EXPECT_FALSE(IsTimeoutRunning());
1813 // The start of a scroll gesture should trigger async touch event dispatch.
1814 MoveTouchPoint(0, 1, 1);
1815 EXPECT_EQ(1U, GetAndResetSentEventCount());
1816 EXPECT_TRUE(IsTimeoutRunning());
1817 WebGestureEvent followup_scroll
;
1818 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1819 SetFollowupEvent(followup_scroll
);
1820 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1821 EXPECT_FALSE(IsTimeoutRunning());
1822 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1824 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1825 INPUT_EVENT_ACK_STATE_CONSUMED
);
1827 // An async touch should fire after the throttling interval has expired, but
1828 // it should not start the touch ack timeout.
1829 MoveTouchPoint(0, 5, 5);
1830 EXPECT_TRUE(HasPendingAsyncTouchMove());
1831 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1833 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves
+ 0.1);
1834 MoveTouchPoint(0, 5, 5);
1835 EXPECT_FALSE(IsTimeoutRunning());
1836 EXPECT_FALSE(HasPendingAsyncTouchMove());
1837 EXPECT_FALSE(sent_event().cancelable
);
1838 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1839 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1840 EXPECT_EQ(1U, GetAndResetSentEventCount());
1842 // An unconsumed scroll event will resume synchronous touchmoves, which are
1843 // subject to the ack timeout.
1844 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1845 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1846 MoveTouchPoint(0, 20, 5);
1847 EXPECT_TRUE(IsTimeoutRunning());
1848 EXPECT_TRUE(sent_event().cancelable
);
1849 EXPECT_EQ(1U, GetAndResetSentEventCount());
1851 // The timeout should fire, disabling touch forwarding until both acks are
1852 // received and acking the timed out event.
1853 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1854 EXPECT_FALSE(IsTimeoutRunning());
1855 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1856 EXPECT_EQ(0U, GetAndResetSentEventCount());
1858 // Ack'ing the original event should trigger a cancel event.
1859 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1860 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1861 EXPECT_FALSE(sent_event().cancelable
);
1862 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1863 EXPECT_EQ(1U, GetAndResetSentEventCount());
1865 // Subsequent touchmove's should not be forwarded, even as the scroll gesture
1866 // goes from unconsumed to consumed.
1867 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1868 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1869 MoveTouchPoint(0, 20, 5);
1870 EXPECT_FALSE(HasPendingAsyncTouchMove());
1871 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1872 EXPECT_EQ(0U, GetAndResetSentEventCount());
1874 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
1875 INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1876 MoveTouchPoint(0, 25, 5);
1877 EXPECT_FALSE(HasPendingAsyncTouchMove());
1878 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1879 EXPECT_EQ(0U, GetAndResetSentEventCount());
1882 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1883 // touch event, that follow-up touch will be forwarded appropriately.
1884 TEST_F(TouchEventQueueTest
, AsyncTouchWithTouchCancelAfterAck
) {
1885 PressTouchPoint(0, 0);
1886 EXPECT_EQ(1U, GetAndResetSentEventCount());
1887 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1888 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1890 // The start of a scroll gesture should trigger async touch event dispatch.
1891 MoveTouchPoint(0, 1, 1);
1892 EXPECT_EQ(1U, GetAndResetSentEventCount());
1893 WebGestureEvent followup_scroll
;
1894 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1895 SetFollowupEvent(followup_scroll
);
1896 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1897 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1898 EXPECT_EQ(0U, queued_event_count());
1900 SendGestureEvent(WebInputEvent::GestureScrollUpdate
);
1902 // The async touchmove should be ack'ed immediately, but not forwarded.
1903 // However, because the ack triggers a touchcancel, both the pending touch and
1904 // the queued touchcancel should be flushed.
1905 WebTouchEvent followup_cancel
;
1906 followup_cancel
.type
= WebInputEvent::TouchCancel
;
1907 followup_cancel
.touchesLength
= 1;
1908 followup_cancel
.touches
[0].state
= WebTouchPoint::StateCancelled
;
1909 SetFollowupEvent(followup_cancel
);
1910 MoveTouchPoint(0, 5, 5);
1911 EXPECT_EQ(2U, queued_event_count());
1912 EXPECT_FALSE(sent_event().cancelable
);
1913 EXPECT_FALSE(HasPendingAsyncTouchMove());
1914 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
1915 EXPECT_EQ(WebInputEvent::TouchMove
, sent_event().type
);
1916 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1917 EXPECT_EQ(1U, GetAndResetSentEventCount());
1919 // The ack for the async touchmove should not reach the client, as it has
1920 // already been ack'ed.
1921 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1922 EXPECT_FALSE(sent_event().cancelable
);
1923 EXPECT_EQ(1U, queued_event_count());
1924 EXPECT_EQ(WebInputEvent::TouchCancel
, sent_event().type
);
1925 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1926 EXPECT_EQ(1U, GetAndResetSentEventCount());
1928 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1929 EXPECT_EQ(0U, queued_event_count());
1930 EXPECT_EQ(WebInputEvent::TouchCancel
, acked_event().type
);
1931 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1932 EXPECT_EQ(0U, GetAndResetSentEventCount());
1935 // Ensure that the async touch is fully reset if the touch sequence restarts
1936 // without properly terminating.
1937 TEST_F(TouchEventQueueTest
, AsyncTouchWithHardTouchStartReset
) {
1938 PressTouchPoint(0, 0);
1939 EXPECT_EQ(1U, GetAndResetSentEventCount());
1940 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1941 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1943 // Trigger async touchmove dispatch.
1944 MoveTouchPoint(0, 1, 1);
1945 EXPECT_EQ(1U, GetAndResetSentEventCount());
1946 WebGestureEvent followup_scroll
;
1947 followup_scroll
.type
= WebInputEvent::GestureScrollBegin
;
1948 SetFollowupEvent(followup_scroll
);
1949 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1950 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1951 EXPECT_EQ(0U, queued_event_count());
1952 SendGestureEvent(WebInputEvent::GestureScrollUpdate
);
1954 // The async touchmove should be immediately ack'ed but delivery is deferred.
1955 MoveTouchPoint(0, 2, 2);
1956 EXPECT_EQ(0U, GetAndResetSentEventCount());
1957 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1958 EXPECT_EQ(0U, queued_event_count());
1959 EXPECT_EQ(WebInputEvent::TouchMove
, acked_event().type
);
1961 // The queue should be robust to hard touch restarts with a new touch
1962 // sequence. In this case, the deferred async touch should not be flushed
1963 // by the new touch sequence.
1964 SendGestureEvent(WebInputEvent::GestureScrollEnd
);
1967 PressTouchPoint(0, 0);
1968 EXPECT_EQ(1U, GetAndResetSentEventCount());
1969 EXPECT_EQ(WebInputEvent::TouchStart
, sent_event().type
);
1970 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1971 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1974 TEST_F(TouchEventQueueTest
, TouchAbsorptionWithConsumedFirstMove
) {
1975 // Queue a TouchStart.
1976 PressTouchPoint(0, 1);
1977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
1978 EXPECT_EQ(0U, queued_event_count());
1979 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1981 MoveTouchPoint(0, 20, 5);
1982 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin
);
1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1984 EXPECT_EQ(0U, queued_event_count());
1985 EXPECT_EQ(2U, GetAndResetSentEventCount());
1987 // Even if the first touchmove event was consumed, subsequent unconsumed
1988 // touchmove events should trigger scrolling.
1989 MoveTouchPoint(0, 60, 5);
1990 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
1991 EXPECT_EQ(0U, queued_event_count());
1992 EXPECT_TRUE(sent_event().cancelable
);
1993 EXPECT_EQ(1U, GetAndResetSentEventCount());
1995 MoveTouchPoint(0, 20, 5);
1996 WebGestureEvent followup_scroll
;
1997 followup_scroll
.type
= WebInputEvent::GestureScrollUpdate
;
1998 SetFollowupEvent(followup_scroll
);
1999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2000 SendGestureEventAck(WebInputEvent::GestureScrollUpdate
,
2001 INPUT_EVENT_ACK_STATE_CONSUMED
);
2002 EXPECT_EQ(0U, queued_event_count());
2003 EXPECT_TRUE(sent_event().cancelable
);
2004 EXPECT_EQ(1U, GetAndResetSentEventCount());
2006 // Touch move event is throttled.
2007 MoveTouchPoint(0, 60, 5);
2008 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2009 EXPECT_EQ(0U, queued_event_count());
2010 EXPECT_EQ(0U, GetAndResetSentEventCount());
2013 TEST_F(TouchEventQueueTest
, TouchStartCancelableDuringScroll
) {
2014 // Queue a touchstart and touchmove that go unconsumed, transitioning to an
2015 // active scroll sequence.
2016 PressTouchPoint(0, 1);
2017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2018 ASSERT_EQ(1U, GetAndResetSentEventCount());
2019 EXPECT_TRUE(sent_event().cancelable
);
2021 MoveTouchPoint(0, 20, 5);
2022 EXPECT_TRUE(sent_event().cancelable
);
2023 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin
);
2024 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate
);
2025 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2026 ASSERT_EQ(1U, GetAndResetSentEventCount());
2027 EXPECT_TRUE(sent_event().cancelable
);
2029 // Even though scrolling has begun, touchstart events should be cancelable,
2030 // allowing, for example, customized pinch processing.
2031 PressTouchPoint(10, 11);
2032 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2033 ASSERT_EQ(1U, GetAndResetSentEventCount());
2034 EXPECT_TRUE(sent_event().cancelable
);
2036 // As the touch start was consumed, touchmoves should no longer be throttled.
2037 MoveTouchPoint(1, 11, 11);
2038 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2039 ASSERT_EQ(1U, GetAndResetSentEventCount());
2040 EXPECT_TRUE(sent_event().cancelable
);
2042 // With throttling disabled, touchend and touchmove events should also be
2044 MoveTouchPoint(1, 12, 12);
2045 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2046 ASSERT_EQ(1U, GetAndResetSentEventCount());
2047 EXPECT_TRUE(sent_event().cancelable
);
2048 ReleaseTouchPoint(1);
2049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2050 ASSERT_EQ(1U, GetAndResetSentEventCount());
2051 EXPECT_TRUE(sent_event().cancelable
);
2053 // If subsequent touchmoves aren't consumed, the generated scroll events
2054 // will restore async touch dispatch.
2055 MoveTouchPoint(0, 25, 5);
2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED
);
2057 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate
);
2058 ASSERT_EQ(1U, GetAndResetSentEventCount());
2059 EXPECT_TRUE(sent_event().cancelable
);
2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves
+ 0.1);
2061 MoveTouchPoint(0, 30, 5);
2062 ASSERT_EQ(1U, GetAndResetSentEventCount());
2063 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED
);
2064 EXPECT_FALSE(sent_event().cancelable
);
2066 // The touchend will be uncancelable during an active scroll sequence.
2067 ReleaseTouchPoint(0);
2068 ASSERT_EQ(1U, GetAndResetSentEventCount());
2069 EXPECT_FALSE(sent_event().cancelable
);
2072 TEST_F(TouchEventQueueTest
, UnseenTouchPointerIdsNotForwarded
) {
2073 SyntheticWebTouchEvent event
;
2074 event
.PressPoint(0, 0);
2075 SendTouchEvent(event
);
2076 EXPECT_EQ(1U, GetAndResetSentEventCount());
2077 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2078 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2080 // Give the touchmove a previously unseen pointer id; it should not be sent.
2081 int press_id
= event
.touches
[0].id
;
2082 event
.MovePoint(0, 1, 1);
2083 event
.touches
[0].id
= 7;
2084 SendTouchEvent(event
);
2085 EXPECT_EQ(0U, GetAndResetSentEventCount());
2086 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2088 // Give the touchmove a valid id; it should be sent.
2089 event
.touches
[0].id
= press_id
;
2090 SendTouchEvent(event
);
2091 EXPECT_EQ(1U, GetAndResetSentEventCount());
2092 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2093 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2095 // Do the same for release.
2096 event
.ReleasePoint(0);
2097 event
.touches
[0].id
= 11;
2098 SendTouchEvent(event
);
2099 EXPECT_EQ(0U, GetAndResetSentEventCount());
2100 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2102 // Give the touchmove a valid id; it should be sent.
2103 event
.touches
[0].id
= press_id
;
2104 SendTouchEvent(event
);
2105 EXPECT_EQ(1U, GetAndResetSentEventCount());
2106 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2107 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2110 // Tests that touch points states are correct in TouchMove events.
2111 TEST_F(TouchEventQueueTest
, PointerStatesInTouchMove
) {
2112 PressTouchPoint(1, 1);
2113 PressTouchPoint(2, 2);
2114 PressTouchPoint(3, 3);
2115 PressTouchPoint(4, 4);
2116 EXPECT_EQ(4U, queued_event_count());
2117 EXPECT_EQ(1U, GetAndResetSentEventCount());
2119 // Receive ACK for the first three touch-events.
2120 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2121 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2122 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2123 EXPECT_EQ(1U, queued_event_count());
2125 // Test current touches state before sending TouchMoves.
2126 const WebTouchEvent
& event1
= sent_event();
2127 EXPECT_EQ(WebInputEvent::TouchStart
, event1
.type
);
2128 EXPECT_EQ(WebTouchPoint::StateStationary
, event1
.touches
[0].state
);
2129 EXPECT_EQ(WebTouchPoint::StateStationary
, event1
.touches
[1].state
);
2130 EXPECT_EQ(WebTouchPoint::StateStationary
, event1
.touches
[2].state
);
2131 EXPECT_EQ(WebTouchPoint::StatePressed
, event1
.touches
[3].state
);
2133 // Move x-position for 1st touch, y-position for 2nd touch
2134 // and do not move other touches.
2135 MoveTouchPoints(0, 1.1f
, 1.f
, 1, 2.f
, 20.001f
);
2136 MoveTouchPoints(2, 3.f
, 3.f
, 3, 4.f
, 4.f
);
2137 EXPECT_EQ(2U, queued_event_count());
2139 // Receive an ACK for the last TouchPress event.
2140 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2142 // 1st TouchMove is sent. Test for touches state.
2143 const WebTouchEvent
& event2
= sent_event();
2144 EXPECT_EQ(WebInputEvent::TouchMove
, event2
.type
);
2145 EXPECT_EQ(WebTouchPoint::StateMoved
, event2
.touches
[0].state
);
2146 EXPECT_EQ(WebTouchPoint::StateMoved
, event2
.touches
[1].state
);
2147 EXPECT_EQ(WebTouchPoint::StateStationary
, event2
.touches
[2].state
);
2148 EXPECT_EQ(WebTouchPoint::StateStationary
, event2
.touches
[3].state
);
2150 // Move only 4th touch but not others.
2151 MoveTouchPoints(0, 1.1f
, 1.f
, 1, 2.f
, 20.001f
);
2152 MoveTouchPoints(2, 3.f
, 3.f
, 3, 4.1f
, 4.1f
);
2154 // Receive an ACK for previous (1st) TouchMove.
2155 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2157 // 2nd TouchMove is sent. Test for touches state.
2158 const WebTouchEvent
& event3
= sent_event();
2159 EXPECT_EQ(WebInputEvent::TouchMove
, event3
.type
);
2160 EXPECT_EQ(WebTouchPoint::StateStationary
, event3
.touches
[0].state
);
2161 EXPECT_EQ(WebTouchPoint::StateStationary
, event3
.touches
[1].state
);
2162 EXPECT_EQ(WebTouchPoint::StateStationary
, event3
.touches
[2].state
);
2163 EXPECT_EQ(WebTouchPoint::StateMoved
, event3
.touches
[3].state
);
2166 // Tests that touch point state is correct in TouchMove events
2167 // when point properties other than position changed.
2168 TEST_F(TouchEventQueueTest
, PointerStatesWhenOtherThanPositionChanged
) {
2169 PressTouchPoint(1, 1);
2170 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2172 // Default initial radiusX/Y is (1.f, 1.f).
2173 // Default initial rotationAngle is 1.f.
2174 // Default initial force is 1.f.
2176 // Change touch point radius only.
2177 ChangeTouchPointRadius(0, 1.5f
, 1.f
);
2178 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2180 // TouchMove is sent. Test for pointer state.
2181 const WebTouchEvent
& event1
= sent_event();
2182 EXPECT_EQ(WebInputEvent::TouchMove
, event1
.type
);
2183 EXPECT_EQ(WebTouchPoint::StateMoved
, event1
.touches
[0].state
);
2185 // Change touch point force.
2186 ChangeTouchPointForce(0, 0.9f
);
2187 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2189 // TouchMove is sent. Test for pointer state.
2190 const WebTouchEvent
& event2
= sent_event();
2191 EXPECT_EQ(WebInputEvent::TouchMove
, event2
.type
);
2192 EXPECT_EQ(WebTouchPoint::StateMoved
, event2
.touches
[0].state
);
2194 // Change touch point rotationAngle.
2195 ChangeTouchPointRotationAngle(0, 1.1f
);
2196 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2198 // TouchMove is sent. Test for pointer state.
2199 const WebTouchEvent
& event3
= sent_event();
2200 EXPECT_EQ(WebInputEvent::TouchMove
, event3
.type
);
2201 EXPECT_EQ(WebTouchPoint::StateMoved
, event3
.touches
[0].state
);
2203 EXPECT_EQ(0U, queued_event_count());
2204 EXPECT_EQ(4U, GetAndResetSentEventCount());
2205 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2208 // Tests that TouchMoves are filtered when none of the points are changed.
2209 TEST_F(TouchEventQueueTest
, FilterTouchMovesWhenNoPointerChanged
) {
2210 PressTouchPoint(1, 1);
2211 PressTouchPoint(2, 2);
2212 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2213 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2214 EXPECT_EQ(0U, queued_event_count());
2215 EXPECT_EQ(2U, GetAndResetSentEventCount());
2216 EXPECT_EQ(2U, GetAndResetAckedEventCount());
2218 // Move 1st touch point.
2219 MoveTouchPoint(0, 10, 10);
2220 EXPECT_EQ(1U, queued_event_count());
2221 EXPECT_EQ(1U, GetAndResetSentEventCount());
2222 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2224 // TouchMove should be allowed and test for touches state.
2225 const WebTouchEvent
& event1
= sent_event();
2226 EXPECT_EQ(WebInputEvent::TouchMove
, event1
.type
);
2227 EXPECT_EQ(WebTouchPoint::StateMoved
, event1
.touches
[0].state
);
2228 EXPECT_EQ(WebTouchPoint::StateStationary
, event1
.touches
[1].state
);
2230 // Do not really move any touch points, but use previous values.
2231 MoveTouchPoint(0, 10, 10);
2232 ChangeTouchPointRadius(1, 1, 1);
2233 MoveTouchPoint(1, 2, 2);
2234 EXPECT_EQ(2U, queued_event_count());
2235 EXPECT_EQ(0U, GetAndResetSentEventCount());
2237 // Receive an ACK for 1st TouchMove.
2238 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2240 // Tries to forward TouchMove but should be filtered
2241 // when none of the touch points have changed.
2242 EXPECT_EQ(0U, queued_event_count());
2243 EXPECT_EQ(0U, GetAndResetSentEventCount());
2244 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2245 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
, acked_event_state());
2247 // Move 2nd touch point.
2248 MoveTouchPoint(1, 3, 3);
2249 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED
);
2250 EXPECT_EQ(0U, queued_event_count());
2251 EXPECT_EQ(1U, GetAndResetSentEventCount());
2252 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2254 // TouchMove should be allowed and test for touches state.
2255 const WebTouchEvent
& event2
= sent_event();
2256 EXPECT_EQ(WebInputEvent::TouchMove
, event2
.type
);
2257 EXPECT_EQ(WebTouchPoint::StateStationary
, event2
.touches
[0].state
);
2258 EXPECT_EQ(WebTouchPoint::StateMoved
, event2
.touches
[1].state
);
2261 } // namespace content