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 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1820 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1821 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1821 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1822 | 1822 |
1823 MoveTouchPoint(0, 0, 10); | 1823 MoveTouchPoint(0, 0, 10); |
1824 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1824 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1825 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1825 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1826 EXPECT_EQ(0U, queued_event_count()); | 1826 EXPECT_EQ(0U, queued_event_count()); |
1827 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1827 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1828 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1828 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1829 | 1829 |
1830 // As soon as a touchmove exceeds the outer slop region it will be forwarded | |
1831 // immediately. | |
1832 MoveTouchPoint(0, 0, 20); | |
1833 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
1834 EXPECT_FALSE(HasPendingAsyncTouchMove()); | |
1835 EXPECT_FALSE(sent_event().cancelable); | |
1836 EXPECT_EQ(0U, queued_event_count()); | |
1837 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
1838 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | |
1839 | |
1840 // Subsequent touchmove's should be deferred. | 1830 // Subsequent touchmove's should be deferred. |
1841 MoveTouchPoint(0, 0, 25); | 1831 MoveTouchPoint(0, 0, 25); |
1842 EXPECT_TRUE(HasPendingAsyncTouchMove()); | 1832 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
1843 EXPECT_EQ(0U, queued_event_count()); | 1833 EXPECT_EQ(0U, queued_event_count()); |
1844 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1834 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1845 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1835 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1846 | 1836 |
1847 // The pending touchmove should be flushed with the the new touchmove if | 1837 // The pending touchmove should be flushed with the the new touchmove if |
1848 // sufficient time has passed. | 1838 // sufficient time has passed. |
1849 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); | 1839 AdvanceTouchTime(kMinSecondsBetweenThrottledTouchmoves + 0.1); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 EXPECT_EQ(1U, queued_event_count()); | 1919 EXPECT_EQ(1U, queued_event_count()); |
1930 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1920 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1931 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1921 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1932 | 1922 |
1933 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1923 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1934 EXPECT_EQ(0U, queued_event_count()); | 1924 EXPECT_EQ(0U, queued_event_count()); |
1935 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1925 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1936 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1926 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1937 } | 1927 } |
1938 | 1928 |
| 1929 TEST_F(TouchEventQueueTest, AsyncTouchFlushedByTouchEnd) { |
| 1930 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
| 1931 |
| 1932 PressTouchPoint(0, 0); |
| 1933 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1934 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1935 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1936 |
| 1937 // Initiate async touchmove dispatch after the start of a scroll sequence. |
| 1938 MoveTouchPoint(0, 0, 5); |
| 1939 WebGestureEvent followup_scroll; |
| 1940 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1941 SetFollowupEvent(followup_scroll); |
| 1942 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1943 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1944 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1945 |
| 1946 MoveTouchPoint(0, 0, 10); |
| 1947 followup_scroll.type = WebInputEvent::GestureScrollUpdate; |
| 1948 SetFollowupEvent(followup_scroll); |
| 1949 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1950 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1951 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1952 |
| 1953 // Now queue a second touchmove and verify it's not (yet) dispatched. |
| 1954 MoveTouchPoint(0, 0, 100); |
| 1955 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| 1956 EXPECT_EQ(0U, queued_event_count()); |
| 1957 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1958 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1959 |
| 1960 // Return the touch sequence to the original touchstart position. Note that |
| 1961 // this (0, 0) touchmove will coalesce with the previous (0, 100) touchmove. |
| 1962 MoveTouchPoint(0, 0, 0); |
| 1963 EXPECT_TRUE(HasPendingAsyncTouchMove()); |
| 1964 EXPECT_EQ(0U, queued_event_count()); |
| 1965 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1966 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1967 |
| 1968 // Queuing the final touchend should flush the pending, async touchmove. |
| 1969 ReleaseTouchPoint(0); |
| 1970 EXPECT_FALSE(HasPendingAsyncTouchMove()); |
| 1971 EXPECT_EQ(WebInputEvent::TouchMove, sent_event().type); |
| 1972 EXPECT_FALSE(sent_event().cancelable); |
| 1973 EXPECT_EQ(0, sent_event().touches[0].position.x); |
| 1974 EXPECT_EQ(0, sent_event().touches[0].position.y); |
| 1975 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1976 |
| 1977 // Touchend is not cancelable during async touch dispatch. |
| 1978 SendTouchEventAck(INPUT_EVENT_ACK_STATE_IGNORED); |
| 1979 EXPECT_EQ(WebInputEvent::TouchEnd, sent_event().type); |
| 1980 EXPECT_FALSE(sent_event().cancelable); |
| 1981 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1982 } |
| 1983 |
1939 // Ensure that async touch dispatch and touch ack timeout interactions work | 1984 // Ensure that async touch dispatch and touch ack timeout interactions work |
1940 // appropriately. | 1985 // appropriately. |
1941 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { | 1986 TEST_F(TouchEventQueueTest, AsyncTouchWithAckTimeout) { |
1942 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); | 1987 SetTouchScrollingMode(TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE); |
1943 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); | 1988 SetUpForTimeoutTesting(DefaultTouchTimeoutDelay()); |
1944 | 1989 |
1945 // The touchstart should start the timeout. | 1990 // The touchstart should start the timeout. |
1946 PressTouchPoint(0, 0); | 1991 PressTouchPoint(0, 0); |
1947 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1992 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1948 EXPECT_TRUE(IsTimeoutRunning()); | 1993 EXPECT_TRUE(IsTimeoutRunning()); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 | 2294 |
2250 // Give the touchmove a valid id; it should be sent. | 2295 // Give the touchmove a valid id; it should be sent. |
2251 event.touches[0].id = press_id; | 2296 event.touches[0].id = press_id; |
2252 SendTouchEvent(event); | 2297 SendTouchEvent(event); |
2253 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2298 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
2254 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 2299 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
2255 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2300 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
2256 } | 2301 } |
2257 | 2302 |
2258 } // namespace content | 2303 } // namespace content |
OLD | NEW |