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