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/time/time.h" | 5 #include "base/time/time.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/gfx/android/scroller.h" | 7 #include "ui/gfx/android/scroller.h" |
8 | 8 |
9 namespace gfx { | 9 namespace gfx { |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 EXPECT_LT(kDefaultStartY, scroller.GetCurrY()); | 56 EXPECT_LT(kDefaultStartY, scroller.GetCurrY()); |
57 EXPECT_LT(scroller.GetFinalX(), scroller.GetCurrX()); | 57 EXPECT_LT(scroller.GetFinalX(), scroller.GetCurrX()); |
58 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); | 58 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); |
59 EXPECT_FALSE(scroller.IsFinished()); | 59 EXPECT_FALSE(scroller.IsFinished()); |
60 | 60 |
61 // Ensure our velocity is non-zero and in the same direction as the delta. | 61 // Ensure our velocity is non-zero and in the same direction as the delta. |
62 EXPECT_GT(0.f, scroller.GetCurrVelocityX() * kDefaultDeltaX); | 62 EXPECT_GT(0.f, scroller.GetCurrVelocityX() * kDefaultDeltaX); |
63 EXPECT_GT(0.f, scroller.GetCurrVelocityY() * kDefaultDeltaY); | 63 EXPECT_GT(0.f, scroller.GetCurrVelocityY() * kDefaultDeltaY); |
64 EXPECT_TRUE(scroller.IsScrollingInDirection(kDefaultDeltaX, kDefaultDeltaY)); | 64 EXPECT_TRUE(scroller.IsScrollingInDirection(kDefaultDeltaX, kDefaultDeltaY)); |
65 | 65 |
66 // Repeated offset computations at the same timestamp should yield identical | |
67 // results. | |
68 float curr_x = scroller.GetCurrX(); | |
69 float curr_y = scroller.GetCurrY(); | |
70 float curr_velocity_x = scroller.GetCurrVelocityX(); | |
71 float curr_velocity_y = scroller.GetCurrVelocityY(); | |
72 scroller.ComputeScrollOffset(start_time + scroll_duration / 2); | |
73 EXPECT_EQ(curr_x, scroller.GetCurrX()); | |
74 EXPECT_EQ(curr_y, scroller.GetCurrY()); | |
75 EXPECT_EQ(curr_velocity_x, scroller.GetCurrVelocityX()); | |
76 EXPECT_EQ(curr_velocity_y, scroller.GetCurrVelocityY()); | |
77 | |
78 // Advance to the end. | 66 // Advance to the end. |
79 scroller.ComputeScrollOffset(start_time + scroll_duration); | 67 scroller.ComputeScrollOffset(start_time + scroll_duration); |
80 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 68 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
81 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 69 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
82 EXPECT_TRUE(scroller.IsFinished()); | 70 EXPECT_TRUE(scroller.IsFinished()); |
83 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 71 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
84 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); | 72 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); |
85 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); | 73 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); |
86 | 74 |
87 // Try to advance further; nothing should change. | 75 // Try to advance further; nothing should change. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); | 116 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); |
129 EXPECT_FALSE(scroller.IsFinished()); | 117 EXPECT_FALSE(scroller.IsFinished()); |
130 | 118 |
131 // Ensure our velocity is non-zero and in the same direction as the original | 119 // Ensure our velocity is non-zero and in the same direction as the original |
132 // velocity. | 120 // velocity. |
133 EXPECT_LT(0.f, scroller.GetCurrVelocityX() * kDefaultVelocityX); | 121 EXPECT_LT(0.f, scroller.GetCurrVelocityX() * kDefaultVelocityX); |
134 EXPECT_LT(0.f, scroller.GetCurrVelocityY() * kDefaultVelocityY); | 122 EXPECT_LT(0.f, scroller.GetCurrVelocityY() * kDefaultVelocityY); |
135 EXPECT_TRUE( | 123 EXPECT_TRUE( |
136 scroller.IsScrollingInDirection(kDefaultVelocityX, kDefaultVelocityY)); | 124 scroller.IsScrollingInDirection(kDefaultVelocityX, kDefaultVelocityY)); |
137 | 125 |
138 // Repeated offset computations at the same timestamp should yield identical | |
139 // results. | |
140 float curr_x = scroller.GetCurrX(); | |
141 float curr_y = scroller.GetCurrY(); | |
142 float curr_velocity_x = scroller.GetCurrVelocityX(); | |
143 float curr_velocity_y = scroller.GetCurrVelocityY(); | |
144 scroller.ComputeScrollOffset(start_time + scroll_duration / 2); | |
145 EXPECT_EQ(curr_x, scroller.GetCurrX()); | |
146 EXPECT_EQ(curr_y, scroller.GetCurrY()); | |
147 EXPECT_EQ(curr_velocity_x, scroller.GetCurrVelocityX()); | |
148 EXPECT_EQ(curr_velocity_y, scroller.GetCurrVelocityY()); | |
149 | |
150 // Advance to the end. | 126 // Advance to the end. |
151 scroller.ComputeScrollOffset(start_time + scroll_duration); | 127 scroller.ComputeScrollOffset(start_time + scroll_duration); |
152 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 128 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
153 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 129 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
154 EXPECT_TRUE(scroller.IsFinished()); | 130 EXPECT_TRUE(scroller.IsFinished()); |
155 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 131 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
156 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); | 132 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); |
157 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); | 133 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); |
158 | 134 |
159 // Try to advance further; nothing should change. | 135 // Try to advance further; nothing should change. |
160 scroller.ComputeScrollOffset(start_time + scroll_duration * 2); | 136 scroller.ComputeScrollOffset(start_time + scroll_duration * 2); |
161 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 137 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
162 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 138 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
163 EXPECT_TRUE(scroller.IsFinished()); | 139 EXPECT_TRUE(scroller.IsFinished()); |
164 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 140 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
165 } | 141 } |
166 | 142 |
167 } // namespace gfx | 143 } // namespace gfx |
OLD | NEW |