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" |
11 #include "ui/gfx/geometry/box_f.h" | 11 #include "ui/gfx/geometry/box_f.h" |
12 #include "ui/gfx/test/gfx_util.h" | 12 #include "ui/gfx/test/gfx_util.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 void ExpectTranslateX(SkMScalar translate_x, const gfx::Transform& transform) { | 17 void ExpectTranslateX(SkMScalar translate_x, const gfx::Transform& transform) { |
18 EXPECT_FLOAT_EQ(translate_x, transform.matrix().get(0, 3)); | 18 EXPECT_FLOAT_EQ(translate_x, transform.matrix().get(0, 3)); |
19 } | 19 } |
20 | 20 |
21 void ExpectBrightness(double brightness, const FilterOperations& filter) { | 21 void ExpectBrightness(double brightness, const FilterOperations& filter) { |
22 EXPECT_EQ(1u, filter.size()); | 22 EXPECT_EQ(1u, filter.size()); |
23 EXPECT_EQ(FilterOperation::BRIGHTNESS, filter.at(0).type()); | 23 EXPECT_EQ(FilterOperation::BRIGHTNESS, filter.at(0).type()); |
24 EXPECT_FLOAT_EQ(brightness, filter.at(0).amount()); | 24 EXPECT_FLOAT_EQ(brightness, filter.at(0).amount()); |
25 } | 25 } |
26 | 26 |
27 // Tests that a color animation with one keyframe works as expected. | 27 // Tests that a color animation with one keyframe works as expected. |
28 TEST(KeyframedAnimationCurveTest, OneColorKeyFrame) { | 28 TEST(KeyframedAnimationCurveTest, OneColorKeyFrame) { |
29 SkColor color = SkColorSetARGB(255, 255, 255, 255); | 29 SkColor color = SkColorSetARGB(255, 255, 255, 255); |
30 scoped_ptr<KeyframedColorAnimationCurve> curve( | 30 std::unique_ptr<KeyframedColorAnimationCurve> curve( |
31 KeyframedColorAnimationCurve::Create()); | 31 KeyframedColorAnimationCurve::Create()); |
32 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta(), color, nullptr)); | 32 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta(), color, nullptr)); |
33 | 33 |
34 EXPECT_SKCOLOR_EQ(color, | 34 EXPECT_SKCOLOR_EQ(color, |
35 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 35 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
36 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 36 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
37 EXPECT_SKCOLOR_EQ(color, | 37 EXPECT_SKCOLOR_EQ(color, |
38 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 38 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
39 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 39 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
40 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 40 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
41 } | 41 } |
42 | 42 |
43 // Tests that a color animation with two keyframes works as expected. | 43 // Tests that a color animation with two keyframes works as expected. |
44 TEST(KeyframedAnimationCurveTest, TwoColorKeyFrame) { | 44 TEST(KeyframedAnimationCurveTest, TwoColorKeyFrame) { |
45 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); | 45 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); |
46 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); | 46 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); |
47 SkColor color_midpoint = gfx::Tween::ColorValueBetween(0.5, color_a, color_b); | 47 SkColor color_midpoint = gfx::Tween::ColorValueBetween(0.5, color_a, color_b); |
48 scoped_ptr<KeyframedColorAnimationCurve> curve( | 48 std::unique_ptr<KeyframedColorAnimationCurve> curve( |
49 KeyframedColorAnimationCurve::Create()); | 49 KeyframedColorAnimationCurve::Create()); |
50 curve->AddKeyframe( | 50 curve->AddKeyframe( |
51 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); | 51 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); |
52 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 52 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
53 color_b, nullptr)); | 53 color_b, nullptr)); |
54 | 54 |
55 EXPECT_SKCOLOR_EQ(color_a, | 55 EXPECT_SKCOLOR_EQ(color_a, |
56 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 56 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
57 EXPECT_SKCOLOR_EQ(color_a, | 57 EXPECT_SKCOLOR_EQ(color_a, |
58 curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 58 curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
59 EXPECT_SKCOLOR_EQ(color_midpoint, | 59 EXPECT_SKCOLOR_EQ(color_midpoint, |
60 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 60 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
61 EXPECT_SKCOLOR_EQ(color_b, | 61 EXPECT_SKCOLOR_EQ(color_b, |
62 curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 62 curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
63 EXPECT_SKCOLOR_EQ(color_b, | 63 EXPECT_SKCOLOR_EQ(color_b, |
64 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 64 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
65 } | 65 } |
66 | 66 |
67 // Tests that a color animation with three keyframes works as expected. | 67 // Tests that a color animation with three keyframes works as expected. |
68 TEST(KeyframedAnimationCurveTest, ThreeColorKeyFrame) { | 68 TEST(KeyframedAnimationCurveTest, ThreeColorKeyFrame) { |
69 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); | 69 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); |
70 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); | 70 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); |
71 SkColor color_c = SkColorSetARGB(255, 0, 0, 255); | 71 SkColor color_c = SkColorSetARGB(255, 0, 0, 255); |
72 SkColor color_midpoint1 = | 72 SkColor color_midpoint1 = |
73 gfx::Tween::ColorValueBetween(0.5, color_a, color_b); | 73 gfx::Tween::ColorValueBetween(0.5, color_a, color_b); |
74 SkColor color_midpoint2 = | 74 SkColor color_midpoint2 = |
75 gfx::Tween::ColorValueBetween(0.5, color_b, color_c); | 75 gfx::Tween::ColorValueBetween(0.5, color_b, color_c); |
76 scoped_ptr<KeyframedColorAnimationCurve> curve( | 76 std::unique_ptr<KeyframedColorAnimationCurve> curve( |
77 KeyframedColorAnimationCurve::Create()); | 77 KeyframedColorAnimationCurve::Create()); |
78 curve->AddKeyframe( | 78 curve->AddKeyframe( |
79 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); | 79 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); |
80 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 80 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
81 color_b, nullptr)); | 81 color_b, nullptr)); |
82 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), | 82 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), |
83 color_c, nullptr)); | 83 color_c, nullptr)); |
84 | 84 |
85 EXPECT_SKCOLOR_EQ(color_a, | 85 EXPECT_SKCOLOR_EQ(color_a, |
86 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 86 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
87 EXPECT_SKCOLOR_EQ(color_a, | 87 EXPECT_SKCOLOR_EQ(color_a, |
88 curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 88 curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
89 EXPECT_SKCOLOR_EQ(color_midpoint1, | 89 EXPECT_SKCOLOR_EQ(color_midpoint1, |
90 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 90 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
91 EXPECT_SKCOLOR_EQ(color_b, | 91 EXPECT_SKCOLOR_EQ(color_b, |
92 curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 92 curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
93 EXPECT_SKCOLOR_EQ(color_midpoint2, | 93 EXPECT_SKCOLOR_EQ(color_midpoint2, |
94 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 94 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
95 EXPECT_SKCOLOR_EQ(color_c, | 95 EXPECT_SKCOLOR_EQ(color_c, |
96 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 96 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
97 EXPECT_SKCOLOR_EQ(color_c, | 97 EXPECT_SKCOLOR_EQ(color_c, |
98 curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 98 curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
99 } | 99 } |
100 | 100 |
101 // Tests that a colro animation with multiple keys at a given time works sanely. | 101 // Tests that a colro animation with multiple keys at a given time works sanely. |
102 TEST(KeyframedAnimationCurveTest, RepeatedColorKeyFrame) { | 102 TEST(KeyframedAnimationCurveTest, RepeatedColorKeyFrame) { |
103 SkColor color_a = SkColorSetARGB(255, 64, 0, 0); | 103 SkColor color_a = SkColorSetARGB(255, 64, 0, 0); |
104 SkColor color_b = SkColorSetARGB(255, 192, 0, 0); | 104 SkColor color_b = SkColorSetARGB(255, 192, 0, 0); |
105 | 105 |
106 scoped_ptr<KeyframedColorAnimationCurve> curve( | 106 std::unique_ptr<KeyframedColorAnimationCurve> curve( |
107 KeyframedColorAnimationCurve::Create()); | 107 KeyframedColorAnimationCurve::Create()); |
108 curve->AddKeyframe( | 108 curve->AddKeyframe( |
109 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); | 109 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr)); |
110 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 110 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
111 color_a, nullptr)); | 111 color_a, nullptr)); |
112 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 112 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
113 color_b, nullptr)); | 113 color_b, nullptr)); |
114 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), | 114 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), |
115 color_b, nullptr)); | 115 color_b, nullptr)); |
116 | 116 |
(...skipping 13 matching lines...) Expand all Loading... |
130 EXPECT_SKCOLOR_EQ(color_b, | 130 EXPECT_SKCOLOR_EQ(color_b, |
131 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 131 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
132 EXPECT_SKCOLOR_EQ(color_b, | 132 EXPECT_SKCOLOR_EQ(color_b, |
133 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 133 curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
134 EXPECT_SKCOLOR_EQ(color_b, | 134 EXPECT_SKCOLOR_EQ(color_b, |
135 curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 135 curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
136 } | 136 } |
137 | 137 |
138 // Tests that a float animation with one keyframe works as expected. | 138 // Tests that a float animation with one keyframe works as expected. |
139 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) { | 139 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) { |
140 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 140 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
141 KeyframedFloatAnimationCurve::Create()); | 141 KeyframedFloatAnimationCurve::Create()); |
142 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); | 142 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); |
143 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 143 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
144 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 144 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
145 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 145 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
146 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 146 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
147 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 147 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
148 } | 148 } |
149 | 149 |
150 // Tests that a float animation with two keyframes works as expected. | 150 // Tests that a float animation with two keyframes works as expected. |
151 TEST(KeyframedAnimationCurveTest, TwoFloatKeyframe) { | 151 TEST(KeyframedAnimationCurveTest, TwoFloatKeyframe) { |
152 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 152 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
153 KeyframedFloatAnimationCurve::Create()); | 153 KeyframedFloatAnimationCurve::Create()); |
154 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); | 154 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); |
155 curve->AddKeyframe( | 155 curve->AddKeyframe( |
156 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); | 156 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); |
157 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 157 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
158 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 158 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
159 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 159 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
160 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 160 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
161 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 161 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
162 } | 162 } |
163 | 163 |
164 // Tests that a float animation with three keyframes works as expected. | 164 // Tests that a float animation with three keyframes works as expected. |
165 TEST(KeyframedAnimationCurveTest, ThreeFloatKeyframe) { | 165 TEST(KeyframedAnimationCurveTest, ThreeFloatKeyframe) { |
166 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 166 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
167 KeyframedFloatAnimationCurve::Create()); | 167 KeyframedFloatAnimationCurve::Create()); |
168 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); | 168 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); |
169 curve->AddKeyframe( | 169 curve->AddKeyframe( |
170 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); | 170 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); |
171 curve->AddKeyframe( | 171 curve->AddKeyframe( |
172 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 8.f, nullptr)); | 172 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 8.f, nullptr)); |
173 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 173 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
174 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 174 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
175 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 175 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
176 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 176 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
177 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 177 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
178 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 178 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
179 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 179 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
180 } | 180 } |
181 | 181 |
182 // Tests that a float animation with multiple keys at a given time works sanely. | 182 // Tests that a float animation with multiple keys at a given time works sanely. |
183 TEST(KeyframedAnimationCurveTest, RepeatedFloatKeyTimes) { | 183 TEST(KeyframedAnimationCurveTest, RepeatedFloatKeyTimes) { |
184 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 184 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
185 KeyframedFloatAnimationCurve::Create()); | 185 KeyframedFloatAnimationCurve::Create()); |
186 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 4.f, nullptr)); | 186 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 4.f, nullptr)); |
187 curve->AddKeyframe( | 187 curve->AddKeyframe( |
188 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); | 188 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr)); |
189 curve->AddKeyframe( | 189 curve->AddKeyframe( |
190 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 6.f, nullptr)); | 190 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 6.f, nullptr)); |
191 curve->AddKeyframe( | 191 curve->AddKeyframe( |
192 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 6.f, nullptr)); | 192 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 6.f, nullptr)); |
193 | 193 |
194 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 194 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
195 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 195 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
196 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 196 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
197 | 197 |
198 // There is a discontinuity at 1. Any value between 4 and 6 is valid. | 198 // There is a discontinuity at 1. Any value between 4 and 6 is valid. |
199 float value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f)); | 199 float value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f)); |
200 EXPECT_TRUE(value >= 4 && value <= 6); | 200 EXPECT_TRUE(value >= 4 && value <= 6); |
201 | 201 |
202 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 202 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
203 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 203 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
204 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 204 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
205 } | 205 } |
206 | 206 |
207 // Tests that a transform animation with one keyframe works as expected. | 207 // Tests that a transform animation with one keyframe works as expected. |
208 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) { | 208 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) { |
209 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 209 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
210 KeyframedTransformAnimationCurve::Create()); | 210 KeyframedTransformAnimationCurve::Create()); |
211 TransformOperations operations; | 211 TransformOperations operations; |
212 operations.AppendTranslate(2.f, 0.f, 0.f); | 212 operations.AppendTranslate(2.f, 0.f, 0.f); |
213 curve->AddKeyframe( | 213 curve->AddKeyframe( |
214 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); | 214 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); |
215 | 215 |
216 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 216 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
217 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 217 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
218 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 218 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
219 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 219 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
220 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 220 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
221 } | 221 } |
222 | 222 |
223 // Tests that a transform animation with two keyframes works as expected. | 223 // Tests that a transform animation with two keyframes works as expected. |
224 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) { | 224 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) { |
225 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 225 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
226 KeyframedTransformAnimationCurve::Create()); | 226 KeyframedTransformAnimationCurve::Create()); |
227 TransformOperations operations1; | 227 TransformOperations operations1; |
228 operations1.AppendTranslate(2.f, 0.f, 0.f); | 228 operations1.AppendTranslate(2.f, 0.f, 0.f); |
229 TransformOperations operations2; | 229 TransformOperations operations2; |
230 operations2.AppendTranslate(4.f, 0.f, 0.f); | 230 operations2.AppendTranslate(4.f, 0.f, 0.f); |
231 | 231 |
232 curve->AddKeyframe( | 232 curve->AddKeyframe( |
233 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 233 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
234 curve->AddKeyframe(TransformKeyframe::Create( | 234 curve->AddKeyframe(TransformKeyframe::Create( |
235 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 235 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
236 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 236 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
237 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 237 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
238 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 238 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
239 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 239 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
240 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 240 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
241 } | 241 } |
242 | 242 |
243 // Tests that a transform animation with three keyframes works as expected. | 243 // Tests that a transform animation with three keyframes works as expected. |
244 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) { | 244 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) { |
245 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 245 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
246 KeyframedTransformAnimationCurve::Create()); | 246 KeyframedTransformAnimationCurve::Create()); |
247 TransformOperations operations1; | 247 TransformOperations operations1; |
248 operations1.AppendTranslate(2.f, 0.f, 0.f); | 248 operations1.AppendTranslate(2.f, 0.f, 0.f); |
249 TransformOperations operations2; | 249 TransformOperations operations2; |
250 operations2.AppendTranslate(4.f, 0.f, 0.f); | 250 operations2.AppendTranslate(4.f, 0.f, 0.f); |
251 TransformOperations operations3; | 251 TransformOperations operations3; |
252 operations3.AppendTranslate(8.f, 0.f, 0.f); | 252 operations3.AppendTranslate(8.f, 0.f, 0.f); |
253 curve->AddKeyframe( | 253 curve->AddKeyframe( |
254 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 254 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
255 curve->AddKeyframe(TransformKeyframe::Create( | 255 curve->AddKeyframe(TransformKeyframe::Create( |
256 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); | 256 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); |
257 curve->AddKeyframe(TransformKeyframe::Create( | 257 curve->AddKeyframe(TransformKeyframe::Create( |
258 base::TimeDelta::FromSecondsD(2.0), operations3, nullptr)); | 258 base::TimeDelta::FromSecondsD(2.0), operations3, nullptr)); |
259 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 259 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
260 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 260 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
261 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 261 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
262 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 262 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
263 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 263 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
264 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 264 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
265 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 265 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
266 } | 266 } |
267 | 267 |
268 // Tests that a transform animation with multiple keys at a given time works | 268 // Tests that a transform animation with multiple keys at a given time works |
269 // sanely. | 269 // sanely. |
270 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) { | 270 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) { |
271 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 271 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
272 KeyframedTransformAnimationCurve::Create()); | 272 KeyframedTransformAnimationCurve::Create()); |
273 // A step function. | 273 // A step function. |
274 TransformOperations operations1; | 274 TransformOperations operations1; |
275 operations1.AppendTranslate(4.f, 0.f, 0.f); | 275 operations1.AppendTranslate(4.f, 0.f, 0.f); |
276 TransformOperations operations2; | 276 TransformOperations operations2; |
277 operations2.AppendTranslate(4.f, 0.f, 0.f); | 277 operations2.AppendTranslate(4.f, 0.f, 0.f); |
278 TransformOperations operations3; | 278 TransformOperations operations3; |
279 operations3.AppendTranslate(6.f, 0.f, 0.f); | 279 operations3.AppendTranslate(6.f, 0.f, 0.f); |
280 TransformOperations operations4; | 280 TransformOperations operations4; |
281 operations4.AppendTranslate(6.f, 0.f, 0.f); | 281 operations4.AppendTranslate(6.f, 0.f, 0.f); |
(...skipping 15 matching lines...) Expand all Loading... |
297 EXPECT_GE(value.matrix().get(0, 3), 4.f); | 297 EXPECT_GE(value.matrix().get(0, 3), 4.f); |
298 EXPECT_LE(value.matrix().get(0, 3), 6.f); | 298 EXPECT_LE(value.matrix().get(0, 3), 6.f); |
299 | 299 |
300 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 300 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
301 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 301 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
302 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 302 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
303 } | 303 } |
304 | 304 |
305 // Tests that a filter animation with one keyframe works as expected. | 305 // Tests that a filter animation with one keyframe works as expected. |
306 TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) { | 306 TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) { |
307 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 307 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
308 KeyframedFilterAnimationCurve::Create()); | 308 KeyframedFilterAnimationCurve::Create()); |
309 FilterOperations operations; | 309 FilterOperations operations; |
310 operations.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 310 operations.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
311 curve->AddKeyframe( | 311 curve->AddKeyframe( |
312 FilterKeyframe::Create(base::TimeDelta(), operations, nullptr)); | 312 FilterKeyframe::Create(base::TimeDelta(), operations, nullptr)); |
313 | 313 |
314 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 314 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
315 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 315 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
316 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 316 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
317 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 317 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
318 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 318 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
319 } | 319 } |
320 | 320 |
321 // Tests that a filter animation with two keyframes works as expected. | 321 // Tests that a filter animation with two keyframes works as expected. |
322 TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) { | 322 TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) { |
323 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 323 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
324 KeyframedFilterAnimationCurve::Create()); | 324 KeyframedFilterAnimationCurve::Create()); |
325 FilterOperations operations1; | 325 FilterOperations operations1; |
326 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 326 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
327 FilterOperations operations2; | 327 FilterOperations operations2; |
328 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); | 328 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); |
329 | 329 |
330 curve->AddKeyframe( | 330 curve->AddKeyframe( |
331 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 331 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
332 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), | 332 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), |
333 operations2, nullptr)); | 333 operations2, nullptr)); |
334 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 334 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
335 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 335 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
336 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 336 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
337 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 337 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
338 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 338 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
339 } | 339 } |
340 | 340 |
341 // Tests that a filter animation with three keyframes works as expected. | 341 // Tests that a filter animation with three keyframes works as expected. |
342 TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) { | 342 TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) { |
343 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 343 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
344 KeyframedFilterAnimationCurve::Create()); | 344 KeyframedFilterAnimationCurve::Create()); |
345 FilterOperations operations1; | 345 FilterOperations operations1; |
346 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); | 346 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); |
347 FilterOperations operations2; | 347 FilterOperations operations2; |
348 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); | 348 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); |
349 FilterOperations operations3; | 349 FilterOperations operations3; |
350 operations3.Append(FilterOperation::CreateBrightnessFilter(8.f)); | 350 operations3.Append(FilterOperation::CreateBrightnessFilter(8.f)); |
351 curve->AddKeyframe( | 351 curve->AddKeyframe( |
352 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 352 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
353 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), | 353 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), |
354 operations2, nullptr)); | 354 operations2, nullptr)); |
355 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), | 355 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), |
356 operations3, nullptr)); | 356 operations3, nullptr)); |
357 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 357 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
358 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 358 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
359 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 359 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
360 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 360 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
361 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 361 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
362 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 362 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
363 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 363 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
364 } | 364 } |
365 | 365 |
366 // Tests that a filter animation with multiple keys at a given time works | 366 // Tests that a filter animation with multiple keys at a given time works |
367 // sanely. | 367 // sanely. |
368 TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) { | 368 TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) { |
369 scoped_ptr<KeyframedFilterAnimationCurve> curve( | 369 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
370 KeyframedFilterAnimationCurve::Create()); | 370 KeyframedFilterAnimationCurve::Create()); |
371 // A step function. | 371 // A step function. |
372 FilterOperations operations1; | 372 FilterOperations operations1; |
373 operations1.Append(FilterOperation::CreateBrightnessFilter(4.f)); | 373 operations1.Append(FilterOperation::CreateBrightnessFilter(4.f)); |
374 FilterOperations operations2; | 374 FilterOperations operations2; |
375 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); | 375 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); |
376 FilterOperations operations3; | 376 FilterOperations operations3; |
377 operations3.Append(FilterOperation::CreateBrightnessFilter(6.f)); | 377 operations3.Append(FilterOperation::CreateBrightnessFilter(6.f)); |
378 FilterOperations operations4; | 378 FilterOperations operations4; |
379 operations4.Append(FilterOperation::CreateBrightnessFilter(6.f)); | 379 operations4.Append(FilterOperation::CreateBrightnessFilter(6.f)); |
(...skipping 17 matching lines...) Expand all Loading... |
397 EXPECT_GE(value.at(0).amount(), 4); | 397 EXPECT_GE(value.at(0).amount(), 4); |
398 EXPECT_LE(value.at(0).amount(), 6); | 398 EXPECT_LE(value.at(0).amount(), 6); |
399 | 399 |
400 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 400 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
401 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 401 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
402 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 402 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
403 } | 403 } |
404 | 404 |
405 // Tests that the keyframes may be added out of order. | 405 // Tests that the keyframes may be added out of order. |
406 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) { | 406 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) { |
407 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 407 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
408 KeyframedFloatAnimationCurve::Create()); | 408 KeyframedFloatAnimationCurve::Create()); |
409 curve->AddKeyframe( | 409 curve->AddKeyframe( |
410 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 8.f, nullptr)); | 410 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 8.f, nullptr)); |
411 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); | 411 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr)); |
412 curve->AddKeyframe( | 412 curve->AddKeyframe( |
413 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 4.f, nullptr)); | 413 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 4.f, nullptr)); |
414 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 414 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
415 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 415 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
416 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 416 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
417 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 417 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
418 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); | 418 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f))); |
419 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 419 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
420 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); | 420 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f))); |
421 } | 421 } |
422 | 422 |
423 // Tests that a cubic bezier timing function works as expected. | 423 // Tests that a cubic bezier timing function works as expected. |
424 TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) { | 424 TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) { |
425 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 425 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
426 KeyframedFloatAnimationCurve::Create()); | 426 KeyframedFloatAnimationCurve::Create()); |
427 curve->AddKeyframe(FloatKeyframe::Create( | 427 curve->AddKeyframe(FloatKeyframe::Create( |
428 base::TimeDelta(), 0.f, | 428 base::TimeDelta(), 0.f, |
429 CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f))); | 429 CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f))); |
430 curve->AddKeyframe( | 430 curve->AddKeyframe( |
431 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr)); | 431 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr)); |
432 | 432 |
433 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 433 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
434 EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 434 EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
435 EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 435 EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
436 EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f, | 436 EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f, |
437 0.00015f); | 437 0.00015f); |
438 EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 438 EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
439 EXPECT_GT(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 439 EXPECT_GT(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
440 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 440 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
441 } | 441 } |
442 | 442 |
443 // Tests a step timing function if the change of values occur at the start. | 443 // Tests a step timing function if the change of values occur at the start. |
444 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtStart) { | 444 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtStart) { |
445 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 445 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
446 KeyframedFloatAnimationCurve::Create()); | 446 KeyframedFloatAnimationCurve::Create()); |
447 const int num_steps = 36; | 447 const int num_steps = 36; |
448 const float steps_start_offset = 1.0f; | 448 const float steps_start_offset = 1.0f; |
449 curve->AddKeyframe(FloatKeyframe::Create( | 449 curve->AddKeyframe(FloatKeyframe::Create( |
450 base::TimeDelta(), 0.f, | 450 base::TimeDelta(), 0.f, |
451 StepsTimingFunction::Create(num_steps, steps_start_offset))); | 451 StepsTimingFunction::Create(num_steps, steps_start_offset))); |
452 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 452 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
453 num_steps, nullptr)); | 453 num_steps, nullptr)); |
454 | 454 |
455 const float time_threshold = 0.0001f; | 455 const float time_threshold = 0.0001f; |
(...skipping 10 matching lines...) Expand all Loading... |
466 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); | 466 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); |
467 | 467 |
468 for (float i = 0.5f; i <= num_steps; i += 1.0f) { | 468 for (float i = 0.5f; i <= num_steps; i += 1.0f) { |
469 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | 469 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); |
470 EXPECT_FLOAT_EQ(std::ceil(i), curve->GetValue(time)); | 470 EXPECT_FLOAT_EQ(std::ceil(i), curve->GetValue(time)); |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 // Tests a step timing function if the change of values occur at the middle. | 474 // Tests a step timing function if the change of values occur at the middle. |
475 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtMiddle) { | 475 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtMiddle) { |
476 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 476 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
477 KeyframedFloatAnimationCurve::Create()); | 477 KeyframedFloatAnimationCurve::Create()); |
478 const int num_steps = 36; | 478 const int num_steps = 36; |
479 const float steps_start_offset = 0.5f; | 479 const float steps_start_offset = 0.5f; |
480 curve->AddKeyframe(FloatKeyframe::Create( | 480 curve->AddKeyframe(FloatKeyframe::Create( |
481 base::TimeDelta(), 0.f, | 481 base::TimeDelta(), 0.f, |
482 StepsTimingFunction::Create(num_steps, steps_start_offset))); | 482 StepsTimingFunction::Create(num_steps, steps_start_offset))); |
483 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 483 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
484 num_steps, nullptr)); | 484 num_steps, nullptr)); |
485 | 485 |
486 const float time_threshold = 0.0001f; | 486 const float time_threshold = 0.0001f; |
(...skipping 11 matching lines...) Expand all Loading... |
498 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); | 498 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); |
499 | 499 |
500 for (float i = 0.25f; i <= num_steps; i += 1.0f) { | 500 for (float i = 0.25f; i <= num_steps; i += 1.0f) { |
501 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | 501 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); |
502 EXPECT_FLOAT_EQ(std::floor(i), curve->GetValue(time)); | 502 EXPECT_FLOAT_EQ(std::floor(i), curve->GetValue(time)); |
503 } | 503 } |
504 } | 504 } |
505 | 505 |
506 // Tests a step timing function if the change of values occur at the end. | 506 // Tests a step timing function if the change of values occur at the end. |
507 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtEnd) { | 507 TEST(KeyframedAnimationCurveTest, StepsTimingFunctionStepAtEnd) { |
508 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 508 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
509 KeyframedFloatAnimationCurve::Create()); | 509 KeyframedFloatAnimationCurve::Create()); |
510 const int num_steps = 36; | 510 const int num_steps = 36; |
511 const float steps_start_offset = 0.0f; | 511 const float steps_start_offset = 0.0f; |
512 curve->AddKeyframe(FloatKeyframe::Create( | 512 curve->AddKeyframe(FloatKeyframe::Create( |
513 base::TimeDelta(), 0.f, | 513 base::TimeDelta(), 0.f, |
514 StepsTimingFunction::Create(num_steps, steps_start_offset))); | 514 StepsTimingFunction::Create(num_steps, steps_start_offset))); |
515 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | 515 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), |
516 num_steps, nullptr)); | 516 num_steps, nullptr)); |
517 | 517 |
518 const float time_threshold = 0.0001f; | 518 const float time_threshold = 0.0001f; |
(...skipping 11 matching lines...) Expand all Loading... |
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 that animated bounds are computed as expected. | 538 // Tests that animated bounds are computed as expected. |
539 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { | 539 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { |
540 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 540 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
541 KeyframedTransformAnimationCurve::Create()); | 541 KeyframedTransformAnimationCurve::Create()); |
542 | 542 |
543 TransformOperations operations1; | 543 TransformOperations operations1; |
544 curve->AddKeyframe( | 544 curve->AddKeyframe( |
545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
546 operations1.AppendTranslate(2.0, 3.0, -1.0); | 546 operations1.AppendTranslate(2.0, 3.0, -1.0); |
547 curve->AddKeyframe(TransformKeyframe::Create( | 547 curve->AddKeyframe(TransformKeyframe::Create( |
548 base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr)); | 548 base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr)); |
549 TransformOperations operations2; | 549 TransformOperations operations2; |
550 operations2.AppendTranslate(4.0, 1.0, 2.0); | 550 operations2.AppendTranslate(4.0, 1.0, 2.0); |
551 curve->AddKeyframe( | 551 curve->AddKeyframe( |
552 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations2, | 552 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations2, |
553 EaseTimingFunction::Create())); | 553 EaseTimingFunction::Create())); |
554 | 554 |
555 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); | 555 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); |
556 gfx::BoxF bounds; | 556 gfx::BoxF bounds; |
557 | 557 |
558 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); | 558 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); |
559 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), | 559 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), |
560 bounds.ToString()); | 560 bounds.ToString()); |
561 } | 561 } |
562 | 562 |
563 // Tests that animations that affect scale are correctly identified. | 563 // Tests that animations that affect scale are correctly identified. |
564 TEST(KeyframedAnimationCurveTest, AffectsScale) { | 564 TEST(KeyframedAnimationCurveTest, AffectsScale) { |
565 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 565 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
566 KeyframedTransformAnimationCurve::Create()); | 566 KeyframedTransformAnimationCurve::Create()); |
567 | 567 |
568 TransformOperations operations1; | 568 TransformOperations operations1; |
569 curve->AddKeyframe( | 569 curve->AddKeyframe( |
570 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 570 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
571 operations1.AppendTranslate(2.0, 3.0, -1.0); | 571 operations1.AppendTranslate(2.0, 3.0, -1.0); |
572 TransformOperations operations2; | 572 TransformOperations operations2; |
573 operations2.AppendTranslate(4.0, 1.0, 2.0); | 573 operations2.AppendTranslate(4.0, 1.0, 2.0); |
574 curve->AddKeyframe(TransformKeyframe::Create( | 574 curve->AddKeyframe(TransformKeyframe::Create( |
575 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr)); | 575 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr)); |
(...skipping 10 matching lines...) Expand all Loading... |
586 TransformOperations operations4; | 586 TransformOperations operations4; |
587 operations3.AppendTranslate(2.f, 2.f, 2.f); | 587 operations3.AppendTranslate(2.f, 2.f, 2.f); |
588 curve->AddKeyframe(TransformKeyframe::Create( | 588 curve->AddKeyframe(TransformKeyframe::Create( |
589 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr)); | 589 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr)); |
590 | 590 |
591 EXPECT_TRUE(curve->AffectsScale()); | 591 EXPECT_TRUE(curve->AffectsScale()); |
592 } | 592 } |
593 | 593 |
594 // Tests that animations that are translations are correctly identified. | 594 // Tests that animations that are translations are correctly identified. |
595 TEST(KeyframedAnimationCurveTest, IsTranslation) { | 595 TEST(KeyframedAnimationCurveTest, IsTranslation) { |
596 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 596 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
597 KeyframedTransformAnimationCurve::Create()); | 597 KeyframedTransformAnimationCurve::Create()); |
598 | 598 |
599 TransformOperations operations1; | 599 TransformOperations operations1; |
600 curve->AddKeyframe( | 600 curve->AddKeyframe( |
601 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 601 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
602 operations1.AppendTranslate(2.0, 3.0, -1.0); | 602 operations1.AppendTranslate(2.0, 3.0, -1.0); |
603 TransformOperations operations2; | 603 TransformOperations operations2; |
604 operations2.AppendTranslate(4.0, 1.0, 2.0); | 604 operations2.AppendTranslate(4.0, 1.0, 2.0); |
605 curve->AddKeyframe(TransformKeyframe::Create( | 605 curve->AddKeyframe(TransformKeyframe::Create( |
606 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr)); | 606 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr)); |
(...skipping 10 matching lines...) Expand all Loading... |
617 TransformOperations operations4; | 617 TransformOperations operations4; |
618 operations3.AppendTranslate(2.f, 2.f, 2.f); | 618 operations3.AppendTranslate(2.f, 2.f, 2.f); |
619 curve->AddKeyframe(TransformKeyframe::Create( | 619 curve->AddKeyframe(TransformKeyframe::Create( |
620 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr)); | 620 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr)); |
621 | 621 |
622 EXPECT_FALSE(curve->IsTranslation()); | 622 EXPECT_FALSE(curve->IsTranslation()); |
623 } | 623 } |
624 | 624 |
625 // Tests that maximum target scale is computed as expected. | 625 // Tests that maximum target scale is computed as expected. |
626 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) { | 626 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) { |
627 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 627 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
628 KeyframedTransformAnimationCurve::Create()); | 628 KeyframedTransformAnimationCurve::Create()); |
629 | 629 |
630 TransformOperations operations1; | 630 TransformOperations operations1; |
631 curve->AddKeyframe( | 631 curve->AddKeyframe( |
632 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 632 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
633 operations1.AppendScale(2.f, -3.f, 1.f); | 633 operations1.AppendScale(2.f, -3.f, 1.f); |
634 curve->AddKeyframe( | 634 curve->AddKeyframe( |
635 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, | 635 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, |
636 EaseTimingFunction::Create())); | 636 EaseTimingFunction::Create())); |
637 | 637 |
(...skipping 12 matching lines...) Expand all Loading... |
650 | 650 |
651 TransformOperations operations3; | 651 TransformOperations operations3; |
652 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); | 652 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); |
653 curve->AddKeyframe( | 653 curve->AddKeyframe( |
654 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, | 654 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, |
655 EaseTimingFunction::Create())); | 655 EaseTimingFunction::Create())); |
656 | 656 |
657 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale)); | 657 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale)); |
658 | 658 |
659 // The original scale is not used in computing the max. | 659 // The original scale is not used in computing the max. |
660 scoped_ptr<KeyframedTransformAnimationCurve> curve2( | 660 std::unique_ptr<KeyframedTransformAnimationCurve> curve2( |
661 KeyframedTransformAnimationCurve::Create()); | 661 KeyframedTransformAnimationCurve::Create()); |
662 | 662 |
663 TransformOperations operations4; | 663 TransformOperations operations4; |
664 operations4.AppendScale(0.4f, 0.2f, 0.6f); | 664 operations4.AppendScale(0.4f, 0.2f, 0.6f); |
665 curve2->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), operations4, | 665 curve2->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), operations4, |
666 EaseTimingFunction::Create())); | 666 EaseTimingFunction::Create())); |
667 TransformOperations operations5; | 667 TransformOperations operations5; |
668 operations5.AppendScale(0.5f, 0.3f, -0.8f); | 668 operations5.AppendScale(0.5f, 0.3f, -0.8f); |
669 curve2->AddKeyframe( | 669 curve2->AddKeyframe( |
670 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations5, | 670 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations5, |
671 EaseTimingFunction::Create())); | 671 EaseTimingFunction::Create())); |
672 | 672 |
673 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale)); | 673 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale)); |
674 EXPECT_EQ(0.8f, maximum_scale); | 674 EXPECT_EQ(0.8f, maximum_scale); |
675 | 675 |
676 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale)); | 676 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale)); |
677 EXPECT_EQ(0.6f, maximum_scale); | 677 EXPECT_EQ(0.6f, maximum_scale); |
678 } | 678 } |
679 | 679 |
680 // Tests that starting animation scale is computed as expected. | 680 // Tests that starting animation scale is computed as expected. |
681 TEST(KeyframedAnimationCurveTest, AnimationStartScale) { | 681 TEST(KeyframedAnimationCurveTest, AnimationStartScale) { |
682 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 682 std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
683 KeyframedTransformAnimationCurve::Create()); | 683 KeyframedTransformAnimationCurve::Create()); |
684 | 684 |
685 TransformOperations operations1; | 685 TransformOperations operations1; |
686 curve->AddKeyframe( | 686 curve->AddKeyframe( |
687 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 687 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
688 operations1.AppendScale(2.f, -3.f, 1.f); | 688 operations1.AppendScale(2.f, -3.f, 1.f); |
689 curve->AddKeyframe( | 689 curve->AddKeyframe( |
690 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, | 690 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1, |
691 EaseTimingFunction::Create())); | 691 EaseTimingFunction::Create())); |
692 | 692 |
(...skipping 26 matching lines...) Expand all Loading... |
719 curve->AddKeyframe( | 719 curve->AddKeyframe( |
720 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, | 720 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3, |
721 EaseTimingFunction::Create())); | 721 EaseTimingFunction::Create())); |
722 | 722 |
723 EXPECT_FALSE(curve->AnimationStartScale(false, &start_scale)); | 723 EXPECT_FALSE(curve->AnimationStartScale(false, &start_scale)); |
724 EXPECT_EQ(0.f, start_scale); | 724 EXPECT_EQ(0.f, start_scale); |
725 } | 725 } |
726 | 726 |
727 // Tests that an animation with a curve timing function works as expected. | 727 // Tests that an animation with a curve timing function works as expected. |
728 TEST(KeyframedAnimationCurveTest, CurveTiming) { | 728 TEST(KeyframedAnimationCurveTest, CurveTiming) { |
729 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 729 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
730 KeyframedFloatAnimationCurve::Create()); | 730 KeyframedFloatAnimationCurve::Create()); |
731 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 731 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
732 curve->AddKeyframe( | 732 curve->AddKeyframe( |
733 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 733 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
734 curve->SetTimingFunction( | 734 curve->SetTimingFunction( |
735 CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f)); | 735 CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f)); |
736 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 736 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
737 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 737 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
738 EXPECT_NEAR(0.05f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), | 738 EXPECT_NEAR(0.05f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), |
739 0.005f); | 739 0.005f); |
740 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 740 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
741 EXPECT_NEAR(0.95f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), | 741 EXPECT_NEAR(0.95f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
742 0.005f); | 742 0.005f); |
743 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 743 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
744 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 744 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
745 } | 745 } |
746 | 746 |
747 // Tests that an animation with a curve and keyframe timing function works as | 747 // Tests that an animation with a curve and keyframe timing function works as |
748 // expected. | 748 // expected. |
749 TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) { | 749 TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) { |
750 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 750 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
751 KeyframedFloatAnimationCurve::Create()); | 751 KeyframedFloatAnimationCurve::Create()); |
752 curve->AddKeyframe(FloatKeyframe::Create( | 752 curve->AddKeyframe(FloatKeyframe::Create( |
753 base::TimeDelta(), 0.f, | 753 base::TimeDelta(), 0.f, |
754 CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f))); | 754 CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f))); |
755 curve->AddKeyframe( | 755 curve->AddKeyframe( |
756 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 756 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
757 // Curve timing function producing outputs outside of range [0,1]. | 757 // Curve timing function producing outputs outside of range [0,1]. |
758 curve->SetTimingFunction( | 758 curve->SetTimingFunction( |
759 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 759 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
760 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 760 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
761 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 761 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
762 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD( | 762 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD( |
763 0.25f))); // Clamped. c(.25) < 0 | 763 0.25f))); // Clamped. c(.25) < 0 |
764 EXPECT_NEAR(0.17f, curve->GetValue(base::TimeDelta::FromSecondsD(0.42f)), | 764 EXPECT_NEAR(0.17f, curve->GetValue(base::TimeDelta::FromSecondsD(0.42f)), |
765 0.005f); // c(.42)=.27, k(.27)=.17 | 765 0.005f); // c(.42)=.27, k(.27)=.17 |
766 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); | 766 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f))); |
767 EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)), | 767 EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)), |
768 0.005f); // c(.58)=.73, k(.73)=.83 | 768 0.005f); // c(.58)=.73, k(.73)=.83 |
769 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD( | 769 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD( |
770 0.75f))); // Clamped. c(.75) > 1 | 770 0.75f))); // Clamped. c(.75) > 1 |
771 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 771 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
772 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 772 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
773 } | 773 } |
774 | 774 |
775 // Tests that a linear timing function works as expected for inputs outside of | 775 // Tests that a linear timing function works as expected for inputs outside of |
776 // range [0,1] | 776 // range [0,1] |
777 TEST(KeyframedAnimationCurveTest, LinearTimingInputsOutsideZeroOneRange) { | 777 TEST(KeyframedAnimationCurveTest, LinearTimingInputsOutsideZeroOneRange) { |
778 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 778 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
779 KeyframedFloatAnimationCurve::Create()); | 779 KeyframedFloatAnimationCurve::Create()); |
780 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 780 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
781 curve->AddKeyframe( | 781 curve->AddKeyframe( |
782 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); | 782 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
783 // Curve timing function producing timing outputs outside of range [0,1]. | 783 // Curve timing function producing timing outputs outside of range [0,1]. |
784 curve->SetTimingFunction( | 784 curve->SetTimingFunction( |
785 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 785 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
786 | 786 |
787 EXPECT_NEAR(-0.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), | 787 EXPECT_NEAR(-0.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), |
788 0.001f); | 788 0.001f); |
789 EXPECT_NEAR(2.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), | 789 EXPECT_NEAR(2.076f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
790 0.001f); | 790 0.001f); |
791 } | 791 } |
792 | 792 |
793 // If a curve cubic-bezier timing function produces timing outputs outside | 793 // If a curve cubic-bezier timing function produces timing outputs outside |
794 // the range [0, 1] then a keyframe cubic-bezier timing function | 794 // the range [0, 1] then a keyframe cubic-bezier timing function |
795 // should consume that input properly (using end-point gradients). | 795 // should consume that input properly (using end-point gradients). |
796 TEST(KeyframedAnimationCurveTest, CurveTimingInputsOutsideZeroOneRange) { | 796 TEST(KeyframedAnimationCurveTest, CurveTimingInputsOutsideZeroOneRange) { |
797 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 797 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
798 KeyframedFloatAnimationCurve::Create()); | 798 KeyframedFloatAnimationCurve::Create()); |
799 // Keyframe timing function with 0.5 gradients at each end. | 799 // Keyframe timing function with 0.5 gradients at each end. |
800 curve->AddKeyframe(FloatKeyframe::Create( | 800 curve->AddKeyframe(FloatKeyframe::Create( |
801 base::TimeDelta(), 0.f, | 801 base::TimeDelta(), 0.f, |
802 CubicBezierTimingFunction::Create(0.5f, 0.25f, 0.5f, 0.75f))); | 802 CubicBezierTimingFunction::Create(0.5f, 0.25f, 0.5f, 0.75f))); |
803 curve->AddKeyframe( | 803 curve->AddKeyframe( |
804 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 804 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
805 // Curve timing function producing timing outputs outside of range [0,1]. | 805 // Curve timing function producing timing outputs outside of range [0,1]. |
806 curve->SetTimingFunction( | 806 curve->SetTimingFunction( |
807 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 807 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
808 | 808 |
809 EXPECT_NEAR(-0.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), | 809 EXPECT_NEAR(-0.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)), |
810 0.002f); // c(.25)=-.04, -.04*0.5=-0.02 | 810 0.002f); // c(.25)=-.04, -.04*0.5=-0.02 |
811 EXPECT_NEAR(0.33f, curve->GetValue(base::TimeDelta::FromSecondsD(0.46f)), | 811 EXPECT_NEAR(0.33f, curve->GetValue(base::TimeDelta::FromSecondsD(0.46f)), |
812 0.002f); // c(.46)=.38, k(.38)=.33 | 812 0.002f); // c(.46)=.38, k(.38)=.33 |
813 | 813 |
814 EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), | 814 EXPECT_NEAR(0.67f, curve->GetValue(base::TimeDelta::FromSecondsD(0.54f)), |
815 0.002f); // c(.54)=.62, k(.62)=.67 | 815 0.002f); // c(.54)=.62, k(.62)=.67 |
816 EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), | 816 EXPECT_NEAR(1.02f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)), |
817 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 | 817 0.002f); // c(.75)=1.04 1+.04*0.5=1.02 |
818 } | 818 } |
819 | 819 |
820 // Tests that a step timing function works as expected for inputs outside of | 820 // Tests that a step timing function works as expected for inputs outside of |
821 // range [0,1] | 821 // range [0,1] |
822 TEST(KeyframedAnimationCurveTest, StepsTimingInputsOutsideZeroOneRange) { | 822 TEST(KeyframedAnimationCurveTest, StepsTimingInputsOutsideZeroOneRange) { |
823 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 823 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
824 KeyframedFloatAnimationCurve::Create()); | 824 KeyframedFloatAnimationCurve::Create()); |
825 curve->AddKeyframe(FloatKeyframe::Create( | 825 curve->AddKeyframe(FloatKeyframe::Create( |
826 base::TimeDelta(), 0.f, StepsTimingFunction::Create(4, 0.5f))); | 826 base::TimeDelta(), 0.f, StepsTimingFunction::Create(4, 0.5f))); |
827 curve->AddKeyframe( | 827 curve->AddKeyframe( |
828 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); | 828 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 2.f, nullptr)); |
829 // Curve timing function producing timing outputs outside of range [0,1]. | 829 // Curve timing function producing timing outputs outside of range [0,1]. |
830 curve->SetTimingFunction( | 830 curve->SetTimingFunction( |
831 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 831 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
832 | 832 |
833 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 833 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
834 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 834 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
835 } | 835 } |
836 | 836 |
837 // Tests that an animation with a curve timing function and multiple keyframes | 837 // Tests that an animation with a curve timing function and multiple keyframes |
838 // works as expected. | 838 // works as expected. |
839 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { | 839 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |
840 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 840 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
841 KeyframedFloatAnimationCurve::Create()); | 841 KeyframedFloatAnimationCurve::Create()); |
842 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 842 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
843 curve->AddKeyframe( | 843 curve->AddKeyframe( |
844 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); | 844 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr)); |
845 curve->AddKeyframe( | 845 curve->AddKeyframe( |
846 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); | 846 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr)); |
847 curve->AddKeyframe( | 847 curve->AddKeyframe( |
848 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), 6.f, nullptr)); | 848 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), 6.f, nullptr)); |
849 curve->AddKeyframe( | 849 curve->AddKeyframe( |
850 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.f), 9.f, nullptr)); | 850 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.f), 9.f, nullptr)); |
851 curve->SetTimingFunction( | 851 curve->SetTimingFunction( |
852 CubicBezierTimingFunction::Create(0.5f, 0.f, 0.5f, 1.f)); | 852 CubicBezierTimingFunction::Create(0.5f, 0.f, 0.5f, 1.f)); |
853 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); | 853 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f))); |
854 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 854 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
855 EXPECT_NEAR(0.42f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), | 855 EXPECT_NEAR(0.42f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), |
856 0.005f); | 856 0.005f); |
857 EXPECT_NEAR(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.455f)), | 857 EXPECT_NEAR(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.455f)), |
858 0.005f); | 858 0.005f); |
859 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); | 859 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f))); |
860 EXPECT_NEAR(8.72f, curve->GetValue(base::TimeDelta::FromSecondsD(3.5f)), | 860 EXPECT_NEAR(8.72f, curve->GetValue(base::TimeDelta::FromSecondsD(3.5f)), |
861 0.01f); | 861 0.01f); |
862 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(4.f))); | 862 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(4.f))); |
863 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(5.f))); | 863 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(5.f))); |
864 } | 864 } |
865 | 865 |
866 // Tests that an animation with a curve timing function that overshoots works as | 866 // Tests that an animation with a curve timing function that overshoots works as |
867 // expected. | 867 // expected. |
868 TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) { | 868 TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) { |
869 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 869 std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
870 KeyframedFloatAnimationCurve::Create()); | 870 KeyframedFloatAnimationCurve::Create()); |
871 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); | 871 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr)); |
872 curve->AddKeyframe( | 872 curve->AddKeyframe( |
873 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr)); | 873 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr)); |
874 curve->AddKeyframe( | 874 curve->AddKeyframe( |
875 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 3.f, nullptr)); | 875 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 3.f, nullptr)); |
876 curve->AddKeyframe( | 876 curve->AddKeyframe( |
877 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.0), 6.f, nullptr)); | 877 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.0), 6.f, nullptr)); |
878 curve->AddKeyframe( | 878 curve->AddKeyframe( |
879 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.0), 9.f, nullptr)); | 879 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.0), 9.f, nullptr)); |
880 // Curve timing function producing outputs outside of range [0,1]. | 880 // Curve timing function producing outputs outside of range [0,1]. |
881 curve->SetTimingFunction( | 881 curve->SetTimingFunction( |
882 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); | 882 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f)); |
883 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), | 883 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), |
884 0.f); // c(.25) < 0 | 884 0.f); // c(.25) < 0 |
885 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), | 885 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), |
886 9.f); // c(.75) > 1 | 886 9.f); // c(.75) > 1 |
887 } | 887 } |
888 | 888 |
889 } // namespace | 889 } // namespace |
890 } // namespace cc | 890 } // namespace cc |
OLD | NEW |