Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_event_queue_unittest.cc
blobe322a5f23f9ea72d88e404a010f65b017079097f
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/location.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "content/browser/renderer_host/input/timeout_monitor.h"
13 #include "content/browser/renderer_host/input/touch_event_queue.h"
14 #include "content/common/input/synthetic_web_input_event_builders.h"
15 #include "content/common/input/web_touch_event_traits.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 using blink::WebGestureEvent;
20 using blink::WebInputEvent;
21 using blink::WebTouchEvent;
22 using blink::WebTouchPoint;
24 namespace content {
25 namespace {
27 const double kMinSecondsBetweenThrottledTouchmoves = 0.2;
28 const float kSlopLengthDips = 10;
29 const float kHalfSlopLengthDips = kSlopLengthDips / 2;
31 base::TimeDelta DefaultTouchTimeoutDelay() {
32 return base::TimeDelta::FromMilliseconds(1);
34 } // namespace
36 class TouchEventQueueTest : public testing::Test,
37 public TouchEventQueueClient {
38 public:
39 TouchEventQueueTest()
40 : acked_event_count_(0),
41 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
42 slop_length_dips_(0) {}
44 ~TouchEventQueueTest() override {}
46 // testing::Test
47 void SetUp() override {
48 ResetQueueWithConfig(TouchEventQueue::Config());
49 sent_events_ids_.clear();
52 void TearDown() override { queue_.reset(); }
54 // TouchEventQueueClient
55 void SendTouchEventImmediately(
56 const TouchEventWithLatencyInfo& event) override {
57 sent_events_.push_back(event.event);
58 sent_events_ids_.push_back(event.event.uniqueTouchEventId);
59 if (sync_ack_result_) {
60 auto sync_ack_result = sync_ack_result_.Pass();
61 SendTouchEventAck(*sync_ack_result);
65 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
66 InputEventAckState ack_result) override {
67 ++acked_event_count_;
68 last_acked_event_ = event.event;
69 last_acked_event_state_ = ack_result;
70 if (followup_touch_event_) {
71 scoped_ptr<WebTouchEvent> followup_touch_event =
72 followup_touch_event_.Pass();
73 SendTouchEvent(*followup_touch_event);
75 if (followup_gesture_event_) {
76 scoped_ptr<WebGestureEvent> followup_gesture_event =
77 followup_gesture_event_.Pass();
78 queue_->OnGestureScrollEvent(
79 GestureEventWithLatencyInfo(*followup_gesture_event,
80 ui::LatencyInfo()));
84 protected:
85 void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
86 slop_length_dips_ = slop_length_dips;
89 void SetUpForTimeoutTesting(base::TimeDelta desktop_timeout_delay,
90 base::TimeDelta mobile_timeout_delay) {
91 TouchEventQueue::Config config;
92 config.desktop_touch_ack_timeout_delay = desktop_timeout_delay;
93 config.mobile_touch_ack_timeout_delay = mobile_timeout_delay;
94 config.touch_ack_timeout_supported = true;
95 ResetQueueWithConfig(config);
98 void SetUpForTimeoutTesting() {
99 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay(),
100 DefaultTouchTimeoutDelay());
103 void SendTouchEvent(WebTouchEvent event) {
104 if (slop_length_dips_) {
105 event.causesScrollingIfUncanceled = false;
106 if (WebTouchEventTraits::IsTouchSequenceStart(event))
107 anchor_ = event.touches[0].position;
108 if (event.type == WebInputEvent::TouchMove) {
109 gfx::Vector2dF delta = anchor_ - event.touches[0].position;
110 if (delta.LengthSquared() > slop_length_dips_ * slop_length_dips_)
111 event.causesScrollingIfUncanceled = true;
113 } else {
114 event.causesScrollingIfUncanceled =
115 event.type == WebInputEvent::TouchMove;
117 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
120 void SendGestureEvent(WebInputEvent::Type type) {
121 WebGestureEvent event;
122 event.type = type;
123 queue_->OnGestureScrollEvent(
124 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
127 void SendTouchEventAck(InputEventAckState ack_result) {
128 DCHECK(!sent_events_ids_.empty());
129 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(),
130 sent_events_ids_.front());
131 sent_events_ids_.pop_front();
134 void SendTouchEventAckWithID(InputEventAckState ack_result,
135 int unique_event_id) {
136 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), unique_event_id);
137 sent_events_ids_.erase(std::remove(sent_events_ids_.begin(),
138 sent_events_ids_.end(), unique_event_id),
139 sent_events_ids_.end());
142 void SendGestureEventAck(WebInputEvent::Type type,
143 InputEventAckState ack_result) {
144 blink::WebGestureEvent gesture_event;
145 gesture_event.type = type;
146 GestureEventWithLatencyInfo event(gesture_event, ui::LatencyInfo());
147 queue_->OnGestureEventAck(event, ack_result);
150 void SetFollowupEvent(const WebTouchEvent& event) {
151 followup_touch_event_.reset(new WebTouchEvent(event));
154 void SetFollowupEvent(const WebGestureEvent& event) {
155 followup_gesture_event_.reset(new WebGestureEvent(event));
158 void SetSyncAckResult(InputEventAckState sync_ack_result) {
159 sync_ack_result_.reset(new InputEventAckState(sync_ack_result));
162 void PressTouchPoint(float x, float y) {
163 touch_event_.PressPoint(x, y);
164 SendTouchEvent();
167 void MoveTouchPoint(int index, float x, float y) {
168 touch_event_.MovePoint(index, x, y);
169 SendTouchEvent();
172 void MoveTouchPoints(int index0,
173 float x0,
174 float y0,
175 int index1,
176 float x1,
177 float y1) {
178 touch_event_.MovePoint(index0, x0, y0);
179 touch_event_.MovePoint(index1, x1, y1);
180 SendTouchEvent();
183 void ChangeTouchPointRadius(int index, float radius_x, float radius_y) {
184 CHECK_GE(index, 0);
185 CHECK_LT(index, touch_event_.touchesLengthCap);
186 WebTouchPoint& point = touch_event_.touches[index];
187 point.radiusX = radius_x;
188 point.radiusY = radius_y;
189 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
190 touch_event_.causesScrollingIfUncanceled = true;
191 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
192 touch_event_.timeStampSeconds,
193 &touch_event_);
194 SendTouchEvent();
197 void ChangeTouchPointRotationAngle(int index, float rotation_angle) {
198 CHECK_GE(index, 0);
199 CHECK_LT(index, touch_event_.touchesLengthCap);
200 WebTouchPoint& point = touch_event_.touches[index];
201 point.rotationAngle = rotation_angle;
202 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
203 touch_event_.causesScrollingIfUncanceled = true;
204 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
205 touch_event_.timeStampSeconds,
206 &touch_event_);
207 SendTouchEvent();
210 void ChangeTouchPointForce(int index, float force) {
211 CHECK_GE(index, 0);
212 CHECK_LT(index, touch_event_.touchesLengthCap);
213 WebTouchPoint& point = touch_event_.touches[index];
214 point.force = force;
215 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
216 touch_event_.causesScrollingIfUncanceled = true;
217 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
218 touch_event_.timeStampSeconds,
219 &touch_event_);
220 SendTouchEvent();
223 void ReleaseTouchPoint(int index) {
224 touch_event_.ReleasePoint(index);
225 SendTouchEvent();
228 void CancelTouchPoint(int index) {
229 touch_event_.CancelPoint(index);
230 SendTouchEvent();
233 void AdvanceTouchTime(double seconds) {
234 touch_event_.timeStampSeconds += seconds;
237 void ResetTouchEvent() {
238 touch_event_ = SyntheticWebTouchEvent();
241 size_t GetAndResetAckedEventCount() {
242 size_t count = acked_event_count_;
243 acked_event_count_ = 0;
244 return count;
247 size_t GetAndResetSentEventCount() {
248 size_t count = sent_events_.size();
249 sent_events_.clear();
250 return count;
253 bool IsPendingAckTouchStart() const {
254 return queue_->IsPendingAckTouchStart();
257 void OnHasTouchEventHandlers(bool has_handlers) {
258 queue_->OnHasTouchEventHandlers(has_handlers);
261 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); }
263 void SetIsMobileOptimizedSite(bool is_mobile_optimized) {
264 queue_->SetIsMobileOptimizedSite(is_mobile_optimized);
267 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); }
269 bool HasPendingAsyncTouchMove() const {
270 return queue_->HasPendingAsyncTouchMoveForTesting();
273 size_t queued_event_count() const {
274 return queue_->size();
277 const WebTouchEvent& latest_event() const {
278 return queue_->GetLatestEventForTesting().event;
281 const WebTouchEvent& acked_event() const {
282 return last_acked_event_;
285 const WebTouchEvent& sent_event() const {
286 DCHECK(!sent_events_.empty());
287 return sent_events_.back();
290 const std::vector<WebTouchEvent>& all_sent_events() const {
291 return sent_events_;
294 InputEventAckState acked_event_state() const {
295 return last_acked_event_state_;
298 static void RunTasksAndWait(base::TimeDelta delay) {
299 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
300 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
301 base::MessageLoop::current()->Run();
304 size_t uncancelable_touch_moves_pending_ack_count() const {
305 return queue_->uncancelable_touch_moves_pending_ack_count();
308 int GetUniqueTouchEventID() { return sent_events_ids_.back(); }
310 private:
311 void SendTouchEvent() {
312 SendTouchEvent(touch_event_);
313 touch_event_.ResetPoints();
316 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
317 queue_.reset(new TouchEventQueue(this, config));
318 queue_->OnHasTouchEventHandlers(true);
321 scoped_ptr<TouchEventQueue> queue_;
322 size_t acked_event_count_;
323 WebTouchEvent last_acked_event_;
324 std::vector<WebTouchEvent> sent_events_;
325 InputEventAckState last_acked_event_state_;
326 SyntheticWebTouchEvent touch_event_;
327 scoped_ptr<WebTouchEvent> followup_touch_event_;
328 scoped_ptr<WebGestureEvent> followup_gesture_event_;
329 scoped_ptr<InputEventAckState> sync_ack_result_;
330 double slop_length_dips_;
331 gfx::PointF anchor_;
332 base::MessageLoopForUI message_loop_;
333 std::deque<int> sent_events_ids_;
337 // Tests that touch-events are queued properly.
338 TEST_F(TouchEventQueueTest, Basic) {
339 PressTouchPoint(1, 1);
340 EXPECT_EQ(1U, queued_event_count());
341 EXPECT_EQ(1U, GetAndResetSentEventCount());
343 // The second touch should not be sent since one is already in queue.
344 MoveTouchPoint(0, 5, 5);
345 EXPECT_EQ(2U, queued_event_count());
346 EXPECT_EQ(0U, GetAndResetSentEventCount());
348 // Receive an ACK for the first touch-event.
349 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
350 EXPECT_EQ(1U, queued_event_count());
351 EXPECT_EQ(1U, GetAndResetSentEventCount());
352 EXPECT_EQ(1U, GetAndResetAckedEventCount());
353 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
354 EXPECT_TRUE(acked_event().cancelable);
356 // Receive an ACK for the second touch-event.
357 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
358 EXPECT_EQ(0U, queued_event_count());
359 EXPECT_EQ(0U, GetAndResetSentEventCount());
360 EXPECT_EQ(1U, GetAndResetAckedEventCount());
361 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
362 EXPECT_TRUE(acked_event().cancelable);
365 // Tests that touch-events with multiple points are queued properly.
366 TEST_F(TouchEventQueueTest, BasicMultiTouch) {
367 const size_t kPointerCount = 10;
368 for (float i = 0; i < kPointerCount; ++i)
369 PressTouchPoint(i, i);
371 EXPECT_EQ(1U, GetAndResetSentEventCount());
372 EXPECT_EQ(0U, GetAndResetAckedEventCount());
373 EXPECT_EQ(kPointerCount, queued_event_count());
375 for (int i = 0; i < static_cast<int>(kPointerCount); ++i)
376 MoveTouchPoint(i, 1.f + i, 2.f + i);
378 EXPECT_EQ(0U, GetAndResetSentEventCount());
379 EXPECT_EQ(0U, GetAndResetAckedEventCount());
380 // All moves should coalesce.
381 EXPECT_EQ(kPointerCount + 1, queued_event_count());
383 for (int i = 0; i < static_cast<int>(kPointerCount); ++i)
384 ReleaseTouchPoint(kPointerCount - 1 - i);
386 EXPECT_EQ(0U, GetAndResetSentEventCount());
387 EXPECT_EQ(0U, GetAndResetAckedEventCount());
388 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count());
390 // Ack all presses.
391 for (size_t i = 0; i < kPointerCount; ++i)
392 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
394 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
395 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount());
397 // Ack the coalesced move.
398 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
399 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
400 EXPECT_EQ(1U, GetAndResetSentEventCount());
402 // Ack all releases.
403 for (size_t i = 0; i < kPointerCount; ++i)
404 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
406 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
407 EXPECT_EQ(kPointerCount - 1, GetAndResetSentEventCount());
410 // Tests that the touch-queue continues delivering events for an active touch
411 // sequence after all handlers are removed.
412 TEST_F(TouchEventQueueTest, TouchesForwardedIfHandlerRemovedDuringSequence) {
413 OnHasTouchEventHandlers(true);
414 EXPECT_EQ(0U, queued_event_count());
415 EXPECT_EQ(0U, GetAndResetSentEventCount());
417 // Send a touch-press event.
418 PressTouchPoint(1, 1);
419 EXPECT_EQ(1U, GetAndResetSentEventCount());
420 EXPECT_EQ(1U, queued_event_count());
422 // Signal that all touch handlers have been removed.
423 OnHasTouchEventHandlers(false);
424 EXPECT_EQ(0U, GetAndResetAckedEventCount());
425 EXPECT_EQ(1U, queued_event_count());
427 // Process the ack for the sent touch, ensuring that it is honored (despite
428 // the touch handler having been removed).
429 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
430 EXPECT_EQ(1U, GetAndResetAckedEventCount());
431 EXPECT_EQ(0U, queued_event_count());
432 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
434 // Try forwarding a new pointer. It should be forwarded as usual.
435 PressTouchPoint(2, 2);
436 EXPECT_EQ(1U, GetAndResetSentEventCount());
437 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
438 EXPECT_EQ(1U, GetAndResetAckedEventCount());
439 EXPECT_EQ(0U, queued_event_count());
441 // Further events for any pointer should be forwarded, even for pointers that
442 // reported no consumer.
443 MoveTouchPoint(1, 3, 3);
444 ReleaseTouchPoint(1);
445 EXPECT_EQ(1U, GetAndResetSentEventCount());
446 EXPECT_EQ(0U, GetAndResetAckedEventCount());
447 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
448 EXPECT_EQ(1U, GetAndResetSentEventCount());
449 EXPECT_EQ(1U, GetAndResetAckedEventCount());
450 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
451 EXPECT_EQ(0U, GetAndResetSentEventCount());
452 EXPECT_EQ(1U, GetAndResetAckedEventCount());
454 // Events for the first pointer, that had a handler, should be forwarded.
455 MoveTouchPoint(0, 4, 4);
456 ReleaseTouchPoint(0);
457 EXPECT_EQ(1U, GetAndResetSentEventCount());
458 EXPECT_EQ(2U, queued_event_count());
460 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
461 EXPECT_EQ(1U, GetAndResetAckedEventCount());
462 EXPECT_EQ(1U, GetAndResetSentEventCount());
463 EXPECT_EQ(1U, queued_event_count());
464 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
467 EXPECT_EQ(1U, GetAndResetAckedEventCount());
468 EXPECT_EQ(0U, GetAndResetSentEventCount());
469 EXPECT_EQ(0U, queued_event_count());
470 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
473 // Tests that addition of a touch handler during a touch sequence will not cause
474 // the remaining sequence to be forwarded.
475 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) {
476 OnHasTouchEventHandlers(false);
478 // Send a touch-press event while there is no handler.
479 PressTouchPoint(1, 1);
480 EXPECT_EQ(1U, GetAndResetAckedEventCount());
481 EXPECT_EQ(0U, GetAndResetSentEventCount());
482 EXPECT_EQ(0U, queued_event_count());
484 OnHasTouchEventHandlers(true);
486 // The remaining touch sequence should not be forwarded.
487 MoveTouchPoint(0, 5, 5);
488 ReleaseTouchPoint(0);
489 EXPECT_EQ(2U, GetAndResetAckedEventCount());
490 EXPECT_EQ(0U, GetAndResetSentEventCount());
491 EXPECT_EQ(0U, queued_event_count());
493 // A new touch sequence should resume forwarding.
494 PressTouchPoint(1, 1);
495 EXPECT_EQ(1U, queued_event_count());
496 EXPECT_EQ(1U, GetAndResetSentEventCount());
499 // Tests that removal of a touch handler during a touch sequence will prevent
500 // the remaining sequence from being forwarded, even if another touch handler is
501 // registered during the same touch sequence.
502 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
503 // Send a touch-press event.
504 PressTouchPoint(1, 1);
505 EXPECT_EQ(1U, GetAndResetSentEventCount());
506 EXPECT_EQ(1U, queued_event_count());
508 // Queue a touch-move event.
509 MoveTouchPoint(0, 5, 5);
510 EXPECT_EQ(2U, queued_event_count());
511 EXPECT_EQ(0U, GetAndResetAckedEventCount());
512 EXPECT_EQ(0U, GetAndResetSentEventCount());
514 // Unregister all touch handlers.
515 OnHasTouchEventHandlers(false);
516 EXPECT_EQ(0U, GetAndResetAckedEventCount());
517 EXPECT_EQ(2U, queued_event_count());
519 // Repeated registration/unregstration of handlers should have no effect as
520 // we're still awaiting the ack arrival.
521 OnHasTouchEventHandlers(true);
522 EXPECT_EQ(0U, GetAndResetAckedEventCount());
523 EXPECT_EQ(2U, queued_event_count());
524 OnHasTouchEventHandlers(false);
525 EXPECT_EQ(0U, GetAndResetAckedEventCount());
526 EXPECT_EQ(2U, queued_event_count());
528 // The ack should be flush the queue.
529 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
530 EXPECT_EQ(2U, GetAndResetAckedEventCount());
531 EXPECT_EQ(0U, queued_event_count());
533 // Events should be dropped while there is no touch handler.
534 MoveTouchPoint(0, 10, 10);
535 EXPECT_EQ(0U, queued_event_count());
536 EXPECT_EQ(1U, GetAndResetAckedEventCount());
537 EXPECT_EQ(0U, GetAndResetSentEventCount());
539 // Simulate touch handler registration in the middle of a touch sequence.
540 OnHasTouchEventHandlers(true);
542 // The touch end for the interrupted sequence should be dropped.
543 ReleaseTouchPoint(0);
544 EXPECT_EQ(0U, queued_event_count());
545 EXPECT_EQ(1U, GetAndResetAckedEventCount());
546 EXPECT_EQ(0U, GetAndResetSentEventCount());
548 // A new touch sequence should be forwarded properly.
549 PressTouchPoint(1, 1);
550 EXPECT_EQ(1U, queued_event_count());
551 EXPECT_EQ(1U, GetAndResetSentEventCount());
554 // Tests that removal/addition of a touch handler without any intervening
555 // touch activity has no affect on touch forwarding.
556 TEST_F(TouchEventQueueTest,
557 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition) {
558 // Send a touch-press event.
559 PressTouchPoint(1, 1);
560 EXPECT_EQ(1U, GetAndResetSentEventCount());
561 EXPECT_EQ(1U, queued_event_count());
563 // Simulate the case where the touchstart handler removes itself, and adds a
564 // touchmove handler.
565 OnHasTouchEventHandlers(false);
566 OnHasTouchEventHandlers(true);
568 // Queue a touch-move event.
569 MoveTouchPoint(0, 5, 5);
570 EXPECT_EQ(2U, queued_event_count());
571 EXPECT_EQ(0U, GetAndResetAckedEventCount());
572 EXPECT_EQ(0U, GetAndResetSentEventCount());
574 // The ack should trigger forwarding of the touchmove, as if no touch
575 // handler registration changes have occurred.
576 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
577 EXPECT_EQ(1U, GetAndResetAckedEventCount());
578 EXPECT_EQ(1U, GetAndResetSentEventCount());
579 EXPECT_EQ(1U, queued_event_count());
582 // Tests that touch-events are coalesced properly in the queue.
583 TEST_F(TouchEventQueueTest, Coalesce) {
584 // Send a touch-press event.
585 PressTouchPoint(1, 1);
586 EXPECT_EQ(1U, GetAndResetSentEventCount());
588 // Send a few touch-move events, followed by a touch-release event. All the
589 // touch-move events should be coalesced into a single event.
590 for (float i = 5; i < 15; ++i)
591 MoveTouchPoint(0, i, i);
593 EXPECT_EQ(0U, GetAndResetSentEventCount());
594 ReleaseTouchPoint(0);
595 EXPECT_EQ(0U, GetAndResetSentEventCount());
596 EXPECT_EQ(3U, queued_event_count());
598 // ACK the press. Coalesced touch-move events should be sent.
599 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
600 EXPECT_EQ(2U, queued_event_count());
601 EXPECT_EQ(1U, GetAndResetSentEventCount());
602 EXPECT_EQ(1U, GetAndResetAckedEventCount());
603 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
604 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
606 // ACK the moves.
607 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
608 EXPECT_EQ(1U, queued_event_count());
609 EXPECT_EQ(1U, GetAndResetSentEventCount());
610 EXPECT_EQ(10U, GetAndResetAckedEventCount());
611 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
613 // ACK the release.
614 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
615 EXPECT_EQ(0U, queued_event_count());
616 EXPECT_EQ(0U, GetAndResetSentEventCount());
617 EXPECT_EQ(1U, GetAndResetAckedEventCount());
618 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
621 // Tests that an event that has already been sent but hasn't been ack'ed yet
622 // doesn't get coalesced with newer events.
623 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
624 // Send a touch-press event.
625 PressTouchPoint(1, 1);
626 EXPECT_EQ(1U, GetAndResetSentEventCount());
628 // Send a few touch-move events, followed by a touch-release event. All the
629 // touch-move events should be coalesced into a single event.
630 for (float i = 5; i < 15; ++i)
631 MoveTouchPoint(0, i, i);
633 EXPECT_EQ(0U, GetAndResetSentEventCount());
634 EXPECT_EQ(2U, queued_event_count());
636 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
637 EXPECT_EQ(1U, GetAndResetSentEventCount());
638 EXPECT_EQ(1U, queued_event_count());
640 // The coalesced touch-move event has been sent to the renderer. Any new
641 // touch-move event should not be coalesced with the sent event.
642 MoveTouchPoint(0, 5, 5);
643 EXPECT_EQ(2U, queued_event_count());
645 MoveTouchPoint(0, 7, 7);
646 EXPECT_EQ(2U, queued_event_count());
649 // Tests that coalescing works correctly for multi-touch events.
650 TEST_F(TouchEventQueueTest, MultiTouch) {
651 // Press the first finger.
652 PressTouchPoint(1, 1);
653 EXPECT_EQ(1U, GetAndResetSentEventCount());
655 // Move the finger.
656 MoveTouchPoint(0, 5, 5);
657 EXPECT_EQ(2U, queued_event_count());
659 // Now press a second finger.
660 PressTouchPoint(2, 2);
661 EXPECT_EQ(3U, queued_event_count());
663 // Move both fingers.
664 MoveTouchPoints(0, 10, 10, 1, 20, 20);
665 MoveTouchPoint(1, 20, 20);
666 EXPECT_EQ(4U, queued_event_count());
668 // Move only one finger now.
669 MoveTouchPoint(0, 15, 15);
670 EXPECT_EQ(4U, queued_event_count());
672 // Move the other finger.
673 MoveTouchPoint(1, 25, 25);
674 EXPECT_EQ(4U, queued_event_count());
676 // Make sure both fingers are marked as having been moved in the coalesced
677 // event.
678 const WebTouchEvent& event = latest_event();
679 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
680 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
683 // Tests that the touch-event queue is robust to redundant acks.
684 TEST_F(TouchEventQueueTest, SpuriousAcksIgnored) {
685 // Trigger a spurious ack.
686 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 0);
687 EXPECT_EQ(0U, GetAndResetAckedEventCount());
689 // Send and ack a touch press.
690 PressTouchPoint(1, 1);
691 EXPECT_EQ(1U, GetAndResetSentEventCount());
692 EXPECT_EQ(1U, queued_event_count());
693 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
694 EXPECT_EQ(1U, GetAndResetAckedEventCount());
695 EXPECT_EQ(0U, queued_event_count());
697 // Trigger a spurious ack.
698 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 3);
699 EXPECT_EQ(0U, GetAndResetAckedEventCount());
702 // Tests that touch-move events are not sent to the renderer if the preceding
703 // touch-press event did not have a consumer (and consequently, did not hit the
704 // main thread in the renderer). Also tests that all queued/coalesced touch
705 // events are flushed immediately when the ACK for the touch-press comes back
706 // with NO_CONSUMER status.
707 TEST_F(TouchEventQueueTest, NoConsumer) {
708 // The first touch-press should reach the renderer.
709 PressTouchPoint(1, 1);
710 EXPECT_EQ(1U, GetAndResetSentEventCount());
712 // The second touch should not be sent since one is already in queue.
713 MoveTouchPoint(0, 5, 5);
714 EXPECT_EQ(0U, GetAndResetSentEventCount());
715 EXPECT_EQ(2U, queued_event_count());
717 // Receive an ACK for the first touch-event. This should release the queued
718 // touch-event, but it should not be sent to the renderer.
719 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
720 EXPECT_EQ(0U, queued_event_count());
721 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
722 EXPECT_EQ(2U, GetAndResetAckedEventCount());
723 EXPECT_EQ(0U, GetAndResetSentEventCount());
725 // Send a release event. This should not reach the renderer.
726 ReleaseTouchPoint(0);
727 EXPECT_EQ(0U, GetAndResetSentEventCount());
728 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
729 EXPECT_EQ(1U, GetAndResetAckedEventCount());
731 // Send a press-event, followed by move and release events, and another press
732 // event, before the ACK for the first press event comes back. All of the
733 // events should be queued first. After the NO_CONSUMER ack for the first
734 // touch-press, all events upto the second touch-press should be flushed.
735 PressTouchPoint(10, 10);
736 EXPECT_EQ(1U, GetAndResetSentEventCount());
738 MoveTouchPoint(0, 5, 5);
739 MoveTouchPoint(0, 6, 5);
740 ReleaseTouchPoint(0);
742 PressTouchPoint(6, 5);
743 EXPECT_EQ(0U, GetAndResetSentEventCount());
744 // The queue should hold the first sent touch-press event, the coalesced
745 // touch-move event, the touch-end event and the second touch-press event.
746 EXPECT_EQ(4U, queued_event_count());
748 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
749 EXPECT_EQ(1U, GetAndResetSentEventCount());
750 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
751 EXPECT_EQ(4U, GetAndResetAckedEventCount());
752 EXPECT_EQ(1U, queued_event_count());
754 // ACK the second press event as NO_CONSUMER too.
755 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
756 EXPECT_EQ(0U, GetAndResetSentEventCount());
757 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
758 EXPECT_EQ(1U, GetAndResetAckedEventCount());
759 EXPECT_EQ(0U, queued_event_count());
761 // Send a second press event. Even though the first touch press had
762 // NO_CONSUMER, this press event should reach the renderer.
763 PressTouchPoint(1, 1);
764 EXPECT_EQ(1U, GetAndResetSentEventCount());
765 EXPECT_EQ(1U, queued_event_count());
766 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
767 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
768 EXPECT_EQ(1U, GetAndResetAckedEventCount());
771 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
772 // Interleave three pointer press, move and release events.
773 PressTouchPoint(1, 1);
774 MoveTouchPoint(0, 5, 5);
775 PressTouchPoint(10, 10);
776 MoveTouchPoint(1, 15, 15);
777 PressTouchPoint(20, 20);
778 MoveTouchPoint(2, 25, 25);
779 ReleaseTouchPoint(2);
780 MoveTouchPoint(1, 20, 20);
781 ReleaseTouchPoint(1);
782 MoveTouchPoint(0, 10, 10);
783 ReleaseTouchPoint(0);
785 // Since the first touch-press is still pending ACK, no other event should
786 // have been sent to the renderer.
787 EXPECT_EQ(1U, GetAndResetSentEventCount());
788 EXPECT_EQ(0U, GetAndResetSentEventCount());
789 EXPECT_EQ(11U, queued_event_count());
791 // ACK the first press as CONSUMED. This should cause the first touch-move of
792 // the first touch-point to be dispatched.
793 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
794 EXPECT_EQ(1U, GetAndResetSentEventCount());
795 EXPECT_EQ(10U, queued_event_count());
797 // ACK the first move as CONSUMED.
798 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
799 EXPECT_EQ(1U, GetAndResetSentEventCount());
800 EXPECT_EQ(9U, queued_event_count());
802 // ACK the second press as NO_CONSUMER_EXISTS. The second pointer's touchmove
803 // should still be forwarded, despite lacking a direct consumer.
804 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
805 EXPECT_EQ(1U, GetAndResetSentEventCount());
806 EXPECT_EQ(8U, queued_event_count());
808 // ACK the coalesced move as NOT_CONSUMED.
809 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
810 EXPECT_EQ(1U, GetAndResetSentEventCount());
811 EXPECT_EQ(7U, queued_event_count());
813 // All remaining touch events should be forwarded, even if the third pointer
814 // press also reports no consumer.
815 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
816 EXPECT_EQ(6U, queued_event_count());
818 while (queued_event_count())
819 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
821 EXPECT_EQ(6U, GetAndResetSentEventCount());
824 // Tests that touch-event's enqueued via a touch ack are properly handled.
825 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
826 // Queue a touch down.
827 PressTouchPoint(1, 1);
828 EXPECT_EQ(1U, queued_event_count());
829 EXPECT_EQ(1U, GetAndResetSentEventCount());
830 EXPECT_EQ(0U, GetAndResetAckedEventCount());
832 // Create a touch event that will be queued synchronously by a touch ack.
833 // Note, this will be triggered by all subsequent touch acks.
834 WebTouchEvent followup_event;
835 followup_event.type = WebInputEvent::TouchMove;
836 followup_event.touchesLength = 1;
837 followup_event.touches[0].id = 0;
838 followup_event.touches[0].state = WebTouchPoint::StateMoved;
839 SetFollowupEvent(followup_event);
841 // Receive an ACK for the press. This should cause the followup touch-move to
842 // be sent to the renderer.
843 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
844 EXPECT_EQ(1U, queued_event_count());
845 EXPECT_EQ(1U, GetAndResetSentEventCount());
846 EXPECT_EQ(1U, GetAndResetAckedEventCount());
847 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
848 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
850 // Queue another event.
851 MoveTouchPoint(0, 2, 2);
852 EXPECT_EQ(2U, queued_event_count());
854 // Receive an ACK for the touch-move followup event. This should cause the
855 // subsequent touch move event be sent to the renderer.
856 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
857 EXPECT_EQ(1U, queued_event_count());
858 EXPECT_EQ(1U, GetAndResetSentEventCount());
859 EXPECT_EQ(1U, GetAndResetAckedEventCount());
862 // Tests that touch-events can be synchronously ack'ed.
863 TEST_F(TouchEventQueueTest, SynchronousAcks) {
864 // TouchStart
865 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
866 PressTouchPoint(1, 1);
867 EXPECT_EQ(0U, queued_event_count());
868 EXPECT_EQ(1U, GetAndResetSentEventCount());
869 EXPECT_EQ(1U, GetAndResetAckedEventCount());
871 // TouchMove
872 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
873 MoveTouchPoint(0, 2, 2);
874 EXPECT_EQ(0U, queued_event_count());
875 EXPECT_EQ(1U, GetAndResetSentEventCount());
876 EXPECT_EQ(1U, GetAndResetAckedEventCount());
878 // TouchEnd
879 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
880 ReleaseTouchPoint(0);
881 EXPECT_EQ(0U, queued_event_count());
882 EXPECT_EQ(1U, GetAndResetSentEventCount());
883 EXPECT_EQ(1U, GetAndResetAckedEventCount());
885 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
886 PressTouchPoint(1, 1);
887 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
888 EXPECT_EQ(0U, queued_event_count());
889 EXPECT_EQ(1U, GetAndResetSentEventCount());
890 EXPECT_EQ(1U, GetAndResetAckedEventCount());
892 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
893 CancelTouchPoint(0);
894 EXPECT_EQ(0U, queued_event_count());
895 EXPECT_EQ(1U, GetAndResetSentEventCount());
896 EXPECT_EQ(1U, GetAndResetAckedEventCount());
899 // Tests that followup events triggered by an immediate ack from
900 // TouchEventQueue::QueueEvent() are properly handled.
901 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
902 // Create a touch event that will be queued synchronously by a touch ack.
903 WebTouchEvent followup_event;
904 followup_event.type = WebInputEvent::TouchStart;
905 followup_event.touchesLength = 1;
906 followup_event.touches[0].id = 1;
907 followup_event.touches[0].state = WebTouchPoint::StatePressed;
908 SetFollowupEvent(followup_event);
910 // Now, enqueue a stationary touch that will not be forwarded. This should be
911 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
912 // then be enqueued and immediately sent to the renderer.
913 WebTouchEvent stationary_event;
914 stationary_event.touchesLength = 1;
915 stationary_event.type = WebInputEvent::TouchMove;
916 stationary_event.touches[0].id = 1;
917 stationary_event.touches[0].state = WebTouchPoint::StateStationary;
918 SendTouchEvent(stationary_event);
920 EXPECT_EQ(1U, queued_event_count());
921 EXPECT_EQ(1U, GetAndResetSentEventCount());
922 EXPECT_EQ(1U, GetAndResetAckedEventCount());
923 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
924 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
927 // Tests basic TouchEvent forwarding suppression.
928 TEST_F(TouchEventQueueTest, NoTouchBasic) {
929 // Disable TouchEvent forwarding.
930 OnHasTouchEventHandlers(false);
931 PressTouchPoint(30, 5);
932 EXPECT_EQ(0U, GetAndResetSentEventCount());
933 EXPECT_EQ(1U, GetAndResetAckedEventCount());
935 // TouchMove should not be sent to renderer.
936 MoveTouchPoint(0, 65, 10);
937 EXPECT_EQ(0U, GetAndResetSentEventCount());
938 EXPECT_EQ(1U, GetAndResetAckedEventCount());
940 // TouchEnd should not be sent to renderer.
941 ReleaseTouchPoint(0);
942 EXPECT_EQ(0U, GetAndResetSentEventCount());
943 EXPECT_EQ(1U, GetAndResetAckedEventCount());
945 // Enable TouchEvent forwarding.
946 OnHasTouchEventHandlers(true);
948 PressTouchPoint(80, 10);
949 EXPECT_EQ(1U, GetAndResetSentEventCount());
950 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
951 EXPECT_EQ(1U, GetAndResetAckedEventCount());
953 MoveTouchPoint(0, 80, 20);
954 EXPECT_EQ(1U, GetAndResetSentEventCount());
955 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
956 EXPECT_EQ(1U, GetAndResetAckedEventCount());
958 ReleaseTouchPoint(0);
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();
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();
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(WebInputEvent::TouchCancel, sent_event().type);
1070 EXPECT_FALSE(sent_event().cancelable);
1071 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1072 EXPECT_EQ(1U, GetAndResetSentEventCount());
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(WebInputEvent::TouchStart, sent_event().type);
1092 EXPECT_TRUE(sent_event().cancelable);
1093 EXPECT_EQ(1U, GetAndResetSentEventCount());
1094 EXPECT_EQ(0U, GetAndResetAckedEventCount());
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();
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();
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_EQ(1U, GetAndResetSentEventCount());
1144 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1146 // Now explicitly disable the timeout.
1147 SetAckTimeoutDisabled();
1148 EXPECT_FALSE(IsTimeoutRunning());
1150 // A TouchMove should not start or trigger the timeout.
1151 MoveTouchPoint(0, 5, 5);
1152 EXPECT_FALSE(IsTimeoutRunning());
1153 EXPECT_EQ(1U, GetAndResetSentEventCount());
1154 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1155 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1158 // Tests that the timeout is never started if the ack is synchronous.
1159 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1160 SetUpForTimeoutTesting();
1162 // Queue a TouchStart.
1163 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1164 ASSERT_FALSE(IsTimeoutRunning());
1165 PressTouchPoint(0, 1);
1166 EXPECT_FALSE(IsTimeoutRunning());
1169 // Tests that the timeout does not fire if explicitly disabled while an event
1170 // is in-flight.
1171 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
1172 SetUpForTimeoutTesting();
1174 // Queue a TouchStart.
1175 PressTouchPoint(0, 1);
1176 ASSERT_TRUE(IsTimeoutRunning());
1178 // Verify that disabling the timeout also turns off the timer.
1179 SetAckTimeoutDisabled();
1180 EXPECT_FALSE(IsTimeoutRunning());
1181 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1182 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1185 // Tests that the timeout does not fire if the delay is zero.
1186 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTimeoutDelayIsZero) {
1187 SetUpForTimeoutTesting(base::TimeDelta(), base::TimeDelta());
1189 // As the delay is zero, timeout behavior should be disabled.
1190 PressTouchPoint(0, 1);
1191 EXPECT_FALSE(IsTimeoutRunning());
1192 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1193 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1196 // Tests that timeout delays for mobile sites take effect when appropriate.
1197 TEST_F(TouchEventQueueTest, TouchTimeoutConfiguredForMobile) {
1198 base::TimeDelta desktop_delay = DefaultTouchTimeoutDelay();
1199 base::TimeDelta mobile_delay = base::TimeDelta();
1200 SetUpForTimeoutTesting(desktop_delay, mobile_delay);
1202 // The desktop delay is non-zero, allowing timeout behavior.
1203 SetIsMobileOptimizedSite(false);
1205 PressTouchPoint(0, 1);
1206 ASSERT_TRUE(IsTimeoutRunning());
1207 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1208 ReleaseTouchPoint(0);
1209 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1210 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1211 ASSERT_FALSE(IsTimeoutRunning());
1213 // The mobile delay is zero, preventing timeout behavior.
1214 SetIsMobileOptimizedSite(true);
1216 PressTouchPoint(0, 1);
1217 EXPECT_FALSE(IsTimeoutRunning());
1218 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1219 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1222 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1223 // turns into a scroll gesture sequence.
1224 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1225 SetUpForTimeoutTesting();
1227 // Queue a TouchStart.
1228 PressTouchPoint(0, 1);
1229 EXPECT_TRUE(IsTimeoutRunning());
1230 EXPECT_EQ(1U, GetAndResetSentEventCount());
1232 // The cancelled sequence may turn into a scroll gesture.
1233 WebGestureEvent followup_scroll;
1234 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1235 SetFollowupEvent(followup_scroll);
1237 // Delay the ack.
1238 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1240 // The timeout should have fired, disabling touch forwarding until both acks
1241 // are received, acking the timed out event.
1242 EXPECT_FALSE(IsTimeoutRunning());
1243 EXPECT_EQ(0U, GetAndResetSentEventCount());
1244 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1246 // Ack the original event, triggering a TouchCancel.
1247 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1248 EXPECT_FALSE(IsTimeoutRunning());
1249 EXPECT_EQ(1U, GetAndResetSentEventCount());
1250 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1252 // Ack the cancel event. Normally, this would resume touch forwarding,
1253 // but we're still within a scroll gesture so it remains disabled.
1254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1255 EXPECT_FALSE(IsTimeoutRunning());
1256 EXPECT_EQ(0U, GetAndResetSentEventCount());
1257 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1259 // Try to forward touch events for the current sequence.
1260 GetAndResetSentEventCount();
1261 GetAndResetAckedEventCount();
1262 MoveTouchPoint(0, 1, 1);
1263 ReleaseTouchPoint(0);
1264 EXPECT_FALSE(IsTimeoutRunning());
1265 EXPECT_EQ(0U, GetAndResetSentEventCount());
1266 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1268 // Now end the scroll sequence, resuming touch handling.
1269 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1270 PressTouchPoint(0, 1);
1271 EXPECT_TRUE(IsTimeoutRunning());
1272 EXPECT_EQ(1U, GetAndResetSentEventCount());
1273 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1276 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1277 // turns into a scroll gesture sequence, but the original event acks are
1278 // significantly delayed.
1279 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1280 SetUpForTimeoutTesting();
1282 // Queue a TouchStart.
1283 PressTouchPoint(0, 1);
1284 EXPECT_TRUE(IsTimeoutRunning());
1285 EXPECT_EQ(1U, GetAndResetSentEventCount());
1287 // The cancelled sequence may turn into a scroll gesture.
1288 WebGestureEvent followup_scroll;
1289 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1290 SetFollowupEvent(followup_scroll);
1292 // Delay the ack.
1293 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1295 // The timeout should have fired, disabling touch forwarding until both acks
1296 // are received and acking the timed out event.
1297 EXPECT_FALSE(IsTimeoutRunning());
1298 EXPECT_EQ(0U, GetAndResetSentEventCount());
1299 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1301 // Try to forward a touch event.
1302 GetAndResetSentEventCount();
1303 GetAndResetAckedEventCount();
1304 MoveTouchPoint(0, 1, 1);
1305 EXPECT_FALSE(IsTimeoutRunning());
1306 EXPECT_EQ(0U, GetAndResetSentEventCount());
1307 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1309 // Now end the scroll sequence. Events will not be forwarded until the two
1310 // outstanding touch acks are received.
1311 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1312 MoveTouchPoint(0, 2, 2);
1313 ReleaseTouchPoint(0);
1314 EXPECT_FALSE(IsTimeoutRunning());
1315 EXPECT_EQ(0U, GetAndResetSentEventCount());
1316 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1318 // Ack the original event, triggering a cancel.
1319 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1320 EXPECT_EQ(1U, GetAndResetSentEventCount());
1321 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1323 // Ack the cancel event, resuming touch forwarding.
1324 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1325 EXPECT_EQ(0U, GetAndResetSentEventCount());
1326 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1328 PressTouchPoint(0, 1);
1329 EXPECT_TRUE(IsTimeoutRunning());
1330 EXPECT_EQ(1U, GetAndResetSentEventCount());
1333 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1334 // the timed-out event had no consumer.
1335 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1336 SetUpForTimeoutTesting();
1338 // Queue a TouchStart.
1339 PressTouchPoint(0, 1);
1340 ASSERT_EQ(1U, GetAndResetSentEventCount());
1341 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1342 EXPECT_TRUE(IsTimeoutRunning());
1344 // Delay the ack.
1345 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1347 // The timeout should have fired, synthetically ack'ing the timed out event.
1348 // TouchEvent forwarding is disabled until the original ack is received.
1349 EXPECT_FALSE(IsTimeoutRunning());
1350 EXPECT_EQ(0U, GetAndResetSentEventCount());
1351 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1353 // Touch events should not be forwarded until we receive the original ack.
1354 MoveTouchPoint(0, 1, 1);
1355 ReleaseTouchPoint(0);
1356 ASSERT_EQ(0U, GetAndResetSentEventCount());
1357 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1359 // Ack'ing the original event should not trigger a cancel event, as the
1360 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1361 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1362 EXPECT_FALSE(IsTimeoutRunning());
1363 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1364 EXPECT_EQ(0U, GetAndResetSentEventCount());
1366 // Subsequent events should be handled normally.
1367 PressTouchPoint(0, 1);
1368 EXPECT_EQ(1U, GetAndResetSentEventCount());
1369 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1372 // Tests that TouchMove's are dropped if within the boundary-inclusive slop
1373 // suppression region for an unconsumed TouchStart.
1374 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) {
1375 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1377 // Queue a TouchStart.
1378 PressTouchPoint(0, 0);
1379 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1380 ASSERT_EQ(1U, GetAndResetSentEventCount());
1381 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1383 // TouchMove's within the region should be suppressed.
1384 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1385 EXPECT_EQ(0U, queued_event_count());
1386 EXPECT_EQ(0U, GetAndResetSentEventCount());
1387 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1388 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1390 MoveTouchPoint(0, kHalfSlopLengthDips, 0);
1391 EXPECT_EQ(0U, queued_event_count());
1392 EXPECT_EQ(0U, GetAndResetSentEventCount());
1393 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1394 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1396 MoveTouchPoint(0, -kHalfSlopLengthDips, 0);
1397 EXPECT_EQ(0U, queued_event_count());
1398 EXPECT_EQ(0U, GetAndResetSentEventCount());
1399 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1400 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1402 MoveTouchPoint(0, -kSlopLengthDips, 0);
1403 EXPECT_EQ(0U, queued_event_count());
1404 EXPECT_EQ(0U, GetAndResetSentEventCount());
1405 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1406 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1408 MoveTouchPoint(0, 0, kSlopLengthDips);
1409 EXPECT_EQ(0U, queued_event_count());
1410 EXPECT_EQ(0U, GetAndResetSentEventCount());
1411 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1412 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state());
1414 // As soon as a TouchMove exceeds the (Euclidean) distance, no more
1415 // TouchMove's should be suppressed.
1416 const float kFortyFiveDegreeSlopLengthXY =
1417 kSlopLengthDips * std::sqrt(2.f) / 2;
1418 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2f,
1419 kFortyFiveDegreeSlopLengthXY + .2f);
1420 EXPECT_EQ(1U, queued_event_count());
1421 EXPECT_EQ(1U, GetAndResetSentEventCount());
1422 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1423 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1424 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1426 // Even TouchMove's within the original slop region should now be forwarded.
1427 MoveTouchPoint(0, 0, 0);
1428 EXPECT_EQ(1U, queued_event_count());
1429 EXPECT_EQ(1U, GetAndResetSentEventCount());
1430 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1431 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1432 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1434 // A new touch sequence should reset suppression.
1435 ReleaseTouchPoint(0);
1436 PressTouchPoint(0, 0);
1437 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1438 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1439 ASSERT_EQ(2U, GetAndResetSentEventCount());
1440 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1441 ASSERT_EQ(0U, queued_event_count());
1443 // The slop region is boundary-inclusive.
1444 MoveTouchPoint(0, kSlopLengthDips - 1, 0);
1445 EXPECT_EQ(0U, queued_event_count());
1446 EXPECT_EQ(0U, GetAndResetSentEventCount());
1447 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1449 MoveTouchPoint(0, kSlopLengthDips, 0);
1450 EXPECT_EQ(0U, queued_event_count());
1451 EXPECT_EQ(0U, GetAndResetSentEventCount());
1452 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1455 // Tests that TouchMove's are not dropped within the slop suppression region if
1456 // the touchstart was consumed.
1457 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) {
1458 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1460 // Queue a TouchStart.
1461 PressTouchPoint(0, 0);
1462 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1463 ASSERT_EQ(1U, GetAndResetSentEventCount());
1464 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1466 // TouchMove's within the region should not be suppressed, as a touch was
1467 // consumed.
1468 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1469 EXPECT_EQ(1U, queued_event_count());
1470 EXPECT_EQ(1U, GetAndResetSentEventCount());
1471 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1474 // Tests that even very small TouchMove's are not suppressed when suppression is
1475 // disabled.
1476 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionIfDisabled) {
1477 // Queue a TouchStart.
1478 PressTouchPoint(0, 0);
1479 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1480 ASSERT_EQ(1U, GetAndResetSentEventCount());
1481 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1483 // Small TouchMove's should not be suppressed.
1484 MoveTouchPoint(0, 0.001f, 0.001f);
1485 EXPECT_EQ(1U, queued_event_count());
1486 EXPECT_EQ(1U, GetAndResetSentEventCount());
1487 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1490 // Tests that TouchMove's are not dropped if a secondary pointer is present
1491 // during any movement.
1492 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) {
1493 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1495 // Queue a TouchStart.
1496 PressTouchPoint(0, 0);
1497 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1498 ASSERT_EQ(1U, GetAndResetSentEventCount());
1499 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1501 // TouchMove's within the region should be suppressed.
1502 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1503 EXPECT_EQ(0U, queued_event_count());
1504 EXPECT_EQ(0U, GetAndResetSentEventCount());
1505 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1507 // Simulate a secondary pointer press.
1508 PressTouchPoint(kSlopLengthDips, 0);
1509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1510 EXPECT_EQ(1U, GetAndResetSentEventCount());
1511 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1513 // TouchMove with a secondary pointer should not be suppressed.
1514 MoveTouchPoint(1, kSlopLengthDips+1, 0);
1515 EXPECT_EQ(1U, queued_event_count());
1516 EXPECT_EQ(1U, GetAndResetSentEventCount());
1517 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1518 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1520 // Release the secondary pointer.
1521 ReleaseTouchPoint(0);
1522 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1523 EXPECT_EQ(1U, GetAndResetSentEventCount());
1524 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1526 // TouchMove's should not should be suppressed, even with the original
1527 // unmoved pointer.
1528 MoveTouchPoint(0, 0, 0);
1529 EXPECT_EQ(1U, queued_event_count());
1530 EXPECT_EQ(1U, GetAndResetSentEventCount());
1531 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1534 // Tests that secondary touch points can be forwarded even if the primary touch
1535 // point had no consumer.
1536 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) {
1537 // Queue a TouchStart.
1538 PressTouchPoint(0, 0);
1539 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1540 ASSERT_EQ(1U, GetAndResetSentEventCount());
1541 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1543 // Events should not be forwarded, as the point had no consumer.
1544 MoveTouchPoint(0, 0, 15);
1545 EXPECT_EQ(0U, queued_event_count());
1546 EXPECT_EQ(0U, GetAndResetSentEventCount());
1547 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1549 // Simulate a secondary pointer press.
1550 PressTouchPoint(20, 0);
1551 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1552 EXPECT_EQ(1U, GetAndResetSentEventCount());
1553 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1555 // TouchMove with a secondary pointer should not be suppressed.
1556 MoveTouchPoint(1, 25, 0);
1557 EXPECT_EQ(1U, queued_event_count());
1558 EXPECT_EQ(1U, GetAndResetSentEventCount());
1559 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1560 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1563 // Tests that secondary touch points can be forwarded after scrolling begins
1564 // while first touch point has no consumer.
1565 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) {
1566 // Queue a TouchStart.
1567 PressTouchPoint(0, 0);
1568 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1569 ASSERT_EQ(1U, GetAndResetSentEventCount());
1570 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1572 WebGestureEvent followup_scroll;
1573 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1574 SetFollowupEvent(followup_scroll);
1575 MoveTouchPoint(0, 20, 5);
1576 EXPECT_EQ(0U, GetAndResetSentEventCount());
1577 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1578 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1580 // The secondary pointer press should be forwarded.
1581 PressTouchPoint(20, 0);
1582 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1583 EXPECT_EQ(1U, GetAndResetSentEventCount());
1584 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1586 // TouchMove with a secondary pointer should also be forwarded.
1587 MoveTouchPoint(1, 25, 0);
1588 EXPECT_EQ(1U, queued_event_count());
1589 EXPECT_EQ(1U, GetAndResetSentEventCount());
1590 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1591 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1594 TEST_F(TouchEventQueueTest, AsyncTouch) {
1595 // Queue a TouchStart.
1596 PressTouchPoint(0, 1);
1597 EXPECT_EQ(1U, GetAndResetSentEventCount());
1598 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1599 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1601 for (int i = 0; i < 3; ++i) {
1602 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1603 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1605 MoveTouchPoint(0, 10, 5+i);
1606 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1607 EXPECT_FALSE(HasPendingAsyncTouchMove());
1608 EXPECT_TRUE(sent_event().cancelable);
1609 EXPECT_EQ(0U, queued_event_count());
1610 EXPECT_EQ(1U, GetAndResetSentEventCount());
1612 // Consuming a scroll event will throttle subsequent touchmoves.
1613 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1614 INPUT_EVENT_ACK_STATE_CONSUMED);
1615 MoveTouchPoint(0, 10, 7+i);
1616 EXPECT_TRUE(HasPendingAsyncTouchMove());
1617 EXPECT_EQ(0U, queued_event_count());
1618 EXPECT_EQ(0U, GetAndResetSentEventCount());
1622 // Ensure that touchmove's are appropriately throttled during a typical
1623 // scroll sequences that transitions between scrolls consumed and unconsumed.
1624 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
1625 // Process a TouchStart
1626 PressTouchPoint(0, 1);
1627 EXPECT_EQ(1U, GetAndResetSentEventCount());
1628 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1629 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1631 // Now send the first touch move and associated GestureScrollBegin.
1632 MoveTouchPoint(0, 0, 5);
1633 WebGestureEvent followup_scroll;
1634 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1635 SetFollowupEvent(followup_scroll);
1636 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1637 EXPECT_EQ(1U, GetAndResetSentEventCount());
1638 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1639 SendGestureEventAck(WebInputEvent::GestureScrollBegin,
1640 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1642 // Send the second touch move and associated GestureScrollUpdate, but don't
1643 // ACK the gesture event yet.
1644 MoveTouchPoint(0, 0, 50);
1645 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1646 SetFollowupEvent(followup_scroll);
1647 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1648 EXPECT_EQ(1U, GetAndResetSentEventCount());
1649 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1651 // Now queue a second touchmove and verify it's not (yet) dispatched.
1652 MoveTouchPoint(0, 0, 100);
1653 SetFollowupEvent(followup_scroll);
1654 EXPECT_TRUE(HasPendingAsyncTouchMove());
1655 EXPECT_EQ(0U, queued_event_count());
1656 EXPECT_EQ(0U, GetAndResetSentEventCount());
1657 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1659 // Queuing the final touchend should flush the pending async touchmove. In
1660 // this case, we will first dispatch an async touchmove and then a touchend.
1661 // For the async touchmove, we will not send ack again.
1662 ReleaseTouchPoint(0);
1663 followup_scroll.type = WebInputEvent::GestureScrollEnd;
1664 SetFollowupEvent(followup_scroll);
1665 EXPECT_FALSE(HasPendingAsyncTouchMove());
1666 EXPECT_EQ(2U, all_sent_events().size());
1667 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1668 EXPECT_FALSE(all_sent_events()[0].cancelable);
1669 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type);
1670 EXPECT_FALSE(all_sent_events()[1].cancelable);
1671 EXPECT_EQ(2U, GetAndResetSentEventCount());
1672 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1673 EXPECT_EQ(1U, queued_event_count());
1675 // Ack the touchend.
1676 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1677 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1678 EXPECT_EQ(0U, queued_event_count());
1679 EXPECT_EQ(0U, GetAndResetSentEventCount());
1680 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1682 // Now mark the scrolls as not consumed (which would cause future touchmoves
1683 // in the active sequence to be sent if there was one).
1684 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1685 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1686 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1687 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1689 // Start a new touch sequence and verify that throttling has been reset.
1690 // Touch moves after the start of scrolling will again be throttled.
1691 PressTouchPoint(0, 0);
1692 EXPECT_EQ(1U, GetAndResetSentEventCount());
1693 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1694 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1695 MoveTouchPoint(0, 0, 5);
1696 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1697 SetFollowupEvent(followup_scroll);
1698 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1699 EXPECT_EQ(1U, GetAndResetSentEventCount());
1700 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1702 MoveTouchPoint(0, 0, 6);
1703 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1704 SetFollowupEvent(followup_scroll);
1705 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1706 EXPECT_FALSE(HasPendingAsyncTouchMove());
1707 EXPECT_EQ(1U, GetAndResetSentEventCount());
1708 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1710 MoveTouchPoint(0, 0, 10);
1711 EXPECT_TRUE(HasPendingAsyncTouchMove());
1712 EXPECT_EQ(0U, queued_event_count());
1713 EXPECT_EQ(0U, GetAndResetSentEventCount());
1714 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1716 // Subsequent touchmove's should be deferred.
1717 MoveTouchPoint(0, 0, 25);
1718 EXPECT_TRUE(HasPendingAsyncTouchMove());
1719 EXPECT_EQ(0U, queued_event_count());
1720 EXPECT_EQ(0U, GetAndResetSentEventCount());
1721 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1722 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
1724 // The pending touchmove should be flushed with the the new touchmove if
1725 // sufficient time has passed and ack to the client.
1726 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1727 MoveTouchPoint(0, 0, 15);
1728 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1729 EXPECT_FALSE(HasPendingAsyncTouchMove());
1730 EXPECT_FALSE(sent_event().cancelable);
1731 EXPECT_EQ(0U, queued_event_count());
1732 EXPECT_EQ(1U, GetAndResetSentEventCount());
1733 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1735 // Non-touchmove events should always flush any pending touchmove events. In
1736 // this case, we will first dispatch an async touchmove and then a
1737 // touchstart. For the async touchmove, we will not send ack again.
1738 MoveTouchPoint(0, 0, 25);
1739 EXPECT_TRUE(HasPendingAsyncTouchMove());
1740 EXPECT_EQ(0U, queued_event_count());
1741 EXPECT_EQ(0U, GetAndResetSentEventCount());
1742 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1743 PressTouchPoint(30, 30);
1744 EXPECT_FALSE(HasPendingAsyncTouchMove());
1745 EXPECT_EQ(2U, all_sent_events().size());
1746 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1747 EXPECT_FALSE(all_sent_events()[0].cancelable);
1748 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type);
1749 EXPECT_TRUE(all_sent_events()[1].cancelable);
1750 EXPECT_EQ(2U, GetAndResetSentEventCount());
1751 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1752 EXPECT_EQ(1U, queued_event_count());
1754 // Ack the touchstart.
1755 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1756 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1757 EXPECT_EQ(0U, queued_event_count());
1758 EXPECT_EQ(0U, GetAndResetSentEventCount());
1759 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1761 // Send a secondary touchmove.
1762 MoveTouchPoint(1, 0, 25);
1763 EXPECT_TRUE(HasPendingAsyncTouchMove());
1764 EXPECT_EQ(0U, queued_event_count());
1765 EXPECT_EQ(0U, GetAndResetSentEventCount());
1766 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1768 // An unconsumed scroll should resume synchronous touch handling.
1769 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1770 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1772 // The pending touchmove should be coalesced with the next (now synchronous)
1773 // touchmove.
1774 MoveTouchPoint(0, 0, 26);
1775 EXPECT_TRUE(sent_event().cancelable);
1776 EXPECT_FALSE(HasPendingAsyncTouchMove());
1777 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
1778 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state);
1779 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1780 EXPECT_EQ(1U, queued_event_count());
1781 EXPECT_EQ(1U, GetAndResetSentEventCount());
1782 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1784 // Subsequent touches will queue until the preceding, synchronous touches are
1785 // ack'ed.
1786 ReleaseTouchPoint(1);
1787 EXPECT_EQ(2U, queued_event_count());
1788 ReleaseTouchPoint(0);
1789 EXPECT_EQ(3U, queued_event_count());
1790 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1791 EXPECT_TRUE(sent_event().cancelable);
1792 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1793 EXPECT_EQ(2U, queued_event_count());
1794 EXPECT_EQ(1U, GetAndResetSentEventCount());
1795 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1797 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1798 EXPECT_TRUE(sent_event().cancelable);
1799 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type);
1800 EXPECT_EQ(1U, queued_event_count());
1801 EXPECT_EQ(1U, GetAndResetSentEventCount());
1802 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1804 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1805 EXPECT_EQ(0U, queued_event_count());
1806 EXPECT_EQ(0U, GetAndResetSentEventCount());
1807 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1810 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByTouchEnd) {
1811 PressTouchPoint(0, 0);
1812 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1813 EXPECT_EQ(1U, GetAndResetSentEventCount());
1814 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1816 // Initiate async touchmove dispatch after the start of a scroll sequence.
1817 MoveTouchPoint(0, 0, 5);
1818 WebGestureEvent followup_scroll;
1819 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1820 SetFollowupEvent(followup_scroll);
1821 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1822 EXPECT_EQ(1U, GetAndResetSentEventCount());
1823 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1825 MoveTouchPoint(0, 0, 10);
1826 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
1827 SetFollowupEvent(followup_scroll);
1828 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1829 EXPECT_EQ(1U, GetAndResetSentEventCount());
1830 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1832 // Now queue a second touchmove and verify it's not (yet) dispatched.
1833 MoveTouchPoint(0, 0, 100);
1834 EXPECT_TRUE(HasPendingAsyncTouchMove());
1835 EXPECT_EQ(0U, queued_event_count());
1836 EXPECT_EQ(0U, GetAndResetSentEventCount());
1837 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1839 // Return the touch sequence to the original touchstart position. Note that
1840 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove.
1841 MoveTouchPoint(0, 0, 0);
1842 EXPECT_TRUE(HasPendingAsyncTouchMove());
1843 EXPECT_EQ(0U, queued_event_count());
1844 EXPECT_EQ(0U, GetAndResetSentEventCount());
1845 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1847 // Queuing the final touchend should flush the pending, async touchmove. In
1848 // this case, we will first dispatch an async touchmove and then a touchend.
1849 // For the async touchmove, we will not send ack again.
1850 ReleaseTouchPoint(0);
1851 EXPECT_FALSE(HasPendingAsyncTouchMove());
1852 EXPECT_EQ(2U, all_sent_events().size());
1853 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1854 EXPECT_FALSE(all_sent_events()[0].cancelable);
1855 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.x);
1856 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.y);
1857 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type);
1858 EXPECT_FALSE(all_sent_events()[1].cancelable);
1859 EXPECT_EQ(2U, GetAndResetSentEventCount());
1860 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1863 // Ensure that async touch dispatch and touch ack timeout interactions work
1864 // appropriately.
1865 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1866 SetUpForTimeoutTesting();
1868 // The touchstart should start the timeout.
1869 PressTouchPoint(0, 0);
1870 EXPECT_EQ(1U, GetAndResetSentEventCount());
1871 EXPECT_TRUE(IsTimeoutRunning());
1872 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1873 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1874 EXPECT_FALSE(IsTimeoutRunning());
1876 // The start of a scroll gesture should trigger async touch event dispatch.
1877 MoveTouchPoint(0, 1, 1);
1878 EXPECT_EQ(1U, GetAndResetSentEventCount());
1879 EXPECT_TRUE(IsTimeoutRunning());
1880 WebGestureEvent followup_scroll;
1881 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1882 SetFollowupEvent(followup_scroll);
1883 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1884 EXPECT_FALSE(IsTimeoutRunning());
1885 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1887 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1888 INPUT_EVENT_ACK_STATE_CONSUMED);
1890 // An async touch should fire after the throttling interval has expired, but
1891 // it should not start the touch ack timeout.
1892 MoveTouchPoint(0, 5, 5);
1893 EXPECT_TRUE(HasPendingAsyncTouchMove());
1894 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1896 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1897 MoveTouchPoint(0, 5, 5);
1898 EXPECT_FALSE(IsTimeoutRunning());
1899 EXPECT_FALSE(HasPendingAsyncTouchMove());
1900 EXPECT_FALSE(sent_event().cancelable);
1901 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1902 EXPECT_EQ(1U, GetAndResetSentEventCount());
1904 // An unconsumed scroll event will resume synchronous touchmoves, which are
1905 // subject to the ack timeout.
1906 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1907 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1908 MoveTouchPoint(0, 20, 5);
1909 EXPECT_TRUE(IsTimeoutRunning());
1910 EXPECT_TRUE(sent_event().cancelable);
1911 EXPECT_EQ(1U, GetAndResetSentEventCount());
1913 // The timeout should fire, disabling touch forwarding until both acks are
1914 // received and acking the timed out event.
1915 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1916 EXPECT_FALSE(IsTimeoutRunning());
1917 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1918 EXPECT_EQ(0U, GetAndResetSentEventCount());
1920 // Ack'ing the original event should trigger a cancel event.
1921 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1922 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1923 EXPECT_FALSE(sent_event().cancelable);
1924 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1925 EXPECT_EQ(1U, GetAndResetSentEventCount());
1927 // Subsequent touchmove's should not be forwarded, even as the scroll gesture
1928 // goes from unconsumed to consumed.
1929 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1930 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1931 MoveTouchPoint(0, 20, 5);
1932 EXPECT_FALSE(HasPendingAsyncTouchMove());
1933 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1934 EXPECT_EQ(0U, GetAndResetSentEventCount());
1936 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1937 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1938 MoveTouchPoint(0, 25, 5);
1939 EXPECT_FALSE(HasPendingAsyncTouchMove());
1940 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1941 EXPECT_EQ(0U, GetAndResetSentEventCount());
1944 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1945 // touch event, that follow-up touch will be forwarded appropriately.
1946 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) {
1947 PressTouchPoint(0, 0);
1948 EXPECT_EQ(1U, GetAndResetSentEventCount());
1949 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1950 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1952 // The start of a scroll gesture should trigger async touch event dispatch.
1953 MoveTouchPoint(0, 1, 1);
1954 EXPECT_EQ(1U, GetAndResetSentEventCount());
1955 WebGestureEvent followup_scroll;
1956 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1957 SetFollowupEvent(followup_scroll);
1958 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1959 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1960 EXPECT_EQ(0U, queued_event_count());
1962 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
1964 // The async touchmove should be ack'ed immediately, but not forwarded.
1965 // However, because the ack triggers a touchcancel, both the pending touch and
1966 // the queued touchcancel should be flushed.
1967 WebTouchEvent followup_cancel;
1968 followup_cancel.type = WebInputEvent::TouchCancel;
1969 followup_cancel.touchesLength = 1;
1970 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
1971 SetFollowupEvent(followup_cancel);
1972 MoveTouchPoint(0, 5, 5);
1973 EXPECT_EQ(1U, queued_event_count());
1974 EXPECT_EQ(2U, all_sent_events().size());
1975 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
1976 EXPECT_FALSE(all_sent_events()[0].cancelable);
1977 EXPECT_EQ(WebInputEvent::TouchCancel, all_sent_events()[1].type);
1978 EXPECT_FALSE(all_sent_events()[1].cancelable);
1979 EXPECT_EQ(2U, GetAndResetSentEventCount());
1980 // Sending the ack is because the async touchmove is not ready for
1981 // dispatching send the ack immediately.
1982 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1983 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
1985 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1986 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1987 EXPECT_EQ(0U, queued_event_count());
1988 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type);
1989 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1990 EXPECT_EQ(0U, GetAndResetSentEventCount());
1993 // Ensure that the async touch is fully reset if the touch sequence restarts
1994 // without properly terminating.
1995 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) {
1996 PressTouchPoint(0, 0);
1997 EXPECT_EQ(1U, GetAndResetSentEventCount());
1998 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1999 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2001 // Trigger async touchmove dispatch.
2002 MoveTouchPoint(0, 1, 1);
2003 EXPECT_EQ(1U, GetAndResetSentEventCount());
2004 WebGestureEvent followup_scroll;
2005 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2006 SetFollowupEvent(followup_scroll);
2007 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2008 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2009 EXPECT_EQ(0U, queued_event_count());
2010 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
2012 // The async touchmove should be immediately ack'ed but delivery is deferred.
2013 MoveTouchPoint(0, 2, 2);
2014 EXPECT_EQ(0U, GetAndResetSentEventCount());
2015 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2016 EXPECT_EQ(0U, queued_event_count());
2017 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
2019 // The queue should be robust to hard touch restarts with a new touch
2020 // sequence. In this case, the deferred async touch should not be flushed
2021 // by the new touch sequence.
2022 SendGestureEvent(WebInputEvent::GestureScrollEnd);
2023 ResetTouchEvent();
2025 PressTouchPoint(0, 0);
2026 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type);
2027 EXPECT_EQ(1U, GetAndResetSentEventCount());
2028 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2029 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2032 // Ensure that even when the interval expires, we still need to wait for the
2033 // ack sent back from render to send the next async touchmove once the scroll
2034 // starts.
2035 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
2036 // Process a TouchStart
2037 PressTouchPoint(0, 1);
2038 EXPECT_EQ(1U, GetAndResetSentEventCount());
2039 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2040 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2042 // Initiate async touchmove dispatch after the start of a scroll sequence.
2043 MoveTouchPoint(0, 0, 5);
2044 WebGestureEvent followup_scroll;
2045 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2046 SetFollowupEvent(followup_scroll);
2047 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2048 EXPECT_EQ(1U, GetAndResetSentEventCount());
2049 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2051 MoveTouchPoint(0, 0, 10);
2052 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2053 SetFollowupEvent(followup_scroll);
2054 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2055 EXPECT_FALSE(HasPendingAsyncTouchMove());
2056 EXPECT_EQ(1U, GetAndResetSentEventCount());
2057 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2059 // We set the next touch event time to be after the throttled interval.
2060 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2061 // Dispatch the touch move event when sufficient time has passed.
2062 MoveTouchPoint(0, 0, 40);
2063 EXPECT_FALSE(HasPendingAsyncTouchMove());
2064 EXPECT_FALSE(sent_event().cancelable);
2065 // When we dispatch an async touchmove, we do not put it back to the queue
2066 // any more and we will ack to client right away.
2067 EXPECT_EQ(0U, queued_event_count());
2068 EXPECT_EQ(1U, GetAndResetSentEventCount());
2069 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2070 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2072 // Do not dispatch the event until throttledTouchmoves intervals expires and
2073 // receive an ack from render.
2074 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2075 MoveTouchPoint(0, 0, 50);
2076 EXPECT_TRUE(HasPendingAsyncTouchMove());
2077 EXPECT_EQ(0U, queued_event_count());
2078 EXPECT_EQ(0U, GetAndResetSentEventCount());
2079 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2080 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2082 // Send pending_async_touch_move_ when we receive an ack back from render,
2083 // but we will not send an ack for pending_async_touch_move_ becasue it is
2084 // been acked before.
2085 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2086 EXPECT_FALSE(HasPendingAsyncTouchMove());
2087 EXPECT_EQ(0U, queued_event_count());
2088 EXPECT_EQ(1U, GetAndResetSentEventCount());
2089 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2090 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2093 // Ensure that even when we receive the ack from render, we still need to wait
2094 // for the interval expires to send the next async touchmove once the scroll
2095 // starts.
2096 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
2097 // Process a TouchStart
2098 PressTouchPoint(0, 1);
2099 EXPECT_EQ(1U, GetAndResetSentEventCount());
2100 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2101 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2103 // Initiate async touchmove dispatch after the start of a scroll sequence.
2104 MoveTouchPoint(0, 0, 5);
2105 WebGestureEvent followup_scroll;
2106 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2107 SetFollowupEvent(followup_scroll);
2108 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2109 EXPECT_EQ(1U, GetAndResetSentEventCount());
2110 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2112 MoveTouchPoint(0, 0, 10);
2113 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2114 SetFollowupEvent(followup_scroll);
2115 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2116 EXPECT_FALSE(HasPendingAsyncTouchMove());
2117 EXPECT_EQ(1U, GetAndResetSentEventCount());
2118 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2120 // Dispatch the touch move event when sufficient time has passed.
2121 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2122 MoveTouchPoint(0, 0, 40);
2123 EXPECT_FALSE(HasPendingAsyncTouchMove());
2124 EXPECT_FALSE(sent_event().cancelable);
2125 // When we dispatch an async touchmove, we do not put it back to the queue
2126 // any more and we will ack to client right away.
2127 EXPECT_EQ(0U, queued_event_count());
2128 EXPECT_EQ(1U, GetAndResetSentEventCount());
2129 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2130 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2132 // We receive an ack back from render but the time interval is not expired,
2133 // so we do not dispatch the touch move event.
2134 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2135 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2136 MoveTouchPoint(0, 0, 50);
2137 EXPECT_TRUE(HasPendingAsyncTouchMove());
2138 EXPECT_EQ(0U, queued_event_count());
2139 EXPECT_EQ(0U, GetAndResetSentEventCount());
2140 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2142 // Dispatch the touch move when sufficient time has passed.
2143 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2144 MoveTouchPoint(0, 0, 50);
2145 EXPECT_FALSE(HasPendingAsyncTouchMove());
2146 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2147 EXPECT_FALSE(sent_event().cancelable);
2148 EXPECT_EQ(0U, queued_event_count());
2149 EXPECT_EQ(1U, GetAndResetSentEventCount());
2150 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2151 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2154 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
2155 // Process a TouchStart
2156 PressTouchPoint(0, 1);
2157 EXPECT_EQ(1U, GetAndResetSentEventCount());
2158 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2159 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2161 // Initiate async touchmove dispatch after the start of a scroll sequence.
2162 MoveTouchPoint(0, 0, 5);
2163 WebGestureEvent followup_scroll;
2164 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2165 SetFollowupEvent(followup_scroll);
2166 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2167 EXPECT_EQ(1U, GetAndResetSentEventCount());
2168 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2170 MoveTouchPoint(0, 0, 10);
2171 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2172 SetFollowupEvent(followup_scroll);
2173 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2174 EXPECT_FALSE(HasPendingAsyncTouchMove());
2175 EXPECT_EQ(1U, GetAndResetSentEventCount());
2176 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2178 // Dispatch the touch move when sufficient time has passed.
2179 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2180 MoveTouchPoint(0, 0, 40);
2181 EXPECT_FALSE(HasPendingAsyncTouchMove());
2182 EXPECT_FALSE(sent_event().cancelable);
2183 // When we dispatch an async touchmove, we do not put it back to the queue
2184 // any more and we will ack to client right away.
2185 EXPECT_EQ(0U, queued_event_count());
2186 EXPECT_EQ(1U, GetAndResetSentEventCount());
2187 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2188 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2190 for (int i = 0; i < 3; ++i) {
2191 // We throttle the touchmoves, put it in the pending_async_touch_move_,
2192 // do not dispatch it.
2193 MoveTouchPoint(0, 10 + 10 * i, 10 + 10 * i);
2194 EXPECT_TRUE(HasPendingAsyncTouchMove());
2195 EXPECT_EQ(0U, queued_event_count());
2196 EXPECT_EQ(0U, GetAndResetSentEventCount());
2197 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2198 EXPECT_EQ(static_cast<size_t>(i + 1),
2199 uncancelable_touch_moves_pending_ack_count());
2201 // Send touchstart will flush pending_async_touch_move_, and increase the
2202 // count. In this case, we will first dispatch an async touchmove and
2203 // then a touchstart. For the async touchmove, we will not send ack again.
2204 PressTouchPoint(30, 30);
2205 EXPECT_FALSE(HasPendingAsyncTouchMove());
2206 EXPECT_EQ(2U, all_sent_events().size());
2207 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type);
2208 EXPECT_FALSE(all_sent_events()[0].cancelable);
2209 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.x);
2210 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.y);
2211 EXPECT_EQ(static_cast<size_t>(i + 2),
2212 uncancelable_touch_moves_pending_ack_count());
2213 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type);
2214 EXPECT_TRUE(all_sent_events()[1].cancelable);
2215 EXPECT_EQ(2U, GetAndResetSentEventCount());
2216 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2218 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_NOT_CONSUMED,
2219 GetUniqueTouchEventID());
2220 EXPECT_EQ(0U, queued_event_count());
2221 EXPECT_FALSE(HasPendingAsyncTouchMove());
2222 EXPECT_EQ(0U, GetAndResetSentEventCount());
2223 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2226 EXPECT_EQ(4U, uncancelable_touch_moves_pending_ack_count());
2228 // When we receive an ack from render we decrease the count.
2229 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2230 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2231 EXPECT_EQ(0U, queued_event_count());
2232 EXPECT_FALSE(HasPendingAsyncTouchMove());
2234 // Do not dispatch the next uncancelable touchmove when we have not received
2235 // all the acks back from render.
2236 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2237 MoveTouchPoint(0, 20, 30);
2238 EXPECT_TRUE(HasPendingAsyncTouchMove());
2239 EXPECT_EQ(0U, queued_event_count());
2240 EXPECT_EQ(0U, GetAndResetSentEventCount());
2241 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2242 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2244 // Once we receive the ack from render, we do not dispatch the
2245 // pending_async_touchmove_ until the count is 0.
2246 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2247 EXPECT_EQ(2U, uncancelable_touch_moves_pending_ack_count());
2248 EXPECT_EQ(0U, queued_event_count());
2249 EXPECT_TRUE(HasPendingAsyncTouchMove());
2251 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2253 // When we receive this ack from render, and the count is 0, so we can
2254 // dispatch the pending_async_touchmove_.
2255 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2256 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2257 EXPECT_FALSE(HasPendingAsyncTouchMove());
2258 EXPECT_EQ(0U, queued_event_count());
2259 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2260 EXPECT_FALSE(sent_event().cancelable);
2261 EXPECT_EQ(1U, GetAndResetSentEventCount());
2262 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2265 // Ensure that even when we receive the ack from render, we still need to wait
2266 // for the interval expires to send the next async touchmove once the scroll
2267 // starts.
2268 TEST_F(TouchEventQueueTest, DoNotIncreaseIfClientConsumeAsyncTouchMove) {
2269 // Process a TouchStart
2270 PressTouchPoint(0, 1);
2271 EXPECT_EQ(1U, GetAndResetSentEventCount());
2272 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2273 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2275 // Initiate async touchmove dispatch after the start of a scroll sequence.
2276 MoveTouchPoint(0, 0, 5);
2277 WebGestureEvent followup_scroll;
2278 followup_scroll.type = WebInputEvent::GestureScrollBegin;
2279 SetFollowupEvent(followup_scroll);
2280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2281 EXPECT_EQ(1U, GetAndResetSentEventCount());
2282 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2284 MoveTouchPoint(0, 0, 10);
2285 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2286 SetFollowupEvent(followup_scroll);
2287 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2288 EXPECT_FALSE(HasPendingAsyncTouchMove());
2289 EXPECT_EQ(1U, GetAndResetSentEventCount());
2290 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2292 // Dispatch the touch move event when sufficient time has passed.
2293 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2294 MoveTouchPoint(0, 0, 40);
2295 EXPECT_FALSE(HasPendingAsyncTouchMove());
2296 EXPECT_FALSE(sent_event().cancelable);
2297 // When we dispatch an async touchmove, we do not put it back to the queue
2298 // any more and we will ack to client right away.
2299 EXPECT_EQ(0U, queued_event_count());
2300 EXPECT_EQ(1U, GetAndResetSentEventCount());
2301 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2302 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2304 // We receive an ack back from render but the time interval is not expired,
2305 // so we do not dispatch the touch move event.
2306 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2307 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2308 MoveTouchPoint(0, 0, 50);
2309 EXPECT_TRUE(HasPendingAsyncTouchMove());
2310 EXPECT_EQ(0U, queued_event_count());
2311 EXPECT_EQ(0U, GetAndResetSentEventCount());
2312 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2314 // Dispatch the touch move when sufficient time has passed. Becasue the event
2315 // is consumed by client already, we would not increase the count and ack to
2316 // client again.
2317 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2318 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
2319 MoveTouchPoint(0, 0, 50);
2320 EXPECT_FALSE(HasPendingAsyncTouchMove());
2321 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type);
2322 EXPECT_FALSE(sent_event().cancelable);
2323 EXPECT_EQ(0U, queued_event_count());
2324 EXPECT_EQ(1U, GetAndResetSentEventCount());
2325 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2326 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2329 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
2330 // Queue a TouchStart.
2331 PressTouchPoint(0, 1);
2332 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2333 EXPECT_EQ(0U, queued_event_count());
2334 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2336 MoveTouchPoint(0, 20, 5);
2337 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2338 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2339 EXPECT_EQ(0U, queued_event_count());
2340 EXPECT_EQ(2U, GetAndResetSentEventCount());
2342 // Even if the first touchmove event was consumed, subsequent unconsumed
2343 // touchmove events should trigger scrolling.
2344 MoveTouchPoint(0, 60, 5);
2345 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2346 EXPECT_EQ(0U, queued_event_count());
2347 EXPECT_TRUE(sent_event().cancelable);
2348 EXPECT_EQ(1U, GetAndResetSentEventCount());
2350 MoveTouchPoint(0, 20, 5);
2351 WebGestureEvent followup_scroll;
2352 followup_scroll.type = WebInputEvent::GestureScrollUpdate;
2353 SetFollowupEvent(followup_scroll);
2354 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2355 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
2356 INPUT_EVENT_ACK_STATE_CONSUMED);
2357 EXPECT_EQ(0U, queued_event_count());
2358 EXPECT_TRUE(sent_event().cancelable);
2359 EXPECT_EQ(1U, GetAndResetSentEventCount());
2361 // Touch move event is throttled.
2362 MoveTouchPoint(0, 60, 5);
2363 EXPECT_EQ(0U, queued_event_count());
2364 EXPECT_EQ(0U, GetAndResetSentEventCount());
2367 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) {
2368 // Queue a touchstart and touchmove that go unconsumed, transitioning to an
2369 // active scroll sequence.
2370 PressTouchPoint(0, 1);
2371 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2372 EXPECT_TRUE(sent_event().cancelable);
2373 ASSERT_EQ(1U, GetAndResetSentEventCount());
2375 MoveTouchPoint(0, 20, 5);
2376 EXPECT_TRUE(sent_event().cancelable);
2377 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2378 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2379 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2380 EXPECT_TRUE(sent_event().cancelable);
2381 ASSERT_EQ(1U, GetAndResetSentEventCount());
2383 // Even though scrolling has begun, touchstart events should be cancelable,
2384 // allowing, for example, customized pinch processing.
2385 PressTouchPoint(10, 11);
2386 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2387 EXPECT_TRUE(sent_event().cancelable);
2388 ASSERT_EQ(1U, GetAndResetSentEventCount());
2390 // As the touch start was consumed, touchmoves should no longer be throttled.
2391 MoveTouchPoint(1, 11, 11);
2392 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2393 EXPECT_TRUE(sent_event().cancelable);
2394 ASSERT_EQ(1U, GetAndResetSentEventCount());
2396 // With throttling disabled, touchend and touchmove events should also be
2397 // cancelable.
2398 MoveTouchPoint(1, 12, 12);
2399 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2400 EXPECT_TRUE(sent_event().cancelable);
2401 ASSERT_EQ(1U, GetAndResetSentEventCount());
2402 ReleaseTouchPoint(1);
2403 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2404 EXPECT_TRUE(sent_event().cancelable);
2405 ASSERT_EQ(1U, GetAndResetSentEventCount());
2407 // If subsequent touchmoves aren't consumed, the generated scroll events
2408 // will restore async touch dispatch.
2409 MoveTouchPoint(0, 25, 5);
2410 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2411 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2412 EXPECT_TRUE(sent_event().cancelable);
2413 ASSERT_EQ(1U, GetAndResetSentEventCount());
2414 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2415 MoveTouchPoint(0, 30, 5);
2416 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2417 EXPECT_FALSE(sent_event().cancelable);
2418 ASSERT_EQ(1U, GetAndResetSentEventCount());
2420 // The touchend will be uncancelable during an active scroll sequence.
2421 ReleaseTouchPoint(0);
2422 EXPECT_FALSE(sent_event().cancelable);
2423 ASSERT_EQ(1U, GetAndResetSentEventCount());
2426 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) {
2427 SyntheticWebTouchEvent event;
2428 event.PressPoint(0, 0);
2429 SendTouchEvent(event);
2430 EXPECT_EQ(1U, GetAndResetSentEventCount());
2431 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2432 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2434 // Give the touchmove a previously unseen pointer id; it should not be sent.
2435 int press_id = event.touches[0].id;
2436 event.MovePoint(0, 1, 1);
2437 event.touches[0].id = 7;
2438 SendTouchEvent(event);
2439 EXPECT_EQ(0U, GetAndResetSentEventCount());
2440 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2442 // Give the touchmove a valid id; it should be sent.
2443 event.touches[0].id = press_id;
2444 SendTouchEvent(event);
2445 EXPECT_EQ(1U, GetAndResetSentEventCount());
2446 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2447 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2449 // Do the same for release.
2450 event.ReleasePoint(0);
2451 event.touches[0].id = 11;
2452 SendTouchEvent(event);
2453 EXPECT_EQ(0U, GetAndResetSentEventCount());
2454 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2456 // Give the touchmove a valid id; it should be sent.
2457 event.touches[0].id = press_id;
2458 SendTouchEvent(event);
2459 EXPECT_EQ(1U, GetAndResetSentEventCount());
2460 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2461 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2464 // Tests that touch points states are correct in TouchMove events.
2465 TEST_F(TouchEventQueueTest, PointerStatesInTouchMove) {
2466 PressTouchPoint(1, 1);
2467 PressTouchPoint(2, 2);
2468 PressTouchPoint(3, 3);
2469 PressTouchPoint(4, 4);
2470 EXPECT_EQ(4U, queued_event_count());
2471 EXPECT_EQ(1U, GetAndResetSentEventCount());
2473 // Receive ACK for the first three touch-events.
2474 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2475 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2476 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2477 EXPECT_EQ(1U, queued_event_count());
2479 // Test current touches state before sending TouchMoves.
2480 const WebTouchEvent& event1 = sent_event();
2481 EXPECT_EQ(WebInputEvent::TouchStart, event1.type);
2482 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state);
2483 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2484 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state);
2485 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state);
2487 // Move x-position for 1st touch, y-position for 2nd touch
2488 // and do not move other touches.
2489 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2490 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f);
2491 EXPECT_EQ(2U, queued_event_count());
2493 // Receive an ACK for the last TouchPress event.
2494 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2496 // 1st TouchMove is sent. Test for touches state.
2497 const WebTouchEvent& event2 = sent_event();
2498 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2499 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2500 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2501 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state);
2502 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[3].state);
2504 // Move only 4th touch but not others.
2505 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2506 MoveTouchPoints(2, 3.f, 3.f, 3, 4.1f, 4.1f);
2508 // Receive an ACK for previous (1st) TouchMove.
2509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2511 // 2nd TouchMove is sent. Test for touches state.
2512 const WebTouchEvent& event3 = sent_event();
2513 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2514 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state);
2515 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state);
2516 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state);
2517 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state);
2520 // Tests that touch point state is correct in TouchMove events
2521 // when point properties other than position changed.
2522 TEST_F(TouchEventQueueTest, PointerStatesWhenOtherThanPositionChanged) {
2523 PressTouchPoint(1, 1);
2524 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2526 // Default initial radiusX/Y is (1.f, 1.f).
2527 // Default initial rotationAngle is 1.f.
2528 // Default initial force is 1.f.
2530 // Change touch point radius only.
2531 ChangeTouchPointRadius(0, 1.5f, 1.f);
2532 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2534 // TouchMove is sent. Test for pointer state.
2535 const WebTouchEvent& event1 = sent_event();
2536 EXPECT_EQ(WebInputEvent::TouchMove, event1.type);
2537 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2539 // Change touch point force.
2540 ChangeTouchPointForce(0, 0.9f);
2541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2543 // TouchMove is sent. Test for pointer state.
2544 const WebTouchEvent& event2 = sent_event();
2545 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2546 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2548 // Change touch point rotationAngle.
2549 ChangeTouchPointRotationAngle(0, 1.1f);
2550 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2552 // TouchMove is sent. Test for pointer state.
2553 const WebTouchEvent& event3 = sent_event();
2554 EXPECT_EQ(WebInputEvent::TouchMove, event3.type);
2555 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state);
2557 EXPECT_EQ(0U, queued_event_count());
2558 EXPECT_EQ(4U, GetAndResetSentEventCount());
2559 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2562 // Tests that TouchMoves are filtered when none of the points are changed.
2563 TEST_F(TouchEventQueueTest, FilterTouchMovesWhenNoPointerChanged) {
2564 PressTouchPoint(1, 1);
2565 PressTouchPoint(2, 2);
2566 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2567 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2568 EXPECT_EQ(0U, queued_event_count());
2569 EXPECT_EQ(2U, GetAndResetSentEventCount());
2570 EXPECT_EQ(2U, GetAndResetAckedEventCount());
2572 // Move 1st touch point.
2573 MoveTouchPoint(0, 10, 10);
2574 EXPECT_EQ(1U, queued_event_count());
2576 // TouchMove should be allowed and test for touches state.
2577 const WebTouchEvent& event1 = sent_event();
2578 EXPECT_EQ(WebInputEvent::TouchMove, event1.type);
2579 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2580 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2581 EXPECT_EQ(1U, GetAndResetSentEventCount());
2582 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2584 // Do not really move any touch points, but use previous values.
2585 MoveTouchPoint(0, 10, 10);
2586 ChangeTouchPointRadius(1, 1, 1);
2587 MoveTouchPoint(1, 2, 2);
2588 EXPECT_EQ(2U, queued_event_count());
2589 EXPECT_EQ(0U, GetAndResetSentEventCount());
2591 // Receive an ACK for 1st TouchMove.
2592 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2594 // Tries to forward TouchMove but should be filtered
2595 // when none of the touch points have changed.
2596 EXPECT_EQ(0U, queued_event_count());
2597 EXPECT_EQ(0U, GetAndResetSentEventCount());
2598 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2599 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
2601 // Move 2nd touch point.
2602 MoveTouchPoint(1, 3, 3);
2603 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2604 EXPECT_EQ(0U, queued_event_count());
2606 // TouchMove should be allowed and test for touches state.
2607 const WebTouchEvent& event2 = sent_event();
2608 EXPECT_EQ(WebInputEvent::TouchMove, event2.type);
2609 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state);
2610 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2611 EXPECT_EQ(1U, GetAndResetSentEventCount());
2612 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2615 } // namespace content