OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" | 5 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 10 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
10 #include "third_party/WebKit/public/platform/WebGestureCurve.h" | 11 #include "third_party/WebKit/public/platform/WebGestureCurve.h" |
11 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 12 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
12 #include "ui/events/gestures/fling_curve.h" | 13 #include "ui/events/gestures/fling_curve.h" |
13 | 14 |
14 using blink::WebFloatSize; | 15 using blink::WebFloatSize; |
15 using blink::WebGestureCurve; | 16 using blink::WebGestureCurve; |
16 using blink::WebGestureCurveTarget; | 17 using blink::WebGestureCurveTarget; |
17 | 18 |
(...skipping 18 matching lines...) Expand all Loading... |
36 WebFloatSize current_velocity_; | 37 WebFloatSize current_velocity_; |
37 }; | 38 }; |
38 | 39 |
39 } // namespace anonymous | 40 } // namespace anonymous |
40 | 41 |
41 TEST(WebGestureCurveImplTest, Basic) { | 42 TEST(WebGestureCurveImplTest, Basic) { |
42 gfx::Vector2dF velocity(5000, 0); | 43 gfx::Vector2dF velocity(5000, 0); |
43 gfx::Vector2dF offset; | 44 gfx::Vector2dF offset; |
44 base::TimeTicks time; | 45 base::TimeTicks time; |
45 auto curve = WebGestureCurveImpl::CreateFromUICurveForTesting( | 46 auto curve = WebGestureCurveImpl::CreateFromUICurveForTesting( |
46 scoped_ptr<ui::GestureCurve>(new ui::FlingCurve(velocity, time)), offset); | 47 std::unique_ptr<ui::GestureCurve>(new ui::FlingCurve(velocity, time)), |
| 48 offset); |
47 | 49 |
48 // coded into the create call above. | 50 // coded into the create call above. |
49 MockGestureCurveTarget target; | 51 MockGestureCurveTarget target; |
50 EXPECT_TRUE(curve->apply(0, &target)); | 52 EXPECT_TRUE(curve->apply(0, &target)); |
51 EXPECT_TRUE(curve->apply(0.25, &target)); | 53 EXPECT_TRUE(curve->apply(0.25, &target)); |
52 EXPECT_NEAR(target.current_velocity().width, 1878, 1); | 54 EXPECT_NEAR(target.current_velocity().width, 1878, 1); |
53 EXPECT_EQ(target.current_velocity().height, 0); | 55 EXPECT_EQ(target.current_velocity().height, 0); |
54 EXPECT_GT(target.cumulative_delta().width, 0); | 56 EXPECT_GT(target.cumulative_delta().width, 0); |
55 EXPECT_TRUE(curve->apply(0.45, &target)); // Use non-uniform tick spacing. | 57 EXPECT_TRUE(curve->apply(0.45, &target)); // Use non-uniform tick spacing. |
56 | 58 |
57 // Ensure fling persists even if successive timestamps are identical. | 59 // Ensure fling persists even if successive timestamps are identical. |
58 gfx::Vector2dF cumulative_delta = target.cumulative_delta(); | 60 gfx::Vector2dF cumulative_delta = target.cumulative_delta(); |
59 gfx::Vector2dF current_velocity = target.current_velocity(); | 61 gfx::Vector2dF current_velocity = target.current_velocity(); |
60 EXPECT_TRUE(curve->apply(0.45, &target)); | 62 EXPECT_TRUE(curve->apply(0.45, &target)); |
61 EXPECT_EQ(cumulative_delta, gfx::Vector2dF(target.cumulative_delta())); | 63 EXPECT_EQ(cumulative_delta, gfx::Vector2dF(target.cumulative_delta())); |
62 EXPECT_EQ(current_velocity, gfx::Vector2dF(target.current_velocity())); | 64 EXPECT_EQ(current_velocity, gfx::Vector2dF(target.current_velocity())); |
63 | 65 |
64 EXPECT_TRUE(curve->apply(0.75, &target)); | 66 EXPECT_TRUE(curve->apply(0.75, &target)); |
65 EXPECT_FALSE(curve->apply(1.5, &target)); | 67 EXPECT_FALSE(curve->apply(1.5, &target)); |
66 EXPECT_NEAR(target.cumulative_delta().width, 1193, 1); | 68 EXPECT_NEAR(target.cumulative_delta().width, 1193, 1); |
67 EXPECT_EQ(target.cumulative_delta().height, 0); | 69 EXPECT_EQ(target.cumulative_delta().height, 0); |
68 EXPECT_EQ(target.current_velocity().width, 0); | 70 EXPECT_EQ(target.current_velocity().width, 0); |
69 EXPECT_EQ(target.current_velocity().height, 0); | 71 EXPECT_EQ(target.current_velocity().height, 0); |
70 } | 72 } |
71 | 73 |
72 } // namespace ui | 74 } // namespace ui |
OLD | NEW |