| 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 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 | 1329 |
| 1330 // A new touch sequence should reset suppression. | 1330 // A new touch sequence should reset suppression. |
| 1331 ReleaseTouchPoint(0); | 1331 ReleaseTouchPoint(0); |
| 1332 PressTouchPoint(0, 0); | 1332 PressTouchPoint(0, 0); |
| 1333 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1333 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1334 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1334 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1335 ASSERT_EQ(2U, GetAndResetSentEventCount()); | 1335 ASSERT_EQ(2U, GetAndResetSentEventCount()); |
| 1336 ASSERT_EQ(2U, GetAndResetAckedEventCount()); | 1336 ASSERT_EQ(2U, GetAndResetAckedEventCount()); |
| 1337 ASSERT_EQ(0U, queued_event_count()); | 1337 ASSERT_EQ(0U, queued_event_count()); |
| 1338 | 1338 |
| 1339 // The slop region is boundary-inclusive. | 1339 // The slop region is boundary-exclusive. |
| 1340 MoveTouchPoint(0, kSlopLengthDips, 0); | 1340 // TODO(jdduke): Change to inclusive upon resolving crbug.com/336807. |
| 1341 MoveTouchPoint(0, kSlopLengthDips - 1., 0); |
| 1341 EXPECT_EQ(0U, queued_event_count()); | 1342 EXPECT_EQ(0U, queued_event_count()); |
| 1342 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1343 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1343 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1344 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1344 | 1345 |
| 1345 MoveTouchPoint(0, kSlopLengthDips + 1., 0); | 1346 MoveTouchPoint(0, kSlopLengthDips, 0); |
| 1346 EXPECT_EQ(1U, queued_event_count()); | 1347 EXPECT_EQ(1U, queued_event_count()); |
| 1347 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1348 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1348 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1349 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1349 } | 1350 } |
| 1350 | 1351 |
| 1351 // Tests that TouchMove's are not dropped within the slop suppression region if | 1352 // Tests that TouchMove's are not dropped within the slop suppression region if |
| 1352 // the touchstart was consumed. | 1353 // the touchstart was consumed. |
| 1353 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { | 1354 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterTouchConsumed) { |
| 1354 const double kSlopLengthDips = 10.; | 1355 const double kSlopLengthDips = 10.; |
| 1355 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1356 const double kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 1356 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1357 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1357 | 1358 |
| 1358 // Queue a TouchStart. | 1359 // Queue a TouchStart. |
| 1359 PressTouchPoint(0, 1); | 1360 PressTouchPoint(0, 0); |
| 1360 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1361 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1361 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1362 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1362 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1363 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1363 | 1364 |
| 1364 // TouchMove's within the region should not be suppressed, as a touch was | 1365 // TouchMove's within the region should not be suppressed, as a touch was |
| 1365 // consumed. | 1366 // consumed. |
| 1366 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1367 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| 1367 EXPECT_EQ(1U, queued_event_count()); | 1368 EXPECT_EQ(1U, queued_event_count()); |
| 1368 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1369 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1369 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1370 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1370 } | 1371 } |
| 1371 | 1372 |
| 1373 // Tests that TouchMove's are not dropped due to integral truncation of |
| 1374 // WebTouchPoint coordinates after DPI scaling. |
| 1375 TEST_F(TouchEventQueueTest, TouchMoveSuppressionWithDIPScaling) { |
| 1376 const float kSlopLengthPixels = 7.f; |
| 1377 const float kDPIScale = 3.f; |
| 1378 SetUpForTouchMoveSlopTesting(kSlopLengthPixels / kDPIScale); |
| 1379 |
| 1380 // Queue a TouchStart. |
| 1381 PressTouchPoint(0, 0); |
| 1382 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1383 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1384 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1385 |
| 1386 // TouchMove's along the slop boundary should not be suppresed. |
| 1387 // TODO(jdduke): These should be suppressed, crbug.com/336807. |
| 1388 MoveTouchPoint(0, 0, kSlopLengthPixels / kDPIScale); |
| 1389 EXPECT_EQ(1U, queued_event_count()); |
| 1390 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1391 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1392 |
| 1393 // Reset the touch sequence. |
| 1394 ReleaseTouchPoint(0); |
| 1395 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1396 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1397 GetAndResetSentEventCount(); |
| 1398 GetAndResetAckedEventCount(); |
| 1399 |
| 1400 // Queue a TouchStart. |
| 1401 PressTouchPoint(0, 0); |
| 1402 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1403 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1404 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1405 |
| 1406 // TouchMove's outside the region should not be suppressed. |
| 1407 const float kPixelCoordOutsideSlopRegion = kSlopLengthPixels + 1.f; |
| 1408 MoveTouchPoint(0, 0, kPixelCoordOutsideSlopRegion / kDPIScale); |
| 1409 EXPECT_EQ(1U, queued_event_count()); |
| 1410 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1411 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1412 } |
| 1413 |
| 1414 |
| 1372 // Tests that TouchMove's are not dropped if a secondary pointer is present | 1415 // Tests that TouchMove's are not dropped if a secondary pointer is present |
| 1373 // during any movement. | 1416 // during any movement. |
| 1374 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { | 1417 TEST_F(TouchEventQueueTest, NoTouchMoveSuppressionAfterMultiTouch) { |
| 1375 const double kSlopLengthDips = 10.; | 1418 const double kSlopLengthDips = 10.; |
| 1376 const double kHalfSlopLengthDips = kSlopLengthDips / 2; | 1419 const double kHalfSlopLengthDips = kSlopLengthDips / 2; |
| 1377 const double kDoubleSlopLengthDips = 10.; | 1420 const double kDoubleSlopLengthDips = 10.; |
| 1378 SetUpForTouchMoveSlopTesting(kSlopLengthDips); | 1421 SetUpForTouchMoveSlopTesting(kSlopLengthDips); |
| 1379 | 1422 |
| 1380 // Queue a TouchStart. | 1423 // Queue a TouchStart. |
| 1381 PressTouchPoint(0, 1); | 1424 PressTouchPoint(0, 0); |
| 1382 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1425 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1383 ASSERT_EQ(1U, GetAndResetSentEventCount()); | 1426 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1384 ASSERT_EQ(1U, GetAndResetAckedEventCount()); | 1427 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1385 | 1428 |
| 1386 // TouchMove's within the region should be suppressed. | 1429 // TouchMove's within the region should be suppressed. |
| 1387 MoveTouchPoint(0, 0, kHalfSlopLengthDips); | 1430 MoveTouchPoint(0, 0, kHalfSlopLengthDips); |
| 1388 EXPECT_EQ(0U, queued_event_count()); | 1431 EXPECT_EQ(0U, queued_event_count()); |
| 1389 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1432 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1390 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1433 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1391 | 1434 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1504 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 1462 INPUT_EVENT_ACK_STATE_CONSUMED); | 1505 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1463 MoveTouchPoint(0, 20, 5); | 1506 MoveTouchPoint(0, 20, 5); |
| 1464 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1507 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1465 EXPECT_EQ(0U, queued_event_count()); | 1508 EXPECT_EQ(0U, queued_event_count()); |
| 1466 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1509 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1467 } | 1510 } |
| 1468 } | 1511 } |
| 1469 | 1512 |
| 1470 } // namespace content | 1513 } // namespace content |
| OLD | NEW |