Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: content/browser/renderer_host/input/touch_event_queue_unittest.cc

Issue 188833004: [Android] Properly disable the touch ack timeout during a touch sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_log_verbose
Patch Set: Timeout tweaks Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/input/touch_event_queue.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "content/common/input/synthetic_web_input_event_builders.h" 11 #include "content/common/input/synthetic_web_input_event_builders.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h" 13 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 14
15 using blink::WebGestureEvent; 15 using blink::WebGestureEvent;
16 using blink::WebInputEvent; 16 using blink::WebInputEvent;
17 using blink::WebTouchEvent; 17 using blink::WebTouchEvent;
18 using blink::WebTouchPoint; 18 using blink::WebTouchPoint;
19 19
20 namespace content { 20 namespace content {
21 namespace { 21 namespace {
22 const size_t kDefaultTouchTimeoutDelayMs = 10; 22 base::TimeDelta DefaultTouchTimeoutDelay() {
23 return base::TimeDelta::FromMilliseconds(1);
23 } 24 }
25 } // namespace
24 26
25 class TouchEventQueueTest : public testing::Test, 27 class TouchEventQueueTest : public testing::Test,
26 public TouchEventQueueClient { 28 public TouchEventQueueClient {
27 public: 29 public:
28 TouchEventQueueTest() 30 TouchEventQueueTest()
29 : sent_event_count_(0), 31 : sent_event_count_(0),
30 acked_event_count_(0), 32 acked_event_count_(0),
31 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), 33 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
32 slop_length_dips_(0), 34 slop_length_dips_(0),
33 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {} 35 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 scoped_ptr<WebGestureEvent> followup_gesture_event = 74 scoped_ptr<WebGestureEvent> followup_gesture_event =
73 followup_gesture_event_.Pass(); 75 followup_gesture_event_.Pass();
74 queue_->OnGestureScrollEvent( 76 queue_->OnGestureScrollEvent(
75 GestureEventWithLatencyInfo(*followup_gesture_event, 77 GestureEventWithLatencyInfo(*followup_gesture_event,
76 ui::LatencyInfo())); 78 ui::LatencyInfo()));
77 } 79 }
78 } 80 }
79 81
80 protected: 82 protected:
81 83
82 void SetUpForTimeoutTesting(size_t timeout_delay_ms) { 84 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) {
83 queue_->SetAckTimeoutEnabled(true, timeout_delay_ms); 85 queue_->SetAckTimeoutEnabled(true, timeout_delay);
84 } 86 }
85 87
86 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { 88 void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
87 slop_length_dips_ = slop_length_dips; 89 slop_length_dips_ = slop_length_dips;
88 ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_); 90 ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_);
89 } 91 }
90 92
91 void SendTouchEvent(const WebTouchEvent& event) { 93 void SendTouchEvent(const WebTouchEvent& event) {
92 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); 94 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo()));
93 } 95 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 164 }
163 165
164 bool IsPendingAckTouchStart() const { 166 bool IsPendingAckTouchStart() const {
165 return queue_->IsPendingAckTouchStart(); 167 return queue_->IsPendingAckTouchStart();
166 } 168 }
167 169
168 void OnHasTouchEventHandlers(bool has_handlers) { 170 void OnHasTouchEventHandlers(bool has_handlers) {
169 queue_->OnHasTouchEventHandlers(has_handlers); 171 queue_->OnHasTouchEventHandlers(has_handlers);
170 } 172 }
171 173
174 void SetAckTimeoutDisabled() {
175 queue_->SetAckTimeoutEnabled(false, base::TimeDelta());
176 }
177
178 bool IsTimeoutEnabled() {
179 return queue_->ack_timeout_enabled();
180 }
181
172 bool IsTimeoutRunning() { 182 bool IsTimeoutRunning() {
173 return queue_->IsTimeoutRunningForTesting(); 183 return queue_->IsTimeoutRunningForTesting();
174 } 184 }
175 185
176 size_t queued_event_count() const { 186 size_t queued_event_count() const {
177 return queue_->size(); 187 return queue_->size();
178 } 188 }
179 189
180 const WebTouchEvent& latest_event() const { 190 const WebTouchEvent& latest_event() const {
181 return queue_->GetLatestEventForTesting().event; 191 return queue_->GetLatestEventForTesting().event;
182 } 192 }
183 193
184 const WebTouchEvent& acked_event() const { 194 const WebTouchEvent& acked_event() const {
185 return last_acked_event_; 195 return last_acked_event_;
186 } 196 }
187 197
188 const WebTouchEvent& sent_event() const { 198 const WebTouchEvent& sent_event() const {
189 return last_sent_event_; 199 return last_sent_event_;
190 } 200 }
191 201
192 InputEventAckState acked_event_state() const { 202 InputEventAckState acked_event_state() const {
193 return last_acked_event_state_; 203 return last_acked_event_state_;
194 } 204 }
195 205
206 static void RunTasksAndWait(base::TimeDelta delay) {
207 base::MessageLoop::current()->PostDelayedTask(
208 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
209 base::MessageLoop::current()->Run();
210 }
211
196 private: 212 private:
197 void SendTouchEvent() { 213 void SendTouchEvent() {
198 SendTouchEvent(touch_event_); 214 SendTouchEvent(touch_event_);
199 touch_event_.ResetPoints(); 215 touch_event_.ResetPoints();
200 } 216 }
201 217
202 void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode, 218 void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode,
203 double slop_length_dips) { 219 double slop_length_dips) {
204 queue_.reset(new TouchEventQueue(this, mode, slop_length_dips)); 220 queue_.reset(new TouchEventQueue(this, mode, slop_length_dips));
205 queue_->OnHasTouchEventHandlers(true); 221 queue_->OnHasTouchEventHandlers(true);
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 EXPECT_TRUE(IsPendingAckTouchStart()); 979 EXPECT_TRUE(IsPendingAckTouchStart());
964 980
965 // Ack the touchstart for the third point (#4). 981 // Ack the touchstart for the third point (#4).
966 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 982 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
967 EXPECT_EQ(0U, queued_event_count()); 983 EXPECT_EQ(0U, queued_event_count());
968 EXPECT_FALSE(IsPendingAckTouchStart()); 984 EXPECT_FALSE(IsPendingAckTouchStart());
969 } 985 }
970 986
971 // Tests that the touch timeout is started when sending certain touch types. 987 // Tests that the touch timeout is started when sending certain touch types.
972 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) { 988 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) {
973 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 989 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
974 990
975 // Sending a TouchStart will start the timeout. 991 // Sending a TouchStart will start the timeout.
976 PressTouchPoint(0, 1); 992 PressTouchPoint(0, 1);
977 EXPECT_TRUE(IsTimeoutRunning()); 993 EXPECT_TRUE(IsTimeoutRunning());
978 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 994 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
979 EXPECT_FALSE(IsTimeoutRunning()); 995 EXPECT_FALSE(IsTimeoutRunning());
980 996
981 // A TouchMove should start the timeout. 997 // A TouchMove should start the timeout.
982 MoveTouchPoint(0, 5, 5); 998 MoveTouchPoint(0, 5, 5);
983 EXPECT_TRUE(IsTimeoutRunning()); 999 EXPECT_TRUE(IsTimeoutRunning());
(...skipping 13 matching lines...) Expand all
997 CancelTouchPoint(0); 1013 CancelTouchPoint(0);
998 EXPECT_FALSE(IsTimeoutRunning()); 1014 EXPECT_FALSE(IsTimeoutRunning());
999 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1015 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1000 EXPECT_FALSE(IsTimeoutRunning()); 1016 EXPECT_FALSE(IsTimeoutRunning());
1001 } 1017 }
1002 1018
1003 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout, 1019 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout,
1004 // disabling touch forwarding until the next TouchStart is received after 1020 // disabling touch forwarding until the next TouchStart is received after
1005 // the timeout events are ack'ed. 1021 // the timeout events are ack'ed.
1006 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { 1022 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) {
1007 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1023 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1008 1024
1009 // Queue a TouchStart. 1025 // Queue a TouchStart.
1010 GetAndResetSentEventCount(); 1026 GetAndResetSentEventCount();
1011 GetAndResetAckedEventCount(); 1027 GetAndResetAckedEventCount();
1012 PressTouchPoint(0, 1); 1028 PressTouchPoint(0, 1);
1013 ASSERT_EQ(1U, GetAndResetSentEventCount()); 1029 ASSERT_EQ(1U, GetAndResetSentEventCount());
1014 ASSERT_EQ(0U, GetAndResetAckedEventCount()); 1030 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1015 EXPECT_TRUE(IsTimeoutRunning()); 1031 EXPECT_TRUE(IsTimeoutRunning());
1016 1032
1017 // Delay the ack. 1033 // Delay the ack.
1018 base::MessageLoop::current()->PostDelayedTask( 1034 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1019 FROM_HERE,
1020 base::MessageLoop::QuitClosure(),
1021 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1022 base::MessageLoop::current()->Run();
1023 1035
1024 // The timeout should have fired, synthetically ack'ing the timed-out event. 1036 // The timeout should have fired, synthetically ack'ing the timed-out event.
1025 // TouchEvent forwarding is disabled until the ack is received for the 1037 // TouchEvent forwarding is disabled until the ack is received for the
1026 // timed-out event and the future cancel event. 1038 // timed-out event and the future cancel event.
1027 EXPECT_FALSE(IsTimeoutRunning()); 1039 EXPECT_FALSE(IsTimeoutRunning());
1028 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1040 EXPECT_EQ(0U, GetAndResetSentEventCount());
1029 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1041 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1030 1042
1031 // Ack'ing the original event should trigger a cancel event. 1043 // Ack'ing the original event should trigger a cancel event.
1032 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1044 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
(...skipping 18 matching lines...) Expand all
1051 1063
1052 // Subsequent events should be handled normally. 1064 // Subsequent events should be handled normally.
1053 PressTouchPoint(0, 1); 1065 PressTouchPoint(0, 1);
1054 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1066 EXPECT_EQ(1U, GetAndResetSentEventCount());
1055 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1067 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1056 } 1068 }
1057 1069
1058 // Tests that the timeout is never started if the renderer consumes 1070 // Tests that the timeout is never started if the renderer consumes
1059 // a TouchEvent from the current touch sequence. 1071 // a TouchEvent from the current touch sequence.
1060 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { 1072 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) {
1061 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1073 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1062 1074
1063 // Queue a TouchStart. 1075 // Queue a TouchStart.
1064 PressTouchPoint(0, 1); 1076 PressTouchPoint(0, 1);
1065 ASSERT_TRUE(IsTimeoutRunning()); 1077 ASSERT_TRUE(IsTimeoutRunning());
1066 1078
1067 // Mark the event as consumed. This should prevent the timeout from 1079 // Mark the event as consumed. This should prevent the timeout from
1068 // being activated on subsequent TouchEvents in this gesture. 1080 // being activated on subsequent TouchEvents in this gesture.
1069 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 1081 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1070 EXPECT_FALSE(IsTimeoutRunning()); 1082 EXPECT_FALSE(IsTimeoutRunning());
1071 1083
(...skipping 10 matching lines...) Expand all
1082 // A TouchEnd should not start the timeout. 1094 // A TouchEnd should not start the timeout.
1083 ReleaseTouchPoint(1); 1095 ReleaseTouchPoint(1);
1084 EXPECT_FALSE(IsTimeoutRunning()); 1096 EXPECT_FALSE(IsTimeoutRunning());
1085 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1097 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1086 1098
1087 // A TouchCancel should not start the timeout. 1099 // A TouchCancel should not start the timeout.
1088 CancelTouchPoint(0); 1100 CancelTouchPoint(0);
1089 EXPECT_FALSE(IsTimeoutRunning()); 1101 EXPECT_FALSE(IsTimeoutRunning());
1090 } 1102 }
1091 1103
1104 // Tests that the timeout is never started if the renderer consumes
1105 // a TouchEvent from the current touch sequence.
1106 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) {
1107 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1108
1109 // Queue a TouchStart.
1110 PressTouchPoint(0, 1);
1111 ASSERT_TRUE(IsTimeoutRunning());
1112
1113 // Send the ack immediately. The timeout should not have fired.
1114 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1115 EXPECT_FALSE(IsTimeoutRunning());
1116 EXPECT_TRUE(IsTimeoutEnabled());
1117 EXPECT_EQ(1U, GetAndResetSentEventCount());
1118 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1119
1120 // Now explicitly disable the timeout.
1121 SetAckTimeoutDisabled();
1122 EXPECT_FALSE(IsTimeoutRunning());
1123 EXPECT_FALSE(IsTimeoutEnabled());
1124
1125 // A TouchMove should not start or trigger the timeout.
1126 MoveTouchPoint(0, 5, 5);
1127 EXPECT_FALSE(IsTimeoutRunning());
1128 EXPECT_EQ(1U, GetAndResetSentEventCount());
1129 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1130 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1131 }
1132
1092 // Tests that the timeout is never started if the ack is synchronous. 1133 // Tests that the timeout is never started if the ack is synchronous.
1093 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { 1134 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) {
1094 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1135 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1095 1136
1096 // Queue a TouchStart. 1137 // Queue a TouchStart.
1097 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); 1138 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED);
1098 ASSERT_FALSE(IsTimeoutRunning()); 1139 ASSERT_FALSE(IsTimeoutRunning());
1099 PressTouchPoint(0, 1); 1140 PressTouchPoint(0, 1);
1100 EXPECT_FALSE(IsTimeoutRunning()); 1141 EXPECT_FALSE(IsTimeoutRunning());
1101 } 1142 }
1102 1143
1103 // Tests that the timeout is disabled if the touch handler disappears. 1144 // Tests that the timeout is disabled if the touch handler disappears.
1104 TEST_F(TouchEventQueueTest, TouchTimeoutStoppedIfTouchHandlerRemoved) { 1145 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) {
1105 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1146 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1106 1147
1107 // Queue a TouchStart. 1148 // Queue a TouchStart.
1108 PressTouchPoint(0, 1); 1149 PressTouchPoint(0, 1);
1109 ASSERT_TRUE(IsTimeoutRunning()); 1150 ASSERT_TRUE(IsTimeoutRunning());
1110 1151
1111 // Unload the touch handler. 1152 // Unload the touch handler.
1112 OnHasTouchEventHandlers(false); 1153 OnHasTouchEventHandlers(false);
1113 EXPECT_FALSE(IsTimeoutRunning()); 1154 EXPECT_FALSE(IsTimeoutRunning());
1114 } 1155 }
1115 1156
1157 // Tests that the timeout does not fire if explicitly disabled while an event
1158 // is in-flight.
1159 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) {
1160 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1161
1162 // Queue a TouchStart.
1163 PressTouchPoint(0, 1);
1164 ASSERT_TRUE(IsTimeoutRunning());
1165
1166 // Verify that disabling the timeout also turns off the timer.
1167 SetAckTimeoutDisabled();
1168 EXPECT_FALSE(IsTimeoutRunning());
1169 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1170 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1171 }
1172
1116 // Tests that a TouchCancel timeout plays nice when the timed out touch stream 1173 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1117 // turns into a scroll gesture sequence. 1174 // turns into a scroll gesture sequence.
1118 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { 1175 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) {
1119 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1176 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1120 1177
1121 // Queue a TouchStart. 1178 // Queue a TouchStart.
1122 PressTouchPoint(0, 1); 1179 PressTouchPoint(0, 1);
1123 EXPECT_TRUE(IsTimeoutRunning()); 1180 EXPECT_TRUE(IsTimeoutRunning());
1124 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1181 EXPECT_EQ(1U, GetAndResetSentEventCount());
1125 1182
1126 // The cancelled sequence may turn into a scroll gesture. 1183 // The cancelled sequence may turn into a scroll gesture.
1127 WebGestureEvent followup_scroll; 1184 WebGestureEvent followup_scroll;
1128 followup_scroll.type = WebInputEvent::GestureScrollBegin; 1185 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1129 SetFollowupEvent(followup_scroll); 1186 SetFollowupEvent(followup_scroll);
1130 1187
1131 // Delay the ack. 1188 // Delay the ack.
1132 base::MessageLoop::current()->PostDelayedTask( 1189 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1133 FROM_HERE,
1134 base::MessageLoop::QuitClosure(),
1135 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1136 base::MessageLoop::current()->Run();
1137 1190
1138 // The timeout should have fired, disabling touch forwarding until both acks 1191 // The timeout should have fired, disabling touch forwarding until both acks
1139 // are received, acking the timed out event. 1192 // are received, acking the timed out event.
1140 EXPECT_FALSE(IsTimeoutRunning()); 1193 EXPECT_FALSE(IsTimeoutRunning());
1141 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1194 EXPECT_EQ(0U, GetAndResetSentEventCount());
1142 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1195 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1143 1196
1144 // Ack the original event, triggering a TouchCancel. 1197 // Ack the original event, triggering a TouchCancel.
1145 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 1198 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1146 EXPECT_FALSE(IsTimeoutRunning()); 1199 EXPECT_FALSE(IsTimeoutRunning());
(...skipping 21 matching lines...) Expand all
1168 PressTouchPoint(0, 1); 1221 PressTouchPoint(0, 1);
1169 EXPECT_TRUE(IsTimeoutRunning()); 1222 EXPECT_TRUE(IsTimeoutRunning());
1170 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1223 EXPECT_EQ(1U, GetAndResetSentEventCount());
1171 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1224 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1172 } 1225 }
1173 1226
1174 // Tests that a TouchCancel timeout plays nice when the timed out touch stream 1227 // Tests that a TouchCancel timeout plays nice when the timed out touch stream
1175 // turns into a scroll gesture sequence, but the original event acks are 1228 // turns into a scroll gesture sequence, but the original event acks are
1176 // significantly delayed. 1229 // significantly delayed.
1177 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { 1230 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) {
1178 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1231 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1179 1232
1180 // Queue a TouchStart. 1233 // Queue a TouchStart.
1181 PressTouchPoint(0, 1); 1234 PressTouchPoint(0, 1);
1182 EXPECT_TRUE(IsTimeoutRunning()); 1235 EXPECT_TRUE(IsTimeoutRunning());
1183 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1236 EXPECT_EQ(1U, GetAndResetSentEventCount());
1184 1237
1185 // The cancelled sequence may turn into a scroll gesture. 1238 // The cancelled sequence may turn into a scroll gesture.
1186 WebGestureEvent followup_scroll; 1239 WebGestureEvent followup_scroll;
1187 followup_scroll.type = WebInputEvent::GestureScrollBegin; 1240 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1188 SetFollowupEvent(followup_scroll); 1241 SetFollowupEvent(followup_scroll);
1189 1242
1190 // Delay the ack. 1243 // Delay the ack.
1191 base::MessageLoop::current()->PostDelayedTask( 1244 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1192 FROM_HERE,
1193 base::MessageLoop::QuitClosure(),
1194 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1195 base::MessageLoop::current()->Run();
1196 1245
1197 // The timeout should have fired, disabling touch forwarding until both acks 1246 // The timeout should have fired, disabling touch forwarding until both acks
1198 // are received and acking the timed out event. 1247 // are received and acking the timed out event.
1199 EXPECT_FALSE(IsTimeoutRunning()); 1248 EXPECT_FALSE(IsTimeoutRunning());
1200 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1249 EXPECT_EQ(0U, GetAndResetSentEventCount());
1201 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1250 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1202 1251
1203 // Try to forward a touch event. 1252 // Try to forward a touch event.
1204 GetAndResetSentEventCount(); 1253 GetAndResetSentEventCount();
1205 GetAndResetAckedEventCount(); 1254 GetAndResetAckedEventCount();
(...skipping 22 matching lines...) Expand all
1228 EXPECT_EQ(0U, GetAndResetAckedEventCount()); 1277 EXPECT_EQ(0U, GetAndResetAckedEventCount());
1229 1278
1230 PressTouchPoint(0, 1); 1279 PressTouchPoint(0, 1);
1231 EXPECT_TRUE(IsTimeoutRunning()); 1280 EXPECT_TRUE(IsTimeoutRunning());
1232 EXPECT_EQ(1U, GetAndResetSentEventCount()); 1281 EXPECT_EQ(1U, GetAndResetSentEventCount());
1233 } 1282 }
1234 1283
1235 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if 1284 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if
1236 // the timed-out event had no consumer. 1285 // the timed-out event had no consumer.
1237 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { 1286 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) {
1238 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); 1287 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay());
1239 1288
1240 // Queue a TouchStart. 1289 // Queue a TouchStart.
1241 PressTouchPoint(0, 1); 1290 PressTouchPoint(0, 1);
1242 ASSERT_EQ(1U, GetAndResetSentEventCount()); 1291 ASSERT_EQ(1U, GetAndResetSentEventCount());
1243 ASSERT_EQ(0U, GetAndResetAckedEventCount()); 1292 ASSERT_EQ(0U, GetAndResetAckedEventCount());
1244 EXPECT_TRUE(IsTimeoutRunning()); 1293 EXPECT_TRUE(IsTimeoutRunning());
1245 1294
1246 // Delay the ack. 1295 // Delay the ack.
1247 base::MessageLoop::current()->PostDelayedTask( 1296 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2);
1248 FROM_HERE,
1249 base::MessageLoop::QuitClosure(),
1250 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2));
1251 base::MessageLoop::current()->Run();
1252 1297
1253 // The timeout should have fired, synthetically ack'ing the timed out event. 1298 // The timeout should have fired, synthetically ack'ing the timed out event.
1254 // TouchEvent forwarding is disabled until the original ack is received. 1299 // TouchEvent forwarding is disabled until the original ack is received.
1255 EXPECT_FALSE(IsTimeoutRunning()); 1300 EXPECT_FALSE(IsTimeoutRunning());
1256 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1301 EXPECT_EQ(0U, GetAndResetSentEventCount());
1257 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 1302 EXPECT_EQ(1U, GetAndResetAckedEventCount());
1258 1303
1259 // Touch events should not be forwarded until we receive the original ack. 1304 // Touch events should not be forwarded until we receive the original ack.
1260 MoveTouchPoint(0, 1, 1); 1305 MoveTouchPoint(0, 1, 1);
1261 ReleaseTouchPoint(0); 1306 ReleaseTouchPoint(0);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, 1551 SendGestureEventAck(WebInputEvent::GestureScrollUpdate,
1507 INPUT_EVENT_ACK_STATE_CONSUMED); 1552 INPUT_EVENT_ACK_STATE_CONSUMED);
1508 MoveTouchPoint(0, 20, 5); 1553 MoveTouchPoint(0, 20, 5);
1509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1554 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1510 EXPECT_EQ(0U, queued_event_count()); 1555 EXPECT_EQ(0U, queued_event_count());
1511 EXPECT_EQ(0U, GetAndResetSentEventCount()); 1556 EXPECT_EQ(0U, GetAndResetSentEventCount());
1512 } 1557 }
1513 } 1558 }
1514 1559
1515 } // namespace content 1560 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_event_queue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698