Chromium Code Reviews| 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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 528 } |
| 529 EXPECT_FLOAT_EQ(num_steps, | 529 EXPECT_FLOAT_EQ(num_steps, |
| 530 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); | 530 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); |
| 531 | 531 |
| 532 for (float i = 0.5f; i <= num_steps; i += 1.0f) { | 532 for (float i = 0.5f; i <= num_steps; i += 1.0f) { |
| 533 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | 533 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); |
| 534 EXPECT_FLOAT_EQ(std::floor(i), curve->GetValue(time)); | 534 EXPECT_FLOAT_EQ(std::floor(i), curve->GetValue(time)); |
| 535 } | 535 } |
| 536 } | 536 } |
| 537 | 537 |
| 538 // Tests a frames timing function. | |
| 539 TEST(KeyframedAnimationCurveTest, FramesTimingFunction) { | |
| 540 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | |
| 541 KeyframedFloatAnimationCurve::Create()); | |
| 542 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, | |
| 543 FramesTimingFunction::Create(5))); | |
| 544 curve->AddKeyframe( | |
| 545 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr)); | |
| 546 | |
| 547 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta())); | |
| 548 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.1999))); | |
| 549 EXPECT_FLOAT_EQ(0.25f, | |
| 550 curve->GetValue(base::TimeDelta::FromSecondsD(0.2001))); | |
| 551 EXPECT_FLOAT_EQ(0.25f, | |
| 552 curve->GetValue(base::TimeDelta::FromSecondsD(0.3999))); | |
| 553 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.4001))); | |
| 554 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5999))); | |
| 555 EXPECT_FLOAT_EQ(0.75f, | |
| 556 curve->GetValue(base::TimeDelta::FromSecondsD(0.6001))); | |
| 557 EXPECT_FLOAT_EQ(0.75f, | |
| 558 curve->GetValue(base::TimeDelta::FromSecondsD(0.7999))); | |
| 559 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.8001))); | |
| 560 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); | |
|
alancutter (OOO until 2018)
2017/03/29 04:58:30
These line wraps make the test a bit harder to rea
suzyh_UTC10 (ex-contributor)
2017/04/04 01:02:02
Rearranged. How's this?
git cl format has Opinion
| |
| 561 } | |
| 562 | |
| 538 // Tests that animated bounds are computed as expected. | 563 // Tests that animated bounds are computed as expected. |
| 539 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { | 564 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { |
| 540 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | 565 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 541 KeyframedTransformAnimationCurve::Create()); | 566 KeyframedTransformAnimationCurve::Create()); |
| 542 | 567 |
| 543 TransformOperations operations1; | 568 TransformOperations operations1; |
| 544 curve->AddKeyframe( | 569 curve->AddKeyframe( |
| 545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 570 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
| 546 operations1.AppendTranslate(2.0, 3.0, -1.0); | 571 operations1.AppendTranslate(2.0, 3.0, -1.0); |
| 547 curve->AddKeyframe(TransformKeyframe::Create( | 572 curve->AddKeyframe(TransformKeyframe::Create( |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 curve->AddKeyframe( | 853 curve->AddKeyframe( |
| 829 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); | 854 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
| 830 // Curve timing function producing timing outputs outside of range [0,1]. | 855 // Curve timing function producing timing outputs outside of range [0,1]. |
| 831 curve->SetTimingFunction( | 856 curve->SetTimingFunction( |
| 832 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 857 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
| 833 | 858 |
| 834 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 859 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
| 835 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 860 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
| 836 } | 861 } |
| 837 | 862 |
| 863 // Tests that a frames timing function works as expected for inputs outside of | |
| 864 // range [0,1] | |
|
alancutter (OOO until 2018)
2017/03/29 04:58:30
Bah these comments, they're just repeating the tes
suzyh_UTC10 (ex-contributor)
2017/04/04 01:02:02
Ack.
| |
| 865 TEST(KeyframedAnimationCurveTest, FramesTimingInputsOutsideZeroOneRange) { | |
| 866 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | |
| 867 KeyframedFloatAnimationCurve::Create()); | |
| 868 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, | |
| 869 FramesTimingFunction::Create(5))); | |
| 870 curve->AddKeyframe( | |
| 871 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); | |
| 872 // Curve timing function producing timing outputs outside of range [0,1]. | |
| 873 curve->SetTimingFunction( | |
| 874 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | |
| 875 | |
| 876 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | |
| 877 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | |
| 878 } | |
| 879 | |
| 838 // Tests that an animation with a curve timing function and multiple keyframes | 880 // Tests that an animation with a curve timing function and multiple keyframes |
| 839 // works as expected. | 881 // works as expected. |
| 840 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { | 882 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |
| 841 std::unique_ptr<KeyframedFloatAnimationCurve> curve( | 883 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
| 842 KeyframedFloatAnimationCurve::Create()); | 884 KeyframedFloatAnimationCurve::Create()); |
| 843 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 885 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
| 844 curve->AddKeyframe( | 886 curve->AddKeyframe( |
| 845 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 887 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
| 846 curve->AddKeyframe( | 888 curve->AddKeyframe( |
| 847 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); | 889 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), | 966 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), |
| 925 0.01f); | 967 0.01f); |
| 926 EXPECT_FLOAT_EQ(9.f, | 968 EXPECT_FLOAT_EQ(9.f, |
| 927 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); | 969 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); |
| 928 EXPECT_FLOAT_EQ(9.f, | 970 EXPECT_FLOAT_EQ(9.f, |
| 929 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); | 971 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); |
| 930 } | 972 } |
| 931 | 973 |
| 932 } // namespace | 974 } // namespace |
| 933 } // namespace cc | 975 } // namespace cc |
| OLD | NEW |