Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 929333002: Adding synthetic touch/mouse drag [Part1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Splitting CL and adding unittests. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 106
104 bool flush_requested() const { return flush_requested_; } 107 bool flush_requested() const { return flush_requested_; }
105 void ClearFlushRequest() { flush_requested_ = false; } 108 void ClearFlushRequest() { flush_requested_ = false; }
106 109
107 private: 110 private:
108 bool flush_requested_; 111 bool flush_requested_;
109 112
110 int pointer_assumed_stopped_time_ms_; 113 int pointer_assumed_stopped_time_ms_;
111 }; 114 };
112 115
113 class MockScrollGestureTarget : public MockSyntheticGestureTarget { 116 class MockMoveGestureTarget : public MockSyntheticGestureTarget {
114 public: 117 public:
115 MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {} 118 MockMoveGestureTarget() : total_abs_move_distance_length_(0) {}
116 ~MockScrollGestureTarget() override {} 119 ~MockMoveGestureTarget() override {}
117 120
118 gfx::Vector2dF start_to_end_distance() const { 121 gfx::Vector2dF start_to_end_distance() const {
119 return start_to_end_distance_; 122 return start_to_end_distance_;
120 } 123 }
121 float total_abs_scroll_distance_length() const { 124 float total_abs_move_distance_length() const {
122 return total_abs_scroll_distance_length_; 125 return total_abs_move_distance_length_;
123 } 126 }
124 127
125 protected: 128 protected:
126 gfx::Vector2dF start_to_end_distance_; 129 gfx::Vector2dF start_to_end_distance_;
127 float total_abs_scroll_distance_length_; 130 float total_abs_move_distance_length_;
128 }; 131 };
129 132
130 class MockScrollMouseTarget : public MockScrollGestureTarget { 133 class MockScrollMouseTarget : public MockMoveGestureTarget {
131 public: 134 public:
132 MockScrollMouseTarget() {} 135 MockScrollMouseTarget() {}
133 ~MockScrollMouseTarget() override {} 136 ~MockScrollMouseTarget() override {}
134 137
135 void DispatchInputEventToPlatform(const WebInputEvent& event) override { 138 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
136 ASSERT_EQ(event.type, WebInputEvent::MouseWheel); 139 ASSERT_EQ(event.type, WebInputEvent::MouseWheel);
137 const WebMouseWheelEvent& mouse_wheel_event = 140 const WebMouseWheelEvent& mouse_wheel_event =
138 static_cast<const WebMouseWheelEvent&>(event); 141 static_cast<const WebMouseWheelEvent&>(event);
139 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY); 142 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY);
140 start_to_end_distance_ += delta; 143 start_to_end_distance_ += delta;
141 total_abs_scroll_distance_length_ += delta.Length(); 144 total_abs_move_distance_length_ += delta.Length();
142 } 145 }
143 }; 146 };
144 147
145 class MockScrollTouchTarget : public MockScrollGestureTarget { 148 class MockMoveTouchTarget : public MockMoveGestureTarget {
146 public: 149 public:
147 MockScrollTouchTarget() : started_(false) {} 150 MockMoveTouchTarget() : started_(false) {}
148 ~MockScrollTouchTarget() override {} 151 ~MockMoveTouchTarget() override {}
149 152
150 void DispatchInputEventToPlatform(const WebInputEvent& event) override { 153 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
151 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 154 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
152 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 155 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
153 ASSERT_EQ(touch_event.touchesLength, 1U); 156 ASSERT_EQ(touch_event.touchesLength, 1U);
154 157
155 if (!started_) { 158 if (!started_) {
156 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); 159 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
157 start_.SetPoint(touch_event.touches[0].position.x, 160 start_.SetPoint(touch_event.touches[0].position.x,
158 touch_event.touches[0].position.y); 161 touch_event.touches[0].position.y);
159 last_touch_point_ = start_; 162 last_touch_point_ = start_;
160 started_ = true; 163 started_ = true;
161 } else { 164 } else {
162 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); 165 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart);
163 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); 166 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel);
164 167
165 gfx::PointF touch_point(touch_event.touches[0].position.x, 168 gfx::PointF touch_point(touch_event.touches[0].position.x,
166 touch_event.touches[0].position.y); 169 touch_event.touches[0].position.y);
167 gfx::Vector2dF delta = touch_point - last_touch_point_; 170 gfx::Vector2dF delta = touch_point - last_touch_point_;
168 total_abs_scroll_distance_length_ += delta.Length(); 171 total_abs_move_distance_length_ += delta.Length();
169 172
170 if (touch_event.type == WebInputEvent::TouchEnd) 173 if (touch_event.type == WebInputEvent::TouchEnd)
171 start_to_end_distance_ = touch_point - start_; 174 start_to_end_distance_ = touch_point - start_;
172 175
173 last_touch_point_ = touch_point; 176 last_touch_point_ = touch_point;
174 } 177 }
175 } 178 }
176 179
177 protected: 180 protected:
178 gfx::Point start_; 181 gfx::Point start_;
179 gfx::PointF last_touch_point_; 182 gfx::PointF last_touch_point_;
180 bool started_; 183 bool started_;
181 }; 184 };
182 185
186 class MockDragMouseTarget : public MockMoveGestureTarget {
187 public:
188 MockDragMouseTarget() : started_(false) {}
189 ~MockDragMouseTarget() override {}
190
191 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
192 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
193 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
194 if (!started_) {
195 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
196 EXPECT_EQ(mouse_event.clickCount, 1);
197 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown);
198 start_.SetPoint(mouse_event.x, mouse_event.y);
199 last_mouse_point_ = start_;
200 started_ = true;
201 } else {
202 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
203 ASSERT_NE(mouse_event.type, WebInputEvent::MouseDown);
204
205 gfx::PointF mouse_point(mouse_event.x, mouse_event.y);
206 gfx::Vector2dF delta = mouse_point - last_mouse_point_;
207 total_abs_move_distance_length_ += delta.Length();
208 if (mouse_event.type == WebInputEvent::MouseUp)
209 start_to_end_distance_ = mouse_point - start_;
210 last_mouse_point_ = mouse_point;
211 }
212 }
213
214 private:
215 bool started_;
216 gfx::PointF start_, last_mouse_point_;
217 };
218
183 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { 219 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget {
184 public: 220 public:
185 enum ZoomDirection { 221 enum ZoomDirection {
186 ZOOM_DIRECTION_UNKNOWN, 222 ZOOM_DIRECTION_UNKNOWN,
187 ZOOM_IN, 223 ZOOM_IN,
188 ZOOM_OUT 224 ZOOM_OUT
189 }; 225 };
190 226
191 MockSyntheticPinchTouchTarget() 227 MockSyntheticPinchTouchTarget()
192 : initial_pointer_distance_(0), 228 : initial_pointer_distance_(0),
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); 385 static_cast<int64>(mouse_event.timeStampSeconds * 1000));
350 state_ = FINISHED; 386 state_ = FINISHED;
351 break; 387 break;
352 case FINISHED: 388 case FINISHED:
353 EXPECT_FALSE(true); 389 EXPECT_FALSE(true);
354 break; 390 break;
355 } 391 }
356 } 392 }
357 }; 393 };
358 394
359 class SyntheticGestureControllerTest : public testing::Test { 395 class SyntheticGestureControllerTestUtility {
360 public: 396 public:
361 SyntheticGestureControllerTest() {} 397 SyntheticGestureControllerTestUtility() {}
362 ~SyntheticGestureControllerTest() override {} 398 ~SyntheticGestureControllerTestUtility() {}
363 399
364 protected: 400 protected:
365 template<typename MockGestureTarget> 401 template<typename MockGestureTarget>
366 void CreateControllerAndTarget() { 402 void CreateControllerAndTarget() {
367 target_ = new MockGestureTarget(); 403 target_ = new MockGestureTarget();
368 controller_.reset(new SyntheticGestureController( 404 controller_.reset(new SyntheticGestureController(
369 scoped_ptr<SyntheticGestureTarget>(target_))); 405 scoped_ptr<SyntheticGestureTarget>(target_)));
370 } 406 }
371 407
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) { 408 void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) {
386 controller_->QueueSyntheticGesture(gesture.Pass(), 409 controller_->QueueSyntheticGesture(
387 base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted, 410 gesture.Pass(),
411 base::Bind(
412 &SyntheticGestureControllerTestUtility::OnSyntheticGestureCompleted,
388 base::Unretained(this))); 413 base::Unretained(this)));
389 } 414 }
390 415
391 void FlushInputUntilComplete() { 416 void FlushInputUntilComplete() {
392 while (target_->flush_requested()) { 417 while (target_->flush_requested()) {
393 while (target_->flush_requested()) { 418 while (target_->flush_requested()) {
394 target_->ClearFlushRequest(); 419 target_->ClearFlushRequest();
395 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); 420 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
396 controller_->Flush(time_); 421 controller_->Flush(time_);
397 } 422 }
(...skipping 12 matching lines...) Expand all
410 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } 435 base::TimeDelta GetTotalTime() const { return time_ - start_time_; }
411 436
412 MockSyntheticGestureTarget* target_; 437 MockSyntheticGestureTarget* target_;
413 scoped_ptr<SyntheticGestureController> controller_; 438 scoped_ptr<SyntheticGestureController> controller_;
414 base::TimeTicks start_time_; 439 base::TimeTicks start_time_;
415 base::TimeTicks time_; 440 base::TimeTicks time_;
416 int num_success_; 441 int num_success_;
417 int num_failure_; 442 int num_failure_;
418 }; 443 };
419 444
445 class SyntheticGestureControllerTest
446 : public SyntheticGestureControllerTestUtility,
447 public testing::Test {
448 protected:
449 void SetUp() override {
450 start_time_ = base::TimeTicks::Now();
451 time_ = start_time_;
452 num_success_ = 0;
453 num_failure_ = 0;
454 }
455
456 void TearDown() override {
457 controller_.reset();
458 target_ = NULL;
459 time_ = base::TimeTicks();
460 }
461 };
462
463 class SyntheticGestureControllerTestWithParam
464 : public SyntheticGestureControllerTestUtility,
465 public testing::TestWithParam<bool> {
466 protected:
467 void SetUp() override {
468 start_time_ = base::TimeTicks::Now();
469 time_ = start_time_;
470 num_success_ = 0;
471 num_failure_ = 0;
472 }
473
474 void TearDown() override {
475 controller_.reset();
476 target_ = NULL;
477 time_ = base::TimeTicks();
478 }
479 };
480
420 TEST_F(SyntheticGestureControllerTest, SingleGesture) { 481 TEST_F(SyntheticGestureControllerTest, SingleGesture) {
421 CreateControllerAndTarget<MockSyntheticGestureTarget>(); 482 CreateControllerAndTarget<MockSyntheticGestureTarget>();
422 483
423 bool finished = false; 484 bool finished = false;
424 scoped_ptr<MockSyntheticGesture> gesture( 485 scoped_ptr<MockSyntheticGesture> gesture(
425 new MockSyntheticGesture(&finished, 3)); 486 new MockSyntheticGesture(&finished, 3));
426 QueueSyntheticGesture(gesture.Pass()); 487 QueueSyntheticGesture(gesture.Pass());
427 FlushInputUntilComplete(); 488 FlushInputUntilComplete();
428 489
429 EXPECT_TRUE(finished); 490 EXPECT_TRUE(finished);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 597
537 int y = vector.y(); 598 int y = vector.y();
538 if (y > 0) 599 if (y > 0)
539 y += kTouchSlop; 600 y += kTouchSlop;
540 else if (y < 0) 601 else if (y < 0)
541 y -= kTouchSlop; 602 y -= kTouchSlop;
542 603
543 return gfx::Vector2d(x, y); 604 return gfx::Vector2d(x, y);
544 } 605 }
545 606
546 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) { 607 scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams(
547 CreateControllerAndTarget<MockScrollTouchTarget>(); 608 SyntheticSmoothScrollGestureParams params,
609 SyntheticSmoothMoveGesture::InputType input_type) {
610 std::vector<gfx::Vector2dF> distances_float;
611 for (uint64 i = 0; i < params.distances.size(); i++)
612 distances_float.push_back(params.distances[i]);
613
614 scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture(
615 input_type, params.anchor, distances_float, params.speed_in_pixels_s,
616 params.prevent_fling));
617 return gesture;
618 }
619
620 TEST_P(SyntheticGestureControllerTestWithParam,
621 SingleMoveGestureTouchVertical) {
622 CreateControllerAndTarget<MockMoveTouchTarget>();
548 623
549 SyntheticSmoothScrollGestureParams params; 624 SyntheticSmoothScrollGestureParams params;
550 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 625 SyntheticSmoothMoveGesture::InputType input_type;
626 if (GetParam()) {
627 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
628 } else {
629 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
630 }
551 params.anchor.SetPoint(89, 32); 631 params.anchor.SetPoint(89, 32);
552 params.distances.push_back(gfx::Vector2d(0, 123)); 632 params.distances.push_back(gfx::Vector2d(0, 123));
553 633
554 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 634 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
555 new SyntheticSmoothScrollGesture(params)); 635 CreateMoveGestureUsingParams(params, input_type);
556 QueueSyntheticGesture(gesture.Pass()); 636 QueueSyntheticGesture(gesture.Pass());
557 FlushInputUntilComplete(); 637 FlushInputUntilComplete();
558 638
559 MockScrollGestureTarget* scroll_target = 639 MockMoveGestureTarget* scroll_target =
560 static_cast<MockScrollGestureTarget*>(target_); 640 static_cast<MockMoveGestureTarget*>(target_);
561 EXPECT_EQ(1, num_success_); 641 EXPECT_EQ(1, num_success_);
562 EXPECT_EQ(0, num_failure_); 642 EXPECT_EQ(0, num_failure_);
563 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), 643 if (GetParam()) {
564 scroll_target->start_to_end_distance()); 644 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
645 scroll_target->start_to_end_distance());
646 } else {
647 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
648 }
565 } 649 }
650 INSTANTIATE_TEST_CASE_P(Single,
ssid 2015/02/20 10:58:56 I am not sure where to place this statement. Hard
651 SyntheticGestureControllerTestWithParam,
652 testing::Values(true, false));
566 653
567 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) { 654 TEST_P(SyntheticGestureControllerTestWithParam,
568 CreateControllerAndTarget<MockScrollTouchTarget>(); 655 SingleScrollGestureTouchHorizontal) {
656 CreateControllerAndTarget<MockMoveTouchTarget>();
569 657
570 SyntheticSmoothScrollGestureParams params; 658 SyntheticSmoothScrollGestureParams params;
571 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 659 SyntheticSmoothMoveGesture::InputType input_type;
660 if (GetParam()) {
661 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
662 } else {
663 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
664 }
572 params.anchor.SetPoint(12, -23); 665 params.anchor.SetPoint(12, -23);
573 params.distances.push_back(gfx::Vector2d(-234, 0)); 666 params.distances.push_back(gfx::Vector2d(-234, 0));
574 667
575 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 668 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
576 new SyntheticSmoothScrollGesture(params)); 669 CreateMoveGestureUsingParams(params, input_type);
577 QueueSyntheticGesture(gesture.Pass()); 670 QueueSyntheticGesture(gesture.Pass());
578 FlushInputUntilComplete(); 671 FlushInputUntilComplete();
579 672
580 MockScrollGestureTarget* scroll_target = 673 MockMoveGestureTarget* scroll_target =
581 static_cast<MockScrollGestureTarget*>(target_); 674 static_cast<MockMoveGestureTarget*>(target_);
582 EXPECT_EQ(1, num_success_); 675 EXPECT_EQ(1, num_success_);
583 EXPECT_EQ(0, num_failure_); 676 EXPECT_EQ(0, num_failure_);
677 if (GetParam()) {
584 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), 678 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
585 scroll_target->start_to_end_distance()); 679 scroll_target->start_to_end_distance());
680 } else {
681 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
682 }
586 } 683 }
587 684
588 void CheckIsWithinRangeSingle(float scroll_distance, 685 void CheckIsWithinRangeSingle(float scroll_distance,
589 int target_distance, 686 int target_distance,
590 SyntheticGestureTarget* target) { 687 SyntheticGestureTarget* target) {
591 if (target_distance > 0) { 688 if (target_distance > 0) {
592 EXPECT_LE(target_distance, scroll_distance); 689 EXPECT_LE(target_distance, scroll_distance);
593 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 690 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
594 } else { 691 } else {
595 EXPECT_GE(target_distance, scroll_distance); 692 EXPECT_GE(target_distance, scroll_distance);
596 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 693 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
597 } 694 }
598 } 695 }
599 696
600 void CheckSingleScrollDistanceIsWithinRange( 697 void CheckSingleScrollDistanceIsWithinRange(
601 const gfx::Vector2dF& scroll_distance, 698 const gfx::Vector2dF& scroll_distance,
602 const gfx::Vector2d& target_distance, 699 const gfx::Vector2d& target_distance,
603 SyntheticGestureTarget* target) { 700 SyntheticGestureTarget* target) {
604 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); 701 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target);
605 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); 702 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target);
606 } 703 }
607 704
608 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { 705 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) {
609 CreateControllerAndTarget<MockScrollTouchTarget>(); 706 CreateControllerAndTarget<MockMoveTouchTarget>();
610 707
611 SyntheticSmoothScrollGestureParams params; 708 SyntheticSmoothScrollGestureParams params;
612 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 709 SyntheticSmoothMoveGesture::InputType input_type =
710 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
613 params.anchor.SetPoint(0, 7); 711 params.anchor.SetPoint(0, 7);
614 params.distances.push_back(gfx::Vector2d(413, -83)); 712 params.distances.push_back(gfx::Vector2d(413, -83));
615 713
616 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 714 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
617 new SyntheticSmoothScrollGesture(params)); 715 CreateMoveGestureUsingParams(params, input_type);
618 QueueSyntheticGesture(gesture.Pass()); 716 QueueSyntheticGesture(gesture.Pass());
619 FlushInputUntilComplete(); 717 FlushInputUntilComplete();
620 718
621 MockScrollGestureTarget* scroll_target = 719 MockMoveGestureTarget* scroll_target =
622 static_cast<MockScrollGestureTarget*>(target_); 720 static_cast<MockMoveGestureTarget*>(target_);
623 EXPECT_EQ(1, num_success_); 721 EXPECT_EQ(1, num_success_);
624 EXPECT_EQ(0, num_failure_); 722 EXPECT_EQ(0, num_failure_);
625 CheckSingleScrollDistanceIsWithinRange( 723 CheckSingleScrollDistanceIsWithinRange(
626 scroll_target->start_to_end_distance(), params.distances[0], target_); 724 scroll_target->start_to_end_distance(), params.distances[0], target_);
627 } 725 }
628 726
629 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { 727 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) {
630 CreateControllerAndTarget<MockScrollTouchTarget>(); 728 CreateControllerAndTarget<MockMoveTouchTarget>();
631 729
632 // Create a smooth scroll with a short distance and set the pointer assumed 730 // 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 731 // stopped time high, so that the stopping should dominate the time the
634 // gesture is active. 732 // gesture is active.
635 SyntheticSmoothScrollGestureParams params; 733 SyntheticSmoothScrollGestureParams params;
636 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 734 SyntheticSmoothMoveGesture::InputType input_type =
735 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
637 params.anchor.SetPoint(-98, -23); 736 params.anchor.SetPoint(-98, -23);
638 params.distances.push_back(gfx::Vector2d(21, -12)); 737 params.distances.push_back(gfx::Vector2d(21, -12));
639 params.prevent_fling = true; 738 params.prevent_fling = true;
640 739
641 target_->set_pointer_assumed_stopped_time_ms(543); 740 target_->set_pointer_assumed_stopped_time_ms(543);
642 741
643 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 742 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
644 new SyntheticSmoothScrollGesture(params)); 743 CreateMoveGestureUsingParams(params, input_type);
645 QueueSyntheticGesture(gesture.Pass()); 744 QueueSyntheticGesture(gesture.Pass());
646 FlushInputUntilComplete(); 745 FlushInputUntilComplete();
647 746
648 MockScrollGestureTarget* scroll_target = 747 MockMoveGestureTarget* scroll_target =
649 static_cast<MockScrollGestureTarget*>(target_); 748 static_cast<MockMoveGestureTarget*>(target_);
650 EXPECT_EQ(1, num_success_); 749 EXPECT_EQ(1, num_success_);
651 EXPECT_EQ(0, num_failure_); 750 EXPECT_EQ(0, num_failure_);
652 CheckSingleScrollDistanceIsWithinRange( 751 CheckSingleScrollDistanceIsWithinRange(
653 scroll_target->start_to_end_distance(), params.distances[0], target_); 752 scroll_target->start_to_end_distance(), params.distances[0], target_);
654 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); 753 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime());
655 } 754 }
656 755
657 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { 756 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) {
658 CreateControllerAndTarget<MockScrollTouchTarget>(); 757 CreateControllerAndTarget<MockMoveTouchTarget>();
659 758
660 // Create a smooth scroll with a short distance and set the pointer assumed 759 // 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 760 // stopped time high. Disable 'prevent_fling' and check that the gesture
662 // finishes without waiting before it stops. 761 // finishes without waiting before it stops.
663 SyntheticSmoothScrollGestureParams params; 762 SyntheticSmoothScrollGestureParams params;
664 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 763 SyntheticSmoothMoveGesture::InputType input_type =
764 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
665 params.anchor.SetPoint(-89, 78); 765 params.anchor.SetPoint(-89, 78);
666 params.distances.push_back(gfx::Vector2d(-43, 19)); 766 params.distances.push_back(gfx::Vector2d(-43, 19));
667 params.prevent_fling = false; 767 params.prevent_fling = false;
668 768
669 target_->set_pointer_assumed_stopped_time_ms(543); 769 target_->set_pointer_assumed_stopped_time_ms(543);
670 770
671 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 771 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
672 new SyntheticSmoothScrollGesture(params)); 772 CreateMoveGestureUsingParams(params, input_type);
673 QueueSyntheticGesture(gesture.Pass()); 773 QueueSyntheticGesture(gesture.Pass());
674 FlushInputUntilComplete(); 774 FlushInputUntilComplete();
675 775
676 MockScrollGestureTarget* scroll_target = 776 MockMoveGestureTarget* scroll_target =
677 static_cast<MockScrollGestureTarget*>(target_); 777 static_cast<MockMoveGestureTarget*>(target_);
678 EXPECT_EQ(1, num_success_); 778 EXPECT_EQ(1, num_success_);
679 EXPECT_EQ(0, num_failure_); 779 EXPECT_EQ(0, num_failure_);
680 CheckSingleScrollDistanceIsWithinRange( 780 CheckSingleScrollDistanceIsWithinRange(
681 scroll_target->start_to_end_distance(), params.distances[0], target_); 781 scroll_target->start_to_end_distance(), params.distances[0], target_);
682 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); 782 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime());
683 } 783 }
684 784
685 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) { 785 TEST_P(SyntheticGestureControllerTestWithParam,
ssid 2015/02/20 10:58:56 Should I move all the tests under SyntheticGesture
686 CreateControllerAndTarget<MockScrollTouchTarget>(); 786 SingleScrollGestureTouchZeroDistance) {
787 CreateControllerAndTarget<MockMoveTouchTarget>();
687 788
688 SyntheticSmoothScrollGestureParams params; 789 SyntheticSmoothScrollGestureParams params;
689 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 790 SyntheticSmoothMoveGesture::InputType input_type;
791 if (GetParam()) {
792 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
793 } else {
794 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
795 }
690 params.anchor.SetPoint(-32, 43); 796 params.anchor.SetPoint(-32, 43);
691 params.distances.push_back(gfx::Vector2d(0, 0)); 797 params.distances.push_back(gfx::Vector2d(0, 0));
692 798
693 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 799 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
694 new SyntheticSmoothScrollGesture(params)); 800 CreateMoveGestureUsingParams(params, input_type);
695 QueueSyntheticGesture(gesture.Pass()); 801 QueueSyntheticGesture(gesture.Pass());
696 FlushInputUntilComplete(); 802 FlushInputUntilComplete();
697 803
698 MockScrollGestureTarget* scroll_target = 804 MockMoveGestureTarget* scroll_target =
699 static_cast<MockScrollGestureTarget*>(target_); 805 static_cast<MockMoveGestureTarget*>(target_);
700 EXPECT_EQ(1, num_success_); 806 EXPECT_EQ(1, num_success_);
701 EXPECT_EQ(0, num_failure_); 807 EXPECT_EQ(0, num_failure_);
702 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); 808 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance());
703 } 809 }
704 810
705 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { 811 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) {
706 CreateControllerAndTarget<MockScrollMouseTarget>(); 812 CreateControllerAndTarget<MockScrollMouseTarget>();
707 813
708 SyntheticSmoothScrollGestureParams params; 814 SyntheticSmoothScrollGestureParams params;
709 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 815 SyntheticSmoothMoveGesture::InputType input_type =
816 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
710 params.anchor.SetPoint(432, 89); 817 params.anchor.SetPoint(432, 89);
711 params.distances.push_back(gfx::Vector2d(0, -234)); 818 params.distances.push_back(gfx::Vector2d(0, -234));
712 819
713 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 820 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
714 new SyntheticSmoothScrollGesture(params)); 821 CreateMoveGestureUsingParams(params, input_type);
715 QueueSyntheticGesture(gesture.Pass()); 822 QueueSyntheticGesture(gesture.Pass());
716 FlushInputUntilComplete(); 823 FlushInputUntilComplete();
717 824
718 MockScrollGestureTarget* scroll_target = 825 MockMoveGestureTarget* scroll_target =
719 static_cast<MockScrollGestureTarget*>(target_); 826 static_cast<MockMoveGestureTarget*>(target_);
720 EXPECT_EQ(1, num_success_); 827 EXPECT_EQ(1, num_success_);
721 EXPECT_EQ(0, num_failure_); 828 EXPECT_EQ(0, num_failure_);
722 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 829 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
723 } 830 }
724 831
725 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { 832 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) {
726 CreateControllerAndTarget<MockScrollMouseTarget>(); 833 CreateControllerAndTarget<MockScrollMouseTarget>();
727 834
728 SyntheticSmoothScrollGestureParams params; 835 SyntheticSmoothScrollGestureParams params;
729 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 836 SyntheticSmoothMoveGesture::InputType input_type =
837 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
730 params.anchor.SetPoint(90, 12); 838 params.anchor.SetPoint(90, 12);
731 params.distances.push_back(gfx::Vector2d(345, 0)); 839 params.distances.push_back(gfx::Vector2d(345, 0));
732 840
733 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 841 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
734 new SyntheticSmoothScrollGesture(params)); 842 CreateMoveGestureUsingParams(params, input_type);
735 QueueSyntheticGesture(gesture.Pass()); 843 QueueSyntheticGesture(gesture.Pass());
736 FlushInputUntilComplete(); 844 FlushInputUntilComplete();
737 845
738 MockScrollGestureTarget* scroll_target = 846 MockMoveGestureTarget* scroll_target =
739 static_cast<MockScrollGestureTarget*>(target_); 847 static_cast<MockMoveGestureTarget*>(target_);
740 EXPECT_EQ(1, num_success_); 848 EXPECT_EQ(1, num_success_);
741 EXPECT_EQ(0, num_failure_); 849 EXPECT_EQ(0, num_failure_);
742 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 850 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
743 } 851 }
744 852
745 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { 853 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) {
746 CreateControllerAndTarget<MockScrollMouseTarget>(); 854 CreateControllerAndTarget<MockScrollMouseTarget>();
747 855
748 SyntheticSmoothScrollGestureParams params; 856 SyntheticSmoothScrollGestureParams params;
749 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 857 SyntheticSmoothMoveGesture::InputType input_type =
858 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
750 params.anchor.SetPoint(90, 12); 859 params.anchor.SetPoint(90, 12);
751 params.distances.push_back(gfx::Vector2d(-194, 303)); 860 params.distances.push_back(gfx::Vector2d(-194, 303));
752 861
753 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 862 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
754 new SyntheticSmoothScrollGesture(params)); 863 CreateMoveGestureUsingParams(params, input_type);
755 QueueSyntheticGesture(gesture.Pass()); 864 QueueSyntheticGesture(gesture.Pass());
756 FlushInputUntilComplete(); 865 FlushInputUntilComplete();
757 866
758 MockScrollGestureTarget* scroll_target = 867 MockMoveGestureTarget* scroll_target =
759 static_cast<MockScrollGestureTarget*>(target_); 868 static_cast<MockMoveGestureTarget*>(target_);
760 EXPECT_EQ(1, num_success_); 869 EXPECT_EQ(1, num_success_);
761 EXPECT_EQ(0, num_failure_); 870 EXPECT_EQ(0, num_failure_);
762 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 871 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
763 } 872 }
764 873
765 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { 874 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) {
766 CreateControllerAndTarget<MockScrollMouseTarget>(); 875 CreateControllerAndTarget<MockScrollMouseTarget>();
767 876
768 SyntheticSmoothScrollGestureParams params; 877 SyntheticSmoothScrollGestureParams params;
769 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 878 SyntheticSmoothMoveGesture::InputType input_type =
879 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
770 params.anchor.SetPoint(90, 12); 880 params.anchor.SetPoint(90, 12);
771 params.distances.push_back(gfx::Vector2d(-129, 212)); 881 params.distances.push_back(gfx::Vector2d(-129, 212));
772 params.distances.push_back(gfx::Vector2d(8, -9)); 882 params.distances.push_back(gfx::Vector2d(8, -9));
773 883
774 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 884 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
775 new SyntheticSmoothScrollGesture(params)); 885 CreateMoveGestureUsingParams(params, input_type);
776 QueueSyntheticGesture(gesture.Pass()); 886 QueueSyntheticGesture(gesture.Pass());
777 FlushInputUntilComplete(); 887 FlushInputUntilComplete();
778 888
779 MockScrollGestureTarget* scroll_target = 889 MockMoveGestureTarget* scroll_target =
780 static_cast<MockScrollGestureTarget*>(target_); 890 static_cast<MockMoveGestureTarget*>(target_);
781 EXPECT_EQ(1, num_success_); 891 EXPECT_EQ(1, num_success_);
782 EXPECT_EQ(0, num_failure_); 892 EXPECT_EQ(0, num_failure_);
783 EXPECT_EQ(params.distances[0] + params.distances[1], 893 EXPECT_EQ(params.distances[0] + params.distances[1],
784 scroll_target->start_to_end_distance()); 894 scroll_target->start_to_end_distance());
785 } 895 }
786 896
787 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { 897 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) {
788 CreateControllerAndTarget<MockScrollMouseTarget>(); 898 CreateControllerAndTarget<MockScrollMouseTarget>();
789 899
790 SyntheticSmoothScrollGestureParams params; 900 SyntheticSmoothScrollGestureParams params;
791 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 901 SyntheticSmoothMoveGesture::InputType input_type =
902 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
792 params.anchor.SetPoint(90, 12); 903 params.anchor.SetPoint(90, 12);
793 params.distances.push_back(gfx::Vector2d(-129, 0)); 904 params.distances.push_back(gfx::Vector2d(-129, 0));
794 params.distances.push_back(gfx::Vector2d(79, 0)); 905 params.distances.push_back(gfx::Vector2d(79, 0));
795 906
796 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 907 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
797 new SyntheticSmoothScrollGesture(params)); 908 CreateMoveGestureUsingParams(params, input_type);
798 QueueSyntheticGesture(gesture.Pass()); 909 QueueSyntheticGesture(gesture.Pass());
799 FlushInputUntilComplete(); 910 FlushInputUntilComplete();
800 911
801 MockScrollGestureTarget* scroll_target = 912 MockMoveGestureTarget* scroll_target =
802 static_cast<MockScrollGestureTarget*>(target_); 913 static_cast<MockMoveGestureTarget*>(target_);
803 EXPECT_EQ(1, num_success_); 914 EXPECT_EQ(1, num_success_);
804 EXPECT_EQ(0, num_failure_); 915 EXPECT_EQ(0, num_failure_);
805 // This check only works for horizontal or vertical scrolls because of 916 // This check only works for horizontal or vertical scrolls because of
806 // floating point precision issues with diagonal scrolls. 917 // floating point precision issues with diagonal scrolls.
807 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), 918 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
808 scroll_target->total_abs_scroll_distance_length()); 919 scroll_target->total_abs_move_distance_length());
809 EXPECT_EQ(params.distances[0] + params.distances[1], 920 EXPECT_EQ(params.distances[0] + params.distances[1],
810 scroll_target->start_to_end_distance()); 921 scroll_target->start_to_end_distance());
811 } 922 }
812 923
813 void CheckIsWithinRangeMulti(float scroll_distance, 924 void CheckIsWithinRangeMulti(float scroll_distance,
814 int target_distance, 925 int target_distance,
815 SyntheticGestureTarget* target) { 926 SyntheticGestureTarget* target) {
816 if (target_distance > 0) { 927 if (target_distance > 0) {
817 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 928 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
818 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 929 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
819 } else { 930 } else {
820 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 931 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
821 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 932 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
822 } 933 }
823 } 934 }
824 935
825 void CheckMultiScrollDistanceIsWithinRange( 936 void CheckMultiScrollDistanceIsWithinRange(
826 const gfx::Vector2dF& scroll_distance, 937 const gfx::Vector2dF& scroll_distance,
827 const gfx::Vector2d& target_distance, 938 const gfx::Vector2d& target_distance,
828 SyntheticGestureTarget* target) { 939 SyntheticGestureTarget* target) {
829 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); 940 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target);
830 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); 941 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target);
831 } 942 }
832 943
833 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { 944 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) {
834 CreateControllerAndTarget<MockScrollTouchTarget>(); 945 CreateControllerAndTarget<MockMoveTouchTarget>();
835 946
836 SyntheticSmoothScrollGestureParams params; 947 SyntheticSmoothScrollGestureParams params;
837 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 948 SyntheticSmoothMoveGesture::InputType input_type =
949 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
838 params.anchor.SetPoint(8, -13); 950 params.anchor.SetPoint(8, -13);
839 params.distances.push_back(gfx::Vector2d(234, 133)); 951 params.distances.push_back(gfx::Vector2d(234, 133));
840 params.distances.push_back(gfx::Vector2d(-9, 78)); 952 params.distances.push_back(gfx::Vector2d(-9, 78));
841 953
842 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 954 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
843 new SyntheticSmoothScrollGesture(params)); 955 CreateMoveGestureUsingParams(params, input_type);
844 QueueSyntheticGesture(gesture.Pass()); 956 QueueSyntheticGesture(gesture.Pass());
845 FlushInputUntilComplete(); 957 FlushInputUntilComplete();
846 958
847 MockScrollGestureTarget* scroll_target = 959 MockMoveGestureTarget* scroll_target =
848 static_cast<MockScrollGestureTarget*>(target_); 960 static_cast<MockMoveGestureTarget*>(target_);
849 EXPECT_EQ(1, num_success_); 961 EXPECT_EQ(1, num_success_);
850 EXPECT_EQ(0, num_failure_); 962 EXPECT_EQ(0, num_failure_);
851 CheckMultiScrollDistanceIsWithinRange( 963 CheckMultiScrollDistanceIsWithinRange(
852 scroll_target->start_to_end_distance(), 964 scroll_target->start_to_end_distance(),
853 params.distances[0] + params.distances[1], 965 params.distances[0] + params.distances[1],
854 target_); 966 target_);
855 } 967 }
856 968
857 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) { 969 TEST_P(SyntheticGestureControllerTestWithParam,
858 CreateControllerAndTarget<MockScrollTouchTarget>(); 970 MultiScrollGestureTouchVertical) {
971 CreateControllerAndTarget<MockMoveTouchTarget>();
859 972
860 SyntheticSmoothScrollGestureParams params; 973 SyntheticSmoothScrollGestureParams params;
861 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 974 SyntheticSmoothMoveGesture::InputType input_type;
975 if (GetParam()) {
976 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
977 } else {
978 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
979 }
862 params.anchor.SetPoint(234, -13); 980 params.anchor.SetPoint(234, -13);
863 params.distances.push_back(gfx::Vector2d(0, 133)); 981 params.distances.push_back(gfx::Vector2d(0, 133));
864 params.distances.push_back(gfx::Vector2d(0, 78)); 982 params.distances.push_back(gfx::Vector2d(0, 78));
865 983
866 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 984 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
867 new SyntheticSmoothScrollGesture(params)); 985 CreateMoveGestureUsingParams(params, input_type);
868 QueueSyntheticGesture(gesture.Pass()); 986 QueueSyntheticGesture(gesture.Pass());
869 FlushInputUntilComplete(); 987 FlushInputUntilComplete();
870 988
871 MockScrollGestureTarget* scroll_target = 989 MockMoveGestureTarget* scroll_target =
872 static_cast<MockScrollGestureTarget*>(target_); 990 static_cast<MockMoveGestureTarget*>(target_);
873 EXPECT_EQ(1, num_success_); 991 EXPECT_EQ(1, num_success_);
874 EXPECT_EQ(0, num_failure_); 992 EXPECT_EQ(0, num_failure_);
875 EXPECT_FLOAT_EQ( 993 if (GetParam()) {
876 params.distances[0].Length() + params.distances[1].Length() + 994 EXPECT_FLOAT_EQ(params.distances[0].Length() +
877 target_->GetTouchSlopInDips(), 995 params.distances[1].Length() +
878 scroll_target->total_abs_scroll_distance_length()); 996 target_->GetTouchSlopInDips(),
997 scroll_target->total_abs_move_distance_length());
879 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], 998 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1],
880 target_), 999 target_),
881 scroll_target->start_to_end_distance()); 1000 scroll_target->start_to_end_distance());
1001 } else {
1002 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
1003 scroll_target->total_abs_move_distance_length());
1004 EXPECT_EQ(params.distances[0] + params.distances[1],
1005 scroll_target->start_to_end_distance());
1006 }
1007 }
1008
1009 scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams(
1010 SyntheticSmoothDragGestureParams params,
1011 SyntheticSmoothMoveGesture::InputType input_type) {
1012 bool prevent_fling = true;
1013
1014 scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture(
1015 input_type, params.start_point, params.distances,
1016 params.speed_in_pixels_s, prevent_fling));
1017 return gesture;
1018 }
1019
1020 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseVertical) {
1021 CreateControllerAndTarget<MockDragMouseTarget>();
1022
1023 SyntheticSmoothDragGestureParams params;
1024 SyntheticSmoothMoveGesture::InputType input_type =
1025 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1026 params.start_point.SetPoint(89, 32);
1027 params.distances.push_back(gfx::Vector2d(0, 123));
1028
1029 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1030 CreateMoveGestureUsingParams(params, input_type);
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(params.distances[0], drag_target->start_to_end_distance());
1039 }
1040
1041 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseHorizontal) {
1042 CreateControllerAndTarget<MockDragMouseTarget>();
1043
1044 SyntheticSmoothDragGestureParams params;
1045 SyntheticSmoothMoveGesture::InputType input_type =
1046 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1047 params.start_point.SetPoint(12, -23);
1048 params.distances.push_back(gfx::Vector2d(-234, 0));
1049
1050 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1051 CreateMoveGestureUsingParams(params, input_type);
1052 QueueSyntheticGesture(gesture.Pass());
1053 FlushInputUntilComplete();
1054
1055 MockMoveGestureTarget* drag_target =
1056 static_cast<MockMoveGestureTarget*>(target_);
1057 EXPECT_EQ(1, num_success_);
1058 EXPECT_EQ(0, num_failure_);
1059 EXPECT_EQ(params.distances[0], drag_target->start_to_end_distance());
1060 }
1061
1062 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) {
1063 CreateControllerAndTarget<MockDragMouseTarget>();
1064
1065 SyntheticSmoothDragGestureParams params;
1066 SyntheticSmoothMoveGesture::InputType input_type =
1067 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1068 params.start_point.SetPoint(0, 7);
1069 params.distances.push_back(gfx::Vector2d(413, -83));
1070
1071 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1072 CreateMoveGestureUsingParams(params, input_type);
1073 QueueSyntheticGesture(gesture.Pass());
1074 FlushInputUntilComplete();
1075
1076 MockMoveGestureTarget* drag_target =
1077 static_cast<MockMoveGestureTarget*>(target_);
1078 EXPECT_EQ(1, num_success_);
1079 EXPECT_EQ(0, num_failure_);
1080 EXPECT_EQ(drag_target->start_to_end_distance(), params.distances[0]);
1081 }
1082
1083 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseZeroDistance) {
1084 CreateControllerAndTarget<MockDragMouseTarget>();
1085
1086 SyntheticSmoothDragGestureParams params;
1087 SyntheticSmoothMoveGesture::InputType input_type =
1088 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1089 params.start_point.SetPoint(-32, 43);
1090 params.distances.push_back(gfx::Vector2d(0, 0));
1091
1092 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1093 CreateMoveGestureUsingParams(params, input_type);
1094 QueueSyntheticGesture(gesture.Pass());
1095 FlushInputUntilComplete();
1096
1097 MockMoveGestureTarget* drag_target =
1098 static_cast<MockMoveGestureTarget*>(target_);
1099 EXPECT_EQ(1, num_success_);
1100 EXPECT_EQ(0, num_failure_);
1101 EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target->start_to_end_distance());
1102 }
1103
1104 TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouse) {
1105 CreateControllerAndTarget<MockDragMouseTarget>();
1106
1107 SyntheticSmoothDragGestureParams params;
1108 SyntheticSmoothMoveGesture::InputType input_type =
1109 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1110 params.start_point.SetPoint(8, -13);
1111 params.distances.push_back(gfx::Vector2d(234, 133));
1112 params.distances.push_back(gfx::Vector2d(-9, 78));
1113
1114 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1115 CreateMoveGestureUsingParams(params, input_type);
1116 QueueSyntheticGesture(gesture.Pass());
1117 FlushInputUntilComplete();
1118
1119 MockMoveGestureTarget* drag_target =
1120 static_cast<MockMoveGestureTarget*>(target_);
1121 EXPECT_EQ(1, num_success_);
1122 EXPECT_EQ(0, num_failure_);
1123 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
1124 drag_target->total_abs_move_distance_length());
1125 EXPECT_EQ(drag_target->start_to_end_distance(),
1126 params.distances[0] + params.distances[1]);
1127 }
1128
1129 TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouseVertical) {
1130 CreateControllerAndTarget<MockDragMouseTarget>();
1131
1132 SyntheticSmoothDragGestureParams params;
1133 SyntheticSmoothMoveGesture::InputType input_type =
1134 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1135 params.start_point.SetPoint(234, -13);
1136 params.distances.push_back(gfx::Vector2d(0, 133));
1137 params.distances.push_back(gfx::Vector2d(0, 78));
1138
1139 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1140 CreateMoveGestureUsingParams(params, input_type);
1141 QueueSyntheticGesture(gesture.Pass());
1142 FlushInputUntilComplete();
1143
1144 MockMoveGestureTarget* drag_target =
1145 static_cast<MockMoveGestureTarget*>(target_);
1146 EXPECT_EQ(1, num_success_);
1147 EXPECT_EQ(0, num_failure_);
1148 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
1149 drag_target->total_abs_move_distance_length());
1150 EXPECT_EQ(params.distances[0] + params.distances[1],
1151 drag_target->start_to_end_distance());
882 } 1152 }
883 1153
884 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { 1154 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) {
885 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); 1155 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>();
886 1156
887 SyntheticPinchGestureParams params; 1157 SyntheticPinchGestureParams params;
888 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 1158 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
889 params.scale_factor = 2.3f; 1159 params.scale_factor = 2.3f;
890 params.anchor.SetPoint(54, 89); 1160 params.anchor.SetPoint(54, 89);
891 1161
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 EXPECT_TRUE(tap_target->GestureFinished()); 1255 EXPECT_TRUE(tap_target->GestureFinished());
986 EXPECT_EQ(tap_target->position(), params.position); 1256 EXPECT_EQ(tap_target->position(), params.position);
987 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); 1257 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
988 EXPECT_GE(GetTotalTime(), 1258 EXPECT_GE(GetTotalTime(),
989 base::TimeDelta::FromMilliseconds(params.duration_ms)); 1259 base::TimeDelta::FromMilliseconds(params.duration_ms));
990 } 1260 }
991 1261
992 } // namespace 1262 } // namespace
993 1263
994 } // namespace content 1264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698