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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/events/gesture_detection/velocity_tracker_state.h" | 10 #include "ui/events/gesture_detection/velocity_tracker_state.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 class VelocityTrackerTest : public testing::Test { | 44 class VelocityTrackerTest : public testing::Test { |
45 public: | 45 public: |
46 VelocityTrackerTest() {} | 46 VelocityTrackerTest() {} |
47 ~VelocityTrackerTest() override {} | 47 ~VelocityTrackerTest() override {} |
48 | 48 |
49 protected: | 49 protected: |
50 static MockMotionEvent Sample(MotionEvent::Action action, | 50 static MockMotionEvent Sample(MotionEvent::Action action, |
51 const gfx::PointF& p0, | 51 const gfx::PointF& p0, |
52 TimeTicks t0, | 52 TimeTicks t0, |
53 gfx::Vector2dF v, | 53 const gfx::Vector2dF& v, |
54 TimeDelta dt) { | 54 TimeDelta dt) { |
55 const gfx::PointF p = p0 + ScaleVector2d(v, dt.InSecondsF()); | 55 const gfx::PointF p = p0 + ScaleVector2d(v, dt.InSecondsF()); |
56 return MockMotionEvent(action, t0 + dt, p.x(), p.y()); | 56 return MockMotionEvent(action, t0 + dt, p.x(), p.y()); |
57 } | 57 } |
58 | 58 |
59 static void ApplyMovementSequence(VelocityTrackerState* state, | 59 static void ApplyMovementSequence(VelocityTrackerState* state, |
60 const gfx::PointF& p0, | 60 const gfx::PointF& p0, |
61 gfx::Vector2dF v, | 61 const gfx::Vector2dF& v, |
62 TimeTicks t0, | 62 TimeTicks t0, |
63 TimeDelta t, | 63 TimeDelta t, |
64 size_t samples) { | 64 size_t samples) { |
65 EXPECT_TRUE(!!samples); | 65 EXPECT_TRUE(!!samples); |
66 if (!samples) | 66 if (!samples) |
67 return; | 67 return; |
68 const base::TimeDelta dt = t / samples; | 68 const base::TimeDelta dt = t / samples; |
69 state->AddMovement(Sample(MotionEvent::ACTION_DOWN, p0, t0, v, dt * 0)); | 69 state->AddMovement(Sample(MotionEvent::ACTION_DOWN, p0, t0, v, dt * 0)); |
70 ApplyMovement(state, p0, v, t0, t, samples); | 70 ApplyMovement(state, p0, v, t0, t, samples); |
71 state->AddMovement(Sample(MotionEvent::ACTION_UP, p0, t0, v, t)); | 71 state->AddMovement(Sample(MotionEvent::ACTION_UP, p0, t0, v, t)); |
72 } | 72 } |
73 | 73 |
74 static void ApplyMovement(VelocityTrackerState* state, | 74 static void ApplyMovement(VelocityTrackerState* state, |
75 const gfx::PointF& p0, | 75 const gfx::PointF& p0, |
76 gfx::Vector2dF v, | 76 const gfx::Vector2dF& v, |
77 TimeTicks t0, | 77 TimeTicks t0, |
78 TimeDelta t, | 78 TimeDelta t, |
79 size_t samples) { | 79 size_t samples) { |
80 EXPECT_TRUE(!!samples); | 80 EXPECT_TRUE(!!samples); |
81 if (!samples) | 81 if (!samples) |
82 return; | 82 return; |
83 const base::TimeDelta dt = t / samples; | 83 const base::TimeDelta dt = t / samples; |
84 for (size_t i = 0; i < samples; ++i) | 84 for (size_t i = 0; i < samples; ++i) |
85 state->AddMovement(Sample(MotionEvent::ACTION_MOVE, p0, t0, v, dt * i)); | 85 state->AddMovement(Sample(MotionEvent::ACTION_MOVE, p0, t0, v, dt * i)); |
86 } | 86 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 253 |
254 // This does not hold for the unrestricted LSQ2 strategy. | 254 // This does not hold for the unrestricted LSQ2 strategy. |
255 state_unrestricted.ComputeCurrentVelocity(1000, 20000); | 255 state_unrestricted.ComputeCurrentVelocity(1000, 20000); |
256 EXPECT_EQ(0, state_unrestricted.GetXVelocity(0)); | 256 EXPECT_EQ(0, state_unrestricted.GetXVelocity(0)); |
257 // Y velocity is negative, despite the fact that the finger only moved in the | 257 // Y velocity is negative, despite the fact that the finger only moved in the |
258 // positive y direction. | 258 // positive y direction. |
259 EXPECT_GT(0, state_unrestricted.GetYVelocity(0)); | 259 EXPECT_GT(0, state_unrestricted.GetYVelocity(0)); |
260 } | 260 } |
261 | 261 |
262 } // namespace ui | 262 } // namespace ui |
OLD | NEW |