OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Tests for the TouchFlingGestureCurve. | 5 // Tests for the TouchFlingGestureCurve. |
6 | 6 |
7 #include "webkit/glue/touch_fling_gesture_curve.h" | 7 #include "webkit/glue/touch_fling_gesture_curve.h" |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatSize.h" |
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurve.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurve.h" |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg
et.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg
et.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h" | |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
16 | 16 |
17 using WebKit::WebFloatPoint; | 17 using WebKit::WebFloatPoint; |
| 18 using WebKit::WebFloatSize; |
18 using WebKit::WebGestureCurve; | 19 using WebKit::WebGestureCurve; |
19 using WebKit::WebGestureCurveTarget; | 20 using WebKit::WebGestureCurveTarget; |
20 using WebKit::WebPoint; | |
21 using WebKit::WebSize; | 21 using WebKit::WebSize; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 class MockGestureCurveTarget : public WebGestureCurveTarget { | 25 class MockGestureCurveTarget : public WebGestureCurveTarget { |
26 public: | 26 public: |
27 virtual void scrollBy(const WebPoint& delta) { | 27 virtual void scrollBy(const WebFloatSize& delta) { |
28 cumulative_delta_.x += delta.x; | 28 cumulative_delta_.width += delta.width; |
29 cumulative_delta_.y += delta.y; | 29 cumulative_delta_.height += delta.height; |
30 } | 30 } |
31 | 31 |
32 WebPoint cumulative_delta() const { return cumulative_delta_; } | 32 WebFloatSize cumulative_delta() const { return cumulative_delta_; } |
33 void resetCumulativeDelta() { cumulative_delta_ = WebPoint(); } | 33 void resetCumulativeDelta() { cumulative_delta_ = WebFloatSize(); } |
34 | 34 |
35 private: | 35 private: |
36 WebPoint cumulative_delta_; | 36 WebFloatSize cumulative_delta_; |
37 }; | 37 }; |
38 | 38 |
39 } // namespace anonymous | 39 } // namespace anonymous |
40 | 40 |
41 TEST(TouchFlingGestureCurve, flingCurveTouch) | 41 TEST(TouchFlingGestureCurve, flingCurveTouch) |
42 { | 42 { |
43 double initialVelocity = 5000; | 43 double initialVelocity = 5000; |
44 MockGestureCurveTarget target; | 44 MockGestureCurveTarget target; |
45 | 45 |
46 scoped_ptr<WebGestureCurve> curve(webkit_glue::TouchFlingGestureCurve::Create( | 46 scoped_ptr<WebGestureCurve> curve(webkit_glue::TouchFlingGestureCurve::Create( |
47 WebFloatPoint(initialVelocity, 0), | 47 WebFloatPoint(initialVelocity, 0), |
48 -5.70762e+03f, 1.72e+02f, 3.7e+00f, WebSize())); | 48 -5.70762e+03f, 1.72e+02f, 3.7e+00f, WebSize())); |
49 | 49 |
50 // Note: the expectations below are dependent on the curve parameters hard | 50 // Note: the expectations below are dependent on the curve parameters hard |
51 // coded into the create call above. | 51 // coded into the create call above. |
52 EXPECT_TRUE(curve->apply(0, &target)); | 52 EXPECT_TRUE(curve->apply(0, &target)); |
53 EXPECT_TRUE(curve->apply(0.25, &target)); | 53 EXPECT_TRUE(curve->apply(0.25, &target)); |
54 EXPECT_TRUE(curve->apply(0.45f, &target)); // Use non-uniform tick spacing. | 54 EXPECT_TRUE(curve->apply(0.45f, &target)); // Use non-uniform tick spacing. |
55 EXPECT_TRUE(curve->apply(1, &target)); | 55 EXPECT_TRUE(curve->apply(1, &target)); |
56 EXPECT_FALSE(curve->apply(1.5, &target)); | 56 EXPECT_FALSE(curve->apply(1.5, &target)); |
57 EXPECT_NEAR(target.cumulative_delta().x, 1193, 1); | 57 EXPECT_NEAR(target.cumulative_delta().width, 1193, 1); |
58 EXPECT_EQ(target.cumulative_delta().y, 0); | 58 EXPECT_EQ(target.cumulative_delta().height, 0); |
59 } | 59 } |
60 | 60 |
OLD | NEW |