summaryrefslogtreecommitdiffstats
path: root/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc')
-rw-r--r--chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc705
1 files changed, 451 insertions, 254 deletions
diff --git a/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc b/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
index f449e5774ca..b79e797aad2 100644
--- a/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
+++ b/chromium/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "content/browser/renderer_host/input/synthetic_gesture.h"
@@ -11,7 +12,6 @@
#include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
#include "content/browser/renderer_host/input/synthetic_tap_gesture.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
-#include "content/common/input/input_event.h"
#include "content/common/input/synthetic_pinch_gesture_params.h"
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
#include "content/common/input/synthetic_tap_gesture_params.h"
@@ -25,13 +25,19 @@
#include "ui/gfx/vector2d.h"
#include "ui/gfx/vector2d_f.h"
+using blink::WebInputEvent;
+using blink::WebMouseEvent;
+using blink::WebMouseWheelEvent;
+using blink::WebTouchEvent;
+
namespace content {
namespace {
const int kFlushInputRateInMs = 16;
const int kPointerAssumedStoppedTimeMs = 43;
-const int kTouchSlopInDips = 7;
+const float kTouchSlopInDips = 7.0f;
+const float kMinScalingSpanInDips = 27.5f;
class MockSyntheticGesture : public SyntheticGesture {
public:
@@ -43,7 +49,7 @@ class MockSyntheticGesture : public SyntheticGesture {
}
virtual ~MockSyntheticGesture() {}
- virtual Result ForwardInputEvents(const base::TimeDelta& interval,
+ virtual Result ForwardInputEvents(const base::TimeTicks& timestamp,
SyntheticGestureTarget* target) OVERRIDE {
step_count_++;
if (step_count_ == num_steps_) {
@@ -67,23 +73,13 @@ class MockSyntheticGesture : public SyntheticGesture {
class MockSyntheticGestureTarget : public SyntheticGestureTarget {
public:
MockSyntheticGestureTarget()
- : num_success_(0),
- num_failure_(0),
- flush_requested_(false),
+ : flush_requested_(false),
pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {}
virtual ~MockSyntheticGestureTarget() {}
// SyntheticGestureTarget:
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {}
-
- virtual void OnSyntheticGestureCompleted(
- SyntheticGesture::Result result) OVERRIDE {
- DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING);
- if (result == SyntheticGesture::GESTURE_FINISHED)
- num_success_++;
- else
- num_failure_++;
- }
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {}
virtual void SetNeedsFlush() OVERRIDE {
flush_requested_ = true;
@@ -93,11 +89,6 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget {
GetDefaultSyntheticGestureSourceType() const OVERRIDE {
return SyntheticGestureParams::TOUCH_INPUT;
}
- virtual bool SupportsSyntheticGestureSourceType(
- SyntheticGestureParams::GestureSourceType gesture_source_type)
- const OVERRIDE {
- return true;
- }
virtual base::TimeDelta PointerAssumedStoppedTime() const OVERRIDE {
return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_);
@@ -107,86 +98,92 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget {
pointer_assumed_stopped_time_ms_ = time_ms;
}
- virtual int GetTouchSlopInDips() const OVERRIDE {
+ virtual float GetTouchSlopInDips() const OVERRIDE {
return kTouchSlopInDips;
}
- int num_success() const { return num_success_; }
- int num_failure() const { return num_failure_; }
+ virtual float GetMinScalingSpanInDips() const OVERRIDE {
+ return kMinScalingSpanInDips;
+ }
bool flush_requested() const { return flush_requested_; }
void ClearFlushRequest() { flush_requested_ = false; }
private:
- int num_success_;
- int num_failure_;
-
bool flush_requested_;
int pointer_assumed_stopped_time_ms_;
};
-class MockSyntheticSmoothScrollGestureTarget
- : public MockSyntheticGestureTarget {
+class MockScrollGestureTarget : public MockSyntheticGestureTarget {
public:
- MockSyntheticSmoothScrollGestureTarget() {}
- virtual ~MockSyntheticSmoothScrollGestureTarget() {}
+ MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {}
+ virtual ~MockScrollGestureTarget() {}
- gfx::Vector2dF scroll_distance() const { return scroll_distance_; }
+ gfx::Vector2dF start_to_end_distance() const {
+ return start_to_end_distance_;
+ }
+ float total_abs_scroll_distance_length() const {
+ return total_abs_scroll_distance_length_;
+ }
protected:
- gfx::Vector2dF scroll_distance_;
+ gfx::Vector2dF start_to_end_distance_;
+ float total_abs_scroll_distance_length_;
};
-class MockSyntheticSmoothScrollMouseTarget
- : public MockSyntheticSmoothScrollGestureTarget {
+class MockScrollMouseTarget : public MockScrollGestureTarget {
public:
- MockSyntheticSmoothScrollMouseTarget() {}
- virtual ~MockSyntheticSmoothScrollMouseTarget() {}
-
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
- const blink::WebInputEvent* web_event = event.web_event.get();
- ASSERT_EQ(web_event->type, blink::WebInputEvent::MouseWheel);
- const blink::WebMouseWheelEvent* mouse_wheel_event =
- static_cast<const blink::WebMouseWheelEvent*>(web_event);
- scroll_distance_ -= gfx::Vector2dF(mouse_wheel_event->deltaX,
- mouse_wheel_event->deltaY);
+ MockScrollMouseTarget() {}
+ virtual ~MockScrollMouseTarget() {}
+
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {
+ ASSERT_EQ(event.type, WebInputEvent::MouseWheel);
+ const WebMouseWheelEvent& mouse_wheel_event =
+ static_cast<const WebMouseWheelEvent&>(event);
+ gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY);
+ start_to_end_distance_ += delta;
+ total_abs_scroll_distance_length_ += delta.Length();
}
};
-class MockSyntheticSmoothScrollTouchTarget
- : public MockSyntheticSmoothScrollGestureTarget {
+class MockScrollTouchTarget : public MockScrollGestureTarget {
public:
- MockSyntheticSmoothScrollTouchTarget()
- : started_(false) {}
- virtual ~MockSyntheticSmoothScrollTouchTarget() {}
+ MockScrollTouchTarget() : started_(false) {}
+ virtual ~MockScrollTouchTarget() {}
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
- const blink::WebInputEvent* web_event = event.web_event.get();
- ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type));
- const blink::WebTouchEvent* touch_event =
- static_cast<const blink::WebTouchEvent*>(web_event);
- ASSERT_EQ(touch_event->touchesLength, (unsigned int)1);
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {
+ ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
+ const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
+ ASSERT_EQ(touch_event.touchesLength, 1U);
if (!started_) {
- ASSERT_EQ(touch_event->type, blink::WebInputEvent::TouchStart);
- anchor_.SetPoint(touch_event->touches[0].position.x,
- touch_event->touches[0].position.y);
+ ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
+ start_.SetPoint(touch_event.touches[0].position.x,
+ touch_event.touches[0].position.y);
+ last_touch_point_ = start_;
started_ = true;
} else {
- ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchStart);
- ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchCancel);
- // Ignore move events.
-
- if (touch_event->type == blink::WebInputEvent::TouchEnd)
- scroll_distance_ =
- anchor_ - gfx::PointF(touch_event->touches[0].position.x,
- touch_event->touches[0].position.y);
+ ASSERT_NE(touch_event.type, WebInputEvent::TouchStart);
+ ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel);
+
+ gfx::PointF touch_point(touch_event.touches[0].position.x,
+ touch_event.touches[0].position.y);
+ gfx::Vector2dF delta = touch_point - last_touch_point_;
+ total_abs_scroll_distance_length_ += delta.Length();
+
+ if (touch_event.type == WebInputEvent::TouchEnd)
+ start_to_end_distance_ = touch_point - start_;
+
+ last_touch_point_ = touch_point;
}
}
protected:
- gfx::Point anchor_;
+ gfx::Point start_;
+ gfx::PointF last_touch_point_;
bool started_;
};
@@ -199,36 +196,35 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget {
};
MockSyntheticPinchTouchTarget()
- : total_num_pixels_covered_(0),
+ : initial_pointer_distance_(0),
last_pointer_distance_(0),
zoom_direction_(ZOOM_DIRECTION_UNKNOWN),
started_(false) {}
virtual ~MockSyntheticPinchTouchTarget() {}
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
- const blink::WebInputEvent* web_event = event.web_event.get();
- ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type));
- const blink::WebTouchEvent* touch_event =
- static_cast<const blink::WebTouchEvent*>(web_event);
- ASSERT_EQ(touch_event->touchesLength, (unsigned int)2);
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {
+ ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
+ const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
+ ASSERT_EQ(touch_event.touchesLength, 2U);
if (!started_) {
- ASSERT_EQ(touch_event->type, blink::WebInputEvent::TouchStart);
+ ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
- start_0_ = gfx::Point(touch_event->touches[0].position);
- start_1_ = gfx::Point(touch_event->touches[1].position);
+ start_0_ = gfx::PointF(touch_event.touches[0].position);
+ start_1_ = gfx::PointF(touch_event.touches[1].position);
last_pointer_distance_ = (start_0_ - start_1_).Length();
+ initial_pointer_distance_ = last_pointer_distance_;
+ EXPECT_GE(initial_pointer_distance_, GetMinScalingSpanInDips());
started_ = true;
} else {
- ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchStart);
- ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchCancel);
+ ASSERT_NE(touch_event.type, WebInputEvent::TouchStart);
+ ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel);
- gfx::PointF current_0 = gfx::Point(touch_event->touches[0].position);
- gfx::PointF current_1 = gfx::Point(touch_event->touches[1].position);
+ gfx::PointF current_0 = gfx::PointF(touch_event.touches[0].position);
+ gfx::PointF current_1 = gfx::PointF(touch_event.touches[1].position);
- total_num_pixels_covered_ =
- (current_0 - start_0_).Length() + (current_1 - start_1_).Length();
float pointer_distance = (current_0 - current_1).Length();
if (last_pointer_distance_ != pointer_distance) {
@@ -245,9 +241,24 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget {
}
}
- float total_num_pixels_covered() const { return total_num_pixels_covered_; }
ZoomDirection zoom_direction() const { return zoom_direction_; }
+ float ComputeScaleFactor() const {
+ switch (zoom_direction_) {
+ case ZOOM_IN:
+ return last_pointer_distance_ /
+ (initial_pointer_distance_ + 2 * GetTouchSlopInDips());
+ case ZOOM_OUT:
+ return last_pointer_distance_ /
+ (initial_pointer_distance_ - 2 * GetTouchSlopInDips());
+ case ZOOM_DIRECTION_UNKNOWN:
+ return 1.0f;
+ default:
+ NOTREACHED();
+ return 0.0f;
+ }
+ }
+
private:
ZoomDirection ComputeZoomDirection(float last_pointer_distance,
float current_pointer_distance) {
@@ -256,7 +267,7 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget {
: ZOOM_OUT;
}
- float total_num_pixels_covered_;
+ float initial_pointer_distance_;
float last_pointer_distance_;
ZoomDirection zoom_direction_;
gfx::PointF start_0_;
@@ -270,7 +281,8 @@ class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget {
virtual ~MockSyntheticTapGestureTarget() {}
bool GestureFinished() const { return state_ == FINISHED; }
- gfx::Point position() const { return position_; }
+ gfx::PointF position() const { return position_; }
+ base::TimeDelta GetDuration() const { return stop_time_ - start_time_; }
protected:
enum GestureState {
@@ -279,7 +291,9 @@ class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget {
FINISHED
};
- gfx::Point position_;
+ gfx::PointF position_;
+ base::TimeDelta start_time_;
+ base::TimeDelta stop_time_;
GestureState state_;
};
@@ -288,22 +302,25 @@ class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget {
MockSyntheticTapTouchTarget() {}
virtual ~MockSyntheticTapTouchTarget() {}
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
- const blink::WebInputEvent* web_event = event.web_event.get();
- ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type));
- const blink::WebTouchEvent* touch_event =
- static_cast<const blink::WebTouchEvent*>(web_event);
- ASSERT_EQ(touch_event->touchesLength, (unsigned int)1);
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {
+ ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
+ const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
+ ASSERT_EQ(touch_event.touchesLength, 1U);
switch (state_) {
case NOT_STARTED:
- EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchStart);
- position_ = gfx::Point(touch_event->touches[0].position);
+ EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart);
+ position_ = gfx::PointF(touch_event.touches[0].position);
+ start_time_ = base::TimeDelta::FromMilliseconds(
+ static_cast<int64>(touch_event.timeStampSeconds * 1000));
state_ = STARTED;
break;
case STARTED:
- EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchEnd);
- EXPECT_EQ(position_, gfx::Point(touch_event->touches[0].position));
+ EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd);
+ EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position));
+ stop_time_ = base::TimeDelta::FromMilliseconds(
+ static_cast<int64>(touch_event.timeStampSeconds * 1000));
state_ = FINISHED;
break;
case FINISHED:
@@ -318,25 +335,28 @@ class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
MockSyntheticTapMouseTarget() {}
virtual ~MockSyntheticTapMouseTarget() {}
- virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
- const blink::WebInputEvent* web_event = event.web_event.get();
- ASSERT_TRUE(blink::WebInputEvent::isMouseEventType(web_event->type));
- const blink::WebMouseEvent* mouse_event =
- static_cast<const blink::WebMouseEvent*>(web_event);
+ virtual void DispatchInputEventToPlatform(
+ const WebInputEvent& event) OVERRIDE {
+ ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
+ const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
switch (state_) {
case NOT_STARTED:
- EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseDown);
- EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft);
- EXPECT_EQ(mouse_event->clickCount, 1);
- position_ = gfx::Point(mouse_event->x, mouse_event->y);
+ EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown);
+ EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
+ EXPECT_EQ(mouse_event.clickCount, 1);
+ position_ = gfx::PointF(mouse_event.x, mouse_event.y);
+ start_time_ = base::TimeDelta::FromMilliseconds(
+ static_cast<int64>(mouse_event.timeStampSeconds * 1000));
state_ = STARTED;
break;
case STARTED:
- EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseUp);
- EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft);
- EXPECT_EQ(mouse_event->clickCount, 1);
- EXPECT_EQ(position_, gfx::Point(mouse_event->x, mouse_event->y));
+ EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp);
+ EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
+ EXPECT_EQ(mouse_event.clickCount, 1);
+ EXPECT_EQ(position_, gfx::PointF(mouse_event.x, mouse_event.y));
+ stop_time_ = base::TimeDelta::FromMilliseconds(
+ static_cast<int64>(mouse_event.timeStampSeconds * 1000));
state_ = FINISHED;
break;
case FINISHED:
@@ -355,7 +375,6 @@ class SyntheticGestureControllerTest : public testing::Test {
template<typename MockGestureTarget>
void CreateControllerAndTarget() {
target_ = new MockGestureTarget();
-
controller_.reset(new SyntheticGestureController(
scoped_ptr<SyntheticGestureTarget>(target_)));
}
@@ -363,6 +382,8 @@ class SyntheticGestureControllerTest : public testing::Test {
virtual void SetUp() OVERRIDE {
start_time_ = base::TimeTicks::Now();
time_ = start_time_;
+ num_success_ = 0;
+ num_failure_ = 0;
}
virtual void TearDown() OVERRIDE {
@@ -371,20 +392,39 @@ class SyntheticGestureControllerTest : public testing::Test {
time_ = base::TimeTicks();
}
+ void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) {
+ controller_->QueueSyntheticGesture(gesture.Pass(),
+ base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted,
+ base::Unretained(this)));
+ }
+
void FlushInputUntilComplete() {
while (target_->flush_requested()) {
- target_->ClearFlushRequest();
- time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
- controller_->Flush(time_);
+ while (target_->flush_requested()) {
+ target_->ClearFlushRequest();
+ time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
+ controller_->Flush(time_);
+ }
+ controller_->OnDidFlushInput();
}
}
+ void OnSyntheticGestureCompleted(SyntheticGesture::Result result) {
+ DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING);
+ if (result == SyntheticGesture::GESTURE_FINISHED)
+ num_success_++;
+ else
+ num_failure_++;
+ }
+
base::TimeDelta GetTotalTime() const { return time_ - start_time_; }
MockSyntheticGestureTarget* target_;
scoped_ptr<SyntheticGestureController> controller_;
base::TimeTicks start_time_;
base::TimeTicks time_;
+ int num_success_;
+ int num_failure_;
};
TEST_F(SyntheticGestureControllerTest, SingleGesture) {
@@ -393,12 +433,12 @@ TEST_F(SyntheticGestureControllerTest, SingleGesture) {
bool finished;
scoped_ptr<MockSyntheticGesture> gesture(
new MockSyntheticGesture(&finished, 3));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
EXPECT_TRUE(finished);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
}
TEST_F(SyntheticGestureControllerTest, GestureFailed) {
@@ -407,12 +447,12 @@ TEST_F(SyntheticGestureControllerTest, GestureFailed) {
bool finished;
scoped_ptr<MockSyntheticGesture> gesture(
new MockSyntheticGesture(&finished, 0));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
EXPECT_TRUE(finished);
- EXPECT_EQ(1, target_->num_failure());
- EXPECT_EQ(0, target_->num_success());
+ EXPECT_EQ(1, num_failure_);
+ EXPECT_EQ(0, num_success_);
}
TEST_F(SyntheticGestureControllerTest, SuccessiveGestures) {
@@ -425,20 +465,20 @@ TEST_F(SyntheticGestureControllerTest, SuccessiveGestures) {
new MockSyntheticGesture(&finished_2, 4));
// Queue first gesture and wait for it to finish
- controller_->QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
EXPECT_TRUE(finished_1);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
// Queue second gesture.
- controller_->QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
EXPECT_TRUE(finished_2);
- EXPECT_EQ(2, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(2, num_success_);
+ EXPECT_EQ(0, num_failure_);
}
TEST_F(SyntheticGestureControllerTest, TwoGesturesInFlight) {
@@ -450,15 +490,46 @@ TEST_F(SyntheticGestureControllerTest, TwoGesturesInFlight) {
scoped_ptr<MockSyntheticGesture> gesture_2(
new MockSyntheticGesture(&finished_2, 4));
- controller_->QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>());
- controller_->QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
EXPECT_TRUE(finished_1);
EXPECT_TRUE(finished_2);
- EXPECT_EQ(2, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(2, num_success_);
+ EXPECT_EQ(0, num_failure_);
+}
+
+TEST_F(SyntheticGestureControllerTest, GestureCompletedOnDidFlushInput) {
+ CreateControllerAndTarget<MockSyntheticGestureTarget>();
+
+ bool finished_1, finished_2;
+ scoped_ptr<MockSyntheticGesture> gesture_1(
+ new MockSyntheticGesture(&finished_1, 2));
+ scoped_ptr<MockSyntheticGesture> gesture_2(
+ new MockSyntheticGesture(&finished_2, 4));
+
+ QueueSyntheticGesture(gesture_1.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture_2.PassAs<SyntheticGesture>());
+
+ while (target_->flush_requested()) {
+ target_->ClearFlushRequest();
+ time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
+ controller_->Flush(time_);
+ }
+ EXPECT_EQ(0, num_success_);
+ controller_->OnDidFlushInput();
+ EXPECT_EQ(1, num_success_);
+
+ while (target_->flush_requested()) {
+ target_->ClearFlushRequest();
+ time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
+ controller_->Flush(time_);
+ }
+ EXPECT_EQ(1, num_success_);
+ controller_->OnDidFlushInput();
+ EXPECT_EQ(2, num_success_);
}
gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector,
@@ -480,51 +551,59 @@ gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector,
return gfx::Vector2d(x, y);
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchVertical) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(0, 123);
params.anchor.SetPoint(89, 32);
+ params.distances.push_back(gfx::Vector2d(0, 123));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(AddTouchSlopToVector(params.distance, target_),
- smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ // TODO(dominikg): Remove adjustment when crbug.com/332418 is fixed.
+ EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
+ scroll_target->start_to_end_distance() - gfx::Vector2dF(0, 0.001f));
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchHorizontal) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(-234, 0);
params.anchor.SetPoint(12, -23);
+ params.distances.push_back(gfx::Vector2d(-234, 0));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(AddTouchSlopToVector(params.distance, target_),
- smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ // TODO(dominikg): Use vector comparison when crbug.com/332418 is fixed.
+ //EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
+ // scroll_target->start_to_end_distance());
+ EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_).x(),
+ scroll_target->start_to_end_distance().x());
+ EXPECT_LT(AddTouchSlopToVector(params.distances[0], target_).y(),
+ scroll_target->start_to_end_distance().y());
+ EXPECT_GE(AddTouchSlopToVector(params.distances[0], target_).y(),
+ scroll_target->start_to_end_distance().y() - 0.001f);
}
-void CheckIsWithinRange(float scroll_distance,
- int target_distance,
- SyntheticGestureTarget* target) {
+void CheckIsWithinRangeSingle(float scroll_distance,
+ int target_distance,
+ SyntheticGestureTarget* target) {
if (target_distance > 0) {
EXPECT_LE(target_distance, scroll_distance);
EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
@@ -534,168 +613,289 @@ void CheckIsWithinRange(float scroll_distance,
}
}
-void CheckScrollDistanceIsWithinRange(const gfx::Vector2dF& scroll_distance,
- const gfx::Vector2d& target_distance,
- SyntheticGestureTarget* target) {
- CheckIsWithinRange(scroll_distance.x(), target_distance.x(), target);
- CheckIsWithinRange(scroll_distance.y(), target_distance.y(), target);
+void CheckSingleScrollDistanceIsWithinRange(
+ const gfx::Vector2dF& scroll_distance,
+ const gfx::Vector2d& target_distance,
+ SyntheticGestureTarget* target) {
+ CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target);
+ CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target);
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchDiagonal) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(413, -83);
params.anchor.SetPoint(0, 7);
+ params.distances.push_back(gfx::Vector2d(413, -83));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- CheckScrollDistanceIsWithinRange(
- smooth_scroll_target->scroll_distance(), params.distance, target_);
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ CheckSingleScrollDistanceIsWithinRange(
+ scroll_target->start_to_end_distance(), params.distances[0], target_);
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchLongStop) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
// Create a smooth scroll with a short distance and set the pointer assumed
// stopped time high, so that the stopping should dominate the time the
// gesture is active.
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(21, -12);
- params.prevent_fling = true;
params.anchor.SetPoint(-98, -23);
+ params.distances.push_back(gfx::Vector2d(21, -12));
+ params.prevent_fling = true;
target_->set_pointer_assumed_stopped_time_ms(543);
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- CheckScrollDistanceIsWithinRange(
- smooth_scroll_target->scroll_distance(), params.distance, target_);
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ CheckSingleScrollDistanceIsWithinRange(
+ scroll_target->start_to_end_distance(), params.distances[0], target_);
EXPECT_GE(GetTotalTime(), target_->PointerAssumedStoppedTime());
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchFling) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
// Create a smooth scroll with a short distance and set the pointer assumed
// stopped time high. Disable 'prevent_fling' and check that the gesture
// finishes without waiting before it stops.
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(-43, 19);
- params.prevent_fling = false;
params.anchor.SetPoint(-89, 78);
+ params.distances.push_back(gfx::Vector2d(-43, 19));
+ params.prevent_fling = false;
target_->set_pointer_assumed_stopped_time_ms(543);
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- CheckScrollDistanceIsWithinRange(
- smooth_scroll_target->scroll_distance(), params.distance, target_);
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ CheckSingleScrollDistanceIsWithinRange(
+ scroll_target->start_to_end_distance(), params.distances[0], target_);
EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime());
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureTouchZeroDistance) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollTouchTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.distance = gfx::Vector2d(0, 0);
params.anchor.SetPoint(-32, 43);
+ params.distances.push_back(gfx::Vector2d(0, 0));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(gfx::Vector2dF(0, 0), smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance());
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureMouseVertical) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollMouseTarget>();
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.distance = gfx::Vector2d(0, -234);
params.anchor.SetPoint(432, 89);
+ params.distances.push_back(gfx::Vector2d(0, -234));
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ FlushInputUntilComplete();
+
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
+}
+
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
+ params.anchor.SetPoint(90, 12);
+ params.distances.push_back(gfx::Vector2d(345, 0));
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ FlushInputUntilComplete();
+
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
+}
+
+TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
+ params.anchor.SetPoint(90, 12);
+ params.distances.push_back(gfx::Vector2d(-194, 303));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(params.distance, smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureMouseHorizontal) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollMouseTarget>();
+TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.distance = gfx::Vector2d(345, 0);
params.anchor.SetPoint(90, 12);
+ params.distances.push_back(gfx::Vector2d(-129, 212));
+ params.distances.push_back(gfx::Vector2d(8, -9));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(params.distance, smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(params.distances[0] + params.distances[1],
+ scroll_target->start_to_end_distance());
}
-TEST_F(SyntheticGestureControllerTest, SmoothScrollGestureMouseDiagonal) {
- CreateControllerAndTarget<MockSyntheticSmoothScrollMouseTarget>();
+TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.distance = gfx::Vector2d(-194, 303);
params.anchor.SetPoint(90, 12);
+ params.distances.push_back(gfx::Vector2d(-129, 0));
+ params.distances.push_back(gfx::Vector2d(79, 0));
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ FlushInputUntilComplete();
+
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ // This check only works for horizontal or vertical scrolls because of
+ // floating point precision issues with diagonal scrolls.
+ EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
+ scroll_target->total_abs_scroll_distance_length());
+ EXPECT_EQ(params.distances[0] + params.distances[1],
+ scroll_target->start_to_end_distance());
+}
+
+void CheckIsWithinRangeMulti(float scroll_distance,
+ int target_distance,
+ SyntheticGestureTarget* target) {
+ if (target_distance > 0) {
+ EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
+ EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
+ } else {
+ EXPECT_LE(scroll_distance, target_distance + target->GetTouchSlopInDips());
+ EXPECT_GE(scroll_distance, target_distance - target->GetTouchSlopInDips());
+ }
+}
+
+void CheckMultiScrollDistanceIsWithinRange(
+ const gfx::Vector2dF& scroll_distance,
+ const gfx::Vector2d& target_distance,
+ SyntheticGestureTarget* target) {
+ CheckIsWithinRangeMulti(scroll_distance.x(), target_distance.x(), target);
+ CheckIsWithinRangeMulti(scroll_distance.y(), target_distance.y(), target);
+}
+
+TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
+ params.anchor.SetPoint(8, -13);
+ params.distances.push_back(gfx::Vector2d(234, 133));
+ params.distances.push_back(gfx::Vector2d(-9, 78));
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ FlushInputUntilComplete();
+
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ CheckMultiScrollDistanceIsWithinRange(
+ scroll_target->start_to_end_distance(),
+ params.distances[0] + params.distances[1],
+ target_);
+}
+
+TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) {
+ CreateControllerAndTarget<MockScrollTouchTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
+ params.anchor.SetPoint(234, -13);
+ params.distances.push_back(gfx::Vector2d(0, 133));
+ params.distances.push_back(gfx::Vector2d(0, 78));
scoped_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
- MockSyntheticSmoothScrollGestureTarget* smooth_scroll_target =
- static_cast<MockSyntheticSmoothScrollGestureTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
- EXPECT_EQ(params.distance, smooth_scroll_target->scroll_distance());
+ MockScrollGestureTarget* scroll_target =
+ static_cast<MockScrollGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ // TODO(dominikg): Remove adjustment when crbug.com/332418 is fixed.
+ EXPECT_FLOAT_EQ(
+ params.distances[0].Length() + params.distances[1].Length() +
+ target_->GetTouchSlopInDips(),
+ scroll_target->total_abs_scroll_distance_length() - 0.001f);
+ EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1],
+ target_),
+ scroll_target->start_to_end_distance() - gfx::Vector2dF(0, 0.001f));
}
TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) {
@@ -703,22 +903,20 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) {
SyntheticPinchGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.zoom_in = true;
- params.total_num_pixels_covered = 345;
+ params.scale_factor = 2.3f;
params.anchor.SetPoint(54, 89);
scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
MockSyntheticPinchTouchTarget* pinch_target =
static_cast<MockSyntheticPinchTouchTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
EXPECT_EQ(pinch_target->zoom_direction(),
MockSyntheticPinchTouchTarget::ZOOM_IN);
- EXPECT_EQ(params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(),
- pinch_target->total_num_pixels_covered());
+ EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor());
}
TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) {
@@ -726,43 +924,40 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) {
SyntheticPinchGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.zoom_in = false;
- params.total_num_pixels_covered = 456;
+ params.scale_factor = 0.4f;
params.anchor.SetPoint(-12, 93);
scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
MockSyntheticPinchTouchTarget* pinch_target =
static_cast<MockSyntheticPinchTouchTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
EXPECT_EQ(pinch_target->zoom_direction(),
MockSyntheticPinchTouchTarget::ZOOM_OUT);
- EXPECT_EQ(params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(),
- pinch_target->total_num_pixels_covered());
+ EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor());
}
-TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZeroPixelsCovered) {
+TEST_F(SyntheticGestureControllerTest, PinchGestureTouchNoScaling) {
CreateControllerAndTarget<MockSyntheticPinchTouchTarget>();
SyntheticPinchGestureParams params;
params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.zoom_in = true;
- params.total_num_pixels_covered = 0;
+ params.scale_factor = 1.0f;
scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
MockSyntheticPinchTouchTarget* pinch_target =
static_cast<MockSyntheticPinchTouchTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
EXPECT_EQ(pinch_target->zoom_direction(),
MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN);
- EXPECT_EQ(0, pinch_target->total_num_pixels_covered());
+ EXPECT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor());
}
TEST_F(SyntheticGestureControllerTest, TapGestureTouch) {
@@ -774,15 +969,16 @@ TEST_F(SyntheticGestureControllerTest, TapGestureTouch) {
params.position.SetPoint(87, -124);
scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
MockSyntheticTapTouchTarget* tap_target =
static_cast<MockSyntheticTapTouchTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
EXPECT_TRUE(tap_target->GestureFinished());
EXPECT_EQ(tap_target->position(), params.position);
+ EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
EXPECT_GE(GetTotalTime(),
base::TimeDelta::FromMilliseconds(params.duration_ms));
}
@@ -796,15 +992,16 @@ TEST_F(SyntheticGestureControllerTest, TapGestureMouse) {
params.position.SetPoint(98, 123);
scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params));
- controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
+ QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
FlushInputUntilComplete();
MockSyntheticTapMouseTarget* tap_target =
static_cast<MockSyntheticTapMouseTarget*>(target_);
- EXPECT_EQ(1, target_->num_success());
- EXPECT_EQ(0, target_->num_failure());
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
EXPECT_TRUE(tap_target->GestureFinished());
EXPECT_EQ(tap_target->position(), params.position);
+ EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
EXPECT_GE(GetTotalTime(),
base::TimeDelta::FromMilliseconds(params.duration_ms));
}