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

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

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

Powered by Google App Engine
This is Rietveld 408576698