| 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 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1542 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1539 EXPECT_EQ(0, client_->in_flight_event_count()); | 1543 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1540 } | 1544 } |
| 1541 | 1545 |
| 1542 // Test that the router will call the client's |DidFlush| after all events have | 1546 // Test that the router will call the client's |DidFlush| after all events have |
| 1543 // been dispatched following a call to |Flush|. | 1547 // been dispatched following a call to |Flush|. |
| 1544 TEST_F(InputRouterImplTest, InputFlush) { | 1548 TEST_F(InputRouterImplTest, InputFlush) { |
| 1545 EXPECT_FALSE(HasPendingEvents()); | 1549 EXPECT_FALSE(HasPendingEvents()); |
| 1546 | 1550 |
| 1547 // Flushing an empty router should immediately trigger DidFlush. | 1551 // Flushing an empty router should immediately trigger DidFlush. |
| 1548 Flush(); | 1552 RequestNotificationWhenFlushed(); |
| 1549 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1553 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1550 EXPECT_FALSE(HasPendingEvents()); | 1554 EXPECT_FALSE(HasPendingEvents()); |
| 1551 | 1555 |
| 1552 // Queue a TouchStart. | 1556 // Queue a TouchStart. |
| 1553 OnHasTouchEventHandlers(true); | 1557 OnHasTouchEventHandlers(true); |
| 1554 PressTouchPoint(1, 1); | 1558 PressTouchPoint(1, 1); |
| 1555 SendTouchEvent(); | 1559 SendTouchEvent(); |
| 1556 EXPECT_TRUE(HasPendingEvents()); | 1560 EXPECT_TRUE(HasPendingEvents()); |
| 1557 | 1561 |
| 1558 // DidFlush should be called only after the event is ack'ed. | 1562 // DidFlush should be called only after the event is ack'ed. |
| 1559 Flush(); | 1563 RequestNotificationWhenFlushed(); |
| 1560 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1564 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1561 SendInputEventACK(WebInputEvent::TouchStart, | 1565 SendInputEventACK(WebInputEvent::TouchStart, |
| 1562 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1566 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1563 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1567 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1564 | 1568 |
| 1565 // Ensure different types of enqueued events will prevent the DidFlush call | 1569 // Ensure different types of enqueued events will prevent the DidFlush call |
| 1566 // until all such events have been fully dispatched. | 1570 // until all such events have been fully dispatched. |
| 1567 MoveTouchPoint(0, 50, 50); | 1571 MoveTouchPoint(0, 50, 50); |
| 1568 SendTouchEvent(); | 1572 SendTouchEvent(); |
| 1569 ASSERT_TRUE(HasPendingEvents()); | 1573 ASSERT_TRUE(HasPendingEvents()); |
| 1570 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1574 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1571 blink::WebGestureDeviceTouchscreen); | 1575 blink::WebGestureDeviceTouchscreen); |
| 1572 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1576 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1573 blink::WebGestureDeviceTouchscreen); | 1577 blink::WebGestureDeviceTouchscreen); |
| 1574 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 1578 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
| 1575 blink::WebGestureDeviceTouchscreen); | 1579 blink::WebGestureDeviceTouchscreen); |
| 1576 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1580 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 1577 blink::WebGestureDeviceTouchscreen); | 1581 blink::WebGestureDeviceTouchscreen); |
| 1578 Flush(); | 1582 RequestNotificationWhenFlushed(); |
| 1579 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1583 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1580 | 1584 |
| 1581 // Repeated flush calls should have no effect. | 1585 // Repeated flush calls should have no effect. |
| 1582 Flush(); | 1586 RequestNotificationWhenFlushed(); |
| 1583 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1587 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1584 | 1588 |
| 1585 // There are still pending gestures. | 1589 // There are still pending gestures. |
| 1586 SendInputEventACK(WebInputEvent::TouchMove, | 1590 SendInputEventACK(WebInputEvent::TouchMove, |
| 1587 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1591 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1588 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1592 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1589 EXPECT_TRUE(HasPendingEvents()); | 1593 EXPECT_TRUE(HasPendingEvents()); |
| 1590 | 1594 |
| 1591 // One more gesture to go. | 1595 // One more gesture to go. |
| 1592 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1596 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1593 INPUT_EVENT_ACK_STATE_CONSUMED); | 1597 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1594 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1598 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1595 EXPECT_TRUE(HasPendingEvents()); | 1599 EXPECT_TRUE(HasPendingEvents()); |
| 1596 | 1600 |
| 1597 // The final ack'ed gesture should trigger the DidFlush. | 1601 // The final ack'ed gesture should trigger the DidFlush. |
| 1598 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 1602 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
| 1599 INPUT_EVENT_ACK_STATE_CONSUMED); | 1603 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1600 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1604 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1601 EXPECT_FALSE(HasPendingEvents()); | 1605 EXPECT_FALSE(HasPendingEvents()); |
| 1602 } | 1606 } |
| 1603 | 1607 |
| 1608 // Test that the router will call the client's |DidFlush| after all fling |
| 1609 // animations have completed. |
| 1610 TEST_F(InputRouterImplTest, InputFlushAfterFling) { |
| 1611 EXPECT_FALSE(HasPendingEvents()); |
| 1612 |
| 1613 // Simulate a fling. |
| 1614 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1615 blink::WebGestureDeviceTouchscreen); |
| 1616 SimulateGestureEvent(WebInputEvent::GestureFlingStart, |
| 1617 blink::WebGestureDeviceTouchscreen); |
| 1618 EXPECT_TRUE(HasPendingEvents()); |
| 1619 |
| 1620 // If the fling is unconsumed, the flush is complete. |
| 1621 RequestNotificationWhenFlushed(); |
| 1622 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1623 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1624 blink::WebGestureDeviceTouchscreen); |
| 1625 SendInputEventACK(WebInputEvent::GestureFlingStart, |
| 1626 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1627 EXPECT_FALSE(HasPendingEvents()); |
| 1628 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1629 |
| 1630 // Simulate a second fling. |
| 1631 SimulateGestureEvent(WebInputEvent::GestureFlingStart, |
| 1632 blink::WebGestureDeviceTouchscreen); |
| 1633 EXPECT_TRUE(HasPendingEvents()); |
| 1634 |
| 1635 // If the fling is consumed, the flush is complete only when the renderer |
| 1636 // reports that is has ended. |
| 1637 RequestNotificationWhenFlushed(); |
| 1638 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1639 SendInputEventACK(WebInputEvent::GestureFlingStart, |
| 1640 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1641 EXPECT_TRUE(HasPendingEvents()); |
| 1642 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1643 |
| 1644 // The fling end notification should signal that the router is flushed. |
| 1645 NotifyDidStopFlinging(); |
| 1646 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1647 } |
| 1648 |
| 1604 // Test that GesturePinchUpdate is handled specially for trackpad | 1649 // Test that GesturePinchUpdate is handled specially for trackpad |
| 1605 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { | 1650 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
| 1606 // GesturePinchUpdate for trackpad sends synthetic wheel events. | 1651 // GesturePinchUpdate for trackpad sends synthetic wheel events. |
| 1607 // Note that the Touchscreen case is verified as NOT doing this as | 1652 // Note that the Touchscreen case is verified as NOT doing this as |
| 1608 // part of the ShowPressIsInOrder test. | 1653 // part of the ShowPressIsInOrder test. |
| 1609 | 1654 |
| 1610 SimulateGesturePinchUpdateEvent( | 1655 SimulateGesturePinchUpdateEvent( |
| 1611 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); | 1656 1.5f, 20, 25, 0, blink::WebGestureDeviceTouchpad); |
| 1612 | 1657 |
| 1613 // Verify we actually sent a special wheel event to the renderer. | 1658 // 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(); | 1784 client_overscroll = client_->GetAndResetOverscroll(); |
| 1740 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1785 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
| 1741 client_overscroll.accumulated_overscroll); | 1786 client_overscroll.accumulated_overscroll); |
| 1742 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1787 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
| 1743 client_overscroll.latest_overscroll_delta); | 1788 client_overscroll.latest_overscroll_delta); |
| 1744 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1789 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
| 1745 client_overscroll.current_fling_velocity); | 1790 client_overscroll.current_fling_velocity); |
| 1746 } | 1791 } |
| 1747 | 1792 |
| 1748 } // namespace content | 1793 } // namespace content |
| OLD | NEW |