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