Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/logging.h" | |
|
tdresser
2014/01/24 13:47:30
Remove unnecessary includes.
jdduke (slow)
2014/01/24 18:17:35
Done.
| |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "content/browser/renderer_host/input/gesture_event_queue.h" | |
| 9 #include "content/common/input/synthetic_web_input_event_builders.h" | |
| 10 #include "content/common/input/web_input_event_traits.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 13 | |
| 14 using blink::WebGestureEvent; | |
| 15 using blink::WebInputEvent; | |
| 16 using blink::WebTouchEvent; | |
| 17 using blink::WebTouchPoint; | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 class GestureEventQueueTest : public testing::Test, | |
| 22 public GestureEventQueueClient { | |
| 23 public: | |
| 24 GestureEventQueueTest() : sent_gesture_count_(0) {} | |
| 25 | |
| 26 virtual ~GestureEventQueueTest() {} | |
| 27 | |
| 28 // testing::Test | |
| 29 virtual void SetUp() OVERRIDE { | |
| 30 queue_.reset(new GestureEventQueue(this)); | |
| 31 } | |
| 32 | |
| 33 virtual void TearDown() OVERRIDE { | |
| 34 queue_.reset(); | |
| 35 } | |
| 36 | |
| 37 // GestureEventQueueClient | |
| 38 virtual void ForwardGestureEvent(const WebGestureEvent& event) OVERRIDE { | |
| 39 ++sent_gesture_count_; | |
| 40 sent_gestures_.push_back(event.type); | |
| 41 } | |
| 42 | |
| 43 protected: | |
| 44 typedef std::vector<WebInputEvent::Type> GestureList; | |
| 45 | |
| 46 ::testing::AssertionResult GesturesMatch(const GestureList& expected, | |
| 47 const GestureList& actual) { | |
| 48 if (expected.size() != actual.size()) { | |
| 49 return ::testing::AssertionFailure() | |
| 50 << "actual.size(" << actual.size() | |
| 51 << ") != expected.size(" << expected.size() << ")"; | |
| 52 } | |
| 53 | |
| 54 for (size_t i = 0; i < expected.size(); ++i) { | |
| 55 if (expected[i] != actual[i]) { | |
| 56 return ::testing::AssertionFailure() | |
| 57 << "actual[" << i << "] (" | |
| 58 << WebInputEventTraits::GetName(actual[i]) | |
| 59 << ") != expected[" << i << "] (" | |
| 60 << WebInputEventTraits::GetName(expected[i]) << ")"; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 return ::testing::AssertionSuccess(); | |
| 65 } | |
| 66 | |
| 67 GestureList Gestures(WebInputEvent::Type type) { | |
| 68 return GestureList(1, type); | |
| 69 } | |
| 70 | |
| 71 GestureList Gestures(WebInputEvent::Type type0, WebInputEvent::Type type1) { | |
| 72 GestureList gestures(2); | |
| 73 gestures[0] = type0; | |
| 74 gestures[1] = type1; | |
| 75 return gestures; | |
| 76 } | |
| 77 | |
| 78 GestureList Gestures(WebInputEvent::Type type0, | |
| 79 WebInputEvent::Type type1, | |
| 80 WebInputEvent::Type type2) { | |
| 81 GestureList gestures(3); | |
| 82 gestures[0] = type0; | |
| 83 gestures[1] = type1; | |
| 84 gestures[2] = type2; | |
| 85 return gestures; | |
| 86 } | |
| 87 | |
| 88 GestureList Gestures(WebInputEvent::Type type0, | |
| 89 WebInputEvent::Type type1, | |
| 90 WebInputEvent::Type type2, | |
| 91 WebInputEvent::Type type3) { | |
| 92 GestureList gestures(4); | |
| 93 gestures[0] = type0; | |
| 94 gestures[1] = type1; | |
| 95 gestures[2] = type2; | |
| 96 gestures[3] = type3; | |
| 97 return gestures; | |
| 98 } | |
| 99 | |
| 100 void SendTouchGestures() { | |
| 101 GestureEventPacket gesture_packet; | |
| 102 std::swap(gesture_packet, gesture_packet_); | |
| 103 SendTouchGestures(touch_event_, gesture_packet); | |
| 104 touch_event_.ResetPoints(); | |
| 105 } | |
| 106 | |
| 107 void SendTouchGestures(const WebTouchEvent& touch, | |
| 108 const GestureEventPacket& packet) { | |
| 109 GestureEventPacket touch_packet = GestureEventPacket::FromTouch(touch); | |
| 110 for (size_t i = 0; i < packet.gesture_count(); ++i) | |
| 111 touch_packet.Push(packet.gesture(i)); | |
| 112 queue_->OnGestureEventPacket(touch_packet); | |
| 113 } | |
| 114 | |
| 115 void SendGesture(GestureEventPacket::GestureSource source, | |
| 116 const WebGestureEvent& gesture) { | |
| 117 queue_->OnGestureEventPacket( | |
| 118 GestureEventPacket::FromGesture(source, gesture)); | |
| 119 } | |
| 120 | |
| 121 void SendTimeoutGesture(WebInputEvent::Type type) { | |
| 122 DCHECK(WebInputEvent::isGestureEventType(type)); | |
| 123 SendGesture(GestureEventPacket::TOUCH_TIMEOUT, CreateGesture(type)); | |
| 124 } | |
| 125 | |
| 126 void SendSyntheticGesture(WebInputEvent::Type type) { | |
| 127 DCHECK(WebInputEvent::isGestureEventType(type)); | |
| 128 SendGesture(GestureEventPacket::SYNTHETIC, CreateGesture(type)); | |
| 129 } | |
| 130 | |
| 131 void SendTouchEventACK(InputEventAckState ack_result) { | |
| 132 queue_->OnTouchEventAck(ack_result); | |
| 133 } | |
| 134 | |
| 135 void PushGesture(WebInputEvent::Type type) { | |
| 136 DCHECK(WebInputEvent::isGestureEventType(type)); | |
| 137 PushGestureImpl(CreateGesture(type)); | |
| 138 } | |
| 139 | |
| 140 void PressTouchPoint(int x, int y) { | |
| 141 touch_event_.PressPoint(x, y); | |
| 142 SendTouchGestures(); | |
| 143 } | |
| 144 | |
| 145 void MoveTouchPoint(int index, int x, int y) { | |
| 146 touch_event_.MovePoint(index, x, y); | |
| 147 SendTouchGestures(); | |
| 148 } | |
| 149 | |
| 150 void MoveTouchPoints(int index0, int x0, int y0, int index1, int x1, int y1) { | |
|
tdresser
2014/01/24 13:47:30
Unused, and probably unnecessary.
jdduke (slow)
2014/01/24 18:17:35
Done.
| |
| 151 touch_event_.MovePoint(index0, x0, y0); | |
| 152 touch_event_.MovePoint(index1, x1, y1); | |
| 153 SendTouchGestures(); | |
| 154 } | |
| 155 | |
| 156 void ReleaseTouchPoint(int index) { | |
| 157 touch_event_.ReleasePoint(index); | |
| 158 SendTouchGestures(); | |
| 159 } | |
| 160 | |
| 161 void CancelTouchPoint(int index) { | |
| 162 touch_event_.CancelPoint(index); | |
| 163 SendTouchGestures(); | |
| 164 } | |
| 165 | |
| 166 bool GesturesSent() const { | |
| 167 return !sent_gestures_.empty(); | |
| 168 } | |
| 169 | |
| 170 GestureList GetAndResetSentGestures() { | |
| 171 GestureList sent_gestures; | |
| 172 sent_gestures.swap(sent_gestures_); | |
| 173 return sent_gestures; | |
| 174 } | |
| 175 | |
| 176 static WebGestureEvent CreateGesture(WebInputEvent::Type type) { | |
| 177 return SyntheticWebGestureEventBuilder::Build( | |
| 178 type, WebGestureEvent::Touchscreen); | |
| 179 } | |
| 180 | |
| 181 private: | |
| 182 void PushGestureImpl(const WebGestureEvent& gesture) { | |
|
tdresser
2014/01/24 13:47:30
Do we need a separate method for this?
jdduke (slow)
2014/01/24 18:17:35
Absolutely not.
| |
| 183 gesture_packet_.Push(gesture); | |
| 184 } | |
| 185 | |
| 186 scoped_ptr<GestureEventQueue> queue_; | |
| 187 SyntheticWebTouchEvent touch_event_; | |
| 188 GestureEventPacket gesture_packet_; | |
| 189 size_t sent_gesture_count_; | |
| 190 GestureList sent_gestures_; | |
| 191 }; | |
| 192 | |
| 193 TEST_F(GestureEventQueueTest, BasicNoGestures) { | |
| 194 PressTouchPoint(1, 1); | |
| 195 EXPECT_FALSE(GesturesSent()); | |
| 196 | |
| 197 MoveTouchPoint(0, 2, 2); | |
| 198 EXPECT_FALSE(GesturesSent()); | |
| 199 | |
| 200 // No gestures should be dispatched by the ack, as the queued packets | |
| 201 // contained no gestures. | |
| 202 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 203 EXPECT_FALSE(GesturesSent()); | |
| 204 | |
| 205 // Release the touch gesture. | |
| 206 ReleaseTouchPoint(0); | |
| 207 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 208 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 209 EXPECT_FALSE(GesturesSent()); | |
| 210 } | |
| 211 | |
| 212 TEST_F(GestureEventQueueTest, BasicGestures) { | |
| 213 // An unconsumed touch's gesture should be sent. | |
| 214 PushGesture(WebInputEvent::GestureScrollBegin); | |
| 215 PressTouchPoint(1, 1); | |
| 216 EXPECT_FALSE(GesturesSent()); | |
| 217 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 218 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin), | |
| 219 GetAndResetSentGestures())); | |
| 220 | |
| 221 // Multiple gestures can be queued for a single event. | |
| 222 PushGesture(WebInputEvent::GestureFlingStart); | |
| 223 PushGesture(WebInputEvent::GestureFlingCancel); | |
| 224 MoveTouchPoint(0, 1, 1); | |
| 225 EXPECT_FALSE(GesturesSent()); | |
| 226 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 227 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, | |
| 228 WebInputEvent::GestureFlingCancel), | |
| 229 GetAndResetSentGestures())); | |
| 230 | |
| 231 // A consumed touch's gesture should not be sent. | |
| 232 PushGesture(WebInputEvent::GestureFlingStart); | |
| 233 PushGesture(WebInputEvent::GestureFlingCancel); | |
| 234 ReleaseTouchPoint(0); | |
| 235 EXPECT_FALSE(GesturesSent()); | |
| 236 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 237 EXPECT_FALSE(GesturesSent()); | |
| 238 } | |
| 239 | |
| 240 TEST_F(GestureEventQueueTest, ConsumedThenNotConsumed) { | |
| 241 // A consumed touch's gesture should not be sent. | |
| 242 PushGesture(WebInputEvent::GestureScrollBegin); | |
| 243 PressTouchPoint(1, 1); | |
| 244 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 245 EXPECT_FALSE(GesturesSent()); | |
| 246 | |
| 247 // Event if the subsequent touch is not consumed, continue dropping gestures. | |
|
tdresser
2014/01/24 13:47:30
Event if -> Even if?
jdduke (slow)
2014/01/24 18:17:35
Done.
| |
| 248 PushGesture(WebInputEvent::GestureScrollUpdate); | |
| 249 MoveTouchPoint(0, 2, 2); | |
| 250 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 251 EXPECT_FALSE(GesturesSent()); | |
| 252 | |
| 253 // Event if the subsequent touch had no consumer, continue dropping gestures. | |
|
tdresser
2014/01/24 13:47:30
As above.
jdduke (slow)
2014/01/24 18:17:35
Done.
| |
| 254 PushGesture(WebInputEvent::GestureFlingStart); | |
| 255 ReleaseTouchPoint(0); | |
| 256 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 257 EXPECT_FALSE(GesturesSent()); | |
| 258 } | |
| 259 | |
| 260 TEST_F(GestureEventQueueTest, NotConsumedThenNoConsumer) { | |
| 261 // An unconsumed touch's gesture should be sent. | |
| 262 PushGesture(WebInputEvent::GestureScrollBegin); | |
| 263 PressTouchPoint(1, 1); | |
| 264 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 265 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin), | |
| 266 GetAndResetSentGestures())); | |
| 267 | |
| 268 // If the subsequent touch has no consumer (e.g., a secondary pointer is | |
| 269 // pressed but not on a touch handling rect), send the gesture. | |
| 270 PushGesture(WebInputEvent::GesturePinchBegin); | |
| 271 PressTouchPoint(2, 2); | |
| 272 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 273 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin), | |
| 274 GetAndResetSentGestures())); | |
| 275 | |
| 276 // If the subsequent touch is consumed, then the remaining gesture sequence | |
| 277 // should be dropped, regardless of subsequent touch ack disposition. | |
| 278 PushGesture(WebInputEvent::GestureScrollUpdate); | |
| 279 PushGesture(WebInputEvent::GesturePinchUpdate); | |
| 280 MoveTouchPoint(0, 2, 2); | |
| 281 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 282 EXPECT_FALSE(GesturesSent()); | |
| 283 | |
| 284 PushGesture(WebInputEvent::GesturePinchEnd); | |
| 285 ReleaseTouchPoint(1); | |
| 286 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 287 EXPECT_FALSE(GesturesSent()); | |
| 288 | |
| 289 PushGesture(WebInputEvent::GestureScrollEnd); | |
| 290 ReleaseTouchPoint(0); | |
| 291 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 292 EXPECT_FALSE(GesturesSent()); | |
| 293 } | |
| 294 | |
| 295 TEST_F(GestureEventQueueTest, MultipleTouchSequences) { | |
| 296 // Queue two touch-to-gestures sequences. | |
| 297 PushGesture(WebInputEvent::GestureFlingStart); | |
| 298 PressTouchPoint(1, 1); | |
| 299 PushGesture(WebInputEvent::GestureFlingCancel); | |
| 300 ReleaseTouchPoint(0); | |
| 301 PushGesture(WebInputEvent::GestureFlingStart); | |
| 302 PressTouchPoint(1, 1); | |
| 303 PushGesture(WebInputEvent::GestureFlingCancel); | |
| 304 ReleaseTouchPoint(0); | |
| 305 | |
| 306 // The first gesture sequence should not be allowed. | |
| 307 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 308 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 309 EXPECT_FALSE(GesturesSent()); | |
| 310 | |
| 311 // The subsequent sequence should "reset" allowance. | |
| 312 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 313 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 314 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, | |
| 315 WebInputEvent::GestureFlingCancel), | |
| 316 GetAndResetSentGestures())); | |
| 317 } | |
| 318 | |
| 319 TEST_F(GestureEventQueueTest, FlingCancelledOnNewTouchSequence) { | |
| 320 // Simulate a fling start that is sent. | |
| 321 PressTouchPoint(1, 1); | |
| 322 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 323 PushGesture(WebInputEvent::GestureFlingStart); | |
| 324 ReleaseTouchPoint(0); | |
| 325 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 326 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart), | |
| 327 GetAndResetSentGestures())); | |
| 328 | |
| 329 // A new touch seqeuence should cancel the outstanding fling. | |
| 330 PressTouchPoint(1, 1); | |
| 331 ReleaseTouchPoint(0); | |
| 332 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 333 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel), | |
| 334 GetAndResetSentGestures())); | |
| 335 } | |
| 336 | |
| 337 TEST_F(GestureEventQueueTest, FlingCancelledOnScrollBegin) { | |
| 338 // Simulate a synthetic fling. | |
| 339 SendSyntheticGesture(WebInputEvent::GestureScrollBegin); | |
| 340 SendSyntheticGesture(WebInputEvent::GestureFlingStart); | |
| 341 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureScrollBegin, | |
| 342 WebInputEvent::GestureFlingStart), | |
| 343 GetAndResetSentGestures())); | |
| 344 | |
| 345 // The new synthetic fling should cancel the preceding one. | |
| 346 SendSyntheticGesture(WebInputEvent::GestureScrollBegin); | |
| 347 SendSyntheticGesture(WebInputEvent::GestureFlingStart); | |
| 348 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingCancel, | |
| 349 WebInputEvent::GestureScrollBegin, | |
| 350 WebInputEvent::GestureFlingStart), | |
| 351 GetAndResetSentGestures())); | |
| 352 } | |
| 353 | |
| 354 TEST_F(GestureEventQueueTest, FlingNotCancelledIfGFCEventReceived) { | |
| 355 // Simulate a fling that is started then cancelled. | |
| 356 PushGesture(WebInputEvent::GestureFlingStart); | |
| 357 PressTouchPoint(1, 1); | |
| 358 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 359 PushGesture(WebInputEvent::GestureFlingCancel); | |
| 360 ReleaseTouchPoint(0); | |
| 361 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 362 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, | |
| 363 WebInputEvent::GestureFlingCancel), | |
| 364 GetAndResetSentGestures())); | |
| 365 | |
| 366 // A new touch sequence will not inject a GestureFlingCancel, as the fling | |
| 367 // has already been cancelled. | |
| 368 PressTouchPoint(1, 1); | |
| 369 ReleaseTouchPoint(0); | |
| 370 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 371 EXPECT_FALSE(GesturesSent()); | |
| 372 } | |
| 373 | |
| 374 TEST_F(GestureEventQueueTest, TapCancelledWhenScrollBegins) { | |
| 375 PushGesture(WebInputEvent::GestureTapDown); | |
| 376 PressTouchPoint(1, 1); | |
| 377 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 378 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown), | |
| 379 GetAndResetSentGestures())); | |
| 380 | |
| 381 // If the subsequent touch turns into a scroll, the tap should be cancelled. | |
| 382 PushGesture(WebInputEvent::GestureScrollBegin); | |
| 383 MoveTouchPoint(0, 2, 2); | |
| 384 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 385 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapCancel, | |
| 386 WebInputEvent::GestureScrollBegin), | |
| 387 GetAndResetSentGestures())); | |
| 388 } | |
| 389 | |
| 390 TEST_F(GestureEventQueueTest, TapCancelledWhenTouchConsumed) { | |
| 391 PushGesture(WebInputEvent::GestureTapDown); | |
| 392 PressTouchPoint(1, 1); | |
| 393 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 394 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown), | |
| 395 GetAndResetSentGestures())); | |
| 396 | |
| 397 // If the subsequent touch is consumed, the tap should be cancelled. | |
| 398 PushGesture(WebInputEvent::GestureScrollBegin); | |
| 399 MoveTouchPoint(0, 2, 2); | |
| 400 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 401 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapCancel), | |
| 402 GetAndResetSentGestures())); | |
| 403 } | |
| 404 | |
| 405 TEST_F(GestureEventQueueTest, TapNotCancelledIfTapEndingEventReceived) { | |
| 406 PushGesture(WebInputEvent::GestureTapDown); | |
| 407 PressTouchPoint(1, 1); | |
| 408 PressTouchPoint(2, 2); | |
| 409 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 410 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 411 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTapDown), | |
| 412 GetAndResetSentGestures())); | |
| 413 | |
| 414 PushGesture(WebInputEvent::GestureTap); | |
| 415 ReleaseTouchPoint(1); | |
| 416 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 417 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureTap), | |
| 418 GetAndResetSentGestures())); | |
| 419 | |
| 420 // The tap should not be cancelled as it was terminated by a |GestureTap|. | |
| 421 ReleaseTouchPoint(0); | |
| 422 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 423 EXPECT_FALSE(GesturesSent()); | |
| 424 } | |
| 425 | |
| 426 TEST_F(GestureEventQueueTest, TimeoutGestures) { | |
| 427 // If the sequence is allowed, and there are no preceding gestures, the | |
| 428 // timeout gestures should be forwarded immediately. | |
| 429 PressTouchPoint(1, 1); | |
| 430 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 431 EXPECT_FALSE(GesturesSent()); | |
| 432 | |
| 433 SendTimeoutGesture(WebInputEvent::GestureShowPress); | |
| 434 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureShowPress), | |
| 435 GetAndResetSentGestures())); | |
| 436 | |
| 437 SendTimeoutGesture(WebInputEvent::GestureLongPress); | |
| 438 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureLongPress), | |
| 439 GetAndResetSentGestures())); | |
| 440 | |
| 441 ReleaseTouchPoint(0); | |
| 442 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 443 | |
| 444 // If the sequence is disallowed, and there are no preceding gestures, the | |
| 445 // timeout gestures should be dropped immediately. | |
| 446 PressTouchPoint(1, 1); | |
| 447 SendTouchEventACK(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 448 EXPECT_FALSE(GesturesSent()); | |
| 449 | |
| 450 SendTimeoutGesture(WebInputEvent::GestureShowPress); | |
| 451 EXPECT_FALSE(GesturesSent()); | |
| 452 ReleaseTouchPoint(0); | |
| 453 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 454 | |
| 455 // If the sequence has a pending ack, the timeout gestures should | |
| 456 // remain queued until the ack is received. | |
| 457 PressTouchPoint(1, 1); | |
| 458 EXPECT_FALSE(GesturesSent()); | |
| 459 | |
| 460 SendTimeoutGesture(WebInputEvent::GestureLongPress); | |
| 461 EXPECT_FALSE(GesturesSent()); | |
| 462 | |
| 463 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 464 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureLongPress), | |
| 465 GetAndResetSentGestures())); | |
| 466 } | |
| 467 | |
| 468 TEST_F(GestureEventQueueTest, SyntheticGestures) { | |
| 469 // Synthetic gestures without an associated touch event should be | |
| 470 // forwarded immediately if there are no preceding gestures. | |
| 471 SendSyntheticGesture(WebInputEvent::GesturePinchBegin); | |
| 472 SendSyntheticGesture(WebInputEvent::GesturePinchUpdate); | |
| 473 SendSyntheticGesture(WebInputEvent::GesturePinchEnd); | |
| 474 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GesturePinchBegin, | |
| 475 WebInputEvent::GesturePinchUpdate, | |
| 476 WebInputEvent::GesturePinchEnd), | |
| 477 GetAndResetSentGestures())); | |
| 478 | |
| 479 // Queue a blocking touch gesture. | |
| 480 PushGesture(WebInputEvent::GestureFlingStart); | |
| 481 PressTouchPoint(1, 1); | |
| 482 ASSERT_FALSE(GesturesSent()); | |
| 483 | |
| 484 // Subsequent synthetic events should only be forwarded after the | |
| 485 // touch-derived gesture has been dispatched. | |
| 486 SendSyntheticGesture(WebInputEvent::GesturePinchBegin); | |
| 487 SendSyntheticGesture(WebInputEvent::GesturePinchUpdate); | |
| 488 SendSyntheticGesture(WebInputEvent::GesturePinchEnd); | |
| 489 EXPECT_FALSE(GesturesSent()); | |
| 490 | |
| 491 // Dispatching the queued gesture should unblock the synthetic gestures. | |
| 492 SendTouchEventACK(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | |
| 493 EXPECT_TRUE(GesturesMatch(Gestures(WebInputEvent::GestureFlingStart, | |
| 494 WebInputEvent::GesturePinchBegin, | |
| 495 WebInputEvent::GesturePinchUpdate, | |
| 496 WebInputEvent::GesturePinchEnd), | |
| 497 GetAndResetSentGestures())); | |
| 498 } | |
| 499 | |
| 500 } // namespace content | |
| OLD | NEW |