| OLD | NEW |
| 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 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 InputMsg_HandleInputEvent::ID)); | 954 InputMsg_HandleInputEvent::ID)); |
| 955 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 955 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 956 | 956 |
| 957 // Check that the correct unhandled wheel event was received. | 957 // Check that the correct unhandled wheel event was received. |
| 958 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); | 958 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); |
| 959 } | 959 } |
| 960 | 960 |
| 961 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { | 961 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { |
| 962 OnHasTouchEventHandlers(true); | 962 OnHasTouchEventHandlers(true); |
| 963 // Only acks for TouchCancel should always be ignored. | 963 // Only acks for TouchCancel should always be ignored. |
| 964 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 964 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 965 GetEventWithType(WebInputEvent::TouchStart))); | 965 GetEventWithType(WebInputEvent::TouchStart))); |
| 966 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 966 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 967 GetEventWithType(WebInputEvent::TouchMove))); | 967 GetEventWithType(WebInputEvent::TouchMove))); |
| 968 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 968 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 969 GetEventWithType(WebInputEvent::TouchEnd))); | 969 GetEventWithType(WebInputEvent::TouchEnd))); |
| 970 | 970 |
| 971 // Precede the TouchCancel with an appropriate TouchStart; | 971 // Precede the TouchCancel with an appropriate TouchStart; |
| 972 PressTouchPoint(1, 1); | 972 PressTouchPoint(1, 1); |
| 973 SendTouchEvent(); | 973 SendTouchEvent(); |
| 974 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 974 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 975 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 975 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 976 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 976 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 977 ASSERT_EQ(0, client_->in_flight_event_count()); | 977 ASSERT_EQ(0, client_->in_flight_event_count()); |
| 978 | 978 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 WebInputEvent::GestureTapCancel, | 1017 WebInputEvent::GestureTapCancel, |
| 1018 WebInputEvent::GestureScrollBegin, | 1018 WebInputEvent::GestureScrollBegin, |
| 1019 WebInputEvent::GestureScrollUpdate, | 1019 WebInputEvent::GestureScrollUpdate, |
| 1020 WebInputEvent::GesturePinchBegin, | 1020 WebInputEvent::GesturePinchBegin, |
| 1021 WebInputEvent::GesturePinchUpdate, | 1021 WebInputEvent::GesturePinchUpdate, |
| 1022 WebInputEvent::GesturePinchEnd, | 1022 WebInputEvent::GesturePinchEnd, |
| 1023 WebInputEvent::GestureScrollEnd}; | 1023 WebInputEvent::GestureScrollEnd}; |
| 1024 for (size_t i = 0; i < arraysize(eventTypes); ++i) { | 1024 for (size_t i = 0; i < arraysize(eventTypes); ++i) { |
| 1025 WebInputEvent::Type type = eventTypes[i]; | 1025 WebInputEvent::Type type = eventTypes[i]; |
| 1026 SCOPED_TRACE(WebInputEventTraits::GetName(type)); | 1026 SCOPED_TRACE(WebInputEventTraits::GetName(type)); |
| 1027 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { | 1027 if (WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1028 GetEventWithType(type))) { |
| 1028 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1029 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1029 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1030 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1030 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1031 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1031 EXPECT_EQ(1, client_->in_flight_event_count()); | 1032 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1032 EXPECT_TRUE(HasPendingEvents()); | 1033 EXPECT_TRUE(HasPendingEvents()); |
| 1033 | 1034 |
| 1034 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_CONSUMED); | 1035 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1035 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1036 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1036 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1037 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1037 EXPECT_EQ(0, client_->in_flight_event_count()); | 1038 EXPECT_EQ(0, client_->in_flight_event_count()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1056 } | 1057 } |
| 1057 } | 1058 } |
| 1058 | 1059 |
| 1059 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { | 1060 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { |
| 1060 int start_type = static_cast<int>(WebInputEvent::MouseDown); | 1061 int start_type = static_cast<int>(WebInputEvent::MouseDown); |
| 1061 int end_type = static_cast<int>(WebInputEvent::ContextMenu); | 1062 int end_type = static_cast<int>(WebInputEvent::ContextMenu); |
| 1062 ASSERT_LT(start_type, end_type); | 1063 ASSERT_LT(start_type, end_type); |
| 1063 for (int i = start_type; i <= end_type; ++i) { | 1064 for (int i = start_type; i <= end_type; ++i) { |
| 1064 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); | 1065 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); |
| 1065 int expected_in_flight_event_count = | 1066 int expected_in_flight_event_count = |
| 1066 WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type)) ? 0 | 1067 !WebInputEventTraits::WillReceiveAckFromRenderer(GetEventWithType(type)) |
| 1067 : 1; | 1068 ? 0 |
| 1069 : 1; |
| 1068 | 1070 |
| 1069 // Note: Mouse event acks are never forwarded to the ack handler, so the key | 1071 // Note: Mouse event acks are never forwarded to the ack handler, so the key |
| 1070 // result here is that ignored ack types don't affect the in-flight count. | 1072 // result here is that ignored ack types don't affect the in-flight count. |
| 1071 SimulateMouseEvent(type, 0, 0); | 1073 SimulateMouseEvent(type, 0, 0); |
| 1072 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1074 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1073 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1075 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1074 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count()); | 1076 EXPECT_EQ(expected_in_flight_event_count, client_->in_flight_event_count()); |
| 1075 if (expected_in_flight_event_count) { | 1077 if (expected_in_flight_event_count) { |
| 1076 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1078 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1077 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1079 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1078 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1080 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1079 EXPECT_EQ(0, client_->in_flight_event_count()); | 1081 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1080 } | 1082 } |
| 1081 } | 1083 } |
| 1082 } | 1084 } |
| 1083 | 1085 |
| 1084 // Guard against breaking changes to the list of ignored event ack types in | 1086 // Guard against breaking changes to the list of ignored event ack types in |
| 1085 // |WebInputEventTraits::IgnoresAckDisposition|. | 1087 // |WebInputEventTraits::WillReceiveAckFromRenderer|. |
| 1086 TEST_F(InputRouterImplTest, RequiredEventAckTypes) { | 1088 TEST_F(InputRouterImplTest, RequiredEventAckTypes) { |
| 1087 const WebInputEvent::Type kRequiredEventAckTypes[] = { | 1089 const WebInputEvent::Type kRequiredEventAckTypes[] = { |
| 1088 WebInputEvent::MouseMove, | 1090 WebInputEvent::MouseMove, |
| 1089 WebInputEvent::MouseWheel, | 1091 WebInputEvent::MouseWheel, |
| 1090 WebInputEvent::RawKeyDown, | 1092 WebInputEvent::RawKeyDown, |
| 1091 WebInputEvent::KeyDown, | 1093 WebInputEvent::KeyDown, |
| 1092 WebInputEvent::KeyUp, | 1094 WebInputEvent::KeyUp, |
| 1093 WebInputEvent::Char, | 1095 WebInputEvent::Char, |
| 1094 WebInputEvent::GestureScrollUpdate, | 1096 WebInputEvent::GestureScrollUpdate, |
| 1095 WebInputEvent::GestureFlingStart, | 1097 WebInputEvent::GestureFlingStart, |
| 1096 WebInputEvent::GestureFlingCancel, | 1098 WebInputEvent::GestureFlingCancel, |
| 1097 WebInputEvent::GesturePinchUpdate, | 1099 WebInputEvent::GesturePinchUpdate, |
| 1098 WebInputEvent::TouchStart, | 1100 WebInputEvent::TouchStart, |
| 1099 WebInputEvent::TouchMove | 1101 WebInputEvent::TouchMove |
| 1100 }; | 1102 }; |
| 1101 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) { | 1103 for (size_t i = 0; i < arraysize(kRequiredEventAckTypes); ++i) { |
| 1102 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i]; | 1104 const WebInputEvent::Type required_ack_type = kRequiredEventAckTypes[i]; |
| 1103 EXPECT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1105 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1104 GetEventWithType(required_ack_type))); | 1106 GetEventWithType(required_ack_type))); |
| 1105 } | 1107 } |
| 1106 } | 1108 } |
| 1107 | 1109 |
| 1108 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't | 1110 // Test that GestureShowPress, GestureTapDown and GestureTapCancel events don't |
| 1109 // wait for ACKs. | 1111 // wait for ACKs. |
| 1110 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) { | 1112 TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) { |
| 1111 // Interleave a few events that do and do not ignore acks, ensuring that | 1113 // Interleave a few events that do and do not ignore acks, ensuring that |
| 1112 // ack-ignoring events aren't dispatched until all prior events which observe | 1114 // ack-ignoring events aren't dispatched until all prior events which observe |
| 1113 // their ack disposition have been dispatched. | 1115 // their ack disposition have been dispatched. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1513 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1512 blink::WebGestureDeviceTouchscreen); | 1514 blink::WebGestureDeviceTouchscreen); |
| 1513 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1515 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1514 | 1516 |
| 1515 // The GestureTapUnconfirmed is converted into a tap, as the touch action is | 1517 // The GestureTapUnconfirmed is converted into a tap, as the touch action is |
| 1516 // none. | 1518 // none. |
| 1517 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, | 1519 SimulateGestureEvent(WebInputEvent::GestureTapUnconfirmed, |
| 1518 blink::WebGestureDeviceTouchscreen); | 1520 blink::WebGestureDeviceTouchscreen); |
| 1519 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1521 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1520 // This test will become invalid if GestureTap stops requiring an ack. | 1522 // This test will become invalid if GestureTap stops requiring an ack. |
| 1521 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1523 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1522 GetEventWithType(WebInputEvent::GestureTap))); | 1524 GetEventWithType(WebInputEvent::GestureTap))); |
| 1523 EXPECT_EQ(2, client_->in_flight_event_count()); | 1525 EXPECT_EQ(2, client_->in_flight_event_count()); |
| 1524 SendInputEventACK(WebInputEvent::GestureTap, | 1526 SendInputEventACK(WebInputEvent::GestureTap, |
| 1525 INPUT_EVENT_ACK_STATE_CONSUMED); | 1527 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1526 EXPECT_EQ(1, client_->in_flight_event_count()); | 1528 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1527 | 1529 |
| 1528 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned | 1530 // This tap gesture is dropped, since the GestureTapUnconfirmed was turned |
| 1529 // into a tap. | 1531 // into a tap. |
| 1530 SimulateGestureEvent(WebInputEvent::GestureTap, | 1532 SimulateGestureEvent(WebInputEvent::GestureTap, |
| 1531 blink::WebGestureDeviceTouchscreen); | 1533 blink::WebGestureDeviceTouchscreen); |
| 1532 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1534 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1533 | 1535 |
| 1534 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1536 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1535 SendInputEventACK(WebInputEvent::TouchStart, | 1537 SendInputEventACK(WebInputEvent::TouchStart, |
| 1536 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 1538 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1537 | 1539 |
| 1538 // Second Tap. | 1540 // Second Tap. |
| 1539 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1541 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1540 SimulateGestureEvent(WebInputEvent::GestureTapDown, | 1542 SimulateGestureEvent(WebInputEvent::GestureTapDown, |
| 1541 blink::WebGestureDeviceTouchscreen); | 1543 blink::WebGestureDeviceTouchscreen); |
| 1542 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1544 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1543 | 1545 |
| 1544 // Although the touch-action is now auto, the double tap still won't be | 1546 // Although the touch-action is now auto, the double tap still won't be |
| 1545 // dispatched, because the first tap occured when the touch-action was none. | 1547 // dispatched, because the first tap occured when the touch-action was none. |
| 1546 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, | 1548 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, |
| 1547 blink::WebGestureDeviceTouchscreen); | 1549 blink::WebGestureDeviceTouchscreen); |
| 1548 // This test will become invalid if GestureDoubleTap stops requiring an ack. | 1550 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
| 1549 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition( | 1551 ASSERT_TRUE(WebInputEventTraits::WillReceiveAckFromRenderer( |
| 1550 GetEventWithType(WebInputEvent::GestureDoubleTap))); | 1552 GetEventWithType(WebInputEvent::GestureDoubleTap))); |
| 1551 EXPECT_EQ(1, client_->in_flight_event_count()); | 1553 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1552 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1554 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1553 EXPECT_EQ(0, client_->in_flight_event_count()); | 1555 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1554 } | 1556 } |
| 1555 | 1557 |
| 1556 // Test that the router will call the client's |DidFlush| after all events have | 1558 // Test that the router will call the client's |DidFlush| after all events have |
| 1557 // been dispatched following a call to |Flush|. | 1559 // been dispatched following a call to |Flush|. |
| 1558 TEST_F(InputRouterImplTest, InputFlush) { | 1560 TEST_F(InputRouterImplTest, InputFlush) { |
| 1559 EXPECT_FALSE(HasPendingEvents()); | 1561 EXPECT_FALSE(HasPendingEvents()); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 client_overscroll = client_->GetAndResetOverscroll(); | 1796 client_overscroll = client_->GetAndResetOverscroll(); |
| 1795 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1797 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
| 1796 client_overscroll.accumulated_overscroll); | 1798 client_overscroll.accumulated_overscroll); |
| 1797 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1799 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
| 1798 client_overscroll.latest_overscroll_delta); | 1800 client_overscroll.latest_overscroll_delta); |
| 1799 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1801 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
| 1800 client_overscroll.current_fling_velocity); | 1802 client_overscroll.current_fling_velocity); |
| 1801 } | 1803 } |
| 1802 | 1804 |
| 1803 } // namespace content | 1805 } // namespace content |
| OLD | NEW |