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

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

Issue 1800143002: Notify Blink about start of gesture scroll through a queued event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 8 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 <math.h> 5 #include <math.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 touch_event_.SetTimestamp(timestamp); 267 touch_event_.SetTimestamp(timestamp);
268 } 268 }
269 269
270 uint32_t SendTouchEvent() { 270 uint32_t SendTouchEvent() {
271 uint32_t touch_event_id = touch_event_.uniqueTouchEventId; 271 uint32_t touch_event_id = touch_event_.uniqueTouchEventId;
272 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); 272 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_));
273 touch_event_.ResetPoints(); 273 touch_event_.ResetPoints();
274 return touch_event_id; 274 return touch_event_id;
275 } 275 }
276 276
277 // The TouchScrollStarted event doesn't need an ack from downstream, and is
278 // acked from within the TouchEventQueue to trigger its dequeing like other
279 // touch events. For this test, we send an artificial ack to get the same
280 // result.
tdresser 2016/04/01 19:03:20 I think we can get rid of "like other touch events
mustaq 2016/04/01 21:49:52 Done.
281 void AckTouchScrollStartedNotification(WebInputEvent::Type type) {
tdresser 2016/04/01 19:03:20 We can hardcode the type in this method.
mustaq 2016/04/01 21:49:52 Done.
282 ui::LatencyInfo latency_info;
283 input_router_->ProcessInputEventAck(type, INPUT_EVENT_ACK_STATE_IGNORED,
284 latency_info, 0, InputRouterImpl::IGNORING_DISPOSITION);
285 }
286
277 int PressTouchPoint(int x, int y) { 287 int PressTouchPoint(int x, int y) {
278 return touch_event_.PressPoint(x, y); 288 return touch_event_.PressPoint(x, y);
279 } 289 }
280 290
281 void MoveTouchPoint(int index, int x, int y) { 291 void MoveTouchPoint(int index, int x, int y) {
282 touch_event_.MovePoint(index, x, y); 292 touch_event_.MovePoint(index, x, y);
283 } 293 }
284 294
285 void ReleaseTouchPoint(int index) { 295 void ReleaseTouchPoint(int index) {
286 touch_event_.ReleasePoint(index); 296 touch_event_.ReleasePoint(index);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1106 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1097 EXPECT_EQ(0, client_->in_flight_event_count()); 1107 EXPECT_EQ(0, client_->in_flight_event_count());
1098 EXPECT_FALSE(HasPendingEvents()); 1108 EXPECT_FALSE(HasPendingEvents());
1099 continue; 1109 continue;
1100 } 1110 }
1101 1111
1102 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); 1112 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
1103 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1113 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1104 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1114 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1105 EXPECT_EQ(0, client_->in_flight_event_count()); 1115 EXPECT_EQ(0, client_->in_flight_event_count());
1116
1117 if (type == WebInputEvent::GestureScrollBegin) {
1118 EXPECT_TRUE(HasPendingEvents());
1119 AckTouchScrollStartedNotification(WebInputEvent::TouchScrollStarted);
1120 }
1106 EXPECT_FALSE(HasPendingEvents()); 1121 EXPECT_FALSE(HasPendingEvents());
1107 } 1122 }
1108 } 1123 }
1109 1124
1110 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { 1125 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) {
1111 int start_type = static_cast<int>(WebInputEvent::MouseDown); 1126 int start_type = static_cast<int>(WebInputEvent::MouseDown);
1112 int end_type = static_cast<int>(WebInputEvent::ContextMenu); 1127 int end_type = static_cast<int>(WebInputEvent::ContextMenu);
1113 ASSERT_LT(start_type, end_type); 1128 ASSERT_LT(start_type, end_type);
1114 for (int i = start_type; i <= end_type; ++i) { 1129 for (int i = start_type; i <= end_type; ++i) {
1115 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 1130 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 } 1241 }
1227 1242
1228 // Test that GestureShowPress events don't get out of order due to 1243 // Test that GestureShowPress events don't get out of order due to
1229 // ignoring their acks. 1244 // ignoring their acks.
1230 TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) { 1245 TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) {
1231 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1246 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1232 blink::WebGestureDeviceTouchscreen); 1247 blink::WebGestureDeviceTouchscreen);
1233 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1248 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1234 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1249 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1235 1250
1236
1237 // GesturePinchBegin ignores its ack. 1251 // GesturePinchBegin ignores its ack.
1238 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, 1252 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
1239 blink::WebGestureDeviceTouchscreen); 1253 blink::WebGestureDeviceTouchscreen);
1240 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1254 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1241 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1255 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1242 1256
1243 // GesturePinchUpdate waits for an ack. 1257 // GesturePinchUpdate waits for an ack.
1244 // This also verifies that GesturePinchUpdates for touchscreen are sent 1258 // This also verifies that GesturePinchUpdates for touchscreen are sent
1245 // to the renderer (in contrast to the TrackpadPinchUpdate test). 1259 // to the renderer (in contrast to the TrackpadPinchUpdate test).
1246 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1260 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 // Test that the router will call the client's |DidFlush| after all fling 1699 // Test that the router will call the client's |DidFlush| after all fling
1686 // animations have completed. 1700 // animations have completed.
1687 TEST_F(InputRouterImplTest, InputFlushAfterFling) { 1701 TEST_F(InputRouterImplTest, InputFlushAfterFling) {
1688 EXPECT_FALSE(HasPendingEvents()); 1702 EXPECT_FALSE(HasPendingEvents());
1689 1703
1690 // Simulate a fling. 1704 // Simulate a fling.
1691 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1705 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1692 blink::WebGestureDeviceTouchscreen); 1706 blink::WebGestureDeviceTouchscreen);
1693 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1707 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1694 blink::WebGestureDeviceTouchscreen); 1708 blink::WebGestureDeviceTouchscreen);
1709 AckTouchScrollStartedNotification(WebInputEvent::TouchScrollStarted);
1695 EXPECT_TRUE(HasPendingEvents()); 1710 EXPECT_TRUE(HasPendingEvents());
1696 1711
1697 // If the fling is unconsumed, the flush is complete. 1712 // If the fling is unconsumed, the flush is complete.
1698 RequestNotificationWhenFlushed(); 1713 RequestNotificationWhenFlushed();
1699 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1714 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1700 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1715 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1701 blink::WebGestureDeviceTouchscreen); 1716 blink::WebGestureDeviceTouchscreen);
1702 SendInputEventACK(WebInputEvent::GestureFlingStart, 1717 SendInputEventACK(WebInputEvent::GestureFlingStart,
1703 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1718 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1719 EXPECT_TRUE(HasPendingEvents());
1720 AckTouchScrollStartedNotification(WebInputEvent::TouchScrollStarted);
1704 EXPECT_FALSE(HasPendingEvents()); 1721 EXPECT_FALSE(HasPendingEvents());
1722
1705 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1723 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1706 1724
1707 // Simulate a second fling. 1725 // Simulate a second fling.
1708 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1726 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1709 blink::WebGestureDeviceTouchscreen); 1727 blink::WebGestureDeviceTouchscreen);
1710 EXPECT_TRUE(HasPendingEvents()); 1728 EXPECT_TRUE(HasPendingEvents());
1711 1729
1712 // If the fling is consumed, the flush is complete only when the renderer 1730 // If the fling is consumed, the flush is complete only when the renderer
1713 // reports that is has ended. 1731 // reports that is has ended.
1714 RequestNotificationWhenFlushed(); 1732 RequestNotificationWhenFlushed();
1715 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1733 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1716 SendInputEventACK(WebInputEvent::GestureFlingStart, 1734 SendInputEventACK(WebInputEvent::GestureFlingStart,
1717 INPUT_EVENT_ACK_STATE_CONSUMED); 1735 INPUT_EVENT_ACK_STATE_CONSUMED);
1718 EXPECT_TRUE(HasPendingEvents()); 1736 EXPECT_TRUE(HasPendingEvents());
1719 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1737 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1720 1738
1721 // The fling end notification should signal that the router is flushed. 1739 // The fling end notification should signal that the router is flushed.
1722 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); 1740 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0));
1723 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1741 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1724 1742
1725 // Even flings consumed by the client require a fling-end notification. 1743 // Even flings consumed by the client require a fling-end notification.
1726 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); 1744 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED);
1727 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1745 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1728 blink::WebGestureDeviceTouchscreen); 1746 blink::WebGestureDeviceTouchscreen);
1729 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1747 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1730 blink::WebGestureDeviceTouchscreen); 1748 blink::WebGestureDeviceTouchscreen);
1749 AckTouchScrollStartedNotification(WebInputEvent::TouchScrollStarted);
1731 ASSERT_TRUE(HasPendingEvents()); 1750 ASSERT_TRUE(HasPendingEvents());
1732 RequestNotificationWhenFlushed(); 1751 RequestNotificationWhenFlushed();
1733 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1752 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1734 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); 1753 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0));
1735 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1754 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1736 } 1755 }
1737 1756
1738 // Test that GesturePinchUpdate is handled specially for trackpad 1757 // Test that GesturePinchUpdate is handled specially for trackpad
1739 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { 1758 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {
1740 // GesturePinchUpdate for trackpad sends synthetic wheel events. 1759 // GesturePinchUpdate for trackpad sends synthetic wheel events.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); 2348 EXPECT_EQ(80, sent_event->data.flingStart.velocityY);
2330 2349
2331 const WebGestureEvent* filter_event = 2350 const WebGestureEvent* filter_event =
2332 GetFilterWebInputEvent<WebGestureEvent>(); 2351 GetFilterWebInputEvent<WebGestureEvent>();
2333 TestLocationInFilterEvent(filter_event, orig); 2352 TestLocationInFilterEvent(filter_event, orig);
2334 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); 2353 EXPECT_EQ(30, filter_event->data.flingStart.velocityX);
2335 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); 2354 EXPECT_EQ(40, filter_event->data.flingStart.velocityY);
2336 } 2355 }
2337 2356
2338 } // namespace content 2357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698