| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // TouchpadTapSuppressionControllerClient | 67 // TouchpadTapSuppressionControllerClient |
| 68 void SendMouseEventImmediately( | 68 void SendMouseEventImmediately( |
| 69 const MouseEventWithLatencyInfo& event) override {} | 69 const MouseEventWithLatencyInfo& event) override {} |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 static GestureEventQueue::Config DefaultConfig() { | 72 static GestureEventQueue::Config DefaultConfig() { |
| 73 return GestureEventQueue::Config(); | 73 return GestureEventQueue::Config(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void SetUpForGFCFilteringDisabled() { | |
| 77 GestureEventQueue::Config config; | |
| 78 config.enable_fling_cancel_filtering = false; | |
| 79 queue_.reset(new GestureEventQueue(this, this, config)); | |
| 80 } | |
| 81 | |
| 82 void SetUpForDebounce(int interval_ms) { | 76 void SetUpForDebounce(int interval_ms) { |
| 83 queue()->set_debounce_interval_time_ms_for_testing(interval_ms); | 77 queue()->set_debounce_interval_time_ms_for_testing(interval_ms); |
| 84 } | 78 } |
| 85 | 79 |
| 86 void SimulateGestureEvent(const WebGestureEvent& gesture) { | 80 void SimulateGestureEvent(const WebGestureEvent& gesture) { |
| 87 queue()->QueueEvent(GestureEventWithLatencyInfo(gesture)); | 81 queue()->QueueEvent(GestureEventWithLatencyInfo(gesture)); |
| 88 } | 82 } |
| 89 | 83 |
| 90 void SimulateGestureEvent(WebInputEvent::Type type, | 84 void SimulateGestureEvent(WebInputEvent::Type type, |
| 91 WebGestureDevice sourceDevice) { | 85 WebGestureDevice sourceDevice) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 166 } |
| 173 | 167 |
| 174 WebGestureEvent GestureEventQueueEventAt(int i) { | 168 WebGestureEvent GestureEventQueueEventAt(int i) { |
| 175 return queue()->coalesced_gesture_events_.at(i).event; | 169 return queue()->coalesced_gesture_events_.at(i).event; |
| 176 } | 170 } |
| 177 | 171 |
| 178 bool ScrollingInProgress() { | 172 bool ScrollingInProgress() { |
| 179 return queue()->scrolling_in_progress_; | 173 return queue()->scrolling_in_progress_; |
| 180 } | 174 } |
| 181 | 175 |
| 182 int ActiveFlingCount() { return queue()->active_fling_count_; } | 176 bool FlingInProgress() { return queue()->fling_in_progress_; } |
| 183 | 177 |
| 184 bool WillIgnoreNextACK() { | 178 bool WillIgnoreNextACK() { |
| 185 return queue()->ignore_next_ack_; | 179 return queue()->ignore_next_ack_; |
| 186 } | 180 } |
| 187 | 181 |
| 188 GestureEventQueue* queue() const { | 182 GestureEventQueue* queue() const { |
| 189 return queue_.get(); | 183 return queue_.get(); |
| 190 } | 184 } |
| 191 | 185 |
| 192 private: | 186 private: |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 | 953 |
| 960 #if GTEST_HAS_PARAM_TEST | 954 #if GTEST_HAS_PARAM_TEST |
| 961 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) { | 955 TEST_P(GestureEventQueueWithSourceTest, GestureFlingCancelsFiltered) { |
| 962 WebGestureDevice source_device = GetParam(); | 956 WebGestureDevice source_device = GetParam(); |
| 963 | 957 |
| 964 // GFC without previous GFS is dropped. | 958 // GFC without previous GFS is dropped. |
| 965 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 959 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 966 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 960 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 967 EXPECT_EQ(0U, GestureEventQueueSize()); | 961 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 968 | 962 |
| 969 // GFC after unconsumed fling is dropped. | |
| 970 SimulateGestureEvent(WebInputEvent::GestureFlingStart, source_device); | |
| 971 SendInputEventACK(WebInputEvent::GestureFlingStart, | |
| 972 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 973 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | |
| 974 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | |
| 975 EXPECT_EQ(0U, GestureEventQueueSize()); | |
| 976 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | |
| 977 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | |
| 978 EXPECT_EQ(0U, GestureEventQueueSize()); | |
| 979 | |
| 980 // GFC after fling has ended is dropped. | |
| 981 SimulateGestureEvent(WebInputEvent::GestureFlingStart, source_device); | |
| 982 SendInputEventACK(WebInputEvent::GestureFlingStart, | |
| 983 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 984 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | |
| 985 EXPECT_EQ(0U, GestureEventQueueSize()); | |
| 986 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | |
| 987 | |
| 988 EXPECT_EQ(1, ActiveFlingCount()); | |
| 989 queue()->DidStopFlinging(); | |
| 990 EXPECT_EQ(0, ActiveFlingCount()); | |
| 991 | |
| 992 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | |
| 993 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | |
| 994 EXPECT_EQ(0U, GestureEventQueueSize()); | |
| 995 | |
| 996 // GFC after previous GFS is dispatched and acked. | 963 // GFC after previous GFS is dispatched and acked. |
| 997 SimulateGestureFlingStartEvent(0, -10, source_device); | 964 SimulateGestureFlingStartEvent(0, -10, source_device); |
| 965 EXPECT_TRUE(FlingInProgress()); |
| 998 SendInputEventACK(WebInputEvent::GestureFlingStart, | 966 SendInputEventACK(WebInputEvent::GestureFlingStart, |
| 999 INPUT_EVENT_ACK_STATE_CONSUMED); | 967 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1000 EXPECT_EQ(1, ActiveFlingCount()); | |
| 1001 RunUntilIdle(); | 968 RunUntilIdle(); |
| 1002 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | 969 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); |
| 1003 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 970 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 1004 queue()->DidStopFlinging(); | 971 EXPECT_FALSE(FlingInProgress()); |
| 1005 EXPECT_EQ(0, ActiveFlingCount()); | |
| 1006 EXPECT_EQ(2U, GetAndResetSentGestureEventCount()); | 972 EXPECT_EQ(2U, GetAndResetSentGestureEventCount()); |
| 1007 SendInputEventACK(WebInputEvent::GestureFlingCancel, | 973 SendInputEventACK(WebInputEvent::GestureFlingCancel, |
| 1008 INPUT_EVENT_ACK_STATE_CONSUMED); | 974 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1009 RunUntilIdle(); | 975 RunUntilIdle(); |
| 1010 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); | 976 EXPECT_EQ(1U, GetAndResetAckedGestureEventCount()); |
| 1011 EXPECT_EQ(0U, GestureEventQueueSize()); | 977 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 1012 | 978 |
| 1013 // GFC before previous GFS is acked. | 979 // GFC before previous GFS is acked. |
| 1014 SimulateGestureFlingStartEvent(0, -10, source_device); | 980 SimulateGestureFlingStartEvent(0, -10, source_device); |
| 981 EXPECT_TRUE(FlingInProgress()); |
| 1015 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 982 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 983 EXPECT_FALSE(FlingInProgress()); |
| 1016 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 984 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1017 EXPECT_EQ(2U, GestureEventQueueSize()); | 985 EXPECT_EQ(2U, GestureEventQueueSize()); |
| 1018 | 986 |
| 1019 // Advance state realistically. | 987 // Advance state realistically. |
| 1020 SendInputEventACK(WebInputEvent::GestureFlingStart, | 988 SendInputEventACK(WebInputEvent::GestureFlingStart, |
| 1021 INPUT_EVENT_ACK_STATE_CONSUMED); | 989 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1022 RunUntilIdle(); | 990 RunUntilIdle(); |
| 1023 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 991 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1024 SendInputEventACK(WebInputEvent::GestureFlingCancel, | 992 SendInputEventACK(WebInputEvent::GestureFlingCancel, |
| 1025 INPUT_EVENT_ACK_STATE_CONSUMED); | 993 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1026 RunUntilIdle(); | 994 RunUntilIdle(); |
| 1027 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount()); | 995 EXPECT_EQ(2U, GetAndResetAckedGestureEventCount()); |
| 1028 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); | 996 EXPECT_EQ(0U, GetAndResetSentGestureEventCount()); |
| 1029 EXPECT_EQ(0U, GestureEventQueueSize()); | 997 EXPECT_EQ(0U, GestureEventQueueSize()); |
| 1030 | 998 |
| 1031 // GFS is added to the queue if another event is pending | 999 // GFS is added to the queue if another event is pending |
| 1032 SimulateGestureScrollUpdateEvent(8, -7, 0); | 1000 SimulateGestureScrollUpdateEvent(8, -7, 0); |
| 1033 SimulateGestureFlingStartEvent(0, -10, source_device); | 1001 SimulateGestureFlingStartEvent(0, -10, source_device); |
| 1034 EXPECT_EQ(2U, GestureEventQueueSize()); | 1002 EXPECT_EQ(2U, GestureEventQueueSize()); |
| 1035 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 1003 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1036 WebGestureEvent merged_event = GestureEventLastQueueEvent(); | 1004 WebGestureEvent merged_event = GestureEventLastQueueEvent(); |
| 1037 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); | 1005 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
| 1006 EXPECT_TRUE(FlingInProgress()); |
| 1038 EXPECT_EQ(2U, GestureEventQueueSize()); | 1007 EXPECT_EQ(2U, GestureEventQueueSize()); |
| 1039 | 1008 |
| 1040 // GFS in queue means that a GFC is added to the queue | 1009 // GFS in queue means that a GFC is added to the queue |
| 1041 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 1010 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 1042 merged_event =GestureEventLastQueueEvent(); | 1011 merged_event =GestureEventLastQueueEvent(); |
| 1043 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 1012 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 1013 EXPECT_FALSE(FlingInProgress()); |
| 1044 EXPECT_EQ(3U, GestureEventQueueSize()); | 1014 EXPECT_EQ(3U, GestureEventQueueSize()); |
| 1045 | 1015 |
| 1046 // Adding a second GFC is dropped. | 1016 // Adding a second GFC is dropped. |
| 1047 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 1017 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 1018 EXPECT_FALSE(FlingInProgress()); |
| 1048 EXPECT_EQ(3U, GestureEventQueueSize()); | 1019 EXPECT_EQ(3U, GestureEventQueueSize()); |
| 1049 | 1020 |
| 1050 // Adding another GFS will add it to the queue. | 1021 // Adding another GFS will add it to the queue. |
| 1051 SimulateGestureFlingStartEvent(0, -10, source_device); | 1022 SimulateGestureFlingStartEvent(0, -10, source_device); |
| 1052 merged_event = GestureEventLastQueueEvent(); | 1023 merged_event = GestureEventLastQueueEvent(); |
| 1053 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); | 1024 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
| 1025 EXPECT_TRUE(FlingInProgress()); |
| 1054 EXPECT_EQ(4U, GestureEventQueueSize()); | 1026 EXPECT_EQ(4U, GestureEventQueueSize()); |
| 1055 | 1027 |
| 1056 // GFS in queue means that a GFC is added to the queue | 1028 // GFS in queue means that a GFC is added to the queue |
| 1057 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 1029 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 1058 merged_event = GestureEventLastQueueEvent(); | 1030 merged_event = GestureEventLastQueueEvent(); |
| 1059 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 1031 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 1032 EXPECT_FALSE(FlingInProgress()); |
| 1060 EXPECT_EQ(5U, GestureEventQueueSize()); | 1033 EXPECT_EQ(5U, GestureEventQueueSize()); |
| 1061 | 1034 |
| 1062 // Adding another GFC with a GFC already there is dropped. | 1035 // Adding another GFC with a GFC already there is dropped. |
| 1063 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); | 1036 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device); |
| 1064 merged_event = GestureEventLastQueueEvent(); | 1037 merged_event = GestureEventLastQueueEvent(); |
| 1065 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 1038 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 1039 EXPECT_FALSE(FlingInProgress()); |
| 1066 EXPECT_EQ(5U, GestureEventQueueSize()); | 1040 EXPECT_EQ(5U, GestureEventQueueSize()); |
| 1067 } | 1041 } |
| 1068 | 1042 |
| 1069 INSTANTIATE_TEST_CASE_P(AllSources, | 1043 INSTANTIATE_TEST_CASE_P(AllSources, |
| 1070 GestureEventQueueWithSourceTest, | 1044 GestureEventQueueWithSourceTest, |
| 1071 testing::Values(blink::WebGestureDeviceTouchscreen, | 1045 testing::Values(blink::WebGestureDeviceTouchscreen, |
| 1072 blink::WebGestureDeviceTouchpad)); | 1046 blink::WebGestureDeviceTouchpad)); |
| 1073 #endif // GTEST_HAS_PARAM_TEST | 1047 #endif // GTEST_HAS_PARAM_TEST |
| 1074 | 1048 |
| 1075 TEST_F(GestureEventQueueTest, GestureFlingCancelFilteringDisabled) { | |
| 1076 SetUpForGFCFilteringDisabled(); | |
| 1077 | |
| 1078 // If so configured, GFC events should never be filtered, even if there are | |
| 1079 // no active flings. | |
| 1080 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, | |
| 1081 blink::WebGestureDeviceTouchscreen); | |
| 1082 EXPECT_EQ(0, ActiveFlingCount()); | |
| 1083 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | |
| 1084 EXPECT_EQ(1U, GestureEventQueueSize()); | |
| 1085 } | |
| 1086 | |
| 1087 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the | 1049 // Test that a GestureScrollEnd | GestureFlingStart are deferred during the |
| 1088 // debounce interval, that Scrolls are not and that the deferred events are | 1050 // debounce interval, that Scrolls are not and that the deferred events are |
| 1089 // sent after that timer fires. | 1051 // sent after that timer fires. |
| 1090 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) { | 1052 TEST_F(GestureEventQueueTest, DebounceDefersFollowingGestureEvents) { |
| 1091 SetUpForDebounce(3); | 1053 SetUpForDebounce(3); |
| 1092 | 1054 |
| 1093 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1055 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1094 blink::WebGestureDeviceTouchscreen); | 1056 blink::WebGestureDeviceTouchscreen); |
| 1095 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); | 1057 EXPECT_EQ(1U, GetAndResetSentGestureEventCount()); |
| 1096 EXPECT_EQ(1U, GestureEventQueueSize()); | 1058 EXPECT_EQ(1U, GestureEventQueueSize()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 WebInputEvent::GestureScrollUpdate}; | 1144 WebInputEvent::GestureScrollUpdate}; |
| 1183 | 1145 |
| 1184 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type); | 1146 for (unsigned i = 0; i < sizeof(expected) / sizeof(WebInputEvent::Type); |
| 1185 i++) { | 1147 i++) { |
| 1186 WebGestureEvent merged_event = GestureEventQueueEventAt(i); | 1148 WebGestureEvent merged_event = GestureEventQueueEventAt(i); |
| 1187 EXPECT_EQ(expected[i], merged_event.type); | 1149 EXPECT_EQ(expected[i], merged_event.type); |
| 1188 } | 1150 } |
| 1189 } | 1151 } |
| 1190 | 1152 |
| 1191 } // namespace content | 1153 } // namespace content |
| OLD | NEW |