| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/animation/scroll_offset_animation_curve.h" | 5 #include "cc/animation/scroll_offset_animation_curve.h" |
| 6 | 6 |
| 7 #include "cc/animation/timing_function.h" | 7 #include "cc/animation/timing_function.h" |
| 8 #include "cc/base/time_util.h" | 8 #include "cc/base/time_util.h" |
| 9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 const double kConstantDuration = 9.0; | 12 const double kConstantDuration = 9.0; |
| 13 const double kDurationDivisor = 60.0; | 13 const double kDurationDivisor = 60.0; |
| 14 const double kInverseDeltaMaxDuration = 12.0; |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 TEST(ScrollOffsetAnimationCurveTest, DeltaBasedDuration) { | 19 TEST(ScrollOffsetAnimationCurveTest, DeltaBasedDuration) { |
| 19 gfx::ScrollOffset target_value(100.f, 200.f); | 20 gfx::ScrollOffset target_value(100.f, 200.f); |
| 20 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 21 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 21 ScrollOffsetAnimationCurve::Create( | 22 ScrollOffsetAnimationCurve::Create( |
| 22 target_value, CubicBezierTimingFunction::CreatePreset( | 23 target_value, CubicBezierTimingFunction::CreatePreset( |
| 23 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); | 24 CubicBezierTimingFunction::EaseType::EASE_IN_OUT))); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 std::unique_ptr<ScrollOffsetAnimationCurve> curve( | 182 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 182 ScrollOffsetAnimationCurve::Create( | 183 ScrollOffsetAnimationCurve::Create( |
| 183 gfx::ScrollOffset(0.f, 100.f), | 184 gfx::ScrollOffset(0.f, 100.f), |
| 184 CubicBezierTimingFunction::CreatePreset( | 185 CubicBezierTimingFunction::CreatePreset( |
| 185 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), | 186 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), |
| 186 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA)); | 187 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA)); |
| 187 | 188 |
| 188 curve->SetInitialValue(gfx::ScrollOffset()); | 189 curve->SetInitialValue(gfx::ScrollOffset()); |
| 189 double smallDeltaDuration = curve->Duration().InSecondsF(); | 190 double smallDeltaDuration = curve->Duration().InSecondsF(); |
| 190 | 191 |
| 191 curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 300.f)); | 192 curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 300.f)); |
| 192 double mediumDeltaDuration = curve->Duration().InSecondsF(); | 193 double mediumDeltaDuration = curve->Duration().InSecondsF(); |
| 193 | 194 |
| 194 curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 500.f)); | 195 curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 500.f)); |
| 195 double largeDeltaDuration = curve->Duration().InSecondsF(); | 196 double largeDeltaDuration = curve->Duration().InSecondsF(); |
| 196 | 197 |
| 197 EXPECT_GT(smallDeltaDuration, mediumDeltaDuration); | 198 EXPECT_GT(smallDeltaDuration, mediumDeltaDuration); |
| 198 EXPECT_GT(mediumDeltaDuration, largeDeltaDuration); | 199 EXPECT_GT(mediumDeltaDuration, largeDeltaDuration); |
| 199 | 200 |
| 200 curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 5000.f)); | 201 curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 5000.f)); |
| 201 EXPECT_EQ(largeDeltaDuration, curve->Duration().InSecondsF()); | 202 EXPECT_EQ(largeDeltaDuration, curve->Duration().InSecondsF()); |
| 202 } | 203 } |
| 203 | 204 |
| 205 TEST(ScrollOffsetAnimationCurveTest, CurveWithDelay) { |
| 206 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 207 ScrollOffsetAnimationCurve::Create( |
| 208 gfx::ScrollOffset(0.f, 100.f), |
| 209 CubicBezierTimingFunction::CreatePreset( |
| 210 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), |
| 211 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA)); |
| 212 double duration_in_seconds = kInverseDeltaMaxDuration / kDurationDivisor; |
| 213 double delay_in_seconds = 0.02; |
| 214 double curve_duration = duration_in_seconds - delay_in_seconds; |
| 215 |
| 216 curve->SetInitialValue(gfx::ScrollOffset(), |
| 217 base::TimeDelta::FromSecondsD(delay_in_seconds)); |
| 218 EXPECT_NEAR(curve_duration, curve->Duration().InSecondsF(), 0.0002f); |
| 219 |
| 220 curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 500.f)); |
| 221 EXPECT_GT(curve_duration, curve->Duration().InSecondsF()); |
| 222 EXPECT_EQ(gfx::ScrollOffset(0.f, 500.f), curve->target_value()); |
| 223 } |
| 224 |
| 225 TEST(ScrollOffsetAnimationCurveTest, CurveWithLargeDelay) { |
| 226 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 227 ScrollOffsetAnimationCurve::Create( |
| 228 gfx::ScrollOffset(0.f, 100.f), |
| 229 CubicBezierTimingFunction::CreatePreset( |
| 230 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), |
| 231 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA)); |
| 232 curve->SetInitialValue(gfx::ScrollOffset(), |
| 233 base::TimeDelta::FromSecondsD(0.2)); |
| 234 EXPECT_EQ(0.f, curve->Duration().InSecondsF()); |
| 235 |
| 236 // Re-targeting when animation duration is 0. |
| 237 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 300.f)); |
| 238 double duration = |
| 239 ScrollOffsetAnimationCurve::SegmentDuration( |
| 240 gfx::Vector2dF(0.f, 300.f), |
| 241 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA, |
| 242 base::TimeDelta::FromSecondsD(0.01)) |
| 243 .InSecondsF(); |
| 244 EXPECT_EQ(duration, curve->Duration().InSecondsF()); |
| 245 |
| 246 // Re-targeting before last_retarget_, the difference should be accounted for |
| 247 // in duration. |
| 248 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 500.f)); |
| 249 duration = ScrollOffsetAnimationCurve::SegmentDuration( |
| 250 gfx::Vector2dF(0.f, 500.f), |
| 251 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA, |
| 252 base::TimeDelta::FromSecondsD(0.01)) |
| 253 .InSecondsF(); |
| 254 EXPECT_EQ(duration, curve->Duration().InSecondsF()); |
| 255 |
| 256 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0.f, 500.f), |
| 257 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); |
| 258 } |
| 259 |
| 204 } // namespace | 260 } // namespace |
| 205 } // namespace cc | 261 } // namespace cc |
| OLD | NEW |