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 "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 345 } |
346 | 346 |
347 bool TouchEventQueueEmpty() const { | 347 bool TouchEventQueueEmpty() const { |
348 return input_router()->touch_event_queue_->Empty(); | 348 return input_router()->touch_event_queue_->Empty(); |
349 } | 349 } |
350 | 350 |
351 bool TouchEventTimeoutEnabled() const { | 351 bool TouchEventTimeoutEnabled() const { |
352 return input_router()->touch_event_queue_->IsAckTimeoutEnabled(); | 352 return input_router()->touch_event_queue_->IsAckTimeoutEnabled(); |
353 } | 353 } |
354 | 354 |
355 void RequestNotificationWhenFlushed() const { | |
356 return input_router_->RequestNotificationWhenFlushed(); | |
357 } | |
358 | |
359 size_t GetAndResetDidFlushCount() { | |
360 return client_->GetAndResetDidFlushCount(); | |
361 } | |
362 | |
363 bool HasPendingEvents() const { | 355 bool HasPendingEvents() const { |
364 return input_router_->HasPendingEvents(); | 356 return input_router_->HasPendingEvents(); |
365 } | 357 } |
366 | 358 |
367 void OnHasTouchEventHandlers(bool has_handlers) { | 359 void OnHasTouchEventHandlers(bool has_handlers) { |
368 input_router_->OnMessageReceived( | 360 input_router_->OnMessageReceived( |
369 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); | 361 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); |
370 } | 362 } |
371 | 363 |
372 void OnSetTouchAction(cc::TouchAction touch_action) { | 364 void OnSetTouchAction(cc::TouchAction touch_action) { |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 SimulateGestureEvent(WebInputEvent::kGestureDoubleTap, | 1774 SimulateGestureEvent(WebInputEvent::kGestureDoubleTap, |
1783 blink::kWebGestureDeviceTouchscreen); | 1775 blink::kWebGestureDeviceTouchscreen); |
1784 // This test will become invalid if GestureDoubleTap stops requiring an ack. | 1776 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
1785 ASSERT_TRUE(ShouldBlockEventStream( | 1777 ASSERT_TRUE(ShouldBlockEventStream( |
1786 GetEventWithType(WebInputEvent::kGestureDoubleTap))); | 1778 GetEventWithType(WebInputEvent::kGestureDoubleTap))); |
1787 EXPECT_EQ(1, client_->in_flight_event_count()); | 1779 EXPECT_EQ(1, client_->in_flight_event_count()); |
1788 SendInputEventACK(WebInputEvent::kGestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1780 SendInputEventACK(WebInputEvent::kGestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
1789 EXPECT_EQ(0, client_->in_flight_event_count()); | 1781 EXPECT_EQ(0, client_->in_flight_event_count()); |
1790 } | 1782 } |
1791 | 1783 |
1792 // Test that the router will call the client's |DidFlush| after all events have | |
1793 // been dispatched following a call to |Flush|. | |
1794 TEST_F(InputRouterImplTest, InputFlush) { | |
1795 EXPECT_FALSE(HasPendingEvents()); | |
1796 | |
1797 // Flushing an empty router should immediately trigger DidFlush. | |
1798 RequestNotificationWhenFlushed(); | |
1799 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1800 EXPECT_FALSE(HasPendingEvents()); | |
1801 | |
1802 // Queue a TouchStart. | |
1803 OnHasTouchEventHandlers(true); | |
1804 PressTouchPoint(1, 1); | |
1805 uint32_t touch_press_event_id = SendTouchEvent(); | |
1806 EXPECT_TRUE(HasPendingEvents()); | |
1807 | |
1808 // DidFlush should be called only after the event is ack'ed. | |
1809 RequestNotificationWhenFlushed(); | |
1810 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1811 SendTouchEventACK(WebInputEvent::kTouchStart, | |
1812 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_press_event_id); | |
1813 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1814 | |
1815 // Ensure different types of enqueued events will prevent the DidFlush call | |
1816 // until all such events have been fully dispatched. | |
1817 MoveTouchPoint(0, 50, 50); | |
1818 uint32_t touch_move_event_id = SendTouchEvent(); | |
1819 ASSERT_TRUE(HasPendingEvents()); | |
1820 SimulateGestureEvent(WebInputEvent::kGestureScrollBegin, | |
1821 blink::kWebGestureDeviceTouchscreen); | |
1822 SimulateGestureEvent(WebInputEvent::kGestureScrollUpdate, | |
1823 blink::kWebGestureDeviceTouchscreen); | |
1824 SimulateGestureEvent(WebInputEvent::kGesturePinchBegin, | |
1825 blink::kWebGestureDeviceTouchscreen); | |
1826 SimulateGestureEvent(WebInputEvent::kGesturePinchUpdate, | |
1827 blink::kWebGestureDeviceTouchscreen); | |
1828 RequestNotificationWhenFlushed(); | |
1829 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1830 | |
1831 // Repeated flush calls should have no effect. | |
1832 RequestNotificationWhenFlushed(); | |
1833 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1834 | |
1835 // There are still pending gestures. | |
1836 SendTouchEventACK(WebInputEvent::kTouchMove, | |
1837 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); | |
1838 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1839 EXPECT_TRUE(HasPendingEvents()); | |
1840 | |
1841 // One more gesture to go. | |
1842 SendInputEventACK(WebInputEvent::kGestureScrollUpdate, | |
1843 INPUT_EVENT_ACK_STATE_CONSUMED); | |
1844 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1845 EXPECT_TRUE(HasPendingEvents()); | |
1846 | |
1847 // The final ack'ed gesture should trigger the DidFlush. | |
1848 SendInputEventACK(WebInputEvent::kGesturePinchUpdate, | |
1849 INPUT_EVENT_ACK_STATE_CONSUMED); | |
1850 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1851 EXPECT_FALSE(HasPendingEvents()); | |
1852 } | |
1853 | |
1854 // Test that the router will call the client's |DidFlush| after all fling | |
1855 // animations have completed. | |
1856 TEST_F(InputRouterImplTest, InputFlushAfterFling) { | |
1857 EXPECT_FALSE(HasPendingEvents()); | |
1858 | |
1859 // Simulate a fling. | |
1860 SimulateGestureEvent(WebInputEvent::kGestureScrollBegin, | |
1861 blink::kWebGestureDeviceTouchscreen); | |
1862 SimulateGestureEvent(WebInputEvent::kGestureFlingStart, | |
1863 blink::kWebGestureDeviceTouchscreen); | |
1864 EXPECT_TRUE(HasPendingEvents()); | |
1865 | |
1866 // If the fling is unconsumed, the flush is complete. | |
1867 RequestNotificationWhenFlushed(); | |
1868 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1869 SimulateGestureEvent(WebInputEvent::kGestureScrollBegin, | |
1870 blink::kWebGestureDeviceTouchscreen); | |
1871 SendInputEventACK(WebInputEvent::kGestureFlingStart, | |
1872 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
1873 EXPECT_FALSE(HasPendingEvents()); | |
1874 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1875 | |
1876 // Simulate a second fling. | |
1877 SimulateGestureEvent(WebInputEvent::kGestureFlingStart, | |
1878 blink::kWebGestureDeviceTouchscreen); | |
1879 EXPECT_TRUE(HasPendingEvents()); | |
1880 | |
1881 // If the fling is consumed, the flush is complete only when the renderer | |
1882 // reports that is has ended. | |
1883 RequestNotificationWhenFlushed(); | |
1884 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1885 SendInputEventACK(WebInputEvent::kGestureFlingStart, | |
1886 INPUT_EVENT_ACK_STATE_CONSUMED); | |
1887 EXPECT_TRUE(HasPendingEvents()); | |
1888 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1889 | |
1890 // The fling end notification should signal that the router is flushed. | |
1891 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); | |
1892 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1893 | |
1894 // Even flings consumed by the client require a fling-end notification. | |
1895 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); | |
1896 SimulateGestureEvent(WebInputEvent::kGestureScrollBegin, | |
1897 blink::kWebGestureDeviceTouchscreen); | |
1898 SimulateGestureEvent(WebInputEvent::kGestureFlingStart, | |
1899 blink::kWebGestureDeviceTouchscreen); | |
1900 ASSERT_TRUE(HasPendingEvents()); | |
1901 RequestNotificationWhenFlushed(); | |
1902 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
1903 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); | |
1904 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
1905 } | |
1906 | |
1907 // Test that GesturePinchUpdate is handled specially for trackpad | 1784 // Test that GesturePinchUpdate is handled specially for trackpad |
1908 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { | 1785 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
1909 // GesturePinchUpdate for trackpad sends synthetic wheel events. | 1786 // GesturePinchUpdate for trackpad sends synthetic wheel events. |
1910 // Note that the Touchscreen case is verified as NOT doing this as | 1787 // Note that the Touchscreen case is verified as NOT doing this as |
1911 // part of the ShowPressIsInOrder test. | 1788 // part of the ShowPressIsInOrder test. |
1912 | 1789 |
1913 SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0, | 1790 SimulateGesturePinchUpdateEvent(1.5f, 20, 25, 0, |
1914 blink::kWebGestureDeviceTouchpad); | 1791 blink::kWebGestureDeviceTouchpad); |
1915 | 1792 |
1916 // Verify we actually sent a special wheel event to the renderer. | 1793 // Verify we actually sent a special wheel event to the renderer. |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 EXPECT_EQ(80, sent_event->data.fling_start.velocity_y); | 2378 EXPECT_EQ(80, sent_event->data.fling_start.velocity_y); |
2502 | 2379 |
2503 const WebGestureEvent* filter_event = | 2380 const WebGestureEvent* filter_event = |
2504 GetFilterWebInputEvent<WebGestureEvent>(); | 2381 GetFilterWebInputEvent<WebGestureEvent>(); |
2505 TestLocationInFilterEvent(filter_event, orig); | 2382 TestLocationInFilterEvent(filter_event, orig); |
2506 EXPECT_EQ(30, filter_event->data.fling_start.velocity_x); | 2383 EXPECT_EQ(30, filter_event->data.fling_start.velocity_x); |
2507 EXPECT_EQ(40, filter_event->data.fling_start.velocity_y); | 2384 EXPECT_EQ(40, filter_event->data.fling_start.velocity_y); |
2508 } | 2385 } |
2509 | 2386 |
2510 } // namespace content | 2387 } // namespace content |
OLD | NEW |