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

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: Added a few checks. 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 "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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 touch_event_.SetTimestamp(timestamp); 269 touch_event_.SetTimestamp(timestamp);
270 } 270 }
271 271
272 uint32_t SendTouchEvent() { 272 uint32_t SendTouchEvent() {
273 uint32_t touch_event_id = touch_event_.uniqueTouchEventId; 273 uint32_t touch_event_id = touch_event_.uniqueTouchEventId;
274 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_)); 274 input_router_->SendTouchEvent(TouchEventWithLatencyInfo(touch_event_));
275 touch_event_.ResetPoints(); 275 touch_event_.ResetPoints();
276 return touch_event_id; 276 return touch_event_id;
277 } 277 }
278 278
279 // The TouchScrollStarted event doesn't need an ack from downstream, and is
280 // acked from within the TouchEventQueue to trigger its dequeuing. For this
281 // test, we send an artificial ack to get the same result.
282 void AckTouchScrollStartedNotification() {
283 ui::LatencyInfo latency_info;
284 input_router_->ProcessInputEventAck(
285 WebInputEvent::TouchScrollStarted, INPUT_EVENT_ACK_STATE_IGNORED,
286 latency_info, 0, InputRouterImpl::IGNORING_DISPOSITION);
287 }
288
279 int PressTouchPoint(int x, int y) { 289 int PressTouchPoint(int x, int y) {
280 return touch_event_.PressPoint(x, y); 290 return touch_event_.PressPoint(x, y);
281 } 291 }
282 292
283 void MoveTouchPoint(int index, int x, int y) { 293 void MoveTouchPoint(int index, int x, int y) {
284 touch_event_.MovePoint(index, x, y); 294 touch_event_.MovePoint(index, x, y);
285 } 295 }
286 296
287 void ReleaseTouchPoint(int index) { 297 void ReleaseTouchPoint(int index) {
288 touch_event_.ReleasePoint(index); 298 touch_event_.ReleasePoint(index);
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1104 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1095 EXPECT_EQ(0, client_->in_flight_event_count()); 1105 EXPECT_EQ(0, client_->in_flight_event_count());
1096 EXPECT_FALSE(HasPendingEvents()); 1106 EXPECT_FALSE(HasPendingEvents());
1097 continue; 1107 continue;
1098 } 1108 }
1099 1109
1100 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); 1110 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
1101 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1111 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1102 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1112 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1103 EXPECT_EQ(0, client_->in_flight_event_count()); 1113 EXPECT_EQ(0, client_->in_flight_event_count());
1114
1115 if (type == WebInputEvent::GestureScrollBegin) {
1116 EXPECT_TRUE(HasPendingEvents());
1117 AckTouchScrollStartedNotification();
1118 }
1104 EXPECT_FALSE(HasPendingEvents()); 1119 EXPECT_FALSE(HasPendingEvents());
1105 } 1120 }
1106 } 1121 }
1107 1122
1108 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { 1123 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) {
1109 int start_type = static_cast<int>(WebInputEvent::MouseDown); 1124 int start_type = static_cast<int>(WebInputEvent::MouseDown);
1110 int end_type = static_cast<int>(WebInputEvent::ContextMenu); 1125 int end_type = static_cast<int>(WebInputEvent::ContextMenu);
1111 ASSERT_LT(start_type, end_type); 1126 ASSERT_LT(start_type, end_type);
1112 for (int i = start_type; i <= end_type; ++i) { 1127 for (int i = start_type; i <= end_type; ++i) {
1113 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 1128 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 } 1239 }
1225 1240
1226 // Test that GestureShowPress events don't get out of order due to 1241 // Test that GestureShowPress events don't get out of order due to
1227 // ignoring their acks. 1242 // ignoring their acks.
1228 TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) { 1243 TEST_F(InputRouterImplTest, GestureShowPressIsInOrder) {
1229 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1244 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1230 blink::WebGestureDeviceTouchscreen); 1245 blink::WebGestureDeviceTouchscreen);
1231 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1246 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1232 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1247 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1233 1248
1234
1235 // GesturePinchBegin ignores its ack. 1249 // GesturePinchBegin ignores its ack.
1236 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, 1250 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
1237 blink::WebGestureDeviceTouchscreen); 1251 blink::WebGestureDeviceTouchscreen);
1238 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1252 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1239 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1253 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1240 1254
1241 // GesturePinchUpdate waits for an ack. 1255 // GesturePinchUpdate waits for an ack.
1242 // This also verifies that GesturePinchUpdates for touchscreen are sent 1256 // This also verifies that GesturePinchUpdates for touchscreen are sent
1243 // to the renderer (in contrast to the TrackpadPinchUpdate test). 1257 // to the renderer (in contrast to the TrackpadPinchUpdate test).
1244 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1258 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 touch_move_event_id2); 1457 touch_move_event_id2);
1444 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); 1458 EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
1445 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1459 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1446 blink::WebGestureDeviceTouchscreen); 1460 blink::WebGestureDeviceTouchscreen);
1447 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1461 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1448 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, 1462 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
1449 blink::WebGestureDeviceTouchscreen); 1463 blink::WebGestureDeviceTouchscreen);
1450 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1464 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1451 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, 1465 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED,
1452 touch_release_event_id2); 1466 touch_release_event_id2);
1467 AckTouchScrollStartedNotification();
1453 } 1468 }
1454 1469
1455 // Test that TouchActionFilter::ResetTouchAction is called when a new touch 1470 // Test that TouchActionFilter::ResetTouchAction is called when a new touch
1456 // sequence has no consumer. 1471 // sequence has no consumer.
1457 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) { 1472 TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) {
1458 OnHasTouchEventHandlers(true); 1473 OnHasTouchEventHandlers(true);
1459 1474
1460 // Sequence 1. 1475 // Sequence 1.
1461 PressTouchPoint(1, 1); 1476 PressTouchPoint(1, 1);
1462 uint32_t touch_press_event_id1 = SendTouchEvent(); 1477 uint32_t touch_press_event_id1 = SendTouchEvent();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 // Test that the router will call the client's |DidFlush| after all fling 1698 // Test that the router will call the client's |DidFlush| after all fling
1684 // animations have completed. 1699 // animations have completed.
1685 TEST_F(InputRouterImplTest, InputFlushAfterFling) { 1700 TEST_F(InputRouterImplTest, InputFlushAfterFling) {
1686 EXPECT_FALSE(HasPendingEvents()); 1701 EXPECT_FALSE(HasPendingEvents());
1687 1702
1688 // Simulate a fling. 1703 // Simulate a fling.
1689 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1704 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1690 blink::WebGestureDeviceTouchscreen); 1705 blink::WebGestureDeviceTouchscreen);
1691 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1706 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1692 blink::WebGestureDeviceTouchscreen); 1707 blink::WebGestureDeviceTouchscreen);
1708 AckTouchScrollStartedNotification();
1693 EXPECT_TRUE(HasPendingEvents()); 1709 EXPECT_TRUE(HasPendingEvents());
1694 1710
1695 // If the fling is unconsumed, the flush is complete. 1711 // If the fling is unconsumed, the flush is complete.
1696 RequestNotificationWhenFlushed(); 1712 RequestNotificationWhenFlushed();
1697 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1713 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1698 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1714 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1699 blink::WebGestureDeviceTouchscreen); 1715 blink::WebGestureDeviceTouchscreen);
1700 SendInputEventACK(WebInputEvent::GestureFlingStart, 1716 SendInputEventACK(WebInputEvent::GestureFlingStart,
1701 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1717 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1718 EXPECT_TRUE(HasPendingEvents());
1719 AckTouchScrollStartedNotification();
1702 EXPECT_FALSE(HasPendingEvents()); 1720 EXPECT_FALSE(HasPendingEvents());
1703 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1721 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1704 1722
1705 // Simulate a second fling. 1723 // Simulate a second fling.
1706 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1724 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1707 blink::WebGestureDeviceTouchscreen); 1725 blink::WebGestureDeviceTouchscreen);
1708 EXPECT_TRUE(HasPendingEvents()); 1726 EXPECT_TRUE(HasPendingEvents());
1709 1727
1710 // If the fling is consumed, the flush is complete only when the renderer 1728 // If the fling is consumed, the flush is complete only when the renderer
1711 // reports that is has ended. 1729 // reports that is has ended.
1712 RequestNotificationWhenFlushed(); 1730 RequestNotificationWhenFlushed();
1713 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1731 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1714 SendInputEventACK(WebInputEvent::GestureFlingStart, 1732 SendInputEventACK(WebInputEvent::GestureFlingStart,
1715 INPUT_EVENT_ACK_STATE_CONSUMED); 1733 INPUT_EVENT_ACK_STATE_CONSUMED);
1716 EXPECT_TRUE(HasPendingEvents()); 1734 EXPECT_TRUE(HasPendingEvents());
1717 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1735 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1718 1736
1719 // The fling end notification should signal that the router is flushed. 1737 // The fling end notification should signal that the router is flushed.
1720 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); 1738 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0));
1721 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1739 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1722 1740
1723 // Even flings consumed by the client require a fling-end notification. 1741 // Even flings consumed by the client require a fling-end notification.
1724 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); 1742 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED);
1725 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1743 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1726 blink::WebGestureDeviceTouchscreen); 1744 blink::WebGestureDeviceTouchscreen);
1727 SimulateGestureEvent(WebInputEvent::GestureFlingStart, 1745 SimulateGestureEvent(WebInputEvent::GestureFlingStart,
1728 blink::WebGestureDeviceTouchscreen); 1746 blink::WebGestureDeviceTouchscreen);
1747 AckTouchScrollStartedNotification();
1729 ASSERT_TRUE(HasPendingEvents()); 1748 ASSERT_TRUE(HasPendingEvents());
1730 RequestNotificationWhenFlushed(); 1749 RequestNotificationWhenFlushed();
1731 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1750 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1732 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); 1751 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0));
1733 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1752 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1734 } 1753 }
1735 1754
1736 // Test that GesturePinchUpdate is handled specially for trackpad 1755 // Test that GesturePinchUpdate is handled specially for trackpad
1737 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { 1756 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) {
1738 // GesturePinchUpdate for trackpad sends synthetic wheel events. 1757 // GesturePinchUpdate for trackpad sends synthetic wheel events.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); 2346 EXPECT_EQ(80, sent_event->data.flingStart.velocityY);
2328 2347
2329 const WebGestureEvent* filter_event = 2348 const WebGestureEvent* filter_event =
2330 GetFilterWebInputEvent<WebGestureEvent>(); 2349 GetFilterWebInputEvent<WebGestureEvent>();
2331 TestLocationInFilterEvent(filter_event, orig); 2350 TestLocationInFilterEvent(filter_event, orig);
2332 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); 2351 EXPECT_EQ(30, filter_event->data.flingStart.velocityX);
2333 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); 2352 EXPECT_EQ(40, filter_event->data.flingStart.velocityY);
2334 } 2353 }
2335 2354
2336 } // namespace content 2355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698