IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / input / touch_event_queue_unittest.cc
blob33a26ca01ccf8ac283893da26315b8889a8e77f7
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/renderer_host/input/timeout_monitor.h"
10 #include "content/browser/renderer_host/input/touch_event_queue.h"
11 #include "content/common/input/synthetic_web_input_event_builders.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 using blink::WebGestureEvent;
16 using blink::WebInputEvent;
17 using blink::WebTouchEvent;
18 using blink::WebTouchPoint;
20 namespace content {
21 namespace {
22 const size_t kDefaultTouchTimeoutDelayMs = 10;
25 class TouchEventQueueTest : public testing::Test,
26 public TouchEventQueueClient {
27 public:
28 TouchEventQueueTest()
29 : sent_event_count_(0),
30 acked_event_count_(0),
31 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {}
33 virtual ~TouchEventQueueTest() {}
35 // testing::Test
36 virtual void SetUp() OVERRIDE {
37 queue_.reset(new TouchEventQueue(this));
38 queue_->OnHasTouchEventHandlers(true);
41 virtual void TearDown() OVERRIDE {
42 queue_.reset();
45 // TouchEventQueueClient
46 virtual void SendTouchEventImmediately(
47 const TouchEventWithLatencyInfo& event) OVERRIDE {
48 ++sent_event_count_;
49 last_sent_event_ = event.event;
50 if (sync_ack_result_)
51 SendTouchEventACK(*sync_ack_result_.Pass());
54 virtual void OnTouchEventAck(
55 const TouchEventWithLatencyInfo& event,
56 InputEventAckState ack_result) OVERRIDE {
57 ++acked_event_count_;
58 last_acked_event_ = event.event;
59 last_acked_event_state_ = ack_result;
60 if (followup_touch_event_) {
61 scoped_ptr<WebTouchEvent> followup_touch_event =
62 followup_touch_event_.Pass();
63 SendTouchEvent(*followup_touch_event);
65 if (followup_gesture_event_) {
66 scoped_ptr<WebGestureEvent> followup_gesture_event =
67 followup_gesture_event_.Pass();
68 queue_->OnGestureScrollEvent(
69 GestureEventWithLatencyInfo(*followup_gesture_event,
70 ui::LatencyInfo()));
74 protected:
76 void SetUpForTimeoutTesting(size_t timeout_delay_ms) {
77 queue_->SetAckTimeoutEnabled(true, timeout_delay_ms);
80 void SendTouchEvent(const WebTouchEvent& event) {
81 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
84 void SendGestureEvent(WebInputEvent::Type type) {
85 WebGestureEvent event;
86 event.type = type;
87 queue_->OnGestureScrollEvent(
88 GestureEventWithLatencyInfo(event, ui::LatencyInfo()));
91 void SendTouchEventACK(InputEventAckState ack_result) {
92 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo());
95 void SetFollowupEvent(const WebTouchEvent& event) {
96 followup_touch_event_.reset(new WebTouchEvent(event));
99 void SetFollowupEvent(const WebGestureEvent& event) {
100 followup_gesture_event_.reset(new WebGestureEvent(event));
103 void SetSyncAckResult(InputEventAckState sync_ack_result) {
104 sync_ack_result_.reset(new InputEventAckState(sync_ack_result));
107 void PressTouchPoint(int x, int y) {
108 touch_event_.PressPoint(x, y);
109 SendTouchEvent();
112 void MoveTouchPoint(int index, int x, int y) {
113 touch_event_.MovePoint(index, x, y);
114 SendTouchEvent();
117 void MoveTouchPoints(int index0, int x0, int y0, int index1, int x1, int y1) {
118 touch_event_.MovePoint(index0, x0, y0);
119 touch_event_.MovePoint(index1, x1, y1);
120 SendTouchEvent();
123 void ReleaseTouchPoint(int index) {
124 touch_event_.ReleasePoint(index);
125 SendTouchEvent();
128 void CancelTouchPoint(int index) {
129 touch_event_.CancelPoint(index);
130 SendTouchEvent();
133 size_t GetAndResetAckedEventCount() {
134 size_t count = acked_event_count_;
135 acked_event_count_ = 0;
136 return count;
139 size_t GetAndResetSentEventCount() {
140 size_t count = sent_event_count_;
141 sent_event_count_ = 0;
142 return count;
145 bool IsPendingAckTouchStart() const {
146 return queue_->IsPendingAckTouchStart();
149 void OnHasTouchEventHandlers(bool has_handlers) {
150 queue_->OnHasTouchEventHandlers(has_handlers);
153 bool WillForwardTouchEvents() {
154 return queue_->has_handlers_ &&
155 !queue_->scroll_in_progress_ &&
156 !queue_->HasTimeoutEvent();
159 bool IsTimeoutRunning() {
160 return queue_->IsTimeoutRunningForTesting();
163 size_t queued_event_count() const {
164 return queue_->size();
167 const WebTouchEvent& latest_event() const {
168 return queue_->GetLatestEventForTesting().event;
171 const WebTouchEvent& acked_event() const {
172 return last_acked_event_;
175 const WebTouchEvent& sent_event() const {
176 return last_sent_event_;
179 InputEventAckState acked_event_state() const {
180 return last_acked_event_state_;
183 private:
184 void SendTouchEvent() {
185 SendTouchEvent(touch_event_);
186 touch_event_.ResetPoints();
189 scoped_ptr<TouchEventQueue> queue_;
190 size_t sent_event_count_;
191 size_t acked_event_count_;
192 WebTouchEvent last_sent_event_;
193 WebTouchEvent last_acked_event_;
194 InputEventAckState last_acked_event_state_;
195 SyntheticWebTouchEvent touch_event_;
196 scoped_ptr<WebTouchEvent> followup_touch_event_;
197 scoped_ptr<WebGestureEvent> followup_gesture_event_;
198 scoped_ptr<InputEventAckState> sync_ack_result_;
199 base::MessageLoopForUI message_loop_;
203 // Tests that touch-events are queued properly.
204 TEST_F(TouchEventQueueTest, Basic) {
205 PressTouchPoint(1, 1);
206 EXPECT_EQ(1U, queued_event_count());
207 EXPECT_EQ(1U, GetAndResetSentEventCount());
209 // The second touch should not be sent since one is already in queue.
210 MoveTouchPoint(0, 5, 5);
211 EXPECT_EQ(2U, queued_event_count());
212 EXPECT_EQ(0U, GetAndResetSentEventCount());
214 // Receive an ACK for the first touch-event.
215 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
216 EXPECT_EQ(1U, queued_event_count());
217 EXPECT_EQ(1U, GetAndResetSentEventCount());
218 EXPECT_EQ(1U, GetAndResetAckedEventCount());
219 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
221 // Receive an ACK for the second touch-event.
222 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
223 EXPECT_EQ(0U, queued_event_count());
224 EXPECT_EQ(0U, GetAndResetSentEventCount());
225 EXPECT_EQ(1U, GetAndResetAckedEventCount());
226 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
229 // Tests that the touch-queue is emptied if a page stops listening for touch
230 // events.
231 TEST_F(TouchEventQueueTest, QueueFlushedWhenHandlersRemoved) {
232 OnHasTouchEventHandlers(true);
233 EXPECT_EQ(0U, queued_event_count());
234 EXPECT_EQ(0U, GetAndResetSentEventCount());
236 // Send a touch-press event.
237 PressTouchPoint(1, 1);
238 EXPECT_EQ(1U, GetAndResetSentEventCount());
240 ReleaseTouchPoint(0);
242 // Events will be queued until the first sent event is ack'ed.
243 for (int i = 5; i < 15; ++i) {
244 PressTouchPoint(1, 1);
245 MoveTouchPoint(0, i, i);
246 ReleaseTouchPoint(0);
248 EXPECT_EQ(32U, queued_event_count());
249 EXPECT_EQ(0U, GetAndResetSentEventCount());
251 // Receive an ACK for the first touch-event. One of the queued touch-event
252 // should be forwarded.
253 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
254 EXPECT_EQ(31U, queued_event_count());
255 EXPECT_EQ(1U, GetAndResetSentEventCount());
256 EXPECT_EQ(1U, GetAndResetAckedEventCount());
257 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
259 // Flush the queue. The touch-event queue should now be emptied, but none of
260 // the queued touch-events should be sent to the renderer.
261 OnHasTouchEventHandlers(false);
262 EXPECT_EQ(0U, queued_event_count());
263 EXPECT_EQ(0U, GetAndResetSentEventCount());
264 EXPECT_EQ(31U, GetAndResetAckedEventCount());
267 // Tests that removal of a touch handler during a touch sequence will prevent
268 // the remaining sequence from being forwarded, even if another touch handler is
269 // registered during the same touch sequence.
270 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) {
271 // Send a touch-press event.
272 PressTouchPoint(1, 1);
273 EXPECT_EQ(1U, GetAndResetSentEventCount());
274 EXPECT_EQ(1U, queued_event_count());
276 // Queue a touch-move event.
277 MoveTouchPoint(0, 5, 5);
278 EXPECT_EQ(2U, queued_event_count());
279 EXPECT_EQ(0U, GetAndResetAckedEventCount());
280 EXPECT_EQ(0U, GetAndResetSentEventCount());
282 // Touch handle deregistration should flush the queue.
283 OnHasTouchEventHandlers(false);
284 EXPECT_EQ(2U, GetAndResetAckedEventCount());
285 EXPECT_EQ(0U, queued_event_count());
287 // The ack should be ignored as the touch queue is now empty.
288 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
289 EXPECT_EQ(0U, GetAndResetAckedEventCount());
290 EXPECT_EQ(0U, queued_event_count());
292 // Events should be dropped while there is no touch handler.
293 MoveTouchPoint(0, 10, 10);
294 EXPECT_EQ(0U, queued_event_count());
295 EXPECT_EQ(1U, GetAndResetAckedEventCount());
296 EXPECT_EQ(0U, GetAndResetSentEventCount());
298 // Simulate touch handler registration in the middle of a touch sequence.
299 OnHasTouchEventHandlers(true);
301 // The touch end for the interrupted sequence should be dropped.
302 ReleaseTouchPoint(0);
303 EXPECT_EQ(0U, queued_event_count());
304 EXPECT_EQ(1U, GetAndResetAckedEventCount());
305 EXPECT_EQ(0U, GetAndResetSentEventCount());
307 // A new touch sequence should be forwarded properly.
308 PressTouchPoint(1, 1);
309 EXPECT_EQ(1U, queued_event_count());
310 EXPECT_EQ(1U, GetAndResetSentEventCount());
313 // Tests that touch-events are coalesced properly in the queue.
314 TEST_F(TouchEventQueueTest, Coalesce) {
315 // Send a touch-press event.
316 PressTouchPoint(1, 1);
317 EXPECT_EQ(1U, GetAndResetSentEventCount());
319 // Send a few touch-move events, followed by a touch-release event. All the
320 // touch-move events should be coalesced into a single event.
321 for (int i = 5; i < 15; ++i)
322 MoveTouchPoint(0, i, i);
324 EXPECT_EQ(0U, GetAndResetSentEventCount());
325 ReleaseTouchPoint(0);
326 EXPECT_EQ(0U, GetAndResetSentEventCount());
327 EXPECT_EQ(3U, queued_event_count());
329 // ACK the press. Coalesced touch-move events should be sent.
330 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
331 EXPECT_EQ(2U, queued_event_count());
332 EXPECT_EQ(1U, GetAndResetSentEventCount());
333 EXPECT_EQ(1U, GetAndResetAckedEventCount());
334 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
335 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
337 // ACK the moves.
338 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
339 EXPECT_EQ(1U, queued_event_count());
340 EXPECT_EQ(1U, GetAndResetSentEventCount());
341 EXPECT_EQ(10U, GetAndResetAckedEventCount());
342 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
344 // ACK the release.
345 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
346 EXPECT_EQ(0U, queued_event_count());
347 EXPECT_EQ(0U, GetAndResetSentEventCount());
348 EXPECT_EQ(1U, GetAndResetAckedEventCount());
349 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
352 // Tests that an event that has already been sent but hasn't been ack'ed yet
353 // doesn't get coalesced with newer events.
354 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) {
355 // Send a touch-press event.
356 PressTouchPoint(1, 1);
357 EXPECT_EQ(1U, GetAndResetSentEventCount());
359 // Send a few touch-move events, followed by a touch-release event. All the
360 // touch-move events should be coalesced into a single event.
361 for (int i = 5; i < 15; ++i)
362 MoveTouchPoint(0, i, i);
364 EXPECT_EQ(0U, GetAndResetSentEventCount());
365 EXPECT_EQ(2U, queued_event_count());
367 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
368 EXPECT_EQ(1U, GetAndResetSentEventCount());
369 EXPECT_EQ(1U, queued_event_count());
371 // The coalesced touch-move event has been sent to the renderer. Any new
372 // touch-move event should not be coalesced with the sent event.
373 MoveTouchPoint(0, 5, 5);
374 EXPECT_EQ(2U, queued_event_count());
376 MoveTouchPoint(0, 7, 7);
377 EXPECT_EQ(2U, queued_event_count());
380 // Tests that coalescing works correctly for multi-touch events.
381 TEST_F(TouchEventQueueTest, MultiTouch) {
382 // Press the first finger.
383 PressTouchPoint(1, 1);
384 EXPECT_EQ(1U, GetAndResetSentEventCount());
386 // Move the finger.
387 MoveTouchPoint(0, 5, 5);
388 EXPECT_EQ(2U, queued_event_count());
390 // Now press a second finger.
391 PressTouchPoint(2, 2);
392 EXPECT_EQ(3U, queued_event_count());
394 // Move both fingers.
395 MoveTouchPoints(0, 10, 10, 1, 20, 20);
396 MoveTouchPoint(1, 20, 20);
397 EXPECT_EQ(4U, queued_event_count());
399 // Move only one finger now.
400 MoveTouchPoint(0, 15, 15);
401 EXPECT_EQ(4U, queued_event_count());
403 // Move the other finger.
404 MoveTouchPoint(1, 25, 25);
405 EXPECT_EQ(4U, queued_event_count());
407 // Make sure both fingers are marked as having been moved in the coalesced
408 // event.
409 const WebTouchEvent& event = latest_event();
410 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state);
411 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state);
414 // Tests that if a touch-event queue is destroyed in response to a touch-event
415 // in the renderer, then there is no crash when the ACK for that touch-event
416 // comes back.
417 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) {
418 // Send some touch-events to the renderer.
419 PressTouchPoint(1, 1);
420 EXPECT_EQ(1U, GetAndResetSentEventCount());
421 EXPECT_EQ(1U, queued_event_count());
423 MoveTouchPoint(0, 10, 10);
424 EXPECT_EQ(0U, GetAndResetSentEventCount());
425 EXPECT_EQ(2U, queued_event_count());
427 // Receive an ACK for the press. This should cause the queued touch-move to
428 // be sent to the renderer.
429 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
430 EXPECT_EQ(1U, GetAndResetSentEventCount());
431 EXPECT_EQ(1U, queued_event_count());
433 OnHasTouchEventHandlers(false);
434 EXPECT_EQ(0U, GetAndResetSentEventCount());
435 EXPECT_EQ(0U, queued_event_count());
437 // Now receive an ACK for the move.
438 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
439 EXPECT_EQ(0U, GetAndResetSentEventCount());
440 EXPECT_EQ(0U, queued_event_count());
443 // Tests that touch-move events are not sent to the renderer if the preceding
444 // touch-press event did not have a consumer (and consequently, did not hit the
445 // main thread in the renderer). Also tests that all queued/coalesced touch
446 // events are flushed immediately when the ACK for the touch-press comes back
447 // with NO_CONSUMER status.
448 TEST_F(TouchEventQueueTest, NoConsumer) {
449 // The first touch-press should reach the renderer.
450 PressTouchPoint(1, 1);
451 EXPECT_EQ(1U, GetAndResetSentEventCount());
453 // The second touch should not be sent since one is already in queue.
454 MoveTouchPoint(0, 5, 5);
455 EXPECT_EQ(0U, GetAndResetSentEventCount());
456 EXPECT_EQ(2U, queued_event_count());
458 // Receive an ACK for the first touch-event. This should release the queued
459 // touch-event, but it should not be sent to the renderer.
460 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
461 EXPECT_EQ(0U, queued_event_count());
462 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
463 EXPECT_EQ(2U, GetAndResetAckedEventCount());
464 EXPECT_EQ(0U, GetAndResetSentEventCount());
466 // Send a release event. This should not reach the renderer.
467 ReleaseTouchPoint(0);
468 EXPECT_EQ(0U, GetAndResetSentEventCount());
469 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
470 EXPECT_EQ(1U, GetAndResetAckedEventCount());
472 // Send a press-event, followed by move and release events, and another press
473 // event, before the ACK for the first press event comes back. All of the
474 // events should be queued first. After the NO_CONSUMER ack for the first
475 // touch-press, all events upto the second touch-press should be flushed.
476 PressTouchPoint(10, 10);
477 EXPECT_EQ(1U, GetAndResetSentEventCount());
479 MoveTouchPoint(0, 5, 5);
480 MoveTouchPoint(0, 6, 5);
481 ReleaseTouchPoint(0);
483 PressTouchPoint(6, 5);
484 EXPECT_EQ(0U, GetAndResetSentEventCount());
485 // The queue should hold the first sent touch-press event, the coalesced
486 // touch-move event, the touch-end event and the second touch-press event.
487 EXPECT_EQ(4U, queued_event_count());
489 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
490 EXPECT_EQ(1U, GetAndResetSentEventCount());
491 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type);
492 EXPECT_EQ(4U, GetAndResetAckedEventCount());
493 EXPECT_EQ(1U, queued_event_count());
495 // ACK the second press event as NO_CONSUMER too.
496 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
497 EXPECT_EQ(0U, GetAndResetSentEventCount());
498 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
499 EXPECT_EQ(1U, GetAndResetAckedEventCount());
500 EXPECT_EQ(0U, queued_event_count());
502 // Send a second press event. Even though the first touch had NO_CONSUMER,
503 // this press event should reach the renderer.
504 PressTouchPoint(1, 1);
505 EXPECT_EQ(1U, GetAndResetSentEventCount());
506 EXPECT_EQ(1U, queued_event_count());
509 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) {
510 // Press two touch points and move them around a bit. The renderer consumes
511 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for
512 // the second touch point.
514 PressTouchPoint(1, 1);
515 EXPECT_EQ(1U, GetAndResetSentEventCount());
517 MoveTouchPoint(0, 5, 5);
519 PressTouchPoint(10, 10);
521 MoveTouchPoint(0, 2, 2);
523 MoveTouchPoint(1, 4, 10);
525 MoveTouchPoints(0, 10, 10, 1, 20, 20);
527 // Since the first touch-press is still pending ACK, no other event should
528 // have been sent to the renderer.
529 EXPECT_EQ(0U, GetAndResetSentEventCount());
530 // The queue includes the two presses, the first touch-move of the first
531 // point, and a coalesced touch-move of both points.
532 EXPECT_EQ(4U, queued_event_count());
534 // ACK the first press as CONSUMED. This should cause the first touch-move of
535 // the first touch-point to be dispatched.
536 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
537 EXPECT_EQ(1U, GetAndResetSentEventCount());
538 EXPECT_EQ(3U, queued_event_count());
540 // ACK the first move as CONSUMED.
541 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
542 EXPECT_EQ(1U, GetAndResetSentEventCount());
543 EXPECT_EQ(2U, queued_event_count());
545 // ACK the second press as NO_CONSUMER_EXISTS. This will dequeue the coalesced
546 // touch-move event (which contains both touch points). Although the second
547 // touch-point does not need to be sent to the renderer, the first touch-point
548 // did move, and so the coalesced touch-event will be sent to the renderer.
549 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
550 EXPECT_EQ(1U, GetAndResetSentEventCount());
551 EXPECT_EQ(1U, queued_event_count());
553 // ACK the coalesced move as NOT_CONSUMED.
554 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
555 EXPECT_EQ(0U, GetAndResetSentEventCount());
556 EXPECT_EQ(0U, queued_event_count());
558 // Move just the second touch point. Because the first touch point did not
559 // move, this event should not reach the renderer.
560 MoveTouchPoint(1, 30, 30);
561 EXPECT_EQ(0U, GetAndResetSentEventCount());
562 EXPECT_EQ(0U, queued_event_count());
564 // Move just the first touch point. This should reach the renderer.
565 MoveTouchPoint(0, 10, 10);
566 EXPECT_EQ(1U, GetAndResetSentEventCount());
567 EXPECT_EQ(1U, queued_event_count());
569 // Move both fingers. This event should reach the renderer (after the ACK of
570 // the previous move event is received), because the first touch point did
571 // move.
572 MoveTouchPoints(0, 15, 15, 1, 25, 25);
573 EXPECT_EQ(0U, GetAndResetSentEventCount());
575 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
576 EXPECT_EQ(1U, GetAndResetSentEventCount());
577 EXPECT_EQ(1U, queued_event_count());
579 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
580 EXPECT_EQ(0U, GetAndResetSentEventCount());
581 EXPECT_EQ(0U, queued_event_count());
583 // Release the first finger. Then move the second finger around some, then
584 // press another finger. Once the release event is ACKed, the move events of
585 // the second finger should be immediately released to the view, and the
586 // touch-press event should be dispatched to the renderer.
587 ReleaseTouchPoint(0);
588 EXPECT_EQ(1U, GetAndResetSentEventCount());
589 EXPECT_EQ(1U, queued_event_count());
591 MoveTouchPoint(1, 40, 40);
593 MoveTouchPoint(1, 50, 50);
595 PressTouchPoint(1, 1);
597 MoveTouchPoint(1, 30, 30);
598 EXPECT_EQ(0U, GetAndResetSentEventCount());
599 EXPECT_EQ(4U, queued_event_count());
601 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
602 EXPECT_EQ(1U, GetAndResetSentEventCount());
603 EXPECT_EQ(2U, queued_event_count());
604 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
606 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued
607 // touch-move events to the view.
608 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
609 EXPECT_EQ(0U, GetAndResetSentEventCount());
610 EXPECT_EQ(0U, queued_event_count());
611 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
613 ReleaseTouchPoint(2);
614 ReleaseTouchPoint(1);
615 EXPECT_EQ(0U, GetAndResetSentEventCount());
616 EXPECT_EQ(0U, queued_event_count());
619 // Tests that touch-event's enqueued via a touch ack are properly handled.
620 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) {
621 // Queue a touch down.
622 PressTouchPoint(1, 1);
623 EXPECT_EQ(1U, queued_event_count());
624 EXPECT_EQ(1U, GetAndResetSentEventCount());
625 EXPECT_EQ(0U, GetAndResetAckedEventCount());
627 // Create a touch event that will be queued synchronously by a touch ack.
628 // Note, this will be triggered by all subsequent touch acks.
629 WebTouchEvent followup_event;
630 followup_event.type = WebInputEvent::TouchStart;
631 followup_event.touchesLength = 1;
632 followup_event.touches[0].id = 1;
633 followup_event.touches[0].state = WebTouchPoint::StatePressed;
634 SetFollowupEvent(followup_event);
636 // Receive an ACK for the press. This should cause the followup touch-move to
637 // be sent to the renderer.
638 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
639 EXPECT_EQ(1U, queued_event_count());
640 EXPECT_EQ(1U, GetAndResetSentEventCount());
641 EXPECT_EQ(1U, GetAndResetAckedEventCount());
642 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state());
643 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
645 // Queue another event.
646 MoveTouchPoint(0, 2, 2);
647 EXPECT_EQ(2U, queued_event_count());
649 // Receive an ACK for the touch-move followup event. This should cause the
650 // subsequent touch move event be sent to the renderer.
651 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
652 EXPECT_EQ(1U, queued_event_count());
653 EXPECT_EQ(1U, GetAndResetSentEventCount());
654 EXPECT_EQ(1U, GetAndResetAckedEventCount());
657 // Tests that touch-events can be synchronously ack'ed.
658 TEST_F(TouchEventQueueTest, SynchronousAcks) {
659 // TouchStart
660 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
661 PressTouchPoint(1, 1);
662 EXPECT_EQ(0U, queued_event_count());
663 EXPECT_EQ(1U, GetAndResetSentEventCount());
664 EXPECT_EQ(1U, GetAndResetAckedEventCount());
666 // TouchMove
667 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
668 MoveTouchPoint(0, 2, 2);
669 EXPECT_EQ(0U, queued_event_count());
670 EXPECT_EQ(1U, GetAndResetSentEventCount());
671 EXPECT_EQ(1U, GetAndResetAckedEventCount());
673 // TouchEnd
674 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
675 ReleaseTouchPoint(0);
676 EXPECT_EQ(0U, queued_event_count());
677 EXPECT_EQ(1U, GetAndResetSentEventCount());
678 EXPECT_EQ(1U, GetAndResetAckedEventCount());
680 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent)
681 PressTouchPoint(1, 1);
682 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
683 EXPECT_EQ(0U, queued_event_count());
684 EXPECT_EQ(1U, GetAndResetSentEventCount());
685 EXPECT_EQ(1U, GetAndResetAckedEventCount());
687 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
688 CancelTouchPoint(0);
689 EXPECT_EQ(0U, queued_event_count());
690 EXPECT_EQ(1U, GetAndResetSentEventCount());
691 EXPECT_EQ(1U, GetAndResetAckedEventCount());
694 // Tests that followup events triggered by an immediate ack from
695 // TouchEventQueue::QueueEvent() are properly handled.
696 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) {
697 // Create a touch event that will be queued synchronously by a touch ack.
698 WebTouchEvent followup_event;
699 followup_event.type = WebInputEvent::TouchStart;
700 followup_event.touchesLength = 1;
701 followup_event.touches[0].id = 1;
702 followup_event.touches[0].state = WebTouchPoint::StatePressed;
703 SetFollowupEvent(followup_event);
705 // Now, enqueue a stationary touch that will not be forwarded. This should be
706 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should
707 // then be enqueued and immediately sent to the renderer.
708 WebTouchEvent stationary_event;
709 stationary_event.touchesLength = 1;
710 stationary_event.type = WebInputEvent::TouchMove;
711 stationary_event.touches[0].id = 1;
712 stationary_event.touches[0].state = WebTouchPoint::StateStationary;
713 SendTouchEvent(stationary_event);
715 EXPECT_EQ(1U, queued_event_count());
716 EXPECT_EQ(1U, GetAndResetSentEventCount());
717 EXPECT_EQ(1U, GetAndResetAckedEventCount());
718 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
719 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type);
722 // Tests basic TouchEvent forwarding suppression.
723 TEST_F(TouchEventQueueTest, NoTouchBasic) {
724 // Disable TouchEvent forwarding.
725 OnHasTouchEventHandlers(false);
726 MoveTouchPoint(0, 30, 5);
727 EXPECT_EQ(0U, GetAndResetSentEventCount());
728 EXPECT_EQ(1U, GetAndResetAckedEventCount());
730 // TouchMove should not be sent to renderer.
731 MoveTouchPoint(0, 65, 10);
732 EXPECT_EQ(0U, GetAndResetSentEventCount());
733 EXPECT_EQ(1U, GetAndResetAckedEventCount());
735 // TouchEnd should not be sent to renderer.
736 ReleaseTouchPoint(0);
737 EXPECT_EQ(0U, GetAndResetSentEventCount());
738 EXPECT_EQ(1U, GetAndResetAckedEventCount());
740 // TouchStart should not be sent to renderer.
741 PressTouchPoint(5, 5);
742 EXPECT_EQ(0U, GetAndResetSentEventCount());
743 EXPECT_EQ(1U, GetAndResetAckedEventCount());
745 // Enable TouchEvent forwarding.
746 OnHasTouchEventHandlers(true);
748 PressTouchPoint(80, 10);
749 EXPECT_EQ(1U, GetAndResetSentEventCount());
750 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
751 EXPECT_EQ(1U, GetAndResetAckedEventCount());
753 MoveTouchPoint(0, 80, 20);
754 EXPECT_EQ(1U, GetAndResetSentEventCount());
755 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
756 EXPECT_EQ(1U, GetAndResetAckedEventCount());
758 ReleaseTouchPoint(0);
759 EXPECT_EQ(1U, GetAndResetSentEventCount());
760 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
761 EXPECT_EQ(1U, GetAndResetAckedEventCount());
764 // Tests that no TouchEvents are sent to renderer during scrolling.
765 TEST_F(TouchEventQueueTest, NoTouchOnScroll) {
766 // Queue a TouchStart.
767 PressTouchPoint(0, 1);
768 EXPECT_EQ(1U, GetAndResetSentEventCount());
769 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
770 EXPECT_EQ(1U, GetAndResetAckedEventCount());
772 MoveTouchPoint(0, 20, 5);
773 EXPECT_EQ(1U, queued_event_count());
774 EXPECT_EQ(1U, GetAndResetSentEventCount());
776 // Queue another TouchStart.
777 PressTouchPoint(20, 20);
778 EXPECT_EQ(2U, queued_event_count());
779 EXPECT_EQ(0U, GetAndResetSentEventCount());
780 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
782 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart.
783 WebGestureEvent followup_scroll;
784 followup_scroll.type = WebInputEvent::GestureScrollBegin;
785 SetFollowupEvent(followup_scroll);
786 ASSERT_TRUE(WillForwardTouchEvents());
787 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
788 EXPECT_FALSE(WillForwardTouchEvents());
789 EXPECT_EQ(1U, GetAndResetSentEventCount());
790 EXPECT_EQ(1U, GetAndResetAckedEventCount());
791 EXPECT_EQ(2U, queued_event_count());
792 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type);
793 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type);
795 // Acking the TouchCancel will result in dispatch of the next TouchStart.
796 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
797 // The synthetic TouchCancel should not reach client, only the TouchStart.
798 EXPECT_EQ(1U, GetAndResetAckedEventCount());
799 EXPECT_EQ(0U, GetAndResetSentEventCount());
800 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type);
802 // TouchMove should not be sent to the renderer.
803 MoveTouchPoint(0, 30, 5);
804 EXPECT_EQ(1U, GetAndResetAckedEventCount());
805 EXPECT_EQ(0U, GetAndResetSentEventCount());
806 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
808 // GestureScrollUpdates should not change affect touch forwarding.
809 SendGestureEvent(WebInputEvent::GestureScrollUpdate);
810 EXPECT_FALSE(WillForwardTouchEvents());
812 // TouchEnd should not be sent to the renderer.
813 ReleaseTouchPoint(0);
814 EXPECT_EQ(1U, GetAndResetAckedEventCount());
815 EXPECT_EQ(0U, GetAndResetSentEventCount());
816 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state());
818 // GestureScrollEnd will resume the sending of TouchEvents to renderer.
819 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
820 EXPECT_TRUE(WillForwardTouchEvents());
822 // Now TouchEvents should be forwarded normally.
823 PressTouchPoint(80, 10);
824 EXPECT_EQ(1U, GetAndResetSentEventCount());
825 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
826 EXPECT_EQ(1U, GetAndResetAckedEventCount());
828 MoveTouchPoint(0, 80, 20);
829 EXPECT_EQ(1U, GetAndResetSentEventCount());
830 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
831 EXPECT_EQ(1U, GetAndResetAckedEventCount());
833 ReleaseTouchPoint(0);
834 EXPECT_EQ(1U, GetAndResetSentEventCount());
835 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
836 EXPECT_EQ(1U, GetAndResetAckedEventCount());
839 // Tests that IsTouchStartPendingAck works correctly.
840 TEST_F(TouchEventQueueTest, PendingStart) {
842 EXPECT_FALSE(IsPendingAckTouchStart());
844 // Send the touchstart for one point (#1).
845 PressTouchPoint(1, 1);
846 EXPECT_EQ(1U, queued_event_count());
847 EXPECT_TRUE(IsPendingAckTouchStart());
849 // Send a touchmove for that point (#2).
850 MoveTouchPoint(0, 5, 5);
851 EXPECT_EQ(2U, queued_event_count());
852 EXPECT_TRUE(IsPendingAckTouchStart());
854 // Ack the touchstart (#1).
855 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
856 EXPECT_EQ(1U, queued_event_count());
857 EXPECT_FALSE(IsPendingAckTouchStart());
859 // Send a touchstart for another point (#3).
860 PressTouchPoint(10, 10);
861 EXPECT_EQ(2U, queued_event_count());
862 EXPECT_FALSE(IsPendingAckTouchStart());
864 // Ack the touchmove (#2).
865 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
866 EXPECT_EQ(1U, queued_event_count());
867 EXPECT_TRUE(IsPendingAckTouchStart());
869 // Send a touchstart for a third point (#4).
870 PressTouchPoint(15, 15);
871 EXPECT_EQ(2U, queued_event_count());
872 EXPECT_TRUE(IsPendingAckTouchStart());
874 // Ack the touchstart for the second point (#3).
875 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
876 EXPECT_EQ(1U, queued_event_count());
877 EXPECT_TRUE(IsPendingAckTouchStart());
879 // Ack the touchstart for the third point (#4).
880 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
881 EXPECT_EQ(0U, queued_event_count());
882 EXPECT_FALSE(IsPendingAckTouchStart());
885 // Tests that the touch timeout is started when sending certain touch types.
886 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
887 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
889 // Sending a TouchStart will start the timeout.
890 PressTouchPoint(0, 1);
891 EXPECT_TRUE(IsTimeoutRunning());
892 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
893 EXPECT_FALSE(IsTimeoutRunning());
895 // A TouchMove should start the timeout.
896 MoveTouchPoint(0, 5, 5);
897 EXPECT_TRUE(IsTimeoutRunning());
898 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
899 EXPECT_FALSE(IsTimeoutRunning());
901 // A TouchEnd should not start the timeout.
902 ReleaseTouchPoint(0);
903 EXPECT_FALSE(IsTimeoutRunning());
904 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
905 EXPECT_FALSE(IsTimeoutRunning());
907 // A TouchCancel should not start the timeout.
908 PressTouchPoint(0, 1);
909 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
910 ASSERT_FALSE(IsTimeoutRunning());
911 CancelTouchPoint(0);
912 EXPECT_FALSE(IsTimeoutRunning());
913 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
914 EXPECT_FALSE(IsTimeoutRunning());
917 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
918 // disabling touch forwarding until the next TouchStart is received after
919 // the timeout events are ack'ed.
920 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
921 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
923 // Queue a TouchStart.
924 GetAndResetSentEventCount();
925 GetAndResetAckedEventCount();
926 PressTouchPoint(0, 1);
927 ASSERT_EQ(1U, GetAndResetSentEventCount());
928 ASSERT_EQ(0U, GetAndResetAckedEventCount());
929 EXPECT_TRUE(IsTimeoutRunning());
930 EXPECT_TRUE(WillForwardTouchEvents());
932 // Delay the ack.
933 base::MessageLoop::current()->PostDelayedTask(
934 FROM_HERE,
935 base::MessageLoop::QuitClosure(),
936 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
937 base::MessageLoop::current()->Run();
939 // The timeout should have fired, synthetically ack'ing the timed-out event.
940 // TouchEvent forwarding is disabled until the ack is received for the
941 // timed-out event and the future cancel event.
942 EXPECT_FALSE(IsTimeoutRunning());
943 EXPECT_FALSE(WillForwardTouchEvents());
944 EXPECT_EQ(0U, GetAndResetSentEventCount());
945 EXPECT_EQ(1U, GetAndResetAckedEventCount());
947 // Ack'ing the original event should trigger a cancel event.
948 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
949 EXPECT_FALSE(IsTimeoutRunning());
950 EXPECT_FALSE(WillForwardTouchEvents());
951 EXPECT_EQ(0U, GetAndResetAckedEventCount());
952 EXPECT_EQ(1U, GetAndResetSentEventCount());
954 // Touch events should not be forwarded until we receive the cancel acks.
955 PressTouchPoint(0, 1);
956 ASSERT_EQ(0U, GetAndResetSentEventCount());
957 ASSERT_EQ(1U, GetAndResetAckedEventCount());
959 // The synthetic TouchCancel ack should not reach the client, but should
960 // resume touch forwarding.
961 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
962 EXPECT_EQ(0U, GetAndResetSentEventCount());
963 EXPECT_EQ(0U, GetAndResetAckedEventCount());
964 EXPECT_TRUE(WillForwardTouchEvents());
966 // Subsequent events should be handled normally.
967 PressTouchPoint(0, 1);
968 EXPECT_EQ(1U, GetAndResetSentEventCount());
969 EXPECT_EQ(0U, GetAndResetAckedEventCount());
972 // Tests that the timeout is never started if the renderer consumes
973 // a TouchEvent from the current touch sequence.
974 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
975 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
977 // Queue a TouchStart.
978 PressTouchPoint(0, 1);
979 ASSERT_TRUE(IsTimeoutRunning());
981 // Mark the event as consumed. This should prevent the timeout from
982 // being activated on subsequent TouchEvents in this gesture.
983 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
984 EXPECT_FALSE(IsTimeoutRunning());
986 // A TouchMove should not start the timeout.
987 MoveTouchPoint(0, 5, 5);
988 EXPECT_FALSE(IsTimeoutRunning());
989 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
991 // A secondary TouchStart should not start the timeout.
992 PressTouchPoint(1, 0);
993 EXPECT_FALSE(IsTimeoutRunning());
994 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
996 // A TouchEnd should not start the timeout.
997 ReleaseTouchPoint(1);
998 EXPECT_FALSE(IsTimeoutRunning());
999 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1001 // A TouchCancel should not start the timeout.
1002 CancelTouchPoint(0);
1003 EXPECT_FALSE(IsTimeoutRunning());
1006 // Tests that the timeout is never started if the ack is synchronous.
1007 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1008 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
1010 // Queue a TouchStart.
1011 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1012 ASSERT_FALSE(IsTimeoutRunning());
1013 PressTouchPoint(0, 1);
1014 EXPECT_FALSE(IsTimeoutRunning());
1017 // Tests that the timeout is disabled if the touch handler disappears.
1018 TEST_F(TouchEventQueueTest, TouchTimeoutStoppedIfTouchHandlerRemoved) {
1019 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
1021 // Queue a TouchStart.
1022 PressTouchPoint(0, 1);
1023 ASSERT_TRUE(IsTimeoutRunning());
1025 // Unload the touch handler.
1026 OnHasTouchEventHandlers(false);
1027 EXPECT_FALSE(IsTimeoutRunning());
1030 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1031 // turns into a scroll gesture sequence.
1032 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1033 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
1035 // Queue a TouchStart.
1036 PressTouchPoint(0, 1);
1037 EXPECT_TRUE(IsTimeoutRunning());
1038 EXPECT_TRUE(WillForwardTouchEvents());
1039 EXPECT_EQ(1U, GetAndResetSentEventCount());
1041 // The cancelled sequence may turn into a scroll gesture.
1042 WebGestureEvent followup_scroll;
1043 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1044 SetFollowupEvent(followup_scroll);
1046 // Delay the ack.
1047 base::MessageLoop::current()->PostDelayedTask(
1048 FROM_HERE,
1049 base::MessageLoop::QuitClosure(),
1050 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1051 base::MessageLoop::current()->Run();
1053 // The timeout should have fired, disabling touch forwarding until both acks
1054 // are received, acking the timed out event.
1055 EXPECT_FALSE(IsTimeoutRunning());
1056 EXPECT_FALSE(WillForwardTouchEvents());
1057 EXPECT_EQ(0U, GetAndResetSentEventCount());
1058 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1060 // Ack the original event, triggering a TouchCancel.
1061 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
1062 EXPECT_FALSE(IsTimeoutRunning());
1063 EXPECT_FALSE(WillForwardTouchEvents());
1064 EXPECT_EQ(1U, GetAndResetSentEventCount());
1065 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1067 // Ack the cancel event. Normally, this would resume touch forwarding,
1068 // but we're still within a scroll gesture so it remains disabled.
1069 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
1070 EXPECT_FALSE(IsTimeoutRunning());
1071 EXPECT_FALSE(WillForwardTouchEvents());
1072 EXPECT_EQ(0U, GetAndResetSentEventCount());
1073 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1075 // Try to forward a touch event.
1076 GetAndResetSentEventCount();
1077 GetAndResetAckedEventCount();
1078 PressTouchPoint(0, 1);
1079 EXPECT_FALSE(IsTimeoutRunning());
1080 EXPECT_EQ(0U, GetAndResetSentEventCount());
1081 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1083 // Now end the scroll sequence, resuming touch handling.
1084 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1085 EXPECT_TRUE(WillForwardTouchEvents());
1086 PressTouchPoint(0, 1);
1087 EXPECT_TRUE(IsTimeoutRunning());
1088 EXPECT_EQ(1U, GetAndResetSentEventCount());
1089 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1092 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1093 // turns into a scroll gesture sequence, but the original event acks are
1094 // significantly delayed.
1095 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1096 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
1098 // Queue a TouchStart.
1099 PressTouchPoint(0, 1);
1100 EXPECT_TRUE(IsTimeoutRunning());
1101 EXPECT_TRUE(WillForwardTouchEvents());
1102 EXPECT_EQ(1U, GetAndResetSentEventCount());
1104 // The cancelled sequence may turn into a scroll gesture.
1105 WebGestureEvent followup_scroll;
1106 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1107 SetFollowupEvent(followup_scroll);
1109 // Delay the ack.
1110 base::MessageLoop::current()->PostDelayedTask(
1111 FROM_HERE,
1112 base::MessageLoop::QuitClosure(),
1113 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1114 base::MessageLoop::current()->Run();
1116 // The timeout should have fired, disabling touch forwarding until both acks
1117 // are received and acking the timed out event.
1118 EXPECT_FALSE(IsTimeoutRunning());
1119 EXPECT_FALSE(WillForwardTouchEvents());
1120 EXPECT_EQ(0U, GetAndResetSentEventCount());
1121 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1123 // Try to forward a touch event.
1124 GetAndResetSentEventCount();
1125 GetAndResetAckedEventCount();
1126 PressTouchPoint(0, 1);
1127 EXPECT_FALSE(IsTimeoutRunning());
1128 EXPECT_EQ(0U, GetAndResetSentEventCount());
1129 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1131 // Now end the scroll sequence. Events will not be forwarded until the two
1132 // outstanding touch acks are received.
1133 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd);
1134 PressTouchPoint(0, 1);
1135 EXPECT_FALSE(IsTimeoutRunning());
1136 EXPECT_EQ(0U, GetAndResetSentEventCount());
1137 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1139 // Ack the original event, triggering a cancel.
1140 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
1141 EXPECT_EQ(1U, GetAndResetSentEventCount());
1142 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1144 // Ack the cancel event, resuming touch forwarding.
1145 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED);
1146 EXPECT_EQ(0U, GetAndResetSentEventCount());
1147 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1149 PressTouchPoint(0, 1);
1150 EXPECT_TRUE(IsTimeoutRunning());
1151 EXPECT_EQ(1U, GetAndResetSentEventCount());
1154 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1155 // the timed-out event had no consumer.
1156 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1157 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs);
1159 // Queue a TouchStart.
1160 PressTouchPoint(0, 1);
1161 ASSERT_EQ(1U, GetAndResetSentEventCount());
1162 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1163 EXPECT_TRUE(IsTimeoutRunning());
1164 EXPECT_TRUE(WillForwardTouchEvents());
1166 // Delay the ack.
1167 base::MessageLoop::current()->PostDelayedTask(
1168 FROM_HERE,
1169 base::MessageLoop::QuitClosure(),
1170 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1171 base::MessageLoop::current()->Run();
1173 // The timeout should have fired, synthetically ack'ing the timed out event.
1174 // TouchEvent forwarding is disabled until the original ack is received.
1175 EXPECT_FALSE(IsTimeoutRunning());
1176 EXPECT_FALSE(WillForwardTouchEvents());
1177 EXPECT_EQ(0U, GetAndResetSentEventCount());
1178 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1180 // Touch events should not be forwarded until we receive the original ack.
1181 PressTouchPoint(0, 1);
1182 ASSERT_EQ(0U, GetAndResetSentEventCount());
1183 ASSERT_EQ(1U, GetAndResetAckedEventCount());
1185 // Ack'ing the original event should not trigger a cancel event, as the
1186 // TouchStart had no consumer. However, it should re-enable touch forwarding.
1187 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
1188 EXPECT_FALSE(IsTimeoutRunning());
1189 EXPECT_TRUE(WillForwardTouchEvents());
1190 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1191 EXPECT_EQ(0U, GetAndResetSentEventCount());
1193 // Subsequent events should be handled normally.
1194 PressTouchPoint(0, 1);
1195 EXPECT_EQ(1U, GetAndResetSentEventCount());
1196 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1198 } // namespace content