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

Side by Side Diff: webkit/compositor_bindings/WebTransformAnimationCurveTest.cpp

Issue 11192050: Rename compositor bindings filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "WebTransformAnimationCurveImpl.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/timing_function.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati ons.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa trix.h"
13
14 using namespace WebKit;
15
16 namespace {
17
18 // Tests that a transform animation with one keyframe works as expected.
19 TEST(WebTransformAnimationCurveTest, OneTransformKeyframe)
20 {
21 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
22 WebKit::WebTransformOperations operations;
23 operations.appendTranslate(2, 0, 0);
24 curve->add(WebTransformKeyframe(0, operations), WebAnimationCurve::TimingFun ctionTypeLinear);
25
26 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41());
27 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41());
28 EXPECT_FLOAT_EQ(2, curve->getValue(0.5).m41());
29 EXPECT_FLOAT_EQ(2, curve->getValue(1).m41());
30 EXPECT_FLOAT_EQ(2, curve->getValue(2).m41());
31 }
32
33 // Tests that a transform animation with two keyframes works as expected.
34 TEST(WebTransformAnimationCurveTest, TwoTransformKeyframe)
35 {
36 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
37 WebKit::WebTransformOperations operations1;
38 operations1.appendTranslate(2, 0, 0);
39 WebKit::WebTransformOperations operations2;
40 operations2.appendTranslate(4, 0, 0);
41 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeLinear);
42 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
43 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41());
44 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41());
45 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41());
46 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41());
47 EXPECT_FLOAT_EQ(4, curve->getValue(2).m41());
48 }
49
50 // Tests that a transform animation with three keyframes works as expected.
51 TEST(WebTransformAnimationCurveTest, ThreeTransformKeyframe)
52 {
53 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
54 WebKit::WebTransformOperations operations1;
55 operations1.appendTranslate(2, 0, 0);
56 WebKit::WebTransformOperations operations2;
57 operations2.appendTranslate(4, 0, 0);
58 WebKit::WebTransformOperations operations3;
59 operations3.appendTranslate(8, 0, 0);
60 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeLinear);
61 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
62 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu nctionTypeLinear);
63 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41());
64 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41());
65 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41());
66 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41());
67 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41());
68 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41());
69 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41());
70 }
71
72 // Tests that a transform animation with multiple keys at a given time works san ely.
73 TEST(WebTransformAnimationCurveTest, RepeatedTransformKeyTimes)
74 {
75 // A step function.
76 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
77 WebKit::WebTransformOperations operations1;
78 operations1.appendTranslate(4, 0, 0);
79 WebKit::WebTransformOperations operations2;
80 operations2.appendTranslate(4, 0, 0);
81 WebKit::WebTransformOperations operations3;
82 operations3.appendTranslate(6, 0, 0);
83 WebKit::WebTransformOperations operations4;
84 operations4.appendTranslate(6, 0, 0);
85 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeLinear);
86 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
87 curve->add(WebTransformKeyframe(1, operations3), WebAnimationCurve::TimingFu nctionTypeLinear);
88 curve->add(WebTransformKeyframe(2, operations4), WebAnimationCurve::TimingFu nctionTypeLinear);
89
90 EXPECT_FLOAT_EQ(4, curve->getValue(-1).m41());
91 EXPECT_FLOAT_EQ(4, curve->getValue(0).m41());
92 EXPECT_FLOAT_EQ(4, curve->getValue(0.5).m41());
93
94 // There is a discontinuity at 1. Any value between 4 and 6 is valid.
95 WebTransformationMatrix value = curve->getValue(1);
96 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6);
97
98 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41());
99 EXPECT_FLOAT_EQ(6, curve->getValue(2).m41());
100 EXPECT_FLOAT_EQ(6, curve->getValue(3).m41());
101 }
102
103 // Tests that the keyframes may be added out of order.
104 TEST(WebTransformAnimationCurveTest, UnsortedKeyframes)
105 {
106 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
107 WebKit::WebTransformOperations operations1;
108 operations1.appendTranslate(2, 0, 0);
109 WebKit::WebTransformOperations operations2;
110 operations2.appendTranslate(4, 0, 0);
111 WebKit::WebTransformOperations operations3;
112 operations3.appendTranslate(8, 0, 0);
113 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu nctionTypeLinear);
114 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeLinear);
115 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
116
117 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41());
118 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41());
119 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41());
120 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41());
121 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41());
122 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41());
123 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41());
124 }
125
126 // Tests that a cubic bezier timing function works as expected.
127 TEST(WebTransformAnimationCurveTest, CubicBezierTimingFunction)
128 {
129 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
130 WebKit::WebTransformOperations operations1;
131 operations1.appendTranslate(0, 0, 0);
132 WebKit::WebTransformOperations operations2;
133 operations2.appendTranslate(1, 0, 0);
134 curve->add(WebTransformKeyframe(0, operations1), 0.25, 0, 0.75, 1);
135 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
136 EXPECT_FLOAT_EQ(0, curve->getValue(0).m41());
137 EXPECT_LT(0, curve->getValue(0.25).m41());
138 EXPECT_GT(0.25, curve->getValue(0.25).m41());
139 EXPECT_FLOAT_EQ(0.5, curve->getValue(0.5).m41());
140 EXPECT_LT(0.75, curve->getValue(0.75).m41());
141 EXPECT_GT(1, curve->getValue(0.75).m41());
142 EXPECT_FLOAT_EQ(1, curve->getValue(1).m41());
143 }
144
145 // Tests that an ease timing function works as expected.
146 TEST(WebTransformAnimationCurveTest, EaseTimingFunction)
147 {
148 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
149 WebKit::WebTransformOperations operations1;
150 operations1.appendTranslate(0, 0, 0);
151 WebKit::WebTransformOperations operations2;
152 operations2.appendTranslate(1, 0, 0);
153 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeEase);
154 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
155
156 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCEaseTimingFunction::cr eate());
157 for (int i = 0; i <= 4; ++i) {
158 const double time = i * 0.25;
159 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
160 }
161 }
162
163 // Tests using a linear timing function.
164 TEST(WebTransformAnimationCurveTest, LinearTimingFunction)
165 {
166 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
167 WebKit::WebTransformOperations operations1;
168 operations1.appendTranslate(0, 0, 0);
169 WebKit::WebTransformOperations operations2;
170 operations2.appendTranslate(1, 0, 0);
171 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeLinear);
172 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
173
174 for (int i = 0; i <= 4; ++i) {
175 const double time = i * 0.25;
176 EXPECT_FLOAT_EQ(time, curve->getValue(time).m41());
177 }
178 }
179
180 // Tests that an ease in timing function works as expected.
181 TEST(WebTransformAnimationCurveTest, EaseInTimingFunction)
182 {
183 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
184 WebKit::WebTransformOperations operations1;
185 operations1.appendTranslate(0, 0, 0);
186 WebKit::WebTransformOperations operations2;
187 operations2.appendTranslate(1, 0, 0);
188 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeEaseIn);
189 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
190
191 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCEaseInTimingFunction:: create());
192 for (int i = 0; i <= 4; ++i) {
193 const double time = i * 0.25;
194 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
195 }
196 }
197
198 // Tests that an ease in timing function works as expected.
199 TEST(WebTransformAnimationCurveTest, EaseOutTimingFunction)
200 {
201 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
202 WebKit::WebTransformOperations operations1;
203 operations1.appendTranslate(0, 0, 0);
204 WebKit::WebTransformOperations operations2;
205 operations2.appendTranslate(1, 0, 0);
206 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeEaseOut);
207 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
208
209 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCEaseOutTimingFunction: :create());
210 for (int i = 0; i <= 4; ++i) {
211 const double time = i * 0.25;
212 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
213 }
214 }
215
216 // Tests that an ease in timing function works as expected.
217 TEST(WebTransformAnimationCurveTest, EaseInOutTimingFunction)
218 {
219 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
220 WebKit::WebTransformOperations operations1;
221 operations1.appendTranslate(0, 0, 0);
222 WebKit::WebTransformOperations operations2;
223 operations2.appendTranslate(1, 0, 0);
224 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu nctionTypeEaseInOut);
225 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
226
227 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCEaseInOutTimingFunctio n::create());
228 for (int i = 0; i <= 4; ++i) {
229 const double time = i * 0.25;
230 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
231 }
232 }
233
234 // Tests that an ease in timing function works as expected.
235 TEST(WebTransformAnimationCurveTest, CustomBezierTimingFunction)
236 {
237 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
238 double x1 = 0.3;
239 double y1 = 0.2;
240 double x2 = 0.8;
241 double y2 = 0.7;
242 WebKit::WebTransformOperations operations1;
243 operations1.appendTranslate(0, 0, 0);
244 WebKit::WebTransformOperations operations2;
245 operations2.appendTranslate(1, 0, 0);
246 curve->add(WebTransformKeyframe(0, operations1), x1, y1, x2, y2);
247 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
248
249 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCCubicBezierTimingFunct ion::create(x1, y1, x2, y2));
250 for (int i = 0; i <= 4; ++i) {
251 const double time = i * 0.25;
252 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
253 }
254 }
255
256 // Tests that the default timing function is indeed ease.
257 TEST(WebTransformAnimationCurveTest, DefaultTimingFunction)
258 {
259 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI mpl);
260 WebKit::WebTransformOperations operations1;
261 operations1.appendTranslate(0, 0, 0);
262 WebKit::WebTransformOperations operations2;
263 operations2.appendTranslate(1, 0, 0);
264 curve->add(WebTransformKeyframe(0, operations1));
265 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu nctionTypeLinear);
266
267 scoped_ptr<cc::CCTimingFunction> timingFunction(cc::CCEaseTimingFunction::cr eate());
268 for (int i = 0; i <= 4; ++i) {
269 const double time = i * 0.25;
270 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4 1());
271 }
272 }
273
274 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698