Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_event_queue_unittest.cc
blob6c23e984ac8f5d1320218038075b7227e0bf68b0
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 "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 using blink::WebGestureEvent;
16 using blink::WebInputEvent;
17 using blink::WebTouchEvent;
18 using blink::WebTouchPoint;
20 namespace content {
21 namespace {
23 const double kMinSecondsBetweenThrottledTouchmoves = 0.2;
25 base::TimeDelta DefaultTouchTimeoutDelay() {
26 return base::TimeDelta::FromMilliseconds(1);
28 } // namespace
30 class TouchEventQueueTest : public testing::Test,
31 public TouchEventQueueClient {
32 public:
33 TouchEventQueueTest()
34 : sent_event_count_(0),
35 acked_event_count_(0),
36 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
37 slop_length_dips_(0),
38 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {}
40 virtual ~TouchEventQueueTest() {}
42 // testing::Test
43 virtual void SetUp() OVERRIDE { ResetQueueWithConfig(CreateConfig()); }
45 virtual void TearDown() OVERRIDE {
46 queue_.reset();
49 // TouchEventQueueClient
50 virtual void SendTouchEventImmediately(
51 const TouchEventWithLatencyInfo& event) OVERRIDE {
52 ++sent_event_count_;
53 last_sent_event_ = event.event;
54 if (sync_ack_result_)
55 SendTouchEventAck(*sync_ack_result_.Pass());
58 virtual void OnTouchEventAck(
59 const TouchEventWithLatencyInfo& event,
60 InputEventAckState ack_result) OVERRIDE {
61 ++acked_event_count_;
62 last_acked_event_ = event.event;
63 last_acked_event_state_ = ack_result;
64 if (followup_touch_event_) {
65 scoped_ptr<WebTouchEvent> followup_touch_event =
66 followup_touch_event_.Pass();
67 SendTouchEvent(*followup_touch_event);
69 if (followup_gesture_event_) {
70 scoped_ptr<WebGestureEvent> followup_gesture_event =
71 followup_gesture_event_.Pass();
72 queue_->OnGestureScrollEvent(
73 GestureEventWithLatencyInfo(*followup_gesture_event,
74 ui::LatencyInfo()));
78 protected:
79 TouchEventQueue::Config CreateConfig() {
80 TouchEventQueue::Config config;
81 config.touch_scrolling_mode = touch_scrolling_mode_;
82 config.touchmove_slop_suppression_length_dips = slop_length_dips_;
83 return config;
86 void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) {
87 touch_scrolling_mode_ = mode;
88 ResetQueueWithConfig(CreateConfig());
91 void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
92 slop_length_dips_ = slop_length_dips;
93 ResetQueueWithConfig(CreateConfig());
96 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) {
97 TouchEventQueue::Config config = CreateConfig();
98 config.touch_ack_timeout_delay = timeout_delay;
99 config.touch_ack_timeout_supported = true;
100 ResetQueueWithConfig(config);
103 void SendTouchEvent(const WebTouchEvent& event) {
104 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
107 void SendGestureEvent(WebInputEvent::Type type) {
108 WebGestureEvent event;
109 event.type = type;
110 queue_->OnGestureScrollEvent(
111 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
114 void SendTouchEventAck(InputEventAckState ack_result) {
115 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo());
118 void SendGestureEventAck(WebInputEvent::Type type,
119 InputEventAckState ack_result) {
120 blink::WebGestureEvent gesture_event;
121 gesture_event.type = type;
122 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo());
123 queue_->OnGestureEventAck(event, ack_result);
126 void SetFollowupEvent(const WebTouchEvent& event) {
127 followup_touch_event_.reset(new WebTouchEvent(event));
130 void SetFollowupEvent(const WebGestureEvent& event) {
131 followup_gesture_event_.reset(new WebGestureEvent(event));
134 void SetSyncAckResult(InputEventAckState sync_ack_result) {
135 sync_ack_result_.reset(new InputEventAckState(sync_ack_result));
138 void PressTouchPoint(float x, float y) {
139 touch_event_.PressPoint(x, y);
140 SendTouchEvent();
143 void MoveTouchPoint(int index, float x, float y) {
144 touch_event_.MovePoint(index, x, y);
145 SendTouchEvent();
148 void MoveTouchPoints(int index0,
149 float x0,
150 float y0,
151 int index1,
152 float x1,
153 float y1) {
154 touch_event_.MovePoint(index0, x0, y0);
155 touch_event_.MovePoint(index1, x1, y1);
156 SendTouchEvent();
159 void ReleaseTouchPoint(int index) {
160 touch_event_.ReleasePoint(index);
161 SendTouchEvent();
164 void CancelTouchPoint(int index) {
165 touch_event_.CancelPoint(index);
166 SendTouchEvent();
169 void AdvanceTouchTime(double seconds) {
170 touch_event_.timeStampSeconds += seconds;
173 size_t GetAndResetAckedEventCount() {
174 size_t count = acked_event_count_;
175 acked_event_count_ = 0;
176 return count;
179 size_t GetAndResetSentEventCount() {
180 size_t count = sent_event_count_;
181 sent_event_count_ = 0;
182 return count;
185 bool IsPendingAckTouchStart() const {
186 return queue_->IsPendingAckTouchStart();
189 void OnHasTouchEventHandlers(bool has_handlers) {
190 queue_->OnHasTouchEventHandlers(has_handlers);
193 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); }
195 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); }
197 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); }
199 bool HasPendingAsyncTouchMove() const {
200 return queue_->HasPendingAsyncTouchMoveForTesting();
203 size_t queued_event_count() const {
204 return queue_->size();
207 const WebTouchEvent& latest_event() const {
208 return queue_->GetLatestEventForTesting().event;
211 const WebTouchEvent& acked_event() const {
212 return last_acked_event_;
215 const WebTouchEvent& sent_event() const {
216 return last_sent_event_;
219 InputEventAckState acked_event_state() const {
220 return last_acked_event_state_;
223 static void RunTasksAndWait(base::TimeDelta delay) {
224 base::MessageLoop::current()->PostDelayedTask(
225 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
226 base::MessageLoop::current()->Run();
229 private:
230 void SendTouchEvent() {
231 SendTouchEvent(touch_event_);
232 touch_event_.ResetPoints();
235 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
236 queue_.reset(new TouchEventQueue(this, config));
237 queue_->OnHasTouchEventHandlers(true);
240 scoped_ptr<TouchEventQueue> queue_;
241 size_t sent_event_count_;
242 size_t acked_event_count_;
243 WebTouchEvent last_sent_event_;
244 WebTouchEvent last_acked_event_;
245 InputEventAckState last_acked_event_state_;
246 SyntheticWebTouchEvent touch_event_;
247 scoped_ptr<WebTouchEvent> followup_touch_event_;
248 scoped_ptr<WebGestureEvent> followup_gesture_event_;
249 scoped_ptr<InputEventAckState> sync_ack_result_;
250 double slop_length_dips_;
251 TouchEventQueue::TouchScrollingMode touch_scrolling_mode_;
252 base::MessageLoopForUI message_loop_;
256 // Tests that touch-events are queued properly.
257 TEST_F(TouchEventQueueTest, Basic) {
258 PressTouchPoint(1, 1);
259 EXPECT_EQ(1U, queued_event_count());
260 EXPECT_EQ(1U, GetAndResetSentEventCount());
262 // The second touch should not be sent since one is already in queue.
263 MoveTouchPoint(0, 5, 5);
264 EXPECT_EQ(2U, queued_event_count());
265 EXPECT_EQ(0U, GetAndResetSentEventCount());
267 // Receive an ACK for the first touch-event.
268 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
269 EXPECT_EQ(1U, queued_event_count());
270 EXPECT_EQ(1U, GetAndResetSentEventCount());
271 EXPECT_EQ(1U, GetAndResetAckedEventCount());
272 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
273 EXPECT_TRUE(acked_event().cancelable);
275 // Receive an ACK for the second touch-event.
276 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
277 EXPECT_EQ(0U, queued_event_count());
278 EXPECT_EQ(0U, GetAndResetSentEventCount());
279 EXPECT_EQ(1U, GetAndResetAckedEventCount());
280 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
281 EXPECT_TRUE(acked_event().cancelable);
284 // Tests that the touch-queue is emptied if a page stops listening for touch
285 // events.
286 TEST_F(TouchEventQueueTest, QueueFlushedWhenHandlersRemoved) {
287 OnHasTouchEventHandlers(true);
288 EXPECT_EQ(0U, queued_event_count());
289 EXPECT_EQ(0U, GetAndResetSentEventCount());
291 // Send a touch-press event.
292 PressTouchPoint(1, 1);
293 EXPECT_EQ(1U, GetAndResetSentEventCount());
295 ReleaseTouchPoint(0);
297 // Events will be queued until the first sent event is ack'ed.
298 for (int i = 5; i < 15; ++i) {
299 PressTouchPoint(1, 1);
300 MoveTouchPoint(0, i, i);
301 ReleaseTouchPoint(0);
303 EXPECT_EQ(32U, queued_event_count());
304 EXPECT_EQ(0U, GetAndResetSentEventCount());
306 // Receive an ACK for the first touch-event. One of the queued touch-event
307 // should be forwarded.
308 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
309 EXPECT_EQ(31U, queued_event_count());
310 EXPECT_EQ(1U, GetAndResetSentEventCount());
311 EXPECT_EQ(1U, GetAndResetAckedEventCount());
312 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
314 // Flush the queue. The touch-event queue should now be emptied, but none of
315 // the queued touch-events should be sent to the renderer.
316 OnHasTouchEventHandlers(false);
317 EXPECT_EQ(0U, queued_event_count());
318 EXPECT_EQ(0U, GetAndResetSentEventCount());
319 EXPECT_EQ(31U, GetAndResetAckedEventCount());
322 // Tests that addition of a touch handler during a touch sequence will not cause
323 // the remaining sequence to be forwarded.
324 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) {
325 OnHasTouchEventHandlers(false);
327 // Send a touch-press event while there is no handler.
328 PressTouchPoint(1, 1);
329 EXPECT_EQ(1U, GetAndResetAckedEventCount());
330 EXPECT_EQ(0U, GetAndResetSentEventCount());
331 EXPECT_EQ(0U, queued_event_count());
333 OnHasTouchEventHandlers(true);
335 // The remaining touch sequence should not be forwarded.
336 MoveTouchPoint(0, 5, 5);
337 ReleaseTouchPoint(0);
338 EXPECT_EQ(2U, GetAndResetAckedEventCount());
339 EXPECT_EQ(0U, GetAndResetSentEventCount());
340 EXPECT_EQ(0U, queued_event_count());
342 // A new touch sequence should resume forwarding.
343 PressTouchPoint(1, 1);
344 EXPECT_EQ(1U, queued_event_count());
345 EXPECT_EQ(1U, GetAndResetSentEventCount());
348 // Tests that removal of a touch handler during a touch sequence will prevent
349 // the remaining sequence from being forwarded, even if another touch handler is
350 // registered during the same touch sequence.
351 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
352 // Send a touch-press event.
353 PressTouchPoint(1, 1);
354 EXPECT_EQ(1U, GetAndResetSentEventCount());
355 EXPECT_EQ(1U, queued_event_count());
357 // Queue a touch-move event.
358 MoveTouchPoint(0, 5, 5);
359 EXPECT_EQ(2U, queued_event_count());
360 EXPECT_EQ(0U, GetAndResetAckedEventCount());
361 EXPECT_EQ(0U, GetAndResetSentEventCount());
363 // Touch handle deregistration should flush the queue.
364 OnHasTouchEventHandlers(false);
365 EXPECT_EQ(2U, GetAndResetAckedEventCount());
366 EXPECT_EQ(0U, queued_event_count());
368 // The ack should be ignored as the touch queue is now empty.
369 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
370 EXPECT_EQ(0U, GetAndResetAckedEventCount());
371 EXPECT_EQ(0U, queued_event_count());
373 // Events should be dropped while there is no touch handler.
374 MoveTouchPoint(0, 10, 10);
375 EXPECT_EQ(0U, queued_event_count());
376 EXPECT_EQ(1U, GetAndResetAckedEventCount());
377 EXPECT_EQ(0U, GetAndResetSentEventCount());
379 // Simulate touch handler registration in the middle of a touch sequence.
380 OnHasTouchEventHandlers(true);
382 // The touch end for the interrupted sequence should be dropped.
383 ReleaseTouchPoint(0);
384 EXPECT_EQ(0U, queued_event_count());
385 EXPECT_EQ(1U, GetAndResetAckedEventCount());
386 EXPECT_EQ(0U, GetAndResetSentEventCount());
388 // A new touch sequence should be forwarded properly.
389 PressTouchPoint(1, 1);
390 EXPECT_EQ(1U, queued_event_count());
391 EXPECT_EQ(1U, GetAndResetSentEventCount());
394 // Tests that touch-events are coalesced properly in the queue.
395 TEST_F(TouchEventQueueTest, Coalesce) {
396 // Send a touch-press event.
397 PressTouchPoint(1, 1);
398 EXPECT_EQ(1U, GetAndResetSentEventCount());
400 // Send a few touch-move events, followed by a touch-release event. All the
401 // touch-move events should be coalesced into a single event.
402 for (int i = 5; i < 15; ++i)
403 MoveTouchPoint(0, i, i);
405 EXPECT_EQ(0U, GetAndResetSentEventCount());
406 ReleaseTouchPoint(0);
407 EXPECT_EQ(0U, GetAndResetSentEventCount());
408 EXPECT_EQ(3U, queued_event_count());
410 // ACK the press. Coalesced touch-move events should be sent.
411 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
412 EXPECT_EQ(2U, queued_event_count());
413 EXPECT_EQ(1U, GetAndResetSentEventCount());
414 EXPECT_EQ(1U, GetAndResetAckedEventCount());
415 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
416 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
418 // ACK the moves.
419 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
420 EXPECT_EQ(1U, queued_event_count());
421 EXPECT_EQ(1U, GetAndResetSentEventCount());
422 EXPECT_EQ(10U, GetAndResetAckedEventCount());
423 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
425 // ACK the release.
426 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
427 EXPECT_EQ(0U, queued_event_count());
428 EXPECT_EQ(0U, GetAndResetSentEventCount());
429 EXPECT_EQ(1U, GetAndResetAckedEventCount());
430 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
433 // Tests that an event that has already been sent but hasn't been ack'ed yet
434 // doesn't get coalesced with newer events.
435 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
436 // Send a touch-press event.
437 PressTouchPoint(1, 1);
438 EXPECT_EQ(1U, GetAndResetSentEventCount());
440 // Send a few touch-move events, followed by a touch-release event. All the
441 // touch-move events should be coalesced into a single event.
442 for (int i = 5; i < 15; ++i)
443 MoveTouchPoint(0, i, i);
445 EXPECT_EQ(0U, GetAndResetSentEventCount());
446 EXPECT_EQ(2U, queued_event_count());
448 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
449 EXPECT_EQ(1U, GetAndResetSentEventCount());
450 EXPECT_EQ(1U, queued_event_count());
452 // The coalesced touch-move event has been sent to the renderer. Any new
453 // touch-move event should not be coalesced with the sent event.
454 MoveTouchPoint(0, 5, 5);
455 EXPECT_EQ(2U, queued_event_count());
457 MoveTouchPoint(0, 7, 7);
458 EXPECT_EQ(2U, queued_event_count());
461 // Tests that coalescing works correctly for multi-touch events.
462 TEST_F(TouchEventQueueTest, MultiTouch) {
463 // Press the first finger.
464 PressTouchPoint(1, 1);
465 EXPECT_EQ(1U, GetAndResetSentEventCount());
467 // Move the finger.
468 MoveTouchPoint(0, 5, 5);
469 EXPECT_EQ(2U, queued_event_count());
471 // Now press a second finger.
472 PressTouchPoint(2, 2);
473 EXPECT_EQ(3U, queued_event_count());
475 // Move both fingers.
476 MoveTouchPoints(0, 10, 10, 1, 20, 20);
477 MoveTouchPoint(1, 20, 20);
478 EXPECT_EQ(4U, queued_event_count());
480 // Move only one finger now.
481 MoveTouchPoint(0, 15, 15);
482 EXPECT_EQ(4U, queued_event_count());
484 // Move the other finger.
485 MoveTouchPoint(1, 25, 25);
486 EXPECT_EQ(4U, queued_event_count());
488 // Make sure both fingers are marked as having been moved in the coalesced
489 // event.
490 const WebTouchEvent& event = latest_event();
491 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
492 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
495 // Tests that if a touch-event queue is destroyed in response to a touch-event
496 // in the renderer, then there is no crash when the ACK for that touch-event
497 // comes back.
498 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) {
499 // Send some touch-events to the renderer.
500 PressTouchPoint(1, 1);
501 EXPECT_EQ(1U, GetAndResetSentEventCount());
502 EXPECT_EQ(1U, queued_event_count());
504 MoveTouchPoint(0, 10, 10);
505 EXPECT_EQ(0U, GetAndResetSentEventCount());
506 EXPECT_EQ(2U, queued_event_count());
508 // Receive an ACK for the press. This should cause the queued touch-move to
509 // be sent to the renderer.
510 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
511 EXPECT_EQ(1U, GetAndResetSentEventCount());
512 EXPECT_EQ(1U, queued_event_count());
514 OnHasTouchEventHandlers(false);
515 EXPECT_EQ(0U, GetAndResetSentEventCount());
516 EXPECT_EQ(0U, queued_event_count());
518 // Now receive an ACK for the move.
519 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
520 EXPECT_EQ(0U, GetAndResetSentEventCount());
521 EXPECT_EQ(0U, queued_event_count());
524 // Tests that touch-move events are not sent to the renderer if the preceding
525 // touch-press event did not have a consumer (and consequently, did not hit the
526 // main thread in the renderer). Also tests that all queued/coalesced touch
527 // events are flushed immediately when the ACK for the touch-press comes back
528 // with NO_CONSUMER status.
529 TEST_F(TouchEventQueueTest, NoConsumer) {
530 // The first touch-press should reach the renderer.
531 PressTouchPoint(1, 1);
532 EXPECT_EQ(1U, GetAndResetSentEventCount());
534 // The second touch should not be sent since one is already in queue.
535 MoveTouchPoint(0, 5, 5);
536 EXPECT_EQ(0U, GetAndResetSentEventCount());
537 EXPECT_EQ(2U, queued_event_count());
539 // Receive an ACK for the first touch-event. This should release the queued
540 // touch-event, but it should not be sent to the renderer.
541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
542 EXPECT_EQ(0U, queued_event_count());
543 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
544 EXPECT_EQ(2U, GetAndResetAckedEventCount());
545 EXPECT_EQ(0U, GetAndResetSentEventCount());
547 // Send a release event. This should not reach the renderer.
548 ReleaseTouchPoint(0);
549 EXPECT_EQ(0U, GetAndResetSentEventCount());
550 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
551 EXPECT_EQ(1U, GetAndResetAckedEventCount());
553 // Send a press-event, followed by move and release events, and another press
554 // event, before the ACK for the first press event comes back. All of the
555 // events should be queued first. After the NO_CONSUMER ack for the first
556 // touch-press, all events upto the second touch-press should be flushed.
557 PressTouchPoint(10, 10);
558 EXPECT_EQ(1U, GetAndResetSentEventCount());
560 MoveTouchPoint(0, 5, 5);
561 MoveTouchPoint(0, 6, 5);
562 ReleaseTouchPoint(0);
564 PressTouchPoint(6, 5);
565 EXPECT_EQ(0U, GetAndResetSentEventCount());
566 // The queue should hold the first sent touch-press event, the coalesced
567 // touch-move event, the touch-end event and the second touch-press event.
568 EXPECT_EQ(4U, queued_event_count());
570 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
571 EXPECT_EQ(1U, GetAndResetSentEventCount());
572 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
573 EXPECT_EQ(4U, GetAndResetAckedEventCount());
574 EXPECT_EQ(1U, queued_event_count());
576 // ACK the second press event as NO_CONSUMER too.
577 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
578 EXPECT_EQ(0U, GetAndResetSentEventCount());
579 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
580 EXPECT_EQ(1U, GetAndResetAckedEventCount());
581 EXPECT_EQ(0U, queued_event_count());
583 // Send a second press event. Even though the first touch press had
584 // NO_CONSUMER, this press event should reach the renderer.
585 PressTouchPoint(1, 1);
586 EXPECT_EQ(1U, GetAndResetSentEventCount());
587 EXPECT_EQ(1U, queued_event_count());
588 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
589 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
590 EXPECT_EQ(1U, GetAndResetAckedEventCount());
593 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
594 // Press two touch points and move them around a bit. The renderer consumes
595 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for
596 // the second touch point.
598 PressTouchPoint(1, 1);
599 EXPECT_EQ(1U, GetAndResetSentEventCount());
601 MoveTouchPoint(0, 5, 5);
603 PressTouchPoint(10, 10);
605 MoveTouchPoint(0, 2, 2);
607 MoveTouchPoint(1, 4, 10);
609 MoveTouchPoints(0, 10, 10, 1, 20, 20);
611 // Since the first touch-press is still pending ACK, no other event should
612 // have been sent to the renderer.
613 EXPECT_EQ(0U, GetAndResetSentEventCount());
614 // The queue includes the two presses, the first touch-move of the first
615 // point, and a coalesced touch-move of both points.
616 EXPECT_EQ(4U, queued_event_count());
618 // ACK the first press as CONSUMED. This should cause the first touch-move of
619 // the first touch-point to be dispatched.
620 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
621 EXPECT_EQ(1U, GetAndResetSentEventCount());
622 EXPECT_EQ(3U, queued_event_count());
624 // ACK the first move as CONSUMED.
625 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
626 EXPECT_EQ(1U, GetAndResetSentEventCount());
627 EXPECT_EQ(2U, queued_event_count());
629 // ACK the second press as NO_CONSUMER_EXISTS. This will dequeue the coalesced
630 // touch-move event (which contains both touch points). Although the second
631 // touch-point does not need to be sent to the renderer, the first touch-point
632 // did move, and so the coalesced touch-event will be sent to the renderer.
633 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
634 EXPECT_EQ(1U, GetAndResetSentEventCount());
635 EXPECT_EQ(1U, queued_event_count());
637 // ACK the coalesced move as NOT_CONSUMED.
638 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
639 EXPECT_EQ(0U, GetAndResetSentEventCount());
640 EXPECT_EQ(0U, queued_event_count());
642 // Move just the second touch point. Because the first touch point did not
643 // move, this event should not reach the renderer.
644 MoveTouchPoint(1, 30, 30);
645 EXPECT_EQ(0U, GetAndResetSentEventCount());
646 EXPECT_EQ(0U, queued_event_count());
648 // Move just the first touch point. This should reach the renderer.
649 MoveTouchPoint(0, 10, 10);
650 EXPECT_EQ(1U, GetAndResetSentEventCount());
651 EXPECT_EQ(1U, queued_event_count());
653 // Move both fingers. This event should reach the renderer (after the ACK of
654 // the previous move event is received), because the first touch point did
655 // move.
656 MoveTouchPoints(0, 15, 15, 1, 25, 25);
657 EXPECT_EQ(0U, GetAndResetSentEventCount());
659 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
660 EXPECT_EQ(1U, GetAndResetSentEventCount());
661 EXPECT_EQ(1U, queued_event_count());
663 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
664 EXPECT_EQ(0U, GetAndResetSentEventCount());
665 EXPECT_EQ(0U, queued_event_count());
667 // Release the first finger. Then move the second finger around some, then
668 // press another finger. Once the release event is ACKed, the move events of
669 // the second finger should be immediately released to the view, and the
670 // touch-press event should be dispatched to the renderer.
671 ReleaseTouchPoint(0);
672 EXPECT_EQ(1U, GetAndResetSentEventCount());
673 EXPECT_EQ(1U, queued_event_count());
675 MoveTouchPoint(1, 40, 40);
677 MoveTouchPoint(1, 50, 50);
679 PressTouchPoint(1, 1);
681 MoveTouchPoint(1, 30, 30);
682 EXPECT_EQ(0U, GetAndResetSentEventCount());
683 EXPECT_EQ(4U, queued_event_count());
685 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
686 EXPECT_EQ(1U, GetAndResetSentEventCount());
687 EXPECT_EQ(2U, queued_event_count());
688 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
690 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued
691 // touch-move events to the view.
692 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
693 EXPECT_EQ(0U, GetAndResetSentEventCount());
694 EXPECT_EQ(0U, queued_event_count());
695 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
697 ReleaseTouchPoint(2);
698 ReleaseTouchPoint(1);
699 EXPECT_EQ(0U, GetAndResetSentEventCount());
700 EXPECT_EQ(0U, queued_event_count());
703 // Tests that touch-event's enqueued via a touch ack are properly handled.
704 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
705 // Queue a touch down.
706 PressTouchPoint(1, 1);
707 EXPECT_EQ(1U, queued_event_count());
708 EXPECT_EQ(1U, GetAndResetSentEventCount());
709 EXPECT_EQ(0U, GetAndResetAckedEventCount());
711 // Create a touch event that will be queued synchronously by a touch ack.
712 // Note, this will be triggered by all subsequent touch acks.
713 WebTouchEvent followup_event;
714 followup_event.type = WebInputEvent::TouchStart;
715 followup_event.touchesLength = 1;
716 followup_event.touches[0].id = 1;
717 followup_event.touches[0].state = WebTouchPoint::StatePressed;
718 SetFollowupEvent(followup_event);
720 // Receive an ACK for the press. This should cause the followup touch-move to
721 // be sent to the renderer.
722 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
723 EXPECT_EQ(1U, queued_event_count());
724 EXPECT_EQ(1U, GetAndResetSentEventCount());
725 EXPECT_EQ(1U, GetAndResetAckedEventCount());
726 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
727 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
729 // Queue another event.
730 MoveTouchPoint(0, 2, 2);
731 EXPECT_EQ(2U, queued_event_count());
733 // Receive an ACK for the touch-move followup event. This should cause the
734 // subsequent touch move event be sent to the renderer.
735 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
736 EXPECT_EQ(1U, queued_event_count());
737 EXPECT_EQ(1U, GetAndResetSentEventCount());
738 EXPECT_EQ(1U, GetAndResetAckedEventCount());
741 // Tests that touch-events can be synchronously ack'ed.
742 TEST_F(TouchEventQueueTest, SynchronousAcks) {
743 // TouchStart
744 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
745 PressTouchPoint(1, 1);
746 EXPECT_EQ(0U, queued_event_count());
747 EXPECT_EQ(1U, GetAndResetSentEventCount());
748 EXPECT_EQ(1U, GetAndResetAckedEventCount());
750 // TouchMove
751 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
752 MoveTouchPoint(0, 2, 2);
753 EXPECT_EQ(0U, queued_event_count());
754 EXPECT_EQ(1U, GetAndResetSentEventCount());
755 EXPECT_EQ(1U, GetAndResetAckedEventCount());
757 // TouchEnd
758 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
759 ReleaseTouchPoint(0);
760 EXPECT_EQ(0U, queued_event_count());
761 EXPECT_EQ(1U, GetAndResetSentEventCount());
762 EXPECT_EQ(1U, GetAndResetAckedEventCount());
764 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
765 PressTouchPoint(1, 1);
766 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
767 EXPECT_EQ(0U, queued_event_count());
768 EXPECT_EQ(1U, GetAndResetSentEventCount());
769 EXPECT_EQ(1U, GetAndResetAckedEventCount());
771 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
772 CancelTouchPoint(0);
773 EXPECT_EQ(0U, queued_event_count());
774 EXPECT_EQ(1U, GetAndResetSentEventCount());
775 EXPECT_EQ(1U, GetAndResetAckedEventCount());
778 // Tests that followup events triggered by an immediate ack from
779 // TouchEventQueue::QueueEvent() are properly handled.
780 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
781 // Create a touch event that will be queued synchronously by a touch ack.
782 WebTouchEvent followup_event;
783 followup_event.type = WebInputEvent::TouchStart;
784 followup_event.touchesLength = 1;
785 followup_event.touches[0].id = 1;
786 followup_event.touches[0].state = WebTouchPoint::StatePressed;
787 SetFollowupEvent(followup_event);
789 // Now, enqueue a stationary touch that will not be forwarded. This should be
790 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
791 // then be enqueued and immediately sent to the renderer.
792 WebTouchEvent stationary_event;
793 stationary_event.touchesLength = 1;
794 stationary_event.type = WebInputEvent::TouchMove;
795 stationary_event.touches[0].id = 1;
796 stationary_event.touches[0].state = WebTouchPoint::StateStationary;
797 SendTouchEvent(stationary_event);
799 EXPECT_EQ(1U, queued_event_count());
800 EXPECT_EQ(1U, GetAndResetSentEventCount());
801 EXPECT_EQ(1U, GetAndResetAckedEventCount());
802 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
803 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
806 // Tests basic TouchEvent forwarding suppression.
807 TEST_F(TouchEventQueueTest, NoTouchBasic) {
808 // Disable TouchEvent forwarding.
809 OnHasTouchEventHandlers(false);
810 PressTouchPoint(30, 5);
811 EXPECT_EQ(0U, GetAndResetSentEventCount());
812 EXPECT_EQ(1U, GetAndResetAckedEventCount());
814 // TouchMove should not be sent to renderer.
815 MoveTouchPoint(0, 65, 10);
816 EXPECT_EQ(0U, GetAndResetSentEventCount());
817 EXPECT_EQ(1U, GetAndResetAckedEventCount());
819 // TouchEnd should not be sent to renderer.
820 ReleaseTouchPoint(0);
821 EXPECT_EQ(0U, GetAndResetSentEventCount());
822 EXPECT_EQ(1U, GetAndResetAckedEventCount());
824 // Enable TouchEvent forwarding.
825 OnHasTouchEventHandlers(true);
827 PressTouchPoint(80, 10);
828 EXPECT_EQ(1U, GetAndResetSentEventCount());
829 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
830 EXPECT_EQ(1U, GetAndResetAckedEventCount());
832 MoveTouchPoint(0, 80, 20);
833 EXPECT_EQ(1U, GetAndResetSentEventCount());
834 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
835 EXPECT_EQ(1U, GetAndResetAckedEventCount());
837 ReleaseTouchPoint(0);
838 EXPECT_EQ(1U, GetAndResetSentEventCount());
839 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
840 EXPECT_EQ(1U, GetAndResetAckedEventCount());
843 // Tests that no TouchEvents are sent to renderer during scrolling.
844 TEST_F(TouchEventQueueTest, TouchCancelOnScroll) {
845 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
846 // Queue a TouchStart.
847 PressTouchPoint(0, 1);
848 EXPECT_EQ(1U, GetAndResetSentEventCount());
849 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
850 EXPECT_EQ(1U, GetAndResetAckedEventCount());
852 MoveTouchPoint(0, 20, 5);
853 EXPECT_EQ(1U, queued_event_count());
854 EXPECT_EQ(1U, GetAndResetSentEventCount());
856 // Queue another TouchStart.
857 PressTouchPoint(20, 20);
858 EXPECT_EQ(2U, queued_event_count());
859 EXPECT_EQ(0U, GetAndResetSentEventCount());
860 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
862 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart.
863 WebGestureEvent followup_scroll;
864 followup_scroll.type = WebInputEvent::GestureScrollBegin;
865 SetFollowupEvent(followup_scroll);
866 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
867 EXPECT_EQ(1U, GetAndResetSentEventCount());
868 EXPECT_EQ(1U, GetAndResetAckedEventCount());
869 EXPECT_EQ(2U, queued_event_count());
870 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
871 EXPECT_FALSE(sent_event().cancelable);
872 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
874 // Acking the TouchCancel will result in dispatch of the next TouchStart.
875 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
876 // The synthetic TouchCancel should not reach client, only the TouchStart.
877 EXPECT_EQ(1U, GetAndResetAckedEventCount());
878 EXPECT_EQ(0U, GetAndResetSentEventCount());
879 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
881 // TouchMove should not be sent to the renderer.
882 MoveTouchPoint(0, 30, 5);
883 EXPECT_EQ(1U, GetAndResetAckedEventCount());
884 EXPECT_EQ(0U, GetAndResetSentEventCount());
885 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
887 // GestureScrollUpdates should not change affect touch forwarding.
888 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
890 // TouchEnd should not be sent to the renderer.
891 ReleaseTouchPoint(0);
892 EXPECT_EQ(1U, GetAndResetAckedEventCount());
893 EXPECT_EQ(0U, GetAndResetSentEventCount());
894 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
896 ReleaseTouchPoint(0);
897 EXPECT_EQ(1U, GetAndResetAckedEventCount());
898 EXPECT_EQ(0U, GetAndResetSentEventCount());
899 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
901 // Touch events from a new gesture sequence should be forwarded normally.
902 PressTouchPoint(80, 10);
903 EXPECT_EQ(1U, GetAndResetSentEventCount());
904 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
905 EXPECT_EQ(1U, GetAndResetAckedEventCount());
907 MoveTouchPoint(0, 80, 20);
908 EXPECT_EQ(1U, GetAndResetSentEventCount());
909 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
910 EXPECT_EQ(1U, GetAndResetAckedEventCount());
912 ReleaseTouchPoint(0);
913 EXPECT_EQ(1U, GetAndResetSentEventCount());
914 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
915 EXPECT_EQ(1U, GetAndResetAckedEventCount());
918 // Tests that a scroll event will not insert a synthetic TouchCancel if there
919 // was no consumer for the current touch sequence.
920 TEST_F(TouchEventQueueTest, NoTouchCancelOnScrollIfNoConsumer) {
921 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
923 // Queue a TouchStart.
924 PressTouchPoint(0, 1);
925 EXPECT_EQ(1U, GetAndResetSentEventCount());
926 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
927 EXPECT_EQ(1U, GetAndResetAckedEventCount());
928 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
930 // Queue a TouchMove that turns into a GestureScrollBegin.
931 WebGestureEvent followup_scroll;
932 followup_scroll.type = WebInputEvent::GestureScrollBegin;
933 SetFollowupEvent(followup_scroll);
934 MoveTouchPoint(0, 20, 5);
936 // The TouchMove has no consumer, and should be ack'ed immediately. However,
937 // *no* synthetic TouchCancel should be inserted as the touch sequence
938 // had no consumer.
939 EXPECT_EQ(0U, queued_event_count());
940 EXPECT_EQ(0U, GetAndResetSentEventCount());
941 EXPECT_EQ(1U, GetAndResetAckedEventCount());
942 EXPECT_EQ(0U, queued_event_count());
943 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
945 // Subsequent TouchMove's should not be sent to the renderer.
946 MoveTouchPoint(0, 30, 5);
947 EXPECT_EQ(1U, GetAndResetAckedEventCount());
948 EXPECT_EQ(0U, GetAndResetSentEventCount());
949 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
951 // TouchEnd should not be sent to the renderer.
952 ReleaseTouchPoint(0);
953 EXPECT_EQ(1U, GetAndResetAckedEventCount());
954 EXPECT_EQ(0U, GetAndResetSentEventCount());
955 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
957 // Touch events from a new gesture sequence should be forwarded normally.
958 PressTouchPoint(80, 10);
959 EXPECT_EQ(1U, GetAndResetSentEventCount());
960 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
961 EXPECT_EQ(1U, GetAndResetAckedEventCount());
964 // Tests that IsTouchStartPendingAck works correctly.
965 TEST_F(TouchEventQueueTest, PendingStart) {
967 EXPECT_FALSE(IsPendingAckTouchStart());
969 // Send the touchstart for one point (#1).
970 PressTouchPoint(1, 1);
971 EXPECT_EQ(1U, queued_event_count());
972 EXPECT_TRUE(IsPendingAckTouchStart());
974 // Send a touchmove for that point (#2).
975 MoveTouchPoint(0, 5, 5);
976 EXPECT_EQ(2U, queued_event_count());
977 EXPECT_TRUE(IsPendingAckTouchStart());
979 // Ack the touchstart (#1).
980 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
981 EXPECT_EQ(1U, queued_event_count());
982 EXPECT_FALSE(IsPendingAckTouchStart());
984 // Send a touchstart for another point (#3).
985 PressTouchPoint(10, 10);
986 EXPECT_EQ(2U, queued_event_count());
987 EXPECT_FALSE(IsPendingAckTouchStart());
989 // Ack the touchmove (#2).
990 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
991 EXPECT_EQ(1U, queued_event_count());
992 EXPECT_TRUE(IsPendingAckTouchStart());
994 // Send a touchstart for a third point (#4).
995 PressTouchPoint(15, 15);
996 EXPECT_EQ(2U, queued_event_count());
997 EXPECT_TRUE(IsPendingAckTouchStart());
999 // Ack the touchstart for the second point (#3).
1000 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1001 EXPECT_EQ(1U, queued_event_count());
1002 EXPECT_TRUE(IsPendingAckTouchStart());
1004 // Ack the touchstart for the third point (#4).
1005 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1006 EXPECT_EQ(0U, queued_event_count());
1007 EXPECT_FALSE(IsPendingAckTouchStart());
1010 // Tests that the touch timeout is started when sending certain touch types.
1011 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
1012 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1014 // Sending a TouchStart will start the timeout.
1015 PressTouchPoint(0, 1);
1016 EXPECT_TRUE(IsTimeoutRunning());
1017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1018 EXPECT_FALSE(IsTimeoutRunning());
1020 // A TouchMove should start the timeout.
1021 MoveTouchPoint(0, 5, 5);
1022 EXPECT_TRUE(IsTimeoutRunning());
1023 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1024 EXPECT_FALSE(IsTimeoutRunning());
1026 // A TouchEnd should not start the timeout.
1027 ReleaseTouchPoint(0);
1028 EXPECT_FALSE(IsTimeoutRunning());
1029 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1030 EXPECT_FALSE(IsTimeoutRunning());
1032 // A TouchCancel should not start the timeout.
1033 PressTouchPoint(0, 1);
1034 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1035 ASSERT_FALSE(IsTimeoutRunning());
1036 CancelTouchPoint(0);
1037 EXPECT_FALSE(IsTimeoutRunning());
1038 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1039 EXPECT_FALSE(IsTimeoutRunning());
1042 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
1043 // disabling touch forwarding until the next TouchStart is received after
1044 // the timeout events are ack'ed.
1045 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
1046 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1048 // Queue a TouchStart.
1049 GetAndResetSentEventCount();
1050 GetAndResetAckedEventCount();
1051 PressTouchPoint(0, 1);
1052 ASSERT_EQ(1U, GetAndResetSentEventCount());
1053 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1054 EXPECT_TRUE(IsTimeoutRunning());
1056 // Delay the ack.
1057 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1059 // The timeout should have fired, synthetically ack'ing the timed-out event.
1060 // TouchEvent forwarding is disabled until the ack is received for the
1061 // timed-out event and the future cancel event.
1062 EXPECT_FALSE(IsTimeoutRunning());
1063 EXPECT_EQ(0U, GetAndResetSentEventCount());
1064 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1066 // Ack'ing the original event should trigger a cancel event.
1067 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1068 EXPECT_FALSE(IsTimeoutRunning());
1069 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1070 EXPECT_EQ(1U, GetAndResetSentEventCount());
1071 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1072 EXPECT_FALSE(sent_event().cancelable);
1074 // Touch events should not be forwarded until we receive the cancel acks.
1075 MoveTouchPoint(0, 1, 1);
1076 ASSERT_EQ(0U, GetAndResetSentEventCount());
1077 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1079 ReleaseTouchPoint(0);
1080 ASSERT_EQ(0U, GetAndResetSentEventCount());
1081 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1083 // The synthetic TouchCancel ack should not reach the client, but should
1084 // resume touch forwarding.
1085 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1086 EXPECT_EQ(0U, GetAndResetSentEventCount());
1087 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1089 // Subsequent events should be handled normally.
1090 PressTouchPoint(0, 1);
1091 EXPECT_EQ(1U, GetAndResetSentEventCount());
1092 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1093 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1094 EXPECT_TRUE(sent_event().cancelable);
1097 // Tests that the timeout is never started if the renderer consumes
1098 // a TouchEvent from the current touch sequence.
1099 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
1100 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1102 // Queue a TouchStart.
1103 PressTouchPoint(0, 1);
1104 ASSERT_TRUE(IsTimeoutRunning());
1106 // Mark the event as consumed. This should prevent the timeout from
1107 // being activated on subsequent TouchEvents in this gesture.
1108 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1109 EXPECT_FALSE(IsTimeoutRunning());
1111 // A TouchMove should not start the timeout.
1112 MoveTouchPoint(0, 5, 5);
1113 EXPECT_FALSE(IsTimeoutRunning());
1114 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1116 // A secondary TouchStart should not start the timeout.
1117 PressTouchPoint(1, 0);
1118 EXPECT_FALSE(IsTimeoutRunning());
1119 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1121 // A TouchEnd should not start the timeout.
1122 ReleaseTouchPoint(1);
1123 EXPECT_FALSE(IsTimeoutRunning());
1124 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1126 // A TouchCancel should not start the timeout.
1127 CancelTouchPoint(0);
1128 EXPECT_FALSE(IsTimeoutRunning());
1131 // Tests that the timeout is never started if the renderer consumes
1132 // a TouchEvent from the current touch sequence.
1133 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) {
1134 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1136 // Queue a TouchStart.
1137 PressTouchPoint(0, 1);
1138 ASSERT_TRUE(IsTimeoutRunning());
1140 // Send the ack immediately. The timeout should not have fired.
1141 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1142 EXPECT_FALSE(IsTimeoutRunning());
1143 EXPECT_TRUE(IsTimeoutEnabled());
1144 EXPECT_EQ(1U, GetAndResetSentEventCount());
1145 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1147 // Now explicitly disable the timeout.
1148 SetAckTimeoutDisabled();
1149 EXPECT_FALSE(IsTimeoutRunning());
1150 EXPECT_FALSE(IsTimeoutEnabled());
1152 // A TouchMove should not start or trigger the timeout.
1153 MoveTouchPoint(0, 5, 5);
1154 EXPECT_FALSE(IsTimeoutRunning());
1155 EXPECT_EQ(1U, GetAndResetSentEventCount());
1156 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1157 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1160 // Tests that the timeout is never started if the ack is synchronous.
1161 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1162 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1164 // Queue a TouchStart.
1165 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1166 ASSERT_FALSE(IsTimeoutRunning());
1167 PressTouchPoint(0, 1);
1168 EXPECT_FALSE(IsTimeoutRunning());
1171 // Tests that the timeout is disabled if the touch handler disappears.
1172 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) {
1173 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1175 // Queue a TouchStart.
1176 PressTouchPoint(0, 1);
1177 ASSERT_TRUE(IsTimeoutRunning());
1179 // Unload the touch handler.
1180 OnHasTouchEventHandlers(false);
1181 EXPECT_FALSE(IsTimeoutRunning());
1184 // Tests that the timeout does not fire if explicitly disabled while an event
1185 // is in-flight.
1186 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
1187 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1189 // Queue a TouchStart.
1190 PressTouchPoint(0, 1);
1191 ASSERT_TRUE(IsTimeoutRunning());
1193 // Verify that disabling the timeout also turns off the timer.
1194 SetAckTimeoutDisabled();
1195 EXPECT_FALSE(IsTimeoutRunning());
1196 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1197 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1200 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1201 // turns into a scroll gesture sequence.
1202 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1203 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1205 // Queue a TouchStart.
1206 PressTouchPoint(0, 1);
1207 EXPECT_TRUE(IsTimeoutRunning());
1208 EXPECT_EQ(1U, GetAndResetSentEventCount());
1210 // The cancelled sequence may turn into a scroll gesture.
1211 WebGestureEvent followup_scroll;
1212 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1213 SetFollowupEvent(followup_scroll);
1215 // Delay the ack.
1216 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1218 // The timeout should have fired, disabling touch forwarding until both acks
1219 // are received, acking the timed out event.
1220 EXPECT_FALSE(IsTimeoutRunning());
1221 EXPECT_EQ(0U, GetAndResetSentEventCount());
1222 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1224 // Ack the original event, triggering a TouchCancel.
1225 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1226 EXPECT_FALSE(IsTimeoutRunning());
1227 EXPECT_EQ(1U, GetAndResetSentEventCount());
1228 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1230 // Ack the cancel event. Normally, this would resume touch forwarding,
1231 // but we're still within a scroll gesture so it remains disabled.
1232 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1233 EXPECT_FALSE(IsTimeoutRunning());
1234 EXPECT_EQ(0U, GetAndResetSentEventCount());
1235 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1237 // Try to forward touch events for the current sequence.
1238 GetAndResetSentEventCount();
1239 GetAndResetAckedEventCount();
1240 MoveTouchPoint(0, 1, 1);
1241 ReleaseTouchPoint(0);
1242 EXPECT_FALSE(IsTimeoutRunning());
1243 EXPECT_EQ(0U, GetAndResetSentEventCount());
1244 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1246 // Now end the scroll sequence, resuming touch handling.
1247 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1248 PressTouchPoint(0, 1);
1249 EXPECT_TRUE(IsTimeoutRunning());
1250 EXPECT_EQ(1U, GetAndResetSentEventCount());
1251 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1254 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1255 // turns into a scroll gesture sequence, but the original event acks are
1256 // significantly delayed.
1257 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1258 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1260 // Queue a TouchStart.
1261 PressTouchPoint(0, 1);
1262 EXPECT_TRUE(IsTimeoutRunning());
1263 EXPECT_EQ(1U, GetAndResetSentEventCount());
1265 // The cancelled sequence may turn into a scroll gesture.
1266 WebGestureEvent followup_scroll;
1267 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1268 SetFollowupEvent(followup_scroll);
1270 // Delay the ack.
1271 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1273 // The timeout should have fired, disabling touch forwarding until both acks
1274 // are received and acking the timed out event.
1275 EXPECT_FALSE(IsTimeoutRunning());
1276 EXPECT_EQ(0U, GetAndResetSentEventCount());
1277 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1279 // Try to forward a touch event.
1280 GetAndResetSentEventCount();
1281 GetAndResetAckedEventCount();
1282 MoveTouchPoint(0, 1, 1);
1283 EXPECT_FALSE(IsTimeoutRunning());
1284 EXPECT_EQ(0U, GetAndResetSentEventCount());
1285 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1287 // Now end the scroll sequence. Events will not be forwarded until the two
1288 // outstanding touch acks are received.
1289 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1290 MoveTouchPoint(0, 2, 2);
1291 ReleaseTouchPoint(0);
1292 EXPECT_FALSE(IsTimeoutRunning());
1293 EXPECT_EQ(0U, GetAndResetSentEventCount());
1294 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1296 // Ack the original event, triggering a cancel.
1297 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1298 EXPECT_EQ(1U, GetAndResetSentEventCount());
1299 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1301 // Ack the cancel event, resuming touch forwarding.
1302 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1303 EXPECT_EQ(0U, GetAndResetSentEventCount());
1304 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1306 PressTouchPoint(0, 1);
1307 EXPECT_TRUE(IsTimeoutRunning());
1308 EXPECT_EQ(1U, GetAndResetSentEventCount());
1311 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1312 // the timed-out event had no consumer.
1313 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1314 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1316 // Queue a TouchStart.
1317 PressTouchPoint(0, 1);
1318 ASSERT_EQ(1U, GetAndResetSentEventCount());
1319 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1320 EXPECT_TRUE(IsTimeoutRunning());
1322 // Delay the ack.
1323 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1325 // The timeout should have fired, synthetically ack'ing the timed out event.
1326 // TouchEvent forwarding is disabled until the original ack is received.
1327 EXPECT_FALSE(IsTimeoutRunning());
1328 EXPECT_EQ(0U, GetAndResetSentEventCount());
1329 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1331 // Touch events should not be forwarded until we receive the original ack.
1332 MoveTouchPoint(0, 1, 1);
1333 ReleaseTouchPoint(0);
1334 ASSERT_EQ(0U, GetAndResetSentEventCount());
1335 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1337 // Ack'ing the original event should not trigger a cancel event, as the
1338 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1339 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1340 EXPECT_FALSE(IsTimeoutRunning());
1341 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1342 EXPECT_EQ(0U, GetAndResetSentEventCount());
1344 // Subsequent events should be handled normally.
1345 PressTouchPoint(0, 1);
1346 EXPECT_EQ(1U, GetAndResetSentEventCount());
1347 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1350 // Tests that TouchMove's are dropped if within the slop suppression region
1351 // for an unconsumed TouchStart
1352 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithinSlopRegion) {
1353 const double kSlopLengthDips = 10.;
1354 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1355 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1357 // Queue a TouchStart.
1358 PressTouchPoint(0, 0);
1359 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1360 ASSERT_EQ(1U, GetAndResetSentEventCount());
1361 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1363 // TouchMove's within the region should be suppressed.
1364 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1365 EXPECT_EQ(0U, queued_event_count());
1366 EXPECT_EQ(0U, GetAndResetSentEventCount());
1367 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1368 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1370 MoveTouchPoint(0, kHalfSlopLengthDips, 0);
1371 EXPECT_EQ(0U, queued_event_count());
1372 EXPECT_EQ(0U, GetAndResetSentEventCount());
1373 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1374 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1376 MoveTouchPoint(0, -kHalfSlopLengthDips, 0);
1377 EXPECT_EQ(0U, queued_event_count());
1378 EXPECT_EQ(0U, GetAndResetSentEventCount());
1379 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1380 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1382 // As soon as a TouchMove exceeds the (Euclidean) distance, no more
1383 // TouchMove's should be suppressed.
1384 const double kFortyFiveDegreeSlopLengthXY =
1385 kSlopLengthDips * std::sqrt(2.) / 2.;
1386 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2,
1387 kFortyFiveDegreeSlopLengthXY + .2);
1388 EXPECT_EQ(1U, queued_event_count());
1389 EXPECT_EQ(1U, GetAndResetSentEventCount());
1390 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1391 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1392 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1394 // Even TouchMove's within the original slop region should now be forwarded.
1395 MoveTouchPoint(0, 0, 0);
1396 EXPECT_EQ(1U, queued_event_count());
1397 EXPECT_EQ(1U, GetAndResetSentEventCount());
1398 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1399 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1400 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1402 // A new touch sequence should reset suppression.
1403 ReleaseTouchPoint(0);
1404 PressTouchPoint(0, 0);
1405 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1406 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1407 ASSERT_EQ(2U, GetAndResetSentEventCount());
1408 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1409 ASSERT_EQ(0U, queued_event_count());
1411 // The slop region is boundary-inclusive.
1412 MoveTouchPoint(0, kSlopLengthDips - 1., 0);
1413 EXPECT_EQ(0U, queued_event_count());
1414 EXPECT_EQ(0U, GetAndResetSentEventCount());
1415 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1417 MoveTouchPoint(0, kSlopLengthDips, 0);
1418 EXPECT_EQ(0U, queued_event_count());
1419 EXPECT_EQ(0U, GetAndResetSentEventCount());
1420 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1423 // Tests that TouchMove's are not dropped within the slop suppression region if
1424 // the touchstart was consumed.
1425 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) {
1426 const double kSlopLengthDips = 10.;
1427 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1428 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1430 // Queue a TouchStart.
1431 PressTouchPoint(0, 0);
1432 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1433 ASSERT_EQ(1U, GetAndResetSentEventCount());
1434 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1436 // TouchMove's within the region should not be suppressed, as a touch was
1437 // consumed.
1438 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1439 EXPECT_EQ(1U, queued_event_count());
1440 EXPECT_EQ(1U, GetAndResetSentEventCount());
1441 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1444 // Tests that TouchMove's are not dropped due to incorrect handling of DPI
1445 // scaling.
1446 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) {
1447 const float kSlopLengthPixels = 7.f;
1448 const float kDPIScale = 3.f;
1449 SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale);
1451 // Queue a TouchStart.
1452 PressTouchPoint(0, 0);
1453 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1454 ASSERT_EQ(1U, GetAndResetSentEventCount());
1455 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1457 // TouchMove's along the slop boundary should be suppresed.
1458 MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale);
1459 EXPECT_EQ(0U, queued_event_count());
1460 EXPECT_EQ(0U, GetAndResetSentEventCount());
1461 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1463 // Reset the touch sequence.
1464 ReleaseTouchPoint(0);
1465 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1467 GetAndResetSentEventCount();
1468 GetAndResetAckedEventCount();
1470 // Queue a TouchStart.
1471 PressTouchPoint(0, 0);
1472 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1473 ASSERT_EQ(1U, GetAndResetSentEventCount());
1474 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1476 // TouchMove's outside the region should not be suppressed.
1477 const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 0.5f;
1478 MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale);
1479 EXPECT_EQ(1U, queued_event_count());
1480 EXPECT_EQ(1U, GetAndResetSentEventCount());
1481 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1484 // Tests that TouchMove's are not dropped if a secondary pointer is present
1485 // during any movement.
1486 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) {
1487 const double kSlopLengthDips = 10.;
1488 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1489 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1491 // Queue a TouchStart.
1492 PressTouchPoint(0, 0);
1493 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1494 ASSERT_EQ(1U, GetAndResetSentEventCount());
1495 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1497 // TouchMove's within the region should be suppressed.
1498 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1499 EXPECT_EQ(0U, queued_event_count());
1500 EXPECT_EQ(0U, GetAndResetSentEventCount());
1501 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1503 // Simulate a secondary pointer press.
1504 PressTouchPoint(kSlopLengthDips, 0);
1505 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1506 EXPECT_EQ(1U, GetAndResetSentEventCount());
1507 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1509 // TouchMove with a secondary pointer should not be suppressed.
1510 MoveTouchPoint(1, kSlopLengthDips, 0);
1511 EXPECT_EQ(1U, queued_event_count());
1512 EXPECT_EQ(1U, GetAndResetSentEventCount());
1513 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1514 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1516 // Release the secondary pointer.
1517 ReleaseTouchPoint(0);
1518 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1519 EXPECT_EQ(1U, GetAndResetSentEventCount());
1520 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1522 // TouchMove's should not should be suppressed, even with the original
1523 // unmoved pointer.
1524 MoveTouchPoint(0, 0, 0);
1525 EXPECT_EQ(1U, queued_event_count());
1526 EXPECT_EQ(1U, GetAndResetSentEventCount());
1527 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1530 // Tests that secondary touch points can be forwarded even if the primary touch
1531 // point had no consumer.
1532 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) {
1533 // Queue a TouchStart.
1534 PressTouchPoint(0, 0);
1535 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1536 ASSERT_EQ(1U, GetAndResetSentEventCount());
1537 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1539 // Events should not be forwarded, as the point had no consumer.
1540 MoveTouchPoint(0, 0, 15);
1541 EXPECT_EQ(0U, queued_event_count());
1542 EXPECT_EQ(0U, GetAndResetSentEventCount());
1543 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1545 // Simulate a secondary pointer press.
1546 PressTouchPoint(20, 0);
1547 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1548 EXPECT_EQ(1U, GetAndResetSentEventCount());
1549 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1551 // TouchMove with a secondary pointer should not be suppressed.
1552 MoveTouchPoint(1, 25, 0);
1553 EXPECT_EQ(1U, queued_event_count());
1554 EXPECT_EQ(1U, GetAndResetSentEventCount());
1555 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1556 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1559 // Tests that no touch points will be forwarded after scrolling begins while no
1560 // touch points have a consumer.
1561 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) {
1562 // Queue a TouchStart.
1563 PressTouchPoint(0, 0);
1564 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1565 ASSERT_EQ(1U, GetAndResetSentEventCount());
1566 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1568 WebGestureEvent followup_scroll;
1569 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1570 SetFollowupEvent(followup_scroll);
1571 MoveTouchPoint(0, 20, 5);
1572 EXPECT_EQ(0U, GetAndResetSentEventCount());
1573 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1574 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1576 // The secondary pointer press should not be forwarded.
1577 PressTouchPoint(20, 0);
1578 EXPECT_EQ(0U, GetAndResetSentEventCount());
1579 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1580 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1582 // Neither should any further touchmoves be forwarded.
1583 MoveTouchPoint(1, 25, 0);
1584 EXPECT_EQ(0U, GetAndResetSentEventCount());
1585 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1586 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1589 TEST_F(TouchEventQueueTest, SyncTouchMoveDoesntCancelTouchOnScroll) {
1590 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE);
1591 // Queue a TouchStart.
1592 PressTouchPoint(0, 1);
1593 EXPECT_EQ(1U, GetAndResetSentEventCount());
1594 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1595 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1597 MoveTouchPoint(0, 20, 5);
1598 EXPECT_EQ(1U, queued_event_count());
1599 EXPECT_EQ(1U, GetAndResetSentEventCount());
1601 // GestureScrollBegin doesn't insert a synthetic TouchCancel.
1602 WebGestureEvent followup_scroll;
1603 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1604 SetFollowupEvent(followup_scroll);
1605 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1606 EXPECT_EQ(0U, GetAndResetSentEventCount());
1607 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1608 EXPECT_EQ(0U, queued_event_count());
1611 TEST_F(TouchEventQueueTest, AsyncTouch) {
1612 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1614 // Queue a TouchStart.
1615 PressTouchPoint(0, 1);
1616 EXPECT_EQ(1U, GetAndResetSentEventCount());
1617 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1618 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1620 for (int i = 0; i < 3; ++i) {
1621 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1622 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1624 MoveTouchPoint(0, 10, 5);
1625 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1626 EXPECT_FALSE(HasPendingAsyncTouchMove());
1627 EXPECT_TRUE(sent_event().cancelable);
1628 EXPECT_EQ(0U, queued_event_count());
1629 EXPECT_EQ(1U, GetAndResetSentEventCount());
1631 // Consuming a scroll event will throttle subsequent touchmoves.
1632 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1633 INPUT_EVENT_ACK_STATE_CONSUMED);
1634 MoveTouchPoint(0, 10, 5);
1635 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1636 EXPECT_TRUE(HasPendingAsyncTouchMove());
1637 EXPECT_EQ(0U, queued_event_count());
1638 EXPECT_EQ(0U, GetAndResetSentEventCount());
1642 // Ensure that touchmove's are appropriately throttled during a typical
1643 // scroll sequences that transitions between scrolls consumed and unconsumed.
1644 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
1645 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1647 // Process a TouchStart
1648 PressTouchPoint(0, 1);
1649 EXPECT_EQ(1U, GetAndResetSentEventCount());
1650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1651 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1653 // Now send the first touch move and associated GestureScrollBegin,
1654 // but don't ACK the gesture event yet.
1655 MoveTouchPoint(0, 0, 5);
1656 WebGestureEvent followup_scroll;
1657 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1658 SetFollowupEvent(followup_scroll);
1659 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1660 EXPECT_EQ(1U, GetAndResetSentEventCount());
1661 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1663 // Now queue a second touchmove and verify it's not (yet) dispatched.
1664 MoveTouchPoint(0, 0, 10);
1665 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1666 EXPECT_TRUE(HasPendingAsyncTouchMove());
1667 EXPECT_EQ(0U, queued_event_count());
1668 EXPECT_EQ(0U, GetAndResetSentEventCount());
1669 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1671 // Queuing the final touchend should flush the pending, async touchmove.
1672 ReleaseTouchPoint(0);
1673 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1674 EXPECT_FALSE(HasPendingAsyncTouchMove());
1675 EXPECT_FALSE(sent_event().cancelable);
1676 EXPECT_EQ(1U, GetAndResetSentEventCount());
1677 EXPECT_EQ(2U, queued_event_count());
1679 // Ack the flushed, async touchmove. The ack should not reach the client, but
1680 // it should trigger sending of the (now non-cancelable) touchend.
1681 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1682 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1683 EXPECT_FALSE(sent_event().cancelable);
1684 EXPECT_EQ(1U, GetAndResetSentEventCount());
1685 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1686 EXPECT_EQ(1U, queued_event_count());
1688 // Ack the touchend.
1689 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1690 EXPECT_EQ(0U, queued_event_count());
1691 EXPECT_EQ(0U, GetAndResetSentEventCount());
1692 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1694 // Now mark the scroll as not consumed (which would cause future
1695 // touchmoves in the active sequence to be sent if there was one).
1696 SendGestureEventAck(WebInputEvent::GestureScrollBegin,
1697 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1699 // Start a new touch sequence and verify that throttling has been reset.
1700 // Touch moves after the start of scrolling will again be throttled.
1701 PressTouchPoint(0, 0);
1702 EXPECT_EQ(1U, GetAndResetSentEventCount());
1703 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1704 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1705 MoveTouchPoint(0, 0, 5);
1706 SetFollowupEvent(followup_scroll);
1707 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1708 EXPECT_EQ(1U, GetAndResetSentEventCount());
1709 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1710 MoveTouchPoint(0, 0, 10);
1711 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1712 EXPECT_TRUE(HasPendingAsyncTouchMove());
1713 EXPECT_EQ(0U, queued_event_count());
1714 EXPECT_EQ(0U, GetAndResetSentEventCount());
1715 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1717 // As soon as a touchmove exceeds the outer slop region it will be forwarded
1718 // immediately.
1719 MoveTouchPoint(0, 0, 20);
1720 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1721 EXPECT_FALSE(HasPendingAsyncTouchMove());
1722 EXPECT_FALSE(sent_event().cancelable);
1723 EXPECT_EQ(0U, queued_event_count());
1724 EXPECT_EQ(1U, GetAndResetSentEventCount());
1725 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1727 // Subsequent touchmove's should be deferred.
1728 MoveTouchPoint(0, 0, 25);
1729 EXPECT_TRUE(HasPendingAsyncTouchMove());
1730 EXPECT_EQ(0U, queued_event_count());
1731 EXPECT_EQ(0U, GetAndResetSentEventCount());
1732 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1734 // The pending touchmove should be flushed with the the new touchmove if
1735 // sufficient time has passed.
1736 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1737 MoveTouchPoint(0, 0, 15);
1738 EXPECT_FALSE(HasPendingAsyncTouchMove());
1739 EXPECT_FALSE(sent_event().cancelable);
1740 EXPECT_EQ(1U, queued_event_count());
1741 EXPECT_EQ(1U, GetAndResetSentEventCount());
1742 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1743 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1744 EXPECT_EQ(0U, queued_event_count());
1745 EXPECT_EQ(0U, GetAndResetSentEventCount());
1746 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1748 // Non-touchmove events should always flush any pending touchmove events.
1749 MoveTouchPoint(0, 0, 25);
1750 EXPECT_TRUE(HasPendingAsyncTouchMove());
1751 EXPECT_EQ(0U, queued_event_count());
1752 EXPECT_EQ(0U, GetAndResetSentEventCount());
1753 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1754 PressTouchPoint(30, 30);
1755 EXPECT_FALSE(HasPendingAsyncTouchMove());
1756 EXPECT_FALSE(sent_event().cancelable);
1757 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1758 EXPECT_EQ(1U, GetAndResetSentEventCount());
1759 EXPECT_EQ(2U, queued_event_count());
1761 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note
1762 // that the flushed touchmove's ack will not reach the client (its
1763 // constituent events have already been ack'ed).
1764 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1765 EXPECT_FALSE(sent_event().cancelable);
1766 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1767 EXPECT_EQ(1U, queued_event_count());
1768 EXPECT_EQ(1U, GetAndResetSentEventCount());
1769 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1771 // Ack the touchstart.
1772 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1773 EXPECT_EQ(0U, queued_event_count());
1774 EXPECT_EQ(0U, GetAndResetSentEventCount());
1775 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1777 // Send a secondary touchmove.
1778 MoveTouchPoint(1, 0, 25);
1779 EXPECT_TRUE(HasPendingAsyncTouchMove());
1780 EXPECT_EQ(0U, queued_event_count());
1781 EXPECT_EQ(0U, GetAndResetSentEventCount());
1782 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1784 // An unconsumed scroll should resume synchronous touch handling.
1785 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1786 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1788 // The pending touchmove should be coalesced with the next (now synchronous)
1789 // touchmove.
1790 MoveTouchPoint(0, 0, 25);
1791 EXPECT_TRUE(sent_event().cancelable);
1792 EXPECT_FALSE(HasPendingAsyncTouchMove());
1793 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1794 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state);
1795 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1796 EXPECT_EQ(1U, queued_event_count());
1797 EXPECT_EQ(1U, GetAndResetSentEventCount());
1798 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1800 // Subsequent touches will queue until the preceding, synchronous touches are
1801 // ack'ed.
1802 ReleaseTouchPoint(1);
1803 EXPECT_EQ(2U, queued_event_count());
1804 ReleaseTouchPoint(0);
1805 EXPECT_EQ(3U, queued_event_count());
1806 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1807 EXPECT_TRUE(sent_event().cancelable);
1808 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1809 EXPECT_EQ(2U, queued_event_count());
1810 EXPECT_EQ(1U, GetAndResetSentEventCount());
1811 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1813 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1814 EXPECT_TRUE(sent_event().cancelable);
1815 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1816 EXPECT_EQ(1U, queued_event_count());
1817 EXPECT_EQ(1U, GetAndResetSentEventCount());
1818 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1820 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1821 EXPECT_EQ(0U, queued_event_count());
1822 EXPECT_EQ(0U, GetAndResetSentEventCount());
1823 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1826 // Ensure that async touch dispatch and touch ack timeout interactions work
1827 // appropriately.
1828 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1829 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1830 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1832 // The touchstart should start the timeout.
1833 PressTouchPoint(0, 0);
1834 EXPECT_EQ(1U, GetAndResetSentEventCount());
1835 EXPECT_TRUE(IsTimeoutRunning());
1837 // The start of a scroll gesture should trigger async touch event dispatch.
1838 WebGestureEvent followup_scroll;
1839 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1840 SetFollowupEvent(followup_scroll);
1841 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1842 EXPECT_FALSE(IsTimeoutRunning());
1843 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1845 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1846 INPUT_EVENT_ACK_STATE_CONSUMED);
1848 // An async touch should fire after the throttling interval has expired, but
1849 // it should not start the touch ack timeout.
1850 MoveTouchPoint(0, 5, 5);
1851 EXPECT_TRUE(HasPendingAsyncTouchMove());
1852 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1854 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1855 MoveTouchPoint(0, 5, 5);
1856 EXPECT_FALSE(IsTimeoutRunning());
1857 EXPECT_FALSE(HasPendingAsyncTouchMove());
1858 EXPECT_FALSE(sent_event().cancelable);
1859 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1860 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1861 EXPECT_EQ(1U, GetAndResetSentEventCount());
1863 // An unconsumed scroll event will resume synchronous touchmoves, which are
1864 // subject to the ack timeout.
1865 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1866 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1867 MoveTouchPoint(0, 20, 5);
1868 EXPECT_TRUE(IsTimeoutRunning());
1869 EXPECT_TRUE(sent_event().cancelable);
1870 EXPECT_EQ(1U, GetAndResetSentEventCount());
1872 // The timeout should fire, disabling touch forwarding until both acks are
1873 // received and acking the timed out event.
1874 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1875 EXPECT_FALSE(IsTimeoutRunning());
1876 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1877 EXPECT_EQ(0U, GetAndResetSentEventCount());
1879 // Ack'ing the original event should trigger a cancel event.
1880 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1881 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1882 EXPECT_FALSE(sent_event().cancelable);
1883 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1884 EXPECT_EQ(1U, GetAndResetSentEventCount());
1886 // Subsequent touchmove's should not be forwarded, even as the scroll gesture
1887 // goes from unconsumed to consumed.
1888 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1889 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1890 MoveTouchPoint(0, 20, 5);
1891 EXPECT_FALSE(HasPendingAsyncTouchMove());
1892 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1893 EXPECT_EQ(0U, GetAndResetSentEventCount());
1895 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1896 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1897 MoveTouchPoint(0, 25, 5);
1898 EXPECT_FALSE(HasPendingAsyncTouchMove());
1899 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1900 EXPECT_EQ(0U, GetAndResetSentEventCount());
1903 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1904 // touch event, that follow-up touch will be forwarded appropriately.
1905 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) {
1906 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1908 PressTouchPoint(0, 0);
1909 EXPECT_EQ(1U, GetAndResetSentEventCount());
1911 // The start of a scroll gesture should trigger async touch event dispatch.
1912 WebGestureEvent followup_scroll;
1913 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1914 SetFollowupEvent(followup_scroll);
1915 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1916 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1917 EXPECT_EQ(0U, queued_event_count());
1919 // The async touchmove should be ack'ed immediately, but not forwarded.
1920 // However, because the ack triggers a touchcancel, both the pending touch and
1921 // the queued touchcancel should be flushed.
1922 WebTouchEvent followup_cancel;
1923 followup_cancel.type = WebInputEvent::TouchCancel;
1924 followup_cancel.touchesLength = 1;
1925 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
1926 SetFollowupEvent(followup_cancel);
1927 MoveTouchPoint(0, 5, 5);
1928 EXPECT_EQ(2U, queued_event_count());
1929 EXPECT_FALSE(sent_event().cancelable);
1930 EXPECT_FALSE(HasPendingAsyncTouchMove());
1931 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
1932 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1933 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1934 EXPECT_EQ(1U, GetAndResetSentEventCount());
1936 // The ack for the asnc touchmove should not reach the client, as it has
1937 // already been ack'ed.
1938 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1939 EXPECT_FALSE(sent_event().cancelable);
1940 EXPECT_EQ(1U, queued_event_count());
1941 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1942 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1943 EXPECT_EQ(1U, GetAndResetSentEventCount());
1945 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1946 EXPECT_EQ(0U, queued_event_count());
1947 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type);
1948 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1949 EXPECT_EQ(0U, GetAndResetSentEventCount());
1952 } // namespace content