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/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 289 } |
290 | 290 |
291 bool TouchEventQueueEmpty() const { | 291 bool TouchEventQueueEmpty() const { |
292 return input_router()->touch_event_queue_.empty(); | 292 return input_router()->touch_event_queue_.empty(); |
293 } | 293 } |
294 | 294 |
295 bool TouchEventTimeoutEnabled() const { | 295 bool TouchEventTimeoutEnabled() const { |
296 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); | 296 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); |
297 } | 297 } |
298 | 298 |
299 void RequestNotificationWhenFlushed() const { | 299 void FlushInput() const { |
300 return input_router_->RequestNotificationWhenFlushed(); | 300 return input_router_->FlushInput(base::TimeTicks::Now()); |
301 } | 301 } |
302 | 302 |
303 size_t GetAndResetDidFlushCount() { | 303 size_t GetAndResetDidFlushCount() { |
304 return client_->GetAndResetDidFlushCount(); | 304 return client_->GetAndResetDidFlushCount(); |
305 } | 305 } |
306 | 306 |
307 bool HasPendingEvents() const { | 307 bool HasPendingEvents() const { |
308 return input_router_->HasPendingEvents(); | 308 return input_router_->HasPendingEvents(); |
309 } | 309 } |
310 | 310 |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); | 1558 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); |
1559 EXPECT_EQ(0, client_->in_flight_event_count()); | 1559 EXPECT_EQ(0, client_->in_flight_event_count()); |
1560 } | 1560 } |
1561 | 1561 |
1562 // Test that the router will call the client's |DidFlush| after all events have | 1562 // Test that the router will call the client's |DidFlush| after all events have |
1563 // been dispatched following a call to |Flush|. | 1563 // been dispatched following a call to |Flush|. |
1564 TEST_F(InputRouterImplTest, InputFlush) { | 1564 TEST_F(InputRouterImplTest, InputFlush) { |
1565 EXPECT_FALSE(HasPendingEvents()); | 1565 EXPECT_FALSE(HasPendingEvents()); |
1566 | 1566 |
1567 // Flushing an empty router should immediately trigger DidFlush. | 1567 // Flushing an empty router should immediately trigger DidFlush. |
1568 RequestNotificationWhenFlushed(); | 1568 FlushInput(); |
1569 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1569 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1570 EXPECT_FALSE(HasPendingEvents()); | 1570 EXPECT_FALSE(HasPendingEvents()); |
1571 | 1571 |
1572 // Queue a TouchStart. | 1572 // Queue a TouchStart. |
1573 OnHasTouchEventHandlers(true); | 1573 OnHasTouchEventHandlers(true); |
1574 PressTouchPoint(1, 1); | 1574 PressTouchPoint(1, 1); |
1575 uint32 touch_press_event_id = SendTouchEvent(); | 1575 uint32 touch_press_event_id = SendTouchEvent(); |
1576 EXPECT_TRUE(HasPendingEvents()); | 1576 EXPECT_TRUE(HasPendingEvents()); |
1577 | 1577 |
1578 // DidFlush should be called only after the event is ack'ed. | 1578 // DidFlush should be called only after the event is ack'ed. |
1579 RequestNotificationWhenFlushed(); | 1579 FlushInput(); |
1580 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1580 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1581 SendTouchEventACK(WebInputEvent::TouchStart, | 1581 SendTouchEventACK(WebInputEvent::TouchStart, |
1582 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_press_event_id); | 1582 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_press_event_id); |
1583 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1583 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1584 | 1584 |
1585 // Ensure different types of enqueued events will prevent the DidFlush call | 1585 // Ensure different types of enqueued events will prevent the DidFlush call |
1586 // until all such events have been fully dispatched. | 1586 // until all such events have been fully dispatched. |
1587 MoveTouchPoint(0, 50, 50); | 1587 MoveTouchPoint(0, 50, 50); |
1588 uint32 touch_move_event_id = SendTouchEvent(); | 1588 uint32 touch_move_event_id = SendTouchEvent(); |
1589 ASSERT_TRUE(HasPendingEvents()); | 1589 ASSERT_TRUE(HasPendingEvents()); |
1590 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1590 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1591 blink::WebGestureDeviceTouchscreen); | 1591 blink::WebGestureDeviceTouchscreen); |
1592 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, | 1592 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
1593 blink::WebGestureDeviceTouchscreen); | 1593 blink::WebGestureDeviceTouchscreen); |
1594 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, | 1594 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, |
1595 blink::WebGestureDeviceTouchscreen); | 1595 blink::WebGestureDeviceTouchscreen); |
1596 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1596 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
1597 blink::WebGestureDeviceTouchscreen); | 1597 blink::WebGestureDeviceTouchscreen); |
1598 RequestNotificationWhenFlushed(); | 1598 FlushInput(); |
1599 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1599 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1600 | 1600 |
1601 // Repeated flush calls should have no effect. | 1601 // Repeated flush calls should have no effect. |
1602 RequestNotificationWhenFlushed(); | 1602 FlushInput(); |
1603 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1603 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1604 | 1604 |
1605 // There are still pending gestures. | 1605 // There are still pending gestures. |
1606 SendTouchEventACK(WebInputEvent::TouchMove, | 1606 SendTouchEventACK(WebInputEvent::TouchMove, |
1607 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); | 1607 INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id); |
1608 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1608 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1609 EXPECT_TRUE(HasPendingEvents()); | 1609 EXPECT_TRUE(HasPendingEvents()); |
1610 | 1610 |
1611 // One more gesture to go. | 1611 // One more gesture to go. |
1612 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1612 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
(...skipping 14 matching lines...) Expand all Loading... |
1627 EXPECT_FALSE(HasPendingEvents()); | 1627 EXPECT_FALSE(HasPendingEvents()); |
1628 | 1628 |
1629 // Simulate a fling. | 1629 // Simulate a fling. |
1630 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1630 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1631 blink::WebGestureDeviceTouchscreen); | 1631 blink::WebGestureDeviceTouchscreen); |
1632 SimulateGestureEvent(WebInputEvent::GestureFlingStart, | 1632 SimulateGestureEvent(WebInputEvent::GestureFlingStart, |
1633 blink::WebGestureDeviceTouchscreen); | 1633 blink::WebGestureDeviceTouchscreen); |
1634 EXPECT_TRUE(HasPendingEvents()); | 1634 EXPECT_TRUE(HasPendingEvents()); |
1635 | 1635 |
1636 // If the fling is unconsumed, the flush is complete. | 1636 // If the fling is unconsumed, the flush is complete. |
1637 RequestNotificationWhenFlushed(); | 1637 FlushInput(); |
1638 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1638 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1639 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1639 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1640 blink::WebGestureDeviceTouchscreen); | 1640 blink::WebGestureDeviceTouchscreen); |
1641 SendInputEventACK(WebInputEvent::GestureFlingStart, | 1641 SendInputEventACK(WebInputEvent::GestureFlingStart, |
1642 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1642 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1643 EXPECT_FALSE(HasPendingEvents()); | 1643 EXPECT_FALSE(HasPendingEvents()); |
1644 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1644 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1645 | 1645 |
1646 // Simulate a second fling. | 1646 // Simulate a second fling. |
1647 SimulateGestureEvent(WebInputEvent::GestureFlingStart, | 1647 SimulateGestureEvent(WebInputEvent::GestureFlingStart, |
1648 blink::WebGestureDeviceTouchscreen); | 1648 blink::WebGestureDeviceTouchscreen); |
1649 EXPECT_TRUE(HasPendingEvents()); | 1649 EXPECT_TRUE(HasPendingEvents()); |
1650 | 1650 |
1651 // If the fling is consumed, the flush is complete only when the renderer | 1651 // If the fling is consumed, the flush is complete only when the renderer |
1652 // reports that is has ended. | 1652 // reports that is has ended. |
1653 RequestNotificationWhenFlushed(); | 1653 FlushInput(); |
1654 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1654 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1655 SendInputEventACK(WebInputEvent::GestureFlingStart, | 1655 SendInputEventACK(WebInputEvent::GestureFlingStart, |
1656 INPUT_EVENT_ACK_STATE_CONSUMED); | 1656 INPUT_EVENT_ACK_STATE_CONSUMED); |
1657 EXPECT_TRUE(HasPendingEvents()); | 1657 EXPECT_TRUE(HasPendingEvents()); |
1658 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1658 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1659 | 1659 |
1660 // The fling end notification should signal that the router is flushed. | 1660 // The fling end notification should signal that the router is flushed. |
1661 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); | 1661 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); |
1662 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1662 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1663 | 1663 |
1664 // Even flings consumed by the client require a fling-end notification. | 1664 // Even flings consumed by the client require a fling-end notification. |
1665 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); | 1665 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); |
1666 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | 1666 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
1667 blink::WebGestureDeviceTouchscreen); | 1667 blink::WebGestureDeviceTouchscreen); |
1668 SimulateGestureEvent(WebInputEvent::GestureFlingStart, | 1668 SimulateGestureEvent(WebInputEvent::GestureFlingStart, |
1669 blink::WebGestureDeviceTouchscreen); | 1669 blink::WebGestureDeviceTouchscreen); |
1670 ASSERT_TRUE(HasPendingEvents()); | 1670 ASSERT_TRUE(HasPendingEvents()); |
1671 RequestNotificationWhenFlushed(); | 1671 FlushInput(); |
1672 EXPECT_EQ(0U, GetAndResetDidFlushCount()); | 1672 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
1673 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); | 1673 input_router()->OnMessageReceived(InputHostMsg_DidStopFlinging(0)); |
1674 EXPECT_EQ(1U, GetAndResetDidFlushCount()); | 1674 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
1675 } | 1675 } |
1676 | 1676 |
1677 // Test that GesturePinchUpdate is handled specially for trackpad | 1677 // Test that GesturePinchUpdate is handled specially for trackpad |
1678 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { | 1678 TEST_F(InputRouterImplTest, TouchpadPinchUpdate) { |
1679 // GesturePinchUpdate for trackpad sends synthetic wheel events. | 1679 // GesturePinchUpdate for trackpad sends synthetic wheel events. |
1680 // Note that the Touchscreen case is verified as NOT doing this as | 1680 // Note that the Touchscreen case is verified as NOT doing this as |
1681 // part of the ShowPressIsInOrder test. | 1681 // part of the ShowPressIsInOrder test. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 client_overscroll = client_->GetAndResetOverscroll(); | 1811 client_overscroll = client_->GetAndResetOverscroll(); |
1812 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, | 1812 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, |
1813 client_overscroll.accumulated_overscroll); | 1813 client_overscroll.accumulated_overscroll); |
1814 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, | 1814 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, |
1815 client_overscroll.latest_overscroll_delta); | 1815 client_overscroll.latest_overscroll_delta); |
1816 EXPECT_EQ(wheel_overscroll.current_fling_velocity, | 1816 EXPECT_EQ(wheel_overscroll.current_fling_velocity, |
1817 client_overscroll.current_fling_velocity); | 1817 client_overscroll.current_fling_velocity); |
1818 } | 1818 } |
1819 | 1819 |
1820 } // namespace content | 1820 } // namespace content |
OLD | NEW |