Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / renderer_host / input / gesture_event_queue_unittest.cc
blob7879b3ed723e89f428edc226db4f68e9282a71f5
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.
5 #include <vector>
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;
24 namespace content {
26 class GestureEventQueueTest : public testing::Test,
27 public GestureEventQueueClient,
28 public TouchpadTapSuppressionControllerClient {
29 public:
30 GestureEventQueueTest()
31 : acked_gesture_event_count_(0),
32 sent_gesture_event_count_(0) {}
34 ~GestureEventQueueTest() override {}
36 // testing::Test
37 void SetUp() override {
38 queue_.reset(new GestureEventQueue(this, this, DefaultConfig()));
41 void TearDown() override {
42 // Process all pending tasks to avoid leaks.
43 RunUntilIdle();
44 queue_.reset();
47 // GestureEventQueueClient
48 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 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
58 InputEventAckState ack_result) override {
59 ++acked_gesture_event_count_;
60 last_acked_event_ = event.event;
61 if (sync_followup_event_) {
62 auto sync_followup_event = sync_followup_event_.Pass();
63 SimulateGestureEvent(*sync_followup_event);
67 // TouchpadTapSuppressionControllerClient
68 void SendMouseEventImmediately(
69 const MouseEventWithLatencyInfo& event) override {}
71 protected:
72 static GestureEventQueue::Config DefaultConfig() {
73 return GestureEventQueue::Config();
76 void SetUpForGFCFilteringDisabled() {
77 GestureEventQueue::Config config;
78 config.enable_fling_cancel_filtering = false;
79 queue_.reset(new GestureEventQueue(this, this, config));
82 void SetUpForDebounce(int interval_ms) {
83 queue()->set_debounce_interval_time_ms_for_testing(interval_ms);
86 void SimulateGestureEvent(const WebGestureEvent& gesture) {
87 queue()->QueueEvent(GestureEventWithLatencyInfo(gesture));
90 void SimulateGestureEvent(WebInputEvent::Type type,
91 WebGestureDevice sourceDevice) {
92 SimulateGestureEvent(
93 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
96 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
97 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
98 dX, dY, modifiers, blink::WebGestureDeviceTouchscreen));
101 void SimulateGesturePinchUpdateEvent(float scale,
102 float anchorX,
103 float anchorY,
104 int modifiers) {
105 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
106 scale,
107 anchorX,
108 anchorY,
109 modifiers,
110 blink::WebGestureDeviceTouchscreen));
113 void SimulateGestureFlingStartEvent(float velocityX,
114 float velocityY,
115 WebGestureDevice sourceDevice) {
116 SimulateGestureEvent(
117 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
118 velocityY,
119 sourceDevice));
122 void SendInputEventACK(WebInputEvent::Type type,
123 InputEventAckState ack) {
124 queue()->ProcessGestureAck(ack, type, ui::LatencyInfo());
127 void RunUntilIdle() {
128 base::MessageLoop::current()->RunUntilIdle();
131 size_t GetAndResetSentGestureEventCount() {
132 size_t count = sent_gesture_event_count_;
133 sent_gesture_event_count_ = 0;
134 return count;
137 size_t GetAndResetAckedGestureEventCount() {
138 size_t count = acked_gesture_event_count_;
139 acked_gesture_event_count_ = 0;
140 return count;
143 const WebGestureEvent& last_acked_event() const {
144 return last_acked_event_;
147 void set_synchronous_ack(InputEventAckState ack_result) {
148 sync_ack_result_.reset(new InputEventAckState(ack_result));
151 void set_sync_followup_event(WebInputEvent::Type type,
152 WebGestureDevice sourceDevice) {
153 sync_followup_event_.reset(new WebGestureEvent(
154 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)));
157 unsigned GestureEventQueueSize() {
158 return queue()->coalesced_gesture_events_.size();
161 WebGestureEvent GestureEventSecondFromLastQueueEvent() {
162 return queue()->coalesced_gesture_events_.at(
163 GestureEventQueueSize() - 2).event;
166 WebGestureEvent GestureEventLastQueueEvent() {
167 return queue()->coalesced_gesture_events_.back().event;
170 unsigned GestureEventDebouncingQueueSize() {
171 return queue()->debouncing_deferral_queue_.size();
174 WebGestureEvent GestureEventQueueEventAt(int i) {
175 return queue()->coalesced_gesture_events_.at(i).event;
178 bool ScrollingInProgress() {
179 return queue()->scrolling_in_progress_;
182 int ActiveFlingCount() { return queue()->active_fling_count_; }
184 bool WillIgnoreNextACK() {
185 return queue()->ignore_next_ack_;
188 GestureEventQueue* queue() const {
189 return queue_.get();
192 private:
193 scoped_ptr<GestureEventQueue> queue_;
194 size_t acked_gesture_event_count_;
195 size_t sent_gesture_event_count_;
196 WebGestureEvent last_acked_event_;
197 scoped_ptr<InputEventAckState> sync_ack_result_;
198 scoped_ptr<WebGestureEvent> sync_followup_event_;
199 base::MessageLoopForUI message_loop_;
202 #if GTEST_HAS_PARAM_TEST
203 // This is for tests that are to be run for all source devices.
204 class GestureEventQueueWithSourceTest
205 : public GestureEventQueueTest,
206 public testing::WithParamInterface<WebGestureDevice> {};
207 #endif // GTEST_HAS_PARAM_TEST
209 TEST_F(GestureEventQueueTest, CoalescesScrollGestureEvents) {
210 // Test coalescing of only GestureScrollUpdate events.
211 // Simulate gesture events.
213 // Sent.
214 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
215 blink::WebGestureDeviceTouchscreen);
216 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
218 // Enqueued.
219 SimulateGestureScrollUpdateEvent(8, -5, 0);
221 // Make sure that the queue contains what we think it should.
222 WebGestureEvent merged_event = GestureEventLastQueueEvent();
223 EXPECT_EQ(2U, GestureEventQueueSize());
224 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
225 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
227 // Coalesced.
228 SimulateGestureScrollUpdateEvent(8, -6, 0);
230 // Check that coalescing updated the correct values.
231 merged_event = GestureEventLastQueueEvent();
232 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
233 EXPECT_EQ(0, merged_event.modifiers);
234 EXPECT_EQ(16, merged_event.data.scrollUpdate.deltaX);
235 EXPECT_EQ(-11, merged_event.data.scrollUpdate.deltaY);
236 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
238 // Enqueued.
239 SimulateGestureScrollUpdateEvent(8, -7, 1);
241 // Check that we didn't wrongly coalesce.
242 merged_event = GestureEventLastQueueEvent();
243 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
244 EXPECT_EQ(1, merged_event.modifiers);
245 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
247 // Different.
248 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
249 blink::WebGestureDeviceTouchscreen);
251 // Check that only the first event was sent.
252 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
254 // Check that the ACK sends the second message.
255 SendInputEventACK(WebInputEvent::GestureScrollBegin,
256 INPUT_EVENT_ACK_STATE_CONSUMED);
257 RunUntilIdle();
258 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
259 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
261 // Ack for queued coalesced event.
262 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
263 INPUT_EVENT_ACK_STATE_CONSUMED);
264 RunUntilIdle();
265 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
266 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
268 // Ack for queued uncoalesced event.
269 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
270 INPUT_EVENT_ACK_STATE_CONSUMED);
271 RunUntilIdle();
272 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
273 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
275 // After the final ack, the queue should be empty.
276 SendInputEventACK(WebInputEvent::GestureScrollEnd,
277 INPUT_EVENT_ACK_STATE_CONSUMED);
278 RunUntilIdle();
279 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
280 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
283 TEST_F(GestureEventQueueTest,
284 DoesNotCoalesceScrollGestureEventsFromDifferentDevices) {
285 // Test that GestureScrollUpdate events from Touchscreen and Touchpad do not
286 // coalesce.
288 // Sent.
289 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
290 blink::WebGestureDeviceTouchscreen);
291 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
293 // Enqueued.
294 SimulateGestureScrollUpdateEvent(8, -5, 0);
296 // Make sure that the queue contains what we think it should.
297 EXPECT_EQ(2U, GestureEventQueueSize());
298 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
299 GestureEventLastQueueEvent().sourceDevice);
301 // Coalesced.
302 SimulateGestureScrollUpdateEvent(8, -6, 0);
303 EXPECT_EQ(2U, GestureEventQueueSize());
304 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
305 GestureEventLastQueueEvent().sourceDevice);
307 // Enqueued.
308 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
309 blink::WebGestureDeviceTouchpad);
310 EXPECT_EQ(3U, GestureEventQueueSize());
311 EXPECT_EQ(blink::WebGestureDeviceTouchpad,
312 GestureEventLastQueueEvent().sourceDevice);
314 // Coalesced.
315 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
316 blink::WebGestureDeviceTouchpad);
317 EXPECT_EQ(3U, GestureEventQueueSize());
318 EXPECT_EQ(blink::WebGestureDeviceTouchpad,
319 GestureEventLastQueueEvent().sourceDevice);
321 // Enqueued.
322 SimulateGestureScrollUpdateEvent(8, -7, 0);
323 EXPECT_EQ(4U, GestureEventQueueSize());
324 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
325 GestureEventLastQueueEvent().sourceDevice);
328 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEvents) {
329 // Test coalescing of only GestureScrollUpdate events.
330 // Simulate gesture events.
332 // Sent.
333 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
334 blink::WebGestureDeviceTouchscreen);
336 // Sent.
337 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
338 blink::WebGestureDeviceTouchscreen);
340 // Enqueued.
341 SimulateGestureScrollUpdateEvent(8, -4, 1);
343 // Make sure that the queue contains what we think it should.
344 WebGestureEvent merged_event = GestureEventLastQueueEvent();
345 EXPECT_EQ(3U, GestureEventQueueSize());
346 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
348 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
349 // from a point that is not the origin should still give us the right scroll.
350 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
351 EXPECT_EQ(4U, GestureEventQueueSize());
352 merged_event = GestureEventLastQueueEvent();
353 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
354 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
355 EXPECT_EQ(1, merged_event.modifiers);
356 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
357 merged_event = GestureEventSecondFromLastQueueEvent();
358 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
359 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
360 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
361 EXPECT_EQ(1, merged_event.modifiers);
362 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
364 // Enqueued.
365 SimulateGestureScrollUpdateEvent(6, -3, 1);
367 // Check whether coalesced correctly.
368 EXPECT_EQ(4U, GestureEventQueueSize());
369 merged_event = GestureEventLastQueueEvent();
370 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
371 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
372 EXPECT_EQ(1, merged_event.modifiers);
373 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
374 merged_event = GestureEventSecondFromLastQueueEvent();
375 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
376 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
377 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
378 EXPECT_EQ(1, merged_event.modifiers);
379 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
381 // Enqueued.
382 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
384 // Check whether coalesced correctly.
385 EXPECT_EQ(4U, GestureEventQueueSize());
386 merged_event = GestureEventLastQueueEvent();
387 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
388 EXPECT_EQ(3, merged_event.data.pinchUpdate.scale);
389 EXPECT_EQ(1, merged_event.modifiers);
390 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
391 merged_event = GestureEventSecondFromLastQueueEvent();
392 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
393 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
394 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
395 EXPECT_EQ(1, merged_event.modifiers);
396 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
398 // Enqueued.
399 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
401 // Check whether coalesced correctly.
402 EXPECT_EQ(4U, GestureEventQueueSize());
403 merged_event = GestureEventLastQueueEvent();
404 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
405 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
406 EXPECT_EQ(1, merged_event.modifiers);
407 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
408 merged_event = GestureEventSecondFromLastQueueEvent();
409 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
410 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
411 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
412 EXPECT_EQ(1, merged_event.modifiers);
413 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
415 // Check that only the first event was sent.
416 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
418 // Check that the ACK sends the second message.
419 SendInputEventACK(WebInputEvent::GestureScrollBegin,
420 INPUT_EVENT_ACK_STATE_CONSUMED);
421 RunUntilIdle();
422 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
424 // Enqueued.
425 SimulateGestureScrollUpdateEvent(6, -6, 1);
427 // Check whether coalesced correctly.
428 EXPECT_EQ(3U, GestureEventQueueSize());
429 merged_event = GestureEventLastQueueEvent();
430 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
431 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
432 EXPECT_EQ(1, merged_event.modifiers);
433 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
434 merged_event = GestureEventSecondFromLastQueueEvent();
435 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
436 EXPECT_EQ(13, merged_event.data.scrollUpdate.deltaX);
437 EXPECT_EQ(-7, merged_event.data.scrollUpdate.deltaY);
438 EXPECT_EQ(1, merged_event.modifiers);
439 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
441 // At this point ACKs shouldn't be getting ignored.
442 EXPECT_FALSE(WillIgnoreNextACK());
444 // Check that the ACK sends both scroll and pinch updates.
445 SendInputEventACK(WebInputEvent::GesturePinchBegin,
446 INPUT_EVENT_ACK_STATE_CONSUMED);
447 RunUntilIdle();
448 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
450 // The next ACK should be getting ignored.
451 EXPECT_TRUE(WillIgnoreNextACK());
453 // Enqueued.
454 SimulateGestureScrollUpdateEvent(1, -1, 1);
456 // Check whether coalesced correctly.
457 EXPECT_EQ(3U, GestureEventQueueSize());
458 merged_event = GestureEventLastQueueEvent();
459 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
460 EXPECT_EQ(1, merged_event.data.scrollUpdate.deltaX);
461 EXPECT_EQ(-1, merged_event.data.scrollUpdate.deltaY);
462 EXPECT_EQ(1, merged_event.modifiers);
463 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
464 merged_event = GestureEventSecondFromLastQueueEvent();
465 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
466 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
467 EXPECT_EQ(1, merged_event.modifiers);
468 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
470 // Enqueued.
471 SimulateGestureScrollUpdateEvent(2, -2, 1);
473 // Coalescing scrolls should still work.
474 EXPECT_EQ(3U, GestureEventQueueSize());
475 merged_event = GestureEventLastQueueEvent();
476 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
477 EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
478 EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
479 EXPECT_EQ(1, merged_event.modifiers);
480 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
481 merged_event = GestureEventSecondFromLastQueueEvent();
482 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
483 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
484 EXPECT_EQ(1, merged_event.modifiers);
485 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
487 // Enqueued.
488 SimulateGesturePinchUpdateEvent(0.5, 60, 60, 1);
490 // Check whether coalesced correctly.
491 EXPECT_EQ(4U, GestureEventQueueSize());
492 merged_event = GestureEventLastQueueEvent();
493 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
494 EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
495 EXPECT_EQ(1, merged_event.modifiers);
496 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
497 merged_event = GestureEventSecondFromLastQueueEvent();
498 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
499 EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
500 EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
501 EXPECT_EQ(1, merged_event.modifiers);
502 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
504 // Check that the ACK gets ignored.
505 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
506 INPUT_EVENT_ACK_STATE_CONSUMED);
507 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
508 RunUntilIdle();
509 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
510 // The flag should have been flipped back to false.
511 EXPECT_FALSE(WillIgnoreNextACK());
513 // Enqueued.
514 SimulateGestureScrollUpdateEvent(2, -2, 2);
516 // Shouldn't coalesce with different modifiers.
517 EXPECT_EQ(4U, GestureEventQueueSize());
518 merged_event = GestureEventLastQueueEvent();
519 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
520 EXPECT_EQ(2, merged_event.data.scrollUpdate.deltaX);
521 EXPECT_EQ(-2, merged_event.data.scrollUpdate.deltaY);
522 EXPECT_EQ(2, merged_event.modifiers);
523 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
524 merged_event = GestureEventSecondFromLastQueueEvent();
525 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
526 EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
527 EXPECT_EQ(1, merged_event.modifiers);
528 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
530 // Check that the ACK sends the next scroll pinch pair.
531 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
532 INPUT_EVENT_ACK_STATE_CONSUMED);
533 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
534 RunUntilIdle();
535 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
537 // Check that the ACK sends the second message.
538 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
539 INPUT_EVENT_ACK_STATE_CONSUMED);
540 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
541 RunUntilIdle();
542 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
544 // Check that the ACK sends the second event.
545 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
546 INPUT_EVENT_ACK_STATE_CONSUMED);
547 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
548 RunUntilIdle();
549 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
551 // Check that the queue is empty after ACK and no events get sent.
552 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
553 INPUT_EVENT_ACK_STATE_CONSUMED);
554 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
555 RunUntilIdle();
556 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
557 EXPECT_EQ(0U, GestureEventQueueSize());
560 TEST_F(GestureEventQueueTest, CoalescesMultiplePinchEventSequences) {
561 // Simulate a pinch sequence.
562 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
563 blink::WebGestureDeviceTouchscreen);
564 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
565 blink::WebGestureDeviceTouchscreen);
567 SimulateGestureScrollUpdateEvent(8, -4, 1);
568 // Make sure that the queue contains what we think it should.
569 WebGestureEvent merged_event = GestureEventLastQueueEvent();
570 size_t expected_events_in_queue = 3;
571 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
572 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
574 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
575 // from a point that is not the origin should still give us the right scroll.
576 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
577 EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
578 merged_event = GestureEventLastQueueEvent();
579 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
580 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
581 EXPECT_EQ(1, merged_event.modifiers);
582 merged_event = GestureEventSecondFromLastQueueEvent();
583 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
584 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
585 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
586 EXPECT_EQ(1, merged_event.modifiers);
588 // Enqueued.
589 SimulateGestureScrollUpdateEvent(6, -3, 1);
591 // Check whether coalesced correctly.
592 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
593 merged_event = GestureEventLastQueueEvent();
594 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
595 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
596 EXPECT_EQ(1, merged_event.modifiers);
597 merged_event = GestureEventSecondFromLastQueueEvent();
598 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
599 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
600 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
601 EXPECT_EQ(1, merged_event.modifiers);
603 // Now start another sequence before the previous sequence has been ack'ed.
604 SimulateGestureEvent(WebInputEvent::GesturePinchEnd,
605 blink::WebGestureDeviceTouchscreen);
606 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
607 blink::WebGestureDeviceTouchscreen);
608 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
609 blink::WebGestureDeviceTouchscreen);
610 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
611 blink::WebGestureDeviceTouchscreen);
613 SimulateGestureScrollUpdateEvent(8, -4, 1);
614 // Make sure that the queue contains what we think it should.
615 expected_events_in_queue += 5;
616 merged_event = GestureEventLastQueueEvent();
617 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
618 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
620 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
621 // from a point that is not the origin should still give us the right scroll.
622 SimulateGesturePinchUpdateEvent(1.5, 30, 30, 1);
623 EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
624 merged_event = GestureEventLastQueueEvent();
625 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
626 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
627 EXPECT_EQ(1, merged_event.modifiers);
628 merged_event = GestureEventSecondFromLastQueueEvent();
629 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
630 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
631 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
632 EXPECT_EQ(1, merged_event.modifiers);
634 // Enqueued.
635 SimulateGestureScrollUpdateEvent(6, -3, 1);
637 // Check whether coalesced correctly.
638 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
639 merged_event = GestureEventLastQueueEvent();
640 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
641 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
642 EXPECT_EQ(1, merged_event.modifiers);
643 merged_event = GestureEventSecondFromLastQueueEvent();
644 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
645 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
646 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
647 EXPECT_EQ(1, merged_event.modifiers);
650 TEST_F(GestureEventQueueTest, CoalescesPinchSequencesWithEarlyAck) {
651 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
652 blink::WebGestureDeviceTouchscreen);
653 SendInputEventACK(WebInputEvent::GestureScrollBegin,
654 INPUT_EVENT_ACK_STATE_CONSUMED);
656 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
657 blink::WebGestureDeviceTouchscreen);
658 SendInputEventACK(WebInputEvent::GesturePinchBegin,
659 INPUT_EVENT_ACK_STATE_CONSUMED);
660 // ScrollBegin and PinchBegin have been sent
661 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
662 EXPECT_EQ(0U, GestureEventQueueSize());
664 SimulateGestureScrollUpdateEvent(5, 5, 1);
665 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
666 EXPECT_EQ(WebInputEvent::GestureScrollUpdate,
667 GestureEventLastQueueEvent().type);
668 EXPECT_EQ(1U, GestureEventQueueSize());
670 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
671 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
672 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
673 GestureEventLastQueueEvent().type);
674 EXPECT_EQ(2U, GestureEventQueueSize());
676 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
677 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
678 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
679 GestureEventLastQueueEvent().type);
680 EXPECT_EQ(3U, GestureEventQueueSize());
682 SimulateGestureScrollUpdateEvent(5, 5, 1);
683 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
684 // The coalesced pinch/scroll pair will have been re-arranged, with the
685 // pinch following the scroll.
686 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
687 GestureEventLastQueueEvent().type);
688 EXPECT_EQ(4U, GestureEventQueueSize());
690 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
691 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
692 EXPECT_EQ(4U, GestureEventQueueSize());
694 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
695 INPUT_EVENT_ACK_STATE_CONSUMED);
696 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
697 EXPECT_EQ(3U, GestureEventQueueSize());
699 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
700 INPUT_EVENT_ACK_STATE_CONSUMED);
701 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
702 EXPECT_EQ(2U, GestureEventQueueSize());
703 EXPECT_EQ(2.f, last_acked_event().data.pinchUpdate.scale);
705 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
706 INPUT_EVENT_ACK_STATE_CONSUMED);
707 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
709 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
710 INPUT_EVENT_ACK_STATE_CONSUMED);
711 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
712 EXPECT_EQ(3.f * 4.f, last_acked_event().data.pinchUpdate.scale);
714 EXPECT_EQ(0U, GestureEventQueueSize());
717 TEST_F(GestureEventQueueTest,
718 DoesNotCoalescePinchGestureEventsWithDifferentModifiers) {
719 // Insert an event to force queueing of gestures.
720 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
721 blink::WebGestureDeviceTouchscreen);
722 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
723 EXPECT_EQ(1U, GestureEventQueueSize());
725 SimulateGestureScrollUpdateEvent(5, 5, 1);
726 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
727 EXPECT_EQ(2U, GestureEventQueueSize());
729 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
730 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
731 EXPECT_EQ(3U, GestureEventQueueSize());
733 SimulateGestureScrollUpdateEvent(10, 15, 1);
734 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
735 EXPECT_EQ(3U, GestureEventQueueSize());
737 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
738 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
739 EXPECT_EQ(3U, GestureEventQueueSize());
741 // Using different modifiers should prevent coalescing.
742 SimulateGesturePinchUpdateEvent(5, 60, 60, 2);
743 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
744 EXPECT_EQ(4U, GestureEventQueueSize());
746 SimulateGesturePinchUpdateEvent(6, 60, 60, 3);
747 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
748 EXPECT_EQ(5U, GestureEventQueueSize());
750 SendInputEventACK(WebInputEvent::GestureTapCancel,
751 INPUT_EVENT_ACK_STATE_CONSUMED);
752 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
753 EXPECT_EQ(4U, GestureEventQueueSize());
755 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
756 INPUT_EVENT_ACK_STATE_CONSUMED);
757 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
758 EXPECT_EQ(3U, GestureEventQueueSize());
760 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
761 INPUT_EVENT_ACK_STATE_CONSUMED);
762 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
763 EXPECT_EQ(3.f * 4.f, last_acked_event().data.pinchUpdate.scale);
764 EXPECT_EQ(2U, GestureEventQueueSize());
765 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
767 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
768 INPUT_EVENT_ACK_STATE_CONSUMED);
769 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
770 EXPECT_EQ(5.f, last_acked_event().data.pinchUpdate.scale);
771 EXPECT_EQ(1U, GestureEventQueueSize());
772 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
774 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
775 INPUT_EVENT_ACK_STATE_CONSUMED);
776 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
777 EXPECT_EQ(6.f, last_acked_event().data.pinchUpdate.scale);
778 EXPECT_EQ(0U, GestureEventQueueSize());
781 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventsIdentity) {
782 // Insert an event to force queueing of gestures.
783 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
784 blink::WebGestureDeviceTouchscreen);
785 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
786 EXPECT_EQ(1U, GestureEventQueueSize());
788 // Ensure that coalescing yields an identity transform for any pinch/scroll
789 // pair combined with its inverse.
790 SimulateGestureScrollUpdateEvent(5, 5, 1);
791 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
792 EXPECT_EQ(2U, GestureEventQueueSize());
794 SimulateGesturePinchUpdateEvent(5, 10, 10, 1);
795 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
796 EXPECT_EQ(3U, GestureEventQueueSize());
798 SimulateGesturePinchUpdateEvent(.2f, 10, 10, 1);
799 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
800 EXPECT_EQ(3U, GestureEventQueueSize());
802 SimulateGestureScrollUpdateEvent(-5, -5, 1);
803 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
804 EXPECT_EQ(3U, GestureEventQueueSize());
806 SendInputEventACK(WebInputEvent::GestureTapCancel,
807 INPUT_EVENT_ACK_STATE_CONSUMED);
808 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
809 EXPECT_EQ(2U, GestureEventQueueSize());
811 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
812 INPUT_EVENT_ACK_STATE_CONSUMED);
813 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
814 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaX);
815 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaY);
817 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
818 INPUT_EVENT_ACK_STATE_CONSUMED);
819 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
820 EXPECT_EQ(1.f, last_acked_event().data.pinchUpdate.scale);
821 EXPECT_EQ(0U, GestureEventQueueSize());
823 // Insert an event to force queueing of gestures.
824 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
825 blink::WebGestureDeviceTouchscreen);
826 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
827 EXPECT_EQ(1U, GestureEventQueueSize());
829 // Ensure that coalescing yields an identity transform for any pinch/scroll
830 // pair combined with its inverse.
831 SimulateGesturePinchUpdateEvent(2, 10, 10, 1);
832 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
833 EXPECT_EQ(2U, GestureEventQueueSize());
835 SimulateGestureScrollUpdateEvent(20, 20, 1);
836 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
837 EXPECT_EQ(3U, GestureEventQueueSize());
839 SimulateGesturePinchUpdateEvent(0.5f, 20, 20, 1);
840 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
841 EXPECT_EQ(3U, GestureEventQueueSize());
843 SimulateGestureScrollUpdateEvent(-5, -5, 1);
844 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
845 EXPECT_EQ(3U, GestureEventQueueSize());
847 SendInputEventACK(WebInputEvent::GestureTapCancel,
848 INPUT_EVENT_ACK_STATE_CONSUMED);
849 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
850 EXPECT_EQ(2U, GestureEventQueueSize());
852 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
853 INPUT_EVENT_ACK_STATE_CONSUMED);
854 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
855 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaX);
856 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaY);
858 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
859 INPUT_EVENT_ACK_STATE_CONSUMED);
860 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
861 EXPECT_EQ(1.f, last_acked_event().data.pinchUpdate.scale);
864 // Tests a single event with an synchronous ack.
865 TEST_F(GestureEventQueueTest, SimpleSyncAck) {
866 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
867 SimulateGestureEvent(WebInputEvent::GestureTapDown,
868 blink::WebGestureDeviceTouchscreen);
869 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
870 EXPECT_EQ(0U, GestureEventQueueSize());
871 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
874 // Tests an event with an synchronous ack which enqueues an additional event.
875 TEST_F(GestureEventQueueTest, SyncAckQueuesEvent) {
876 scoped_ptr<WebGestureEvent> queued_event;
877 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
878 set_sync_followup_event(WebInputEvent::GestureShowPress,
879 blink::WebGestureDeviceTouchscreen);
880 // This event enqueues the show press event.
881 SimulateGestureEvent(WebInputEvent::GestureTapDown,
882 blink::WebGestureDeviceTouchscreen);
883 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
884 EXPECT_EQ(1U, GestureEventQueueSize());
885 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
887 SendInputEventACK(WebInputEvent::GestureShowPress,
888 INPUT_EVENT_ACK_STATE_CONSUMED);
889 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
890 EXPECT_EQ(0U, GestureEventQueueSize());
891 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
894 // Tests an event with an async ack followed by an event with a sync ack.
895 TEST_F(GestureEventQueueTest, AsyncThenSyncAck) {
896 SimulateGestureEvent(WebInputEvent::GestureTapDown,
897 blink::WebGestureDeviceTouchscreen);
899 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
900 EXPECT_EQ(1U, GestureEventQueueSize());
901 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
903 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
904 blink::WebGestureDeviceTouchscreen);
905 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
906 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
907 EXPECT_EQ(2U, GestureEventQueueSize());
908 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
910 SendInputEventACK(WebInputEvent::GestureTapDown,
911 INPUT_EVENT_ACK_STATE_CONSUMED);
912 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
913 EXPECT_EQ(0U, GestureEventQueueSize());
914 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
917 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventWithSyncAck) {
918 // Simulate a pinch sequence.
919 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
920 blink::WebGestureDeviceTouchscreen);
921 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
922 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
923 blink::WebGestureDeviceTouchscreen);
924 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
926 SimulateGestureScrollUpdateEvent(8, -4, 1);
927 // Make sure that the queue contains what we think it should.
928 WebGestureEvent merged_event = GestureEventLastQueueEvent();
929 EXPECT_EQ(3U, GestureEventQueueSize());
930 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
932 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
933 // from a point that is not the origin should still give us the right scroll.
934 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
935 EXPECT_EQ(4U, GestureEventQueueSize());
937 SendInputEventACK(WebInputEvent::GestureScrollBegin,
938 INPUT_EVENT_ACK_STATE_CONSUMED);
939 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
940 EXPECT_EQ(3U, GestureEventQueueSize());
942 // Ack the PinchBegin, and schedule a synchronous ack for GestureScrollUpdate.
943 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
944 SendInputEventACK(WebInputEvent::GesturePinchBegin,
945 INPUT_EVENT_ACK_STATE_CONSUMED);
947 // Both GestureScrollUpdate and GesturePinchUpdate should have been sent.
948 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
949 EXPECT_EQ(1U, GestureEventQueueSize());
950 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
952 // Ack the final GesturePinchUpdate.
953 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
954 INPUT_EVENT_ACK_STATE_CONSUMED);
955 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
956 EXPECT_EQ(0U, GestureEventQueueSize());
957 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
960 #if GTEST_HAS_PARAM_TEST
961 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) {
962 WebGestureDevice source_device = GetParam();
964 // GFC without previous GFS is dropped.
965 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
966 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
967 EXPECT_EQ(0U, GestureEventQueueSize());
969 // GFC after unconsumed fling is dropped.
970 SimulateGestureEvent(WebInputEvent::GestureFlingStart, source_device);
971 SendInputEventACK(WebInputEvent::GestureFlingStart,
972 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
973 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
974 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
975 EXPECT_EQ(0U, GestureEventQueueSize());
976 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
977 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
978 EXPECT_EQ(0U, GestureEventQueueSize());
980 // GFC after fling has ended is dropped.
981 SimulateGestureEvent(WebInputEvent::GestureFlingStart, source_device);
982 SendInputEventACK(WebInputEvent::GestureFlingStart,
983 INPUT_EVENT_ACK_STATE_CONSUMED);
984 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
985 EXPECT_EQ(0U, GestureEventQueueSize());
986 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
988 EXPECT_EQ(1, ActiveFlingCount());
989 queue()->DidStopFlinging();
990 EXPECT_EQ(0, ActiveFlingCount());
992 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
993 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
994 EXPECT_EQ(0U, GestureEventQueueSize());
996 // GFC after previous GFS is dispatched and acked.
997 SimulateGestureFlingStartEvent(0, -10, source_device);
998 SendInputEventACK(WebInputEvent::GestureFlingStart,
999 INPUT_EVENT_ACK_STATE_CONSUMED);
1000 EXPECT_EQ(1, ActiveFlingCount());
1001 RunUntilIdle();
1002 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
1003 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1004 queue()->DidStopFlinging();
1005 EXPECT_EQ(0, ActiveFlingCount());
1006 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
1007 SendInputEventACK(WebInputEvent::GestureFlingCancel,
1008 INPUT_EVENT_ACK_STATE_CONSUMED);
1009 RunUntilIdle();
1010 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
1011 EXPECT_EQ(0U, GestureEventQueueSize());
1013 // GFC before previous GFS is acked.
1014 SimulateGestureFlingStartEvent(0, -10, source_device);
1015 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1016 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1017 EXPECT_EQ(2U, GestureEventQueueSize());
1019 // Advance state realistically.
1020 SendInputEventACK(WebInputEvent::GestureFlingStart,
1021 INPUT_EVENT_ACK_STATE_CONSUMED);
1022 RunUntilIdle();
1023 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1024 SendInputEventACK(WebInputEvent::GestureFlingCancel,
1025 INPUT_EVENT_ACK_STATE_CONSUMED);
1026 RunUntilIdle();
1027 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
1028 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1029 EXPECT_EQ(0U, GestureEventQueueSize());
1031 // GFS is added to the queue if another event is pending
1032 SimulateGestureScrollUpdateEvent(8, -7, 0);
1033 SimulateGestureFlingStartEvent(0, -10, source_device);
1034 EXPECT_EQ(2U, GestureEventQueueSize());
1035 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1036 WebGestureEvent merged_event = GestureEventLastQueueEvent();
1037 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
1038 EXPECT_EQ(2U, GestureEventQueueSize());
1040 // GFS in queue means that a GFC is added to the queue
1041 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1042 merged_event =GestureEventLastQueueEvent();
1043 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1044 EXPECT_EQ(3U, GestureEventQueueSize());
1046 // Adding a second GFC is dropped.
1047 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1048 EXPECT_EQ(3U, GestureEventQueueSize());
1050 // Adding another GFS will add it to the queue.
1051 SimulateGestureFlingStartEvent(0, -10, source_device);
1052 merged_event = GestureEventLastQueueEvent();
1053 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
1054 EXPECT_EQ(4U, GestureEventQueueSize());
1056 // GFS in queue means that a GFC is added to the queue
1057 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1058 merged_event = GestureEventLastQueueEvent();
1059 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1060 EXPECT_EQ(5U, GestureEventQueueSize());
1062 // Adding another GFC with a GFC already there is dropped.
1063 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1064 merged_event = GestureEventLastQueueEvent();
1065 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1066 EXPECT_EQ(5U, GestureEventQueueSize());
1069 INSTANTIATE_TEST_CASE_P(AllSources,
1070 GestureEventQueueWithSourceTest,
1071 testing::Values(blink::WebGestureDeviceTouchscreen,
1072 blink::WebGestureDeviceTouchpad));
1073 #endif // GTEST_HAS_PARAM_TEST
1075 TEST_F(GestureEventQueueTest, GestureFlingCancelFilteringDisabled) {
1076 SetUpForGFCFilteringDisabled();
1078 // If so configured, GFC events should never be filtered, even if there are
1079 // no active flings.
1080 SimulateGestureEvent(WebInputEvent::GestureFlingCancel,
1081 blink::WebGestureDeviceTouchscreen);
1082 EXPECT_EQ(0, ActiveFlingCount());
1083 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1084 EXPECT_EQ(1U, GestureEventQueueSize());
1087 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the
1088 // debounce interval, that Scrolls are not and that the deferred events are
1089 // sent after that timer fires.
1090 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) {
1091 SetUpForDebounce(3);
1093 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1094 blink::WebGestureDeviceTouchscreen);
1095 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1096 EXPECT_EQ(1U, GestureEventQueueSize());
1097 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1098 EXPECT_TRUE(ScrollingInProgress());
1100 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1101 blink::WebGestureDeviceTouchscreen);
1102 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1103 EXPECT_EQ(2U, GestureEventQueueSize());
1104 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1105 EXPECT_TRUE(ScrollingInProgress());
1107 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1108 blink::WebGestureDeviceTouchscreen);
1109 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1110 EXPECT_EQ(2U, GestureEventQueueSize());
1111 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1113 SimulateGestureFlingStartEvent(0, 10, blink::WebGestureDeviceTouchscreen);
1114 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1115 EXPECT_EQ(2U, GestureEventQueueSize());
1116 EXPECT_EQ(2U, GestureEventDebouncingQueueSize());
1118 SimulateGestureEvent(WebInputEvent::GestureTapDown,
1119 blink::WebGestureDeviceTouchscreen);
1120 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1121 EXPECT_EQ(2U, GestureEventQueueSize());
1122 EXPECT_EQ(3U, GestureEventDebouncingQueueSize());
1124 base::MessageLoop::current()->PostDelayedTask(
1125 FROM_HERE,
1126 base::MessageLoop::QuitClosure(),
1127 TimeDelta::FromMilliseconds(5));
1128 base::MessageLoop::current()->Run();
1130 // The deferred events are correctly queued in coalescing queue.
1131 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1132 EXPECT_EQ(5U, GestureEventQueueSize());
1133 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1134 EXPECT_FALSE(ScrollingInProgress());
1136 // Verify that the coalescing queue contains the correct events.
1137 WebInputEvent::Type expected[] = {
1138 WebInputEvent::GestureScrollUpdate,
1139 WebInputEvent::GestureScrollUpdate,
1140 WebInputEvent::GestureScrollEnd,
1141 WebInputEvent::GestureFlingStart};
1143 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
1144 i++) {
1145 WebGestureEvent merged_event = GestureEventQueueEventAt(i);
1146 EXPECT_EQ(expected[i], merged_event.type);
1150 // Test that non-scroll events are deferred while scrolling during the debounce
1151 // interval and are discarded if a GestureScrollUpdate event arrives before the
1152 // interval end.
1153 TEST_F(GestureEventQueueTest, DebounceDropsDeferredEvents) {
1154 SetUpForDebounce(3);
1156 EXPECT_FALSE(ScrollingInProgress());
1158 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1159 blink::WebGestureDeviceTouchscreen);
1160 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1161 EXPECT_EQ(1U, GestureEventQueueSize());
1162 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1163 EXPECT_TRUE(ScrollingInProgress());
1165 // This event should get discarded.
1166 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1167 blink::WebGestureDeviceTouchscreen);
1168 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1169 EXPECT_EQ(1U, GestureEventQueueSize());
1170 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1172 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1173 blink::WebGestureDeviceTouchscreen);
1174 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1175 EXPECT_EQ(2U, GestureEventQueueSize());
1176 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1177 EXPECT_TRUE(ScrollingInProgress());
1179 // Verify that the coalescing queue contains the correct events.
1180 WebInputEvent::Type expected[] = {
1181 WebInputEvent::GestureScrollUpdate,
1182 WebInputEvent::GestureScrollUpdate};
1184 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
1185 i++) {
1186 WebGestureEvent merged_event = GestureEventQueueEventAt(i);
1187 EXPECT_EQ(expected[i], merged_event.type);
1191 } // namespace content