| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 public TouchpadTapSuppressionControllerClient { | 27 public TouchpadTapSuppressionControllerClient { |
| 28 public: | 28 public: |
| 29 GestureEventQueueTest() | 29 GestureEventQueueTest() |
| 30 : acked_gesture_event_count_(0), | 30 : acked_gesture_event_count_(0), |
| 31 sent_gesture_event_count_(0) {} | 31 sent_gesture_event_count_(0) {} |
| 32 | 32 |
| 33 virtual ~GestureEventQueueTest() {} | 33 virtual ~GestureEventQueueTest() {} |
| 34 | 34 |
| 35 // testing::Test | 35 // testing::Test |
| 36 virtual void SetUp() OVERRIDE { | 36 virtual void SetUp() OVERRIDE { |
| 37 queue_.reset(new GestureEventQueue(this, this)); | 37 queue_.reset(new GestureEventQueue(this, this, DefaultConfig())); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual void TearDown() OVERRIDE { | 40 virtual void TearDown() OVERRIDE { |
| 41 // Process all pending tasks to avoid leaks. | 41 // Process all pending tasks to avoid leaks. |
| 42 RunUntilIdle(); | 42 RunUntilIdle(); |
| 43 queue_.reset(); | 43 queue_.reset(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // GestureEventQueueClient | 46 // GestureEventQueueClient |
| 47 virtual void SendGestureEventImmediately( | 47 virtual void SendGestureEventImmediately( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 if (sync_followup_event_) | 61 if (sync_followup_event_) |
| 62 SimulateGestureEvent(*sync_followup_event_.Pass()); | 62 SimulateGestureEvent(*sync_followup_event_.Pass()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // TouchpadTapSuppressionControllerClient | 65 // TouchpadTapSuppressionControllerClient |
| 66 virtual void SendMouseEventImmediately( | 66 virtual void SendMouseEventImmediately( |
| 67 const MouseEventWithLatencyInfo& event) OVERRIDE { | 67 const MouseEventWithLatencyInfo& event) OVERRIDE { |
| 68 } | 68 } |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 static GestureEventQueue::Config DefaultConfig() { |
| 72 return GestureEventQueue::Config(); |
| 73 } |
| 74 |
| 75 void SetUpForDebounce(int interval_ms) { |
| 76 queue()->set_debounce_interval_time_ms_for_testing(interval_ms); |
| 77 } |
| 71 | 78 |
| 72 // Returns the result of |GestureEventQueue::ShouldForward()|. | 79 // Returns the result of |GestureEventQueue::ShouldForward()|. |
| 73 bool SimulateGestureEvent(const WebGestureEvent& gesture) { | 80 bool SimulateGestureEvent(const WebGestureEvent& gesture) { |
| 74 GestureEventWithLatencyInfo gesture_with_latency(gesture, | 81 GestureEventWithLatencyInfo gesture_with_latency(gesture, |
| 75 ui::LatencyInfo()); | 82 ui::LatencyInfo()); |
| 76 if (queue()->ShouldForward(gesture_with_latency)) { | 83 if (queue()->ShouldForward(gesture_with_latency)) { |
| 77 SendGestureEventImmediately(gesture_with_latency); | 84 SendGestureEventImmediately(gesture_with_latency); |
| 78 return true; | 85 return true; |
| 79 } | 86 } |
| 80 return false; | 87 return false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 size_t GetAndResetAckedGestureEventCount() { | 137 size_t GetAndResetAckedGestureEventCount() { |
| 131 size_t count = acked_gesture_event_count_; | 138 size_t count = acked_gesture_event_count_; |
| 132 acked_gesture_event_count_ = 0; | 139 acked_gesture_event_count_ = 0; |
| 133 return count; | 140 return count; |
| 134 } | 141 } |
| 135 | 142 |
| 136 const WebGestureEvent& last_acked_event() const { | 143 const WebGestureEvent& last_acked_event() const { |
| 137 return last_acked_event_; | 144 return last_acked_event_; |
| 138 } | 145 } |
| 139 | 146 |
| 140 void DisableDebounce() { | |
| 141 queue()->set_debounce_enabled_for_testing(false); | |
| 142 } | |
| 143 | |
| 144 void set_debounce_interval_time_ms(int ms) { | |
| 145 queue()->set_debounce_interval_time_ms_for_testing(ms); | |
| 146 } | |
| 147 | |
| 148 void set_synchronous_ack(InputEventAckState ack_result) { | 147 void set_synchronous_ack(InputEventAckState ack_result) { |
| 149 sync_ack_result_.reset(new InputEventAckState(ack_result)); | 148 sync_ack_result_.reset(new InputEventAckState(ack_result)); |
| 150 } | 149 } |
| 151 | 150 |
| 152 void set_sync_followup_event(WebInputEvent::Type type, | 151 void set_sync_followup_event(WebInputEvent::Type type, |
| 153 WebGestureEvent::SourceDevice sourceDevice) { | 152 WebGestureEvent::SourceDevice sourceDevice) { |
| 154 sync_followup_event_.reset(new WebGestureEvent( | 153 sync_followup_event_.reset(new WebGestureEvent( |
| 155 SyntheticWebGestureEventBuilder::Build(type, sourceDevice))); | 154 SyntheticWebGestureEventBuilder::Build(type, sourceDevice))); |
| 156 } | 155 } |
| 157 | 156 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 203 |
| 205 #if GTEST_HAS_PARAM_TEST | 204 #if GTEST_HAS_PARAM_TEST |
| 206 // This is for tests that are to be run for all source devices. | 205 // This is for tests that are to be run for all source devices. |
| 207 class GestureEventQueueWithSourceTest | 206 class GestureEventQueueWithSourceTest |
| 208 : public GestureEventQueueTest, | 207 : public GestureEventQueueTest, |
| 209 public testing::WithParamInterface<WebGestureEvent::SourceDevice> { | 208 public testing::WithParamInterface<WebGestureEvent::SourceDevice> { |
| 210 }; | 209 }; |
| 211 #endif // GTEST_HAS_PARAM_TEST | 210 #endif // GTEST_HAS_PARAM_TEST |
| 212 | 211 |
| 213 TEST_F(GestureEventQueueTest, CoalescesScrollGestureEvents) { | 212 TEST_F(GestureEventQueueTest, CoalescesScrollGestureEvents) { |
| 214 // Turn off debounce handling for test isolation. | |
| 215 DisableDebounce(); | |
| 216 | |
| 217 // Test coalescing of only GestureScrollUpdate events. | 213 // Test coalescing of only GestureScrollUpdate events. |
| 218 // Simulate gesture events. | 214 // Simulate gesture events. |
| 219 | 215 |
| 220 // Sent. | 216 // Sent. |
| 221 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 217 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 222 WebGestureEvent::Touchscreen); | 218 WebGestureEvent::Touchscreen); |
| 223 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 219 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 224 | 220 |
| 225 // Enqueued. | 221 // Enqueued. |
| 226 SimulateGestureScrollUpdateEvent(8, -5, 0); | 222 SimulateGestureScrollUpdateEvent(8, -5, 0); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // After the final ack, the queue should be empty. | 278 // After the final ack, the queue should be empty. |
| 283 SendInputEventACK(WebInputEvent::GestureScrollEnd, | 279 SendInputEventACK(WebInputEvent::GestureScrollEnd, |
| 284 INPUT_EVENT_ACK_STATE_CONSUMED); | 280 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 285 RunUntilIdle(); | 281 RunUntilIdle(); |
| 286 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | 282 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); |
| 287 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 283 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 288 } | 284 } |
| 289 | 285 |
| 290 TEST_F(GestureEventQueueTest, | 286 TEST_F(GestureEventQueueTest, |
| 291 DoesNotCoalesceScrollGestureEventsFromDifferentDevices) { | 287 DoesNotCoalesceScrollGestureEventsFromDifferentDevices) { |
| 292 // Turn off debounce handling for test isolation. | |
| 293 DisableDebounce(); | |
| 294 | |
| 295 // Test that GestureScrollUpdate events from Touchscreen and Touchpad do not | 288 // Test that GestureScrollUpdate events from Touchscreen and Touchpad do not |
| 296 // coalesce. | 289 // coalesce. |
| 297 | 290 |
| 298 // Sent. | 291 // Sent. |
| 299 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 292 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 300 WebGestureEvent::Touchscreen); | 293 WebGestureEvent::Touchscreen); |
| 301 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 294 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 302 | 295 |
| 303 // Enqueued. | 296 // Enqueued. |
| 304 SimulateGestureScrollUpdateEvent(8, -5, 0); | 297 SimulateGestureScrollUpdateEvent(8, -5, 0); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 329 GestureEventLastQueueEvent().sourceDevice); | 322 GestureEventLastQueueEvent().sourceDevice); |
| 330 | 323 |
| 331 // Enqueued. | 324 // Enqueued. |
| 332 SimulateGestureScrollUpdateEvent(8, -7, 0); | 325 SimulateGestureScrollUpdateEvent(8, -7, 0); |
| 333 EXPECT_EQ(4U, GestureEventQueueSize()); | 326 EXPECT_EQ(4U, GestureEventQueueSize()); |
| 334 EXPECT_EQ(WebGestureEvent::Touchscreen, | 327 EXPECT_EQ(WebGestureEvent::Touchscreen, |
| 335 GestureEventLastQueueEvent().sourceDevice); | 328 GestureEventLastQueueEvent().sourceDevice); |
| 336 } | 329 } |
| 337 | 330 |
| 338 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEvents) { | 331 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEvents) { |
| 339 // Turn off debounce handling for test isolation. | |
| 340 DisableDebounce(); | |
| 341 | |
| 342 // Test coalescing of only GestureScrollUpdate events. | 332 // Test coalescing of only GestureScrollUpdate events. |
| 343 // Simulate gesture events. | 333 // Simulate gesture events. |
| 344 | 334 |
| 345 // Sent. | 335 // Sent. |
| 346 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 336 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 347 WebGestureEvent::Touchscreen); | 337 WebGestureEvent::Touchscreen); |
| 348 | 338 |
| 349 // Sent. | 339 // Sent. |
| 350 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 340 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 351 WebGestureEvent::Touchscreen); | 341 WebGestureEvent::Touchscreen); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // Check that the queue is empty after ACK and no events get sent. | 554 // Check that the queue is empty after ACK and no events get sent. |
| 565 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 555 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 566 INPUT_EVENT_ACK_STATE_CONSUMED); | 556 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 567 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type); | 557 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, last_acked_event().type); |
| 568 RunUntilIdle(); | 558 RunUntilIdle(); |
| 569 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 559 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 570 EXPECT_EQ(0U, GestureEventQueueSize()); | 560 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 571 } | 561 } |
| 572 | 562 |
| 573 TEST_F(GestureEventQueueTest, CoalescesMultiplePinchEventSequences) { | 563 TEST_F(GestureEventQueueTest, CoalescesMultiplePinchEventSequences) { |
| 574 // Turn off debounce handling for test isolation. | |
| 575 DisableDebounce(); | |
| 576 | |
| 577 // Simulate a pinch sequence. | 564 // Simulate a pinch sequence. |
| 578 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 565 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 579 WebGestureEvent::Touchscreen); | 566 WebGestureEvent::Touchscreen); |
| 580 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 567 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 581 WebGestureEvent::Touchscreen); | 568 WebGestureEvent::Touchscreen); |
| 582 | 569 |
| 583 SimulateGestureScrollUpdateEvent(8, -4, 1); | 570 SimulateGestureScrollUpdateEvent(8, -4, 1); |
| 584 // Make sure that the queue contains what we think it should. | 571 // Make sure that the queue contains what we think it should. |
| 585 WebGestureEvent merged_event = GestureEventLastQueueEvent(); | 572 WebGestureEvent merged_event = GestureEventLastQueueEvent(); |
| 586 size_t expected_events_in_queue = 3; | 573 size_t expected_events_in_queue = 3; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale); | 644 EXPECT_EQ(1.5, merged_event.data.pinchUpdate.scale); |
| 658 EXPECT_EQ(1, merged_event.modifiers); | 645 EXPECT_EQ(1, merged_event.modifiers); |
| 659 merged_event = GestureEventSecondFromLastQueueEvent(); | 646 merged_event = GestureEventSecondFromLastQueueEvent(); |
| 660 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); | 647 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); |
| 661 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX); | 648 EXPECT_EQ(12, merged_event.data.scrollUpdate.deltaX); |
| 662 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY); | 649 EXPECT_EQ(-6, merged_event.data.scrollUpdate.deltaY); |
| 663 EXPECT_EQ(1, merged_event.modifiers); | 650 EXPECT_EQ(1, merged_event.modifiers); |
| 664 } | 651 } |
| 665 | 652 |
| 666 TEST_F(GestureEventQueueTest, CoalescesPinchSequencesWithEarlyAck) { | 653 TEST_F(GestureEventQueueTest, CoalescesPinchSequencesWithEarlyAck) { |
| 667 // Turn off debounce handling for test isolation. | |
| 668 DisableDebounce(); | |
| 669 | |
| 670 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 654 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 671 WebGestureEvent::Touchscreen); | 655 WebGestureEvent::Touchscreen); |
| 672 SendInputEventACK(WebInputEvent::GestureScrollBegin, | 656 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
| 673 INPUT_EVENT_ACK_STATE_CONSUMED); | 657 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 674 | 658 |
| 675 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 659 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 676 WebGestureEvent::Touchscreen); | 660 WebGestureEvent::Touchscreen); |
| 677 SendInputEventACK(WebInputEvent::GesturePinchBegin, | 661 SendInputEventACK(WebInputEvent::GesturePinchBegin, |
| 678 INPUT_EVENT_ACK_STATE_CONSUMED); | 662 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 679 // ScrollBegin and PinchBegin have been sent | 663 // ScrollBegin and PinchBegin have been sent |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 707 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
| 724 INPUT_EVENT_ACK_STATE_CONSUMED); | 708 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 725 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); | 709 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); |
| 726 EXPECT_EQ(2.f * 3.f * 4.f, last_acked_event().data.pinchUpdate.scale); | 710 EXPECT_EQ(2.f * 3.f * 4.f, last_acked_event().data.pinchUpdate.scale); |
| 727 | 711 |
| 728 EXPECT_EQ(0U, GestureEventQueueSize()); | 712 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 729 } | 713 } |
| 730 | 714 |
| 731 TEST_F(GestureEventQueueTest, | 715 TEST_F(GestureEventQueueTest, |
| 732 DoesNotCoalescePinchGestureEventsWithDifferentModifiers) { | 716 DoesNotCoalescePinchGestureEventsWithDifferentModifiers) { |
| 733 // Turn off debounce handling for test isolation. | |
| 734 DisableDebounce(); | |
| 735 | |
| 736 // Insert an event to force queueing of gestures. | 717 // Insert an event to force queueing of gestures. |
| 737 SimulateGestureEvent(WebInputEvent::GestureTapCancel, | 718 SimulateGestureEvent(WebInputEvent::GestureTapCancel, |
| 738 WebGestureEvent::Touchscreen); | 719 WebGestureEvent::Touchscreen); |
| 739 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 720 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 740 EXPECT_EQ(1U, GestureEventQueueSize()); | 721 EXPECT_EQ(1U, GestureEventQueueSize()); |
| 741 | 722 |
| 742 SimulateGestureScrollUpdateEvent(5, 5, 1); | 723 SimulateGestureScrollUpdateEvent(5, 5, 1); |
| 743 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 724 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 744 EXPECT_EQ(2U, GestureEventQueueSize()); | 725 EXPECT_EQ(2U, GestureEventQueueSize()); |
| 745 | 726 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 770 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 790 | 771 |
| 791 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 772 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
| 792 INPUT_EVENT_ACK_STATE_CONSUMED); | 773 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 793 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); | 774 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); |
| 794 EXPECT_EQ(6.f, last_acked_event().data.pinchUpdate.scale); | 775 EXPECT_EQ(6.f, last_acked_event().data.pinchUpdate.scale); |
| 795 EXPECT_EQ(0U, GestureEventQueueSize()); | 776 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 796 } | 777 } |
| 797 | 778 |
| 798 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventsIdentity) { | 779 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventsIdentity) { |
| 799 // Turn off debounce handling for test isolation. | |
| 800 DisableDebounce(); | |
| 801 | |
| 802 // Insert an event to force queueing of gestures. | 780 // Insert an event to force queueing of gestures. |
| 803 SimulateGestureEvent(WebInputEvent::GestureTapCancel, | 781 SimulateGestureEvent(WebInputEvent::GestureTapCancel, |
| 804 WebGestureEvent::Touchscreen); | 782 WebGestureEvent::Touchscreen); |
| 805 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 783 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 806 EXPECT_EQ(1U, GestureEventQueueSize()); | 784 EXPECT_EQ(1U, GestureEventQueueSize()); |
| 807 | 785 |
| 808 // Ensure that coalescing yields an identity transform for any pinch/scroll | 786 // Ensure that coalescing yields an identity transform for any pinch/scroll |
| 809 // pair combined with its inverse. | 787 // pair combined with its inverse. |
| 810 SimulateGestureScrollUpdateEvent(5, 5, 1); | 788 SimulateGestureScrollUpdateEvent(5, 5, 1); |
| 811 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 789 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 | 884 |
| 907 SendInputEventACK(WebInputEvent::GestureShowPress, | 885 SendInputEventACK(WebInputEvent::GestureShowPress, |
| 908 INPUT_EVENT_ACK_STATE_CONSUMED); | 886 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 909 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 887 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 910 EXPECT_EQ(0U, GestureEventQueueSize()); | 888 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 911 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | 889 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); |
| 912 } | 890 } |
| 913 | 891 |
| 914 // Tests an event with an async ack followed by an event with a sync ack. | 892 // Tests an event with an async ack followed by an event with a sync ack. |
| 915 TEST_F(GestureEventQueueTest, AsyncThenSyncAck) { | 893 TEST_F(GestureEventQueueTest, AsyncThenSyncAck) { |
| 916 // Turn off debounce handling for test isolation. | |
| 917 DisableDebounce(); | |
| 918 | |
| 919 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 894 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 920 WebGestureEvent::Touchscreen); | 895 WebGestureEvent::Touchscreen); |
| 921 | 896 |
| 922 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 897 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 923 EXPECT_EQ(1U, GestureEventQueueSize()); | 898 EXPECT_EQ(1U, GestureEventQueueSize()); |
| 924 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount()); | 899 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount()); |
| 925 | 900 |
| 926 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 901 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 927 WebGestureEvent::Touchscreen); | 902 WebGestureEvent::Touchscreen); |
| 928 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED); | 903 set_synchronous_ack(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 929 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 904 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 930 EXPECT_EQ(2U, GestureEventQueueSize()); | 905 EXPECT_EQ(2U, GestureEventQueueSize()); |
| 931 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount()); | 906 EXPECT_EQ(0U, GetAndResetAckedGestureEventCount()); |
| 932 | 907 |
| 933 SendInputEventACK(WebInputEvent::GestureTapDown, | 908 SendInputEventACK(WebInputEvent::GestureTapDown, |
| 934 INPUT_EVENT_ACK_STATE_CONSUMED); | 909 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 935 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 910 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 936 EXPECT_EQ(0U, GestureEventQueueSize()); | 911 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 937 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount()); | 912 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount()); |
| 938 } | 913 } |
| 939 | 914 |
| 940 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventWithSyncAck) { | 915 TEST_F(GestureEventQueueTest, CoalescesScrollAndPinchEventWithSyncAck) { |
| 941 // Turn off debounce handling for test isolation. | |
| 942 DisableDebounce(); | |
| 943 | |
| 944 // Simulate a pinch sequence. | 916 // Simulate a pinch sequence. |
| 945 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 917 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 946 WebGestureEvent::Touchscreen); | 918 WebGestureEvent::Touchscreen); |
| 947 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 919 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 948 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 920 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 949 WebGestureEvent::Touchscreen); | 921 WebGestureEvent::Touchscreen); |
| 950 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 922 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 951 | 923 |
| 952 SimulateGestureScrollUpdateEvent(8, -4, 1); | 924 SimulateGestureScrollUpdateEvent(8, -4, 1); |
| 953 // Make sure that the queue contains what we think it should. | 925 // Make sure that the queue contains what we think it should. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 980 INPUT_EVENT_ACK_STATE_CONSUMED); | 952 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 981 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); | 953 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, last_acked_event().type); |
| 982 EXPECT_EQ(0U, GestureEventQueueSize()); | 954 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 983 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 955 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 984 } | 956 } |
| 985 | 957 |
| 986 #if GTEST_HAS_PARAM_TEST | 958 #if GTEST_HAS_PARAM_TEST |
| 987 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) { | 959 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) { |
| 988 WebGestureEvent::SourceDevice source_device = GetParam(); | 960 WebGestureEvent::SourceDevice source_device = GetParam(); |
| 989 | 961 |
| 990 // Turn off debounce handling for test isolation. | |
| 991 DisableDebounce(); | |
| 992 // GFC without previous GFS is dropped. | 962 // GFC without previous GFS is dropped. |
| 993 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 963 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 994 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 964 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 995 EXPECT_EQ(0U, GestureEventQueueSize()); | 965 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 996 | 966 |
| 997 // GFC after previous GFS is dispatched and acked. | 967 // GFC after previous GFS is dispatched and acked. |
| 998 SimulateGestureFlingStartEvent(0, -10, source_device); | 968 SimulateGestureFlingStartEvent(0, -10, source_device); |
| 999 EXPECT_TRUE(FlingInProgress()); | 969 EXPECT_TRUE(FlingInProgress()); |
| 1000 SendInputEventACK(WebInputEvent::GestureFlingStart, | 970 SendInputEventACK(WebInputEvent::GestureFlingStart, |
| 1001 INPUT_EVENT_ACK_STATE_CONSUMED); | 971 INPUT_EVENT_ACK_STATE_CONSUMED); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 INSTANTIATE_TEST_CASE_P(AllSources, | 1047 INSTANTIATE_TEST_CASE_P(AllSources, |
| 1078 GestureEventQueueWithSourceTest, | 1048 GestureEventQueueWithSourceTest, |
| 1079 testing::Values(WebGestureEvent::Touchscreen, | 1049 testing::Values(WebGestureEvent::Touchscreen, |
| 1080 WebGestureEvent::Touchpad)); | 1050 WebGestureEvent::Touchpad)); |
| 1081 #endif // GTEST_HAS_PARAM_TEST | 1051 #endif // GTEST_HAS_PARAM_TEST |
| 1082 | 1052 |
| 1083 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the | 1053 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the |
| 1084 // debounce interval, that Scrolls are not and that the deferred events are | 1054 // debounce interval, that Scrolls are not and that the deferred events are |
| 1085 // sent after that timer fires. | 1055 // sent after that timer fires. |
| 1086 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) { | 1056 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) { |
| 1087 set_debounce_interval_time_ms(3); | 1057 SetUpForDebounce(3); |
| 1088 | 1058 |
| 1089 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1059 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1090 WebGestureEvent::Touchscreen); | 1060 WebGestureEvent::Touchscreen); |
| 1091 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 1061 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1092 EXPECT_EQ(1U, GestureEventQueueSize()); | 1062 EXPECT_EQ(1U, GestureEventQueueSize()); |
| 1093 EXPECT_EQ(0U, GestureEventDebouncingQueueSize()); | 1063 EXPECT_EQ(0U, GestureEventDebouncingQueueSize()); |
| 1094 EXPECT_TRUE(ScrollingInProgress()); | 1064 EXPECT_TRUE(ScrollingInProgress()); |
| 1095 | 1065 |
| 1096 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1066 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1097 WebGestureEvent::Touchscreen); | 1067 WebGestureEvent::Touchscreen); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 i++) { | 1110 i++) { |
| 1141 WebGestureEvent merged_event = GestureEventQueueEventAt(i); | 1111 WebGestureEvent merged_event = GestureEventQueueEventAt(i); |
| 1142 EXPECT_EQ(expected[i], merged_event.type); | 1112 EXPECT_EQ(expected[i], merged_event.type); |
| 1143 } | 1113 } |
| 1144 } | 1114 } |
| 1145 | 1115 |
| 1146 // Test that non-scroll events are deferred while scrolling during the debounce | 1116 // Test that non-scroll events are deferred while scrolling during the debounce |
| 1147 // interval and are discarded if a GestureScrollUpdate event arrives before the | 1117 // interval and are discarded if a GestureScrollUpdate event arrives before the |
| 1148 // interval end. | 1118 // interval end. |
| 1149 TEST_F(GestureEventQueueTest, DebounceDropsDeferredEvents) { | 1119 TEST_F(GestureEventQueueTest, DebounceDropsDeferredEvents) { |
| 1150 set_debounce_interval_time_ms(3); | 1120 SetUpForDebounce(3); |
| 1121 |
| 1151 EXPECT_FALSE(ScrollingInProgress()); | 1122 EXPECT_FALSE(ScrollingInProgress()); |
| 1152 | 1123 |
| 1153 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1124 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1154 WebGestureEvent::Touchscreen); | 1125 WebGestureEvent::Touchscreen); |
| 1155 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 1126 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1156 EXPECT_EQ(1U, GestureEventQueueSize()); | 1127 EXPECT_EQ(1U, GestureEventQueueSize()); |
| 1157 EXPECT_EQ(0U, GestureEventDebouncingQueueSize()); | 1128 EXPECT_EQ(0U, GestureEventDebouncingQueueSize()); |
| 1158 EXPECT_TRUE(ScrollingInProgress()); | 1129 EXPECT_TRUE(ScrollingInProgress()); |
| 1159 | 1130 |
| 1160 // This event should get discarded. | 1131 // This event should get discarded. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1190 gesture_event.data.flingStart.velocityX = 0.f; | 1161 gesture_event.data.flingStart.velocityX = 0.f; |
| 1191 gesture_event.data.flingStart.velocityY = 0.f; | 1162 gesture_event.data.flingStart.velocityY = 0.f; |
| 1192 ASSERT_EQ(0U, GetAndResetSentGestureEventCount()); | 1163 ASSERT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 1193 ASSERT_EQ(0U, GestureEventQueueSize()); | 1164 ASSERT_EQ(0U, GestureEventQueueSize()); |
| 1194 EXPECT_FALSE(SimulateGestureEvent(gesture_event)); | 1165 EXPECT_FALSE(SimulateGestureEvent(gesture_event)); |
| 1195 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 1166 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 1196 EXPECT_EQ(0U, GestureEventQueueSize()); | 1167 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 1197 } | 1168 } |
| 1198 | 1169 |
| 1199 } // namespace content | 1170 } // namespace content |
| OLD | NEW |