Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool IsPendingAckTouchStart() const { | 164 bool IsPendingAckTouchStart() const { |
| 165 return queue_->IsPendingAckTouchStart(); | 165 return queue_->IsPendingAckTouchStart(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void OnHasTouchEventHandlers(bool has_handlers) { | 168 void OnHasTouchEventHandlers(bool has_handlers) { |
| 169 queue_->OnHasTouchEventHandlers(has_handlers); | 169 queue_->OnHasTouchEventHandlers(has_handlers); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void SetAckTimeoutDisabled() { | |
| 173 queue_->SetAckTimeoutEnabled(false, 0); | |
| 174 } | |
| 175 | |
| 176 bool IsTimeoutEnabled() { | |
| 177 return queue_->ack_timeout_enabled(); | |
| 178 } | |
| 179 | |
| 172 bool IsTimeoutRunning() { | 180 bool IsTimeoutRunning() { |
| 173 return queue_->IsTimeoutRunningForTesting(); | 181 return queue_->IsTimeoutRunningForTesting(); |
| 174 } | 182 } |
| 175 | 183 |
| 176 size_t queued_event_count() const { | 184 size_t queued_event_count() const { |
| 177 return queue_->size(); | 185 return queue_->size(); |
| 178 } | 186 } |
| 179 | 187 |
| 180 const WebTouchEvent& latest_event() const { | 188 const WebTouchEvent& latest_event() const { |
| 181 return queue_->GetLatestEventForTesting().event; | 189 return queue_->GetLatestEventForTesting().event; |
| 182 } | 190 } |
| 183 | 191 |
| 184 const WebTouchEvent& acked_event() const { | 192 const WebTouchEvent& acked_event() const { |
| 185 return last_acked_event_; | 193 return last_acked_event_; |
| 186 } | 194 } |
| 187 | 195 |
| 188 const WebTouchEvent& sent_event() const { | 196 const WebTouchEvent& sent_event() const { |
| 189 return last_sent_event_; | 197 return last_sent_event_; |
| 190 } | 198 } |
| 191 | 199 |
| 192 InputEventAckState acked_event_state() const { | 200 InputEventAckState acked_event_state() const { |
| 193 return last_acked_event_state_; | 201 return last_acked_event_state_; |
| 194 } | 202 } |
| 195 | 203 |
| 204 static void Wait(base::TimeDelta delay) { | |
| 205 base::MessageLoop::current()->PostDelayedTask( | |
| 206 FROM_HERE, base::MessageLoop::QuitClosure(), delay); | |
| 207 base::MessageLoop::current()->Run(); | |
| 208 } | |
| 209 | |
| 196 private: | 210 private: |
| 197 void SendTouchEvent() { | 211 void SendTouchEvent() { |
| 198 SendTouchEvent(touch_event_); | 212 SendTouchEvent(touch_event_); |
| 199 touch_event_.ResetPoints(); | 213 touch_event_.ResetPoints(); |
| 200 } | 214 } |
| 201 | 215 |
| 202 void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode, | 216 void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode, |
| 203 double slop_length_dips) { | 217 double slop_length_dips) { |
| 204 queue_.reset(new TouchEventQueue(this, mode, slop_length_dips)); | 218 queue_.reset(new TouchEventQueue(this, mode, slop_length_dips)); |
| 205 queue_->OnHasTouchEventHandlers(true); | 219 queue_->OnHasTouchEventHandlers(true); |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 | 1022 |
| 1009 // Queue a TouchStart. | 1023 // Queue a TouchStart. |
| 1010 GetAndResetSentEventCount(); | 1024 GetAndResetSentEventCount(); |
| 1011 GetAndResetAckedEventCount(); | 1025 GetAndResetAckedEventCount(); |
| 1012 PressTouchPoint(0, 1); | 1026 PressTouchPoint(0, 1); |
| 1013 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1027 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1014 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 1028 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1015 EXPECT_TRUE(IsTimeoutRunning()); | 1029 EXPECT_TRUE(IsTimeoutRunning()); |
| 1016 | 1030 |
| 1017 // Delay the ack. | 1031 // Delay the ack. |
| 1018 base::MessageLoop::current()->PostDelayedTask( | 1032 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
|
Rick Byers
2014/03/06 22:46:11
To what extent do you believe this is immune from
jdduke (slow)
2014/03/06 22:52:20
This isn't just spinning. We post a delayed quit
| |
| 1019 FROM_HERE, | |
| 1020 base::MessageLoop::QuitClosure(), | |
| 1021 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1022 base::MessageLoop::current()->Run(); | |
| 1023 | 1033 |
| 1024 // The timeout should have fired, synthetically ack'ing the timed-out event. | 1034 // The timeout should have fired, synthetically ack'ing the timed-out event. |
| 1025 // TouchEvent forwarding is disabled until the ack is received for the | 1035 // TouchEvent forwarding is disabled until the ack is received for the |
| 1026 // timed-out event and the future cancel event. | 1036 // timed-out event and the future cancel event. |
| 1027 EXPECT_FALSE(IsTimeoutRunning()); | 1037 EXPECT_FALSE(IsTimeoutRunning()); |
| 1028 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1038 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1029 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1039 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1030 | 1040 |
| 1031 // Ack'ing the original event should trigger a cancel event. | 1041 // Ack'ing the original event should trigger a cancel event. |
| 1032 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1042 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 // A TouchEnd should not start the timeout. | 1092 // A TouchEnd should not start the timeout. |
| 1083 ReleaseTouchPoint(1); | 1093 ReleaseTouchPoint(1); |
| 1084 EXPECT_FALSE(IsTimeoutRunning()); | 1094 EXPECT_FALSE(IsTimeoutRunning()); |
| 1085 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1095 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1086 | 1096 |
| 1087 // A TouchCancel should not start the timeout. | 1097 // A TouchCancel should not start the timeout. |
| 1088 CancelTouchPoint(0); | 1098 CancelTouchPoint(0); |
| 1089 EXPECT_FALSE(IsTimeoutRunning()); | 1099 EXPECT_FALSE(IsTimeoutRunning()); |
| 1090 } | 1100 } |
| 1091 | 1101 |
| 1102 // Tests that the timeout is never started if the renderer consumes | |
| 1103 // a TouchEvent from the current touch sequence. | |
| 1104 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) { | |
| 1105 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | |
| 1106 | |
| 1107 // Queue a TouchStart. | |
| 1108 PressTouchPoint(0, 1); | |
| 1109 ASSERT_TRUE(IsTimeoutRunning()); | |
| 1110 | |
| 1111 // Send the ack immediately. The timeout should not have fired. | |
| 1112 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1113 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1114 EXPECT_TRUE(IsTimeoutEnabled()); | |
| 1115 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1116 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1117 | |
| 1118 // Now explicitly disable the timeout. | |
| 1119 SetAckTimeoutDisabled(); | |
| 1120 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1121 EXPECT_FALSE(IsTimeoutEnabled()); | |
| 1122 | |
| 1123 // A TouchMove should not start or trigger the timeout. | |
| 1124 MoveTouchPoint(0, 5, 5); | |
| 1125 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1126 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1127 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1128 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1129 } | |
| 1130 | |
| 1092 // Tests that the timeout is never started if the ack is synchronous. | 1131 // Tests that the timeout is never started if the ack is synchronous. |
| 1093 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { | 1132 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { |
| 1094 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1133 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1095 | 1134 |
| 1096 // Queue a TouchStart. | 1135 // Queue a TouchStart. |
| 1097 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 1136 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1098 ASSERT_FALSE(IsTimeoutRunning()); | 1137 ASSERT_FALSE(IsTimeoutRunning()); |
| 1099 PressTouchPoint(0, 1); | 1138 PressTouchPoint(0, 1); |
| 1100 EXPECT_FALSE(IsTimeoutRunning()); | 1139 EXPECT_FALSE(IsTimeoutRunning()); |
| 1101 } | 1140 } |
| 1102 | 1141 |
| 1103 // Tests that the timeout is disabled if the touch handler disappears. | 1142 // Tests that the timeout is disabled if the touch handler disappears. |
| 1104 TEST_F(TouchEventQueueTest, TouchTimeoutStoppedIfTouchHandlerRemoved) { | 1143 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) { |
| 1105 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1144 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1106 | 1145 |
| 1107 // Queue a TouchStart. | 1146 // Queue a TouchStart. |
| 1108 PressTouchPoint(0, 1); | 1147 PressTouchPoint(0, 1); |
| 1109 ASSERT_TRUE(IsTimeoutRunning()); | 1148 ASSERT_TRUE(IsTimeoutRunning()); |
| 1110 | 1149 |
| 1111 // Unload the touch handler. | 1150 // Unload the touch handler. |
| 1112 OnHasTouchEventHandlers(false); | 1151 OnHasTouchEventHandlers(false); |
| 1113 EXPECT_FALSE(IsTimeoutRunning()); | 1152 EXPECT_FALSE(IsTimeoutRunning()); |
| 1114 } | 1153 } |
| 1115 | 1154 |
| 1155 // Tests that the timeout does not fire if explicitly disabled while an event | |
| 1156 // is in-flight. | |
| 1157 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) { | |
| 1158 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | |
| 1159 | |
| 1160 // Queue a TouchStart. | |
| 1161 PressTouchPoint(0, 1); | |
| 1162 ASSERT_TRUE(IsTimeoutRunning()); | |
| 1163 | |
| 1164 // Verify that disabling the timeout also turns off the timer. | |
| 1165 SetAckTimeoutDisabled(); | |
| 1166 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1167 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1168 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1169 } | |
| 1170 | |
| 1116 // Tests that a TouchCancel timeout plays nice when the timed out touch stream | 1171 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1117 // turns into a scroll gesture sequence. | 1172 // turns into a scroll gesture sequence. |
| 1118 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { | 1173 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { |
| 1119 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1174 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1120 | 1175 |
| 1121 // Queue a TouchStart. | 1176 // Queue a TouchStart. |
| 1122 PressTouchPoint(0, 1); | 1177 PressTouchPoint(0, 1); |
| 1123 EXPECT_TRUE(IsTimeoutRunning()); | 1178 EXPECT_TRUE(IsTimeoutRunning()); |
| 1124 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1179 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1125 | 1180 |
| 1126 // The cancelled sequence may turn into a scroll gesture. | 1181 // The cancelled sequence may turn into a scroll gesture. |
| 1127 WebGestureEvent followup_scroll; | 1182 WebGestureEvent followup_scroll; |
| 1128 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1183 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1129 SetFollowupEvent(followup_scroll); | 1184 SetFollowupEvent(followup_scroll); |
| 1130 | 1185 |
| 1131 // Delay the ack. | 1186 // Delay the ack. |
| 1132 base::MessageLoop::current()->PostDelayedTask( | 1187 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1133 FROM_HERE, | |
| 1134 base::MessageLoop::QuitClosure(), | |
| 1135 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1136 base::MessageLoop::current()->Run(); | |
| 1137 | 1188 |
| 1138 // The timeout should have fired, disabling touch forwarding until both acks | 1189 // The timeout should have fired, disabling touch forwarding until both acks |
| 1139 // are received, acking the timed out event. | 1190 // are received, acking the timed out event. |
| 1140 EXPECT_FALSE(IsTimeoutRunning()); | 1191 EXPECT_FALSE(IsTimeoutRunning()); |
| 1141 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1192 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1142 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1193 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1143 | 1194 |
| 1144 // Ack the original event, triggering a TouchCancel. | 1195 // Ack the original event, triggering a TouchCancel. |
| 1145 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1196 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1146 EXPECT_FALSE(IsTimeoutRunning()); | 1197 EXPECT_FALSE(IsTimeoutRunning()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 PressTouchPoint(0, 1); | 1232 PressTouchPoint(0, 1); |
| 1182 EXPECT_TRUE(IsTimeoutRunning()); | 1233 EXPECT_TRUE(IsTimeoutRunning()); |
| 1183 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1234 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1184 | 1235 |
| 1185 // The cancelled sequence may turn into a scroll gesture. | 1236 // The cancelled sequence may turn into a scroll gesture. |
| 1186 WebGestureEvent followup_scroll; | 1237 WebGestureEvent followup_scroll; |
| 1187 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1238 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1188 SetFollowupEvent(followup_scroll); | 1239 SetFollowupEvent(followup_scroll); |
| 1189 | 1240 |
| 1190 // Delay the ack. | 1241 // Delay the ack. |
| 1191 base::MessageLoop::current()->PostDelayedTask( | 1242 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1192 FROM_HERE, | |
| 1193 base::MessageLoop::QuitClosure(), | |
| 1194 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1195 base::MessageLoop::current()->Run(); | |
| 1196 | 1243 |
| 1197 // The timeout should have fired, disabling touch forwarding until both acks | 1244 // The timeout should have fired, disabling touch forwarding until both acks |
| 1198 // are received and acking the timed out event. | 1245 // are received and acking the timed out event. |
| 1199 EXPECT_FALSE(IsTimeoutRunning()); | 1246 EXPECT_FALSE(IsTimeoutRunning()); |
| 1200 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1247 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1201 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1248 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1202 | 1249 |
| 1203 // Try to forward a touch event. | 1250 // Try to forward a touch event. |
| 1204 GetAndResetSentEventCount(); | 1251 GetAndResetSentEventCount(); |
| 1205 GetAndResetAckedEventCount(); | 1252 GetAndResetAckedEventCount(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1237 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { | 1284 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { |
| 1238 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); | 1285 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1239 | 1286 |
| 1240 // Queue a TouchStart. | 1287 // Queue a TouchStart. |
| 1241 PressTouchPoint(0, 1); | 1288 PressTouchPoint(0, 1); |
| 1242 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1289 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1243 ASSERT_EQ(0U, GetAndResetAckedEventCount()); | 1290 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1244 EXPECT_TRUE(IsTimeoutRunning()); | 1291 EXPECT_TRUE(IsTimeoutRunning()); |
| 1245 | 1292 |
| 1246 // Delay the ack. | 1293 // Delay the ack. |
| 1247 base::MessageLoop::current()->PostDelayedTask( | 1294 Wait(base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1248 FROM_HERE, | |
| 1249 base::MessageLoop::QuitClosure(), | |
| 1250 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); | |
| 1251 base::MessageLoop::current()->Run(); | |
| 1252 | 1295 |
| 1253 // The timeout should have fired, synthetically ack'ing the timed out event. | 1296 // The timeout should have fired, synthetically ack'ing the timed out event. |
| 1254 // TouchEvent forwarding is disabled until the original ack is received. | 1297 // TouchEvent forwarding is disabled until the original ack is received. |
| 1255 EXPECT_FALSE(IsTimeoutRunning()); | 1298 EXPECT_FALSE(IsTimeoutRunning()); |
| 1256 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1299 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1257 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1300 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1258 | 1301 |
| 1259 // Touch events should not be forwarded until we receive the original ack. | 1302 // Touch events should not be forwarded until we receive the original ack. |
| 1260 MoveTouchPoint(0, 1, 1); | 1303 MoveTouchPoint(0, 1, 1); |
| 1261 ReleaseTouchPoint(0); | 1304 ReleaseTouchPoint(0); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1506 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1549 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 1507 INPUT_EVENT_ACK_STATE_CONSUMED); | 1550 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1508 MoveTouchPoint(0, 20, 5); | 1551 MoveTouchPoint(0, 20, 5); |
| 1509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1552 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1510 EXPECT_EQ(0U, queued_event_count()); | 1553 EXPECT_EQ(0U, queued_event_count()); |
| 1511 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1554 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1512 } | 1555 } |
| 1513 } | 1556 } |
| 1514 | 1557 |
| 1515 } // namespace content | 1558 } // namespace content |
| OLD | NEW |