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 |
279 InputRouterImpl* input_router() const { | 283 InputRouterImpl* input_router() const { |
280 return input_router_.get(); | 284 return input_router_.get(); |
281 } | 285 } |
282 | 286 |
283 bool TouchEventQueueEmpty() const { | 287 bool TouchEventQueueEmpty() const { |
284 return input_router()->touch_event_queue_.empty(); | 288 return input_router()->touch_event_queue_.empty(); |
285 } | 289 } |
286 | 290 |
287 bool TouchEventTimeoutEnabled() const { | 291 bool TouchEventTimeoutEnabled() const { |
288 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); | 292 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); |
289 } | 293 } |
290 | 294 |
291 void Flush() const { | 295 void RequestNotificationWhenFlushed() const { |
292 return input_router_->Flush(); | 296 return input_router_->RequestNotificationWhenFlushed(); |
293 } | 297 } |
294 | 298 |
295 size_t GetAndResetDidFlushCount() { | 299 size_t GetAndResetDidFlushCount() { |
296 return client_->GetAndResetDidFlushCount(); | 300 return client_->GetAndResetDidFlushCount(); |
297 } | 301 } |
298 | 302 |
299 bool HasPendingEvents() const { | 303 bool HasPendingEvents() const { |
300 return input_router_->HasPendingEvents(); | 304 return input_router_->HasPendingEvents(); |
301 } | 305 } |
302 | 306 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 WebInputEvent::GestureTapDown, | 1016 WebInputEvent::GestureTapDown, |
1013 WebInputEvent::GestureTapCancel, | 1017 WebInputEvent::GestureTapCancel, |
1014 WebInputEvent::GestureScrollBegin, | 1018 WebInputEvent::GestureScrollBegin, |
1015 WebInputEvent::GestureScrollUpdate, | 1019 WebInputEvent::GestureScrollUpdate, |
1016 WebInputEvent::GesturePinchBegin, | 1020 WebInputEvent::GesturePinchBegin, |
1017 WebInputEvent::GesturePinchUpdate, | 1021 WebInputEvent::GesturePinchUpdate, |
1018 WebInputEvent::GesturePinchEnd, | 1022 WebInputEvent::GesturePinchEnd, |
1019 WebInputEvent::GestureScrollEnd}; | 1023 WebInputEvent::GestureScrollEnd}; |
1020 for (size_t i = 0; i < arraysize(eventTypes); ++i) { | 1024 for (size_t i = 0; i < arraysize(eventTypes); ++i) { |
1021 WebInputEvent::Type type = eventTypes[i]; | 1025 WebInputEvent::Type type = eventTypes[i]; |
| 1026 SCOPED_TRACE(WebInputEventTraits::GetName(type)); |
1022 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { | 1027 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) { |
1023 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1028 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
1024 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1029 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1025 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1030 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1026 EXPECT_EQ(1, client_->in_flight_event_count()); | 1031 EXPECT_EQ(1, client_->in_flight_event_count()); |
1027 EXPECT_TRUE(HasPendingEvents()); | 1032 EXPECT_TRUE(HasPendingEvents()); |
1028 | 1033 |
1029 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1034 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_CONSUMED); |
1030 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1035 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1031 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1036 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1032 EXPECT_EQ(0, client_->in_flight_event_count()); | 1037 EXPECT_EQ(0, client_->in_flight_event_count()); |
1033 EXPECT_FALSE(HasPendingEvents()); | 1038 |
| 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 |
1034 continue; | 1048 continue; |
1035 } | 1049 } |
1036 | 1050 |
1037 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); | 1051 SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen); |
1038 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1052 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1039 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1053 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1040 EXPECT_EQ(0, client_->in_flight_event_count()); | 1054 EXPECT_EQ(0, client_->in_flight_event_count()); |
1041 EXPECT_FALSE(HasPendingEvents()); | 1055 EXPECT_FALSE(HasPendingEvents()); |
1042 } | 1056 } |
1043 } | 1057 } |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1552 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
1539 EXPECT_EQ(0, client_->in_flight_event_count()); | 1553 EXPECT_EQ(0, client_->in_flight_event_count()); |
1540 } | 1554 } |
1541 | 1555 |
1542 // Test that the router will call the client's |DidFlush| after all events have | 1556 // Test that the router will call the client's |DidFlush| after all events have |
1543 // been dispatched following a call to |Flush|. | 1557 // been dispatched following a call to |Flush|. |
1544 TEST_F(InputRouterImplTest, InputFlush) { | 1558 TEST_F(InputRouterImplTest, InputFlush) { |
1545 EXPECT_FALSE(HasPendingEvents()); | 1559 EXPECT_FALSE(HasPendingEvents()); |
1546 | 1560 |
1547 // Flushing an empty router should immediately trigger DidFlush. | 1561 // Flushing an empty router should immediately trigger DidFlush. |
1548 Flush(); | 1562 RequestNotificationWhenFlushed(); |
1549 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1563 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1550 EXPECT_FALSE(HasPendingEvents()); | 1564 EXPECT_FALSE(HasPendingEvents()); |
1551 | 1565 |
1552 // Queue a TouchStart. | 1566 // Queue a TouchStart. |
1553 OnHasTouchEventHandlers(true); | 1567 OnHasTouchEventHandlers(true); |
1554 PressTouchPoint(1, 1); | 1568 PressTouchPoint(1, 1); |
1555 SendTouchEvent(); | 1569 SendTouchEvent(); |
1556 EXPECT_TRUE(HasPendingEvents()); | 1570 EXPECT_TRUE(HasPendingEvents()); |
1557 | 1571 |
1558 // DidFlush should be called only after the event is ack'ed. | 1572 // DidFlush should be called only after the event is ack'ed. |
1559 Flush(); | 1573 RequestNotificationWhenFlushed(); |
1560 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1574 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1561 SendInputEventACK(WebInputEvent::TouchStart, | 1575 SendInputEventACK(WebInputEvent::TouchStart, |
1562 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1576 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1563 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1577 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1564 | 1578 |
1565 // Ensure different types of enqueued events will prevent the DidFlush call | 1579 // Ensure different types of enqueued events will prevent the DidFlush call |
1566 // until all such events have been fully dispatched. | 1580 // until all such events have been fully dispatched. |
1567 MoveTouchPoint(0, 50, 50); | 1581 MoveTouchPoint(0, 50, 50); |
1568 SendTouchEvent(); | 1582 SendTouchEvent(); |
1569 ASSERT_TRUE(HasPendingEvents()); | 1583 ASSERT_TRUE(HasPendingEvents()); |
1570 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1584 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1571 blink::WebGestureDeviceTouchscreen); | 1585 blink::WebGestureDeviceTouchscreen); |
1572 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1586 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
1573 blink::WebGestureDeviceTouchscreen); | 1587 blink::WebGestureDeviceTouchscreen); |
1574 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 1588 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
1575 blink::WebGestureDeviceTouchscreen); | 1589 blink::WebGestureDeviceTouchscreen); |
1576 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1590 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
1577 blink::WebGestureDeviceTouchscreen); | 1591 blink::WebGestureDeviceTouchscreen); |
1578 Flush(); | 1592 RequestNotificationWhenFlushed(); |
1579 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1593 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1580 | 1594 |
1581 // Repeated flush calls should have no effect. | 1595 // Repeated flush calls should have no effect. |
1582 Flush(); | 1596 RequestNotificationWhenFlushed(); |
1583 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1597 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1584 | 1598 |
1585 // There are still pending gestures. | 1599 // There are still pending gestures. |
1586 SendInputEventACK(WebInputEvent::TouchMove, | 1600 SendInputEventACK(WebInputEvent::TouchMove, |
1587 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1601 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1588 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1602 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1589 EXPECT_TRUE(HasPendingEvents()); | 1603 EXPECT_TRUE(HasPendingEvents()); |
1590 | 1604 |
1591 // One more gesture to go. | 1605 // One more gesture to go. |
1592 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1606 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
1593 INPUT_EVENT_ACK_STATE_CONSUMED); | 1607 INPUT_EVENT_ACK_STATE_CONSUMED); |
1594 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1608 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1595 EXPECT_TRUE(HasPendingEvents()); | 1609 EXPECT_TRUE(HasPendingEvents()); |
1596 | 1610 |
1597 // The final ack'ed gesture should trigger the DidFlush. | 1611 // The final ack'ed gesture should trigger the DidFlush. |
1598 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 1612 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
1599 INPUT_EVENT_ACK_STATE_CONSUMED); | 1613 INPUT_EVENT_ACK_STATE_CONSUMED); |
1600 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1614 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1601 EXPECT_FALSE(HasPendingEvents()); | 1615 EXPECT_FALSE(HasPendingEvents()); |
1602 } | 1616 } |
1603 | 1617 |
| 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 |
1604 // Test that GesturePinchUpdate is handled specially for trackpad | 1659 // Test that GesturePinchUpdate is handled specially for trackpad |
1605 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { | 1660 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
1606 // GesturePinchUpdate for trackpad sends synthetic wheel events. | 1661 // GesturePinchUpdate for trackpad sends synthetic wheel events. |
1607 // Note that the Touchscreen case is verified as NOT doing this as | 1662 // Note that the Touchscreen case is verified as NOT doing this as |
1608 // part of the ShowPressIsInOrder test. | 1663 // part of the ShowPressIsInOrder test. |
1609 | 1664 |
1610 SimulateGesturePinchUpdateEvent( | 1665 SimulateGesturePinchUpdateEvent( |
1611 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); | 1666 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); |
1612 | 1667 |
1613 // Verify we actually sent a special wheel event to the renderer. | 1668 // Verify we actually sent a special wheel event to the renderer. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 client_overscroll = client_->GetAndResetOverscroll(); | 1794 client_overscroll = client_->GetAndResetOverscroll(); |
1740 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1795 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
1741 client_overscroll.accumulated_overscroll); | 1796 client_overscroll.accumulated_overscroll); |
1742 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1797 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
1743 client_overscroll.latest_overscroll_delta); | 1798 client_overscroll.latest_overscroll_delta); |
1744 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1799 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
1745 client_overscroll.current_fling_velocity); | 1800 client_overscroll.current_fling_velocity); |
1746 } | 1801 } |
1747 | 1802 |
1748 } // namespace content | 1803 } // namespace content |
OLD | NEW |