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
3 // found in the LICENSE file.
6 #include "base/memory/scoped_ptr.h"
7 #include "base/time/time.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.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"
14 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
15 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h"
16 #include "content/browser/renderer_host/render_widget_host_delegate.h"
17 #include "content/common/input/synthetic_pinch_gesture_params.h"
18 #include "content/common/input/synthetic_smooth_drag_gesture_params.h"
19 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
20 #include "content/common/input/synthetic_tap_gesture_params.h"
21 #include "content/public/test/mock_render_process_host.h"
22 #include "content/public/test/test_browser_context.h"
23 #include "content/test/test_render_view_host.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/public/web/WebInputEvent.h"
26 #include "ui/gfx/geometry/point.h"
27 #include "ui/gfx/geometry/point_f.h"
28 #include "ui/gfx/geometry/vector2d.h"
29 #include "ui/gfx/geometry/vector2d_f.h"
31 using blink::WebInputEvent
;
32 using blink::WebMouseEvent
;
33 using blink::WebMouseWheelEvent
;
34 using blink::WebTouchEvent
;
40 const int kFlushInputRateInMs
= 16;
41 const int kPointerAssumedStoppedTimeMs
= 43;
42 const float kTouchSlopInDips
= 7.0f
;
43 const float kMinScalingSpanInDips
= 27.5f
;
45 enum TouchGestureType
{ TOUCH_SCROLL
, TOUCH_DRAG
};
47 class MockSyntheticGesture
: public SyntheticGesture
{
49 MockSyntheticGesture(bool* finished
, int num_steps
)
50 : finished_(finished
),
51 num_steps_(num_steps
),
55 ~MockSyntheticGesture() override
{}
57 Result
ForwardInputEvents(const base::TimeTicks
& timestamp
,
58 SyntheticGestureTarget
* target
) override
{
60 if (step_count_
== num_steps_
) {
62 return SyntheticGesture::GESTURE_FINISHED
;
63 } else if (step_count_
> num_steps_
) {
65 // Return arbitrary failure.
66 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED
;
69 return SyntheticGesture::GESTURE_RUNNING
;
78 class MockSyntheticGestureTarget
: public SyntheticGestureTarget
{
80 MockSyntheticGestureTarget()
81 : flush_requested_(false),
82 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs
) {}
83 ~MockSyntheticGestureTarget() override
{}
85 // SyntheticGestureTarget:
86 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{}
88 void SetNeedsFlush() override
{ flush_requested_
= true; }
90 SyntheticGestureParams::GestureSourceType
91 GetDefaultSyntheticGestureSourceType() const override
{
92 return SyntheticGestureParams::TOUCH_INPUT
;
95 base::TimeDelta
PointerAssumedStoppedTime() const override
{
96 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_
);
99 void set_pointer_assumed_stopped_time_ms(int time_ms
) {
100 pointer_assumed_stopped_time_ms_
= time_ms
;
103 float GetTouchSlopInDips() const override
{ return kTouchSlopInDips
; }
105 float GetMinScalingSpanInDips() const override
{
106 return kMinScalingSpanInDips
;
109 bool flush_requested() const { return flush_requested_
; }
110 void ClearFlushRequest() { flush_requested_
= false; }
113 bool flush_requested_
;
115 int pointer_assumed_stopped_time_ms_
;
118 class MockMoveGestureTarget
: public MockSyntheticGestureTarget
{
120 MockMoveGestureTarget() : total_abs_move_distance_length_(0) {}
121 ~MockMoveGestureTarget() override
{}
123 gfx::Vector2dF
start_to_end_distance() const {
124 return start_to_end_distance_
;
126 float total_abs_move_distance_length() const {
127 return total_abs_move_distance_length_
;
131 gfx::Vector2dF start_to_end_distance_
;
132 float total_abs_move_distance_length_
;
135 class MockScrollMouseTarget
: public MockMoveGestureTarget
{
137 MockScrollMouseTarget() {}
138 ~MockScrollMouseTarget() override
{}
140 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
141 ASSERT_EQ(event
.type
, WebInputEvent::MouseWheel
);
142 const WebMouseWheelEvent
& mouse_wheel_event
=
143 static_cast<const WebMouseWheelEvent
&>(event
);
144 gfx::Vector2dF
delta(mouse_wheel_event
.deltaX
, mouse_wheel_event
.deltaY
);
145 start_to_end_distance_
+= delta
;
146 total_abs_move_distance_length_
+= delta
.Length();
150 class MockMoveTouchTarget
: public MockMoveGestureTarget
{
152 MockMoveTouchTarget() : started_(false) {}
153 ~MockMoveTouchTarget() override
{}
155 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
156 ASSERT_TRUE(WebInputEvent::isTouchEventType(event
.type
));
157 const WebTouchEvent
& touch_event
= static_cast<const WebTouchEvent
&>(event
);
158 ASSERT_EQ(touch_event
.touchesLength
, 1U);
161 ASSERT_EQ(touch_event
.type
, WebInputEvent::TouchStart
);
162 start_
.SetPoint(touch_event
.touches
[0].position
.x
,
163 touch_event
.touches
[0].position
.y
);
164 last_touch_point_
= start_
;
167 ASSERT_NE(touch_event
.type
, WebInputEvent::TouchStart
);
168 ASSERT_NE(touch_event
.type
, WebInputEvent::TouchCancel
);
170 gfx::PointF
touch_point(touch_event
.touches
[0].position
.x
,
171 touch_event
.touches
[0].position
.y
);
172 gfx::Vector2dF delta
= touch_point
- last_touch_point_
;
173 total_abs_move_distance_length_
+= delta
.Length();
175 if (touch_event
.type
== WebInputEvent::TouchEnd
)
176 start_to_end_distance_
= touch_point
- start_
;
178 last_touch_point_
= touch_point
;
184 gfx::PointF last_touch_point_
;
188 class MockDragMouseTarget
: public MockMoveGestureTarget
{
190 MockDragMouseTarget() : started_(false) {}
191 ~MockDragMouseTarget() override
{}
193 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
194 ASSERT_TRUE(WebInputEvent::isMouseEventType(event
.type
));
195 const WebMouseEvent
& mouse_event
= static_cast<const WebMouseEvent
&>(event
);
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_
;
204 EXPECT_EQ(mouse_event
.button
, WebMouseEvent::ButtonLeft
);
205 ASSERT_NE(mouse_event
.type
, WebInputEvent::MouseDown
);
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
;
218 gfx::PointF start_
, last_mouse_point_
;
221 class MockSyntheticPinchTouchTarget
: public MockSyntheticGestureTarget
{
224 ZOOM_DIRECTION_UNKNOWN
,
229 MockSyntheticPinchTouchTarget()
230 : initial_pointer_distance_(0),
231 last_pointer_distance_(0),
232 zoom_direction_(ZOOM_DIRECTION_UNKNOWN
),
234 ~MockSyntheticPinchTouchTarget() override
{}
236 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
237 ASSERT_TRUE(WebInputEvent::isTouchEventType(event
.type
));
238 const WebTouchEvent
& touch_event
= static_cast<const WebTouchEvent
&>(event
);
239 ASSERT_EQ(touch_event
.touchesLength
, 2U);
242 ASSERT_EQ(touch_event
.type
, WebInputEvent::TouchStart
);
244 start_0_
= gfx::PointF(touch_event
.touches
[0].position
);
245 start_1_
= gfx::PointF(touch_event
.touches
[1].position
);
246 last_pointer_distance_
= (start_0_
- start_1_
).Length();
247 initial_pointer_distance_
= last_pointer_distance_
;
248 EXPECT_GE(initial_pointer_distance_
, GetMinScalingSpanInDips());
252 ASSERT_NE(touch_event
.type
, WebInputEvent::TouchStart
);
253 ASSERT_NE(touch_event
.type
, WebInputEvent::TouchCancel
);
255 gfx::PointF current_0
= gfx::PointF(touch_event
.touches
[0].position
);
256 gfx::PointF current_1
= gfx::PointF(touch_event
.touches
[1].position
);
258 float pointer_distance
= (current_0
- current_1
).Length();
260 if (last_pointer_distance_
!= pointer_distance
) {
261 if (zoom_direction_
== ZOOM_DIRECTION_UNKNOWN
)
263 ComputeZoomDirection(last_pointer_distance_
, pointer_distance
);
267 ComputeZoomDirection(last_pointer_distance_
, pointer_distance
));
270 last_pointer_distance_
= pointer_distance
;
274 ZoomDirection
zoom_direction() const { return zoom_direction_
; }
276 float ComputeScaleFactor() const {
277 switch (zoom_direction_
) {
279 return last_pointer_distance_
/
280 (initial_pointer_distance_
+ 2 * GetTouchSlopInDips());
282 return last_pointer_distance_
/
283 (initial_pointer_distance_
- 2 * GetTouchSlopInDips());
284 case ZOOM_DIRECTION_UNKNOWN
:
293 ZoomDirection
ComputeZoomDirection(float last_pointer_distance
,
294 float current_pointer_distance
) {
295 DCHECK_NE(last_pointer_distance
, current_pointer_distance
);
296 return last_pointer_distance
< current_pointer_distance
? ZOOM_IN
300 float initial_pointer_distance_
;
301 float last_pointer_distance_
;
302 ZoomDirection zoom_direction_
;
303 gfx::PointF start_0_
;
304 gfx::PointF start_1_
;
308 class MockSyntheticTapGestureTarget
: public MockSyntheticGestureTarget
{
310 MockSyntheticTapGestureTarget() : state_(NOT_STARTED
) {}
311 ~MockSyntheticTapGestureTarget() override
{}
313 bool GestureFinished() const { return state_
== FINISHED
; }
314 gfx::PointF
position() const { return position_
; }
315 base::TimeDelta
GetDuration() const { return stop_time_
- start_time_
; }
324 gfx::PointF position_
;
325 base::TimeDelta start_time_
;
326 base::TimeDelta stop_time_
;
330 class MockSyntheticTapTouchTarget
: public MockSyntheticTapGestureTarget
{
332 MockSyntheticTapTouchTarget() {}
333 ~MockSyntheticTapTouchTarget() override
{}
335 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
336 ASSERT_TRUE(WebInputEvent::isTouchEventType(event
.type
));
337 const WebTouchEvent
& touch_event
= static_cast<const WebTouchEvent
&>(event
);
338 ASSERT_EQ(touch_event
.touchesLength
, 1U);
342 EXPECT_EQ(touch_event
.type
, WebInputEvent::TouchStart
);
343 position_
= gfx::PointF(touch_event
.touches
[0].position
);
344 start_time_
= base::TimeDelta::FromMilliseconds(
345 static_cast<int64
>(touch_event
.timeStampSeconds
* 1000));
349 EXPECT_EQ(touch_event
.type
, WebInputEvent::TouchEnd
);
350 EXPECT_EQ(position_
, gfx::PointF(touch_event
.touches
[0].position
));
351 stop_time_
= base::TimeDelta::FromMilliseconds(
352 static_cast<int64
>(touch_event
.timeStampSeconds
* 1000));
362 class MockSyntheticTapMouseTarget
: public MockSyntheticTapGestureTarget
{
364 MockSyntheticTapMouseTarget() {}
365 ~MockSyntheticTapMouseTarget() override
{}
367 void DispatchInputEventToPlatform(const WebInputEvent
& event
) override
{
368 ASSERT_TRUE(WebInputEvent::isMouseEventType(event
.type
));
369 const WebMouseEvent
& mouse_event
= static_cast<const WebMouseEvent
&>(event
);
373 EXPECT_EQ(mouse_event
.type
, WebInputEvent::MouseDown
);
374 EXPECT_EQ(mouse_event
.button
, WebMouseEvent::ButtonLeft
);
375 EXPECT_EQ(mouse_event
.clickCount
, 1);
376 position_
= gfx::PointF(mouse_event
.x
, mouse_event
.y
);
377 start_time_
= base::TimeDelta::FromMilliseconds(
378 static_cast<int64
>(mouse_event
.timeStampSeconds
* 1000));
382 EXPECT_EQ(mouse_event
.type
, WebInputEvent::MouseUp
);
383 EXPECT_EQ(mouse_event
.button
, WebMouseEvent::ButtonLeft
);
384 EXPECT_EQ(mouse_event
.clickCount
, 1);
385 EXPECT_EQ(position_
, gfx::PointF(mouse_event
.x
, mouse_event
.y
));
386 stop_time_
= base::TimeDelta::FromMilliseconds(
387 static_cast<int64
>(mouse_event
.timeStampSeconds
* 1000));
397 class SyntheticGestureControllerTestBase
{
399 SyntheticGestureControllerTestBase() {}
400 ~SyntheticGestureControllerTestBase() {}
403 template<typename MockGestureTarget
>
404 void CreateControllerAndTarget() {
405 target_
= new MockGestureTarget();
406 controller_
.reset(new SyntheticGestureController(
407 scoped_ptr
<SyntheticGestureTarget
>(target_
)));
410 void QueueSyntheticGesture(scoped_ptr
<SyntheticGesture
> gesture
) {
411 controller_
->QueueSyntheticGesture(
414 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted
,
415 base::Unretained(this)));
418 void FlushInputUntilComplete() {
419 while (target_
->flush_requested()) {
420 while (target_
->flush_requested()) {
421 target_
->ClearFlushRequest();
422 time_
+= base::TimeDelta::FromMilliseconds(kFlushInputRateInMs
);
423 controller_
->Flush(time_
);
425 controller_
->OnDidFlushInput();
429 void OnSyntheticGestureCompleted(SyntheticGesture::Result result
) {
430 DCHECK_NE(result
, SyntheticGesture::GESTURE_RUNNING
);
431 if (result
== SyntheticGesture::GESTURE_FINISHED
)
437 base::TimeDelta
GetTotalTime() const { return time_
- start_time_
; }
439 MockSyntheticGestureTarget
* target_
;
440 scoped_ptr
<SyntheticGestureController
> controller_
;
441 base::TimeTicks start_time_
;
442 base::TimeTicks time_
;
447 class SyntheticGestureControllerTest
448 : public SyntheticGestureControllerTestBase
,
449 public testing::Test
{
451 void SetUp() override
{
452 start_time_
= base::TimeTicks::Now();
458 void TearDown() override
{
461 time_
= base::TimeTicks();
465 class SyntheticGestureControllerTestWithParam
466 : public SyntheticGestureControllerTestBase
,
467 public testing::TestWithParam
<bool> {
469 void SetUp() override
{
470 start_time_
= base::TimeTicks::Now();
476 void TearDown() override
{
479 time_
= base::TimeTicks();
483 TEST_F(SyntheticGestureControllerTest
, SingleGesture
) {
484 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
486 bool finished
= false;
487 scoped_ptr
<MockSyntheticGesture
> gesture(
488 new MockSyntheticGesture(&finished
, 3));
489 QueueSyntheticGesture(gesture
.Pass());
490 FlushInputUntilComplete();
492 EXPECT_TRUE(finished
);
493 EXPECT_EQ(1, num_success_
);
494 EXPECT_EQ(0, num_failure_
);
497 TEST_F(SyntheticGestureControllerTest
, GestureFailed
) {
498 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
500 bool finished
= false;
501 scoped_ptr
<MockSyntheticGesture
> gesture(
502 new MockSyntheticGesture(&finished
, 0));
503 QueueSyntheticGesture(gesture
.Pass());
504 FlushInputUntilComplete();
506 EXPECT_TRUE(finished
);
507 EXPECT_EQ(1, num_failure_
);
508 EXPECT_EQ(0, num_success_
);
511 TEST_F(SyntheticGestureControllerTest
, SuccessiveGestures
) {
512 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
514 bool finished_1
= false;
515 scoped_ptr
<MockSyntheticGesture
> gesture_1(
516 new MockSyntheticGesture(&finished_1
, 2));
517 bool finished_2
= false;
518 scoped_ptr
<MockSyntheticGesture
> gesture_2(
519 new MockSyntheticGesture(&finished_2
, 4));
521 // Queue first gesture and wait for it to finish
522 QueueSyntheticGesture(gesture_1
.Pass());
523 FlushInputUntilComplete();
525 EXPECT_TRUE(finished_1
);
526 EXPECT_EQ(1, num_success_
);
527 EXPECT_EQ(0, num_failure_
);
529 // Queue second gesture.
530 QueueSyntheticGesture(gesture_2
.Pass());
531 FlushInputUntilComplete();
533 EXPECT_TRUE(finished_2
);
534 EXPECT_EQ(2, num_success_
);
535 EXPECT_EQ(0, num_failure_
);
538 TEST_F(SyntheticGestureControllerTest
, TwoGesturesInFlight
) {
539 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
541 bool finished_1
= false;
542 scoped_ptr
<MockSyntheticGesture
> gesture_1(
543 new MockSyntheticGesture(&finished_1
, 2));
544 bool finished_2
= false;
545 scoped_ptr
<MockSyntheticGesture
> gesture_2(
546 new MockSyntheticGesture(&finished_2
, 4));
548 QueueSyntheticGesture(gesture_1
.Pass());
549 QueueSyntheticGesture(gesture_2
.Pass());
550 FlushInputUntilComplete();
552 EXPECT_TRUE(finished_1
);
553 EXPECT_TRUE(finished_2
);
555 EXPECT_EQ(2, num_success_
);
556 EXPECT_EQ(0, num_failure_
);
559 TEST_F(SyntheticGestureControllerTest
, GestureCompletedOnDidFlushInput
) {
560 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
562 bool finished_1
, finished_2
;
563 scoped_ptr
<MockSyntheticGesture
> gesture_1(
564 new MockSyntheticGesture(&finished_1
, 2));
565 scoped_ptr
<MockSyntheticGesture
> gesture_2(
566 new MockSyntheticGesture(&finished_2
, 4));
568 QueueSyntheticGesture(gesture_1
.Pass());
569 QueueSyntheticGesture(gesture_2
.Pass());
571 while (target_
->flush_requested()) {
572 target_
->ClearFlushRequest();
573 time_
+= base::TimeDelta::FromMilliseconds(kFlushInputRateInMs
);
574 controller_
->Flush(time_
);
576 EXPECT_EQ(0, num_success_
);
577 controller_
->OnDidFlushInput();
578 EXPECT_EQ(1, num_success_
);
580 while (target_
->flush_requested()) {
581 target_
->ClearFlushRequest();
582 time_
+= base::TimeDelta::FromMilliseconds(kFlushInputRateInMs
);
583 controller_
->Flush(time_
);
585 EXPECT_EQ(1, num_success_
);
586 controller_
->OnDidFlushInput();
587 EXPECT_EQ(2, num_success_
);
590 gfx::Vector2d
AddTouchSlopToVector(const gfx::Vector2dF
& vector
,
591 SyntheticGestureTarget
* target
) {
592 const int kTouchSlop
= target
->GetTouchSlopInDips();
606 return gfx::Vector2d(x
, y
);
609 TEST_P(SyntheticGestureControllerTestWithParam
,
610 SingleMoveGestureTouchVertical
) {
611 CreateControllerAndTarget
<MockMoveTouchTarget
>();
613 SyntheticSmoothMoveGestureParams params
;
614 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
615 if (GetParam() == TOUCH_DRAG
) {
616 params
.add_slop
= false;
618 params
.start_point
.SetPoint(89, 32);
619 params
.distances
.push_back(gfx::Vector2d(0, 123));
621 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
622 new SyntheticSmoothMoveGesture(params
));
623 QueueSyntheticGesture(gesture
.Pass());
624 FlushInputUntilComplete();
626 MockMoveGestureTarget
* scroll_target
=
627 static_cast<MockMoveGestureTarget
*>(target_
);
628 EXPECT_EQ(1, num_success_
);
629 EXPECT_EQ(0, num_failure_
);
630 if (GetParam() == TOUCH_SCROLL
) {
631 EXPECT_EQ(AddTouchSlopToVector(params
.distances
[0], target_
),
632 scroll_target
->start_to_end_distance());
634 EXPECT_EQ(params
.distances
[0], scroll_target
->start_to_end_distance());
638 TEST_P(SyntheticGestureControllerTestWithParam
,
639 SingleScrollGestureTouchHorizontal
) {
640 CreateControllerAndTarget
<MockMoveTouchTarget
>();
642 SyntheticSmoothMoveGestureParams params
;
643 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
644 if (GetParam() == TOUCH_DRAG
) {
645 params
.add_slop
= false;
647 params
.start_point
.SetPoint(12, -23);
648 params
.distances
.push_back(gfx::Vector2d(-234, 0));
650 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
651 new SyntheticSmoothMoveGesture(params
));
652 QueueSyntheticGesture(gesture
.Pass());
653 FlushInputUntilComplete();
655 MockMoveGestureTarget
* scroll_target
=
656 static_cast<MockMoveGestureTarget
*>(target_
);
657 EXPECT_EQ(1, num_success_
);
658 EXPECT_EQ(0, num_failure_
);
659 if (GetParam() == TOUCH_SCROLL
) {
660 EXPECT_EQ(AddTouchSlopToVector(params
.distances
[0], target_
),
661 scroll_target
->start_to_end_distance());
663 EXPECT_EQ(params
.distances
[0], scroll_target
->start_to_end_distance());
667 void CheckIsWithinRangeSingle(float scroll_distance
,
669 SyntheticGestureTarget
* target
) {
670 if (target_distance
> 0) {
671 EXPECT_LE(target_distance
, scroll_distance
);
672 EXPECT_LE(scroll_distance
, target_distance
+ target
->GetTouchSlopInDips());
674 EXPECT_GE(target_distance
, scroll_distance
);
675 EXPECT_GE(scroll_distance
, target_distance
- target
->GetTouchSlopInDips());
679 void CheckSingleScrollDistanceIsWithinRange(
680 const gfx::Vector2dF
& scroll_distance
,
681 const gfx::Vector2dF
& target_distance
,
682 SyntheticGestureTarget
* target
) {
683 CheckIsWithinRangeSingle(scroll_distance
.x(), target_distance
.x(), target
);
684 CheckIsWithinRangeSingle(scroll_distance
.y(), target_distance
.y(), target
);
687 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureTouchDiagonal
) {
688 CreateControllerAndTarget
<MockMoveTouchTarget
>();
690 SyntheticSmoothMoveGestureParams params
;
691 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
692 params
.start_point
.SetPoint(0, 7);
693 params
.distances
.push_back(gfx::Vector2d(413, -83));
695 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
696 new SyntheticSmoothMoveGesture(params
));
697 QueueSyntheticGesture(gesture
.Pass());
698 FlushInputUntilComplete();
700 MockMoveGestureTarget
* scroll_target
=
701 static_cast<MockMoveGestureTarget
*>(target_
);
702 EXPECT_EQ(1, num_success_
);
703 EXPECT_EQ(0, num_failure_
);
704 CheckSingleScrollDistanceIsWithinRange(
705 scroll_target
->start_to_end_distance(), params
.distances
[0], target_
);
708 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureTouchLongStop
) {
709 CreateControllerAndTarget
<MockMoveTouchTarget
>();
711 // Create a smooth scroll with a short distance and set the pointer assumed
712 // stopped time high, so that the stopping should dominate the time the
713 // gesture is active.
714 SyntheticSmoothMoveGestureParams params
;
715 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
716 params
.start_point
.SetPoint(-98, -23);
717 params
.distances
.push_back(gfx::Vector2d(21, -12));
718 params
.prevent_fling
= true;
719 target_
->set_pointer_assumed_stopped_time_ms(543);
721 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
722 new SyntheticSmoothMoveGesture(params
));
723 QueueSyntheticGesture(gesture
.Pass());
724 FlushInputUntilComplete();
726 MockMoveGestureTarget
* scroll_target
=
727 static_cast<MockMoveGestureTarget
*>(target_
);
728 EXPECT_EQ(1, num_success_
);
729 EXPECT_EQ(0, num_failure_
);
730 CheckSingleScrollDistanceIsWithinRange(
731 scroll_target
->start_to_end_distance(), params
.distances
[0], target_
);
732 EXPECT_GE(GetTotalTime(), target_
->PointerAssumedStoppedTime());
735 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureTouchFling
) {
736 CreateControllerAndTarget
<MockMoveTouchTarget
>();
738 // Create a smooth scroll with a short distance and set the pointer assumed
739 // stopped time high. Disable 'prevent_fling' and check that the gesture
740 // finishes without waiting before it stops.
741 SyntheticSmoothMoveGestureParams params
;
742 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
743 params
.start_point
.SetPoint(-89, 78);
744 params
.distances
.push_back(gfx::Vector2d(-43, 19));
745 params
.prevent_fling
= false;
747 target_
->set_pointer_assumed_stopped_time_ms(543);
749 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
750 new SyntheticSmoothMoveGesture(params
));
751 QueueSyntheticGesture(gesture
.Pass());
752 FlushInputUntilComplete();
754 MockMoveGestureTarget
* scroll_target
=
755 static_cast<MockMoveGestureTarget
*>(target_
);
756 EXPECT_EQ(1, num_success_
);
757 EXPECT_EQ(0, num_failure_
);
758 CheckSingleScrollDistanceIsWithinRange(
759 scroll_target
->start_to_end_distance(), params
.distances
[0], target_
);
760 EXPECT_LE(GetTotalTime(), target_
->PointerAssumedStoppedTime());
763 TEST_P(SyntheticGestureControllerTestWithParam
,
764 SingleScrollGestureTouchZeroDistance
) {
765 CreateControllerAndTarget
<MockMoveTouchTarget
>();
767 SyntheticSmoothMoveGestureParams params
;
768 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
769 if (GetParam() == TOUCH_DRAG
) {
770 params
.add_slop
= false;
772 params
.start_point
.SetPoint(-32, 43);
773 params
.distances
.push_back(gfx::Vector2d(0, 0));
775 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
776 new SyntheticSmoothMoveGesture(params
));
777 QueueSyntheticGesture(gesture
.Pass());
778 FlushInputUntilComplete();
780 MockMoveGestureTarget
* scroll_target
=
781 static_cast<MockMoveGestureTarget
*>(target_
);
782 EXPECT_EQ(1, num_success_
);
783 EXPECT_EQ(0, num_failure_
);
784 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target
->start_to_end_distance());
787 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureMouseVertical
) {
788 CreateControllerAndTarget
<MockScrollMouseTarget
>();
790 SyntheticSmoothMoveGestureParams params
;
791 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT
;
792 params
.start_point
.SetPoint(432, 89);
793 params
.distances
.push_back(gfx::Vector2d(0, -234));
795 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
796 new SyntheticSmoothMoveGesture(params
));
797 QueueSyntheticGesture(gesture
.Pass());
798 FlushInputUntilComplete();
800 MockMoveGestureTarget
* scroll_target
=
801 static_cast<MockMoveGestureTarget
*>(target_
);
802 EXPECT_EQ(1, num_success_
);
803 EXPECT_EQ(0, num_failure_
);
804 EXPECT_EQ(params
.distances
[0], scroll_target
->start_to_end_distance());
807 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureMouseHorizontal
) {
808 CreateControllerAndTarget
<MockScrollMouseTarget
>();
810 SyntheticSmoothMoveGestureParams params
;
811 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT
;
812 params
.start_point
.SetPoint(90, 12);
813 params
.distances
.push_back(gfx::Vector2d(345, 0));
815 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
816 new SyntheticSmoothMoveGesture(params
));
817 QueueSyntheticGesture(gesture
.Pass());
818 FlushInputUntilComplete();
820 MockMoveGestureTarget
* scroll_target
=
821 static_cast<MockMoveGestureTarget
*>(target_
);
822 EXPECT_EQ(1, num_success_
);
823 EXPECT_EQ(0, num_failure_
);
824 EXPECT_EQ(params
.distances
[0], scroll_target
->start_to_end_distance());
827 TEST_F(SyntheticGestureControllerTest
, SingleScrollGestureMouseDiagonal
) {
828 CreateControllerAndTarget
<MockScrollMouseTarget
>();
830 SyntheticSmoothMoveGestureParams params
;
831 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT
;
832 params
.start_point
.SetPoint(90, 12);
833 params
.distances
.push_back(gfx::Vector2d(-194, 303));
835 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
836 new SyntheticSmoothMoveGesture(params
));
837 QueueSyntheticGesture(gesture
.Pass());
838 FlushInputUntilComplete();
840 MockMoveGestureTarget
* scroll_target
=
841 static_cast<MockMoveGestureTarget
*>(target_
);
842 EXPECT_EQ(1, num_success_
);
843 EXPECT_EQ(0, num_failure_
);
844 EXPECT_EQ(params
.distances
[0], scroll_target
->start_to_end_distance());
847 TEST_F(SyntheticGestureControllerTest
, MultiScrollGestureMouse
) {
848 CreateControllerAndTarget
<MockScrollMouseTarget
>();
850 SyntheticSmoothMoveGestureParams params
;
851 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT
;
852 params
.start_point
.SetPoint(90, 12);
853 params
.distances
.push_back(gfx::Vector2d(-129, 212));
854 params
.distances
.push_back(gfx::Vector2d(8, -9));
856 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
857 new SyntheticSmoothMoveGesture(params
));
858 QueueSyntheticGesture(gesture
.Pass());
859 FlushInputUntilComplete();
861 MockMoveGestureTarget
* scroll_target
=
862 static_cast<MockMoveGestureTarget
*>(target_
);
863 EXPECT_EQ(1, num_success_
);
864 EXPECT_EQ(0, num_failure_
);
865 EXPECT_EQ(params
.distances
[0] + params
.distances
[1],
866 scroll_target
->start_to_end_distance());
869 TEST_F(SyntheticGestureControllerTest
, MultiScrollGestureMouseHorizontal
) {
870 CreateControllerAndTarget
<MockScrollMouseTarget
>();
872 SyntheticSmoothMoveGestureParams params
;
873 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT
;
874 params
.start_point
.SetPoint(90, 12);
875 params
.distances
.push_back(gfx::Vector2d(-129, 0));
876 params
.distances
.push_back(gfx::Vector2d(79, 0));
878 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
879 new SyntheticSmoothMoveGesture(params
));
880 QueueSyntheticGesture(gesture
.Pass());
881 FlushInputUntilComplete();
883 MockMoveGestureTarget
* scroll_target
=
884 static_cast<MockMoveGestureTarget
*>(target_
);
885 EXPECT_EQ(1, num_success_
);
886 EXPECT_EQ(0, num_failure_
);
887 // This check only works for horizontal or vertical scrolls because of
888 // floating point precision issues with diagonal scrolls.
889 EXPECT_FLOAT_EQ(params
.distances
[0].Length() + params
.distances
[1].Length(),
890 scroll_target
->total_abs_move_distance_length());
891 EXPECT_EQ(params
.distances
[0] + params
.distances
[1],
892 scroll_target
->start_to_end_distance());
895 void CheckIsWithinRangeMulti(float scroll_distance
,
897 SyntheticGestureTarget
* target
) {
898 if (target_distance
> 0) {
899 EXPECT_GE(scroll_distance
, target_distance
- target
->GetTouchSlopInDips());
900 EXPECT_LE(scroll_distance
, target_distance
+ target
->GetTouchSlopInDips());
902 EXPECT_LE(scroll_distance
, target_distance
+ target
->GetTouchSlopInDips());
903 EXPECT_GE(scroll_distance
, target_distance
- target
->GetTouchSlopInDips());
907 void CheckMultiScrollDistanceIsWithinRange(
908 const gfx::Vector2dF
& scroll_distance
,
909 const gfx::Vector2dF
& target_distance
,
910 SyntheticGestureTarget
* target
) {
911 CheckIsWithinRangeMulti(scroll_distance
.x(), target_distance
.x(), target
);
912 CheckIsWithinRangeMulti(scroll_distance
.y(), target_distance
.y(), target
);
915 TEST_F(SyntheticGestureControllerTest
, MultiScrollGestureTouch
) {
916 CreateControllerAndTarget
<MockMoveTouchTarget
>();
918 SyntheticSmoothMoveGestureParams params
;
919 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
920 params
.start_point
.SetPoint(8, -13);
921 params
.distances
.push_back(gfx::Vector2d(234, 133));
922 params
.distances
.push_back(gfx::Vector2d(-9, 78));
924 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
925 new SyntheticSmoothMoveGesture(params
));
926 QueueSyntheticGesture(gesture
.Pass());
927 FlushInputUntilComplete();
929 MockMoveGestureTarget
* scroll_target
=
930 static_cast<MockMoveGestureTarget
*>(target_
);
931 EXPECT_EQ(1, num_success_
);
932 EXPECT_EQ(0, num_failure_
);
933 CheckMultiScrollDistanceIsWithinRange(
934 scroll_target
->start_to_end_distance(),
935 params
.distances
[0] + params
.distances
[1],
939 TEST_P(SyntheticGestureControllerTestWithParam
,
940 MultiScrollGestureTouchVertical
) {
941 CreateControllerAndTarget
<MockMoveTouchTarget
>();
943 SyntheticSmoothMoveGestureParams params
;
944 params
.input_type
= SyntheticSmoothMoveGestureParams::TOUCH_INPUT
;
945 if (GetParam() == TOUCH_DRAG
) {
946 params
.add_slop
= false;
948 params
.start_point
.SetPoint(234, -13);
949 params
.distances
.push_back(gfx::Vector2d(0, 133));
950 params
.distances
.push_back(gfx::Vector2d(0, 78));
952 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
953 new SyntheticSmoothMoveGesture(params
));
954 QueueSyntheticGesture(gesture
.Pass());
955 FlushInputUntilComplete();
957 MockMoveGestureTarget
* scroll_target
=
958 static_cast<MockMoveGestureTarget
*>(target_
);
959 EXPECT_EQ(1, num_success_
);
960 EXPECT_EQ(0, num_failure_
);
961 if (GetParam() == TOUCH_SCROLL
) {
962 EXPECT_FLOAT_EQ(params
.distances
[0].Length() +
963 params
.distances
[1].Length() +
964 target_
->GetTouchSlopInDips(),
965 scroll_target
->total_abs_move_distance_length());
966 EXPECT_EQ(AddTouchSlopToVector(params
.distances
[0] + params
.distances
[1],
968 scroll_target
->start_to_end_distance());
970 EXPECT_FLOAT_EQ(params
.distances
[0].Length() + params
.distances
[1].Length(),
971 scroll_target
->total_abs_move_distance_length());
972 EXPECT_EQ(params
.distances
[0] + params
.distances
[1],
973 scroll_target
->start_to_end_distance());
977 INSTANTIATE_TEST_CASE_P(Single
,
978 SyntheticGestureControllerTestWithParam
,
979 testing::Values(TOUCH_SCROLL
, TOUCH_DRAG
));
981 TEST_F(SyntheticGestureControllerTest
, SingleDragGestureMouseDiagonal
) {
982 CreateControllerAndTarget
<MockDragMouseTarget
>();
984 SyntheticSmoothMoveGestureParams params
;
985 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT
;
986 params
.start_point
.SetPoint(0, 7);
987 params
.distances
.push_back(gfx::Vector2d(413, -83));
989 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
990 new SyntheticSmoothMoveGesture(params
));
991 QueueSyntheticGesture(gesture
.Pass());
992 FlushInputUntilComplete();
994 MockMoveGestureTarget
* drag_target
=
995 static_cast<MockMoveGestureTarget
*>(target_
);
996 EXPECT_EQ(1, num_success_
);
997 EXPECT_EQ(0, num_failure_
);
998 EXPECT_EQ(drag_target
->start_to_end_distance(), params
.distances
[0]);
1001 TEST_F(SyntheticGestureControllerTest
, SingleDragGestureMouseZeroDistance
) {
1002 CreateControllerAndTarget
<MockDragMouseTarget
>();
1004 SyntheticSmoothMoveGestureParams params
;
1005 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT
;
1006 params
.start_point
.SetPoint(-32, 43);
1007 params
.distances
.push_back(gfx::Vector2d(0, 0));
1009 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
1010 new SyntheticSmoothMoveGesture(params
));
1011 QueueSyntheticGesture(gesture
.Pass());
1012 FlushInputUntilComplete();
1014 MockMoveGestureTarget
* drag_target
=
1015 static_cast<MockMoveGestureTarget
*>(target_
);
1016 EXPECT_EQ(1, num_success_
);
1017 EXPECT_EQ(0, num_failure_
);
1018 EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target
->start_to_end_distance());
1021 TEST_F(SyntheticGestureControllerTest
, MultiDragGestureMouse
) {
1022 CreateControllerAndTarget
<MockDragMouseTarget
>();
1024 SyntheticSmoothMoveGestureParams params
;
1025 params
.input_type
= SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT
;
1026 params
.start_point
.SetPoint(8, -13);
1027 params
.distances
.push_back(gfx::Vector2d(234, 133));
1028 params
.distances
.push_back(gfx::Vector2d(-9, 78));
1030 scoped_ptr
<SyntheticSmoothMoveGesture
> gesture(
1031 new SyntheticSmoothMoveGesture(params
));
1032 QueueSyntheticGesture(gesture
.Pass());
1033 FlushInputUntilComplete();
1035 MockMoveGestureTarget
* drag_target
=
1036 static_cast<MockMoveGestureTarget
*>(target_
);
1037 EXPECT_EQ(1, num_success_
);
1038 EXPECT_EQ(0, num_failure_
);
1039 EXPECT_EQ(drag_target
->start_to_end_distance(),
1040 params
.distances
[0] + params
.distances
[1]);
1043 TEST_F(SyntheticGestureControllerTest
,
1044 SyntheticSmoothDragTestUsingSingleMouseDrag
) {
1045 CreateControllerAndTarget
<MockDragMouseTarget
>();
1047 SyntheticSmoothDragGestureParams params
;
1048 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
1049 params
.distances
.push_back(gfx::Vector2d(234, 133));
1050 params
.speed_in_pixels_s
= 800;
1052 scoped_ptr
<SyntheticSmoothDragGesture
> gesture(
1053 new SyntheticSmoothDragGesture(params
));
1054 const base::TimeTicks timestamp
;
1055 gesture
->ForwardInputEvents(timestamp
, target_
);
1058 TEST_F(SyntheticGestureControllerTest
,
1059 SyntheticSmoothDragTestUsingSingleTouchDrag
) {
1060 CreateControllerAndTarget
<MockMoveTouchTarget
>();
1062 SyntheticSmoothDragGestureParams params
;
1063 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1064 params
.start_point
.SetPoint(89, 32);
1065 params
.distances
.push_back(gfx::Vector2d(0, 123));
1066 params
.speed_in_pixels_s
= 800;
1068 scoped_ptr
<SyntheticSmoothDragGesture
> gesture(
1069 new SyntheticSmoothDragGesture(params
));
1070 const base::TimeTicks timestamp
;
1071 gesture
->ForwardInputEvents(timestamp
, target_
);
1074 TEST_F(SyntheticGestureControllerTest
,
1075 SyntheticSmoothScrollTestUsingSingleTouchScroll
) {
1076 CreateControllerAndTarget
<MockMoveTouchTarget
>();
1078 SyntheticSmoothScrollGestureParams params
;
1079 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1081 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
1082 new SyntheticSmoothScrollGesture(params
));
1083 const base::TimeTicks timestamp
;
1084 gesture
->ForwardInputEvents(timestamp
, target_
);
1087 TEST_F(SyntheticGestureControllerTest
,
1088 SyntheticSmoothScrollTestUsingSingleMouseScroll
) {
1089 CreateControllerAndTarget
<MockScrollMouseTarget
>();
1091 SyntheticSmoothScrollGestureParams params
;
1092 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
1093 params
.anchor
.SetPoint(432, 89);
1094 params
.distances
.push_back(gfx::Vector2d(0, -234));
1095 params
.speed_in_pixels_s
= 800;
1097 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
1098 new SyntheticSmoothScrollGesture(params
));
1099 const base::TimeTicks timestamp
;
1100 gesture
->ForwardInputEvents(timestamp
, target_
);
1103 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchZoomIn
) {
1104 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
1106 SyntheticPinchGestureParams params
;
1107 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1108 params
.scale_factor
= 2.3f
;
1109 params
.anchor
.SetPoint(54, 89);
1111 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
1112 QueueSyntheticGesture(gesture
.Pass());
1113 FlushInputUntilComplete();
1115 MockSyntheticPinchTouchTarget
* pinch_target
=
1116 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
1117 EXPECT_EQ(1, num_success_
);
1118 EXPECT_EQ(0, num_failure_
);
1119 EXPECT_EQ(pinch_target
->zoom_direction(),
1120 MockSyntheticPinchTouchTarget::ZOOM_IN
);
1121 EXPECT_FLOAT_EQ(params
.scale_factor
, pinch_target
->ComputeScaleFactor());
1124 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchZoomOut
) {
1125 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
1127 SyntheticPinchGestureParams params
;
1128 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1129 params
.scale_factor
= 0.4f
;
1130 params
.anchor
.SetPoint(-12, 93);
1132 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
1133 QueueSyntheticGesture(gesture
.Pass());
1134 FlushInputUntilComplete();
1136 MockSyntheticPinchTouchTarget
* pinch_target
=
1137 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
1138 EXPECT_EQ(1, num_success_
);
1139 EXPECT_EQ(0, num_failure_
);
1140 EXPECT_EQ(pinch_target
->zoom_direction(),
1141 MockSyntheticPinchTouchTarget::ZOOM_OUT
);
1142 EXPECT_FLOAT_EQ(params
.scale_factor
, pinch_target
->ComputeScaleFactor());
1145 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchNoScaling
) {
1146 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
1148 SyntheticPinchGestureParams params
;
1149 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1150 params
.scale_factor
= 1.0f
;
1152 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
1153 QueueSyntheticGesture(gesture
.Pass());
1154 FlushInputUntilComplete();
1156 MockSyntheticPinchTouchTarget
* pinch_target
=
1157 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
1158 EXPECT_EQ(1, num_success_
);
1159 EXPECT_EQ(0, num_failure_
);
1160 EXPECT_EQ(pinch_target
->zoom_direction(),
1161 MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN
);
1162 EXPECT_EQ(params
.scale_factor
, pinch_target
->ComputeScaleFactor());
1165 TEST_F(SyntheticGestureControllerTest
, TapGestureTouch
) {
1166 CreateControllerAndTarget
<MockSyntheticTapTouchTarget
>();
1168 SyntheticTapGestureParams params
;
1169 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
1170 params
.duration_ms
= 123;
1171 params
.position
.SetPoint(87, -124);
1173 scoped_ptr
<SyntheticTapGesture
> gesture(new SyntheticTapGesture(params
));
1174 QueueSyntheticGesture(gesture
.Pass());
1175 FlushInputUntilComplete();
1177 MockSyntheticTapTouchTarget
* tap_target
=
1178 static_cast<MockSyntheticTapTouchTarget
*>(target_
);
1179 EXPECT_EQ(1, num_success_
);
1180 EXPECT_EQ(0, num_failure_
);
1181 EXPECT_TRUE(tap_target
->GestureFinished());
1182 EXPECT_EQ(tap_target
->position(), params
.position
);
1183 EXPECT_EQ(tap_target
->GetDuration().InMilliseconds(), params
.duration_ms
);
1184 EXPECT_GE(GetTotalTime(),
1185 base::TimeDelta::FromMilliseconds(params
.duration_ms
));
1188 TEST_F(SyntheticGestureControllerTest
, TapGestureMouse
) {
1189 CreateControllerAndTarget
<MockSyntheticTapMouseTarget
>();
1191 SyntheticTapGestureParams params
;
1192 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
1193 params
.duration_ms
= 79;
1194 params
.position
.SetPoint(98, 123);
1196 scoped_ptr
<SyntheticTapGesture
> gesture(new SyntheticTapGesture(params
));
1197 QueueSyntheticGesture(gesture
.Pass());
1198 FlushInputUntilComplete();
1200 MockSyntheticTapMouseTarget
* tap_target
=
1201 static_cast<MockSyntheticTapMouseTarget
*>(target_
);
1202 EXPECT_EQ(1, num_success_
);
1203 EXPECT_EQ(0, num_failure_
);
1204 EXPECT_TRUE(tap_target
->GestureFinished());
1205 EXPECT_EQ(tap_target
->position(), params
.position
);
1206 EXPECT_EQ(tap_target
->GetDuration().InMilliseconds(), params
.duration_ms
);
1207 EXPECT_GE(GetTotalTime(),
1208 base::TimeDelta::FromMilliseconds(params
.duration_ms
));
1213 } // namespace content