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_ = nullptr; |
| 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_ = nullptr; |
| 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 TEST_P(SyntheticGestureControllerTestWithParam, |
547 CreateControllerAndTarget<MockScrollTouchTarget>(); | 610 SingleMoveGestureTouchVertical) { |
| 611 CreateControllerAndTarget<MockMoveTouchTarget>(); |
548 | 612 |
549 SyntheticSmoothScrollGestureParams params; | 613 SyntheticSmoothMoveGestureParams params; |
550 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 614 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
551 params.anchor.SetPoint(89, 32); | 615 if (GetParam() == TOUCH_DRAG) { |
| 616 params.add_slop = false; |
| 617 } |
| 618 params.start_point.SetPoint(89, 32); |
552 params.distances.push_back(gfx::Vector2d(0, 123)); | 619 params.distances.push_back(gfx::Vector2d(0, 123)); |
553 | 620 |
554 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 621 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
555 new SyntheticSmoothScrollGesture(params)); | 622 new SyntheticSmoothMoveGesture(params)); |
556 QueueSyntheticGesture(gesture.Pass()); | 623 QueueSyntheticGesture(gesture.Pass()); |
557 FlushInputUntilComplete(); | 624 FlushInputUntilComplete(); |
558 | 625 |
559 MockScrollGestureTarget* scroll_target = | 626 MockMoveGestureTarget* scroll_target = |
560 static_cast<MockScrollGestureTarget*>(target_); | 627 static_cast<MockMoveGestureTarget*>(target_); |
561 EXPECT_EQ(1, num_success_); | 628 EXPECT_EQ(1, num_success_); |
562 EXPECT_EQ(0, num_failure_); | 629 EXPECT_EQ(0, num_failure_); |
563 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), | 630 if (GetParam() == TOUCH_SCROLL) { |
564 scroll_target->start_to_end_distance()); | 631 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), |
| 632 scroll_target->start_to_end_distance()); |
| 633 } else { |
| 634 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
| 635 } |
565 } | 636 } |
566 | 637 |
567 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) { | 638 TEST_P(SyntheticGestureControllerTestWithParam, |
568 CreateControllerAndTarget<MockScrollTouchTarget>(); | 639 SingleScrollGestureTouchHorizontal) { |
| 640 CreateControllerAndTarget<MockMoveTouchTarget>(); |
569 | 641 |
570 SyntheticSmoothScrollGestureParams params; | 642 SyntheticSmoothMoveGestureParams params; |
571 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 643 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
572 params.anchor.SetPoint(12, -23); | 644 if (GetParam() == TOUCH_DRAG) { |
| 645 params.add_slop = false; |
| 646 } |
| 647 params.start_point.SetPoint(12, -23); |
573 params.distances.push_back(gfx::Vector2d(-234, 0)); | 648 params.distances.push_back(gfx::Vector2d(-234, 0)); |
574 | 649 |
575 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 650 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
576 new SyntheticSmoothScrollGesture(params)); | 651 new SyntheticSmoothMoveGesture(params)); |
577 QueueSyntheticGesture(gesture.Pass()); | 652 QueueSyntheticGesture(gesture.Pass()); |
578 FlushInputUntilComplete(); | 653 FlushInputUntilComplete(); |
579 | 654 |
580 MockScrollGestureTarget* scroll_target = | 655 MockMoveGestureTarget* scroll_target = |
581 static_cast<MockScrollGestureTarget*>(target_); | 656 static_cast<MockMoveGestureTarget*>(target_); |
582 EXPECT_EQ(1, num_success_); | 657 EXPECT_EQ(1, num_success_); |
583 EXPECT_EQ(0, num_failure_); | 658 EXPECT_EQ(0, num_failure_); |
584 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), | 659 if (GetParam() == TOUCH_SCROLL) { |
585 scroll_target->start_to_end_distance()); | 660 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), |
| 661 scroll_target->start_to_end_distance()); |
| 662 } else { |
| 663 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
| 664 } |
586 } | 665 } |
587 | 666 |
588 void CheckIsWithinRangeSingle(float scroll_distance, | 667 void CheckIsWithinRangeSingle(float scroll_distance, |
589 int target_distance, | 668 int target_distance, |
590 SyntheticGestureTarget* target) { | 669 SyntheticGestureTarget* target) { |
591 if (target_distance > 0) { | 670 if (target_distance > 0) { |
592 EXPECT_LE(target_distance, scroll_distance); | 671 EXPECT_LE(target_distance, scroll_distance); |
593 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 672 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
594 } else { | 673 } else { |
595 EXPECT_GE(target_distance, scroll_distance); | 674 EXPECT_GE(target_distance, scroll_distance); |
596 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 675 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
597 } | 676 } |
598 } | 677 } |
599 | 678 |
600 void CheckSingleScrollDistanceIsWithinRange( | 679 void CheckSingleScrollDistanceIsWithinRange( |
601 const gfx::Vector2dF& scroll_distance, | 680 const gfx::Vector2dF& scroll_distance, |
602 const gfx::Vector2d& target_distance, | 681 const gfx::Vector2dF& target_distance, |
603 SyntheticGestureTarget* target) { | 682 SyntheticGestureTarget* target) { |
604 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); | 683 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); |
605 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); | 684 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); |
606 } | 685 } |
607 | 686 |
608 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { | 687 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { |
609 CreateControllerAndTarget<MockScrollTouchTarget>(); | 688 CreateControllerAndTarget<MockMoveTouchTarget>(); |
610 | 689 |
611 SyntheticSmoothScrollGestureParams params; | 690 SyntheticSmoothMoveGestureParams params; |
612 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 691 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
613 params.anchor.SetPoint(0, 7); | 692 params.start_point.SetPoint(0, 7); |
614 params.distances.push_back(gfx::Vector2d(413, -83)); | 693 params.distances.push_back(gfx::Vector2d(413, -83)); |
615 | 694 |
616 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 695 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
617 new SyntheticSmoothScrollGesture(params)); | 696 new SyntheticSmoothMoveGesture(params)); |
618 QueueSyntheticGesture(gesture.Pass()); | 697 QueueSyntheticGesture(gesture.Pass()); |
619 FlushInputUntilComplete(); | 698 FlushInputUntilComplete(); |
620 | 699 |
621 MockScrollGestureTarget* scroll_target = | 700 MockMoveGestureTarget* scroll_target = |
622 static_cast<MockScrollGestureTarget*>(target_); | 701 static_cast<MockMoveGestureTarget*>(target_); |
623 EXPECT_EQ(1, num_success_); | 702 EXPECT_EQ(1, num_success_); |
624 EXPECT_EQ(0, num_failure_); | 703 EXPECT_EQ(0, num_failure_); |
625 CheckSingleScrollDistanceIsWithinRange( | 704 CheckSingleScrollDistanceIsWithinRange( |
626 scroll_target->start_to_end_distance(), params.distances[0], target_); | 705 scroll_target->start_to_end_distance(), params.distances[0], target_); |
627 } | 706 } |
628 | 707 |
629 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { | 708 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { |
630 CreateControllerAndTarget<MockScrollTouchTarget>(); | 709 CreateControllerAndTarget<MockMoveTouchTarget>(); |
631 | 710 |
632 // Create a smooth scroll with a short distance and set the pointer assumed | 711 // 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 | 712 // stopped time high, so that the stopping should dominate the time the |
634 // gesture is active. | 713 // gesture is active. |
635 SyntheticSmoothScrollGestureParams params; | 714 SyntheticSmoothMoveGestureParams params; |
636 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 715 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
637 params.anchor.SetPoint(-98, -23); | 716 params.start_point.SetPoint(-98, -23); |
638 params.distances.push_back(gfx::Vector2d(21, -12)); | 717 params.distances.push_back(gfx::Vector2d(21, -12)); |
639 params.prevent_fling = true; | 718 params.prevent_fling = true; |
640 | |
641 target_->set_pointer_assumed_stopped_time_ms(543); | 719 target_->set_pointer_assumed_stopped_time_ms(543); |
642 | 720 |
643 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 721 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
644 new SyntheticSmoothScrollGesture(params)); | 722 new SyntheticSmoothMoveGesture(params)); |
645 QueueSyntheticGesture(gesture.Pass()); | 723 QueueSyntheticGesture(gesture.Pass()); |
646 FlushInputUntilComplete(); | 724 FlushInputUntilComplete(); |
647 | 725 |
648 MockScrollGestureTarget* scroll_target = | 726 MockMoveGestureTarget* scroll_target = |
649 static_cast<MockScrollGestureTarget*>(target_); | 727 static_cast<MockMoveGestureTarget*>(target_); |
650 EXPECT_EQ(1, num_success_); | 728 EXPECT_EQ(1, num_success_); |
651 EXPECT_EQ(0, num_failure_); | 729 EXPECT_EQ(0, num_failure_); |
652 CheckSingleScrollDistanceIsWithinRange( | 730 CheckSingleScrollDistanceIsWithinRange( |
653 scroll_target->start_to_end_distance(), params.distances[0], target_); | 731 scroll_target->start_to_end_distance(), params.distances[0], target_); |
654 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); | 732 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
655 } | 733 } |
656 | 734 |
657 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { | 735 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { |
658 CreateControllerAndTarget<MockScrollTouchTarget>(); | 736 CreateControllerAndTarget<MockMoveTouchTarget>(); |
659 | 737 |
660 // Create a smooth scroll with a short distance and set the pointer assumed | 738 // 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 | 739 // stopped time high. Disable 'prevent_fling' and check that the gesture |
662 // finishes without waiting before it stops. | 740 // finishes without waiting before it stops. |
663 SyntheticSmoothScrollGestureParams params; | 741 SyntheticSmoothMoveGestureParams params; |
664 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 742 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
665 params.anchor.SetPoint(-89, 78); | 743 params.start_point.SetPoint(-89, 78); |
666 params.distances.push_back(gfx::Vector2d(-43, 19)); | 744 params.distances.push_back(gfx::Vector2d(-43, 19)); |
667 params.prevent_fling = false; | 745 params.prevent_fling = false; |
668 | 746 |
669 target_->set_pointer_assumed_stopped_time_ms(543); | 747 target_->set_pointer_assumed_stopped_time_ms(543); |
670 | 748 |
671 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 749 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
672 new SyntheticSmoothScrollGesture(params)); | 750 new SyntheticSmoothMoveGesture(params)); |
673 QueueSyntheticGesture(gesture.Pass()); | 751 QueueSyntheticGesture(gesture.Pass()); |
674 FlushInputUntilComplete(); | 752 FlushInputUntilComplete(); |
675 | 753 |
676 MockScrollGestureTarget* scroll_target = | 754 MockMoveGestureTarget* scroll_target = |
677 static_cast<MockScrollGestureTarget*>(target_); | 755 static_cast<MockMoveGestureTarget*>(target_); |
678 EXPECT_EQ(1, num_success_); | 756 EXPECT_EQ(1, num_success_); |
679 EXPECT_EQ(0, num_failure_); | 757 EXPECT_EQ(0, num_failure_); |
680 CheckSingleScrollDistanceIsWithinRange( | 758 CheckSingleScrollDistanceIsWithinRange( |
681 scroll_target->start_to_end_distance(), params.distances[0], target_); | 759 scroll_target->start_to_end_distance(), params.distances[0], target_); |
682 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); | 760 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
683 } | 761 } |
684 | 762 |
685 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) { | 763 TEST_P(SyntheticGestureControllerTestWithParam, |
686 CreateControllerAndTarget<MockScrollTouchTarget>(); | 764 SingleScrollGestureTouchZeroDistance) { |
| 765 CreateControllerAndTarget<MockMoveTouchTarget>(); |
687 | 766 |
688 SyntheticSmoothScrollGestureParams params; | 767 SyntheticSmoothMoveGestureParams params; |
689 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 768 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
690 params.anchor.SetPoint(-32, 43); | 769 if (GetParam() == TOUCH_DRAG) { |
| 770 params.add_slop = false; |
| 771 } |
| 772 params.start_point.SetPoint(-32, 43); |
691 params.distances.push_back(gfx::Vector2d(0, 0)); | 773 params.distances.push_back(gfx::Vector2d(0, 0)); |
692 | 774 |
693 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 775 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
694 new SyntheticSmoothScrollGesture(params)); | 776 new SyntheticSmoothMoveGesture(params)); |
695 QueueSyntheticGesture(gesture.Pass()); | 777 QueueSyntheticGesture(gesture.Pass()); |
696 FlushInputUntilComplete(); | 778 FlushInputUntilComplete(); |
697 | 779 |
698 MockScrollGestureTarget* scroll_target = | 780 MockMoveGestureTarget* scroll_target = |
699 static_cast<MockScrollGestureTarget*>(target_); | 781 static_cast<MockMoveGestureTarget*>(target_); |
700 EXPECT_EQ(1, num_success_); | 782 EXPECT_EQ(1, num_success_); |
701 EXPECT_EQ(0, num_failure_); | 783 EXPECT_EQ(0, num_failure_); |
702 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); | 784 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); |
703 } | 785 } |
704 | 786 |
705 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { | 787 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { |
706 CreateControllerAndTarget<MockScrollMouseTarget>(); | 788 CreateControllerAndTarget<MockScrollMouseTarget>(); |
707 | 789 |
708 SyntheticSmoothScrollGestureParams params; | 790 SyntheticSmoothMoveGestureParams params; |
709 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 791 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
710 params.anchor.SetPoint(432, 89); | 792 params.start_point.SetPoint(432, 89); |
711 params.distances.push_back(gfx::Vector2d(0, -234)); | 793 params.distances.push_back(gfx::Vector2d(0, -234)); |
712 | 794 |
713 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 795 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
714 new SyntheticSmoothScrollGesture(params)); | 796 new SyntheticSmoothMoveGesture(params)); |
715 QueueSyntheticGesture(gesture.Pass()); | 797 QueueSyntheticGesture(gesture.Pass()); |
716 FlushInputUntilComplete(); | 798 FlushInputUntilComplete(); |
717 | 799 |
718 MockScrollGestureTarget* scroll_target = | 800 MockMoveGestureTarget* scroll_target = |
719 static_cast<MockScrollGestureTarget*>(target_); | 801 static_cast<MockMoveGestureTarget*>(target_); |
720 EXPECT_EQ(1, num_success_); | 802 EXPECT_EQ(1, num_success_); |
721 EXPECT_EQ(0, num_failure_); | 803 EXPECT_EQ(0, num_failure_); |
722 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 804 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
723 } | 805 } |
724 | 806 |
725 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { | 807 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { |
726 CreateControllerAndTarget<MockScrollMouseTarget>(); | 808 CreateControllerAndTarget<MockScrollMouseTarget>(); |
727 | 809 |
728 SyntheticSmoothScrollGestureParams params; | 810 SyntheticSmoothMoveGestureParams params; |
729 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 811 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
730 params.anchor.SetPoint(90, 12); | 812 params.start_point.SetPoint(90, 12); |
731 params.distances.push_back(gfx::Vector2d(345, 0)); | 813 params.distances.push_back(gfx::Vector2d(345, 0)); |
732 | 814 |
733 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 815 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
734 new SyntheticSmoothScrollGesture(params)); | 816 new SyntheticSmoothMoveGesture(params)); |
735 QueueSyntheticGesture(gesture.Pass()); | 817 QueueSyntheticGesture(gesture.Pass()); |
736 FlushInputUntilComplete(); | 818 FlushInputUntilComplete(); |
737 | 819 |
738 MockScrollGestureTarget* scroll_target = | 820 MockMoveGestureTarget* scroll_target = |
739 static_cast<MockScrollGestureTarget*>(target_); | 821 static_cast<MockMoveGestureTarget*>(target_); |
740 EXPECT_EQ(1, num_success_); | 822 EXPECT_EQ(1, num_success_); |
741 EXPECT_EQ(0, num_failure_); | 823 EXPECT_EQ(0, num_failure_); |
742 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 824 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
743 } | 825 } |
744 | 826 |
745 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { | 827 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { |
746 CreateControllerAndTarget<MockScrollMouseTarget>(); | 828 CreateControllerAndTarget<MockScrollMouseTarget>(); |
747 | 829 |
748 SyntheticSmoothScrollGestureParams params; | 830 SyntheticSmoothMoveGestureParams params; |
749 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 831 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
750 params.anchor.SetPoint(90, 12); | 832 params.start_point.SetPoint(90, 12); |
751 params.distances.push_back(gfx::Vector2d(-194, 303)); | 833 params.distances.push_back(gfx::Vector2d(-194, 303)); |
752 | 834 |
753 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 835 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
754 new SyntheticSmoothScrollGesture(params)); | 836 new SyntheticSmoothMoveGesture(params)); |
755 QueueSyntheticGesture(gesture.Pass()); | 837 QueueSyntheticGesture(gesture.Pass()); |
756 FlushInputUntilComplete(); | 838 FlushInputUntilComplete(); |
757 | 839 |
758 MockScrollGestureTarget* scroll_target = | 840 MockMoveGestureTarget* scroll_target = |
759 static_cast<MockScrollGestureTarget*>(target_); | 841 static_cast<MockMoveGestureTarget*>(target_); |
760 EXPECT_EQ(1, num_success_); | 842 EXPECT_EQ(1, num_success_); |
761 EXPECT_EQ(0, num_failure_); | 843 EXPECT_EQ(0, num_failure_); |
762 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); | 844 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
763 } | 845 } |
764 | 846 |
765 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { | 847 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { |
766 CreateControllerAndTarget<MockScrollMouseTarget>(); | 848 CreateControllerAndTarget<MockScrollMouseTarget>(); |
767 | 849 |
768 SyntheticSmoothScrollGestureParams params; | 850 SyntheticSmoothMoveGestureParams params; |
769 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 851 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
770 params.anchor.SetPoint(90, 12); | 852 params.start_point.SetPoint(90, 12); |
771 params.distances.push_back(gfx::Vector2d(-129, 212)); | 853 params.distances.push_back(gfx::Vector2d(-129, 212)); |
772 params.distances.push_back(gfx::Vector2d(8, -9)); | 854 params.distances.push_back(gfx::Vector2d(8, -9)); |
773 | 855 |
774 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 856 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
775 new SyntheticSmoothScrollGesture(params)); | 857 new SyntheticSmoothMoveGesture(params)); |
776 QueueSyntheticGesture(gesture.Pass()); | 858 QueueSyntheticGesture(gesture.Pass()); |
777 FlushInputUntilComplete(); | 859 FlushInputUntilComplete(); |
778 | 860 |
779 MockScrollGestureTarget* scroll_target = | 861 MockMoveGestureTarget* scroll_target = |
780 static_cast<MockScrollGestureTarget*>(target_); | 862 static_cast<MockMoveGestureTarget*>(target_); |
781 EXPECT_EQ(1, num_success_); | 863 EXPECT_EQ(1, num_success_); |
782 EXPECT_EQ(0, num_failure_); | 864 EXPECT_EQ(0, num_failure_); |
783 EXPECT_EQ(params.distances[0] + params.distances[1], | 865 EXPECT_EQ(params.distances[0] + params.distances[1], |
784 scroll_target->start_to_end_distance()); | 866 scroll_target->start_to_end_distance()); |
785 } | 867 } |
786 | 868 |
787 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { | 869 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { |
788 CreateControllerAndTarget<MockScrollMouseTarget>(); | 870 CreateControllerAndTarget<MockScrollMouseTarget>(); |
789 | 871 |
790 SyntheticSmoothScrollGestureParams params; | 872 SyntheticSmoothMoveGestureParams params; |
791 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | 873 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT; |
792 params.anchor.SetPoint(90, 12); | 874 params.start_point.SetPoint(90, 12); |
793 params.distances.push_back(gfx::Vector2d(-129, 0)); | 875 params.distances.push_back(gfx::Vector2d(-129, 0)); |
794 params.distances.push_back(gfx::Vector2d(79, 0)); | 876 params.distances.push_back(gfx::Vector2d(79, 0)); |
795 | 877 |
796 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 878 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
797 new SyntheticSmoothScrollGesture(params)); | 879 new SyntheticSmoothMoveGesture(params)); |
798 QueueSyntheticGesture(gesture.Pass()); | 880 QueueSyntheticGesture(gesture.Pass()); |
799 FlushInputUntilComplete(); | 881 FlushInputUntilComplete(); |
800 | 882 |
801 MockScrollGestureTarget* scroll_target = | 883 MockMoveGestureTarget* scroll_target = |
802 static_cast<MockScrollGestureTarget*>(target_); | 884 static_cast<MockMoveGestureTarget*>(target_); |
803 EXPECT_EQ(1, num_success_); | 885 EXPECT_EQ(1, num_success_); |
804 EXPECT_EQ(0, num_failure_); | 886 EXPECT_EQ(0, num_failure_); |
805 // This check only works for horizontal or vertical scrolls because of | 887 // This check only works for horizontal or vertical scrolls because of |
806 // floating point precision issues with diagonal scrolls. | 888 // floating point precision issues with diagonal scrolls. |
807 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), | 889 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), |
808 scroll_target->total_abs_scroll_distance_length()); | 890 scroll_target->total_abs_move_distance_length()); |
809 EXPECT_EQ(params.distances[0] + params.distances[1], | 891 EXPECT_EQ(params.distances[0] + params.distances[1], |
810 scroll_target->start_to_end_distance()); | 892 scroll_target->start_to_end_distance()); |
811 } | 893 } |
812 | 894 |
813 void CheckIsWithinRangeMulti(float scroll_distance, | 895 void CheckIsWithinRangeMulti(float scroll_distance, |
814 int target_distance, | 896 int target_distance, |
815 SyntheticGestureTarget* target) { | 897 SyntheticGestureTarget* target) { |
816 if (target_distance > 0) { | 898 if (target_distance > 0) { |
817 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 899 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
818 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 900 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
819 } else { | 901 } else { |
820 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); | 902 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); |
821 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); | 903 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); |
822 } | 904 } |
823 } | 905 } |
824 | 906 |
825 void CheckMultiScrollDistanceIsWithinRange( | 907 void CheckMultiScrollDistanceIsWithinRange( |
826 const gfx::Vector2dF& scroll_distance, | 908 const gfx::Vector2dF& scroll_distance, |
827 const gfx::Vector2d& target_distance, | 909 const gfx::Vector2dF& target_distance, |
828 SyntheticGestureTarget* target) { | 910 SyntheticGestureTarget* target) { |
829 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); | 911 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); |
830 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); | 912 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); |
831 } | 913 } |
832 | 914 |
833 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { | 915 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { |
834 CreateControllerAndTarget<MockScrollTouchTarget>(); | 916 CreateControllerAndTarget<MockMoveTouchTarget>(); |
835 | 917 |
836 SyntheticSmoothScrollGestureParams params; | 918 SyntheticSmoothMoveGestureParams params; |
837 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 919 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
838 params.anchor.SetPoint(8, -13); | 920 params.start_point.SetPoint(8, -13); |
839 params.distances.push_back(gfx::Vector2d(234, 133)); | 921 params.distances.push_back(gfx::Vector2d(234, 133)); |
840 params.distances.push_back(gfx::Vector2d(-9, 78)); | 922 params.distances.push_back(gfx::Vector2d(-9, 78)); |
841 | 923 |
842 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 924 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
843 new SyntheticSmoothScrollGesture(params)); | 925 new SyntheticSmoothMoveGesture(params)); |
844 QueueSyntheticGesture(gesture.Pass()); | 926 QueueSyntheticGesture(gesture.Pass()); |
845 FlushInputUntilComplete(); | 927 FlushInputUntilComplete(); |
846 | 928 |
847 MockScrollGestureTarget* scroll_target = | 929 MockMoveGestureTarget* scroll_target = |
848 static_cast<MockScrollGestureTarget*>(target_); | 930 static_cast<MockMoveGestureTarget*>(target_); |
849 EXPECT_EQ(1, num_success_); | 931 EXPECT_EQ(1, num_success_); |
850 EXPECT_EQ(0, num_failure_); | 932 EXPECT_EQ(0, num_failure_); |
851 CheckMultiScrollDistanceIsWithinRange( | 933 CheckMultiScrollDistanceIsWithinRange( |
852 scroll_target->start_to_end_distance(), | 934 scroll_target->start_to_end_distance(), |
853 params.distances[0] + params.distances[1], | 935 params.distances[0] + params.distances[1], |
854 target_); | 936 target_); |
855 } | 937 } |
856 | 938 |
857 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) { | 939 TEST_P(SyntheticGestureControllerTestWithParam, |
858 CreateControllerAndTarget<MockScrollTouchTarget>(); | 940 MultiScrollGestureTouchVertical) { |
| 941 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 942 |
| 943 SyntheticSmoothMoveGestureParams params; |
| 944 params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT; |
| 945 if (GetParam() == TOUCH_DRAG) { |
| 946 params.add_slop = false; |
| 947 } |
| 948 params.start_point.SetPoint(234, -13); |
| 949 params.distances.push_back(gfx::Vector2d(0, 133)); |
| 950 params.distances.push_back(gfx::Vector2d(0, 78)); |
| 951 |
| 952 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 953 new SyntheticSmoothMoveGesture(params)); |
| 954 QueueSyntheticGesture(gesture.Pass()); |
| 955 FlushInputUntilComplete(); |
| 956 |
| 957 MockMoveGestureTarget* scroll_target = |
| 958 static_cast<MockMoveGestureTarget*>(target_); |
| 959 EXPECT_EQ(1, num_success_); |
| 960 EXPECT_EQ(0, num_failure_); |
| 961 if (GetParam() == TOUCH_SCROLL) { |
| 962 EXPECT_FLOAT_EQ(params.distances[0].Length() + |
| 963 params.distances[1].Length() + |
| 964 target_->GetTouchSlopInDips(), |
| 965 scroll_target->total_abs_move_distance_length()); |
| 966 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], |
| 967 target_), |
| 968 scroll_target->start_to_end_distance()); |
| 969 } else { |
| 970 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), |
| 971 scroll_target->total_abs_move_distance_length()); |
| 972 EXPECT_EQ(params.distances[0] + params.distances[1], |
| 973 scroll_target->start_to_end_distance()); |
| 974 } |
| 975 } |
| 976 |
| 977 INSTANTIATE_TEST_CASE_P(Single, |
| 978 SyntheticGestureControllerTestWithParam, |
| 979 testing::Values(TOUCH_SCROLL, TOUCH_DRAG)); |
| 980 |
| 981 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) { |
| 982 CreateControllerAndTarget<MockDragMouseTarget>(); |
| 983 |
| 984 SyntheticSmoothMoveGestureParams params; |
| 985 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; |
| 986 params.start_point.SetPoint(0, 7); |
| 987 params.distances.push_back(gfx::Vector2d(413, -83)); |
| 988 |
| 989 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 990 new SyntheticSmoothMoveGesture(params)); |
| 991 QueueSyntheticGesture(gesture.Pass()); |
| 992 FlushInputUntilComplete(); |
| 993 |
| 994 MockMoveGestureTarget* drag_target = |
| 995 static_cast<MockMoveGestureTarget*>(target_); |
| 996 EXPECT_EQ(1, num_success_); |
| 997 EXPECT_EQ(0, num_failure_); |
| 998 EXPECT_EQ(drag_target->start_to_end_distance(), params.distances[0]); |
| 999 } |
| 1000 |
| 1001 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseZeroDistance) { |
| 1002 CreateControllerAndTarget<MockDragMouseTarget>(); |
| 1003 |
| 1004 SyntheticSmoothMoveGestureParams params; |
| 1005 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; |
| 1006 params.start_point.SetPoint(-32, 43); |
| 1007 params.distances.push_back(gfx::Vector2d(0, 0)); |
| 1008 |
| 1009 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 1010 new SyntheticSmoothMoveGesture(params)); |
| 1011 QueueSyntheticGesture(gesture.Pass()); |
| 1012 FlushInputUntilComplete(); |
| 1013 |
| 1014 MockMoveGestureTarget* drag_target = |
| 1015 static_cast<MockMoveGestureTarget*>(target_); |
| 1016 EXPECT_EQ(1, num_success_); |
| 1017 EXPECT_EQ(0, num_failure_); |
| 1018 EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target->start_to_end_distance()); |
| 1019 } |
| 1020 |
| 1021 TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouse) { |
| 1022 CreateControllerAndTarget<MockDragMouseTarget>(); |
| 1023 |
| 1024 SyntheticSmoothMoveGestureParams params; |
| 1025 params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT; |
| 1026 params.start_point.SetPoint(8, -13); |
| 1027 params.distances.push_back(gfx::Vector2d(234, 133)); |
| 1028 params.distances.push_back(gfx::Vector2d(-9, 78)); |
| 1029 |
| 1030 scoped_ptr<SyntheticSmoothMoveGesture> gesture( |
| 1031 new SyntheticSmoothMoveGesture(params)); |
| 1032 QueueSyntheticGesture(gesture.Pass()); |
| 1033 FlushInputUntilComplete(); |
| 1034 |
| 1035 MockMoveGestureTarget* drag_target = |
| 1036 static_cast<MockMoveGestureTarget*>(target_); |
| 1037 EXPECT_EQ(1, num_success_); |
| 1038 EXPECT_EQ(0, num_failure_); |
| 1039 EXPECT_EQ(drag_target->start_to_end_distance(), |
| 1040 params.distances[0] + params.distances[1]); |
| 1041 } |
| 1042 |
| 1043 TEST_F(SyntheticGestureControllerTest, |
| 1044 SyntheticSmoothDragTestUsingSingleMouseDrag) { |
| 1045 CreateControllerAndTarget<MockDragMouseTarget>(); |
| 1046 |
| 1047 SyntheticSmoothDragGestureParams params; |
| 1048 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
| 1049 params.distances.push_back(gfx::Vector2d(234, 133)); |
| 1050 params.speed_in_pixels_s = 800; |
| 1051 |
| 1052 scoped_ptr<SyntheticSmoothDragGesture> gesture( |
| 1053 new SyntheticSmoothDragGesture(params)); |
| 1054 const base::TimeTicks timestamp; |
| 1055 gesture->ForwardInputEvents(timestamp, target_); |
| 1056 } |
| 1057 |
| 1058 TEST_F(SyntheticGestureControllerTest, |
| 1059 SyntheticSmoothDragTestUsingSingleTouchDrag) { |
| 1060 CreateControllerAndTarget<MockMoveTouchTarget>(); |
| 1061 |
| 1062 SyntheticSmoothDragGestureParams params; |
| 1063 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 1064 params.start_point.SetPoint(89, 32); |
| 1065 params.distances.push_back(gfx::Vector2d(0, 123)); |
| 1066 params.speed_in_pixels_s = 800; |
| 1067 |
| 1068 scoped_ptr<SyntheticSmoothDragGesture> gesture( |
| 1069 new SyntheticSmoothDragGesture(params)); |
| 1070 const base::TimeTicks timestamp; |
| 1071 gesture->ForwardInputEvents(timestamp, target_); |
| 1072 } |
| 1073 |
| 1074 TEST_F(SyntheticGestureControllerTest, |
| 1075 SyntheticSmoothScrollTestUsingSingleTouchScroll) { |
| 1076 CreateControllerAndTarget<MockMoveTouchTarget>(); |
859 | 1077 |
860 SyntheticSmoothScrollGestureParams params; | 1078 SyntheticSmoothScrollGestureParams params; |
861 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1079 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 | 1080 |
866 scoped_ptr<SyntheticSmoothScrollGesture> gesture( | 1081 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
867 new SyntheticSmoothScrollGesture(params)); | 1082 new SyntheticSmoothScrollGesture(params)); |
868 QueueSyntheticGesture(gesture.Pass()); | 1083 const base::TimeTicks timestamp; |
869 FlushInputUntilComplete(); | 1084 gesture->ForwardInputEvents(timestamp, target_); |
| 1085 } |
870 | 1086 |
871 MockScrollGestureTarget* scroll_target = | 1087 TEST_F(SyntheticGestureControllerTest, |
872 static_cast<MockScrollGestureTarget*>(target_); | 1088 SyntheticSmoothScrollTestUsingSingleMouseScroll) { |
873 EXPECT_EQ(1, num_success_); | 1089 CreateControllerAndTarget<MockScrollMouseTarget>(); |
874 EXPECT_EQ(0, num_failure_); | 1090 |
875 EXPECT_FLOAT_EQ( | 1091 SyntheticSmoothScrollGestureParams params; |
876 params.distances[0].Length() + params.distances[1].Length() + | 1092 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
877 target_->GetTouchSlopInDips(), | 1093 params.anchor.SetPoint(432, 89); |
878 scroll_target->total_abs_scroll_distance_length()); | 1094 params.distances.push_back(gfx::Vector2d(0, -234)); |
879 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], | 1095 params.speed_in_pixels_s = 800; |
880 target_), | 1096 |
881 scroll_target->start_to_end_distance()); | 1097 scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
| 1098 new SyntheticSmoothScrollGesture(params)); |
| 1099 const base::TimeTicks timestamp; |
| 1100 gesture->ForwardInputEvents(timestamp, target_); |
882 } | 1101 } |
883 | 1102 |
884 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { | 1103 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |
885 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); | 1104 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); |
886 | 1105 |
887 SyntheticPinchGestureParams params; | 1106 SyntheticPinchGestureParams params; |
888 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 1107 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
889 params.scale_factor = 2.3f; | 1108 params.scale_factor = 2.3f; |
890 params.anchor.SetPoint(54, 89); | 1109 params.anchor.SetPoint(54, 89); |
891 | 1110 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 EXPECT_TRUE(tap_target->GestureFinished()); | 1204 EXPECT_TRUE(tap_target->GestureFinished()); |
986 EXPECT_EQ(tap_target->position(), params.position); | 1205 EXPECT_EQ(tap_target->position(), params.position); |
987 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1206 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
988 EXPECT_GE(GetTotalTime(), | 1207 EXPECT_GE(GetTotalTime(), |
989 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1208 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
990 } | 1209 } |
991 | 1210 |
992 } // namespace | 1211 } // namespace |
993 | 1212 |
994 } // namespace content | 1213 } // namespace content |
OLD | NEW |