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

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

Issue 2966723003: Add support for bounds animations (Closed)
Patch Set: Added another unit test to confirm that extrapolation won't lead to invalid sizes. Created 3 years, 5 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 | « cc/animation/keyframed_animation_curve.cc ('k') | cc/trees/target_property.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 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 2.f))); 979 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 2.f)));
980 EXPECT_NEAR(8.72f, 980 EXPECT_NEAR(8.72f,
981 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)), 981 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 3.5f)),
982 0.01f); 982 0.01f);
983 EXPECT_FLOAT_EQ(9.f, 983 EXPECT_FLOAT_EQ(9.f,
984 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f))); 984 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 4.f)));
985 EXPECT_FLOAT_EQ(9.f, 985 EXPECT_FLOAT_EQ(9.f,
986 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f))); 986 curve->GetValue(base::TimeDelta::FromSecondsD(scale * 5.f)));
987 } 987 }
988 988
989 // 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.
990 TEST(KeyframedAnimationCurveTest, OneSizeKeyFrame) {
991 gfx::SizeF size = gfx::SizeF(100, 100);
992 std::unique_ptr<KeyframedSizeAnimationCurve> curve(
993 KeyframedSizeAnimationCurve::Create());
994 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size, nullptr));
995
996 EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
997 EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
998 EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
999 EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
1000 EXPECT_SIZEF_EQ(size, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
1001 }
1002
1003 // Tests that a size animation with two keyframes works as expected.
1004 TEST(KeyframedAnimationCurveTest, TwoSizeKeyFrame) {
1005 gfx::SizeF size_a = gfx::SizeF(100, 100);
1006 gfx::SizeF size_b = gfx::SizeF(100, 0);
1007 gfx::SizeF size_midpoint = gfx::Tween::SizeValueBetween(0.5, size_a, size_b);
1008 std::unique_ptr<KeyframedSizeAnimationCurve> curve(
1009 KeyframedSizeAnimationCurve::Create());
1010 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
1011 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
1012 size_b, nullptr));
1013
1014 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
1015 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
1016 EXPECT_SIZEF_EQ(size_midpoint,
1017 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
1018 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
1019 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
1020 }
1021
1022 // Tests that a size animation with three keyframes works as expected.
1023 TEST(KeyframedAnimationCurveTest, ThreeSizeKeyFrame) {
1024 gfx::SizeF size_a = gfx::SizeF(100, 100);
1025 gfx::SizeF size_b = gfx::SizeF(100, 0);
1026 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.
1027 gfx::SizeF size_midpoint1 = gfx::Tween::SizeValueBetween(0.5, size_a, size_b);
1028 gfx::SizeF size_midpoint2 = gfx::Tween::SizeValueBetween(0.5, size_b, size_c);
1029 std::unique_ptr<KeyframedSizeAnimationCurve> curve(
1030 KeyframedSizeAnimationCurve::Create());
1031 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
1032 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
1033 size_b, nullptr));
1034 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
1035 size_c, nullptr));
1036
1037 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
1038 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
1039 EXPECT_SIZEF_EQ(size_midpoint1,
1040 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
1041 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
1042 EXPECT_SIZEF_EQ(size_midpoint2,
1043 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
1044 EXPECT_SIZEF_EQ(size_c, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
1045 EXPECT_SIZEF_EQ(size_c, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
1046 }
1047
1048 // Tests that a size animation with multiple keys at a given time works sanely.
1049 TEST(KeyframedAnimationCurveTest, RepeatedSizeKeyFrame) {
1050 gfx::SizeF size_a = gfx::SizeF(100, 64);
1051 gfx::SizeF size_b = gfx::SizeF(100, 192);
1052
1053 std::unique_ptr<KeyframedSizeAnimationCurve> curve(
1054 KeyframedSizeAnimationCurve::Create());
1055 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta(), size_a, nullptr));
1056 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
1057 size_a, nullptr));
1058 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
1059 size_b, nullptr));
1060 curve->AddKeyframe(SizeKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
1061 size_b, nullptr));
1062
1063 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
1064 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
1065 EXPECT_SIZEF_EQ(size_a, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
1066
1067 gfx::SizeF value = curve->GetValue(base::TimeDelta::FromSecondsD(1.0f));
1068 EXPECT_FLOAT_EQ(100.0f, value.width());
1069 EXPECT_LE(64.0f, value.height());
1070 EXPECT_GE(192.0f, value.height());
1071
1072 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
1073 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
1074 EXPECT_SIZEF_EQ(size_b, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
1075 }
1076
989 } // namespace 1077 } // namespace
990 } // namespace cc 1078 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/keyframed_animation_curve.cc ('k') | cc/trees/target_property.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698