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 d9cdbf441136eaf48bf561abb9885ecf3b4363e2..c5cdd6b1ff66423cfba801b807521bc3d406378a 100644 |
| --- a/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| +++ b/content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc |
| @@ -37,6 +37,7 @@ namespace { |
| const int kFlushInputRateInMs = 16; |
| const int kPointerAssumedStoppedTimeMs = 43; |
| const int kTouchSlopInDips = 7; |
| +const int kMinScalingSpanInDips = 27; |
| class MockSyntheticGesture : public SyntheticGesture { |
| public: |
| @@ -101,6 +102,10 @@ class MockSyntheticGestureTarget : public SyntheticGestureTarget { |
| return kTouchSlopInDips; |
| } |
| + virtual int GetMinScalingSpanInDips() const OVERRIDE { |
| + return kMinScalingSpanInDips; |
| + } |
| + |
| bool flush_requested() const { return flush_requested_; } |
| void ClearFlushRequest() { flush_requested_ = false; } |
| @@ -191,7 +196,8 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| }; |
| MockSyntheticPinchTouchTarget() |
| - : total_num_pixels_covered_(0), |
| + : initial_pointer_distance_(0), |
| + total_num_pixels_covered_(0), |
|
Sami
2014/05/19 14:49:04
Do we still need total_num_pixel_covered here?
Dominik Grewe
2014/05/19 17:31:43
I'm only using for the NoScaling unit test to make
|
| last_pointer_distance_(0), |
| zoom_direction_(ZOOM_DIRECTION_UNKNOWN), |
| started_(false) {} |
| @@ -209,6 +215,8 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| start_0_ = gfx::PointF(touch_event.touches[0].position); |
| start_1_ = gfx::PointF(touch_event.touches[1].position); |
| last_pointer_distance_ = (start_0_ - start_1_).Length(); |
| + initial_pointer_distance_ = last_pointer_distance_; |
| + EXPECT_GE(initial_pointer_distance_, GetMinScalingSpanInDips()); |
| started_ = true; |
| } else { |
| @@ -239,6 +247,22 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| float total_num_pixels_covered() const { return total_num_pixels_covered_; } |
| ZoomDirection zoom_direction() const { return zoom_direction_; } |
| + float ComputeScaleFactor() const { |
| + switch (zoom_direction_) { |
| + case ZOOM_IN: |
| + return last_pointer_distance_ / |
| + (initial_pointer_distance_ + 2 * GetTouchSlopInDips()); |
| + case ZOOM_OUT: |
| + return last_pointer_distance_ / |
| + (initial_pointer_distance_ - 2 * GetTouchSlopInDips()); |
| + case ZOOM_DIRECTION_UNKNOWN: |
| + return 1.0f; |
| + default: |
| + EXPECT_TRUE(false); |
|
Sami
2014/05/19 14:49:04
NOTREACHED();
Dominik Grewe
2014/05/19 17:31:43
Done.
|
| + return 0.0f; |
| + } |
| + } |
| + |
| private: |
| ZoomDirection ComputeZoomDirection(float last_pointer_distance, |
| float current_pointer_distance) { |
| @@ -247,6 +271,7 @@ class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
| : ZOOM_OUT; |
| } |
| + float initial_pointer_distance_; |
| float total_num_pixels_covered_; |
| float last_pointer_distance_; |
| ZoomDirection zoom_direction_; |
| @@ -883,8 +908,7 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |
| SyntheticPinchGestureParams params; |
| params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| - params.zoom_in = true; |
| - params.total_num_pixels_covered = 345; |
| + params.scale_factor = 2.3f; |
| params.anchor.SetPoint(54, 89); |
| scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
| @@ -897,8 +921,7 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomIn) { |
| EXPECT_EQ(0, num_failure_); |
| EXPECT_EQ(pinch_target->zoom_direction(), |
| MockSyntheticPinchTouchTarget::ZOOM_IN); |
| - EXPECT_EQ(params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(), |
| - pinch_target->total_num_pixels_covered()); |
| + EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); |
| } |
| TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { |
| @@ -906,8 +929,7 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { |
| SyntheticPinchGestureParams params; |
| params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| - params.zoom_in = false; |
| - params.total_num_pixels_covered = 456; |
| + params.scale_factor = 0.4f; |
| params.anchor.SetPoint(-12, 93); |
| scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
| @@ -920,17 +942,15 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZoomOut) { |
| EXPECT_EQ(0, num_failure_); |
| EXPECT_EQ(pinch_target->zoom_direction(), |
| MockSyntheticPinchTouchTarget::ZOOM_OUT); |
| - EXPECT_EQ(params.total_num_pixels_covered + 2 * target_->GetTouchSlopInDips(), |
| - pinch_target->total_num_pixels_covered()); |
| + EXPECT_FLOAT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); |
| } |
| -TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZeroPixelsCovered) { |
| +TEST_F(SyntheticGestureControllerTest, PinchGestureTouchNoScaling) { |
| CreateControllerAndTarget<MockSyntheticPinchTouchTarget>(); |
| SyntheticPinchGestureParams params; |
| params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| - params.zoom_in = true; |
| - params.total_num_pixels_covered = 0; |
| + params.scale_factor = 1.0f; |
| scoped_ptr<SyntheticPinchGesture> gesture(new SyntheticPinchGesture(params)); |
| QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); |
| @@ -943,6 +963,7 @@ TEST_F(SyntheticGestureControllerTest, PinchGestureTouchZeroPixelsCovered) { |
| EXPECT_EQ(pinch_target->zoom_direction(), |
| MockSyntheticPinchTouchTarget::ZOOM_DIRECTION_UNKNOWN); |
| EXPECT_EQ(0, pinch_target->total_num_pixels_covered()); |
| + EXPECT_EQ(params.scale_factor, pinch_target->ComputeScaleFactor()); |
| } |
| TEST_F(SyntheticGestureControllerTest, TapGestureTouch) { |