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

Side by Side Diff: Source/core/animation/AnimationPlayerTest.cpp

Issue 1113173003: Web Animations: Update naming to reflect spec changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: No, really. Created 5 years, 7 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 | « Source/core/animation/AnimationPlayer.idl ('k') | Source/core/animation/AnimationStack.h » ('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 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "core/animation/AnimationPlayer.h"
33
34 #include "core/animation/Animation.h"
35 #include "core/animation/AnimationClock.h"
36 #include "core/animation/AnimationTimeline.h"
37 #include "core/animation/ElementAnimations.h"
38 #include "core/dom/Document.h"
39 #include "core/dom/ExceptionCode.h"
40 #include "core/dom/QualifiedName.h"
41 #include "platform/weborigin/KURL.h"
42 #include <gtest/gtest.h>
43
44 using namespace blink;
45
46 namespace {
47
48 class AnimationAnimationPlayerTest : public ::testing::Test {
49 protected:
50 virtual void SetUp()
51 {
52 setUpWithoutStartingTimeline();
53 startTimeline();
54 }
55
56 void setUpWithoutStartingTimeline()
57 {
58 document = Document::create();
59 document->animationClock().resetTimeForTesting();
60 timeline = AnimationTimeline::create(document.get());
61 player = timeline->play(0);
62 player->setStartTime(0);
63 player->setSource(makeAnimation().get());
64 }
65
66 void startTimeline()
67 {
68 simulateFrame(0);
69 }
70
71 PassRefPtrWillBeRawPtr<Animation> makeAnimation(double duration = 30, double playbackRate = 1)
72 {
73 Timing timing;
74 timing.iterationDuration = duration;
75 timing.playbackRate = playbackRate;
76 return Animation::create(0, nullptr, timing);
77 }
78
79 bool simulateFrame(double time)
80 {
81 document->animationClock().updateTime(time);
82 document->compositorPendingAnimations().update(false);
83 // The timeline does not know about our player, so we have to explicitly call update().
84 return player->update(TimingUpdateForAnimationFrame);
85 }
86
87 RefPtrWillBePersistent<Document> document;
88 RefPtrWillBePersistent<AnimationTimeline> timeline;
89 RefPtrWillBePersistent<AnimationPlayer> player;
90 TrackExceptionState exceptionState;
91 };
92
93 TEST_F(AnimationAnimationPlayerTest, InitialState)
94 {
95 setUpWithoutStartingTimeline();
96 player = timeline->play(0);
97 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
98 EXPECT_EQ(0, player->currentTimeInternal());
99 EXPECT_FALSE(player->paused());
100 EXPECT_EQ(1, player->playbackRate());
101 EXPECT_FALSE(player->hasStartTime());
102 EXPECT_TRUE(isNull(player->startTimeInternal()));
103
104 startTimeline();
105 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
106 EXPECT_EQ(0, timeline->currentTimeInternal());
107 EXPECT_EQ(0, player->currentTimeInternal());
108 EXPECT_FALSE(player->paused());
109 EXPECT_EQ(1, player->playbackRate());
110 EXPECT_EQ(0, player->startTimeInternal());
111 EXPECT_TRUE(player->hasStartTime());
112 }
113
114
115 TEST_F(AnimationAnimationPlayerTest, CurrentTimeDoesNotSetOutdated)
116 {
117 EXPECT_FALSE(player->outdated());
118 EXPECT_EQ(0, player->currentTimeInternal());
119 EXPECT_FALSE(player->outdated());
120 // FIXME: We should split simulateFrame into a version that doesn't update
121 // the player and one that does, as most of the tests don't require update()
122 // to be called.
123 document->animationClock().updateTime(10);
124 EXPECT_EQ(10, player->currentTimeInternal());
125 EXPECT_FALSE(player->outdated());
126 }
127
128 TEST_F(AnimationAnimationPlayerTest, SetCurrentTime)
129 {
130 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
131 player->setCurrentTimeInternal(10);
132 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
133 EXPECT_EQ(10, player->currentTimeInternal());
134 simulateFrame(10);
135 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
136 EXPECT_EQ(20, player->currentTimeInternal());
137 }
138
139 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegative)
140 {
141 player->setCurrentTimeInternal(-10);
142 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
143 EXPECT_EQ(-10, player->currentTimeInternal());
144 simulateFrame(20);
145 EXPECT_EQ(10, player->currentTimeInternal());
146
147 player->setPlaybackRate(-2);
148 player->setCurrentTimeInternal(-10);
149 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
150 EXPECT_EQ(-10, player->currentTimeInternal());
151 simulateFrame(40);
152 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
153 EXPECT_EQ(-10, player->currentTimeInternal());
154 }
155
156 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegativeWithoutSimultaneousPl aybackRateChange)
157 {
158 simulateFrame(20);
159 EXPECT_EQ(20, player->currentTimeInternal());
160 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
161 player->setPlaybackRate(-1);
162 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
163 simulateFrame(30);
164 EXPECT_EQ(20, player->currentTimeInternal());
165 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
166 player->setCurrentTime(-10 * 1000);
167 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
168 }
169
170 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEnd)
171 {
172 player->setCurrentTime(50 * 1000);
173 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
174 EXPECT_EQ(50, player->currentTimeInternal());
175 simulateFrame(20);
176 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
177 EXPECT_EQ(50, player->currentTimeInternal());
178
179 player->setPlaybackRate(-2);
180 player->setCurrentTime(50 * 1000);
181 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
182 EXPECT_EQ(50, player->currentTimeInternal());
183 simulateFrame(20);
184 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
185 simulateFrame(40);
186 EXPECT_EQ(10, player->currentTimeInternal());
187 }
188
189 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeBeforeTimelineStarted)
190 {
191 setUpWithoutStartingTimeline();
192 player->setCurrentTimeInternal(5);
193 EXPECT_EQ(5, player->currentTimeInternal());
194 startTimeline();
195 simulateFrame(10);
196 EXPECT_EQ(15, player->currentTimeInternal());
197 }
198
199 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEndBeforeTimelineS tarted)
200 {
201 setUpWithoutStartingTimeline();
202 player->setCurrentTime(250 * 1000);
203 EXPECT_EQ(250, player->currentTimeInternal());
204 startTimeline();
205 simulateFrame(10);
206 EXPECT_EQ(250, player->currentTimeInternal());
207 }
208
209 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeMax)
210 {
211 player->setCurrentTimeInternal(std::numeric_limits<double>::max());
212 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal()) ;
213 simulateFrame(100);
214 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal()) ;
215 }
216
217 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeSetsStartTime)
218 {
219 EXPECT_EQ(0, player->startTime());
220 player->setCurrentTime(1000);
221 EXPECT_EQ(-1000, player->startTime());
222 simulateFrame(1);
223 EXPECT_EQ(-1000, player->startTime());
224 EXPECT_EQ(2000, player->currentTime());
225 }
226
227 TEST_F(AnimationAnimationPlayerTest, SetStartTime)
228 {
229 simulateFrame(20);
230 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
231 EXPECT_EQ(0, player->startTimeInternal());
232 EXPECT_EQ(20 * 1000, player->currentTime());
233 player->setStartTime(10 * 1000);
234 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
235 EXPECT_EQ(10, player->startTimeInternal());
236 EXPECT_EQ(10 * 1000, player->currentTime());
237 simulateFrame(30);
238 EXPECT_EQ(10, player->startTimeInternal());
239 EXPECT_EQ(20 * 1000, player->currentTime());
240 player->setStartTime(-20 * 1000);
241 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
242 }
243
244 TEST_F(AnimationAnimationPlayerTest, SetStartTimeLimitsAnimationPlayer)
245 {
246 player->setStartTime(-50 * 1000);
247 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
248 EXPECT_EQ(30, player->currentTimeInternal());
249 player->setPlaybackRate(-1);
250 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
251 player->setStartTime(-100 * 1000);
252 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
253 EXPECT_EQ(0, player->currentTimeInternal());
254 EXPECT_TRUE(player->limited());
255 }
256
257 TEST_F(AnimationAnimationPlayerTest, SetStartTimeOnLimitedAnimationPlayer)
258 {
259 simulateFrame(30);
260 player->setStartTime(-10 * 1000);
261 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
262 EXPECT_EQ(30, player->currentTimeInternal());
263 player->setCurrentTimeInternal(50);
264 player->setStartTime(-40 * 1000);
265 EXPECT_EQ(30, player->currentTimeInternal());
266 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
267 EXPECT_TRUE(player->limited());
268 }
269
270 TEST_F(AnimationAnimationPlayerTest, StartTimePauseFinish)
271 {
272 player->pause();
273 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
274 EXPECT_TRUE(std::isnan(player->startTime()));
275 player->finish(exceptionState);
276 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
277 EXPECT_TRUE(std::isnan(player->startTime()));
278 }
279
280 TEST_F(AnimationAnimationPlayerTest, PauseBeatsFinish)
281 {
282 player->pause();
283 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
284 simulateFrame(10);
285 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
286 player->finish(exceptionState);
287 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
288 }
289
290 TEST_F(AnimationAnimationPlayerTest, StartTimeFinishPause)
291 {
292 player->finish(exceptionState);
293 EXPECT_EQ(-30 * 1000, player->startTime());
294 player->pause();
295 EXPECT_TRUE(std::isnan(player->startTime()));
296 }
297
298 TEST_F(AnimationAnimationPlayerTest, StartTimeWithZeroPlaybackRate)
299 {
300 player->setPlaybackRate(0);
301 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
302 EXPECT_TRUE(std::isnan(player->startTime()));
303 simulateFrame(10);
304 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
305 }
306
307 TEST_F(AnimationAnimationPlayerTest, PausePlay)
308 {
309 simulateFrame(10);
310 player->pause();
311 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
312 EXPECT_TRUE(player->paused());
313 EXPECT_EQ(10, player->currentTimeInternal());
314 simulateFrame(20);
315 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
316 player->play();
317 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
318 simulateFrame(20);
319 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
320 EXPECT_FALSE(player->paused());
321 EXPECT_EQ(10, player->currentTimeInternal());
322 simulateFrame(30);
323 EXPECT_EQ(20, player->currentTimeInternal());
324 }
325
326 TEST_F(AnimationAnimationPlayerTest, PauseBeforeTimelineStarted)
327 {
328 setUpWithoutStartingTimeline();
329 player->pause();
330 EXPECT_TRUE(player->paused());
331 player->play();
332 EXPECT_FALSE(player->paused());
333
334 player->pause();
335 startTimeline();
336 simulateFrame(100);
337 EXPECT_TRUE(player->paused());
338 EXPECT_EQ(0, player->currentTimeInternal());
339 }
340
341 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToStart)
342 {
343 player->setCurrentTimeInternal(30);
344 player->play();
345 EXPECT_EQ(0, player->currentTimeInternal());
346
347 player->setCurrentTimeInternal(40);
348 player->play();
349 EXPECT_EQ(0, player->currentTimeInternal());
350 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
351 simulateFrame(10);
352 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
353
354 player->setCurrentTimeInternal(-10);
355 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
356 player->play();
357 EXPECT_EQ(0, player->currentTimeInternal());
358 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
359 simulateFrame(10);
360 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
361 }
362
363 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToEnd)
364 {
365 player->setPlaybackRate(-1);
366 player->play();
367 EXPECT_EQ(30, player->currentTimeInternal());
368
369 player->setCurrentTimeInternal(40);
370 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
371 player->play();
372 EXPECT_EQ(30, player->currentTimeInternal());
373 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
374 simulateFrame(10);
375 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
376
377 player->setCurrentTimeInternal(-10);
378 player->play();
379 EXPECT_EQ(30, player->currentTimeInternal());
380 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
381 simulateFrame(20);
382 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
383 }
384
385 TEST_F(AnimationAnimationPlayerTest, PlayWithPlaybackRateZeroDoesNotSeek)
386 {
387 player->setPlaybackRate(0);
388 player->play();
389 EXPECT_EQ(0, player->currentTimeInternal());
390
391 player->setCurrentTimeInternal(40);
392 player->play();
393 EXPECT_EQ(40, player->currentTimeInternal());
394
395 player->setCurrentTimeInternal(-10);
396 player->play();
397 EXPECT_EQ(-10, player->currentTimeInternal());
398 }
399
400 TEST_F(AnimationAnimationPlayerTest, PlayAfterPauseWithPlaybackRateZeroUpdatesPl ayState)
401 {
402 player->pause();
403 player->setPlaybackRate(0);
404 simulateFrame(1);
405 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal());
406 player->play();
407 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
408 }
409
410 TEST_F(AnimationAnimationPlayerTest, Reverse)
411 {
412 player->setCurrentTimeInternal(10);
413 player->pause();
414 player->reverse();
415 EXPECT_FALSE(player->paused());
416 EXPECT_EQ(-1, player->playbackRate());
417 EXPECT_EQ(10, player->currentTimeInternal());
418 }
419
420 TEST_F(AnimationAnimationPlayerTest, ReverseDoesNothingWithPlaybackRateZero)
421 {
422 player->setCurrentTimeInternal(10);
423 player->setPlaybackRate(0);
424 player->pause();
425 player->reverse();
426 EXPECT_TRUE(player->paused());
427 EXPECT_EQ(0, player->playbackRate());
428 EXPECT_EQ(10, player->currentTimeInternal());
429 }
430
431 TEST_F(AnimationAnimationPlayerTest, ReverseDoesNotSeekWithNoSource)
432 {
433 player->setSource(0);
434 player->setCurrentTimeInternal(10);
435 player->reverse();
436 EXPECT_EQ(10, player->currentTimeInternal());
437 }
438
439 TEST_F(AnimationAnimationPlayerTest, ReverseSeeksToStart)
440 {
441 player->setCurrentTimeInternal(-10);
442 player->setPlaybackRate(-1);
443 player->reverse();
444 EXPECT_EQ(0, player->currentTimeInternal());
445 }
446
447 TEST_F(AnimationAnimationPlayerTest, ReverseSeeksToEnd)
448 {
449 player->setCurrentTime(40 * 1000);
450 player->reverse();
451 EXPECT_EQ(30, player->currentTimeInternal());
452 }
453
454 TEST_F(AnimationAnimationPlayerTest, ReverseBeyondLimit)
455 {
456 player->setCurrentTimeInternal(40);
457 player->setPlaybackRate(-1);
458 player->reverse();
459 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
460 EXPECT_EQ(0, player->currentTimeInternal());
461
462 player->setCurrentTimeInternal(-10);
463 player->reverse();
464 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
465 EXPECT_EQ(30, player->currentTimeInternal());
466 }
467
468
469 TEST_F(AnimationAnimationPlayerTest, Finish)
470 {
471 player->finish(exceptionState);
472 EXPECT_EQ(30, player->currentTimeInternal());
473 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
474
475 player->setPlaybackRate(-1);
476 player->finish(exceptionState);
477 EXPECT_EQ(0, player->currentTimeInternal());
478 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal());
479
480 EXPECT_FALSE(exceptionState.hadException());
481 }
482
483 TEST_F(AnimationAnimationPlayerTest, FinishAfterSourceEnd)
484 {
485 player->setCurrentTime(40 * 1000);
486 player->finish(exceptionState);
487 EXPECT_EQ(30, player->currentTimeInternal());
488 }
489
490 TEST_F(AnimationAnimationPlayerTest, FinishBeforeStart)
491 {
492 player->setCurrentTimeInternal(-10);
493 player->setPlaybackRate(-1);
494 player->finish(exceptionState);
495 EXPECT_EQ(0, player->currentTimeInternal());
496 }
497
498 TEST_F(AnimationAnimationPlayerTest, FinishDoesNothingWithPlaybackRateZero)
499 {
500 player->setCurrentTimeInternal(10);
501 player->setPlaybackRate(0);
502 player->finish(exceptionState);
503 EXPECT_EQ(10, player->currentTimeInternal());
504 }
505
506 TEST_F(AnimationAnimationPlayerTest, FinishRaisesException)
507 {
508 Timing timing;
509 timing.iterationDuration = 1;
510 timing.iterationCount = std::numeric_limits<double>::infinity();
511 player->setSource(Animation::create(0, nullptr, timing).get());
512 player->setCurrentTimeInternal(10);
513
514 player->finish(exceptionState);
515 EXPECT_EQ(10, player->currentTimeInternal());
516 EXPECT_TRUE(exceptionState.hadException());
517 EXPECT_EQ(InvalidStateError, exceptionState.code());
518 }
519
520
521 TEST_F(AnimationAnimationPlayerTest, LimitingAtSourceEnd)
522 {
523 simulateFrame(30);
524 EXPECT_EQ(30, player->currentTimeInternal());
525 EXPECT_TRUE(player->limited());
526 simulateFrame(40);
527 EXPECT_EQ(30, player->currentTimeInternal());
528 EXPECT_FALSE(player->paused());
529 }
530
531 TEST_F(AnimationAnimationPlayerTest, LimitingAtStart)
532 {
533 simulateFrame(30);
534 player->setPlaybackRate(-2);
535 simulateFrame(30);
536 simulateFrame(45);
537 EXPECT_EQ(0, player->currentTimeInternal());
538 EXPECT_TRUE(player->limited());
539 simulateFrame(60);
540 EXPECT_EQ(0, player->currentTimeInternal());
541 EXPECT_FALSE(player->paused());
542 }
543
544 TEST_F(AnimationAnimationPlayerTest, LimitingWithNoSource)
545 {
546 player->setSource(0);
547 EXPECT_TRUE(player->limited());
548 simulateFrame(30);
549 EXPECT_EQ(0, player->currentTimeInternal());
550 }
551
552
553 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRate)
554 {
555 player->setPlaybackRate(2);
556 simulateFrame(0);
557 EXPECT_EQ(2, player->playbackRate());
558 EXPECT_EQ(0, player->currentTimeInternal());
559 simulateFrame(10);
560 EXPECT_EQ(20, player->currentTimeInternal());
561 }
562
563 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateBeforeTimelineStarted)
564 {
565 setUpWithoutStartingTimeline();
566 player->setPlaybackRate(2);
567 EXPECT_EQ(2, player->playbackRate());
568 EXPECT_EQ(0, player->currentTimeInternal());
569 startTimeline();
570 simulateFrame(10);
571 EXPECT_EQ(20, player->currentTimeInternal());
572 }
573
574 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhilePaused)
575 {
576 simulateFrame(10);
577 player->pause();
578 player->setPlaybackRate(2);
579 simulateFrame(20);
580 player->play();
581 EXPECT_EQ(10, player->currentTimeInternal());
582 simulateFrame(20);
583 simulateFrame(25);
584 EXPECT_EQ(20, player->currentTimeInternal());
585 }
586
587 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhileLimited)
588 {
589 simulateFrame(40);
590 EXPECT_EQ(30, player->currentTimeInternal());
591 player->setPlaybackRate(2);
592 simulateFrame(50);
593 EXPECT_EQ(30, player->currentTimeInternal());
594 player->setPlaybackRate(-2);
595 simulateFrame(50);
596 simulateFrame(60);
597 EXPECT_FALSE(player->limited());
598 EXPECT_EQ(10, player->currentTimeInternal());
599 }
600
601 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateZero)
602 {
603 simulateFrame(0);
604 simulateFrame(10);
605 player->setPlaybackRate(0);
606 simulateFrame(10);
607 EXPECT_EQ(10, player->currentTimeInternal());
608 simulateFrame(20);
609 EXPECT_EQ(10, player->currentTimeInternal());
610 player->setCurrentTimeInternal(20);
611 EXPECT_EQ(20, player->currentTimeInternal());
612 }
613
614 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateMax)
615 {
616 player->setPlaybackRate(std::numeric_limits<double>::max());
617 simulateFrame(0);
618 EXPECT_EQ(std::numeric_limits<double>::max(), player->playbackRate());
619 EXPECT_EQ(0, player->currentTimeInternal());
620 simulateFrame(1);
621 EXPECT_EQ(30, player->currentTimeInternal());
622 }
623
624
625 TEST_F(AnimationAnimationPlayerTest, SetSource)
626 {
627 player = timeline->play(0);
628 player->setStartTime(0);
629 RefPtrWillBeRawPtr<AnimationNode> source1 = makeAnimation();
630 RefPtrWillBeRawPtr<AnimationNode> source2 = makeAnimation();
631 player->setSource(source1.get());
632 EXPECT_EQ(source1, player->source());
633 EXPECT_EQ(0, player->currentTimeInternal());
634 player->setCurrentTimeInternal(15);
635 player->setSource(source2.get());
636 EXPECT_EQ(15, player->currentTimeInternal());
637 EXPECT_EQ(0, source1->player());
638 EXPECT_EQ(player.get(), source2->player());
639 EXPECT_EQ(source2, player->source());
640 }
641
642 TEST_F(AnimationAnimationPlayerTest, SetSourceLimitsAnimationPlayer)
643 {
644 player->setCurrentTimeInternal(20);
645 player->setSource(makeAnimation(10).get());
646 EXPECT_EQ(20, player->currentTimeInternal());
647 EXPECT_TRUE(player->limited());
648 simulateFrame(10);
649 EXPECT_EQ(20, player->currentTimeInternal());
650 }
651
652 TEST_F(AnimationAnimationPlayerTest, SetSourceUnlimitsAnimationPlayer)
653 {
654 player->setCurrentTimeInternal(40);
655 player->setSource(makeAnimation(60).get());
656 EXPECT_FALSE(player->limited());
657 EXPECT_EQ(40, player->currentTimeInternal());
658 simulateFrame(10);
659 EXPECT_EQ(50, player->currentTimeInternal());
660 }
661
662
663 TEST_F(AnimationAnimationPlayerTest, EmptyAnimationPlayersDontUpdateEffects)
664 {
665 player = timeline->play(0);
666 player->update(TimingUpdateOnDemand);
667 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
668
669 simulateFrame(1234);
670 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
671 }
672
673 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersDisassociateFromSource)
674 {
675 AnimationNode* animationNode = player->source();
676 AnimationPlayer* player2 = timeline->play(animationNode);
677 EXPECT_EQ(0, player->source());
678 player->setSource(animationNode);
679 EXPECT_EQ(0, player2->source());
680 }
681
682 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect)
683 {
684 Timing timing;
685 timing.startDelay = 1;
686 timing.iterationDuration = 1;
687 timing.endDelay = 1;
688 RefPtrWillBeRawPtr<Animation> animation = Animation::create(0, nullptr, timi ng);
689 player = timeline->play(animation.get());
690 player->setStartTime(0);
691
692 simulateFrame(0);
693 EXPECT_EQ(1, player->timeToEffectChange());
694
695 simulateFrame(0.5);
696 EXPECT_EQ(0.5, player->timeToEffectChange());
697
698 simulateFrame(1);
699 EXPECT_EQ(0, player->timeToEffectChange());
700
701 simulateFrame(1.5);
702 EXPECT_EQ(0, player->timeToEffectChange());
703
704 simulateFrame(2);
705 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
706
707 simulateFrame(3);
708 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
709
710 player->setCurrentTimeInternal(0);
711 simulateFrame(3);
712 EXPECT_EQ(1, player->timeToEffectChange());
713
714 player->setPlaybackRate(2);
715 simulateFrame(3);
716 EXPECT_EQ(0.5, player->timeToEffectChange());
717
718 player->setPlaybackRate(0);
719 player->update(TimingUpdateOnDemand);
720 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
721
722 player->setCurrentTimeInternal(3);
723 player->setPlaybackRate(-1);
724 player->update(TimingUpdateOnDemand);
725 simulateFrame(3);
726 EXPECT_EQ(1, player->timeToEffectChange());
727
728 player->setPlaybackRate(-2);
729 player->update(TimingUpdateOnDemand);
730 simulateFrame(3);
731 EXPECT_EQ(0.5, player->timeToEffectChange());
732 }
733
734 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenPaused)
735 {
736 EXPECT_EQ(0, player->timeToEffectChange());
737 player->pause();
738 player->update(TimingUpdateOnDemand);
739 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
740 }
741
742 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStart)
743 {
744 EXPECT_EQ(0, player->timeToEffectChange());
745 player->setCurrentTimeInternal(-8);
746 player->setPlaybackRate(2);
747 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
748 player->cancel();
749 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
750 player->update(TimingUpdateOnDemand);
751 // This frame will fire the finish event event though no start time has been
752 // received from the compositor yet, as cancel() nukes start times.
753 simulateFrame(0);
754 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
755 }
756
757 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartRev erse)
758 {
759 EXPECT_EQ(0, player->timeToEffectChange());
760 player->setCurrentTimeInternal(9);
761 player->setPlaybackRate(-3);
762 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
763 player->cancel();
764 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
765 player->update(TimingUpdateOnDemand);
766 // This frame will fire the finish event event though no start time has been
767 // received from the compositor yet, as cancel() nukes start times.
768 simulateFrame(0);
769 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
770 }
771
772 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectSimpleCancelledBeforeStart)
773 {
774 EXPECT_EQ(0, player->timeToEffectChange());
775 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
776 player->cancel();
777 player->update(TimingUpdateOnDemand);
778 // This frame will fire the finish event event though no start time has been
779 // received from the compositor yet, as cancel() nukes start times.
780 simulateFrame(0);
781 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang e());
782 }
783
784 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers)
785 {
786 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION);
787
788 Timing timing;
789 RefPtrWillBeRawPtr<Animation> animation = Animation::create(element.get(), n ullptr, timing);
790 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->play(animation.get()) ;
791 simulateFrame(0);
792 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
793 EXPECT_EQ(1U, element->elementAnimations()->players().find(player.get())->va lue);
794
795 player.release();
796 Heap::collectAllGarbage();
797 EXPECT_TRUE(element->elementAnimations()->players().isEmpty());
798 }
799
800 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority)
801 {
802 RefPtrWillBeRawPtr<AnimationPlayer> player1 = timeline->play(0);
803 RefPtrWillBeRawPtr<AnimationPlayer> player2 = timeline->play(0);
804 EXPECT_TRUE(AnimationPlayer::hasLowerPriority(player1.get(), player2.get())) ;
805 }
806
807 TEST_F(AnimationAnimationPlayerTest, PlayAfterCancel)
808 {
809 player->cancel();
810 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
811 EXPECT_TRUE(std::isnan(player->currentTime()));
812 EXPECT_TRUE(std::isnan(player->startTime()));
813 player->play();
814 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
815 EXPECT_EQ(0, player->currentTime());
816 EXPECT_TRUE(std::isnan(player->startTime()));
817 simulateFrame(10);
818 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
819 EXPECT_EQ(0, player->currentTime());
820 EXPECT_EQ(10 * 1000, player->startTime());
821 }
822
823 TEST_F(AnimationAnimationPlayerTest, PlayBackwardsAfterCancel)
824 {
825 player->setPlaybackRate(-1);
826 player->setCurrentTime(15 * 1000);
827 simulateFrame(0);
828 player->cancel();
829 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
830 EXPECT_TRUE(std::isnan(player->currentTime()));
831 EXPECT_TRUE(std::isnan(player->startTime()));
832 player->play();
833 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
834 EXPECT_EQ(30 * 1000, player->currentTime());
835 EXPECT_TRUE(std::isnan(player->startTime()));
836 simulateFrame(10);
837 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
838 EXPECT_EQ(30 * 1000, player->currentTime());
839 EXPECT_EQ(40 * 1000, player->startTime());
840 }
841
842 TEST_F(AnimationAnimationPlayerTest, ReverseAfterCancel)
843 {
844 player->cancel();
845 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
846 EXPECT_TRUE(std::isnan(player->currentTime()));
847 EXPECT_TRUE(std::isnan(player->startTime()));
848 player->reverse();
849 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal());
850 EXPECT_EQ(30 * 1000, player->currentTime());
851 EXPECT_TRUE(std::isnan(player->startTime()));
852 simulateFrame(10);
853 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal());
854 EXPECT_EQ(30 * 1000, player->currentTime());
855 EXPECT_EQ(40 * 1000, player->startTime());
856 }
857
858 TEST_F(AnimationAnimationPlayerTest, FinishAfterCancel)
859 {
860 player->cancel();
861 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
862 EXPECT_TRUE(std::isnan(player->currentTime()));
863 EXPECT_TRUE(std::isnan(player->startTime()));
864 player->finish(exceptionState);
865 EXPECT_TRUE(std::isnan(player->currentTime()));
866 EXPECT_TRUE(std::isnan(player->startTime()));
867 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
868 }
869
870 TEST_F(AnimationAnimationPlayerTest, PauseAfterCancel)
871 {
872 player->cancel();
873 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
874 EXPECT_TRUE(std::isnan(player->currentTime()));
875 EXPECT_TRUE(std::isnan(player->startTime()));
876 player->pause();
877 EXPECT_EQ(AnimationPlayer::Idle, player->playStateInternal());
878 EXPECT_TRUE(std::isnan(player->currentTime()));
879 EXPECT_TRUE(std::isnan(player->startTime()));
880 }
881
882 }
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationPlayer.idl ('k') | Source/core/animation/AnimationStack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698