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 "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/browser/renderer_host/input/timeout_monitor.h" | 9 #include "content/browser/renderer_host/input/timeout_monitor.h" |
10 #include "content/browser/renderer_host/input/touch_event_queue.h" | 10 #include "content/browser/renderer_host/input/touch_event_queue.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 : sent_event_count_(0), | 34 : sent_event_count_(0), |
35 acked_event_count_(0), | 35 acked_event_count_(0), |
36 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), | 36 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), |
37 slop_length_dips_(0), | 37 slop_length_dips_(0), |
38 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {} | 38 touch_scrolling_mode_(TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT) {} |
39 | 39 |
40 virtual ~TouchEventQueueTest() {} | 40 virtual ~TouchEventQueueTest() {} |
41 | 41 |
42 // testing::Test | 42 // testing::Test |
43 virtual void SetUp() OVERRIDE { | 43 virtual void SetUp() OVERRIDE { |
44 ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_); | 44 ResetQueueWithConfig(CreateConfig()); |
45 } | |
46 | |
47 virtual void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) { | |
48 touch_scrolling_mode_ = mode; | |
49 ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_); | |
50 } | 45 } |
51 | 46 |
52 virtual void TearDown() OVERRIDE { | 47 virtual void TearDown() OVERRIDE { |
53 queue_.reset(); | 48 queue_.reset(); |
54 } | 49 } |
55 | 50 |
56 // TouchEventQueueClient | 51 // TouchEventQueueClient |
57 virtual void SendTouchEventImmediately( | 52 virtual void SendTouchEventImmediately( |
58 const TouchEventWithLatencyInfo& event) OVERRIDE { | 53 const TouchEventWithLatencyInfo& event) OVERRIDE { |
59 ++sent_event_count_; | 54 ++sent_event_count_; |
(...skipping 17 matching lines...) Expand all Loading... |
77 scoped_ptr<WebGestureEvent> followup_gesture_event = | 72 scoped_ptr<WebGestureEvent> followup_gesture_event = |
78 followup_gesture_event_.Pass(); | 73 followup_gesture_event_.Pass(); |
79 queue_->OnGestureScrollEvent( | 74 queue_->OnGestureScrollEvent( |
80 GestureEventWithLatencyInfo(*followup_gesture_event, | 75 GestureEventWithLatencyInfo(*followup_gesture_event, |
81 ui::LatencyInfo())); | 76 ui::LatencyInfo())); |
82 } | 77 } |
83 } | 78 } |
84 | 79 |
85 protected: | 80 protected: |
86 | 81 |
87 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) { | 82 TouchEventQueue::Config CreateConfig() { |
88 queue_->SetAckTimeoutEnabled(true, timeout_delay); | 83 TouchEventQueue::Config config; |
| 84 config.touch_scrolling_mode = touch_scrolling_mode_; |
| 85 config.touchmove_slop_suppression_length_dips = slop_length_dips_; |
| 86 return config; |
| 87 } |
| 88 |
| 89 void SetTouchScrollingMode(TouchEventQueue::TouchScrollingMode mode) { |
| 90 touch_scrolling_mode_ = mode; |
| 91 ResetQueueWithConfig(CreateConfig()); |
89 } | 92 } |
90 | 93 |
91 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { | 94 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { |
92 slop_length_dips_ = slop_length_dips; | 95 slop_length_dips_ = slop_length_dips; |
93 ResetQueueWithParameters(touch_scrolling_mode_, slop_length_dips_); | 96 ResetQueueWithConfig(CreateConfig()); |
| 97 } |
| 98 |
| 99 void SetUpForTimeoutTesting(base::TimeDelta timeout_delay) { |
| 100 TouchEventQueue::Config config = CreateConfig(); |
| 101 config.touch_ack_timeout_delay = timeout_delay; |
| 102 config.touch_ack_timeout_supported = true; |
| 103 ResetQueueWithConfig(config); |
94 } | 104 } |
95 | 105 |
96 void SendTouchEvent(const WebTouchEvent& event) { | 106 void SendTouchEvent(const WebTouchEvent& event) { |
97 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); | 107 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); |
98 } | 108 } |
99 | 109 |
100 void SendGestureEvent(WebInputEvent::Type type) { | 110 void SendGestureEvent(WebInputEvent::Type type) { |
101 WebGestureEvent event; | 111 WebGestureEvent event; |
102 event.type = type; | 112 event.type = type; |
103 queue_->OnGestureScrollEvent( | 113 queue_->OnGestureScrollEvent( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 186 } |
177 | 187 |
178 bool IsPendingAckTouchStart() const { | 188 bool IsPendingAckTouchStart() const { |
179 return queue_->IsPendingAckTouchStart(); | 189 return queue_->IsPendingAckTouchStart(); |
180 } | 190 } |
181 | 191 |
182 void OnHasTouchEventHandlers(bool has_handlers) { | 192 void OnHasTouchEventHandlers(bool has_handlers) { |
183 queue_->OnHasTouchEventHandlers(has_handlers); | 193 queue_->OnHasTouchEventHandlers(has_handlers); |
184 } | 194 } |
185 | 195 |
186 void SetAckTimeoutDisabled() { | 196 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } |
187 queue_->SetAckTimeoutEnabled(false, base::TimeDelta()); | |
188 } | |
189 | 197 |
190 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); } | 198 bool IsTimeoutEnabled() const { return queue_->ack_timeout_enabled(); } |
191 | 199 |
192 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } | 200 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } |
193 | 201 |
194 bool HasPendingAsyncTouchMove() const { | 202 bool HasPendingAsyncTouchMove() const { |
195 return queue_->HasPendingAsyncTouchMoveForTesting(); | 203 return queue_->HasPendingAsyncTouchMoveForTesting(); |
196 } | 204 } |
197 | 205 |
198 size_t queued_event_count() const { | 206 size_t queued_event_count() const { |
(...skipping 21 matching lines...) Expand all Loading... |
220 FROM_HERE, base::MessageLoop::QuitClosure(), delay); | 228 FROM_HERE, base::MessageLoop::QuitClosure(), delay); |
221 base::MessageLoop::current()->Run(); | 229 base::MessageLoop::current()->Run(); |
222 } | 230 } |
223 | 231 |
224 private: | 232 private: |
225 void SendTouchEvent() { | 233 void SendTouchEvent() { |
226 SendTouchEvent(touch_event_); | 234 SendTouchEvent(touch_event_); |
227 touch_event_.ResetPoints(); | 235 touch_event_.ResetPoints(); |
228 } | 236 } |
229 | 237 |
230 void ResetQueueWithParameters(TouchEventQueue::TouchScrollingMode mode, | 238 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { |
231 double slop_length_dips) { | 239 queue_.reset(new TouchEventQueue(this, config)); |
232 queue_.reset(new TouchEventQueue(this, mode, slop_length_dips)); | |
233 queue_->OnHasTouchEventHandlers(true); | 240 queue_->OnHasTouchEventHandlers(true); |
234 } | 241 } |
235 | 242 |
236 scoped_ptr<TouchEventQueue> queue_; | 243 scoped_ptr<TouchEventQueue> queue_; |
237 size_t sent_event_count_; | 244 size_t sent_event_count_; |
238 size_t acked_event_count_; | 245 size_t acked_event_count_; |
239 WebTouchEvent last_sent_event_; | 246 WebTouchEvent last_sent_event_; |
240 WebTouchEvent last_acked_event_; | 247 WebTouchEvent last_acked_event_; |
241 InputEventAckState last_acked_event_state_; | 248 InputEventAckState last_acked_event_state_; |
242 SyntheticWebTouchEvent touch_event_; | 249 SyntheticWebTouchEvent touch_event_; |
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 1946 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
1940 | 1947 |
1941 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1948 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1942 EXPECT_EQ(0U, queued_event_count()); | 1949 EXPECT_EQ(0U, queued_event_count()); |
1943 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); | 1950 EXPECT_EQ(WebInputEvent::TouchCancel, acked_event().type); |
1944 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 1951 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
1945 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 1952 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
1946 } | 1953 } |
1947 | 1954 |
1948 } // namespace content | 1955 } // namespace content |
OLD | NEW |