| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/browser/renderer_host/input/timeout_monitor.h" | 9 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 10 #include "content/browser/renderer_host/input/touch_event_queue.h" | 10 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool IsPendingAckTouchStart() const { | 145 bool IsPendingAckTouchStart() const { |
| 146 return queue_->IsPendingAckTouchStart(); | 146 return queue_->IsPendingAckTouchStart(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void OnHasTouchEventHandlers(bool has_handlers) { | 149 void OnHasTouchEventHandlers(bool has_handlers) { |
| 150 queue_->OnHasTouchEventHandlers(has_handlers); | 150 queue_->OnHasTouchEventHandlers(has_handlers); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool WillForwardTouchEvents() { | |
| 154 return queue_->has_handlers_ && | |
| 155 !queue_->scroll_in_progress_ && | |
| 156 !queue_->HasTimeoutEvent(); | |
| 157 } | |
| 158 | |
| 159 bool IsTimeoutRunning() { | 153 bool IsTimeoutRunning() { |
| 160 return queue_->IsTimeoutRunningForTesting(); | 154 return queue_->IsTimeoutRunningForTesting(); |
| 161 } | 155 } |
| 162 | 156 |
| 163 size_t queued_event_count() const { | 157 size_t queued_event_count() const { |
| 164 return queue_->size(); | 158 return queue_->size(); |
| 165 } | 159 } |
| 166 | 160 |
| 167 const WebTouchEvent& latest_event() const { | 161 const WebTouchEvent& latest_event() const { |
| 168 return queue_->GetLatestEventForTesting().event; | 162 return queue_->GetLatestEventForTesting().event; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 251 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
| 258 | 252 |
| 259 // Flush the queue. The touch-event queue should now be emptied, but none of | 253 // Flush the queue. The touch-event queue should now be emptied, but none of |
| 260 // the queued touch-events should be sent to the renderer. | 254 // the queued touch-events should be sent to the renderer. |
| 261 OnHasTouchEventHandlers(false); | 255 OnHasTouchEventHandlers(false); |
| 262 EXPECT_EQ(0U, queued_event_count()); | 256 EXPECT_EQ(0U, queued_event_count()); |
| 263 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 257 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 264 EXPECT_EQ(31U, GetAndResetAckedEventCount()); | 258 EXPECT_EQ(31U, GetAndResetAckedEventCount()); |
| 265 } | 259 } |
| 266 | 260 |
| 261 // Tests that addition of a touch handler during a touch sequence will not cause |
| 262 // the remaining sequence to be forwarded. |
| 263 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) { |
| 264 OnHasTouchEventHandlers(false); |
| 265 |
| 266 // Send a touch-press event while there is no handler. |
| 267 PressTouchPoint(1, 1); |
| 268 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 269 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 270 EXPECT_EQ(0U, queued_event_count()); |
| 271 |
| 272 OnHasTouchEventHandlers(true); |
| 273 |
| 274 // The remaining touch sequence should not be forwarded. |
| 275 MoveTouchPoint(0, 5, 5); |
| 276 ReleaseTouchPoint(0); |
| 277 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 278 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 279 EXPECT_EQ(0U, queued_event_count()); |
| 280 |
| 281 // A new touch sequence should resume forwarding. |
| 282 PressTouchPoint(1, 1); |
| 283 EXPECT_EQ(1U, queued_event_count()); |
| 284 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 285 } |
| 286 |
| 267 // Tests that removal of a touch handler during a touch sequence will prevent | 287 // Tests that removal of a touch handler during a touch sequence will prevent |
| 268 // the remaining sequence from being forwarded, even if another touch handler is | 288 // the remaining sequence from being forwarded, even if another touch handler is |
| 269 // registered during the same touch sequence. | 289 // registered during the same touch sequence. |
| 270 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) { | 290 TEST_F(TouchEventQueueTest, ActiveSequenceDroppedWhenHandlersRemoved) { |
| 271 // Send a touch-press event. | 291 // Send a touch-press event. |
| 272 PressTouchPoint(1, 1); | 292 PressTouchPoint(1, 1); |
| 273 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 293 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 274 EXPECT_EQ(1U, queued_event_count()); | 294 EXPECT_EQ(1U, queued_event_count()); |
| 275 | 295 |
| 276 // Queue a touch-move event. | 296 // Queue a touch-move event. |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 736 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 717 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 737 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 718 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 738 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 719 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 739 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
| 720 } | 740 } |
| 721 | 741 |
| 722 // Tests basic TouchEvent forwarding suppression. | 742 // Tests basic TouchEvent forwarding suppression. |
| 723 TEST_F(TouchEventQueueTest, NoTouchBasic) { | 743 TEST_F(TouchEventQueueTest, NoTouchBasic) { |
| 724 // Disable TouchEvent forwarding. | 744 // Disable TouchEvent forwarding. |
| 725 OnHasTouchEventHandlers(false); | 745 OnHasTouchEventHandlers(false); |
| 726 MoveTouchPoint(0, 30, 5); | 746 PressTouchPoint(30, 5); |
| 727 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 747 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 728 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 748 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 729 | 749 |
| 730 // TouchMove should not be sent to renderer. | 750 // TouchMove should not be sent to renderer. |
| 731 MoveTouchPoint(0, 65, 10); | 751 MoveTouchPoint(0, 65, 10); |
| 732 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 752 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 733 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 753 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 734 | 754 |
| 735 // TouchEnd should not be sent to renderer. | 755 // TouchEnd should not be sent to renderer. |
| 736 ReleaseTouchPoint(0); | 756 ReleaseTouchPoint(0); |
| 737 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 757 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 738 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 758 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 739 | 759 |
| 740 // TouchStart should not be sent to renderer. | |
| 741 PressTouchPoint(5, 5); | |
| 742 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 743 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 744 | |
| 745 // Enable TouchEvent forwarding. | 760 // Enable TouchEvent forwarding. |
| 746 OnHasTouchEventHandlers(true); | 761 OnHasTouchEventHandlers(true); |
| 747 | 762 |
| 748 PressTouchPoint(80, 10); | 763 PressTouchPoint(80, 10); |
| 749 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 764 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 750 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 765 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 751 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 766 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 752 | 767 |
| 753 MoveTouchPoint(0, 80, 20); | 768 MoveTouchPoint(0, 80, 20); |
| 754 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 769 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 776 // Queue another TouchStart. | 791 // Queue another TouchStart. |
| 777 PressTouchPoint(20, 20); | 792 PressTouchPoint(20, 20); |
| 778 EXPECT_EQ(2U, queued_event_count()); | 793 EXPECT_EQ(2U, queued_event_count()); |
| 779 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 794 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 780 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 795 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
| 781 | 796 |
| 782 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. | 797 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. |
| 783 WebGestureEvent followup_scroll; | 798 WebGestureEvent followup_scroll; |
| 784 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 799 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 785 SetFollowupEvent(followup_scroll); | 800 SetFollowupEvent(followup_scroll); |
| 786 ASSERT_TRUE(WillForwardTouchEvents()); | |
| 787 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 801 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 788 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 789 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 802 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 790 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 803 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 791 EXPECT_EQ(2U, queued_event_count()); | 804 EXPECT_EQ(2U, queued_event_count()); |
| 792 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 805 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
| 793 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 806 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
| 794 | 807 |
| 795 // Acking the TouchCancel will result in dispatch of the next TouchStart. | 808 // Acking the TouchCancel will result in dispatch of the next TouchStart. |
| 796 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 809 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 797 // The synthetic TouchCancel should not reach client, only the TouchStart. | 810 // The synthetic TouchCancel should not reach client, only the TouchStart. |
| 798 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 811 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 799 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 812 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 800 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 813 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
| 801 | 814 |
| 802 // TouchMove should not be sent to the renderer. | 815 // TouchMove should not be sent to the renderer. |
| 803 MoveTouchPoint(0, 30, 5); | 816 MoveTouchPoint(0, 30, 5); |
| 804 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 817 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 805 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 818 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 806 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 819 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 807 | 820 |
| 808 // GestureScrollUpdates should not change affect touch forwarding. | 821 // GestureScrollUpdates should not change affect touch forwarding. |
| 809 SendGestureEvent(WebInputEvent::GestureScrollUpdate); | 822 SendGestureEvent(WebInputEvent::GestureScrollUpdate); |
| 810 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 811 | 823 |
| 812 // TouchEnd should not be sent to the renderer. | 824 // TouchEnd should not be sent to the renderer. |
| 813 ReleaseTouchPoint(0); | 825 ReleaseTouchPoint(0); |
| 814 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 826 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 815 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 827 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 816 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 828 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 817 | 829 |
| 818 // GestureScrollEnd will resume the sending of TouchEvents to renderer. | 830 ReleaseTouchPoint(0); |
| 819 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 831 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 820 EXPECT_TRUE(WillForwardTouchEvents()); | 832 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 833 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 821 | 834 |
| 822 // Now TouchEvents should be forwarded normally. | 835 // Touch events from a new gesture sequence should be forwarded normally. |
| 823 PressTouchPoint(80, 10); | 836 PressTouchPoint(80, 10); |
| 824 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 837 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 825 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 838 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 826 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 839 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 827 | 840 |
| 828 MoveTouchPoint(0, 80, 20); | 841 MoveTouchPoint(0, 80, 20); |
| 829 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 842 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 830 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 843 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 831 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 844 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 832 | 845 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { | 933 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { |
| 921 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 934 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 922 | 935 |
| 923 // Queue a TouchStart. | 936 // Queue a TouchStart. |
| 924 GetAndResetSentEventCount(); | 937 GetAndResetSentEventCount(); |
| 925 GetAndResetAckedEventCount(); | 938 GetAndResetAckedEventCount(); |
| 926 PressTouchPoint(0, 1); | 939 PressTouchPoint(0, 1); |
| 927 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 940 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 928 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 941 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 929 EXPECT_TRUE(IsTimeoutRunning()); | 942 EXPECT_TRUE(IsTimeoutRunning()); |
| 930 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 931 | 943 |
| 932 // Delay the ack. | 944 // Delay the ack. |
| 933 base::MessageLoop::current()->PostDelayedTask( | 945 base::MessageLoop::current()->PostDelayedTask( |
| 934 FROM_HERE, | 946 FROM_HERE, |
| 935 base::MessageLoop::QuitClosure(), | 947 base::MessageLoop::QuitClosure(), |
| 936 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | 948 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 937 base::MessageLoop::current()->Run(); | 949 base::MessageLoop::current()->Run(); |
| 938 | 950 |
| 939 // The timeout should have fired, synthetically ack'ing the timed-out event. | 951 // The timeout should have fired, synthetically ack'ing the timed-out event. |
| 940 // TouchEvent forwarding is disabled until the ack is received for the | 952 // TouchEvent forwarding is disabled until the ack is received for the |
| 941 // timed-out event and the future cancel event. | 953 // timed-out event and the future cancel event. |
| 942 EXPECT_FALSE(IsTimeoutRunning()); | 954 EXPECT_FALSE(IsTimeoutRunning()); |
| 943 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 944 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 955 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 945 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 956 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 946 | 957 |
| 947 // Ack'ing the original event should trigger a cancel event. | 958 // Ack'ing the original event should trigger a cancel event. |
| 948 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 959 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 949 EXPECT_FALSE(IsTimeoutRunning()); | 960 EXPECT_FALSE(IsTimeoutRunning()); |
| 950 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 951 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 961 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 952 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 962 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 953 | 963 |
| 954 // Touch events should not be forwarded until we receive the cancel acks. | 964 // Touch events should not be forwarded until we receive the cancel acks. |
| 955 PressTouchPoint(0, 1); | 965 MoveTouchPoint(0, 1, 1); |
| 956 ASSERT_EQ(0U, GetAndResetSentEventCount()); | 966 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 957 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 967 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 958 | 968 |
| 969 ReleaseTouchPoint(0); |
| 970 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 971 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 972 |
| 959 // The synthetic TouchCancel ack should not reach the client, but should | 973 // The synthetic TouchCancel ack should not reach the client, but should |
| 960 // resume touch forwarding. | 974 // resume touch forwarding. |
| 961 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 975 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 962 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 976 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 963 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 977 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 964 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 965 | 978 |
| 966 // Subsequent events should be handled normally. | 979 // Subsequent events should be handled normally. |
| 967 PressTouchPoint(0, 1); | 980 PressTouchPoint(0, 1); |
| 968 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 981 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 969 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 982 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 970 } | 983 } |
| 971 | 984 |
| 972 // Tests that the timeout is never started if the renderer consumes | 985 // Tests that the timeout is never started if the renderer consumes |
| 973 // a TouchEvent from the current touch sequence. | 986 // a TouchEvent from the current touch sequence. |
| 974 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { | 987 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 } | 1041 } |
| 1029 | 1042 |
| 1030 // Tests that a TouchCancel timeout plays nice when the timed out touch stream | 1043 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1031 // turns into a scroll gesture sequence. | 1044 // turns into a scroll gesture sequence. |
| 1032 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { | 1045 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { |
| 1033 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1046 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1034 | 1047 |
| 1035 // Queue a TouchStart. | 1048 // Queue a TouchStart. |
| 1036 PressTouchPoint(0, 1); | 1049 PressTouchPoint(0, 1); |
| 1037 EXPECT_TRUE(IsTimeoutRunning()); | 1050 EXPECT_TRUE(IsTimeoutRunning()); |
| 1038 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 1039 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1051 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1040 | 1052 |
| 1041 // The cancelled sequence may turn into a scroll gesture. | 1053 // The cancelled sequence may turn into a scroll gesture. |
| 1042 WebGestureEvent followup_scroll; | 1054 WebGestureEvent followup_scroll; |
| 1043 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1055 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1044 SetFollowupEvent(followup_scroll); | 1056 SetFollowupEvent(followup_scroll); |
| 1045 | 1057 |
| 1046 // Delay the ack. | 1058 // Delay the ack. |
| 1047 base::MessageLoop::current()->PostDelayedTask( | 1059 base::MessageLoop::current()->PostDelayedTask( |
| 1048 FROM_HERE, | 1060 FROM_HERE, |
| 1049 base::MessageLoop::QuitClosure(), | 1061 base::MessageLoop::QuitClosure(), |
| 1050 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | 1062 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1051 base::MessageLoop::current()->Run(); | 1063 base::MessageLoop::current()->Run(); |
| 1052 | 1064 |
| 1053 // The timeout should have fired, disabling touch forwarding until both acks | 1065 // The timeout should have fired, disabling touch forwarding until both acks |
| 1054 // are received, acking the timed out event. | 1066 // are received, acking the timed out event. |
| 1055 EXPECT_FALSE(IsTimeoutRunning()); | 1067 EXPECT_FALSE(IsTimeoutRunning()); |
| 1056 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 1057 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1068 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1058 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1069 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1059 | 1070 |
| 1060 // Ack the original event, triggering a TouchCancel. | 1071 // Ack the original event, triggering a TouchCancel. |
| 1061 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 1072 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1062 EXPECT_FALSE(IsTimeoutRunning()); | 1073 EXPECT_FALSE(IsTimeoutRunning()); |
| 1063 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 1064 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1074 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1065 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1075 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1066 | 1076 |
| 1067 // Ack the cancel event. Normally, this would resume touch forwarding, | 1077 // Ack the cancel event. Normally, this would resume touch forwarding, |
| 1068 // but we're still within a scroll gesture so it remains disabled. | 1078 // but we're still within a scroll gesture so it remains disabled. |
| 1069 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 1079 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1070 EXPECT_FALSE(IsTimeoutRunning()); | 1080 EXPECT_FALSE(IsTimeoutRunning()); |
| 1071 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 1072 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1081 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1073 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1082 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1074 | 1083 |
| 1075 // Try to forward a touch event. | 1084 // Try to forward touch events for the current sequence. |
| 1076 GetAndResetSentEventCount(); | 1085 GetAndResetSentEventCount(); |
| 1077 GetAndResetAckedEventCount(); | 1086 GetAndResetAckedEventCount(); |
| 1078 PressTouchPoint(0, 1); | 1087 MoveTouchPoint(0, 1, 1); |
| 1088 ReleaseTouchPoint(0); |
| 1079 EXPECT_FALSE(IsTimeoutRunning()); | 1089 EXPECT_FALSE(IsTimeoutRunning()); |
| 1080 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1090 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1081 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1091 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 1082 | 1092 |
| 1083 // Now end the scroll sequence, resuming touch handling. | 1093 // Now end the scroll sequence, resuming touch handling. |
| 1084 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 1094 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1085 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 1086 PressTouchPoint(0, 1); | 1095 PressTouchPoint(0, 1); |
| 1087 EXPECT_TRUE(IsTimeoutRunning()); | 1096 EXPECT_TRUE(IsTimeoutRunning()); |
| 1088 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1097 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1089 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1098 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1090 } | 1099 } |
| 1091 | 1100 |
| 1092 // Tests that a TouchCancel timeout plays nice when the timed out touch stream | 1101 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1093 // turns into a scroll gesture sequence, but the original event acks are | 1102 // turns into a scroll gesture sequence, but the original event acks are |
| 1094 // significantly delayed. | 1103 // significantly delayed. |
| 1095 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { | 1104 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { |
| 1096 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1105 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1097 | 1106 |
| 1098 // Queue a TouchStart. | 1107 // Queue a TouchStart. |
| 1099 PressTouchPoint(0, 1); | 1108 PressTouchPoint(0, 1); |
| 1100 EXPECT_TRUE(IsTimeoutRunning()); | 1109 EXPECT_TRUE(IsTimeoutRunning()); |
| 1101 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 1102 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1110 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1103 | 1111 |
| 1104 // The cancelled sequence may turn into a scroll gesture. | 1112 // The cancelled sequence may turn into a scroll gesture. |
| 1105 WebGestureEvent followup_scroll; | 1113 WebGestureEvent followup_scroll; |
| 1106 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1114 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1107 SetFollowupEvent(followup_scroll); | 1115 SetFollowupEvent(followup_scroll); |
| 1108 | 1116 |
| 1109 // Delay the ack. | 1117 // Delay the ack. |
| 1110 base::MessageLoop::current()->PostDelayedTask( | 1118 base::MessageLoop::current()->PostDelayedTask( |
| 1111 FROM_HERE, | 1119 FROM_HERE, |
| 1112 base::MessageLoop::QuitClosure(), | 1120 base::MessageLoop::QuitClosure(), |
| 1113 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | 1121 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1114 base::MessageLoop::current()->Run(); | 1122 base::MessageLoop::current()->Run(); |
| 1115 | 1123 |
| 1116 // The timeout should have fired, disabling touch forwarding until both acks | 1124 // The timeout should have fired, disabling touch forwarding until both acks |
| 1117 // are received and acking the timed out event. | 1125 // are received and acking the timed out event. |
| 1118 EXPECT_FALSE(IsTimeoutRunning()); | 1126 EXPECT_FALSE(IsTimeoutRunning()); |
| 1119 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 1120 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1127 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1121 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1128 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1122 | 1129 |
| 1123 // Try to forward a touch event. | 1130 // Try to forward a touch event. |
| 1124 GetAndResetSentEventCount(); | 1131 GetAndResetSentEventCount(); |
| 1125 GetAndResetAckedEventCount(); | 1132 GetAndResetAckedEventCount(); |
| 1126 PressTouchPoint(0, 1); | 1133 MoveTouchPoint(0, 1, 1); |
| 1127 EXPECT_FALSE(IsTimeoutRunning()); | 1134 EXPECT_FALSE(IsTimeoutRunning()); |
| 1128 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1135 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1129 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1136 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1130 | 1137 |
| 1131 // Now end the scroll sequence. Events will not be forwarded until the two | 1138 // Now end the scroll sequence. Events will not be forwarded until the two |
| 1132 // outstanding touch acks are received. | 1139 // outstanding touch acks are received. |
| 1133 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 1140 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1134 PressTouchPoint(0, 1); | 1141 MoveTouchPoint(0, 2, 2); |
| 1142 ReleaseTouchPoint(0); |
| 1135 EXPECT_FALSE(IsTimeoutRunning()); | 1143 EXPECT_FALSE(IsTimeoutRunning()); |
| 1136 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1144 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1137 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1145 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 1138 | 1146 |
| 1139 // Ack the original event, triggering a cancel. | 1147 // Ack the original event, triggering a cancel. |
| 1140 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 1148 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1141 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1149 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1142 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1150 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1143 | 1151 |
| 1144 // Ack the cancel event, resuming touch forwarding. | 1152 // Ack the cancel event, resuming touch forwarding. |
| 1145 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 1153 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1146 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1154 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1147 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1155 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1148 | 1156 |
| 1149 PressTouchPoint(0, 1); | 1157 PressTouchPoint(0, 1); |
| 1150 EXPECT_TRUE(IsTimeoutRunning()); | 1158 EXPECT_TRUE(IsTimeoutRunning()); |
| 1151 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1159 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1152 } | 1160 } |
| 1153 | 1161 |
| 1154 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if | 1162 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if |
| 1155 // the timed-out event had no consumer. | 1163 // the timed-out event had no consumer. |
| 1156 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { | 1164 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { |
| 1157 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1165 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1158 | 1166 |
| 1159 // Queue a TouchStart. | 1167 // Queue a TouchStart. |
| 1160 PressTouchPoint(0, 1); | 1168 PressTouchPoint(0, 1); |
| 1161 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1169 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1162 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 1170 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1163 EXPECT_TRUE(IsTimeoutRunning()); | 1171 EXPECT_TRUE(IsTimeoutRunning()); |
| 1164 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 1165 | 1172 |
| 1166 // Delay the ack. | 1173 // Delay the ack. |
| 1167 base::MessageLoop::current()->PostDelayedTask( | 1174 base::MessageLoop::current()->PostDelayedTask( |
| 1168 FROM_HERE, | 1175 FROM_HERE, |
| 1169 base::MessageLoop::QuitClosure(), | 1176 base::MessageLoop::QuitClosure(), |
| 1170 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | 1177 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1171 base::MessageLoop::current()->Run(); | 1178 base::MessageLoop::current()->Run(); |
| 1172 | 1179 |
| 1173 // The timeout should have fired, synthetically ack'ing the timed out event. | 1180 // The timeout should have fired, synthetically ack'ing the timed out event. |
| 1174 // TouchEvent forwarding is disabled until the original ack is received. | 1181 // TouchEvent forwarding is disabled until the original ack is received. |
| 1175 EXPECT_FALSE(IsTimeoutRunning()); | 1182 EXPECT_FALSE(IsTimeoutRunning()); |
| 1176 EXPECT_FALSE(WillForwardTouchEvents()); | |
| 1177 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1183 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1178 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1184 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1179 | 1185 |
| 1180 // Touch events should not be forwarded until we receive the original ack. | 1186 // Touch events should not be forwarded until we receive the original ack. |
| 1181 PressTouchPoint(0, 1); | 1187 MoveTouchPoint(0, 1, 1); |
| 1188 ReleaseTouchPoint(0); |
| 1182 ASSERT_EQ(0U, GetAndResetSentEventCount()); | 1189 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 1183 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1190 ASSERT_EQ(2U, GetAndResetAckedEventCount()); |
| 1184 | 1191 |
| 1185 // Ack'ing the original event should not trigger a cancel event, as the | 1192 // Ack'ing the original event should not trigger a cancel event, as the |
| 1186 // TouchStart had no consumer. However, it should re-enable touch forwarding. | 1193 // TouchStart had no consumer. However, it should re-enable touch forwarding. |
| 1187 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1194 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1188 EXPECT_FALSE(IsTimeoutRunning()); | 1195 EXPECT_FALSE(IsTimeoutRunning()); |
| 1189 EXPECT_TRUE(WillForwardTouchEvents()); | |
| 1190 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1196 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1191 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1197 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1192 | 1198 |
| 1193 // Subsequent events should be handled normally. | 1199 // Subsequent events should be handled normally. |
| 1194 PressTouchPoint(0, 1); | 1200 PressTouchPoint(0, 1); |
| 1195 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1201 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1196 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1202 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1197 } | 1203 } |
| 1198 } // namespace content | 1204 } // namespace content |
| OLD | NEW |