Chromium Code Reviews| 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..d4b0e0e9516aa19ad169b839213233997123e5f4 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" |
| @@ -110,24 +113,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 +141,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 +168,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 +183,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 +392,10 @@ class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { |
| } |
| }; |
| -class SyntheticGestureControllerTest : public testing::Test { |
| +class SyntheticGestureControllerTestUtility { |
| public: |
| - SyntheticGestureControllerTest() {} |
| - ~SyntheticGestureControllerTest() override {} |
| + SyntheticGestureControllerTestUtility() {} |
| + ~SyntheticGestureControllerTestUtility() {} |
| protected: |
| template<typename MockGestureTarget> |
| @@ -369,22 +405,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 +442,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 +604,82 @@ gfx::Vector2d AddTouchSlopToVector(const gfx::Vector2d& vector, |
| return gfx::Vector2d(x, y); |
| } |
| -TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchVertical) { |
| - CreateControllerAndTarget<MockScrollTouchTarget>(); |
| +scoped_ptr<SyntheticSmoothMoveGesture> CreateMoveGestureUsingParams( |
| + SyntheticSmoothScrollGestureParams params, |
| + 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()) { |
| + 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)); |
| - 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()) { |
| + 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()); |
| + } |
| } |
| +INSTANTIATE_TEST_CASE_P(Single, |
|
ssid
2015/02/20 10:58:56
I am not sure where to place this statement. Hard
|
| + SyntheticGestureControllerTestWithParam, |
| + testing::Values(true, false)); |
| -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()) { |
| + 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)); |
| - 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()) { |
| 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, |
| @@ -606,20 +703,21 @@ 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)); |
| - 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 +725,27 @@ 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; |
| 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 +754,27 @@ 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; |
| 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 +782,27 @@ TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchFling) { |
| EXPECT_LE(GetTotalTime(), target_->PointerAssumedStoppedTime()); |
| } |
| -TEST_F(SyntheticGestureControllerTest, SingleScrollGestureTouchZeroDistance) { |
| - CreateControllerAndTarget<MockScrollTouchTarget>(); |
| +TEST_P(SyntheticGestureControllerTestWithParam, |
|
ssid
2015/02/20 10:58:56
Should I move all the tests under SyntheticGesture
|
| + SingleScrollGestureTouchZeroDistance) { |
| + CreateControllerAndTarget<MockMoveTouchTarget>(); |
| SyntheticSmoothScrollGestureParams params; |
| - params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| + SyntheticSmoothMoveGesture::InputType input_type; |
| + if (GetParam()) { |
| + 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)); |
| - 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 +812,18 @@ 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)); |
| - 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 +833,18 @@ 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)); |
| - 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 +854,18 @@ 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)); |
| - 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 +875,19 @@ 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)); |
| - 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 +898,25 @@ 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)); |
| - 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()); |
| } |
| @@ -831,21 +942,22 @@ 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)); |
| - 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 +966,189 @@ 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()) { |
| + 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)); |
| - 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()) { |
| + 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, SingleDragGestureMouseVertical) { |
| + CreateControllerAndTarget<MockDragMouseTarget>(); |
| + |
| + SyntheticSmoothDragGestureParams params; |
| + SyntheticSmoothMoveGesture::InputType input_type = |
| + SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT; |
| + params.start_point.SetPoint(89, 32); |
| + params.distances.push_back(gfx::Vector2d(0, 123)); |
| + |
| + 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(params.distances[0], drag_target->start_to_end_distance()); |
| +} |
| + |
| +TEST_F(SyntheticGestureControllerTest, SingleDragGestureMouseHorizontal) { |
| + CreateControllerAndTarget<MockDragMouseTarget>(); |
| + |
| + SyntheticSmoothDragGestureParams params; |
| + SyntheticSmoothMoveGesture::InputType input_type = |
| + SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT; |
| + params.start_point.SetPoint(12, -23); |
| + params.distances.push_back(gfx::Vector2d(-234, 0)); |
| + |
| + 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(params.distances[0], drag_target->start_to_end_distance()); |
| +} |
| + |
| +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)); |
| + |
| + 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)); |
| + |
| + 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)); |
| + |
| + 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_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), |
| + drag_target->total_abs_move_distance_length()); |
| + EXPECT_EQ(drag_target->start_to_end_distance(), |
| + params.distances[0] + params.distances[1]); |
| +} |
| + |
| +TEST_F(SyntheticGestureControllerTest, MultiDragGestureMouseVertical) { |
| + CreateControllerAndTarget<MockDragMouseTarget>(); |
| + |
| + SyntheticSmoothDragGestureParams params; |
| + SyntheticSmoothMoveGesture::InputType input_type = |
| + SyntheticSmoothMoveGesture::MOUSE_DRAG_INPUT; |
| + params.start_point.SetPoint(234, -13); |
| + params.distances.push_back(gfx::Vector2d(0, 133)); |
| + params.distances.push_back(gfx::Vector2d(0, 78)); |
| + |
| + 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_FLOAT_EQ(params.distances[0].Length() + params.distances[1].Length(), |
| + drag_target->total_abs_move_distance_length()); |
| + EXPECT_EQ(params.distances[0] + params.distances[1], |
| + drag_target->start_to_end_distance()); |
| } |
| TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |