| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class AnimationAnimationTimelineTest : public ::testing::Test { | 87 class AnimationAnimationTimelineTest : public ::testing::Test { |
| 88 protected: | 88 protected: |
| 89 virtual void SetUp() | 89 virtual void SetUp() |
| 90 { | 90 { |
| 91 document = Document::create(); | 91 document = Document::create(); |
| 92 document->animationClock().resetTimeForTesting(); | 92 document->animationClock().resetTimeForTesting(); |
| 93 element = Element::create(QualifiedName::null() , document.get()); | 93 element = Element::create(QualifiedName::null() , document.get()); |
| 94 platformTiming = new MockPlatformTiming; | 94 platformTiming = new MockPlatformTiming; |
| 95 timeline = AnimationTimeline::create(document.get(), adoptPtrWillBeNoop(
platformTiming.get())); | 95 timeline = AnimationTimeline::create(document.get(), platformTiming); |
| 96 ASSERT_EQ(0, timeline->currentTimeInternal()); | 96 ASSERT_EQ(0, timeline->currentTimeInternal()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 virtual void TearDown() | 99 virtual void TearDown() |
| 100 { | 100 { |
| 101 document.release(); | 101 document.release(); |
| 102 element.release(); | 102 element.release(); |
| 103 timeline.release(); | 103 timeline.release(); |
| 104 #if ENABLE(OILPAN) | 104 #if ENABLE(OILPAN) |
| 105 Heap::collectAllGarbage(); | 105 Heap::collectAllGarbage(); |
| 106 #endif | 106 #endif |
| 107 } | 107 } |
| 108 | 108 |
| 109 void updateClockAndService(double time) | 109 void updateClockAndService(double time) |
| 110 { | 110 { |
| 111 document->animationClock().updateTime(time); | 111 document->animationClock().updateTime(time); |
| 112 document->compositorPendingAnimations().update(false); | 112 document->compositorPendingAnimations().update(false); |
| 113 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 113 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 114 timeline->scheduleNextService(); | 114 timeline->scheduleNextService(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 RefPtrWillBePersistent<Document> document; | 117 RefPtrWillBePersistent<Document> document; |
| 118 RefPtrWillBePersistent<Element> element; | 118 RefPtrWillBePersistent<Element> element; |
| 119 RefPtrWillBePersistent<AnimationTimeline> timeline; | 119 Persistent<AnimationTimeline> timeline; |
| 120 Timing timing; | 120 Timing timing; |
| 121 RawPtrWillBePersistent<MockPlatformTiming> platformTiming; | 121 Persistent<MockPlatformTiming> platformTiming; |
| 122 | 122 |
| 123 void wake() | 123 void wake() |
| 124 { | 124 { |
| 125 timeline->wake(); | 125 timeline->wake(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 double minimumDelay() | 128 double minimumDelay() |
| 129 { | 129 { |
| 130 return AnimationTimeline::s_minimumDelay; | 130 return AnimationTimeline::s_minimumDelay; |
| 131 } | 131 } |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 TEST_F(AnimationAnimationTimelineTest, HasStarted) | 134 TEST_F(AnimationAnimationTimelineTest, HasStarted) |
| 135 { | 135 { |
| 136 timeline = AnimationTimeline::create(document.get()); | 136 timeline = AnimationTimeline::create(document.get()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) | 139 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) |
| 140 { | 140 { |
| 141 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 141 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
| 142 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), effect, timing); | 142 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
| 143 | 143 |
| 144 timeline->play(keyframeEffect.get()); | 144 timeline->play(keyframeEffect); |
| 145 | 145 |
| 146 platformTiming->expectNoMoreActions(); | 146 platformTiming->expectNoMoreActions(); |
| 147 updateClockAndService(0); | 147 updateClockAndService(0); |
| 148 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 148 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 149 EXPECT_FALSE(keyframeEffect->isInEffect()); | 149 EXPECT_FALSE(keyframeEffect->isInEffect()); |
| 150 | 150 |
| 151 platformTiming->expectNoMoreActions(); | 151 platformTiming->expectNoMoreActions(); |
| 152 updateClockAndService(100); | 152 updateClockAndService(100); |
| 153 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 153 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) | 156 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) |
| 157 { | 157 { |
| 158 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 158 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
| 159 timing.fillMode = Timing::FillModeForwards; | 159 timing.fillMode = Timing::FillModeForwards; |
| 160 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), effect, timing); | 160 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
| 161 | 161 |
| 162 timeline->play(keyframeEffect.get()); | 162 timeline->play(keyframeEffect); |
| 163 | 163 |
| 164 platformTiming->expectNoMoreActions(); | 164 platformTiming->expectNoMoreActions(); |
| 165 updateClockAndService(0); | 165 updateClockAndService(0); |
| 166 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 166 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 167 EXPECT_TRUE(keyframeEffect->isInEffect()); | 167 EXPECT_TRUE(keyframeEffect->isInEffect()); |
| 168 | 168 |
| 169 platformTiming->expectNoMoreActions(); | 169 platformTiming->expectNoMoreActions(); |
| 170 updateClockAndService(100); | 170 updateClockAndService(100); |
| 171 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 171 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
| 172 } | 172 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 timeline->setCurrentTime(2000); | 340 timeline->setCurrentTime(2000); |
| 341 EXPECT_EQ(2000, timeline->currentTime()); | 341 EXPECT_EQ(2000, timeline->currentTime()); |
| 342 EXPECT_EQ(zeroTime + 198, timeline->zeroTime()); | 342 EXPECT_EQ(zeroTime + 198, timeline->zeroTime()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 TEST_F(AnimationAnimationTimelineTest, PauseForTesting) | 345 TEST_F(AnimationAnimationTimelineTest, PauseForTesting) |
| 346 { | 346 { |
| 347 float seekTime = 1; | 347 float seekTime = 1; |
| 348 timing.fillMode = Timing::FillModeForwards; | 348 timing.fillMode = Timing::FillModeForwards; |
| 349 RefPtrWillBeRawPtr<KeyframeEffect> anim1 = KeyframeEffect::create(element.ge
t(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector())
, timing); | 349 KeyframeEffect* anim1 = KeyframeEffect::create(element.get(), AnimatableValu
eKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); |
| 350 RefPtrWillBeRawPtr<KeyframeEffect> anim2 = KeyframeEffect::create(element.g
et(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()
), timing); | 350 KeyframeEffect* anim2 = KeyframeEffect::create(element.get(), AnimatableVal
ueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); |
| 351 Animation* animation1 = timeline->play(anim1.get()); | 351 Animation* animation1 = timeline->play(anim1); |
| 352 Animation* animation2 = timeline->play(anim2.get()); | 352 Animation* animation2 = timeline->play(anim2); |
| 353 timeline->pauseAnimationsForTesting(seekTime); | 353 timeline->pauseAnimationsForTesting(seekTime); |
| 354 | 354 |
| 355 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0); | 355 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0); |
| 356 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0); | 356 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0); |
| 357 } | 357 } |
| 358 | 358 |
| 359 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart) | 359 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart) |
| 360 { | 360 { |
| 361 timing.iterationDuration = 2; | 361 timing.iterationDuration = 2; |
| 362 timing.startDelay = 5; | 362 timing.startDelay = 5; |
| 363 | 363 |
| 364 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), nullptr, timing); | 364 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp
tr, timing); |
| 365 | 365 |
| 366 timeline->play(keyframeEffect.get()); | 366 timeline->play(keyframeEffect); |
| 367 | 367 |
| 368 // TODO: Put the animation startTime in the future when we add the capabilit
y to change animation startTime | 368 // TODO: Put the animation startTime in the future when we add the capabilit
y to change animation startTime |
| 369 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); | 369 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); |
| 370 updateClockAndService(0); | 370 updateClockAndService(0); |
| 371 | 371 |
| 372 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); | 372 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); |
| 373 updateClockAndService(1.5); | 373 updateClockAndService(1.5); |
| 374 | 374 |
| 375 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); | 375 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); |
| 376 wake(); | 376 wake(); |
| 377 | 377 |
| 378 platformTiming->expectNextFrameAction(); | 378 platformTiming->expectNextFrameAction(); |
| 379 updateClockAndService(4.98); | 379 updateClockAndService(4.98); |
| 380 } | 380 } |
| 381 | 381 |
| 382 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref) | 382 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref) |
| 383 { | 383 { |
| 384 timing.iterationDuration = 2; | 384 timing.iterationDuration = 2; |
| 385 timing.startDelay = 5; | 385 timing.startDelay = 5; |
| 386 | 386 |
| 387 timeline = &document->timeline(); | 387 timeline = &document->timeline(); |
| 388 element = nullptr; | 388 element = nullptr; |
| 389 document = nullptr; | 389 document = nullptr; |
| 390 | 390 |
| 391 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0
, nullptr, timing); | 391 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing); |
| 392 // Test passes if this does not crash. | 392 // Test passes if this does not crash. |
| 393 timeline->play(keyframeEffect.get()); | 393 timeline->play(keyframeEffect); |
| 394 } | 394 } |
| 395 | 395 |
| 396 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) | 396 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) |
| 397 { | 397 { |
| 398 RefPtrWillBeRawPtr<Animation> animation = timeline->play(0); | 398 Animation* animation = timeline->play(0); |
| 399 timeline.clear(); | 399 timeline.clear(); |
| 400 // Test passes if this does not crash. | 400 // Test passes if this does not crash. |
| 401 animation->setStartTime(0); | 401 animation->setStartTime(0); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } | 404 } |
| OLD | NEW |