Chromium Code Reviews| 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..c59eff76a2b3c2801e89ddcbc32ba54a26082cf4 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 color animation with one keyframe works as expected. |
|
ajuma
2017/07/04 14:13:36
"size animation"
Ian Vollick
2017/07/04 14:31:05
Done.
|
| +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(100, 0); |
|
ajuma
2017/07/04 14:13:36
nit: Make size_c != size_b.
Ian Vollick
2017/07/04 14:31:05
Done.
|
| + 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 |