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

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: Fix the issue that TouchCancel may never be sent 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 1868
1869 // Touch move will trigger scroll. 1869 // Touch move will trigger scroll.
1870 MoveTouchPoint(0, 20, 5); 1870 MoveTouchPoint(0, 20, 5);
1871 SendTouchEvent(); 1871 SendTouchEvent();
1872 EXPECT_EQ(1U, process_->sink().message_count()); 1872 EXPECT_EQ(1U, process_->sink().message_count());
1873 process_->sink().ClearMessages(); 1873 process_->sink().ClearMessages();
1874
1875 WebGestureEvent followup_scroll;
1876 followup_scroll.type = WebInputEvent::GestureScrollBegin;
1877 ack_handler_->set_followup_touch_event(make_scoped_ptr(
1878 new GestureEventWithLatencyInfo(followup_scroll, ui::LatencyInfo())));
1879
1874 SendInputEventACK(WebInputEvent::TouchMove, 1880 SendInputEventACK(WebInputEvent::TouchMove,
1875 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1881 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1882 // GestureScroll inserts touch cancel into the queue.
1883 EXPECT_EQ(1U, TouchEventQueueSize());
1884 EXPECT_EQ(latest_event().type, WebInputEvent::TouchCancel);
1885 EXPECT_EQ(2U, process_->sink().message_count());
1886 // TouchCancel is sent first, then the ScrollBegin.
1887 const WebInputEvent* input_event =
1888 GetInputEventFromMessage(*process_->sink().GetMessageAt(0));
1889 EXPECT_EQ(input_event->type, WebInputEvent::TouchCancel);
1890 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1));
1891 EXPECT_EQ(input_event->type, WebInputEvent::GestureScrollBegin);
1892 EXPECT_TRUE(no_touch_to_renderer());
1893 process_->sink().ClearMessages();
1876 1894
1877 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1895 // Clear the followup events since now the touch events are directly
1878 WebGestureEvent::Touchscreen); 1896 // sent to client, instead of being sent to renderer and waiting for
1879 EXPECT_EQ(1U, process_->sink().message_count()); 1897 // ack. So we should use SimulateGestureScrollUpdateEvent() instead of
1880 EXPECT_TRUE(no_touch_move_to_renderer()); 1898 // followup gesture events.
1881 process_->sink().ClearMessages(); 1899 ack_handler_->set_followup_touch_event(make_scoped_ptr(
1900 static_cast<GestureEventWithLatencyInfo*>(NULL)));
1901 SendInputEventACK(WebInputEvent::TouchCancel,
1902 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1882 SendInputEventACK(WebInputEvent::GestureScrollBegin, 1903 SendInputEventACK(WebInputEvent::GestureScrollBegin,
1883 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1904 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1905 EXPECT_EQ(0U, TouchEventQueueSize());
1906 EXPECT_EQ(0U, process_->sink().message_count());
1907 process_->sink().ClearMessages();
sadrul 2013/09/27 15:13:51 Can you check that the cancel event didn't go to t
Yufeng Shen (Slow to review) 2013/09/30 20:43:14 Done.
1884 1908
1885 // Touch move should not be sent to renderer. 1909 // Touch move should not be sent to renderer.
1886 MoveTouchPoint(0, 30, 5); 1910 MoveTouchPoint(0, 30, 5);
1887 SendTouchEvent(); 1911 SendTouchEvent();
1888 EXPECT_EQ(0U, process_->sink().message_count()); 1912 EXPECT_EQ(0U, process_->sink().message_count());
1889 process_->sink().ClearMessages(); 1913 process_->sink().ClearMessages();
1890 1914
1891 // Touch moves become ScrollUpdate. 1915 // Touch moves become ScrollUpdate.
1892 SimulateGestureScrollUpdateEvent(20, 4, 0); 1916 SimulateGestureScrollUpdateEvent(20, 4, 0);
1893 EXPECT_TRUE(no_touch_move_to_renderer());
1894 process_->sink().ClearMessages(); 1917 process_->sink().ClearMessages();
1895 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1918 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1896 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1919 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1897 1920
1898 // Touch move should not be sent to renderer. 1921 // Touch end should not be sent to renderer.
1899 MoveTouchPoint(0, 65, 10); 1922 ReleaseTouchPoint(0);
1900 SendTouchEvent(); 1923 SendTouchEvent();
1901 EXPECT_EQ(0U, process_->sink().message_count()); 1924 EXPECT_EQ(0U, process_->sink().message_count());
1902 process_->sink().ClearMessages(); 1925 process_->sink().ClearMessages();
1903 1926
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. 1927 // On GestureScrollEnd, resume sending touch moves to renderer.
1913 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd, 1928 SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd,
1914 WebGestureEvent::Touchscreen); 1929 WebGestureEvent::Touchscreen);
1915 EXPECT_EQ(1U, process_->sink().message_count()); 1930 EXPECT_EQ(1U, process_->sink().message_count());
1916 EXPECT_FALSE(no_touch_move_to_renderer()); 1931 EXPECT_FALSE(no_touch_to_renderer());
1917 process_->sink().ClearMessages(); 1932 process_->sink().ClearMessages();
1918 SendInputEventACK(WebInputEvent::GestureScrollEnd, 1933 SendInputEventACK(WebInputEvent::GestureScrollEnd,
1919 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1934 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1920 1935
1921 // Now touch events should come through to renderer. 1936 // Now touch events should come through to renderer.
1922 PressTouchPoint(80, 10); 1937 PressTouchPoint(80, 10);
1923 SendTouchEvent(); 1938 SendTouchEvent();
1924 EXPECT_EQ(1U, process_->sink().message_count()); 1939 EXPECT_EQ(1U, process_->sink().message_count());
1925 process_->sink().ClearMessages(); 1940 process_->sink().ClearMessages();
1926 SendInputEventACK(WebInputEvent::TouchStart, 1941 SendInputEventACK(WebInputEvent::TouchStart,
1927 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1942 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1928 1943
1929 MoveTouchPoint(0, 80, 20); 1944 MoveTouchPoint(0, 80, 20);
1930 SendTouchEvent(); 1945 SendTouchEvent();
1931 EXPECT_EQ(1U, process_->sink().message_count()); 1946 EXPECT_EQ(1U, process_->sink().message_count());
1932 process_->sink().ClearMessages(); 1947 process_->sink().ClearMessages();
1933 SendInputEventACK(WebInputEvent::TouchMove, 1948 SendInputEventACK(WebInputEvent::TouchMove,
1934 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1949 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1935 1950
1936 ReleaseTouchPoint(0); 1951 ReleaseTouchPoint(0);
1937 SendTouchEvent(); 1952 SendTouchEvent();
1938 EXPECT_EQ(1U, process_->sink().message_count()); 1953 EXPECT_EQ(1U, process_->sink().message_count());
1939 process_->sink().ClearMessages(); 1954 process_->sink().ClearMessages();
1940 SendInputEventACK(WebInputEvent::TouchEnd, 1955 SendInputEventACK(WebInputEvent::TouchEnd,
1941 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1956 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1942 } 1957 }
sadrul 2013/09/27 15:13:51 You should also add some test cases where the touc
Yufeng Shen (Slow to review) 2013/09/30 20:43:14 now changed to that the touch cancel is always at
1943 } // namespace content 1958 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698