| OLD | NEW |
| (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 "sky/engine/core/animation/AnimationPlayer.h" | |
| 32 | |
| 33 #include <gtest/gtest.h> | |
| 34 #include "sky/engine/core/animation/ActiveAnimations.h" | |
| 35 #include "sky/engine/core/animation/Animation.h" | |
| 36 #include "sky/engine/core/animation/AnimationClock.h" | |
| 37 #include "sky/engine/core/animation/AnimationTimeline.h" | |
| 38 #include "sky/engine/core/dom/Document.h" | |
| 39 #include "sky/engine/core/dom/QualifiedName.h" | |
| 40 #include "sky/engine/platform/weborigin/KURL.h" | |
| 41 | |
| 42 using namespace blink; | |
| 43 | |
| 44 namespace { | |
| 45 | |
| 46 class AnimationAnimationPlayerTest : public ::testing::Test { | |
| 47 protected: | |
| 48 virtual void SetUp() | |
| 49 { | |
| 50 setUpWithoutStartingTimeline(); | |
| 51 startTimeline(); | |
| 52 } | |
| 53 | |
| 54 void setUpWithoutStartingTimeline() | |
| 55 { | |
| 56 document = Document::create(); | |
| 57 document->animationClock().resetTimeForTesting(); | |
| 58 timeline = AnimationTimeline::create(document.get()); | |
| 59 player = timeline->createAnimationPlayer(0); | |
| 60 player->setStartTime(0); | |
| 61 player->setSource(makeAnimation().get()); | |
| 62 } | |
| 63 | |
| 64 void startTimeline() | |
| 65 { | |
| 66 simulateFrame(0); | |
| 67 } | |
| 68 | |
| 69 PassRefPtr<Animation> makeAnimation(double duration = 30, double playbackRat
e = 1) | |
| 70 { | |
| 71 Timing timing; | |
| 72 timing.iterationDuration = duration; | |
| 73 timing.playbackRate = playbackRate; | |
| 74 return Animation::create(0, nullptr, timing); | |
| 75 } | |
| 76 | |
| 77 bool simulateFrame(double time) | |
| 78 { | |
| 79 document->animationClock().updateTime(time); | |
| 80 document->pendingAnimations().update(false); | |
| 81 // The timeline does not know about our player, so we have to explicitly
call update(). | |
| 82 return player->update(TimingUpdateForAnimationFrame); | |
| 83 } | |
| 84 | |
| 85 RefPtr<Document> document; | |
| 86 RefPtr<AnimationTimeline> timeline; | |
| 87 RefPtr<AnimationPlayer> player; | |
| 88 TrackExceptionState exceptionState; | |
| 89 }; | |
| 90 | |
| 91 TEST_F(AnimationAnimationPlayerTest, InitialState) | |
| 92 { | |
| 93 setUpWithoutStartingTimeline(); | |
| 94 player = timeline->createAnimationPlayer(0); | |
| 95 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 96 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 97 EXPECT_FALSE(player->paused()); | |
| 98 EXPECT_EQ(1, player->playbackRate()); | |
| 99 EXPECT_FALSE(player->hasStartTime()); | |
| 100 EXPECT_TRUE(isNull(player->startTimeInternal())); | |
| 101 | |
| 102 startTimeline(); | |
| 103 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 104 EXPECT_EQ(0, timeline->currentTimeInternal()); | |
| 105 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 106 EXPECT_FALSE(player->paused()); | |
| 107 EXPECT_EQ(1, player->playbackRate()); | |
| 108 EXPECT_EQ(0, player->startTimeInternal()); | |
| 109 EXPECT_TRUE(player->hasStartTime()); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 TEST_F(AnimationAnimationPlayerTest, CurrentTimeDoesNotSetOutdated) | |
| 114 { | |
| 115 EXPECT_FALSE(player->outdated()); | |
| 116 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 117 EXPECT_FALSE(player->outdated()); | |
| 118 // FIXME: We should split simulateFrame into a version that doesn't update | |
| 119 // the player and one that does, as most of the tests don't require update() | |
| 120 // to be called. | |
| 121 document->animationClock().updateTime(10); | |
| 122 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 123 EXPECT_FALSE(player->outdated()); | |
| 124 } | |
| 125 | |
| 126 TEST_F(AnimationAnimationPlayerTest, SetCurrentTime) | |
| 127 { | |
| 128 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 129 player->setCurrentTimeInternal(10); | |
| 130 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 131 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 132 simulateFrame(10); | |
| 133 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 134 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 135 } | |
| 136 | |
| 137 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegative) | |
| 138 { | |
| 139 player->setCurrentTimeInternal(-10); | |
| 140 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 141 EXPECT_EQ(-10, player->currentTimeInternal()); | |
| 142 simulateFrame(20); | |
| 143 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 144 | |
| 145 player->setPlaybackRate(-2); | |
| 146 player->setCurrentTimeInternal(-10); | |
| 147 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 148 EXPECT_EQ(-10, player->currentTimeInternal()); | |
| 149 simulateFrame(40); | |
| 150 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 151 EXPECT_EQ(-10, player->currentTimeInternal()); | |
| 152 } | |
| 153 | |
| 154 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeNegativeWithoutSimultaneousPl
aybackRateChange) | |
| 155 { | |
| 156 simulateFrame(20); | |
| 157 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 158 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 159 player->setPlaybackRate(-1); | |
| 160 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 161 simulateFrame(30); | |
| 162 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 163 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 164 player->setCurrentTimeInternal(-10); | |
| 165 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 166 } | |
| 167 | |
| 168 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEnd) | |
| 169 { | |
| 170 player->setCurrentTimeInternal(50); | |
| 171 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 172 EXPECT_EQ(50, player->currentTimeInternal()); | |
| 173 simulateFrame(20); | |
| 174 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 175 EXPECT_EQ(50, player->currentTimeInternal()); | |
| 176 | |
| 177 player->setPlaybackRate(-2); | |
| 178 player->setCurrentTimeInternal(50); | |
| 179 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 180 EXPECT_EQ(50, player->currentTimeInternal()); | |
| 181 simulateFrame(20); | |
| 182 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 183 simulateFrame(40); | |
| 184 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 185 } | |
| 186 | |
| 187 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeBeforeTimelineStarted) | |
| 188 { | |
| 189 setUpWithoutStartingTimeline(); | |
| 190 player->setCurrentTimeInternal(5); | |
| 191 EXPECT_EQ(5, player->currentTimeInternal()); | |
| 192 startTimeline(); | |
| 193 simulateFrame(10); | |
| 194 EXPECT_EQ(15, player->currentTimeInternal()); | |
| 195 } | |
| 196 | |
| 197 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimePastContentEndBeforeTimelineS
tarted) | |
| 198 { | |
| 199 setUpWithoutStartingTimeline(); | |
| 200 player->setCurrentTimeInternal(250); | |
| 201 EXPECT_EQ(250, player->currentTimeInternal()); | |
| 202 startTimeline(); | |
| 203 simulateFrame(10); | |
| 204 EXPECT_EQ(250, player->currentTimeInternal()); | |
| 205 } | |
| 206 | |
| 207 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeMax) | |
| 208 { | |
| 209 player->setCurrentTimeInternal(std::numeric_limits<double>::max()); | |
| 210 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal())
; | |
| 211 simulateFrame(100); | |
| 212 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTimeInternal())
; | |
| 213 } | |
| 214 | |
| 215 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeUnrestrictedDouble) | |
| 216 { | |
| 217 simulateFrame(10); | |
| 218 player->setCurrentTime(nullValue()); | |
| 219 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 220 player->setCurrentTime(std::numeric_limits<double>::infinity()); | |
| 221 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 222 player->setCurrentTime(-std::numeric_limits<double>::infinity()); | |
| 223 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 224 } | |
| 225 | |
| 226 | |
| 227 TEST_F(AnimationAnimationPlayerTest, SetCurrentTimeSetsStartTime) | |
| 228 { | |
| 229 EXPECT_EQ(0, player->startTime()); | |
| 230 player->setCurrentTime(1000); | |
| 231 EXPECT_EQ(-1000, player->startTime()); | |
| 232 simulateFrame(1); | |
| 233 EXPECT_EQ(-1000, player->startTime()); | |
| 234 EXPECT_EQ(2000, player->currentTime()); | |
| 235 } | |
| 236 | |
| 237 TEST_F(AnimationAnimationPlayerTest, SetStartTime) | |
| 238 { | |
| 239 simulateFrame(20); | |
| 240 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 241 EXPECT_EQ(0, player->startTimeInternal()); | |
| 242 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 243 player->setStartTime(10 * 1000); | |
| 244 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 245 EXPECT_EQ(10, player->startTimeInternal()); | |
| 246 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 247 simulateFrame(30); | |
| 248 EXPECT_EQ(10, player->startTimeInternal()); | |
| 249 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 250 player->setStartTime(-20 * 1000); | |
| 251 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 252 } | |
| 253 | |
| 254 TEST_F(AnimationAnimationPlayerTest, SetStartTimeLimitsAnimationPlayer) | |
| 255 { | |
| 256 player->setStartTime(-50 * 1000); | |
| 257 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 258 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 259 player->setPlaybackRate(-1); | |
| 260 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 261 player->setStartTime(-100 * 1000); | |
| 262 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 263 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 264 EXPECT_TRUE(player->finished()); | |
| 265 } | |
| 266 | |
| 267 TEST_F(AnimationAnimationPlayerTest, SetStartTimeOnLimitedAnimationPlayer) | |
| 268 { | |
| 269 simulateFrame(30); | |
| 270 player->setStartTime(-10 * 1000); | |
| 271 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 272 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 273 player->setCurrentTimeInternal(50); | |
| 274 player->setStartTime(-40 * 1000); | |
| 275 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 276 EXPECT_EQ(AnimationPlayer::Finished, player->playStateInternal()); | |
| 277 EXPECT_TRUE(player->finished()); | |
| 278 } | |
| 279 | |
| 280 TEST_F(AnimationAnimationPlayerTest, StartTimePauseFinish) | |
| 281 { | |
| 282 player->pause(); | |
| 283 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 284 EXPECT_TRUE(std::isnan(player->startTime())); | |
| 285 player->finish(exceptionState); | |
| 286 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 287 EXPECT_TRUE(std::isnan(player->startTime())); | |
| 288 } | |
| 289 | |
| 290 TEST_F(AnimationAnimationPlayerTest, PauseBeatsFinish) | |
| 291 { | |
| 292 player->pause(); | |
| 293 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 294 simulateFrame(10); | |
| 295 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal()); | |
| 296 player->finish(exceptionState); | |
| 297 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal()); | |
| 298 } | |
| 299 | |
| 300 TEST_F(AnimationAnimationPlayerTest, StartTimeFinishPause) | |
| 301 { | |
| 302 double startTime = player->startTime(); | |
| 303 player->finish(exceptionState); | |
| 304 EXPECT_EQ(startTime, player->startTime()); | |
| 305 player->pause(); | |
| 306 EXPECT_TRUE(std::isnan(player->startTime())); | |
| 307 } | |
| 308 | |
| 309 TEST_F(AnimationAnimationPlayerTest, StartTimeWithZeroPlaybackRate) | |
| 310 { | |
| 311 player->setPlaybackRate(0); | |
| 312 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 313 EXPECT_TRUE(std::isnan(player->startTime())); | |
| 314 simulateFrame(10); | |
| 315 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 316 } | |
| 317 | |
| 318 TEST_F(AnimationAnimationPlayerTest, PausePlay) | |
| 319 { | |
| 320 simulateFrame(10); | |
| 321 player->pause(); | |
| 322 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 323 EXPECT_TRUE(player->paused()); | |
| 324 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 325 simulateFrame(20); | |
| 326 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal()); | |
| 327 player->play(); | |
| 328 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 329 simulateFrame(20); | |
| 330 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 331 EXPECT_FALSE(player->paused()); | |
| 332 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 333 simulateFrame(30); | |
| 334 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 335 } | |
| 336 | |
| 337 TEST_F(AnimationAnimationPlayerTest, PauseBeforeTimelineStarted) | |
| 338 { | |
| 339 setUpWithoutStartingTimeline(); | |
| 340 player->pause(); | |
| 341 EXPECT_TRUE(player->paused()); | |
| 342 player->play(); | |
| 343 EXPECT_FALSE(player->paused()); | |
| 344 | |
| 345 player->pause(); | |
| 346 startTimeline(); | |
| 347 simulateFrame(100); | |
| 348 EXPECT_TRUE(player->paused()); | |
| 349 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 350 } | |
| 351 | |
| 352 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToStart) | |
| 353 { | |
| 354 player->setCurrentTimeInternal(30); | |
| 355 player->play(); | |
| 356 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 357 | |
| 358 player->setCurrentTimeInternal(40); | |
| 359 player->play(); | |
| 360 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 361 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 362 simulateFrame(10); | |
| 363 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 364 | |
| 365 player->setCurrentTimeInternal(-10); | |
| 366 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 367 player->play(); | |
| 368 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 369 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 370 } | |
| 371 | |
| 372 TEST_F(AnimationAnimationPlayerTest, PlayRewindsToEnd) | |
| 373 { | |
| 374 player->setPlaybackRate(-1); | |
| 375 player->play(); | |
| 376 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 377 | |
| 378 player->setCurrentTimeInternal(40); | |
| 379 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 380 player->play(); | |
| 381 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 382 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 383 simulateFrame(10); | |
| 384 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 385 | |
| 386 player->setCurrentTimeInternal(-10); | |
| 387 player->play(); | |
| 388 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 389 EXPECT_EQ(AnimationPlayer::Pending, player->playStateInternal()); | |
| 390 simulateFrame(20); | |
| 391 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 392 } | |
| 393 | |
| 394 TEST_F(AnimationAnimationPlayerTest, PlayWithPlaybackRateZeroDoesNotSeek) | |
| 395 { | |
| 396 player->setPlaybackRate(0); | |
| 397 player->play(); | |
| 398 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 399 | |
| 400 player->setCurrentTimeInternal(40); | |
| 401 player->play(); | |
| 402 EXPECT_EQ(40, player->currentTimeInternal()); | |
| 403 | |
| 404 player->setCurrentTimeInternal(-10); | |
| 405 player->play(); | |
| 406 EXPECT_EQ(-10, player->currentTimeInternal()); | |
| 407 } | |
| 408 | |
| 409 TEST_F(AnimationAnimationPlayerTest, PlayAfterPauseWithPlaybackRateZeroUpdatesPl
ayState) | |
| 410 { | |
| 411 player->pause(); | |
| 412 player->setPlaybackRate(0); | |
| 413 simulateFrame(1); | |
| 414 EXPECT_EQ(AnimationPlayer::Paused, player->playStateInternal()); | |
| 415 player->play(); | |
| 416 EXPECT_EQ(AnimationPlayer::Running, player->playStateInternal()); | |
| 417 } | |
| 418 | |
| 419 TEST_F(AnimationAnimationPlayerTest, Reverse) | |
| 420 { | |
| 421 player->setCurrentTimeInternal(10); | |
| 422 player->pause(); | |
| 423 player->reverse(); | |
| 424 EXPECT_FALSE(player->paused()); | |
| 425 EXPECT_EQ(-1, player->playbackRate()); | |
| 426 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 427 } | |
| 428 | |
| 429 TEST_F(AnimationAnimationPlayerTest, ReverseDoesNothingWithPlaybackRateZero) | |
| 430 { | |
| 431 player->setCurrentTimeInternal(10); | |
| 432 player->setPlaybackRate(0); | |
| 433 player->pause(); | |
| 434 player->reverse(); | |
| 435 EXPECT_TRUE(player->paused()); | |
| 436 EXPECT_EQ(0, player->playbackRate()); | |
| 437 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 438 } | |
| 439 | |
| 440 TEST_F(AnimationAnimationPlayerTest, ReverseDoesNotSeekWithNoSource) | |
| 441 { | |
| 442 player->setSource(0); | |
| 443 player->setCurrentTimeInternal(10); | |
| 444 player->reverse(); | |
| 445 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 446 } | |
| 447 | |
| 448 TEST_F(AnimationAnimationPlayerTest, ReverseSeeksToStart) | |
| 449 { | |
| 450 player->setCurrentTimeInternal(-10); | |
| 451 player->setPlaybackRate(-1); | |
| 452 player->reverse(); | |
| 453 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 454 } | |
| 455 | |
| 456 TEST_F(AnimationAnimationPlayerTest, ReverseSeeksToEnd) | |
| 457 { | |
| 458 player->setCurrentTimeInternal(40); | |
| 459 player->reverse(); | |
| 460 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 461 } | |
| 462 | |
| 463 TEST_F(AnimationAnimationPlayerTest, ReverseLimitsAnimationPlayer) | |
| 464 { | |
| 465 player->setCurrentTimeInternal(40); | |
| 466 player->setPlaybackRate(-1); | |
| 467 player->reverse(); | |
| 468 EXPECT_TRUE(player->finished()); | |
| 469 EXPECT_EQ(40, player->currentTimeInternal()); | |
| 470 | |
| 471 player->setCurrentTimeInternal(-10); | |
| 472 player->reverse(); | |
| 473 EXPECT_TRUE(player->finished()); | |
| 474 EXPECT_EQ(-10, player->currentTimeInternal()); | |
| 475 } | |
| 476 | |
| 477 | |
| 478 TEST_F(AnimationAnimationPlayerTest, Finish) | |
| 479 { | |
| 480 player->finish(exceptionState); | |
| 481 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 482 EXPECT_TRUE(player->finished()); | |
| 483 | |
| 484 player->setPlaybackRate(-1); | |
| 485 player->finish(exceptionState); | |
| 486 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 487 EXPECT_TRUE(player->finished()); | |
| 488 | |
| 489 EXPECT_FALSE(exceptionState.had_exception()); | |
| 490 } | |
| 491 | |
| 492 TEST_F(AnimationAnimationPlayerTest, FinishAfterSourceEnd) | |
| 493 { | |
| 494 player->setCurrentTimeInternal(40); | |
| 495 player->finish(exceptionState); | |
| 496 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 497 } | |
| 498 | |
| 499 TEST_F(AnimationAnimationPlayerTest, FinishBeforeStart) | |
| 500 { | |
| 501 player->setCurrentTimeInternal(-10); | |
| 502 player->setPlaybackRate(-1); | |
| 503 player->finish(exceptionState); | |
| 504 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 505 } | |
| 506 | |
| 507 TEST_F(AnimationAnimationPlayerTest, FinishDoesNothingWithPlaybackRateZero) | |
| 508 { | |
| 509 player->setCurrentTimeInternal(10); | |
| 510 player->setPlaybackRate(0); | |
| 511 player->finish(exceptionState); | |
| 512 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 513 } | |
| 514 | |
| 515 TEST_F(AnimationAnimationPlayerTest, FinishRaisesException) | |
| 516 { | |
| 517 Timing timing; | |
| 518 timing.iterationDuration = 1; | |
| 519 timing.iterationCount = std::numeric_limits<double>::infinity(); | |
| 520 player->setSource(Animation::create(0, nullptr, timing).get()); | |
| 521 player->setCurrentTimeInternal(10); | |
| 522 | |
| 523 player->finish(exceptionState); | |
| 524 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 525 EXPECT_TRUE(exceptionState.had_exception()); | |
| 526 EXPECT_EQ(InvalidStateError, exceptionState.code()); | |
| 527 } | |
| 528 | |
| 529 | |
| 530 TEST_F(AnimationAnimationPlayerTest, LimitingAtSourceEnd) | |
| 531 { | |
| 532 simulateFrame(30); | |
| 533 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 534 EXPECT_TRUE(player->finished()); | |
| 535 simulateFrame(40); | |
| 536 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 537 EXPECT_FALSE(player->paused()); | |
| 538 } | |
| 539 | |
| 540 TEST_F(AnimationAnimationPlayerTest, LimitingAtStart) | |
| 541 { | |
| 542 simulateFrame(30); | |
| 543 player->setPlaybackRate(-2); | |
| 544 simulateFrame(30); | |
| 545 simulateFrame(45); | |
| 546 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 547 EXPECT_TRUE(player->finished()); | |
| 548 simulateFrame(60); | |
| 549 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 550 EXPECT_FALSE(player->paused()); | |
| 551 } | |
| 552 | |
| 553 TEST_F(AnimationAnimationPlayerTest, LimitingWithNoSource) | |
| 554 { | |
| 555 player->setSource(0); | |
| 556 EXPECT_TRUE(player->finished()); | |
| 557 simulateFrame(30); | |
| 558 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 559 } | |
| 560 | |
| 561 | |
| 562 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRate) | |
| 563 { | |
| 564 player->setPlaybackRate(2); | |
| 565 simulateFrame(0); | |
| 566 EXPECT_EQ(2, player->playbackRate()); | |
| 567 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 568 simulateFrame(10); | |
| 569 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 570 } | |
| 571 | |
| 572 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateBeforeTimelineStarted) | |
| 573 { | |
| 574 setUpWithoutStartingTimeline(); | |
| 575 player->setPlaybackRate(2); | |
| 576 EXPECT_EQ(2, player->playbackRate()); | |
| 577 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 578 startTimeline(); | |
| 579 simulateFrame(10); | |
| 580 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 581 } | |
| 582 | |
| 583 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhilePaused) | |
| 584 { | |
| 585 simulateFrame(10); | |
| 586 player->pause(); | |
| 587 player->setPlaybackRate(2); | |
| 588 simulateFrame(20); | |
| 589 player->play(); | |
| 590 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 591 simulateFrame(20); | |
| 592 simulateFrame(25); | |
| 593 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 594 } | |
| 595 | |
| 596 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateWhileLimited) | |
| 597 { | |
| 598 simulateFrame(40); | |
| 599 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 600 player->setPlaybackRate(2); | |
| 601 simulateFrame(50); | |
| 602 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 603 player->setPlaybackRate(-2); | |
| 604 simulateFrame(50); | |
| 605 simulateFrame(60); | |
| 606 EXPECT_FALSE(player->finished()); | |
| 607 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 608 } | |
| 609 | |
| 610 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateZero) | |
| 611 { | |
| 612 simulateFrame(0); | |
| 613 simulateFrame(10); | |
| 614 player->setPlaybackRate(0); | |
| 615 simulateFrame(10); | |
| 616 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 617 simulateFrame(20); | |
| 618 EXPECT_EQ(10, player->currentTimeInternal()); | |
| 619 player->setCurrentTimeInternal(20); | |
| 620 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 621 } | |
| 622 | |
| 623 TEST_F(AnimationAnimationPlayerTest, SetPlaybackRateMax) | |
| 624 { | |
| 625 player->setPlaybackRate(std::numeric_limits<double>::max()); | |
| 626 simulateFrame(0); | |
| 627 EXPECT_EQ(std::numeric_limits<double>::max(), player->playbackRate()); | |
| 628 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 629 simulateFrame(1); | |
| 630 EXPECT_EQ(30, player->currentTimeInternal()); | |
| 631 } | |
| 632 | |
| 633 | |
| 634 TEST_F(AnimationAnimationPlayerTest, SetSource) | |
| 635 { | |
| 636 player = timeline->createAnimationPlayer(0); | |
| 637 player->setStartTime(0); | |
| 638 RefPtr<AnimationNode> source1 = makeAnimation(); | |
| 639 RefPtr<AnimationNode> source2 = makeAnimation(); | |
| 640 player->setSource(source1.get()); | |
| 641 EXPECT_EQ(source1, player->source()); | |
| 642 EXPECT_EQ(0, player->currentTimeInternal()); | |
| 643 player->setCurrentTimeInternal(15); | |
| 644 player->setSource(source2.get()); | |
| 645 EXPECT_EQ(15, player->currentTimeInternal()); | |
| 646 EXPECT_EQ(0, source1->player()); | |
| 647 EXPECT_EQ(player.get(), source2->player()); | |
| 648 EXPECT_EQ(source2, player->source()); | |
| 649 } | |
| 650 | |
| 651 TEST_F(AnimationAnimationPlayerTest, SetSourceLimitsAnimationPlayer) | |
| 652 { | |
| 653 player->setCurrentTimeInternal(20); | |
| 654 player->setSource(makeAnimation(10).get()); | |
| 655 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 656 EXPECT_TRUE(player->finished()); | |
| 657 simulateFrame(10); | |
| 658 EXPECT_EQ(20, player->currentTimeInternal()); | |
| 659 } | |
| 660 | |
| 661 TEST_F(AnimationAnimationPlayerTest, SetSourceUnlimitsAnimationPlayer) | |
| 662 { | |
| 663 player->setCurrentTimeInternal(40); | |
| 664 player->setSource(makeAnimation(60).get()); | |
| 665 EXPECT_FALSE(player->finished()); | |
| 666 EXPECT_EQ(40, player->currentTimeInternal()); | |
| 667 simulateFrame(10); | |
| 668 EXPECT_EQ(50, player->currentTimeInternal()); | |
| 669 } | |
| 670 | |
| 671 | |
| 672 TEST_F(AnimationAnimationPlayerTest, EmptyAnimationPlayersDontUpdateEffects) | |
| 673 { | |
| 674 player = timeline->createAnimationPlayer(0); | |
| 675 player->update(TimingUpdateOnDemand); | |
| 676 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 677 | |
| 678 simulateFrame(1234); | |
| 679 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 680 } | |
| 681 | |
| 682 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersDisassociateFromSource) | |
| 683 { | |
| 684 AnimationNode* animationNode = player->source(); | |
| 685 AnimationPlayer* player2 = timeline->createAnimationPlayer(animationNode); | |
| 686 EXPECT_EQ(0, player->source()); | |
| 687 player->setSource(animationNode); | |
| 688 EXPECT_EQ(0, player2->source()); | |
| 689 } | |
| 690 | |
| 691 TEST_F(AnimationAnimationPlayerTest, AnimationPlayersReturnTimeToNextEffect) | |
| 692 { | |
| 693 Timing timing; | |
| 694 timing.startDelay = 1; | |
| 695 timing.iterationDuration = 1; | |
| 696 timing.endDelay = 1; | |
| 697 RefPtr<Animation> animation = Animation::create(0, nullptr, timing); | |
| 698 player = timeline->createAnimationPlayer(animation.get()); | |
| 699 player->setStartTime(0); | |
| 700 | |
| 701 simulateFrame(0); | |
| 702 EXPECT_EQ(1, player->timeToEffectChange()); | |
| 703 | |
| 704 simulateFrame(0.5); | |
| 705 EXPECT_EQ(0.5, player->timeToEffectChange()); | |
| 706 | |
| 707 simulateFrame(1); | |
| 708 EXPECT_EQ(0, player->timeToEffectChange()); | |
| 709 | |
| 710 simulateFrame(1.5); | |
| 711 EXPECT_EQ(0, player->timeToEffectChange()); | |
| 712 | |
| 713 simulateFrame(2); | |
| 714 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 715 | |
| 716 simulateFrame(3); | |
| 717 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 718 | |
| 719 player->setCurrentTimeInternal(0); | |
| 720 simulateFrame(3); | |
| 721 EXPECT_EQ(1, player->timeToEffectChange()); | |
| 722 | |
| 723 player->setPlaybackRate(2); | |
| 724 simulateFrame(3); | |
| 725 EXPECT_EQ(0.5, player->timeToEffectChange()); | |
| 726 | |
| 727 player->setPlaybackRate(0); | |
| 728 player->update(TimingUpdateOnDemand); | |
| 729 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 730 | |
| 731 player->setCurrentTimeInternal(3); | |
| 732 player->setPlaybackRate(-1); | |
| 733 player->update(TimingUpdateOnDemand); | |
| 734 simulateFrame(3); | |
| 735 EXPECT_EQ(1, player->timeToEffectChange()); | |
| 736 | |
| 737 player->setPlaybackRate(-2); | |
| 738 player->update(TimingUpdateOnDemand); | |
| 739 simulateFrame(3); | |
| 740 EXPECT_EQ(0.5, player->timeToEffectChange()); | |
| 741 } | |
| 742 | |
| 743 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenPaused) | |
| 744 { | |
| 745 EXPECT_EQ(0, player->timeToEffectChange()); | |
| 746 player->pause(); | |
| 747 player->update(TimingUpdateOnDemand); | |
| 748 EXPECT_EQ(std::numeric_limits<double>::infinity(), player->timeToEffectChang
e()); | |
| 749 } | |
| 750 | |
| 751 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStart) | |
| 752 { | |
| 753 EXPECT_EQ(0, player->timeToEffectChange()); | |
| 754 player->setCurrentTimeInternal(-8); | |
| 755 player->setPlaybackRate(2); | |
| 756 player->cancel(); | |
| 757 player->update(TimingUpdateOnDemand); | |
| 758 simulateFrame(0); | |
| 759 EXPECT_EQ(4, player->timeToEffectChange()); | |
| 760 } | |
| 761 | |
| 762 TEST_F(AnimationAnimationPlayerTest, TimeToNextEffectWhenCancelledBeforeStartRev
erse) | |
| 763 { | |
| 764 EXPECT_EQ(0, player->timeToEffectChange()); | |
| 765 player->setCurrentTimeInternal(9); | |
| 766 player->setPlaybackRate(-3); | |
| 767 player->cancel(); | |
| 768 player->update(TimingUpdateOnDemand); | |
| 769 simulateFrame(0); | |
| 770 EXPECT_EQ(3, player->timeToEffectChange()); | |
| 771 } | |
| 772 | |
| 773 TEST_F(AnimationAnimationPlayerTest, AttachedAnimationPlayers) | |
| 774 { | |
| 775 RefPtr<Element> element = document->createElement("foo", ASSERT_NO_EXCEPTION
); | |
| 776 | |
| 777 Timing timing; | |
| 778 RefPtr<Animation> animation = Animation::create(element.get(), nullptr, timi
ng); | |
| 779 RefPtr<AnimationPlayer> player = timeline->createAnimationPlayer(animation.g
et()); | |
| 780 simulateFrame(0); | |
| 781 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | |
| 782 EXPECT_EQ(1U, element->activeAnimations()->players().find(player.get())->val
ue); | |
| 783 | |
| 784 player.release(); | |
| 785 EXPECT_TRUE(element->activeAnimations()->players().isEmpty()); | |
| 786 } | |
| 787 | |
| 788 TEST_F(AnimationAnimationPlayerTest, HasLowerPriority) | |
| 789 { | |
| 790 RefPtr<AnimationPlayer> player1 = timeline->createAnimationPlayer(0); | |
| 791 RefPtr<AnimationPlayer> player2 = timeline->createAnimationPlayer(0); | |
| 792 EXPECT_TRUE(AnimationPlayer::hasLowerPriority(player1.get(), player2.get()))
; | |
| 793 } | |
| 794 | |
| 795 } | |
| OLD | NEW |