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" |
| 9 #include "content/browser/renderer_host/input/timeout_monitor.h" |
8 #include "content/browser/renderer_host/input/touch_event_queue.h" | 10 #include "content/browser/renderer_host/input/touch_event_queue.h" |
9 #include "content/common/input/synthetic_web_input_event_builders.h" | 11 #include "content/common/input/synthetic_web_input_event_builders.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/public/web/WebInputEvent.h" | 13 #include "third_party/WebKit/public/web/WebInputEvent.h" |
12 | 14 |
13 using blink::WebGestureEvent; | 15 using blink::WebGestureEvent; |
14 using blink::WebInputEvent; | 16 using blink::WebInputEvent; |
15 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
16 using blink::WebTouchPoint; | 18 using blink::WebTouchPoint; |
17 | 19 |
18 namespace content { | 20 namespace content { |
| 21 namespace { |
| 22 const size_t kDefaultTouchTimeoutDelayMs = 10; |
| 23 } |
19 | 24 |
20 class TouchEventQueueTest : public testing::Test, | 25 class TouchEventQueueTest : public testing::Test, |
21 public TouchEventQueueClient { | 26 public TouchEventQueueClient { |
22 public: | 27 public: |
23 TouchEventQueueTest() | 28 TouchEventQueueTest() |
24 : sent_event_count_(0), | 29 : sent_event_count_(0), |
25 acked_event_count_(0), | 30 acked_event_count_(0), |
26 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {} | 31 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {} |
27 | 32 |
28 virtual ~TouchEventQueueTest() {} | 33 virtual ~TouchEventQueueTest() {} |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 scoped_ptr<WebGestureEvent> followup_gesture_event = | 65 scoped_ptr<WebGestureEvent> followup_gesture_event = |
61 followup_gesture_event_.Pass(); | 66 followup_gesture_event_.Pass(); |
62 queue_->OnGestureScrollEvent( | 67 queue_->OnGestureScrollEvent( |
63 GestureEventWithLatencyInfo(*followup_gesture_event, | 68 GestureEventWithLatencyInfo(*followup_gesture_event, |
64 ui::LatencyInfo())); | 69 ui::LatencyInfo())); |
65 } | 70 } |
66 } | 71 } |
67 | 72 |
68 protected: | 73 protected: |
69 | 74 |
| 75 void SetUpForTimeoutTesting(size_t timeout_delay_ms) { |
| 76 queue_->SetAckTimeoutEnabled(true, timeout_delay_ms); |
| 77 } |
| 78 |
70 void SendTouchEvent(const WebTouchEvent& event) { | 79 void SendTouchEvent(const WebTouchEvent& event) { |
71 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); | 80 queue_->QueueEvent(TouchEventWithLatencyInfo(event, ui::LatencyInfo())); |
72 } | 81 } |
73 | 82 |
74 void SendTouchEvent() { | |
75 SendTouchEvent(touch_event_); | |
76 touch_event_.ResetPoints(); | |
77 } | |
78 | |
79 void SendGestureEvent(WebInputEvent::Type type) { | 83 void SendGestureEvent(WebInputEvent::Type type) { |
80 WebGestureEvent event; | 84 WebGestureEvent event; |
81 event.type = type; | 85 event.type = type; |
82 queue_->OnGestureScrollEvent( | 86 queue_->OnGestureScrollEvent( |
83 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); | 87 GestureEventWithLatencyInfo(event, ui::LatencyInfo())); |
84 } | 88 } |
85 | 89 |
86 void SendTouchEventACK(InputEventAckState ack_result) { | 90 void SendTouchEventACK(InputEventAckState ack_result) { |
87 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo()); | 91 queue_->ProcessTouchAck(ack_result, ui::LatencyInfo()); |
88 } | 92 } |
89 | 93 |
90 void SetFollowupEvent(const WebTouchEvent& event) { | 94 void SetFollowupEvent(const WebTouchEvent& event) { |
91 followup_touch_event_.reset(new WebTouchEvent(event)); | 95 followup_touch_event_.reset(new WebTouchEvent(event)); |
92 } | 96 } |
93 | 97 |
94 void SetFollowupEvent(const WebGestureEvent& event) { | 98 void SetFollowupEvent(const WebGestureEvent& event) { |
95 followup_gesture_event_.reset(new WebGestureEvent(event)); | 99 followup_gesture_event_.reset(new WebGestureEvent(event)); |
96 } | 100 } |
97 | 101 |
98 void SetSyncAckResult(InputEventAckState sync_ack_result) { | 102 void SetSyncAckResult(InputEventAckState sync_ack_result) { |
99 sync_ack_result_.reset(new InputEventAckState(sync_ack_result)); | 103 sync_ack_result_.reset(new InputEventAckState(sync_ack_result)); |
100 } | 104 } |
101 | 105 |
102 int PressTouchPoint(int x, int y) { | 106 void PressTouchPoint(int x, int y) { |
103 return touch_event_.PressPoint(x, y); | 107 touch_event_.PressPoint(x, y); |
| 108 SendTouchEvent(); |
104 } | 109 } |
105 | 110 |
106 void MoveTouchPoint(int index, int x, int y) { | 111 void MoveTouchPoint(int index, int x, int y) { |
107 touch_event_.MovePoint(index, x, y); | 112 touch_event_.MovePoint(index, x, y); |
| 113 SendTouchEvent(); |
| 114 } |
| 115 |
| 116 void MoveTouchPoints(int index0, int x0, int y0, int index1, int x1, int y1) { |
| 117 touch_event_.MovePoint(index0, x0, y0); |
| 118 touch_event_.MovePoint(index1, x1, y1); |
| 119 SendTouchEvent(); |
108 } | 120 } |
109 | 121 |
110 void ReleaseTouchPoint(int index) { | 122 void ReleaseTouchPoint(int index) { |
111 touch_event_.ReleasePoint(index); | 123 touch_event_.ReleasePoint(index); |
| 124 SendTouchEvent(); |
112 } | 125 } |
113 | 126 |
114 void CancelTouchPoint(int index) { | 127 void CancelTouchPoint(int index) { |
115 touch_event_.CancelPoint(index); | 128 touch_event_.CancelPoint(index); |
| 129 SendTouchEvent(); |
116 } | 130 } |
117 | 131 |
118 size_t GetAndResetAckedEventCount() { | 132 size_t GetAndResetAckedEventCount() { |
119 size_t count = acked_event_count_; | 133 size_t count = acked_event_count_; |
120 acked_event_count_ = 0; | 134 acked_event_count_ = 0; |
121 return count; | 135 return count; |
122 } | 136 } |
123 | 137 |
124 size_t GetAndResetSentEventCount() { | 138 size_t GetAndResetSentEventCount() { |
125 size_t count = sent_event_count_; | 139 size_t count = sent_event_count_; |
126 sent_event_count_ = 0; | 140 sent_event_count_ = 0; |
127 return count; | 141 return count; |
128 } | 142 } |
129 | 143 |
130 bool IsPendingAckTouchStart() const { | 144 bool IsPendingAckTouchStart() const { |
131 return queue_->IsPendingAckTouchStart(); | 145 return queue_->IsPendingAckTouchStart(); |
132 } | 146 } |
133 | 147 |
134 void Flush() { | 148 void Flush() { |
135 queue_->FlushQueue(); | 149 queue_->FlushQueue(); |
136 } | 150 } |
137 | 151 |
| 152 void SetEnableTouchForwarding(bool enabled) { |
| 153 queue_->no_touch_to_renderer_ = !enabled; |
| 154 } |
| 155 |
| 156 bool WillForwardTouchEvents() { |
| 157 return !queue_->no_touch_to_renderer_ && !queue_->HasTimeoutEvent(); |
| 158 } |
| 159 |
| 160 bool IsTimeoutRunning() { |
| 161 return queue_->IsTimeoutRunningForTesting(); |
| 162 } |
| 163 |
138 size_t queued_event_count() const { | 164 size_t queued_event_count() const { |
139 return queue_->GetQueueSize(); | 165 return queue_->size(); |
140 } | 166 } |
141 | 167 |
142 const WebTouchEvent& latest_event() const { | 168 const WebTouchEvent& latest_event() const { |
143 return queue_->GetLatestEvent().event; | 169 return queue_->GetLatestEventForTesting().event; |
144 } | 170 } |
145 | 171 |
146 const WebTouchEvent& acked_event() const { | 172 const WebTouchEvent& acked_event() const { |
147 return last_acked_event_; | 173 return last_acked_event_; |
148 } | 174 } |
149 | 175 |
150 const WebTouchEvent& sent_event() const { | 176 const WebTouchEvent& sent_event() const { |
151 return last_sent_event_; | 177 return last_sent_event_; |
152 } | 178 } |
153 | 179 |
154 InputEventAckState acked_event_state() const { | 180 InputEventAckState acked_event_state() const { |
155 return last_acked_event_state_; | 181 return last_acked_event_state_; |
156 } | 182 } |
157 | 183 |
158 void set_no_touch_to_renderer(bool no_touch) { | 184 void set_no_touch_to_renderer(bool no_touch) { |
159 queue_->no_touch_to_renderer_ = no_touch; | 185 queue_->no_touch_to_renderer_ = no_touch; |
160 } | 186 } |
161 | 187 |
162 bool no_touch_to_renderer() const { | 188 bool no_touch_to_renderer() const { |
163 return queue_->no_touch_to_renderer_; | 189 return queue_->no_touch_to_renderer_; |
164 } | 190 } |
165 | 191 |
166 private: | 192 private: |
| 193 void SendTouchEvent() { |
| 194 SendTouchEvent(touch_event_); |
| 195 touch_event_.ResetPoints(); |
| 196 } |
| 197 |
167 scoped_ptr<TouchEventQueue> queue_; | 198 scoped_ptr<TouchEventQueue> queue_; |
168 size_t sent_event_count_; | 199 size_t sent_event_count_; |
169 size_t acked_event_count_; | 200 size_t acked_event_count_; |
170 WebTouchEvent last_sent_event_; | 201 WebTouchEvent last_sent_event_; |
171 WebTouchEvent last_acked_event_; | 202 WebTouchEvent last_acked_event_; |
172 InputEventAckState last_acked_event_state_; | 203 InputEventAckState last_acked_event_state_; |
173 SyntheticWebTouchEvent touch_event_; | 204 SyntheticWebTouchEvent touch_event_; |
174 scoped_ptr<WebTouchEvent> followup_touch_event_; | 205 scoped_ptr<WebTouchEvent> followup_touch_event_; |
175 scoped_ptr<WebGestureEvent> followup_gesture_event_; | 206 scoped_ptr<WebGestureEvent> followup_gesture_event_; |
176 scoped_ptr<InputEventAckState> sync_ack_result_; | 207 scoped_ptr<InputEventAckState> sync_ack_result_; |
| 208 base::MessageLoopForUI message_loop_; |
177 }; | 209 }; |
178 | 210 |
179 | 211 |
180 // Tests that touch-events are queued properly. | 212 // Tests that touch-events are queued properly. |
181 TEST_F(TouchEventQueueTest, Basic) { | 213 TEST_F(TouchEventQueueTest, Basic) { |
182 PressTouchPoint(1, 1); | 214 PressTouchPoint(1, 1); |
183 SendTouchEvent(); | |
184 EXPECT_EQ(1U, queued_event_count()); | 215 EXPECT_EQ(1U, queued_event_count()); |
185 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 216 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
186 | 217 |
187 // The second touch should not be sent since one is already in queue. | 218 // The second touch should not be sent since one is already in queue. |
188 MoveTouchPoint(0, 5, 5); | 219 MoveTouchPoint(0, 5, 5); |
189 SendTouchEvent(); | |
190 EXPECT_EQ(2U, queued_event_count()); | 220 EXPECT_EQ(2U, queued_event_count()); |
191 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 221 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
192 | 222 |
193 // Receive an ACK for the first touch-event. | 223 // Receive an ACK for the first touch-event. |
194 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 224 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
195 EXPECT_EQ(1U, queued_event_count()); | 225 EXPECT_EQ(1U, queued_event_count()); |
196 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 226 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
197 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 227 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
198 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 228 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
199 | 229 |
200 // Receive an ACK for the second touch-event. | 230 // Receive an ACK for the second touch-event. |
201 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 231 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
202 EXPECT_EQ(0U, queued_event_count()); | 232 EXPECT_EQ(0U, queued_event_count()); |
203 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 233 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
204 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 234 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
205 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 235 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
206 } | 236 } |
207 | 237 |
208 // Tests that the touch-queue is emptied if a page stops listening for touch | 238 // Tests that the touch-queue is emptied if a page stops listening for touch |
209 // events. | 239 // events. |
210 TEST_F(TouchEventQueueTest, Flush) { | 240 TEST_F(TouchEventQueueTest, Flush) { |
211 Flush(); | 241 Flush(); |
212 EXPECT_EQ(0U, queued_event_count()); | 242 EXPECT_EQ(0U, queued_event_count()); |
213 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 243 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
214 | 244 |
215 // Send a touch-press event. | 245 // Send a touch-press event. |
216 PressTouchPoint(1, 1); | 246 PressTouchPoint(1, 1); |
217 SendTouchEvent(); | |
218 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 247 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
219 | 248 |
220 ReleaseTouchPoint(0); | 249 ReleaseTouchPoint(0); |
221 SendTouchEvent(); | |
222 | 250 |
223 // Events will be queued until the first sent event is ack'ed. | 251 // Events will be queued until the first sent event is ack'ed. |
224 for (int i = 5; i < 15; ++i) { | 252 for (int i = 5; i < 15; ++i) { |
225 PressTouchPoint(1, 1); | 253 PressTouchPoint(1, 1); |
226 SendTouchEvent(); | |
227 MoveTouchPoint(0, i, i); | 254 MoveTouchPoint(0, i, i); |
228 SendTouchEvent(); | |
229 ReleaseTouchPoint(0); | 255 ReleaseTouchPoint(0); |
230 SendTouchEvent(); | |
231 } | 256 } |
232 EXPECT_EQ(32U, queued_event_count()); | 257 EXPECT_EQ(32U, queued_event_count()); |
233 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 258 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
234 | 259 |
235 // Receive an ACK for the first touch-event. One of the queued touch-event | 260 // Receive an ACK for the first touch-event. One of the queued touch-event |
236 // should be forwarded. | 261 // should be forwarded. |
237 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 262 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
238 EXPECT_EQ(31U, queued_event_count()); | 263 EXPECT_EQ(31U, queued_event_count()); |
239 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 264 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
240 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 265 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
241 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 266 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
242 | 267 |
243 // Flush the queue. The touch-event queue should now be emptied, but none of | 268 // Flush the queue. The touch-event queue should now be emptied, but none of |
244 // the queued touch-events should be sent to the renderer. | 269 // the queued touch-events should be sent to the renderer. |
245 Flush(); | 270 Flush(); |
246 EXPECT_EQ(0U, queued_event_count()); | 271 EXPECT_EQ(0U, queued_event_count()); |
247 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 272 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
248 EXPECT_EQ(31U, GetAndResetAckedEventCount()); | 273 EXPECT_EQ(31U, GetAndResetAckedEventCount()); |
249 } | 274 } |
250 | 275 |
251 // Tests that touch-events are coalesced properly in the queue. | 276 // Tests that touch-events are coalesced properly in the queue. |
252 TEST_F(TouchEventQueueTest, Coalesce) { | 277 TEST_F(TouchEventQueueTest, Coalesce) { |
253 // Send a touch-press event. | 278 // Send a touch-press event. |
254 PressTouchPoint(1, 1); | 279 PressTouchPoint(1, 1); |
255 SendTouchEvent(); | |
256 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 280 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
257 | 281 |
258 // Send a few touch-move events, followed by a touch-release event. All the | 282 // Send a few touch-move events, followed by a touch-release event. All the |
259 // touch-move events should be coalesced into a single event. | 283 // touch-move events should be coalesced into a single event. |
260 for (int i = 5; i < 15; ++i) { | 284 for (int i = 5; i < 15; ++i) |
261 MoveTouchPoint(0, i, i); | 285 MoveTouchPoint(0, i, i); |
262 SendTouchEvent(); | 286 |
263 } | |
264 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 287 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
265 ReleaseTouchPoint(0); | 288 ReleaseTouchPoint(0); |
266 SendTouchEvent(); | |
267 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 289 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
268 EXPECT_EQ(3U, queued_event_count()); | 290 EXPECT_EQ(3U, queued_event_count()); |
269 | 291 |
270 // ACK the press. Coalesced touch-move events should be sent. | 292 // ACK the press. Coalesced touch-move events should be sent. |
271 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 293 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
272 EXPECT_EQ(2U, queued_event_count()); | 294 EXPECT_EQ(2U, queued_event_count()); |
273 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 295 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
274 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 296 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
275 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 297 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
276 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 298 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
(...skipping 11 matching lines...) Expand all Loading... |
288 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 310 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
289 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 311 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
290 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 312 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
291 } | 313 } |
292 | 314 |
293 // Tests that an event that has already been sent but hasn't been ack'ed yet | 315 // Tests that an event that has already been sent but hasn't been ack'ed yet |
294 // doesn't get coalesced with newer events. | 316 // doesn't get coalesced with newer events. |
295 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { | 317 TEST_F(TouchEventQueueTest, SentTouchEventDoesNotCoalesce) { |
296 // Send a touch-press event. | 318 // Send a touch-press event. |
297 PressTouchPoint(1, 1); | 319 PressTouchPoint(1, 1); |
298 SendTouchEvent(); | |
299 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 320 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
300 | 321 |
301 // Send a few touch-move events, followed by a touch-release event. All the | 322 // Send a few touch-move events, followed by a touch-release event. All the |
302 // touch-move events should be coalesced into a single event. | 323 // touch-move events should be coalesced into a single event. |
303 for (int i = 5; i < 15; ++i) { | 324 for (int i = 5; i < 15; ++i) |
304 MoveTouchPoint(0, i, i); | 325 MoveTouchPoint(0, i, i); |
305 SendTouchEvent(); | 326 |
306 } | |
307 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 327 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
308 EXPECT_EQ(2U, queued_event_count()); | 328 EXPECT_EQ(2U, queued_event_count()); |
309 | 329 |
310 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 330 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
311 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 331 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
312 EXPECT_EQ(1U, queued_event_count()); | 332 EXPECT_EQ(1U, queued_event_count()); |
313 | 333 |
314 // The coalesced touch-move event has been sent to the renderer. Any new | 334 // The coalesced touch-move event has been sent to the renderer. Any new |
315 // touch-move event should not be coalesced with the sent event. | 335 // touch-move event should not be coalesced with the sent event. |
316 MoveTouchPoint(0, 5, 5); | 336 MoveTouchPoint(0, 5, 5); |
317 SendTouchEvent(); | |
318 EXPECT_EQ(2U, queued_event_count()); | 337 EXPECT_EQ(2U, queued_event_count()); |
319 | 338 |
320 MoveTouchPoint(0, 7, 7); | 339 MoveTouchPoint(0, 7, 7); |
321 SendTouchEvent(); | |
322 EXPECT_EQ(2U, queued_event_count()); | 340 EXPECT_EQ(2U, queued_event_count()); |
323 } | 341 } |
324 | 342 |
325 // Tests that coalescing works correctly for multi-touch events. | 343 // Tests that coalescing works correctly for multi-touch events. |
326 TEST_F(TouchEventQueueTest, MultiTouch) { | 344 TEST_F(TouchEventQueueTest, MultiTouch) { |
327 // Press the first finger. | 345 // Press the first finger. |
328 PressTouchPoint(1, 1); | 346 PressTouchPoint(1, 1); |
329 SendTouchEvent(); | |
330 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 347 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
331 | 348 |
332 // Move the finger. | 349 // Move the finger. |
333 MoveTouchPoint(0, 5, 5); | 350 MoveTouchPoint(0, 5, 5); |
334 SendTouchEvent(); | |
335 EXPECT_EQ(2U, queued_event_count()); | 351 EXPECT_EQ(2U, queued_event_count()); |
336 | 352 |
337 // Now press a second finger. | 353 // Now press a second finger. |
338 PressTouchPoint(2, 2); | 354 PressTouchPoint(2, 2); |
339 SendTouchEvent(); | |
340 EXPECT_EQ(3U, queued_event_count()); | 355 EXPECT_EQ(3U, queued_event_count()); |
341 | 356 |
342 // Move both fingers. | 357 // Move both fingers. |
343 MoveTouchPoint(0, 10, 10); | 358 MoveTouchPoints(0, 10, 10, 1, 20, 20); |
344 MoveTouchPoint(1, 20, 20); | 359 MoveTouchPoint(1, 20, 20); |
345 SendTouchEvent(); | |
346 EXPECT_EQ(4U, queued_event_count()); | 360 EXPECT_EQ(4U, queued_event_count()); |
347 | 361 |
348 // Move only one finger now. | 362 // Move only one finger now. |
349 MoveTouchPoint(0, 15, 15); | 363 MoveTouchPoint(0, 15, 15); |
350 SendTouchEvent(); | |
351 EXPECT_EQ(4U, queued_event_count()); | 364 EXPECT_EQ(4U, queued_event_count()); |
352 | 365 |
353 // Move the other finger. | 366 // Move the other finger. |
354 MoveTouchPoint(1, 25, 25); | 367 MoveTouchPoint(1, 25, 25); |
355 SendTouchEvent(); | |
356 EXPECT_EQ(4U, queued_event_count()); | 368 EXPECT_EQ(4U, queued_event_count()); |
357 | 369 |
358 // Make sure both fingers are marked as having been moved in the coalesced | 370 // Make sure both fingers are marked as having been moved in the coalesced |
359 // event. | 371 // event. |
360 const WebTouchEvent& event = latest_event(); | 372 const WebTouchEvent& event = latest_event(); |
361 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); | 373 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[0].state); |
362 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); | 374 EXPECT_EQ(WebTouchPoint::StateMoved, event.touches[1].state); |
363 } | 375 } |
364 | 376 |
365 // Tests that if a touch-event queue is destroyed in response to a touch-event | 377 // Tests that if a touch-event queue is destroyed in response to a touch-event |
366 // in the renderer, then there is no crash when the ACK for that touch-event | 378 // in the renderer, then there is no crash when the ACK for that touch-event |
367 // comes back. | 379 // comes back. |
368 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) { | 380 TEST_F(TouchEventQueueTest, AckAfterQueueFlushed) { |
369 // Send some touch-events to the renderer. | 381 // Send some touch-events to the renderer. |
370 PressTouchPoint(1, 1); | 382 PressTouchPoint(1, 1); |
371 SendTouchEvent(); | |
372 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 383 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
373 EXPECT_EQ(1U, queued_event_count()); | 384 EXPECT_EQ(1U, queued_event_count()); |
374 | 385 |
375 MoveTouchPoint(0, 10, 10); | 386 MoveTouchPoint(0, 10, 10); |
376 SendTouchEvent(); | |
377 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 387 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
378 EXPECT_EQ(2U, queued_event_count()); | 388 EXPECT_EQ(2U, queued_event_count()); |
379 | 389 |
380 // Receive an ACK for the press. This should cause the queued touch-move to | 390 // Receive an ACK for the press. This should cause the queued touch-move to |
381 // be sent to the renderer. | 391 // be sent to the renderer. |
382 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 392 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
383 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 393 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
384 EXPECT_EQ(1U, queued_event_count()); | 394 EXPECT_EQ(1U, queued_event_count()); |
385 | 395 |
386 Flush(); | 396 Flush(); |
387 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 397 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
388 EXPECT_EQ(0U, queued_event_count()); | 398 EXPECT_EQ(0U, queued_event_count()); |
389 | 399 |
390 // Now receive an ACK for the move. | 400 // Now receive an ACK for the move. |
391 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 401 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
392 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 402 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
393 EXPECT_EQ(0U, queued_event_count()); | 403 EXPECT_EQ(0U, queued_event_count()); |
394 } | 404 } |
395 | 405 |
396 // Tests that touch-move events are not sent to the renderer if the preceding | 406 // Tests that touch-move events are not sent to the renderer if the preceding |
397 // touch-press event did not have a consumer (and consequently, did not hit the | 407 // touch-press event did not have a consumer (and consequently, did not hit the |
398 // main thread in the renderer). Also tests that all queued/coalesced touch | 408 // main thread in the renderer). Also tests that all queued/coalesced touch |
399 // events are flushed immediately when the ACK for the touch-press comes back | 409 // events are flushed immediately when the ACK for the touch-press comes back |
400 // with NO_CONSUMER status. | 410 // with NO_CONSUMER status. |
401 TEST_F(TouchEventQueueTest, NoConsumer) { | 411 TEST_F(TouchEventQueueTest, NoConsumer) { |
402 // The first touch-press should reach the renderer. | 412 // The first touch-press should reach the renderer. |
403 PressTouchPoint(1, 1); | 413 PressTouchPoint(1, 1); |
404 SendTouchEvent(); | |
405 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 414 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
406 | 415 |
407 // The second touch should not be sent since one is already in queue. | 416 // The second touch should not be sent since one is already in queue. |
408 MoveTouchPoint(0, 5, 5); | 417 MoveTouchPoint(0, 5, 5); |
409 SendTouchEvent(); | |
410 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 418 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
411 EXPECT_EQ(2U, queued_event_count()); | 419 EXPECT_EQ(2U, queued_event_count()); |
412 | 420 |
413 // Receive an ACK for the first touch-event. This should release the queued | 421 // Receive an ACK for the first touch-event. This should release the queued |
414 // touch-event, but it should not be sent to the renderer. | 422 // touch-event, but it should not be sent to the renderer. |
415 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 423 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
416 EXPECT_EQ(0U, queued_event_count()); | 424 EXPECT_EQ(0U, queued_event_count()); |
417 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 425 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
418 EXPECT_EQ(2U, GetAndResetAckedEventCount()); | 426 EXPECT_EQ(2U, GetAndResetAckedEventCount()); |
419 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 427 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
420 | 428 |
421 // Send a release event. This should not reach the renderer. | 429 // Send a release event. This should not reach the renderer. |
422 ReleaseTouchPoint(0); | 430 ReleaseTouchPoint(0); |
423 SendTouchEvent(); | |
424 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 431 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
425 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 432 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
426 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 433 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
427 | 434 |
428 // Send a press-event, followed by move and release events, and another press | 435 // Send a press-event, followed by move and release events, and another press |
429 // event, before the ACK for the first press event comes back. All of the | 436 // event, before the ACK for the first press event comes back. All of the |
430 // events should be queued first. After the NO_CONSUMER ack for the first | 437 // events should be queued first. After the NO_CONSUMER ack for the first |
431 // touch-press, all events upto the second touch-press should be flushed. | 438 // touch-press, all events upto the second touch-press should be flushed. |
432 PressTouchPoint(10, 10); | 439 PressTouchPoint(10, 10); |
433 SendTouchEvent(); | |
434 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 440 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
435 | 441 |
436 MoveTouchPoint(0, 5, 5); | 442 MoveTouchPoint(0, 5, 5); |
437 SendTouchEvent(); | |
438 MoveTouchPoint(0, 6, 5); | 443 MoveTouchPoint(0, 6, 5); |
439 SendTouchEvent(); | |
440 ReleaseTouchPoint(0); | 444 ReleaseTouchPoint(0); |
441 SendTouchEvent(); | |
442 | 445 |
443 PressTouchPoint(6, 5); | 446 PressTouchPoint(6, 5); |
444 SendTouchEvent(); | |
445 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 447 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
446 // The queue should hold the first sent touch-press event, the coalesced | 448 // The queue should hold the first sent touch-press event, the coalesced |
447 // touch-move event, the touch-end event and the second touch-press event. | 449 // touch-move event, the touch-end event and the second touch-press event. |
448 EXPECT_EQ(4U, queued_event_count()); | 450 EXPECT_EQ(4U, queued_event_count()); |
449 | 451 |
450 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 452 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
451 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 453 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
452 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); | 454 EXPECT_EQ(WebInputEvent::TouchEnd, acked_event().type); |
453 EXPECT_EQ(4U, GetAndResetAckedEventCount()); | 455 EXPECT_EQ(4U, GetAndResetAckedEventCount()); |
454 EXPECT_EQ(1U, queued_event_count()); | 456 EXPECT_EQ(1U, queued_event_count()); |
455 | 457 |
456 // ACK the second press event as NO_CONSUMER too. | 458 // ACK the second press event as NO_CONSUMER too. |
457 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 459 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
458 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 460 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
459 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 461 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
460 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 462 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
461 EXPECT_EQ(0U, queued_event_count()); | 463 EXPECT_EQ(0U, queued_event_count()); |
462 | 464 |
463 // Send a second press event. Even though the first touch had NO_CONSUMER, | 465 // Send a second press event. Even though the first touch had NO_CONSUMER, |
464 // this press event should reach the renderer. | 466 // this press event should reach the renderer. |
465 PressTouchPoint(1, 1); | 467 PressTouchPoint(1, 1); |
466 SendTouchEvent(); | |
467 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 468 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
468 EXPECT_EQ(1U, queued_event_count()); | 469 EXPECT_EQ(1U, queued_event_count()); |
469 } | 470 } |
470 | 471 |
471 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { | 472 TEST_F(TouchEventQueueTest, ConsumerIgnoreMultiFinger) { |
472 // Press two touch points and move them around a bit. The renderer consumes | 473 // Press two touch points and move them around a bit. The renderer consumes |
473 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for | 474 // the events for the first touch point, but returns NO_CONSUMER_EXISTS for |
474 // the second touch point. | 475 // the second touch point. |
475 | 476 |
476 PressTouchPoint(1, 1); | 477 PressTouchPoint(1, 1); |
477 SendTouchEvent(); | |
478 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 478 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
479 | 479 |
480 MoveTouchPoint(0, 5, 5); | 480 MoveTouchPoint(0, 5, 5); |
481 SendTouchEvent(); | |
482 | 481 |
483 PressTouchPoint(10, 10); | 482 PressTouchPoint(10, 10); |
484 SendTouchEvent(); | |
485 | 483 |
486 MoveTouchPoint(0, 2, 2); | 484 MoveTouchPoint(0, 2, 2); |
487 SendTouchEvent(); | |
488 | 485 |
489 MoveTouchPoint(1, 4, 10); | 486 MoveTouchPoint(1, 4, 10); |
490 SendTouchEvent(); | |
491 | 487 |
492 MoveTouchPoint(0, 10, 10); | 488 MoveTouchPoints(0, 10, 10, 1, 20, 20); |
493 MoveTouchPoint(1, 20, 20); | |
494 SendTouchEvent(); | |
495 | 489 |
496 // Since the first touch-press is still pending ACK, no other event should | 490 // Since the first touch-press is still pending ACK, no other event should |
497 // have been sent to the renderer. | 491 // have been sent to the renderer. |
498 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 492 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
499 // The queue includes the two presses, the first touch-move of the first | 493 // The queue includes the two presses, the first touch-move of the first |
500 // point, and a coalesced touch-move of both points. | 494 // point, and a coalesced touch-move of both points. |
501 EXPECT_EQ(4U, queued_event_count()); | 495 EXPECT_EQ(4U, queued_event_count()); |
502 | 496 |
503 // ACK the first press as CONSUMED. This should cause the first touch-move of | 497 // ACK the first press as CONSUMED. This should cause the first touch-move of |
504 // the first touch-point to be dispatched. | 498 // the first touch-point to be dispatched. |
(...skipping 15 matching lines...) Expand all Loading... |
520 EXPECT_EQ(1U, queued_event_count()); | 514 EXPECT_EQ(1U, queued_event_count()); |
521 | 515 |
522 // ACK the coalesced move as NOT_CONSUMED. | 516 // ACK the coalesced move as NOT_CONSUMED. |
523 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 517 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
524 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 518 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
525 EXPECT_EQ(0U, queued_event_count()); | 519 EXPECT_EQ(0U, queued_event_count()); |
526 | 520 |
527 // Move just the second touch point. Because the first touch point did not | 521 // Move just the second touch point. Because the first touch point did not |
528 // move, this event should not reach the renderer. | 522 // move, this event should not reach the renderer. |
529 MoveTouchPoint(1, 30, 30); | 523 MoveTouchPoint(1, 30, 30); |
530 SendTouchEvent(); | |
531 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 524 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
532 EXPECT_EQ(0U, queued_event_count()); | 525 EXPECT_EQ(0U, queued_event_count()); |
533 | 526 |
534 // Move just the first touch point. This should reach the renderer. | 527 // Move just the first touch point. This should reach the renderer. |
535 MoveTouchPoint(0, 10, 10); | 528 MoveTouchPoint(0, 10, 10); |
536 SendTouchEvent(); | |
537 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 529 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
538 EXPECT_EQ(1U, queued_event_count()); | 530 EXPECT_EQ(1U, queued_event_count()); |
539 | 531 |
540 // Move both fingers. This event should reach the renderer (after the ACK of | 532 // Move both fingers. This event should reach the renderer (after the ACK of |
541 // the previous move event is received), because the first touch point did | 533 // the previous move event is received), because the first touch point did |
542 // move. | 534 // move. |
543 MoveTouchPoint(0, 15, 15); | 535 MoveTouchPoints(0, 15, 15, 1, 25, 25); |
544 MoveTouchPoint(1, 25, 25); | |
545 SendTouchEvent(); | |
546 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 536 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
547 | 537 |
548 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 538 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
549 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 539 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
550 EXPECT_EQ(1U, queued_event_count()); | 540 EXPECT_EQ(1U, queued_event_count()); |
551 | 541 |
552 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 542 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
553 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 543 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
554 EXPECT_EQ(0U, queued_event_count()); | 544 EXPECT_EQ(0U, queued_event_count()); |
555 | 545 |
556 // Release the first finger. Then move the second finger around some, then | 546 // Release the first finger. Then move the second finger around some, then |
557 // press another finger. Once the release event is ACKed, the move events of | 547 // press another finger. Once the release event is ACKed, the move events of |
558 // the second finger should be immediately released to the view, and the | 548 // the second finger should be immediately released to the view, and the |
559 // touch-press event should be dispatched to the renderer. | 549 // touch-press event should be dispatched to the renderer. |
560 ReleaseTouchPoint(0); | 550 ReleaseTouchPoint(0); |
561 SendTouchEvent(); | |
562 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 551 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
563 EXPECT_EQ(1U, queued_event_count()); | 552 EXPECT_EQ(1U, queued_event_count()); |
564 | 553 |
565 MoveTouchPoint(1, 40, 40); | 554 MoveTouchPoint(1, 40, 40); |
566 SendTouchEvent(); | |
567 | 555 |
568 MoveTouchPoint(1, 50, 50); | 556 MoveTouchPoint(1, 50, 50); |
569 SendTouchEvent(); | |
570 | 557 |
571 PressTouchPoint(1, 1); | 558 PressTouchPoint(1, 1); |
572 SendTouchEvent(); | |
573 | 559 |
574 MoveTouchPoint(1, 30, 30); | 560 MoveTouchPoint(1, 30, 30); |
575 SendTouchEvent(); | |
576 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 561 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
577 EXPECT_EQ(4U, queued_event_count()); | 562 EXPECT_EQ(4U, queued_event_count()); |
578 | 563 |
579 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 564 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
580 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 565 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
581 EXPECT_EQ(2U, queued_event_count()); | 566 EXPECT_EQ(2U, queued_event_count()); |
582 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 567 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
583 | 568 |
584 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued | 569 // ACK the press with NO_CONSUMED_EXISTS. This should release the queued |
585 // touch-move events to the view. | 570 // touch-move events to the view. |
586 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 571 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
587 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 572 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
588 EXPECT_EQ(0U, queued_event_count()); | 573 EXPECT_EQ(0U, queued_event_count()); |
589 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 574 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
590 | 575 |
591 ReleaseTouchPoint(2); | 576 ReleaseTouchPoint(2); |
592 ReleaseTouchPoint(1); | 577 ReleaseTouchPoint(1); |
593 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 578 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
594 EXPECT_EQ(0U, queued_event_count()); | 579 EXPECT_EQ(0U, queued_event_count()); |
595 } | 580 } |
596 | 581 |
597 // Tests that touch-event's enqueued via a touch ack are properly handled. | 582 // Tests that touch-event's enqueued via a touch ack are properly handled. |
598 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { | 583 TEST_F(TouchEventQueueTest, AckWithFollowupEvents) { |
599 // Queue a touch down. | 584 // Queue a touch down. |
600 PressTouchPoint(1, 1); | 585 PressTouchPoint(1, 1); |
601 SendTouchEvent(); | |
602 EXPECT_EQ(1U, queued_event_count()); | 586 EXPECT_EQ(1U, queued_event_count()); |
603 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 587 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
604 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | 588 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
605 | 589 |
606 // Create a touch event that will be queued synchronously by a touch ack. | 590 // Create a touch event that will be queued synchronously by a touch ack. |
607 // Note, this will be triggered by all subsequent touch acks. | 591 // Note, this will be triggered by all subsequent touch acks. |
608 WebTouchEvent followup_event; | 592 WebTouchEvent followup_event; |
609 followup_event.type = WebInputEvent::TouchStart; | 593 followup_event.type = WebInputEvent::TouchStart; |
610 followup_event.touchesLength = 1; | 594 followup_event.touchesLength = 1; |
611 followup_event.touches[0].id = 1; | 595 followup_event.touches[0].id = 1; |
612 followup_event.touches[0].state = WebTouchPoint::StatePressed; | 596 followup_event.touches[0].state = WebTouchPoint::StatePressed; |
613 SetFollowupEvent(followup_event); | 597 SetFollowupEvent(followup_event); |
614 | 598 |
615 // Receive an ACK for the press. This should cause the followup touch-move to | 599 // Receive an ACK for the press. This should cause the followup touch-move to |
616 // be sent to the renderer. | 600 // be sent to the renderer. |
617 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 601 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
618 EXPECT_EQ(1U, queued_event_count()); | 602 EXPECT_EQ(1U, queued_event_count()); |
619 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 603 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
620 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 604 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
621 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); | 605 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, acked_event_state()); |
622 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 606 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
623 | 607 |
624 // Queue another event. | 608 // Queue another event. |
625 PressTouchPoint(1, 1); | |
626 MoveTouchPoint(0, 2, 2); | 609 MoveTouchPoint(0, 2, 2); |
627 SendTouchEvent(); | |
628 EXPECT_EQ(2U, queued_event_count()); | 610 EXPECT_EQ(2U, queued_event_count()); |
629 | 611 |
630 // Receive an ACK for the touch-move followup event. This should cause the | 612 // Receive an ACK for the touch-move followup event. This should cause the |
631 // subsequent touch move event be sent to the renderer. | 613 // subsequent touch move event be sent to the renderer. |
632 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 614 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
633 EXPECT_EQ(1U, queued_event_count()); | 615 EXPECT_EQ(1U, queued_event_count()); |
634 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 616 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
635 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 617 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
636 } | 618 } |
637 | 619 |
638 // Tests that touch-events can be synchronously ack'ed. | 620 // Tests that touch-events can be synchronously ack'ed. |
639 TEST_F(TouchEventQueueTest, SynchronousAcks) { | 621 TEST_F(TouchEventQueueTest, SynchronousAcks) { |
640 // TouchStart | 622 // TouchStart |
641 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 623 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
642 PressTouchPoint(1, 1); | 624 PressTouchPoint(1, 1); |
643 SendTouchEvent(); | |
644 EXPECT_EQ(0U, queued_event_count()); | 625 EXPECT_EQ(0U, queued_event_count()); |
645 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 626 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
646 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 627 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
647 | 628 |
648 // TouchMove | 629 // TouchMove |
649 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 630 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
650 PressTouchPoint(1, 1); | |
651 MoveTouchPoint(0, 2, 2); | 631 MoveTouchPoint(0, 2, 2); |
652 SendTouchEvent(); | |
653 EXPECT_EQ(0U, queued_event_count()); | 632 EXPECT_EQ(0U, queued_event_count()); |
654 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 633 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
655 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 634 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
656 | 635 |
657 // TouchEnd | 636 // TouchEnd |
658 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 637 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
659 PressTouchPoint(1, 1); | |
660 ReleaseTouchPoint(0); | 638 ReleaseTouchPoint(0); |
661 SendTouchEvent(); | |
662 EXPECT_EQ(0U, queued_event_count()); | 639 EXPECT_EQ(0U, queued_event_count()); |
663 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 640 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
664 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 641 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
665 | 642 |
666 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent) | 643 // TouchCancel (first inserting a TouchStart so the TouchCancel will be sent) |
667 PressTouchPoint(1, 1); | 644 PressTouchPoint(1, 1); |
668 SendTouchEvent(); | |
669 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | 645 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
670 EXPECT_EQ(0U, queued_event_count()); | 646 EXPECT_EQ(0U, queued_event_count()); |
671 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 647 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
672 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 648 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
673 | 649 |
674 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 650 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
675 PressTouchPoint(1, 1); | |
676 CancelTouchPoint(0); | 651 CancelTouchPoint(0); |
677 SendTouchEvent(); | |
678 EXPECT_EQ(0U, queued_event_count()); | 652 EXPECT_EQ(0U, queued_event_count()); |
679 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 653 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
680 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 654 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
681 } | 655 } |
682 | 656 |
683 // Tests that followup events triggered by an immediate ack from | 657 // Tests that followup events triggered by an immediate ack from |
684 // TouchEventQueue::QueueEvent() are properly handled. | 658 // TouchEventQueue::QueueEvent() are properly handled. |
685 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { | 659 TEST_F(TouchEventQueueTest, ImmediateAckWithFollowupEvents) { |
686 // Create a touch event that will be queued synchronously by a touch ack. | 660 // Create a touch event that will be queued synchronously by a touch ack. |
687 WebTouchEvent followup_event; | 661 WebTouchEvent followup_event; |
(...skipping 16 matching lines...) Expand all Loading... |
704 EXPECT_EQ(1U, queued_event_count()); | 678 EXPECT_EQ(1U, queued_event_count()); |
705 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 679 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
706 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 680 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
707 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 681 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
708 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); | 682 EXPECT_EQ(WebInputEvent::TouchMove, acked_event().type); |
709 } | 683 } |
710 | 684 |
711 // Tests basic TouchEvent forwarding suppression. | 685 // Tests basic TouchEvent forwarding suppression. |
712 TEST_F(TouchEventQueueTest, NoTouchBasic) { | 686 TEST_F(TouchEventQueueTest, NoTouchBasic) { |
713 // Disable TouchEvent forwarding. | 687 // Disable TouchEvent forwarding. |
714 set_no_touch_to_renderer(true); | 688 SetEnableTouchForwarding(false); |
715 MoveTouchPoint(0, 30, 5); | 689 MoveTouchPoint(0, 30, 5); |
716 SendTouchEvent(); | |
717 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 690 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
718 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 691 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
719 | 692 |
720 // TouchMove should not be sent to renderer. | 693 // TouchMove should not be sent to renderer. |
721 MoveTouchPoint(0, 65, 10); | 694 MoveTouchPoint(0, 65, 10); |
722 SendTouchEvent(); | |
723 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 695 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
724 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 696 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
725 | 697 |
726 // TouchEnd should not be sent to renderer. | 698 // TouchEnd should not be sent to renderer. |
727 ReleaseTouchPoint(0); | 699 ReleaseTouchPoint(0); |
728 SendTouchEvent(); | |
729 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 700 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
730 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 701 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
731 | 702 |
732 // TouchStart should not be sent to renderer. | 703 // TouchStart should not be sent to renderer. |
733 PressTouchPoint(5, 5); | 704 PressTouchPoint(5, 5); |
734 SendTouchEvent(); | |
735 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 705 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
736 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 706 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
737 | 707 |
738 // Enable TouchEvent forwarding. | 708 // Enable TouchEvent forwarding. |
739 set_no_touch_to_renderer(false); | 709 SetEnableTouchForwarding(true); |
740 | 710 |
741 PressTouchPoint(80, 10); | 711 PressTouchPoint(80, 10); |
742 SendTouchEvent(); | |
743 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 712 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
744 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 713 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
745 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 714 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
746 | 715 |
747 MoveTouchPoint(0, 80, 20); | 716 MoveTouchPoint(0, 80, 20); |
748 SendTouchEvent(); | |
749 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 717 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
750 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 718 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
751 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 719 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
752 | 720 |
753 ReleaseTouchPoint(0); | 721 ReleaseTouchPoint(0); |
754 SendTouchEvent(); | |
755 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 722 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
756 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 723 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
757 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 724 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
758 } | 725 } |
759 | 726 |
760 // Tests that no TouchEvents are sent to renderer during scrolling. | 727 // Tests that no TouchEvents are sent to renderer during scrolling. |
761 TEST_F(TouchEventQueueTest, NoTouchOnScroll) { | 728 TEST_F(TouchEventQueueTest, NoTouchOnScroll) { |
762 // Queue a TouchStart. | 729 // Queue a TouchStart. |
763 PressTouchPoint(0, 1); | 730 PressTouchPoint(0, 1); |
764 SendTouchEvent(); | |
765 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 731 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
766 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 732 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
767 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 733 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
768 | 734 |
769 MoveTouchPoint(0, 20, 5); | 735 MoveTouchPoint(0, 20, 5); |
770 SendTouchEvent(); | |
771 EXPECT_EQ(1U, queued_event_count()); | 736 EXPECT_EQ(1U, queued_event_count()); |
772 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 737 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
773 | 738 |
774 // Queue another TouchStart. | 739 // Queue another TouchStart. |
775 PressTouchPoint(20, 20); | 740 PressTouchPoint(20, 20); |
776 SendTouchEvent(); | |
777 EXPECT_EQ(2U, queued_event_count()); | 741 EXPECT_EQ(2U, queued_event_count()); |
778 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 742 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
779 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 743 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
780 | 744 |
781 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. | 745 // GestureScrollBegin inserts a synthetic TouchCancel before the TouchStart. |
782 WebGestureEvent followup_scroll; | 746 WebGestureEvent followup_scroll; |
783 followup_scroll.type = WebInputEvent::GestureScrollBegin; | 747 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
784 SetFollowupEvent(followup_scroll); | 748 SetFollowupEvent(followup_scroll); |
785 ASSERT_FALSE(no_touch_to_renderer()); | 749 ASSERT_TRUE(WillForwardTouchEvents()); |
786 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 750 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
787 EXPECT_TRUE(no_touch_to_renderer()); | 751 EXPECT_FALSE(WillForwardTouchEvents()); |
788 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 752 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
789 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 753 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
790 EXPECT_EQ(2U, queued_event_count()); | 754 EXPECT_EQ(2U, queued_event_count()); |
791 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); | 755 EXPECT_EQ(WebInputEvent::TouchCancel, sent_event().type); |
792 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); | 756 EXPECT_EQ(WebInputEvent::TouchStart, latest_event().type); |
793 | 757 |
794 // Acking the TouchCancel will result in dispatch of the next TouchStart. | 758 // Acking the TouchCancel will result in dispatch of the next TouchStart. |
795 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 759 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
796 // The synthetic TouchCancel should not reach client, only the TouchStart. | 760 // The synthetic TouchCancel should not reach client, only the TouchStart. |
797 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 761 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
798 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 762 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
799 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); | 763 EXPECT_EQ(WebInputEvent::TouchStart, acked_event().type); |
800 | 764 |
801 // TouchMove should not be sent to renderer. | 765 // TouchMove should not be sent to the renderer. |
802 MoveTouchPoint(0, 30, 5); | 766 MoveTouchPoint(0, 30, 5); |
803 SendTouchEvent(); | |
804 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 767 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
805 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 768 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
806 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 769 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
807 | 770 |
808 // GestureScrollUpdates should not change affect touch forwarding. | 771 // GestureScrollUpdates should not change affect touch forwarding. |
809 SendGestureEvent(WebInputEvent::GestureScrollUpdate); | 772 SendGestureEvent(WebInputEvent::GestureScrollUpdate); |
810 EXPECT_TRUE(no_touch_to_renderer()); | 773 EXPECT_FALSE(WillForwardTouchEvents()); |
811 | 774 |
812 // TouchEnd should not be sent to renderer. | 775 // TouchEnd should not be sent to the renderer. |
813 ReleaseTouchPoint(0); | 776 ReleaseTouchPoint(0); |
814 SendTouchEvent(); | |
815 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 777 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
816 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 778 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
817 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 779 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
818 | 780 |
819 // GestureScrollEnd will resume the sending of TouchEvents to renderer. | 781 // GestureScrollEnd will resume the sending of TouchEvents to renderer. |
820 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); | 782 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
821 EXPECT_FALSE(no_touch_to_renderer()); | 783 EXPECT_TRUE(WillForwardTouchEvents()); |
822 | 784 |
823 // Now TouchEvents should be forwarded normally. | 785 // Now TouchEvents should be forwarded normally. |
824 PressTouchPoint(80, 10); | 786 PressTouchPoint(80, 10); |
825 SendTouchEvent(); | |
826 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 787 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
827 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 788 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
828 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 789 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
829 | 790 |
830 MoveTouchPoint(0, 80, 20); | 791 MoveTouchPoint(0, 80, 20); |
831 SendTouchEvent(); | |
832 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 792 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
833 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 793 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
834 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 794 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
835 | 795 |
836 ReleaseTouchPoint(0); | 796 ReleaseTouchPoint(0); |
837 SendTouchEvent(); | |
838 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 797 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
839 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 798 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
840 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 799 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
841 } | 800 } |
842 | 801 |
843 // Tests that IsTouchStartPendingAck works correctly. | 802 // Tests that IsTouchStartPendingAck works correctly. |
844 TEST_F(TouchEventQueueTest, PendingStart) { | 803 TEST_F(TouchEventQueueTest, PendingStart) { |
845 | 804 |
846 EXPECT_FALSE(IsPendingAckTouchStart()); | 805 EXPECT_FALSE(IsPendingAckTouchStart()); |
847 | 806 |
848 // Send the touchstart for one point (#1). | 807 // Send the touchstart for one point (#1). |
849 PressTouchPoint(1, 1); | 808 PressTouchPoint(1, 1); |
850 SendTouchEvent(); | |
851 EXPECT_EQ(1U, queued_event_count()); | 809 EXPECT_EQ(1U, queued_event_count()); |
852 EXPECT_TRUE(IsPendingAckTouchStart()); | 810 EXPECT_TRUE(IsPendingAckTouchStart()); |
853 | 811 |
854 // Send a touchmove for that point (#2). | 812 // Send a touchmove for that point (#2). |
855 MoveTouchPoint(0, 5, 5); | 813 MoveTouchPoint(0, 5, 5); |
856 SendTouchEvent(); | |
857 EXPECT_EQ(2U, queued_event_count()); | 814 EXPECT_EQ(2U, queued_event_count()); |
858 EXPECT_TRUE(IsPendingAckTouchStart()); | 815 EXPECT_TRUE(IsPendingAckTouchStart()); |
859 | 816 |
860 // Ack the touchstart (#1). | 817 // Ack the touchstart (#1). |
861 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 818 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
862 EXPECT_EQ(1U, queued_event_count()); | 819 EXPECT_EQ(1U, queued_event_count()); |
863 EXPECT_FALSE(IsPendingAckTouchStart()); | 820 EXPECT_FALSE(IsPendingAckTouchStart()); |
864 | 821 |
865 // Send a touchstart for another point (#3). | 822 // Send a touchstart for another point (#3). |
866 PressTouchPoint(10, 10); | 823 PressTouchPoint(10, 10); |
867 SendTouchEvent(); | |
868 EXPECT_EQ(2U, queued_event_count()); | 824 EXPECT_EQ(2U, queued_event_count()); |
869 EXPECT_FALSE(IsPendingAckTouchStart()); | 825 EXPECT_FALSE(IsPendingAckTouchStart()); |
870 | 826 |
871 // Ack the touchmove (#2). | 827 // Ack the touchmove (#2). |
872 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 828 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
873 EXPECT_EQ(1U, queued_event_count()); | 829 EXPECT_EQ(1U, queued_event_count()); |
874 EXPECT_TRUE(IsPendingAckTouchStart()); | 830 EXPECT_TRUE(IsPendingAckTouchStart()); |
875 | 831 |
876 // Send a touchstart for a third point (#4). | 832 // Send a touchstart for a third point (#4). |
877 PressTouchPoint(15, 15); | 833 PressTouchPoint(15, 15); |
878 SendTouchEvent(); | |
879 EXPECT_EQ(2U, queued_event_count()); | 834 EXPECT_EQ(2U, queued_event_count()); |
880 EXPECT_TRUE(IsPendingAckTouchStart()); | 835 EXPECT_TRUE(IsPendingAckTouchStart()); |
881 | 836 |
882 // Ack the touchstart for the second point (#3). | 837 // Ack the touchstart for the second point (#3). |
883 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 838 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
884 EXPECT_EQ(1U, queued_event_count()); | 839 EXPECT_EQ(1U, queued_event_count()); |
885 EXPECT_TRUE(IsPendingAckTouchStart()); | 840 EXPECT_TRUE(IsPendingAckTouchStart()); |
886 | 841 |
887 // Ack the touchstart for the third point (#4). | 842 // Ack the touchstart for the third point (#4). |
888 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 843 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
889 EXPECT_EQ(0U, queued_event_count()); | 844 EXPECT_EQ(0U, queued_event_count()); |
890 EXPECT_FALSE(IsPendingAckTouchStart()); | 845 EXPECT_FALSE(IsPendingAckTouchStart()); |
891 } | 846 } |
892 | 847 |
| 848 // Tests that the touch timeout is started when sending certain touch types. |
| 849 TEST_F(TouchEventQueueTest, TouchTimeoutTypes) { |
| 850 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 851 |
| 852 // Sending a TouchStart will start the timeout. |
| 853 PressTouchPoint(0, 1); |
| 854 EXPECT_TRUE(IsTimeoutRunning()); |
| 855 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 856 EXPECT_FALSE(IsTimeoutRunning()); |
| 857 |
| 858 // A TouchMove should start the timeout. |
| 859 MoveTouchPoint(0, 5, 5); |
| 860 EXPECT_TRUE(IsTimeoutRunning()); |
| 861 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 862 EXPECT_FALSE(IsTimeoutRunning()); |
| 863 |
| 864 // A TouchEnd should not start the timeout. |
| 865 ReleaseTouchPoint(0); |
| 866 EXPECT_FALSE(IsTimeoutRunning()); |
| 867 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 868 EXPECT_FALSE(IsTimeoutRunning()); |
| 869 |
| 870 // A TouchCancel should not start the timeout. |
| 871 PressTouchPoint(0, 1); |
| 872 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 873 ASSERT_FALSE(IsTimeoutRunning()); |
| 874 CancelTouchPoint(0); |
| 875 EXPECT_FALSE(IsTimeoutRunning()); |
| 876 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 877 EXPECT_FALSE(IsTimeoutRunning()); |
| 878 } |
| 879 |
| 880 // Tests that a delayed TouchEvent ack will trigger a TouchCancel timeout, |
| 881 // disabling touch forwarding until the next TouchStart is received after |
| 882 // the timeout events are ack'ed. |
| 883 TEST_F(TouchEventQueueTest, TouchTimeoutBasic) { |
| 884 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 885 |
| 886 // Queue a TouchStart. |
| 887 GetAndResetSentEventCount(); |
| 888 GetAndResetAckedEventCount(); |
| 889 PressTouchPoint(0, 1); |
| 890 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 891 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 892 EXPECT_TRUE(IsTimeoutRunning()); |
| 893 EXPECT_TRUE(WillForwardTouchEvents()); |
| 894 |
| 895 // Delay the ack. |
| 896 base::MessageLoop::current()->PostDelayedTask( |
| 897 FROM_HERE, |
| 898 base::MessageLoop::QuitClosure(), |
| 899 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 900 base::MessageLoop::current()->Run(); |
| 901 |
| 902 // The timeout should have fired, synthetically ack'ing the timed-out event. |
| 903 // TouchEvent forwarding is disabled until the ack is received for the |
| 904 // timed-out event and the future cancel event. |
| 905 EXPECT_FALSE(IsTimeoutRunning()); |
| 906 EXPECT_FALSE(WillForwardTouchEvents()); |
| 907 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 908 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 909 |
| 910 // Ack'ing the original event should trigger a cancel event. |
| 911 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 912 EXPECT_FALSE(IsTimeoutRunning()); |
| 913 EXPECT_FALSE(WillForwardTouchEvents()); |
| 914 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 915 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 916 |
| 917 // Touch events should not be forwarded until we receive the cancel acks. |
| 918 PressTouchPoint(0, 1); |
| 919 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 920 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 921 |
| 922 // The synthetic TouchCancel ack should not reach the client, but should |
| 923 // resume touch forwarding. |
| 924 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 925 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 926 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 927 EXPECT_TRUE(WillForwardTouchEvents()); |
| 928 |
| 929 // Subsequent events should be handled normally. |
| 930 PressTouchPoint(0, 1); |
| 931 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 932 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 933 } |
| 934 |
| 935 // Tests that the timeout is never started if the renderer consumes |
| 936 // a TouchEvent from the current touch sequence. |
| 937 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfRendererIsConsumingGesture) { |
| 938 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 939 |
| 940 // Queue a TouchStart. |
| 941 PressTouchPoint(0, 1); |
| 942 ASSERT_TRUE(IsTimeoutRunning()); |
| 943 |
| 944 // Mark the event as consumed. This should prevent the timeout from |
| 945 // being activated on subsequent TouchEvents in this gesture. |
| 946 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 947 EXPECT_FALSE(IsTimeoutRunning()); |
| 948 |
| 949 // A TouchMove should not start the timeout. |
| 950 MoveTouchPoint(0, 5, 5); |
| 951 EXPECT_FALSE(IsTimeoutRunning()); |
| 952 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 953 |
| 954 // A secondary TouchStart should not start the timeout. |
| 955 PressTouchPoint(1, 0); |
| 956 EXPECT_FALSE(IsTimeoutRunning()); |
| 957 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 958 |
| 959 // A TouchEnd should not start the timeout. |
| 960 ReleaseTouchPoint(1); |
| 961 EXPECT_FALSE(IsTimeoutRunning()); |
| 962 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 963 |
| 964 // A TouchCancel should not start the timeout. |
| 965 CancelTouchPoint(0); |
| 966 EXPECT_FALSE(IsTimeoutRunning()); |
| 967 } |
| 968 |
| 969 // Tests that the timeout is never started if the ack is synchronous. |
| 970 TEST_F(TouchEventQueueTest, NoTouchTimeoutIfAckIsSynchronous) { |
| 971 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 972 |
| 973 // Queue a TouchStart. |
| 974 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 975 ASSERT_FALSE(IsTimeoutRunning()); |
| 976 PressTouchPoint(0, 1); |
| 977 EXPECT_FALSE(IsTimeoutRunning()); |
| 978 } |
| 979 |
| 980 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 981 // turns into a scroll gesture sequence. |
| 982 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGesture) { |
| 983 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 984 |
| 985 // Queue a TouchStart. |
| 986 PressTouchPoint(0, 1); |
| 987 EXPECT_TRUE(IsTimeoutRunning()); |
| 988 EXPECT_TRUE(WillForwardTouchEvents()); |
| 989 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 990 |
| 991 // The cancelled sequence may turn into a scroll gesture. |
| 992 WebGestureEvent followup_scroll; |
| 993 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 994 SetFollowupEvent(followup_scroll); |
| 995 |
| 996 // Delay the ack. |
| 997 base::MessageLoop::current()->PostDelayedTask( |
| 998 FROM_HERE, |
| 999 base::MessageLoop::QuitClosure(), |
| 1000 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1001 base::MessageLoop::current()->Run(); |
| 1002 |
| 1003 // The timeout should have fired, disabling touch forwarding until both acks |
| 1004 // are received, acking the timed out event. |
| 1005 EXPECT_FALSE(IsTimeoutRunning()); |
| 1006 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1007 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1008 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1009 |
| 1010 // Ack the original event, triggering a TouchCancel. |
| 1011 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1012 EXPECT_FALSE(IsTimeoutRunning()); |
| 1013 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1014 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1015 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1016 |
| 1017 // Ack the cancel event. Normally, this would resume touch forwarding, |
| 1018 // but we're still within a scroll gesture so it remains disabled. |
| 1019 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1020 EXPECT_FALSE(IsTimeoutRunning()); |
| 1021 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1022 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1023 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1024 |
| 1025 // Try to forward a touch event. |
| 1026 GetAndResetSentEventCount(); |
| 1027 GetAndResetAckedEventCount(); |
| 1028 PressTouchPoint(0, 1); |
| 1029 EXPECT_FALSE(IsTimeoutRunning()); |
| 1030 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1031 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1032 |
| 1033 // Now end the scroll sequence, resuming touch handling. |
| 1034 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1035 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1036 PressTouchPoint(0, 1); |
| 1037 EXPECT_TRUE(IsTimeoutRunning()); |
| 1038 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1039 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1040 } |
| 1041 |
| 1042 // Tests that a TouchCancel timeout plays nice when the timed out touch stream |
| 1043 // turns into a scroll gesture sequence, but the original event acks are |
| 1044 // significantly delayed. |
| 1045 TEST_F(TouchEventQueueTest, TouchTimeoutWithFollowupGestureAndDelayedAck) { |
| 1046 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1047 |
| 1048 // Queue a TouchStart. |
| 1049 PressTouchPoint(0, 1); |
| 1050 EXPECT_TRUE(IsTimeoutRunning()); |
| 1051 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1052 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1053 |
| 1054 // The cancelled sequence may turn into a scroll gesture. |
| 1055 WebGestureEvent followup_scroll; |
| 1056 followup_scroll.type = WebInputEvent::GestureScrollBegin; |
| 1057 SetFollowupEvent(followup_scroll); |
| 1058 |
| 1059 // Delay the ack. |
| 1060 base::MessageLoop::current()->PostDelayedTask( |
| 1061 FROM_HERE, |
| 1062 base::MessageLoop::QuitClosure(), |
| 1063 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1064 base::MessageLoop::current()->Run(); |
| 1065 |
| 1066 // The timeout should have fired, disabling touch forwarding until both acks |
| 1067 // are received and acking the timed out event. |
| 1068 EXPECT_FALSE(IsTimeoutRunning()); |
| 1069 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1070 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1071 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1072 |
| 1073 // Try to forward a touch event. |
| 1074 GetAndResetSentEventCount(); |
| 1075 GetAndResetAckedEventCount(); |
| 1076 PressTouchPoint(0, 1); |
| 1077 EXPECT_FALSE(IsTimeoutRunning()); |
| 1078 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1079 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1080 |
| 1081 // Now end the scroll sequence. Events will not be forwarded until the two |
| 1082 // outstanding touch acks are received. |
| 1083 SendGestureEvent(blink::WebInputEvent::GestureScrollEnd); |
| 1084 PressTouchPoint(0, 1); |
| 1085 EXPECT_FALSE(IsTimeoutRunning()); |
| 1086 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1087 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1088 |
| 1089 // Ack the original event, triggering a cancel. |
| 1090 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1091 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1092 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1093 |
| 1094 // Ack the cancel event, resuming touch forwarding. |
| 1095 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1096 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1097 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1098 |
| 1099 PressTouchPoint(0, 1); |
| 1100 EXPECT_TRUE(IsTimeoutRunning()); |
| 1101 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1102 } |
| 1103 |
| 1104 // Tests that a delayed TouchEvent ack will not trigger a TouchCancel timeout if |
| 1105 // the timed-out event had no consumer. |
| 1106 TEST_F(TouchEventQueueTest, NoCancelOnTouchTimeoutWithoutConsumer) { |
| 1107 SetUpForTimeoutTesting(kDefaultTouchTimeoutDelayMs); |
| 1108 |
| 1109 // Queue a TouchStart. |
| 1110 PressTouchPoint(0, 1); |
| 1111 ASSERT_EQ(1U, GetAndResetSentEventCount()); |
| 1112 ASSERT_EQ(0U, GetAndResetAckedEventCount()); |
| 1113 EXPECT_TRUE(IsTimeoutRunning()); |
| 1114 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1115 |
| 1116 // Delay the ack. |
| 1117 base::MessageLoop::current()->PostDelayedTask( |
| 1118 FROM_HERE, |
| 1119 base::MessageLoop::QuitClosure(), |
| 1120 base::TimeDelta::FromMilliseconds(kDefaultTouchTimeoutDelayMs * 2)); |
| 1121 base::MessageLoop::current()->Run(); |
| 1122 |
| 1123 // The timeout should have fired, synthetically ack'ing the timed out event. |
| 1124 // TouchEvent forwarding is disabled until the original ack is received. |
| 1125 EXPECT_FALSE(IsTimeoutRunning()); |
| 1126 EXPECT_FALSE(WillForwardTouchEvents()); |
| 1127 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1128 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 1129 |
| 1130 // Touch events should not be forwarded until we receive the original ack. |
| 1131 PressTouchPoint(0, 1); |
| 1132 ASSERT_EQ(0U, GetAndResetSentEventCount()); |
| 1133 ASSERT_EQ(1U, GetAndResetAckedEventCount()); |
| 1134 |
| 1135 // Ack'ing the original event should not trigger a cancel event, as the |
| 1136 // TouchStart had no consumer. However, it should re-enable touch forwarding. |
| 1137 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1138 EXPECT_FALSE(IsTimeoutRunning()); |
| 1139 EXPECT_TRUE(WillForwardTouchEvents()); |
| 1140 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1141 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 1142 |
| 1143 // Subsequent events should be handled normally. |
| 1144 PressTouchPoint(0, 1); |
| 1145 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 1146 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 1147 } |
893 } // namespace content | 1148 } // namespace content |
OLD | NEW |