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

Unified Diff: cc/animation/keyframed_animation_curve_unittest.cc

Issue 2966723003: Add support for bounds animations (Closed)
Patch Set: address reviewer feedback Created 3 years, 5 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/keyframed_animation_curve.cc ('k') | cc/trees/target_property.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 c050404d7143584645a08d11d96c3b98c3c83be5..bf45bccbc6ffdef8e02b44d0c8ed5bba4992f2d2 100644
--- a/cc/animation/keyframed_animation_curve_unittest.cc
+++ b/cc/animation/keyframed_animation_curve_unittest.cc
@@ -986,5 +986,93 @@ TEST(KeyframedAnimationCurveTest, ScaledDuration) {
curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f)));
}
+// Tests that a size animation with one keyframe works as expected.
+TEST(KeyframedAnimationCurveTest, OneSizeKeyFrame) {
+ gfx::SizeF size = gfx::SizeF(100, 100);
+ std::unique_ptr<KeyframedSizeAnimationCurve> curve(
+ KeyframedSizeAnimationCurve::Create());
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size, nullptr));
+
+ EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+}
+
+// Tests that a size animation with two keyframes works as expected.
+TEST(KeyframedAnimationCurveTest, TwoSizeKeyFrame) {
+ gfx::SizeF size_a = gfx::SizeF(100, 100);
+ gfx::SizeF size_b = gfx::SizeF(100, 0);
+ gfx::SizeF size_midpoint = gfx::Tween::SizeValueBetween(0.5, size_a, size_b);
+ std::unique_ptr<KeyframedSizeAnimationCurve> curve(
+ KeyframedSizeAnimationCurve::Create());
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ size_b, nullptr));
+
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SIZEF_EQ(size_midpoint,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+}
+
+// Tests that a size animation with three keyframes works as expected.
+TEST(KeyframedAnimationCurveTest, ThreeSizeKeyFrame) {
+ gfx::SizeF size_a = gfx::SizeF(100, 100);
+ gfx::SizeF size_b = gfx::SizeF(100, 0);
+ gfx::SizeF size_c = gfx::SizeF(200, 0);
+ gfx::SizeF size_midpoint1 = gfx::Tween::SizeValueBetween(0.5, size_a, size_b);
+ gfx::SizeF size_midpoint2 = gfx::Tween::SizeValueBetween(0.5, size_b, size_c);
+ std::unique_ptr<KeyframedSizeAnimationCurve> curve(
+ KeyframedSizeAnimationCurve::Create());
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ size_b, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
+ size_c, nullptr));
+
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SIZEF_EQ(size_midpoint1,
+ curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
+ EXPECT_SIZEF_EQ(size_midpoint2,
+ curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_SIZEF_EQ(size_c, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_SIZEF_EQ(size_c, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
+}
+
+// Tests that a size animation with multiple keys at a given time works sanely.
+TEST(KeyframedAnimationCurveTest, RepeatedSizeKeyFrame) {
+ gfx::SizeF size_a = gfx::SizeF(100, 64);
+ gfx::SizeF size_b = gfx::SizeF(100, 192);
+
+ std::unique_ptr<KeyframedSizeAnimationCurve> curve(
+ KeyframedSizeAnimationCurve::Create());
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ size_a, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
+ size_b, nullptr));
+ curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
+ size_b, nullptr));
+
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
+ EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
+
+ gfx::SizeF value = curve->GetValue(base::TimeDelta::FromSecondsD(1.0f));
+ EXPECT_FLOAT_EQ(100.0f, value.width());
+ EXPECT_LE(64.0f, value.height());
+ EXPECT_GE(192.0f, value.height());
+
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
+ EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/animation/keyframed_animation_curve.cc ('k') | cc/trees/target_property.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698