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

Side by Side Diff: third_party/WebKit/Source/core/animation/AnimationTest.cpp

Issue 1410313004: Web Animations: Use a single animation clock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/Animation.h" 32 #include "core/animation/Animation.h"
33 33
34 #include "core/animation/AnimationClock.h" 34 #include "core/animation/AnimationClock.h"
35 #include "core/animation/AnimationTimeline.h" 35 #include "core/animation/AnimationTimeline.h"
36 #include "core/animation/ElementAnimations.h" 36 #include "core/animation/ElementAnimations.h"
37 #include "core/animation/KeyframeEffect.h" 37 #include "core/animation/KeyframeEffect.h"
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/ExceptionCode.h" 39 #include "core/dom/ExceptionCode.h"
40 #include "core/dom/QualifiedName.h" 40 #include "core/dom/QualifiedName.h"
41 #include "core/testing/DummyPageHolder.h"
41 #include "platform/weborigin/KURL.h" 42 #include "platform/weborigin/KURL.h"
42 #include <gtest/gtest.h> 43 #include <gtest/gtest.h>
43 44
44 namespace blink { 45 namespace blink {
45 46
46 class AnimationAnimationTest : public ::testing::Test { 47 class AnimationAnimationTest : public ::testing::Test {
47 protected: 48 protected:
48 void SetUp() override 49 void SetUp() override
49 { 50 {
50 setUpWithoutStartingTimeline(); 51 setUpWithoutStartingTimeline();
51 startTimeline(); 52 startTimeline();
52 } 53 }
53 54
54 void setUpWithoutStartingTimeline() 55 void setUpWithoutStartingTimeline()
55 { 56 {
56 document = Document::create(); 57 pageHolder = DummyPageHolder::create();
58 document = &pageHolder->document();
57 document->animationClock().resetTimeForTesting(); 59 document->animationClock().resetTimeForTesting();
58 timeline = AnimationTimeline::create(document.get()); 60 timeline = AnimationTimeline::create(document.get());
61 timeline->resetForTesting();
59 animation = timeline->play(0); 62 animation = timeline->play(0);
60 animation->setStartTime(0); 63 animation->setStartTime(0);
61 animation->setEffect(makeAnimation()); 64 animation->setEffect(makeAnimation());
62 } 65 }
63 66
64 void startTimeline() 67 void startTimeline()
65 { 68 {
66 simulateFrame(0); 69 simulateFrame(0);
67 } 70 }
68 71
(...skipping 10 matching lines...) Expand all
79 document->animationClock().updateTime(time); 82 document->animationClock().updateTime(time);
80 document->compositorPendingAnimations().update(false); 83 document->compositorPendingAnimations().update(false);
81 // The timeline does not know about our animation, so we have to explici tly call update(). 84 // The timeline does not know about our animation, so we have to explici tly call update().
82 return animation->update(TimingUpdateForAnimationFrame); 85 return animation->update(TimingUpdateForAnimationFrame);
83 } 86 }
84 87
85 RefPtrWillBePersistent<Document> document; 88 RefPtrWillBePersistent<Document> document;
86 Persistent<AnimationTimeline> timeline; 89 Persistent<AnimationTimeline> timeline;
87 Persistent<Animation> animation; 90 Persistent<Animation> animation;
88 TrackExceptionState exceptionState; 91 TrackExceptionState exceptionState;
92 OwnPtr<DummyPageHolder> pageHolder;
89 }; 93 };
90 94
91 TEST_F(AnimationAnimationTest, InitialState) 95 TEST_F(AnimationAnimationTest, InitialState)
92 { 96 {
93 setUpWithoutStartingTimeline(); 97 setUpWithoutStartingTimeline();
94 animation = timeline->play(0); 98 animation = timeline->play(0);
95 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 99 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
96 EXPECT_EQ(0, animation->currentTimeInternal()); 100 EXPECT_EQ(0, animation->currentTimeInternal());
97 EXPECT_FALSE(animation->paused()); 101 EXPECT_FALSE(animation->paused());
98 EXPECT_EQ(1, animation->playbackRate()); 102 EXPECT_EQ(1, animation->playbackRate());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 animation->setPlaybackRate(-2); 180 animation->setPlaybackRate(-2);
177 animation->setCurrentTime(50 * 1000); 181 animation->setCurrentTime(50 * 1000);
178 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 182 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
179 EXPECT_EQ(50, animation->currentTimeInternal()); 183 EXPECT_EQ(50, animation->currentTimeInternal());
180 simulateFrame(20); 184 simulateFrame(20);
181 EXPECT_EQ(Animation::Running, animation->playStateInternal()); 185 EXPECT_EQ(Animation::Running, animation->playStateInternal());
182 simulateFrame(40); 186 simulateFrame(40);
183 EXPECT_EQ(10, animation->currentTimeInternal()); 187 EXPECT_EQ(10, animation->currentTimeInternal());
184 } 188 }
185 189
186 TEST_F(AnimationAnimationTest, SetCurrentTimeBeforeTimelineStarted)
187 {
188 setUpWithoutStartingTimeline();
189 animation->setCurrentTimeInternal(5);
190 EXPECT_EQ(5, animation->currentTimeInternal());
191 startTimeline();
192 simulateFrame(10);
193 EXPECT_EQ(15, animation->currentTimeInternal());
194 }
195
196 TEST_F(AnimationAnimationTest, SetCurrentTimePastContentEndBeforeTimelineStarted )
197 {
198 setUpWithoutStartingTimeline();
199 animation->setCurrentTime(250 * 1000);
200 EXPECT_EQ(250, animation->currentTimeInternal());
201 startTimeline();
202 simulateFrame(10);
203 EXPECT_EQ(250, animation->currentTimeInternal());
204 }
205
206 TEST_F(AnimationAnimationTest, SetCurrentTimeMax) 190 TEST_F(AnimationAnimationTest, SetCurrentTimeMax)
207 { 191 {
208 animation->setCurrentTimeInternal(std::numeric_limits<double>::max()); 192 animation->setCurrentTimeInternal(std::numeric_limits<double>::max());
209 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal ()); 193 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal ());
210 simulateFrame(100); 194 simulateFrame(100);
211 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal ()); 195 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal ());
212 } 196 }
213 197
214 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime) 198 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime)
215 { 199 {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 animation->play(); 297 animation->play();
314 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 298 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
315 simulateFrame(20); 299 simulateFrame(20);
316 EXPECT_EQ(Animation::Running, animation->playStateInternal()); 300 EXPECT_EQ(Animation::Running, animation->playStateInternal());
317 EXPECT_FALSE(animation->paused()); 301 EXPECT_FALSE(animation->paused());
318 EXPECT_EQ(10, animation->currentTimeInternal()); 302 EXPECT_EQ(10, animation->currentTimeInternal());
319 simulateFrame(30); 303 simulateFrame(30);
320 EXPECT_EQ(20, animation->currentTimeInternal()); 304 EXPECT_EQ(20, animation->currentTimeInternal());
321 } 305 }
322 306
323 TEST_F(AnimationAnimationTest, PauseBeforeTimelineStarted)
324 {
325 setUpWithoutStartingTimeline();
326 animation->pause();
327 EXPECT_TRUE(animation->paused());
328 animation->play();
329 EXPECT_FALSE(animation->paused());
330
331 animation->pause();
332 startTimeline();
333 simulateFrame(100);
334 EXPECT_TRUE(animation->paused());
335 EXPECT_EQ(0, animation->currentTimeInternal());
336 }
337
338 TEST_F(AnimationAnimationTest, PlayRewindsToStart) 307 TEST_F(AnimationAnimationTest, PlayRewindsToStart)
339 { 308 {
340 animation->setCurrentTimeInternal(30); 309 animation->setCurrentTimeInternal(30);
341 animation->play(); 310 animation->play();
342 EXPECT_EQ(0, animation->currentTimeInternal()); 311 EXPECT_EQ(0, animation->currentTimeInternal());
343 312
344 animation->setCurrentTimeInternal(40); 313 animation->setCurrentTimeInternal(40);
345 animation->play(); 314 animation->play();
346 EXPECT_EQ(0, animation->currentTimeInternal()); 315 EXPECT_EQ(0, animation->currentTimeInternal());
347 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 316 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 TEST_F(AnimationAnimationTest, SetPlaybackRate) 517 TEST_F(AnimationAnimationTest, SetPlaybackRate)
549 { 518 {
550 animation->setPlaybackRate(2); 519 animation->setPlaybackRate(2);
551 simulateFrame(0); 520 simulateFrame(0);
552 EXPECT_EQ(2, animation->playbackRate()); 521 EXPECT_EQ(2, animation->playbackRate());
553 EXPECT_EQ(0, animation->currentTimeInternal()); 522 EXPECT_EQ(0, animation->currentTimeInternal());
554 simulateFrame(10); 523 simulateFrame(10);
555 EXPECT_EQ(20, animation->currentTimeInternal()); 524 EXPECT_EQ(20, animation->currentTimeInternal());
556 } 525 }
557 526
558 TEST_F(AnimationAnimationTest, SetPlaybackRateBeforeTimelineStarted)
559 {
560 setUpWithoutStartingTimeline();
561 animation->setPlaybackRate(2);
562 EXPECT_EQ(2, animation->playbackRate());
563 EXPECT_EQ(0, animation->currentTimeInternal());
564 startTimeline();
565 simulateFrame(10);
566 EXPECT_EQ(20, animation->currentTimeInternal());
567 }
568
569 TEST_F(AnimationAnimationTest, SetPlaybackRateWhilePaused) 527 TEST_F(AnimationAnimationTest, SetPlaybackRateWhilePaused)
570 { 528 {
571 simulateFrame(10); 529 simulateFrame(10);
572 animation->pause(); 530 animation->pause();
573 animation->setPlaybackRate(2); 531 animation->setPlaybackRate(2);
574 simulateFrame(20); 532 simulateFrame(20);
575 animation->play(); 533 animation->play();
576 EXPECT_EQ(10, animation->currentTimeInternal()); 534 EXPECT_EQ(10, animation->currentTimeInternal());
577 simulateFrame(20); 535 simulateFrame(20);
578 simulateFrame(25); 536 simulateFrame(25);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 825 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
868 EXPECT_TRUE(std::isnan(animation->currentTime())); 826 EXPECT_TRUE(std::isnan(animation->currentTime()));
869 EXPECT_TRUE(std::isnan(animation->startTime())); 827 EXPECT_TRUE(std::isnan(animation->startTime()));
870 animation->pause(); 828 animation->pause();
871 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 829 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
872 EXPECT_TRUE(std::isnan(animation->currentTime())); 830 EXPECT_TRUE(std::isnan(animation->currentTime()));
873 EXPECT_TRUE(std::isnan(animation->startTime())); 831 EXPECT_TRUE(std::isnan(animation->startTime()));
874 } 832 }
875 833
876 } // namespace blink 834 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698