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

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

Issue 1780953003: Change the non-blocking event queue to the main thread event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_regression_5
Patch Set: Fix android Created 4 years, 9 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 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 1014
1015 // Check that the correct unhandled wheel event was received. 1015 // Check that the correct unhandled wheel event was received.
1016 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount()); 1016 EXPECT_EQ(2U, ack_handler_->GetAndResetAckCount());
1017 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state()); 1017 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, ack_handler_->ack_state());
1018 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -10); 1018 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -10);
1019 } 1019 }
1020 1020
1021 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { 1021 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {
1022 OnHasTouchEventHandlers(true); 1022 OnHasTouchEventHandlers(true);
1023 // Only acks for TouchCancel should always be ignored. 1023 // Only acks for TouchCancel should always be ignored.
1024 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1024 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1025 GetEventWithType(WebInputEvent::TouchStart))); 1025 GetEventWithType(WebInputEvent::TouchStart)));
1026 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1026 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1027 GetEventWithType(WebInputEvent::TouchMove))); 1027 GetEventWithType(WebInputEvent::TouchMove)));
1028 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1028 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1029 GetEventWithType(WebInputEvent::TouchEnd))); 1029 GetEventWithType(WebInputEvent::TouchEnd)));
1030 1030
1031 // Precede the TouchCancel with an appropriate TouchStart; 1031 // Precede the TouchCancel with an appropriate TouchStart;
1032 PressTouchPoint(1, 1); 1032 PressTouchPoint(1, 1);
1033 uint32_t touch_press_event_id = SendTouchEvent(); 1033 uint32_t touch_press_event_id = SendTouchEvent();
1034 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED, 1034 SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED,
1035 touch_press_event_id); 1035 touch_press_event_id);
1036 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); 1036 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
1037 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1037 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount());
1038 ASSERT_EQ(0, client_->in_flight_event_count()); 1038 ASSERT_EQ(0, client_->in_flight_event_count());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 WebInputEvent::GestureTapDown, 1077 WebInputEvent::GestureTapDown,
1078 WebInputEvent::GestureTapCancel, 1078 WebInputEvent::GestureTapCancel,
1079 WebInputEvent::GestureScrollBegin, 1079 WebInputEvent::GestureScrollBegin,
1080 WebInputEvent::GestureScrollUpdate, 1080 WebInputEvent::GestureScrollUpdate,
1081 WebInputEvent::GesturePinchBegin, 1081 WebInputEvent::GesturePinchBegin,
1082 WebInputEvent::GesturePinchUpdate, 1082 WebInputEvent::GesturePinchUpdate,
1083 WebInputEvent::GesturePinchEnd, 1083 WebInputEvent::GesturePinchEnd,
1084 WebInputEvent::GestureScrollEnd}; 1084 WebInputEvent::GestureScrollEnd};
1085 for (size_t i = 0; i < arraysize(eventTypes); ++i) { 1085 for (size_t i = 0; i < arraysize(eventTypes); ++i) {
1086 WebInputEvent::Type type = eventTypes[i]; 1086 WebInputEvent::Type type = eventTypes[i];
1087 if (WebInputEventTraits::WillReceiveAckFromRenderer( 1087 if (WebInputEventTraits::ShouldBlockEventStream(GetEventWithType(type))) {
1088 GetEventWithType(type))) {
1089 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); 1088 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
1090 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1089 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1091 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1090 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1092 EXPECT_EQ(1, client_->in_flight_event_count()); 1091 EXPECT_EQ(1, client_->in_flight_event_count());
1093 EXPECT_TRUE(HasPendingEvents()); 1092 EXPECT_TRUE(HasPendingEvents());
1094 1093
1095 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1094 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1096 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1095 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1097 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1096 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1098 EXPECT_EQ(0, client_->in_flight_event_count()); 1097 EXPECT_EQ(0, client_->in_flight_event_count());
1099 EXPECT_FALSE(HasPendingEvents()); 1098 EXPECT_FALSE(HasPendingEvents());
1100 continue; 1099 continue;
1101 } 1100 }
1102 1101
1103 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); 1102 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
1104 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1103 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1105 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1104 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1106 EXPECT_EQ(0, client_->in_flight_event_count()); 1105 EXPECT_EQ(0, client_->in_flight_event_count());
1107 EXPECT_FALSE(HasPendingEvents()); 1106 EXPECT_FALSE(HasPendingEvents());
1108 } 1107 }
1109 } 1108 }
1110 1109
1111 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { 1110 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) {
1112 int start_type = static_cast<int>(WebInputEvent::MouseDown); 1111 int start_type = static_cast<int>(WebInputEvent::MouseDown);
1113 int end_type = static_cast<int>(WebInputEvent::ContextMenu); 1112 int end_type = static_cast<int>(WebInputEvent::ContextMenu);
1114 ASSERT_LT(start_type, end_type); 1113 ASSERT_LT(start_type, end_type);
1115 for (int i = start_type; i <= end_type; ++i) { 1114 for (int i = start_type; i <= end_type; ++i) {
1116 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 1115 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i);
1117 int expected_in_flight_event_count = 1116 int expected_in_flight_event_count =
1118 !WebInputEventTraits::WillReceiveAckFromRenderer(GetEventWithType(type)) 1117 !WebInputEventTraits::ShouldBlockEventStream(GetEventWithType(type))
1119 ? 0 1118 ? 0
1120 : 1; 1119 : 1;
1121 1120
1122 // Note: Only MouseMove ack is forwarded to the ack handler. 1121 // Note: Only MouseMove ack is forwarded to the ack handler.
1123 SimulateMouseEvent(type, 0, 0); 1122 SimulateMouseEvent(type, 0, 0);
1124 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1123 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1125 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1124 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1126 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count()); 1125 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count());
1127 if (expected_in_flight_event_count) { 1126 if (expected_in_flight_event_count) {
1128 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1127 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1129 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1128 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1130 uint32_t expected_ack_count = type == WebInputEvent::MouseMove ? 1 : 0; 1129 uint32_t expected_ack_count = type == WebInputEvent::MouseMove ? 1 : 0;
1131 EXPECT_EQ(expected_ack_count, ack_handler_->GetAndResetAckCount()); 1130 EXPECT_EQ(expected_ack_count, ack_handler_->GetAndResetAckCount());
1132 EXPECT_EQ(0, client_->in_flight_event_count()); 1131 EXPECT_EQ(0, client_->in_flight_event_count());
1133 } 1132 }
1134 } 1133 }
1135 } 1134 }
1136 1135
1137 // Guard against breaking changes to the list of ignored event ack types in 1136 // Guard against breaking changes to the list of ignored event ack types in
1138 // |WebInputEventTraits::WillReceiveAckFromRenderer|. 1137 // |WebInputEventTraits::ShouldBlockEventStream|.
1139 TEST_F(InputRouterImplTest, RequiredEventAckTypes) { 1138 TEST_F(InputRouterImplTest, RequiredEventAckTypes) {
1140 const WebInputEvent::Type kRequiredEventAckTypes[] = { 1139 const WebInputEvent::Type kRequiredEventAckTypes[] = {
1141 WebInputEvent::MouseMove, 1140 WebInputEvent::MouseMove,
1142 WebInputEvent::MouseWheel, 1141 WebInputEvent::MouseWheel,
1143 WebInputEvent::RawKeyDown, 1142 WebInputEvent::RawKeyDown,
1144 WebInputEvent::KeyDown, 1143 WebInputEvent::KeyDown,
1145 WebInputEvent::KeyUp, 1144 WebInputEvent::KeyUp,
1146 WebInputEvent::Char, 1145 WebInputEvent::Char,
1147 WebInputEvent::GestureScrollUpdate, 1146 WebInputEvent::GestureScrollUpdate,
1148 WebInputEvent::GestureFlingStart, 1147 WebInputEvent::GestureFlingStart,
1149 WebInputEvent::GestureFlingCancel, 1148 WebInputEvent::GestureFlingCancel,
1150 WebInputEvent::GesturePinchUpdate, 1149 WebInputEvent::GesturePinchUpdate,
1151 WebInputEvent::TouchStart, 1150 WebInputEvent::TouchStart,
1152 WebInputEvent::TouchMove 1151 WebInputEvent::TouchMove
1153 }; 1152 };
1154 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) { 1153 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) {
1155 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i]; 1154 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i];
1156 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1155 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1157 GetEventWithType(required_ack_type))); 1156 GetEventWithType(required_ack_type)));
1158 } 1157 }
1159 } 1158 }
1160 1159
1161 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't 1160 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't
1162 // wait for ACKs. 1161 // wait for ACKs.
1163 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) { 1162 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) {
1164 // Interleave a few events that do and do not ignore acks, ensuring that 1163 // Interleave a few events that do and do not ignore acks, ensuring that
1165 // ack-ignoring events aren't dispatched until all prior events which observe 1164 // ack-ignoring events aren't dispatched until all prior events which observe
1166 // their ack disposition have been dispatched. 1165 // their ack disposition have been dispatched.
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 SimulateGestureEvent(WebInputEvent::GestureTapDown, 1576 SimulateGestureEvent(WebInputEvent::GestureTapDown,
1578 blink::WebGestureDeviceTouchscreen); 1577 blink::WebGestureDeviceTouchscreen);
1579 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1578 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1580 1579
1581 // The GestureTapUnconfirmed is converted into a tap, as the touch action is 1580 // The GestureTapUnconfirmed is converted into a tap, as the touch action is
1582 // none. 1581 // none.
1583 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, 1582 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed,
1584 blink::WebGestureDeviceTouchscreen); 1583 blink::WebGestureDeviceTouchscreen);
1585 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1584 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1586 // This test will become invalid if GestureTap stops requiring an ack. 1585 // This test will become invalid if GestureTap stops requiring an ack.
1587 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1586 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1588 GetEventWithType(WebInputEvent::GestureTap))); 1587 GetEventWithType(WebInputEvent::GestureTap)));
1589 EXPECT_EQ(2, client_->in_flight_event_count()); 1588 EXPECT_EQ(2, client_->in_flight_event_count());
1590 SendInputEventACK(WebInputEvent::GestureTap, 1589 SendInputEventACK(WebInputEvent::GestureTap,
1591 INPUT_EVENT_ACK_STATE_CONSUMED); 1590 INPUT_EVENT_ACK_STATE_CONSUMED);
1592 EXPECT_EQ(1, client_->in_flight_event_count()); 1591 EXPECT_EQ(1, client_->in_flight_event_count());
1593 1592
1594 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned 1593 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned
1595 // into a tap. 1594 // into a tap.
1596 SimulateGestureEvent(WebInputEvent::GestureTap, 1595 SimulateGestureEvent(WebInputEvent::GestureTap,
1597 blink::WebGestureDeviceTouchscreen); 1596 blink::WebGestureDeviceTouchscreen);
1598 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1597 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1599 1598
1600 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED, 1599 SendTouchEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED,
1601 touch_release_event_id); 1600 touch_release_event_id);
1602 SendTouchEventACK(WebInputEvent::TouchStart, 1601 SendTouchEventACK(WebInputEvent::TouchStart,
1603 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, 1602 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS,
1604 touch_press_event_id2); 1603 touch_press_event_id2);
1605 1604
1606 // Second Tap. 1605 // Second Tap.
1607 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1606 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1608 SimulateGestureEvent(WebInputEvent::GestureTapDown, 1607 SimulateGestureEvent(WebInputEvent::GestureTapDown,
1609 blink::WebGestureDeviceTouchscreen); 1608 blink::WebGestureDeviceTouchscreen);
1610 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1609 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1611 1610
1612 // Although the touch-action is now auto, the double tap still won't be 1611 // Although the touch-action is now auto, the double tap still won't be
1613 // dispatched, because the first tap occured when the touch-action was none. 1612 // dispatched, because the first tap occured when the touch-action was none.
1614 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, 1613 SimulateGestureEvent(WebInputEvent::GestureDoubleTap,
1615 blink::WebGestureDeviceTouchscreen); 1614 blink::WebGestureDeviceTouchscreen);
1616 // This test will become invalid if GestureDoubleTap stops requiring an ack. 1615 // This test will become invalid if GestureDoubleTap stops requiring an ack.
1617 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( 1616 ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
1618 GetEventWithType(WebInputEvent::GestureDoubleTap))); 1617 GetEventWithType(WebInputEvent::GestureDoubleTap)));
1619 EXPECT_EQ(1, client_->in_flight_event_count()); 1618 EXPECT_EQ(1, client_->in_flight_event_count());
1620 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); 1619 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED);
1621 EXPECT_EQ(0, client_->in_flight_event_count()); 1620 EXPECT_EQ(0, client_->in_flight_event_count());
1622 } 1621 }
1623 1622
1624 // Test that the router will call the client's |DidFlush| after all events have 1623 // Test that the router will call the client's |DidFlush| after all events have
1625 // been dispatched following a call to |Flush|. 1624 // been dispatched following a call to |Flush|.
1626 TEST_F(InputRouterImplTest, InputFlush) { 1625 TEST_F(InputRouterImplTest, InputFlush) {
1627 EXPECT_FALSE(HasPendingEvents()); 1626 EXPECT_FALSE(HasPendingEvents());
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); 2329 EXPECT_EQ(80, sent_event->data.flingStart.velocityY);
2331 2330
2332 const WebGestureEvent* filter_event = 2331 const WebGestureEvent* filter_event =
2333 GetFilterWebInputEvent<WebGestureEvent>(); 2332 GetFilterWebInputEvent<WebGestureEvent>();
2334 TestLocationInFilterEvent(filter_event, orig); 2333 TestLocationInFilterEvent(filter_event, orig);
2335 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); 2334 EXPECT_EQ(30, filter_event->data.flingStart.velocityX);
2336 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); 2335 EXPECT_EQ(40, filter_event->data.flingStart.velocityY);
2337 } 2336 }
2338 2337
2339 } // namespace content 2338 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698