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

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: Fixed nits. 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"
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
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
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 SyntheticGestureControllerTestUtility {
Sami 2015/02/20 17:57:07 nit: call this SyntheticGestureControllerTestBase
ssid 2015/02/23 11:40:32 Done.
360 public: 398 public:
361 SyntheticGestureControllerTest() {} 399 SyntheticGestureControllerTestUtility() {}
362 ~SyntheticGestureControllerTest() override {} 400 ~SyntheticGestureControllerTestUtility() {}
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 &SyntheticGestureControllerTestUtility::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
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 SyntheticGestureControllerTestUtility,
449 public testing::Test {
450 protected:
451 void SetUp() override {
452 start_time_ = base::TimeTicks::Now();
453 time_ = start_time_;
454 num_success_ = 0;
455 num_failure_ = 0;
456 }
457
458 void TearDown() override {
459 controller_.reset();
460 target_ = NULL;
461 time_ = base::TimeTicks();
462 }
463 };
464
465 class SyntheticGestureControllerTestWithParam
466 : public SyntheticGestureControllerTestUtility,
467 public testing::TestWithParam<bool> {
468 protected:
469 void SetUp() override {
470 start_time_ = base::TimeTicks::Now();
471 time_ = start_time_;
472 num_success_ = 0;
473 num_failure_ = 0;
474 }
475
476 void TearDown() override {
477 controller_.reset();
478 target_ = NULL;
479 time_ = base::TimeTicks();
480 }
481 };
482
420 TEST_F(SyntheticGestureControllerTest, SingleGesture) { 483 TEST_F(SyntheticGestureControllerTest, SingleGesture) {
421 CreateControllerAndTarget<MockSyntheticGestureTarget>(); 484 CreateControllerAndTarget<MockSyntheticGestureTarget>();
422 485
423 bool finished = false; 486 bool finished = false;
424 scoped_ptr<MockSyntheticGesture> gesture( 487 scoped_ptr<MockSyntheticGesture> gesture(
425 new MockSyntheticGesture(&finished, 3)); 488 new MockSyntheticGesture(&finished, 3));
426 QueueSyntheticGesture(gesture.Pass()); 489 QueueSyntheticGesture(gesture.Pass());
427 FlushInputUntilComplete(); 490 FlushInputUntilComplete();
428 491
429 EXPECT_TRUE(finished); 492 EXPECT_TRUE(finished);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams(
547 CreateControllerAndTarget<MockScrollTouchTarget>(); 610 SyntheticSmoothScrollGestureParams params,
Sami 2015/02/20 17:57:07 This shouldn't take scroll parameters since we're
ssid 2015/02/20 18:48:16 struct for move parameters sounds better because,
ssid 2015/02/23 11:40:32 Added a class for move gesture params. PTAL.
611 SyntheticSmoothMoveGesture::InputType input_type) {
612 std::vector<gfx::Vector2dF> distances_float;
613 for (uint64 i = 0; i < params.distances.size(); i++)
614 distances_float.push_back(params.distances[i]);
615
616 scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture(
617 input_type, params.anchor, distances_float, params.speed_in_pixels_s,
618 params.prevent_fling));
619 return gesture;
620 }
621
622 TEST_P(SyntheticGestureControllerTestWithParam,
623 SingleMoveGestureTouchVertical) {
624 CreateControllerAndTarget<MockMoveTouchTarget>();
548 625
549 SyntheticSmoothScrollGestureParams params; 626 SyntheticSmoothScrollGestureParams params;
550 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 627 SyntheticSmoothMoveGesture::InputType input_type;
628 if (GetParam() == TOUCH_SCROLL) {
629 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
630 } else {
631 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
632 }
551 params.anchor.SetPoint(89, 32); 633 params.anchor.SetPoint(89, 32);
552 params.distances.push_back(gfx::Vector2d(0, 123)); 634 params.distances.push_back(gfx::Vector2d(0, 123));
635 params.speed_in_pixels_s = 800;
Sami 2015/02/20 17:57:07 Why this change?
ssid 2015/02/20 18:48:16 Some tests were failing because this wasn't set an
553 636
554 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 637 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
555 new SyntheticSmoothScrollGesture(params)); 638 CreateMoveGestureUsingParams(params, input_type);
556 QueueSyntheticGesture(gesture.Pass()); 639 QueueSyntheticGesture(gesture.Pass());
557 FlushInputUntilComplete(); 640 FlushInputUntilComplete();
558 641
559 MockScrollGestureTarget* scroll_target = 642 MockMoveGestureTarget* scroll_target =
560 static_cast<MockScrollGestureTarget*>(target_); 643 static_cast<MockMoveGestureTarget*>(target_);
561 EXPECT_EQ(1, num_success_); 644 EXPECT_EQ(1, num_success_);
562 EXPECT_EQ(0, num_failure_); 645 EXPECT_EQ(0, num_failure_);
563 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), 646 if (GetParam() == TOUCH_SCROLL) {
564 scroll_target->start_to_end_distance()); 647 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
648 scroll_target->start_to_end_distance());
picksi 2015/02/20 16:34:11 Calling this 'distance' and the param 'distances'
649 } else {
650 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
651 }
565 } 652 }
653 INSTANTIATE_TEST_CASE_P(Single,
654 SyntheticGestureControllerTestWithParam,
655 testing::Values(TOUCH_SCROLL, TOUCH_DRAG));
566 656
567 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) { 657 TEST_P(SyntheticGestureControllerTestWithParam,
568 CreateControllerAndTarget<MockScrollTouchTarget>(); 658 SingleScrollGestureTouchHorizontal) {
659 CreateControllerAndTarget<MockMoveTouchTarget>();
569 660
570 SyntheticSmoothScrollGestureParams params; 661 SyntheticSmoothScrollGestureParams params;
571 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 662 SyntheticSmoothMoveGesture::InputType input_type;
663 if (GetParam() == TOUCH_SCROLL) {
664 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
665 } else {
666 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
667 }
572 params.anchor.SetPoint(12, -23); 668 params.anchor.SetPoint(12, -23);
573 params.distances.push_back(gfx::Vector2d(-234, 0)); 669 params.distances.push_back(gfx::Vector2d(-234, 0));
670 params.speed_in_pixels_s = 800;
574 671
575 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 672 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
576 new SyntheticSmoothScrollGesture(params)); 673 CreateMoveGestureUsingParams(params, input_type);
577 QueueSyntheticGesture(gesture.Pass()); 674 QueueSyntheticGesture(gesture.Pass());
578 FlushInputUntilComplete(); 675 FlushInputUntilComplete();
579 676
580 MockScrollGestureTarget* scroll_target = 677 MockMoveGestureTarget* scroll_target =
581 static_cast<MockScrollGestureTarget*>(target_); 678 static_cast<MockMoveGestureTarget*>(target_);
582 EXPECT_EQ(1, num_success_); 679 EXPECT_EQ(1, num_success_);
583 EXPECT_EQ(0, num_failure_); 680 EXPECT_EQ(0, num_failure_);
681 if (GetParam() == TOUCH_SCROLL) {
584 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), 682 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
Sami 2015/02/20 17:57:06 Indenting seems off here. "git cl format" should f
ssid 2015/02/20 18:48:16 Git cl format didn't fix this because no change=!
585 scroll_target->start_to_end_distance()); 683 scroll_target->start_to_end_distance());
684 } else {
685 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
686 }
586 } 687 }
587 688
588 void CheckIsWithinRangeSingle(float scroll_distance, 689 void CheckIsWithinRangeSingle(float scroll_distance,
589 int target_distance, 690 int target_distance,
590 SyntheticGestureTarget* target) { 691 SyntheticGestureTarget* target) {
591 if (target_distance > 0) { 692 if (target_distance > 0) {
592 EXPECT_LE(target_distance, scroll_distance); 693 EXPECT_LE(target_distance, scroll_distance);
593 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 694 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
594 } else { 695 } else {
595 EXPECT_GE(target_distance, scroll_distance); 696 EXPECT_GE(target_distance, scroll_distance);
596 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 697 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
597 } 698 }
598 } 699 }
599 700
600 void CheckSingleScrollDistanceIsWithinRange( 701 void CheckSingleScrollDistanceIsWithinRange(
601 const gfx::Vector2dF& scroll_distance, 702 const gfx::Vector2dF& scroll_distance,
602 const gfx::Vector2d& target_distance, 703 const gfx::Vector2d& target_distance,
603 SyntheticGestureTarget* target) { 704 SyntheticGestureTarget* target) {
604 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target); 705 CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target);
605 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target); 706 CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target);
606 } 707 }
607 708
608 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { 709 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) {
609 CreateControllerAndTarget<MockScrollTouchTarget>(); 710 CreateControllerAndTarget<MockMoveTouchTarget>();
610 711
611 SyntheticSmoothScrollGestureParams params; 712 SyntheticSmoothScrollGestureParams params;
612 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 713 SyntheticSmoothMoveGesture::InputType input_type =
714 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
613 params.anchor.SetPoint(0, 7); 715 params.anchor.SetPoint(0, 7);
614 params.distances.push_back(gfx::Vector2d(413, -83)); 716 params.distances.push_back(gfx::Vector2d(413, -83));
717 params.speed_in_pixels_s = 800;
615 718
picksi 2015/02/20 16:34:11 The vertical, horizontal, diagonal and zero tests
616 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 719 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
617 new SyntheticSmoothScrollGesture(params)); 720 CreateMoveGestureUsingParams(params, input_type);
618 QueueSyntheticGesture(gesture.Pass()); 721 QueueSyntheticGesture(gesture.Pass());
619 FlushInputUntilComplete(); 722 FlushInputUntilComplete();
620 723
621 MockScrollGestureTarget* scroll_target = 724 MockMoveGestureTarget* scroll_target =
622 static_cast<MockScrollGestureTarget*>(target_); 725 static_cast<MockMoveGestureTarget*>(target_);
623 EXPECT_EQ(1, num_success_); 726 EXPECT_EQ(1, num_success_);
624 EXPECT_EQ(0, num_failure_); 727 EXPECT_EQ(0, num_failure_);
625 CheckSingleScrollDistanceIsWithinRange( 728 CheckSingleScrollDistanceIsWithinRange(
626 scroll_target->start_to_end_distance(), params.distances[0], target_); 729 scroll_target->start_to_end_distance(), params.distances[0], target_);
627 } 730 }
628 731
629 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) { 732 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) {
630 CreateControllerAndTarget<MockScrollTouchTarget>(); 733 CreateControllerAndTarget<MockMoveTouchTarget>();
631 734
632 // Create a smooth scroll with a short distance and set the pointer assumed 735 // 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 736 // stopped time high, so that the stopping should dominate the time the
634 // gesture is active. 737 // gesture is active.
635 SyntheticSmoothScrollGestureParams params; 738 SyntheticSmoothScrollGestureParams params;
636 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 739 SyntheticSmoothMoveGesture::InputType input_type =
740 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
637 params.anchor.SetPoint(-98, -23); 741 params.anchor.SetPoint(-98, -23);
638 params.distances.push_back(gfx::Vector2d(21, -12)); 742 params.distances.push_back(gfx::Vector2d(21, -12));
639 params.prevent_fling = true; 743 params.prevent_fling = true;
744 params.speed_in_pixels_s = 800;
640 745
641 target_->set_pointer_assumed_stopped_time_ms(543); 746 target_->set_pointer_assumed_stopped_time_ms(543);
642 747
643 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 748 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
644 new SyntheticSmoothScrollGesture(params)); 749 CreateMoveGestureUsingParams(params, input_type);
645 QueueSyntheticGesture(gesture.Pass()); 750 QueueSyntheticGesture(gesture.Pass());
646 FlushInputUntilComplete(); 751 FlushInputUntilComplete();
647 752
648 MockScrollGestureTarget* scroll_target = 753 MockMoveGestureTarget* scroll_target =
649 static_cast<MockScrollGestureTarget*>(target_); 754 static_cast<MockMoveGestureTarget*>(target_);
650 EXPECT_EQ(1, num_success_); 755 EXPECT_EQ(1, num_success_);
651 EXPECT_EQ(0, num_failure_); 756 EXPECT_EQ(0, num_failure_);
652 CheckSingleScrollDistanceIsWithinRange( 757 CheckSingleScrollDistanceIsWithinRange(
653 scroll_target->start_to_end_distance(), params.distances[0], target_); 758 scroll_target->start_to_end_distance(), params.distances[0], target_);
654 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime()); 759 EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime());
655 } 760 }
656 761
657 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { 762 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) {
658 CreateControllerAndTarget<MockScrollTouchTarget>(); 763 CreateControllerAndTarget<MockMoveTouchTarget>();
659 764
660 // Create a smooth scroll with a short distance and set the pointer assumed 765 // 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 766 // stopped time high. Disable 'prevent_fling' and check that the gesture
662 // finishes without waiting before it stops. 767 // finishes without waiting before it stops.
663 SyntheticSmoothScrollGestureParams params; 768 SyntheticSmoothScrollGestureParams params;
664 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 769 SyntheticSmoothMoveGesture::InputType input_type =
770 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
665 params.anchor.SetPoint(-89, 78); 771 params.anchor.SetPoint(-89, 78);
666 params.distances.push_back(gfx::Vector2d(-43, 19)); 772 params.distances.push_back(gfx::Vector2d(-43, 19));
667 params.prevent_fling = false; 773 params.prevent_fling = false;
774 params.speed_in_pixels_s = 800;
668 775
669 target_->set_pointer_assumed_stopped_time_ms(543); 776 target_->set_pointer_assumed_stopped_time_ms(543);
670 777
671 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 778 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
672 new SyntheticSmoothScrollGesture(params)); 779 CreateMoveGestureUsingParams(params, input_type);
673 QueueSyntheticGesture(gesture.Pass()); 780 QueueSyntheticGesture(gesture.Pass());
674 FlushInputUntilComplete(); 781 FlushInputUntilComplete();
675 782
676 MockScrollGestureTarget* scroll_target = 783 MockMoveGestureTarget* scroll_target =
677 static_cast<MockScrollGestureTarget*>(target_); 784 static_cast<MockMoveGestureTarget*>(target_);
678 EXPECT_EQ(1, num_success_); 785 EXPECT_EQ(1, num_success_);
679 EXPECT_EQ(0, num_failure_); 786 EXPECT_EQ(0, num_failure_);
680 CheckSingleScrollDistanceIsWithinRange( 787 CheckSingleScrollDistanceIsWithinRange(
681 scroll_target->start_to_end_distance(), params.distances[0], target_); 788 scroll_target->start_to_end_distance(), params.distances[0], target_);
682 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); 789 EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime());
683 } 790 }
684 791
685 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) { 792 TEST_P(SyntheticGestureControllerTestWithParam,
686 CreateControllerAndTarget<MockScrollTouchTarget>(); 793 SingleScrollGestureTouchZeroDistance) {
794 CreateControllerAndTarget<MockMoveTouchTarget>();
687 795
688 SyntheticSmoothScrollGestureParams params; 796 SyntheticSmoothScrollGestureParams params;
689 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 797 SyntheticSmoothMoveGesture::InputType input_type;
798 if (GetParam() == TOUCH_SCROLL) {
799 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
800 } else {
801 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
802 }
690 params.anchor.SetPoint(-32, 43); 803 params.anchor.SetPoint(-32, 43);
691 params.distances.push_back(gfx::Vector2d(0, 0)); 804 params.distances.push_back(gfx::Vector2d(0, 0));
805 params.speed_in_pixels_s = 800;
692 806
693 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 807 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
694 new SyntheticSmoothScrollGesture(params)); 808 CreateMoveGestureUsingParams(params, input_type);
695 QueueSyntheticGesture(gesture.Pass()); 809 QueueSyntheticGesture(gesture.Pass());
696 FlushInputUntilComplete(); 810 FlushInputUntilComplete();
697 811
698 MockScrollGestureTarget* scroll_target = 812 MockMoveGestureTarget* scroll_target =
699 static_cast<MockScrollGestureTarget*>(target_); 813 static_cast<MockMoveGestureTarget*>(target_);
700 EXPECT_EQ(1, num_success_); 814 EXPECT_EQ(1, num_success_);
701 EXPECT_EQ(0, num_failure_); 815 EXPECT_EQ(0, num_failure_);
702 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance()); 816 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance());
703 } 817 }
704 818
705 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { 819 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) {
706 CreateControllerAndTarget<MockScrollMouseTarget>(); 820 CreateControllerAndTarget<MockScrollMouseTarget>();
707 821
708 SyntheticSmoothScrollGestureParams params; 822 SyntheticSmoothScrollGestureParams params;
709 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 823 SyntheticSmoothMoveGesture::InputType input_type =
824 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
710 params.anchor.SetPoint(432, 89); 825 params.anchor.SetPoint(432, 89);
711 params.distances.push_back(gfx::Vector2d(0, -234)); 826 params.distances.push_back(gfx::Vector2d(0, -234));
827 params.speed_in_pixels_s = 800;
712 828
picksi 2015/02/20 16:34:10 Could this function be part of the other tests by
ssid 2015/02/23 11:40:32 I think there is very less common code for this to
713 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 829 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
714 new SyntheticSmoothScrollGesture(params)); 830 CreateMoveGestureUsingParams(params, input_type);
715 QueueSyntheticGesture(gesture.Pass()); 831 QueueSyntheticGesture(gesture.Pass());
716 FlushInputUntilComplete(); 832 FlushInputUntilComplete();
717 833
718 MockScrollGestureTarget* scroll_target = 834 MockMoveGestureTarget* scroll_target =
719 static_cast<MockScrollGestureTarget*>(target_); 835 static_cast<MockMoveGestureTarget*>(target_);
720 EXPECT_EQ(1, num_success_); 836 EXPECT_EQ(1, num_success_);
721 EXPECT_EQ(0, num_failure_); 837 EXPECT_EQ(0, num_failure_);
722 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 838 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
723 } 839 }
724 840
725 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { 841 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) {
726 CreateControllerAndTarget<MockScrollMouseTarget>(); 842 CreateControllerAndTarget<MockScrollMouseTarget>();
727 843
728 SyntheticSmoothScrollGestureParams params; 844 SyntheticSmoothScrollGestureParams params;
729 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 845 SyntheticSmoothMoveGesture::InputType input_type =
846 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
730 params.anchor.SetPoint(90, 12); 847 params.anchor.SetPoint(90, 12);
731 params.distances.push_back(gfx::Vector2d(345, 0)); 848 params.distances.push_back(gfx::Vector2d(345, 0));
849 params.speed_in_pixels_s = 800;
732 850
733 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 851 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
734 new SyntheticSmoothScrollGesture(params)); 852 CreateMoveGestureUsingParams(params, input_type);
735 QueueSyntheticGesture(gesture.Pass()); 853 QueueSyntheticGesture(gesture.Pass());
736 FlushInputUntilComplete(); 854 FlushInputUntilComplete();
737 855
738 MockScrollGestureTarget* scroll_target = 856 MockMoveGestureTarget* scroll_target =
739 static_cast<MockScrollGestureTarget*>(target_); 857 static_cast<MockMoveGestureTarget*>(target_);
740 EXPECT_EQ(1, num_success_); 858 EXPECT_EQ(1, num_success_);
741 EXPECT_EQ(0, num_failure_); 859 EXPECT_EQ(0, num_failure_);
742 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 860 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
743 } 861 }
744 862
745 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { 863 TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) {
746 CreateControllerAndTarget<MockScrollMouseTarget>(); 864 CreateControllerAndTarget<MockScrollMouseTarget>();
747 865
748 SyntheticSmoothScrollGestureParams params; 866 SyntheticSmoothScrollGestureParams params;
749 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 867 SyntheticSmoothMoveGesture::InputType input_type =
868 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
750 params.anchor.SetPoint(90, 12); 869 params.anchor.SetPoint(90, 12);
751 params.distances.push_back(gfx::Vector2d(-194, 303)); 870 params.distances.push_back(gfx::Vector2d(-194, 303));
871 params.speed_in_pixels_s = 800;
752 872
753 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 873 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
754 new SyntheticSmoothScrollGesture(params)); 874 CreateMoveGestureUsingParams(params, input_type);
755 QueueSyntheticGesture(gesture.Pass()); 875 QueueSyntheticGesture(gesture.Pass());
756 FlushInputUntilComplete(); 876 FlushInputUntilComplete();
757 877
758 MockScrollGestureTarget* scroll_target = 878 MockMoveGestureTarget* scroll_target =
759 static_cast<MockScrollGestureTarget*>(target_); 879 static_cast<MockMoveGestureTarget*>(target_);
760 EXPECT_EQ(1, num_success_); 880 EXPECT_EQ(1, num_success_);
761 EXPECT_EQ(0, num_failure_); 881 EXPECT_EQ(0, num_failure_);
762 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); 882 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
763 } 883 }
764 884
765 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { 885 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) {
766 CreateControllerAndTarget<MockScrollMouseTarget>(); 886 CreateControllerAndTarget<MockScrollMouseTarget>();
767 887
768 SyntheticSmoothScrollGestureParams params; 888 SyntheticSmoothScrollGestureParams params;
769 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 889 SyntheticSmoothMoveGesture::InputType input_type =
890 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
770 params.anchor.SetPoint(90, 12); 891 params.anchor.SetPoint(90, 12);
771 params.distances.push_back(gfx::Vector2d(-129, 212)); 892 params.distances.push_back(gfx::Vector2d(-129, 212));
772 params.distances.push_back(gfx::Vector2d(8, -9)); 893 params.distances.push_back(gfx::Vector2d(8, -9));
894 params.speed_in_pixels_s = 800;
773 895
774 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 896 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
775 new SyntheticSmoothScrollGesture(params)); 897 CreateMoveGestureUsingParams(params, input_type);
776 QueueSyntheticGesture(gesture.Pass()); 898 QueueSyntheticGesture(gesture.Pass());
777 FlushInputUntilComplete(); 899 FlushInputUntilComplete();
778 900
779 MockScrollGestureTarget* scroll_target = 901 MockMoveGestureTarget* scroll_target =
780 static_cast<MockScrollGestureTarget*>(target_); 902 static_cast<MockMoveGestureTarget*>(target_);
781 EXPECT_EQ(1, num_success_); 903 EXPECT_EQ(1, num_success_);
782 EXPECT_EQ(0, num_failure_); 904 EXPECT_EQ(0, num_failure_);
783 EXPECT_EQ(params.distances[0] + params.distances[1], 905 EXPECT_EQ(params.distances[0] + params.distances[1],
784 scroll_target->start_to_end_distance()); 906 scroll_target->start_to_end_distance());
785 } 907 }
786 908
787 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { 909 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) {
788 CreateControllerAndTarget<MockScrollMouseTarget>(); 910 CreateControllerAndTarget<MockScrollMouseTarget>();
789 911
790 SyntheticSmoothScrollGestureParams params; 912 SyntheticSmoothScrollGestureParams params;
791 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 913 SyntheticSmoothMoveGesture::InputType input_type =
914 SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT;
792 params.anchor.SetPoint(90, 12); 915 params.anchor.SetPoint(90, 12);
793 params.distances.push_back(gfx::Vector2d(-129, 0)); 916 params.distances.push_back(gfx::Vector2d(-129, 0));
794 params.distances.push_back(gfx::Vector2d(79, 0)); 917 params.distances.push_back(gfx::Vector2d(79, 0));
918 params.speed_in_pixels_s = 800;
795 919
796 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 920 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
797 new SyntheticSmoothScrollGesture(params)); 921 CreateMoveGestureUsingParams(params, input_type);
798 QueueSyntheticGesture(gesture.Pass()); 922 QueueSyntheticGesture(gesture.Pass());
799 FlushInputUntilComplete(); 923 FlushInputUntilComplete();
800 924
801 MockScrollGestureTarget* scroll_target = 925 MockMoveGestureTarget* scroll_target =
802 static_cast<MockScrollGestureTarget*>(target_); 926 static_cast<MockMoveGestureTarget*>(target_);
803 EXPECT_EQ(1, num_success_); 927 EXPECT_EQ(1, num_success_);
804 EXPECT_EQ(0, num_failure_); 928 EXPECT_EQ(0, num_failure_);
805 // This check only works for horizontal or vertical scrolls because of 929 // This check only works for horizontal or vertical scrolls because of
806 // floating point precision issues with diagonal scrolls. 930 // floating point precision issues with diagonal scrolls.
807 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), 931 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
808 scroll_target->total_abs_scroll_distance_length()); 932 scroll_target->total_abs_move_distance_length());
809 EXPECT_EQ(params.distances[0] + params.distances[1], 933 EXPECT_EQ(params.distances[0] + params.distances[1],
810 scroll_target->start_to_end_distance()); 934 scroll_target->start_to_end_distance());
picksi 2015/02/20 16:34:10 The MOUSE_WHEEL_INPUT types are all identical too,
ssid 2015/02/23 11:40:32 The change in test structure can be kept for next
811 } 935 }
812 936
813 void CheckIsWithinRangeMulti(float scroll_distance, 937 void CheckIsWithinRangeMulti(float scroll_distance,
814 int target_distance, 938 int target_distance,
815 SyntheticGestureTarget* target) { 939 SyntheticGestureTarget* target) {
816 if (target_distance > 0) { 940 if (target_distance > 0) {
817 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 941 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
818 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 942 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
819 } else { 943 } else {
820 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips()); 944 EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
821 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips()); 945 EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
822 } 946 }
823 } 947 }
824 948
825 void CheckMultiScrollDistanceIsWithinRange( 949 void CheckMultiScrollDistanceIsWithinRange(
826 const gfx::Vector2dF& scroll_distance, 950 const gfx::Vector2dF& scroll_distance,
827 const gfx::Vector2d& target_distance, 951 const gfx::Vector2d& target_distance,
828 SyntheticGestureTarget* target) { 952 SyntheticGestureTarget* target) {
829 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target); 953 CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target);
830 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target); 954 CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target);
831 } 955 }
832 956
833 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { 957 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) {
834 CreateControllerAndTarget<MockScrollTouchTarget>(); 958 CreateControllerAndTarget<MockMoveTouchTarget>();
835 959
836 SyntheticSmoothScrollGestureParams params; 960 SyntheticSmoothScrollGestureParams params;
837 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 961 SyntheticSmoothMoveGesture::InputType input_type =
962 SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
838 params.anchor.SetPoint(8, -13); 963 params.anchor.SetPoint(8, -13);
839 params.distances.push_back(gfx::Vector2d(234, 133)); 964 params.distances.push_back(gfx::Vector2d(234, 133));
840 params.distances.push_back(gfx::Vector2d(-9, 78)); 965 params.distances.push_back(gfx::Vector2d(-9, 78));
966 params.speed_in_pixels_s = 800;
841 967
842 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 968 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
843 new SyntheticSmoothScrollGesture(params)); 969 CreateMoveGestureUsingParams(params, input_type);
844 QueueSyntheticGesture(gesture.Pass()); 970 QueueSyntheticGesture(gesture.Pass());
845 FlushInputUntilComplete(); 971 FlushInputUntilComplete();
846 972
847 MockScrollGestureTarget* scroll_target = 973 MockMoveGestureTarget* scroll_target =
848 static_cast<MockScrollGestureTarget*>(target_); 974 static_cast<MockMoveGestureTarget*>(target_);
849 EXPECT_EQ(1, num_success_); 975 EXPECT_EQ(1, num_success_);
850 EXPECT_EQ(0, num_failure_); 976 EXPECT_EQ(0, num_failure_);
851 CheckMultiScrollDistanceIsWithinRange( 977 CheckMultiScrollDistanceIsWithinRange(
852 scroll_target->start_to_end_distance(), 978 scroll_target->start_to_end_distance(),
853 params.distances[0] + params.distances[1], 979 params.distances[0] + params.distances[1],
854 target_); 980 target_);
855 } 981 }
856 982
857 TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) { 983 TEST_P(SyntheticGestureControllerTestWithParam,
858 CreateControllerAndTarget<MockScrollTouchTarget>(); 984 MultiScrollGestureTouchVertical) {
985 CreateControllerAndTarget<MockMoveTouchTarget>();
859 986
860 SyntheticSmoothScrollGestureParams params; 987 SyntheticSmoothScrollGestureParams params;
861 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 988 SyntheticSmoothMoveGesture::InputType input_type;
989 if (GetParam() == TOUCH_SCROLL) {
990 input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT;
991 } else {
992 input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT;
993 }
862 params.anchor.SetPoint(234, -13); 994 params.anchor.SetPoint(234, -13);
863 params.distances.push_back(gfx::Vector2d(0, 133)); 995 params.distances.push_back(gfx::Vector2d(0, 133));
864 params.distances.push_back(gfx::Vector2d(0, 78)); 996 params.distances.push_back(gfx::Vector2d(0, 78));
865 997 params.speed_in_pixels_s = 800;
866 scoped_ptr<SyntheticSmoothScrollGesture> gesture( 998
867 new SyntheticSmoothScrollGesture(params)); 999 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
868 QueueSyntheticGesture(gesture.Pass()); 1000 CreateMoveGestureUsingParams(params, input_type);
869 FlushInputUntilComplete(); 1001 QueueSyntheticGesture(gesture.Pass());
870 1002 FlushInputUntilComplete();
871 MockScrollGestureTarget* scroll_target = 1003
872 static_cast<MockScrollGestureTarget*>(target_); 1004 MockMoveGestureTarget* scroll_target =
873 EXPECT_EQ(1, num_success_); 1005 static_cast<MockMoveGestureTarget*>(target_);
874 EXPECT_EQ(0, num_failure_); 1006 EXPECT_EQ(1, num_success_);
875 EXPECT_FLOAT_EQ( 1007 EXPECT_EQ(0, num_failure_);
876 params.distances[0].Length() + params.distances[1].Length() + 1008 if (GetParam() == TOUCH_SCROLL) {
877 target_->GetTouchSlopInDips(), 1009 EXPECT_FLOAT_EQ(params.distances[0].Length() +
878 scroll_target->total_abs_scroll_distance_length()); 1010 params.distances[1].Length() +
1011 target_->GetTouchSlopInDips(),
1012 scroll_target->total_abs_move_distance_length());
879 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1], 1013 EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1],
880 target_), 1014 target_),
881 scroll_target->start_to_end_distance()); 1015 scroll_target->start_to_end_distance());
1016 } else {
1017 EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
1018 scroll_target->total_abs_move_distance_length());
1019 EXPECT_EQ(params.distances[0] + params.distances[1],
1020 scroll_target->start_to_end_distance());
1021 }
1022 }
1023
1024 scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams(
1025 SyntheticSmoothDragGestureParams params,
1026 SyntheticSmoothMoveGesture::InputType input_type) {
1027 bool prevent_fling = true;
1028
1029 scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture(
1030 input_type, params.start_point, params.distances,
1031 params.speed_in_pixels_s, prevent_fling));
1032 return gesture;
1033 }
1034
1035 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) {
1036 CreateControllerAndTarget<MockDragMouseTarget>();
1037
1038 SyntheticSmoothDragGestureParams params;
1039 SyntheticSmoothMoveGesture::InputType input_type =
1040 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1041 params.start_point.SetPoint(0, 7);
1042 params.distances.push_back(gfx::Vector2d(413, -83));
1043 params.speed_in_pixels_s = 800;
1044
picksi 2015/02/20 16:34:11 Aren't these MOUSE_DRAG_INPUT tests the same as th
Sami 2015/02/20 17:57:07 Yeah, this is starting to look like too much dupli
ssid 2015/02/20 18:48:16 I will reduce the last 4 tests to just check if ty
1045 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1046 CreateMoveGestureUsingParams(params, input_type);
1047 QueueSyntheticGesture(gesture.Pass());
1048 FlushInputUntilComplete();
1049
1050 MockMoveGestureTarget* drag_target =
1051 static_cast<MockMoveGestureTarget*>(target_);
1052 EXPECT_EQ(1, num_success_);
1053 EXPECT_EQ(0, num_failure_);
1054 EXPECT_EQ(drag_target->start_to_end_distance(), params.distances[0]);
1055 }
1056
1057 TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseZeroDistance) {
1058 CreateControllerAndTarget<MockDragMouseTarget>();
1059
1060 SyntheticSmoothDragGestureParams params;
1061 SyntheticSmoothMoveGesture::InputType input_type =
1062 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1063 params.start_point.SetPoint(-32, 43);
1064 params.distances.push_back(gfx::Vector2d(0, 0));
1065 params.speed_in_pixels_s = 800;
1066
1067 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1068 CreateMoveGestureUsingParams(params, input_type);
1069 QueueSyntheticGesture(gesture.Pass());
1070 FlushInputUntilComplete();
1071
1072 MockMoveGestureTarget* drag_target =
1073 static_cast<MockMoveGestureTarget*>(target_);
1074 EXPECT_EQ(1, num_success_);
1075 EXPECT_EQ(0, num_failure_);
1076 EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target->start_to_end_distance());
1077 }
1078
1079 TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouse) {
1080 CreateControllerAndTarget<MockDragMouseTarget>();
1081
1082 SyntheticSmoothDragGestureParams params;
1083 SyntheticSmoothMoveGesture::InputType input_type =
1084 SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT;
1085 params.start_point.SetPoint(8, -13);
1086 params.distances.push_back(gfx::Vector2d(234, 133));
1087 params.distances.push_back(gfx::Vector2d(-9, 78));
1088 params.speed_in_pixels_s = 800;
1089
1090 scoped_ptr<SyntheticSmoothMoveGesture> gesture =
1091 CreateMoveGestureUsingParams(params, input_type);
1092 QueueSyntheticGesture(gesture.Pass());
1093 FlushInputUntilComplete();
1094
1095 MockMoveGestureTarget* drag_target =
1096 static_cast<MockMoveGestureTarget*>(target_);
1097 EXPECT_EQ(1, num_success_);
1098 EXPECT_EQ(0, num_failure_);
1099 EXPECT_EQ(drag_target->start_to_end_distance(),
1100 params.distances[0] + params.distances[1]);
1101 }
1102
1103 TEST_F(SyntheticGestureControllerTest,
1104 SingleDragGestureMouseUsingDragGestureObject) {
Sami 2015/02/20 17:57:07 I'm not sure what the name of this test means.
ssid 2015/02/23 11:40:32 Changed the names.
1105 CreateControllerAndTarget<MockDragMouseTarget>();
1106
1107 SyntheticSmoothDragGestureParams params;
1108 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
1109 params.start_point.SetPoint(89, 32);
1110 params.distances.push_back(gfx::Vector2d(0, 123));
1111 params.speed_in_pixels_s = 800;
1112
1113 scoped_ptr<SyntheticSmoothDragGesture> gesture(
1114 new SyntheticSmoothDragGesture(params));
1115 QueueSyntheticGesture(gesture.Pass());
1116 FlushInputUntilComplete();
1117
1118 MockMoveGestureTarget* drag_target =
1119 static_cast<MockMoveGestureTarget*>(target_);
1120 EXPECT_EQ(1, num_success_);
1121 EXPECT_EQ(0, num_failure_);
1122 EXPECT_EQ(params.distances[0], drag_target->start_to_end_distance());
1123 }
1124
1125 TEST_F(SyntheticGestureControllerTest,
1126 SingleMoveGestureTouchVerticalUsingScrollObject) {
1127 CreateControllerAndTarget<MockMoveTouchTarget>();
1128
1129 SyntheticSmoothScrollGestureParams params;
1130 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
1131 params.anchor.SetPoint(89, 32);
1132 params.distances.push_back(gfx::Vector2d(0, 123));
1133 params.speed_in_pixels_s = 800;
1134
1135 scoped_ptr<SyntheticSmoothScrollGesture> gesture(
1136 new SyntheticSmoothScrollGesture(params));
1137
1138 QueueSyntheticGesture(gesture.Pass());
1139 FlushInputUntilComplete();
1140
1141 MockMoveGestureTarget* scroll_target =
1142 static_cast<MockMoveGestureTarget*>(target_);
1143 EXPECT_EQ(1, num_success_);
1144 EXPECT_EQ(0, num_failure_);
1145 EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
1146 scroll_target->start_to_end_distance());
1147 }
1148
1149 TEST_F(SyntheticGestureControllerTest,
1150 SingleMoveGestureTouchVerticalUsingDragObject) {
1151 CreateControllerAndTarget<MockMoveTouchTarget>();
1152
1153 SyntheticSmoothDragGestureParams params;
1154 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
1155 params.start_point.SetPoint(89, 32);
1156 params.distances.push_back(gfx::Vector2d(0, 123));
1157 params.speed_in_pixels_s = 800;
1158
1159 scoped_ptr<SyntheticSmoothDragGesture> gesture(
1160 new SyntheticSmoothDragGesture(params));
1161
1162 QueueSyntheticGesture(gesture.Pass());
1163 FlushInputUntilComplete();
1164
1165 MockMoveGestureTarget* scroll_target =
1166 static_cast<MockMoveGestureTarget*>(target_);
1167 EXPECT_EQ(1, num_success_);
1168 EXPECT_EQ(0, num_failure_);
1169 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
1170 }
1171
1172 TEST_F(SyntheticGestureControllerTest,
1173 SingleScrollGestureMouseVerticalUsingScrollObject) {
1174 CreateControllerAndTarget<MockScrollMouseTarget>();
1175
1176 SyntheticSmoothScrollGestureParams params;
1177 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
1178 params.anchor.SetPoint(432, 89);
1179 params.distances.push_back(gfx::Vector2d(0, -234));
1180 params.speed_in_pixels_s = 800;
1181
1182 scoped_ptr<SyntheticSmoothScrollGesture> gesture(
1183 new SyntheticSmoothScrollGesture(params));
1184 QueueSyntheticGesture(gesture.Pass());
1185 FlushInputUntilComplete();
1186
1187 MockMoveGestureTarget* scroll_target =
1188 static_cast<MockMoveGestureTarget*>(target_);
1189 EXPECT_EQ(1, num_success_);
1190 EXPECT_EQ(0, num_failure_);
1191 EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
882 } 1192 }
883 1193
884 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { 1194 TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) {
885 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); 1195 CreateControllerAndTarget<MockSyntheticPinchTouchTarget>();
886 1196
887 SyntheticPinchGestureParams params; 1197 SyntheticPinchGestureParams params;
888 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 1198 params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
889 params.scale_factor = 2.3f; 1199 params.scale_factor = 2.3f;
890 params.anchor.SetPoint(54, 89); 1200 params.anchor.SetPoint(54, 89);
891 1201
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 EXPECT_TRUE(tap_target->GestureFinished()); 1295 EXPECT_TRUE(tap_target->GestureFinished());
986 EXPECT_EQ(tap_target->position(), params.position); 1296 EXPECT_EQ(tap_target->position(), params.position);
987 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); 1297 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
988 EXPECT_GE(GetTotalTime(), 1298 EXPECT_GE(GetTotalTime(),
989 base::TimeDelta::FromMilliseconds(params.duration_ms)); 1299 base::TimeDelta::FromMilliseconds(params.duration_ms));
990 } 1300 }
991 1301
992 } // namespace 1302 } // namespace
993 1303
994 } // namespace content 1304 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698