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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 bool IsPendingAckTouchStart() const { | 189 bool IsPendingAckTouchStart() const { |
190 return queue_->IsPendingAckTouchStart(); | 190 return queue_->IsPendingAckTouchStart(); |
191 } | 191 } |
192 | 192 |
193 void OnHasTouchEventHandlers(bool has_handlers) { | 193 void OnHasTouchEventHandlers(bool has_handlers) { |
194 queue_->OnHasTouchEventHandlers(has_handlers); | 194 queue_->OnHasTouchEventHandlers(has_handlers); |
195 } | 195 } |
196 | 196 |
197 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } | 197 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } |
198 | 198 |
199 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); } | |
200 | |
201 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } | 199 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } |
202 | 200 |
203 bool HasPendingAsyncTouchMove() const { | 201 bool HasPendingAsyncTouchMove() const { |
204 return queue_->HasPendingAsyncTouchMoveForTesting(); | 202 return queue_->HasPendingAsyncTouchMoveForTesting(); |
205 } | 203 } |
206 | 204 |
207 size_t queued_event_count() const { | 205 size_t queued_event_count() const { |
208 return queue_->size(); | 206 return queue_->size(); |
209 } | 207 } |
210 | 208 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 276 |
279 // Receive an ACK for the second touch-event. | 277 // Receive an ACK for the second touch-event. |
280 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 278 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
281 EXPECT_EQ(0U, queued_event_count()); | 279 EXPECT_EQ(0U, queued_event_count()); |
282 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 280 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
283 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 281 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
284 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 282 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
285 EXPECT_TRUE(acked_event().cancelable); | 283 EXPECT_TRUE(acked_event().cancelable); |
286 } | 284 } |
287 | 285 |
288 // Tests that the touch-queue is emptied after the outstanding ack is received | 286 // Tests that touch-events with multiple points are queued properly. |
289 // if a page stops listening for touch events. | 287 TEST_F(TouchEventQueueTest, BasicMultiTouch) { |
290 TEST_F(TouchEventQueueTest, QueueFlushedOnAckAfterHandlersRemoved) { | 288 const size_t kPointerCount = 10; |
| 289 for (size_t i = 0; i < kPointerCount; ++i) |
| 290 PressTouchPoint(i, i); |
| 291 |
| 292 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 293 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 294 EXPECT_EQ(kPointerCount, queued_event_count()); |
| 295 |
| 296 for (size_t i = 0; i < kPointerCount; ++i) |
| 297 MoveTouchPoint(i, 1.f + i, 2.f + i); |
| 298 |
| 299 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 300 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 301 // All moves should coalesce. |
| 302 EXPECT_EQ(kPointerCount + 1, queued_event_count()); |
| 303 |
| 304 for (size_t i = 0; i < kPointerCount; ++i) |
| 305 ReleaseTouchPoint(kPointerCount - 1 - i); |
| 306 |
| 307 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 308 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 309 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count()); |
| 310 |
| 311 // Ack all presses. |
| 312 for (size_t i = 0; i < kPointerCount; ++i) |
| 313 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 314 |
| 315 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 316 EXPECT_EQ(kPointerCount, GetAndResetSentEventCount()); |
| 317 |
| 318 // Ack the coalesced move. |
| 319 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 320 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 321 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 322 |
| 323 // Ack all releases. |
| 324 for (size_t i = 0; i < kPointerCount; ++i) |
| 325 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 326 |
| 327 EXPECT_EQ(kPointerCount, GetAndResetAckedEventCount()); |
| 328 EXPECT_EQ(kPointerCount - 1, GetAndResetSentEventCount()); |
| 329 } |
| 330 |
| 331 // Tests that the touch-queue continues delivering events for an active pointer |
| 332 // after all handlers are removed, but acks new pointers immediately as having |
| 333 // no consumer. |
| 334 TEST_F(TouchEventQueueTest, NoNewTouchesForwardedAfterHandlersRemoved) { |
291 OnHasTouchEventHandlers(true); | 335 OnHasTouchEventHandlers(true); |
292 EXPECT_EQ(0U, queued_event_count()); | 336 EXPECT_EQ(0U, queued_event_count()); |
293 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 337 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
294 | 338 |
295 // Send a touch-press event. | 339 // Send a touch-press event. |
296 PressTouchPoint(1, 1); | 340 PressTouchPoint(1, 1); |
297 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 341 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
298 EXPECT_EQ(1U, queued_event_count()); | 342 EXPECT_EQ(1U, queued_event_count()); |
299 | 343 |
300 // Signal that all touch handlers have been removed. | 344 // Signal that all touch handlers have been removed. |
301 OnHasTouchEventHandlers(false); | 345 OnHasTouchEventHandlers(false); |
302 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 346 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
303 EXPECT_EQ(1U, queued_event_count()); | 347 EXPECT_EQ(1U, queued_event_count()); |
304 | 348 |
305 // Process the ack for the sent touch, ensuring that it is honored (despite | 349 // Process the ack for the sent touch, ensuring that it is honored (despite |
306 // the touch handler having been removed). | 350 // the touch handler having been removed). |
307 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 351 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
308 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 352 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
309 EXPECT_EQ(0U, queued_event_count()); | 353 EXPECT_EQ(0U, queued_event_count()); |
310 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 354 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
311 | 355 |
312 // The release should not be forwarded. | 356 // Try forwarding a new pointer. It should be rejected immediately. |
313 ReleaseTouchPoint(0); | 357 PressTouchPoint(2, 2); |
314 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 358 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
315 EXPECT_EQ(0U, queued_event_count()); | 359 EXPECT_EQ(0U, queued_event_count()); |
316 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 360 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
317 | 361 |
318 OnHasTouchEventHandlers(true); | 362 // Further events for the pointer without a handler should not be forwarded. |
| 363 MoveTouchPoint(1, 3, 3); |
| 364 ReleaseTouchPoint(1); |
| 365 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
| 366 EXPECT_EQ(0U, queued_event_count()); |
| 367 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
319 | 368 |
320 // Events will be queued until the first sent event is ack'ed. | 369 // Events for the first pointer, that had a handler, should be forwarded, even |
321 for (int i = 0; i < 10; ++i) { | 370 // if the renderer reports that no handlers exist. |
322 PressTouchPoint(1, 1); | 371 MoveTouchPoint(0, 4, 4); |
323 MoveTouchPoint(0, i, i); | 372 ReleaseTouchPoint(0); |
324 ReleaseTouchPoint(0); | |
325 } | |
326 EXPECT_EQ(30U, queued_event_count()); | |
327 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 373 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 374 EXPECT_EQ(2U, queued_event_count()); |
328 | 375 |
329 // Signal that all touch handlers have been removed. Note that flushing of | 376 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
330 // the queue will not occur until *after* the outstanding ack is received. | 377 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
331 OnHasTouchEventHandlers(false); | 378 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
332 EXPECT_EQ(30U, queued_event_count()); | 379 EXPECT_EQ(1U, queued_event_count()); |
| 380 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
| 381 |
| 382 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 383 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
333 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 384 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
334 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
335 | |
336 // Receive an ACK for the first touch-event. All remaining touch events should | |
337 // be flushed with the appropriate ack type. | |
338 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | |
339 EXPECT_EQ(0U, queued_event_count()); | 385 EXPECT_EQ(0U, queued_event_count()); |
340 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 386 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
341 EXPECT_EQ(30U, GetAndResetAckedEventCount()); | |
342 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | |
343 } | 387 } |
344 | 388 |
345 // Tests that addition of a touch handler during a touch sequence will not cause | 389 // Tests that addition of a touch handler during a touch sequence will not cause |
346 // the remaining sequence to be forwarded. | 390 // the remaining sequence to be forwarded. |
347 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) { | 391 TEST_F(TouchEventQueueTest, ActiveSequenceNotForwardedWhenHandlersAdded) { |
348 OnHasTouchEventHandlers(false); | 392 OnHasTouchEventHandlers(false); |
349 | 393 |
350 // Send a touch-press event while there is no handler. | 394 // Send a touch-press event while there is no handler. |
351 PressTouchPoint(1, 1); | 395 PressTouchPoint(1, 1); |
352 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 396 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 EXPECT_EQ(0U, queued_event_count()); | 460 EXPECT_EQ(0U, queued_event_count()); |
417 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 461 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
418 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 462 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
419 | 463 |
420 // A new touch sequence should be forwarded properly. | 464 // A new touch sequence should be forwarded properly. |
421 PressTouchPoint(1, 1); | 465 PressTouchPoint(1, 1); |
422 EXPECT_EQ(1U, queued_event_count()); | 466 EXPECT_EQ(1U, queued_event_count()); |
423 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 467 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
424 } | 468 } |
425 | 469 |
| 470 // Tests that removal/addition of a touch handler without any intervening |
| 471 // touch activity has no affect on touch forwarding. |
| 472 TEST_F(TouchEventQueueTest, |
| 473 ActiveSequenceUnaffectedByRepeatedHandlerRemovalAndAddition) { |
| 474 // Send a touch-press event. |
| 475 PressTouchPoint(1, 1); |
| 476 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 477 EXPECT_EQ(1U, queued_event_count()); |
| 478 |
| 479 // Simulate the case where the touchstart handler removes itself, and adds a |
| 480 // touchmove handler. |
| 481 OnHasTouchEventHandlers(false); |
| 482 OnHasTouchEventHandlers(true); |
| 483 |
| 484 // Queue a touch-move event. |
| 485 MoveTouchPoint(0, 5, 5); |
| 486 EXPECT_EQ(2U, queued_event_count()); |
| 487 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 488 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 489 |
| 490 // The ack should trigger forwarding of the touchmove, as if no touch |
| 491 // handler registration changes have occurred. |
| 492 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 493 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 494 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 495 EXPECT_EQ(1U, queued_event_count()); |
| 496 } |
| 497 |
426 // Tests that touch-events are coalesced properly in the queue. | 498 // Tests that touch-events are coalesced properly in the queue. |
427 TEST_F(TouchEventQueueTest, Coalesce) { | 499 TEST_F(TouchEventQueueTest, Coalesce) { |
428 // Send a touch-press event. | 500 // Send a touch-press event. |
429 PressTouchPoint(1, 1); | 501 PressTouchPoint(1, 1); |
430 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 502 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
431 | 503 |
432 // Send a few touch-move events, followed by a touch-release event. All the | 504 // Send a few touch-move events, followed by a touch-release event. All the |
433 // touch-move events should be coalesced into a single event. | 505 // touch-move events should be coalesced into a single event. |
434 for (int i = 5; i < 15; ++i) | 506 for (int i = 5; i < 15; ++i) |
435 MoveTouchPoint(0, i, i); | 507 MoveTouchPoint(0, i, i); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { | 798 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { |
727 // Queue a touch down. | 799 // Queue a touch down. |
728 PressTouchPoint(1, 1); | 800 PressTouchPoint(1, 1); |
729 EXPECT_EQ(1U, queued_event_count()); | 801 EXPECT_EQ(1U, queued_event_count()); |
730 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 802 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
731 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 803 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
732 | 804 |
733 // Create a touch event that will be queued synchronously by a touch ack. | 805 // Create a touch event that will be queued synchronously by a touch ack. |
734 // Note, this will be triggered by all subsequent touch acks. | 806 // Note, this will be triggered by all subsequent touch acks. |
735 WebTouchEvent followup_event; | 807 WebTouchEvent followup_event; |
736 followup_event.type = WebInputEvent::TouchStart; | 808 followup_event.type = WebInputEvent::TouchMove; |
737 followup_event.touchesLength = 1; | 809 followup_event.touchesLength = 1; |
738 followup_event.touches[0].id = 1; | 810 followup_event.touches[0].id = 0; |
739 followup_event.touches[0].state = WebTouchPoint::StatePressed; | 811 followup_event.touches[0].state = WebTouchPoint::StateMoved; |
740 SetFollowupEvent(followup_event); | 812 SetFollowupEvent(followup_event); |
741 | 813 |
742 // Receive an ACK for the press. This should cause the followup touch-move to | 814 // Receive an ACK for the press. This should cause the followup touch-move to |
743 // be sent to the renderer. | 815 // be sent to the renderer. |
744 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 816 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
745 EXPECT_EQ(1U, queued_event_count()); | 817 EXPECT_EQ(1U, queued_event_count()); |
746 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 818 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
747 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 819 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
748 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 820 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
749 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 821 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) { | 1240 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledAfterTouchStart) { |
1169 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | 1241 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); |
1170 | 1242 |
1171 // Queue a TouchStart. | 1243 // Queue a TouchStart. |
1172 PressTouchPoint(0, 1); | 1244 PressTouchPoint(0, 1); |
1173 ASSERT_TRUE(IsTimeoutRunning()); | 1245 ASSERT_TRUE(IsTimeoutRunning()); |
1174 | 1246 |
1175 // Send the ack immediately. The timeout should not have fired. | 1247 // Send the ack immediately. The timeout should not have fired. |
1176 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1248 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1177 EXPECT_FALSE(IsTimeoutRunning()); | 1249 EXPECT_FALSE(IsTimeoutRunning()); |
1178 EXPECT_TRUE(IsTimeoutEnabled()); | |
1179 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1250 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1180 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1251 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1181 | 1252 |
1182 // Now explicitly disable the timeout. | 1253 // Now explicitly disable the timeout. |
1183 SetAckTimeoutDisabled(); | 1254 SetAckTimeoutDisabled(); |
1184 EXPECT_FALSE(IsTimeoutRunning()); | 1255 EXPECT_FALSE(IsTimeoutRunning()); |
1185 EXPECT_FALSE(IsTimeoutEnabled()); | |
1186 | 1256 |
1187 // A TouchMove should not start or trigger the timeout. | 1257 // A TouchMove should not start or trigger the timeout. |
1188 MoveTouchPoint(0, 5, 5); | 1258 MoveTouchPoint(0, 5, 5); |
1189 EXPECT_FALSE(IsTimeoutRunning()); | 1259 EXPECT_FALSE(IsTimeoutRunning()); |
1190 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1260 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1191 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | 1261 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); |
1192 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1262 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1193 } | 1263 } |
1194 | 1264 |
1195 // Tests that the timeout is never started if the ack is synchronous. | 1265 // Tests that the timeout is never started if the ack is synchronous. |
1196 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { | 1266 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { |
1197 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | 1267 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); |
1198 | 1268 |
1199 // Queue a TouchStart. | 1269 // Queue a TouchStart. |
1200 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 1270 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
1201 ASSERT_FALSE(IsTimeoutRunning()); | 1271 ASSERT_FALSE(IsTimeoutRunning()); |
1202 PressTouchPoint(0, 1); | 1272 PressTouchPoint(0, 1); |
1203 EXPECT_FALSE(IsTimeoutRunning()); | 1273 EXPECT_FALSE(IsTimeoutRunning()); |
1204 } | 1274 } |
1205 | 1275 |
1206 // Tests that the timeout is disabled if the touch handler disappears. | |
1207 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfTouchHandlerRemoved) { | |
1208 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | |
1209 | |
1210 // Queue a TouchStart. | |
1211 PressTouchPoint(0, 1); | |
1212 ASSERT_TRUE(IsTimeoutRunning()); | |
1213 | |
1214 // Unload the touch handler. | |
1215 OnHasTouchEventHandlers(false); | |
1216 EXPECT_FALSE(IsTimeoutRunning()); | |
1217 } | |
1218 | |
1219 // Tests that the timeout does not fire if explicitly disabled while an event | 1276 // Tests that the timeout does not fire if explicitly disabled while an event |
1220 // is in-flight. | 1277 // is in-flight. |
1221 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) { | 1278 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfDisabledWhileTimerIsActive) { |
1222 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | 1279 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); |
1223 | 1280 |
1224 // Queue a TouchStart. | 1281 // Queue a TouchStart. |
1225 PressTouchPoint(0, 1); | 1282 PressTouchPoint(0, 1); |
1226 ASSERT_TRUE(IsTimeoutRunning()); | 1283 ASSERT_TRUE(IsTimeoutRunning()); |
1227 | 1284 |
1228 // Verify that disabling the timeout also turns off the timer. | 1285 // Verify that disabling the timeout also turns off the timer. |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2124 EXPECT_TRUE(sent_event().cancelable); | 2181 EXPECT_TRUE(sent_event().cancelable); |
2125 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2182 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2126 | 2183 |
2127 // Touch move event is throttled. | 2184 // Touch move event is throttled. |
2128 MoveTouchPoint(0, 60, 5); | 2185 MoveTouchPoint(0, 60, 5); |
2129 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2186 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2130 EXPECT_EQ(0U, queued_event_count()); | 2187 EXPECT_EQ(0U, queued_event_count()); |
2131 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 2188 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
2132 } | 2189 } |
2133 | 2190 |
| 2191 TEST_F(TouchEventQueueTest, UnseenTouchPointerIdsNotForwarded) { |
| 2192 SyntheticWebTouchEvent event; |
| 2193 event.PressPoint(0, 0); |
| 2194 SendTouchEvent(event); |
| 2195 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2196 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2197 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2198 |
| 2199 // Give the touchmove a previously unseen pointer id; it should not be sent. |
| 2200 int press_id = event.touches[0].id; |
| 2201 event.MovePoint(0, 1, 1); |
| 2202 event.touches[0].id = 7; |
| 2203 SendTouchEvent(event); |
| 2204 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2205 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2206 |
| 2207 // Give the touchmove a valid id; it should be sent. |
| 2208 event.touches[0].id = press_id; |
| 2209 SendTouchEvent(event); |
| 2210 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2211 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2212 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2213 |
| 2214 // Do the same for release. |
| 2215 event.ReleasePoint(0); |
| 2216 event.touches[0].id = 11; |
| 2217 SendTouchEvent(event); |
| 2218 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2219 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2220 |
| 2221 // Give the touchmove a valid id; it should be sent. |
| 2222 event.touches[0].id = press_id; |
| 2223 SendTouchEvent(event); |
| 2224 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2225 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2226 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2227 } |
| 2228 |
2134 } // namespace content | 2229 } // namespace content |
OLD | NEW |