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