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

Unified Diff: cc/animation/keyframed_animation_curve_unittest.cc

Issue 2775143002: Implement frames() timing function (Closed)
Patch Set: Fix behaviour outside input range [0,1] Created 3 years, 8 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 | « no previous file | cc/animation/timing_function.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation/keyframed_animation_curve_unittest.cc
diff --git a/cc/animation/keyframed_animation_curve_unittest.cc b/cc/animation/keyframed_animation_curve_unittest.cc
index df3a0b1e7551f3ecb40487ead300173d75ca9f81..c050404d7143584645a08d11d96c3b98c3c83be5 100644
--- a/cc/animation/keyframed_animation_curve_unittest.cc
+++ b/cc/animation/keyframed_animation_curve_unittest.cc
@@ -535,6 +535,30 @@ TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtEnd) {
}
}
+// Tests a frames timing function.
+TEST(KeyframedAnimationCurveTest, FramesTimingFunction) {
+ std::unique_ptr<KeyframedFloatAnimationCurve> curve(
+ KeyframedFloatAnimationCurve::Create());
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f,
+ FramesTimingFunction::Create(5)));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr));
+
+ struct Expected {
+ double time;
+ float value;
+ } expectations[] = {
+ {0.0, 0.f}, {0.1999, 0.f}, {0.2001, 0.25f}, {0.3999, 0.25f},
+ {0.4001, 0.5f}, {0.5999, 0.5f}, {0.6001, 0.75f}, {0.7999, 0.75f},
+ {0.8001, 1.f}, {1.0, 1.f},
+ };
+ for (const auto& expectation : expectations) {
+ EXPECT_FLOAT_EQ(
+ expectation.value,
+ curve->GetValue(base::TimeDelta::FromSecondsD(expectation.time)));
+ }
+}
+
// Tests that animated bounds are computed as expected.
TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
std::unique_ptr<KeyframedTransformAnimationCurve> curve(
@@ -851,6 +875,23 @@ TEST(KeyframedAnimationCurveTest, StepsTimingEndInputsOutsideZeroOneRange) {
EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
}
+// Tests that a frames timing function works as expected for inputs outside of
+// range [0,1]
+TEST(KeyframedAnimationCurveTest, FramesTimingInputsOutsideZeroOneRange) {
+ std::unique_ptr<KeyframedFloatAnimationCurve> curve(
+ KeyframedFloatAnimationCurve::Create());
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f,
+ FramesTimingFunction::Create(5)));
+ curve->AddKeyframe(
+ FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr));
+ // Curve timing function producing timing outputs outside of range [0,1].
+ curve->SetTimingFunction(
+ CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f));
+
+ EXPECT_FLOAT_EQ(-0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
+ EXPECT_FLOAT_EQ(2.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
+}
+
// Tests that an animation with a curve timing function and multiple keyframes
// works as expected.
TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) {
« no previous file with comments | « no previous file | cc/animation/timing_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698