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..972167d02721ddbee3720a6ac6cfa5235dae989d 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 SyntheticGestureControllerTestUtility { |
Sami
2015/02/20 17:57:07
nit: call this SyntheticGestureControllerTestBase
ssid
2015/02/23 11:40:32
Done.
|
public: |
- SyntheticGestureControllerTest() {} |
- ~SyntheticGestureControllerTest() override {} |
+ SyntheticGestureControllerTestUtility() {} |
+ ~SyntheticGestureControllerTestUtility() {} |
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( |
+ &SyntheticGestureControllerTestUtility::OnSyntheticGestureCompleted, |
base::Unretained(this))); |
} |
@@ -417,6 +444,42 @@ class SyntheticGestureControllerTest : public testing::Test { |
int num_failure_; |
}; |
+class SyntheticGestureControllerTest |
+ : public SyntheticGestureControllerTestUtility, |
+ 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_ = NULL; |
+ time_ = base::TimeTicks(); |
+ } |
+}; |
+ |
+class SyntheticGestureControllerTestWithParam |
+ : public SyntheticGestureControllerTestUtility, |
+ 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_ = NULL; |
+ time_ = base::TimeTicks(); |
+ } |
+}; |
+ |
TEST_F(SyntheticGestureControllerTest, SingleGesture) { |
CreateControllerAndTarget<MockSyntheticGestureTarget>(); |
@@ -543,46 +606,84 @@ gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector, |
return gfx::Vector2d(x, y); |
} |
-TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) { |
- CreateControllerAndTarget<MockScrollTouchTarget>(); |
+scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams( |
+ SyntheticSmoothScrollGestureParams params, |
Sami
2015/02/20 17:57:07
This shouldn't take scroll parameters since we're
ssid
2015/02/20 18:48:16
struct for move parameters sounds better because,
ssid
2015/02/23 11:40:32
Added a class for move gesture params. PTAL.
|
+ SyntheticSmoothMoveGesture::InputType input_type) { |
+ std::vector<gfx::Vector2dF> distances_float; |
+ for (uint64 i = 0; i < params.distances.size(); i++) |
+ distances_float.push_back(params.distances[i]); |
+ |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture( |
+ input_type, params.anchor, distances_float, params.speed_in_pixels_s, |
+ params.prevent_fling)); |
+ return gesture; |
+} |
+ |
+TEST_P(SyntheticGestureControllerTestWithParam, |
+ SingleMoveGestureTouchVertical) { |
+ CreateControllerAndTarget<MockMoveTouchTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type; |
+ if (GetParam() == TOUCH_SCROLL) { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
+ } else { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT; |
+ } |
params.anchor.SetPoint(89, 32); |
params.distances.push_back(gfx::Vector2d(0, 123)); |
+ params.speed_in_pixels_s = 800; |
Sami
2015/02/20 17:57:07
Why this change?
ssid
2015/02/20 18:48:16
Some tests were failing because this wasn't set an
|
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
picksi
2015/02/20 16:34:11
Calling this 'distance' and the param 'distances'
|
+ } else { |
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
+ } |
} |
+INSTANTIATE_TEST_CASE_P(Single, |
+ SyntheticGestureControllerTestWithParam, |
+ testing::Values(TOUCH_SCROLL, TOUCH_DRAG)); |
-TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchHorizontal) { |
- CreateControllerAndTarget<MockScrollTouchTarget>(); |
+TEST_P(SyntheticGestureControllerTestWithParam, |
+ SingleScrollGestureTouchHorizontal) { |
+ CreateControllerAndTarget<MockMoveTouchTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type; |
+ if (GetParam() == TOUCH_SCROLL) { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
+ } else { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT; |
+ } |
params.anchor.SetPoint(12, -23); |
params.distances.push_back(gfx::Vector2d(-234, 0)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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_); |
+ if (GetParam() == TOUCH_SCROLL) { |
EXPECT_EQ(AddTouchSlopToVector(params.distances[0], target_), |
Sami
2015/02/20 17:57:06
Indenting seems off here. "git cl format" should f
ssid
2015/02/20 18:48:16
Git cl format didn't fix this because no change=!
|
scroll_target->start_to_end_distance()); |
+ } else { |
+ EXPECT_EQ(params.distances[0], scroll_target->start_to_end_distance()); |
+ } |
} |
void CheckIsWithinRangeSingle(float scroll_distance, |
@@ -606,20 +707,22 @@ void CheckSingleScrollDistanceIsWithinRange( |
} |
TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchDiagonal) { |
- CreateControllerAndTarget<MockScrollTouchTarget>(); |
+ CreateControllerAndTarget<MockMoveTouchTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
params.anchor.SetPoint(0, 7); |
params.distances.push_back(gfx::Vector2d(413, -83)); |
+ params.speed_in_pixels_s = 800; |
picksi
2015/02/20 16:34:11
The vertical, horizontal, diagonal and zero tests
|
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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 +730,28 @@ 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; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
params.anchor.SetPoint(-98, -23); |
params.distances.push_back(gfx::Vector2d(21, -12)); |
params.prevent_fling = true; |
+ params.speed_in_pixels_s = 800; |
target_->set_pointer_assumed_stopped_time_ms(543); |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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 +760,28 @@ 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; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
params.anchor.SetPoint(-89, 78); |
params.distances.push_back(gfx::Vector2d(-43, 19)); |
params.prevent_fling = false; |
+ params.speed_in_pixels_s = 800; |
target_->set_pointer_assumed_stopped_time_ms(543); |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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 +789,28 @@ 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; |
+ SyntheticSmoothMoveGesture::InputType input_type; |
+ if (GetParam() == TOUCH_SCROLL) { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
+ } else { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT; |
+ } |
params.anchor.SetPoint(-32, 43); |
params.distances.push_back(gfx::Vector2d(0, 0)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
@@ -706,17 +820,19 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseVertical) { |
CreateControllerAndTarget<MockScrollMouseTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT; |
params.anchor.SetPoint(432, 89); |
params.distances.push_back(gfx::Vector2d(0, -234)); |
+ params.speed_in_pixels_s = 800; |
picksi
2015/02/20 16:34:10
Could this function be part of the other tests by
ssid
2015/02/23 11:40:32
I think there is very less common code for this to
|
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
@@ -726,17 +842,19 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseHorizontal) { |
CreateControllerAndTarget<MockScrollMouseTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT; |
params.anchor.SetPoint(90, 12); |
params.distances.push_back(gfx::Vector2d(345, 0)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
@@ -746,17 +864,19 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureMouseDiagonal) { |
CreateControllerAndTarget<MockScrollMouseTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT; |
params.anchor.SetPoint(90, 12); |
params.distances.push_back(gfx::Vector2d(-194, 303)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
@@ -766,18 +886,20 @@ TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouse) { |
CreateControllerAndTarget<MockScrollMouseTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT; |
params.anchor.SetPoint(90, 12); |
params.distances.push_back(gfx::Vector2d(-129, 212)); |
params.distances.push_back(gfx::Vector2d(8, -9)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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], |
@@ -788,24 +910,26 @@ TEST_F(SyntheticGestureControllerTest, MultiScrollGestureMouseHorizontal) { |
CreateControllerAndTarget<MockScrollMouseTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_WHEEL_INPUT; |
params.anchor.SetPoint(90, 12); |
params.distances.push_back(gfx::Vector2d(-129, 0)); |
params.distances.push_back(gfx::Vector2d(79, 0)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
picksi
2015/02/20 16:34:10
The MOUSE_WHEEL_INPUT types are all identical too,
ssid
2015/02/23 11:40:32
The change in test structure can be kept for next
|
} |
@@ -831,21 +955,23 @@ void CheckMultiScrollDistanceIsWithinRange( |
} |
TEST_F(SyntheticGestureControllerTest, MultiScrollGestureTouch) { |
- CreateControllerAndTarget<MockScrollTouchTarget>(); |
+ CreateControllerAndTarget<MockMoveTouchTarget>(); |
SyntheticSmoothScrollGestureParams params; |
- params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
params.anchor.SetPoint(8, -13); |
params.distances.push_back(gfx::Vector2d(234, 133)); |
params.distances.push_back(gfx::Vector2d(-9, 78)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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 +980,215 @@ 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; |
+ SyntheticSmoothMoveGesture::InputType input_type; |
+ if (GetParam() == TOUCH_SCROLL) { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_SCROLL_INPUT; |
+ } else { |
+ input_type = SyntheticSmoothMoveGesture::TOUCH_DRAG_INPUT; |
+ } |
params.anchor.SetPoint(234, -13); |
params.distances.push_back(gfx::Vector2d(0, 133)); |
params.distances.push_back(gfx::Vector2d(0, 78)); |
+ params.speed_in_pixels_s = 800; |
- scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
- new SyntheticSmoothScrollGesture(params)); |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
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()); |
+ } |
+} |
+ |
+scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams( |
+ SyntheticSmoothDragGestureParams params, |
+ SyntheticSmoothMoveGesture::InputType input_type) { |
+ bool prevent_fling = true; |
+ |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture(new SyntheticSmoothMoveGesture( |
+ input_type, params.start_point, params.distances, |
+ params.speed_in_pixels_s, prevent_fling)); |
+ return gesture; |
+} |
+ |
+TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseDiagonal) { |
+ CreateControllerAndTarget<MockDragMouseTarget>(); |
+ |
+ SyntheticSmoothDragGestureParams params; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT; |
+ params.start_point.SetPoint(0, 7); |
+ params.distances.push_back(gfx::Vector2d(413, -83)); |
+ params.speed_in_pixels_s = 800; |
+ |
picksi
2015/02/20 16:34:11
Aren't these MOUSE_DRAG_INPUT tests the same as th
Sami
2015/02/20 17:57:07
Yeah, this is starting to look like too much dupli
ssid
2015/02/20 18:48:16
I will reduce the last 4 tests to just check if ty
|
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
+ 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>(); |
+ |
+ SyntheticSmoothDragGestureParams params; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT; |
+ params.start_point.SetPoint(-32, 43); |
+ params.distances.push_back(gfx::Vector2d(0, 0)); |
+ params.speed_in_pixels_s = 800; |
+ |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
+ 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>(); |
+ |
+ SyntheticSmoothDragGestureParams params; |
+ SyntheticSmoothMoveGesture::InputType input_type = |
+ SyntheticSmoothMoveGesture::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)); |
+ params.speed_in_pixels_s = 800; |
+ |
+ scoped_ptr<SyntheticSmoothMoveGesture> gesture = |
+ CreateMoveGestureUsingParams(params, input_type); |
+ 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, |
+ SingleDragGestureMouseUsingDragGestureObject) { |
Sami
2015/02/20 17:57:07
I'm not sure what the name of this test means.
ssid
2015/02/23 11:40:32
Changed the names.
|
+ CreateControllerAndTarget<MockDragMouseTarget>(); |
+ |
+ SyntheticSmoothDragGestureParams params; |
+ params.gesture_source_type = SyntheticGestureParams::MOUSE_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)); |
+ QueueSyntheticGesture(gesture.Pass()); |
+ FlushInputUntilComplete(); |
+ |
+ MockMoveGestureTarget* drag_target = |
+ static_cast<MockMoveGestureTarget*>(target_); |
+ EXPECT_EQ(1, num_success_); |
+ EXPECT_EQ(0, num_failure_); |
+ EXPECT_EQ(params.distances[0], drag_target->start_to_end_distance()); |
+} |
+ |
+TEST_F(SyntheticGestureControllerTest, |
+ SingleMoveGestureTouchVerticalUsingScrollObject) { |
+ CreateControllerAndTarget<MockMoveTouchTarget>(); |
+ |
+ SyntheticSmoothScrollGestureParams params; |
+ params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
+ params.anchor.SetPoint(89, 32); |
+ params.distances.push_back(gfx::Vector2d(0, 123)); |
+ params.speed_in_pixels_s = 800; |
+ |
+ scoped_ptr<SyntheticSmoothScrollGesture> gesture( |
+ new SyntheticSmoothScrollGesture(params)); |
+ |
+ QueueSyntheticGesture(gesture.Pass()); |
+ FlushInputUntilComplete(); |
+ |
+ 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()); |
+} |
+ |
+TEST_F(SyntheticGestureControllerTest, |
+ SingleMoveGestureTouchVerticalUsingDragObject) { |
+ 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)); |
+ |
+ QueueSyntheticGesture(gesture.Pass()); |
+ FlushInputUntilComplete(); |
+ |
+ 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()); |
+} |
+ |
+TEST_F(SyntheticGestureControllerTest, |
+ SingleScrollGestureMouseVerticalUsingScrollObject) { |
+ 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)); |
+ QueueSyntheticGesture(gesture.Pass()); |
+ FlushInputUntilComplete(); |
+ |
+ 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()); |
} |
TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |