Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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" | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "ui/events/gesture_detection/gesture_event_params.h" | |
| 12 #include "ui/events/gesture_detection/gesture_provider.h" | |
| 13 #include "ui/events/gesture_detection/mock_motion_event.h" | |
| 14 #include "ui/events/gesture_detection/motion_event.h" | |
| 15 #include "ui/gfx/geometry/point_f.h" | |
| 16 | |
| 17 using base::TimeDelta; | |
| 18 using base::TimeTicks; | |
| 19 | |
| 20 namespace ui { | |
| 21 namespace { | |
| 22 | |
| 23 const float kFakeCoordX = 42.f; | |
| 24 const float kFakeCoordY = 24.f; | |
| 25 const TimeDelta kOneSecond = TimeDelta::FromSeconds(1); | |
| 26 const TimeDelta kFiveMilliseconds = TimeDelta::FromMilliseconds(5); | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 class GestureProviderTest : public testing::Test, public GestureProviderClient { | |
| 31 public: | |
| 32 GestureProviderTest() {} | |
| 33 virtual ~GestureProviderTest() {} | |
| 34 | |
| 35 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, | |
| 36 MotionEvent::Action action, | |
| 37 float x, | |
| 38 float y) { | |
| 39 return MockMotionEvent(action, event_time, x, y); | |
| 40 } | |
| 41 | |
| 42 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, | |
| 43 MotionEvent::Action action, | |
| 44 float x0, | |
| 45 float y0, | |
| 46 float x1, | |
| 47 float y1) { | |
| 48 return MockMotionEvent(action, event_time, x0, y0, x1, y1); | |
| 49 } | |
| 50 | |
| 51 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, | |
| 52 MotionEvent::Action action) { | |
| 53 return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY); | |
| 54 } | |
| 55 | |
| 56 // Test | |
| 57 virtual void SetUp() OVERRIDE { | |
| 58 gesture_provider_.reset(new GestureProvider(GetDefaultConfig(), this)); | |
| 59 gesture_provider_->UpdateMultiTouchSupport(false); | |
| 60 } | |
| 61 | |
| 62 virtual void TearDown() OVERRIDE { | |
| 63 gestures_.clear(); | |
| 64 gesture_provider_.reset(); | |
| 65 } | |
| 66 | |
| 67 // GestureProviderClient | |
| 68 virtual void OnGestureEvent(const GestureEventParams& gesture) OVERRIDE { | |
| 69 if (gesture.type == GESTURE_SCROLL_BEGIN) | |
| 70 active_scroll_begin_event_.reset(new GestureEventParams(gesture)); | |
| 71 gestures_.push_back(gesture); | |
| 72 } | |
| 73 | |
| 74 bool HasReceivedGesture(GestureEventType type) const { | |
| 75 for (size_t i = 0; i < gestures_.size(); ++i) { | |
| 76 if (gestures_[i].type == type) | |
| 77 return true; | |
| 78 } | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 const GestureEventParams& GetMostRecentGestureEvent() const { | |
| 83 EXPECT_FALSE(gestures_.empty()); | |
| 84 return gestures_.back(); | |
| 85 } | |
| 86 | |
| 87 const GestureEventType GetMostRecentGestureEventType() const { | |
| 88 EXPECT_FALSE(gestures_.empty()); | |
| 89 return gestures_.back().type; | |
| 90 } | |
| 91 | |
| 92 size_t GetReceivedGestureCount() const { return gestures_.size(); } | |
| 93 | |
| 94 const GestureEventParams& GetReceivedGesture(size_t index) const { | |
| 95 EXPECT_LT(index, GetReceivedGestureCount()); | |
| 96 return gestures_[index]; | |
| 97 } | |
| 98 | |
| 99 const GestureEventParams* GetActiveScrollBeginEvent() const { | |
| 100 return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL; | |
| 101 } | |
| 102 | |
| 103 const GestureProvider::Config& GetDefaultConfig() const { | |
| 104 static GestureProvider::Config sConfig; | |
| 105 return sConfig; | |
| 106 } | |
| 107 | |
| 108 int GetTouchSlop() const { | |
| 109 return GetDefaultConfig().gesture_detector_config.scaled_touch_slop; | |
| 110 } | |
| 111 | |
| 112 base::TimeDelta GetLongPressTimeout() const { | |
| 113 return GetDefaultConfig().gesture_detector_config.longpress_timeout; | |
| 114 } | |
| 115 | |
| 116 base::TimeDelta GetShowPressTimeout() const { | |
| 117 return GetDefaultConfig().gesture_detector_config.tap_timeout; | |
| 118 } | |
| 119 | |
| 120 protected: | |
| 121 void CheckScrollEventSequenceForendActionType( | |
|
tdresser
2014/02/20 19:11:24
ForendAction -> ForEndAction
jdduke (slow)
2014/02/21 02:31:56
Done.
| |
| 122 MotionEvent::Action end_action_type) { | |
| 123 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 124 const int scroll_to_x = kFakeCoordX + 100; | |
| 125 const int scroll_to_y = kFakeCoordY + 100; | |
| 126 | |
| 127 MockMotionEvent event = | |
| 128 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 129 | |
| 130 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 131 | |
| 132 event = ObtainMotionEvent(event_time + kOneSecond, | |
| 133 MotionEvent::ACTION_MOVE, | |
| 134 scroll_to_x, | |
| 135 scroll_to_y); | |
| 136 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 137 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | |
| 138 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 139 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 140 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, " | |
| 141 "ScrollBegin and ScrollBy " | |
| 142 "should have been sent"; | |
| 143 | |
| 144 EXPECT_EQ(GESTURE_TAP_CANCEL, GetReceivedGesture(1).type); | |
| 145 EXPECT_EQ(GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); | |
| 146 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time) | |
| 147 << "ScrollBegin should have the time of the ACTION_MOVE"; | |
| 148 | |
| 149 event = ObtainMotionEvent( | |
| 150 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); | |
| 151 gesture_provider_->OnTouchEvent(event); | |
| 152 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | |
| 153 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_END)); | |
| 154 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 155 } | |
| 156 | |
| 157 static void Wait(base::TimeDelta delay) { | |
| 158 base::MessageLoop::current()->PostDelayedTask( | |
| 159 FROM_HERE, base::MessageLoop::QuitClosure(), delay); | |
| 160 base::MessageLoop::current()->Run(); | |
| 161 } | |
| 162 | |
| 163 std::vector<GestureEventParams> gestures_; | |
| 164 scoped_ptr<GestureProvider> gesture_provider_; | |
| 165 scoped_ptr<GestureEventParams> active_scroll_begin_event_; | |
| 166 base::MessageLoopForUI message_loop_; | |
| 167 }; | |
| 168 | |
| 169 // Verify that a DOWN followed shortly by an UP will trigger a single tap. | |
| 170 TEST_F(GestureProviderTest, GestureSingleTap) { | |
| 171 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 172 | |
| 173 gesture_provider_->UpdateDoubleTapSupportForPlatform(false); | |
| 174 | |
| 175 MockMotionEvent event = | |
| 176 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 177 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 178 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 179 | |
| 180 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 181 MotionEvent::ACTION_UP); | |
| 182 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 183 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType()); | |
| 184 } | |
| 185 | |
| 186 // Verify that a DOWN followed shortly by an UP will trigger | |
| 187 // a GESTURE_SINGLE_TAP_UNCONFIRMED event if double-tap is enabled. | |
| 188 TEST_F(GestureProviderTest, GestureSingleTapWithDelay) { | |
| 189 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 190 | |
| 191 gesture_provider_->UpdateDoubleTapSupportForPlatform(true); | |
| 192 | |
| 193 MockMotionEvent event = | |
| 194 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 195 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 196 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 197 | |
| 198 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 199 MotionEvent::ACTION_UP); | |
| 200 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 201 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 202 EXPECT_FALSE(HasReceivedGesture(GESTURE_SINGLE_TAP_CONFIRMED)); | |
| 203 } | |
| 204 | |
| 205 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). | |
| 206 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { | |
| 207 base::TimeTicks event_time = TimeTicks::Now(); | |
| 208 | |
| 209 MockMotionEvent event = | |
| 210 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 211 | |
| 212 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 213 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 214 | |
| 215 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 216 MotionEvent::ACTION_MOVE, | |
| 217 kFakeCoordX * 10, | |
| 218 kFakeCoordY * 10); | |
| 219 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 220 | |
| 221 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 222 MotionEvent::ACTION_UP, | |
| 223 kFakeCoordX * 10, | |
| 224 kFakeCoordY * 10); | |
| 225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 226 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType()); | |
| 227 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS)); | |
| 228 } | |
| 229 | |
| 230 // Verify that for a normal scroll the following events are sent: | |
| 231 // - GESTURE_SCROLL_BEGIN | |
| 232 // - GESTURE_SCROLL_UPDATE | |
| 233 // - GESTURE_SCROLL_END | |
| 234 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { | |
| 235 CheckScrollEventSequenceForendActionType(MotionEvent::ACTION_UP); | |
| 236 } | |
| 237 | |
| 238 // Verify that for a cancelled scroll the following events are sent: | |
| 239 // - GESTURE_SCROLL_BEGIN | |
| 240 // - GESTURE_SCROLL_UPDATE | |
| 241 // - GESTURE_SCROLL_END | |
| 242 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) { | |
| 243 CheckScrollEventSequenceForendActionType(MotionEvent::ACTION_CANCEL); | |
| 244 } | |
| 245 | |
| 246 // Verify that for a normal fling (fling after scroll) the following events are | |
| 247 // sent: | |
| 248 // - GESTURE_SCROLL_BEGIN | |
| 249 // - GESTURE_FLING_START | |
| 250 TEST_F(GestureProviderTest, FlingEventSequence) { | |
| 251 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 252 | |
| 253 MockMotionEvent event = | |
| 254 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 255 | |
| 256 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 257 | |
| 258 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 259 MotionEvent::ACTION_MOVE, | |
| 260 kFakeCoordX * 5, | |
| 261 kFakeCoordY * 5); | |
| 262 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 263 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | |
| 264 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 265 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 266 ASSERT_EQ(4U, GetReceivedGestureCount()); | |
| 267 ASSERT_EQ(GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); | |
| 268 | |
| 269 // We don't want to take a dependency here on exactly how hints are calculated | |
| 270 // for a fling (eg. may depend on velocity), so just validate the direction. | |
| 271 int hint_x = GetReceivedGesture(2).data.scroll_begin.delta_x_hint; | |
| 272 int hint_y = GetReceivedGesture(2).data.scroll_begin.delta_y_hint; | |
| 273 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) | |
| 274 << "ScrollBegin hint should be in positive X axis"; | |
| 275 | |
| 276 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | |
| 277 MotionEvent::ACTION_UP, | |
| 278 kFakeCoordX * 10, | |
| 279 kFakeCoordY * 10); | |
| 280 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 281 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | |
| 282 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType()); | |
| 283 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END)); | |
| 284 EXPECT_EQ(event_time + kFiveMilliseconds * 3, | |
| 285 GetMostRecentGestureEvent().time) | |
| 286 << "FlingStart should have the time of the ACTION_UP"; | |
| 287 } | |
| 288 | |
| 289 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) { | |
| 290 const base::TimeTicks event_time = TimeTicks::Now(); | |
| 291 | |
| 292 MockMotionEvent event = | |
| 293 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 294 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 295 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 296 | |
| 297 Wait(GetShowPressTimeout() + kFiveMilliseconds); | |
| 298 EXPECT_EQ(GESTURE_SHOW_PRESS, GetMostRecentGestureEventType()); | |
| 299 | |
| 300 Wait(GetLongPressTimeout() + kFiveMilliseconds); | |
| 301 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | |
| 302 | |
| 303 // The long press triggers window focus loss by opening a context menu | |
| 304 gesture_provider_->CancelActiveTouchSequence(); | |
| 305 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | |
| 306 } | |
| 307 | |
| 308 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) { | |
| 309 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 310 | |
| 311 MockMotionEvent event = | |
| 312 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 313 | |
| 314 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 315 | |
| 316 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 317 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 318 MotionEvent::ACTION_MOVE, | |
| 319 kFakeCoordX + 50, | |
| 320 kFakeCoordY + 50); | |
| 321 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 322 | |
| 323 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 324 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL)); | |
| 325 | |
| 326 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 327 MotionEvent::ACTION_UP, | |
| 328 kFakeCoordX + 100, | |
| 329 kFakeCoordY + 100); | |
| 330 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 331 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType()); | |
| 332 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END)); | |
| 333 } | |
| 334 | |
| 335 TEST_F(GestureProviderTest, DoubleTap) { | |
| 336 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 337 | |
| 338 MockMotionEvent event = | |
| 339 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 340 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 341 | |
| 342 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 343 | |
| 344 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 345 MotionEvent::ACTION_UP, | |
| 346 kFakeCoordX, | |
| 347 kFakeCoordY); | |
| 348 gesture_provider_->OnTouchEvent(event); | |
| 349 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 350 | |
| 351 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 352 MotionEvent::ACTION_DOWN, | |
| 353 kFakeCoordX, | |
| 354 kFakeCoordY); | |
| 355 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 356 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 357 | |
| 358 // Moving a very small amount of distance should not trigger the double tap | |
| 359 // drag zoom mode. | |
| 360 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | |
| 361 MotionEvent::ACTION_MOVE, | |
| 362 kFakeCoordX, | |
| 363 kFakeCoordY + 1); | |
| 364 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 365 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 366 | |
| 367 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | |
| 368 MotionEvent::ACTION_UP, | |
| 369 kFakeCoordX, | |
| 370 kFakeCoordY + 1); | |
| 371 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 372 EXPECT_EQ(GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType()); | |
| 373 } | |
| 374 | |
| 375 TEST_F(GestureProviderTest, DoubleTapDragZoom) { | |
| 376 const base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 377 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20; | |
| 378 | |
| 379 MockMotionEvent event = | |
| 380 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 381 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 382 | |
| 383 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 384 MotionEvent::ACTION_UP, | |
| 385 kFakeCoordX, | |
| 386 kFakeCoordY); | |
| 387 gesture_provider_->OnTouchEvent(event); | |
| 388 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 389 | |
| 390 event = ObtainMotionEvent( | |
| 391 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 392 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 393 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 394 | |
| 395 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds, | |
| 396 MotionEvent::ACTION_MOVE, | |
| 397 kFakeCoordX, | |
| 398 kFakeCoordY + 100); | |
| 399 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 400 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 401 const GestureEventParams* scroll_begin_gesture = GetActiveScrollBeginEvent(); | |
| 402 ASSERT_TRUE(!!scroll_begin_gesture); | |
| 403 EXPECT_EQ(0, scroll_begin_gesture->data.scroll_begin.delta_x_hint); | |
| 404 EXPECT_EQ(100, scroll_begin_gesture->data.scroll_begin.delta_y_hint); | |
| 405 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 406 | |
| 407 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2, | |
| 408 MotionEvent::ACTION_MOVE, | |
| 409 kFakeCoordX, | |
| 410 kFakeCoordY + 200); | |
| 411 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 412 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE)); | |
| 413 EXPECT_EQ(GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); | |
| 414 | |
| 415 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3, | |
| 416 MotionEvent::ACTION_UP, | |
| 417 kFakeCoordX, | |
| 418 kFakeCoordY + 200); | |
| 419 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 420 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 421 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 422 } | |
| 423 | |
| 424 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) { | |
| 425 const base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 426 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20; | |
| 427 | |
| 428 MockMotionEvent event = | |
| 429 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 430 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 431 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 432 | |
| 433 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 434 MotionEvent::ACTION_UP); | |
| 435 gesture_provider_->OnTouchEvent(event); | |
| 436 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 437 | |
| 438 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN); | |
| 439 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 440 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 441 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL)); | |
| 442 | |
| 443 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 10, | |
| 444 MotionEvent::ACTION_MOVE, | |
| 445 kFakeCoordX, | |
| 446 kFakeCoordY - 30); | |
| 447 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 448 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 449 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 450 | |
| 451 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 20, | |
| 452 MotionEvent::ACTION_POINTER_DOWN, | |
| 453 kFakeCoordX, | |
| 454 kFakeCoordY - 30, | |
| 455 kFakeCoordX + 50, | |
| 456 kFakeCoordY + 50); | |
| 457 gesture_provider_->OnTouchEvent(event); | |
| 458 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 459 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 460 const size_t gesture_count = GetReceivedGestureCount(); | |
| 461 | |
| 462 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 30, | |
| 463 MotionEvent::ACTION_POINTER_UP, | |
| 464 kFakeCoordX, | |
| 465 kFakeCoordY - 30, | |
| 466 kFakeCoordX + 50, | |
| 467 kFakeCoordY + 50); | |
| 468 gesture_provider_->OnTouchEvent(event); | |
| 469 EXPECT_EQ(gesture_count, GetReceivedGestureCount()); | |
| 470 } | |
| 471 | |
| 472 // Generate a scroll gesture and verify that the resulting scroll motion event | |
| 473 // has both absolute and relative position information. | |
| 474 TEST_F(GestureProviderTest, ScrollUpdateValues) { | |
| 475 const int delta_x = 16; | |
| 476 const int delta_y = 84; | |
| 477 | |
| 478 const base::TimeTicks event_time = TimeTicks::Now(); | |
| 479 | |
| 480 MockMotionEvent event = | |
| 481 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 482 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 483 | |
| 484 // Move twice so that we get two GESTURE_SCROLL_UPDATE events and can compare | |
| 485 // the relative and absolute coordinates. | |
| 486 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 487 MotionEvent::ACTION_MOVE, | |
| 488 kFakeCoordX - delta_x / 2, | |
| 489 kFakeCoordY - delta_y / 2); | |
| 490 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 491 | |
| 492 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 493 MotionEvent::ACTION_MOVE, | |
| 494 kFakeCoordX - delta_x, | |
| 495 kFakeCoordY - delta_y); | |
| 496 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 497 | |
| 498 // Make sure the reported gesture event has all the expected data. | |
| 499 ASSERT_LT(0U, GetReceivedGestureCount()); | |
| 500 GestureEventParams gesture = GetMostRecentGestureEvent(); | |
| 501 EXPECT_EQ(GESTURE_SCROLL_UPDATE, gesture.type); | |
| 502 EXPECT_EQ(event_time + kFiveMilliseconds * 2, gesture.time); | |
| 503 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); | |
| 504 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); | |
| 505 | |
| 506 // No horizontal delta because of snapping. | |
| 507 EXPECT_EQ(0, gesture.data.scroll_update.delta_x); | |
| 508 EXPECT_EQ(-delta_y / 2, gesture.data.scroll_update.delta_y); | |
| 509 } | |
| 510 | |
| 511 // Generate a scroll gesture and verify that the resulting scroll begin event | |
| 512 // has the expected hint values. | |
| 513 TEST_F(GestureProviderTest, ScrollBeginValues) { | |
| 514 const int delta_x = 13; | |
| 515 const int delta_y = 89; | |
| 516 | |
| 517 const base::TimeTicks event_time = TimeTicks::Now(); | |
| 518 | |
| 519 MockMotionEvent event = | |
| 520 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 521 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 522 | |
| 523 // Move twice such that the first event isn't sufficient to start | |
| 524 // scrolling on it's own. | |
| 525 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 526 MotionEvent::ACTION_MOVE, | |
| 527 kFakeCoordX + 2, | |
| 528 kFakeCoordY + 1); | |
| 529 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 530 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | |
| 531 | |
| 532 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 533 MotionEvent::ACTION_MOVE, | |
| 534 kFakeCoordX + delta_x, | |
| 535 kFakeCoordY + delta_y); | |
| 536 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 537 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | |
| 538 | |
| 539 const GestureEventParams* scroll_begin_gesture = GetActiveScrollBeginEvent(); | |
| 540 ASSERT_TRUE(!!scroll_begin_gesture); | |
| 541 EXPECT_EQ(delta_x, scroll_begin_gesture->data.scroll_begin.delta_x_hint); | |
| 542 EXPECT_EQ(delta_y, scroll_begin_gesture->data.scroll_begin.delta_y_hint); | |
| 543 } | |
| 544 | |
| 545 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { | |
| 546 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 547 | |
| 548 MockMotionEvent event = | |
| 549 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 550 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 551 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 552 MotionEvent::ACTION_MOVE, | |
| 553 kFakeCoordX * 5, | |
| 554 kFakeCoordY * 5); | |
| 555 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 556 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 557 MotionEvent::ACTION_MOVE, | |
| 558 kFakeCoordX * 10, | |
| 559 kFakeCoordY * 10); | |
| 560 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 561 | |
| 562 const base::TimeDelta long_press_timeout = | |
| 563 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | |
| 564 Wait(long_press_timeout); | |
| 565 | |
| 566 // No LONG_TAP as the LONG_PRESS timer is cancelled. | |
| 567 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS)); | |
| 568 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP)); | |
| 569 } | |
| 570 | |
| 571 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP. | |
| 572 TEST_F(GestureProviderTest, GestureLongTap) { | |
| 573 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 574 | |
| 575 MockMotionEvent event = | |
| 576 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 577 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 578 | |
| 579 const base::TimeDelta long_press_timeout = | |
| 580 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | |
| 581 Wait(long_press_timeout); | |
| 582 | |
| 583 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | |
| 584 | |
| 585 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP); | |
| 586 gesture_provider_->OnTouchEvent(event); | |
| 587 EXPECT_EQ(GESTURE_LONG_TAP, GetMostRecentGestureEventType()); | |
| 588 } | |
| 589 | |
| 590 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) { | |
| 591 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 592 | |
| 593 MockMotionEvent event = | |
| 594 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 595 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 596 | |
| 597 const base::TimeDelta long_press_timeout = | |
| 598 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | |
| 599 Wait(long_press_timeout); | |
| 600 | |
| 601 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | |
| 602 event = ObtainMotionEvent(event_time + long_press_timeout, | |
| 603 MotionEvent::ACTION_MOVE, | |
| 604 kFakeCoordX + 100, | |
| 605 kFakeCoordY + 100); | |
| 606 gesture_provider_->OnTouchEvent(event); | |
| 607 | |
| 608 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 609 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 610 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL)); | |
| 611 | |
| 612 event = ObtainMotionEvent(event_time + long_press_timeout, | |
| 613 MotionEvent::ACTION_UP); | |
| 614 gesture_provider_->OnTouchEvent(event); | |
| 615 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP)); | |
| 616 } | |
| 617 | |
| 618 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { | |
| 619 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 620 | |
| 621 MockMotionEvent event = ObtainMotionEvent( | |
| 622 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 623 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 624 | |
| 625 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 626 MotionEvent::ACTION_UP, | |
| 627 kFakeCoordX, | |
| 628 kFakeCoordY); | |
| 629 gesture_provider_->OnTouchEvent(event); | |
| 630 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 631 | |
| 632 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 633 MotionEvent::ACTION_DOWN, | |
| 634 kFakeCoordX, | |
| 635 kFakeCoordY); | |
| 636 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 637 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 638 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); | |
| 639 | |
| 640 const base::TimeDelta long_press_timeout = | |
| 641 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | |
| 642 Wait(long_press_timeout); | |
| 643 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS)); | |
| 644 | |
| 645 event = ObtainMotionEvent(event_time + long_press_timeout, | |
| 646 MotionEvent::ACTION_MOVE, | |
| 647 kFakeCoordX + 20, | |
| 648 kFakeCoordY + 20); | |
| 649 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 650 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 651 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); | |
| 652 | |
| 653 event = ObtainMotionEvent(event_time + long_press_timeout + kFiveMilliseconds, | |
| 654 MotionEvent::ACTION_UP, | |
| 655 kFakeCoordX, | |
| 656 kFakeCoordY + 1); | |
| 657 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 658 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 659 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); | |
| 660 } | |
| 661 | |
| 662 // Verify that the touch slop region is removed from the first scroll delta to | |
| 663 // avoid a jump when starting to scroll. | |
| 664 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { | |
| 665 const int scaled_touch_slop = GetTouchSlop(); | |
| 666 const int scroll_delta = 5; | |
| 667 | |
| 668 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 669 | |
| 670 MockMotionEvent event = | |
| 671 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 672 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 673 | |
| 674 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 675 MotionEvent::ACTION_MOVE, | |
| 676 kFakeCoordX, | |
| 677 kFakeCoordY + scaled_touch_slop + scroll_delta); | |
| 678 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 679 | |
| 680 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 681 GestureEventParams gesture = GetMostRecentGestureEvent(); | |
| 682 EXPECT_EQ(0, gesture.data.scroll_update.delta_x); | |
| 683 EXPECT_EQ(scroll_delta, gesture.data.scroll_update.delta_y); | |
| 684 } | |
| 685 | |
| 686 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { | |
| 687 gesture_provider_->UpdateDoubleTapSupportForPlatform(false); | |
| 688 | |
| 689 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 690 MockMotionEvent event = ObtainMotionEvent( | |
| 691 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 692 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 693 EXPECT_EQ(1U, GetReceivedGestureCount()); | |
| 694 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 695 | |
| 696 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 697 MotionEvent::ACTION_UP, | |
| 698 kFakeCoordX, | |
| 699 kFakeCoordY); | |
| 700 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 701 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType()); | |
| 702 | |
| 703 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 704 MotionEvent::ACTION_DOWN, | |
| 705 kFakeCoordX, | |
| 706 kFakeCoordY); | |
| 707 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 708 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 709 | |
| 710 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | |
| 711 MotionEvent::ACTION_UP, | |
| 712 kFakeCoordX, | |
| 713 kFakeCoordY); | |
| 714 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 715 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType()); | |
| 716 } | |
| 717 | |
| 718 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) { | |
| 719 const base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 720 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20; | |
| 721 | |
| 722 gesture_provider_->UpdateDoubleTapSupportForPlatform(false); | |
| 723 | |
| 724 MockMotionEvent event = | |
| 725 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 726 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 727 | |
| 728 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 729 MotionEvent::ACTION_UP, | |
| 730 kFakeCoordX, | |
| 731 kFakeCoordY); | |
| 732 gesture_provider_->OnTouchEvent(event); | |
| 733 | |
| 734 event = ObtainMotionEvent( | |
| 735 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 736 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 737 | |
| 738 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds, | |
| 739 MotionEvent::ACTION_MOVE, | |
| 740 kFakeCoordX, | |
| 741 kFakeCoordY + 100); | |
| 742 | |
| 743 // The move should become a scroll, as doubletap drag zoom is disabled. | |
| 744 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 745 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 746 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN)); | |
| 747 | |
| 748 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2, | |
| 749 MotionEvent::ACTION_MOVE, | |
| 750 kFakeCoordX, | |
| 751 kFakeCoordY + 200); | |
| 752 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 753 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 754 EXPECT_EQ(down_time_2 + kFiveMilliseconds * 2, | |
| 755 GetMostRecentGestureEvent().time); | |
| 756 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE)); | |
| 757 | |
| 758 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3, | |
| 759 MotionEvent::ACTION_UP, | |
| 760 kFakeCoordX, | |
| 761 kFakeCoordY + 200); | |
| 762 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 763 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 764 } | |
| 765 | |
| 766 // Verify that double tap drag zoom feature is not invoked when the gesture | |
| 767 // handler is told to disable double tap gesture detection. | |
| 768 // The second tap sequence should be treated just as the first would be. | |
| 769 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) { | |
| 770 const base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 771 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20; | |
| 772 | |
| 773 gesture_provider_->UpdateDoubleTapSupportForPage(false); | |
| 774 | |
| 775 MockMotionEvent event = | |
| 776 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 777 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 778 | |
| 779 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 780 MotionEvent::ACTION_UP, | |
| 781 kFakeCoordX, | |
| 782 kFakeCoordY); | |
| 783 gesture_provider_->OnTouchEvent(event); | |
| 784 | |
| 785 event = ObtainMotionEvent( | |
| 786 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 787 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 788 | |
| 789 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds, | |
| 790 MotionEvent::ACTION_MOVE, | |
| 791 kFakeCoordX, | |
| 792 kFakeCoordY + 100); | |
| 793 | |
| 794 // The move should become a scroll, as double tap drag zoom is disabled. | |
| 795 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 796 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 797 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN)); | |
| 798 | |
| 799 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2, | |
| 800 MotionEvent::ACTION_MOVE, | |
| 801 kFakeCoordX, | |
| 802 kFakeCoordY + 200); | |
| 803 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 804 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | |
| 805 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE)); | |
| 806 | |
| 807 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3, | |
| 808 MotionEvent::ACTION_UP, | |
| 809 kFakeCoordX, | |
| 810 kFakeCoordY + 200); | |
| 811 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 812 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 813 } | |
| 814 | |
| 815 // Verify that updating double tap support during a double tap drag zoom | |
| 816 // disables double tap detection after the gesture has ended. | |
| 817 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) { | |
| 818 base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 819 base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20; | |
| 820 | |
| 821 // Start a double-tap drag gesture. | |
| 822 MockMotionEvent event = | |
| 823 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 824 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 825 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 826 MotionEvent::ACTION_UP, | |
| 827 kFakeCoordX, | |
| 828 kFakeCoordY); | |
| 829 gesture_provider_->OnTouchEvent(event); | |
| 830 event = ObtainMotionEvent( | |
| 831 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 832 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 833 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds, | |
| 834 MotionEvent::ACTION_MOVE, | |
| 835 kFakeCoordX, | |
| 836 kFakeCoordY + 100); | |
| 837 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 838 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 839 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 840 | |
| 841 // Simulate setting a fixed page scale (or a mobile viewport); | |
| 842 // this should not disrupt the current double-tap gesture. | |
| 843 gesture_provider_->UpdateDoubleTapSupportForPage(false); | |
| 844 | |
| 845 // Double tap zoom updates should continue. | |
| 846 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2, | |
| 847 MotionEvent::ACTION_MOVE, | |
| 848 kFakeCoordX, | |
| 849 kFakeCoordY + 200); | |
| 850 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 851 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE)); | |
| 852 EXPECT_EQ(GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); | |
| 853 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3, | |
| 854 MotionEvent::ACTION_UP, | |
| 855 kFakeCoordX, | |
| 856 kFakeCoordY + 200); | |
| 857 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 858 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 859 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 860 | |
| 861 // The double-tap gesture has finished, but the page scale is fixed. | |
| 862 // The same event sequence should not generate any double tap getsures. | |
| 863 gestures_.clear(); | |
| 864 down_time_1 += kFiveMilliseconds * 40; | |
| 865 down_time_2 += kFiveMilliseconds * 40; | |
| 866 | |
| 867 // Start a double-tap drag gesture. | |
| 868 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 869 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 870 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds, | |
| 871 MotionEvent::ACTION_UP, | |
| 872 kFakeCoordX, | |
| 873 kFakeCoordY); | |
| 874 gesture_provider_->OnTouchEvent(event); | |
| 875 event = ObtainMotionEvent( | |
| 876 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | |
| 877 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 878 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds, | |
| 879 MotionEvent::ACTION_MOVE, | |
| 880 kFakeCoordX, | |
| 881 kFakeCoordY + 100); | |
| 882 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 883 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 884 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN)); | |
| 885 | |
| 886 // Double tap zoom updates should not be sent. | |
| 887 // Instead, the second tap drag becomes a scroll gesture sequence. | |
| 888 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2, | |
| 889 MotionEvent::ACTION_MOVE, | |
| 890 kFakeCoordX, | |
| 891 kFakeCoordY + 200); | |
| 892 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 893 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE)); | |
| 894 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE)); | |
| 895 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3, | |
| 896 MotionEvent::ACTION_UP, | |
| 897 kFakeCoordX, | |
| 898 kFakeCoordY + 200); | |
| 899 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 900 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END)); | |
| 901 } | |
| 902 | |
| 903 // Verify that pinch zoom sends the proper event sequence. | |
| 904 TEST_F(GestureProviderTest, PinchZoom) { | |
| 905 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 906 const int scaled_touch_slop = GetTouchSlop(); | |
| 907 | |
| 908 gesture_provider_->UpdateMultiTouchSupport(true); | |
| 909 | |
| 910 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; | |
| 911 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; | |
| 912 | |
| 913 MockMotionEvent event = | |
| 914 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 915 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 916 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 917 | |
| 918 event = ObtainMotionEvent(event_time, | |
| 919 MotionEvent::ACTION_POINTER_DOWN, | |
| 920 kFakeCoordX, | |
| 921 kFakeCoordY, | |
| 922 secondary_coord_x, | |
| 923 secondary_coord_y); | |
| 924 gesture_provider_->OnTouchEvent(event); | |
| 925 EXPECT_EQ(1U, GetReceivedGestureCount()); | |
| 926 | |
| 927 secondary_coord_x += 5 * scaled_touch_slop; | |
| 928 secondary_coord_y += 5 * scaled_touch_slop; | |
| 929 | |
| 930 event = ObtainMotionEvent(event_time, | |
| 931 MotionEvent::ACTION_MOVE, | |
| 932 kFakeCoordX, | |
| 933 kFakeCoordY, | |
| 934 secondary_coord_x, | |
| 935 secondary_coord_y); | |
| 936 | |
| 937 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 938 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_BEGIN)); | |
| 939 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN)); | |
| 940 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_UPDATE)); | |
| 941 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE)); | |
| 942 | |
| 943 event = ObtainMotionEvent(event_time, | |
| 944 MotionEvent::ACTION_POINTER_UP, | |
| 945 kFakeCoordX, | |
| 946 kFakeCoordY, | |
| 947 secondary_coord_x, | |
| 948 secondary_coord_y); | |
| 949 | |
| 950 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 951 EXPECT_EQ(GESTURE_PINCH_END, GetMostRecentGestureEventType()); | |
| 952 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END)); | |
| 953 | |
| 954 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 955 gesture_provider_->OnTouchEvent(event); | |
| 956 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 957 } | |
| 958 | |
| 959 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins | |
| 960 // so LONG_PRESS and LONG_TAP won't be triggered. | |
| 961 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) { | |
| 962 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 963 | |
| 964 MockMotionEvent event = | |
| 965 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 966 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 967 | |
| 968 const base::TimeDelta long_press_timeout = | |
| 969 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | |
| 970 Wait(long_press_timeout); | |
| 971 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | |
| 972 | |
| 973 gesture_provider_->CancelActiveTouchSequence(); | |
| 974 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | |
| 975 | |
| 976 event = ObtainMotionEvent(event_time + long_press_timeout, | |
| 977 MotionEvent::ACTION_UP); | |
| 978 gesture_provider_->OnTouchEvent(event); | |
| 979 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP)); | |
| 980 } | |
| 981 | |
| 982 // Verify that ignoring the remaining touch sequence triggers proper touch and | |
| 983 // gesture cancellation. | |
| 984 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { | |
| 985 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 986 | |
| 987 gesture_provider_->CancelActiveTouchSequence(); | |
| 988 EXPECT_EQ(0U, GetReceivedGestureCount()); | |
| 989 | |
| 990 MockMotionEvent event = | |
| 991 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 992 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 993 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 994 | |
| 995 gesture_provider_->CancelActiveTouchSequence(); | |
| 996 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | |
| 997 | |
| 998 // Subsequent MotionEvent's are dropped until ACTION_DOWN. | |
| 999 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | |
| 1000 MotionEvent::ACTION_MOVE); | |
| 1001 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | |
| 1002 | |
| 1003 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | |
| 1004 MotionEvent::ACTION_UP); | |
| 1005 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | |
| 1006 | |
| 1007 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | |
| 1008 MotionEvent::ACTION_DOWN); | |
| 1009 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 1010 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 1011 } | |
| 1012 | |
| 1013 } // namespace ui | |
| OLD | NEW |