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 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1431 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1432 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1432 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1433 | 1433 |
1434 // Simulate a secondary pointer press. | 1434 // Simulate a secondary pointer press. |
1435 PressTouchPoint(kSlopLengthDips, 0); | 1435 PressTouchPoint(kSlopLengthDips, 0); |
1436 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1436 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1437 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1437 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1438 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1438 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1439 | 1439 |
1440 // TouchMove with a secondary pointer should not be suppressed. | 1440 // TouchMove with a secondary pointer should not be suppressed. |
1441 MoveTouchPoint(1, kSlopLengthDips, 0); | 1441 MoveTouchPoint(1, kSlopLengthDips+1, 0); |
1442 EXPECT_EQ(1U, queued_event_count()); | 1442 EXPECT_EQ(1U, queued_event_count()); |
1443 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1443 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1444 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1444 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1445 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1445 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1446 | 1446 |
1447 // Release the secondary pointer. | 1447 // Release the secondary pointer. |
1448 ReleaseTouchPoint(0); | 1448 ReleaseTouchPoint(0); |
1449 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1449 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1450 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1450 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1451 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1451 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 // Queue a TouchStart. | 1521 // Queue a TouchStart. |
1522 PressTouchPoint(0, 1); | 1522 PressTouchPoint(0, 1); |
1523 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1523 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1524 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1524 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1525 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1525 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1526 | 1526 |
1527 for (int i = 0; i < 3; ++i) { | 1527 for (int i = 0; i < 3; ++i) { |
1528 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1528 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
1529 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1529 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1530 | 1530 |
1531 MoveTouchPoint(0, 10, 5); | 1531 MoveTouchPoint(0, 10, 5+i); |
1532 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1532 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1533 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 1533 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
1534 EXPECT_TRUE(sent_event().cancelable); | 1534 EXPECT_TRUE(sent_event().cancelable); |
1535 EXPECT_EQ(0U, queued_event_count()); | 1535 EXPECT_EQ(0U, queued_event_count()); |
1536 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1536 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1537 | 1537 |
1538 // Consuming a scroll event will throttle subsequent touchmoves. | 1538 // Consuming a scroll event will throttle subsequent touchmoves. |
1539 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1539 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
1540 INPUT_EVENT_ACK_STATE_CONSUMED); | 1540 INPUT_EVENT_ACK_STATE_CONSUMED); |
1541 MoveTouchPoint(0, 10, 5); | 1541 MoveTouchPoint(0, 10, 7+i); |
1542 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1542 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1543 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1543 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1544 EXPECT_EQ(0U, queued_event_count()); | 1544 EXPECT_EQ(0U, queued_event_count()); |
1545 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1545 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1546 } | 1546 } |
1547 } | 1547 } |
1548 | 1548 |
1549 // Ensure that touchmove's are appropriately throttled during a typical | 1549 // Ensure that touchmove's are appropriately throttled during a typical |
1550 // scroll sequences that transitions between scrolls consumed and unconsumed. | 1550 // scroll sequences that transitions between scrolls consumed and unconsumed. |
1551 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { | 1551 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1622 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1623 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1623 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1624 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1624 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1625 MoveTouchPoint(0, 0, 5); | 1625 MoveTouchPoint(0, 0, 5); |
1626 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1626 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1627 SetFollowupEvent(followup_scroll); | 1627 SetFollowupEvent(followup_scroll); |
1628 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1628 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1629 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1629 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1630 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1630 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1631 | 1631 |
1632 MoveTouchPoint(0, 0, 5); | 1632 MoveTouchPoint(0, 0, 6); |
1633 followup_scroll.type = WebInputEvent::GestureScrollUpdate; | 1633 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
1634 SetFollowupEvent(followup_scroll); | 1634 SetFollowupEvent(followup_scroll); |
1635 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1635 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1636 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 1636 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
1637 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1637 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1638 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1638 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1639 | 1639 |
1640 MoveTouchPoint(0, 0, 10); | 1640 MoveTouchPoint(0, 0, 10); |
1641 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1641 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1642 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1642 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 EXPECT_EQ(0U, queued_event_count()); | 1700 EXPECT_EQ(0U, queued_event_count()); |
1701 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1701 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1702 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1702 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1703 | 1703 |
1704 // An unconsumed scroll should resume synchronous touch handling. | 1704 // An unconsumed scroll should resume synchronous touch handling. |
1705 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1705 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
1706 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1706 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1707 | 1707 |
1708 // The pending touchmove should be coalesced with the next (now synchronous) | 1708 // The pending touchmove should be coalesced with the next (now synchronous) |
1709 // touchmove. | 1709 // touchmove. |
1710 MoveTouchPoint(0, 0, 25); | 1710 MoveTouchPoint(0, 0, 26); |
1711 EXPECT_TRUE(sent_event().cancelable); | 1711 EXPECT_TRUE(sent_event().cancelable); |
1712 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 1712 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
1713 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | 1713 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
1714 EXPECT_EQ(WebTouchPoint::StateStationary, sent_event().touches[0].state); | 1714 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state); |
1715 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); | 1715 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); |
1716 EXPECT_EQ(1U, queued_event_count()); | 1716 EXPECT_EQ(1U, queued_event_count()); |
1717 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1717 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1718 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 1718 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
1719 | 1719 |
1720 // Subsequent touches will queue until the preceding, synchronous touches are | 1720 // Subsequent touches will queue until the preceding, synchronous touches are |
1721 // ack'ed. | 1721 // ack'ed. |
1722 ReleaseTouchPoint(1); | 1722 ReleaseTouchPoint(1); |
1723 EXPECT_EQ(2U, queued_event_count()); | 1723 EXPECT_EQ(2U, queued_event_count()); |
1724 ReleaseTouchPoint(0); | 1724 ReleaseTouchPoint(0); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 ChangeTouchPointForce(0, 0.9f); | 2185 ChangeTouchPointForce(0, 0.9f); |
2186 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2186 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2187 | 2187 |
2188 // TouchMove is sent. Test for pointer state. | 2188 // TouchMove is sent. Test for pointer state. |
2189 const WebTouchEvent& event2 = sent_event(); | 2189 const WebTouchEvent& event2 = sent_event(); |
2190 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); | 2190 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); |
2191 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state); | 2191 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[0].state); |
2192 | 2192 |
2193 // Change touch point rotationAngle. | 2193 // Change touch point rotationAngle. |
2194 ChangeTouchPointRotationAngle(0, 1.1f); | 2194 ChangeTouchPointRotationAngle(0, 1.1f); |
| 2195 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2195 | 2196 |
2196 // TouchMove is sent. Test for pointer state. | 2197 // TouchMove is sent. Test for pointer state. |
2197 const WebTouchEvent& event3 = sent_event(); | 2198 const WebTouchEvent& event3 = sent_event(); |
2198 EXPECT_EQ(WebInputEvent::TouchMove, event3.type); | 2199 EXPECT_EQ(WebInputEvent::TouchMove, event3.type); |
2199 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state); | 2200 EXPECT_EQ(WebTouchPoint::StateMoved, event3.touches[0].state); |
2200 | 2201 |
2201 // TODO(jdduke): Now trying to forward a TouchMove event without really | 2202 EXPECT_EQ(0U, queued_event_count()); |
2202 // changing touch point properties. Update below test with testing for | 2203 EXPECT_EQ(4U, GetAndResetSentEventCount()); |
2203 // rejected TouchMove with ack state INPUT_EVENT_ACK_STATE_NOT_CONSUMED, | 2204 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
2204 // crbug.com/452032. Or should it be in a separte test?. | 2205 } |
2205 | 2206 |
2206 // Do not change any properties, but use previous values. | 2207 // Tests that TouchMoves are filtered when none of the points are changed. |
2207 MoveTouchPoint(0, 1.f, 1.f); | 2208 TEST_F(TouchEventQueueTest, FilterTouchMovesWhenNoPointerChanged) { |
2208 ChangeTouchPointRadius(0, 1.5f, 1.f); | 2209 PressTouchPoint(1, 1); |
| 2210 PressTouchPoint(2, 2); |
| 2211 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2212 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2213 EXPECT_EQ(0U, queued_event_count()); |
| 2214 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2215 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
2209 | 2216 |
2210 // Receive an ACK for previous TouchMove. | 2217 // Move 1st touch point. |
| 2218 MoveTouchPoint(0, 10, 10); |
| 2219 EXPECT_EQ(1U, queued_event_count()); |
| 2220 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2221 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 2222 |
| 2223 // TouchMove should be allowed and test for touches state. |
| 2224 const WebTouchEvent& event1 = sent_event(); |
| 2225 EXPECT_EQ(WebInputEvent::TouchMove, event1.type); |
| 2226 EXPECT_EQ(WebTouchPoint::StateMoved, event1.touches[0].state); |
| 2227 EXPECT_EQ(WebTouchPoint::StateStationary, event1.touches[1].state); |
| 2228 |
| 2229 // Do not really move any touch points, but use previous values. |
| 2230 MoveTouchPoint(0, 10, 10); |
| 2231 ChangeTouchPointRadius(1, 1, 1); |
| 2232 MoveTouchPoint(1, 2, 2); |
| 2233 EXPECT_EQ(2U, queued_event_count()); |
| 2234 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2235 |
| 2236 // Receive an ACK for 1st TouchMove. |
2211 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2237 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2212 | 2238 |
2213 // TouchMove is sent, but pointer state should be StateStationary. | 2239 // Tries to forward TouchMove but should be filtered |
2214 const WebTouchEvent& event4 = sent_event(); | 2240 // when none of the touch points have changed. |
2215 EXPECT_EQ(WebInputEvent::TouchMove, event4.type); | 2241 EXPECT_EQ(0U, queued_event_count()); |
2216 EXPECT_EQ(WebTouchPoint::StateStationary, event4.touches[0].state); | 2242 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 2243 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
| 2244 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 2245 |
| 2246 // Move 2nd touch point. |
| 2247 MoveTouchPoint(1, 3, 3); |
| 2248 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2249 EXPECT_EQ(0U, queued_event_count()); |
| 2250 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2251 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2252 |
| 2253 // TouchMove should be allowed and test for touches state. |
| 2254 const WebTouchEvent& event2 = sent_event(); |
| 2255 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); |
| 2256 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); |
| 2257 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
2217 } | 2258 } |
2218 | 2259 |
2219 } // namespace content | 2260 } // namespace content |
OLD | NEW |