OLD | NEW |
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 Loading... |
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" | |
42 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
43 #include <gtest/gtest.h> | 42 #include <gtest/gtest.h> |
44 | 43 |
45 namespace blink { | 44 namespace blink { |
46 | 45 |
47 class AnimationAnimationTest : public ::testing::Test { | 46 class AnimationAnimationTest : public ::testing::Test { |
48 protected: | 47 protected: |
49 void SetUp() override | 48 void SetUp() override |
50 { | 49 { |
51 setUpWithoutStartingTimeline(); | 50 setUpWithoutStartingTimeline(); |
52 startTimeline(); | 51 startTimeline(); |
53 } | 52 } |
54 | 53 |
55 void setUpWithoutStartingTimeline() | 54 void setUpWithoutStartingTimeline() |
56 { | 55 { |
57 pageHolder = DummyPageHolder::create(); | 56 document = Document::create(); |
58 document = &pageHolder->document(); | |
59 document->animationClock().resetTimeForTesting(); | 57 document->animationClock().resetTimeForTesting(); |
60 timeline = AnimationTimeline::create(document.get()); | 58 timeline = AnimationTimeline::create(document.get()); |
61 animation = timeline->play(0); | 59 animation = timeline->play(0); |
62 animation->setStartTime(0); | 60 animation->setStartTime(0); |
63 animation->setEffect(makeAnimation()); | 61 animation->setEffect(makeAnimation()); |
64 } | 62 } |
65 | 63 |
66 void startTimeline() | 64 void startTimeline() |
67 { | 65 { |
68 simulateFrame(0); | 66 simulateFrame(0); |
69 } | 67 } |
70 | 68 |
71 KeyframeEffect* makeAnimation(double duration = 30, double playbackRate = 1) | 69 KeyframeEffect* makeAnimation(double duration = 30, double playbackRate = 1) |
72 { | 70 { |
73 Timing timing; | 71 Timing timing; |
74 timing.iterationDuration = duration; | 72 timing.iterationDuration = duration; |
75 timing.playbackRate = playbackRate; | 73 timing.playbackRate = playbackRate; |
76 return KeyframeEffect::create(0, nullptr, timing); | 74 return KeyframeEffect::create(0, nullptr, timing); |
77 } | 75 } |
78 | 76 |
79 bool simulateFrame(double time) | 77 bool simulateFrame(double time) |
80 { | 78 { |
81 document->animationClock().updateTime(document->timeline().zeroTime() +
time); | 79 document->animationClock().updateTime(time); |
82 document->compositorPendingAnimations().update(false); | 80 document->compositorPendingAnimations().update(false); |
83 // The timeline does not know about our animation, so we have to explici
tly call update(). | 81 // The timeline does not know about our animation, so we have to explici
tly call update(). |
84 return animation->update(TimingUpdateForAnimationFrame); | 82 return animation->update(TimingUpdateForAnimationFrame); |
85 } | 83 } |
86 | 84 |
87 RefPtrWillBePersistent<Document> document; | 85 RefPtrWillBePersistent<Document> document; |
88 Persistent<AnimationTimeline> timeline; | 86 Persistent<AnimationTimeline> timeline; |
89 Persistent<Animation> animation; | 87 Persistent<Animation> animation; |
90 TrackExceptionState exceptionState; | 88 TrackExceptionState exceptionState; |
91 OwnPtr<DummyPageHolder> pageHolder; | |
92 }; | 89 }; |
93 | 90 |
94 TEST_F(AnimationAnimationTest, InitialState) | 91 TEST_F(AnimationAnimationTest, InitialState) |
95 { | 92 { |
96 setUpWithoutStartingTimeline(); | 93 setUpWithoutStartingTimeline(); |
97 animation = timeline->play(0); | 94 animation = timeline->play(0); |
98 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); | 95 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); |
99 EXPECT_EQ(0, animation->currentTimeInternal()); | 96 EXPECT_EQ(0, animation->currentTimeInternal()); |
100 EXPECT_FALSE(animation->paused()); | 97 EXPECT_FALSE(animation->paused()); |
101 EXPECT_EQ(1, animation->playbackRate()); | 98 EXPECT_EQ(1, animation->playbackRate()); |
(...skipping 11 matching lines...) Expand all Loading... |
113 } | 110 } |
114 | 111 |
115 TEST_F(AnimationAnimationTest, CurrentTimeDoesNotSetOutdated) | 112 TEST_F(AnimationAnimationTest, CurrentTimeDoesNotSetOutdated) |
116 { | 113 { |
117 EXPECT_FALSE(animation->outdated()); | 114 EXPECT_FALSE(animation->outdated()); |
118 EXPECT_EQ(0, animation->currentTimeInternal()); | 115 EXPECT_EQ(0, animation->currentTimeInternal()); |
119 EXPECT_FALSE(animation->outdated()); | 116 EXPECT_FALSE(animation->outdated()); |
120 // FIXME: We should split simulateFrame into a version that doesn't update | 117 // FIXME: We should split simulateFrame into a version that doesn't update |
121 // the animation and one that does, as most of the tests don't require updat
e() | 118 // the animation and one that does, as most of the tests don't require updat
e() |
122 // to be called. | 119 // to be called. |
123 document->animationClock().updateTime(document->timeline().zeroTime() + 10); | 120 document->animationClock().updateTime(10); |
124 EXPECT_EQ(10, animation->currentTimeInternal()); | 121 EXPECT_EQ(10, animation->currentTimeInternal()); |
125 EXPECT_FALSE(animation->outdated()); | 122 EXPECT_FALSE(animation->outdated()); |
126 } | 123 } |
127 | 124 |
128 TEST_F(AnimationAnimationTest, SetCurrentTime) | 125 TEST_F(AnimationAnimationTest, SetCurrentTime) |
129 { | 126 { |
130 EXPECT_EQ(Animation::Running, animation->playStateInternal()); | 127 EXPECT_EQ(Animation::Running, animation->playStateInternal()); |
131 animation->setCurrentTimeInternal(10); | 128 animation->setCurrentTimeInternal(10); |
132 EXPECT_EQ(Animation::Running, animation->playStateInternal()); | 129 EXPECT_EQ(Animation::Running, animation->playStateInternal()); |
133 EXPECT_EQ(10, animation->currentTimeInternal()); | 130 EXPECT_EQ(10, animation->currentTimeInternal()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 animation->setPlaybackRate(-2); | 176 animation->setPlaybackRate(-2); |
180 animation->setCurrentTime(50 * 1000); | 177 animation->setCurrentTime(50 * 1000); |
181 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); | 178 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); |
182 EXPECT_EQ(50, animation->currentTimeInternal()); | 179 EXPECT_EQ(50, animation->currentTimeInternal()); |
183 simulateFrame(20); | 180 simulateFrame(20); |
184 EXPECT_EQ(Animation::Running, animation->playStateInternal()); | 181 EXPECT_EQ(Animation::Running, animation->playStateInternal()); |
185 simulateFrame(40); | 182 simulateFrame(40); |
186 EXPECT_EQ(10, animation->currentTimeInternal()); | 183 EXPECT_EQ(10, animation->currentTimeInternal()); |
187 } | 184 } |
188 | 185 |
| 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 |
189 TEST_F(AnimationAnimationTest, SetCurrentTimeMax) | 206 TEST_F(AnimationAnimationTest, SetCurrentTimeMax) |
190 { | 207 { |
191 animation->setCurrentTimeInternal(std::numeric_limits<double>::max()); | 208 animation->setCurrentTimeInternal(std::numeric_limits<double>::max()); |
192 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal
()); | 209 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal
()); |
193 simulateFrame(100); | 210 simulateFrame(100); |
194 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal
()); | 211 EXPECT_EQ(std::numeric_limits<double>::max(), animation->currentTimeInternal
()); |
195 } | 212 } |
196 | 213 |
197 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime) | 214 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime) |
198 { | 215 { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 animation->play(); | 313 animation->play(); |
297 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); | 314 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); |
298 simulateFrame(20); | 315 simulateFrame(20); |
299 EXPECT_EQ(Animation::Running, animation->playStateInternal()); | 316 EXPECT_EQ(Animation::Running, animation->playStateInternal()); |
300 EXPECT_FALSE(animation->paused()); | 317 EXPECT_FALSE(animation->paused()); |
301 EXPECT_EQ(10, animation->currentTimeInternal()); | 318 EXPECT_EQ(10, animation->currentTimeInternal()); |
302 simulateFrame(30); | 319 simulateFrame(30); |
303 EXPECT_EQ(20, animation->currentTimeInternal()); | 320 EXPECT_EQ(20, animation->currentTimeInternal()); |
304 } | 321 } |
305 | 322 |
| 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 |
306 TEST_F(AnimationAnimationTest, PlayRewindsToStart) | 338 TEST_F(AnimationAnimationTest, PlayRewindsToStart) |
307 { | 339 { |
308 animation->setCurrentTimeInternal(30); | 340 animation->setCurrentTimeInternal(30); |
309 animation->play(); | 341 animation->play(); |
310 EXPECT_EQ(0, animation->currentTimeInternal()); | 342 EXPECT_EQ(0, animation->currentTimeInternal()); |
311 | 343 |
312 animation->setCurrentTimeInternal(40); | 344 animation->setCurrentTimeInternal(40); |
313 animation->play(); | 345 animation->play(); |
314 EXPECT_EQ(0, animation->currentTimeInternal()); | 346 EXPECT_EQ(0, animation->currentTimeInternal()); |
315 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); | 347 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 547 |
516 TEST_F(AnimationAnimationTest, SetPlaybackRate) | 548 TEST_F(AnimationAnimationTest, SetPlaybackRate) |
517 { | 549 { |
518 animation->setPlaybackRate(2); | 550 animation->setPlaybackRate(2); |
519 simulateFrame(0); | 551 simulateFrame(0); |
520 EXPECT_EQ(2, animation->playbackRate()); | 552 EXPECT_EQ(2, animation->playbackRate()); |
521 EXPECT_EQ(0, animation->currentTimeInternal()); | 553 EXPECT_EQ(0, animation->currentTimeInternal()); |
522 simulateFrame(10); | 554 simulateFrame(10); |
523 EXPECT_EQ(20, animation->currentTimeInternal()); | 555 EXPECT_EQ(20, animation->currentTimeInternal()); |
524 } | 556 } |
| 557 |
| 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 } |
525 | 568 |
526 TEST_F(AnimationAnimationTest, SetPlaybackRateWhilePaused) | 569 TEST_F(AnimationAnimationTest, SetPlaybackRateWhilePaused) |
527 { | 570 { |
528 simulateFrame(10); | 571 simulateFrame(10); |
529 animation->pause(); | 572 animation->pause(); |
530 animation->setPlaybackRate(2); | 573 animation->setPlaybackRate(2); |
531 simulateFrame(20); | 574 simulateFrame(20); |
532 animation->play(); | 575 animation->play(); |
533 EXPECT_EQ(10, animation->currentTimeInternal()); | 576 EXPECT_EQ(10, animation->currentTimeInternal()); |
534 simulateFrame(20); | 577 simulateFrame(20); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); | 867 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); |
825 EXPECT_TRUE(std::isnan(animation->currentTime())); | 868 EXPECT_TRUE(std::isnan(animation->currentTime())); |
826 EXPECT_TRUE(std::isnan(animation->startTime())); | 869 EXPECT_TRUE(std::isnan(animation->startTime())); |
827 animation->pause(); | 870 animation->pause(); |
828 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); | 871 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); |
829 EXPECT_TRUE(std::isnan(animation->currentTime())); | 872 EXPECT_TRUE(std::isnan(animation->currentTime())); |
830 EXPECT_TRUE(std::isnan(animation->startTime())); | 873 EXPECT_TRUE(std::isnan(animation->startTime())); |
831 } | 874 } |
832 | 875 |
833 } // namespace blink | 876 } // namespace blink |
OLD | NEW |