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

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

Issue 2715623002: Add a passthrough touch event queue. (Closed)
Patch Set: Rebase on throttling change Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/browser/renderer_host/input/touch_event_queue.h"
6
7 #include <stddef.h>
8
9 #include <memory>
10 #include <utility>
11
12 #include "base/location.h"
13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h"
18 #include "content/browser/renderer_host/input/legacy_touch_event_queue.h"
19 #include "content/browser/renderer_host/input/timeout_monitor.h"
20 #include "content/common/input/synthetic_web_input_event_builders.h"
21 #include "content/common/input/web_touch_event_traits.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/public/platform/WebInputEvent.h"
24 #include "ui/events/base_event_utils.h"
25
26 using blink::WebGestureEvent;
27 using blink::WebInputEvent;
28 using blink::WebTouchEvent;
29 using blink::WebTouchPoint;
30
31 namespace content {
32 namespace {
33
34 const double kMinSecondsBetweenThrottledTouchmoves = 0.2;
35 const float kSlopLengthDips = 10;
36 const float kHalfSlopLengthDips = kSlopLengthDips / 2;
37
38 base::TimeDelta DefaultTouchTimeoutDelay() {
39 return base::TimeDelta::FromMilliseconds(1);
40 }
41 } // namespace
42
43 class TouchEventQueueTest : public testing::Test,
44 public TouchEventQueueClient {
45 public:
46 TouchEventQueueTest()
47 : acked_event_count_(0),
48 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
49 slop_length_dips_(0) {}
50
51 ~TouchEventQueueTest() override {}
52
53 // testing::Test
54 void SetUp() override {
55 ResetQueueWithConfig(TouchEventQueue::Config());
56 sent_events_ids_.clear();
57 }
58
59 void TearDown() override { queue_.reset(); }
60
61 // TouchEventQueueClient
62 void SendTouchEventImmediately(
63 const TouchEventWithLatencyInfo& event) override {
64 sent_events_.push_back(event.event);
65 sent_events_ids_.push_back(event.event.uniqueTouchEventId);
66 if (sync_ack_result_) {
67 auto sync_ack_result = std::move(sync_ack_result_);
68 SendTouchEventAck(*sync_ack_result);
69 }
70 }
71
72 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
73 InputEventAckState ack_result) override {
74 ++acked_event_count_;
75 last_acked_event_ = event.event;
76 last_acked_event_state_ = ack_result;
77 if (followup_touch_event_) {
78 std::unique_ptr<WebTouchEvent> followup_touch_event =
79 std::move(followup_touch_event_);
80 SendTouchEvent(*followup_touch_event);
81 }
82 if (followup_gesture_event_) {
83 std::unique_ptr<WebGestureEvent> followup_gesture_event =
84 std::move(followup_gesture_event_);
85 queue_->OnGestureScrollEvent(
86 GestureEventWithLatencyInfo(*followup_gesture_event,
87 ui::LatencyInfo()));
88 }
89 }
90
91 void OnFilteringTouchEvent(const blink::WebTouchEvent& touch_event) override {
92 }
93
94 protected:
95 void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
96 slop_length_dips_ = slop_length_dips;
97 }
98
99 void SetUpForTimeoutTesting(base::TimeDelta desktop_timeout_delay,
100 base::TimeDelta mobile_timeout_delay) {
101 TouchEventQueue::Config config;
102 config.desktop_touch_ack_timeout_delay = desktop_timeout_delay;
103 config.mobile_touch_ack_timeout_delay = mobile_timeout_delay;
104 config.touch_ack_timeout_supported = true;
105 ResetQueueWithConfig(config);
106 }
107
108 void SetUpForTimeoutTesting() {
109 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay(),
110 DefaultTouchTimeoutDelay());
111 }
112
113 void SendTouchEvent(WebTouchEvent event) {
114 if (slop_length_dips_) {
115 event.movedBeyondSlopRegion = false;
116 if (WebTouchEventTraits::IsTouchSequenceStart(event))
117 anchor_ = event.touches[0].position;
118 if (event.type() == WebInputEvent::TouchMove) {
119 gfx::Vector2dF delta = anchor_ - event.touches[0].position;
120 if (delta.LengthSquared() > slop_length_dips_ * slop_length_dips_)
121 event.movedBeyondSlopRegion = true;
122 }
123 } else {
124 event.movedBeyondSlopRegion = event.type() == WebInputEvent::TouchMove;
125 }
126 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
127 }
128
129 void SendGestureEvent(WebInputEvent::Type type) {
130 WebGestureEvent event(type, WebInputEvent::NoModifiers,
131 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
132 queue_->OnGestureScrollEvent(
133 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
134 }
135
136 void SendTouchEventAck(InputEventAckState ack_result) {
137 DCHECK(!sent_events_ids_.empty());
138 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(),
139 sent_events_ids_.front());
140 sent_events_ids_.pop_front();
141 }
142
143 void SendTouchEventAckWithID(InputEventAckState ack_result,
144 int unique_event_id) {
145 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo(), unique_event_id);
146 sent_events_ids_.erase(std::remove(sent_events_ids_.begin(),
147 sent_events_ids_.end(), unique_event_id),
148 sent_events_ids_.end());
149 }
150
151 void SendGestureEventAck(WebInputEvent::Type type,
152 InputEventAckState ack_result) {
153 GestureEventWithLatencyInfo event(
154 type, blink::WebInputEvent::NoModifiers,
155 ui::EventTimeStampToSeconds(ui::EventTimeForNow()), ui::LatencyInfo());
156 queue_->OnGestureEventAck(event, ack_result);
157 }
158
159 void SetFollowupEvent(const WebTouchEvent& event) {
160 followup_touch_event_.reset(new WebTouchEvent(event));
161 }
162
163 void SetFollowupEvent(const WebGestureEvent& event) {
164 followup_gesture_event_.reset(new WebGestureEvent(event));
165 }
166
167 void SetSyncAckResult(InputEventAckState sync_ack_result) {
168 sync_ack_result_.reset(new InputEventAckState(sync_ack_result));
169 }
170
171 void PressTouchPoint(float x, float y) {
172 touch_event_.PressPoint(x, y);
173 SendTouchEvent();
174 }
175
176 void MoveTouchPoint(int index, float x, float y) {
177 touch_event_.MovePoint(index, x, y);
178 SendTouchEvent();
179 }
180
181 void MoveTouchPoints(int index0,
182 float x0,
183 float y0,
184 int index1,
185 float x1,
186 float y1) {
187 touch_event_.MovePoint(index0, x0, y0);
188 touch_event_.MovePoint(index1, x1, y1);
189 SendTouchEvent();
190 }
191
192 void ChangeTouchPointRadius(int index, float radius_x, float radius_y) {
193 CHECK_GE(index, 0);
194 CHECK_LT(index, touch_event_.kTouchesLengthCap);
195 WebTouchPoint& point = touch_event_.touches[index];
196 point.radiusX = radius_x;
197 point.radiusY = radius_y;
198 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
199 touch_event_.movedBeyondSlopRegion = true;
200 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
201 touch_event_.timeStampSeconds(),
202 &touch_event_);
203 SendTouchEvent();
204 }
205
206 void ChangeTouchPointRotationAngle(int index, float rotation_angle) {
207 CHECK_GE(index, 0);
208 CHECK_LT(index, touch_event_.kTouchesLengthCap);
209 WebTouchPoint& point = touch_event_.touches[index];
210 point.rotationAngle = rotation_angle;
211 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
212 touch_event_.movedBeyondSlopRegion = true;
213 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
214 touch_event_.timeStampSeconds(),
215 &touch_event_);
216 SendTouchEvent();
217 }
218
219 void ChangeTouchPointForce(int index, float force) {
220 CHECK_GE(index, 0);
221 CHECK_LT(index, touch_event_.kTouchesLengthCap);
222 WebTouchPoint& point = touch_event_.touches[index];
223 point.force = force;
224 touch_event_.touches[index].state = WebTouchPoint::StateMoved;
225 touch_event_.movedBeyondSlopRegion = true;
226 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove,
227 touch_event_.timeStampSeconds(),
228 &touch_event_);
229 SendTouchEvent();
230 }
231
232 void ReleaseTouchPoint(int index) {
233 touch_event_.ReleasePoint(index);
234 SendTouchEvent();
235 }
236
237 void CancelTouchPoint(int index) {
238 touch_event_.CancelPoint(index);
239 SendTouchEvent();
240 }
241
242 void PrependTouchScrollNotification() {
243 queue_->PrependTouchScrollNotification();
244 }
245
246 void AdvanceTouchTime(double seconds) {
247 touch_event_.setTimeStampSeconds(touch_event_.timeStampSeconds() + seconds);
248 }
249
250 void ResetTouchEvent() {
251 touch_event_ = SyntheticWebTouchEvent();
252 }
253
254 size_t GetAndResetAckedEventCount() {
255 size_t count = acked_event_count_;
256 acked_event_count_ = 0;
257 return count;
258 }
259
260 size_t GetAndResetSentEventCount() {
261 size_t count = sent_events_.size();
262 sent_events_.clear();
263 return count;
264 }
265
266 bool IsPendingAckTouchStart() const {
267 return queue_->IsPendingAckTouchStart();
268 }
269
270 void OnHasTouchEventHandlers(bool has_handlers) {
271 queue_->OnHasTouchEventHandlers(has_handlers);
272 }
273
274 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); }
275
276 void SetIsMobileOptimizedSite(bool is_mobile_optimized) {
277 queue_->SetIsMobileOptimizedSite(is_mobile_optimized);
278 }
279
280 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); }
281
282 bool HasPendingAsyncTouchMove() const {
283 return queue_->HasPendingAsyncTouchMoveForTesting();
284 }
285
286 size_t queued_event_count() const {
287 return queue_->size();
288 }
289
290 const WebTouchEvent& latest_event() const {
291 return queue_->GetLatestEventForTesting().event;
292 }
293
294 const WebTouchEvent& acked_event() const {
295 return last_acked_event_;
296 }
297
298 const WebTouchEvent& sent_event() const {
299 DCHECK(!sent_events_.empty());
300 return sent_events_.back();
301 }
302
303 const std::vector<WebTouchEvent>& all_sent_events() const {
304 return sent_events_;
305 }
306
307 InputEventAckState acked_event_state() const {
308 return last_acked_event_state_;
309 }
310
311 static void RunTasksAndWait(base::TimeDelta delay) {
312 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
313 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay);
314 base::RunLoop().Run();
315 }
316
317 size_t uncancelable_touch_moves_pending_ack_count() const {
318 return queue_->uncancelable_touch_moves_pending_ack_count();
319 }
320
321 int GetUniqueTouchEventID() { return sent_events_ids_.back(); }
322
323 private:
324 void SendTouchEvent() {
325 SendTouchEvent(touch_event_);
326 touch_event_.ResetPoints();
327 }
328
329 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
330 queue_.reset(new LegacyTouchEventQueue(this, config));
331 queue_->OnHasTouchEventHandlers(true);
332 }
333
334 std::unique_ptr<LegacyTouchEventQueue> queue_;
335 size_t acked_event_count_;
336 WebTouchEvent last_acked_event_;
337 std::vector<WebTouchEvent> sent_events_;
338 InputEventAckState last_acked_event_state_;
339 SyntheticWebTouchEvent touch_event_;
340 std::unique_ptr<WebTouchEvent> followup_touch_event_;
341 std::unique_ptr<WebGestureEvent> followup_gesture_event_;
342 std::unique_ptr<InputEventAckState> sync_ack_result_;
343 double slop_length_dips_;
344 gfx::PointF anchor_;
345 base::MessageLoopForUI message_loop_;
346 std::deque<int> sent_events_ids_;
347 };
348
349
350 // Tests that touch-events are queued properly.
351 TEST_F(TouchEventQueueTest, Basic) {
352 PressTouchPoint(1, 1);
353 EXPECT_EQ(1U, queued_event_count());
354 EXPECT_EQ(1U, GetAndResetSentEventCount());
355
356 // The second touch should not be sent since one is already in queue.
357 MoveTouchPoint(0, 5, 5);
358 EXPECT_EQ(2U, queued_event_count());
359 EXPECT_EQ(0U, GetAndResetSentEventCount());
360
361 // Receive an ACK for the first touch-event.
362 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
363 EXPECT_EQ(1U, queued_event_count());
364 EXPECT_EQ(1U, GetAndResetSentEventCount());
365 EXPECT_EQ(1U, GetAndResetAckedEventCount());
366 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
367 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType);
368
369 // Receive an ACK for the second touch-event.
370 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
371 EXPECT_EQ(0U, queued_event_count());
372 EXPECT_EQ(0U, GetAndResetSentEventCount());
373 EXPECT_EQ(1U, GetAndResetAckedEventCount());
374 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
375 EXPECT_EQ(WebInputEvent::Blocking, acked_event().dispatchType);
376 }
377
378 // Tests that touch-events with multiple points are queued properly.
379 TEST_F(TouchEventQueueTest, BasicMultiTouch) {
380 const size_t kPointerCount = 10;
381 for (float i = 0; i < kPointerCount; ++i)
382 PressTouchPoint(i, i);
383
384 EXPECT_EQ(1U, GetAndResetSentEventCount());
385 EXPECT_EQ(0U, GetAndResetAckedEventCount());
386 EXPECT_EQ(kPointerCount, queued_event_count());
387
388 for (int i = 0; i < static_cast<int>(kPointerCount); ++i)
389 MoveTouchPoint(i, 1.f + i, 2.f + i);
390
391 EXPECT_EQ(0U, GetAndResetSentEventCount());
392 EXPECT_EQ(0U, GetAndResetAckedEventCount());
393 // All moves should coalesce.
394 EXPECT_EQ(kPointerCount + 1, queued_event_count());
395
396 for (int i = 0; i < static_cast<int>(kPointerCount); ++i)
397 ReleaseTouchPoint(kPointerCount - 1 - i);
398
399 EXPECT_EQ(0U, GetAndResetSentEventCount());
400 EXPECT_EQ(0U, GetAndResetAckedEventCount());
401 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count());
402
403 // Ack all presses.
404 for (size_t i = 0; i < kPointerCount; ++i)
405 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
406
407 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
408 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount());
409
410 // Ack the coalesced move.
411 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
412 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
413 EXPECT_EQ(1U, GetAndResetSentEventCount());
414
415 // Ack all releases.
416 for (size_t i = 0; i < kPointerCount; ++i)
417 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
418
419 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount());
420 EXPECT_EQ(kPointerCount - 1, GetAndResetSentEventCount());
421 }
422
423 // Tests that the touch-queue continues delivering events for an active touch
424 // sequence after all handlers are removed.
425 TEST_F(TouchEventQueueTest, TouchesForwardedIfHandlerRemovedDuringSequence) {
426 OnHasTouchEventHandlers(true);
427 EXPECT_EQ(0U, queued_event_count());
428 EXPECT_EQ(0U, GetAndResetSentEventCount());
429
430 // Send a touch-press event.
431 PressTouchPoint(1, 1);
432 EXPECT_EQ(1U, GetAndResetSentEventCount());
433 EXPECT_EQ(1U, queued_event_count());
434
435 // Signal that all touch handlers have been removed.
436 OnHasTouchEventHandlers(false);
437 EXPECT_EQ(0U, GetAndResetAckedEventCount());
438 EXPECT_EQ(1U, queued_event_count());
439
440 // Process the ack for the sent touch, ensuring that it is honored (despite
441 // the touch handler having been removed).
442 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
443 EXPECT_EQ(1U, GetAndResetAckedEventCount());
444 EXPECT_EQ(0U, queued_event_count());
445 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
446
447 // Try forwarding a new pointer. It should be forwarded as usual.
448 PressTouchPoint(2, 2);
449 EXPECT_EQ(1U, GetAndResetSentEventCount());
450 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
451 EXPECT_EQ(1U, GetAndResetAckedEventCount());
452 EXPECT_EQ(0U, queued_event_count());
453
454 // Further events for any pointer should be forwarded, even for pointers that
455 // reported no consumer.
456 MoveTouchPoint(1, 3, 3);
457 ReleaseTouchPoint(1);
458 EXPECT_EQ(1U, GetAndResetSentEventCount());
459 EXPECT_EQ(0U, GetAndResetAckedEventCount());
460 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
461 EXPECT_EQ(1U, GetAndResetSentEventCount());
462 EXPECT_EQ(1U, GetAndResetAckedEventCount());
463 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
464 EXPECT_EQ(0U, GetAndResetSentEventCount());
465 EXPECT_EQ(1U, GetAndResetAckedEventCount());
466
467 // Events for the first pointer, that had a handler, should be forwarded.
468 MoveTouchPoint(0, 4, 4);
469 ReleaseTouchPoint(0);
470 EXPECT_EQ(1U, GetAndResetSentEventCount());
471 EXPECT_EQ(2U, queued_event_count());
472
473 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
474 EXPECT_EQ(1U, GetAndResetAckedEventCount());
475 EXPECT_EQ(1U, GetAndResetSentEventCount());
476 EXPECT_EQ(1U, queued_event_count());
477 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
478
479 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
480 EXPECT_EQ(1U, GetAndResetAckedEventCount());
481 EXPECT_EQ(0U, GetAndResetSentEventCount());
482 EXPECT_EQ(0U, queued_event_count());
483 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
484 }
485
486 // Tests that addition of a touch handler during a touch sequence will not cause
487 // the remaining sequence to be forwarded.
488 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) {
489 OnHasTouchEventHandlers(false);
490
491 // Send a touch-press event while there is no handler.
492 PressTouchPoint(1, 1);
493 EXPECT_EQ(1U, GetAndResetAckedEventCount());
494 EXPECT_EQ(0U, GetAndResetSentEventCount());
495 EXPECT_EQ(0U, queued_event_count());
496
497 OnHasTouchEventHandlers(true);
498
499 // The remaining touch sequence should not be forwarded.
500 MoveTouchPoint(0, 5, 5);
501 ReleaseTouchPoint(0);
502 EXPECT_EQ(2U, GetAndResetAckedEventCount());
503 EXPECT_EQ(0U, GetAndResetSentEventCount());
504 EXPECT_EQ(0U, queued_event_count());
505
506 // A new touch sequence should resume forwarding.
507 PressTouchPoint(1, 1);
508 EXPECT_EQ(1U, queued_event_count());
509 EXPECT_EQ(1U, GetAndResetSentEventCount());
510 }
511
512 // Tests that removal of a touch handler during a touch sequence will prevent
513 // the remaining sequence from being forwarded, even if another touch handler is
514 // registered during the same touch sequence.
515 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
516 // Send a touch-press event.
517 PressTouchPoint(1, 1);
518 EXPECT_EQ(1U, GetAndResetSentEventCount());
519 EXPECT_EQ(1U, queued_event_count());
520
521 // Queue a touch-move event.
522 MoveTouchPoint(0, 5, 5);
523 EXPECT_EQ(2U, queued_event_count());
524 EXPECT_EQ(0U, GetAndResetAckedEventCount());
525 EXPECT_EQ(0U, GetAndResetSentEventCount());
526
527 // Unregister all touch handlers.
528 OnHasTouchEventHandlers(false);
529 EXPECT_EQ(0U, GetAndResetAckedEventCount());
530 EXPECT_EQ(2U, queued_event_count());
531
532 // Repeated registration/unregstration of handlers should have no effect as
533 // we're still awaiting the ack arrival.
534 OnHasTouchEventHandlers(true);
535 EXPECT_EQ(0U, GetAndResetAckedEventCount());
536 EXPECT_EQ(2U, queued_event_count());
537 OnHasTouchEventHandlers(false);
538 EXPECT_EQ(0U, GetAndResetAckedEventCount());
539 EXPECT_EQ(2U, queued_event_count());
540
541 // The ack should be flush the queue.
542 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
543 EXPECT_EQ(2U, GetAndResetAckedEventCount());
544 EXPECT_EQ(0U, queued_event_count());
545
546 // Events should be dropped while there is no touch handler.
547 MoveTouchPoint(0, 10, 10);
548 EXPECT_EQ(0U, queued_event_count());
549 EXPECT_EQ(1U, GetAndResetAckedEventCount());
550 EXPECT_EQ(0U, GetAndResetSentEventCount());
551
552 // Simulate touch handler registration in the middle of a touch sequence.
553 OnHasTouchEventHandlers(true);
554
555 // The touch end for the interrupted sequence should be dropped.
556 ReleaseTouchPoint(0);
557 EXPECT_EQ(0U, queued_event_count());
558 EXPECT_EQ(1U, GetAndResetAckedEventCount());
559 EXPECT_EQ(0U, GetAndResetSentEventCount());
560
561 // A new touch sequence should be forwarded properly.
562 PressTouchPoint(1, 1);
563 EXPECT_EQ(1U, queued_event_count());
564 EXPECT_EQ(1U, GetAndResetSentEventCount());
565 }
566
567 // Tests that removal/addition of a touch handler without any intervening
568 // touch activity has no affect on touch forwarding.
569 TEST_F(TouchEventQueueTest,
570 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition) {
571 // Send a touch-press event.
572 PressTouchPoint(1, 1);
573 EXPECT_EQ(1U, GetAndResetSentEventCount());
574 EXPECT_EQ(1U, queued_event_count());
575
576 // Simulate the case where the touchstart handler removes itself, and adds a
577 // touchmove handler.
578 OnHasTouchEventHandlers(false);
579 OnHasTouchEventHandlers(true);
580
581 // Queue a touch-move event.
582 MoveTouchPoint(0, 5, 5);
583 EXPECT_EQ(2U, queued_event_count());
584 EXPECT_EQ(0U, GetAndResetAckedEventCount());
585 EXPECT_EQ(0U, GetAndResetSentEventCount());
586
587 // The ack should trigger forwarding of the touchmove, as if no touch
588 // handler registration changes have occurred.
589 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
590 EXPECT_EQ(1U, GetAndResetAckedEventCount());
591 EXPECT_EQ(1U, GetAndResetSentEventCount());
592 EXPECT_EQ(1U, queued_event_count());
593 }
594
595 // Tests that touch-events are coalesced properly in the queue.
596 TEST_F(TouchEventQueueTest, Coalesce) {
597 // Send a touch-press event.
598 PressTouchPoint(1, 1);
599 EXPECT_EQ(1U, GetAndResetSentEventCount());
600
601 // Send a few touch-move events, followed by a touch-release event. All the
602 // touch-move events should be coalesced into a single event.
603 for (float i = 5; i < 15; ++i)
604 MoveTouchPoint(0, i, i);
605
606 EXPECT_EQ(0U, GetAndResetSentEventCount());
607 ReleaseTouchPoint(0);
608 EXPECT_EQ(0U, GetAndResetSentEventCount());
609 EXPECT_EQ(3U, queued_event_count());
610
611 // ACK the press. Coalesced touch-move events should be sent.
612 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
613 EXPECT_EQ(2U, queued_event_count());
614 EXPECT_EQ(1U, GetAndResetSentEventCount());
615 EXPECT_EQ(1U, GetAndResetAckedEventCount());
616 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
617 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
618
619 // ACK the moves.
620 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
621 EXPECT_EQ(1U, queued_event_count());
622 EXPECT_EQ(1U, GetAndResetSentEventCount());
623 EXPECT_EQ(10U, GetAndResetAckedEventCount());
624 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
625
626 // ACK the release.
627 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
628 EXPECT_EQ(0U, queued_event_count());
629 EXPECT_EQ(0U, GetAndResetSentEventCount());
630 EXPECT_EQ(1U, GetAndResetAckedEventCount());
631 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type());
632 }
633
634 // Tests that an event that has already been sent but hasn't been ack'ed yet
635 // doesn't get coalesced with newer events.
636 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
637 // Send a touch-press event.
638 PressTouchPoint(1, 1);
639 EXPECT_EQ(1U, GetAndResetSentEventCount());
640
641 // Send a few touch-move events, followed by a touch-release event. All the
642 // touch-move events should be coalesced into a single event.
643 for (float i = 5; i < 15; ++i)
644 MoveTouchPoint(0, i, i);
645
646 EXPECT_EQ(0U, GetAndResetSentEventCount());
647 EXPECT_EQ(2U, queued_event_count());
648
649 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
650 EXPECT_EQ(1U, GetAndResetSentEventCount());
651 EXPECT_EQ(1U, queued_event_count());
652
653 // The coalesced touch-move event has been sent to the renderer. Any new
654 // touch-move event should not be coalesced with the sent event.
655 MoveTouchPoint(0, 5, 5);
656 EXPECT_EQ(2U, queued_event_count());
657
658 MoveTouchPoint(0, 7, 7);
659 EXPECT_EQ(2U, queued_event_count());
660 }
661
662 // Tests that coalescing works correctly for multi-touch events.
663 TEST_F(TouchEventQueueTest, MultiTouch) {
664 // Press the first finger.
665 PressTouchPoint(1, 1);
666 EXPECT_EQ(1U, GetAndResetSentEventCount());
667
668 // Move the finger.
669 MoveTouchPoint(0, 5, 5);
670 EXPECT_EQ(2U, queued_event_count());
671
672 // Now press a second finger.
673 PressTouchPoint(2, 2);
674 EXPECT_EQ(3U, queued_event_count());
675
676 // Move both fingers.
677 MoveTouchPoints(0, 10, 10, 1, 20, 20);
678 MoveTouchPoint(1, 20, 20);
679 EXPECT_EQ(4U, queued_event_count());
680
681 // Move only one finger now.
682 MoveTouchPoint(0, 15, 15);
683 EXPECT_EQ(4U, queued_event_count());
684
685 // Move the other finger.
686 MoveTouchPoint(1, 25, 25);
687 EXPECT_EQ(4U, queued_event_count());
688
689 // Make sure both fingers are marked as having been moved in the coalesced
690 // event.
691 const WebTouchEvent& event = latest_event();
692 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
693 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
694 }
695
696 // Tests that the touch-event queue is robust to redundant acks.
697 TEST_F(TouchEventQueueTest, SpuriousAcksIgnored) {
698 // Trigger a spurious ack.
699 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 0);
700 EXPECT_EQ(0U, GetAndResetAckedEventCount());
701
702 // Send and ack a touch press.
703 PressTouchPoint(1, 1);
704 EXPECT_EQ(1U, GetAndResetSentEventCount());
705 EXPECT_EQ(1U, queued_event_count());
706 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
707 EXPECT_EQ(1U, GetAndResetAckedEventCount());
708 EXPECT_EQ(0U, queued_event_count());
709
710 // Trigger a spurious ack.
711 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_CONSUMED, 3);
712 EXPECT_EQ(0U, GetAndResetAckedEventCount());
713 }
714
715 // Tests that touch-move events are not sent to the renderer if the preceding
716 // touch-press event did not have a consumer (and consequently, did not hit the
717 // main thread in the renderer). Also tests that all queued/coalesced touch
718 // events are flushed immediately when the ACK for the touch-press comes back
719 // with NO_CONSUMER status.
720 TEST_F(TouchEventQueueTest, NoConsumer) {
721 // The first touch-press should reach the renderer.
722 PressTouchPoint(1, 1);
723 EXPECT_EQ(1U, GetAndResetSentEventCount());
724
725 // The second touch should not be sent since one is already in queue.
726 MoveTouchPoint(0, 5, 5);
727 EXPECT_EQ(0U, GetAndResetSentEventCount());
728 EXPECT_EQ(2U, queued_event_count());
729
730 // Receive an ACK for the first touch-event. This should release the queued
731 // touch-event, but it should not be sent to the renderer.
732 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
733 EXPECT_EQ(0U, queued_event_count());
734 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
735 EXPECT_EQ(2U, GetAndResetAckedEventCount());
736 EXPECT_EQ(0U, GetAndResetSentEventCount());
737
738 // Send a release event. This should not reach the renderer.
739 ReleaseTouchPoint(0);
740 EXPECT_EQ(0U, GetAndResetSentEventCount());
741 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type());
742 EXPECT_EQ(1U, GetAndResetAckedEventCount());
743
744 // Send a press-event, followed by move and release events, and another press
745 // event, before the ACK for the first press event comes back. All of the
746 // events should be queued first. After the NO_CONSUMER ack for the first
747 // touch-press, all events upto the second touch-press should be flushed.
748 PressTouchPoint(10, 10);
749 EXPECT_EQ(1U, GetAndResetSentEventCount());
750
751 MoveTouchPoint(0, 5, 5);
752 MoveTouchPoint(0, 6, 5);
753 ReleaseTouchPoint(0);
754
755 PressTouchPoint(6, 5);
756 EXPECT_EQ(0U, GetAndResetSentEventCount());
757 // The queue should hold the first sent touch-press event, the coalesced
758 // touch-move event, the touch-end event and the second touch-press event.
759 EXPECT_EQ(4U, queued_event_count());
760
761 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
762 EXPECT_EQ(1U, GetAndResetSentEventCount());
763 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type());
764 EXPECT_EQ(4U, GetAndResetAckedEventCount());
765 EXPECT_EQ(1U, queued_event_count());
766
767 // ACK the second press event as NO_CONSUMER too.
768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
769 EXPECT_EQ(0U, GetAndResetSentEventCount());
770 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
771 EXPECT_EQ(1U, GetAndResetAckedEventCount());
772 EXPECT_EQ(0U, queued_event_count());
773
774 // Send a second press event. Even though the first touch press had
775 // NO_CONSUMER, this press event should reach the renderer.
776 PressTouchPoint(1, 1);
777 EXPECT_EQ(1U, GetAndResetSentEventCount());
778 EXPECT_EQ(1U, queued_event_count());
779 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
780 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
781 EXPECT_EQ(1U, GetAndResetAckedEventCount());
782 }
783
784 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
785 // Interleave three pointer press, move and release events.
786 PressTouchPoint(1, 1);
787 MoveTouchPoint(0, 5, 5);
788 PressTouchPoint(10, 10);
789 MoveTouchPoint(1, 15, 15);
790 PressTouchPoint(20, 20);
791 MoveTouchPoint(2, 25, 25);
792 ReleaseTouchPoint(2);
793 MoveTouchPoint(1, 20, 20);
794 ReleaseTouchPoint(1);
795 MoveTouchPoint(0, 10, 10);
796 ReleaseTouchPoint(0);
797
798 // Since the first touch-press is still pending ACK, no other event should
799 // have been sent to the renderer.
800 EXPECT_EQ(1U, GetAndResetSentEventCount());
801 EXPECT_EQ(0U, GetAndResetSentEventCount());
802 EXPECT_EQ(11U, queued_event_count());
803
804 // ACK the first press as CONSUMED. This should cause the first touch-move of
805 // the first touch-point to be dispatched.
806 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
807 EXPECT_EQ(1U, GetAndResetSentEventCount());
808 EXPECT_EQ(10U, queued_event_count());
809
810 // ACK the first move as CONSUMED.
811 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
812 EXPECT_EQ(1U, GetAndResetSentEventCount());
813 EXPECT_EQ(9U, queued_event_count());
814
815 // ACK the second press as NO_CONSUMER_EXISTS. The second pointer's touchmove
816 // should still be forwarded, despite lacking a direct consumer.
817 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
818 EXPECT_EQ(1U, GetAndResetSentEventCount());
819 EXPECT_EQ(8U, queued_event_count());
820
821 // ACK the coalesced move as NOT_CONSUMED.
822 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
823 EXPECT_EQ(1U, GetAndResetSentEventCount());
824 EXPECT_EQ(7U, queued_event_count());
825
826 // All remaining touch events should be forwarded, even if the third pointer
827 // press also reports no consumer.
828 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
829 EXPECT_EQ(6U, queued_event_count());
830
831 while (queued_event_count())
832 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
833
834 EXPECT_EQ(6U, GetAndResetSentEventCount());
835 }
836
837 // Tests that touch-event's enqueued via a touch ack are properly handled.
838 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
839 // Queue a touch down.
840 PressTouchPoint(1, 1);
841 EXPECT_EQ(1U, queued_event_count());
842 EXPECT_EQ(1U, GetAndResetSentEventCount());
843 EXPECT_EQ(0U, GetAndResetAckedEventCount());
844
845 // Create a touch event that will be queued synchronously by a touch ack.
846 // Note, this will be triggered by all subsequent touch acks.
847 WebTouchEvent followup_event(
848 WebInputEvent::TouchMove, WebInputEvent::NoModifiers,
849 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
850 followup_event.touchesLength = 1;
851 followup_event.touches[0].id = 0;
852 followup_event.touches[0].state = WebTouchPoint::StateMoved;
853 SetFollowupEvent(followup_event);
854
855 // Receive an ACK for the press. This should cause the followup touch-move to
856 // be sent to the renderer.
857 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
858 EXPECT_EQ(1U, queued_event_count());
859 EXPECT_EQ(1U, GetAndResetSentEventCount());
860 EXPECT_EQ(1U, GetAndResetAckedEventCount());
861 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
862 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
863
864 // Queue another event.
865 MoveTouchPoint(0, 2, 2);
866 EXPECT_EQ(2U, queued_event_count());
867
868 // Receive an ACK for the touch-move followup event. This should cause the
869 // subsequent touch move event be sent to the renderer.
870 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
871 EXPECT_EQ(1U, queued_event_count());
872 EXPECT_EQ(1U, GetAndResetSentEventCount());
873 EXPECT_EQ(1U, GetAndResetAckedEventCount());
874 }
875
876 // Tests that touch-events can be synchronously ack'ed.
877 TEST_F(TouchEventQueueTest, SynchronousAcks) {
878 // TouchStart
879 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
880 PressTouchPoint(1, 1);
881 EXPECT_EQ(0U, queued_event_count());
882 EXPECT_EQ(1U, GetAndResetSentEventCount());
883 EXPECT_EQ(1U, GetAndResetAckedEventCount());
884
885 // TouchMove
886 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
887 MoveTouchPoint(0, 2, 2);
888 EXPECT_EQ(0U, queued_event_count());
889 EXPECT_EQ(1U, GetAndResetSentEventCount());
890 EXPECT_EQ(1U, GetAndResetAckedEventCount());
891
892 // TouchEnd
893 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
894 ReleaseTouchPoint(0);
895 EXPECT_EQ(0U, queued_event_count());
896 EXPECT_EQ(1U, GetAndResetSentEventCount());
897 EXPECT_EQ(1U, GetAndResetAckedEventCount());
898
899 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
900 PressTouchPoint(1, 1);
901 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
902 EXPECT_EQ(0U, queued_event_count());
903 EXPECT_EQ(1U, GetAndResetSentEventCount());
904 EXPECT_EQ(1U, GetAndResetAckedEventCount());
905
906 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
907 CancelTouchPoint(0);
908 EXPECT_EQ(0U, queued_event_count());
909 EXPECT_EQ(1U, GetAndResetSentEventCount());
910 EXPECT_EQ(1U, GetAndResetAckedEventCount());
911 }
912
913 // Tests that followup events triggered by an immediate ack from
914 // TouchEventQueue::QueueEvent() are properly handled.
915 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
916 // Create a touch event that will be queued synchronously by a touch ack.
917 WebTouchEvent followup_event(
918 WebInputEvent::TouchStart, WebInputEvent::NoModifiers,
919 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
920 followup_event.touchesLength = 1;
921 followup_event.touches[0].id = 1;
922 followup_event.touches[0].state = WebTouchPoint::StatePressed;
923 SetFollowupEvent(followup_event);
924
925 // Now, enqueue a stationary touch that will not be forwarded. This should be
926 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
927 // then be enqueued and immediately sent to the renderer.
928 WebTouchEvent stationary_event(
929 WebInputEvent::TouchMove, WebInputEvent::NoModifiers,
930 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
931 ;
932 stationary_event.touchesLength = 1;
933 stationary_event.touches[0].id = 1;
934 stationary_event.touches[0].state = WebTouchPoint::StateStationary;
935 SendTouchEvent(stationary_event);
936
937 EXPECT_EQ(1U, queued_event_count());
938 EXPECT_EQ(1U, GetAndResetSentEventCount());
939 EXPECT_EQ(1U, GetAndResetAckedEventCount());
940 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
941 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
942 }
943
944 // Tests basic TouchEvent forwarding suppression.
945 TEST_F(TouchEventQueueTest, NoTouchBasic) {
946 // Disable TouchEvent forwarding.
947 OnHasTouchEventHandlers(false);
948 PressTouchPoint(30, 5);
949 EXPECT_EQ(0U, GetAndResetSentEventCount());
950 EXPECT_EQ(1U, GetAndResetAckedEventCount());
951
952 // TouchMove should not be sent to renderer.
953 MoveTouchPoint(0, 65, 10);
954 EXPECT_EQ(0U, GetAndResetSentEventCount());
955 EXPECT_EQ(1U, GetAndResetAckedEventCount());
956
957 // TouchEnd should not be sent to renderer.
958 ReleaseTouchPoint(0);
959 EXPECT_EQ(0U, GetAndResetSentEventCount());
960 EXPECT_EQ(1U, GetAndResetAckedEventCount());
961
962 // Enable TouchEvent forwarding.
963 OnHasTouchEventHandlers(true);
964
965 PressTouchPoint(80, 10);
966 EXPECT_EQ(1U, GetAndResetSentEventCount());
967 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
968 EXPECT_EQ(1U, GetAndResetAckedEventCount());
969
970 MoveTouchPoint(0, 80, 20);
971 EXPECT_EQ(1U, GetAndResetSentEventCount());
972 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
973 EXPECT_EQ(1U, GetAndResetAckedEventCount());
974
975 ReleaseTouchPoint(0);
976 EXPECT_EQ(1U, GetAndResetSentEventCount());
977 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
978 EXPECT_EQ(1U, GetAndResetAckedEventCount());
979 }
980
981 // Tests that IsTouchStartPendingAck works correctly.
982 TEST_F(TouchEventQueueTest, PendingStart) {
983
984 EXPECT_FALSE(IsPendingAckTouchStart());
985
986 // Send the touchstart for one point (#1).
987 PressTouchPoint(1, 1);
988 EXPECT_EQ(1U, queued_event_count());
989 EXPECT_TRUE(IsPendingAckTouchStart());
990
991 // Send a touchmove for that point (#2).
992 MoveTouchPoint(0, 5, 5);
993 EXPECT_EQ(2U, queued_event_count());
994 EXPECT_TRUE(IsPendingAckTouchStart());
995
996 // Ack the touchstart (#1).
997 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
998 EXPECT_EQ(1U, queued_event_count());
999 EXPECT_FALSE(IsPendingAckTouchStart());
1000
1001 // Send a touchstart for another point (#3).
1002 PressTouchPoint(10, 10);
1003 EXPECT_EQ(2U, queued_event_count());
1004 EXPECT_FALSE(IsPendingAckTouchStart());
1005
1006 // Ack the touchmove (#2).
1007 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1008 EXPECT_EQ(1U, queued_event_count());
1009 EXPECT_TRUE(IsPendingAckTouchStart());
1010
1011 // Send a touchstart for a third point (#4).
1012 PressTouchPoint(15, 15);
1013 EXPECT_EQ(2U, queued_event_count());
1014 EXPECT_TRUE(IsPendingAckTouchStart());
1015
1016 // Ack the touchstart for the second point (#3).
1017 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1018 EXPECT_EQ(1U, queued_event_count());
1019 EXPECT_TRUE(IsPendingAckTouchStart());
1020
1021 // Ack the touchstart for the third point (#4).
1022 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1023 EXPECT_EQ(0U, queued_event_count());
1024 EXPECT_FALSE(IsPendingAckTouchStart());
1025 }
1026
1027 // Tests that the touch timeout is started when sending certain touch types.
1028 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
1029 SetUpForTimeoutTesting();
1030
1031 // Sending a TouchStart will start the timeout.
1032 PressTouchPoint(0, 1);
1033 EXPECT_TRUE(IsTimeoutRunning());
1034 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1035 EXPECT_FALSE(IsTimeoutRunning());
1036
1037 // A TouchMove should start the timeout.
1038 MoveTouchPoint(0, 5, 5);
1039 EXPECT_TRUE(IsTimeoutRunning());
1040 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1041 EXPECT_FALSE(IsTimeoutRunning());
1042
1043 // A TouchEnd should not start the timeout.
1044 ReleaseTouchPoint(0);
1045 EXPECT_FALSE(IsTimeoutRunning());
1046 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1047 EXPECT_FALSE(IsTimeoutRunning());
1048
1049 // A TouchCancel should not start the timeout.
1050 PressTouchPoint(0, 1);
1051 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1052 ASSERT_FALSE(IsTimeoutRunning());
1053 CancelTouchPoint(0);
1054 EXPECT_FALSE(IsTimeoutRunning());
1055 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1056 EXPECT_FALSE(IsTimeoutRunning());
1057 }
1058
1059 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
1060 // disabling touch forwarding until the next TouchStart is received after
1061 // the timeout events are ack'ed.
1062 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
1063 SetUpForTimeoutTesting();
1064
1065 // Queue a TouchStart.
1066 GetAndResetSentEventCount();
1067 GetAndResetAckedEventCount();
1068 PressTouchPoint(0, 1);
1069 ASSERT_EQ(1U, GetAndResetSentEventCount());
1070 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1071 EXPECT_TRUE(IsTimeoutRunning());
1072
1073 // Delay the ack.
1074 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1075
1076 // The timeout should have fired, synthetically ack'ing the timed-out event.
1077 // TouchEvent forwarding is disabled until the ack is received for the
1078 // timed-out event and the future cancel event.
1079 EXPECT_FALSE(IsTimeoutRunning());
1080 EXPECT_EQ(0U, GetAndResetSentEventCount());
1081 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1082
1083 // Ack'ing the original event should trigger a cancel event.
1084 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1085 EXPECT_FALSE(IsTimeoutRunning());
1086 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type());
1087 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
1088 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1089 EXPECT_EQ(1U, GetAndResetSentEventCount());
1090
1091 // Touch events should not be forwarded until we receive the cancel acks.
1092 MoveTouchPoint(0, 1, 1);
1093 ASSERT_EQ(0U, GetAndResetSentEventCount());
1094 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1095
1096 ReleaseTouchPoint(0);
1097 ASSERT_EQ(0U, GetAndResetSentEventCount());
1098 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1099
1100 // The synthetic TouchCancel ack should not reach the client, but should
1101 // resume touch forwarding.
1102 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1103 EXPECT_EQ(0U, GetAndResetSentEventCount());
1104 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1105
1106 // Subsequent events should be handled normally.
1107 PressTouchPoint(0, 1);
1108 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type());
1109 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1110 EXPECT_EQ(1U, GetAndResetSentEventCount());
1111 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1112 }
1113
1114 // Tests that the timeout is never started if the renderer consumes
1115 // a TouchEvent from the current touch sequence.
1116 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
1117 SetUpForTimeoutTesting();
1118
1119 // Queue a TouchStart.
1120 PressTouchPoint(0, 1);
1121 ASSERT_TRUE(IsTimeoutRunning());
1122
1123 // Mark the event as consumed. This should prevent the timeout from
1124 // being activated on subsequent TouchEvents in this gesture.
1125 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1126 EXPECT_FALSE(IsTimeoutRunning());
1127
1128 // A TouchMove should not start the timeout.
1129 MoveTouchPoint(0, 5, 5);
1130 EXPECT_FALSE(IsTimeoutRunning());
1131 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1132
1133 // A secondary TouchStart should not start the timeout.
1134 PressTouchPoint(1, 0);
1135 EXPECT_FALSE(IsTimeoutRunning());
1136 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1137
1138 // A TouchEnd should not start the timeout.
1139 ReleaseTouchPoint(1);
1140 EXPECT_FALSE(IsTimeoutRunning());
1141 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1142
1143 // A TouchCancel should not start the timeout.
1144 CancelTouchPoint(0);
1145 EXPECT_FALSE(IsTimeoutRunning());
1146 }
1147
1148 // Tests that the timeout is never started if the renderer consumes
1149 // a TouchEvent from the current touch sequence.
1150 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) {
1151 SetUpForTimeoutTesting();
1152
1153 // Queue a TouchStart.
1154 PressTouchPoint(0, 1);
1155 ASSERT_TRUE(IsTimeoutRunning());
1156
1157 // Send the ack immediately. The timeout should not have fired.
1158 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1159 EXPECT_FALSE(IsTimeoutRunning());
1160 EXPECT_EQ(1U, GetAndResetSentEventCount());
1161 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1162
1163 // Now explicitly disable the timeout.
1164 SetAckTimeoutDisabled();
1165 EXPECT_FALSE(IsTimeoutRunning());
1166
1167 // A TouchMove should not start or trigger the timeout.
1168 MoveTouchPoint(0, 5, 5);
1169 EXPECT_FALSE(IsTimeoutRunning());
1170 EXPECT_EQ(1U, GetAndResetSentEventCount());
1171 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1172 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1173 }
1174
1175 // Tests that the timeout is never started if the ack is synchronous.
1176 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1177 SetUpForTimeoutTesting();
1178
1179 // Queue a TouchStart.
1180 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1181 ASSERT_FALSE(IsTimeoutRunning());
1182 PressTouchPoint(0, 1);
1183 EXPECT_FALSE(IsTimeoutRunning());
1184 }
1185
1186 // Tests that the timeout does not fire if explicitly disabled while an event
1187 // is in-flight.
1188 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
1189 SetUpForTimeoutTesting();
1190
1191 // Queue a TouchStart.
1192 PressTouchPoint(0, 1);
1193 ASSERT_TRUE(IsTimeoutRunning());
1194
1195 // Verify that disabling the timeout also turns off the timer.
1196 SetAckTimeoutDisabled();
1197 EXPECT_FALSE(IsTimeoutRunning());
1198 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1199 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1200 }
1201
1202 // Tests that the timeout does not fire if the delay is zero.
1203 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTimeoutDelayIsZero) {
1204 SetUpForTimeoutTesting(base::TimeDelta(), base::TimeDelta());
1205
1206 // As the delay is zero, timeout behavior should be disabled.
1207 PressTouchPoint(0, 1);
1208 EXPECT_FALSE(IsTimeoutRunning());
1209 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1210 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1211 }
1212
1213 // Tests that timeout delays for mobile sites take effect when appropriate.
1214 TEST_F(TouchEventQueueTest, TouchTimeoutConfiguredForMobile) {
1215 base::TimeDelta desktop_delay = DefaultTouchTimeoutDelay();
1216 base::TimeDelta mobile_delay = base::TimeDelta();
1217 SetUpForTimeoutTesting(desktop_delay, mobile_delay);
1218
1219 // The desktop delay is non-zero, allowing timeout behavior.
1220 SetIsMobileOptimizedSite(false);
1221
1222 PressTouchPoint(0, 1);
1223 ASSERT_TRUE(IsTimeoutRunning());
1224 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1225 ReleaseTouchPoint(0);
1226 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1227 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1228 ASSERT_FALSE(IsTimeoutRunning());
1229
1230 // The mobile delay is zero, preventing timeout behavior.
1231 SetIsMobileOptimizedSite(true);
1232
1233 PressTouchPoint(0, 1);
1234 EXPECT_FALSE(IsTimeoutRunning());
1235 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1236 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1237 }
1238
1239 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1240 // turns into a scroll gesture sequence.
1241 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1242 SetUpForTimeoutTesting();
1243
1244 // Queue a TouchStart.
1245 PressTouchPoint(0, 1);
1246 EXPECT_TRUE(IsTimeoutRunning());
1247 EXPECT_EQ(1U, GetAndResetSentEventCount());
1248
1249 // The cancelled sequence may turn into a scroll gesture.
1250 WebGestureEvent followup_scroll(
1251 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers,
1252 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
1253 SetFollowupEvent(followup_scroll);
1254
1255 // Delay the ack.
1256 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1257
1258 // The timeout should have fired, disabling touch forwarding until both acks
1259 // are received, acking the timed out event.
1260 EXPECT_FALSE(IsTimeoutRunning());
1261 EXPECT_EQ(0U, GetAndResetSentEventCount());
1262 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1263
1264 // Ack the original event, triggering a TouchCancel.
1265 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1266 EXPECT_FALSE(IsTimeoutRunning());
1267 EXPECT_EQ(1U, GetAndResetSentEventCount());
1268 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1269
1270 // Ack the cancel event. Normally, this would resume touch forwarding,
1271 // but we're still within a scroll gesture so it remains disabled.
1272 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1273 EXPECT_FALSE(IsTimeoutRunning());
1274 EXPECT_EQ(0U, GetAndResetSentEventCount());
1275 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1276
1277 // Try to forward touch events for the current sequence.
1278 GetAndResetSentEventCount();
1279 GetAndResetAckedEventCount();
1280 MoveTouchPoint(0, 1, 1);
1281 ReleaseTouchPoint(0);
1282 EXPECT_FALSE(IsTimeoutRunning());
1283 EXPECT_EQ(0U, GetAndResetSentEventCount());
1284 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1285
1286 // Now end the scroll sequence, resuming touch handling.
1287 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1288 PressTouchPoint(0, 1);
1289 EXPECT_TRUE(IsTimeoutRunning());
1290 EXPECT_EQ(1U, GetAndResetSentEventCount());
1291 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1292 }
1293
1294 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1295 // turns into a scroll gesture sequence, but the original event acks are
1296 // significantly delayed.
1297 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1298 SetUpForTimeoutTesting();
1299
1300 // Queue a TouchStart.
1301 PressTouchPoint(0, 1);
1302 EXPECT_TRUE(IsTimeoutRunning());
1303 EXPECT_EQ(1U, GetAndResetSentEventCount());
1304
1305 // The cancelled sequence may turn into a scroll gesture.
1306 WebGestureEvent followup_scroll(
1307 WebInputEvent::GestureScrollBegin, WebInputEvent::NoModifiers,
1308 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
1309 SetFollowupEvent(followup_scroll);
1310
1311 // Delay the ack.
1312 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1313
1314 // The timeout should have fired, disabling touch forwarding until both acks
1315 // are received and acking the timed out event.
1316 EXPECT_FALSE(IsTimeoutRunning());
1317 EXPECT_EQ(0U, GetAndResetSentEventCount());
1318 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1319
1320 // Try to forward a touch event.
1321 GetAndResetSentEventCount();
1322 GetAndResetAckedEventCount();
1323 MoveTouchPoint(0, 1, 1);
1324 EXPECT_FALSE(IsTimeoutRunning());
1325 EXPECT_EQ(0U, GetAndResetSentEventCount());
1326 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1327
1328 // Now end the scroll sequence. Events will not be forwarded until the two
1329 // outstanding touch acks are received.
1330 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1331 MoveTouchPoint(0, 2, 2);
1332 ReleaseTouchPoint(0);
1333 EXPECT_FALSE(IsTimeoutRunning());
1334 EXPECT_EQ(0U, GetAndResetSentEventCount());
1335 EXPECT_EQ(2U, GetAndResetAckedEventCount());
1336
1337 // Ack the original event, triggering a cancel.
1338 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1339 EXPECT_EQ(1U, GetAndResetSentEventCount());
1340 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1341
1342 // Ack the cancel event, resuming touch forwarding.
1343 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1344 EXPECT_EQ(0U, GetAndResetSentEventCount());
1345 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1346
1347 PressTouchPoint(0, 1);
1348 EXPECT_TRUE(IsTimeoutRunning());
1349 EXPECT_EQ(1U, GetAndResetSentEventCount());
1350 }
1351
1352 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1353 // the timed-out event had no consumer.
1354 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1355 SetUpForTimeoutTesting();
1356
1357 // Queue a TouchStart.
1358 PressTouchPoint(0, 1);
1359 ASSERT_EQ(1U, GetAndResetSentEventCount());
1360 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1361 EXPECT_TRUE(IsTimeoutRunning());
1362
1363 // Delay the ack.
1364 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1365
1366 // The timeout should have fired, synthetically ack'ing the timed out event.
1367 // TouchEvent forwarding is disabled until the original ack is received.
1368 EXPECT_FALSE(IsTimeoutRunning());
1369 EXPECT_EQ(0U, GetAndResetSentEventCount());
1370 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1371
1372 // Touch events should not be forwarded until we receive the original ack.
1373 MoveTouchPoint(0, 1, 1);
1374 ReleaseTouchPoint(0);
1375 ASSERT_EQ(0U, GetAndResetSentEventCount());
1376 ASSERT_EQ(2U, GetAndResetAckedEventCount());
1377
1378 // Ack'ing the original event should not trigger a cancel event, as the
1379 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1380 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1381 EXPECT_FALSE(IsTimeoutRunning());
1382 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1383 EXPECT_EQ(0U, GetAndResetSentEventCount());
1384
1385 // Subsequent events should be handled normally.
1386 PressTouchPoint(0, 1);
1387 EXPECT_EQ(1U, GetAndResetSentEventCount());
1388 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1389 }
1390
1391 // Tests that TouchMove's movedBeyondSlopRegion is set to false if within the
1392 // boundary-inclusive slop region for an unconsumed TouchStart.
1393 TEST_F(TouchEventQueueTest, TouchMovedBeyondSlopRegionCheck) {
1394 SetUpForTouchMoveSlopTesting(kSlopLengthDips);
1395
1396 // Queue a TouchStart.
1397 PressTouchPoint(0, 0);
1398 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1399 ASSERT_EQ(1U, GetAndResetSentEventCount());
1400 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1401
1402 // TouchMove's movedBeyondSlopRegion within the slop region is set to false.
1403 MoveTouchPoint(0, 0, kHalfSlopLengthDips);
1404 EXPECT_EQ(1U, queued_event_count());
1405 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1406 EXPECT_EQ(1U, GetAndResetSentEventCount());
1407 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1408 EXPECT_FALSE(acked_event().movedBeyondSlopRegion);
1409
1410 MoveTouchPoint(0, kHalfSlopLengthDips, 0);
1411 EXPECT_EQ(1U, queued_event_count());
1412 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1413 EXPECT_EQ(1U, GetAndResetSentEventCount());
1414 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1415 EXPECT_FALSE(acked_event().movedBeyondSlopRegion);
1416
1417 MoveTouchPoint(0, -kHalfSlopLengthDips, 0);
1418 EXPECT_EQ(1U, queued_event_count());
1419 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1420 EXPECT_EQ(1U, GetAndResetSentEventCount());
1421 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1422 EXPECT_FALSE(acked_event().movedBeyondSlopRegion);
1423
1424 MoveTouchPoint(0, -kSlopLengthDips, 0);
1425 EXPECT_EQ(1U, queued_event_count());
1426 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1427 EXPECT_EQ(1U, GetAndResetSentEventCount());
1428 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1429 EXPECT_FALSE(acked_event().movedBeyondSlopRegion);
1430
1431 MoveTouchPoint(0, 0, kSlopLengthDips);
1432 EXPECT_EQ(1U, queued_event_count());
1433 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1434 EXPECT_EQ(1U, GetAndResetSentEventCount());
1435 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1436 EXPECT_FALSE(acked_event().movedBeyondSlopRegion);
1437
1438 // When a TouchMove exceeds the (Euclidean) distance, the TouchMove's
1439 // movedBeyondSlopRegion is set to true.
1440 const float kFortyFiveDegreeSlopLengthXY =
1441 kSlopLengthDips * std::sqrt(2.f) / 2;
1442 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2f,
1443 kFortyFiveDegreeSlopLengthXY + .2f);
1444 EXPECT_EQ(1U, queued_event_count());
1445 EXPECT_EQ(1U, GetAndResetSentEventCount());
1446 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1447 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1448 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1449 EXPECT_TRUE(acked_event().movedBeyondSlopRegion);
1450 }
1451
1452 // Tests that even very small TouchMove's movedBeyondSlopRegion is set to true
1453 // when the slop region's dimension is 0.
1454 TEST_F(TouchEventQueueTest, MovedBeyondSlopRegionAlwaysTrueIfDimensionZero) {
1455 // Queue a TouchStart.
1456 PressTouchPoint(0, 0);
1457 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1458 ASSERT_EQ(1U, GetAndResetSentEventCount());
1459 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1460
1461 // Small TouchMove's movedBeyondSlopRegion is set to true.
1462 MoveTouchPoint(0, 0.001f, 0.001f);
1463 EXPECT_EQ(1U, queued_event_count());
1464 EXPECT_EQ(1U, GetAndResetSentEventCount());
1465 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1466 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1467 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1468 EXPECT_TRUE(acked_event().movedBeyondSlopRegion);
1469 }
1470
1471 // Tests that secondary touch points can be forwarded even if the primary touch
1472 // point had no consumer.
1473 TEST_F(TouchEventQueueTest, SecondaryTouchForwardedAfterPrimaryHadNoConsumer) {
1474 // Queue a TouchStart.
1475 PressTouchPoint(0, 0);
1476 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1477 ASSERT_EQ(1U, GetAndResetSentEventCount());
1478 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1479
1480 // Events should not be forwarded, as the point had no consumer.
1481 MoveTouchPoint(0, 0, 15);
1482 EXPECT_EQ(0U, queued_event_count());
1483 EXPECT_EQ(0U, GetAndResetSentEventCount());
1484 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1485
1486 // Simulate a secondary pointer press.
1487 PressTouchPoint(20, 0);
1488 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1489 EXPECT_EQ(1U, GetAndResetSentEventCount());
1490 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1491
1492 // TouchMove with a secondary pointer should not be suppressed.
1493 MoveTouchPoint(1, 25, 0);
1494 EXPECT_EQ(1U, queued_event_count());
1495 EXPECT_EQ(1U, GetAndResetSentEventCount());
1496 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1497 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1498 }
1499
1500 // Tests that secondary touch points can be forwarded after scrolling begins
1501 // while first touch point has no consumer.
1502 TEST_F(TouchEventQueueTest, NoForwardingAfterScrollWithNoTouchConsumers) {
1503 // Queue a TouchStart.
1504 PressTouchPoint(0, 0);
1505 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1506 ASSERT_EQ(1U, GetAndResetSentEventCount());
1507 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1508
1509 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1510 WebInputEvent::NoModifiers,
1511 WebInputEvent::TimeStampForTesting);
1512 SetFollowupEvent(followup_scroll);
1513 MoveTouchPoint(0, 20, 5);
1514 EXPECT_EQ(0U, GetAndResetSentEventCount());
1515 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1516 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
1517
1518 // The secondary pointer press should be forwarded.
1519 PressTouchPoint(20, 0);
1520 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1521 EXPECT_EQ(1U, GetAndResetSentEventCount());
1522 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1523
1524 // TouchMove with a secondary pointer should also be forwarded.
1525 MoveTouchPoint(1, 25, 0);
1526 EXPECT_EQ(1U, queued_event_count());
1527 EXPECT_EQ(1U, GetAndResetSentEventCount());
1528 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1529 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1530 }
1531
1532 TEST_F(TouchEventQueueTest, AsyncTouch) {
1533 // Queue a TouchStart.
1534 PressTouchPoint(0, 1);
1535 EXPECT_EQ(1U, GetAndResetSentEventCount());
1536 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1537 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1538
1539 for (int i = 0; i < 3; ++i) {
1540 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1541 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1542
1543 MoveTouchPoint(0, 10, 5+i);
1544 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1545 EXPECT_FALSE(HasPendingAsyncTouchMove());
1546 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1547 EXPECT_EQ(0U, queued_event_count());
1548 EXPECT_EQ(1U, GetAndResetSentEventCount());
1549
1550 // Consuming a scroll event will throttle subsequent touchmoves.
1551 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1552 INPUT_EVENT_ACK_STATE_CONSUMED);
1553 MoveTouchPoint(0, 10, 7+i);
1554 EXPECT_TRUE(HasPendingAsyncTouchMove());
1555 EXPECT_EQ(0U, queued_event_count());
1556 EXPECT_EQ(0U, GetAndResetSentEventCount());
1557 }
1558 }
1559
1560 // Ensure that touchmove's are appropriately throttled during a typical
1561 // scroll sequences that transitions between scrolls consumed and unconsumed.
1562 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) {
1563 // Process a TouchStart
1564 PressTouchPoint(0, 1);
1565 EXPECT_EQ(1U, GetAndResetSentEventCount());
1566 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1567 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1568
1569 // Now send the first touch move and associated GestureScrollBegin.
1570 MoveTouchPoint(0, 0, 5);
1571 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1572 WebInputEvent::NoModifiers,
1573 WebInputEvent::TimeStampForTesting);
1574 SetFollowupEvent(followup_scroll);
1575 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1576 EXPECT_EQ(1U, GetAndResetSentEventCount());
1577 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1578 SendGestureEventAck(WebInputEvent::GestureScrollBegin,
1579 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1580
1581 // Send the second touch move and associated GestureScrollUpdate, but don't
1582 // ACK the gesture event yet.
1583 MoveTouchPoint(0, 0, 50);
1584 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
1585 SetFollowupEvent(followup_scroll);
1586 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1587 EXPECT_EQ(1U, GetAndResetSentEventCount());
1588 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1589
1590 // Now queue a second touchmove and verify it's not (yet) dispatched.
1591 MoveTouchPoint(0, 0, 100);
1592 SetFollowupEvent(followup_scroll);
1593 EXPECT_TRUE(HasPendingAsyncTouchMove());
1594 EXPECT_EQ(0U, queued_event_count());
1595 EXPECT_EQ(0U, GetAndResetSentEventCount());
1596 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1597
1598 // Queuing the final touchend should flush the pending async touchmove. In
1599 // this case, we will first dispatch an async touchmove and then a touchend.
1600 // For the async touchmove, we will not send ack again.
1601 ReleaseTouchPoint(0);
1602 followup_scroll.setType(WebInputEvent::GestureScrollEnd);
1603 SetFollowupEvent(followup_scroll);
1604 EXPECT_FALSE(HasPendingAsyncTouchMove());
1605 EXPECT_EQ(2U, all_sent_events().size());
1606 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type());
1607 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType);
1608 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type());
1609 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType);
1610 EXPECT_EQ(2U, GetAndResetSentEventCount());
1611 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1612 EXPECT_EQ(1U, queued_event_count());
1613
1614 // Ack the touchend.
1615 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1616 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1617 EXPECT_EQ(0U, queued_event_count());
1618 EXPECT_EQ(0U, GetAndResetSentEventCount());
1619 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1620
1621 // Now mark the scrolls as not consumed (which would cause future touchmoves
1622 // in the active sequence to be sent if there was one).
1623 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1624 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1625 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1626 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1627
1628 // Start a new touch sequence and verify that throttling has been reset.
1629 // Touch moves after the start of scrolling will again be throttled.
1630 PressTouchPoint(0, 0);
1631 EXPECT_EQ(1U, GetAndResetSentEventCount());
1632 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1633 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1634 MoveTouchPoint(0, 0, 5);
1635 followup_scroll.setType(WebInputEvent::GestureScrollBegin);
1636 SetFollowupEvent(followup_scroll);
1637 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1638 EXPECT_EQ(1U, GetAndResetSentEventCount());
1639 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1640
1641 MoveTouchPoint(0, 0, 6);
1642 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
1643 SetFollowupEvent(followup_scroll);
1644 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1645 EXPECT_FALSE(HasPendingAsyncTouchMove());
1646 EXPECT_EQ(1U, GetAndResetSentEventCount());
1647 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1648
1649 MoveTouchPoint(0, 0, 10);
1650 EXPECT_TRUE(HasPendingAsyncTouchMove());
1651 EXPECT_EQ(0U, queued_event_count());
1652 EXPECT_EQ(0U, GetAndResetSentEventCount());
1653 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1654
1655 // Subsequent touchmove's should be deferred.
1656 MoveTouchPoint(0, 0, 25);
1657 EXPECT_TRUE(HasPendingAsyncTouchMove());
1658 EXPECT_EQ(0U, queued_event_count());
1659 EXPECT_EQ(0U, GetAndResetSentEventCount());
1660 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1661 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
1662
1663 // The pending touchmove should be flushed with the the new touchmove if
1664 // sufficient time has passed and ack to the client.
1665 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1666 MoveTouchPoint(0, 0, 15);
1667 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1668 EXPECT_FALSE(HasPendingAsyncTouchMove());
1669 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
1670 EXPECT_EQ(0U, queued_event_count());
1671 EXPECT_EQ(1U, GetAndResetSentEventCount());
1672 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1673
1674 // Non-touchmove events should always flush any pending touchmove events. In
1675 // this case, we will first dispatch an async touchmove and then a
1676 // touchstart. For the async touchmove, we will not send ack again.
1677 MoveTouchPoint(0, 0, 25);
1678 EXPECT_TRUE(HasPendingAsyncTouchMove());
1679 EXPECT_EQ(0U, queued_event_count());
1680 EXPECT_EQ(0U, GetAndResetSentEventCount());
1681 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1682 PressTouchPoint(30, 30);
1683 EXPECT_FALSE(HasPendingAsyncTouchMove());
1684 EXPECT_EQ(2U, all_sent_events().size());
1685 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type());
1686 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType);
1687 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type());
1688 EXPECT_EQ(WebInputEvent::Blocking, all_sent_events()[1].dispatchType);
1689 EXPECT_EQ(2U, GetAndResetSentEventCount());
1690 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1691 EXPECT_EQ(1U, queued_event_count());
1692
1693 // Ack the touchstart.
1694 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1695 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1696 EXPECT_EQ(0U, queued_event_count());
1697 EXPECT_EQ(0U, GetAndResetSentEventCount());
1698 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1699
1700 // Send a secondary touchmove.
1701 MoveTouchPoint(1, 0, 25);
1702 EXPECT_TRUE(HasPendingAsyncTouchMove());
1703 EXPECT_EQ(0U, queued_event_count());
1704 EXPECT_EQ(0U, GetAndResetSentEventCount());
1705 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1706
1707 // An unconsumed scroll should resume synchronous touch handling.
1708 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1709 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1710
1711 // The pending touchmove should be coalesced with the next (now synchronous)
1712 // touchmove.
1713 MoveTouchPoint(0, 0, 26);
1714 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1715 EXPECT_FALSE(HasPendingAsyncTouchMove());
1716 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
1717 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state);
1718 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state);
1719 EXPECT_EQ(1U, queued_event_count());
1720 EXPECT_EQ(1U, GetAndResetSentEventCount());
1721 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1722
1723 // Subsequent touches will queue until the preceding, synchronous touches are
1724 // ack'ed.
1725 ReleaseTouchPoint(1);
1726 EXPECT_EQ(2U, queued_event_count());
1727 ReleaseTouchPoint(0);
1728 EXPECT_EQ(3U, queued_event_count());
1729 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1730 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1731 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type());
1732 EXPECT_EQ(2U, queued_event_count());
1733 EXPECT_EQ(1U, GetAndResetSentEventCount());
1734 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1735
1736 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1737 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1738 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type());
1739 EXPECT_EQ(1U, queued_event_count());
1740 EXPECT_EQ(1U, GetAndResetSentEventCount());
1741 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1742
1743 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1744 EXPECT_EQ(0U, queued_event_count());
1745 EXPECT_EQ(0U, GetAndResetSentEventCount());
1746 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1747 }
1748
1749 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByTouchEnd) {
1750 PressTouchPoint(0, 0);
1751 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1752 EXPECT_EQ(1U, GetAndResetSentEventCount());
1753 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1754
1755 // Initiate async touchmove dispatch after the start of a scroll sequence.
1756 MoveTouchPoint(0, 0, 5);
1757 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1758 WebInputEvent::NoModifiers,
1759 WebInputEvent::TimeStampForTesting);
1760 SetFollowupEvent(followup_scroll);
1761 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1762 EXPECT_EQ(1U, GetAndResetSentEventCount());
1763 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1764
1765 MoveTouchPoint(0, 0, 10);
1766 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
1767 SetFollowupEvent(followup_scroll);
1768 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1769 EXPECT_EQ(1U, GetAndResetSentEventCount());
1770 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1771
1772 // Now queue a second touchmove and verify it's not (yet) dispatched.
1773 MoveTouchPoint(0, 0, 100);
1774 EXPECT_TRUE(HasPendingAsyncTouchMove());
1775 EXPECT_EQ(0U, queued_event_count());
1776 EXPECT_EQ(0U, GetAndResetSentEventCount());
1777 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1778
1779 // Return the touch sequence to the original touchstart position. Note that
1780 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove.
1781 MoveTouchPoint(0, 0, 0);
1782 EXPECT_TRUE(HasPendingAsyncTouchMove());
1783 EXPECT_EQ(0U, queued_event_count());
1784 EXPECT_EQ(0U, GetAndResetSentEventCount());
1785 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1786
1787 // Queuing the final touchend should flush the pending, async touchmove. In
1788 // this case, we will first dispatch an async touchmove and then a touchend.
1789 // For the async touchmove, we will not send ack again.
1790 ReleaseTouchPoint(0);
1791 EXPECT_FALSE(HasPendingAsyncTouchMove());
1792 EXPECT_EQ(2U, all_sent_events().size());
1793 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type());
1794 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType);
1795 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.x);
1796 EXPECT_EQ(0, all_sent_events()[0].touches[0].position.y);
1797 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[1].type());
1798 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType);
1799 EXPECT_EQ(2U, GetAndResetSentEventCount());
1800 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1801 }
1802
1803 // Ensure that async touch dispatch and touch ack timeout interactions work
1804 // appropriately.
1805 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) {
1806 SetUpForTimeoutTesting();
1807
1808 // The touchstart should start the timeout.
1809 PressTouchPoint(0, 0);
1810 EXPECT_EQ(1U, GetAndResetSentEventCount());
1811 EXPECT_TRUE(IsTimeoutRunning());
1812 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1813 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1814 EXPECT_FALSE(IsTimeoutRunning());
1815
1816 // The start of a scroll gesture should trigger async touch event dispatch.
1817 MoveTouchPoint(0, 1, 1);
1818 EXPECT_EQ(1U, GetAndResetSentEventCount());
1819 EXPECT_TRUE(IsTimeoutRunning());
1820 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1821 WebInputEvent::NoModifiers,
1822 WebInputEvent::TimeStampForTesting);
1823 SetFollowupEvent(followup_scroll);
1824 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1825 EXPECT_FALSE(IsTimeoutRunning());
1826 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1827
1828 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1829 INPUT_EVENT_ACK_STATE_CONSUMED);
1830
1831 // An async touch should fire after the throttling interval has expired, but
1832 // it should not start the touch ack timeout.
1833 MoveTouchPoint(0, 5, 5);
1834 EXPECT_TRUE(HasPendingAsyncTouchMove());
1835 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1836
1837 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
1838 MoveTouchPoint(0, 5, 5);
1839 EXPECT_FALSE(IsTimeoutRunning());
1840 EXPECT_FALSE(HasPendingAsyncTouchMove());
1841 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
1842 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1843 EXPECT_EQ(1U, GetAndResetSentEventCount());
1844
1845 // An unconsumed scroll event will resume synchronous touchmoves, which are
1846 // subject to the ack timeout.
1847 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1848 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1849 MoveTouchPoint(0, 20, 5);
1850 EXPECT_TRUE(IsTimeoutRunning());
1851 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
1852 EXPECT_EQ(1U, GetAndResetSentEventCount());
1853
1854 // The timeout should fire, disabling touch forwarding until both acks are
1855 // received and acking the timed out event.
1856 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1857 EXPECT_FALSE(IsTimeoutRunning());
1858 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1859 EXPECT_EQ(0U, GetAndResetSentEventCount());
1860
1861 // Ack'ing the original event should trigger a cancel event.
1862 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1863 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1864 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
1865 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1866 EXPECT_EQ(1U, GetAndResetSentEventCount());
1867
1868 // Subsequent touchmove's should not be forwarded, even as the scroll gesture
1869 // goes from unconsumed to consumed.
1870 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1871 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1872 MoveTouchPoint(0, 20, 5);
1873 EXPECT_FALSE(HasPendingAsyncTouchMove());
1874 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1875 EXPECT_EQ(0U, GetAndResetSentEventCount());
1876
1877 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1878 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1879 MoveTouchPoint(0, 25, 5);
1880 EXPECT_FALSE(HasPendingAsyncTouchMove());
1881 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1882 EXPECT_EQ(0U, GetAndResetSentEventCount());
1883 }
1884
1885 // Ensure that if the touch ack for an async touchmove triggers a follow-up
1886 // touch event, that follow-up touch will be forwarded appropriately.
1887 TEST_F(TouchEventQueueTest, AsyncTouchWithTouchCancelAfterAck) {
1888 PressTouchPoint(0, 0);
1889 EXPECT_EQ(1U, GetAndResetSentEventCount());
1890 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1891 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1892
1893 // The start of a scroll gesture should trigger async touch event dispatch.
1894 MoveTouchPoint(0, 1, 1);
1895 EXPECT_EQ(1U, GetAndResetSentEventCount());
1896 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1897 WebInputEvent::NoModifiers,
1898 WebInputEvent::TimeStampForTesting);
1899 SetFollowupEvent(followup_scroll);
1900 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1901 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1902 EXPECT_EQ(0U, queued_event_count());
1903
1904 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
1905
1906 // The async touchmove should be ack'ed immediately, but not forwarded.
1907 // However, because the ack triggers a touchcancel, both the pending touch and
1908 // the queued touchcancel should be flushed.
1909 WebTouchEvent followup_cancel(WebInputEvent::TouchCancel,
1910 WebInputEvent::NoModifiers,
1911 WebInputEvent::TimeStampForTesting);
1912 followup_cancel.touchesLength = 1;
1913 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled;
1914 SetFollowupEvent(followup_cancel);
1915 MoveTouchPoint(0, 5, 5);
1916 EXPECT_EQ(1U, queued_event_count());
1917 EXPECT_EQ(2U, all_sent_events().size());
1918 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type());
1919 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType);
1920 EXPECT_EQ(WebInputEvent::TouchCancel, all_sent_events()[1].type());
1921 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[1].dispatchType);
1922 EXPECT_EQ(2U, GetAndResetSentEventCount());
1923 // Sending the ack is because the async touchmove is not ready for
1924 // dispatching send the ack immediately.
1925 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1926 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
1927
1928 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1929 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1930 EXPECT_EQ(0U, queued_event_count());
1931 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type());
1932 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1933 EXPECT_EQ(0U, GetAndResetSentEventCount());
1934 }
1935
1936 // Ensure that the async touch is fully reset if the touch sequence restarts
1937 // without properly terminating.
1938 TEST_F(TouchEventQueueTest, AsyncTouchWithHardTouchStartReset) {
1939 PressTouchPoint(0, 0);
1940 EXPECT_EQ(1U, GetAndResetSentEventCount());
1941 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1942 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1943
1944 // Trigger async touchmove dispatch.
1945 MoveTouchPoint(0, 1, 1);
1946 EXPECT_EQ(1U, GetAndResetSentEventCount());
1947 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1948 WebInputEvent::NoModifiers,
1949 WebInputEvent::TimeStampForTesting);
1950 SetFollowupEvent(followup_scroll);
1951 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1952 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1953 EXPECT_EQ(0U, queued_event_count());
1954 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
1955
1956 // The async touchmove should be immediately ack'ed but delivery is deferred.
1957 MoveTouchPoint(0, 2, 2);
1958 EXPECT_EQ(0U, GetAndResetSentEventCount());
1959 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1960 EXPECT_EQ(0U, queued_event_count());
1961 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
1962
1963 // The queue should be robust to hard touch restarts with a new touch
1964 // sequence. In this case, the deferred async touch should not be flushed
1965 // by the new touch sequence.
1966 SendGestureEvent(WebInputEvent::GestureScrollEnd);
1967 ResetTouchEvent();
1968
1969 PressTouchPoint(0, 0);
1970 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type());
1971 EXPECT_EQ(1U, GetAndResetSentEventCount());
1972 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1973 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1974 }
1975
1976 // Ensure that even when the interval expires, we still need to wait for the
1977 // ack sent back from render to send the next async touchmove once the scroll
1978 // starts.
1979 TEST_F(TouchEventQueueTest, SendNextThrottledAsyncTouchMoveAfterAck) {
1980 // Process a TouchStart
1981 PressTouchPoint(0, 1);
1982 EXPECT_EQ(1U, GetAndResetSentEventCount());
1983 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1984 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1985
1986 // Initiate async touchmove dispatch after the start of a scroll sequence.
1987 MoveTouchPoint(0, 0, 5);
1988 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
1989 WebInputEvent::NoModifiers,
1990 WebInputEvent::TimeStampForTesting);
1991 SetFollowupEvent(followup_scroll);
1992 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1993 EXPECT_EQ(1U, GetAndResetSentEventCount());
1994 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1995
1996 MoveTouchPoint(0, 0, 10);
1997 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
1998 SetFollowupEvent(followup_scroll);
1999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2000 EXPECT_FALSE(HasPendingAsyncTouchMove());
2001 EXPECT_EQ(1U, GetAndResetSentEventCount());
2002 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2003
2004 // We set the next touch event time to be after the throttled interval.
2005 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2006 // Dispatch the touch move event when sufficient time has passed.
2007 MoveTouchPoint(0, 0, 40);
2008 EXPECT_FALSE(HasPendingAsyncTouchMove());
2009 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2010 // When we dispatch an async touchmove, we do not put it back to the queue
2011 // any more and we will ack to client right away.
2012 EXPECT_EQ(0U, queued_event_count());
2013 EXPECT_EQ(1U, GetAndResetSentEventCount());
2014 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2015 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2016
2017 // Do not dispatch the event until throttledTouchmoves intervals expires and
2018 // receive an ack from render.
2019 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2020 MoveTouchPoint(0, 0, 50);
2021 EXPECT_TRUE(HasPendingAsyncTouchMove());
2022 EXPECT_EQ(0U, queued_event_count());
2023 EXPECT_EQ(0U, GetAndResetSentEventCount());
2024 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2025 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2026
2027 // Send pending_async_touch_move_ when we receive an ack back from render,
2028 // but we will not send an ack for pending_async_touch_move_ becasue it is
2029 // been acked before.
2030 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2031 EXPECT_FALSE(HasPendingAsyncTouchMove());
2032 EXPECT_EQ(0U, queued_event_count());
2033 EXPECT_EQ(1U, GetAndResetSentEventCount());
2034 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2035 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2036 }
2037
2038 // Ensure that even when we receive the ack from render, we still need to wait
2039 // for the interval expires to send the next async touchmove once the scroll
2040 // starts.
2041 TEST_F(TouchEventQueueTest, SendNextAsyncTouchMoveAfterAckAndTimeExpire) {
2042 // Process a TouchStart
2043 PressTouchPoint(0, 1);
2044 EXPECT_EQ(1U, GetAndResetSentEventCount());
2045 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2046 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2047
2048 // Initiate async touchmove dispatch after the start of a scroll sequence.
2049 MoveTouchPoint(0, 0, 5);
2050 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
2051 WebInputEvent::NoModifiers,
2052 WebInputEvent::TimeStampForTesting);
2053 SetFollowupEvent(followup_scroll);
2054 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2055 EXPECT_EQ(1U, GetAndResetSentEventCount());
2056 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2057
2058 MoveTouchPoint(0, 0, 10);
2059 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
2060 SetFollowupEvent(followup_scroll);
2061 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2062 EXPECT_FALSE(HasPendingAsyncTouchMove());
2063 EXPECT_EQ(1U, GetAndResetSentEventCount());
2064 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2065
2066 // Dispatch the touch move event when sufficient time has passed.
2067 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2068 MoveTouchPoint(0, 0, 40);
2069 EXPECT_FALSE(HasPendingAsyncTouchMove());
2070 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2071 // When we dispatch an async touchmove, we do not put it back to the queue
2072 // any more and we will ack to client right away.
2073 EXPECT_EQ(0U, queued_event_count());
2074 EXPECT_EQ(1U, GetAndResetSentEventCount());
2075 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2076 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2077
2078 // We receive an ack back from render but the time interval is not expired,
2079 // so we do not dispatch the touch move event.
2080 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2081 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2082 MoveTouchPoint(0, 0, 50);
2083 EXPECT_TRUE(HasPendingAsyncTouchMove());
2084 EXPECT_EQ(0U, queued_event_count());
2085 EXPECT_EQ(0U, GetAndResetSentEventCount());
2086 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2087
2088 // Dispatch the touch move when sufficient time has passed.
2089 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2090 MoveTouchPoint(0, 0, 50);
2091 EXPECT_FALSE(HasPendingAsyncTouchMove());
2092 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
2093 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2094 EXPECT_EQ(0U, queued_event_count());
2095 EXPECT_EQ(1U, GetAndResetSentEventCount());
2096 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2097 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2098 }
2099
2100 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByNonTouchMove) {
2101 // Process a TouchStart
2102 PressTouchPoint(0, 1);
2103 EXPECT_EQ(1U, GetAndResetSentEventCount());
2104 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2105 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2106
2107 // Initiate async touchmove dispatch after the start of a scroll sequence.
2108 MoveTouchPoint(0, 0, 5);
2109 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
2110 WebInputEvent::NoModifiers,
2111 WebInputEvent::TimeStampForTesting);
2112 SetFollowupEvent(followup_scroll);
2113 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2114 EXPECT_EQ(1U, GetAndResetSentEventCount());
2115 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2116
2117 MoveTouchPoint(0, 0, 10);
2118 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
2119 SetFollowupEvent(followup_scroll);
2120 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2121 EXPECT_FALSE(HasPendingAsyncTouchMove());
2122 EXPECT_EQ(1U, GetAndResetSentEventCount());
2123 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2124
2125 // Dispatch the touch move when sufficient time has passed.
2126 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2127 MoveTouchPoint(0, 0, 40);
2128 EXPECT_FALSE(HasPendingAsyncTouchMove());
2129 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2130 // When we dispatch an async touchmove, we do not put it back to the queue
2131 // any more and we will ack to client right away.
2132 EXPECT_EQ(0U, queued_event_count());
2133 EXPECT_EQ(1U, GetAndResetSentEventCount());
2134 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2135 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2136
2137 for (int i = 0; i < 3; ++i) {
2138 // We throttle the touchmoves, put it in the pending_async_touch_move_,
2139 // do not dispatch it.
2140 MoveTouchPoint(0, 10 + 10 * i, 10 + 10 * i);
2141 EXPECT_TRUE(HasPendingAsyncTouchMove());
2142 EXPECT_EQ(0U, queued_event_count());
2143 EXPECT_EQ(0U, GetAndResetSentEventCount());
2144 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2145 EXPECT_EQ(static_cast<size_t>(i + 1),
2146 uncancelable_touch_moves_pending_ack_count());
2147
2148 // Send touchstart will flush pending_async_touch_move_, and increase the
2149 // count. In this case, we will first dispatch an async touchmove and
2150 // then a touchstart. For the async touchmove, we will not send ack again.
2151 PressTouchPoint(30, 30);
2152 EXPECT_FALSE(HasPendingAsyncTouchMove());
2153 EXPECT_EQ(2U, all_sent_events().size());
2154 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[0].type());
2155 EXPECT_NE(WebInputEvent::Blocking, all_sent_events()[0].dispatchType);
2156 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.x);
2157 EXPECT_EQ(10 + 10 * i, all_sent_events()[0].touches[0].position.y);
2158 EXPECT_EQ(static_cast<size_t>(i + 2),
2159 uncancelable_touch_moves_pending_ack_count());
2160 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[1].type());
2161 EXPECT_EQ(WebInputEvent::Blocking, all_sent_events()[1].dispatchType);
2162 EXPECT_EQ(2U, GetAndResetSentEventCount());
2163 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2164
2165 SendTouchEventAckWithID(INPUT_EVENT_ACK_STATE_NOT_CONSUMED,
2166 GetUniqueTouchEventID());
2167 EXPECT_EQ(0U, queued_event_count());
2168 EXPECT_FALSE(HasPendingAsyncTouchMove());
2169 EXPECT_EQ(0U, GetAndResetSentEventCount());
2170 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2171 }
2172
2173 EXPECT_EQ(4U, uncancelable_touch_moves_pending_ack_count());
2174
2175 // When we receive an ack from render we decrease the count.
2176 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2177 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2178 EXPECT_EQ(0U, queued_event_count());
2179 EXPECT_FALSE(HasPendingAsyncTouchMove());
2180
2181 // Do not dispatch the next uncancelable touchmove when we have not received
2182 // all the acks back from render.
2183 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2184 MoveTouchPoint(0, 20, 30);
2185 EXPECT_TRUE(HasPendingAsyncTouchMove());
2186 EXPECT_EQ(0U, queued_event_count());
2187 EXPECT_EQ(0U, GetAndResetSentEventCount());
2188 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2189 EXPECT_EQ(3U, uncancelable_touch_moves_pending_ack_count());
2190
2191 // Once we receive the ack from render, we do not dispatch the
2192 // pending_async_touchmove_ until the count is 0.
2193 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2194 EXPECT_EQ(2U, uncancelable_touch_moves_pending_ack_count());
2195 EXPECT_EQ(0U, queued_event_count());
2196 EXPECT_TRUE(HasPendingAsyncTouchMove());
2197
2198 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2199
2200 // When we receive this ack from render, and the count is 0, so we can
2201 // dispatch the pending_async_touchmove_.
2202 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2203 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2204 EXPECT_FALSE(HasPendingAsyncTouchMove());
2205 EXPECT_EQ(0U, queued_event_count());
2206 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
2207 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2208 EXPECT_EQ(1U, GetAndResetSentEventCount());
2209 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2210 }
2211
2212 // Ensure that even when we receive the ack from render, we still need to wait
2213 // for the interval expires to send the next async touchmove once the scroll
2214 // starts.
2215 TEST_F(TouchEventQueueTest, DoNotIncreaseIfClientConsumeAsyncTouchMove) {
2216 // Process a TouchStart
2217 PressTouchPoint(0, 1);
2218 EXPECT_EQ(1U, GetAndResetSentEventCount());
2219 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2220 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2221
2222 // Initiate async touchmove dispatch after the start of a scroll sequence.
2223 MoveTouchPoint(0, 0, 5);
2224 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollBegin,
2225 WebInputEvent::NoModifiers,
2226 WebInputEvent::TimeStampForTesting);
2227 SetFollowupEvent(followup_scroll);
2228 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2229 EXPECT_EQ(1U, GetAndResetSentEventCount());
2230 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2231
2232 MoveTouchPoint(0, 0, 10);
2233 followup_scroll.setType(WebInputEvent::GestureScrollUpdate);
2234 SetFollowupEvent(followup_scroll);
2235 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2236 EXPECT_FALSE(HasPendingAsyncTouchMove());
2237 EXPECT_EQ(1U, GetAndResetSentEventCount());
2238 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2239
2240 // Dispatch the touch move event when sufficient time has passed.
2241 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2242 MoveTouchPoint(0, 0, 40);
2243 EXPECT_FALSE(HasPendingAsyncTouchMove());
2244 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2245 // When we dispatch an async touchmove, we do not put it back to the queue
2246 // any more and we will ack to client right away.
2247 EXPECT_EQ(0U, queued_event_count());
2248 EXPECT_EQ(1U, GetAndResetSentEventCount());
2249 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2250 EXPECT_EQ(1U, uncancelable_touch_moves_pending_ack_count());
2251
2252 // We receive an ack back from render but the time interval is not expired,
2253 // so we do not dispatch the touch move event.
2254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2255 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2256 MoveTouchPoint(0, 0, 50);
2257 EXPECT_TRUE(HasPendingAsyncTouchMove());
2258 EXPECT_EQ(0U, queued_event_count());
2259 EXPECT_EQ(0U, GetAndResetSentEventCount());
2260 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2261
2262 // Dispatch the touch move when sufficient time has passed. Becasue the event
2263 // is consumed by client already, we would not increase the count and ack to
2264 // client again.
2265 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2266 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
2267 MoveTouchPoint(0, 0, 50);
2268 EXPECT_FALSE(HasPendingAsyncTouchMove());
2269 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
2270 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2271 EXPECT_EQ(0U, queued_event_count());
2272 EXPECT_EQ(1U, GetAndResetSentEventCount());
2273 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2274 EXPECT_EQ(0U, uncancelable_touch_moves_pending_ack_count());
2275 }
2276
2277 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) {
2278 // Queue a TouchStart.
2279 PressTouchPoint(0, 1);
2280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2281 EXPECT_EQ(0U, queued_event_count());
2282 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2283
2284 MoveTouchPoint(0, 20, 5);
2285 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2286 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2287 EXPECT_EQ(0U, queued_event_count());
2288 EXPECT_EQ(2U, GetAndResetSentEventCount());
2289
2290 // Even if the first touchmove event was consumed, subsequent unconsumed
2291 // touchmove events should trigger scrolling.
2292 MoveTouchPoint(0, 60, 5);
2293 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2294 EXPECT_EQ(0U, queued_event_count());
2295 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2296 EXPECT_EQ(1U, GetAndResetSentEventCount());
2297
2298 MoveTouchPoint(0, 20, 5);
2299 WebGestureEvent followup_scroll(WebInputEvent::GestureScrollUpdate,
2300 WebInputEvent::NoModifiers,
2301 WebInputEvent::TimeStampForTesting);
2302 SetFollowupEvent(followup_scroll);
2303 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2304 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
2305 INPUT_EVENT_ACK_STATE_CONSUMED);
2306 EXPECT_EQ(0U, queued_event_count());
2307 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2308 EXPECT_EQ(1U, GetAndResetSentEventCount());
2309
2310 // Touch move event is throttled.
2311 MoveTouchPoint(0, 60, 5);
2312 EXPECT_EQ(0U, queued_event_count());
2313 EXPECT_EQ(0U, GetAndResetSentEventCount());
2314 }
2315
2316 TEST_F(TouchEventQueueTest, TouchStartCancelableDuringScroll) {
2317 // Queue a touchstart and touchmove that go unconsumed, transitioning to an
2318 // active scroll sequence.
2319 PressTouchPoint(0, 1);
2320 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2321 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2322 ASSERT_EQ(1U, GetAndResetSentEventCount());
2323
2324 MoveTouchPoint(0, 20, 5);
2325 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2326 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin);
2327 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2328 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2329 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2330 ASSERT_EQ(1U, GetAndResetSentEventCount());
2331
2332 // Even though scrolling has begun, touchstart events should be cancelable,
2333 // allowing, for example, customized pinch processing.
2334 PressTouchPoint(10, 11);
2335 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2336 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2337 ASSERT_EQ(1U, GetAndResetSentEventCount());
2338
2339 // As the touch start was consumed, touchmoves should no longer be throttled.
2340 MoveTouchPoint(1, 11, 11);
2341 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2342 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2343 ASSERT_EQ(1U, GetAndResetSentEventCount());
2344
2345 // With throttling disabled, touchend and touchmove events should also be
2346 // cancelable.
2347 MoveTouchPoint(1, 12, 12);
2348 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2349 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2350 ASSERT_EQ(1U, GetAndResetSentEventCount());
2351 ReleaseTouchPoint(1);
2352 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2353 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2354 ASSERT_EQ(1U, GetAndResetSentEventCount());
2355
2356 // If subsequent touchmoves aren't consumed, the generated scroll events
2357 // will restore async touch dispatch.
2358 MoveTouchPoint(0, 25, 5);
2359 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2360 SendGestureEvent(blink::WebInputEvent::GestureScrollUpdate);
2361 EXPECT_EQ(WebInputEvent::Blocking, sent_event().dispatchType);
2362 ASSERT_EQ(1U, GetAndResetSentEventCount());
2363 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1);
2364 MoveTouchPoint(0, 30, 5);
2365 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2366 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2367 ASSERT_EQ(1U, GetAndResetSentEventCount());
2368
2369 // The touchend will be uncancelable during an active scroll sequence.
2370 ReleaseTouchPoint(0);
2371 EXPECT_NE(WebInputEvent::Blocking, sent_event().dispatchType);
2372 ASSERT_EQ(1U, GetAndResetSentEventCount());
2373 }
2374
2375 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) {
2376 SyntheticWebTouchEvent event;
2377 event.PressPoint(0, 0);
2378 SendTouchEvent(event);
2379 EXPECT_EQ(1U, GetAndResetSentEventCount());
2380 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2381 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2382
2383 // Give the touchmove a previously unseen pointer id; it should not be sent.
2384 int press_id = event.touches[0].id;
2385 event.MovePoint(0, 1, 1);
2386 event.touches[0].id = 7;
2387 SendTouchEvent(event);
2388 EXPECT_EQ(0U, GetAndResetSentEventCount());
2389 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2390
2391 // Give the touchmove a valid id; it should be sent.
2392 event.touches[0].id = press_id;
2393 SendTouchEvent(event);
2394 EXPECT_EQ(1U, GetAndResetSentEventCount());
2395 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2396 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2397
2398 // Do the same for release.
2399 event.ReleasePoint(0);
2400 event.touches[0].id = 11;
2401 SendTouchEvent(event);
2402 EXPECT_EQ(0U, GetAndResetSentEventCount());
2403 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2404
2405 // Give the touchmove a valid id; it should be sent.
2406 event.touches[0].id = press_id;
2407 SendTouchEvent(event);
2408 EXPECT_EQ(1U, GetAndResetSentEventCount());
2409 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2410 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2411 }
2412
2413 // Tests that touch points states are correct in TouchMove events.
2414 TEST_F(TouchEventQueueTest, PointerStatesInTouchMove) {
2415 PressTouchPoint(1, 1);
2416 PressTouchPoint(2, 2);
2417 PressTouchPoint(3, 3);
2418 PressTouchPoint(4, 4);
2419 EXPECT_EQ(4U, queued_event_count());
2420 EXPECT_EQ(1U, GetAndResetSentEventCount());
2421
2422 // Receive ACK for the first three touch-events.
2423 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2424 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2425 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2426 EXPECT_EQ(1U, queued_event_count());
2427
2428 // Test current touches state before sending TouchMoves.
2429 const WebTouchEvent& event1 = sent_event();
2430 EXPECT_EQ(WebInputEvent::TouchStart, event1.type());
2431 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[0].state);
2432 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2433 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[2].state);
2434 EXPECT_EQ(WebTouchPoint::StatePressed, event1.touches[3].state);
2435
2436 // Move x-position for 1st touch, y-position for 2nd touch
2437 // and do not move other touches.
2438 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2439 MoveTouchPoints(2, 3.f, 3.f, 3, 4.f, 4.f);
2440 EXPECT_EQ(2U, queued_event_count());
2441
2442 // Receive an ACK for the last TouchPress event.
2443 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2444
2445 // 1st TouchMove is sent. Test for touches state.
2446 const WebTouchEvent& event2 = sent_event();
2447 EXPECT_EQ(WebInputEvent::TouchMove, event2.type());
2448 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2449 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2450 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[2].state);
2451 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[3].state);
2452
2453 // Move only 4th touch but not others.
2454 MoveTouchPoints(0, 1.1f, 1.f, 1, 2.f, 20.001f);
2455 MoveTouchPoints(2, 3.f, 3.f, 3, 4.1f, 4.1f);
2456
2457 // Receive an ACK for previous (1st) TouchMove.
2458 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2459
2460 // 2nd TouchMove is sent. Test for touches state.
2461 const WebTouchEvent& event3 = sent_event();
2462 EXPECT_EQ(WebInputEvent::TouchMove, event3.type());
2463 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[0].state);
2464 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[1].state);
2465 EXPECT_EQ(WebTouchPoint::StateStationary, event3.touches[2].state);
2466 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[3].state);
2467 }
2468
2469 // Tests that touch point state is correct in TouchMove events
2470 // when point properties other than position changed.
2471 TEST_F(TouchEventQueueTest, PointerStatesWhenOtherThanPositionChanged) {
2472 PressTouchPoint(1, 1);
2473 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2474
2475 // Default initial radiusX/Y is (1.f, 1.f).
2476 // Default initial rotationAngle is 1.f.
2477 // Default initial force is 1.f.
2478
2479 // Change touch point radius only.
2480 ChangeTouchPointRadius(0, 1.5f, 1.f);
2481 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2482
2483 // TouchMove is sent. Test for pointer state.
2484 const WebTouchEvent& event1 = sent_event();
2485 EXPECT_EQ(WebInputEvent::TouchMove, event1.type());
2486 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2487
2488 // Change touch point force.
2489 ChangeTouchPointForce(0, 0.9f);
2490 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2491
2492 // TouchMove is sent. Test for pointer state.
2493 const WebTouchEvent& event2 = sent_event();
2494 EXPECT_EQ(WebInputEvent::TouchMove, event2.type());
2495 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state);
2496
2497 // Change touch point rotationAngle.
2498 ChangeTouchPointRotationAngle(0, 1.1f);
2499 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2500
2501 // TouchMove is sent. Test for pointer state.
2502 const WebTouchEvent& event3 = sent_event();
2503 EXPECT_EQ(WebInputEvent::TouchMove, event3.type());
2504 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state);
2505
2506 EXPECT_EQ(0U, queued_event_count());
2507 EXPECT_EQ(4U, GetAndResetSentEventCount());
2508 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2509 }
2510
2511 // Tests that TouchMoves are filtered when none of the points are changed.
2512 TEST_F(TouchEventQueueTest, FilterTouchMovesWhenNoPointerChanged) {
2513 PressTouchPoint(1, 1);
2514 PressTouchPoint(2, 2);
2515 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2516 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2517 EXPECT_EQ(0U, queued_event_count());
2518 EXPECT_EQ(2U, GetAndResetSentEventCount());
2519 EXPECT_EQ(2U, GetAndResetAckedEventCount());
2520
2521 // Move 1st touch point.
2522 MoveTouchPoint(0, 10, 10);
2523 EXPECT_EQ(1U, queued_event_count());
2524
2525 // TouchMove should be allowed and test for touches state.
2526 const WebTouchEvent& event1 = sent_event();
2527 EXPECT_EQ(WebInputEvent::TouchMove, event1.type());
2528 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state);
2529 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state);
2530 EXPECT_EQ(1U, GetAndResetSentEventCount());
2531 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2532
2533 // Do not really move any touch points, but use previous values.
2534 MoveTouchPoint(0, 10, 10);
2535 ChangeTouchPointRadius(1, 1, 1);
2536 MoveTouchPoint(1, 2, 2);
2537 EXPECT_EQ(2U, queued_event_count());
2538 EXPECT_EQ(0U, GetAndResetSentEventCount());
2539
2540 // Receive an ACK for 1st TouchMove.
2541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2542
2543 // Tries to forward TouchMove but should be filtered
2544 // when none of the touch points have changed.
2545 EXPECT_EQ(0U, queued_event_count());
2546 EXPECT_EQ(0U, GetAndResetSentEventCount());
2547 EXPECT_EQ(4U, GetAndResetAckedEventCount());
2548 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
2549
2550 // Move 2nd touch point.
2551 MoveTouchPoint(1, 3, 3);
2552 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2553 EXPECT_EQ(0U, queued_event_count());
2554
2555 // TouchMove should be allowed and test for touches state.
2556 const WebTouchEvent& event2 = sent_event();
2557 EXPECT_EQ(WebInputEvent::TouchMove, event2.type());
2558 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state);
2559 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state);
2560 EXPECT_EQ(1U, GetAndResetSentEventCount());
2561 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2562 }
2563
2564 // Tests that touch-scroll-notification is not pushed into an empty queue.
2565 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EmptyQueue) {
2566 PrependTouchScrollNotification();
2567
2568 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2569 EXPECT_EQ(0U, queued_event_count());
2570 EXPECT_EQ(0U, GetAndResetSentEventCount());
2571 }
2572
2573 // Tests touch-scroll-notification firing order when the event is placed at the
2574 // end of touch queue because of a pending ack for the head of the queue.
2575 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_EndOfQueue) {
2576 PressTouchPoint(1, 1);
2577
2578 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2579 EXPECT_EQ(1U, queued_event_count());
2580
2581 // Send the touch-scroll-notification when 3 events are in the queue.
2582 PrependTouchScrollNotification();
2583
2584 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2585 EXPECT_EQ(2U, queued_event_count());
2586
2587 // Receive an ACK for the touchstart.
2588 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2589
2590 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2591 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
2592 EXPECT_EQ(1U, queued_event_count());
2593
2594 // Receive an ACK for the touch-scroll-notification.
2595 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2596
2597 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2598 EXPECT_EQ(0U, queued_event_count());
2599
2600 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type());
2601 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type());
2602 EXPECT_EQ(2U, GetAndResetSentEventCount());
2603 }
2604
2605 // Tests touch-scroll-notification firing order when the event is placed in the
2606 // 2nd position in the touch queue between two events.
2607 TEST_F(TouchEventQueueTest, TouchScrollNotificationOrder_SecondPosition) {
2608 PressTouchPoint(1, 1);
2609 MoveTouchPoint(0, 5, 5);
2610 ReleaseTouchPoint(0);
2611
2612 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2613 EXPECT_EQ(3U, queued_event_count());
2614
2615 // Send the touch-scroll-notification when 3 events are in the queue.
2616 PrependTouchScrollNotification();
2617
2618 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2619 EXPECT_EQ(4U, queued_event_count());
2620
2621 // Receive an ACK for the touchstart.
2622 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2623
2624 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2625 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type());
2626 EXPECT_EQ(3U, queued_event_count());
2627
2628 // Receive an ACK for the touch-scroll-notification.
2629 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED);
2630
2631 EXPECT_EQ(0U, GetAndResetAckedEventCount());
2632 EXPECT_EQ(2U, queued_event_count());
2633
2634 // Receive an ACK for the touchmove.
2635 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2636
2637 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2638 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type());
2639 EXPECT_EQ(1U, queued_event_count());
2640
2641 // Receive an ACK for the touchend.
2642 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2643
2644 EXPECT_EQ(1U, GetAndResetAckedEventCount());
2645 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type());
2646 EXPECT_EQ(0U, queued_event_count());
2647
2648 EXPECT_EQ(WebInputEvent::TouchStart, all_sent_events()[0].type());
2649 EXPECT_EQ(WebInputEvent::TouchScrollStarted, all_sent_events()[1].type());
2650 EXPECT_EQ(WebInputEvent::TouchMove, all_sent_events()[2].type());
2651 EXPECT_EQ(WebInputEvent::TouchEnd, all_sent_events()[3].type());
2652 EXPECT_EQ(4U, GetAndResetSentEventCount());
2653 }
2654
2655 // Tests that if touchStartOrFirstTouchMove is correctly set up for touch
2656 // events.
2657 TEST_F(TouchEventQueueTest, TouchStartOrFirstTouchMove) {
2658 PressTouchPoint(1, 1);
2659 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2660 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type());
2661 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove);
2662
2663 MoveTouchPoint(0, 5, 5);
2664 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2665 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
2666 EXPECT_TRUE(sent_event().touchStartOrFirstTouchMove);
2667
2668 MoveTouchPoint(0, 15, 15);
2669 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2670 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type());
2671 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove);
2672
2673 ReleaseTouchPoint(0);
2674 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
2675 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type());
2676 EXPECT_FALSE(sent_event().touchStartOrFirstTouchMove);
2677 }
2678
2679 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698