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

Unified Diff: cc/animation/scroll_offset_animation_curve_unittest.cc

Issue 719453007: Make Keyframe use TimeTicks/TimeDelta to represent time instead of double. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/base/time_util.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 d57814e794e9470a22b557007a9af4f6885900d3..cb3e914b871e3e7219e31691c0f49c98153da2f8 100644
--- a/cc/animation/scroll_offset_animation_curve_unittest.cc
+++ b/cc/animation/scroll_offset_animation_curve_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/animation/scroll_offset_animation_curve.h"
#include "cc/animation/timing_function.h"
+#include "cc/base/time_util.h"
#include "cc/test/geometry_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -63,24 +64,28 @@ TEST(ScrollOffsetAnimationCurveTest, GetValue) {
EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
- double duration_in_seconds = curve->Duration().InSecondsF();
+ base::TimeDelta duration = curve->Duration();
EXPECT_GT(curve->Duration().InSecondsF(), 0);
EXPECT_LT(curve->Duration().InSecondsF(), 0.1);
EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type());
- EXPECT_EQ(duration_in_seconds, curve->Duration().InSecondsF());
+ EXPECT_EQ(duration, curve->Duration());
- EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0));
- EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0));
- EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
- curve->GetValue(duration_in_seconds / 2.0));
- EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds));
- EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds + 1.0));
+ EXPECT_VECTOR2DF_EQ(initial_value,
+ curve->GetValue(base::TimeDelta::FromSecondsD(-1.0)));
+ EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
+ EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
+ curve->GetValue(TimeUtil::Scale(duration, 0.5f)),
+ 0.00025);
+ EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration));
+ EXPECT_VECTOR2DF_EQ(
+ target_value,
+ curve->GetValue(duration + base::TimeDelta::FromSecondsD(1.0)));
// Verify that GetValue takes the timing function into account.
- gfx::ScrollOffset value = curve->GetValue(duration_in_seconds / 4.0);
- EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
- EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
+ gfx::ScrollOffset value = curve->GetValue(TimeUtil::Scale(duration, 0.25f));
+ EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
+ EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
// Verify that a clone behaves exactly like the original.
@@ -92,32 +97,34 @@ TEST(ScrollOffsetAnimationCurveTest, Clone) {
target_value,
EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
- double duration_in_seconds = curve->Duration().InSecondsF();
+ base::TimeDelta duration = curve->Duration();
scoped_ptr<AnimationCurve> clone(curve->Clone().Pass());
EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type());
- EXPECT_EQ(duration_in_seconds, clone->Duration().InSecondsF());
+ EXPECT_EQ(duration, clone->Duration());
EXPECT_VECTOR2DF_EQ(initial_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(-1.0));
- EXPECT_VECTOR2DF_EQ(initial_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(0.0));
- EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds / 2.0));
+ base::TimeDelta::FromSecondsD(-1.0)));
EXPECT_VECTOR2DF_EQ(
- target_value,
- clone->ToScrollOffsetAnimationCurve()->GetValue(duration_in_seconds));
+ initial_value,
+ clone->ToScrollOffsetAnimationCurve()->GetValue(base::TimeDelta()));
+ EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
+ clone->ToScrollOffsetAnimationCurve()->GetValue(
+ TimeUtil::Scale(duration, 0.5f)),
+ 0.00025);
+ EXPECT_VECTOR2DF_EQ(
+ target_value, clone->ToScrollOffsetAnimationCurve()->GetValue(duration));
EXPECT_VECTOR2DF_EQ(target_value,
clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds + 1.0));
+ duration + base::TimeDelta::FromSecondsD(1.f)));
// Verify that the timing function was cloned correctly.
gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue(
- duration_in_seconds / 4.0);
- EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
- EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
+ TimeUtil::Scale(duration, 0.25f));
+ EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
+ EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
}
TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
@@ -128,21 +135,23 @@ TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
target_value, EaseInOutTimingFunction::Create().Pass()));
curve->SetInitialValue(initial_value);
EXPECT_EQ(1.0, curve->Duration().InSecondsF());
- EXPECT_EQ(1800.0, curve->GetValue(0.5).y());
- EXPECT_EQ(3600.0, curve->GetValue(1.0).y());
+ 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(0.5).y());
- EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
- EXPECT_EQ(9900.0, curve->GetValue(2.0).y());
+ EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
+ EXPECT_NEAR(5566.49, 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.674, curve->Duration().InSecondsF(), 0.01);
- EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01);
- EXPECT_EQ(7200.0, curve->GetValue(1.674).y());
+ EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
+ 0.01);
+ EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.674)).y());
}
} // namespace
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/base/time_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698