| 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" |
| 11 #include "content/common/input/synthetic_web_input_event_builders.h" | 11 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/web/WebInputEvent.h" | 13 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 14 | 14 |
| 15 using blink::WebGestureEvent; | 15 using blink::WebGestureEvent; |
| 16 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
| 17 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
| 18 using blink::WebTouchPoint; | 18 using blink::WebTouchPoint; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 namespace { | 21 namespace { |
| 22 | |
| 23 const double kMinSecondsBetweenThrottledTouchmoves = 0.2; | |
| 24 | |
| 25 base::TimeDelta DefaultTouchTimeoutDelay() { | 22 base::TimeDelta DefaultTouchTimeoutDelay() { |
| 26 return base::TimeDelta::FromMilliseconds(1); | 23 return base::TimeDelta::FromMilliseconds(1); |
| 27 } | 24 } |
| 28 } // namespace | 25 } // namespace |
| 29 | 26 |
| 30 class TouchEventQueueTest : public testing::Test, | 27 class TouchEventQueueTest : public testing::Test, |
| 31 public TouchEventQueueClient { | 28 public TouchEventQueueClient { |
| 32 public: | 29 public: |
| 33 TouchEventQueueTest() | 30 TouchEventQueueTest() |
| 34 : sent_event_count_(0), | 31 : sent_event_count_(0), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void ReleaseTouchPoint(int index) { | 149 void ReleaseTouchPoint(int index) { |
| 153 touch_event_.ReleasePoint(index); | 150 touch_event_.ReleasePoint(index); |
| 154 SendTouchEvent(); | 151 SendTouchEvent(); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void CancelTouchPoint(int index) { | 154 void CancelTouchPoint(int index) { |
| 158 touch_event_.CancelPoint(index); | 155 touch_event_.CancelPoint(index); |
| 159 SendTouchEvent(); | 156 SendTouchEvent(); |
| 160 } | 157 } |
| 161 | 158 |
| 162 void AdvanceTouchTime(double seconds) { | |
| 163 touch_event_.timeStampSeconds += seconds; | |
| 164 } | |
| 165 | |
| 166 size_t GetAndResetAckedEventCount() { | 159 size_t GetAndResetAckedEventCount() { |
| 167 size_t count = acked_event_count_; | 160 size_t count = acked_event_count_; |
| 168 acked_event_count_ = 0; | 161 acked_event_count_ = 0; |
| 169 return count; | 162 return count; |
| 170 } | 163 } |
| 171 | 164 |
| 172 size_t GetAndResetSentEventCount() { | 165 size_t GetAndResetSentEventCount() { |
| 173 size_t count = sent_event_count_; | 166 size_t count = sent_event_count_; |
| 174 sent_event_count_ = 0; | 167 sent_event_count_ = 0; |
| 175 return count; | 168 return count; |
| 176 } | 169 } |
| 177 | 170 |
| 178 bool IsPendingAckTouchStart() const { | 171 bool IsPendingAckTouchStart() const { |
| 179 return queue_->IsPendingAckTouchStart(); | 172 return queue_->IsPendingAckTouchStart(); |
| 180 } | 173 } |
| 181 | 174 |
| 182 void OnHasTouchEventHandlers(bool has_handlers) { | 175 void OnHasTouchEventHandlers(bool has_handlers) { |
| 183 queue_->OnHasTouchEventHandlers(has_handlers); | 176 queue_->OnHasTouchEventHandlers(has_handlers); |
| 184 } | 177 } |
| 185 | 178 |
| 186 void SetAckTimeoutDisabled() { | 179 void SetAckTimeoutDisabled() { |
| 187 queue_->SetAckTimeoutEnabled(false, base::TimeDelta()); | 180 queue_->SetAckTimeoutEnabled(false, base::TimeDelta()); |
| 188 } | 181 } |
| 189 | 182 |
| 190 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); } | 183 bool IsTimeoutEnabled() { |
| 184 return queue_->ack_timeout_enabled(); |
| 185 } |
| 191 | 186 |
| 192 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } | 187 bool IsTimeoutRunning() { |
| 193 | 188 return queue_->IsTimeoutRunningForTesting(); |
| 194 bool HasPendingAsyncTouchMove() const { | |
| 195 return queue_->HasPendingAsyncTouchMoveForTesting(); | |
| 196 } | 189 } |
| 197 | 190 |
| 198 size_t queued_event_count() const { | 191 size_t queued_event_count() const { |
| 199 return queue_->size(); | 192 return queue_->size(); |
| 200 } | 193 } |
| 201 | 194 |
| 202 const WebTouchEvent& latest_event() const { | 195 const WebTouchEvent& latest_event() const { |
| 203 return queue_->GetLatestEventForTesting().event; | 196 return queue_->GetLatestEventForTesting().event; |
| 204 } | 197 } |
| 205 | 198 |
| (...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 // GestureScrollBegin doesn't insert a synthetic TouchCancel. | 1530 // GestureScrollBegin doesn't insert a synthetic TouchCancel. |
| 1538 WebGestureEvent followup_scroll; | 1531 WebGestureEvent followup_scroll; |
| 1539 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1532 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1540 SetFollowupEvent(followup_scroll); | 1533 SetFollowupEvent(followup_scroll); |
| 1541 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1534 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1542 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1535 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1543 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1536 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1544 EXPECT_EQ(0U, queued_event_count()); | 1537 EXPECT_EQ(0U, queued_event_count()); |
| 1545 } | 1538 } |
| 1546 | 1539 |
| 1547 TEST_F(TouchEventQueueTest, AsyncTouch) { | 1540 TEST_F(TouchEventQueueTest, TouchAbsorption) { |
| 1548 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | 1541 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE); |
| 1549 | 1542 |
| 1550 // Queue a TouchStart. | 1543 // Queue a TouchStart. |
| 1551 PressTouchPoint(0, 1); | 1544 PressTouchPoint(0, 1); |
| 1552 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1545 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1553 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1546 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1554 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1547 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1555 | 1548 |
| 1556 for (int i = 0; i < 3; ++i) { | 1549 for (int i = 0; i < 3; ++i) { |
| 1557 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1550 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 1558 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1551 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1559 | 1552 |
| 1560 MoveTouchPoint(0, 10, 5); | 1553 MoveTouchPoint(0, 20, 5); |
| 1561 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1554 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1562 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1563 EXPECT_TRUE(sent_event().cancelable); | |
| 1564 EXPECT_EQ(0U, queued_event_count()); | 1555 EXPECT_EQ(0U, queued_event_count()); |
| 1565 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1556 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1566 | 1557 |
| 1567 // Consuming a scroll event will throttle subsequent touchmoves. | 1558 // Consuming a scroll event prevents the next touch moves from being |
| 1559 // dispatched. |
| 1568 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | 1560 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 1569 INPUT_EVENT_ACK_STATE_CONSUMED); | 1561 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1570 MoveTouchPoint(0, 10, 5); | 1562 MoveTouchPoint(0, 20, 5); |
| 1571 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1563 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1572 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1573 EXPECT_EQ(0U, queued_event_count()); | 1564 EXPECT_EQ(0U, queued_event_count()); |
| 1574 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1565 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1575 } | 1566 } |
| 1576 } | 1567 } |
| 1577 | 1568 |
| 1578 // Ensure that touchmove's are appropriately throttled during a typical | 1569 TEST_F(TouchEventQueueTest, TouchAbsorptionNoTouchAfterScroll) { |
| 1579 // scroll sequences that transitions between scrolls consumed and unconsumed. | 1570 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE); |
| 1580 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { | |
| 1581 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | |
| 1582 | 1571 |
| 1583 // Process a TouchStart | 1572 // Process a TouchStart |
| 1584 PressTouchPoint(0, 1); | 1573 PressTouchPoint(0, 1); |
| 1585 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1574 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1586 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1575 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1587 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1576 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1588 | 1577 |
| 1589 // Now send the first touch move and associated GestureScrollBegin, | 1578 // Now send the first touch move and associated GestureScrollBegin, |
| 1590 // but don't ACK the gesture event yet. | 1579 // but don't ACK the gesture event yet. |
| 1591 MoveTouchPoint(0, 0, 5); | 1580 MoveTouchPoint(0, 0, 5); |
| 1592 WebGestureEvent followup_scroll; | 1581 WebGestureEvent followup_scroll; |
| 1593 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1582 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1594 SetFollowupEvent(followup_scroll); | 1583 SetFollowupEvent(followup_scroll); |
| 1595 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1584 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1596 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1585 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1597 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1586 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1598 | 1587 |
| 1599 // Now queue a second touchmove and verify it's not (yet) dispatched. | 1588 // Now queue a second touchmove and verify it's not dispatched. |
| 1600 MoveTouchPoint(0, 0, 10); | 1589 MoveTouchPoint(0, 0, 10); |
| 1601 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1590 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1602 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1603 EXPECT_EQ(0U, queued_event_count()); | 1591 EXPECT_EQ(0U, queued_event_count()); |
| 1604 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1592 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1605 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1593 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1606 | 1594 |
| 1607 // Queuing the final touchend should flush the pending, async touchmove. | 1595 // But a final touchend is sent (even before any gesture events |
| 1596 // have been ACKed). |
| 1608 ReleaseTouchPoint(0); | 1597 ReleaseTouchPoint(0); |
| 1609 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 1610 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1611 EXPECT_FALSE(sent_event().cancelable); | |
| 1612 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1613 EXPECT_EQ(2U, queued_event_count()); | |
| 1614 | |
| 1615 // Ack the flushed, async touchmove. The ack should not reach the client, but | |
| 1616 // it should trigger sending of the (now non-cancelable) touchend. | |
| 1617 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1618 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); | |
| 1619 EXPECT_FALSE(sent_event().cancelable); | |
| 1620 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1621 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1622 EXPECT_EQ(1U, queued_event_count()); | |
| 1623 | |
| 1624 // Ack the touchend. | |
| 1625 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1598 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1626 EXPECT_EQ(0U, queued_event_count()); | 1599 EXPECT_EQ(0U, queued_event_count()); |
| 1627 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1600 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1628 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1601 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1602 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); |
| 1629 | 1603 |
| 1630 // Now mark the scroll as not consumed (which would cause future | 1604 // Now mark the scroll as not consumed (which would cause future |
| 1631 // touchmoves in the active sequence to be sent if there was one). | 1605 // touchmoves in the active sequence to be sent if there was one). |
| 1632 SendGestureEventAck(WebInputEvent::GestureScrollBegin, | 1606 SendGestureEventAck(WebInputEvent::GestureScrollBegin, |
| 1633 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1607 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1634 | 1608 |
| 1635 // Start a new touch sequence and verify that throttling has been reset. | 1609 // Start a new touch sequence and verify that absorption has been |
| 1636 // Touch moves after the start of scrolling will again be throttled. | 1610 // reset so that moves after the start of scrolling are not sent. |
| 1637 PressTouchPoint(0, 0); | 1611 PressTouchPoint(0, 1); |
| 1638 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1612 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1639 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1613 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1640 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1614 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1641 MoveTouchPoint(0, 0, 5); | 1615 MoveTouchPoint(0, 0, 5); |
| 1642 SetFollowupEvent(followup_scroll); | 1616 SetFollowupEvent(followup_scroll); |
| 1643 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1617 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1644 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1618 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1645 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1619 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1646 MoveTouchPoint(0, 0, 10); | 1620 MoveTouchPoint(0, 0, 10); |
| 1647 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1621 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1648 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1649 EXPECT_EQ(0U, queued_event_count()); | 1622 EXPECT_EQ(0U, queued_event_count()); |
| 1650 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1623 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1651 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1652 | |
| 1653 // As soon as a touchmove exceeds the outer slop region it will be forwarded | |
| 1654 // immediately. | |
| 1655 MoveTouchPoint(0, 0, 20); | |
| 1656 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1657 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1658 EXPECT_FALSE(sent_event().cancelable); | |
| 1659 EXPECT_EQ(0U, queued_event_count()); | |
| 1660 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1661 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1662 | |
| 1663 // Subsequent touchmove's should be deferred. | |
| 1664 MoveTouchPoint(0, 0, 25); | |
| 1665 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1666 EXPECT_EQ(0U, queued_event_count()); | |
| 1667 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1668 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1669 | |
| 1670 // The pending touchmove should be flushed with the the new touchmove if | |
| 1671 // sufficient time has passed. | |
| 1672 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 1673 MoveTouchPoint(0, 0, 15); | |
| 1674 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1675 EXPECT_FALSE(sent_event().cancelable); | |
| 1676 EXPECT_EQ(1U, queued_event_count()); | |
| 1677 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1678 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1679 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1680 EXPECT_EQ(0U, queued_event_count()); | |
| 1681 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1682 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1683 | |
| 1684 // Non-touchmove events should always flush any pending touchmove events. | |
| 1685 MoveTouchPoint(0, 0, 25); | |
| 1686 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1687 EXPECT_EQ(0U, queued_event_count()); | |
| 1688 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1689 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1690 PressTouchPoint(30, 30); | |
| 1691 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1692 EXPECT_FALSE(sent_event().cancelable); | |
| 1693 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 1694 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1695 EXPECT_EQ(2U, queued_event_count()); | |
| 1696 | |
| 1697 // Ack'ing the flushed, async touchmove will dispatch the touchstart. Note | |
| 1698 // that the flushed touchmove's ack will not reach the client (its | |
| 1699 // constituent events have already been ack'ed). | |
| 1700 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1701 EXPECT_FALSE(sent_event().cancelable); | |
| 1702 EXPECT_EQ(WebInputEvent::TouchStart, sent_event().type); | |
| 1703 EXPECT_EQ(1U, queued_event_count()); | |
| 1704 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1705 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1706 | |
| 1707 // Ack the touchstart. | |
| 1708 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1709 EXPECT_EQ(0U, queued_event_count()); | |
| 1710 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1711 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1712 | |
| 1713 // Send a secondary touchmove. | |
| 1714 MoveTouchPoint(1, 0, 25); | |
| 1715 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1716 EXPECT_EQ(0U, queued_event_count()); | |
| 1717 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1719 | |
| 1720 // An unconsumed scroll should resume synchronous touch handling. | |
| 1721 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1722 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1723 | |
| 1724 // The pending touchmove should be coalesced with the next (now synchronous) | |
| 1725 // touchmove. | |
| 1726 MoveTouchPoint(0, 0, 25); | |
| 1727 EXPECT_TRUE(sent_event().cancelable); | |
| 1728 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1729 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | |
| 1730 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[0].state); | |
| 1731 EXPECT_EQ(WebTouchPoint::StateMoved, sent_event().touches[1].state); | |
| 1732 EXPECT_EQ(1U, queued_event_count()); | |
| 1733 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1734 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1735 | |
| 1736 // Subsequent touches will queue until the preceding, synchronous touches are | |
| 1737 // ack'ed. | |
| 1738 ReleaseTouchPoint(1); | |
| 1739 EXPECT_EQ(2U, queued_event_count()); | |
| 1740 ReleaseTouchPoint(0); | |
| 1741 EXPECT_EQ(3U, queued_event_count()); | |
| 1742 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1743 EXPECT_TRUE(sent_event().cancelable); | |
| 1744 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); | |
| 1745 EXPECT_EQ(2U, queued_event_count()); | |
| 1746 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1747 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1748 | |
| 1749 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1750 EXPECT_TRUE(sent_event().cancelable); | |
| 1751 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); | |
| 1752 EXPECT_EQ(1U, queued_event_count()); | |
| 1753 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1754 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1755 | |
| 1756 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1757 EXPECT_EQ(0U, queued_event_count()); | |
| 1758 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1759 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1760 } | |
| 1761 | |
| 1762 // Ensure that async touch dispatch and touch ack timeout interactions work | |
| 1763 // appropriately. | |
| 1764 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { | |
| 1765 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | |
| 1766 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | |
| 1767 | |
| 1768 // The touchstart should start the timeout. | |
| 1769 PressTouchPoint(0, 0); | |
| 1770 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1771 EXPECT_TRUE(IsTimeoutRunning()); | |
| 1772 | |
| 1773 // The start of a scroll gesture should triger async touch event dispatch. | |
| 1774 WebGestureEvent followup_scroll; | |
| 1775 followup_scroll.type = WebInputEvent::GestureScrollBegin; | |
| 1776 SetFollowupEvent(followup_scroll); | |
| 1777 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1778 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1779 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1780 | |
| 1781 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1782 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1783 | |
| 1784 // An async touch should fire after the throttling interval has expired, but | |
| 1785 // it should not start the touch ack timeout. | |
| 1786 MoveTouchPoint(0, 5, 5); | |
| 1787 EXPECT_TRUE(HasPendingAsyncTouchMove()); | |
| 1788 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1789 | |
| 1790 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | |
| 1791 MoveTouchPoint(0, 5, 5); | |
| 1792 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1793 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1794 EXPECT_FALSE(sent_event().cancelable); | |
| 1795 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1796 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1797 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1798 | |
| 1799 // An unconsumed scroll event will resume synchronous touchmoves, which are | |
| 1800 // subject to the ack timeout. | |
| 1801 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1802 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1803 MoveTouchPoint(0, 20, 5); | |
| 1804 EXPECT_TRUE(IsTimeoutRunning()); | |
| 1805 EXPECT_TRUE(sent_event().cancelable); | |
| 1806 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1807 | |
| 1808 // The timeout should fire, disabling touch forwarding until both acks are | |
| 1809 // received and acking the timed out event. | |
| 1810 RunTasksAndWait(DefaultTouchTimeoutDelay() * 2); | |
| 1811 EXPECT_FALSE(IsTimeoutRunning()); | |
| 1812 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1813 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1814 | |
| 1815 // Ack'ing the original event should trigger a cancel event. | |
| 1816 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1817 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1818 EXPECT_FALSE(sent_event().cancelable); | |
| 1819 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 1820 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 1821 | |
| 1822 // Subsequent touchmove's should not be forwarded, even as the scroll gesture | |
| 1823 // goes from unconsumed to consumed. | |
| 1824 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1825 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1826 MoveTouchPoint(0, 20, 5); | |
| 1827 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1828 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1829 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1830 | |
| 1831 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, | |
| 1832 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1833 MoveTouchPoint(0, 25, 5); | |
| 1834 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
| 1835 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
| 1836 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 1837 } | 1624 } |
| 1838 | 1625 |
| 1839 } // namespace content | 1626 } // namespace content |
| OLD | NEW |