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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 EXPECT_EQ(0U, queued_event_count()); | 281 EXPECT_EQ(0U, queued_event_count()); |
282 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 282 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
283 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 283 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
284 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 284 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
285 EXPECT_TRUE(acked_event().cancelable); | 285 EXPECT_TRUE(acked_event().cancelable); |
286 } | 286 } |
287 | 287 |
288 // Tests that touch-events with multiple points are queued properly. | 288 // Tests that touch-events with multiple points are queued properly. |
289 TEST_F(TouchEventQueueTest, BasicMultiTouch) { | 289 TEST_F(TouchEventQueueTest, BasicMultiTouch) { |
290 const size_t kPointerCount = 10; | 290 const size_t kPointerCount = 10; |
291 for (size_t i = 0; i < kPointerCount; ++i) | 291 for (float i = 0; i < kPointerCount; ++i) |
292 PressTouchPoint(i, i); | 292 PressTouchPoint(i, i); |
293 | 293 |
294 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 294 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
295 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 295 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
296 EXPECT_EQ(kPointerCount, queued_event_count()); | 296 EXPECT_EQ(kPointerCount, queued_event_count()); |
297 | 297 |
298 for (size_t i = 0; i < kPointerCount; ++i) | 298 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) |
299 MoveTouchPoint(i, 1.f + i, 2.f + i); | 299 MoveTouchPoint(i, 1.f + i, 2.f + i); |
300 | 300 |
301 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 301 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
302 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 302 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
303 // All moves should coalesce. | 303 // All moves should coalesce. |
304 EXPECT_EQ(kPointerCount + 1, queued_event_count()); | 304 EXPECT_EQ(kPointerCount + 1, queued_event_count()); |
305 | 305 |
306 for (size_t i = 0; i < kPointerCount; ++i) | 306 for (int i = 0; i < static_cast<int>(kPointerCount); ++i) |
307 ReleaseTouchPoint(kPointerCount - 1 - i); | 307 ReleaseTouchPoint(kPointerCount - 1 - i); |
308 | 308 |
309 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 309 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
310 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 310 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
311 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count()); | 311 EXPECT_EQ(kPointerCount * 2 + 1, queued_event_count()); |
312 | 312 |
313 // Ack all presses. | 313 // Ack all presses. |
314 for (size_t i = 0; i < kPointerCount; ++i) | 314 for (size_t i = 0; i < kPointerCount; ++i) |
315 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 315 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
316 | 316 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 498 } |
499 | 499 |
500 // Tests that touch-events are coalesced properly in the queue. | 500 // Tests that touch-events are coalesced properly in the queue. |
501 TEST_F(TouchEventQueueTest, Coalesce) { | 501 TEST_F(TouchEventQueueTest, Coalesce) { |
502 // Send a touch-press event. | 502 // Send a touch-press event. |
503 PressTouchPoint(1, 1); | 503 PressTouchPoint(1, 1); |
504 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 504 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
505 | 505 |
506 // Send a few touch-move events, followed by a touch-release event. All the | 506 // Send a few touch-move events, followed by a touch-release event. All the |
507 // touch-move events should be coalesced into a single event. | 507 // touch-move events should be coalesced into a single event. |
508 for (int i = 5; i < 15; ++i) | 508 for (float i = 5; i < 15; ++i) |
509 MoveTouchPoint(0, i, i); | 509 MoveTouchPoint(0, i, i); |
510 | 510 |
511 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 511 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
512 ReleaseTouchPoint(0); | 512 ReleaseTouchPoint(0); |
513 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 513 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
514 EXPECT_EQ(3U, queued_event_count()); | 514 EXPECT_EQ(3U, queued_event_count()); |
515 | 515 |
516 // ACK the press. Coalesced touch-move events should be sent. | 516 // ACK the press. Coalesced touch-move events should be sent. |
517 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 517 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
518 EXPECT_EQ(2U, queued_event_count()); | 518 EXPECT_EQ(2U, queued_event_count()); |
(...skipping 19 matching lines...) Expand all Loading... |
538 | 538 |
539 // Tests that an event that has already been sent but hasn't been ack'ed yet | 539 // Tests that an event that has already been sent but hasn't been ack'ed yet |
540 // doesn't get coalesced with newer events. | 540 // doesn't get coalesced with newer events. |
541 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { | 541 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { |
542 // Send a touch-press event. | 542 // Send a touch-press event. |
543 PressTouchPoint(1, 1); | 543 PressTouchPoint(1, 1); |
544 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 544 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
545 | 545 |
546 // Send a few touch-move events, followed by a touch-release event. All the | 546 // Send a few touch-move events, followed by a touch-release event. All the |
547 // touch-move events should be coalesced into a single event. | 547 // touch-move events should be coalesced into a single event. |
548 for (int i = 5; i < 15; ++i) | 548 for (float i = 5; i < 15; ++i) |
549 MoveTouchPoint(0, i, i); | 549 MoveTouchPoint(0, i, i); |
550 | 550 |
551 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 551 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
552 EXPECT_EQ(2U, queued_event_count()); | 552 EXPECT_EQ(2U, queued_event_count()); |
553 | 553 |
554 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 554 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
555 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 555 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
556 EXPECT_EQ(1U, queued_event_count()); | 556 EXPECT_EQ(1U, queued_event_count()); |
557 | 557 |
558 // The coalesced touch-move event has been sent to the renderer. Any new | 558 // The coalesced touch-move event has been sent to the renderer. Any new |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 | 1437 |
1438 // Subsequent events should be handled normally. | 1438 // Subsequent events should be handled normally. |
1439 PressTouchPoint(0, 1); | 1439 PressTouchPoint(0, 1); |
1440 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1440 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1441 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1441 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1442 } | 1442 } |
1443 | 1443 |
1444 // Tests that TouchMove's are dropped if within the boundary-inclusive slop | 1444 // Tests that TouchMove's are dropped if within the boundary-inclusive slop |
1445 // suppression region for an unconsumed TouchStart. | 1445 // suppression region for an unconsumed TouchStart. |
1446 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) { | 1446 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) { |
1447 const double kSlopLengthDips = 10.; | 1447 const float kSlopLengthDips = 10; |
1448 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1448 const float kHalfSlopLengthDips = kSlopLengthDips / 2; |
1449 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1449 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
1450 | 1450 |
1451 // Queue a TouchStart. | 1451 // Queue a TouchStart. |
1452 PressTouchPoint(0, 0); | 1452 PressTouchPoint(0, 0); |
1453 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1453 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1454 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1454 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
1455 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1455 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
1456 | 1456 |
1457 // TouchMove's within the region should be suppressed. | 1457 // TouchMove's within the region should be suppressed. |
1458 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1458 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
(...skipping 21 matching lines...) Expand all Loading... |
1480 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); | 1480 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); |
1481 | 1481 |
1482 MoveTouchPoint(0, 0, kSlopLengthDips); | 1482 MoveTouchPoint(0, 0, kSlopLengthDips); |
1483 EXPECT_EQ(0U, queued_event_count()); | 1483 EXPECT_EQ(0U, queued_event_count()); |
1484 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1484 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1485 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1485 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1486 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); | 1486 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); |
1487 | 1487 |
1488 // As soon as a TouchMove exceeds the (Euclidean) distance, no more | 1488 // As soon as a TouchMove exceeds the (Euclidean) distance, no more |
1489 // TouchMove's should be suppressed. | 1489 // TouchMove's should be suppressed. |
1490 const double kFortyFiveDegreeSlopLengthXY = | 1490 const float kFortyFiveDegreeSlopLengthXY = |
1491 kSlopLengthDips * std::sqrt(2.) / 2.; | 1491 kSlopLengthDips * std::sqrt(2.f) / 2; |
1492 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2, | 1492 MoveTouchPoint(0, kFortyFiveDegreeSlopLengthXY + .2f, |
1493 kFortyFiveDegreeSlopLengthXY + .2); | 1493 kFortyFiveDegreeSlopLengthXY + .2f); |
1494 EXPECT_EQ(1U, queued_event_count()); | 1494 EXPECT_EQ(1U, queued_event_count()); |
1495 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1495 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1496 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1496 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1497 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1497 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1498 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1498 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1499 | 1499 |
1500 // Even TouchMove's within the original slop region should now be forwarded. | 1500 // Even TouchMove's within the original slop region should now be forwarded. |
1501 MoveTouchPoint(0, 0, 0); | 1501 MoveTouchPoint(0, 0, 0); |
1502 EXPECT_EQ(1U, queued_event_count()); | 1502 EXPECT_EQ(1U, queued_event_count()); |
1503 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1503 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1504 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1504 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1505 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1505 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1506 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1506 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1507 | 1507 |
1508 // A new touch sequence should reset suppression. | 1508 // A new touch sequence should reset suppression. |
1509 ReleaseTouchPoint(0); | 1509 ReleaseTouchPoint(0); |
1510 PressTouchPoint(0, 0); | 1510 PressTouchPoint(0, 0); |
1511 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1511 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1512 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1512 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1513 ASSERT_EQ(2U, GetAndResetSentEventCount()); | 1513 ASSERT_EQ(2U, GetAndResetSentEventCount()); |
1514 ASSERT_EQ(2U, GetAndResetAckedEventCount()); | 1514 ASSERT_EQ(2U, GetAndResetAckedEventCount()); |
1515 ASSERT_EQ(0U, queued_event_count()); | 1515 ASSERT_EQ(0U, queued_event_count()); |
1516 | 1516 |
1517 // The slop region is boundary-inclusive. | 1517 // The slop region is boundary-inclusive. |
1518 MoveTouchPoint(0, kSlopLengthDips - 1., 0); | 1518 MoveTouchPoint(0, kSlopLengthDips - 1, 0); |
1519 EXPECT_EQ(0U, queued_event_count()); | 1519 EXPECT_EQ(0U, queued_event_count()); |
1520 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1520 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1521 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1521 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1522 | 1522 |
1523 MoveTouchPoint(0, kSlopLengthDips, 0); | 1523 MoveTouchPoint(0, kSlopLengthDips, 0); |
1524 EXPECT_EQ(0U, queued_event_count()); | 1524 EXPECT_EQ(0U, queued_event_count()); |
1525 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1525 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1526 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1526 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1527 } | 1527 } |
1528 | 1528 |
1529 // Tests that TouchMove's are not dropped within the slop suppression region if | 1529 // Tests that TouchMove's are not dropped within the slop suppression region if |
1530 // the touchstart was consumed. | 1530 // the touchstart was consumed. |
1531 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { | 1531 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { |
1532 const double kSlopLengthDips = 10.; | 1532 const float kSlopLengthDips = 10; |
1533 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1533 const float kHalfSlopLengthDips = kSlopLengthDips / 2; |
1534 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1534 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
1535 | 1535 |
1536 // Queue a TouchStart. | 1536 // Queue a TouchStart. |
1537 PressTouchPoint(0, 0); | 1537 PressTouchPoint(0, 0); |
1538 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1538 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
1539 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1539 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
1540 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1540 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
1541 | 1541 |
1542 // TouchMove's within the region should not be suppressed, as a touch was | 1542 // TouchMove's within the region should not be suppressed, as a touch was |
1543 // consumed. | 1543 // consumed. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 0.5f; | 1599 const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 0.5f; |
1600 MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale); | 1600 MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale); |
1601 EXPECT_EQ(1U, queued_event_count()); | 1601 EXPECT_EQ(1U, queued_event_count()); |
1602 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1602 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1603 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1603 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1604 } | 1604 } |
1605 | 1605 |
1606 // Tests that TouchMove's are not dropped if a secondary pointer is present | 1606 // Tests that TouchMove's are not dropped if a secondary pointer is present |
1607 // during any movement. | 1607 // during any movement. |
1608 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { | 1608 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { |
1609 const double kSlopLengthDips = 10.; | 1609 const float kSlopLengthDips = 10; |
1610 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1610 const float kHalfSlopLengthDips = kSlopLengthDips / 2; |
1611 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1611 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
1612 | 1612 |
1613 // Queue a TouchStart. | 1613 // Queue a TouchStart. |
1614 PressTouchPoint(0, 0); | 1614 PressTouchPoint(0, 0); |
1615 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1615 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1616 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1616 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
1617 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1617 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
1618 | 1618 |
1619 // TouchMove's within the region should be suppressed. | 1619 // TouchMove's within the region should be suppressed. |
1620 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1620 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2222 | 2222 |
2223 // Give the touchmove a valid id; it should be sent. | 2223 // Give the touchmove a valid id; it should be sent. |
2224 event.touches[0].id = press_id; | 2224 event.touches[0].id = press_id; |
2225 SendTouchEvent(event); | 2225 SendTouchEvent(event); |
2226 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2226 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2227 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2227 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2228 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2228 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2229 } | 2229 } |
2230 | 2230 |
2231 } // namespace content | 2231 } // namespace content |
OLD | NEW |