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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "content/browser/renderer_host/input/synthetic_web_input_event_builders
.h" | 8 #include "content/browser/renderer_host/input/synthetic_web_input_event_builders
.h" |
9 #include "content/browser/renderer_host/input/touch_event_queue.h" | 9 #include "content/browser/renderer_host/input/touch_event_queue.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 virtual void TearDown() OVERRIDE { | 35 virtual void TearDown() OVERRIDE { |
36 queue_.reset(); | 36 queue_.reset(); |
37 } | 37 } |
38 | 38 |
39 // TouchEventQueueClient | 39 // TouchEventQueueClient |
40 virtual void SendTouchEventImmediately( | 40 virtual void SendTouchEventImmediately( |
41 const TouchEventWithLatencyInfo& event) OVERRIDE { | 41 const TouchEventWithLatencyInfo& event) OVERRIDE { |
42 ++sent_event_count_; | 42 ++sent_event_count_; |
43 last_sent_event_ = event.event; | 43 last_sent_event_ = event.event; |
| 44 if (sync_ack_result_) |
| 45 SendTouchEventACK(*sync_ack_result_.Pass()); |
44 } | 46 } |
45 | 47 |
46 virtual void OnTouchEventAck( | 48 virtual void OnTouchEventAck( |
47 const TouchEventWithLatencyInfo& event, | 49 const TouchEventWithLatencyInfo& event, |
48 InputEventAckState ack_result) OVERRIDE { | 50 InputEventAckState ack_result) OVERRIDE { |
49 ++acked_event_count_; | 51 ++acked_event_count_; |
50 last_acked_event_ = event.event; | 52 last_acked_event_ = event.event; |
51 last_acked_event_state_ = ack_result; | 53 last_acked_event_state_ = ack_result; |
52 if (followup_touch_event_) { | 54 if (followup_touch_event_) { |
53 scoped_ptr<WebTouchEvent> followup_touch_event = | 55 scoped_ptr<WebTouchEvent> followup_touch_event = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 88 } |
87 | 89 |
88 void SetFollowupEvent(const WebTouchEvent& event) { | 90 void SetFollowupEvent(const WebTouchEvent& event) { |
89 followup_touch_event_.reset(new WebTouchEvent(event)); | 91 followup_touch_event_.reset(new WebTouchEvent(event)); |
90 } | 92 } |
91 | 93 |
92 void SetFollowupEvent(const WebGestureEvent& event) { | 94 void SetFollowupEvent(const WebGestureEvent& event) { |
93 followup_gesture_event_.reset(new WebGestureEvent(event)); | 95 followup_gesture_event_.reset(new WebGestureEvent(event)); |
94 } | 96 } |
95 | 97 |
| 98 void SetSyncAckResult(InputEventAckState sync_ack_result) { |
| 99 sync_ack_result_.reset(new InputEventAckState(sync_ack_result)); |
| 100 } |
| 101 |
96 int PressTouchPoint(int x, int y) { | 102 int PressTouchPoint(int x, int y) { |
97 return touch_event_.PressPoint(x, y); | 103 return touch_event_.PressPoint(x, y); |
98 } | 104 } |
99 | 105 |
100 void MoveTouchPoint(int index, int x, int y) { | 106 void MoveTouchPoint(int index, int x, int y) { |
101 touch_event_.MovePoint(index, x, y); | 107 touch_event_.MovePoint(index, x, y); |
102 } | 108 } |
103 | 109 |
104 void ReleaseTouchPoint(int index) { | 110 void ReleaseTouchPoint(int index) { |
105 touch_event_.ReleasePoint(index); | 111 touch_event_.ReleasePoint(index); |
106 } | 112 } |
107 | 113 |
| 114 void CancelTouchPoint(int index) { |
| 115 touch_event_.CancelPoint(index); |
| 116 } |
| 117 |
108 size_t GetAndResetAckedEventCount() { | 118 size_t GetAndResetAckedEventCount() { |
109 size_t count = acked_event_count_; | 119 size_t count = acked_event_count_; |
110 acked_event_count_ = 0; | 120 acked_event_count_ = 0; |
111 return count; | 121 return count; |
112 } | 122 } |
113 | 123 |
114 size_t GetAndResetSentEventCount() { | 124 size_t GetAndResetSentEventCount() { |
115 size_t count = sent_event_count_; | 125 size_t count = sent_event_count_; |
116 sent_event_count_ = 0; | 126 sent_event_count_ = 0; |
117 return count; | 127 return count; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 private: | 162 private: |
153 scoped_ptr<TouchEventQueue> queue_; | 163 scoped_ptr<TouchEventQueue> queue_; |
154 size_t sent_event_count_; | 164 size_t sent_event_count_; |
155 size_t acked_event_count_; | 165 size_t acked_event_count_; |
156 WebTouchEvent last_sent_event_; | 166 WebTouchEvent last_sent_event_; |
157 WebTouchEvent last_acked_event_; | 167 WebTouchEvent last_acked_event_; |
158 InputEventAckState last_acked_event_state_; | 168 InputEventAckState last_acked_event_state_; |
159 SyntheticWebTouchEvent touch_event_; | 169 SyntheticWebTouchEvent touch_event_; |
160 scoped_ptr<WebTouchEvent> followup_touch_event_; | 170 scoped_ptr<WebTouchEvent> followup_touch_event_; |
161 scoped_ptr<WebGestureEvent> followup_gesture_event_; | 171 scoped_ptr<WebGestureEvent> followup_gesture_event_; |
| 172 scoped_ptr<InputEventAckState> sync_ack_result_; |
162 }; | 173 }; |
163 | 174 |
164 | 175 |
165 // Tests that touch-events are queued properly. | 176 // Tests that touch-events are queued properly. |
166 TEST_F(TouchEventQueueTest, Basic) { | 177 TEST_F(TouchEventQueueTest, Basic) { |
167 PressTouchPoint(1, 1); | 178 PressTouchPoint(1, 1); |
168 SendTouchEvent(); | 179 SendTouchEvent(); |
169 EXPECT_EQ(1U, queued_event_count()); | 180 EXPECT_EQ(1U, queued_event_count()); |
170 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 181 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
171 | 182 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 EXPECT_EQ(2U, queued_event_count()); | 624 EXPECT_EQ(2U, queued_event_count()); |
614 | 625 |
615 // Receive an ACK for the touch-move followup event. This should cause the | 626 // Receive an ACK for the touch-move followup event. This should cause the |
616 // subsequent touch move event be sent to the renderer. | 627 // subsequent touch move event be sent to the renderer. |
617 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 628 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
618 EXPECT_EQ(1U, queued_event_count()); | 629 EXPECT_EQ(1U, queued_event_count()); |
619 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 630 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
620 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 631 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
621 } | 632 } |
622 | 633 |
| 634 // Tests that touch-events can be synchronously ack'ed. |
| 635 TEST_F(TouchEventQueueTest, SynchronousAcks) { |
| 636 // TouchStart |
| 637 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 638 PressTouchPoint(1, 1); |
| 639 SendTouchEvent(); |
| 640 EXPECT_EQ(0U, queued_event_count()); |
| 641 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 642 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 643 |
| 644 // TouchMove |
| 645 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 646 PressTouchPoint(1, 1); |
| 647 MoveTouchPoint(0, 2, 2); |
| 648 SendTouchEvent(); |
| 649 EXPECT_EQ(0U, queued_event_count()); |
| 650 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 651 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 652 |
| 653 // TouchEnd |
| 654 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 655 PressTouchPoint(1, 1); |
| 656 ReleaseTouchPoint(0); |
| 657 SendTouchEvent(); |
| 658 EXPECT_EQ(0U, queued_event_count()); |
| 659 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 660 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 661 |
| 662 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent) |
| 663 PressTouchPoint(1, 1); |
| 664 SendTouchEvent(); |
| 665 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 666 EXPECT_EQ(0U, queued_event_count()); |
| 667 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 668 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 669 |
| 670 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 671 PressTouchPoint(1, 1); |
| 672 CancelTouchPoint(0); |
| 673 SendTouchEvent(); |
| 674 EXPECT_EQ(0U, queued_event_count()); |
| 675 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 676 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 677 } |
| 678 |
623 // Tests that followup events triggered by an immediate ack from | 679 // Tests that followup events triggered by an immediate ack from |
624 // TouchEventQueue::QueueEvent() are properly handled. | 680 // TouchEventQueue::QueueEvent() are properly handled. |
625 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { | 681 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { |
626 // Create a touch event that will be queued synchronously by a touch ack. | 682 // Create a touch event that will be queued synchronously by a touch ack. |
627 WebTouchEvent followup_event; | 683 WebTouchEvent followup_event; |
628 followup_event.type = WebInputEvent::TouchStart; | 684 followup_event.type = WebInputEvent::TouchStart; |
629 followup_event.touchesLength = 1; | 685 followup_event.touchesLength = 1; |
630 followup_event.touches[0].id = 1; | 686 followup_event.touches[0].id = 1; |
631 followup_event.touches[0].state = WebTouchPoint::StatePressed; | 687 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
632 SetFollowupEvent(followup_event); | 688 SetFollowupEvent(followup_event); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 830 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
775 | 831 |
776 ReleaseTouchPoint(0); | 832 ReleaseTouchPoint(0); |
777 SendTouchEvent(); | 833 SendTouchEvent(); |
778 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 834 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
779 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 835 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
780 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 836 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
781 } | 837 } |
782 | 838 |
783 } // namespace content | 839 } // namespace content |
OLD | NEW |