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.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/time/time.h"
7 #include "content/browser/renderer_host/input/synthetic_gesture.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
10 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
12 #include "content/browser/renderer_host/render_widget_host_delegate.h"
13 #include "content/common/input/input_event.h"
14 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
15 #include "content/public/test/mock_render_process_host.h"
16 #include "content/public/test/test_browser_context.h"
17 #include "content/test/test_render_view_host.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/web/WebInputEvent.h"
20 #include "ui/gfx/point.h"
21 #include "ui/gfx/point_f.h"
22 #include "ui/gfx/vector2d.h"
23 #include "ui/gfx/vector2d_f.h"
29 const int kFlushInputRateInMs
= 16;
30 const int kPointerAssumedStoppedTimeMs
= 43;
31 const int kTouchSlopInDips
= 7;
33 class MockSyntheticGesture
: public SyntheticGesture
{
35 MockSyntheticGesture(bool* finished
, int num_steps
)
36 : finished_(finished
),
37 num_steps_(num_steps
),
41 virtual ~MockSyntheticGesture() {}
43 virtual Result
ForwardInputEvents(const base::TimeDelta
& interval
,
44 SyntheticGestureTarget
* target
) OVERRIDE
{
46 if (step_count_
== num_steps_
) {
48 return SyntheticGesture::GESTURE_FINISHED
;
49 } else if (step_count_
> num_steps_
) {
51 // Return arbitrary failure.
52 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED
;
55 return SyntheticGesture::GESTURE_RUNNING
;
64 class MockSyntheticGestureTarget
: public SyntheticGestureTarget
{
66 MockSyntheticGestureTarget()
69 flush_requested_(false),
70 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs
) {}
71 virtual ~MockSyntheticGestureTarget() {}
73 // SyntheticGestureTarget:
74 virtual void DispatchInputEventToPlatform(const InputEvent
& event
) OVERRIDE
{}
76 virtual void OnSyntheticGestureCompleted(
77 SyntheticGesture::Result result
) OVERRIDE
{
78 DCHECK_NE(result
, SyntheticGesture::GESTURE_RUNNING
);
79 if (result
== SyntheticGesture::GESTURE_FINISHED
)
85 virtual void SetNeedsFlush() OVERRIDE
{
86 flush_requested_
= true;
89 virtual SyntheticGestureParams::GestureSourceType
90 GetDefaultSyntheticGestureSourceType() const OVERRIDE
{
91 return SyntheticGestureParams::TOUCH_INPUT
;
93 virtual bool SupportsSyntheticGestureSourceType(
94 SyntheticGestureParams::GestureSourceType gesture_source_type
)
99 virtual base::TimeDelta
PointerAssumedStoppedTime() const OVERRIDE
{
100 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_
);
103 void set_pointer_assumed_stopped_time_ms(int time_ms
) {
104 pointer_assumed_stopped_time_ms_
= time_ms
;
107 virtual int GetTouchSlopInDips() const OVERRIDE
{
108 return kTouchSlopInDips
;
111 int num_success() const { return num_success_
; }
112 int num_failure() const { return num_failure_
; }
114 bool flush_requested() const { return flush_requested_
; }
115 void ClearFlushRequest() { flush_requested_
= false; }
121 bool flush_requested_
;
123 int pointer_assumed_stopped_time_ms_
;
126 class MockSyntheticSmoothScrollGestureTarget
127 : public MockSyntheticGestureTarget
{
129 MockSyntheticSmoothScrollGestureTarget() {}
130 virtual ~MockSyntheticSmoothScrollGestureTarget() {}
132 gfx::Vector2dF
scroll_distance() const { return scroll_distance_
; }
135 gfx::Vector2dF scroll_distance_
;
138 class MockSyntheticSmoothScrollMouseTarget
139 : public MockSyntheticSmoothScrollGestureTarget
{
141 MockSyntheticSmoothScrollMouseTarget() {}
142 virtual ~MockSyntheticSmoothScrollMouseTarget() {}
144 virtual void DispatchInputEventToPlatform(const InputEvent
& event
) OVERRIDE
{
145 const blink::WebInputEvent
* web_event
= event
.web_event
.get();
146 ASSERT_EQ(web_event
->type
, blink::WebInputEvent::MouseWheel
);
147 const blink::WebMouseWheelEvent
* mouse_wheel_event
=
148 static_cast<const blink::WebMouseWheelEvent
*>(web_event
);
149 scroll_distance_
-= gfx::Vector2dF(mouse_wheel_event
->deltaX
,
150 mouse_wheel_event
->deltaY
);
154 class MockSyntheticSmoothScrollTouchTarget
155 : public MockSyntheticSmoothScrollGestureTarget
{
157 MockSyntheticSmoothScrollTouchTarget()
159 virtual ~MockSyntheticSmoothScrollTouchTarget() {}
161 virtual void DispatchInputEventToPlatform(const InputEvent
& event
) OVERRIDE
{
162 const blink::WebInputEvent
* web_event
= event
.web_event
.get();
163 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event
->type
));
164 const blink::WebTouchEvent
* touch_event
=
165 static_cast<const blink::WebTouchEvent
*>(web_event
);
166 ASSERT_EQ(touch_event
->touchesLength
, (unsigned int)1);
169 ASSERT_EQ(touch_event
->type
, blink::WebInputEvent::TouchStart
);
170 anchor_
.SetPoint(touch_event
->touches
[0].position
.x
,
171 touch_event
->touches
[0].position
.y
);
174 ASSERT_NE(touch_event
->type
, blink::WebInputEvent::TouchStart
);
175 ASSERT_NE(touch_event
->type
, blink::WebInputEvent::TouchCancel
);
176 // Ignore move events.
178 if (touch_event
->type
== blink::WebInputEvent::TouchEnd
)
180 anchor_
- gfx::PointF(touch_event
->touches
[0].position
.x
,
181 touch_event
->touches
[0].position
.y
);
190 class MockSyntheticPinchTouchTarget
: public MockSyntheticGestureTarget
{
193 ZOOM_DIRECTION_UNKNOWN
,
198 MockSyntheticPinchTouchTarget()
199 : total_num_pixels_covered_(0),
200 last_pointer_distance_(0),
201 zoom_direction_(ZOOM_DIRECTION_UNKNOWN
),
203 virtual ~MockSyntheticPinchTouchTarget() {}
205 virtual void DispatchInputEventToPlatform(const InputEvent
& event
) OVERRIDE
{
206 const blink::WebInputEvent
* web_event
= event
.web_event
.get();
207 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event
->type
));
208 const blink::WebTouchEvent
* touch_event
=
209 static_cast<const blink::WebTouchEvent
*>(web_event
);
210 ASSERT_EQ(touch_event
->touchesLength
, (unsigned int)2);
213 ASSERT_EQ(touch_event
->type
, blink::WebInputEvent::TouchStart
);
215 start_0_
= gfx::Point(touch_event
->touches
[0].position
);
216 start_1_
= gfx::Point(touch_event
->touches
[1].position
);
217 last_pointer_distance_
= (start_0_
- start_1_
).Length();
221 ASSERT_NE(touch_event
->type
, blink::WebInputEvent::TouchStart
);
222 ASSERT_NE(touch_event
->type
, blink::WebInputEvent::TouchCancel
);
224 gfx::PointF current_0
= gfx::Point(touch_event
->touches
[0].position
);
225 gfx::PointF current_1
= gfx::Point(touch_event
->touches
[1].position
);
227 total_num_pixels_covered_
=
228 (current_0
- start_0_
).Length() + (current_1
- start_1_
).Length();
229 float pointer_distance
= (current_0
- current_1
).Length();
231 if (last_pointer_distance_
!= pointer_distance
) {
232 if (zoom_direction_
== ZOOM_DIRECTION_UNKNOWN
)
234 ComputeZoomDirection(last_pointer_distance_
, pointer_distance
);
238 ComputeZoomDirection(last_pointer_distance_
, pointer_distance
));
241 last_pointer_distance_
= pointer_distance
;
245 float total_num_pixels_covered() const { return total_num_pixels_covered_
; }
246 ZoomDirection
zoom_direction() const { return zoom_direction_
; }
249 ZoomDirection
ComputeZoomDirection(float last_pointer_distance
,
250 float current_pointer_distance
) {
251 DCHECK_NE(last_pointer_distance
, current_pointer_distance
);
252 return last_pointer_distance
< current_pointer_distance
? ZOOM_IN
256 float total_num_pixels_covered_
;
257 float last_pointer_distance_
;
258 ZoomDirection zoom_direction_
;
259 gfx::PointF start_0_
;
260 gfx::PointF start_1_
;
264 class SyntheticGestureControllerTest
: public testing::Test
{
266 SyntheticGestureControllerTest() {}
267 virtual ~SyntheticGestureControllerTest() {}
270 template<typename MockGestureTarget
>
271 void CreateControllerAndTarget() {
272 target_
= new MockGestureTarget();
274 controller_
.reset(new SyntheticGestureController(
275 scoped_ptr
<SyntheticGestureTarget
>(target_
)));
278 virtual void SetUp() OVERRIDE
{
279 start_time_
= base::TimeTicks::Now();
283 virtual void TearDown() OVERRIDE
{
286 time_
= base::TimeTicks();
289 void FlushInputUntilComplete() {
290 while (target_
->flush_requested()) {
291 target_
->ClearFlushRequest();
292 time_
+= base::TimeDelta::FromMilliseconds(kFlushInputRateInMs
);
293 controller_
->Flush(time_
);
297 base::TimeDelta
GetTotalTime() const { return time_
- start_time_
; }
299 MockSyntheticGestureTarget
* target_
;
300 scoped_ptr
<SyntheticGestureController
> controller_
;
301 base::TimeTicks start_time_
;
302 base::TimeTicks time_
;
305 TEST_F(SyntheticGestureControllerTest
, SingleGesture
) {
306 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
309 scoped_ptr
<MockSyntheticGesture
> gesture(
310 new MockSyntheticGesture(&finished
, 3));
311 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
312 FlushInputUntilComplete();
314 EXPECT_TRUE(finished
);
315 EXPECT_EQ(1, target_
->num_success());
316 EXPECT_EQ(0, target_
->num_failure());
319 TEST_F(SyntheticGestureControllerTest
, GestureFailed
) {
320 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
323 scoped_ptr
<MockSyntheticGesture
> gesture(
324 new MockSyntheticGesture(&finished
, 0));
325 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
326 FlushInputUntilComplete();
328 EXPECT_TRUE(finished
);
329 EXPECT_EQ(1, target_
->num_failure());
330 EXPECT_EQ(0, target_
->num_success());
333 TEST_F(SyntheticGestureControllerTest
, SuccessiveGestures
) {
334 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
336 bool finished_1
, finished_2
;
337 scoped_ptr
<MockSyntheticGesture
> gesture_1(
338 new MockSyntheticGesture(&finished_1
, 2));
339 scoped_ptr
<MockSyntheticGesture
> gesture_2(
340 new MockSyntheticGesture(&finished_2
, 4));
342 // Queue first gesture and wait for it to finish
343 controller_
->QueueSyntheticGesture(gesture_1
.PassAs
<SyntheticGesture
>());
344 FlushInputUntilComplete();
346 EXPECT_TRUE(finished_1
);
347 EXPECT_EQ(1, target_
->num_success());
348 EXPECT_EQ(0, target_
->num_failure());
350 // Queue second gesture.
351 controller_
->QueueSyntheticGesture(gesture_2
.PassAs
<SyntheticGesture
>());
352 FlushInputUntilComplete();
354 EXPECT_TRUE(finished_2
);
355 EXPECT_EQ(2, target_
->num_success());
356 EXPECT_EQ(0, target_
->num_failure());
359 TEST_F(SyntheticGestureControllerTest
, TwoGesturesInFlight
) {
360 CreateControllerAndTarget
<MockSyntheticGestureTarget
>();
362 bool finished_1
, finished_2
;
363 scoped_ptr
<MockSyntheticGesture
> gesture_1(
364 new MockSyntheticGesture(&finished_1
, 2));
365 scoped_ptr
<MockSyntheticGesture
> gesture_2(
366 new MockSyntheticGesture(&finished_2
, 4));
368 controller_
->QueueSyntheticGesture(gesture_1
.PassAs
<SyntheticGesture
>());
369 controller_
->QueueSyntheticGesture(gesture_2
.PassAs
<SyntheticGesture
>());
370 FlushInputUntilComplete();
372 EXPECT_TRUE(finished_1
);
373 EXPECT_TRUE(finished_2
);
375 EXPECT_EQ(2, target_
->num_success());
376 EXPECT_EQ(0, target_
->num_failure());
379 gfx::Vector2d
AddTouchSlopToVector(const gfx::Vector2d
& vector
,
380 SyntheticGestureTarget
* target
) {
381 const int kTouchSlop
= target
->GetTouchSlopInDips();
395 return gfx::Vector2d(x
, y
);
398 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchVertical
) {
399 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
401 SyntheticSmoothScrollGestureParams params
;
402 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
403 params
.distance
= gfx::Vector2d(0, 123);
404 params
.anchor
.SetPoint(89, 32);
406 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
407 new SyntheticSmoothScrollGesture(params
));
408 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
409 FlushInputUntilComplete();
411 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
412 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
413 EXPECT_EQ(1, target_
->num_success());
414 EXPECT_EQ(0, target_
->num_failure());
415 EXPECT_EQ(AddTouchSlopToVector(params
.distance
, target_
),
416 smooth_scroll_target
->scroll_distance());
419 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchHorizontal
) {
420 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
422 SyntheticSmoothScrollGestureParams params
;
423 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
424 params
.distance
= gfx::Vector2d(-234, 0);
425 params
.anchor
.SetPoint(12, -23);
427 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
428 new SyntheticSmoothScrollGesture(params
));
429 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
430 FlushInputUntilComplete();
432 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
433 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
434 EXPECT_EQ(1, target_
->num_success());
435 EXPECT_EQ(0, target_
->num_failure());
436 EXPECT_EQ(AddTouchSlopToVector(params
.distance
, target_
),
437 smooth_scroll_target
->scroll_distance());
440 void CheckIsWithinRange(float scroll_distance
,
442 SyntheticGestureTarget
* target
) {
443 if (target_distance
> 0) {
444 EXPECT_LE(target_distance
, scroll_distance
);
445 EXPECT_LE(scroll_distance
, target_distance
+ target
->GetTouchSlopInDips());
447 EXPECT_GE(target_distance
, scroll_distance
);
448 EXPECT_GE(scroll_distance
, target_distance
- target
->GetTouchSlopInDips());
452 void CheckScrollDistanceIsWithinRange(const gfx::Vector2dF
& scroll_distance
,
453 const gfx::Vector2d
& target_distance
,
454 SyntheticGestureTarget
* target
) {
455 CheckIsWithinRange(scroll_distance
.x(), target_distance
.x(), target
);
456 CheckIsWithinRange(scroll_distance
.y(), target_distance
.y(), target
);
459 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchDiagonal
) {
460 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
462 SyntheticSmoothScrollGestureParams params
;
463 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
464 params
.distance
= gfx::Vector2d(413, -83);
465 params
.anchor
.SetPoint(0, 7);
467 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
468 new SyntheticSmoothScrollGesture(params
));
469 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
470 FlushInputUntilComplete();
472 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
473 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
474 EXPECT_EQ(1, target_
->num_success());
475 EXPECT_EQ(0, target_
->num_failure());
476 CheckScrollDistanceIsWithinRange(
477 smooth_scroll_target
->scroll_distance(), params
.distance
, target_
);
480 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchLongStop
) {
481 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
483 // Create a smooth scroll with a short distance and set the pointer assumed
484 // stopped time high, so that the stopping should dominate the time the
485 // gesture is active.
486 SyntheticSmoothScrollGestureParams params
;
487 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
488 params
.distance
= gfx::Vector2d(21, -12);
489 params
.prevent_fling
= true;
490 params
.anchor
.SetPoint(-98, -23);
492 target_
->set_pointer_assumed_stopped_time_ms(543);
494 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
495 new SyntheticSmoothScrollGesture(params
));
496 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
497 FlushInputUntilComplete();
499 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
500 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
501 EXPECT_EQ(1, target_
->num_success());
502 EXPECT_EQ(0, target_
->num_failure());
503 CheckScrollDistanceIsWithinRange(
504 smooth_scroll_target
->scroll_distance(), params
.distance
, target_
);
505 EXPECT_GE(GetTotalTime(), target_
->PointerAssumedStoppedTime());
508 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchFling
) {
509 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
511 // Create a smooth scroll with a short distance and set the pointer assumed
512 // stopped time high. Disable 'prevent_fling' and check that the gesture
513 // finishes without waiting before it stops.
514 SyntheticSmoothScrollGestureParams params
;
515 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
516 params
.distance
= gfx::Vector2d(-43, 19);
517 params
.prevent_fling
= false;
518 params
.anchor
.SetPoint(-89, 78);
520 target_
->set_pointer_assumed_stopped_time_ms(543);
522 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
523 new SyntheticSmoothScrollGesture(params
));
524 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
525 FlushInputUntilComplete();
527 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
528 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
529 EXPECT_EQ(1, target_
->num_success());
530 EXPECT_EQ(0, target_
->num_failure());
531 CheckScrollDistanceIsWithinRange(
532 smooth_scroll_target
->scroll_distance(), params
.distance
, target_
);
533 EXPECT_LE(GetTotalTime(), target_
->PointerAssumedStoppedTime());
536 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureTouchZeroDistance
) {
537 CreateControllerAndTarget
<MockSyntheticSmoothScrollTouchTarget
>();
539 SyntheticSmoothScrollGestureParams params
;
540 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
541 params
.distance
= gfx::Vector2d(0, 0);
542 params
.anchor
.SetPoint(-32, 43);
544 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
545 new SyntheticSmoothScrollGesture(params
));
546 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
547 FlushInputUntilComplete();
549 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
550 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
551 EXPECT_EQ(1, target_
->num_success());
552 EXPECT_EQ(0, target_
->num_failure());
553 EXPECT_EQ(gfx::Vector2dF(0, 0), smooth_scroll_target
->scroll_distance());
556 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureMouseVertical
) {
557 CreateControllerAndTarget
<MockSyntheticSmoothScrollMouseTarget
>();
559 SyntheticSmoothScrollGestureParams params
;
560 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
561 params
.distance
= gfx::Vector2d(0, -234);
562 params
.anchor
.SetPoint(432, 89);
564 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
565 new SyntheticSmoothScrollGesture(params
));
566 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
567 FlushInputUntilComplete();
569 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
570 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
571 EXPECT_EQ(1, target_
->num_success());
572 EXPECT_EQ(0, target_
->num_failure());
573 EXPECT_EQ(params
.distance
, smooth_scroll_target
->scroll_distance());
576 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureMouseHorizontal
) {
577 CreateControllerAndTarget
<MockSyntheticSmoothScrollMouseTarget
>();
579 SyntheticSmoothScrollGestureParams params
;
580 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
581 params
.distance
= gfx::Vector2d(345, 0);
582 params
.anchor
.SetPoint(90, 12);
584 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
585 new SyntheticSmoothScrollGesture(params
));
586 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
587 FlushInputUntilComplete();
589 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
590 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
591 EXPECT_EQ(1, target_
->num_success());
592 EXPECT_EQ(0, target_
->num_failure());
593 EXPECT_EQ(params
.distance
, smooth_scroll_target
->scroll_distance());
596 TEST_F(SyntheticGestureControllerTest
, SmoothScrollGestureMouseDiagonal
) {
597 CreateControllerAndTarget
<MockSyntheticSmoothScrollMouseTarget
>();
599 SyntheticSmoothScrollGestureParams params
;
600 params
.gesture_source_type
= SyntheticGestureParams::MOUSE_INPUT
;
601 params
.distance
= gfx::Vector2d(-194, 303);
602 params
.anchor
.SetPoint(90, 12);
604 scoped_ptr
<SyntheticSmoothScrollGesture
> gesture(
605 new SyntheticSmoothScrollGesture(params
));
606 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
607 FlushInputUntilComplete();
609 MockSyntheticSmoothScrollGestureTarget
* smooth_scroll_target
=
610 static_cast<MockSyntheticSmoothScrollGestureTarget
*>(target_
);
611 EXPECT_EQ(1, target_
->num_success());
612 EXPECT_EQ(0, target_
->num_failure());
613 EXPECT_EQ(params
.distance
, smooth_scroll_target
->scroll_distance());
616 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchZoomIn
) {
617 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
619 SyntheticPinchGestureParams params
;
620 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
621 params
.zoom_in
= true;
622 params
.total_num_pixels_covered
= 345;
623 params
.anchor
.SetPoint(54, 89);
625 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
626 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
627 FlushInputUntilComplete();
629 MockSyntheticPinchTouchTarget
* pinch_target
=
630 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
631 EXPECT_EQ(1, target_
->num_success());
632 EXPECT_EQ(0, target_
->num_failure());
633 EXPECT_EQ(pinch_target
->zoom_direction(),
634 MockSyntheticPinchTouchTarget::ZOOM_IN
);
635 EXPECT_EQ(params
.total_num_pixels_covered
+ 2 * target_
->GetTouchSlopInDips(),
636 pinch_target
->total_num_pixels_covered());
639 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchZoomOut
) {
640 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
642 SyntheticPinchGestureParams params
;
643 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
644 params
.zoom_in
= false;
645 params
.total_num_pixels_covered
= 456;
646 params
.anchor
.SetPoint(-12, 93);
648 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
649 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
650 FlushInputUntilComplete();
652 MockSyntheticPinchTouchTarget
* pinch_target
=
653 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
654 EXPECT_EQ(1, target_
->num_success());
655 EXPECT_EQ(0, target_
->num_failure());
656 EXPECT_EQ(pinch_target
->zoom_direction(),
657 MockSyntheticPinchTouchTarget::ZOOM_OUT
);
658 EXPECT_EQ(params
.total_num_pixels_covered
+ 2 * target_
->GetTouchSlopInDips(),
659 pinch_target
->total_num_pixels_covered());
662 TEST_F(SyntheticGestureControllerTest
, PinchGestureTouchZeroPixelsCovered
) {
663 CreateControllerAndTarget
<MockSyntheticPinchTouchTarget
>();
665 SyntheticPinchGestureParams params
;
666 params
.gesture_source_type
= SyntheticGestureParams::TOUCH_INPUT
;
667 params
.zoom_in
= true;
668 params
.total_num_pixels_covered
= 0;
670 scoped_ptr
<SyntheticPinchGesture
> gesture(new SyntheticPinchGesture(params
));
671 controller_
->QueueSyntheticGesture(gesture
.PassAs
<SyntheticGesture
>());
672 FlushInputUntilComplete();
674 MockSyntheticPinchTouchTarget
* pinch_target
=
675 static_cast<MockSyntheticPinchTouchTarget
*>(target_
);
676 EXPECT_EQ(1, target_
->num_success());
677 EXPECT_EQ(0, target_
->num_failure());
678 EXPECT_EQ(pinch_target
->zoom_direction(),
679 MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN
);
680 EXPECT_EQ(0, pinch_target
->total_num_pixels_covered());
685 } // namespace content