Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/browser/renderer_host/input/immediate_input_router_unittest.cc

Issue 23856016: Send touch cancel to renderer when scrolling starts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: always insert the touch cancel at the beginning of TEQ Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/renderer_host/input/gesture_event_filter.h" 8 #include "content/browser/renderer_host/input/gesture_event_filter.h"
9 #include "content/browser/renderer_host/input/immediate_input_router.h" 9 #include "content/browser/renderer_host/input/immediate_input_router.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 10 #include "content/browser/renderer_host/input/input_router_client.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 const WebTouchEvent& latest_event() const { 144 const WebTouchEvent& latest_event() const {
145 return touch_event_queue()->GetLatestEvent().event; 145 return touch_event_queue()->GetLatestEvent().event;
146 } 146 }
147 147
148 void EnableNoTouchToRendererWhileScrolling() { 148 void EnableNoTouchToRendererWhileScrolling() {
149 input_router()->enable_no_touch_to_renderer_while_scrolling_ = true; 149 input_router()->enable_no_touch_to_renderer_while_scrolling_ = true;
150 } 150 }
151 151
152 bool no_touch_move_to_renderer() { 152 bool no_touch_to_renderer() {
153 return touch_event_queue()->no_touch_move_to_renderer_; 153 return touch_event_queue()->no_touch_to_renderer_;
154 } 154 }
155 155
156 TouchEventQueue* touch_event_queue() const { 156 TouchEventQueue* touch_event_queue() const {
157 return input_router()->touch_event_queue(); 157 return input_router()->touch_event_queue();
158 } 158 }
159 159
160 unsigned GestureEventLastQueueEventSize() { 160 unsigned GestureEventLastQueueEventSize() {
161 return gesture_event_filter()->coalesced_gesture_events_.size(); 161 return gesture_event_filter()->coalesced_gesture_events_.size();
162 } 162 }
163 163
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 // Check that the second event was sent. 1844 // Check that the second event was sent.
1845 EXPECT_EQ(1U, process_->sink().message_count()); 1845 EXPECT_EQ(1U, process_->sink().message_count());
1846 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 1846 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
1847 InputMsg_HandleInputEvent::ID)); 1847 InputMsg_HandleInputEvent::ID));
1848 process_->sink().ClearMessages(); 1848 process_->sink().ClearMessages();
1849 1849
1850 // Check that the correct unhandled wheel event was received. 1850 // Check that the correct unhandled wheel event was received.
1851 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); 1851 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
1852 } 1852 }
1853 1853
1854 // Tests that no touch move events are sent to renderer during scrolling. 1854 // Tests that no touch events are sent to renderer during scrolling.
1855 TEST_F(ImmediateInputRouterTest, NoTouchMoveWhileScroll) { 1855 TEST_F(ImmediateInputRouterTest, NoTouchWhileScroll) {
1856 EnableNoTouchToRendererWhileScrolling(); 1856 EnableNoTouchToRendererWhileScrolling();
1857 set_debounce_interval_time_ms(0); 1857 set_debounce_interval_time_ms(0);
1858 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 1858 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
1859 process_->sink().ClearMessages(); 1859 process_->sink().ClearMessages();
1860 1860
1861 // First touch press. 1861 // First touch press.
1862 PressTouchPoint(0, 1); 1862 PressTouchPoint(0, 1);
1863 SendTouchEvent(); 1863 SendTouchEvent();
1864 EXPECT_EQ(1U, process_->sink().message_count()); 1864 EXPECT_EQ(1U, process_->sink().message_count());
1865 process_->sink().ClearMessages(); 1865 process_->sink().ClearMessages();
1866 SendInputEventACK(WebInputEvent::TouchStart, 1866 SendInputEventACK(WebInputEvent::TouchStart,
1867 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1867 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1868 ack_handler_->ExpectAckCalled(1);
1868 1869
1869 // Touch move will trigger scroll. 1870 // Touch move will trigger scroll.
1870 MoveTouchPoint(0, 20, 5); 1871 MoveTouchPoint(0, 20, 5);
1871 SendTouchEvent(); 1872 SendTouchEvent();
1872 EXPECT_EQ(1U, process_->sink().message_count()); 1873 EXPECT_EQ(1U, process_->sink().message_count());
1873 process_->sink().ClearMessages(); 1874 process_->sink().ClearMessages();
1875
1876 WebGestureEvent followup_scroll;
1877 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1878 ack_handler_->set_followup_touch_event(make_scoped_ptr(
1879 new GestureEventWithLatencyInfo(followup_scroll, ui::LatencyInfo())));
1880
jdduke (slow) 2013/10/01 16:27:42 Would it be worthwhile to add another (non-coalesc
Yufeng Shen (Slow to review) 2013/10/01 20:38:50 Done. Send another TouchStart to the queue (so it
1874 SendInputEventACK(WebInputEvent::TouchMove, 1881 SendInputEventACK(WebInputEvent::TouchMove,
1875 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1882 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1883 ack_handler_->ExpectAckCalled(1);
1884 // GestureScroll inserts touch cancel into the queue.
1885 EXPECT_EQ(1U, TouchEventQueueSize());
1886 EXPECT_EQ(latest_event().type, WebInputEvent::TouchCancel);
sadrul 2013/10/01 11:32:45 EXPECT_EQ(<expected value>, <actual value>), so th
Yufeng Shen (Slow to review) 2013/10/01 20:38:50 Done.
1887 EXPECT_EQ(2U, process_->sink().message_count());
1888 // ScrollBegin is sent first, then the TouchCancel.
1889 const WebInputEvent* input_event =
1890 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1891 EXPECT_EQ(input_event->type, WebInputEvent::GestureScrollBegin);
1892 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1));
1893 EXPECT_EQ(input_event->type, WebInputEvent::TouchCancel);
1894 EXPECT_TRUE(no_touch_to_renderer());
1895 process_->sink().ClearMessages();
1876 1896
1877 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1897 // Clear the followup events since now the touch events are directly
1878 WebGestureEvent::Touchscreen); 1898 // sent to client, instead of being sent to renderer and waiting for
1879 EXPECT_EQ(1U, process_->sink().message_count()); 1899 // ack. So we should use SimulateGestureScrollUpdateEvent() instead of
1880 EXPECT_TRUE(no_touch_move_to_renderer()); 1900 // followup gesture events.
1881 process_->sink().ClearMessages(); 1901 ack_handler_->set_followup_touch_event(make_scoped_ptr(
1902 static_cast<GestureEventWithLatencyInfo*>(NULL)));
1903 SendInputEventACK(WebInputEvent::TouchCancel,
1904 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1905 // The touch cancel does not reach client.
1906 ack_handler_->ExpectAckCalled(0);
1882 SendInputEventACK(WebInputEvent::GestureScrollBegin, 1907 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1883 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1908 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1909 ack_handler_->ExpectAckCalled(1);
1910 EXPECT_EQ(0U, TouchEventQueueSize());
1911 EXPECT_EQ(0U, process_->sink().message_count());
1912 process_->sink().ClearMessages();
1884 1913
1885 // Touch move should not be sent to renderer. 1914 // Touch move should not be sent to renderer.
1886 MoveTouchPoint(0, 30, 5); 1915 MoveTouchPoint(0, 30, 5);
1887 SendTouchEvent(); 1916 SendTouchEvent();
1888 EXPECT_EQ(0U, process_->sink().message_count()); 1917 EXPECT_EQ(0U, process_->sink().message_count());
1889 process_->sink().ClearMessages(); 1918 process_->sink().ClearMessages();
1890 1919
1891 // Touch moves become ScrollUpdate. 1920 // Touch moves become ScrollUpdate.
1892 SimulateGestureScrollUpdateEvent(20, 4, 0); 1921 SimulateGestureScrollUpdateEvent(20, 4, 0);
1893 EXPECT_TRUE(no_touch_move_to_renderer());
1894 process_->sink().ClearMessages(); 1922 process_->sink().ClearMessages();
1895 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1923 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1896 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1924 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1897 1925
1898 // Touch move should not be sent to renderer. 1926 // Touch end should not be sent to renderer.
1899 MoveTouchPoint(0, 65, 10); 1927 ReleaseTouchPoint(0);
1900 SendTouchEvent(); 1928 SendTouchEvent();
1901 EXPECT_EQ(0U, process_->sink().message_count()); 1929 EXPECT_EQ(0U, process_->sink().message_count());
1902 process_->sink().ClearMessages(); 1930 process_->sink().ClearMessages();
1903 1931
1904 // Touch end should still be sent to renderer.
1905 ReleaseTouchPoint(0);
1906 SendTouchEvent();
1907 EXPECT_EQ(1U, process_->sink().message_count());
1908 process_->sink().ClearMessages();
1909 SendInputEventACK(WebInputEvent::TouchEnd,
1910 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1911
1912 // On GestureScrollEnd, resume sending touch moves to renderer. 1932 // On GestureScrollEnd, resume sending touch moves to renderer.
1913 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd, 1933 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd,
1914 WebGestureEvent::Touchscreen); 1934 WebGestureEvent::Touchscreen);
1915 EXPECT_EQ(1U, process_->sink().message_count()); 1935 EXPECT_EQ(1U, process_->sink().message_count());
1916 EXPECT_FALSE(no_touch_move_to_renderer()); 1936 EXPECT_FALSE(no_touch_to_renderer());
1917 process_->sink().ClearMessages(); 1937 process_->sink().ClearMessages();
1918 SendInputEventACK(WebInputEvent::GestureScrollEnd, 1938 SendInputEventACK(WebInputEvent::GestureScrollEnd,
1919 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1939 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1920 1940
1921 // Now touch events should come through to renderer. 1941 // Now touch events should come through to renderer.
1922 PressTouchPoint(80, 10); 1942 PressTouchPoint(80, 10);
1923 SendTouchEvent(); 1943 SendTouchEvent();
1924 EXPECT_EQ(1U, process_->sink().message_count()); 1944 EXPECT_EQ(1U, process_->sink().message_count());
1925 process_->sink().ClearMessages(); 1945 process_->sink().ClearMessages();
1926 SendInputEventACK(WebInputEvent::TouchStart, 1946 SendInputEventACK(WebInputEvent::TouchStart,
1927 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1947 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1928 1948
1929 MoveTouchPoint(0, 80, 20); 1949 MoveTouchPoint(0, 80, 20);
1930 SendTouchEvent(); 1950 SendTouchEvent();
1931 EXPECT_EQ(1U, process_->sink().message_count()); 1951 EXPECT_EQ(1U, process_->sink().message_count());
1932 process_->sink().ClearMessages(); 1952 process_->sink().ClearMessages();
1933 SendInputEventACK(WebInputEvent::TouchMove, 1953 SendInputEventACK(WebInputEvent::TouchMove,
1934 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1954 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1935 1955
1936 ReleaseTouchPoint(0); 1956 ReleaseTouchPoint(0);
1937 SendTouchEvent(); 1957 SendTouchEvent();
1938 EXPECT_EQ(1U, process_->sink().message_count()); 1958 EXPECT_EQ(1U, process_->sink().message_count());
1939 process_->sink().ClearMessages(); 1959 process_->sink().ClearMessages();
1940 SendInputEventACK(WebInputEvent::TouchEnd, 1960 SendInputEventACK(WebInputEvent::TouchEnd,
1941 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1961 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1942 } 1962 }
1943 } // namespace content 1963 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698