Chromium Code Reviews| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
| 12 #include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h" | |
| 13 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" | |
| 12 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
| 13 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 15 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
| 14 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 16 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 15 #include "content/common/input/synthetic_pinch_gesture_params.h" | 17 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 18 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | |
| 16 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 19 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 17 #include "content/common/input/synthetic_tap_gesture_params.h" | 20 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 18 #include "content/public/test/mock_render_process_host.h" | 21 #include "content/public/test/mock_render_process_host.h" |
| 19 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
| 20 #include "content/test/test_render_view_host.h" | 23 #include "content/test/test_render_view_host.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/WebKit/public/web/WebInputEvent.h" | 25 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 23 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
| 24 #include "ui/gfx/geometry/point_f.h" | 27 #include "ui/gfx/geometry/point_f.h" |
| 25 #include "ui/gfx/geometry/vector2d.h" | 28 #include "ui/gfx/geometry/vector2d.h" |
| 26 #include "ui/gfx/geometry/vector2d_f.h" | 29 #include "ui/gfx/geometry/vector2d_f.h" |
| 27 | 30 |
| 28 using blink::WebInputEvent; | 31 using blink::WebInputEvent; |
| 29 using blink::WebMouseEvent; | 32 using blink::WebMouseEvent; |
| 30 using blink::WebMouseWheelEvent; | 33 using blink::WebMouseWheelEvent; |
| 31 using blink::WebTouchEvent; | 34 using blink::WebTouchEvent; |
| 32 | 35 |
| 33 namespace content { | 36 namespace content { |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 const int kFlushInputRateInMs = 16; | 40 const int kFlushInputRateInMs = 16; |
| 38 const int kPointerAssumedStoppedTimeMs = 43; | 41 const int kPointerAssumedStoppedTimeMs = 43; |
| 39 const float kTouchSlopInDips = 7.0f; | 42 const float kTouchSlopInDips = 7.0f; |
| 40 const float kMinScalingSpanInDips = 27.5f; | 43 const float kMinScalingSpanInDips = 27.5f; |
| 41 | 44 |
| 45 enum TouchGestureType { TOUCH_SCROLL, TOUCH_DRAG }; | |
| 46 | |
| 42 class MockSyntheticGesture : public SyntheticGesture { | 47 class MockSyntheticGesture : public SyntheticGesture { |
| 43 public: | 48 public: |
| 44 MockSyntheticGesture(bool* finished, int num_steps) | 49 MockSyntheticGesture(bool* finished, int num_steps) |
| 45 : finished_(finished), | 50 : finished_(finished), |
| 46 num_steps_(num_steps), | 51 num_steps_(num_steps), |
| 47 step_count_(0) { | 52 step_count_(0) { |
| 48 *finished_ = false; | 53 *finished_ = false; |
| 49 } | 54 } |
| 50 ~MockSyntheticGesture() override {} | 55 ~MockSyntheticGesture() override {} |
| 51 | 56 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 108 |
| 104 bool flush_requested() const { return flush_requested_; } | 109 bool flush_requested() const { return flush_requested_; } |
| 105 void ClearFlushRequest() { flush_requested_ = false; } | 110 void ClearFlushRequest() { flush_requested_ = false; } |
| 106 | 111 |
| 107 private: | 112 private: |
| 108 bool flush_requested_; | 113 bool flush_requested_; |
| 109 | 114 |
| 110 int pointer_assumed_stopped_time_ms_; | 115 int pointer_assumed_stopped_time_ms_; |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 class MockScrollGestureTarget : public MockSyntheticGestureTarget { | 118 class MockMoveGestureTarget : public MockSyntheticGestureTarget { |
| 114 public: | 119 public: |
| 115 MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {} | 120 MockMoveGestureTarget() : total_abs_move_distance_length_(0) {} |
| 116 ~MockScrollGestureTarget() override {} | 121 ~MockMoveGestureTarget() override {} |
| 117 | 122 |
| 118 gfx::Vector2dF start_to_end_distance() const { | 123 gfx::Vector2dF start_to_end_distance() const { |
| 119 return start_to_end_distance_; | 124 return start_to_end_distance_; |
| 120 } | 125 } |
| 121 float total_abs_scroll_distance_length() const { | 126 float total_abs_move_distance_length() const { |
| 122 return total_abs_scroll_distance_length_; | 127 return total_abs_move_distance_length_; |
| 123 } | 128 } |
| 124 | 129 |
| 125 protected: | 130 protected: |
| 126 gfx::Vector2dF start_to_end_distance_; | 131 gfx::Vector2dF start_to_end_distance_; |
| 127 float total_abs_scroll_distance_length_; | 132 float total_abs_move_distance_length_; |
| 128 }; | 133 }; |
| 129 | 134 |
| 130 class MockScrollMouseTarget : public MockScrollGestureTarget { | 135 class MockScrollMouseTarget : public MockMoveGestureTarget { |
| 131 public: | 136 public: |
| 132 MockScrollMouseTarget() {} | 137 MockScrollMouseTarget() {} |
| 133 ~MockScrollMouseTarget() override {} | 138 ~MockScrollMouseTarget() override {} |
| 134 | 139 |
| 135 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 140 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 136 ASSERT_EQ(event.type, WebInputEvent::MouseWheel); | 141 ASSERT_EQ(event.type, WebInputEvent::MouseWheel); |
| 137 const WebMouseWheelEvent& mouse_wheel_event = | 142 const WebMouseWheelEvent& mouse_wheel_event = |
| 138 static_cast<const WebMouseWheelEvent&>(event); | 143 static_cast<const WebMouseWheelEvent&>(event); |
| 139 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY); | 144 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY); |
| 140 start_to_end_distance_ += delta; | 145 start_to_end_distance_ += delta; |
| 141 total_abs_scroll_distance_length_ += delta.Length(); | 146 total_abs_move_distance_length_ += delta.Length(); |
| 142 } | 147 } |
| 143 }; | 148 }; |
| 144 | 149 |
| 145 class MockScrollTouchTarget : public MockScrollGestureTarget { | 150 class MockMoveTouchTarget : public MockMoveGestureTarget { |
| 146 public: | 151 public: |
| 147 MockScrollTouchTarget() : started_(false) {} | 152 MockMoveTouchTarget() : started_(false) {} |
| 148 ~MockScrollTouchTarget() override {} | 153 ~MockMoveTouchTarget() override {} |
| 149 | 154 |
| 150 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 155 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 151 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 156 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
| 152 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 157 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
| 153 ASSERT_EQ(touch_event.touchesLength, 1U); | 158 ASSERT_EQ(touch_event.touchesLength, 1U); |
| 154 | 159 |
| 155 if (!started_) { | 160 if (!started_) { |
| 156 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); | 161 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); |
| 157 start_.SetPoint(touch_event.touches[0].position.x, | 162 start_.SetPoint(touch_event.touches[0].position.x, |
| 158 touch_event.touches[0].position.y); | 163 touch_event.touches[0].position.y); |
| 159 last_touch_point_ = start_; | 164 last_touch_point_ = start_; |
| 160 started_ = true; | 165 started_ = true; |
| 161 } else { | 166 } else { |
| 162 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); | 167 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); |
| 163 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); | 168 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); |
| 164 | 169 |
| 165 gfx::PointF touch_point(touch_event.touches[0].position.x, | 170 gfx::PointF touch_point(touch_event.touches[0].position.x, |
| 166 touch_event.touches[0].position.y); | 171 touch_event.touches[0].position.y); |
| 167 gfx::Vector2dF delta = touch_point - last_touch_point_; | 172 gfx::Vector2dF delta = touch_point - last_touch_point_; |
| 168 total_abs_scroll_distance_length_ += delta.Length(); | 173 total_abs_move_distance_length_ += delta.Length(); |
| 169 | 174 |
| 170 if (touch_event.type == WebInputEvent::TouchEnd) | 175 if (touch_event.type == WebInputEvent::TouchEnd) |
| 171 start_to_end_distance_ = touch_point - start_; | 176 start_to_end_distance_ = touch_point - start_; |
| 172 | 177 |
| 173 last_touch_point_ = touch_point; | 178 last_touch_point_ = touch_point; |
| 174 } | 179 } |
| 175 } | 180 } |
| 176 | 181 |
| 177 protected: | 182 protected: |
| 178 gfx::Point start_; | 183 gfx::Point start_; |
| 179 gfx::PointF last_touch_point_; | 184 gfx::PointF last_touch_point_; |
| 180 bool started_; | 185 bool started_; |
| 181 }; | 186 }; |
| 182 | 187 |
| 188 class MockDragMouseTarget : public MockMoveGestureTarget { | |
| 189 public: | |
| 190 MockDragMouseTarget() : started_(false) {} | |
| 191 ~MockDragMouseTarget() override {} | |
| 192 | |
| 193 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | |
| 194 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); | |
| 195 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
| 196 if (!started_) { | |
| 197 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); | |
| 198 EXPECT_EQ(mouse_event.clickCount, 1); | |
| 199 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); | |
| 200 start_.SetPoint(mouse_event.x, mouse_event.y); | |
| 201 last_mouse_point_ = start_; | |
| 202 started_ = true; | |
| 203 } else { | |
| 204 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); | |
| 205 ASSERT_NE(mouse_event.type, WebInputEvent::MouseDown); | |
| 206 | |
| 207 gfx::PointF mouse_point(mouse_event.x, mouse_event.y); | |
| 208 gfx::Vector2dF delta = mouse_point - last_mouse_point_; | |
| 209 total_abs_move_distance_length_ += delta.Length(); | |
| 210 if (mouse_event.type == WebInputEvent::MouseUp) | |
| 211 start_to_end_distance_ = mouse_point - start_; | |
| 212 last_mouse_point_ = mouse_point; | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 private: | |
| 217 bool started_; | |
| 218 gfx::PointF start_, last_mouse_point_; | |
| 219 }; | |
| 220 | |
| 183 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { | 221 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| 184 public: | 222 public: |
| 185 enum ZoomDirection { | 223 enum ZoomDirection { |
| 186 ZOOM_DIRECTION_UNKNOWN, | 224 ZOOM_DIRECTION_UNKNOWN, |
| 187 ZOOM_IN, | 225 ZOOM_IN, |
| 188 ZOOM_OUT | 226 ZOOM_OUT |
| 189 }; | 227 }; |
| 190 | 228 |
| 191 MockSyntheticPinchTouchTarget() | 229 MockSyntheticPinchTouchTarget() |
| 192 : initial_pointer_distance_(0), | 230 : initial_pointer_distance_(0), |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); | 387 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
| 350 state_ = FINISHED; | 388 state_ = FINISHED; |
| 351 break; | 389 break; |
| 352 case FINISHED: | 390 case FINISHED: |
| 353 EXPECT_FALSE(true); | 391 EXPECT_FALSE(true); |
| 354 break; | 392 break; |
| 355 } | 393 } |
| 356 } | 394 } |
| 357 }; | 395 }; |
| 358 | 396 |
| 359 class SyntheticGestureControllerTest : public testing::Test { | 397 class SyntheticGestureControllerTestBase { |
| 360 public: | 398 public: |
| 361 SyntheticGestureControllerTest() {} | 399 SyntheticGestureControllerTestBase() {} |
| 362 ~SyntheticGestureControllerTest() override {} | 400 ~SyntheticGestureControllerTestBase() {} |
| 363 | 401 |
| 364 protected: | 402 protected: |
| 365 template<typename MockGestureTarget> | 403 template<typename MockGestureTarget> |
| 366 void CreateControllerAndTarget() { | 404 void CreateControllerAndTarget() { |
| 367 target_ = new MockGestureTarget(); | 405 target_ = new MockGestureTarget(); |
| 368 controller_.reset(new SyntheticGestureController( | 406 controller_.reset(new SyntheticGestureController( |
| 369 scoped_ptr<SyntheticGestureTarget>(target_))); | 407 scoped_ptr<SyntheticGestureTarget>(target_))); |
| 370 } | 408 } |
| 371 | 409 |
| 372 void SetUp() override { | |
| 373 start_time_ = base::TimeTicks::Now(); | |
| 374 time_ = start_time_; | |
| 375 num_success_ = 0; | |
| 376 num_failure_ = 0; | |
| 377 } | |
| 378 | |
| 379 void TearDown() override { | |
| 380 controller_.reset(); | |
| 381 target_ = NULL; | |
| 382 time_ = base::TimeTicks(); | |
| 383 } | |
| 384 | |
| 385 void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) { | 410 void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) { |
| 386 controller_->QueueSyntheticGesture(gesture.Pass(), | 411 controller_->QueueSyntheticGesture( |
| 387 base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted, | 412 gesture.Pass(), |
| 413 base::Bind( | |
| 414 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, | |
| 388 base::Unretained(this))); | 415 base::Unretained(this))); |
| 389 } | 416 } |
| 390 | 417 |
| 391 void FlushInputUntilComplete() { | 418 void FlushInputUntilComplete() { |
| 392 while (target_->flush_requested()) { | 419 while (target_->flush_requested()) { |
| 393 while (target_->flush_requested()) { | 420 while (target_->flush_requested()) { |
| 394 target_->ClearFlushRequest(); | 421 target_->ClearFlushRequest(); |
| 395 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 422 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
| 396 controller_->Flush(time_); | 423 controller_->Flush(time_); |
| 397 } | 424 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 410 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } | 437 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } |
| 411 | 438 |
| 412 MockSyntheticGestureTarget* target_; | 439 MockSyntheticGestureTarget* target_; |
| 413 scoped_ptr<SyntheticGestureController> controller_; | 440 scoped_ptr<SyntheticGestureController> controller_; |
| 414 base::TimeTicks start_time_; | 441 base::TimeTicks start_time_; |
| 415 base::TimeTicks time_; | 442 base::TimeTicks time_; |
| 416 int num_success_; | 443 int num_success_; |
| 417 int num_failure_; | 444 int num_failure_; |
| 418 }; | 445 }; |
| 419 | 446 |
| 447 class SyntheticGestureControllerTest | |
| 448 : public SyntheticGestureControllerTestBase, | |
| 449 public testing::Test { | |
| 450 protected: | |
| 451 void SetUp() override { | |
| 452 start_time_ = base::TimeTicks::Now(); | |
| 453 time_ = start_time_; | |
| 454 num_success_ = 0; | |
| 455 num_failure_ = 0; | |
| 456 } | |
| 457 | |
| 458 void TearDown() override { | |
| 459 controller_.reset(); | |
| 460 target_ = NULL; | |
| 461 time_ = base::TimeTicks(); | |
| 462 } | |
| 463 }; | |
| 464 | |
| 465 class SyntheticGestureControllerTestWithParam | |
| 466 : public SyntheticGestureControllerTestBase, | |
| 467 public testing::TestWithParam<bool> { | |
| 468 protected: | |
| 469 void SetUp() override { | |
| 470 start_time_ = base::TimeTicks::Now(); | |
| 471 time_ = start_time_; | |
| 472 num_success_ = 0; | |
| 473 num_failure_ = 0; | |
| 474 } | |
| 475 | |
| 476 void TearDown() override { | |
| 477 controller_.reset(); | |
| 478 target_ = NULL; | |
| 479 time_ = base::TimeTicks(); | |
| 480 } | |
| 481 }; | |
| 482 | |
| 420 TEST_F(SyntheticGestureControllerTest, SingleGesture) { | 483 TEST_F(SyntheticGestureControllerTest, SingleGesture) { |
| 421 CreateControllerAndTarget<MockSyntheticGestureTarget>(); | 484 CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
| 422 | 485 |
| 423 bool finished = false; | 486 bool finished = false; |
| 424 scoped_ptr<MockSyntheticGesture> gesture( | 487 scoped_ptr<MockSyntheticGesture> gesture( |
| 425 new MockSyntheticGesture(&finished, 3)); | 488 new MockSyntheticGesture(&finished, 3)); |
| 426 QueueSyntheticGesture(gesture.Pass()); | 489 QueueSyntheticGesture(gesture.Pass()); |
| 427 FlushInputUntilComplete(); | 490 FlushInputUntilComplete(); |
| 428 | 491 |
| 429 EXPECT_TRUE(finished); | 492 EXPECT_TRUE(finished); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 while (target_->flush_requested()) { | 580 while (target_->flush_requested()) { |
| 518 target_->ClearFlushRequest(); | 581 target_->ClearFlushRequest(); |
| 519 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); | 582 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); |
| 520 controller_->Flush(time_); | 583 controller_->Flush(time_); |
| 521 } | 584 } |
| 522 EXPECT_EQ(1, num_success_); | 585 EXPECT_EQ(1, num_success_); |
| 523 controller_->OnDidFlushInput(); | 586 controller_->OnDidFlushInput(); |
| 524 EXPECT_EQ(2, num_success_); | 587 EXPECT_EQ(2, num_success_); |
| 525 } | 588 } |
| 526 | 589 |
| 527 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector, | 590 gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector, |
| 528 SyntheticGestureTarget* target) { | 591 SyntheticGestureTarget* target) { |
| 529 const int kTouchSlop = target->GetTouchSlopInDips(); | 592 const int kTouchSlop = target->GetTouchSlopInDips(); |
| 530 | 593 |
| 531 int x = vector.x(); | 594 int x = vector.x(); |
| 532 if (x > 0) | 595 if (x > 0) |
| 533 x += kTouchSlop; | 596 x += kTouchSlop; |
| 534 else if (x < 0) | 597 else if (x < 0) |
| 535 x -= kTouchSlop; | 598 x -= kTouchSlop; |
| 536 | 599 |
| 537 int y = vector.y(); | 600 int y = vector.y(); |
| 538 if (y > 0) | 601 if (y > 0) |
| 539 y += kTouchSlop; | 602 y += kTouchSlop; |
| 540 else if (y < 0) | 603 else if (y < 0) |
| 541 y -= kTouchSlop; | 604 y -= kTouchSlop; |
| 542 | 605 |
| 543 return gfx::Vector2d(x, y); | 606 return gfx::Vector2d(x, y); |
| 544 } | 607 } |
| 545 | 608 |
| 546 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) { | 609 void SetDefaultsForSyntheticMoveParams( |
| 547 CreateControllerAndTarget<MockScrollTouchTarget>(); | 610 SyntheticSmoothMoveGestureParams& params) { |
| 611 params.speed_in_pixels_s = 800; | |
|
Sami
2015/02/23 18:03:28
I think we should just set these defaults in the c
ssid
2015/02/23 19:10:36
Done.
| |
| 612 params.prevent_slop = false; | |
| 613 } | |
| 548 | 614 |
| 549 SyntheticSmoothScrollGestureParams params; | 615 TEST_P(SyntheticGestureControllerTestWithParam, |
| 550 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 616 SingleMoveGestureTouchVertical) { |
| 551 params.anchor.SetPoint(89, 32); | 617 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 618 | |
| 619 SyntheticSmoothMoveGestureParams params; | |
| 620 SetDefaultsForSyntheticMoveParams(params); | |
| 621 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; | |
| 622 if (GetParam() == TOUCH_DRAG) { | |
| 623 params.prevent_slop = true; | |
| 624 } | |
| 625 params.start_point.SetPoint(89, 32); | |
| 552 params.distances.push_back(gfx::Vector2d(0, 123)); | 626 params.distances.push_back(gfx::Vector2d(0, 123)); |
| 553 | 627 |
| 554 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 628 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 555 new SyntheticSmoothScrollGesture(params)); | 629 new SyntheticSmoothMoveGesture(params)); |
| 556 QueueSyntheticGesture(gesture.Pass()); | 630 QueueSyntheticGesture(gesture.Pass()); |
| 557 FlushInputUntilComplete(); | 631 FlushInputUntilComplete(); |
| 558 | 632 |
| 559 MockScrollGestureTarget* scroll_target = | 633 MockMoveGestureTarget* scroll_target = |
| 560 static_cast<MockScrollGestureTarget*>(target_); | 634 static_cast<MockMoveGestureTarget*>(target_); |
| 561 EXPECT_EQ(1, num_success_); | 635 EXPECT_EQ(1, num_success_); |
| 562 EXPECT_EQ(0, num_failure_); | 636 EXPECT_EQ(0, num_failure_); |
| 563 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), | 637 if (GetParam() == TOUCH_SCROLL) { |
| 564 scroll_target->start_to_end_distance()); | 638 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), |
| 639 scroll_target->start_to_end_distance()); | |
| 640 } else { | |
| 641 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | |
| 642 } | |
| 565 } | 643 } |
| 566 | 644 |
| 567 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) { | 645 TEST_P(SyntheticGestureControllerTestWithParam, |
| 568 CreateControllerAndTarget<MockScrollTouchTarget>(); | 646 SingleScrollGestureTouchHorizontal) { |
| 647 CreateControllerAndTarget<MockMoveTouchTarget>(); | |
| 569 | 648 |
| 570 SyntheticSmoothScrollGestureParams params; | 649 SyntheticSmoothMoveGestureParams params; |
| 571 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 650 SetDefaultsForSyntheticMoveParams(params); |
| 572 params.anchor.SetPoint(12, -23); | 651 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 652 if (GetParam() == TOUCH_DRAG) { | |
|
picksi
2015/02/23 14:24:27
This reads better now!
| |
| 653 params.prevent_slop = true; | |
| 654 } | |
| 655 params.start_point.SetPoint(12, -23); | |
| 573 params.distances.push_back(gfx::Vector2d(-234, 0)); | 656 params.distances.push_back(gfx::Vector2d(-234, 0)); |
| 574 | 657 |
| 575 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 658 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 576 new SyntheticSmoothScrollGesture(params)); | 659 new SyntheticSmoothMoveGesture(params)); |
| 577 QueueSyntheticGesture(gesture.Pass()); | 660 QueueSyntheticGesture(gesture.Pass()); |
| 578 FlushInputUntilComplete(); | 661 FlushInputUntilComplete(); |
| 579 | 662 |
| 580 MockScrollGestureTarget* scroll_target = | 663 MockMoveGestureTarget* scroll_target = |
| 581 static_cast<MockScrollGestureTarget*>(target_); | 664 static_cast<MockMoveGestureTarget*>(target_); |
| 582 EXPECT_EQ(1, num_success_); | 665 EXPECT_EQ(1, num_success_); |
| 583 EXPECT_EQ(0, num_failure_); | 666 EXPECT_EQ(0, num_failure_); |
| 584 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), | 667 if (GetParam() == TOUCH_SCROLL) { |
| 585 scroll_target->start_to_end_distance()); | 668 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), |
| 669 scroll_target->start_to_end_distance()); | |
| 670 } else { | |
| 671 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | |
| 672 } | |
| 586 } | 673 } |
| 587 | 674 |
| 588 void CheckIsWithinRangeSingle(float scroll_distance, | 675 void CheckIsWithinRangeSingle(float scroll_distance, |
| 589 int target_distance, | 676 int target_distance, |
| 590 SyntheticGestureTarget* target) { | 677 SyntheticGestureTarget* target) { |
| 591 if (target_distance > 0) { | 678 if (target_distance > 0) { |
| 592 EXPECT_LE(target_distance, scroll_distance); | 679 EXPECT_LE(target_distance, scroll_distance); |
| 593 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 680 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
| 594 } else { | 681 } else { |
| 595 EXPECT_GE(target_distance, scroll_distance); | 682 EXPECT_GE(target_distance, scroll_distance); |
| 596 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 683 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
| 597 } | 684 } |
| 598 } | 685 } |
| 599 | 686 |
| 600 void CheckSingleScrollDistanceIsWithinRange( | 687 void CheckSingleScrollDistanceIsWithinRange( |
| 601 const gfx::Vector2dF& scroll_distance, | 688 const gfx::Vector2dF& scroll_distance, |
| 602 const gfx::Vector2d& target_distance, | 689 const gfx::Vector2dF& target_distance, |
| 603 SyntheticGestureTarget* target) { | 690 SyntheticGestureTarget* target) { |
| 604 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); | 691 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); |
| 605 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); | 692 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); |
| 606 } | 693 } |
| 607 | 694 |
| 608 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { | 695 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { |
| 609 CreateControllerAndTarget<MockScrollTouchTarget>(); | 696 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 610 | 697 |
| 611 SyntheticSmoothScrollGestureParams params; | 698 SyntheticSmoothMoveGestureParams params; |
| 612 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 699 SetDefaultsForSyntheticMoveParams(params); |
| 613 params.anchor.SetPoint(0, 7); | 700 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 701 params.start_point.SetPoint(0, 7); | |
| 614 params.distances.push_back(gfx::Vector2d(413, -83)); | 702 params.distances.push_back(gfx::Vector2d(413, -83)); |
| 615 | 703 |
| 616 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 704 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 617 new SyntheticSmoothScrollGesture(params)); | 705 new SyntheticSmoothMoveGesture(params)); |
| 618 QueueSyntheticGesture(gesture.Pass()); | 706 QueueSyntheticGesture(gesture.Pass()); |
| 619 FlushInputUntilComplete(); | 707 FlushInputUntilComplete(); |
| 620 | 708 |
| 621 MockScrollGestureTarget* scroll_target = | 709 MockMoveGestureTarget* scroll_target = |
| 622 static_cast<MockScrollGestureTarget*>(target_); | 710 static_cast<MockMoveGestureTarget*>(target_); |
| 623 EXPECT_EQ(1, num_success_); | 711 EXPECT_EQ(1, num_success_); |
| 624 EXPECT_EQ(0, num_failure_); | 712 EXPECT_EQ(0, num_failure_); |
| 625 CheckSingleScrollDistanceIsWithinRange( | 713 CheckSingleScrollDistanceIsWithinRange( |
| 626 scroll_target->start_to_end_distance(), params.distances[0], target_); | 714 scroll_target->start_to_end_distance(), params.distances[0], target_); |
| 627 } | 715 } |
| 628 | 716 |
| 629 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { | 717 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { |
| 630 CreateControllerAndTarget<MockScrollTouchTarget>(); | 718 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 631 | 719 |
| 632 // Create a smooth scroll with a short distance and set the pointer assumed | 720 // Create a smooth scroll with a short distance and set the pointer assumed |
| 633 // stopped time high, so that the stopping should dominate the time the | 721 // stopped time high, so that the stopping should dominate the time the |
| 634 // gesture is active. | 722 // gesture is active. |
| 635 SyntheticSmoothScrollGestureParams params; | 723 SyntheticSmoothMoveGestureParams params; |
| 636 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 724 SetDefaultsForSyntheticMoveParams(params); |
| 637 params.anchor.SetPoint(-98, -23); | 725 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 726 params.start_point.SetPoint(-98, -23); | |
| 638 params.distances.push_back(gfx::Vector2d(21, -12)); | 727 params.distances.push_back(gfx::Vector2d(21, -12)); |
| 639 params.prevent_fling = true; | 728 params.prevent_fling = true; |
| 640 | |
| 641 target_->set_pointer_assumed_stopped_time_ms(543); | 729 target_->set_pointer_assumed_stopped_time_ms(543); |
| 642 | 730 |
| 643 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 731 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 644 new SyntheticSmoothScrollGesture(params)); | 732 new SyntheticSmoothMoveGesture(params)); |
| 645 QueueSyntheticGesture(gesture.Pass()); | 733 QueueSyntheticGesture(gesture.Pass()); |
| 646 FlushInputUntilComplete(); | 734 FlushInputUntilComplete(); |
| 647 | 735 |
| 648 MockScrollGestureTarget* scroll_target = | 736 MockMoveGestureTarget* scroll_target = |
| 649 static_cast<MockScrollGestureTarget*>(target_); | 737 static_cast<MockMoveGestureTarget*>(target_); |
| 650 EXPECT_EQ(1, num_success_); | 738 EXPECT_EQ(1, num_success_); |
| 651 EXPECT_EQ(0, num_failure_); | 739 EXPECT_EQ(0, num_failure_); |
| 652 CheckSingleScrollDistanceIsWithinRange( | 740 CheckSingleScrollDistanceIsWithinRange( |
| 653 scroll_target->start_to_end_distance(), params.distances[0], target_); | 741 scroll_target->start_to_end_distance(), params.distances[0], target_); |
| 654 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); | 742 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
| 655 } | 743 } |
| 656 | 744 |
| 657 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { | 745 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { |
| 658 CreateControllerAndTarget<MockScrollTouchTarget>(); | 746 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 659 | 747 |
| 660 // Create a smooth scroll with a short distance and set the pointer assumed | 748 // Create a smooth scroll with a short distance and set the pointer assumed |
| 661 // stopped time high. Disable 'prevent_fling' and check that the gesture | 749 // stopped time high. Disable 'prevent_fling' and check that the gesture |
| 662 // finishes without waiting before it stops. | 750 // finishes without waiting before it stops. |
| 663 SyntheticSmoothScrollGestureParams params; | 751 SyntheticSmoothMoveGestureParams params; |
| 664 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 752 SetDefaultsForSyntheticMoveParams(params); |
| 665 params.anchor.SetPoint(-89, 78); | 753 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 754 params.start_point.SetPoint(-89, 78); | |
| 666 params.distances.push_back(gfx::Vector2d(-43, 19)); | 755 params.distances.push_back(gfx::Vector2d(-43, 19)); |
| 667 params.prevent_fling = false; | 756 params.prevent_fling = false; |
| 668 | 757 |
| 669 target_->set_pointer_assumed_stopped_time_ms(543); | 758 target_->set_pointer_assumed_stopped_time_ms(543); |
| 670 | 759 |
| 671 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 760 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 672 new SyntheticSmoothScrollGesture(params)); | 761 new SyntheticSmoothMoveGesture(params)); |
| 673 QueueSyntheticGesture(gesture.Pass()); | 762 QueueSyntheticGesture(gesture.Pass()); |
| 674 FlushInputUntilComplete(); | 763 FlushInputUntilComplete(); |
| 675 | 764 |
| 676 MockScrollGestureTarget* scroll_target = | 765 MockMoveGestureTarget* scroll_target = |
| 677 static_cast<MockScrollGestureTarget*>(target_); | 766 static_cast<MockMoveGestureTarget*>(target_); |
| 678 EXPECT_EQ(1, num_success_); | 767 EXPECT_EQ(1, num_success_); |
| 679 EXPECT_EQ(0, num_failure_); | 768 EXPECT_EQ(0, num_failure_); |
| 680 CheckSingleScrollDistanceIsWithinRange( | 769 CheckSingleScrollDistanceIsWithinRange( |
| 681 scroll_target->start_to_end_distance(), params.distances[0], target_); | 770 scroll_target->start_to_end_distance(), params.distances[0], target_); |
| 682 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); | 771 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
| 683 } | 772 } |
| 684 | 773 |
| 685 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) { | 774 TEST_P(SyntheticGestureControllerTestWithParam, |
| 686 CreateControllerAndTarget<MockScrollTouchTarget>(); | 775 SingleScrollGestureTouchZeroDistance) { |
| 776 CreateControllerAndTarget<MockMoveTouchTarget>(); | |
| 687 | 777 |
| 688 SyntheticSmoothScrollGestureParams params; | 778 SyntheticSmoothMoveGestureParams params; |
| 689 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 779 SetDefaultsForSyntheticMoveParams(params); |
| 690 params.anchor.SetPoint(-32, 43); | 780 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 781 if (GetParam() == TOUCH_DRAG) { | |
| 782 params.prevent_slop = true; | |
| 783 } | |
| 784 params.start_point.SetPoint(-32, 43); | |
| 691 params.distances.push_back(gfx::Vector2d(0, 0)); | 785 params.distances.push_back(gfx::Vector2d(0, 0)); |
| 692 | 786 |
| 693 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 787 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 694 new SyntheticSmoothScrollGesture(params)); | 788 new SyntheticSmoothMoveGesture(params)); |
| 695 QueueSyntheticGesture(gesture.Pass()); | 789 QueueSyntheticGesture(gesture.Pass()); |
| 696 FlushInputUntilComplete(); | 790 FlushInputUntilComplete(); |
| 697 | 791 |
| 698 MockScrollGestureTarget* scroll_target = | 792 MockMoveGestureTarget* scroll_target = |
| 699 static_cast<MockScrollGestureTarget*>(target_); | 793 static_cast<MockMoveGestureTarget*>(target_); |
| 700 EXPECT_EQ(1, num_success_); | 794 EXPECT_EQ(1, num_success_); |
| 701 EXPECT_EQ(0, num_failure_); | 795 EXPECT_EQ(0, num_failure_); |
| 702 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); | 796 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); |
| 703 } | 797 } |
| 704 | 798 |
| 705 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { | 799 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { |
| 706 CreateControllerAndTarget<MockScrollMouseTarget>(); | 800 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 707 | 801 |
| 708 SyntheticSmoothScrollGestureParams params; | 802 SyntheticSmoothMoveGestureParams params; |
| 709 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 803 SetDefaultsForSyntheticMoveParams(params); |
| 710 params.anchor.SetPoint(432, 89); | 804 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
| 805 params.start_point.SetPoint(432, 89); | |
| 711 params.distances.push_back(gfx::Vector2d(0, -234)); | 806 params.distances.push_back(gfx::Vector2d(0, -234)); |
| 712 | 807 |
| 713 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 808 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 714 new SyntheticSmoothScrollGesture(params)); | 809 new SyntheticSmoothMoveGesture(params)); |
| 715 QueueSyntheticGesture(gesture.Pass()); | 810 QueueSyntheticGesture(gesture.Pass()); |
| 716 FlushInputUntilComplete(); | 811 FlushInputUntilComplete(); |
| 717 | 812 |
| 718 MockScrollGestureTarget* scroll_target = | 813 MockMoveGestureTarget* scroll_target = |
| 719 static_cast<MockScrollGestureTarget*>(target_); | 814 static_cast<MockMoveGestureTarget*>(target_); |
| 720 EXPECT_EQ(1, num_success_); | 815 EXPECT_EQ(1, num_success_); |
| 721 EXPECT_EQ(0, num_failure_); | 816 EXPECT_EQ(0, num_failure_); |
| 722 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 817 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
| 723 } | 818 } |
| 724 | 819 |
| 725 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { | 820 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { |
| 726 CreateControllerAndTarget<MockScrollMouseTarget>(); | 821 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 727 | 822 |
| 728 SyntheticSmoothScrollGestureParams params; | 823 SyntheticSmoothMoveGestureParams params; |
| 729 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 824 SetDefaultsForSyntheticMoveParams(params); |
| 730 params.anchor.SetPoint(90, 12); | 825 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
| 826 params.start_point.SetPoint(90, 12); | |
| 731 params.distances.push_back(gfx::Vector2d(345, 0)); | 827 params.distances.push_back(gfx::Vector2d(345, 0)); |
| 732 | 828 |
| 733 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 829 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 734 new SyntheticSmoothScrollGesture(params)); | 830 new SyntheticSmoothMoveGesture(params)); |
| 735 QueueSyntheticGesture(gesture.Pass()); | 831 QueueSyntheticGesture(gesture.Pass()); |
| 736 FlushInputUntilComplete(); | 832 FlushInputUntilComplete(); |
| 737 | 833 |
| 738 MockScrollGestureTarget* scroll_target = | 834 MockMoveGestureTarget* scroll_target = |
| 739 static_cast<MockScrollGestureTarget*>(target_); | 835 static_cast<MockMoveGestureTarget*>(target_); |
| 740 EXPECT_EQ(1, num_success_); | 836 EXPECT_EQ(1, num_success_); |
| 741 EXPECT_EQ(0, num_failure_); | 837 EXPECT_EQ(0, num_failure_); |
| 742 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 838 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
| 743 } | 839 } |
| 744 | 840 |
| 745 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { | 841 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { |
| 746 CreateControllerAndTarget<MockScrollMouseTarget>(); | 842 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 747 | 843 |
| 748 SyntheticSmoothScrollGestureParams params; | 844 SyntheticSmoothMoveGestureParams params; |
| 749 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 845 SetDefaultsForSyntheticMoveParams(params); |
| 750 params.anchor.SetPoint(90, 12); | 846 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
| 847 params.start_point.SetPoint(90, 12); | |
| 751 params.distances.push_back(gfx::Vector2d(-194, 303)); | 848 params.distances.push_back(gfx::Vector2d(-194, 303)); |
| 752 | 849 |
| 753 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 850 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 754 new SyntheticSmoothScrollGesture(params)); | 851 new SyntheticSmoothMoveGesture(params)); |
| 755 QueueSyntheticGesture(gesture.Pass()); | 852 QueueSyntheticGesture(gesture.Pass()); |
| 756 FlushInputUntilComplete(); | 853 FlushInputUntilComplete(); |
| 757 | 854 |
| 758 MockScrollGestureTarget* scroll_target = | 855 MockMoveGestureTarget* scroll_target = |
| 759 static_cast<MockScrollGestureTarget*>(target_); | 856 static_cast<MockMoveGestureTarget*>(target_); |
| 760 EXPECT_EQ(1, num_success_); | 857 EXPECT_EQ(1, num_success_); |
| 761 EXPECT_EQ(0, num_failure_); | 858 EXPECT_EQ(0, num_failure_); |
| 762 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 859 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
| 763 } | 860 } |
| 764 | 861 |
| 765 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { | 862 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { |
| 766 CreateControllerAndTarget<MockScrollMouseTarget>(); | 863 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 767 | 864 |
| 768 SyntheticSmoothScrollGestureParams params; | 865 SyntheticSmoothMoveGestureParams params; |
| 769 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 866 SetDefaultsForSyntheticMoveParams(params); |
| 770 params.anchor.SetPoint(90, 12); | 867 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
| 868 params.start_point.SetPoint(90, 12); | |
| 771 params.distances.push_back(gfx::Vector2d(-129, 212)); | 869 params.distances.push_back(gfx::Vector2d(-129, 212)); |
| 772 params.distances.push_back(gfx::Vector2d(8, -9)); | 870 params.distances.push_back(gfx::Vector2d(8, -9)); |
| 773 | 871 |
| 774 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 872 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 775 new SyntheticSmoothScrollGesture(params)); | 873 new SyntheticSmoothMoveGesture(params)); |
| 776 QueueSyntheticGesture(gesture.Pass()); | 874 QueueSyntheticGesture(gesture.Pass()); |
| 777 FlushInputUntilComplete(); | 875 FlushInputUntilComplete(); |
| 778 | 876 |
| 779 MockScrollGestureTarget* scroll_target = | 877 MockMoveGestureTarget* scroll_target = |
| 780 static_cast<MockScrollGestureTarget*>(target_); | 878 static_cast<MockMoveGestureTarget*>(target_); |
| 781 EXPECT_EQ(1, num_success_); | 879 EXPECT_EQ(1, num_success_); |
| 782 EXPECT_EQ(0, num_failure_); | 880 EXPECT_EQ(0, num_failure_); |
| 783 EXPECT_EQ(params.distances[0] + params.distances[1], | 881 EXPECT_EQ(params.distances[0] + params.distances[1], |
| 784 scroll_target->start_to_end_distance()); | 882 scroll_target->start_to_end_distance()); |
| 785 } | 883 } |
| 786 | 884 |
| 787 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { | 885 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { |
| 788 CreateControllerAndTarget<MockScrollMouseTarget>(); | 886 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 789 | 887 |
| 790 SyntheticSmoothScrollGestureParams params; | 888 SyntheticSmoothMoveGestureParams params; |
| 791 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 889 SetDefaultsForSyntheticMoveParams(params); |
| 792 params.anchor.SetPoint(90, 12); | 890 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
| 891 params.start_point.SetPoint(90, 12); | |
| 793 params.distances.push_back(gfx::Vector2d(-129, 0)); | 892 params.distances.push_back(gfx::Vector2d(-129, 0)); |
| 794 params.distances.push_back(gfx::Vector2d(79, 0)); | 893 params.distances.push_back(gfx::Vector2d(79, 0)); |
| 795 | 894 |
| 796 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 895 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 797 new SyntheticSmoothScrollGesture(params)); | 896 new SyntheticSmoothMoveGesture(params)); |
| 798 QueueSyntheticGesture(gesture.Pass()); | 897 QueueSyntheticGesture(gesture.Pass()); |
| 799 FlushInputUntilComplete(); | 898 FlushInputUntilComplete(); |
| 800 | 899 |
| 801 MockScrollGestureTarget* scroll_target = | 900 MockMoveGestureTarget* scroll_target = |
| 802 static_cast<MockScrollGestureTarget*>(target_); | 901 static_cast<MockMoveGestureTarget*>(target_); |
| 803 EXPECT_EQ(1, num_success_); | 902 EXPECT_EQ(1, num_success_); |
| 804 EXPECT_EQ(0, num_failure_); | 903 EXPECT_EQ(0, num_failure_); |
| 805 // This check only works for horizontal or vertical scrolls because of | 904 // This check only works for horizontal or vertical scrolls because of |
| 806 // floating point precision issues with diagonal scrolls. | 905 // floating point precision issues with diagonal scrolls. |
| 807 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), | 906 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), |
| 808 scroll_target->total_abs_scroll_distance_length()); | 907 scroll_target->total_abs_move_distance_length()); |
| 809 EXPECT_EQ(params.distances[0] + params.distances[1], | 908 EXPECT_EQ(params.distances[0] + params.distances[1], |
| 810 scroll_target->start_to_end_distance()); | 909 scroll_target->start_to_end_distance()); |
| 811 } | 910 } |
| 812 | 911 |
| 813 void CheckIsWithinRangeMulti(float scroll_distance, | 912 void CheckIsWithinRangeMulti(float scroll_distance, |
| 814 int target_distance, | 913 int target_distance, |
| 815 SyntheticGestureTarget* target) { | 914 SyntheticGestureTarget* target) { |
| 816 if (target_distance > 0) { | 915 if (target_distance > 0) { |
| 817 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 916 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
| 818 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 917 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
| 819 } else { | 918 } else { |
| 820 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 919 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
| 821 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 920 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
| 822 } | 921 } |
| 823 } | 922 } |
| 824 | 923 |
| 825 void CheckMultiScrollDistanceIsWithinRange( | 924 void CheckMultiScrollDistanceIsWithinRange( |
| 826 const gfx::Vector2dF& scroll_distance, | 925 const gfx::Vector2dF& scroll_distance, |
| 827 const gfx::Vector2d& target_distance, | 926 const gfx::Vector2dF& target_distance, |
| 828 SyntheticGestureTarget* target) { | 927 SyntheticGestureTarget* target) { |
| 829 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); | 928 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); |
| 830 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); | 929 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); |
| 831 } | 930 } |
| 832 | 931 |
| 833 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { | 932 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { |
| 834 CreateControllerAndTarget<MockScrollTouchTarget>(); | 933 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 835 | 934 |
| 836 SyntheticSmoothScrollGestureParams params; | 935 SyntheticSmoothMoveGestureParams params; |
| 837 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 936 SetDefaultsForSyntheticMoveParams(params); |
| 838 params.anchor.SetPoint(8, -13); | 937 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 938 params.start_point.SetPoint(8, -13); | |
| 839 params.distances.push_back(gfx::Vector2d(234, 133)); | 939 params.distances.push_back(gfx::Vector2d(234, 133)); |
| 840 params.distances.push_back(gfx::Vector2d(-9, 78)); | 940 params.distances.push_back(gfx::Vector2d(-9, 78)); |
| 841 | 941 |
| 842 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 942 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 843 new SyntheticSmoothScrollGesture(params)); | 943 new SyntheticSmoothMoveGesture(params)); |
| 844 QueueSyntheticGesture(gesture.Pass()); | 944 QueueSyntheticGesture(gesture.Pass()); |
| 845 FlushInputUntilComplete(); | 945 FlushInputUntilComplete(); |
| 846 | 946 |
| 847 MockScrollGestureTarget* scroll_target = | 947 MockMoveGestureTarget* scroll_target = |
| 848 static_cast<MockScrollGestureTarget*>(target_); | 948 static_cast<MockMoveGestureTarget*>(target_); |
| 849 EXPECT_EQ(1, num_success_); | 949 EXPECT_EQ(1, num_success_); |
| 850 EXPECT_EQ(0, num_failure_); | 950 EXPECT_EQ(0, num_failure_); |
| 851 CheckMultiScrollDistanceIsWithinRange( | 951 CheckMultiScrollDistanceIsWithinRange( |
| 852 scroll_target->start_to_end_distance(), | 952 scroll_target->start_to_end_distance(), |
| 853 params.distances[0] + params.distances[1], | 953 params.distances[0] + params.distances[1], |
| 854 target_); | 954 target_); |
| 855 } | 955 } |
| 856 | 956 |
| 857 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) { | 957 TEST_P(SyntheticGestureControllerTestWithParam, |
| 858 CreateControllerAndTarget<MockScrollTouchTarget>(); | 958 MultiScrollGestureTouchVertical) { |
| 959 CreateControllerAndTarget<MockMoveTouchTarget>(); | |
| 960 | |
| 961 SyntheticSmoothMoveGestureParams params; | |
| 962 SetDefaultsForSyntheticMoveParams(params); | |
| 963 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; | |
| 964 if (GetParam() == TOUCH_DRAG) { | |
| 965 params.prevent_slop = true; | |
| 966 } | |
| 967 params.start_point.SetPoint(234, -13); | |
| 968 params.distances.push_back(gfx::Vector2d(0, 133)); | |
| 969 params.distances.push_back(gfx::Vector2d(0, 78)); | |
| 970 | |
| 971 scoped_ptr<SyntheticSmoothMoveGesture> gesture( | |
| 972 new SyntheticSmoothMoveGesture(params)); | |
| 973 QueueSyntheticGesture(gesture.Pass()); | |
| 974 FlushInputUntilComplete(); | |
| 975 | |
| 976 MockMoveGestureTarget* scroll_target = | |
| 977 static_cast<MockMoveGestureTarget*>(target_); | |
| 978 EXPECT_EQ(1, num_success_); | |
| 979 EXPECT_EQ(0, num_failure_); | |
| 980 if (GetParam() == TOUCH_SCROLL) { | |
| 981 EXPECT_FLOAT_EQ(params.distances[0].Length() + | |
| 982 params.distances[1].Length() + | |
| 983 target_->GetTouchSlopInDips(), | |
| 984 scroll_target->total_abs_move_distance_length()); | |
| 985 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], | |
| 986 target_), | |
| 987 scroll_target->start_to_end_distance()); | |
| 988 } else { | |
| 989 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), | |
| 990 scroll_target->total_abs_move_distance_length()); | |
| 991 EXPECT_EQ(params.distances[0] + params.distances[1], | |
| 992 scroll_target->start_to_end_distance()); | |
| 993 } | |
| 994 } | |
| 995 INSTANTIATE_TEST_CASE_P(Single, | |
|
Sami
2015/02/23 18:03:28
nit: Add a blank line above this.
ssid
2015/02/23 19:10:36
Done.
| |
| 996 SyntheticGestureControllerTestWithParam, | |
| 997 testing::Values(TOUCH_SCROLL, TOUCH_DRAG)); | |
| 998 | |
| 999 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) { | |
| 1000 CreateControllerAndTarget<MockDragMouseTarget>(); | |
| 1001 | |
| 1002 SyntheticSmoothMoveGestureParams params; | |
| 1003 SetDefaultsForSyntheticMoveParams(params); | |
| 1004 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; | |
| 1005 params.start_point.SetPoint(0, 7); | |
| 1006 params.distances.push_back(gfx::Vector2d(413, -83)); | |
| 1007 | |
| 1008 scoped_ptr<SyntheticSmoothMoveGesture> gesture( | |
| 1009 new SyntheticSmoothMoveGesture(params)); | |
| 1010 QueueSyntheticGesture(gesture.Pass()); | |
| 1011 FlushInputUntilComplete(); | |
| 1012 | |
| 1013 MockMoveGestureTarget* drag_target = | |
| 1014 static_cast<MockMoveGestureTarget*>(target_); | |
| 1015 EXPECT_EQ(1, num_success_); | |
| 1016 EXPECT_EQ(0, num_failure_); | |
| 1017 EXPECT_EQ(drag_target->start_to_end_distance(), params.distances[0]); | |
| 1018 } | |
| 1019 | |
| 1020 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseZeroDistance) { | |
| 1021 CreateControllerAndTarget<MockDragMouseTarget>(); | |
| 1022 | |
| 1023 SyntheticSmoothMoveGestureParams params; | |
| 1024 SetDefaultsForSyntheticMoveParams(params); | |
| 1025 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; | |
| 1026 params.start_point.SetPoint(-32, 43); | |
| 1027 params.distances.push_back(gfx::Vector2d(0, 0)); | |
| 1028 | |
| 1029 scoped_ptr<SyntheticSmoothMoveGesture> gesture( | |
| 1030 new SyntheticSmoothMoveGesture(params)); | |
| 1031 QueueSyntheticGesture(gesture.Pass()); | |
| 1032 FlushInputUntilComplete(); | |
| 1033 | |
| 1034 MockMoveGestureTarget* drag_target = | |
| 1035 static_cast<MockMoveGestureTarget*>(target_); | |
| 1036 EXPECT_EQ(1, num_success_); | |
| 1037 EXPECT_EQ(0, num_failure_); | |
| 1038 EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target->start_to_end_distance()); | |
| 1039 } | |
| 1040 | |
| 1041 TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouse) { | |
| 1042 CreateControllerAndTarget<MockDragMouseTarget>(); | |
| 1043 | |
| 1044 SyntheticSmoothMoveGestureParams params; | |
| 1045 SetDefaultsForSyntheticMoveParams(params); | |
| 1046 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; | |
| 1047 params.start_point.SetPoint(8, -13); | |
| 1048 params.distances.push_back(gfx::Vector2d(234, 133)); | |
| 1049 params.distances.push_back(gfx::Vector2d(-9, 78)); | |
| 1050 | |
| 1051 scoped_ptr<SyntheticSmoothMoveGesture> gesture( | |
| 1052 new SyntheticSmoothMoveGesture(params)); | |
| 1053 QueueSyntheticGesture(gesture.Pass()); | |
| 1054 FlushInputUntilComplete(); | |
| 1055 | |
| 1056 MockMoveGestureTarget* drag_target = | |
| 1057 static_cast<MockMoveGestureTarget*>(target_); | |
| 1058 EXPECT_EQ(1, num_success_); | |
| 1059 EXPECT_EQ(0, num_failure_); | |
| 1060 EXPECT_EQ(drag_target->start_to_end_distance(), | |
| 1061 params.distances[0] + params.distances[1]); | |
| 1062 } | |
| 1063 | |
| 1064 TEST_F(SyntheticGestureControllerTest, | |
| 1065 SyntheticSmoothDragTestUsingSingleMouseDrag) { | |
| 1066 CreateControllerAndTarget<MockDragMouseTarget>(); | |
| 1067 | |
| 1068 SyntheticSmoothDragGestureParams params; | |
| 1069 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
| 1070 params.distances.push_back(gfx::Vector2d(234, 133)); | |
| 1071 params.speed_in_pixels_s = 800; | |
| 1072 | |
| 1073 scoped_ptr<SyntheticSmoothDragGesture> gesture( | |
| 1074 new SyntheticSmoothDragGesture(params)); | |
| 1075 const base::TimeTicks timestamp; | |
| 1076 gesture->ForwardInputEvents(timestamp, target_); | |
| 1077 } | |
| 1078 | |
| 1079 TEST_F(SyntheticGestureControllerTest, | |
| 1080 SyntheticSmoothDragTestUsingSingleTouchDrag) { | |
| 1081 CreateControllerAndTarget<MockMoveTouchTarget>(); | |
| 1082 | |
| 1083 SyntheticSmoothDragGestureParams params; | |
| 1084 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 1085 params.start_point.SetPoint(89, 32); | |
| 1086 params.distances.push_back(gfx::Vector2d(0, 123)); | |
| 1087 params.speed_in_pixels_s = 800; | |
| 1088 | |
| 1089 scoped_ptr<SyntheticSmoothDragGesture> gesture( | |
| 1090 new SyntheticSmoothDragGesture(params)); | |
| 1091 const base::TimeTicks timestamp; | |
| 1092 gesture->ForwardInputEvents(timestamp, target_); | |
| 1093 } | |
| 1094 | |
| 1095 TEST_F(SyntheticGestureControllerTest, | |
| 1096 SyntheticSmoothScrollTestUsingSingleTouchScroll) { | |
| 1097 CreateControllerAndTarget<MockMoveTouchTarget>(); | |
| 859 | 1098 |
| 860 SyntheticSmoothScrollGestureParams params; | 1099 SyntheticSmoothScrollGestureParams params; |
| 861 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1100 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 862 params.anchor.SetPoint(234, -13); | |
| 863 params.distances.push_back(gfx::Vector2d(0, 133)); | |
| 864 params.distances.push_back(gfx::Vector2d(0, 78)); | |
| 865 | 1101 |
| 866 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 1102 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
| 867 new SyntheticSmoothScrollGesture(params)); | 1103 new SyntheticSmoothScrollGesture(params)); |
| 868 QueueSyntheticGesture(gesture.Pass()); | 1104 const base::TimeTicks timestamp; |
| 869 FlushInputUntilComplete(); | 1105 gesture->ForwardInputEvents(timestamp, target_); |
| 1106 } | |
| 870 | 1107 |
| 871 MockScrollGestureTarget* scroll_target = | 1108 TEST_F(SyntheticGestureControllerTest, |
| 872 static_cast<MockScrollGestureTarget*>(target_); | 1109 SyntheticSmoothScrollTestUsingSingleMouseScroll) { |
| 873 EXPECT_EQ(1, num_success_); | 1110 CreateControllerAndTarget<MockScrollMouseTarget>(); |
| 874 EXPECT_EQ(0, num_failure_); | 1111 |
| 875 EXPECT_FLOAT_EQ( | 1112 SyntheticSmoothScrollGestureParams params; |
| 876 params.distances[0].Length() + params.distances[1].Length() + | 1113 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| 877 target_->GetTouchSlopInDips(), | 1114 params.anchor.SetPoint(432, 89); |
| 878 scroll_target->total_abs_scroll_distance_length()); | 1115 params.distances.push_back(gfx::Vector2d(0, -234)); |
| 879 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], | 1116 params.speed_in_pixels_s = 800; |
| 880 target_), | 1117 |
| 881 scroll_target->start_to_end_distance()); | 1118 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
| 1119 new SyntheticSmoothScrollGesture(params)); | |
| 1120 const base::TimeTicks timestamp; | |
| 1121 gesture->ForwardInputEvents(timestamp, target_); | |
| 882 } | 1122 } |
| 883 | 1123 |
| 884 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { | 1124 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |
| 885 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 1125 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); |
| 886 | 1126 |
| 887 SyntheticPinchGestureParams params; | 1127 SyntheticPinchGestureParams params; |
| 888 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1128 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 889 params.scale_factor = 2.3f; | 1129 params.scale_factor = 2.3f; |
| 890 params.anchor.SetPoint(54, 89); | 1130 params.anchor.SetPoint(54, 89); |
| 891 | 1131 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 EXPECT_TRUE(tap_target->GestureFinished()); | 1225 EXPECT_TRUE(tap_target->GestureFinished()); |
| 986 EXPECT_EQ(tap_target->position(), params.position); | 1226 EXPECT_EQ(tap_target->position(), params.position); |
| 987 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1227 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
| 988 EXPECT_GE(GetTotalTime(), | 1228 EXPECT_GE(GetTotalTime(), |
| 989 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1229 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| 990 } | 1230 } |
| 991 | 1231 |
| 992 } // namespace | 1232 } // namespace |
| 993 | 1233 |
| 994 } // namespace content | 1234 } // namespace content |
| OLD | NEW |