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

Unified Diff: cc/animation/keyframed_animation_curve_unittest.cc

Issue 809523004: Define step timing function for the cc animation framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « no previous file | cc/animation/timing_function.h » ('j') | cc/animation/timing_function.h » ('J')
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 314ce9da2fdb765d49fee9bd61f57814236b14a3..ec8ce6dc029703e4ec7914603d87ce36f4c69688 100644
--- a/cc/animation/keyframed_animation_curve_unittest.cc
+++ b/cc/animation/keyframed_animation_curve_unittest.cc
@@ -440,6 +440,101 @@ TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) {
EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
}
+// Tests that a steps timing function works as expected.
ajuma 2014/12/17 16:32:55 Please add a few words so that it explains how thi
+TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtStart) {
ajuma 2014/12/17 16:32:55 Style nit: no underscore in the test name. (Same f
+ scoped_ptr<KeyframedFloatAnimationCurve> curve(
+ KeyframedFloatAnimationCurve::Create());
+ const int num_steps = 36;
+ const float steps_start_offset = 1.0f;
+ curve->AddKeyframe(FloatKeyframe::Create(
+ base::TimeDelta(), 0.f,
+ StepsTimingFunction::Create(num_steps, steps_start_offset)));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ num_steps, nullptr));
+
+ const float time_threshold = 0.0001f;
+
+ for (float i = 0; i < num_steps; i += 1.0f) {
ajuma 2014/12/17 16:32:56 0.f
loyso (OOO) 2014/12/18 01:53:05 Do we have a rationale behind it (any references t
ajuma 2014/12/18 02:15:41 Not sure if it's documented anywhere, but this is
loyso (OOO) 2014/12/18 03:17:30 Ok, I'll make it consistent to cc/ folder. Overall
+ const base::TimeDelta time1 =
+ base::TimeDelta::FromSecondsD(i / num_steps - time_threshold);
+ const base::TimeDelta time2 =
+ base::TimeDelta::FromSecondsD(i / num_steps + time_threshold);
+ EXPECT_FLOAT_EQ(ceil(i), curve->GetValue(time1));
+ EXPECT_FLOAT_EQ(ceil(i) + 1, curve->GetValue(time2));
ajuma 2014/12/17 16:32:56 1.f
+ }
+ EXPECT_FLOAT_EQ(num_steps,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.0f)));
+
+ for (float i = 0.5f; i <= num_steps; i += 1.0f) {
+ const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps);
+ EXPECT_FLOAT_EQ(ceil(i), curve->GetValue(time));
+ }
+}
+
+// Tests that a steps timing function works as expected.
+TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtMiddle) {
+ scoped_ptr<KeyframedFloatAnimationCurve> curve(
+ KeyframedFloatAnimationCurve::Create());
+ const int num_steps = 36;
+ const float steps_start_offset = 0.5f;
+ curve->AddKeyframe(FloatKeyframe::Create(
+ base::TimeDelta(), 0.f,
+ StepsTimingFunction::Create(num_steps, steps_start_offset)));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ num_steps, nullptr));
+
+ const float time_threshold = 0.0001f;
+
+ EXPECT_FLOAT_EQ(0, curve->GetValue(base::TimeDelta()));
ajuma 2014/12/17 16:32:55 0.f
+ for (float i = 0.5f; i < num_steps; i += 1.0f) {
+ const base::TimeDelta time1 =
+ base::TimeDelta::FromSecondsD(i / num_steps - time_threshold);
+ const base::TimeDelta time2 =
+ base::TimeDelta::FromSecondsD(i / num_steps + time_threshold);
+ EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time1));
+ EXPECT_FLOAT_EQ(floor(i) + 1.0f, curve->GetValue(time2));
+ }
+ EXPECT_FLOAT_EQ(num_steps,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.0f)));
+
+ for (float i = 0.25f; i <= num_steps; i += 1.0f) {
+ const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps);
+ EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time));
+ }
+}
+
+// Tests that a steps timing function works as expected.
+TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtEnd) {
+ scoped_ptr<KeyframedFloatAnimationCurve> curve(
+ KeyframedFloatAnimationCurve::Create());
+ const int num_steps = 36;
+ const float steps_start_offset = 0.0f;
+ curve->AddKeyframe(FloatKeyframe::Create(
+ base::TimeDelta(), 0.f,
+ StepsTimingFunction::Create(num_steps, steps_start_offset)));
+ curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ num_steps, nullptr));
+
+ const float time_threshold = 0.0001f;
+
+ EXPECT_FLOAT_EQ(0, curve->GetValue(base::TimeDelta()));
ajuma 2014/12/17 16:32:55 0.f
+ for (float i = 1; i <= num_steps; i += 1.0f) {
ajuma 2014/12/17 16:32:56 1.f
+ const base::TimeDelta time1 =
+ base::TimeDelta::FromSecondsD(i / num_steps - time_threshold);
+ const base::TimeDelta time2 =
+ base::TimeDelta::FromSecondsD(i / num_steps + time_threshold);
+ EXPECT_FLOAT_EQ(floor(i) - 1, curve->GetValue(time1));
ajuma 2014/12/17 16:32:55 1.f
+ EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time2));
+ }
+ EXPECT_FLOAT_EQ(num_steps,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.0f)));
+
+ for (float i = 0.5f; i <= num_steps; i += 1.0f) {
+ const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps);
+ EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time));
+ }
+}
+
// Tests that animated bounds are computed as expected.
TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
scoped_ptr<KeyframedTransformAnimationCurve> curve(
« no previous file with comments | « no previous file | cc/animation/timing_function.h » ('j') | cc/animation/timing_function.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698