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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 0.005f); // c(.42)=.27, k(.27)=.17 | 718 0.005f); // c(.42)=.27, k(.27)=.17 |
719 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 719 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
720 EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)), | 720 EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)), |
721 0.005f); // c(.58)=.73, k(.73)=.83 | 721 0.005f); // c(.58)=.73, k(.73)=.83 |
722 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD( | 722 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD( |
723 0.75f))); // Clamped. c(.75) > 1 | 723 0.75f))); // Clamped. c(.75) > 1 |
724 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 724 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
725 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 725 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
726 } | 726 } |
727 | 727 |
| 728 // Tests that a linear timing function works as expected for inputs outside of |
| 729 // range [0,1] |
| 730 TEST(KeyframedAnimationCurveTest, LinearTimingInputsOutsideZeroOneRange) { |
| 731 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 732 KeyframedFloatAnimationCurve::Create()); |
| 733 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
| 734 curve->AddKeyframe( |
| 735 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
| 736 // Curve timing function producing timing outputs outside of range [0,1]. |
| 737 curve->SetTimingFunction( |
| 738 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
| 739 |
| 740 EXPECT_NEAR(-0.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), |
| 741 0.001f); |
| 742 EXPECT_NEAR(2.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
| 743 0.001f); |
| 744 } |
| 745 |
| 746 // If a curve cubic-bezier timing function produces timing outputs outside |
| 747 // the range [0, 1] then a keyframe cubic-bezier timing function |
| 748 // should consume that input properly (using end-point gradients). |
| 749 TEST(KeyframedAnimationCurveTest, CurveTimingInputsOutsideZeroOneRange) { |
| 750 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 751 KeyframedFloatAnimationCurve::Create()); |
| 752 // Keyframe timing function with 0.5 gradients at each end. |
| 753 curve->AddKeyframe(FloatKeyframe::Create( |
| 754 base::TimeDelta(), 0.f, |
| 755 CubicBezierTimingFunction::Create(0.5f, 0.25f, 0.5f, 0.75f).Pass())); |
| 756 curve->AddKeyframe( |
| 757 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
| 758 // Curve timing function producing timing outputs outside of range [0,1]. |
| 759 curve->SetTimingFunction( |
| 760 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
| 761 |
| 762 EXPECT_NEAR(-0.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), |
| 763 0.002f); // c(.25)=-.04, -.04*0.5=-0.02 |
| 764 EXPECT_NEAR(0.33f, curve->GetValue(base::TimeDelta::FromSecondsD(0.46f)), |
| 765 0.002f); // c(.46)=.38, k(.38)=.33 |
| 766 |
| 767 EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), |
| 768 0.002f); // c(.54)=.62, k(.62)=.67 |
| 769 EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
| 770 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 |
| 771 } |
| 772 |
| 773 // Tests that a step timing function works as expected for inputs outside of |
| 774 // range [0,1] |
| 775 TEST(KeyframedAnimationCurveTest, StepsTimingInputsOutsideZeroOneRange) { |
| 776 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 777 KeyframedFloatAnimationCurve::Create()); |
| 778 curve->AddKeyframe(FloatKeyframe::Create( |
| 779 base::TimeDelta(), 0.f, StepsTimingFunction::Create(4, 0.5f))); |
| 780 curve->AddKeyframe( |
| 781 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
| 782 // Curve timing function producing timing outputs outside of range [0,1]. |
| 783 curve->SetTimingFunction( |
| 784 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
| 785 |
| 786 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
| 787 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
| 788 } |
| 789 |
728 // Tests that an animation with a curve timing function and multiple keyframes | 790 // Tests that an animation with a curve timing function and multiple keyframes |
729 // works as expected. | 791 // works as expected. |
730 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { | 792 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |
731 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 793 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
732 KeyframedFloatAnimationCurve::Create()); | 794 KeyframedFloatAnimationCurve::Create()); |
733 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 795 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
734 curve->AddKeyframe( | 796 curve->AddKeyframe( |
735 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 797 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
736 curve->AddKeyframe( | 798 curve->AddKeyframe( |
737 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); | 799 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 curve->SetTimingFunction( | 834 curve->SetTimingFunction( |
773 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); | 835 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
774 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), | 836 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), |
775 0.f); // c(.25) < 0 | 837 0.f); // c(.25) < 0 |
776 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), | 838 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), |
777 9.f); // c(.75) > 1 | 839 9.f); // c(.75) > 1 |
778 } | 840 } |
779 | 841 |
780 } // namespace | 842 } // namespace |
781 } // namespace cc | 843 } // namespace cc |
OLD | NEW |