| 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 "config.h" | |
| 32 #include "core/animation/AnimationNode.h" | |
| 33 #include "core/animation/ComputedTimingProperties.h" | |
| 34 | |
| 35 #include <gtest/gtest.h> | |
| 36 | |
| 37 using namespace blink; | |
| 38 | |
| 39 namespace { | |
| 40 | |
| 41 class TestAnimationNodeEventDelegate : public AnimationNode::EventDelegate { | |
| 42 public: | |
| 43 virtual void onEventCondition(const AnimationNode& animationNode) override | |
| 44 { | |
| 45 m_eventTriggered = true; | |
| 46 | |
| 47 } | |
| 48 virtual bool requiresIterationEvents(const AnimationNode& animationNode) ove
rride | |
| 49 { | |
| 50 return true; | |
| 51 } | |
| 52 void reset() | |
| 53 { | |
| 54 m_eventTriggered = false; | |
| 55 } | |
| 56 bool eventTriggered() { return m_eventTriggered; } | |
| 57 | |
| 58 private: | |
| 59 bool m_eventTriggered; | |
| 60 }; | |
| 61 | |
| 62 class TestAnimationNode : public AnimationNode { | |
| 63 public: | |
| 64 static PassRefPtrWillBeRawPtr<TestAnimationNode> create(const Timing& specif
ied) | |
| 65 { | |
| 66 return adoptRefWillBeNoop(new TestAnimationNode(specified, new TestAnima
tionNodeEventDelegate())); | |
| 67 } | |
| 68 | |
| 69 void updateInheritedTime(double time) | |
| 70 { | |
| 71 updateInheritedTime(time, TimingUpdateForAnimationFrame); | |
| 72 } | |
| 73 | |
| 74 void updateInheritedTime(double time, TimingUpdateReason reason) | |
| 75 { | |
| 76 m_eventDelegate->reset(); | |
| 77 AnimationNode::updateInheritedTime(time, reason); | |
| 78 } | |
| 79 | |
| 80 virtual void updateChildrenAndEffects() const override { } | |
| 81 void willDetach() { } | |
| 82 TestAnimationNodeEventDelegate* eventDelegate() { return m_eventDelegate.get
(); } | |
| 83 virtual double calculateTimeToEffectChange(bool forwards, double localTime,
double timeToNextIteration) const override | |
| 84 { | |
| 85 m_localTime = localTime; | |
| 86 m_timeToNextIteration = timeToNextIteration; | |
| 87 return -1; | |
| 88 } | |
| 89 double takeLocalTime() | |
| 90 { | |
| 91 const double result = m_localTime; | |
| 92 m_localTime = nullValue(); | |
| 93 return result; | |
| 94 } | |
| 95 | |
| 96 double takeTimeToNextIteration() | |
| 97 { | |
| 98 const double result = m_timeToNextIteration; | |
| 99 m_timeToNextIteration = nullValue(); | |
| 100 return result; | |
| 101 } | |
| 102 | |
| 103 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 104 { | |
| 105 visitor->trace(m_eventDelegate); | |
| 106 AnimationNode::trace(visitor); | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 TestAnimationNode(const Timing& specified, TestAnimationNodeEventDelegate* e
ventDelegate) | |
| 111 : AnimationNode(specified, adoptPtrWillBeNoop(eventDelegate)) | |
| 112 , m_eventDelegate(eventDelegate) | |
| 113 { | |
| 114 } | |
| 115 | |
| 116 RawPtrWillBeMember<TestAnimationNodeEventDelegate> m_eventDelegate; | |
| 117 mutable double m_localTime; | |
| 118 mutable double m_timeToNextIteration; | |
| 119 }; | |
| 120 | |
| 121 TEST(AnimationAnimationNodeTest, Sanity) | |
| 122 { | |
| 123 Timing timing; | |
| 124 timing.iterationDuration = 2; | |
| 125 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 126 | |
| 127 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 128 | |
| 129 animationNode->updateInheritedTime(0); | |
| 130 | |
| 131 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 132 EXPECT_TRUE(animationNode->isInPlay()); | |
| 133 EXPECT_TRUE(animationNode->isCurrent()); | |
| 134 EXPECT_TRUE(animationNode->isInEffect()); | |
| 135 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 136 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 137 EXPECT_EQ(2, animationNode->activeDurationInternal()); | |
| 138 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 139 | |
| 140 animationNode->updateInheritedTime(1); | |
| 141 | |
| 142 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 143 EXPECT_TRUE(animationNode->isInPlay()); | |
| 144 EXPECT_TRUE(animationNode->isCurrent()); | |
| 145 EXPECT_TRUE(animationNode->isInEffect()); | |
| 146 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 147 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 148 EXPECT_EQ(2, animationNode->activeDurationInternal()); | |
| 149 EXPECT_EQ(0.5, animationNode->timeFraction()); | |
| 150 | |
| 151 animationNode->updateInheritedTime(2); | |
| 152 | |
| 153 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 154 EXPECT_FALSE(animationNode->isInPlay()); | |
| 155 EXPECT_FALSE(animationNode->isCurrent()); | |
| 156 EXPECT_TRUE(animationNode->isInEffect()); | |
| 157 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 158 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 159 EXPECT_EQ(2, animationNode->activeDurationInternal()); | |
| 160 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 161 | |
| 162 animationNode->updateInheritedTime(3); | |
| 163 | |
| 164 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 165 EXPECT_FALSE(animationNode->isInPlay()); | |
| 166 EXPECT_FALSE(animationNode->isCurrent()); | |
| 167 EXPECT_TRUE(animationNode->isInEffect()); | |
| 168 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 169 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 170 EXPECT_EQ(2, animationNode->activeDurationInternal()); | |
| 171 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 172 } | |
| 173 | |
| 174 TEST(AnimationAnimationNodeTest, FillAuto) | |
| 175 { | |
| 176 Timing timing; | |
| 177 timing.iterationDuration = 1; | |
| 178 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 179 | |
| 180 animationNode->updateInheritedTime(-1); | |
| 181 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 182 | |
| 183 animationNode->updateInheritedTime(2); | |
| 184 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 185 } | |
| 186 | |
| 187 TEST(AnimationAnimationNodeTest, FillForwards) | |
| 188 { | |
| 189 Timing timing; | |
| 190 timing.iterationDuration = 1; | |
| 191 timing.fillMode = Timing::FillModeForwards; | |
| 192 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 193 | |
| 194 animationNode->updateInheritedTime(-1); | |
| 195 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 196 | |
| 197 animationNode->updateInheritedTime(2); | |
| 198 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 199 } | |
| 200 | |
| 201 TEST(AnimationAnimationNodeTest, FillBackwards) | |
| 202 { | |
| 203 Timing timing; | |
| 204 timing.iterationDuration = 1; | |
| 205 timing.fillMode = Timing::FillModeBackwards; | |
| 206 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 207 | |
| 208 animationNode->updateInheritedTime(-1); | |
| 209 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 210 | |
| 211 animationNode->updateInheritedTime(2); | |
| 212 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 213 } | |
| 214 | |
| 215 TEST(AnimationAnimationNodeTest, FillBoth) | |
| 216 { | |
| 217 Timing timing; | |
| 218 timing.iterationDuration = 1; | |
| 219 timing.fillMode = Timing::FillModeBoth; | |
| 220 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 221 | |
| 222 animationNode->updateInheritedTime(-1); | |
| 223 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 224 | |
| 225 animationNode->updateInheritedTime(2); | |
| 226 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 227 } | |
| 228 | |
| 229 TEST(AnimationAnimationNodeTest, StartDelay) | |
| 230 { | |
| 231 Timing timing; | |
| 232 timing.iterationDuration = 1; | |
| 233 timing.fillMode = Timing::FillModeForwards; | |
| 234 timing.startDelay = 0.5; | |
| 235 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 236 | |
| 237 animationNode->updateInheritedTime(0); | |
| 238 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 239 | |
| 240 animationNode->updateInheritedTime(0.5); | |
| 241 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 242 | |
| 243 animationNode->updateInheritedTime(1.5); | |
| 244 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 245 } | |
| 246 | |
| 247 TEST(AnimationAnimationNodeTest, ZeroIteration) | |
| 248 { | |
| 249 Timing timing; | |
| 250 timing.iterationDuration = 1; | |
| 251 timing.fillMode = Timing::FillModeForwards; | |
| 252 timing.iterationCount = 0; | |
| 253 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 254 | |
| 255 animationNode->updateInheritedTime(-1); | |
| 256 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 257 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 258 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 259 | |
| 260 animationNode->updateInheritedTime(0); | |
| 261 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 262 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 263 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 264 } | |
| 265 | |
| 266 TEST(AnimationAnimationNodeTest, InfiniteIteration) | |
| 267 { | |
| 268 Timing timing; | |
| 269 timing.iterationDuration = 1; | |
| 270 timing.fillMode = Timing::FillModeForwards; | |
| 271 timing.iterationCount = std::numeric_limits<double>::infinity(); | |
| 272 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 273 | |
| 274 animationNode->updateInheritedTime(-1); | |
| 275 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 276 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 277 | |
| 278 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 279 | |
| 280 animationNode->updateInheritedTime(0); | |
| 281 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 282 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 283 } | |
| 284 | |
| 285 TEST(AnimationAnimationNodeTest, Iteration) | |
| 286 { | |
| 287 Timing timing; | |
| 288 timing.iterationCount = 2; | |
| 289 timing.iterationDuration = 2; | |
| 290 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 291 | |
| 292 animationNode->updateInheritedTime(0); | |
| 293 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 294 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 295 | |
| 296 animationNode->updateInheritedTime(1); | |
| 297 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 298 EXPECT_EQ(0.5, animationNode->timeFraction()); | |
| 299 | |
| 300 animationNode->updateInheritedTime(2); | |
| 301 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 302 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 303 | |
| 304 animationNode->updateInheritedTime(2); | |
| 305 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 306 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 307 | |
| 308 animationNode->updateInheritedTime(5); | |
| 309 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 310 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 311 } | |
| 312 | |
| 313 TEST(AnimationAnimationNodeTest, IterationStart) | |
| 314 { | |
| 315 Timing timing; | |
| 316 timing.iterationStart = 1.2; | |
| 317 timing.iterationCount = 2.2; | |
| 318 timing.iterationDuration = 1; | |
| 319 timing.fillMode = Timing::FillModeBoth; | |
| 320 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 321 | |
| 322 animationNode->updateInheritedTime(-1); | |
| 323 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 324 EXPECT_NEAR(0.2, animationNode->timeFraction(), 0.000000000000001); | |
| 325 | |
| 326 animationNode->updateInheritedTime(0); | |
| 327 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 328 EXPECT_NEAR(0.2, animationNode->timeFraction(), 0.000000000000001); | |
| 329 | |
| 330 animationNode->updateInheritedTime(10); | |
| 331 EXPECT_EQ(3, animationNode->currentIteration()); | |
| 332 EXPECT_NEAR(0.4, animationNode->timeFraction(), 0.000000000000001); | |
| 333 } | |
| 334 | |
| 335 TEST(AnimationAnimationNodeTest, IterationAlternate) | |
| 336 { | |
| 337 Timing timing; | |
| 338 timing.iterationCount = 10; | |
| 339 timing.iterationDuration = 1; | |
| 340 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 341 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 342 | |
| 343 animationNode->updateInheritedTime(0.75); | |
| 344 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 345 EXPECT_EQ(0.75, animationNode->timeFraction()); | |
| 346 | |
| 347 animationNode->updateInheritedTime(1.75); | |
| 348 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 349 EXPECT_EQ(0.25, animationNode->timeFraction()); | |
| 350 | |
| 351 animationNode->updateInheritedTime(2.75); | |
| 352 EXPECT_EQ(2, animationNode->currentIteration()); | |
| 353 EXPECT_EQ(0.75, animationNode->timeFraction()); | |
| 354 } | |
| 355 | |
| 356 TEST(AnimationAnimationNodeTest, IterationAlternateReverse) | |
| 357 { | |
| 358 Timing timing; | |
| 359 timing.iterationCount = 10; | |
| 360 timing.iterationDuration = 1; | |
| 361 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 362 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 363 | |
| 364 animationNode->updateInheritedTime(0.75); | |
| 365 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 366 EXPECT_EQ(0.25, animationNode->timeFraction()); | |
| 367 | |
| 368 animationNode->updateInheritedTime(1.75); | |
| 369 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 370 EXPECT_EQ(0.75, animationNode->timeFraction()); | |
| 371 | |
| 372 animationNode->updateInheritedTime(2.75); | |
| 373 EXPECT_EQ(2, animationNode->currentIteration()); | |
| 374 EXPECT_EQ(0.25, animationNode->timeFraction()); | |
| 375 } | |
| 376 | |
| 377 TEST(AnimationAnimationNodeTest, ZeroDurationSanity) | |
| 378 { | |
| 379 Timing timing; | |
| 380 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 381 | |
| 382 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 383 | |
| 384 animationNode->updateInheritedTime(0); | |
| 385 | |
| 386 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 387 EXPECT_FALSE(animationNode->isInPlay()); | |
| 388 EXPECT_FALSE(animationNode->isCurrent()); | |
| 389 EXPECT_TRUE(animationNode->isInEffect()); | |
| 390 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 391 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 392 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 393 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 394 | |
| 395 animationNode->updateInheritedTime(1); | |
| 396 | |
| 397 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 398 EXPECT_FALSE(animationNode->isInPlay()); | |
| 399 EXPECT_FALSE(animationNode->isCurrent()); | |
| 400 EXPECT_TRUE(animationNode->isInEffect()); | |
| 401 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 402 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 403 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 404 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 405 } | |
| 406 | |
| 407 TEST(AnimationAnimationNodeTest, ZeroDurationFillForwards) | |
| 408 { | |
| 409 Timing timing; | |
| 410 timing.fillMode = Timing::FillModeForwards; | |
| 411 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 412 | |
| 413 animationNode->updateInheritedTime(-1); | |
| 414 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 415 | |
| 416 animationNode->updateInheritedTime(0); | |
| 417 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 418 | |
| 419 animationNode->updateInheritedTime(1); | |
| 420 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 421 } | |
| 422 | |
| 423 TEST(AnimationAnimationNodeTest, ZeroDurationFillBackwards) | |
| 424 { | |
| 425 Timing timing; | |
| 426 timing.fillMode = Timing::FillModeBackwards; | |
| 427 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 428 | |
| 429 animationNode->updateInheritedTime(-1); | |
| 430 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 431 | |
| 432 animationNode->updateInheritedTime(0); | |
| 433 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 434 | |
| 435 animationNode->updateInheritedTime(1); | |
| 436 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 437 } | |
| 438 | |
| 439 TEST(AnimationAnimationNodeTest, ZeroDurationFillBoth) | |
| 440 { | |
| 441 Timing timing; | |
| 442 timing.fillMode = Timing::FillModeBoth; | |
| 443 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 444 | |
| 445 animationNode->updateInheritedTime(-1); | |
| 446 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 447 | |
| 448 animationNode->updateInheritedTime(0); | |
| 449 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 450 | |
| 451 animationNode->updateInheritedTime(1); | |
| 452 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 453 } | |
| 454 | |
| 455 TEST(AnimationAnimationNodeTest, ZeroDurationStartDelay) | |
| 456 { | |
| 457 Timing timing; | |
| 458 timing.fillMode = Timing::FillModeForwards; | |
| 459 timing.startDelay = 0.5; | |
| 460 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 461 | |
| 462 animationNode->updateInheritedTime(0); | |
| 463 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 464 | |
| 465 animationNode->updateInheritedTime(0.5); | |
| 466 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 467 | |
| 468 animationNode->updateInheritedTime(1.5); | |
| 469 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 470 } | |
| 471 | |
| 472 TEST(AnimationAnimationNodeTest, ZeroDurationIterationStartAndCount) | |
| 473 { | |
| 474 Timing timing; | |
| 475 timing.iterationStart = 0.1; | |
| 476 timing.iterationCount = 0.2; | |
| 477 timing.fillMode = Timing::FillModeBoth; | |
| 478 timing.startDelay = 0.3; | |
| 479 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 480 | |
| 481 animationNode->updateInheritedTime(0); | |
| 482 EXPECT_EQ(0.1, animationNode->timeFraction()); | |
| 483 | |
| 484 animationNode->updateInheritedTime(0.3); | |
| 485 EXPECT_DOUBLE_EQ(0.3, animationNode->timeFraction()); | |
| 486 | |
| 487 animationNode->updateInheritedTime(1); | |
| 488 EXPECT_DOUBLE_EQ(0.3, animationNode->timeFraction()); | |
| 489 } | |
| 490 | |
| 491 // FIXME: Needs specification work. | |
| 492 TEST(AnimationAnimationNodeTest, ZeroDurationInfiniteIteration) | |
| 493 { | |
| 494 Timing timing; | |
| 495 timing.fillMode = Timing::FillModeForwards; | |
| 496 timing.iterationCount = std::numeric_limits<double>::infinity(); | |
| 497 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 498 | |
| 499 animationNode->updateInheritedTime(-1); | |
| 500 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 501 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 502 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 503 | |
| 504 animationNode->updateInheritedTime(0); | |
| 505 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 506 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->currentIte
ration()); | |
| 507 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 508 } | |
| 509 | |
| 510 TEST(AnimationAnimationNodeTest, ZeroDurationIteration) | |
| 511 { | |
| 512 Timing timing; | |
| 513 timing.fillMode = Timing::FillModeForwards; | |
| 514 timing.iterationCount = 2; | |
| 515 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 516 | |
| 517 animationNode->updateInheritedTime(-1); | |
| 518 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 519 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 520 | |
| 521 animationNode->updateInheritedTime(0); | |
| 522 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 523 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 524 | |
| 525 animationNode->updateInheritedTime(1); | |
| 526 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 527 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 528 } | |
| 529 | |
| 530 TEST(AnimationAnimationNodeTest, ZeroDurationIterationStart) | |
| 531 { | |
| 532 Timing timing; | |
| 533 timing.iterationStart = 1.2; | |
| 534 timing.iterationCount = 2.2; | |
| 535 timing.fillMode = Timing::FillModeBoth; | |
| 536 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 537 | |
| 538 animationNode->updateInheritedTime(-1); | |
| 539 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 540 EXPECT_NEAR(0.2, animationNode->timeFraction(), 0.000000000000001); | |
| 541 | |
| 542 animationNode->updateInheritedTime(0); | |
| 543 EXPECT_EQ(3, animationNode->currentIteration()); | |
| 544 EXPECT_NEAR(0.4, animationNode->timeFraction(), 0.000000000000001); | |
| 545 | |
| 546 animationNode->updateInheritedTime(10); | |
| 547 EXPECT_EQ(3, animationNode->currentIteration()); | |
| 548 EXPECT_NEAR(0.4, animationNode->timeFraction(), 0.000000000000001); | |
| 549 } | |
| 550 | |
| 551 TEST(AnimationAnimationNodeTest, ZeroDurationIterationAlternate) | |
| 552 { | |
| 553 Timing timing; | |
| 554 timing.fillMode = Timing::FillModeForwards; | |
| 555 timing.iterationCount = 2; | |
| 556 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 557 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 558 | |
| 559 animationNode->updateInheritedTime(-1); | |
| 560 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 561 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 562 | |
| 563 animationNode->updateInheritedTime(0); | |
| 564 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 565 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 566 | |
| 567 animationNode->updateInheritedTime(1); | |
| 568 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 569 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 570 } | |
| 571 | |
| 572 TEST(AnimationAnimationNodeTest, ZeroDurationIterationAlternateReverse) | |
| 573 { | |
| 574 Timing timing; | |
| 575 timing.fillMode = Timing::FillModeForwards; | |
| 576 timing.iterationCount = 2; | |
| 577 timing.direction = Timing::PlaybackDirectionAlternateReverse; | |
| 578 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 579 | |
| 580 animationNode->updateInheritedTime(-1); | |
| 581 EXPECT_TRUE(isNull(animationNode->currentIteration())); | |
| 582 EXPECT_TRUE(isNull(animationNode->timeFraction())); | |
| 583 | |
| 584 animationNode->updateInheritedTime(0); | |
| 585 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 586 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 587 | |
| 588 animationNode->updateInheritedTime(1); | |
| 589 EXPECT_EQ(1, animationNode->currentIteration()); | |
| 590 EXPECT_EQ(1, animationNode->timeFraction()); | |
| 591 } | |
| 592 | |
| 593 TEST(AnimationAnimationNodeTest, InfiniteDurationSanity) | |
| 594 { | |
| 595 Timing timing; | |
| 596 timing.iterationDuration = std::numeric_limits<double>::infinity(); | |
| 597 timing.iterationCount = 1; | |
| 598 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 599 | |
| 600 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 601 | |
| 602 animationNode->updateInheritedTime(0); | |
| 603 | |
| 604 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 605 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 606 EXPECT_TRUE(animationNode->isInPlay()); | |
| 607 EXPECT_TRUE(animationNode->isCurrent()); | |
| 608 EXPECT_TRUE(animationNode->isInEffect()); | |
| 609 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 610 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 611 | |
| 612 animationNode->updateInheritedTime(1); | |
| 613 | |
| 614 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 615 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 616 EXPECT_TRUE(animationNode->isInPlay()); | |
| 617 EXPECT_TRUE(animationNode->isCurrent()); | |
| 618 EXPECT_TRUE(animationNode->isInEffect()); | |
| 619 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 620 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 621 } | |
| 622 | |
| 623 // FIXME: Needs specification work. | |
| 624 TEST(AnimationAnimationNodeTest, InfiniteDurationZeroIterations) | |
| 625 { | |
| 626 Timing timing; | |
| 627 timing.iterationDuration = std::numeric_limits<double>::infinity(); | |
| 628 timing.iterationCount = 0; | |
| 629 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 630 | |
| 631 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 632 | |
| 633 animationNode->updateInheritedTime(0); | |
| 634 | |
| 635 EXPECT_EQ(0, animationNode->activeDurationInternal()); | |
| 636 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 637 EXPECT_FALSE(animationNode->isInPlay()); | |
| 638 EXPECT_FALSE(animationNode->isCurrent()); | |
| 639 EXPECT_TRUE(animationNode->isInEffect()); | |
| 640 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 641 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 642 | |
| 643 animationNode->updateInheritedTime(1); | |
| 644 | |
| 645 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 646 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 647 EXPECT_FALSE(animationNode->isInPlay()); | |
| 648 EXPECT_FALSE(animationNode->isCurrent()); | |
| 649 EXPECT_TRUE(animationNode->isInEffect()); | |
| 650 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 651 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 652 } | |
| 653 | |
| 654 TEST(AnimationAnimationNodeTest, InfiniteDurationInfiniteIterations) | |
| 655 { | |
| 656 Timing timing; | |
| 657 timing.iterationDuration = std::numeric_limits<double>::infinity(); | |
| 658 timing.iterationCount = std::numeric_limits<double>::infinity(); | |
| 659 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 660 | |
| 661 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 662 | |
| 663 animationNode->updateInheritedTime(0); | |
| 664 | |
| 665 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 666 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 667 EXPECT_TRUE(animationNode->isInPlay()); | |
| 668 EXPECT_TRUE(animationNode->isCurrent()); | |
| 669 EXPECT_TRUE(animationNode->isInEffect()); | |
| 670 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 671 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 672 | |
| 673 animationNode->updateInheritedTime(1); | |
| 674 | |
| 675 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 676 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 677 EXPECT_TRUE(animationNode->isInPlay()); | |
| 678 EXPECT_TRUE(animationNode->isCurrent()); | |
| 679 EXPECT_TRUE(animationNode->isInEffect()); | |
| 680 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 681 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 682 } | |
| 683 | |
| 684 TEST(AnimationAnimationNodeTest, InfiniteDurationZeroPlaybackRate) | |
| 685 { | |
| 686 Timing timing; | |
| 687 timing.iterationDuration = std::numeric_limits<double>::infinity(); | |
| 688 timing.playbackRate = 0; | |
| 689 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 690 | |
| 691 EXPECT_EQ(0, animationNode->computedTiming().startTime()); | |
| 692 | |
| 693 animationNode->updateInheritedTime(0); | |
| 694 | |
| 695 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 696 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 697 EXPECT_TRUE(animationNode->isInPlay()); | |
| 698 EXPECT_TRUE(animationNode->isCurrent()); | |
| 699 EXPECT_TRUE(animationNode->isInEffect()); | |
| 700 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 701 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 702 | |
| 703 animationNode->updateInheritedTime(std::numeric_limits<double>::infinity()); | |
| 704 | |
| 705 EXPECT_EQ(std::numeric_limits<double>::infinity(), animationNode->activeDura
tionInternal()); | |
| 706 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 707 EXPECT_FALSE(animationNode->isInPlay()); | |
| 708 EXPECT_FALSE(animationNode->isCurrent()); | |
| 709 EXPECT_TRUE(animationNode->isInEffect()); | |
| 710 EXPECT_EQ(0, animationNode->currentIteration()); | |
| 711 EXPECT_EQ(0, animationNode->timeFraction()); | |
| 712 } | |
| 713 | |
| 714 TEST(AnimationAnimationNodeTest, EndTime) | |
| 715 { | |
| 716 Timing timing; | |
| 717 timing.startDelay = 1; | |
| 718 timing.endDelay = 2; | |
| 719 timing.iterationDuration = 4; | |
| 720 timing.iterationCount = 2; | |
| 721 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 722 EXPECT_EQ(11, animationNode->endTimeInternal()); | |
| 723 } | |
| 724 | |
| 725 TEST(AnimationAnimationNodeTest, Events) | |
| 726 { | |
| 727 Timing timing; | |
| 728 timing.iterationDuration = 1; | |
| 729 timing.fillMode = Timing::FillModeForwards; | |
| 730 timing.iterationCount = 2; | |
| 731 timing.startDelay = 1; | |
| 732 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 733 | |
| 734 animationNode->updateInheritedTime(0.0, TimingUpdateOnDemand); | |
| 735 EXPECT_FALSE(animationNode->eventDelegate()->eventTriggered()); | |
| 736 | |
| 737 animationNode->updateInheritedTime(0.0, TimingUpdateForAnimationFrame); | |
| 738 EXPECT_TRUE(animationNode->eventDelegate()->eventTriggered()); | |
| 739 | |
| 740 animationNode->updateInheritedTime(1.5, TimingUpdateOnDemand); | |
| 741 EXPECT_FALSE(animationNode->eventDelegate()->eventTriggered()); | |
| 742 | |
| 743 animationNode->updateInheritedTime(1.5, TimingUpdateForAnimationFrame); | |
| 744 EXPECT_TRUE(animationNode->eventDelegate()->eventTriggered()); | |
| 745 | |
| 746 } | |
| 747 | |
| 748 TEST(AnimationAnimationNodeTest, TimeToEffectChange) | |
| 749 { | |
| 750 Timing timing; | |
| 751 timing.iterationDuration = 1; | |
| 752 timing.fillMode = Timing::FillModeForwards; | |
| 753 timing.iterationStart = 0.2; | |
| 754 timing.iterationCount = 2.5; | |
| 755 timing.startDelay = 1; | |
| 756 timing.direction = Timing::PlaybackDirectionAlternate; | |
| 757 RefPtrWillBeRawPtr<TestAnimationNode> animationNode = TestAnimationNode::cre
ate(timing); | |
| 758 | |
| 759 animationNode->updateInheritedTime(0); | |
| 760 EXPECT_EQ(0, animationNode->takeLocalTime()); | |
| 761 EXPECT_TRUE(std::isinf(animationNode->takeTimeToNextIteration())); | |
| 762 | |
| 763 // Normal iteration. | |
| 764 animationNode->updateInheritedTime(1.75); | |
| 765 EXPECT_EQ(1.75, animationNode->takeLocalTime()); | |
| 766 EXPECT_NEAR(0.05, animationNode->takeTimeToNextIteration(), 0.00000000000000
1); | |
| 767 | |
| 768 // Reverse iteration. | |
| 769 animationNode->updateInheritedTime(2.75); | |
| 770 EXPECT_EQ(2.75, animationNode->takeLocalTime()); | |
| 771 EXPECT_NEAR(0.05, animationNode->takeTimeToNextIteration(), 0.00000000000000
1); | |
| 772 | |
| 773 // Item ends before iteration finishes. | |
| 774 animationNode->updateInheritedTime(3.4); | |
| 775 EXPECT_EQ(AnimationNode::PhaseActive, animationNode->phase()); | |
| 776 EXPECT_EQ(3.4, animationNode->takeLocalTime()); | |
| 777 EXPECT_TRUE(std::isinf(animationNode->takeTimeToNextIteration())); | |
| 778 | |
| 779 // Item has finished. | |
| 780 animationNode->updateInheritedTime(3.5); | |
| 781 EXPECT_EQ(AnimationNode::PhaseAfter, animationNode->phase()); | |
| 782 EXPECT_EQ(3.5, animationNode->takeLocalTime()); | |
| 783 EXPECT_TRUE(std::isinf(animationNode->takeTimeToNextIteration())); | |
| 784 } | |
| 785 | |
| 786 } | |
| OLD | NEW |