| 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 17 matching lines...) Expand all Loading... |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 class TouchEventQueueTest : public testing::Test, | 30 class TouchEventQueueTest : public testing::Test, |
| 31 public TouchEventQueueClient { | 31 public TouchEventQueueClient { |
| 32 public: | 32 public: |
| 33 TouchEventQueueTest() | 33 TouchEventQueueTest() |
| 34 : sent_event_count_(0), | 34 : sent_event_count_(0), |
| 35 acked_event_count_(0), | 35 acked_event_count_(0), |
| 36 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), | 36 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), |
| 37 slop_length_dips_(0), | 37 slop_length_dips_(0), |
| 38 slop_includes_boundary_(true), | |
| 39 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {} | 38 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {} |
| 40 | 39 |
| 41 virtual ~TouchEventQueueTest() {} | 40 virtual ~TouchEventQueueTest() {} |
| 42 | 41 |
| 43 // testing::Test | 42 // testing::Test |
| 44 virtual void SetUp() OVERRIDE { ResetQueueWithConfig(CreateConfig()); } | 43 virtual void SetUp() OVERRIDE { ResetQueueWithConfig(CreateConfig()); } |
| 45 | 44 |
| 46 virtual void TearDown() OVERRIDE { | 45 virtual void TearDown() OVERRIDE { |
| 47 queue_.reset(); | 46 queue_.reset(); |
| 48 } | 47 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 GestureEventWithLatencyInfo(*followup_gesture_event, | 73 GestureEventWithLatencyInfo(*followup_gesture_event, |
| 75 ui::LatencyInfo())); | 74 ui::LatencyInfo())); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 protected: | 78 protected: |
| 80 TouchEventQueue::Config CreateConfig() { | 79 TouchEventQueue::Config CreateConfig() { |
| 81 TouchEventQueue::Config config; | 80 TouchEventQueue::Config config; |
| 82 config.touch_scrolling_mode = touch_scrolling_mode_; | 81 config.touch_scrolling_mode = touch_scrolling_mode_; |
| 83 config.touchmove_slop_suppression_length_dips = slop_length_dips_; | 82 config.touchmove_slop_suppression_length_dips = slop_length_dips_; |
| 84 config.touchmove_slop_suppression_region_includes_boundary = | |
| 85 slop_includes_boundary_; | |
| 86 return config; | 83 return config; |
| 87 } | 84 } |
| 88 | 85 |
| 89 void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) { | 86 void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) { |
| 90 touch_scrolling_mode_ = mode; | 87 touch_scrolling_mode_ = mode; |
| 91 ResetQueueWithConfig(CreateConfig()); | 88 ResetQueueWithConfig(CreateConfig()); |
| 92 } | 89 } |
| 93 | 90 |
| 94 void SetUpForTouchMoveSlopTesting(double slop_length_dips, | 91 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { |
| 95 bool slop_includes_boundary) { | |
| 96 slop_length_dips_ = slop_length_dips; | 92 slop_length_dips_ = slop_length_dips; |
| 97 slop_includes_boundary_ = slop_includes_boundary; | |
| 98 ResetQueueWithConfig(CreateConfig()); | 93 ResetQueueWithConfig(CreateConfig()); |
| 99 } | 94 } |
| 100 | 95 |
| 101 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) { | 96 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) { |
| 102 TouchEventQueue::Config config = CreateConfig(); | 97 TouchEventQueue::Config config = CreateConfig(); |
| 103 config.touch_ack_timeout_delay = timeout_delay; | 98 config.touch_ack_timeout_delay = timeout_delay; |
| 104 config.touch_ack_timeout_supported = true; | 99 config.touch_ack_timeout_supported = true; |
| 105 ResetQueueWithConfig(config); | 100 ResetQueueWithConfig(config); |
| 106 } | 101 } |
| 107 | 102 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 size_t sent_event_count_; | 241 size_t sent_event_count_; |
| 247 size_t acked_event_count_; | 242 size_t acked_event_count_; |
| 248 WebTouchEvent last_sent_event_; | 243 WebTouchEvent last_sent_event_; |
| 249 WebTouchEvent last_acked_event_; | 244 WebTouchEvent last_acked_event_; |
| 250 InputEventAckState last_acked_event_state_; | 245 InputEventAckState last_acked_event_state_; |
| 251 SyntheticWebTouchEvent touch_event_; | 246 SyntheticWebTouchEvent touch_event_; |
| 252 scoped_ptr<WebTouchEvent> followup_touch_event_; | 247 scoped_ptr<WebTouchEvent> followup_touch_event_; |
| 253 scoped_ptr<WebGestureEvent> followup_gesture_event_; | 248 scoped_ptr<WebGestureEvent> followup_gesture_event_; |
| 254 scoped_ptr<InputEventAckState> sync_ack_result_; | 249 scoped_ptr<InputEventAckState> sync_ack_result_; |
| 255 double slop_length_dips_; | 250 double slop_length_dips_; |
| 256 bool slop_includes_boundary_; | |
| 257 TouchEventQueue::TouchScrollingMode touch_scrolling_mode_; | 251 TouchEventQueue::TouchScrollingMode touch_scrolling_mode_; |
| 258 base::MessageLoopForUI message_loop_; | 252 base::MessageLoopForUI message_loop_; |
| 259 }; | 253 }; |
| 260 | 254 |
| 261 | 255 |
| 262 // Tests that touch-events are queued properly. | 256 // Tests that touch-events are queued properly. |
| 263 TEST_F(TouchEventQueueTest, Basic) { | 257 TEST_F(TouchEventQueueTest, Basic) { |
| 264 PressTouchPoint(1, 1); | 258 PressTouchPoint(1, 1); |
| 265 EXPECT_EQ(1U, queued_event_count()); | 259 EXPECT_EQ(1U, queued_event_count()); |
| 266 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 260 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 PressTouchPoint(0, 1); | 1358 PressTouchPoint(0, 1); |
| 1365 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1359 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1366 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1360 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1367 } | 1361 } |
| 1368 | 1362 |
| 1369 // Tests that TouchMove's are dropped if within the boundary-inclusive slop | 1363 // Tests that TouchMove's are dropped if within the boundary-inclusive slop |
| 1370 // suppression region for an unconsumed TouchStart. | 1364 // suppression region for an unconsumed TouchStart. |
| 1371 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) { | 1365 TEST_F(TouchEventQueueTest, TouchMoveSuppressionIncludingSlopBoundary) { |
| 1372 const double kSlopLengthDips = 10.; | 1366 const double kSlopLengthDips = 10.; |
| 1373 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1367 const double kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 1374 const bool slop_includes_boundary = true; | 1368 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1375 SetUpForTouchMoveSlopTesting(kSlopLengthDips, slop_includes_boundary); | |
| 1376 | 1369 |
| 1377 // Queue a TouchStart. | 1370 // Queue a TouchStart. |
| 1378 PressTouchPoint(0, 0); | 1371 PressTouchPoint(0, 0); |
| 1379 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1372 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1380 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1373 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1381 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1374 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1382 | 1375 |
| 1383 // TouchMove's within the region should be suppressed. | 1376 // TouchMove's within the region should be suppressed. |
| 1384 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1377 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| 1385 EXPECT_EQ(0U, queued_event_count()); | 1378 EXPECT_EQ(0U, queued_event_count()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 EXPECT_EQ(0U, queued_event_count()); | 1438 EXPECT_EQ(0U, queued_event_count()); |
| 1446 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1439 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1447 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1440 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1448 | 1441 |
| 1449 MoveTouchPoint(0, kSlopLengthDips, 0); | 1442 MoveTouchPoint(0, kSlopLengthDips, 0); |
| 1450 EXPECT_EQ(0U, queued_event_count()); | 1443 EXPECT_EQ(0U, queued_event_count()); |
| 1451 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1444 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1452 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1445 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1453 } | 1446 } |
| 1454 | 1447 |
| 1455 // Tests that TouchMove's are dropped if within the boundary-exclusive slop | |
| 1456 // suppression region for an unconsumed TouchStart. | |
| 1457 TEST_F(TouchEventQueueTest, TouchMoveSuppressionExcludingSlopBoundary) { | |
| 1458 const double kSlopLengthDips = 10.; | |
| 1459 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | |
| 1460 const bool slop_includes_boundary = false; | |
| 1461 SetUpForTouchMoveSlopTesting(kSlopLengthDips, slop_includes_boundary); | |
| 1462 | |
| 1463 // Queue a TouchStart. | |
| 1464 PressTouchPoint(0, 0); | |
| 1465 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1466 ASSERT_EQ(1U, GetAndResetSentEventCount()); | |
| 1467 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1468 | |
| 1469 // TouchMove's within the region should be suppressed. | |
| 1470 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | |
| 1471 EXPECT_EQ(0U, queued_event_count()); | |
| 1472 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1473 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1474 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); | |
| 1475 | |
| 1476 MoveTouchPoint(0, kSlopLengthDips - 0.2f, 0); | |
| 1477 EXPECT_EQ(0U, queued_event_count()); | |
| 1478 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1479 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1480 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, acked_event_state()); | |
| 1481 | |
| 1482 // As soon as a TouchMove reaches the (Euclidean) slop distance, no more | |
| 1483 // TouchMove's should be suppressed. | |
| 1484 MoveTouchPoint(0, kSlopLengthDips, 0); | |
| 1485 EXPECT_EQ(1U, queued_event_count()); | |
| 1486 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1487 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1488 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1489 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1490 | |
| 1491 MoveTouchPoint(0, kHalfSlopLengthDips, 0); | |
| 1492 EXPECT_EQ(1U, queued_event_count()); | |
| 1493 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1494 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1495 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1496 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1497 } | |
| 1498 | |
| 1499 // Tests that TouchMove's are not dropped within the slop suppression region if | 1448 // Tests that TouchMove's are not dropped within the slop suppression region if |
| 1500 // the touchstart was consumed. | 1449 // the touchstart was consumed. |
| 1501 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { | 1450 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { |
| 1502 const double kSlopLengthDips = 10.; | 1451 const double kSlopLengthDips = 10.; |
| 1503 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1452 const double kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 1504 const bool slop_includes_boundary = true; | 1453 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1505 SetUpForTouchMoveSlopTesting(kSlopLengthDips, slop_includes_boundary); | |
| 1506 | 1454 |
| 1507 // Queue a TouchStart. | 1455 // Queue a TouchStart. |
| 1508 PressTouchPoint(0, 0); | 1456 PressTouchPoint(0, 0); |
| 1509 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1457 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1510 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1458 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1511 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1459 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1512 | 1460 |
| 1513 // TouchMove's within the region should not be suppressed, as a touch was | 1461 // TouchMove's within the region should not be suppressed, as a touch was |
| 1514 // consumed. | 1462 // consumed. |
| 1515 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1463 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| 1516 EXPECT_EQ(1U, queued_event_count()); | 1464 EXPECT_EQ(1U, queued_event_count()); |
| 1517 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1465 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1518 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1466 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1519 } | 1467 } |
| 1520 | 1468 |
| 1521 // Tests that TouchMove's are not dropped due to incorrect handling of DPI | 1469 // Tests that TouchMove's are not dropped due to incorrect handling of DPI |
| 1522 // scaling. | 1470 // scaling. |
| 1523 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) { | 1471 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) { |
| 1524 const float kSlopLengthPixels = 7.f; | 1472 const float kSlopLengthPixels = 7.f; |
| 1525 const float kDPIScale = 3.f; | 1473 const float kDPIScale = 3.f; |
| 1526 const bool slop_includes_boundary = true; | 1474 SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale); |
| 1527 SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale, | |
| 1528 slop_includes_boundary); | |
| 1529 | 1475 |
| 1530 // Queue a TouchStart. | 1476 // Queue a TouchStart. |
| 1531 PressTouchPoint(0, 0); | 1477 PressTouchPoint(0, 0); |
| 1532 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1478 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1533 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1479 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1534 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1480 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1535 | 1481 |
| 1536 // TouchMove's along the slop boundary should be suppresed. | 1482 // TouchMove's along the slop boundary should be suppresed. |
| 1537 MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale); | 1483 MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale); |
| 1538 EXPECT_EQ(0U, queued_event_count()); | 1484 EXPECT_EQ(0U, queued_event_count()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1558 EXPECT_EQ(1U, queued_event_count()); | 1504 EXPECT_EQ(1U, queued_event_count()); |
| 1559 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1505 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1560 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1506 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1561 } | 1507 } |
| 1562 | 1508 |
| 1563 // Tests that TouchMove's are not dropped if a secondary pointer is present | 1509 // Tests that TouchMove's are not dropped if a secondary pointer is present |
| 1564 // during any movement. | 1510 // during any movement. |
| 1565 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { | 1511 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { |
| 1566 const double kSlopLengthDips = 10.; | 1512 const double kSlopLengthDips = 10.; |
| 1567 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1513 const double kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 1568 const bool slop_includes_boundary = true; | 1514 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1569 SetUpForTouchMoveSlopTesting(kSlopLengthDips, slop_includes_boundary); | |
| 1570 | 1515 |
| 1571 // Queue a TouchStart. | 1516 // Queue a TouchStart. |
| 1572 PressTouchPoint(0, 0); | 1517 PressTouchPoint(0, 0); |
| 1573 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1518 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1574 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1519 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1575 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1520 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1576 | 1521 |
| 1577 // TouchMove's within the region should be suppressed. | 1522 // TouchMove's within the region should be suppressed. |
| 1578 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1523 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| 1579 EXPECT_EQ(0U, queued_event_count()); | 1524 EXPECT_EQ(0U, queued_event_count()); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2046 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2102 | 2047 |
| 2103 // Touch move event is throttled. | 2048 // Touch move event is throttled. |
| 2104 MoveTouchPoint(0, 60, 5); | 2049 MoveTouchPoint(0, 60, 5); |
| 2105 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2050 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2106 EXPECT_EQ(0U, queued_event_count()); | 2051 EXPECT_EQ(0U, queued_event_count()); |
| 2107 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 2052 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2108 } | 2053 } |
| 2109 | 2054 |
| 2110 } // namespace content | 2055 } // namespace content |
| OLD | NEW |