OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/animation/keyframed_animation_curve.h" | 5 #include "cc/animation/keyframed_animation_curve.h" |
6 | 6 |
7 #include "cc/animation/transform_operations.h" | 7 #include "cc/animation/transform_operations.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/animation/tween.h" | 10 #include "ui/gfx/animation/tween.h" |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 0.002f); // c(.46)=.38, k(.38)=.33 | 811 0.002f); // c(.46)=.38, k(.38)=.33 |
812 | 812 |
813 EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), | 813 EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), |
814 0.002f); // c(.54)=.62, k(.62)=.67 | 814 0.002f); // c(.54)=.62, k(.62)=.67 |
815 EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), | 815 EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
816 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 | 816 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 |
817 } | 817 } |
818 | 818 |
819 // Tests that a step timing function works as expected for inputs outside of | 819 // Tests that a step timing function works as expected for inputs outside of |
820 // range [0,1] | 820 // range [0,1] |
821 TEST(KeyframedAnimationCurveTest, StepsTimingInputsOutsideZeroOneRange) { | 821 TEST(KeyframedAnimationCurveTest, StepsTimingStartInputsOutsideZeroOneRange) { |
822 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | 822 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
823 KeyframedFloatAnimationCurve::Create()); | 823 KeyframedFloatAnimationCurve::Create()); |
824 curve->AddKeyframe( | 824 curve->AddKeyframe( |
825 FloatKeyframe::Create(base::TimeDelta(), 0.f, | 825 FloatKeyframe::Create(base::TimeDelta(), 0.f, |
826 StepsTimingFunction::Create( | 826 StepsTimingFunction::Create( |
827 4, StepsTimingFunction::StepPosition::MIDDLE))); | 827 4, StepsTimingFunction::StepPosition::START))); |
828 curve->AddKeyframe( | 828 curve->AddKeyframe( |
829 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); | 829 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
830 // Curve timing function producing timing outputs outside of range [0,1]. | 830 // Curve timing function producing timing outputs outside of range [0,1]. |
831 curve->SetTimingFunction( | 831 curve->SetTimingFunction( |
832 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 832 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
833 | 833 |
834 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 834 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
| 835 EXPECT_FLOAT_EQ(2.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
| 836 } |
| 837 |
| 838 TEST(KeyframedAnimationCurveTest, StepsTimingEndInputsOutsideZeroOneRange) { |
| 839 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
| 840 KeyframedFloatAnimationCurve::Create()); |
| 841 curve->AddKeyframe(FloatKeyframe::Create( |
| 842 base::TimeDelta(), 0.f, |
| 843 StepsTimingFunction::Create(4, StepsTimingFunction::StepPosition::END))); |
| 844 curve->AddKeyframe( |
| 845 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
| 846 // Curve timing function producing timing outputs outside of range [0,1]. |
| 847 curve->SetTimingFunction( |
| 848 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
| 849 |
| 850 EXPECT_FLOAT_EQ(-0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
835 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 851 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
836 } | 852 } |
837 | 853 |
838 // Tests that an animation with a curve timing function and multiple keyframes | 854 // Tests that an animation with a curve timing function and multiple keyframes |
839 // works as expected. | 855 // works as expected. |
840 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { | 856 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |
841 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | 857 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
842 KeyframedFloatAnimationCurve::Create()); | 858 KeyframedFloatAnimationCurve::Create()); |
843 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 859 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
844 curve->AddKeyframe( | 860 curve->AddKeyframe( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), | 940 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), |
925 0.01f); | 941 0.01f); |
926 EXPECT_FLOAT_EQ(9.f, | 942 EXPECT_FLOAT_EQ(9.f, |
927 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); | 943 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); |
928 EXPECT_FLOAT_EQ(9.f, | 944 EXPECT_FLOAT_EQ(9.f, |
929 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); | 945 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); |
930 } | 946 } |
931 | 947 |
932 } // namespace | 948 } // namespace |
933 } // namespace cc | 949 } // namespace cc |
OLD | NEW |