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

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

Issue 719453007: Make Keyframe use TimeTicks/TimeDelta to represent time instead of double. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/animation/layer_animation_controller.cc » ('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 11 matching lines...) Expand all
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 scoped_ptr<KeyframedColorAnimationCurve> curve(
31 KeyframedColorAnimationCurve::Create()); 31 KeyframedColorAnimationCurve::Create());
32 curve->AddKeyframe(ColorKeyframe::Create(0.0, color, nullptr)); 32 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta(), color, nullptr));
33 33
34 EXPECT_SKCOLOR_EQ(color, curve->GetValue(-1.f)); 34 EXPECT_SKCOLOR_EQ(color,
35 EXPECT_SKCOLOR_EQ(color, curve->GetValue(0.f)); 35 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
36 EXPECT_SKCOLOR_EQ(color, curve->GetValue(0.5f)); 36 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
37 EXPECT_SKCOLOR_EQ(color, curve->GetValue(1.f)); 37 EXPECT_SKCOLOR_EQ(color,
38 EXPECT_SKCOLOR_EQ(color, curve->GetValue(2.f)); 38 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
39 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
40 EXPECT_SKCOLOR_EQ(color, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
39 } 41 }
40 42
41 // Tests that a color animation with two keyframes works as expected. 43 // Tests that a color animation with two keyframes works as expected.
42 TEST(KeyframedAnimationCurveTest, TwoColorKeyFrame) { 44 TEST(KeyframedAnimationCurveTest, TwoColorKeyFrame) {
43 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); 45 SkColor color_a = SkColorSetARGB(255, 255, 0, 0);
44 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); 46 SkColor color_b = SkColorSetARGB(255, 0, 255, 0);
45 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);
46 scoped_ptr<KeyframedColorAnimationCurve> curve( 48 scoped_ptr<KeyframedColorAnimationCurve> curve(
47 KeyframedColorAnimationCurve::Create()); 49 KeyframedColorAnimationCurve::Create());
48 curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr)); 50 curve->AddKeyframe(
49 curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr)); 51 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
52 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
53 color_b, nullptr));
50 54
51 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f)); 55 EXPECT_SKCOLOR_EQ(color_a,
52 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f)); 56 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
53 EXPECT_SKCOLOR_EQ(color_midpoint, curve->GetValue(0.5f)); 57 EXPECT_SKCOLOR_EQ(color_a,
54 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.f)); 58 curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
55 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(2.f)); 59 EXPECT_SKCOLOR_EQ(color_midpoint,
60 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
61 EXPECT_SKCOLOR_EQ(color_b,
62 curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
63 EXPECT_SKCOLOR_EQ(color_b,
64 curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
56 } 65 }
57 66
58 // Tests that a color animation with three keyframes works as expected. 67 // Tests that a color animation with three keyframes works as expected.
59 TEST(KeyframedAnimationCurveTest, ThreeColorKeyFrame) { 68 TEST(KeyframedAnimationCurveTest, ThreeColorKeyFrame) {
60 SkColor color_a = SkColorSetARGB(255, 255, 0, 0); 69 SkColor color_a = SkColorSetARGB(255, 255, 0, 0);
61 SkColor color_b = SkColorSetARGB(255, 0, 255, 0); 70 SkColor color_b = SkColorSetARGB(255, 0, 255, 0);
62 SkColor color_c = SkColorSetARGB(255, 0, 0, 255); 71 SkColor color_c = SkColorSetARGB(255, 0, 0, 255);
63 SkColor color_midpoint1 = 72 SkColor color_midpoint1 =
64 gfx::Tween::ColorValueBetween(0.5, color_a, color_b); 73 gfx::Tween::ColorValueBetween(0.5, color_a, color_b);
65 SkColor color_midpoint2 = 74 SkColor color_midpoint2 =
66 gfx::Tween::ColorValueBetween(0.5, color_b, color_c); 75 gfx::Tween::ColorValueBetween(0.5, color_b, color_c);
67 scoped_ptr<KeyframedColorAnimationCurve> curve( 76 scoped_ptr<KeyframedColorAnimationCurve> curve(
68 KeyframedColorAnimationCurve::Create()); 77 KeyframedColorAnimationCurve::Create());
69 curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr)); 78 curve->AddKeyframe(
70 curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr)); 79 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
71 curve->AddKeyframe(ColorKeyframe::Create(2.0, color_c, nullptr)); 80 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
81 color_b, nullptr));
82 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
83 color_c, nullptr));
72 84
73 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f)); 85 EXPECT_SKCOLOR_EQ(color_a,
74 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f)); 86 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
75 EXPECT_SKCOLOR_EQ(color_midpoint1, curve->GetValue(0.5f)); 87 EXPECT_SKCOLOR_EQ(color_a,
76 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.f)); 88 curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
77 EXPECT_SKCOLOR_EQ(color_midpoint2, curve->GetValue(1.5f)); 89 EXPECT_SKCOLOR_EQ(color_midpoint1,
78 EXPECT_SKCOLOR_EQ(color_c, curve->GetValue(2.f)); 90 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
79 EXPECT_SKCOLOR_EQ(color_c, curve->GetValue(3.f)); 91 EXPECT_SKCOLOR_EQ(color_b,
92 curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
93 EXPECT_SKCOLOR_EQ(color_midpoint2,
94 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
95 EXPECT_SKCOLOR_EQ(color_c,
96 curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
97 EXPECT_SKCOLOR_EQ(color_c,
98 curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
80 } 99 }
81 100
82 // 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.
83 TEST(KeyframedAnimationCurveTest, RepeatedColorKeyFrame) { 102 TEST(KeyframedAnimationCurveTest, RepeatedColorKeyFrame) {
84 SkColor color_a = SkColorSetARGB(255, 64, 0, 0); 103 SkColor color_a = SkColorSetARGB(255, 64, 0, 0);
85 SkColor color_b = SkColorSetARGB(255, 192, 0, 0); 104 SkColor color_b = SkColorSetARGB(255, 192, 0, 0);
86 105
87 scoped_ptr<KeyframedColorAnimationCurve> curve( 106 scoped_ptr<KeyframedColorAnimationCurve> curve(
88 KeyframedColorAnimationCurve::Create()); 107 KeyframedColorAnimationCurve::Create());
89 curve->AddKeyframe(ColorKeyframe::Create(0.0, color_a, nullptr)); 108 curve->AddKeyframe(
90 curve->AddKeyframe(ColorKeyframe::Create(1.0, color_a, nullptr)); 109 ColorKeyframe::Create(base::TimeDelta(), color_a, nullptr));
91 curve->AddKeyframe(ColorKeyframe::Create(1.0, color_b, nullptr)); 110 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
92 curve->AddKeyframe(ColorKeyframe::Create(2.0, color_b, nullptr)); 111 color_a, nullptr));
112 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(1.0),
113 color_b, nullptr));
114 curve->AddKeyframe(ColorKeyframe::Create(base::TimeDelta::FromSecondsD(2.0),
115 color_b, nullptr));
93 116
94 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(-1.f)); 117 EXPECT_SKCOLOR_EQ(color_a,
95 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.f)); 118 curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
96 EXPECT_SKCOLOR_EQ(color_a, curve->GetValue(0.5f)); 119 EXPECT_SKCOLOR_EQ(color_a,
120 curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
121 EXPECT_SKCOLOR_EQ(color_a,
122 curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
97 123
98 SkColor value = curve->GetValue(1.0f); 124 SkColor value = curve->GetValue(base::TimeDelta::FromSecondsD(1.0f));
99 EXPECT_EQ(255u, SkColorGetA(value)); 125 EXPECT_EQ(255u, SkColorGetA(value));
100 int red_value = SkColorGetR(value); 126 int red_value = SkColorGetR(value);
101 EXPECT_LE(64, red_value); 127 EXPECT_LE(64, red_value);
102 EXPECT_GE(192, red_value); 128 EXPECT_GE(192, red_value);
103 129
104 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(1.5f)); 130 EXPECT_SKCOLOR_EQ(color_b,
105 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(2.f)); 131 curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
106 EXPECT_SKCOLOR_EQ(color_b, curve->GetValue(3.f)); 132 EXPECT_SKCOLOR_EQ(color_b,
133 curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
134 EXPECT_SKCOLOR_EQ(color_b,
135 curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
107 } 136 }
108 137
109 // Tests that a float animation with one keyframe works as expected. 138 // Tests that a float animation with one keyframe works as expected.
110 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) { 139 TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) {
111 scoped_ptr<KeyframedFloatAnimationCurve> curve( 140 scoped_ptr<KeyframedFloatAnimationCurve> curve(
112 KeyframedFloatAnimationCurve::Create()); 141 KeyframedFloatAnimationCurve::Create());
113 curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr)); 142 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
114 EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f)); 143 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
115 EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f)); 144 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
116 EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.5f)); 145 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
117 EXPECT_FLOAT_EQ(2.f, curve->GetValue(1.f)); 146 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
118 EXPECT_FLOAT_EQ(2.f, curve->GetValue(2.f)); 147 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
119 } 148 }
120 149
121 // Tests that a float animation with two keyframes works as expected. 150 // Tests that a float animation with two keyframes works as expected.
122 TEST(KeyframedAnimationCurveTest, TwoFloatKeyframe) { 151 TEST(KeyframedAnimationCurveTest, TwoFloatKeyframe) {
123 scoped_ptr<KeyframedFloatAnimationCurve> curve( 152 scoped_ptr<KeyframedFloatAnimationCurve> curve(
124 KeyframedFloatAnimationCurve::Create()); 153 KeyframedFloatAnimationCurve::Create());
125 curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr)); 154 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
126 curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr)); 155 curve->AddKeyframe(
127 EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f)); 156 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
128 EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f)); 157 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
129 EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f)); 158 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
130 EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f)); 159 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
131 EXPECT_FLOAT_EQ(4.f, curve->GetValue(2.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)));
132 } 162 }
133 163
134 // Tests that a float animation with three keyframes works as expected. 164 // Tests that a float animation with three keyframes works as expected.
135 TEST(KeyframedAnimationCurveTest, ThreeFloatKeyframe) { 165 TEST(KeyframedAnimationCurveTest, ThreeFloatKeyframe) {
136 scoped_ptr<KeyframedFloatAnimationCurve> curve( 166 scoped_ptr<KeyframedFloatAnimationCurve> curve(
137 KeyframedFloatAnimationCurve::Create()); 167 KeyframedFloatAnimationCurve::Create());
138 curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr)); 168 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
139 curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr)); 169 curve->AddKeyframe(
140 curve->AddKeyframe(FloatKeyframe::Create(2.0, 8.f, nullptr)); 170 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
141 EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f)); 171 curve->AddKeyframe(
142 EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f)); 172 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 8.f, nullptr));
143 EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f)); 173 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
144 EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f)); 174 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
145 EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f)); 175 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
146 EXPECT_FLOAT_EQ(8.f, curve->GetValue(2.f)); 176 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
147 EXPECT_FLOAT_EQ(8.f, curve->GetValue(3.f)); 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)));
179 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
148 } 180 }
149 181
150 // 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.
151 TEST(KeyframedAnimationCurveTest, RepeatedFloatKeyTimes) { 183 TEST(KeyframedAnimationCurveTest, RepeatedFloatKeyTimes) {
152 scoped_ptr<KeyframedFloatAnimationCurve> curve( 184 scoped_ptr<KeyframedFloatAnimationCurve> curve(
153 KeyframedFloatAnimationCurve::Create()); 185 KeyframedFloatAnimationCurve::Create());
154 curve->AddKeyframe(FloatKeyframe::Create(0.0, 4.f, nullptr)); 186 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 4.f, nullptr));
155 curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr)); 187 curve->AddKeyframe(
156 curve->AddKeyframe(FloatKeyframe::Create(1.0, 6.f, nullptr)); 188 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 4.f, nullptr));
157 curve->AddKeyframe(FloatKeyframe::Create(2.0, 6.f, nullptr)); 189 curve->AddKeyframe(
190 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 6.f, nullptr));
191 curve->AddKeyframe(
192 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 6.f, nullptr));
158 193
159 EXPECT_FLOAT_EQ(4.f, curve->GetValue(-1.f)); 194 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
160 EXPECT_FLOAT_EQ(4.f, curve->GetValue(0.f)); 195 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
161 EXPECT_FLOAT_EQ(4.f, curve->GetValue(0.5f)); 196 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
162 197
163 // 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.
164 float value = curve->GetValue(1.f); 199 float value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
165 EXPECT_TRUE(value >= 4 && value <= 6); 200 EXPECT_TRUE(value >= 4 && value <= 6);
166 201
167 EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f)); 202 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
168 EXPECT_FLOAT_EQ(6.f, curve->GetValue(2.f)); 203 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
169 EXPECT_FLOAT_EQ(6.f, curve->GetValue(3.f)); 204 EXPECT_FLOAT_EQ(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
170 } 205 }
171 206
172 // Tests that a transform animation with one keyframe works as expected. 207 // Tests that a transform animation with one keyframe works as expected.
173 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) { 208 TEST(KeyframedAnimationCurveTest, OneTransformKeyframe) {
174 scoped_ptr<KeyframedTransformAnimationCurve> curve( 209 scoped_ptr<KeyframedTransformAnimationCurve> curve(
175 KeyframedTransformAnimationCurve::Create()); 210 KeyframedTransformAnimationCurve::Create());
176 TransformOperations operations; 211 TransformOperations operations;
177 operations.AppendTranslate(2.f, 0.f, 0.f); 212 operations.AppendTranslate(2.f, 0.f, 0.f);
178 curve->AddKeyframe(TransformKeyframe::Create(0.f, operations, nullptr)); 213 curve->AddKeyframe(
214 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
179 215
180 ExpectTranslateX(2.f, curve->GetValue(-1.f)); 216 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
181 ExpectTranslateX(2.f, curve->GetValue(0.f)); 217 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
182 ExpectTranslateX(2.f, curve->GetValue(0.5f)); 218 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
183 ExpectTranslateX(2.f, curve->GetValue(1.f)); 219 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
184 ExpectTranslateX(2.f, curve->GetValue(2.f)); 220 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
185 } 221 }
186 222
187 // Tests that a transform animation with two keyframes works as expected. 223 // Tests that a transform animation with two keyframes works as expected.
188 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) { 224 TEST(KeyframedAnimationCurveTest, TwoTransformKeyframe) {
189 scoped_ptr<KeyframedTransformAnimationCurve> curve( 225 scoped_ptr<KeyframedTransformAnimationCurve> curve(
190 KeyframedTransformAnimationCurve::Create()); 226 KeyframedTransformAnimationCurve::Create());
191 TransformOperations operations1; 227 TransformOperations operations1;
192 operations1.AppendTranslate(2.f, 0.f, 0.f); 228 operations1.AppendTranslate(2.f, 0.f, 0.f);
193 TransformOperations operations2; 229 TransformOperations operations2;
194 operations2.AppendTranslate(4.f, 0.f, 0.f); 230 operations2.AppendTranslate(4.f, 0.f, 0.f);
195 231
196 curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr)); 232 curve->AddKeyframe(
197 curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr)); 233 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
198 ExpectTranslateX(2.f, curve->GetValue(-1.f)); 234 curve->AddKeyframe(TransformKeyframe::Create(
199 ExpectTranslateX(2.f, curve->GetValue(0.f)); 235 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
200 ExpectTranslateX(3.f, curve->GetValue(0.5f)); 236 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
201 ExpectTranslateX(4.f, curve->GetValue(1.f)); 237 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
202 ExpectTranslateX(4.f, curve->GetValue(2.f)); 238 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
239 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
240 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
203 } 241 }
204 242
205 // Tests that a transform animation with three keyframes works as expected. 243 // Tests that a transform animation with three keyframes works as expected.
206 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) { 244 TEST(KeyframedAnimationCurveTest, ThreeTransformKeyframe) {
207 scoped_ptr<KeyframedTransformAnimationCurve> curve( 245 scoped_ptr<KeyframedTransformAnimationCurve> curve(
208 KeyframedTransformAnimationCurve::Create()); 246 KeyframedTransformAnimationCurve::Create());
209 TransformOperations operations1; 247 TransformOperations operations1;
210 operations1.AppendTranslate(2.f, 0.f, 0.f); 248 operations1.AppendTranslate(2.f, 0.f, 0.f);
211 TransformOperations operations2; 249 TransformOperations operations2;
212 operations2.AppendTranslate(4.f, 0.f, 0.f); 250 operations2.AppendTranslate(4.f, 0.f, 0.f);
213 TransformOperations operations3; 251 TransformOperations operations3;
214 operations3.AppendTranslate(8.f, 0.f, 0.f); 252 operations3.AppendTranslate(8.f, 0.f, 0.f);
215 curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr)); 253 curve->AddKeyframe(
216 curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr)); 254 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
217 curve->AddKeyframe(TransformKeyframe::Create(2.f, operations3, nullptr)); 255 curve->AddKeyframe(TransformKeyframe::Create(
218 ExpectTranslateX(2.f, curve->GetValue(-1.f)); 256 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
219 ExpectTranslateX(2.f, curve->GetValue(0.f)); 257 curve->AddKeyframe(TransformKeyframe::Create(
220 ExpectTranslateX(3.f, curve->GetValue(0.5f)); 258 base::TimeDelta::FromSecondsD(2.0), operations3, nullptr));
221 ExpectTranslateX(4.f, curve->GetValue(1.f)); 259 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
222 ExpectTranslateX(6.f, curve->GetValue(1.5f)); 260 ExpectTranslateX(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
223 ExpectTranslateX(8.f, curve->GetValue(2.f)); 261 ExpectTranslateX(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
224 ExpectTranslateX(8.f, curve->GetValue(3.f)); 262 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
263 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
264 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
265 ExpectTranslateX(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
225 } 266 }
226 267
227 // 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
228 // sanely. 269 // sanely.
229 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) { 270 TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) {
230 scoped_ptr<KeyframedTransformAnimationCurve> curve( 271 scoped_ptr<KeyframedTransformAnimationCurve> curve(
231 KeyframedTransformAnimationCurve::Create()); 272 KeyframedTransformAnimationCurve::Create());
232 // A step function. 273 // A step function.
233 TransformOperations operations1; 274 TransformOperations operations1;
234 operations1.AppendTranslate(4.f, 0.f, 0.f); 275 operations1.AppendTranslate(4.f, 0.f, 0.f);
235 TransformOperations operations2; 276 TransformOperations operations2;
236 operations2.AppendTranslate(4.f, 0.f, 0.f); 277 operations2.AppendTranslate(4.f, 0.f, 0.f);
237 TransformOperations operations3; 278 TransformOperations operations3;
238 operations3.AppendTranslate(6.f, 0.f, 0.f); 279 operations3.AppendTranslate(6.f, 0.f, 0.f);
239 TransformOperations operations4; 280 TransformOperations operations4;
240 operations4.AppendTranslate(6.f, 0.f, 0.f); 281 operations4.AppendTranslate(6.f, 0.f, 0.f);
241 curve->AddKeyframe(TransformKeyframe::Create(0.f, operations1, nullptr)); 282 curve->AddKeyframe(
242 curve->AddKeyframe(TransformKeyframe::Create(1.f, operations2, nullptr)); 283 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
243 curve->AddKeyframe(TransformKeyframe::Create(1.f, operations3, nullptr)); 284 curve->AddKeyframe(TransformKeyframe::Create(
244 curve->AddKeyframe(TransformKeyframe::Create(2.f, operations4, nullptr)); 285 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
286 curve->AddKeyframe(TransformKeyframe::Create(
287 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
288 curve->AddKeyframe(TransformKeyframe::Create(
289 base::TimeDelta::FromSecondsD(2.0), operations4, nullptr));
245 290
246 ExpectTranslateX(4.f, curve->GetValue(-1.f)); 291 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
247 ExpectTranslateX(4.f, curve->GetValue(0.f)); 292 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
248 ExpectTranslateX(4.f, curve->GetValue(0.5f)); 293 ExpectTranslateX(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
249 294
250 // There is a discontinuity at 1. Any value between 4 and 6 is valid. 295 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
251 gfx::Transform value = curve->GetValue(1.f); 296 gfx::Transform value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
252 EXPECT_GE(value.matrix().get(0, 3), 4.f); 297 EXPECT_GE(value.matrix().get(0, 3), 4.f);
253 EXPECT_LE(value.matrix().get(0, 3), 6.f); 298 EXPECT_LE(value.matrix().get(0, 3), 6.f);
254 299
255 ExpectTranslateX(6.f, curve->GetValue(1.5f)); 300 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
256 ExpectTranslateX(6.f, curve->GetValue(2.f)); 301 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
257 ExpectTranslateX(6.f, curve->GetValue(3.f)); 302 ExpectTranslateX(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
258 } 303 }
259 304
260 // Tests that a filter animation with one keyframe works as expected. 305 // Tests that a filter animation with one keyframe works as expected.
261 TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) { 306 TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) {
262 scoped_ptr<KeyframedFilterAnimationCurve> curve( 307 scoped_ptr<KeyframedFilterAnimationCurve> curve(
263 KeyframedFilterAnimationCurve::Create()); 308 KeyframedFilterAnimationCurve::Create());
264 FilterOperations operations; 309 FilterOperations operations;
265 operations.Append(FilterOperation::CreateBrightnessFilter(2.f)); 310 operations.Append(FilterOperation::CreateBrightnessFilter(2.f));
266 curve->AddKeyframe(FilterKeyframe::Create(0.f, operations, nullptr)); 311 curve->AddKeyframe(
312 FilterKeyframe::Create(base::TimeDelta(), operations, nullptr));
267 313
268 ExpectBrightness(2.f, curve->GetValue(-1.f)); 314 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
269 ExpectBrightness(2.f, curve->GetValue(0.f)); 315 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
270 ExpectBrightness(2.f, curve->GetValue(0.5f)); 316 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
271 ExpectBrightness(2.f, curve->GetValue(1.f)); 317 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
272 ExpectBrightness(2.f, curve->GetValue(2.f)); 318 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
273 } 319 }
274 320
275 // Tests that a filter animation with two keyframes works as expected. 321 // Tests that a filter animation with two keyframes works as expected.
276 TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) { 322 TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) {
277 scoped_ptr<KeyframedFilterAnimationCurve> curve( 323 scoped_ptr<KeyframedFilterAnimationCurve> curve(
278 KeyframedFilterAnimationCurve::Create()); 324 KeyframedFilterAnimationCurve::Create());
279 FilterOperations operations1; 325 FilterOperations operations1;
280 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); 326 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f));
281 FilterOperations operations2; 327 FilterOperations operations2;
282 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); 328 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f));
283 329
284 curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr)); 330 curve->AddKeyframe(
285 curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr)); 331 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
286 ExpectBrightness(2.f, curve->GetValue(-1.f)); 332 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
287 ExpectBrightness(2.f, curve->GetValue(0.f)); 333 operations2, nullptr));
288 ExpectBrightness(3.f, curve->GetValue(0.5f)); 334 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
289 ExpectBrightness(4.f, curve->GetValue(1.f)); 335 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
290 ExpectBrightness(4.f, curve->GetValue(2.f)); 336 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
337 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
338 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
291 } 339 }
292 340
293 // Tests that a filter animation with three keyframes works as expected. 341 // Tests that a filter animation with three keyframes works as expected.
294 TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) { 342 TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) {
295 scoped_ptr<KeyframedFilterAnimationCurve> curve( 343 scoped_ptr<KeyframedFilterAnimationCurve> curve(
296 KeyframedFilterAnimationCurve::Create()); 344 KeyframedFilterAnimationCurve::Create());
297 FilterOperations operations1; 345 FilterOperations operations1;
298 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); 346 operations1.Append(FilterOperation::CreateBrightnessFilter(2.f));
299 FilterOperations operations2; 347 FilterOperations operations2;
300 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); 348 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f));
301 FilterOperations operations3; 349 FilterOperations operations3;
302 operations3.Append(FilterOperation::CreateBrightnessFilter(8.f)); 350 operations3.Append(FilterOperation::CreateBrightnessFilter(8.f));
303 curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr)); 351 curve->AddKeyframe(
304 curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr)); 352 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
305 curve->AddKeyframe(FilterKeyframe::Create(2.f, operations3, nullptr)); 353 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
306 ExpectBrightness(2.f, curve->GetValue(-1.f)); 354 operations2, nullptr));
307 ExpectBrightness(2.f, curve->GetValue(0.f)); 355 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f),
308 ExpectBrightness(3.f, curve->GetValue(0.5f)); 356 operations3, nullptr));
309 ExpectBrightness(4.f, curve->GetValue(1.f)); 357 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
310 ExpectBrightness(6.f, curve->GetValue(1.5f)); 358 ExpectBrightness(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
311 ExpectBrightness(8.f, curve->GetValue(2.f)); 359 ExpectBrightness(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
312 ExpectBrightness(8.f, curve->GetValue(3.f)); 360 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
361 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
362 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
363 ExpectBrightness(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
313 } 364 }
314 365
315 // 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
316 // sanely. 367 // sanely.
317 TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) { 368 TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) {
318 scoped_ptr<KeyframedFilterAnimationCurve> curve( 369 scoped_ptr<KeyframedFilterAnimationCurve> curve(
319 KeyframedFilterAnimationCurve::Create()); 370 KeyframedFilterAnimationCurve::Create());
320 // A step function. 371 // A step function.
321 FilterOperations operations1; 372 FilterOperations operations1;
322 operations1.Append(FilterOperation::CreateBrightnessFilter(4.f)); 373 operations1.Append(FilterOperation::CreateBrightnessFilter(4.f));
323 FilterOperations operations2; 374 FilterOperations operations2;
324 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); 375 operations2.Append(FilterOperation::CreateBrightnessFilter(4.f));
325 FilterOperations operations3; 376 FilterOperations operations3;
326 operations3.Append(FilterOperation::CreateBrightnessFilter(6.f)); 377 operations3.Append(FilterOperation::CreateBrightnessFilter(6.f));
327 FilterOperations operations4; 378 FilterOperations operations4;
328 operations4.Append(FilterOperation::CreateBrightnessFilter(6.f)); 379 operations4.Append(FilterOperation::CreateBrightnessFilter(6.f));
329 curve->AddKeyframe(FilterKeyframe::Create(0.f, operations1, nullptr)); 380 curve->AddKeyframe(
330 curve->AddKeyframe(FilterKeyframe::Create(1.f, operations2, nullptr)); 381 FilterKeyframe::Create(base::TimeDelta(), operations1, nullptr));
331 curve->AddKeyframe(FilterKeyframe::Create(1.f, operations3, nullptr)); 382 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
332 curve->AddKeyframe(FilterKeyframe::Create(2.f, operations4, nullptr)); 383 operations2, nullptr));
384 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.f),
385 operations3, nullptr));
386 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(2.f),
387 operations4, nullptr));
333 388
334 ExpectBrightness(4.f, curve->GetValue(-1.f)); 389 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
335 ExpectBrightness(4.f, curve->GetValue(0.f)); 390 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
336 ExpectBrightness(4.f, curve->GetValue(0.5f)); 391 ExpectBrightness(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
337 392
338 // There is a discontinuity at 1. Any value between 4 and 6 is valid. 393 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
339 FilterOperations value = curve->GetValue(1.f); 394 FilterOperations value = curve->GetValue(base::TimeDelta::FromSecondsD(1.f));
340 EXPECT_EQ(1u, value.size()); 395 EXPECT_EQ(1u, value.size());
341 EXPECT_EQ(FilterOperation::BRIGHTNESS, value.at(0).type()); 396 EXPECT_EQ(FilterOperation::BRIGHTNESS, value.at(0).type());
342 EXPECT_GE(value.at(0).amount(), 4); 397 EXPECT_GE(value.at(0).amount(), 4);
343 EXPECT_LE(value.at(0).amount(), 6); 398 EXPECT_LE(value.at(0).amount(), 6);
344 399
345 ExpectBrightness(6.f, curve->GetValue(1.5f)); 400 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.5f)));
346 ExpectBrightness(6.f, curve->GetValue(2.f)); 401 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
347 ExpectBrightness(6.f, curve->GetValue(3.f)); 402 ExpectBrightness(6.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
348 } 403 }
349 404
350 // Tests that the keyframes may be added out of order. 405 // Tests that the keyframes may be added out of order.
351 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) { 406 TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) {
352 scoped_ptr<KeyframedFloatAnimationCurve> curve( 407 scoped_ptr<KeyframedFloatAnimationCurve> curve(
353 KeyframedFloatAnimationCurve::Create()); 408 KeyframedFloatAnimationCurve::Create());
354 curve->AddKeyframe(FloatKeyframe::Create(2.0, 8.f, nullptr)); 409 curve->AddKeyframe(
355 curve->AddKeyframe(FloatKeyframe::Create(0.0, 2.f, nullptr)); 410 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 8.f, nullptr));
356 curve->AddKeyframe(FloatKeyframe::Create(1.0, 4.f, nullptr)); 411 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 2.f, nullptr));
357 EXPECT_FLOAT_EQ(2.f, curve->GetValue(-1.f)); 412 curve->AddKeyframe(
358 EXPECT_FLOAT_EQ(2.f, curve->GetValue(0.f)); 413 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 4.f, nullptr));
359 EXPECT_FLOAT_EQ(3.f, curve->GetValue(0.5f)); 414 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
360 EXPECT_FLOAT_EQ(4.f, curve->GetValue(1.f)); 415 EXPECT_FLOAT_EQ(2.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
361 EXPECT_FLOAT_EQ(6.f, curve->GetValue(1.5f)); 416 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
362 EXPECT_FLOAT_EQ(8.f, curve->GetValue(2.f)); 417 EXPECT_FLOAT_EQ(4.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
363 EXPECT_FLOAT_EQ(8.f, curve->GetValue(3.f)); 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)));
420 EXPECT_FLOAT_EQ(8.f, curve->GetValue(base::TimeDelta::FromSecondsD(3.f)));
364 } 421 }
365 422
366 // Tests that a cubic bezier timing function works as expected. 423 // Tests that a cubic bezier timing function works as expected.
367 TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) { 424 TEST(KeyframedAnimationCurveTest, CubicBezierTimingFunction) {
368 scoped_ptr<KeyframedFloatAnimationCurve> curve( 425 scoped_ptr<KeyframedFloatAnimationCurve> curve(
369 KeyframedFloatAnimationCurve::Create()); 426 KeyframedFloatAnimationCurve::Create());
370 curve->AddKeyframe(FloatKeyframe::Create( 427 curve->AddKeyframe(FloatKeyframe::Create(
371 0.0, 0.f, CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f))); 428 base::TimeDelta(), 0.f,
372 curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr)); 429 CubicBezierTimingFunction::Create(0.25f, 0.f, 0.75f, 1.f)));
430 curve->AddKeyframe(
431 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr));
373 432
374 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); 433 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
375 EXPECT_LT(0.f, curve->GetValue(0.25f)); 434 EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
376 EXPECT_GT(0.25f, curve->GetValue(0.25f)); 435 EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)));
377 EXPECT_NEAR(curve->GetValue(0.5f), 0.5f, 0.00015f); 436 EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f,
378 EXPECT_LT(0.75f, curve->GetValue(0.75f)); 437 0.00015f);
379 EXPECT_GT(1.f, curve->GetValue(0.75f)); 438 EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)));
380 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); 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)));
381 } 441 }
382 442
383 // Tests that animated bounds are computed as expected. 443 // Tests that animated bounds are computed as expected.
384 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { 444 TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
385 scoped_ptr<KeyframedTransformAnimationCurve> curve( 445 scoped_ptr<KeyframedTransformAnimationCurve> curve(
386 KeyframedTransformAnimationCurve::Create()); 446 KeyframedTransformAnimationCurve::Create());
387 447
388 TransformOperations operations1; 448 TransformOperations operations1;
389 curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr)); 449 curve->AddKeyframe(
450 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
390 operations1.AppendTranslate(2.0, 3.0, -1.0); 451 operations1.AppendTranslate(2.0, 3.0, -1.0);
391 curve->AddKeyframe(TransformKeyframe::Create(0.5, operations1, nullptr)); 452 curve->AddKeyframe(TransformKeyframe::Create(
453 base::TimeDelta::FromSecondsD(0.5f), operations1, nullptr));
392 TransformOperations operations2; 454 TransformOperations operations2;
393 operations2.AppendTranslate(4.0, 1.0, 2.0); 455 operations2.AppendTranslate(4.0, 1.0, 2.0);
394 curve->AddKeyframe(TransformKeyframe::Create( 456 curve->AddKeyframe(
395 1.0, operations2, EaseTimingFunction::Create())); 457 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations2,
458 EaseTimingFunction::Create()));
396 459
397 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); 460 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f);
398 gfx::BoxF bounds; 461 gfx::BoxF bounds;
399 462
400 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); 463 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds));
401 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), 464 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(),
402 bounds.ToString()); 465 bounds.ToString());
403 } 466 }
404 467
405 // Tests that animations that affect scale are correctly identified. 468 // Tests that animations that affect scale are correctly identified.
406 TEST(KeyframedAnimationCurveTest, AffectsScale) { 469 TEST(KeyframedAnimationCurveTest, AffectsScale) {
407 scoped_ptr<KeyframedTransformAnimationCurve> curve( 470 scoped_ptr<KeyframedTransformAnimationCurve> curve(
408 KeyframedTransformAnimationCurve::Create()); 471 KeyframedTransformAnimationCurve::Create());
409 472
410 TransformOperations operations1; 473 TransformOperations operations1;
411 curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr)); 474 curve->AddKeyframe(
475 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
412 operations1.AppendTranslate(2.0, 3.0, -1.0); 476 operations1.AppendTranslate(2.0, 3.0, -1.0);
413 TransformOperations operations2; 477 TransformOperations operations2;
414 operations2.AppendTranslate(4.0, 1.0, 2.0); 478 operations2.AppendTranslate(4.0, 1.0, 2.0);
415 curve->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr)); 479 curve->AddKeyframe(TransformKeyframe::Create(
480 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr));
416 481
417 EXPECT_FALSE(curve->AffectsScale()); 482 EXPECT_FALSE(curve->AffectsScale());
418 483
419 TransformOperations operations3; 484 TransformOperations operations3;
420 operations3.AppendScale(2.f, 2.f, 2.f); 485 operations3.AppendScale(2.f, 2.f, 2.f);
421 curve->AddKeyframe(TransformKeyframe::Create(2.0, operations3, nullptr)); 486 curve->AddKeyframe(TransformKeyframe::Create(
487 base::TimeDelta::FromSecondsD(2.f), operations3, nullptr));
422 488
423 EXPECT_TRUE(curve->AffectsScale()); 489 EXPECT_TRUE(curve->AffectsScale());
424 490
425 TransformOperations operations4; 491 TransformOperations operations4;
426 operations3.AppendTranslate(2.f, 2.f, 2.f); 492 operations3.AppendTranslate(2.f, 2.f, 2.f);
427 curve->AddKeyframe(TransformKeyframe::Create(3.0, operations4, nullptr)); 493 curve->AddKeyframe(TransformKeyframe::Create(
494 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr));
428 495
429 EXPECT_TRUE(curve->AffectsScale()); 496 EXPECT_TRUE(curve->AffectsScale());
430 } 497 }
431 498
432 // Tests that animations that are translations are correctly identified. 499 // Tests that animations that are translations are correctly identified.
433 TEST(KeyframedAnimationCurveTest, IsTranslation) { 500 TEST(KeyframedAnimationCurveTest, IsTranslation) {
434 scoped_ptr<KeyframedTransformAnimationCurve> curve( 501 scoped_ptr<KeyframedTransformAnimationCurve> curve(
435 KeyframedTransformAnimationCurve::Create()); 502 KeyframedTransformAnimationCurve::Create());
436 503
437 TransformOperations operations1; 504 TransformOperations operations1;
438 curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr)); 505 curve->AddKeyframe(
506 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
439 operations1.AppendTranslate(2.0, 3.0, -1.0); 507 operations1.AppendTranslate(2.0, 3.0, -1.0);
440 TransformOperations operations2; 508 TransformOperations operations2;
441 operations2.AppendTranslate(4.0, 1.0, 2.0); 509 operations2.AppendTranslate(4.0, 1.0, 2.0);
442 curve->AddKeyframe(TransformKeyframe::Create(1.0, operations2, nullptr)); 510 curve->AddKeyframe(TransformKeyframe::Create(
511 base::TimeDelta::FromSecondsD(1.f), operations2, nullptr));
443 512
444 EXPECT_TRUE(curve->IsTranslation()); 513 EXPECT_TRUE(curve->IsTranslation());
445 514
446 TransformOperations operations3; 515 TransformOperations operations3;
447 operations3.AppendScale(2.f, 2.f, 2.f); 516 operations3.AppendScale(2.f, 2.f, 2.f);
448 curve->AddKeyframe(TransformKeyframe::Create(2.0, operations3, nullptr)); 517 curve->AddKeyframe(TransformKeyframe::Create(
518 base::TimeDelta::FromSecondsD(2.f), operations3, nullptr));
449 519
450 EXPECT_FALSE(curve->IsTranslation()); 520 EXPECT_FALSE(curve->IsTranslation());
451 521
452 TransformOperations operations4; 522 TransformOperations operations4;
453 operations3.AppendTranslate(2.f, 2.f, 2.f); 523 operations3.AppendTranslate(2.f, 2.f, 2.f);
454 curve->AddKeyframe(TransformKeyframe::Create(3.0, operations4, nullptr)); 524 curve->AddKeyframe(TransformKeyframe::Create(
525 base::TimeDelta::FromSecondsD(3.f), operations4, nullptr));
455 526
456 EXPECT_FALSE(curve->IsTranslation()); 527 EXPECT_FALSE(curve->IsTranslation());
457 } 528 }
458 529
459 // Tests that maximum target scale is computed as expected. 530 // Tests that maximum target scale is computed as expected.
460 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) { 531 TEST(KeyframedAnimationCurveTest, MaximumTargetScale) {
461 scoped_ptr<KeyframedTransformAnimationCurve> curve( 532 scoped_ptr<KeyframedTransformAnimationCurve> curve(
462 KeyframedTransformAnimationCurve::Create()); 533 KeyframedTransformAnimationCurve::Create());
463 534
464 TransformOperations operations1; 535 TransformOperations operations1;
465 curve->AddKeyframe(TransformKeyframe::Create(0.0, operations1, nullptr)); 536 curve->AddKeyframe(
537 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
466 operations1.AppendScale(2.f, -3.f, 1.f); 538 operations1.AppendScale(2.f, -3.f, 1.f);
467 curve->AddKeyframe(TransformKeyframe::Create( 539 curve->AddKeyframe(
468 1.0, operations1, EaseTimingFunction::Create())); 540 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations1,
541 EaseTimingFunction::Create()));
469 542
470 float maximum_scale = 0.f; 543 float maximum_scale = 0.f;
471 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); 544 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale));
472 EXPECT_EQ(3.f, maximum_scale); 545 EXPECT_EQ(3.f, maximum_scale);
473 546
474 TransformOperations operations2; 547 TransformOperations operations2;
475 operations2.AppendScale(6.f, 3.f, 2.f); 548 operations2.AppendScale(6.f, 3.f, 2.f);
476 curve->AddKeyframe(TransformKeyframe::Create( 549 curve->AddKeyframe(
477 2.0, operations2, EaseTimingFunction::Create())); 550 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), operations2,
551 EaseTimingFunction::Create()));
478 552
479 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale)); 553 EXPECT_TRUE(curve->MaximumTargetScale(true, &maximum_scale));
480 EXPECT_EQ(6.f, maximum_scale); 554 EXPECT_EQ(6.f, maximum_scale);
481 555
482 TransformOperations operations3; 556 TransformOperations operations3;
483 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); 557 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f);
484 curve->AddKeyframe(TransformKeyframe::Create( 558 curve->AddKeyframe(
485 3.0, operations3, EaseTimingFunction::Create())); 559 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), operations3,
560 EaseTimingFunction::Create()));
486 561
487 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale)); 562 EXPECT_FALSE(curve->MaximumTargetScale(true, &maximum_scale));
488 563
489 // The original scale is not used in computing the max. 564 // The original scale is not used in computing the max.
490 scoped_ptr<KeyframedTransformAnimationCurve> curve2( 565 scoped_ptr<KeyframedTransformAnimationCurve> curve2(
491 KeyframedTransformAnimationCurve::Create()); 566 KeyframedTransformAnimationCurve::Create());
492 567
493 TransformOperations operations4; 568 TransformOperations operations4;
494 operations4.AppendScale(0.4f, 0.2f, 0.6f); 569 operations4.AppendScale(0.4f, 0.2f, 0.6f);
495 curve2->AddKeyframe(TransformKeyframe::Create( 570 curve2->AddKeyframe(TransformKeyframe::Create(base::TimeDelta(), operations4,
496 0.0, operations4, EaseTimingFunction::Create())); 571 EaseTimingFunction::Create()));
497 TransformOperations operations5; 572 TransformOperations operations5;
498 operations5.AppendScale(0.5f, 0.3f, -0.8f); 573 operations5.AppendScale(0.5f, 0.3f, -0.8f);
499 curve2->AddKeyframe(TransformKeyframe::Create( 574 curve2->AddKeyframe(
500 1.0, operations5, EaseTimingFunction::Create())); 575 TransformKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), operations5,
576 EaseTimingFunction::Create()));
501 577
502 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale)); 578 EXPECT_TRUE(curve2->MaximumTargetScale(true, &maximum_scale));
503 EXPECT_EQ(0.8f, maximum_scale); 579 EXPECT_EQ(0.8f, maximum_scale);
504 580
505 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale)); 581 EXPECT_TRUE(curve2->MaximumTargetScale(false, &maximum_scale));
506 EXPECT_EQ(0.6f, maximum_scale); 582 EXPECT_EQ(0.6f, maximum_scale);
507 } 583 }
508 584
509 // Tests that an animation with a curve timing function works as expected. 585 // Tests that an animation with a curve timing function works as expected.
510 TEST(KeyframedAnimationCurveTest, CurveTiming) { 586 TEST(KeyframedAnimationCurveTest, CurveTiming) {
511 scoped_ptr<KeyframedFloatAnimationCurve> curve( 587 scoped_ptr<KeyframedFloatAnimationCurve> curve(
512 KeyframedFloatAnimationCurve::Create()); 588 KeyframedFloatAnimationCurve::Create());
513 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr)); 589 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
514 curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr)); 590 curve->AddKeyframe(
591 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
515 curve->SetTimingFunction( 592 curve->SetTimingFunction(
516 CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f).Pass()); 593 CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f).Pass());
517 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); 594 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
518 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); 595 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
519 EXPECT_NEAR(0.05f, curve->GetValue(0.25f), 0.005f); 596 EXPECT_NEAR(0.05f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f)),
520 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f)); 597 0.005f);
521 EXPECT_NEAR(0.95f, curve->GetValue(0.75f), 0.005f); 598 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
522 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); 599 EXPECT_NEAR(0.95f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f)),
523 EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f)); 600 0.005f);
601 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
602 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
524 } 603 }
525 604
526 // Tests that an animation with a curve and keyframe timing function works as 605 // Tests that an animation with a curve and keyframe timing function works as
527 // expected. 606 // expected.
528 TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) { 607 TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) {
529 scoped_ptr<KeyframedFloatAnimationCurve> curve( 608 scoped_ptr<KeyframedFloatAnimationCurve> curve(
530 KeyframedFloatAnimationCurve::Create()); 609 KeyframedFloatAnimationCurve::Create());
531 curve->AddKeyframe(FloatKeyframe::Create( 610 curve->AddKeyframe(FloatKeyframe::Create(
532 0.0, 611 base::TimeDelta(), 0.f,
533 0.f,
534 CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f).Pass())); 612 CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f).Pass()));
535 curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr)); 613 curve->AddKeyframe(
614 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
536 // Curve timing function producing outputs outside of range [0,1]. 615 // Curve timing function producing outputs outside of range [0,1].
537 curve->SetTimingFunction( 616 curve->SetTimingFunction(
538 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); 617 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass());
539 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); 618 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
540 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); 619 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
541 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.25f)); // Clamped. c(.25) < 0 620 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(
542 EXPECT_NEAR(0.17f, curve->GetValue(0.42f), 0.005f); // c(.42)=.27, k(.27)=.17 621 0.25f))); // Clamped. c(.25) < 0
543 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f)); 622 EXPECT_NEAR(0.17f, curve->GetValue(base::TimeDelta::FromSecondsD(0.42f)),
544 EXPECT_NEAR(0.83f, curve->GetValue(0.58f), 0.005f); // c(.58)=.73, k(.73)=.83 623 0.005f); // c(.42)=.27, k(.27)=.17
545 EXPECT_FLOAT_EQ(1.f, curve->GetValue(0.75f)); // Clamped. c(.75) > 1 624 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)));
546 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); 625 EXPECT_NEAR(0.83f, curve->GetValue(base::TimeDelta::FromSecondsD(0.58f)),
547 EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f)); 626 0.005f); // c(.58)=.73, k(.73)=.83
627 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(
628 0.75f))); // Clamped. c(.75) > 1
629 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)));
630 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
548 } 631 }
549 632
550 // Tests that an animation with a curve timing function and multiple keyframes 633 // Tests that an animation with a curve timing function and multiple keyframes
551 // works as expected. 634 // works as expected.
552 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { 635 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) {
553 scoped_ptr<KeyframedFloatAnimationCurve> curve( 636 scoped_ptr<KeyframedFloatAnimationCurve> curve(
554 KeyframedFloatAnimationCurve::Create()); 637 KeyframedFloatAnimationCurve::Create());
555 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr)); 638 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
556 curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr)); 639 curve->AddKeyframe(
557 curve->AddKeyframe(FloatKeyframe::Create(2.0, 3.f, nullptr)); 640 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.f), 1.f, nullptr));
558 curve->AddKeyframe(FloatKeyframe::Create(3.0, 6.f, nullptr)); 641 curve->AddKeyframe(
559 curve->AddKeyframe(FloatKeyframe::Create(4.0, 9.f, nullptr)); 642 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.f), 3.f, nullptr));
643 curve->AddKeyframe(
644 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.f), 6.f, nullptr));
645 curve->AddKeyframe(
646 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.f), 9.f, nullptr));
560 curve->SetTimingFunction( 647 curve->SetTimingFunction(
561 CubicBezierTimingFunction::Create(0.5f, 0.f, 0.5f, 1.f).Pass()); 648 CubicBezierTimingFunction::Create(0.5f, 0.f, 0.5f, 1.f).Pass());
562 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); 649 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(-1.f)));
563 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); 650 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f)));
564 EXPECT_NEAR(0.42f, curve->GetValue(1.f), 0.005f); 651 EXPECT_NEAR(0.42f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f)),
565 EXPECT_NEAR(1.f, curve->GetValue(1.455f), 0.005f); 652 0.005f);
566 EXPECT_FLOAT_EQ(3.f, curve->GetValue(2.f)); 653 EXPECT_NEAR(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.455f)),
567 EXPECT_NEAR(8.72f, curve->GetValue(3.5f), 0.01f); 654 0.005f);
568 EXPECT_FLOAT_EQ(9.f, curve->GetValue(4.f)); 655 EXPECT_FLOAT_EQ(3.f, curve->GetValue(base::TimeDelta::FromSecondsD(2.f)));
569 EXPECT_FLOAT_EQ(9.f, curve->GetValue(5.f)); 656 EXPECT_NEAR(8.72f, curve->GetValue(base::TimeDelta::FromSecondsD(3.5f)),
657 0.01f);
658 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(4.f)));
659 EXPECT_FLOAT_EQ(9.f, curve->GetValue(base::TimeDelta::FromSecondsD(5.f)));
570 } 660 }
571 661
572 // Tests that an animation with a curve timing function that overshoots works as 662 // Tests that an animation with a curve timing function that overshoots works as
573 // expected. 663 // expected.
574 TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) { 664 TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) {
575 scoped_ptr<KeyframedFloatAnimationCurve> curve( 665 scoped_ptr<KeyframedFloatAnimationCurve> curve(
576 KeyframedFloatAnimationCurve::Create()); 666 KeyframedFloatAnimationCurve::Create());
577 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.f, nullptr)); 667 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta(), 0.f, nullptr));
578 curve->AddKeyframe(FloatKeyframe::Create(1.0, 1.f, nullptr)); 668 curve->AddKeyframe(
579 curve->AddKeyframe(FloatKeyframe::Create(2.0, 3.f, nullptr)); 669 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 1.f, nullptr));
580 curve->AddKeyframe(FloatKeyframe::Create(3.0, 6.f, nullptr)); 670 curve->AddKeyframe(
581 curve->AddKeyframe(FloatKeyframe::Create(4.0, 9.f, nullptr)); 671 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(2.0), 3.f, nullptr));
672 curve->AddKeyframe(
673 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(3.0), 6.f, nullptr));
674 curve->AddKeyframe(
675 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(4.0), 9.f, nullptr));
582 // Curve timing function producing outputs outside of range [0,1]. 676 // Curve timing function producing outputs outside of range [0,1].
583 curve->SetTimingFunction( 677 curve->SetTimingFunction(
584 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); 678 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass());
585 EXPECT_LE(curve->GetValue(1.f), 0.f); // c(.25) < 0 679 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)),
586 EXPECT_GE(curve->GetValue(3.f), 9.f); // c(.75) > 1 680 0.f); // c(.25) < 0
681 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)),
682 9.f); // c(.75) > 1
587 } 683 }
588 684
589 } // namespace 685 } // namespace
590 } // namespace cc 686 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/keyframed_animation_curve.cc ('k') | cc/animation/layer_animation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698