Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_event_queue_unittest.cc
blob9066c7126320a744fcb2d1819cb081b6ee8b3c1a
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 void ResetTouchEvent() {
174 touch_event_ = SyntheticWebTouchEvent();
177 size_t GetAndResetAckedEventCount() {
178 size_t count = acked_event_count_;
179 acked_event_count_ = 0;
180 return count;
183 size_t GetAndResetSentEventCount() {
184 size_t count = sent_event_count_;
185 sent_event_count_ = 0;
186 return count;
189 bool IsPendingAckTouchStart() const {
190 return queue_->IsPendingAckTouchStart();
193 void OnHasTouchEventHandlers(bool has_handlers) {
194 queue_->OnHasTouchEventHandlers(has_handlers);
197 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); }
199 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); }
201 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); }
203 bool HasPendingAsyncTouchMove() const {
204 return queue_->HasPendingAsyncTouchMoveForTesting();
207 size_t queued_event_count() const {
208 return queue_->size();
211 const WebTouchEvent& latest_event() const {
212 return queue_->GetLatestEventForTesting().event;
215 const WebTouchEvent& acked_event() const {
216 return last_acked_event_;
219 const WebTouchEvent& sent_event() const {
220 return last_sent_event_;
223 InputEventAckState acked_event_state() const {
224 return last_acked_event_state_;
227 static void RunTasksAndWait(base::TimeDelta delay) {
228 base::MessageLoop::current()->PostDelayedTask(
229 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
230 base::MessageLoop::current()->Run();
233 private:
234 void SendTouchEvent() {
235 SendTouchEvent(touch_event_);
236 touch_event_.ResetPoints();
239 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
240 queue_.reset(new TouchEventQueue(this, config));
241 queue_->OnHasTouchEventHandlers(true);
244 scoped_ptr<TouchEventQueue> queue_;
245 size_t sent_event_count_;
246 size_t acked_event_count_;
247 WebTouchEvent last_sent_event_;
248 WebTouchEvent last_acked_event_;
249 InputEventAckState last_acked_event_state_;
250 SyntheticWebTouchEvent touch_event_;
251 scoped_ptr<WebTouchEvent> followup_touch_event_;
252 scoped_ptr<WebGestureEvent> followup_gesture_event_;
253 scoped_ptr<InputEventAckState> sync_ack_result_;
254 double slop_length_dips_;
255 TouchEventQueue::TouchScrollingMode touch_scrolling_mode_;
256 base::MessageLoopForUI message_loop_;
260 // Tests that touch-events are queued properly.
261 TEST_F(TouchEventQueueTest, Basic) {
262 PressTouchPoint(1, 1);
263 EXPECT_EQ(1U, queued_event_count());
264 EXPECT_EQ(1U, GetAndResetSentEventCount());
266 // The second touch should not be sent since one is already in queue.
267 MoveTouchPoint(0, 5, 5);
268 EXPECT_EQ(2U, queued_event_count());
269 EXPECT_EQ(0U, GetAndResetSentEventCount());
271 // Receive an ACK for the first touch-event.
272 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
273 EXPECT_EQ(1U, queued_event_count());
274 EXPECT_EQ(1U, GetAndResetSentEventCount());
275 EXPECT_EQ(1U, GetAndResetAckedEventCount());
276 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
277 EXPECT_TRUE(acked_event().cancelable);
279 // Receive an ACK for the second touch-event.
280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
281 EXPECT_EQ(0U, queued_event_count());
282 EXPECT_EQ(0U, GetAndResetSentEventCount());
283 EXPECT_EQ(1U, GetAndResetAckedEventCount());
284 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
285 EXPECT_TRUE(acked_event().cancelable);
288 // Tests that the touch-queue is emptied if a page stops listening for touch
289 // events.
290 TEST_F(TouchEventQueueTest, QueueFlushedWhenHandlersRemoved) {
291 OnHasTouchEventHandlers(true);
292 EXPECT_EQ(0U, queued_event_count());
293 EXPECT_EQ(0U, GetAndResetSentEventCount());
295 // Send a touch-press event.
296 PressTouchPoint(1, 1);
297 EXPECT_EQ(1U, GetAndResetSentEventCount());
299 ReleaseTouchPoint(0);
301 // Events will be queued until the first sent event is ack'ed.
302 for (int i = 5; i < 15; ++i) {
303 PressTouchPoint(1, 1);
304 MoveTouchPoint(0, i, i);
305 ReleaseTouchPoint(0);
307 EXPECT_EQ(32U, queued_event_count());
308 EXPECT_EQ(0U, GetAndResetSentEventCount());
310 // Receive an ACK for the first touch-event. One of the queued touch-event
311 // should be forwarded.
312 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
313 EXPECT_EQ(31U, queued_event_count());
314 EXPECT_EQ(1U, GetAndResetSentEventCount());
315 EXPECT_EQ(1U, GetAndResetAckedEventCount());
316 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
318 // Flush the queue. The touch-event queue should now be emptied, but none of
319 // the queued touch-events should be sent to the renderer.
320 OnHasTouchEventHandlers(false);
321 EXPECT_EQ(0U, queued_event_count());
322 EXPECT_EQ(0U, GetAndResetSentEventCount());
323 EXPECT_EQ(31U, GetAndResetAckedEventCount());
326 // Tests that addition of a touch handler during a touch sequence will not cause
327 // the remaining sequence to be forwarded.
328 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) {
329 OnHasTouchEventHandlers(false);
331 // Send a touch-press event while there is no handler.
332 PressTouchPoint(1, 1);
333 EXPECT_EQ(1U, GetAndResetAckedEventCount());
334 EXPECT_EQ(0U, GetAndResetSentEventCount());
335 EXPECT_EQ(0U, queued_event_count());
337 OnHasTouchEventHandlers(true);
339 // The remaining touch sequence should not be forwarded.
340 MoveTouchPoint(0, 5, 5);
341 ReleaseTouchPoint(0);
342 EXPECT_EQ(2U, GetAndResetAckedEventCount());
343 EXPECT_EQ(0U, GetAndResetSentEventCount());
344 EXPECT_EQ(0U, queued_event_count());
346 // A new touch sequence should resume forwarding.
347 PressTouchPoint(1, 1);
348 EXPECT_EQ(1U, queued_event_count());
349 EXPECT_EQ(1U, GetAndResetSentEventCount());
352 // Tests that removal of a touch handler during a touch sequence will prevent
353 // the remaining sequence from being forwarded, even if another touch handler is
354 // registered during the same touch sequence.
355 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
356 // Send a touch-press event.
357 PressTouchPoint(1, 1);
358 EXPECT_EQ(1U, GetAndResetSentEventCount());
359 EXPECT_EQ(1U, queued_event_count());
361 // Queue a touch-move event.
362 MoveTouchPoint(0, 5, 5);
363 EXPECT_EQ(2U, queued_event_count());
364 EXPECT_EQ(0U, GetAndResetAckedEventCount());
365 EXPECT_EQ(0U, GetAndResetSentEventCount());
367 // Touch handle deregistration should flush the queue.
368 OnHasTouchEventHandlers(false);
369 EXPECT_EQ(2U, GetAndResetAckedEventCount());
370 EXPECT_EQ(0U, queued_event_count());
372 // The ack should be ignored as the touch queue is now empty.
373 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
374 EXPECT_EQ(0U, GetAndResetAckedEventCount());
375 EXPECT_EQ(0U, queued_event_count());
377 // Events should be dropped while there is no touch handler.
378 MoveTouchPoint(0, 10, 10);
379 EXPECT_EQ(0U, queued_event_count());
380 EXPECT_EQ(1U, GetAndResetAckedEventCount());
381 EXPECT_EQ(0U, GetAndResetSentEventCount());
383 // Simulate touch handler registration in the middle of a touch sequence.
384 OnHasTouchEventHandlers(true);
386 // The touch end for the interrupted sequence should be dropped.
387 ReleaseTouchPoint(0);
388 EXPECT_EQ(0U, queued_event_count());
389 EXPECT_EQ(1U, GetAndResetAckedEventCount());
390 EXPECT_EQ(0U, GetAndResetSentEventCount());
392 // A new touch sequence should be forwarded properly.
393 PressTouchPoint(1, 1);
394 EXPECT_EQ(1U, queued_event_count());
395 EXPECT_EQ(1U, GetAndResetSentEventCount());
398 // Tests that touch-events are coalesced properly in the queue.
399 TEST_F(TouchEventQueueTest, Coalesce) {
400 // Send a touch-press event.
401 PressTouchPoint(1, 1);
402 EXPECT_EQ(1U, GetAndResetSentEventCount());
404 // Send a few touch-move events, followed by a touch-release event. All the
405 // touch-move events should be coalesced into a single event.
406 for (int i = 5; i < 15; ++i)
407 MoveTouchPoint(0, i, i);
409 EXPECT_EQ(0U, GetAndResetSentEventCount());
410 ReleaseTouchPoint(0);
411 EXPECT_EQ(0U, GetAndResetSentEventCount());
412 EXPECT_EQ(3U, queued_event_count());
414 // ACK the press. Coalesced touch-move events should be sent.
415 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
416 EXPECT_EQ(2U, queued_event_count());
417 EXPECT_EQ(1U, GetAndResetSentEventCount());
418 EXPECT_EQ(1U, GetAndResetAckedEventCount());
419 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
420 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
422 // ACK the moves.
423 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
424 EXPECT_EQ(1U, queued_event_count());
425 EXPECT_EQ(1U, GetAndResetSentEventCount());
426 EXPECT_EQ(10U, GetAndResetAckedEventCount());
427 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
429 // ACK the release.
430 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
431 EXPECT_EQ(0U, queued_event_count());
432 EXPECT_EQ(0U, GetAndResetSentEventCount());
433 EXPECT_EQ(1U, GetAndResetAckedEventCount());
434 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
437 // Tests that an event that has already been sent but hasn't been ack'ed yet
438 // doesn't get coalesced with newer events.
439 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
440 // Send a touch-press event.
441 PressTouchPoint(1, 1);
442 EXPECT_EQ(1U, GetAndResetSentEventCount());
444 // Send a few touch-move events, followed by a touch-release event. All the
445 // touch-move events should be coalesced into a single event.
446 for (int i = 5; i < 15; ++i)
447 MoveTouchPoint(0, i, i);
449 EXPECT_EQ(0U, GetAndResetSentEventCount());
450 EXPECT_EQ(2U, queued_event_count());
452 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
453 EXPECT_EQ(1U, GetAndResetSentEventCount());
454 EXPECT_EQ(1U, queued_event_count());
456 // The coalesced touch-move event has been sent to the renderer. Any new
457 // touch-move event should not be coalesced with the sent event.
458 MoveTouchPoint(0, 5, 5);
459 EXPECT_EQ(2U, queued_event_count());
461 MoveTouchPoint(0, 7, 7);
462 EXPECT_EQ(2U, queued_event_count());
465 // Tests that coalescing works correctly for multi-touch events.
466 TEST_F(TouchEventQueueTest, MultiTouch) {
467 // Press the first finger.
468 PressTouchPoint(1, 1);
469 EXPECT_EQ(1U, GetAndResetSentEventCount());
471 // Move the finger.
472 MoveTouchPoint(0, 5, 5);
473 EXPECT_EQ(2U, queued_event_count());
475 // Now press a second finger.
476 PressTouchPoint(2, 2);
477 EXPECT_EQ(3U, queued_event_count());
479 // Move both fingers.
480 MoveTouchPoints(0, 10, 10, 1, 20, 20);
481 MoveTouchPoint(1, 20, 20);
482 EXPECT_EQ(4U, queued_event_count());
484 // Move only one finger now.
485 MoveTouchPoint(0, 15, 15);
486 EXPECT_EQ(4U, queued_event_count());
488 // Move the other finger.
489 MoveTouchPoint(1, 25, 25);
490 EXPECT_EQ(4U, queued_event_count());
492 // Make sure both fingers are marked as having been moved in the coalesced
493 // event.
494 const WebTouchEvent& event = latest_event();
495 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
496 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
499 // Tests that if a touch-event queue is destroyed in response to a touch-event
500 // in the renderer, then there is no crash when the ACK for that touch-event
501 // comes back.
502 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) {
503 // Send some touch-events to the renderer.
504 PressTouchPoint(1, 1);
505 EXPECT_EQ(1U, GetAndResetSentEventCount());
506 EXPECT_EQ(1U, queued_event_count());
508 MoveTouchPoint(0, 10, 10);
509 EXPECT_EQ(0U, GetAndResetSentEventCount());
510 EXPECT_EQ(2U, queued_event_count());
512 // Receive an ACK for the press. This should cause the queued touch-move to
513 // be sent to the renderer.
514 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
515 EXPECT_EQ(1U, GetAndResetSentEventCount());
516 EXPECT_EQ(1U, queued_event_count());
518 OnHasTouchEventHandlers(false);
519 EXPECT_EQ(0U, GetAndResetSentEventCount());
520 EXPECT_EQ(0U, queued_event_count());
522 // Now receive an ACK for the move.
523 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
524 EXPECT_EQ(0U, GetAndResetSentEventCount());
525 EXPECT_EQ(0U, queued_event_count());
528 // Tests that touch-move events are not sent to the renderer if the preceding
529 // touch-press event did not have a consumer (and consequently, did not hit the
530 // main thread in the renderer). Also tests that all queued/coalesced touch
531 // events are flushed immediately when the ACK for the touch-press comes back
532 // with NO_CONSUMER status.
533 TEST_F(TouchEventQueueTest, NoConsumer) {
534 // The first touch-press should reach the renderer.
535 PressTouchPoint(1, 1);
536 EXPECT_EQ(1U, GetAndResetSentEventCount());
538 // The second touch should not be sent since one is already in queue.
539 MoveTouchPoint(0, 5, 5);
540 EXPECT_EQ(0U, GetAndResetSentEventCount());
541 EXPECT_EQ(2U, queued_event_count());
543 // Receive an ACK for the first touch-event. This should release the queued
544 // touch-event, but it should not be sent to the renderer.
545 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
546 EXPECT_EQ(0U, queued_event_count());
547 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
548 EXPECT_EQ(2U, GetAndResetAckedEventCount());
549 EXPECT_EQ(0U, GetAndResetSentEventCount());
551 // Send a release event. This should not reach the renderer.
552 ReleaseTouchPoint(0);
553 EXPECT_EQ(0U, GetAndResetSentEventCount());
554 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
555 EXPECT_EQ(1U, GetAndResetAckedEventCount());
557 // Send a press-event, followed by move and release events, and another press
558 // event, before the ACK for the first press event comes back. All of the
559 // events should be queued first. After the NO_CONSUMER ack for the first
560 // touch-press, all events upto the second touch-press should be flushed.
561 PressTouchPoint(10, 10);
562 EXPECT_EQ(1U, GetAndResetSentEventCount());
564 MoveTouchPoint(0, 5, 5);
565 MoveTouchPoint(0, 6, 5);
566 ReleaseTouchPoint(0);
568 PressTouchPoint(6, 5);
569 EXPECT_EQ(0U, GetAndResetSentEventCount());
570 // The queue should hold the first sent touch-press event, the coalesced
571 // touch-move event, the touch-end event and the second touch-press event.
572 EXPECT_EQ(4U, queued_event_count());
574 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
575 EXPECT_EQ(1U, GetAndResetSentEventCount());
576 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
577 EXPECT_EQ(4U, GetAndResetAckedEventCount());
578 EXPECT_EQ(1U, queued_event_count());
580 // ACK the second press event as NO_CONSUMER too.
581 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
582 EXPECT_EQ(0U, GetAndResetSentEventCount());
583 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
584 EXPECT_EQ(1U, GetAndResetAckedEventCount());
585 EXPECT_EQ(0U, queued_event_count());
587 // Send a second press event. Even though the first touch press had
588 // NO_CONSUMER, this press event should reach the renderer.
589 PressTouchPoint(1, 1);
590 EXPECT_EQ(1U, GetAndResetSentEventCount());
591 EXPECT_EQ(1U, queued_event_count());
592 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
593 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
594 EXPECT_EQ(1U, GetAndResetAckedEventCount());
597 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
598 // Press two touch points and move them around a bit. The renderer consumes
599 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for
600 // the second touch point.
602 PressTouchPoint(1, 1);
603 EXPECT_EQ(1U, GetAndResetSentEventCount());
605 MoveTouchPoint(0, 5, 5);
607 PressTouchPoint(10, 10);
609 MoveTouchPoint(0, 2, 2);
611 MoveTouchPoint(1, 4, 10);
613 MoveTouchPoints(0, 10, 10, 1, 20, 20);
615 // Since the first touch-press is still pending ACK, no other event should
616 // have been sent to the renderer.
617 EXPECT_EQ(0U, GetAndResetSentEventCount());
618 // The queue includes the two presses, the first touch-move of the first
619 // point, and a coalesced touch-move of both points.
620 EXPECT_EQ(4U, queued_event_count());
622 // ACK the first press as CONSUMED. This should cause the first touch-move of
623 // the first touch-point to be dispatched.
624 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
625 EXPECT_EQ(1U, GetAndResetSentEventCount());
626 EXPECT_EQ(3U, queued_event_count());
628 // ACK the first move as CONSUMED.
629 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
630 EXPECT_EQ(1U, GetAndResetSentEventCount());
631 EXPECT_EQ(2U, queued_event_count());
633 // ACK the second press as NO_CONSUMER_EXISTS. This will dequeue the coalesced
634 // touch-move event (which contains both touch points). Although the second
635 // touch-point does not need to be sent to the renderer, the first touch-point
636 // did move, and so the coalesced touch-event will be sent to the renderer.
637 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
638 EXPECT_EQ(1U, GetAndResetSentEventCount());
639 EXPECT_EQ(1U, queued_event_count());
641 // ACK the coalesced move as NOT_CONSUMED.
642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
643 EXPECT_EQ(0U, GetAndResetSentEventCount());
644 EXPECT_EQ(0U, queued_event_count());
646 // Move just the second touch point. Because the first touch point did not
647 // move, this event should not reach the renderer.
648 MoveTouchPoint(1, 30, 30);
649 EXPECT_EQ(0U, GetAndResetSentEventCount());
650 EXPECT_EQ(0U, queued_event_count());
652 // Move just the first touch point. This should reach the renderer.
653 MoveTouchPoint(0, 10, 10);
654 EXPECT_EQ(1U, GetAndResetSentEventCount());
655 EXPECT_EQ(1U, queued_event_count());
657 // Move both fingers. This event should reach the renderer (after the ACK of
658 // the previous move event is received), because the first touch point did
659 // move.
660 MoveTouchPoints(0, 15, 15, 1, 25, 25);
661 EXPECT_EQ(0U, GetAndResetSentEventCount());
663 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
664 EXPECT_EQ(1U, GetAndResetSentEventCount());
665 EXPECT_EQ(1U, queued_event_count());
667 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
668 EXPECT_EQ(0U, GetAndResetSentEventCount());
669 EXPECT_EQ(0U, queued_event_count());
671 // Release the first finger. Then move the second finger around some, then
672 // press another finger. Once the release event is ACKed, the move events of
673 // the second finger should be immediately released to the view, and the
674 // touch-press event should be dispatched to the renderer.
675 ReleaseTouchPoint(0);
676 EXPECT_EQ(1U, GetAndResetSentEventCount());
677 EXPECT_EQ(1U, queued_event_count());
679 MoveTouchPoint(1, 40, 40);
681 MoveTouchPoint(1, 50, 50);
683 PressTouchPoint(1, 1);
685 MoveTouchPoint(1, 30, 30);
686 EXPECT_EQ(0U, GetAndResetSentEventCount());
687 EXPECT_EQ(4U, queued_event_count());
689 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
690 EXPECT_EQ(1U, GetAndResetSentEventCount());
691 EXPECT_EQ(2U, queued_event_count());
692 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
694 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued
695 // touch-move events to the view.
696 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
697 EXPECT_EQ(0U, GetAndResetSentEventCount());
698 EXPECT_EQ(0U, queued_event_count());
699 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
701 ReleaseTouchPoint(2);
702 ReleaseTouchPoint(1);
703 EXPECT_EQ(0U, GetAndResetSentEventCount());
704 EXPECT_EQ(0U, queued_event_count());
707 // Tests that touch-event's enqueued via a touch ack are properly handled.
708 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
709 // Queue a touch down.
710 PressTouchPoint(1, 1);
711 EXPECT_EQ(1U, queued_event_count());
712 EXPECT_EQ(1U, GetAndResetSentEventCount());
713 EXPECT_EQ(0U, GetAndResetAckedEventCount());
715 // Create a touch event that will be queued synchronously by a touch ack.
716 // Note, this will be triggered by all subsequent touch acks.
717 WebTouchEvent followup_event;
718 followup_event.type = WebInputEvent::TouchStart;
719 followup_event.touchesLength = 1;
720 followup_event.touches[0].id = 1;
721 followup_event.touches[0].state = WebTouchPoint::StatePressed;
722 SetFollowupEvent(followup_event);
724 // Receive an ACK for the press. This should cause the followup touch-move to
725 // be sent to the renderer.
726 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
727 EXPECT_EQ(1U, queued_event_count());
728 EXPECT_EQ(1U, GetAndResetSentEventCount());
729 EXPECT_EQ(1U, GetAndResetAckedEventCount());
730 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
731 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
733 // Queue another event.
734 MoveTouchPoint(0, 2, 2);
735 EXPECT_EQ(2U, queued_event_count());
737 // Receive an ACK for the touch-move followup event. This should cause the
738 // subsequent touch move event be sent to the renderer.
739 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
740 EXPECT_EQ(1U, queued_event_count());
741 EXPECT_EQ(1U, GetAndResetSentEventCount());
742 EXPECT_EQ(1U, GetAndResetAckedEventCount());
745 // Tests that touch-events can be synchronously ack'ed.
746 TEST_F(TouchEventQueueTest, SynchronousAcks) {
747 // TouchStart
748 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
749 PressTouchPoint(1, 1);
750 EXPECT_EQ(0U, queued_event_count());
751 EXPECT_EQ(1U, GetAndResetSentEventCount());
752 EXPECT_EQ(1U, GetAndResetAckedEventCount());
754 // TouchMove
755 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
756 MoveTouchPoint(0, 2, 2);
757 EXPECT_EQ(0U, queued_event_count());
758 EXPECT_EQ(1U, GetAndResetSentEventCount());
759 EXPECT_EQ(1U, GetAndResetAckedEventCount());
761 // TouchEnd
762 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
763 ReleaseTouchPoint(0);
764 EXPECT_EQ(0U, queued_event_count());
765 EXPECT_EQ(1U, GetAndResetSentEventCount());
766 EXPECT_EQ(1U, GetAndResetAckedEventCount());
768 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
769 PressTouchPoint(1, 1);
770 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
771 EXPECT_EQ(0U, queued_event_count());
772 EXPECT_EQ(1U, GetAndResetSentEventCount());
773 EXPECT_EQ(1U, GetAndResetAckedEventCount());
775 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
776 CancelTouchPoint(0);
777 EXPECT_EQ(0U, queued_event_count());
778 EXPECT_EQ(1U, GetAndResetSentEventCount());
779 EXPECT_EQ(1U, GetAndResetAckedEventCount());
782 // Tests that followup events triggered by an immediate ack from
783 // TouchEventQueue::QueueEvent() are properly handled.
784 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
785 // Create a touch event that will be queued synchronously by a touch ack.
786 WebTouchEvent followup_event;
787 followup_event.type = WebInputEvent::TouchStart;
788 followup_event.touchesLength = 1;
789 followup_event.touches[0].id = 1;
790 followup_event.touches[0].state = WebTouchPoint::StatePressed;
791 SetFollowupEvent(followup_event);
793 // Now, enqueue a stationary touch that will not be forwarded. This should be
794 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
795 // then be enqueued and immediately sent to the renderer.
796 WebTouchEvent stationary_event;
797 stationary_event.touchesLength = 1;
798 stationary_event.type = WebInputEvent::TouchMove;
799 stationary_event.touches[0].id = 1;
800 stationary_event.touches[0].state = WebTouchPoint::StateStationary;
801 SendTouchEvent(stationary_event);
803 EXPECT_EQ(1U, queued_event_count());
804 EXPECT_EQ(1U, GetAndResetSentEventCount());
805 EXPECT_EQ(1U, GetAndResetAckedEventCount());
806 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
807 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
810 // Tests basic TouchEvent forwarding suppression.
811 TEST_F(TouchEventQueueTest, NoTouchBasic) {
812 // Disable TouchEvent forwarding.
813 OnHasTouchEventHandlers(false);
814 PressTouchPoint(30, 5);
815 EXPECT_EQ(0U, GetAndResetSentEventCount());
816 EXPECT_EQ(1U, GetAndResetAckedEventCount());
818 // TouchMove should not be sent to renderer.
819 MoveTouchPoint(0, 65, 10);
820 EXPECT_EQ(0U, GetAndResetSentEventCount());
821 EXPECT_EQ(1U, GetAndResetAckedEventCount());
823 // TouchEnd should not be sent to renderer.
824 ReleaseTouchPoint(0);
825 EXPECT_EQ(0U, GetAndResetSentEventCount());
826 EXPECT_EQ(1U, GetAndResetAckedEventCount());
828 // Enable TouchEvent forwarding.
829 OnHasTouchEventHandlers(true);
831 PressTouchPoint(80, 10);
832 EXPECT_EQ(1U, GetAndResetSentEventCount());
833 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
834 EXPECT_EQ(1U, GetAndResetAckedEventCount());
836 MoveTouchPoint(0, 80, 20);
837 EXPECT_EQ(1U, GetAndResetSentEventCount());
838 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
839 EXPECT_EQ(1U, GetAndResetAckedEventCount());
841 ReleaseTouchPoint(0);
842 EXPECT_EQ(1U, GetAndResetSentEventCount());
843 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
844 EXPECT_EQ(1U, GetAndResetAckedEventCount());
847 // Tests that no TouchEvents are sent to renderer during scrolling.
848 TEST_F(TouchEventQueueTest, TouchCancelOnScroll) {
849 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
850 // Queue a TouchStart.
851 PressTouchPoint(0, 1);
852 EXPECT_EQ(1U, GetAndResetSentEventCount());
853 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
854 EXPECT_EQ(1U, GetAndResetAckedEventCount());
856 MoveTouchPoint(0, 20, 5);
857 EXPECT_EQ(1U, queued_event_count());
858 EXPECT_EQ(1U, GetAndResetSentEventCount());
860 MoveTouchPoint(0, 30, 15);
861 EXPECT_EQ(2U, queued_event_count());
862 EXPECT_EQ(0U, GetAndResetSentEventCount());
864 // Queue another TouchStart.
865 PressTouchPoint(20, 20);
866 EXPECT_EQ(3U, queued_event_count());
867 EXPECT_EQ(0U, GetAndResetSentEventCount());
868 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
870 WebGestureEvent followup_scroll;
871 followup_scroll.type = WebInputEvent::GestureScrollBegin;
872 SetFollowupEvent(followup_scroll);
873 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
874 EXPECT_EQ(1U, GetAndResetSentEventCount());
875 EXPECT_EQ(1U, GetAndResetAckedEventCount());
876 EXPECT_EQ(2U, queued_event_count());
877 EXPECT_TRUE(sent_event().cancelable);
878 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
880 // GestureScrollUpdate inserts a synthetic TouchCancel before the TouchStart.
881 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
882 SetFollowupEvent(followup_scroll);
883 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
884 EXPECT_EQ(1U, GetAndResetSentEventCount());
885 EXPECT_EQ(1U, GetAndResetAckedEventCount());
886 EXPECT_EQ(2U, queued_event_count());
887 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
888 EXPECT_FALSE(sent_event().cancelable);
889 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
891 // Acking the TouchCancel will result in dispatch of the next TouchStart.
892 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
893 // The synthetic TouchCancel should not reach client, only the TouchStart.
894 EXPECT_EQ(1U, GetAndResetAckedEventCount());
895 EXPECT_EQ(0U, GetAndResetSentEventCount());
896 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
898 // TouchMove should not be sent to the renderer.
899 MoveTouchPoint(0, 30, 5);
900 EXPECT_EQ(1U, GetAndResetAckedEventCount());
901 EXPECT_EQ(0U, GetAndResetSentEventCount());
902 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
904 // GestureScrollUpdates should not change affect touch forwarding.
905 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
907 // TouchEnd should not be sent to the renderer.
908 ReleaseTouchPoint(0);
909 EXPECT_EQ(1U, GetAndResetAckedEventCount());
910 EXPECT_EQ(0U, GetAndResetSentEventCount());
911 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
913 ReleaseTouchPoint(0);
914 EXPECT_EQ(1U, GetAndResetAckedEventCount());
915 EXPECT_EQ(0U, GetAndResetSentEventCount());
916 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
918 // Touch events from a new gesture sequence should be forwarded normally.
919 PressTouchPoint(80, 10);
920 EXPECT_EQ(1U, GetAndResetSentEventCount());
921 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
922 EXPECT_EQ(1U, GetAndResetAckedEventCount());
924 MoveTouchPoint(0, 80, 20);
925 EXPECT_EQ(1U, GetAndResetSentEventCount());
926 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
927 EXPECT_EQ(1U, GetAndResetAckedEventCount());
929 ReleaseTouchPoint(0);
930 EXPECT_EQ(1U, GetAndResetSentEventCount());
931 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
932 EXPECT_EQ(1U, GetAndResetAckedEventCount());
935 // Tests that a scroll event will not insert a synthetic TouchCancel if there
936 // was no consumer for the current touch sequence.
937 TEST_F(TouchEventQueueTest, NoTouchCancelOnScrollIfNoConsumer) {
938 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL);
940 // Queue a TouchStart.
941 PressTouchPoint(0, 1);
942 EXPECT_EQ(1U, GetAndResetSentEventCount());
943 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
944 EXPECT_EQ(1U, GetAndResetAckedEventCount());
945 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
947 // Queue a TouchMove that turns into a GestureScrollBegin.
948 WebGestureEvent followup_scroll;
949 followup_scroll.type = WebInputEvent::GestureScrollBegin;
950 SetFollowupEvent(followup_scroll);
951 MoveTouchPoint(0, 20, 5);
953 // The TouchMove has no consumer, and should be ack'ed immediately. However,
954 // *no* synthetic TouchCancel should be inserted as the touch sequence
955 // had no consumer.
956 EXPECT_EQ(0U, queued_event_count());
957 EXPECT_EQ(0U, GetAndResetSentEventCount());
958 EXPECT_EQ(1U, GetAndResetAckedEventCount());
959 EXPECT_EQ(0U, queued_event_count());
960 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
962 // Subsequent TouchMove's should not be sent to the renderer.
963 MoveTouchPoint(0, 30, 5);
964 EXPECT_EQ(1U, GetAndResetAckedEventCount());
965 EXPECT_EQ(0U, GetAndResetSentEventCount());
966 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
968 // TouchEnd should not be sent to the renderer.
969 ReleaseTouchPoint(0);
970 EXPECT_EQ(1U, GetAndResetAckedEventCount());
971 EXPECT_EQ(0U, GetAndResetSentEventCount());
972 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
974 // Touch events from a new gesture sequence should be forwarded normally.
975 PressTouchPoint(80, 10);
976 EXPECT_EQ(1U, GetAndResetSentEventCount());
977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
978 EXPECT_EQ(1U, GetAndResetAckedEventCount());
981 // Tests that IsTouchStartPendingAck works correctly.
982 TEST_F(TouchEventQueueTest, PendingStart) {
984 EXPECT_FALSE(IsPendingAckTouchStart());
986 // Send the touchstart for one point (#1).
987 PressTouchPoint(1, 1);
988 EXPECT_EQ(1U, queued_event_count());
989 EXPECT_TRUE(IsPendingAckTouchStart());
991 // Send a touchmove for that point (#2).
992 MoveTouchPoint(0, 5, 5);
993 EXPECT_EQ(2U, queued_event_count());
994 EXPECT_TRUE(IsPendingAckTouchStart());
996 // Ack the touchstart (#1).
997 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
998 EXPECT_EQ(1U, queued_event_count());
999 EXPECT_FALSE(IsPendingAckTouchStart());
1001 // Send a touchstart for another point (#3).
1002 PressTouchPoint(10, 10);
1003 EXPECT_EQ(2U, queued_event_count());
1004 EXPECT_FALSE(IsPendingAckTouchStart());
1006 // Ack the touchmove (#2).
1007 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1008 EXPECT_EQ(1U, queued_event_count());
1009 EXPECT_TRUE(IsPendingAckTouchStart());
1011 // Send a touchstart for a third point (#4).
1012 PressTouchPoint(15, 15);
1013 EXPECT_EQ(2U, queued_event_count());
1014 EXPECT_TRUE(IsPendingAckTouchStart());
1016 // Ack the touchstart for the second point (#3).
1017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1018 EXPECT_EQ(1U, queued_event_count());
1019 EXPECT_TRUE(IsPendingAckTouchStart());
1021 // Ack the touchstart for the third point (#4).
1022 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1023 EXPECT_EQ(0U, queued_event_count());
1024 EXPECT_FALSE(IsPendingAckTouchStart());
1027 // Tests that the touch timeout is started when sending certain touch types.
1028 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
1029 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1031 // Sending a TouchStart will start the timeout.
1032 PressTouchPoint(0, 1);
1033 EXPECT_TRUE(IsTimeoutRunning());
1034 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1035 EXPECT_FALSE(IsTimeoutRunning());
1037 // A TouchMove should start the timeout.
1038 MoveTouchPoint(0, 5, 5);
1039 EXPECT_TRUE(IsTimeoutRunning());
1040 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1041 EXPECT_FALSE(IsTimeoutRunning());
1043 // A TouchEnd should not start the timeout.
1044 ReleaseTouchPoint(0);
1045 EXPECT_FALSE(IsTimeoutRunning());
1046 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1047 EXPECT_FALSE(IsTimeoutRunning());
1049 // A TouchCancel should not start the timeout.
1050 PressTouchPoint(0, 1);
1051 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1052 ASSERT_FALSE(IsTimeoutRunning());
1053 CancelTouchPoint(0);
1054 EXPECT_FALSE(IsTimeoutRunning());
1055 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1056 EXPECT_FALSE(IsTimeoutRunning());
1059 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
1060 // disabling touch forwarding until the next TouchStart is received after
1061 // the timeout events are ack'ed.
1062 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
1063 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1065 // Queue a TouchStart.
1066 GetAndResetSentEventCount();
1067 GetAndResetAckedEventCount();
1068 PressTouchPoint(0, 1);
1069 ASSERT_EQ(1U, GetAndResetSentEventCount());
1070 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1071 EXPECT_TRUE(IsTimeoutRunning());
1073 // Delay the ack.
1074 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1076 // The timeout should have fired, synthetically ack'ing the timed-out event.
1077 // TouchEvent forwarding is disabled until the ack is received for the
1078 // timed-out event and the future cancel event.
1079 EXPECT_FALSE(IsTimeoutRunning());
1080 EXPECT_EQ(0U, GetAndResetSentEventCount());
1081 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1083 // Ack'ing the original event should trigger a cancel event.
1084 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1085 EXPECT_FALSE(IsTimeoutRunning());
1086 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1087 EXPECT_EQ(1U, GetAndResetSentEventCount());
1088 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
1089 EXPECT_FALSE(sent_event().cancelable);
1091 // Touch events should not be forwarded until we receive the cancel acks.
1092 MoveTouchPoint(0, 1, 1);
1093 ASSERT_EQ(0U, GetAndResetSentEventCount());
1094 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1096 ReleaseTouchPoint(0);
1097 ASSERT_EQ(0U, GetAndResetSentEventCount());
1098 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1100 // The synthetic TouchCancel ack should not reach the client, but should
1101 // resume touch forwarding.
1102 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1103 EXPECT_EQ(0U, GetAndResetSentEventCount());
1104 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1106 // Subsequent events should be handled normally.
1107 PressTouchPoint(0, 1);
1108 EXPECT_EQ(1U, GetAndResetSentEventCount());
1109 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1110 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1111 EXPECT_TRUE(sent_event().cancelable);
1114 // Tests that the timeout is never started if the renderer consumes
1115 // a TouchEvent from the current touch sequence.
1116 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
1117 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1119 // Queue a TouchStart.
1120 PressTouchPoint(0, 1);
1121 ASSERT_TRUE(IsTimeoutRunning());
1123 // Mark the event as consumed. This should prevent the timeout from
1124 // being activated on subsequent TouchEvents in this gesture.
1125 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1126 EXPECT_FALSE(IsTimeoutRunning());
1128 // A TouchMove should not start the timeout.
1129 MoveTouchPoint(0, 5, 5);
1130 EXPECT_FALSE(IsTimeoutRunning());
1131 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1133 // A secondary TouchStart should not start the timeout.
1134 PressTouchPoint(1, 0);
1135 EXPECT_FALSE(IsTimeoutRunning());
1136 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1138 // A TouchEnd should not start the timeout.
1139 ReleaseTouchPoint(1);
1140 EXPECT_FALSE(IsTimeoutRunning());
1141 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1143 // A TouchCancel should not start the timeout.
1144 CancelTouchPoint(0);
1145 EXPECT_FALSE(IsTimeoutRunning());
1148 // Tests that the timeout is never started if the renderer consumes
1149 // a TouchEvent from the current touch sequence.
1150 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) {
1151 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1153 // Queue a TouchStart.
1154 PressTouchPoint(0, 1);
1155 ASSERT_TRUE(IsTimeoutRunning());
1157 // Send the ack immediately. The timeout should not have fired.
1158 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1159 EXPECT_FALSE(IsTimeoutRunning());
1160 EXPECT_TRUE(IsTimeoutEnabled());
1161 EXPECT_EQ(1U, GetAndResetSentEventCount());
1162 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1164 // Now explicitly disable the timeout.
1165 SetAckTimeoutDisabled();
1166 EXPECT_FALSE(IsTimeoutRunning());
1167 EXPECT_FALSE(IsTimeoutEnabled());
1169 // A TouchMove should not start or trigger the timeout.
1170 MoveTouchPoint(0, 5, 5);
1171 EXPECT_FALSE(IsTimeoutRunning());
1172 EXPECT_EQ(1U, GetAndResetSentEventCount());
1173 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1174 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1177 // Tests that the timeout is never started if the ack is synchronous.
1178 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1179 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1181 // Queue a TouchStart.
1182 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1183 ASSERT_FALSE(IsTimeoutRunning());
1184 PressTouchPoint(0, 1);
1185 EXPECT_FALSE(IsTimeoutRunning());
1188 // Tests that the timeout is disabled if the touch handler disappears.
1189 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) {
1190 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1192 // Queue a TouchStart.
1193 PressTouchPoint(0, 1);
1194 ASSERT_TRUE(IsTimeoutRunning());
1196 // Unload the touch handler.
1197 OnHasTouchEventHandlers(false);
1198 EXPECT_FALSE(IsTimeoutRunning());
1201 // Tests that the timeout does not fire if explicitly disabled while an event
1202 // is in-flight.
1203 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
1204 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1206 // Queue a TouchStart.
1207 PressTouchPoint(0, 1);
1208 ASSERT_TRUE(IsTimeoutRunning());
1210 // Verify that disabling the timeout also turns off the timer.
1211 SetAckTimeoutDisabled();
1212 EXPECT_FALSE(IsTimeoutRunning());
1213 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1214 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1217 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1218 // turns into a scroll gesture sequence.
1219 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1220 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1222 // Queue a TouchStart.
1223 PressTouchPoint(0, 1);
1224 EXPECT_TRUE(IsTimeoutRunning());
1225 EXPECT_EQ(1U, GetAndResetSentEventCount());
1227 // The cancelled sequence may turn into a scroll gesture.
1228 WebGestureEvent followup_scroll;
1229 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1230 SetFollowupEvent(followup_scroll);
1232 // Delay the ack.
1233 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1235 // The timeout should have fired, disabling touch forwarding until both acks
1236 // are received, acking the timed out event.
1237 EXPECT_FALSE(IsTimeoutRunning());
1238 EXPECT_EQ(0U, GetAndResetSentEventCount());
1239 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1241 // Ack the original event, triggering a TouchCancel.
1242 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1243 EXPECT_FALSE(IsTimeoutRunning());
1244 EXPECT_EQ(1U, GetAndResetSentEventCount());
1245 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1247 // Ack the cancel event. Normally, this would resume touch forwarding,
1248 // but we're still within a scroll gesture so it remains disabled.
1249 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1250 EXPECT_FALSE(IsTimeoutRunning());
1251 EXPECT_EQ(0U, GetAndResetSentEventCount());
1252 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1254 // Try to forward touch events for the current sequence.
1255 GetAndResetSentEventCount();
1256 GetAndResetAckedEventCount();
1257 MoveTouchPoint(0, 1, 1);
1258 ReleaseTouchPoint(0);
1259 EXPECT_FALSE(IsTimeoutRunning());
1260 EXPECT_EQ(0U, GetAndResetSentEventCount());
1261 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1263 // Now end the scroll sequence, resuming touch handling.
1264 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1265 PressTouchPoint(0, 1);
1266 EXPECT_TRUE(IsTimeoutRunning());
1267 EXPECT_EQ(1U, GetAndResetSentEventCount());
1268 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1271 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1272 // turns into a scroll gesture sequence, but the original event acks are
1273 // significantly delayed.
1274 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1275 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1277 // Queue a TouchStart.
1278 PressTouchPoint(0, 1);
1279 EXPECT_TRUE(IsTimeoutRunning());
1280 EXPECT_EQ(1U, GetAndResetSentEventCount());
1282 // The cancelled sequence may turn into a scroll gesture.
1283 WebGestureEvent followup_scroll;
1284 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1285 SetFollowupEvent(followup_scroll);
1287 // Delay the ack.
1288 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1290 // The timeout should have fired, disabling touch forwarding until both acks
1291 // are received and acking the timed out event.
1292 EXPECT_FALSE(IsTimeoutRunning());
1293 EXPECT_EQ(0U, GetAndResetSentEventCount());
1294 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1296 // Try to forward a touch event.
1297 GetAndResetSentEventCount();
1298 GetAndResetAckedEventCount();
1299 MoveTouchPoint(0, 1, 1);
1300 EXPECT_FALSE(IsTimeoutRunning());
1301 EXPECT_EQ(0U, GetAndResetSentEventCount());
1302 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1304 // Now end the scroll sequence. Events will not be forwarded until the two
1305 // outstanding touch acks are received.
1306 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1307 MoveTouchPoint(0, 2, 2);
1308 ReleaseTouchPoint(0);
1309 EXPECT_FALSE(IsTimeoutRunning());
1310 EXPECT_EQ(0U, GetAndResetSentEventCount());
1311 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1313 // Ack the original event, triggering a cancel.
1314 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1315 EXPECT_EQ(1U, GetAndResetSentEventCount());
1316 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1318 // Ack the cancel event, resuming touch forwarding.
1319 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1320 EXPECT_EQ(0U, GetAndResetSentEventCount());
1321 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1323 PressTouchPoint(0, 1);
1324 EXPECT_TRUE(IsTimeoutRunning());
1325 EXPECT_EQ(1U, GetAndResetSentEventCount());
1328 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1329 // the timed-out event had no consumer.
1330 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1331 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1333 // Queue a TouchStart.
1334 PressTouchPoint(0, 1);
1335 ASSERT_EQ(1U, GetAndResetSentEventCount());
1336 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1337 EXPECT_TRUE(IsTimeoutRunning());
1339 // Delay the ack.
1340 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1342 // The timeout should have fired, synthetically ack'ing the timed out event.
1343 // TouchEvent forwarding is disabled until the original ack is received.
1344 EXPECT_FALSE(IsTimeoutRunning());
1345 EXPECT_EQ(0U, GetAndResetSentEventCount());
1346 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1348 // Touch events should not be forwarded until we receive the original ack.
1349 MoveTouchPoint(0, 1, 1);
1350 ReleaseTouchPoint(0);
1351 ASSERT_EQ(0U, GetAndResetSentEventCount());
1352 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1354 // Ack'ing the original event should not trigger a cancel event, as the
1355 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1356 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1357 EXPECT_FALSE(IsTimeoutRunning());
1358 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1359 EXPECT_EQ(0U, GetAndResetSentEventCount());
1361 // Subsequent events should be handled normally.
1362 PressTouchPoint(0, 1);
1363 EXPECT_EQ(1U, GetAndResetSentEventCount());
1364 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1367 // Tests that TouchMove's are dropped if within the boundary-inclusive slop
1368 // suppression region for an unconsumed TouchStart.
1369 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) {
1370 const double kSlopLengthDips = 10.;
1371 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1372 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1374 // Queue a TouchStart.
1375 PressTouchPoint(0, 0);
1376 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1377 ASSERT_EQ(1U, GetAndResetSentEventCount());
1378 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1380 // TouchMove's within the region should be suppressed.
1381 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1382 EXPECT_EQ(0U, queued_event_count());
1383 EXPECT_EQ(0U, GetAndResetSentEventCount());
1384 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1385 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1387 MoveTouchPoint(0, kHalfSlopLengthDips, 0);
1388 EXPECT_EQ(0U, queued_event_count());
1389 EXPECT_EQ(0U, GetAndResetSentEventCount());
1390 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1391 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1393 MoveTouchPoint(0, -kHalfSlopLengthDips, 0);
1394 EXPECT_EQ(0U, queued_event_count());
1395 EXPECT_EQ(0U, GetAndResetSentEventCount());
1396 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1397 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1399 MoveTouchPoint(0, -kSlopLengthDips, 0);
1400 EXPECT_EQ(0U, queued_event_count());
1401 EXPECT_EQ(0U, GetAndResetSentEventCount());
1402 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1403 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1405 MoveTouchPoint(0, 0, kSlopLengthDips);
1406 EXPECT_EQ(0U, queued_event_count());
1407 EXPECT_EQ(0U, GetAndResetSentEventCount());
1408 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1409 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1411 // As soon as a TouchMove exceeds the (Euclidean) distance, no more
1412 // TouchMove's should be suppressed.
1413 const double kFortyFiveDegreeSlopLengthXY =
1414 kSlopLengthDips * std::sqrt(2.) / 2.;
1415 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2,
1416 kFortyFiveDegreeSlopLengthXY + .2);
1417 EXPECT_EQ(1U, queued_event_count());
1418 EXPECT_EQ(1U, GetAndResetSentEventCount());
1419 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1420 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1421 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1423 // Even TouchMove's within the original slop region should now be forwarded.
1424 MoveTouchPoint(0, 0, 0);
1425 EXPECT_EQ(1U, queued_event_count());
1426 EXPECT_EQ(1U, GetAndResetSentEventCount());
1427 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1428 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1429 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1431 // A new touch sequence should reset suppression.
1432 ReleaseTouchPoint(0);
1433 PressTouchPoint(0, 0);
1434 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1435 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1436 ASSERT_EQ(2U, GetAndResetSentEventCount());
1437 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1438 ASSERT_EQ(0U, queued_event_count());
1440 // The slop region is boundary-inclusive.
1441 MoveTouchPoint(0, kSlopLengthDips - 1., 0);
1442 EXPECT_EQ(0U, queued_event_count());
1443 EXPECT_EQ(0U, GetAndResetSentEventCount());
1444 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1446 MoveTouchPoint(0, kSlopLengthDips, 0);
1447 EXPECT_EQ(0U, queued_event_count());
1448 EXPECT_EQ(0U, GetAndResetSentEventCount());
1449 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1452 // Tests that TouchMove's are not dropped within the slop suppression region if
1453 // the touchstart was consumed.
1454 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) {
1455 const double kSlopLengthDips = 10.;
1456 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1457 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1459 // Queue a TouchStart.
1460 PressTouchPoint(0, 0);
1461 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1462 ASSERT_EQ(1U, GetAndResetSentEventCount());
1463 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1465 // TouchMove's within the region should not be suppressed, as a touch was
1466 // consumed.
1467 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1468 EXPECT_EQ(1U, queued_event_count());
1469 EXPECT_EQ(1U, GetAndResetSentEventCount());
1470 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1473 // Tests that even very small TouchMove's are not suppressed when suppression is
1474 // disabled.
1475 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionIfDisabled) {
1476 // Queue a TouchStart.
1477 PressTouchPoint(0, 0);
1478 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1479 ASSERT_EQ(1U, GetAndResetSentEventCount());
1480 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1482 // Small TouchMove's should not be suppressed.
1483 MoveTouchPoint(0, 0.001f, 0.001f);
1484 EXPECT_EQ(1U, queued_event_count());
1485 EXPECT_EQ(1U, GetAndResetSentEventCount());
1486 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1489 // Tests that TouchMove's are not dropped due to incorrect handling of DPI
1490 // scaling.
1491 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) {
1492 const float kSlopLengthPixels = 7.f;
1493 const float kDPIScale = 3.f;
1494 SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale);
1496 // Queue a TouchStart.
1497 PressTouchPoint(0, 0);
1498 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1499 ASSERT_EQ(1U, GetAndResetSentEventCount());
1500 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1502 // TouchMove's along the slop boundary should be suppresed.
1503 MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale);
1504 EXPECT_EQ(0U, queued_event_count());
1505 EXPECT_EQ(0U, GetAndResetSentEventCount());
1506 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1508 // Reset the touch sequence.
1509 ReleaseTouchPoint(0);
1510 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1511 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1512 GetAndResetSentEventCount();
1513 GetAndResetAckedEventCount();
1515 // Queue a TouchStart.
1516 PressTouchPoint(0, 0);
1517 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1518 ASSERT_EQ(1U, GetAndResetSentEventCount());
1519 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1521 // TouchMove's outside the region should not be suppressed.
1522 const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 0.5f;
1523 MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale);
1524 EXPECT_EQ(1U, queued_event_count());
1525 EXPECT_EQ(1U, GetAndResetSentEventCount());
1526 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1529 // Tests that TouchMove's are not dropped if a secondary pointer is present
1530 // during any movement.
1531 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) {
1532 const double kSlopLengthDips = 10.;
1533 const double kHalfSlopLengthDips = kSlopLengthDips / 2;
1534 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1536 // Queue a TouchStart.
1537 PressTouchPoint(0, 0);
1538 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1539 ASSERT_EQ(1U, GetAndResetSentEventCount());
1540 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1542 // TouchMove's within the region should be suppressed.
1543 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1544 EXPECT_EQ(0U, queued_event_count());
1545 EXPECT_EQ(0U, GetAndResetSentEventCount());
1546 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1548 // Simulate a secondary pointer press.
1549 PressTouchPoint(kSlopLengthDips, 0);
1550 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1551 EXPECT_EQ(1U, GetAndResetSentEventCount());
1552 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1554 // TouchMove with a secondary pointer should not be suppressed.
1555 MoveTouchPoint(1, kSlopLengthDips, 0);
1556 EXPECT_EQ(1U, queued_event_count());
1557 EXPECT_EQ(1U, GetAndResetSentEventCount());
1558 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1559 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1561 // Release the secondary pointer.
1562 ReleaseTouchPoint(0);
1563 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1564 EXPECT_EQ(1U, GetAndResetSentEventCount());
1565 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1567 // TouchMove's should not should be suppressed, even with the original
1568 // unmoved pointer.
1569 MoveTouchPoint(0, 0, 0);
1570 EXPECT_EQ(1U, queued_event_count());
1571 EXPECT_EQ(1U, GetAndResetSentEventCount());
1572 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1575 // Tests that secondary touch points can be forwarded even if the primary touch
1576 // point had no consumer.
1577 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) {
1578 // Queue a TouchStart.
1579 PressTouchPoint(0, 0);
1580 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1581 ASSERT_EQ(1U, GetAndResetSentEventCount());
1582 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1584 // Events should not be forwarded, as the point had no consumer.
1585 MoveTouchPoint(0, 0, 15);
1586 EXPECT_EQ(0U, queued_event_count());
1587 EXPECT_EQ(0U, GetAndResetSentEventCount());
1588 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1590 // Simulate a secondary pointer press.
1591 PressTouchPoint(20, 0);
1592 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1593 EXPECT_EQ(1U, GetAndResetSentEventCount());
1594 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1596 // TouchMove with a secondary pointer should not be suppressed.
1597 MoveTouchPoint(1, 25, 0);
1598 EXPECT_EQ(1U, queued_event_count());
1599 EXPECT_EQ(1U, GetAndResetSentEventCount());
1600 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1601 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1604 // Tests that no touch points will be forwarded after scrolling begins while no
1605 // touch points have a consumer.
1606 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) {
1607 // Queue a TouchStart.
1608 PressTouchPoint(0, 0);
1609 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1610 ASSERT_EQ(1U, GetAndResetSentEventCount());
1611 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1613 WebGestureEvent followup_scroll;
1614 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1615 SetFollowupEvent(followup_scroll);
1616 MoveTouchPoint(0, 20, 5);
1617 EXPECT_EQ(0U, GetAndResetSentEventCount());
1618 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1619 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1621 // The secondary pointer press should not be forwarded.
1622 PressTouchPoint(20, 0);
1623 EXPECT_EQ(0U, GetAndResetSentEventCount());
1624 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1625 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1627 // Neither should any further touchmoves be forwarded.
1628 MoveTouchPoint(1, 25, 0);
1629 EXPECT_EQ(0U, GetAndResetSentEventCount());
1630 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1631 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1634 TEST_F(TouchEventQueueTest, SyncTouchMoveDoesntCancelTouchOnScroll) {
1635 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE);
1636 // Queue a TouchStart.
1637 PressTouchPoint(0, 1);
1638 EXPECT_EQ(1U, GetAndResetSentEventCount());
1639 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1640 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1642 MoveTouchPoint(0, 20, 5);
1643 EXPECT_EQ(1U, queued_event_count());
1644 EXPECT_EQ(1U, GetAndResetSentEventCount());
1646 // GestureScrollBegin doesn't insert a synthetic TouchCancel.
1647 WebGestureEvent followup_scroll;
1648 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1649 SetFollowupEvent(followup_scroll);
1650 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1651 EXPECT_EQ(0U, GetAndResetSentEventCount());
1652 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1653 EXPECT_EQ(0U, queued_event_count());
1656 TEST_F(TouchEventQueueTest, AsyncTouch) {
1657 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1659 // Queue a TouchStart.
1660 PressTouchPoint(0, 1);
1661 EXPECT_EQ(1U, GetAndResetSentEventCount());
1662 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1663 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1665 for (int i = 0; i < 3; ++i) {
1666 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1667 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1669 MoveTouchPoint(0, 10, 5);
1670 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1671 EXPECT_FALSE(HasPendingAsyncTouchMove());
1672 EXPECT_TRUE(sent_event().cancelable);
1673 EXPECT_EQ(0U, queued_event_count());
1674 EXPECT_EQ(1U, GetAndResetSentEventCount());
1676 // Consuming a scroll event will throttle subsequent touchmoves.
1677 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1678 INPUT_EVENT_ACK_STATE_CONSUMED);
1679 MoveTouchPoint(0, 10, 5);
1680 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1681 EXPECT_TRUE(HasPendingAsyncTouchMove());
1682 EXPECT_EQ(0U, queued_event_count());
1683 EXPECT_EQ(0U, GetAndResetSentEventCount());
1687 // Ensure that touchmove's are appropriately throttled during a typical
1688 // scroll sequences that transitions between scrolls consumed and unconsumed.
1689 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
1690 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1692 // Process a TouchStart
1693 PressTouchPoint(0, 1);
1694 EXPECT_EQ(1U, GetAndResetSentEventCount());
1695 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1696 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1698 // Now send the first touch move and associated GestureScrollBegin.
1699 MoveTouchPoint(0, 0, 5);
1700 WebGestureEvent followup_scroll;
1701 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1702 SetFollowupEvent(followup_scroll);
1703 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1704 EXPECT_EQ(1U, GetAndResetSentEventCount());
1705 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1706 SendGestureEventAck(WebInputEvent::GestureScrollBegin,
1707 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1709 // Send the second touch move and associated GestureScrollUpdate, but don't
1710 // ACK the gesture event yet.
1711 MoveTouchPoint(0, 0, 50);
1712 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1713 SetFollowupEvent(followup_scroll);
1714 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1715 EXPECT_EQ(1U, GetAndResetSentEventCount());
1716 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1718 // Now queue a second touchmove and verify it's not (yet) dispatched.
1719 MoveTouchPoint(0, 0, 100);
1720 SetFollowupEvent(followup_scroll);
1721 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1722 EXPECT_TRUE(HasPendingAsyncTouchMove());
1723 EXPECT_EQ(0U, queued_event_count());
1724 EXPECT_EQ(0U, GetAndResetSentEventCount());
1725 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1727 // Queuing the final touchend should flush the pending, async touchmove.
1728 ReleaseTouchPoint(0);
1729 followup_scroll.type = WebInputEvent::GestureScrollEnd;
1730 SetFollowupEvent(followup_scroll);
1731 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1732 EXPECT_FALSE(HasPendingAsyncTouchMove());
1733 EXPECT_FALSE(sent_event().cancelable);
1734 EXPECT_EQ(1U, GetAndResetSentEventCount());
1735 EXPECT_EQ(2U, queued_event_count());
1737 // Ack the flushed, async touchmove. The ack should not reach the client, but
1738 // it should trigger sending of the (now non-cancelable) touchend.
1739 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1740 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1741 EXPECT_FALSE(sent_event().cancelable);
1742 EXPECT_EQ(1U, GetAndResetSentEventCount());
1743 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1744 EXPECT_EQ(1U, queued_event_count());
1746 // Ack the touchend.
1747 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1748 EXPECT_EQ(0U, queued_event_count());
1749 EXPECT_EQ(0U, GetAndResetSentEventCount());
1750 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1752 // Now mark the scrolls as not consumed (which would cause future touchmoves
1753 // in the active sequence to be sent if there was one).
1754 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1755 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1756 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1757 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1759 // Start a new touch sequence and verify that throttling has been reset.
1760 // Touch moves after the start of scrolling will again be throttled.
1761 PressTouchPoint(0, 0);
1762 EXPECT_EQ(1U, GetAndResetSentEventCount());
1763 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1764 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1765 MoveTouchPoint(0, 0, 5);
1766 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1767 SetFollowupEvent(followup_scroll);
1768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1769 EXPECT_EQ(1U, GetAndResetSentEventCount());
1770 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1772 MoveTouchPoint(0, 0, 5);
1773 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1774 SetFollowupEvent(followup_scroll);
1775 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1776 EXPECT_FALSE(HasPendingAsyncTouchMove());
1777 EXPECT_EQ(1U, GetAndResetSentEventCount());
1778 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1780 MoveTouchPoint(0, 0, 10);
1781 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1782 EXPECT_TRUE(HasPendingAsyncTouchMove());
1783 EXPECT_EQ(0U, queued_event_count());
1784 EXPECT_EQ(0U, GetAndResetSentEventCount());
1785 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1787 // As soon as a touchmove exceeds the outer slop region it will be forwarded
1788 // immediately.
1789 MoveTouchPoint(0, 0, 20);
1790 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1791 EXPECT_FALSE(HasPendingAsyncTouchMove());
1792 EXPECT_FALSE(sent_event().cancelable);
1793 EXPECT_EQ(0U, queued_event_count());
1794 EXPECT_EQ(1U, GetAndResetSentEventCount());
1795 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1797 // Subsequent touchmove's should be deferred.
1798 MoveTouchPoint(0, 0, 25);
1799 EXPECT_TRUE(HasPendingAsyncTouchMove());
1800 EXPECT_EQ(0U, queued_event_count());
1801 EXPECT_EQ(0U, GetAndResetSentEventCount());
1802 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1804 // The pending touchmove should be flushed with the the new touchmove if
1805 // sufficient time has passed.
1806 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1807 MoveTouchPoint(0, 0, 15);
1808 EXPECT_FALSE(HasPendingAsyncTouchMove());
1809 EXPECT_FALSE(sent_event().cancelable);
1810 EXPECT_EQ(1U, queued_event_count());
1811 EXPECT_EQ(1U, GetAndResetSentEventCount());
1812 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1813 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1814 EXPECT_EQ(0U, queued_event_count());
1815 EXPECT_EQ(0U, GetAndResetSentEventCount());
1816 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1818 // Non-touchmove events should always flush any pending touchmove events.
1819 MoveTouchPoint(0, 0, 25);
1820 EXPECT_TRUE(HasPendingAsyncTouchMove());
1821 EXPECT_EQ(0U, queued_event_count());
1822 EXPECT_EQ(0U, GetAndResetSentEventCount());
1823 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1824 PressTouchPoint(30, 30);
1825 EXPECT_FALSE(HasPendingAsyncTouchMove());
1826 EXPECT_FALSE(sent_event().cancelable);
1827 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1828 EXPECT_EQ(1U, GetAndResetSentEventCount());
1829 EXPECT_EQ(2U, queued_event_count());
1831 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note
1832 // that the flushed touchmove's ack will not reach the client (its
1833 // constituent events have already been ack'ed).
1834 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1835 EXPECT_FALSE(sent_event().cancelable);
1836 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
1837 EXPECT_EQ(1U, queued_event_count());
1838 EXPECT_EQ(1U, GetAndResetSentEventCount());
1839 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1841 // Ack the touchstart.
1842 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1843 EXPECT_EQ(0U, queued_event_count());
1844 EXPECT_EQ(0U, GetAndResetSentEventCount());
1845 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1847 // Send a secondary touchmove.
1848 MoveTouchPoint(1, 0, 25);
1849 EXPECT_TRUE(HasPendingAsyncTouchMove());
1850 EXPECT_EQ(0U, queued_event_count());
1851 EXPECT_EQ(0U, GetAndResetSentEventCount());
1852 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1854 // An unconsumed scroll should resume synchronous touch handling.
1855 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1856 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1858 // The pending touchmove should be coalesced with the next (now synchronous)
1859 // touchmove.
1860 MoveTouchPoint(0, 0, 25);
1861 EXPECT_TRUE(sent_event().cancelable);
1862 EXPECT_FALSE(HasPendingAsyncTouchMove());
1863 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1864 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state);
1865 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1866 EXPECT_EQ(1U, queued_event_count());
1867 EXPECT_EQ(1U, GetAndResetSentEventCount());
1868 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1870 // Subsequent touches will queue until the preceding, synchronous touches are
1871 // ack'ed.
1872 ReleaseTouchPoint(1);
1873 EXPECT_EQ(2U, queued_event_count());
1874 ReleaseTouchPoint(0);
1875 EXPECT_EQ(3U, queued_event_count());
1876 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1877 EXPECT_TRUE(sent_event().cancelable);
1878 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1879 EXPECT_EQ(2U, queued_event_count());
1880 EXPECT_EQ(1U, GetAndResetSentEventCount());
1881 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1883 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1884 EXPECT_TRUE(sent_event().cancelable);
1885 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1886 EXPECT_EQ(1U, queued_event_count());
1887 EXPECT_EQ(1U, GetAndResetSentEventCount());
1888 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1890 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1891 EXPECT_EQ(0U, queued_event_count());
1892 EXPECT_EQ(0U, GetAndResetSentEventCount());
1893 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1896 // Ensure that async touch dispatch and touch ack timeout interactions work
1897 // appropriately.
1898 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1899 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1900 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1902 // The touchstart should start the timeout.
1903 PressTouchPoint(0, 0);
1904 EXPECT_EQ(1U, GetAndResetSentEventCount());
1905 EXPECT_TRUE(IsTimeoutRunning());
1906 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1907 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1908 EXPECT_FALSE(IsTimeoutRunning());
1910 // The start of a scroll gesture should trigger async touch event dispatch.
1911 MoveTouchPoint(0, 1, 1);
1912 EXPECT_EQ(1U, GetAndResetSentEventCount());
1913 EXPECT_TRUE(IsTimeoutRunning());
1914 WebGestureEvent followup_scroll;
1915 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1916 SetFollowupEvent(followup_scroll);
1917 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1918 EXPECT_FALSE(IsTimeoutRunning());
1919 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1921 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1922 INPUT_EVENT_ACK_STATE_CONSUMED);
1924 // An async touch should fire after the throttling interval has expired, but
1925 // it should not start the touch ack timeout.
1926 MoveTouchPoint(0, 5, 5);
1927 EXPECT_TRUE(HasPendingAsyncTouchMove());
1928 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1930 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1931 MoveTouchPoint(0, 5, 5);
1932 EXPECT_FALSE(IsTimeoutRunning());
1933 EXPECT_FALSE(HasPendingAsyncTouchMove());
1934 EXPECT_FALSE(sent_event().cancelable);
1935 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1936 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1937 EXPECT_EQ(1U, GetAndResetSentEventCount());
1939 // An unconsumed scroll event will resume synchronous touchmoves, which are
1940 // subject to the ack timeout.
1941 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1942 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1943 MoveTouchPoint(0, 20, 5);
1944 EXPECT_TRUE(IsTimeoutRunning());
1945 EXPECT_TRUE(sent_event().cancelable);
1946 EXPECT_EQ(1U, GetAndResetSentEventCount());
1948 // The timeout should fire, disabling touch forwarding until both acks are
1949 // received and acking the timed out event.
1950 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1951 EXPECT_FALSE(IsTimeoutRunning());
1952 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1953 EXPECT_EQ(0U, GetAndResetSentEventCount());
1955 // Ack'ing the original event should trigger a cancel event.
1956 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1957 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1958 EXPECT_FALSE(sent_event().cancelable);
1959 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1960 EXPECT_EQ(1U, GetAndResetSentEventCount());
1962 // Subsequent touchmove's should not be forwarded, even as the scroll gesture
1963 // goes from unconsumed to consumed.
1964 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1965 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1966 MoveTouchPoint(0, 20, 5);
1967 EXPECT_FALSE(HasPendingAsyncTouchMove());
1968 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1969 EXPECT_EQ(0U, GetAndResetSentEventCount());
1971 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1972 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1973 MoveTouchPoint(0, 25, 5);
1974 EXPECT_FALSE(HasPendingAsyncTouchMove());
1975 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1976 EXPECT_EQ(0U, GetAndResetSentEventCount());
1979 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1980 // touch event, that follow-up touch will be forwarded appropriately.
1981 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) {
1982 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
1984 PressTouchPoint(0, 0);
1985 EXPECT_EQ(1U, GetAndResetSentEventCount());
1986 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1987 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1989 // The start of a scroll gesture should trigger async touch event dispatch.
1990 MoveTouchPoint(0, 1, 1);
1991 EXPECT_EQ(1U, GetAndResetSentEventCount());
1992 WebGestureEvent followup_scroll;
1993 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1994 SetFollowupEvent(followup_scroll);
1995 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1996 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1997 EXPECT_EQ(0U, queued_event_count());
1999 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
2001 // The async touchmove should be ack'ed immediately, but not forwarded.
2002 // However, because the ack triggers a touchcancel, both the pending touch and
2003 // the queued touchcancel should be flushed.
2004 WebTouchEvent followup_cancel;
2005 followup_cancel.type = WebInputEvent::TouchCancel;
2006 followup_cancel.touchesLength = 1;
2007 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
2008 SetFollowupEvent(followup_cancel);
2009 MoveTouchPoint(0, 5, 5);
2010 EXPECT_EQ(2U, queued_event_count());
2011 EXPECT_FALSE(sent_event().cancelable);
2012 EXPECT_FALSE(HasPendingAsyncTouchMove());
2013 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
2014 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2015 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2016 EXPECT_EQ(1U, GetAndResetSentEventCount());
2018 // The ack for the async touchmove should not reach the client, as it has
2019 // already been ack'ed.
2020 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2021 EXPECT_FALSE(sent_event().cancelable);
2022 EXPECT_EQ(1U, queued_event_count());
2023 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
2024 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2025 EXPECT_EQ(1U, GetAndResetSentEventCount());
2027 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2028 EXPECT_EQ(0U, queued_event_count());
2029 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type);
2030 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2031 EXPECT_EQ(0U, GetAndResetSentEventCount());
2034 // Ensure that the async touch is fully reset if the touch sequence restarts
2035 // without properly terminating.
2036 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) {
2037 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
2039 PressTouchPoint(0, 0);
2040 EXPECT_EQ(1U, GetAndResetSentEventCount());
2041 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2042 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2044 // Trigger async touchmove dispatch.
2045 MoveTouchPoint(0, 1, 1);
2046 EXPECT_EQ(1U, GetAndResetSentEventCount());
2047 WebGestureEvent followup_scroll;
2048 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2049 SetFollowupEvent(followup_scroll);
2050 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2051 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2052 EXPECT_EQ(0U, queued_event_count());
2053 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
2055 // The async touchmove should be immediately ack'ed but delivery is deferred.
2056 MoveTouchPoint(0, 2, 2);
2057 EXPECT_EQ(0U, GetAndResetSentEventCount());
2058 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2059 EXPECT_EQ(0U, queued_event_count());
2060 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
2062 // The queue should be robust to hard touch restarts with a new touch
2063 // sequence. In this case, the deferred async touch should not be flushed
2064 // by the new touch sequence.
2065 SendGestureEvent(WebInputEvent::GestureScrollEnd);
2066 ResetTouchEvent();
2068 PressTouchPoint(0, 0);
2069 EXPECT_EQ(1U, GetAndResetSentEventCount());
2070 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
2071 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2072 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2075 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
2076 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE);
2078 // Queue a TouchStart.
2079 PressTouchPoint(0, 1);
2080 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2081 EXPECT_EQ(0U, queued_event_count());
2082 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2084 MoveTouchPoint(0, 20, 5);
2085 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2086 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2087 EXPECT_EQ(0U, queued_event_count());
2088 EXPECT_EQ(2U, GetAndResetSentEventCount());
2090 // Even if the first touchmove event was consumed, subsequent unconsumed
2091 // touchmove events should trigger scrolling.
2092 MoveTouchPoint(0, 60, 5);
2093 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2094 EXPECT_EQ(0U, queued_event_count());
2095 EXPECT_TRUE(sent_event().cancelable);
2096 EXPECT_EQ(1U, GetAndResetSentEventCount());
2098 MoveTouchPoint(0, 20, 5);
2099 WebGestureEvent followup_scroll;
2100 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2101 SetFollowupEvent(followup_scroll);
2102 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2103 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
2104 INPUT_EVENT_ACK_STATE_CONSUMED);
2105 EXPECT_EQ(0U, queued_event_count());
2106 EXPECT_TRUE(sent_event().cancelable);
2107 EXPECT_EQ(1U, GetAndResetSentEventCount());
2109 // Touch move event is throttled.
2110 MoveTouchPoint(0, 60, 5);
2111 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2112 EXPECT_EQ(0U, queued_event_count());
2113 EXPECT_EQ(0U, GetAndResetSentEventCount());
2116 } // namespace content