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

Unified Diff: cc/animation/scroll_offset_animation_curve_unittest.cc

Issue 2040543002: Take MT jank into account when animating the scroll offset on CC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test + apply suggested improvement Created 4 years, 3 months 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') | cc/animation/scroll_offset_animations_impl.h » ('j') | 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 feb5e65e4dcb425951077e98da964cbfe3fb5bf3..0c6e1eba46fac8ab0e8475372419df954451336a 100644
--- a/cc/animation/scroll_offset_animation_curve_unittest.cc
+++ b/cc/animation/scroll_offset_animation_curve_unittest.cc
@@ -11,6 +11,7 @@
const double kConstantDuration = 9.0;
const double kDurationDivisor = 60.0;
+const double kInverseDeltaMaxDuration = 12.0;
namespace cc {
namespace {
@@ -188,18 +189,73 @@ TEST(ScrollOffsetAnimationCurveTest, InverseDeltaDuration) {
curve->SetInitialValue(gfx::ScrollOffset());
double smallDeltaDuration = curve->Duration().InSecondsF();
- curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 300.f));
+ curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 300.f));
double mediumDeltaDuration = curve->Duration().InSecondsF();
- curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 500.f));
+ curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 500.f));
double largeDeltaDuration = curve->Duration().InSecondsF();
EXPECT_GT(smallDeltaDuration, mediumDeltaDuration);
EXPECT_GT(mediumDeltaDuration, largeDeltaDuration);
- curve->UpdateTarget(0.f, gfx::ScrollOffset(0.f, 5000.f));
+ curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 5000.f));
EXPECT_EQ(largeDeltaDuration, curve->Duration().InSecondsF());
}
+TEST(ScrollOffsetAnimationCurveTest, CurveWithDelay) {
+ std::unique_ptr<ScrollOffsetAnimationCurve> curve(
+ ScrollOffsetAnimationCurve::Create(
+ gfx::ScrollOffset(0.f, 100.f),
+ CubicBezierTimingFunction::CreatePreset(
+ CubicBezierTimingFunction::EaseType::EASE_IN_OUT),
+ ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA));
+ double duration_in_seconds = kInverseDeltaMaxDuration / kDurationDivisor;
+ double delay_in_seconds = 0.02;
+ double curve_duration = duration_in_seconds - delay_in_seconds;
+
+ curve->SetInitialValue(gfx::ScrollOffset(),
+ base::TimeDelta::FromSecondsD(delay_in_seconds));
+ EXPECT_NEAR(curve_duration, curve->Duration().InSecondsF(), 0.0002f);
+
+ curve->UpdateTarget(0.01f, gfx::ScrollOffset(0.f, 500.f));
+ EXPECT_GT(curve_duration, curve->Duration().InSecondsF());
+ EXPECT_EQ(gfx::ScrollOffset(0.f, 500.f), curve->target_value());
+}
+
+TEST(ScrollOffsetAnimationCurveTest, CurveWithLargeDelay) {
+ std::unique_ptr<ScrollOffsetAnimationCurve> curve(
+ ScrollOffsetAnimationCurve::Create(
+ gfx::ScrollOffset(0.f, 100.f),
+ CubicBezierTimingFunction::CreatePreset(
+ CubicBezierTimingFunction::EaseType::EASE_IN_OUT),
+ ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA));
+ curve->SetInitialValue(gfx::ScrollOffset(),
+ base::TimeDelta::FromSecondsD(0.2));
+ EXPECT_EQ(0.f, curve->Duration().InSecondsF());
+
+ // Re-targeting when animation duration is 0.
+ curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 300.f));
+ double duration =
+ ScrollOffsetAnimationCurve::SegmentDuration(
+ gfx::Vector2dF(0.f, 300.f),
+ ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
+ base::TimeDelta::FromSecondsD(0.01))
+ .InSecondsF();
+ EXPECT_EQ(duration, curve->Duration().InSecondsF());
+
+ // Re-targeting before last_retarget_, the difference should be accounted for
+ // in duration.
+ curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 500.f));
+ duration = ScrollOffsetAnimationCurve::SegmentDuration(
+ gfx::Vector2dF(0.f, 500.f),
+ ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
+ base::TimeDelta::FromSecondsD(0.01))
+ .InSecondsF();
+ EXPECT_EQ(duration, curve->Duration().InSecondsF());
+
+ EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0.f, 500.f),
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.0)));
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/animation/scroll_offset_animations_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698