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 |
66 // Advance to the end. | 78 // Advance to the end. |
67 scroller.ComputeScrollOffset(start_time + scroll_duration); | 79 scroller.ComputeScrollOffset(start_time + scroll_duration); |
68 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 80 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
69 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 81 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
70 EXPECT_TRUE(scroller.IsFinished()); | 82 EXPECT_TRUE(scroller.IsFinished()); |
71 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 83 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
72 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); | 84 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); |
73 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); | 85 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); |
74 | 86 |
75 // Try to advance further; nothing should change. | 87 // Try to advance further; nothing should change. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); | 128 EXPECT_GT(scroller.GetFinalY(), scroller.GetCurrY()); |
117 EXPECT_FALSE(scroller.IsFinished()); | 129 EXPECT_FALSE(scroller.IsFinished()); |
118 | 130 |
119 // Ensure our velocity is non-zero and in the same direction as the original | 131 // Ensure our velocity is non-zero and in the same direction as the original |
120 // velocity. | 132 // velocity. |
121 EXPECT_LT(0.f, scroller.GetCurrVelocityX() * kDefaultVelocityX); | 133 EXPECT_LT(0.f, scroller.GetCurrVelocityX() * kDefaultVelocityX); |
122 EXPECT_LT(0.f, scroller.GetCurrVelocityY() * kDefaultVelocityY); | 134 EXPECT_LT(0.f, scroller.GetCurrVelocityY() * kDefaultVelocityY); |
123 EXPECT_TRUE( | 135 EXPECT_TRUE( |
124 scroller.IsScrollingInDirection(kDefaultVelocityX, kDefaultVelocityY)); | 136 scroller.IsScrollingInDirection(kDefaultVelocityX, kDefaultVelocityY)); |
125 | 137 |
| 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 |
126 // Advance to the end. | 150 // Advance to the end. |
127 scroller.ComputeScrollOffset(start_time + scroll_duration); | 151 scroller.ComputeScrollOffset(start_time + scroll_duration); |
128 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 152 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
129 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 153 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
130 EXPECT_TRUE(scroller.IsFinished()); | 154 EXPECT_TRUE(scroller.IsFinished()); |
131 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 155 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
132 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); | 156 EXPECT_NEAR(0.f, scroller.GetCurrVelocityX(), kEpsilon); |
133 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); | 157 EXPECT_NEAR(0.f, scroller.GetCurrVelocityY(), kEpsilon); |
134 | 158 |
135 // Try to advance further; nothing should change. | 159 // Try to advance further; nothing should change. |
136 scroller.ComputeScrollOffset(start_time + scroll_duration * 2); | 160 scroller.ComputeScrollOffset(start_time + scroll_duration * 2); |
137 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); | 161 EXPECT_EQ(scroller.GetFinalX(), scroller.GetCurrX()); |
138 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); | 162 EXPECT_EQ(scroller.GetFinalY(), scroller.GetCurrY()); |
139 EXPECT_TRUE(scroller.IsFinished()); | 163 EXPECT_TRUE(scroller.IsFinished()); |
140 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); | 164 EXPECT_EQ(scroll_duration, scroller.GetTimePassed()); |
141 } | 165 } |
142 | 166 |
143 } // namespace gfx | 167 } // namespace gfx |
OLD | NEW |