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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 // Queue a TouchStart. | 852 // Queue a TouchStart. |
853 PressTouchPoint(0, 1); | 853 PressTouchPoint(0, 1); |
854 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 854 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
855 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 855 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
856 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 856 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
857 | 857 |
858 MoveTouchPoint(0, 20, 5); | 858 MoveTouchPoint(0, 20, 5); |
859 EXPECT_EQ(1U, queued_event_count()); | 859 EXPECT_EQ(1U, queued_event_count()); |
860 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 860 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
861 | 861 |
| 862 MoveTouchPoint(0, 30, 15); |
| 863 EXPECT_EQ(2U, queued_event_count()); |
| 864 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 865 |
862 // Queue another TouchStart. | 866 // Queue another TouchStart. |
863 PressTouchPoint(20, 20); | 867 PressTouchPoint(20, 20); |
864 EXPECT_EQ(2U, queued_event_count()); | 868 EXPECT_EQ(3U, queued_event_count()); |
865 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 869 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
866 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 870 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
867 | 871 |
868 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. | |
869 WebGestureEvent followup_scroll; | 872 WebGestureEvent followup_scroll; |
870 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 873 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
871 SetFollowupEvent(followup_scroll); | 874 SetFollowupEvent(followup_scroll); |
872 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 875 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
873 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 876 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
874 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 877 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
875 EXPECT_EQ(2U, queued_event_count()); | 878 EXPECT_EQ(2U, queued_event_count()); |
| 879 EXPECT_TRUE(sent_event().cancelable); |
| 880 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
| 881 |
| 882 // GestureScrollUpdate inserts a synthetic TouchCancel before the TouchStart. |
| 883 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 884 SetFollowupEvent(followup_scroll); |
| 885 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 886 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 887 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 888 EXPECT_EQ(2U, queued_event_count()); |
876 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 889 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
877 EXPECT_FALSE(sent_event().cancelable); | 890 EXPECT_FALSE(sent_event().cancelable); |
878 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 891 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
879 | 892 |
880 // Acking the TouchCancel will result in dispatch of the next TouchStart. | 893 // Acking the TouchCancel will result in dispatch of the next TouchStart. |
881 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 894 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
882 // The synthetic TouchCancel should not reach client, only the TouchStart. | 895 // The synthetic TouchCancel should not reach client, only the TouchStart. |
883 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 896 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
884 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 897 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
885 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 898 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 // scroll sequences that transitions between scrolls consumed and unconsumed. | 1723 // scroll sequences that transitions between scrolls consumed and unconsumed. |
1711 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { | 1724 TEST_F(TouchEventQueueTest, AsyncTouchThrottledAfterScroll) { |
1712 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | 1725 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
1713 | 1726 |
1714 // Process a TouchStart | 1727 // Process a TouchStart |
1715 PressTouchPoint(0, 1); | 1728 PressTouchPoint(0, 1); |
1716 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1729 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1717 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1730 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1731 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1719 | 1732 |
1720 // Now send the first touch move and associated GestureScrollBegin, | 1733 // Now send the first touch move and associated GestureScrollBegin. |
1721 // but don't ACK the gesture event yet. | |
1722 MoveTouchPoint(0, 0, 5); | 1734 MoveTouchPoint(0, 0, 5); |
1723 WebGestureEvent followup_scroll; | 1735 WebGestureEvent followup_scroll; |
1724 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 1736 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1725 SetFollowupEvent(followup_scroll); | 1737 SetFollowupEvent(followup_scroll); |
1726 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1738 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1727 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1739 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1728 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1740 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1741 SendGestureEventAck(WebInputEvent::GestureScrollBegin, |
| 1742 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1743 |
| 1744 // Send the second touch move and associated GestureScrollUpdate, but don't |
| 1745 // ACK the gesture event yet. |
| 1746 MoveTouchPoint(0, 0, 5); |
| 1747 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 1748 SetFollowupEvent(followup_scroll); |
| 1749 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1750 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1751 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1729 | 1752 |
1730 // Now queue a second touchmove and verify it's not (yet) dispatched. | 1753 // Now queue a second touchmove and verify it's not (yet) dispatched. |
1731 MoveTouchPoint(0, 0, 10); | 1754 MoveTouchPoint(0, 0, 10); |
1732 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1755 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1733 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1756 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1734 EXPECT_EQ(0U, queued_event_count()); | 1757 EXPECT_EQ(0U, queued_event_count()); |
1735 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1758 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1736 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1759 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1737 | 1760 |
1738 // Queuing the final touchend should flush the pending, async touchmove. | 1761 // Queuing the final touchend should flush the pending, async touchmove. |
(...skipping 14 matching lines...) Expand all Loading... |
1753 EXPECT_EQ(1U, queued_event_count()); | 1776 EXPECT_EQ(1U, queued_event_count()); |
1754 | 1777 |
1755 // Ack the touchend. | 1778 // Ack the touchend. |
1756 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1779 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1757 EXPECT_EQ(0U, queued_event_count()); | 1780 EXPECT_EQ(0U, queued_event_count()); |
1758 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1781 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1759 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1782 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1760 | 1783 |
1761 // Now mark the scroll as not consumed (which would cause future | 1784 // Now mark the scroll as not consumed (which would cause future |
1762 // touchmoves in the active sequence to be sent if there was one). | 1785 // touchmoves in the active sequence to be sent if there was one). |
1763 SendGestureEventAck(WebInputEvent::GestureScrollBegin, | 1786 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
1764 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1787 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1765 | 1788 |
1766 // Start a new touch sequence and verify that throttling has been reset. | 1789 // Start a new touch sequence and verify that throttling has been reset. |
1767 // Touch moves after the start of scrolling will again be throttled. | 1790 // Touch moves after the start of scrolling will again be throttled. |
1768 PressTouchPoint(0, 0); | 1791 PressTouchPoint(0, 0); |
1769 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1792 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1770 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1793 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1771 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1794 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1772 MoveTouchPoint(0, 0, 5); | 1795 MoveTouchPoint(0, 0, 5); |
| 1796 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1773 SetFollowupEvent(followup_scroll); | 1797 SetFollowupEvent(followup_scroll); |
1774 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1798 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1775 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1799 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1776 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1800 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1801 |
| 1802 MoveTouchPoint(0, 0, 5); |
| 1803 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 1804 SetFollowupEvent(followup_scroll); |
| 1805 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1806 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1807 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1808 |
1777 MoveTouchPoint(0, 0, 10); | 1809 MoveTouchPoint(0, 0, 10); |
1778 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1810 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1779 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1811 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1780 EXPECT_EQ(0U, queued_event_count()); | 1812 EXPECT_EQ(0U, queued_event_count()); |
1781 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1813 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1782 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1814 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1783 | 1815 |
1784 // As soon as a touchmove exceeds the outer slop region it will be forwarded | 1816 // As soon as a touchmove exceeds the outer slop region it will be forwarded |
1785 // immediately. | 1817 // immediately. |
1786 MoveTouchPoint(0, 0, 20); | 1818 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. | 2018 // The start of a scroll gesture should trigger async touch event dispatch. |
1987 MoveTouchPoint(0, 1, 1); | 2019 MoveTouchPoint(0, 1, 1); |
1988 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2020 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1989 WebGestureEvent followup_scroll; | 2021 WebGestureEvent followup_scroll; |
1990 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 2022 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
1991 SetFollowupEvent(followup_scroll); | 2023 SetFollowupEvent(followup_scroll); |
1992 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2024 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1993 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2025 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1994 EXPECT_EQ(0U, queued_event_count()); | 2026 EXPECT_EQ(0U, queued_event_count()); |
1995 | 2027 |
| 2028 SendGestureEvent(WebInputEvent::GestureScrollUpdate); |
| 2029 |
1996 // The async touchmove should be ack'ed immediately, but not forwarded. | 2030 // The async touchmove should be ack'ed immediately, but not forwarded. |
1997 // However, because the ack triggers a touchcancel, both the pending touch and | 2031 // However, because the ack triggers a touchcancel, both the pending touch and |
1998 // the queued touchcancel should be flushed. | 2032 // the queued touchcancel should be flushed. |
1999 WebTouchEvent followup_cancel; | 2033 WebTouchEvent followup_cancel; |
2000 followup_cancel.type = WebInputEvent::TouchCancel; | 2034 followup_cancel.type = WebInputEvent::TouchCancel; |
2001 followup_cancel.touchesLength = 1; | 2035 followup_cancel.touchesLength = 1; |
2002 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; | 2036 followup_cancel.touches[0].state = WebTouchPoint::StateCancelled; |
2003 SetFollowupEvent(followup_cancel); | 2037 SetFollowupEvent(followup_cancel); |
2004 MoveTouchPoint(0, 5, 5); | 2038 MoveTouchPoint(0, 5, 5); |
2005 EXPECT_EQ(2U, queued_event_count()); | 2039 EXPECT_EQ(2U, queued_event_count()); |
2006 EXPECT_FALSE(sent_event().cancelable); | 2040 EXPECT_FALSE(sent_event().cancelable); |
2007 EXPECT_FALSE(HasPendingAsyncTouchMove()); | 2041 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
2008 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 2042 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
2009 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); | 2043 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
2010 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2044 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2011 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2045 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2012 | 2046 |
2013 // The ack for the asnc touchmove should not reach the client, as it has | 2047 // The ack for the async touchmove should not reach the client, as it has |
2014 // already been ack'ed. | 2048 // already been ack'ed. |
2015 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2049 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2016 EXPECT_FALSE(sent_event().cancelable); | 2050 EXPECT_FALSE(sent_event().cancelable); |
2017 EXPECT_EQ(1U, queued_event_count()); | 2051 EXPECT_EQ(1U, queued_event_count()); |
2018 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 2052 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
2019 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 2053 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
2020 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2054 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2021 | 2055 |
2022 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2056 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2023 EXPECT_EQ(0U, queued_event_count()); | 2057 EXPECT_EQ(0U, queued_event_count()); |
2024 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); | 2058 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); |
2025 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2059 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2026 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 2060 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
2027 } | 2061 } |
2028 | 2062 |
| 2063 TEST_F(TouchEventQueueTest, TouchAbsorptionWithConsumedFirstMove) { |
| 2064 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
| 2065 |
| 2066 // Queue a TouchStart. |
| 2067 PressTouchPoint(0, 1); |
| 2068 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2069 EXPECT_EQ(0U, queued_event_count()); |
| 2070 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2071 |
| 2072 MoveTouchPoint(0, 20, 5); |
| 2073 SendGestureEvent(blink::WebInputEvent::GestureScrollBegin); |
| 2074 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2075 EXPECT_EQ(0U, queued_event_count()); |
| 2076 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
| 2077 |
| 2078 // Even if the first touchmove event was consumed, subsequent unconsumed |
| 2079 // touchmove events should trigger scrolling. |
| 2080 MoveTouchPoint(0, 60, 5); |
| 2081 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2082 EXPECT_EQ(0U, queued_event_count()); |
| 2083 EXPECT_TRUE(sent_event().cancelable); |
| 2084 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2085 |
| 2086 MoveTouchPoint(0, 20, 5); |
| 2087 WebGestureEvent followup_scroll; |
| 2088 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 2089 SetFollowupEvent(followup_scroll); |
| 2090 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2091 SendGestureEventAck(WebInputEvent::GestureScrollUpdate, |
| 2092 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2093 EXPECT_EQ(0U, queued_event_count()); |
| 2094 EXPECT_TRUE(sent_event().cancelable); |
| 2095 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2096 |
| 2097 MoveTouchPoint(0, 60, 5); |
| 2098 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2099 EXPECT_EQ(0U, queued_event_count()); |
| 2100 EXPECT_FALSE(sent_event().cancelable); |
| 2101 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2102 } |
| 2103 |
2029 } // namespace content | 2104 } // namespace content |
OLD | NEW |