| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" | 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" |
| 9 #include "content/browser/renderer_host/input/immediate_input_router.h" | 9 #include "content/browser/renderer_host/input/immediate_input_router.h" |
| 10 #include "content/browser/renderer_host/input/input_router_client.h" | 10 #include "content/browser/renderer_host/input/input_router_client.h" |
| (...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 EXPECT_EQ(0U, TouchEventQueueSize()); | 1642 EXPECT_EQ(0U, TouchEventQueueSize()); |
| 1643 EXPECT_EQ(WebInputEvent::TouchMove, | 1643 EXPECT_EQ(WebInputEvent::TouchMove, |
| 1644 ack_handler_->acked_touch_event().event.type); | 1644 ack_handler_->acked_touch_event().event.type); |
| 1645 | 1645 |
| 1646 ReleaseTouchPoint(2); | 1646 ReleaseTouchPoint(2); |
| 1647 ReleaseTouchPoint(1); | 1647 ReleaseTouchPoint(1); |
| 1648 EXPECT_EQ(0U, process_->sink().message_count()); | 1648 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1649 EXPECT_EQ(0U, TouchEventQueueSize()); | 1649 EXPECT_EQ(0U, TouchEventQueueSize()); |
| 1650 } | 1650 } |
| 1651 | 1651 |
| 1652 // Tests that touch-event's enqueued via a touch ack are properly handled. |
| 1653 TEST_F(ImmediateInputRouterTest, TouchEventAckWithFollowupEvents) { |
| 1654 // First, install a touch-event handler. |
| 1655 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 1656 ASSERT_EQ(0U, process_->sink().message_count()); |
| 1657 ASSERT_EQ(0U, TouchEventQueueSize()); |
| 1658 ASSERT_TRUE(input_router_->ShouldForwardTouchEvent()); |
| 1659 |
| 1660 // Queue a touch down. |
| 1661 PressTouchPoint(1, 1); |
| 1662 SendTouchEvent(); |
| 1663 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1664 EXPECT_EQ(1U, TouchEventQueueSize()); |
| 1665 process_->sink().ClearMessages(); |
| 1666 |
| 1667 // Create a touch event that will be queued synchronously by a touch ack. |
| 1668 // Note, this will be triggered by all subsequent touch acks. |
| 1669 WebTouchEvent followup_event; |
| 1670 followup_event.type = WebInputEvent::TouchStart; |
| 1671 followup_event.touchesLength = 1; |
| 1672 followup_event.touches[0].id = 1; |
| 1673 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
| 1674 ack_handler_->set_followup_touch_event(make_scoped_ptr( |
| 1675 new TouchEventWithLatencyInfo(followup_event, ui::LatencyInfo()))); |
| 1676 |
| 1677 // Receive an ACK for the press. This should cause the followup touch-move to |
| 1678 // be sent to the renderer. |
| 1679 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1680 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1681 EXPECT_EQ(1U, TouchEventQueueSize()); |
| 1682 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, ack_handler_->ack_state()); |
| 1683 process_->sink().ClearMessages(); |
| 1684 |
| 1685 // Queue another event. |
| 1686 PressTouchPoint(1, 1); |
| 1687 MoveTouchPoint(0, 2, 2); |
| 1688 SendTouchEvent(); |
| 1689 |
| 1690 // Receive an ACK for the touch-move followup event. This should cause the |
| 1691 // subsequent touch move event be sent to the renderer, and another followup |
| 1692 // to be queued. |
| 1693 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1694 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1695 EXPECT_EQ(2U, TouchEventQueueSize()); |
| 1696 process_->sink().ClearMessages(); |
| 1697 } |
| 1698 |
| 1699 // Tests that followup events triggered by an immediae ack from |
| 1700 // TouchEventQueue::QueueEvent() are properly handled. |
| 1701 TEST_F(ImmediateInputRouterTest, TouchEventImmediateAckWithFollowupEvents) { |
| 1702 // First, install a touch-event handler. |
| 1703 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 1704 ASSERT_EQ(0U, process_->sink().message_count()); |
| 1705 ASSERT_EQ(0U, TouchEventQueueSize()); |
| 1706 ASSERT_TRUE(input_router_->ShouldForwardTouchEvent()); |
| 1707 |
| 1708 // Create a touch event that will be queued synchronously by a touch ack. |
| 1709 // Note, this will be triggered by all subsequent touch acks. |
| 1710 WebTouchEvent followup_event; |
| 1711 followup_event.type = WebInputEvent::TouchStart; |
| 1712 followup_event.touchesLength = 1; |
| 1713 followup_event.touches[0].id = 1; |
| 1714 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
| 1715 ack_handler_->set_followup_touch_event(make_scoped_ptr( |
| 1716 new TouchEventWithLatencyInfo(followup_event, ui::LatencyInfo()))); |
| 1717 |
| 1718 // Now, enqueue a stationary touch that will not be forwarded. This should be |
| 1719 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should |
| 1720 // then be enqueued and immediately sent to the renderer. |
| 1721 WebTouchEvent stationary_event; |
| 1722 stationary_event.touchesLength = 1; |
| 1723 stationary_event.type = WebInputEvent::TouchMove; |
| 1724 stationary_event.touches[0].id = 1; |
| 1725 stationary_event.touches[0].state = WebTouchPoint::StateStationary; |
| 1726 input_router_->SendTouchEvent( |
| 1727 TouchEventWithLatencyInfo(stationary_event, ui::LatencyInfo())); |
| 1728 |
| 1729 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1730 EXPECT_EQ(1U, TouchEventQueueSize()); |
| 1731 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 1732 ack_handler_->ack_state()); |
| 1733 EXPECT_EQ(WebInputEvent::TouchMove, |
| 1734 ack_handler_->acked_touch_event().event.type); |
| 1735 } |
| 1736 |
| 1652 #if defined(OS_WIN) || defined(USE_AURA) | 1737 #if defined(OS_WIN) || defined(USE_AURA) |
| 1653 // Tests that the acked events have correct state. (ui::Events are used only on | 1738 // Tests that the acked events have correct state. (ui::Events are used only on |
| 1654 // windows and aura) | 1739 // windows and aura) |
| 1655 TEST_F(ImmediateInputRouterTest, AckedTouchEventState) { | 1740 TEST_F(ImmediateInputRouterTest, AckedTouchEventState) { |
| 1656 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 1741 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
| 1657 EXPECT_EQ(0U, process_->sink().message_count()); | 1742 EXPECT_EQ(0U, process_->sink().message_count()); |
| 1658 EXPECT_EQ(0U, TouchEventQueueSize()); | 1743 EXPECT_EQ(0U, TouchEventQueueSize()); |
| 1659 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); | 1744 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); |
| 1660 | 1745 |
| 1661 // Send a bunch of events, and make sure the ACKed events are correct. | 1746 // Send a bunch of events, and make sure the ACKed events are correct. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1934 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1850 | 1935 |
| 1851 ReleaseTouchPoint(0); | 1936 ReleaseTouchPoint(0); |
| 1852 SendTouchEvent(); | 1937 SendTouchEvent(); |
| 1853 EXPECT_EQ(1U, process_->sink().message_count()); | 1938 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1854 process_->sink().ClearMessages(); | 1939 process_->sink().ClearMessages(); |
| 1855 SendInputEventACK(WebInputEvent::TouchEnd, | 1940 SendInputEventACK(WebInputEvent::TouchEnd, |
| 1856 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1941 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1857 } | 1942 } |
| 1858 } // namespace content | 1943 } // namespace content |
| OLD | NEW |