1 // Copyright 2014 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.
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h"
12 #include "content/browser/renderer_host/input/gesture_event_queue.h"
13 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h"
14 #include "content/common/input/input_event_ack_state.h"
15 #include "content/common/input/synthetic_web_input_event_builders.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 using base::TimeDelta
;
20 using blink::WebGestureDevice
;
21 using blink::WebGestureEvent
;
22 using blink::WebInputEvent
;
26 class GestureEventQueueTest
: public testing::Test
,
27 public GestureEventQueueClient
,
28 public TouchpadTapSuppressionControllerClient
{
30 GestureEventQueueTest()
31 : acked_gesture_event_count_(0),
32 sent_gesture_event_count_(0) {}
34 virtual ~GestureEventQueueTest() {}
37 virtual void SetUp() OVERRIDE
{
38 queue_
.reset(new GestureEventQueue(this, this, DefaultConfig()));
41 virtual void TearDown() OVERRIDE
{
42 // Process all pending tasks to avoid leaks.
47 // GestureEventQueueClient
48 virtual void SendGestureEventImmediately(
49 const GestureEventWithLatencyInfo
& event
) OVERRIDE
{
50 ++sent_gesture_event_count_
;
51 if (sync_ack_result_
) {
52 scoped_ptr
<InputEventAckState
> ack_result
= sync_ack_result_
.Pass();
53 SendInputEventACK(event
.event
.type
, *ack_result
);
57 virtual void OnGestureEventAck(
58 const GestureEventWithLatencyInfo
& event
,
59 InputEventAckState ack_result
) OVERRIDE
{
60 ++acked_gesture_event_count_
;
61 last_acked_event_
= event
.event
;
62 if (sync_followup_event_
)
63 SimulateGestureEvent(*sync_followup_event_
.Pass());
66 // TouchpadTapSuppressionControllerClient
67 virtual void SendMouseEventImmediately(
68 const MouseEventWithLatencyInfo
& event
) OVERRIDE
{
72 static GestureEventQueue::Config
DefaultConfig() {
73 return GestureEventQueue::Config();
76 void SetUpForDebounce(int interval_ms
) {
77 queue()->set_debounce_interval_time_ms_for_testing(interval_ms
);
80 // Returns the result of |GestureEventQueue::ShouldForward()|.
81 bool SimulateGestureEvent(const WebGestureEvent
& gesture
) {
82 GestureEventWithLatencyInfo
gesture_with_latency(gesture
,
84 if (queue()->ShouldForward(gesture_with_latency
)) {
85 SendGestureEventImmediately(gesture_with_latency
);
91 void SimulateGestureEvent(WebInputEvent::Type type
,
92 WebGestureDevice sourceDevice
) {
94 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
));
97 void SimulateGestureScrollUpdateEvent(float dX
, float dY
, int modifiers
) {
99 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dX
, dY
, modifiers
));
102 void SimulateGesturePinchUpdateEvent(float scale
,
106 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
111 blink::WebGestureDeviceTouchscreen
));
114 void SimulateGestureFlingStartEvent(float velocityX
,
116 WebGestureDevice sourceDevice
) {
117 SimulateGestureEvent(
118 SyntheticWebGestureEventBuilder::BuildFling(velocityX
,
123 void SendInputEventACK(WebInputEvent::Type type
,
124 InputEventAckState ack
) {
125 queue()->ProcessGestureAck(ack
, type
, ui::LatencyInfo());
128 void RunUntilIdle() {
129 base::MessageLoop::current()->RunUntilIdle();
132 size_t GetAndResetSentGestureEventCount() {
133 size_t count
= sent_gesture_event_count_
;
134 sent_gesture_event_count_
= 0;
138 size_t GetAndResetAckedGestureEventCount() {
139 size_t count
= acked_gesture_event_count_
;
140 acked_gesture_event_count_
= 0;
144 const WebGestureEvent
& last_acked_event() const {
145 return last_acked_event_
;
148 void set_synchronous_ack(InputEventAckState ack_result
) {
149 sync_ack_result_
.reset(new InputEventAckState(ack_result
));
152 void set_sync_followup_event(WebInputEvent::Type type
,
153 WebGestureDevice sourceDevice
) {
154 sync_followup_event_
.reset(new WebGestureEvent(
155 SyntheticWebGestureEventBuilder::Build(type
, sourceDevice
)));
158 unsigned GestureEventQueueSize() {
159 return queue()->coalesced_gesture_events_
.size();
162 WebGestureEvent
GestureEventSecondFromLastQueueEvent() {
163 return queue()->coalesced_gesture_events_
.at(
164 GestureEventQueueSize() - 2).event
;
167 WebGestureEvent
GestureEventLastQueueEvent() {
168 return queue()->coalesced_gesture_events_
.back().event
;
171 unsigned GestureEventDebouncingQueueSize() {
172 return queue()->debouncing_deferral_queue_
.size();
175 WebGestureEvent
GestureEventQueueEventAt(int i
) {
176 return queue()->coalesced_gesture_events_
.at(i
).event
;
179 bool ScrollingInProgress() {
180 return queue()->scrolling_in_progress_
;
183 bool FlingInProgress() {
184 return queue()->fling_in_progress_
;
187 bool WillIgnoreNextACK() {
188 return queue()->ignore_next_ack_
;
191 GestureEventQueue
* queue() const {
196 scoped_ptr
<GestureEventQueue
> queue_
;
197 size_t acked_gesture_event_count_
;
198 size_t sent_gesture_event_count_
;
199 WebGestureEvent last_acked_event_
;
200 scoped_ptr
<InputEventAckState
> sync_ack_result_
;
201 scoped_ptr
<WebGestureEvent
> sync_followup_event_
;
202 base::MessageLoopForUI message_loop_
;
205 #if GTEST_HAS_PARAM_TEST
206 // This is for tests that are to be run for all source devices.
207 class GestureEventQueueWithSourceTest
208 : public GestureEventQueueTest
,
209 public testing::WithParamInterface
<WebGestureDevice
> {};
210 #endif // GTEST_HAS_PARAM_TEST
212 TEST_F(GestureEventQueueTest
, CoalescesScrollGestureEvents
) {
213 // Test coalescing of only GestureScrollUpdate events.
214 // Simulate gesture events.
217 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
218 blink::WebGestureDeviceTouchscreen
);
219 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
222 SimulateGestureScrollUpdateEvent(8, -5, 0);
224 // Make sure that the queue contains what we think it should.
225 WebGestureEvent merged_event
= GestureEventLastQueueEvent();
226 EXPECT_EQ(2U, GestureEventQueueSize());
227 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
228 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
231 SimulateGestureScrollUpdateEvent(8, -6, 0);
233 // Check that coalescing updated the correct values.
234 merged_event
= GestureEventLastQueueEvent();
235 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
236 EXPECT_EQ(0, merged_event
.modifiers
);
237 EXPECT_EQ(16, merged_event
.data
.scrollUpdate
.deltaX
);
238 EXPECT_EQ(-11, merged_event
.data
.scrollUpdate
.deltaY
);
239 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
242 SimulateGestureScrollUpdateEvent(8, -7, 1);
244 // Check that we didn't wrongly coalesce.
245 merged_event
= GestureEventLastQueueEvent();
246 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
247 EXPECT_EQ(1, merged_event
.modifiers
);
248 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
251 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
252 blink::WebGestureDeviceTouchscreen
);
254 // Check that only the first event was sent.
255 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
257 // Check that the ACK sends the second message.
258 SendInputEventACK(WebInputEvent::GestureScrollBegin
,
259 INPUT_EVENT_ACK_STATE_CONSUMED
);
261 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
262 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
264 // Ack for queued coalesced event.
265 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
266 INPUT_EVENT_ACK_STATE_CONSUMED
);
268 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
269 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
271 // Ack for queued uncoalesced event.
272 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
273 INPUT_EVENT_ACK_STATE_CONSUMED
);
275 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
276 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
278 // After the final ack, the queue should be empty.
279 SendInputEventACK(WebInputEvent::GestureScrollEnd
,
280 INPUT_EVENT_ACK_STATE_CONSUMED
);
282 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
283 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
286 TEST_F(GestureEventQueueTest
,
287 DoesNotCoalesceScrollGestureEventsFromDifferentDevices
) {
288 // Test that GestureScrollUpdate events from Touchscreen and Touchpad do not
292 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
293 blink::WebGestureDeviceTouchscreen
);
294 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
297 SimulateGestureScrollUpdateEvent(8, -5, 0);
299 // Make sure that the queue contains what we think it should.
300 EXPECT_EQ(2U, GestureEventQueueSize());
301 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
,
302 GestureEventLastQueueEvent().sourceDevice
);
305 SimulateGestureScrollUpdateEvent(8, -6, 0);
306 EXPECT_EQ(2U, GestureEventQueueSize());
307 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
,
308 GestureEventLastQueueEvent().sourceDevice
);
311 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
312 blink::WebGestureDeviceTouchpad
);
313 EXPECT_EQ(3U, GestureEventQueueSize());
314 EXPECT_EQ(blink::WebGestureDeviceTouchpad
,
315 GestureEventLastQueueEvent().sourceDevice
);
318 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
319 blink::WebGestureDeviceTouchpad
);
320 EXPECT_EQ(3U, GestureEventQueueSize());
321 EXPECT_EQ(blink::WebGestureDeviceTouchpad
,
322 GestureEventLastQueueEvent().sourceDevice
);
325 SimulateGestureScrollUpdateEvent(8, -7, 0);
326 EXPECT_EQ(4U, GestureEventQueueSize());
327 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
,
328 GestureEventLastQueueEvent().sourceDevice
);
331 TEST_F(GestureEventQueueTest
, CoalescesScrollAndPinchEvents
) {
332 // Test coalescing of only GestureScrollUpdate events.
333 // Simulate gesture events.
336 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
337 blink::WebGestureDeviceTouchscreen
);
340 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
341 blink::WebGestureDeviceTouchscreen
);
344 SimulateGestureScrollUpdateEvent(8, -4, 1);
346 // Make sure that the queue contains what we think it should.
347 WebGestureEvent merged_event
= GestureEventLastQueueEvent();
348 EXPECT_EQ(3U, GestureEventQueueSize());
349 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
351 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
352 // from a point that is not the origin should still give us the right scroll.
353 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
354 EXPECT_EQ(4U, GestureEventQueueSize());
355 merged_event
= GestureEventLastQueueEvent();
356 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
357 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
358 EXPECT_EQ(1, merged_event
.modifiers
);
359 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
360 merged_event
= GestureEventSecondFromLastQueueEvent();
361 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
362 EXPECT_EQ(8, merged_event
.data
.scrollUpdate
.deltaX
);
363 EXPECT_EQ(-4, merged_event
.data
.scrollUpdate
.deltaY
);
364 EXPECT_EQ(1, merged_event
.modifiers
);
365 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
368 SimulateGestureScrollUpdateEvent(6, -3, 1);
370 // Check whether coalesced correctly.
371 EXPECT_EQ(4U, GestureEventQueueSize());
372 merged_event
= GestureEventLastQueueEvent();
373 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
374 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
375 EXPECT_EQ(1, merged_event
.modifiers
);
376 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
377 merged_event
= GestureEventSecondFromLastQueueEvent();
378 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
379 EXPECT_EQ(12, merged_event
.data
.scrollUpdate
.deltaX
);
380 EXPECT_EQ(-6, merged_event
.data
.scrollUpdate
.deltaY
);
381 EXPECT_EQ(1, merged_event
.modifiers
);
382 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
385 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
387 // Check whether coalesced correctly.
388 EXPECT_EQ(4U, GestureEventQueueSize());
389 merged_event
= GestureEventLastQueueEvent();
390 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
391 EXPECT_EQ(3, merged_event
.data
.pinchUpdate
.scale
);
392 EXPECT_EQ(1, merged_event
.modifiers
);
393 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
394 merged_event
= GestureEventSecondFromLastQueueEvent();
395 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
396 EXPECT_EQ(12, merged_event
.data
.scrollUpdate
.deltaX
);
397 EXPECT_EQ(-6, merged_event
.data
.scrollUpdate
.deltaY
);
398 EXPECT_EQ(1, merged_event
.modifiers
);
399 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
402 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
404 // Check whether coalesced correctly.
405 EXPECT_EQ(4U, GestureEventQueueSize());
406 merged_event
= GestureEventLastQueueEvent();
407 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
408 EXPECT_EQ(6, merged_event
.data
.pinchUpdate
.scale
);
409 EXPECT_EQ(1, merged_event
.modifiers
);
410 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
411 merged_event
= GestureEventSecondFromLastQueueEvent();
412 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
413 EXPECT_EQ(12, merged_event
.data
.scrollUpdate
.deltaX
);
414 EXPECT_EQ(-6, merged_event
.data
.scrollUpdate
.deltaY
);
415 EXPECT_EQ(1, merged_event
.modifiers
);
416 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
418 // Check that only the first event was sent.
419 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
421 // Check that the ACK sends the second message.
422 SendInputEventACK(WebInputEvent::GestureScrollBegin
,
423 INPUT_EVENT_ACK_STATE_CONSUMED
);
425 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
428 SimulateGestureScrollUpdateEvent(6, -6, 1);
430 // Check whether coalesced correctly.
431 EXPECT_EQ(3U, GestureEventQueueSize());
432 merged_event
= GestureEventLastQueueEvent();
433 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
434 EXPECT_EQ(6, merged_event
.data
.pinchUpdate
.scale
);
435 EXPECT_EQ(1, merged_event
.modifiers
);
436 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
437 merged_event
= GestureEventSecondFromLastQueueEvent();
438 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
439 EXPECT_EQ(13, merged_event
.data
.scrollUpdate
.deltaX
);
440 EXPECT_EQ(-7, merged_event
.data
.scrollUpdate
.deltaY
);
441 EXPECT_EQ(1, merged_event
.modifiers
);
442 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
444 // At this point ACKs shouldn't be getting ignored.
445 EXPECT_FALSE(WillIgnoreNextACK());
447 // Check that the ACK sends both scroll and pinch updates.
448 SendInputEventACK(WebInputEvent::GesturePinchBegin
,
449 INPUT_EVENT_ACK_STATE_CONSUMED
);
451 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
453 // The next ACK should be getting ignored.
454 EXPECT_TRUE(WillIgnoreNextACK());
457 SimulateGestureScrollUpdateEvent(1, -1, 1);
459 // Check whether coalesced correctly.
460 EXPECT_EQ(3U, GestureEventQueueSize());
461 merged_event
= GestureEventLastQueueEvent();
462 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
463 EXPECT_EQ(1, merged_event
.data
.scrollUpdate
.deltaX
);
464 EXPECT_EQ(-1, merged_event
.data
.scrollUpdate
.deltaY
);
465 EXPECT_EQ(1, merged_event
.modifiers
);
466 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
467 merged_event
= GestureEventSecondFromLastQueueEvent();
468 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
469 EXPECT_EQ(6, merged_event
.data
.pinchUpdate
.scale
);
470 EXPECT_EQ(1, merged_event
.modifiers
);
471 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
474 SimulateGestureScrollUpdateEvent(2, -2, 1);
476 // Coalescing scrolls should still work.
477 EXPECT_EQ(3U, GestureEventQueueSize());
478 merged_event
= GestureEventLastQueueEvent();
479 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
480 EXPECT_EQ(3, merged_event
.data
.scrollUpdate
.deltaX
);
481 EXPECT_EQ(-3, merged_event
.data
.scrollUpdate
.deltaY
);
482 EXPECT_EQ(1, merged_event
.modifiers
);
483 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
484 merged_event
= GestureEventSecondFromLastQueueEvent();
485 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
486 EXPECT_EQ(6, merged_event
.data
.pinchUpdate
.scale
);
487 EXPECT_EQ(1, merged_event
.modifiers
);
488 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
491 SimulateGesturePinchUpdateEvent(0.5, 60, 60, 1);
493 // Check whether coalesced correctly.
494 EXPECT_EQ(4U, GestureEventQueueSize());
495 merged_event
= GestureEventLastQueueEvent();
496 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
497 EXPECT_EQ(0.5, merged_event
.data
.pinchUpdate
.scale
);
498 EXPECT_EQ(1, merged_event
.modifiers
);
499 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
500 merged_event
= GestureEventSecondFromLastQueueEvent();
501 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
502 EXPECT_EQ(3, merged_event
.data
.scrollUpdate
.deltaX
);
503 EXPECT_EQ(-3, merged_event
.data
.scrollUpdate
.deltaY
);
504 EXPECT_EQ(1, merged_event
.modifiers
);
505 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
507 // Check that the ACK gets ignored.
508 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
509 INPUT_EVENT_ACK_STATE_CONSUMED
);
510 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
512 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
513 // The flag should have been flipped back to false.
514 EXPECT_FALSE(WillIgnoreNextACK());
517 SimulateGestureScrollUpdateEvent(2, -2, 2);
519 // Shouldn't coalesce with different modifiers.
520 EXPECT_EQ(4U, GestureEventQueueSize());
521 merged_event
= GestureEventLastQueueEvent();
522 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
523 EXPECT_EQ(2, merged_event
.data
.scrollUpdate
.deltaX
);
524 EXPECT_EQ(-2, merged_event
.data
.scrollUpdate
.deltaY
);
525 EXPECT_EQ(2, merged_event
.modifiers
);
526 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
527 merged_event
= GestureEventSecondFromLastQueueEvent();
528 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
529 EXPECT_EQ(0.5, merged_event
.data
.pinchUpdate
.scale
);
530 EXPECT_EQ(1, merged_event
.modifiers
);
531 EXPECT_EQ(blink::WebGestureDeviceTouchscreen
, merged_event
.sourceDevice
);
533 // Check that the ACK sends the next scroll pinch pair.
534 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
535 INPUT_EVENT_ACK_STATE_CONSUMED
);
536 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
538 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
540 // Check that the ACK sends the second message.
541 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
542 INPUT_EVENT_ACK_STATE_CONSUMED
);
543 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
545 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
547 // Check that the ACK sends the second event.
548 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
549 INPUT_EVENT_ACK_STATE_CONSUMED
);
550 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
552 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
554 // Check that the queue is empty after ACK and no events get sent.
555 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
556 INPUT_EVENT_ACK_STATE_CONSUMED
);
557 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
559 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
560 EXPECT_EQ(0U, GestureEventQueueSize());
563 TEST_F(GestureEventQueueTest
, CoalescesMultiplePinchEventSequences
) {
564 // Simulate a pinch sequence.
565 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
566 blink::WebGestureDeviceTouchscreen
);
567 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
568 blink::WebGestureDeviceTouchscreen
);
570 SimulateGestureScrollUpdateEvent(8, -4, 1);
571 // Make sure that the queue contains what we think it should.
572 WebGestureEvent merged_event
= GestureEventLastQueueEvent();
573 size_t expected_events_in_queue
= 3;
574 EXPECT_EQ(expected_events_in_queue
, GestureEventQueueSize());
575 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
577 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
578 // from a point that is not the origin should still give us the right scroll.
579 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
580 EXPECT_EQ(++expected_events_in_queue
, GestureEventQueueSize());
581 merged_event
= GestureEventLastQueueEvent();
582 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
583 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
584 EXPECT_EQ(1, merged_event
.modifiers
);
585 merged_event
= GestureEventSecondFromLastQueueEvent();
586 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
587 EXPECT_EQ(8, merged_event
.data
.scrollUpdate
.deltaX
);
588 EXPECT_EQ(-4, merged_event
.data
.scrollUpdate
.deltaY
);
589 EXPECT_EQ(1, merged_event
.modifiers
);
592 SimulateGestureScrollUpdateEvent(6, -3, 1);
594 // Check whether coalesced correctly.
595 EXPECT_EQ(expected_events_in_queue
, GestureEventQueueSize());
596 merged_event
= GestureEventLastQueueEvent();
597 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
598 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
599 EXPECT_EQ(1, merged_event
.modifiers
);
600 merged_event
= GestureEventSecondFromLastQueueEvent();
601 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
602 EXPECT_EQ(12, merged_event
.data
.scrollUpdate
.deltaX
);
603 EXPECT_EQ(-6, merged_event
.data
.scrollUpdate
.deltaY
);
604 EXPECT_EQ(1, merged_event
.modifiers
);
606 // Now start another sequence before the previous sequence has been ack'ed.
607 SimulateGestureEvent(WebInputEvent::GesturePinchEnd
,
608 blink::WebGestureDeviceTouchscreen
);
609 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
610 blink::WebGestureDeviceTouchscreen
);
611 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
612 blink::WebGestureDeviceTouchscreen
);
613 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
614 blink::WebGestureDeviceTouchscreen
);
616 SimulateGestureScrollUpdateEvent(8, -4, 1);
617 // Make sure that the queue contains what we think it should.
618 expected_events_in_queue
+= 5;
619 merged_event
= GestureEventLastQueueEvent();
620 EXPECT_EQ(expected_events_in_queue
, GestureEventQueueSize());
621 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
623 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
624 // from a point that is not the origin should still give us the right scroll.
625 SimulateGesturePinchUpdateEvent(1.5, 30, 30, 1);
626 EXPECT_EQ(++expected_events_in_queue
, GestureEventQueueSize());
627 merged_event
= GestureEventLastQueueEvent();
628 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
629 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
630 EXPECT_EQ(1, merged_event
.modifiers
);
631 merged_event
= GestureEventSecondFromLastQueueEvent();
632 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
633 EXPECT_EQ(8, merged_event
.data
.scrollUpdate
.deltaX
);
634 EXPECT_EQ(-4, merged_event
.data
.scrollUpdate
.deltaY
);
635 EXPECT_EQ(1, merged_event
.modifiers
);
638 SimulateGestureScrollUpdateEvent(6, -3, 1);
640 // Check whether coalesced correctly.
641 EXPECT_EQ(expected_events_in_queue
, GestureEventQueueSize());
642 merged_event
= GestureEventLastQueueEvent();
643 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, merged_event
.type
);
644 EXPECT_EQ(1.5, merged_event
.data
.pinchUpdate
.scale
);
645 EXPECT_EQ(1, merged_event
.modifiers
);
646 merged_event
= GestureEventSecondFromLastQueueEvent();
647 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
648 EXPECT_EQ(12, merged_event
.data
.scrollUpdate
.deltaX
);
649 EXPECT_EQ(-6, merged_event
.data
.scrollUpdate
.deltaY
);
650 EXPECT_EQ(1, merged_event
.modifiers
);
653 TEST_F(GestureEventQueueTest
, CoalescesPinchSequencesWithEarlyAck
) {
654 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
655 blink::WebGestureDeviceTouchscreen
);
656 SendInputEventACK(WebInputEvent::GestureScrollBegin
,
657 INPUT_EVENT_ACK_STATE_CONSUMED
);
659 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
660 blink::WebGestureDeviceTouchscreen
);
661 SendInputEventACK(WebInputEvent::GesturePinchBegin
,
662 INPUT_EVENT_ACK_STATE_CONSUMED
);
663 // ScrollBegin and PinchBegin have been sent
664 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
665 EXPECT_EQ(0U, GestureEventQueueSize());
667 SimulateGestureScrollUpdateEvent(5, 5, 1);
668 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
669 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
,
670 GestureEventLastQueueEvent().type
);
671 EXPECT_EQ(1U, GestureEventQueueSize());
674 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
675 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
676 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
,
677 GestureEventLastQueueEvent().type
);
678 EXPECT_EQ(2U, GestureEventQueueSize());
680 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
681 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
682 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
,
683 GestureEventLastQueueEvent().type
);
684 EXPECT_EQ(2U, GestureEventQueueSize());
686 SimulateGestureScrollUpdateEvent(5, 5, 1);
687 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
688 // The coalesced pinch/scroll pair will have been re-arranged, with the
689 // pinch following the scroll.
690 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
,
691 GestureEventLastQueueEvent().type
);
692 EXPECT_EQ(3U, GestureEventQueueSize());
694 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
695 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
696 EXPECT_EQ(3U, GestureEventQueueSize());
698 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
699 INPUT_EVENT_ACK_STATE_CONSUMED
);
700 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
701 EXPECT_EQ(2U, GestureEventQueueSize());
703 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
704 INPUT_EVENT_ACK_STATE_CONSUMED
);
705 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
707 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
708 INPUT_EVENT_ACK_STATE_CONSUMED
);
709 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
710 EXPECT_EQ(2.f
* 3.f
* 4.f
, last_acked_event().data
.pinchUpdate
.scale
);
712 EXPECT_EQ(0U, GestureEventQueueSize());
715 TEST_F(GestureEventQueueTest
,
716 DoesNotCoalescePinchGestureEventsWithDifferentModifiers
) {
717 // Insert an event to force queueing of gestures.
718 SimulateGestureEvent(WebInputEvent::GestureTapCancel
,
719 blink::WebGestureDeviceTouchscreen
);
720 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
721 EXPECT_EQ(1U, GestureEventQueueSize());
723 SimulateGestureScrollUpdateEvent(5, 5, 1);
724 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
725 EXPECT_EQ(2U, GestureEventQueueSize());
727 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
728 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
729 EXPECT_EQ(3U, GestureEventQueueSize());
731 SimulateGestureScrollUpdateEvent(10, 15, 1);
732 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
733 EXPECT_EQ(3U, GestureEventQueueSize());
735 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
736 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
737 EXPECT_EQ(3U, GestureEventQueueSize());
739 // Using different modifiers should prevent coalescing.
740 SimulateGesturePinchUpdateEvent(5, 60, 60, 2);
741 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
742 EXPECT_EQ(4U, GestureEventQueueSize());
744 SimulateGesturePinchUpdateEvent(6, 60, 60, 3);
745 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
746 EXPECT_EQ(5U, GestureEventQueueSize());
748 SendInputEventACK(WebInputEvent::GestureTapCancel
,
749 INPUT_EVENT_ACK_STATE_CONSUMED
);
750 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
751 EXPECT_EQ(4U, GestureEventQueueSize());
753 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
754 INPUT_EVENT_ACK_STATE_CONSUMED
);
755 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
756 EXPECT_EQ(3U, GestureEventQueueSize());
758 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
759 INPUT_EVENT_ACK_STATE_CONSUMED
);
760 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
761 EXPECT_EQ(3.f
* 4.f
, last_acked_event().data
.pinchUpdate
.scale
);
762 EXPECT_EQ(2U, GestureEventQueueSize());
763 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
765 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
766 INPUT_EVENT_ACK_STATE_CONSUMED
);
767 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
768 EXPECT_EQ(5.f
, last_acked_event().data
.pinchUpdate
.scale
);
769 EXPECT_EQ(1U, GestureEventQueueSize());
770 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
772 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
773 INPUT_EVENT_ACK_STATE_CONSUMED
);
774 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
775 EXPECT_EQ(6.f
, last_acked_event().data
.pinchUpdate
.scale
);
776 EXPECT_EQ(0U, GestureEventQueueSize());
779 TEST_F(GestureEventQueueTest
, CoalescesScrollAndPinchEventsIdentity
) {
780 // Insert an event to force queueing of gestures.
781 SimulateGestureEvent(WebInputEvent::GestureTapCancel
,
782 blink::WebGestureDeviceTouchscreen
);
783 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
784 EXPECT_EQ(1U, GestureEventQueueSize());
786 // Ensure that coalescing yields an identity transform for any pinch/scroll
787 // pair combined with its inverse.
788 SimulateGestureScrollUpdateEvent(5, 5, 1);
789 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
790 EXPECT_EQ(2U, GestureEventQueueSize());
792 SimulateGesturePinchUpdateEvent(5, 10, 10, 1);
793 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
794 EXPECT_EQ(3U, GestureEventQueueSize());
796 SimulateGesturePinchUpdateEvent(.2f
, 10, 10, 1);
797 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
798 EXPECT_EQ(3U, GestureEventQueueSize());
800 SimulateGestureScrollUpdateEvent(-5, -5, 1);
801 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
802 EXPECT_EQ(3U, GestureEventQueueSize());
804 SendInputEventACK(WebInputEvent::GestureTapCancel
,
805 INPUT_EVENT_ACK_STATE_CONSUMED
);
806 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
807 EXPECT_EQ(2U, GestureEventQueueSize());
809 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
810 INPUT_EVENT_ACK_STATE_CONSUMED
);
811 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
812 EXPECT_EQ(0.f
, last_acked_event().data
.scrollUpdate
.deltaX
);
813 EXPECT_EQ(0.f
, last_acked_event().data
.scrollUpdate
.deltaY
);
815 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
816 INPUT_EVENT_ACK_STATE_CONSUMED
);
817 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
818 EXPECT_EQ(1.f
, last_acked_event().data
.pinchUpdate
.scale
);
819 EXPECT_EQ(0U, GestureEventQueueSize());
821 // Insert an event to force queueing of gestures.
822 SimulateGestureEvent(WebInputEvent::GestureTapCancel
,
823 blink::WebGestureDeviceTouchscreen
);
824 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
825 EXPECT_EQ(1U, GestureEventQueueSize());
827 // Ensure that coalescing yields an identity transform for any pinch/scroll
828 // pair combined with its inverse.
829 SimulateGesturePinchUpdateEvent(2, 10, 10, 1);
830 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
831 EXPECT_EQ(2U, GestureEventQueueSize());
833 SimulateGestureScrollUpdateEvent(20, 20, 1);
834 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
835 EXPECT_EQ(3U, GestureEventQueueSize());
837 SimulateGesturePinchUpdateEvent(0.5f
, 20, 20, 1);
838 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
839 EXPECT_EQ(3U, GestureEventQueueSize());
841 SimulateGestureScrollUpdateEvent(-5, -5, 1);
842 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
843 EXPECT_EQ(3U, GestureEventQueueSize());
845 SendInputEventACK(WebInputEvent::GestureTapCancel
,
846 INPUT_EVENT_ACK_STATE_CONSUMED
);
847 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
848 EXPECT_EQ(2U, GestureEventQueueSize());
850 SendInputEventACK(WebInputEvent::GestureScrollUpdate
,
851 INPUT_EVENT_ACK_STATE_CONSUMED
);
852 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
853 EXPECT_EQ(0.f
, last_acked_event().data
.scrollUpdate
.deltaX
);
854 EXPECT_EQ(0.f
, last_acked_event().data
.scrollUpdate
.deltaY
);
856 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
857 INPUT_EVENT_ACK_STATE_CONSUMED
);
858 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
859 EXPECT_EQ(1.f
, last_acked_event().data
.pinchUpdate
.scale
);
862 // Tests a single event with an synchronous ack.
863 TEST_F(GestureEventQueueTest
, SimpleSyncAck
) {
864 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED
);
865 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
866 blink::WebGestureDeviceTouchscreen
);
867 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
868 EXPECT_EQ(0U, GestureEventQueueSize());
869 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
872 // Tests an event with an synchronous ack which enqueues an additional event.
873 TEST_F(GestureEventQueueTest
, SyncAckQueuesEvent
) {
874 scoped_ptr
<WebGestureEvent
> queued_event
;
875 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED
);
876 set_sync_followup_event(WebInputEvent::GestureShowPress
,
877 blink::WebGestureDeviceTouchscreen
);
878 // This event enqueues the show press event.
879 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
880 blink::WebGestureDeviceTouchscreen
);
881 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
882 EXPECT_EQ(1U, GestureEventQueueSize());
883 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
885 SendInputEventACK(WebInputEvent::GestureShowPress
,
886 INPUT_EVENT_ACK_STATE_CONSUMED
);
887 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
888 EXPECT_EQ(0U, GestureEventQueueSize());
889 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
892 // Tests an event with an async ack followed by an event with a sync ack.
893 TEST_F(GestureEventQueueTest
, AsyncThenSyncAck
) {
894 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
895 blink::WebGestureDeviceTouchscreen
);
897 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
898 EXPECT_EQ(1U, GestureEventQueueSize());
899 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
901 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
902 blink::WebGestureDeviceTouchscreen
);
903 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED
);
904 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
905 EXPECT_EQ(2U, GestureEventQueueSize());
906 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
908 SendInputEventACK(WebInputEvent::GestureTapDown
,
909 INPUT_EVENT_ACK_STATE_CONSUMED
);
910 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
911 EXPECT_EQ(0U, GestureEventQueueSize());
912 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
915 TEST_F(GestureEventQueueTest
, CoalescesScrollAndPinchEventWithSyncAck
) {
916 // Simulate a pinch sequence.
917 SimulateGestureEvent(WebInputEvent::GestureScrollBegin
,
918 blink::WebGestureDeviceTouchscreen
);
919 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
920 SimulateGestureEvent(WebInputEvent::GesturePinchBegin
,
921 blink::WebGestureDeviceTouchscreen
);
922 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
924 SimulateGestureScrollUpdateEvent(8, -4, 1);
925 // Make sure that the queue contains what we think it should.
926 WebGestureEvent merged_event
= GestureEventLastQueueEvent();
927 EXPECT_EQ(3U, GestureEventQueueSize());
928 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, merged_event
.type
);
930 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
931 // from a point that is not the origin should still give us the right scroll.
932 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
933 EXPECT_EQ(4U, GestureEventQueueSize());
935 SendInputEventACK(WebInputEvent::GestureScrollBegin
,
936 INPUT_EVENT_ACK_STATE_CONSUMED
);
937 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
938 EXPECT_EQ(3U, GestureEventQueueSize());
940 // Ack the PinchBegin, and schedule a synchronous ack for GestureScrollUpdate.
941 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED
);
942 SendInputEventACK(WebInputEvent::GesturePinchBegin
,
943 INPUT_EVENT_ACK_STATE_CONSUMED
);
945 // Both GestureScrollUpdate and GesturePinchUpdate should have been sent.
946 EXPECT_EQ(WebInputEvent::GestureScrollUpdate
, last_acked_event().type
);
947 EXPECT_EQ(1U, GestureEventQueueSize());
948 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
950 // Ack the final GesturePinchUpdate.
951 SendInputEventACK(WebInputEvent::GesturePinchUpdate
,
952 INPUT_EVENT_ACK_STATE_CONSUMED
);
953 EXPECT_EQ(WebInputEvent::GesturePinchUpdate
, last_acked_event().type
);
954 EXPECT_EQ(0U, GestureEventQueueSize());
955 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
958 #if GTEST_HAS_PARAM_TEST
959 TEST_P(GestureEventQueueWithSourceTest
, GestureFlingCancelsFiltered
) {
960 WebGestureDevice source_device
= GetParam();
962 // GFC without previous GFS is dropped.
963 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
964 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
965 EXPECT_EQ(0U, GestureEventQueueSize());
967 // GFC after previous GFS is dispatched and acked.
968 SimulateGestureFlingStartEvent(0, -10, source_device
);
969 EXPECT_TRUE(FlingInProgress());
970 SendInputEventACK(WebInputEvent::GestureFlingStart
,
971 INPUT_EVENT_ACK_STATE_CONSUMED
);
973 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
974 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
975 EXPECT_FALSE(FlingInProgress());
976 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
977 SendInputEventACK(WebInputEvent::GestureFlingCancel
,
978 INPUT_EVENT_ACK_STATE_CONSUMED
);
980 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
981 EXPECT_EQ(0U, GestureEventQueueSize());
983 // GFC before previous GFS is acked.
984 SimulateGestureFlingStartEvent(0, -10, source_device
);
985 EXPECT_TRUE(FlingInProgress());
986 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
987 EXPECT_FALSE(FlingInProgress());
988 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
989 EXPECT_EQ(2U, GestureEventQueueSize());
991 // Advance state realistically.
992 SendInputEventACK(WebInputEvent::GestureFlingStart
,
993 INPUT_EVENT_ACK_STATE_CONSUMED
);
995 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
996 SendInputEventACK(WebInputEvent::GestureFlingCancel
,
997 INPUT_EVENT_ACK_STATE_CONSUMED
);
999 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
1000 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1001 EXPECT_EQ(0U, GestureEventQueueSize());
1003 // GFS is added to the queue if another event is pending
1004 SimulateGestureScrollUpdateEvent(8, -7, 0);
1005 SimulateGestureFlingStartEvent(0, -10, source_device
);
1006 EXPECT_EQ(2U, GestureEventQueueSize());
1007 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1008 WebGestureEvent merged_event
= GestureEventLastQueueEvent();
1009 EXPECT_EQ(WebInputEvent::GestureFlingStart
, merged_event
.type
);
1010 EXPECT_TRUE(FlingInProgress());
1011 EXPECT_EQ(2U, GestureEventQueueSize());
1013 // GFS in queue means that a GFC is added to the queue
1014 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
1015 merged_event
=GestureEventLastQueueEvent();
1016 EXPECT_EQ(WebInputEvent::GestureFlingCancel
, merged_event
.type
);
1017 EXPECT_FALSE(FlingInProgress());
1018 EXPECT_EQ(3U, GestureEventQueueSize());
1020 // Adding a second GFC is dropped.
1021 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
1022 EXPECT_FALSE(FlingInProgress());
1023 EXPECT_EQ(3U, GestureEventQueueSize());
1025 // Adding another GFS will add it to the queue.
1026 SimulateGestureFlingStartEvent(0, -10, source_device
);
1027 merged_event
= GestureEventLastQueueEvent();
1028 EXPECT_EQ(WebInputEvent::GestureFlingStart
, merged_event
.type
);
1029 EXPECT_TRUE(FlingInProgress());
1030 EXPECT_EQ(4U, GestureEventQueueSize());
1032 // GFS in queue means that a GFC is added to the queue
1033 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
1034 merged_event
= GestureEventLastQueueEvent();
1035 EXPECT_EQ(WebInputEvent::GestureFlingCancel
, merged_event
.type
);
1036 EXPECT_FALSE(FlingInProgress());
1037 EXPECT_EQ(5U, GestureEventQueueSize());
1039 // Adding another GFC with a GFC already there is dropped.
1040 SimulateGestureEvent(WebInputEvent::GestureFlingCancel
, source_device
);
1041 merged_event
= GestureEventLastQueueEvent();
1042 EXPECT_EQ(WebInputEvent::GestureFlingCancel
, merged_event
.type
);
1043 EXPECT_FALSE(FlingInProgress());
1044 EXPECT_EQ(5U, GestureEventQueueSize());
1047 INSTANTIATE_TEST_CASE_P(AllSources
,
1048 GestureEventQueueWithSourceTest
,
1049 testing::Values(blink::WebGestureDeviceTouchscreen
,
1050 blink::WebGestureDeviceTouchpad
));
1051 #endif // GTEST_HAS_PARAM_TEST
1053 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the
1054 // debounce interval, that Scrolls are not and that the deferred events are
1055 // sent after that timer fires.
1056 TEST_F(GestureEventQueueTest
, DebounceDefersFollowingGestureEvents
) {
1057 SetUpForDebounce(3);
1059 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1060 blink::WebGestureDeviceTouchscreen
);
1061 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1062 EXPECT_EQ(1U, GestureEventQueueSize());
1063 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1064 EXPECT_TRUE(ScrollingInProgress());
1066 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1067 blink::WebGestureDeviceTouchscreen
);
1068 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1069 EXPECT_EQ(2U, GestureEventQueueSize());
1070 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1071 EXPECT_TRUE(ScrollingInProgress());
1073 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1074 blink::WebGestureDeviceTouchscreen
);
1075 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1076 EXPECT_EQ(2U, GestureEventQueueSize());
1077 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1079 SimulateGestureFlingStartEvent(0, 10, blink::WebGestureDeviceTouchscreen
);
1080 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1081 EXPECT_EQ(2U, GestureEventQueueSize());
1082 EXPECT_EQ(2U, GestureEventDebouncingQueueSize());
1084 SimulateGestureEvent(WebInputEvent::GestureTapDown
,
1085 blink::WebGestureDeviceTouchscreen
);
1086 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1087 EXPECT_EQ(2U, GestureEventQueueSize());
1088 EXPECT_EQ(3U, GestureEventDebouncingQueueSize());
1090 base::MessageLoop::current()->PostDelayedTask(
1092 base::MessageLoop::QuitClosure(),
1093 TimeDelta::FromMilliseconds(5));
1094 base::MessageLoop::current()->Run();
1096 // The deferred events are correctly queued in coalescing queue.
1097 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1098 EXPECT_EQ(5U, GestureEventQueueSize());
1099 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1100 EXPECT_FALSE(ScrollingInProgress());
1102 // Verify that the coalescing queue contains the correct events.
1103 WebInputEvent::Type expected
[] = {
1104 WebInputEvent::GestureScrollUpdate
,
1105 WebInputEvent::GestureScrollUpdate
,
1106 WebInputEvent::GestureScrollEnd
,
1107 WebInputEvent::GestureFlingStart
};
1109 for (unsigned i
= 0; i
< sizeof(expected
) / sizeof(WebInputEvent::Type
);
1111 WebGestureEvent merged_event
= GestureEventQueueEventAt(i
);
1112 EXPECT_EQ(expected
[i
], merged_event
.type
);
1116 // Test that non-scroll events are deferred while scrolling during the debounce
1117 // interval and are discarded if a GestureScrollUpdate event arrives before the
1119 TEST_F(GestureEventQueueTest
, DebounceDropsDeferredEvents
) {
1120 SetUpForDebounce(3);
1122 EXPECT_FALSE(ScrollingInProgress());
1124 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1125 blink::WebGestureDeviceTouchscreen
);
1126 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1127 EXPECT_EQ(1U, GestureEventQueueSize());
1128 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1129 EXPECT_TRUE(ScrollingInProgress());
1131 // This event should get discarded.
1132 SimulateGestureEvent(WebInputEvent::GestureScrollEnd
,
1133 blink::WebGestureDeviceTouchscreen
);
1134 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1135 EXPECT_EQ(1U, GestureEventQueueSize());
1136 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1138 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate
,
1139 blink::WebGestureDeviceTouchscreen
);
1140 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1141 EXPECT_EQ(2U, GestureEventQueueSize());
1142 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1143 EXPECT_TRUE(ScrollingInProgress());
1145 // Verify that the coalescing queue contains the correct events.
1146 WebInputEvent::Type expected
[] = {
1147 WebInputEvent::GestureScrollUpdate
,
1148 WebInputEvent::GestureScrollUpdate
};
1150 for (unsigned i
= 0; i
< sizeof(expected
) / sizeof(WebInputEvent::Type
);
1152 WebGestureEvent merged_event
= GestureEventQueueEventAt(i
);
1153 EXPECT_EQ(expected
[i
], merged_event
.type
);
1157 } // namespace content