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

Side by Side Diff: cc/animation/keyframed_animation_curve_unittest.cc

Issue 2775143002: Implement frames() timing function (Closed)
Patch Set: Fix behaviour outside input range [0,1] Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/animation/timing_function.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 struct Expected {
548 double time;
549 float value;
550 } expectations[] = {
551 {0.0, 0.f}, {0.1999, 0.f}, {0.2001, 0.25f}, {0.3999, 0.25f},
552 {0.4001, 0.5f}, {0.5999, 0.5f}, {0.6001, 0.75f}, {0.7999, 0.75f},
553 {0.8001, 1.f}, {1.0, 1.f},
554 };
555 for (const auto& expectation : expectations) {
556 EXPECT_FLOAT_EQ(
557 expectation.value,
558 curve->GetValue(base::TimeDelta::FromSecondsD(expectation.time)));
559 }
560 }
561
538 // Tests that animated bounds are computed as expected. 562 // Tests that animated bounds are computed as expected.
539 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { 563 TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
540 std::unique_ptr<KeyframedTransformAnimationCurve> curve( 564 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
541 KeyframedTransformAnimationCurve::Create()); 565 KeyframedTransformAnimationCurve::Create());
542 566
543 TransformOperations operations1; 567 TransformOperations operations1;
544 curve->AddKeyframe( 568 curve->AddKeyframe(
545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); 569 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
546 operations1.AppendTranslate(2.0, 3.0, -1.0); 570 operations1.AppendTranslate(2.0, 3.0, -1.0);
547 curve->AddKeyframe(TransformKeyframe::Create( 571 curve->AddKeyframe(TransformKeyframe::Create(
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 curve->AddKeyframe( 868 curve->AddKeyframe(
845 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); 869 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr));
846 // Curve timing function producing timing outputs outside of range [0,1]. 870 // Curve timing function producing timing outputs outside of range [0,1].
847 curve->SetTimingFunction( 871 curve->SetTimingFunction(
848 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); 872 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f));
849 873
850 EXPECT_FLOAT_EQ(-0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); 874 EXPECT_FLOAT_EQ(-0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
851 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); 875 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
852 } 876 }
853 877
878 // Tests that a frames timing function works as expected for inputs outside of
879 // range [0,1]
880 TEST(KeyframedAnimationCurveTest, FramesTimingInputsOutsideZeroOneRange) {
881 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
882 KeyframedFloatAnimationCurve::Create());
883 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f,
884 FramesTimingFunction::Create(5)));
885 curve->AddKeyframe(
886 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr));
887 // Curve timing function producing timing outputs outside of range [0,1].
888 curve->SetTimingFunction(
889 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f));
890
891 EXPECT_FLOAT_EQ(-0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
892 EXPECT_FLOAT_EQ(2.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
893 }
894
854 // Tests that an animation with a curve timing function and multiple keyframes 895 // Tests that an animation with a curve timing function and multiple keyframes
855 // works as expected. 896 // works as expected.
856 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { 897 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) {
857 std::unique_ptr<KeyframedFloatAnimationCurve> curve( 898 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
858 KeyframedFloatAnimationCurve::Create()); 899 KeyframedFloatAnimationCurve::Create());
859 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); 900 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
860 curve->AddKeyframe( 901 curve->AddKeyframe(
861 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); 902 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
862 curve->AddKeyframe( 903 curve->AddKeyframe(
863 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); 904 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), 981 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)),
941 0.01f); 982 0.01f);
942 EXPECT_FLOAT_EQ(9.f, 983 EXPECT_FLOAT_EQ(9.f,
943 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); 984 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f)));
944 EXPECT_FLOAT_EQ(9.f, 985 EXPECT_FLOAT_EQ(9.f,
945 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); 986 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f)));
946 } 987 }
947 988
948 } // namespace 989 } // namespace
949 } // namespace cc 990 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/animation/timing_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698