Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2226)

Unified Diff: cc/animation/scroll_offset_animation_curve_unittest.cc

Issue 1553603003: Tweak the math in ScrollOffsetAnimationCurve::UpdateTarget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address ymalik's comment Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation/scroll_offset_animation_curve_unittest.cc
diff --git a/cc/animation/scroll_offset_animation_curve_unittest.cc b/cc/animation/scroll_offset_animation_curve_unittest.cc
index 4638ecfbfb0ea2f9066c29ab9eb0af8b33601f26..7044b03addae2ce538a69a0ab4986bc399fbf22c 100644
--- a/cc/animation/scroll_offset_animation_curve_unittest.cc
+++ b/cc/animation/scroll_offset_animation_curve_unittest.cc
@@ -128,64 +128,29 @@ TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
gfx::ScrollOffset initial_value(0.f, 0.f);
gfx::ScrollOffset target_value(0.f, 3600.f);
scoped_ptr<ScrollOffsetAnimationCurve> curve(
- ScrollOffsetAnimationCurve::Create(target_value,
- EaseInOutTimingFunction::Create()));
- curve->SetInitialValue(initial_value);
- EXPECT_EQ(1.0, curve->Duration().InSecondsF());
- EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
- EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y());
-
- curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0));
-
- EXPECT_EQ(2.0, curve->Duration().InSecondsF());
- EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
- EXPECT_NEAR(5410.05, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
- 0.01);
- EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(2.0)).y());
-
- curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0));
-
- EXPECT_NEAR(1.705, curve->Duration().InSecondsF(), 0.01);
- EXPECT_NEAR(5410.05, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
- 0.01);
- EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.705)).y());
-}
-
-TEST(ScrollOffsetAnimationCurveTest, UpdateTargetWithLargeVelocity) {
- gfx::ScrollOffset initial_value(0.f, 0.f);
- gfx::ScrollOffset target_value(0.f, 900.f);
- scoped_ptr<ScrollOffsetAnimationCurve> curve(
- ScrollOffsetAnimationCurve::Create(target_value,
- EaseInOutTimingFunction::Create()));
- curve->SetInitialValue(initial_value);
- EXPECT_EQ(0.5, curve->Duration().InSecondsF());
-
- EXPECT_EQ(450.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.25)).y());
-
- // This leads to a new computed velocity larger than 5000.
- curve->UpdateTarget(0.25, gfx::ScrollOffset(0.0, 450.0001));
-
- EXPECT_NEAR(0.25015, curve->Duration().InSecondsF(), 0.0001);
- EXPECT_NEAR(450.0,
- curve->GetValue(base::TimeDelta::FromSecondsD(0.22501)).y(),
- 0.001);
- EXPECT_NEAR(450.0,
- curve->GetValue(base::TimeDelta::FromSecondsD(0.225015)).y(),
- 0.001);
-}
-
-TEST(ScrollOffsetAnimationCurveTest, UpdateTargetConstantDuration) {
- gfx::ScrollOffset initial_value(0.f, 0.f);
- gfx::ScrollOffset target_value(0.f, 3600.f);
- scoped_ptr<ScrollOffsetAnimationCurve> curve(
ScrollOffsetAnimationCurve::Create(
target_value, EaseInOutTimingFunction::Create(),
ScrollOffsetAnimationCurve::DurationBehavior::CONSTANT));
curve->SetInitialValue(initial_value);
EXPECT_EQ(0.2, curve->Duration().InSecondsF());
+ EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.1)).y());
+ EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y());
curve->UpdateTarget(0.1, gfx::ScrollOffset(0.0, 9900.0));
+
EXPECT_EQ(0.3, curve->Duration().InSecondsF());
+ EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.1)).y());
+ EXPECT_NEAR(6827.59, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y(),
+ 0.01);
+ EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.3)).y());
+
+ curve->UpdateTarget(0.2, gfx::ScrollOffset(0.0, 7200.0));
+
+ // A closer target at high velocity reduces the duration.
+ EXPECT_NEAR(0.22, curve->Duration().InSecondsF(), 0.01);
+ EXPECT_NEAR(6827.59, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y(),
+ 0.01);
+ EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.22)).y());
}
} // namespace
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698