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 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 // scroll sequences that transitions between scrolls consumed and unconsumed. | 1710 // scroll sequences that transitions between scrolls consumed and unconsumed. |
1711 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { | 1711 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { |
1712 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | 1712 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
1713 | 1713 |
1714 // Process a TouchStart | 1714 // Process a TouchStart |
1715 PressTouchPoint(0, 1); | 1715 PressTouchPoint(0, 1); |
1716 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1716 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1717 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1717 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1719 | 1719 |
1720 // Now send the first touch move and associated GestureScrollBegin, | 1720 // Now send the first touch move and associated GestureScrollBegin. |
1721 // but don't ACK the gesture event yet. | |
1722 MoveTouchPoint(0, 0, 5); | 1721 MoveTouchPoint(0, 0, 5); |
1723 WebGestureEvent followup_scroll; | 1722 WebGestureEvent followup_scroll; |
1724 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1723 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1725 SetFollowupEvent(followup_scroll); | 1724 SetFollowupEvent(followup_scroll); |
1726 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1725 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1727 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1726 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1728 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1727 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1728 SendGestureEventAck(WebInputEvent::GestureScrollBegin, |
| 1729 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1730 |
| 1731 // Send the second touch move and associated GestureScrollUpdate, but don't |
| 1732 // ACK the gesture event yet. |
| 1733 MoveTouchPoint(0, 0, 5); |
| 1734 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 1735 SetFollowupEvent(followup_scroll); |
| 1736 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1737 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1738 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1729 | 1739 |
1730 // Now queue a second touchmove and verify it's not (yet) dispatched. | 1740 // Now queue a second touchmove and verify it's not (yet) dispatched. |
1731 MoveTouchPoint(0, 0, 10); | 1741 MoveTouchPoint(0, 0, 10); |
1732 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1742 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1733 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1743 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1734 EXPECT_EQ(0U, queued_event_count()); | 1744 EXPECT_EQ(0U, queued_event_count()); |
1735 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1745 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1736 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1746 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1737 | 1747 |
1738 // Queuing the final touchend should flush the pending, async touchmove. | 1748 // Queuing the final touchend should flush the pending, async touchmove. |
(...skipping 14 matching lines...) Expand all Loading... |
1753 EXPECT_EQ(1U, queued_event_count()); | 1763 EXPECT_EQ(1U, queued_event_count()); |
1754 | 1764 |
1755 // Ack the touchend. | 1765 // Ack the touchend. |
1756 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1766 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1757 EXPECT_EQ(0U, queued_event_count()); | 1767 EXPECT_EQ(0U, queued_event_count()); |
1758 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1768 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1759 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1769 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1760 | 1770 |
1761 // Now mark the scroll as not consumed (which would cause future | 1771 // Now mark the scroll as not consumed (which would cause future |
1762 // touchmoves in the active sequence to be sent if there was one). | 1772 // touchmoves in the active sequence to be sent if there was one). |
1763 SendGestureEventAck(WebInputEvent::GestureScrollBegin, | 1773 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
1764 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1774 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1765 | 1775 |
1766 // Start a new touch sequence and verify that throttling has been reset. | 1776 // Start a new touch sequence and verify that throttling has been reset. |
1767 // Touch moves after the start of scrolling will again be throttled. | 1777 // Touch moves after the start of scrolling will again be throttled. |
1768 PressTouchPoint(0, 0); | 1778 PressTouchPoint(0, 0); |
1769 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1779 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1770 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1780 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1771 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1781 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1772 MoveTouchPoint(0, 0, 5); | 1782 MoveTouchPoint(0, 0, 5); |
| 1783 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1773 SetFollowupEvent(followup_scroll); | 1784 SetFollowupEvent(followup_scroll); |
1774 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1785 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1775 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1786 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1776 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1787 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1788 |
| 1789 MoveTouchPoint(0, 0, 5); |
| 1790 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 1791 SetFollowupEvent(followup_scroll); |
| 1792 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1793 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1794 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1795 |
1777 MoveTouchPoint(0, 0, 10); | 1796 MoveTouchPoint(0, 0, 10); |
1778 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1797 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1779 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1798 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1780 EXPECT_EQ(0U, queued_event_count()); | 1799 EXPECT_EQ(0U, queued_event_count()); |
1781 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1800 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1782 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1801 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1783 | 1802 |
1784 // As soon as a touchmove exceeds the outer slop region it will be forwarded | 1803 // As soon as a touchmove exceeds the outer slop region it will be forwarded |
1785 // immediately. | 1804 // immediately. |
1786 MoveTouchPoint(0, 0, 20); | 1805 MoveTouchPoint(0, 0, 20); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 // The start of a scroll gesture should trigger async touch event dispatch. | 2005 // The start of a scroll gesture should trigger async touch event dispatch. |
1987 MoveTouchPoint(0, 1, 1); | 2006 MoveTouchPoint(0, 1, 1); |
1988 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2007 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1989 WebGestureEvent followup_scroll; | 2008 WebGestureEvent followup_scroll; |
1990 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 2009 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1991 SetFollowupEvent(followup_scroll); | 2010 SetFollowupEvent(followup_scroll); |
1992 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2011 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1993 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2012 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1994 EXPECT_EQ(0U, queued_event_count()); | 2013 EXPECT_EQ(0U, queued_event_count()); |
1995 | 2014 |
| 2015 SendGestureEvent(WebInputEvent::GestureScrollUpdate); |
| 2016 |
1996 // The async touchmove should be ack'ed immediately, but not forwarded. | 2017 // The async touchmove should be ack'ed immediately, but not forwarded. |
1997 // However, because the ack triggers a touchcancel, both the pending touch and | 2018 // However, because the ack triggers a touchcancel, both the pending touch and |
1998 // the queued touchcancel should be flushed. | 2019 // the queued touchcancel should be flushed. |
1999 WebTouchEvent followup_cancel; | 2020 WebTouchEvent followup_cancel; |
2000 followup_cancel.type = WebInputEvent::TouchCancel; | 2021 followup_cancel.type = WebInputEvent::TouchCancel; |
2001 followup_cancel.touchesLength = 1; | 2022 followup_cancel.touchesLength = 1; |
2002 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; | 2023 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; |
2003 SetFollowupEvent(followup_cancel); | 2024 SetFollowupEvent(followup_cancel); |
2004 MoveTouchPoint(0, 5, 5); | 2025 MoveTouchPoint(0, 5, 5); |
2005 EXPECT_EQ(2U, queued_event_count()); | 2026 EXPECT_EQ(2U, queued_event_count()); |
2006 EXPECT_FALSE(sent_event().cancelable); | 2027 EXPECT_FALSE(sent_event().cancelable); |
2007 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 2028 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
2008 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 2029 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
2009 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | 2030 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
2010 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2031 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2011 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2032 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2012 | 2033 |
2013 // The ack for the asnc touchmove should not reach the client, as it has | 2034 // The ack for the async touchmove should not reach the client, as it has |
2014 // already been ack'ed. | 2035 // already been ack'ed. |
2015 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2036 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2016 EXPECT_FALSE(sent_event().cancelable); | 2037 EXPECT_FALSE(sent_event().cancelable); |
2017 EXPECT_EQ(1U, queued_event_count()); | 2038 EXPECT_EQ(1U, queued_event_count()); |
2018 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 2039 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
2019 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 2040 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
2020 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2041 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2021 | 2042 |
2022 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2043 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2023 EXPECT_EQ(0U, queued_event_count()); | 2044 EXPECT_EQ(0U, queued_event_count()); |
2024 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); | 2045 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); |
2025 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2046 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2026 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 2047 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
2027 } | 2048 } |
2028 | 2049 |
| 2050 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { |
| 2051 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
| 2052 |
| 2053 // Queue a TouchStart. |
| 2054 PressTouchPoint(0, 1); |
| 2055 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2056 EXPECT_EQ(0U, queued_event_count()); |
| 2057 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2058 |
| 2059 MoveTouchPoint(0, 20, 5); |
| 2060 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| 2061 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2062 EXPECT_EQ(0U, queued_event_count()); |
| 2063 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2064 |
| 2065 // Even if the first touchmove event was consumed, we should be able to |
| 2066 // scroll if we receive unconsumed touchmove events. |
| 2067 MoveTouchPoint(0, 60, 5); |
| 2068 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2069 EXPECT_EQ(0U, queued_event_count()); |
| 2070 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2071 } |
| 2072 |
2029 } // namespace content | 2073 } // namespace content |
OLD | NEW |