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

Side by Side Diff: cc/CCLayerAnimationControllerTest.cpp

Issue 11108020: [cc] Change cc_tests.gyp filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
« no previous file with comments | « cc/CCKeyframedAnimationCurveTest.cpp ('k') | cc/CCLayerImplTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "CCLayerAnimationController.h"
8
9 #include "CCActiveAnimation.h"
10 #include "CCAnimationCurve.h"
11 #include "CCAnimationTestCommon.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include <public/WebTransformationMatrix.h>
15
16 using namespace cc;
17 using namespace WebKitTests;
18 using WebKit::WebTransformationMatrix;
19
20 namespace {
21
22 void expectTranslateX(double translateX, const WebTransformationMatrix& matrix)
23 {
24 EXPECT_FLOAT_EQ(translateX, matrix.m41());
25 }
26
27 scoped_ptr<CCActiveAnimation> createActiveAnimation(scoped_ptr<CCAnimationCurve> curve, int id, CCActiveAnimation::TargetProperty property)
28 {
29 return CCActiveAnimation::create(curve.Pass(), 0, id, property);
30 }
31
32 TEST(CCLayerAnimationControllerTest, syncNewAnimation)
33 {
34 FakeLayerAnimationControllerClient dummyImpl;
35 scoped_ptr<CCLayerAnimationController> controllerImpl(CCLayerAnimationContro ller::create(&dummyImpl));
36 FakeLayerAnimationControllerClient dummy;
37 scoped_ptr<CCLayerAnimationController> controller(CCLayerAnimationController ::create(&dummy));
38
39 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
40
41 addOpacityTransitionToController(*controller, 1, 0, 1, false);
42
43 controller->pushAnimationUpdatesTo(controllerImpl.get());
44
45 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity ));
46 EXPECT_EQ(CCActiveAnimation::WaitingForTargetAvailability, controllerImpl->g etActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
47 }
48
49 // If an animation is started on the impl thread before it is ticked on the main
50 // thread, we must be sure to respect the synchronized start time.
51 TEST(CCLayerAnimationControllerTest, doNotClobberStartTimes)
52 {
53 FakeLayerAnimationControllerClient dummyImpl;
54 scoped_ptr<CCLayerAnimationController> controllerImpl(CCLayerAnimationContro ller::create(&dummyImpl));
55 FakeLayerAnimationControllerClient dummy;
56 scoped_ptr<CCLayerAnimationController> controller(CCLayerAnimationController ::create(&dummy));
57
58 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
59
60 addOpacityTransitionToController(*controller, 1, 0, 1, false);
61
62 controller->pushAnimationUpdatesTo(controllerImpl.get());
63
64 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity ));
65 EXPECT_EQ(CCActiveAnimation::WaitingForTargetAvailability, controllerImpl->g etActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
66
67 CCAnimationEventsVector events;
68 controllerImpl->animate(1, &events);
69
70 // Synchronize the start times.
71 EXPECT_EQ(1u, events.size());
72 controller->notifyAnimationStarted(events[0]);
73 EXPECT_EQ(controller->getActiveAnimation(0, CCActiveAnimation::Opacity)->sta rtTime(), controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity)->sta rtTime());
74
75 // Start the animation on the main thread. Should not affect the start time.
76 controller->animate(1.5, 0);
77 EXPECT_EQ(controller->getActiveAnimation(0, CCActiveAnimation::Opacity)->sta rtTime(), controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity)->sta rtTime());
78 }
79
80 TEST(CCLayerAnimationControllerTest, syncPauseAndResume)
81 {
82 FakeLayerAnimationControllerClient dummyImpl;
83 scoped_ptr<CCLayerAnimationController> controllerImpl(CCLayerAnimationContro ller::create(&dummyImpl));
84 FakeLayerAnimationControllerClient dummy;
85 scoped_ptr<CCLayerAnimationController> controller(CCLayerAnimationController ::create(&dummy));
86
87 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
88
89 addOpacityTransitionToController(*controller, 1, 0, 1, false);
90
91 controller->pushAnimationUpdatesTo(controllerImpl.get());
92
93 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity ));
94 EXPECT_EQ(CCActiveAnimation::WaitingForTargetAvailability, controllerImpl->g etActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
95
96 // Start the animations on each controller.
97 CCAnimationEventsVector events;
98 controllerImpl->animate(0, &events);
99 controller->animate(0, 0);
100 EXPECT_EQ(CCActiveAnimation::Running, controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
101 EXPECT_EQ(CCActiveAnimation::Running, controller->getActiveAnimation(0, CCAc tiveAnimation::Opacity)->runState());
102
103 // Pause the main-thread animation.
104 controller->suspendAnimations(1);
105 EXPECT_EQ(CCActiveAnimation::Paused, controller->getActiveAnimation(0, CCAct iveAnimation::Opacity)->runState());
106
107 // The pause run state change should make it to the impl thread controller.
108 controller->pushAnimationUpdatesTo(controllerImpl.get());
109 EXPECT_EQ(CCActiveAnimation::Paused, controllerImpl->getActiveAnimation(0, C CActiveAnimation::Opacity)->runState());
110
111 // Resume the main-thread animation.
112 controller->resumeAnimations(2);
113 EXPECT_EQ(CCActiveAnimation::Running, controller->getActiveAnimation(0, CCAc tiveAnimation::Opacity)->runState());
114
115 // The pause run state change should make it to the impl thread controller.
116 controller->pushAnimationUpdatesTo(controllerImpl.get());
117 EXPECT_EQ(CCActiveAnimation::Running, controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
118 }
119
120 TEST(CCLayerAnimationControllerTest, doNotSyncFinishedAnimation)
121 {
122 FakeLayerAnimationControllerClient dummyImpl;
123 scoped_ptr<CCLayerAnimationController> controllerImpl(CCLayerAnimationContro ller::create(&dummyImpl));
124 FakeLayerAnimationControllerClient dummy;
125 scoped_ptr<CCLayerAnimationController> controller(CCLayerAnimationController ::create(&dummy));
126
127 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
128
129 addOpacityTransitionToController(*controller, 1, 0, 1, false);
130
131 controller->pushAnimationUpdatesTo(controllerImpl.get());
132
133 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity ));
134 EXPECT_EQ(CCActiveAnimation::WaitingForTargetAvailability, controllerImpl->g etActiveAnimation(0, CCActiveAnimation::Opacity)->runState());
135
136 // Notify main thread controller that the animation has started.
137 CCAnimationEvent animationStartedEvent(CCAnimationEvent::Started, 0, 0, CCAc tiveAnimation::Opacity, 0);
138 controller->notifyAnimationStarted(animationStartedEvent);
139
140 // Force animation to complete on impl thread.
141 controllerImpl->removeAnimation(0);
142
143 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
144
145 controller->pushAnimationUpdatesTo(controllerImpl.get());
146
147 // Even though the main thread has a 'new' animation, it should not be pushe d because the animation has already completed on the impl thread.
148 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacit y));
149 }
150
151 // Tests that transitioning opacity from 0 to 1 works as expected.
152 TEST(CCLayerAnimationControllerTest, TrivialTransition)
153 {
154 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
155 FakeLayerAnimationControllerClient dummy;
156 scoped_ptr<CCLayerAnimationController> controller(
157 CCLayerAnimationController::create(&dummy));
158
159 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation ::Opacity));
160
161 controller->addAnimation(toAdd.Pass());
162 controller->animate(0, events.get());
163 EXPECT_TRUE(controller->hasActiveAnimation());
164 EXPECT_EQ(0, dummy.opacity());
165 controller->animate(1, events.get());
166 EXPECT_EQ(1, dummy.opacity());
167 EXPECT_FALSE(controller->hasActiveAnimation());
168 }
169
170 // Tests animations that are waiting for a synchronized start time do not finish .
171 TEST(CCLayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfT heyWaitLongerToStartThanTheirDuration)
172 {
173 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
174 FakeLayerAnimationControllerClient dummy;
175 scoped_ptr<CCLayerAnimationController> controller(
176 CCLayerAnimationController::create(&dummy));
177
178 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation ::Opacity));
179 toAdd->setNeedsSynchronizedStartTime(true);
180
181 // We should pause at the first keyframe indefinitely waiting for that anima tion to start.
182 controller->addAnimation(toAdd.Pass());
183 controller->animate(0, events.get());
184 EXPECT_TRUE(controller->hasActiveAnimation());
185 EXPECT_EQ(0, dummy.opacity());
186 controller->animate(1, events.get());
187 EXPECT_TRUE(controller->hasActiveAnimation());
188 EXPECT_EQ(0, dummy.opacity());
189 controller->animate(2, events.get());
190 EXPECT_TRUE(controller->hasActiveAnimation());
191 EXPECT_EQ(0, dummy.opacity());
192
193 // Send the synchronized start time.
194 controller->notifyAnimationStarted(CCAnimationEvent(CCAnimationEvent::Starte d, 0, 1, CCActiveAnimation::Opacity, 2));
195 controller->animate(5, events.get());
196 EXPECT_EQ(1, dummy.opacity());
197 EXPECT_FALSE(controller->hasActiveAnimation());
198 }
199
200 // Tests that two queued animations affecting the same property run in sequence.
201 TEST(CCLayerAnimationControllerTest, TrivialQueuing)
202 {
203 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
204 FakeLayerAnimationControllerClient dummy;
205 scoped_ptr<CCLayerAnimationController> controller(
206 CCLayerAnimationController::create(&dummy));
207
208 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Opacity)) ;
209 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 1, 0.5)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimation::Opacity ));
210
211 controller->animate(0, events.get());
212 EXPECT_TRUE(controller->hasActiveAnimation());
213 EXPECT_EQ(0, dummy.opacity());
214 controller->animate(1, events.get());
215 EXPECT_TRUE(controller->hasActiveAnimation());
216 EXPECT_EQ(1, dummy.opacity());
217 controller->animate(2, events.get());
218 EXPECT_EQ(0.5, dummy.opacity());
219 EXPECT_FALSE(controller->hasActiveAnimation());
220 }
221
222 // Tests interrupting a transition with another transition.
223 TEST(CCLayerAnimationControllerTest, Interrupt)
224 {
225 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
226 FakeLayerAnimationControllerClient dummy;
227 scoped_ptr<CCLayerAnimationController> controller(
228 CCLayerAnimationController::create(&dummy));
229 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Opacity)) ;
230 controller->animate(0, events.get());
231 EXPECT_TRUE(controller->hasActiveAnimation());
232 EXPECT_EQ(0, dummy.opacity());
233
234 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 1, 0.5)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimati on::Opacity));
235 toAdd->setRunState(CCActiveAnimation::WaitingForNextTick, 0);
236 controller->addAnimation(toAdd.Pass());
237
238 // Since the animation was in the WaitingForNextTick state, it should start right in
239 // this call to animate.
240 controller->animate(0.5, events.get());
241 EXPECT_TRUE(controller->hasActiveAnimation());
242 EXPECT_EQ(1, dummy.opacity());
243 controller->animate(1.5, events.get());
244 EXPECT_EQ(0.5, dummy.opacity());
245 EXPECT_FALSE(controller->hasActiveAnimation());
246 }
247
248 // Tests scheduling two animations to run together when only one property is fre e.
249 TEST(CCLayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked)
250 {
251 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
252 FakeLayerAnimationControllerClient dummy;
253 scoped_ptr<CCLayerAnimationController> controller(
254 CCLayerAnimationController::create(&dummy));
255
256 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Transform)) ;
257 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(1)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimation::Transform)) ;
258 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimation::Opacity)) ;
259
260 controller->animate(0, events.get());
261 EXPECT_EQ(0, dummy.opacity());
262 EXPECT_TRUE(controller->hasActiveAnimation());
263 controller->animate(1, events.get());
264 // Should not have started the float transition yet.
265 EXPECT_TRUE(controller->hasActiveAnimation());
266 EXPECT_EQ(0, dummy.opacity());
267 // The float animation should have started at time 1 and should be done.
268 controller->animate(2, events.get());
269 EXPECT_EQ(1, dummy.opacity());
270 EXPECT_FALSE(controller->hasActiveAnimation());
271 }
272
273 // Tests scheduling two animations to run together with different lengths and an other
274 // animation queued to start when the shorter animation finishes (should wait
275 // for both to finish).
276 TEST(CCLayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting)
277 {
278 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
279 FakeLayerAnimationControllerClient dummy;
280 scoped_ptr<CCLayerAnimationController> controller(
281 CCLayerAnimationController::create(&dummy));
282
283 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(2)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Transform)) ;
284 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Opacity)) ;
285 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 1, 0.5)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimation::Opacity ));
286
287 // Animations with id 1 should both start now.
288 controller->animate(0, events.get());
289 EXPECT_TRUE(controller->hasActiveAnimation());
290 EXPECT_EQ(0, dummy.opacity());
291 // The opacity animation should have finished at time 1, but the group
292 // of animations with id 1 don't finish until time 2 because of the length
293 // of the transform animation.
294 controller->animate(2, events.get());
295 // Should not have started the float transition yet.
296 EXPECT_TRUE(controller->hasActiveAnimation());
297 EXPECT_EQ(1, dummy.opacity());
298
299 // The second opacity animation should start at time 2 and should be done by time 3
300 controller->animate(3, events.get());
301 EXPECT_EQ(0.5, dummy.opacity());
302 EXPECT_FALSE(controller->hasActiveAnimation());
303 }
304
305 // Tests scheduling an animation to start in the future.
306 TEST(CCLayerAnimationControllerTest, ScheduleAnimation)
307 {
308 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
309 FakeLayerAnimationControllerClient dummy;
310 scoped_ptr<CCLayerAnimationController> controller(
311 CCLayerAnimationController::create(&dummy));
312
313 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation ::Opacity));
314 toAdd->setRunState(CCActiveAnimation::WaitingForStartTime, 0);
315 toAdd->setStartTime(1);
316 controller->addAnimation(toAdd.Pass());
317
318 controller->animate(0, events.get());
319 EXPECT_TRUE(controller->hasActiveAnimation());
320 EXPECT_EQ(0, dummy.opacity());
321 controller->animate(1, events.get());
322 EXPECT_TRUE(controller->hasActiveAnimation());
323 EXPECT_EQ(0, dummy.opacity());
324 controller->animate(2, events.get());
325 EXPECT_EQ(1, dummy.opacity());
326 EXPECT_FALSE(controller->hasActiveAnimation());
327 }
328
329 // Tests scheduling an animation to start in the future that's interrupting a ru nning animation.
330 TEST(CCLayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimatio n)
331 {
332 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
333 FakeLayerAnimationControllerClient dummy;
334 scoped_ptr<CCLayerAnimationController> controller(
335 CCLayerAnimationController::create(&dummy));
336
337 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Opacity)) ;
338
339 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0.5, 0)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimati on::Opacity));
340 toAdd->setRunState(CCActiveAnimation::WaitingForStartTime, 0);
341 toAdd->setStartTime(1);
342 controller->addAnimation(toAdd.Pass());
343
344 // First 2s opacity transition should start immediately.
345 controller->animate(0, events.get());
346 EXPECT_TRUE(controller->hasActiveAnimation());
347 EXPECT_EQ(0, dummy.opacity());
348 controller->animate(0.5, events.get());
349 EXPECT_TRUE(controller->hasActiveAnimation());
350 EXPECT_EQ(0.25, dummy.opacity());
351 controller->animate(1, events.get());
352 EXPECT_TRUE(controller->hasActiveAnimation());
353 EXPECT_EQ(0.5, dummy.opacity());
354 controller->animate(2, events.get());
355 EXPECT_EQ(0, dummy.opacity());
356 EXPECT_FALSE(controller->hasActiveAnimation());
357 }
358
359 // Tests scheduling an animation to start in the future that interrupts a runnin g animation
360 // and there is yet another animation queued to start later.
361 TEST(CCLayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimatio nWithAnimInQueue)
362 {
363 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
364 FakeLayerAnimationControllerClient dummy;
365 scoped_ptr<CCLayerAnimationController> controller(
366 CCLayerAnimationController::create(&dummy));
367
368 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation::Opacity)) ;
369
370 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(2, 0.5, 0)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimati on::Opacity));
371 toAdd->setRunState(CCActiveAnimation::WaitingForStartTime, 0);
372 toAdd->setStartTime(1);
373 controller->addAnimation(toAdd.Pass());
374
375 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 0.75)).PassAs<CCAnimationCurve>(), 3, CCActiveAnimation::Opacit y));
376
377 // First 2s opacity transition should start immediately.
378 controller->animate(0, events.get());
379 EXPECT_TRUE(controller->hasActiveAnimation());
380 EXPECT_EQ(0, dummy.opacity());
381 controller->animate(0.5, events.get());
382 EXPECT_TRUE(controller->hasActiveAnimation());
383 EXPECT_EQ(0.25, dummy.opacity());
384 EXPECT_TRUE(controller->hasActiveAnimation());
385 controller->animate(1, events.get());
386 EXPECT_TRUE(controller->hasActiveAnimation());
387 EXPECT_EQ(0.5, dummy.opacity());
388 controller->animate(3, events.get());
389 EXPECT_TRUE(controller->hasActiveAnimation());
390 EXPECT_EQ(0, dummy.opacity());
391 controller->animate(4, events.get());
392 EXPECT_EQ(0.75, dummy.opacity());
393 EXPECT_FALSE(controller->hasActiveAnimation());
394 }
395
396 // Test that a looping animation loops and for the correct number of iterations.
397 TEST(CCLayerAnimationControllerTest, TrivialLooping)
398 {
399 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
400 FakeLayerAnimationControllerClient dummy;
401 scoped_ptr<CCLayerAnimationController> controller(
402 CCLayerAnimationController::create(&dummy));
403
404 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0, 1)).PassAs<CCAnimationCurve>(), 1, CCActiveAnimation ::Opacity));
405 toAdd->setIterations(3);
406 controller->addAnimation(toAdd.Pass());
407
408 controller->animate(0, events.get());
409 EXPECT_TRUE(controller->hasActiveAnimation());
410 EXPECT_EQ(0, dummy.opacity());
411 controller->animate(1.25, events.get());
412 EXPECT_TRUE(controller->hasActiveAnimation());
413 EXPECT_EQ(0.25, dummy.opacity());
414 controller->animate(1.75, events.get());
415 EXPECT_TRUE(controller->hasActiveAnimation());
416 EXPECT_EQ(0.75, dummy.opacity());
417 controller->animate(2.25, events.get());
418 EXPECT_TRUE(controller->hasActiveAnimation());
419 EXPECT_EQ(0.25, dummy.opacity());
420 controller->animate(2.75, events.get());
421 EXPECT_TRUE(controller->hasActiveAnimation());
422 EXPECT_EQ(0.75, dummy.opacity());
423 controller->animate(3, events.get());
424 EXPECT_FALSE(controller->hasActiveAnimation());
425 EXPECT_EQ(1, dummy.opacity());
426
427 // Just be extra sure.
428 controller->animate(4, events.get());
429 EXPECT_EQ(1, dummy.opacity());
430 }
431
432 // Test that an infinitely looping animation does indeed go until aborted.
433 TEST(CCLayerAnimationControllerTest, InfiniteLooping)
434 {
435 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
436 FakeLayerAnimationControllerClient dummy;
437 scoped_ptr<CCLayerAnimationController> controller(
438 CCLayerAnimationController::create(&dummy));
439
440 const int id = 1;
441 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(1, 0, 1)).PassAs<CCAnimationCurve>(), id, CCActiveAnimatio n::Opacity));
442 toAdd->setIterations(-1);
443 controller->addAnimation(toAdd.Pass());
444
445 controller->animate(0, events.get());
446 EXPECT_TRUE(controller->hasActiveAnimation());
447 EXPECT_EQ(0, dummy.opacity());
448 controller->animate(1.25, events.get());
449 EXPECT_TRUE(controller->hasActiveAnimation());
450 EXPECT_EQ(0.25, dummy.opacity());
451 controller->animate(1.75, events.get());
452 EXPECT_TRUE(controller->hasActiveAnimation());
453 EXPECT_EQ(0.75, dummy.opacity());
454
455 controller->animate(1073741824.25, events.get());
456 EXPECT_TRUE(controller->hasActiveAnimation());
457 EXPECT_EQ(0.25, dummy.opacity());
458 controller->animate(1073741824.75, events.get());
459 EXPECT_TRUE(controller->hasActiveAnimation());
460 EXPECT_EQ(0.75, dummy.opacity());
461
462 EXPECT_TRUE(controller->getActiveAnimation(id, CCActiveAnimation::Opacity));
463 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState( CCActiveAnimation::Aborted, 0.75);
464 EXPECT_FALSE(controller->hasActiveAnimation());
465 EXPECT_EQ(0.75, dummy.opacity());
466 }
467
468 // Test that pausing and resuming work as expected.
469 TEST(CCLayerAnimationControllerTest, PauseResume)
470 {
471 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
472 FakeLayerAnimationControllerClient dummy;
473 scoped_ptr<CCLayerAnimationController> controller(
474 CCLayerAnimationController::create(&dummy));
475
476 const int id = 1;
477 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 0, 1)).PassAs<CCAnimationCurve>(), id, CCActiveAnimation::Opacity) );
478
479 controller->animate(0, events.get());
480 EXPECT_TRUE(controller->hasActiveAnimation());
481 EXPECT_EQ(0, dummy.opacity());
482 controller->animate(0.5, events.get());
483 EXPECT_TRUE(controller->hasActiveAnimation());
484 EXPECT_EQ(0.5, dummy.opacity());
485
486 EXPECT_TRUE(controller->getActiveAnimation(id, CCActiveAnimation::Opacity));
487 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState( CCActiveAnimation::Paused, 0.5);
488
489 controller->animate(1024, events.get());
490 EXPECT_TRUE(controller->hasActiveAnimation());
491 EXPECT_EQ(0.5, dummy.opacity());
492
493 EXPECT_TRUE(controller->getActiveAnimation(id, CCActiveAnimation::Opacity));
494 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState( CCActiveAnimation::Running, 1024);
495
496 controller->animate(1024.25, events.get());
497 EXPECT_TRUE(controller->hasActiveAnimation());
498 EXPECT_EQ(0.75, dummy.opacity());
499 controller->animate(1024.5, events.get());
500 EXPECT_FALSE(controller->hasActiveAnimation());
501 EXPECT_EQ(1, dummy.opacity());
502 }
503
504 TEST(CCLayerAnimationControllerTest, AbortAGroupedAnimation)
505 {
506 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
507 FakeLayerAnimationControllerClient dummy;
508 scoped_ptr<CCLayerAnimationController> controller(
509 CCLayerAnimationController::create(&dummy));
510
511 const int id = 1;
512 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans formTransition(1)).PassAs<CCAnimationCurve>(), id, CCActiveAnimation::Transform) );
513 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(2, 0, 1)).PassAs<CCAnimationCurve>(), id, CCActiveAnimation::Opacity) );
514 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat Transition(1, 1, 0.75)).PassAs<CCAnimationCurve>(), 2, CCActiveAnimation::Opacit y));
515
516 controller->animate(0, events.get());
517 EXPECT_TRUE(controller->hasActiveAnimation());
518 EXPECT_EQ(0, dummy.opacity());
519 controller->animate(1, events.get());
520 EXPECT_TRUE(controller->hasActiveAnimation());
521 EXPECT_EQ(0.5, dummy.opacity());
522
523 EXPECT_TRUE(controller->getActiveAnimation(id, CCActiveAnimation::Opacity));
524 controller->getActiveAnimation(id, CCActiveAnimation::Opacity)->setRunState( CCActiveAnimation::Aborted, 1);
525 controller->animate(1, events.get());
526 EXPECT_TRUE(controller->hasActiveAnimation());
527 EXPECT_EQ(1, dummy.opacity());
528 controller->animate(2, events.get());
529 EXPECT_TRUE(!controller->hasActiveAnimation());
530 EXPECT_EQ(0.75, dummy.opacity());
531 }
532
533 TEST(CCLayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded)
534 {
535 FakeLayerAnimationControllerClient dummyImpl;
536 scoped_ptr<CCLayerAnimationController> controllerImpl(CCLayerAnimationContro ller::create(&dummyImpl));
537 scoped_ptr<CCAnimationEventsVector> events(make_scoped_ptr(new CCAnimationEv entsVector));
538 FakeLayerAnimationControllerClient dummy;
539 scoped_ptr<CCLayerAnimationController> controller(
540 CCLayerAnimationController::create(&dummy));
541
542 scoped_ptr<CCActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(ne w FakeFloatTransition(2, 0, 1)).PassAs<CCAnimationCurve>(), 0, CCActiveAnimation ::Opacity));
543 toAdd->setNeedsSynchronizedStartTime(true);
544 controller->addAnimation(toAdd.Pass());
545
546 controller->animate(0, 0);
547 EXPECT_TRUE(controller->hasActiveAnimation());
548 CCActiveAnimation* activeAnimation = controller->getActiveAnimation(0, CCAct iveAnimation::Opacity);
549 EXPECT_TRUE(activeAnimation);
550 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime());
551
552 controller->setForceSync();
553
554 controller->pushAnimationUpdatesTo(controllerImpl.get());
555
556 activeAnimation = controllerImpl->getActiveAnimation(0, CCActiveAnimation::O pacity);
557 EXPECT_TRUE(activeAnimation);
558 EXPECT_EQ(CCActiveAnimation::WaitingForTargetAvailability, activeAnimation-> runState());
559 }
560
561 } // namespace
OLDNEW
« no previous file with comments | « cc/CCKeyframedAnimationCurveTest.cpp ('k') | cc/CCLayerImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698