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

Unified Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 929333002: Adding synthetic touch/mouse drag [Part1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
diff --git a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
index 84f04f6ff6afd44adf657a3fed64043e785db857..5d84b4b48fcc63caeeaea3c883af0452f9dbfdad 100644
--- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
+++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc
@@ -9,10 +9,13 @@
#include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target.h"
#include "content/browser/renderer_host/input/synthetic_pinch_gesture.h"
+#include "content/browser/renderer_host/input/synthetic_smooth_drag_gesture.h"
+#include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h"
#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/synthetic_pinch_gesture_params.h"
+#include "content/common/input/synthetic_smooth_drag_gesture_params.h"
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
#include "content/common/input/synthetic_tap_gesture_params.h"
#include "content/public/test/mock_render_process_host.h"
@@ -39,6 +42,8 @@ const int kPointerAssumedStoppedTimeMs = 43;
const float kTouchSlopInDips = 7.0f;
const float kMinScalingSpanInDips = 27.5f;
+enum TouchGestureType { TOUCH_SCROLL, TOUCH_DRAG };
+
class MockSyntheticGesture : public SyntheticGesture {
public:
MockSyntheticGesture(bool* finished, int num_steps)
@@ -110,24 +115,24 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget {
int pointer_assumed_stopped_time_ms_;
};
-class MockScrollGestureTarget : public MockSyntheticGestureTarget {
+class MockMoveGestureTarget : public MockSyntheticGestureTarget {
public:
- MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {}
- ~MockScrollGestureTarget() override {}
+ MockMoveGestureTarget() : total_abs_move_distance_length_(0) {}
+ ~MockMoveGestureTarget() override {}
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_;
+ float total_abs_move_distance_length() const {
+ return total_abs_move_distance_length_;
}
protected:
gfx::Vector2dF start_to_end_distance_;
- float total_abs_scroll_distance_length_;
+ float total_abs_move_distance_length_;
};
-class MockScrollMouseTarget : public MockScrollGestureTarget {
+class MockScrollMouseTarget : public MockMoveGestureTarget {
public:
MockScrollMouseTarget() {}
~MockScrollMouseTarget() override {}
@@ -138,14 +143,14 @@ class MockScrollMouseTarget : public MockScrollGestureTarget {
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();
+ total_abs_move_distance_length_ += delta.Length();
}
};
-class MockScrollTouchTarget : public MockScrollGestureTarget {
+class MockMoveTouchTarget : public MockMoveGestureTarget {
public:
- MockScrollTouchTarget() : started_(false) {}
- ~MockScrollTouchTarget() override {}
+ MockMoveTouchTarget() : started_(false) {}
+ ~MockMoveTouchTarget() override {}
void DispatchInputEventToPlatform(const WebInputEvent& event) override {
ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
@@ -165,7 +170,7 @@ class MockScrollTouchTarget : public MockScrollGestureTarget {
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();
+ total_abs_move_distance_length_ += delta.Length();
if (touch_event.type == WebInputEvent::TouchEnd)
start_to_end_distance_ = touch_point - start_;
@@ -180,6 +185,39 @@ class MockScrollTouchTarget : public MockScrollGestureTarget {
bool started_;
};
+class MockDragMouseTarget : public MockMoveGestureTarget {
+ public:
+ MockDragMouseTarget() : started_(false) {}
+ ~MockDragMouseTarget() override {}
+
+ void DispatchInputEventToPlatform(const WebInputEvent& event) override {
+ ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
+ const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
+ if (!started_) {
+ EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
+ EXPECT_EQ(mouse_event.clickCount, 1);
+ EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown);
+ start_.SetPoint(mouse_event.x, mouse_event.y);
+ last_mouse_point_ = start_;
+ started_ = true;
+ } else {
+ EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
+ ASSERT_NE(mouse_event.type, WebInputEvent::MouseDown);
+
+ gfx::PointF mouse_point(mouse_event.x, mouse_event.y);
+ gfx::Vector2dF delta = mouse_point - last_mouse_point_;
+ total_abs_move_distance_length_ += delta.Length();
+ if (mouse_event.type == WebInputEvent::MouseUp)
+ start_to_end_distance_ = mouse_point - start_;
+ last_mouse_point_ = mouse_point;
+ }
+ }
+
+ private:
+ bool started_;
+ gfx::PointF start_, last_mouse_point_;
+};
+
class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget {
public:
enum ZoomDirection {
@@ -356,10 +394,10 @@ class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
}
};
-class SyntheticGestureControllerTest : public testing::Test {
+class SyntheticGestureControllerTestBase {
public:
- SyntheticGestureControllerTest() {}
- ~SyntheticGestureControllerTest() override {}
+ SyntheticGestureControllerTestBase() {}
+ ~SyntheticGestureControllerTestBase() {}
protected:
template<typename MockGestureTarget>
@@ -369,22 +407,11 @@ class SyntheticGestureControllerTest : public testing::Test {
scoped_ptr<SyntheticGestureTarget>(target_)));
}
- void SetUp() override {
- start_time_ = base::TimeTicks::Now();
- time_ = start_time_;
- num_success_ = 0;
- num_failure_ = 0;
- }
-
- void TearDown() override {
- controller_.reset();
- target_ = NULL;
- time_ = base::TimeTicks();
- }
-
void QueueSyntheticGesture(scoped_ptr<SyntheticGesture> gesture) {
- controller_->QueueSyntheticGesture(gesture.Pass(),
- base::Bind(&SyntheticGestureControllerTest::OnSyntheticGestureCompleted,
+ controller_->QueueSyntheticGesture(
+ gesture.Pass(),
+ base::Bind(
+ &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted,
base::Unretained(this)));
}
@@ -417,6 +444,42 @@ class SyntheticGestureControllerTest : public testing::Test {
int num_failure_;
};
+class SyntheticGestureControllerTest
+ : public SyntheticGestureControllerTestBase,
+ public testing::Test {
+ protected:
+ void SetUp() override {
+ start_time_ = base::TimeTicks::Now();
+ time_ = start_time_;
+ num_success_ = 0;
+ num_failure_ = 0;
+ }
+
+ void TearDown() override {
+ controller_.reset();
+ target_ = nullptr;
+ time_ = base::TimeTicks();
+ }
+};
+
+class SyntheticGestureControllerTestWithParam
+ : public SyntheticGestureControllerTestBase,
+ public testing::TestWithParam<bool> {
+ protected:
+ void SetUp() override {
+ start_time_ = base::TimeTicks::Now();
+ time_ = start_time_;
+ num_success_ = 0;
+ num_failure_ = 0;
+ }
+
+ void TearDown() override {
+ controller_.reset();
+ target_ = nullptr;
+ time_ = base::TimeTicks();
+ }
+};
+
TEST_F(SyntheticGestureControllerTest, SingleGesture) {
CreateControllerAndTarget<MockSyntheticGestureTarget>();
@@ -524,7 +587,7 @@ TEST_F(SyntheticGestureControllerTest, GestureCompletedOnDidFlushInput) {
EXPECT_EQ(2, num_success_);
}
-gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector,
+gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2dF& vector,
SyntheticGestureTarget* target) {
const int kTouchSlop = target->GetTouchSlopInDips();
@@ -543,46 +606,62 @@ gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector,
return gfx::Vector2d(x, y);
}
-TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+TEST_P(SyntheticGestureControllerTestWithParam,
+ SingleMoveGestureTouchVertical) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(89, 32);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ if (GetParam() == TOUCH_DRAG) {
+ params.add_slop = false;
+ }
+ params.start_point.SetPoint(89, 32);
params.distances.push_back(gfx::Vector2d(0, 123));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
- EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
- scroll_target->start_to_end_distance());
+ if (GetParam() == TOUCH_SCROLL) {
+ EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
+ scroll_target->start_to_end_distance());
+ } else {
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
+ }
}
-TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+TEST_P(SyntheticGestureControllerTestWithParam,
+ SingleScrollGestureTouchHorizontal) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(12, -23);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ if (GetParam() == TOUCH_DRAG) {
+ params.add_slop = false;
+ }
+ params.start_point.SetPoint(12, -23);
params.distances.push_back(gfx::Vector2d(-234, 0));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
- EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
- scroll_target->start_to_end_distance());
+ if (GetParam() == TOUCH_SCROLL) {
+ EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_),
+ scroll_target->start_to_end_distance());
+ } else {
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
+ }
}
void CheckIsWithinRangeSingle(float scroll_distance,
@@ -599,27 +678,27 @@ void CheckIsWithinRangeSingle(float scroll_distance,
void CheckSingleScrollDistanceIsWithinRange(
const gfx::Vector2dF& scroll_distance,
- const gfx::Vector2d& target_distance,
+ const gfx::Vector2dF& target_distance,
SyntheticGestureTarget* target) {
CheckIsWithinRangeSingle(scroll_distance.x(), target_distance.x(), target);
CheckIsWithinRangeSingle(scroll_distance.y(), target_distance.y(), target);
}
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(0, 7);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ params.start_point.SetPoint(0, 7);
params.distances.push_back(gfx::Vector2d(413, -83));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
CheckSingleScrollDistanceIsWithinRange(
@@ -627,26 +706,25 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) {
}
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+ CreateControllerAndTarget<MockMoveTouchTarget>();
// 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.anchor.SetPoint(-98, -23);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
CheckSingleScrollDistanceIsWithinRange(
@@ -655,26 +733,26 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchLongStop) {
}
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+ CreateControllerAndTarget<MockMoveTouchTarget>();
// 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.anchor.SetPoint(-89, 78);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
CheckSingleScrollDistanceIsWithinRange(
@@ -682,21 +760,25 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) {
EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime());
}
-TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+TEST_P(SyntheticGestureControllerTestWithParam,
+ SingleScrollGestureTouchZeroDistance) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(-32, 43);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ if (GetParam() == TOUCH_DRAG) {
+ params.add_slop = false;
+ }
+ params.start_point.SetPoint(-32, 43);
params.distances.push_back(gfx::Vector2d(0, 0));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_target->start_to_end_distance());
@@ -705,18 +787,18 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) {
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) {
CreateControllerAndTarget<MockScrollMouseTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.anchor.SetPoint(432, 89);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT;
+ params.start_point.SetPoint(432, 89);
params.distances.push_back(gfx::Vector2d(0, -234));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
@@ -725,18 +807,18 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) {
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) {
CreateControllerAndTarget<MockScrollMouseTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.anchor.SetPoint(90, 12);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT;
+ params.start_point.SetPoint(90, 12);
params.distances.push_back(gfx::Vector2d(345, 0));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
@@ -745,18 +827,18 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) {
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) {
CreateControllerAndTarget<MockScrollMouseTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.anchor.SetPoint(90, 12);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT;
+ params.start_point.SetPoint(90, 12);
params.distances.push_back(gfx::Vector2d(-194, 303));
- scoped_ptr<SyntheticSmoothScrollGesture> gesture(
- new SyntheticSmoothScrollGesture(params));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance());
@@ -765,19 +847,19 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) {
TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) {
CreateControllerAndTarget<MockScrollMouseTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.anchor.SetPoint(90, 12);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT;
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
EXPECT_EQ(params.distances[0] + params.distances[1],
@@ -787,25 +869,25 @@ TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) {
TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) {
CreateControllerAndTarget<MockScrollMouseTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
- params.anchor.SetPoint(90, 12);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_WHEEL_INPUT;
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(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());
+ scroll_target->total_abs_move_distance_length());
EXPECT_EQ(params.distances[0] + params.distances[1],
scroll_target->start_to_end_distance());
}
@@ -824,28 +906,28 @@ void CheckIsWithinRangeMulti(float scroll_distance,
void CheckMultiScrollDistanceIsWithinRange(
const gfx::Vector2dF& scroll_distance,
- const gfx::Vector2d& target_distance,
+ const gfx::Vector2dF& 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>();
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(8, -13);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
CheckMultiScrollDistanceIsWithinRange(
@@ -854,31 +936,168 @@ TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) {
target_);
}
-TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouchVertical) {
- CreateControllerAndTarget<MockScrollTouchTarget>();
+TEST_P(SyntheticGestureControllerTestWithParam,
+ MultiScrollGestureTouchVertical) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
- SyntheticSmoothScrollGestureParams params;
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
- params.anchor.SetPoint(234, -13);
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::TOUCH_INPUT;
+ if (GetParam() == TOUCH_DRAG) {
+ params.add_slop = false;
+ }
+ params.start_point.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));
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
QueueSyntheticGesture(gesture.Pass());
FlushInputUntilComplete();
- MockScrollGestureTarget* scroll_target =
- static_cast<MockScrollGestureTarget*>(target_);
+ MockMoveGestureTarget* scroll_target =
+ static_cast<MockMoveGestureTarget*>(target_);
EXPECT_EQ(1, num_success_);
EXPECT_EQ(0, num_failure_);
- EXPECT_FLOAT_EQ(
- params.distances[0].Length() + params.distances[1].Length() +
- target_->GetTouchSlopInDips(),
- scroll_target->total_abs_scroll_distance_length());
+ if (GetParam() == TOUCH_SCROLL) {
+ EXPECT_FLOAT_EQ(params.distances[0].Length() +
+ params.distances[1].Length() +
+ target_->GetTouchSlopInDips(),
+ scroll_target->total_abs_move_distance_length());
EXPECT_EQ(AddTouchSlopToVector(params.distances[0] + params.distances[1],
target_),
scroll_target->start_to_end_distance());
+ } else {
+ EXPECT_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(),
+ scroll_target->total_abs_move_distance_length());
+ EXPECT_EQ(params.distances[0] + params.distances[1],
+ scroll_target->start_to_end_distance());
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(Single,
+ SyntheticGestureControllerTestWithParam,
+ testing::Values(TOUCH_SCROLL, TOUCH_DRAG));
+
+TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) {
+ CreateControllerAndTarget<MockDragMouseTarget>();
+
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT;
+ params.start_point.SetPoint(0, 7);
+ params.distances.push_back(gfx::Vector2d(413, -83));
+
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
+ QueueSyntheticGesture(gesture.Pass());
+ FlushInputUntilComplete();
+
+ MockMoveGestureTarget* drag_target =
+ static_cast<MockMoveGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(drag_target->start_to_end_distance(), params.distances[0]);
+}
+
+TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseZeroDistance) {
+ CreateControllerAndTarget<MockDragMouseTarget>();
+
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT;
+ params.start_point.SetPoint(-32, 43);
+ params.distances.push_back(gfx::Vector2d(0, 0));
+
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
+ QueueSyntheticGesture(gesture.Pass());
+ FlushInputUntilComplete();
+
+ MockMoveGestureTarget* drag_target =
+ static_cast<MockMoveGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(gfx::Vector2dF(0, 0), drag_target->start_to_end_distance());
+}
+
+TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouse) {
+ CreateControllerAndTarget<MockDragMouseTarget>();
+
+ SyntheticSmoothMoveGestureParams params;
+ params.input_type = SyntheticSmoothMoveGestureParams::MOUSE_DRAG_INPUT;
+ params.start_point.SetPoint(8, -13);
+ params.distances.push_back(gfx::Vector2d(234, 133));
+ params.distances.push_back(gfx::Vector2d(-9, 78));
+
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(
+ new SyntheticSmoothMoveGesture(params));
+ QueueSyntheticGesture(gesture.Pass());
+ FlushInputUntilComplete();
+
+ MockMoveGestureTarget* drag_target =
+ static_cast<MockMoveGestureTarget*>(target_);
+ EXPECT_EQ(1, num_success_);
+ EXPECT_EQ(0, num_failure_);
+ EXPECT_EQ(drag_target->start_to_end_distance(),
+ params.distances[0] + params.distances[1]);
+}
+
+TEST_F(SyntheticGestureControllerTest,
+ SyntheticSmoothDragTestUsingSingleMouseDrag) {
+ CreateControllerAndTarget<MockDragMouseTarget>();
+
+ SyntheticSmoothDragGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
+ params.distances.push_back(gfx::Vector2d(234, 133));
+ params.speed_in_pixels_s = 800;
+
+ scoped_ptr<SyntheticSmoothDragGesture> gesture(
+ new SyntheticSmoothDragGesture(params));
+ const base::TimeTicks timestamp;
+ gesture->ForwardInputEvents(timestamp, target_);
+}
+
+TEST_F(SyntheticGestureControllerTest,
+ SyntheticSmoothDragTestUsingSingleTouchDrag) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
+
+ SyntheticSmoothDragGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
+ params.start_point.SetPoint(89, 32);
+ params.distances.push_back(gfx::Vector2d(0, 123));
+ params.speed_in_pixels_s = 800;
+
+ scoped_ptr<SyntheticSmoothDragGesture> gesture(
+ new SyntheticSmoothDragGesture(params));
+ const base::TimeTicks timestamp;
+ gesture->ForwardInputEvents(timestamp, target_);
+}
+
+TEST_F(SyntheticGestureControllerTest,
+ SyntheticSmoothScrollTestUsingSingleTouchScroll) {
+ CreateControllerAndTarget<MockMoveTouchTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ const base::TimeTicks timestamp;
+ gesture->ForwardInputEvents(timestamp, target_);
+}
+
+TEST_F(SyntheticGestureControllerTest,
+ SyntheticSmoothScrollTestUsingSingleMouseScroll) {
+ CreateControllerAndTarget<MockScrollMouseTarget>();
+
+ SyntheticSmoothScrollGestureParams params;
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
+ params.anchor.SetPoint(432, 89);
+ params.distances.push_back(gfx::Vector2d(0, -234));
+ params.speed_in_pixels_s = 800;
+
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture(
+ new SyntheticSmoothScrollGesture(params));
+ const base::TimeTicks timestamp;
+ gesture->ForwardInputEvents(timestamp, target_);
}
TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) {

Powered by Google App Engine
This is Rietveld 408576698