Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / gesture_event_queue_unittest.cc
blob7e7a6ead4988a6aefc21a5926cb55af686b5b5c6
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/location.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h"
15 #include "content/browser/renderer_host/input/gesture_event_queue.h"
16 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h"
17 #include "content/common/input/input_event_ack_state.h"
18 #include "content/common/input/synthetic_web_input_event_builders.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 using base::TimeDelta;
23 using blink::WebGestureDevice;
24 using blink::WebGestureEvent;
25 using blink::WebInputEvent;
27 namespace content {
29 class GestureEventQueueTest : public testing::Test,
30 public GestureEventQueueClient,
31 public TouchpadTapSuppressionControllerClient {
32 public:
33 GestureEventQueueTest()
34 : acked_gesture_event_count_(0),
35 sent_gesture_event_count_(0) {}
37 ~GestureEventQueueTest() override {}
39 // testing::Test
40 void SetUp() override {
41 queue_.reset(new GestureEventQueue(this, this, DefaultConfig()));
44 void TearDown() override {
45 // Process all pending tasks to avoid leaks.
46 RunUntilIdle();
47 queue_.reset();
50 // GestureEventQueueClient
51 void SendGestureEventImmediately(
52 const GestureEventWithLatencyInfo& event) override {
53 ++sent_gesture_event_count_;
54 if (sync_ack_result_) {
55 scoped_ptr<InputEventAckState> ack_result = sync_ack_result_.Pass();
56 SendInputEventACK(event.event.type, *ack_result);
60 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
61 InputEventAckState ack_result) override {
62 ++acked_gesture_event_count_;
63 last_acked_event_ = event.event;
64 if (sync_followup_event_) {
65 auto sync_followup_event = sync_followup_event_.Pass();
66 SimulateGestureEvent(*sync_followup_event);
70 // TouchpadTapSuppressionControllerClient
71 void SendMouseEventImmediately(
72 const MouseEventWithLatencyInfo& event) override {}
74 protected:
75 static GestureEventQueue::Config DefaultConfig() {
76 return GestureEventQueue::Config();
79 void SetUpForDebounce(int interval_ms) {
80 queue()->set_debounce_interval_time_ms_for_testing(interval_ms);
83 void SimulateGestureEvent(const WebGestureEvent& gesture) {
84 queue()->QueueEvent(GestureEventWithLatencyInfo(gesture));
87 void SimulateGestureEvent(WebInputEvent::Type type,
88 WebGestureDevice sourceDevice) {
89 SimulateGestureEvent(
90 SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
93 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
94 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
95 dX, dY, modifiers, blink::WebGestureDeviceTouchscreen));
98 void SimulateGesturePinchUpdateEvent(float scale,
99 float anchorX,
100 float anchorY,
101 int modifiers) {
102 SimulateGestureEvent(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
103 scale,
104 anchorX,
105 anchorY,
106 modifiers,
107 blink::WebGestureDeviceTouchscreen));
110 void SimulateGestureFlingStartEvent(float velocityX,
111 float velocityY,
112 WebGestureDevice sourceDevice) {
113 SimulateGestureEvent(
114 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
115 velocityY,
116 sourceDevice));
119 void SendInputEventACK(WebInputEvent::Type type,
120 InputEventAckState ack) {
121 queue()->ProcessGestureAck(ack, type, ui::LatencyInfo());
124 void RunUntilIdle() {
125 base::MessageLoop::current()->RunUntilIdle();
128 size_t GetAndResetSentGestureEventCount() {
129 size_t count = sent_gesture_event_count_;
130 sent_gesture_event_count_ = 0;
131 return count;
134 size_t GetAndResetAckedGestureEventCount() {
135 size_t count = acked_gesture_event_count_;
136 acked_gesture_event_count_ = 0;
137 return count;
140 const WebGestureEvent& last_acked_event() const {
141 return last_acked_event_;
144 void set_synchronous_ack(InputEventAckState ack_result) {
145 sync_ack_result_.reset(new InputEventAckState(ack_result));
148 void set_sync_followup_event(WebInputEvent::Type type,
149 WebGestureDevice sourceDevice) {
150 sync_followup_event_.reset(new WebGestureEvent(
151 SyntheticWebGestureEventBuilder::Build(type, sourceDevice)));
154 unsigned GestureEventQueueSize() {
155 return queue()->coalesced_gesture_events_.size();
158 WebGestureEvent GestureEventSecondFromLastQueueEvent() {
159 return queue()->coalesced_gesture_events_.at(
160 GestureEventQueueSize() - 2).event;
163 WebGestureEvent GestureEventLastQueueEvent() {
164 return queue()->coalesced_gesture_events_.back().event;
167 unsigned GestureEventDebouncingQueueSize() {
168 return queue()->debouncing_deferral_queue_.size();
171 WebGestureEvent GestureEventQueueEventAt(int i) {
172 return queue()->coalesced_gesture_events_.at(i).event;
175 bool ScrollingInProgress() {
176 return queue()->scrolling_in_progress_;
179 bool FlingInProgress() { return queue()->fling_in_progress_; }
181 bool WillIgnoreNextACK() {
182 return queue()->ignore_next_ack_;
185 GestureEventQueue* queue() const {
186 return queue_.get();
189 private:
190 scoped_ptr<GestureEventQueue> queue_;
191 size_t acked_gesture_event_count_;
192 size_t sent_gesture_event_count_;
193 WebGestureEvent last_acked_event_;
194 scoped_ptr<InputEventAckState> sync_ack_result_;
195 scoped_ptr<WebGestureEvent> sync_followup_event_;
196 base::MessageLoopForUI message_loop_;
199 #if GTEST_HAS_PARAM_TEST
200 // This is for tests that are to be run for all source devices.
201 class GestureEventQueueWithSourceTest
202 : public GestureEventQueueTest,
203 public testing::WithParamInterface<WebGestureDevice> {};
204 #endif // GTEST_HAS_PARAM_TEST
206 TEST_F(GestureEventQueueTest, CoalescesScrollGestureEvents) {
207 // Test coalescing of only GestureScrollUpdate events.
208 // Simulate gesture events.
210 // Sent.
211 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
212 blink::WebGestureDeviceTouchscreen);
213 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
215 // Enqueued.
216 SimulateGestureScrollUpdateEvent(8, -5, 0);
218 // Make sure that the queue contains what we think it should.
219 WebGestureEvent merged_event = GestureEventLastQueueEvent();
220 EXPECT_EQ(2U, GestureEventQueueSize());
221 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
222 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
224 // Coalesced.
225 SimulateGestureScrollUpdateEvent(8, -6, 0);
227 // Check that coalescing updated the correct values.
228 merged_event = GestureEventLastQueueEvent();
229 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
230 EXPECT_EQ(0, merged_event.modifiers);
231 EXPECT_EQ(16, merged_event.data.scrollUpdate.deltaX);
232 EXPECT_EQ(-11, merged_event.data.scrollUpdate.deltaY);
233 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
235 // Enqueued.
236 SimulateGestureScrollUpdateEvent(8, -7, 1);
238 // Check that we didn't wrongly coalesce.
239 merged_event = GestureEventLastQueueEvent();
240 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
241 EXPECT_EQ(1, merged_event.modifiers);
242 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
244 // Different.
245 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
246 blink::WebGestureDeviceTouchscreen);
248 // Check that only the first event was sent.
249 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
251 // Check that the ACK sends the second message.
252 SendInputEventACK(WebInputEvent::GestureScrollBegin,
253 INPUT_EVENT_ACK_STATE_CONSUMED);
254 RunUntilIdle();
255 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
256 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
258 // Ack for queued coalesced event.
259 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
260 INPUT_EVENT_ACK_STATE_CONSUMED);
261 RunUntilIdle();
262 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
263 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
265 // Ack for queued uncoalesced event.
266 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
267 INPUT_EVENT_ACK_STATE_CONSUMED);
268 RunUntilIdle();
269 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
270 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
272 // After the final ack, the queue should be empty.
273 SendInputEventACK(WebInputEvent::GestureScrollEnd,
274 INPUT_EVENT_ACK_STATE_CONSUMED);
275 RunUntilIdle();
276 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
277 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
280 TEST_F(GestureEventQueueTest,
281 DoesNotCoalesceScrollGestureEventsFromDifferentDevices) {
282 // Test that GestureScrollUpdate events from Touchscreen and Touchpad do not
283 // coalesce.
285 // Sent.
286 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
287 blink::WebGestureDeviceTouchscreen);
288 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
290 // Enqueued.
291 SimulateGestureScrollUpdateEvent(8, -5, 0);
293 // Make sure that the queue contains what we think it should.
294 EXPECT_EQ(2U, GestureEventQueueSize());
295 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
296 GestureEventLastQueueEvent().sourceDevice);
298 // Coalesced.
299 SimulateGestureScrollUpdateEvent(8, -6, 0);
300 EXPECT_EQ(2U, GestureEventQueueSize());
301 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
302 GestureEventLastQueueEvent().sourceDevice);
304 // Enqueued.
305 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
306 blink::WebGestureDeviceTouchpad);
307 EXPECT_EQ(3U, GestureEventQueueSize());
308 EXPECT_EQ(blink::WebGestureDeviceTouchpad,
309 GestureEventLastQueueEvent().sourceDevice);
311 // Coalesced.
312 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
313 blink::WebGestureDeviceTouchpad);
314 EXPECT_EQ(3U, GestureEventQueueSize());
315 EXPECT_EQ(blink::WebGestureDeviceTouchpad,
316 GestureEventLastQueueEvent().sourceDevice);
318 // Enqueued.
319 SimulateGestureScrollUpdateEvent(8, -7, 0);
320 EXPECT_EQ(4U, GestureEventQueueSize());
321 EXPECT_EQ(blink::WebGestureDeviceTouchscreen,
322 GestureEventLastQueueEvent().sourceDevice);
325 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEvents) {
326 // Test coalescing of only GestureScrollUpdate events.
327 // Simulate gesture events.
329 // Sent.
330 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
331 blink::WebGestureDeviceTouchscreen);
333 // Sent.
334 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
335 blink::WebGestureDeviceTouchscreen);
337 // Enqueued.
338 SimulateGestureScrollUpdateEvent(8, -4, 1);
340 // Make sure that the queue contains what we think it should.
341 WebGestureEvent merged_event = GestureEventLastQueueEvent();
342 EXPECT_EQ(3U, GestureEventQueueSize());
343 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
345 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
346 // from a point that is not the origin should still give us the right scroll.
347 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
348 EXPECT_EQ(4U, GestureEventQueueSize());
349 merged_event = GestureEventLastQueueEvent();
350 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
351 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
352 EXPECT_EQ(1, merged_event.modifiers);
353 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
354 merged_event = GestureEventSecondFromLastQueueEvent();
355 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
356 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
357 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
358 EXPECT_EQ(1, merged_event.modifiers);
359 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
361 // Enqueued.
362 SimulateGestureScrollUpdateEvent(6, -3, 1);
364 // Check whether coalesced correctly.
365 EXPECT_EQ(4U, GestureEventQueueSize());
366 merged_event = GestureEventLastQueueEvent();
367 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
368 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
369 EXPECT_EQ(1, merged_event.modifiers);
370 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
371 merged_event = GestureEventSecondFromLastQueueEvent();
372 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
373 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
374 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
375 EXPECT_EQ(1, merged_event.modifiers);
376 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
378 // Enqueued.
379 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
381 // Check whether coalesced correctly.
382 EXPECT_EQ(4U, GestureEventQueueSize());
383 merged_event = GestureEventLastQueueEvent();
384 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
385 EXPECT_EQ(3, merged_event.data.pinchUpdate.scale);
386 EXPECT_EQ(1, merged_event.modifiers);
387 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
388 merged_event = GestureEventSecondFromLastQueueEvent();
389 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
390 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
391 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
392 EXPECT_EQ(1, merged_event.modifiers);
393 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
395 // Enqueued.
396 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
398 // Check whether coalesced correctly.
399 EXPECT_EQ(4U, GestureEventQueueSize());
400 merged_event = GestureEventLastQueueEvent();
401 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
402 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
403 EXPECT_EQ(1, merged_event.modifiers);
404 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
405 merged_event = GestureEventSecondFromLastQueueEvent();
406 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
407 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
408 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
409 EXPECT_EQ(1, merged_event.modifiers);
410 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
412 // Check that only the first event was sent.
413 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
415 // Check that the ACK sends the second message.
416 SendInputEventACK(WebInputEvent::GestureScrollBegin,
417 INPUT_EVENT_ACK_STATE_CONSUMED);
418 RunUntilIdle();
419 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
421 // Enqueued.
422 SimulateGestureScrollUpdateEvent(6, -6, 1);
424 // Check whether coalesced correctly.
425 EXPECT_EQ(3U, GestureEventQueueSize());
426 merged_event = GestureEventLastQueueEvent();
427 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
428 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
429 EXPECT_EQ(1, merged_event.modifiers);
430 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
431 merged_event = GestureEventSecondFromLastQueueEvent();
432 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
433 EXPECT_EQ(13, merged_event.data.scrollUpdate.deltaX);
434 EXPECT_EQ(-7, merged_event.data.scrollUpdate.deltaY);
435 EXPECT_EQ(1, merged_event.modifiers);
436 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
438 // At this point ACKs shouldn't be getting ignored.
439 EXPECT_FALSE(WillIgnoreNextACK());
441 // Check that the ACK sends both scroll and pinch updates.
442 SendInputEventACK(WebInputEvent::GesturePinchBegin,
443 INPUT_EVENT_ACK_STATE_CONSUMED);
444 RunUntilIdle();
445 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
447 // The next ACK should be getting ignored.
448 EXPECT_TRUE(WillIgnoreNextACK());
450 // Enqueued.
451 SimulateGestureScrollUpdateEvent(1, -1, 1);
453 // Check whether coalesced correctly.
454 EXPECT_EQ(3U, GestureEventQueueSize());
455 merged_event = GestureEventLastQueueEvent();
456 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
457 EXPECT_EQ(1, merged_event.data.scrollUpdate.deltaX);
458 EXPECT_EQ(-1, merged_event.data.scrollUpdate.deltaY);
459 EXPECT_EQ(1, merged_event.modifiers);
460 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
461 merged_event = GestureEventSecondFromLastQueueEvent();
462 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
463 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
464 EXPECT_EQ(1, merged_event.modifiers);
465 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
467 // Enqueued.
468 SimulateGestureScrollUpdateEvent(2, -2, 1);
470 // Coalescing scrolls should still work.
471 EXPECT_EQ(3U, GestureEventQueueSize());
472 merged_event = GestureEventLastQueueEvent();
473 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
474 EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
475 EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
476 EXPECT_EQ(1, merged_event.modifiers);
477 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
478 merged_event = GestureEventSecondFromLastQueueEvent();
479 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
480 EXPECT_EQ(6, merged_event.data.pinchUpdate.scale);
481 EXPECT_EQ(1, merged_event.modifiers);
482 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
484 // Enqueued.
485 SimulateGesturePinchUpdateEvent(0.5, 60, 60, 1);
487 // Check whether coalesced correctly.
488 EXPECT_EQ(4U, GestureEventQueueSize());
489 merged_event = GestureEventLastQueueEvent();
490 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
491 EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
492 EXPECT_EQ(1, merged_event.modifiers);
493 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
494 merged_event = GestureEventSecondFromLastQueueEvent();
495 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
496 EXPECT_EQ(3, merged_event.data.scrollUpdate.deltaX);
497 EXPECT_EQ(-3, merged_event.data.scrollUpdate.deltaY);
498 EXPECT_EQ(1, merged_event.modifiers);
499 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
501 // Check that the ACK gets ignored.
502 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
503 INPUT_EVENT_ACK_STATE_CONSUMED);
504 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
505 RunUntilIdle();
506 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
507 // The flag should have been flipped back to false.
508 EXPECT_FALSE(WillIgnoreNextACK());
510 // Enqueued.
511 SimulateGestureScrollUpdateEvent(2, -2, 2);
513 // Shouldn't coalesce with different modifiers.
514 EXPECT_EQ(4U, GestureEventQueueSize());
515 merged_event = GestureEventLastQueueEvent();
516 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
517 EXPECT_EQ(2, merged_event.data.scrollUpdate.deltaX);
518 EXPECT_EQ(-2, merged_event.data.scrollUpdate.deltaY);
519 EXPECT_EQ(2, merged_event.modifiers);
520 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
521 merged_event = GestureEventSecondFromLastQueueEvent();
522 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
523 EXPECT_EQ(0.5, merged_event.data.pinchUpdate.scale);
524 EXPECT_EQ(1, merged_event.modifiers);
525 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, merged_event.sourceDevice);
527 // Check that the ACK sends the next scroll pinch pair.
528 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
529 INPUT_EVENT_ACK_STATE_CONSUMED);
530 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
531 RunUntilIdle();
532 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
534 // Check that the ACK sends the second message.
535 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
536 INPUT_EVENT_ACK_STATE_CONSUMED);
537 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
538 RunUntilIdle();
539 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
541 // Check that the ACK sends the second event.
542 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
543 INPUT_EVENT_ACK_STATE_CONSUMED);
544 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
545 RunUntilIdle();
546 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
548 // Check that the queue is empty after ACK and no events get sent.
549 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
550 INPUT_EVENT_ACK_STATE_CONSUMED);
551 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
552 RunUntilIdle();
553 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
554 EXPECT_EQ(0U, GestureEventQueueSize());
557 TEST_F(GestureEventQueueTest, CoalescesMultiplePinchEventSequences) {
558 // Simulate a pinch sequence.
559 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
560 blink::WebGestureDeviceTouchscreen);
561 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
562 blink::WebGestureDeviceTouchscreen);
564 SimulateGestureScrollUpdateEvent(8, -4, 1);
565 // Make sure that the queue contains what we think it should.
566 WebGestureEvent merged_event = GestureEventLastQueueEvent();
567 size_t expected_events_in_queue = 3;
568 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
569 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
571 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
572 // from a point that is not the origin should still give us the right scroll.
573 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
574 EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
575 merged_event = GestureEventLastQueueEvent();
576 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
577 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
578 EXPECT_EQ(1, merged_event.modifiers);
579 merged_event = GestureEventSecondFromLastQueueEvent();
580 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
581 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
582 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
583 EXPECT_EQ(1, merged_event.modifiers);
585 // Enqueued.
586 SimulateGestureScrollUpdateEvent(6, -3, 1);
588 // Check whether coalesced correctly.
589 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
590 merged_event = GestureEventLastQueueEvent();
591 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
592 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
593 EXPECT_EQ(1, merged_event.modifiers);
594 merged_event = GestureEventSecondFromLastQueueEvent();
595 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
596 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
597 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
598 EXPECT_EQ(1, merged_event.modifiers);
600 // Now start another sequence before the previous sequence has been ack'ed.
601 SimulateGestureEvent(WebInputEvent::GesturePinchEnd,
602 blink::WebGestureDeviceTouchscreen);
603 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
604 blink::WebGestureDeviceTouchscreen);
605 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
606 blink::WebGestureDeviceTouchscreen);
607 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
608 blink::WebGestureDeviceTouchscreen);
610 SimulateGestureScrollUpdateEvent(8, -4, 1);
611 // Make sure that the queue contains what we think it should.
612 expected_events_in_queue += 5;
613 merged_event = GestureEventLastQueueEvent();
614 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
615 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
617 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
618 // from a point that is not the origin should still give us the right scroll.
619 SimulateGesturePinchUpdateEvent(1.5, 30, 30, 1);
620 EXPECT_EQ(++expected_events_in_queue, GestureEventQueueSize());
621 merged_event = GestureEventLastQueueEvent();
622 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
623 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
624 EXPECT_EQ(1, merged_event.modifiers);
625 merged_event = GestureEventSecondFromLastQueueEvent();
626 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
627 EXPECT_EQ(8, merged_event.data.scrollUpdate.deltaX);
628 EXPECT_EQ(-4, merged_event.data.scrollUpdate.deltaY);
629 EXPECT_EQ(1, merged_event.modifiers);
631 // Enqueued.
632 SimulateGestureScrollUpdateEvent(6, -3, 1);
634 // Check whether coalesced correctly.
635 EXPECT_EQ(expected_events_in_queue, GestureEventQueueSize());
636 merged_event = GestureEventLastQueueEvent();
637 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, merged_event.type);
638 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale);
639 EXPECT_EQ(1, merged_event.modifiers);
640 merged_event = GestureEventSecondFromLastQueueEvent();
641 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
642 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX);
643 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY);
644 EXPECT_EQ(1, merged_event.modifiers);
647 TEST_F(GestureEventQueueTest, CoalescesPinchSequencesWithEarlyAck) {
648 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
649 blink::WebGestureDeviceTouchscreen);
650 SendInputEventACK(WebInputEvent::GestureScrollBegin,
651 INPUT_EVENT_ACK_STATE_CONSUMED);
653 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
654 blink::WebGestureDeviceTouchscreen);
655 SendInputEventACK(WebInputEvent::GesturePinchBegin,
656 INPUT_EVENT_ACK_STATE_CONSUMED);
657 // ScrollBegin and PinchBegin have been sent
658 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
659 EXPECT_EQ(0U, GestureEventQueueSize());
661 SimulateGestureScrollUpdateEvent(5, 5, 1);
662 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
663 EXPECT_EQ(WebInputEvent::GestureScrollUpdate,
664 GestureEventLastQueueEvent().type);
665 EXPECT_EQ(1U, GestureEventQueueSize());
667 SimulateGesturePinchUpdateEvent(2, 60, 60, 1);
668 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
669 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
670 GestureEventLastQueueEvent().type);
671 EXPECT_EQ(2U, GestureEventQueueSize());
673 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
674 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
675 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
676 GestureEventLastQueueEvent().type);
677 EXPECT_EQ(3U, GestureEventQueueSize());
679 SimulateGestureScrollUpdateEvent(5, 5, 1);
680 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
681 // The coalesced pinch/scroll pair will have been re-arranged, with the
682 // pinch following the scroll.
683 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
684 GestureEventLastQueueEvent().type);
685 EXPECT_EQ(4U, GestureEventQueueSize());
687 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
688 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
689 EXPECT_EQ(4U, GestureEventQueueSize());
691 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
692 INPUT_EVENT_ACK_STATE_CONSUMED);
693 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
694 EXPECT_EQ(3U, GestureEventQueueSize());
696 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
697 INPUT_EVENT_ACK_STATE_CONSUMED);
698 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
699 EXPECT_EQ(2U, GestureEventQueueSize());
700 EXPECT_EQ(2.f, last_acked_event().data.pinchUpdate.scale);
702 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
703 INPUT_EVENT_ACK_STATE_CONSUMED);
704 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
706 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
707 INPUT_EVENT_ACK_STATE_CONSUMED);
708 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
709 EXPECT_EQ(3.f * 4.f, last_acked_event().data.pinchUpdate.scale);
711 EXPECT_EQ(0U, GestureEventQueueSize());
714 TEST_F(GestureEventQueueTest,
715 DoesNotCoalescePinchGestureEventsWithDifferentModifiers) {
716 // Insert an event to force queueing of gestures.
717 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
718 blink::WebGestureDeviceTouchscreen);
719 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
720 EXPECT_EQ(1U, GestureEventQueueSize());
722 SimulateGestureScrollUpdateEvent(5, 5, 1);
723 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
724 EXPECT_EQ(2U, GestureEventQueueSize());
726 SimulateGesturePinchUpdateEvent(3, 60, 60, 1);
727 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
728 EXPECT_EQ(3U, GestureEventQueueSize());
730 SimulateGestureScrollUpdateEvent(10, 15, 1);
731 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
732 EXPECT_EQ(3U, GestureEventQueueSize());
734 SimulateGesturePinchUpdateEvent(4, 60, 60, 1);
735 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
736 EXPECT_EQ(3U, GestureEventQueueSize());
738 // Using different modifiers should prevent coalescing.
739 SimulateGesturePinchUpdateEvent(5, 60, 60, 2);
740 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
741 EXPECT_EQ(4U, GestureEventQueueSize());
743 SimulateGesturePinchUpdateEvent(6, 60, 60, 3);
744 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
745 EXPECT_EQ(5U, GestureEventQueueSize());
747 SendInputEventACK(WebInputEvent::GestureTapCancel,
748 INPUT_EVENT_ACK_STATE_CONSUMED);
749 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
750 EXPECT_EQ(4U, GestureEventQueueSize());
752 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
753 INPUT_EVENT_ACK_STATE_CONSUMED);
754 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
755 EXPECT_EQ(3U, GestureEventQueueSize());
757 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
758 INPUT_EVENT_ACK_STATE_CONSUMED);
759 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
760 EXPECT_EQ(3.f * 4.f, last_acked_event().data.pinchUpdate.scale);
761 EXPECT_EQ(2U, GestureEventQueueSize());
762 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
764 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
765 INPUT_EVENT_ACK_STATE_CONSUMED);
766 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
767 EXPECT_EQ(5.f, last_acked_event().data.pinchUpdate.scale);
768 EXPECT_EQ(1U, GestureEventQueueSize());
769 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
771 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
772 INPUT_EVENT_ACK_STATE_CONSUMED);
773 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
774 EXPECT_EQ(6.f, last_acked_event().data.pinchUpdate.scale);
775 EXPECT_EQ(0U, GestureEventQueueSize());
778 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventsIdentity) {
779 // Insert an event to force queueing of gestures.
780 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
781 blink::WebGestureDeviceTouchscreen);
782 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
783 EXPECT_EQ(1U, GestureEventQueueSize());
785 // Ensure that coalescing yields an identity transform for any pinch/scroll
786 // pair combined with its inverse.
787 SimulateGestureScrollUpdateEvent(5, 5, 1);
788 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
789 EXPECT_EQ(2U, GestureEventQueueSize());
791 SimulateGesturePinchUpdateEvent(5, 10, 10, 1);
792 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
793 EXPECT_EQ(3U, GestureEventQueueSize());
795 SimulateGesturePinchUpdateEvent(.2f, 10, 10, 1);
796 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
797 EXPECT_EQ(3U, GestureEventQueueSize());
799 SimulateGestureScrollUpdateEvent(-5, -5, 1);
800 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
801 EXPECT_EQ(3U, GestureEventQueueSize());
803 SendInputEventACK(WebInputEvent::GestureTapCancel,
804 INPUT_EVENT_ACK_STATE_CONSUMED);
805 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
806 EXPECT_EQ(2U, GestureEventQueueSize());
808 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
809 INPUT_EVENT_ACK_STATE_CONSUMED);
810 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
811 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaX);
812 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaY);
814 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
815 INPUT_EVENT_ACK_STATE_CONSUMED);
816 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
817 EXPECT_EQ(1.f, last_acked_event().data.pinchUpdate.scale);
818 EXPECT_EQ(0U, GestureEventQueueSize());
820 // Insert an event to force queueing of gestures.
821 SimulateGestureEvent(WebInputEvent::GestureTapCancel,
822 blink::WebGestureDeviceTouchscreen);
823 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
824 EXPECT_EQ(1U, GestureEventQueueSize());
826 // Ensure that coalescing yields an identity transform for any pinch/scroll
827 // pair combined with its inverse.
828 SimulateGesturePinchUpdateEvent(2, 10, 10, 1);
829 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
830 EXPECT_EQ(2U, GestureEventQueueSize());
832 SimulateGestureScrollUpdateEvent(20, 20, 1);
833 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
834 EXPECT_EQ(3U, GestureEventQueueSize());
836 SimulateGesturePinchUpdateEvent(0.5f, 20, 20, 1);
837 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
838 EXPECT_EQ(3U, GestureEventQueueSize());
840 SimulateGestureScrollUpdateEvent(-5, -5, 1);
841 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
842 EXPECT_EQ(3U, GestureEventQueueSize());
844 SendInputEventACK(WebInputEvent::GestureTapCancel,
845 INPUT_EVENT_ACK_STATE_CONSUMED);
846 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
847 EXPECT_EQ(2U, GestureEventQueueSize());
849 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
850 INPUT_EVENT_ACK_STATE_CONSUMED);
851 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
852 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaX);
853 EXPECT_EQ(0.f, last_acked_event().data.scrollUpdate.deltaY);
855 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
856 INPUT_EVENT_ACK_STATE_CONSUMED);
857 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
858 EXPECT_EQ(1.f, last_acked_event().data.pinchUpdate.scale);
861 // Tests a single event with an synchronous ack.
862 TEST_F(GestureEventQueueTest, SimpleSyncAck) {
863 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
864 SimulateGestureEvent(WebInputEvent::GestureTapDown,
865 blink::WebGestureDeviceTouchscreen);
866 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
867 EXPECT_EQ(0U, GestureEventQueueSize());
868 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
871 // Tests an event with an synchronous ack which enqueues an additional event.
872 TEST_F(GestureEventQueueTest, SyncAckQueuesEvent) {
873 scoped_ptr<WebGestureEvent> queued_event;
874 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
875 set_sync_followup_event(WebInputEvent::GestureShowPress,
876 blink::WebGestureDeviceTouchscreen);
877 // This event enqueues the show press event.
878 SimulateGestureEvent(WebInputEvent::GestureTapDown,
879 blink::WebGestureDeviceTouchscreen);
880 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
881 EXPECT_EQ(1U, GestureEventQueueSize());
882 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
884 SendInputEventACK(WebInputEvent::GestureShowPress,
885 INPUT_EVENT_ACK_STATE_CONSUMED);
886 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
887 EXPECT_EQ(0U, GestureEventQueueSize());
888 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
891 // Tests an event with an async ack followed by an event with a sync ack.
892 TEST_F(GestureEventQueueTest, AsyncThenSyncAck) {
893 SimulateGestureEvent(WebInputEvent::GestureTapDown,
894 blink::WebGestureDeviceTouchscreen);
896 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
897 EXPECT_EQ(1U, GestureEventQueueSize());
898 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
900 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
901 blink::WebGestureDeviceTouchscreen);
902 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
903 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
904 EXPECT_EQ(2U, GestureEventQueueSize());
905 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount());
907 SendInputEventACK(WebInputEvent::GestureTapDown,
908 INPUT_EVENT_ACK_STATE_CONSUMED);
909 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
910 EXPECT_EQ(0U, GestureEventQueueSize());
911 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
914 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventWithSyncAck) {
915 // Simulate a pinch sequence.
916 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
917 blink::WebGestureDeviceTouchscreen);
918 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
919 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
920 blink::WebGestureDeviceTouchscreen);
921 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
923 SimulateGestureScrollUpdateEvent(8, -4, 1);
924 // Make sure that the queue contains what we think it should.
925 WebGestureEvent merged_event = GestureEventLastQueueEvent();
926 EXPECT_EQ(3U, GestureEventQueueSize());
927 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type);
929 // Coalesced without changing event order. Note anchor at (60, 60). Anchoring
930 // from a point that is not the origin should still give us the right scroll.
931 SimulateGesturePinchUpdateEvent(1.5, 60, 60, 1);
932 EXPECT_EQ(4U, GestureEventQueueSize());
934 SendInputEventACK(WebInputEvent::GestureScrollBegin,
935 INPUT_EVENT_ACK_STATE_CONSUMED);
936 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
937 EXPECT_EQ(3U, GestureEventQueueSize());
939 // Ack the PinchBegin, and schedule a synchronous ack for GestureScrollUpdate.
940 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED);
941 SendInputEventACK(WebInputEvent::GesturePinchBegin,
942 INPUT_EVENT_ACK_STATE_CONSUMED);
944 // Both GestureScrollUpdate and GesturePinchUpdate should have been sent.
945 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type);
946 EXPECT_EQ(1U, GestureEventQueueSize());
947 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
949 // Ack the final GesturePinchUpdate.
950 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
951 INPUT_EVENT_ACK_STATE_CONSUMED);
952 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type);
953 EXPECT_EQ(0U, GestureEventQueueSize());
954 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
957 #if GTEST_HAS_PARAM_TEST
958 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) {
959 WebGestureDevice source_device = GetParam();
961 // GFC without previous GFS is dropped.
962 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
963 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
964 EXPECT_EQ(0U, GestureEventQueueSize());
966 // GFC after previous GFS is dispatched and acked.
967 SimulateGestureFlingStartEvent(0, -10, source_device);
968 EXPECT_TRUE(FlingInProgress());
969 SendInputEventACK(WebInputEvent::GestureFlingStart,
970 INPUT_EVENT_ACK_STATE_CONSUMED);
971 RunUntilIdle();
972 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
973 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
974 EXPECT_FALSE(FlingInProgress());
975 EXPECT_EQ(2U, GetAndResetSentGestureEventCount());
976 SendInputEventACK(WebInputEvent::GestureFlingCancel,
977 INPUT_EVENT_ACK_STATE_CONSUMED);
978 RunUntilIdle();
979 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount());
980 EXPECT_EQ(0U, GestureEventQueueSize());
982 // GFC before previous GFS is acked.
983 SimulateGestureFlingStartEvent(0, -10, source_device);
984 EXPECT_TRUE(FlingInProgress());
985 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
986 EXPECT_FALSE(FlingInProgress());
987 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
988 EXPECT_EQ(2U, GestureEventQueueSize());
990 // Advance state realistically.
991 SendInputEventACK(WebInputEvent::GestureFlingStart,
992 INPUT_EVENT_ACK_STATE_CONSUMED);
993 RunUntilIdle();
994 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
995 SendInputEventACK(WebInputEvent::GestureFlingCancel,
996 INPUT_EVENT_ACK_STATE_CONSUMED);
997 RunUntilIdle();
998 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount());
999 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1000 EXPECT_EQ(0U, GestureEventQueueSize());
1002 // GFS is added to the queue if another event is pending
1003 SimulateGestureScrollUpdateEvent(8, -7, 0);
1004 SimulateGestureFlingStartEvent(0, -10, source_device);
1005 EXPECT_EQ(2U, GestureEventQueueSize());
1006 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1007 WebGestureEvent merged_event = GestureEventLastQueueEvent();
1008 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
1009 EXPECT_TRUE(FlingInProgress());
1010 EXPECT_EQ(2U, GestureEventQueueSize());
1012 // GFS in queue means that a GFC is added to the queue
1013 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1014 merged_event =GestureEventLastQueueEvent();
1015 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1016 EXPECT_FALSE(FlingInProgress());
1017 EXPECT_EQ(3U, GestureEventQueueSize());
1019 // Adding a second GFC is dropped.
1020 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1021 EXPECT_FALSE(FlingInProgress());
1022 EXPECT_EQ(3U, GestureEventQueueSize());
1024 // Adding another GFS will add it to the queue.
1025 SimulateGestureFlingStartEvent(0, -10, source_device);
1026 merged_event = GestureEventLastQueueEvent();
1027 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
1028 EXPECT_TRUE(FlingInProgress());
1029 EXPECT_EQ(4U, GestureEventQueueSize());
1031 // GFS in queue means that a GFC is added to the queue
1032 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1033 merged_event = GestureEventLastQueueEvent();
1034 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1035 EXPECT_FALSE(FlingInProgress());
1036 EXPECT_EQ(5U, GestureEventQueueSize());
1038 // Adding another GFC with a GFC already there is dropped.
1039 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
1040 merged_event = GestureEventLastQueueEvent();
1041 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
1042 EXPECT_FALSE(FlingInProgress());
1043 EXPECT_EQ(5U, GestureEventQueueSize());
1046 INSTANTIATE_TEST_CASE_P(AllSources,
1047 GestureEventQueueWithSourceTest,
1048 testing::Values(blink::WebGestureDeviceTouchscreen,
1049 blink::WebGestureDeviceTouchpad));
1050 #endif // GTEST_HAS_PARAM_TEST
1052 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the
1053 // debounce interval, that Scrolls are not and that the deferred events are
1054 // sent after that timer fires.
1055 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) {
1056 SetUpForDebounce(3);
1058 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1059 blink::WebGestureDeviceTouchscreen);
1060 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1061 EXPECT_EQ(1U, GestureEventQueueSize());
1062 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1063 EXPECT_TRUE(ScrollingInProgress());
1065 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1066 blink::WebGestureDeviceTouchscreen);
1067 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1068 EXPECT_EQ(2U, GestureEventQueueSize());
1069 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1070 EXPECT_TRUE(ScrollingInProgress());
1072 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1073 blink::WebGestureDeviceTouchscreen);
1074 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1075 EXPECT_EQ(2U, GestureEventQueueSize());
1076 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1078 SimulateGestureFlingStartEvent(0, 10, blink::WebGestureDeviceTouchscreen);
1079 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1080 EXPECT_EQ(2U, GestureEventQueueSize());
1081 EXPECT_EQ(2U, GestureEventDebouncingQueueSize());
1083 SimulateGestureEvent(WebInputEvent::GestureTapDown,
1084 blink::WebGestureDeviceTouchscreen);
1085 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1086 EXPECT_EQ(2U, GestureEventQueueSize());
1087 EXPECT_EQ(3U, GestureEventDebouncingQueueSize());
1089 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1090 FROM_HERE, base::MessageLoop::QuitClosure(),
1091 TimeDelta::FromMilliseconds(5));
1092 base::MessageLoop::current()->Run();
1094 // The deferred events are correctly queued in coalescing queue.
1095 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1096 EXPECT_EQ(5U, GestureEventQueueSize());
1097 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1098 EXPECT_FALSE(ScrollingInProgress());
1100 // Verify that the coalescing queue contains the correct events.
1101 WebInputEvent::Type expected[] = {
1102 WebInputEvent::GestureScrollUpdate,
1103 WebInputEvent::GestureScrollUpdate,
1104 WebInputEvent::GestureScrollEnd,
1105 WebInputEvent::GestureFlingStart};
1107 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
1108 i++) {
1109 WebGestureEvent merged_event = GestureEventQueueEventAt(i);
1110 EXPECT_EQ(expected[i], merged_event.type);
1114 // Test that non-scroll events are deferred while scrolling during the debounce
1115 // interval and are discarded if a GestureScrollUpdate event arrives before the
1116 // interval end.
1117 TEST_F(GestureEventQueueTest, DebounceDropsDeferredEvents) {
1118 SetUpForDebounce(3);
1120 EXPECT_FALSE(ScrollingInProgress());
1122 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1123 blink::WebGestureDeviceTouchscreen);
1124 EXPECT_EQ(1U, GetAndResetSentGestureEventCount());
1125 EXPECT_EQ(1U, GestureEventQueueSize());
1126 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1127 EXPECT_TRUE(ScrollingInProgress());
1129 // This event should get discarded.
1130 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1131 blink::WebGestureDeviceTouchscreen);
1132 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1133 EXPECT_EQ(1U, GestureEventQueueSize());
1134 EXPECT_EQ(1U, GestureEventDebouncingQueueSize());
1136 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1137 blink::WebGestureDeviceTouchscreen);
1138 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
1139 EXPECT_EQ(2U, GestureEventQueueSize());
1140 EXPECT_EQ(0U, GestureEventDebouncingQueueSize());
1141 EXPECT_TRUE(ScrollingInProgress());
1143 // Verify that the coalescing queue contains the correct events.
1144 WebInputEvent::Type expected[] = {
1145 WebInputEvent::GestureScrollUpdate,
1146 WebInputEvent::GestureScrollUpdate};
1148 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type);
1149 i++) {
1150 WebGestureEvent merged_event = GestureEventQueueEventAt(i);
1151 EXPECT_EQ(expected[i], merged_event.type);
1155 } // namespace content