| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 void SendInputEventACK(blink::WebInputEvent::Type type, | 271 void SendInputEventACK(blink::WebInputEvent::Type type, |
| 272 InputEventAckState ack_result) { | 272 InputEventAckState ack_result) { |
| 273 InputHostMsg_HandleInputEvent_ACK_Params ack; | 273 InputHostMsg_HandleInputEvent_ACK_Params ack; |
| 274 ack.type = type; | 274 ack.type = type; |
| 275 ack.state = ack_result; | 275 ack.state = ack_result; |
| 276 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); | 276 input_router_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack)); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void NotifyDidStopFlinging() { | |
| 280 input_router_->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); | |
| 281 } | |
| 282 | |
| 283 InputRouterImpl* input_router() const { | 279 InputRouterImpl* input_router() const { |
| 284 return input_router_.get(); | 280 return input_router_.get(); |
| 285 } | 281 } |
| 286 | 282 |
| 287 bool TouchEventQueueEmpty() const { | 283 bool TouchEventQueueEmpty() const { |
| 288 return input_router()->touch_event_queue_.empty(); | 284 return input_router()->touch_event_queue_.empty(); |
| 289 } | 285 } |
| 290 | 286 |
| 291 bool TouchEventTimeoutEnabled() const { | 287 bool TouchEventTimeoutEnabled() const { |
| 292 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); | 288 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 WebInputEvent::GestureTapDown, | 1012 WebInputEvent::GestureTapDown, |
| 1017 WebInputEvent::GestureTapCancel, | 1013 WebInputEvent::GestureTapCancel, |
| 1018 WebInputEvent::GestureScrollBegin, | 1014 WebInputEvent::GestureScrollBegin, |
| 1019 WebInputEvent::GestureScrollUpdate, | 1015 WebInputEvent::GestureScrollUpdate, |
| 1020 WebInputEvent::GesturePinchBegin, | 1016 WebInputEvent::GesturePinchBegin, |
| 1021 WebInputEvent::GesturePinchUpdate, | 1017 WebInputEvent::GesturePinchUpdate, |
| 1022 WebInputEvent::GesturePinchEnd, | 1018 WebInputEvent::GesturePinchEnd, |
| 1023 WebInputEvent::GestureScrollEnd}; | 1019 WebInputEvent::GestureScrollEnd}; |
| 1024 for (size_t i = 0; i < arraysize(eventTypes); ++i) { | 1020 for (size_t i = 0; i < arraysize(eventTypes); ++i) { |
| 1025 WebInputEvent::Type type = eventTypes[i]; | 1021 WebInputEvent::Type type = eventTypes[i]; |
| 1026 SCOPED_TRACE(WebInputEventTraits::GetName(type)); | |
| 1027 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { | 1022 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { |
| 1028 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1023 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1029 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1024 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1030 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1025 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 1031 EXPECT_EQ(1, client_->in_flight_event_count()); | 1026 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 1032 EXPECT_TRUE(HasPendingEvents()); | 1027 EXPECT_TRUE(HasPendingEvents()); |
| 1033 | 1028 |
| 1034 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_CONSUMED); | 1029 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1035 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1030 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1036 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1031 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1037 EXPECT_EQ(0, client_->in_flight_event_count()); | 1032 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1038 | 1033 EXPECT_FALSE(HasPendingEvents()); |
| 1039 // A GestureFlingCancel will be dropped unless there's an active | |
| 1040 // fling, and an active fling is considered a "pending" event. This rather | |
| 1041 // nasty bookkeeping is necessary to ensure the fling cancel gets properly | |
| 1042 // dispatched and the pending event expectations are valid. | |
| 1043 if (type == blink::WebInputEvent::GestureFlingCancel) | |
| 1044 NotifyDidStopFlinging(); | |
| 1045 if (type != blink::WebInputEvent::GestureFlingStart) | |
| 1046 EXPECT_FALSE(HasPendingEvents()); | |
| 1047 | |
| 1048 continue; | 1034 continue; |
| 1049 } | 1035 } |
| 1050 | 1036 |
| 1051 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1037 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
| 1052 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1038 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 1053 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1039 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1054 EXPECT_EQ(0, client_->in_flight_event_count()); | 1040 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1055 EXPECT_FALSE(HasPendingEvents()); | 1041 EXPECT_FALSE(HasPendingEvents()); |
| 1056 } | 1042 } |
| 1057 } | 1043 } |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1594 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1609 EXPECT_TRUE(HasPendingEvents()); | 1595 EXPECT_TRUE(HasPendingEvents()); |
| 1610 | 1596 |
| 1611 // The final ack'ed gesture should trigger the DidFlush. | 1597 // The final ack'ed gesture should trigger the DidFlush. |
| 1612 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 1598 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
| 1613 INPUT_EVENT_ACK_STATE_CONSUMED); | 1599 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1614 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1600 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1615 EXPECT_FALSE(HasPendingEvents()); | 1601 EXPECT_FALSE(HasPendingEvents()); |
| 1616 } | 1602 } |
| 1617 | 1603 |
| 1618 // Test that the router will call the client's |DidFlush| after all fling | |
| 1619 // animations have completed. | |
| 1620 TEST_F(InputRouterImplTest, InputFlushAfterFling) { | |
| 1621 EXPECT_FALSE(HasPendingEvents()); | |
| 1622 | |
| 1623 // Simulate a fling. | |
| 1624 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
| 1625 blink::WebGestureDeviceTouchscreen); | |
| 1626 SimulateGestureEvent(WebInputEvent::GestureFlingStart, | |
| 1627 blink::WebGestureDeviceTouchscreen); | |
| 1628 EXPECT_TRUE(HasPendingEvents()); | |
| 1629 | |
| 1630 // If the fling is unconsumed, the flush is complete. | |
| 1631 RequestNotificationWhenFlushed(); | |
| 1632 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
| 1633 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
| 1634 blink::WebGestureDeviceTouchscreen); | |
| 1635 SendInputEventACK(WebInputEvent::GestureFlingStart, | |
| 1636 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 1637 EXPECT_FALSE(HasPendingEvents()); | |
| 1638 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
| 1639 | |
| 1640 // Simulate a second fling. | |
| 1641 SimulateGestureEvent(WebInputEvent::GestureFlingStart, | |
| 1642 blink::WebGestureDeviceTouchscreen); | |
| 1643 EXPECT_TRUE(HasPendingEvents()); | |
| 1644 | |
| 1645 // If the fling is consumed, the flush is complete only when the renderer | |
| 1646 // reports that is has ended. | |
| 1647 RequestNotificationWhenFlushed(); | |
| 1648 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
| 1649 SendInputEventACK(WebInputEvent::GestureFlingStart, | |
| 1650 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 1651 EXPECT_TRUE(HasPendingEvents()); | |
| 1652 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | |
| 1653 | |
| 1654 // The fling end notification should signal that the router is flushed. | |
| 1655 NotifyDidStopFlinging(); | |
| 1656 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | |
| 1657 } | |
| 1658 | |
| 1659 // Test that GesturePinchUpdate is handled specially for trackpad | 1604 // Test that GesturePinchUpdate is handled specially for trackpad |
| 1660 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { | 1605 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
| 1661 // GesturePinchUpdate for trackpad sends synthetic wheel events. | 1606 // GesturePinchUpdate for trackpad sends synthetic wheel events. |
| 1662 // Note that the Touchscreen case is verified as NOT doing this as | 1607 // Note that the Touchscreen case is verified as NOT doing this as |
| 1663 // part of the ShowPressIsInOrder test. | 1608 // part of the ShowPressIsInOrder test. |
| 1664 | 1609 |
| 1665 SimulateGesturePinchUpdateEvent( | 1610 SimulateGesturePinchUpdateEvent( |
| 1666 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); | 1611 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); |
| 1667 | 1612 |
| 1668 // Verify we actually sent a special wheel event to the renderer. | 1613 // Verify we actually sent a special wheel event to the renderer. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 client_overscroll = client_->GetAndResetOverscroll(); | 1739 client_overscroll = client_->GetAndResetOverscroll(); |
| 1795 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1740 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
| 1796 client_overscroll.accumulated_overscroll); | 1741 client_overscroll.accumulated_overscroll); |
| 1797 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1742 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
| 1798 client_overscroll.latest_overscroll_delta); | 1743 client_overscroll.latest_overscroll_delta); |
| 1799 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1744 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
| 1800 client_overscroll.current_fling_velocity); | 1745 client_overscroll.current_fling_velocity); |
| 1801 } | 1746 } |
| 1802 | 1747 |
| 1803 } // namespace content | 1748 } // namespace content |
| OLD | NEW |