| 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 27 matching lines...) Expand all Loading... |
| 38 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 39 #include "core/dom/Element.h" | 39 #include "core/dom/Element.h" |
| 40 #include "core/dom/QualifiedName.h" | 40 #include "core/dom/QualifiedName.h" |
| 41 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
| 42 | 42 |
| 43 #include <gmock/gmock.h> | 43 #include <gmock/gmock.h> |
| 44 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 class MockPlatformTiming : public AnimationTimeline::PlatformTiming { | 48 class MockPlatformTiming final : public AnimationTimeline::PlatformTiming { |
| 49 public: | 49 public: |
| 50 | 50 |
| 51 MOCK_METHOD1(wakeAfter, void(double)); | 51 MOCK_METHOD1(wakeAfter, void(double)); |
| 52 MOCK_METHOD0(cancelWake, void()); | 52 MOCK_METHOD0(cancelWake, void()); |
| 53 MOCK_METHOD0(serviceOnNextFrame, void()); | 53 MOCK_METHOD0(serviceOnNextFrame, void()); |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * AnimationTimelines should do one of the following things after servicing
animations: | 56 * AnimationTimelines should do one of the following things after servicing
animations: |
| 57 * - cancel the timer and not request to be woken again (expectNoMoreAction
s) | 57 * - cancel the timer and not request to be woken again (expectNoMoreAction
s) |
| 58 * - cancel the timer and request to be woken on the next frame (expectNext
FrameAction) | 58 * - cancel the timer and request to be woken on the next frame (expectNext
FrameAction) |
| (...skipping 26 matching lines...) Expand all 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) | |
| 105 Heap::collectAllGarbage(); | 104 Heap::collectAllGarbage(); |
| 106 #endif | |
| 107 } | 105 } |
| 108 | 106 |
| 109 void updateClockAndService(double time) | 107 void updateClockAndService(double time) |
| 110 { | 108 { |
| 111 document->animationClock().updateTime(time); | 109 document->animationClock().updateTime(time); |
| 112 document->compositorPendingAnimations().update(false); | 110 document->compositorPendingAnimations().update(false); |
| 113 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 111 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 114 timeline->scheduleNextService(); | 112 timeline->scheduleNextService(); |
| 115 } | 113 } |
| 116 | 114 |
| 117 RefPtrWillBePersistent<Document> document; | 115 RefPtrWillBePersistent<Document> document; |
| 118 RefPtrWillBePersistent<Element> element; | 116 RefPtrWillBePersistent<Element> element; |
| 119 RefPtrWillBePersistent<AnimationTimeline> timeline; | 117 Persistent<AnimationTimeline> timeline; |
| 120 Timing timing; | 118 Timing timing; |
| 121 RawPtrWillBePersistent<MockPlatformTiming> platformTiming; | 119 Persistent<MockPlatformTiming> platformTiming; |
| 122 | 120 |
| 123 void wake() | 121 void wake() |
| 124 { | 122 { |
| 125 timeline->wake(); | 123 timeline->wake(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 double minimumDelay() | 126 double minimumDelay() |
| 129 { | 127 { |
| 130 return AnimationTimeline::s_minimumDelay; | 128 return AnimationTimeline::s_minimumDelay; |
| 131 } | 129 } |
| 132 }; | 130 }; |
| 133 | 131 |
| 134 TEST_F(AnimationAnimationTimelineTest, HasStarted) | 132 TEST_F(AnimationAnimationTimelineTest, HasStarted) |
| 135 { | 133 { |
| 136 timeline = AnimationTimeline::create(document.get()); | 134 timeline = AnimationTimeline::create(document.get()); |
| 137 } | 135 } |
| 138 | 136 |
| 139 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) | 137 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) |
| 140 { | 138 { |
| 141 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 139 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
| 142 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), effect, timing); | 140 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
| 143 | 141 |
| 144 timeline->play(keyframeEffect.get()); | 142 timeline->play(keyframeEffect); |
| 145 | 143 |
| 146 platformTiming->expectNoMoreActions(); | 144 platformTiming->expectNoMoreActions(); |
| 147 updateClockAndService(0); | 145 updateClockAndService(0); |
| 148 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 146 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 149 EXPECT_FALSE(keyframeEffect->isInEffect()); | 147 EXPECT_FALSE(keyframeEffect->isInEffect()); |
| 150 | 148 |
| 151 platformTiming->expectNoMoreActions(); | 149 platformTiming->expectNoMoreActions(); |
| 152 updateClockAndService(100); | 150 updateClockAndService(100); |
| 153 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 151 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
| 154 } | 152 } |
| 155 | 153 |
| 156 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) | 154 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) |
| 157 { | 155 { |
| 158 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 156 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
| 159 timing.fillMode = Timing::FillModeForwards; | 157 timing.fillMode = Timing::FillModeForwards; |
| 160 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), effect, timing); | 158 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
| 161 | 159 |
| 162 timeline->play(keyframeEffect.get()); | 160 timeline->play(keyframeEffect); |
| 163 | 161 |
| 164 platformTiming->expectNoMoreActions(); | 162 platformTiming->expectNoMoreActions(); |
| 165 updateClockAndService(0); | 163 updateClockAndService(0); |
| 166 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 164 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 167 EXPECT_TRUE(keyframeEffect->isInEffect()); | 165 EXPECT_TRUE(keyframeEffect->isInEffect()); |
| 168 | 166 |
| 169 platformTiming->expectNoMoreActions(); | 167 platformTiming->expectNoMoreActions(); |
| 170 updateClockAndService(100); | 168 updateClockAndService(100); |
| 171 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 169 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
| 172 } | 170 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 337 |
| 340 timeline->setCurrentTime(2000); | 338 timeline->setCurrentTime(2000); |
| 341 EXPECT_EQ(2000, timeline->currentTime()); | 339 EXPECT_EQ(2000, timeline->currentTime()); |
| 342 EXPECT_EQ(zeroTime + 198, timeline->zeroTime()); | 340 EXPECT_EQ(zeroTime + 198, timeline->zeroTime()); |
| 343 } | 341 } |
| 344 | 342 |
| 345 TEST_F(AnimationAnimationTimelineTest, PauseForTesting) | 343 TEST_F(AnimationAnimationTimelineTest, PauseForTesting) |
| 346 { | 344 { |
| 347 float seekTime = 1; | 345 float seekTime = 1; |
| 348 timing.fillMode = Timing::FillModeForwards; | 346 timing.fillMode = Timing::FillModeForwards; |
| 349 RefPtrWillBeRawPtr<KeyframeEffect> anim1 = KeyframeEffect::create(element.ge
t(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector())
, timing); | 347 KeyframeEffect* anim1 = KeyframeEffect::create(element.get(), AnimatableValu
eKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); |
| 350 RefPtrWillBeRawPtr<KeyframeEffect> anim2 = KeyframeEffect::create(element.g
et(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()
), timing); | 348 KeyframeEffect* anim2 = KeyframeEffect::create(element.get(), AnimatableVal
ueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); |
| 351 Animation* animation1 = timeline->play(anim1.get()); | 349 Animation* animation1 = timeline->play(anim1); |
| 352 Animation* animation2 = timeline->play(anim2.get()); | 350 Animation* animation2 = timeline->play(anim2); |
| 353 timeline->pauseAnimationsForTesting(seekTime); | 351 timeline->pauseAnimationsForTesting(seekTime); |
| 354 | 352 |
| 355 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0); | 353 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0); |
| 356 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0); | 354 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0); |
| 357 } | 355 } |
| 358 | 356 |
| 359 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart) | 357 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart) |
| 360 { | 358 { |
| 361 timing.iterationDuration = 2; | 359 timing.iterationDuration = 2; |
| 362 timing.startDelay = 5; | 360 timing.startDelay = 5; |
| 363 | 361 |
| 364 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e
lement.get(), nullptr, timing); | 362 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp
tr, timing); |
| 365 | 363 |
| 366 timeline->play(keyframeEffect.get()); | 364 timeline->play(keyframeEffect); |
| 367 | 365 |
| 368 // TODO: Put the animation startTime in the future when we add the capabilit
y to change animation startTime | 366 // TODO: Put the animation startTime in the future when we add the capabilit
y to change animation startTime |
| 369 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); | 367 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); |
| 370 updateClockAndService(0); | 368 updateClockAndService(0); |
| 371 | 369 |
| 372 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); | 370 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); |
| 373 updateClockAndService(1.5); | 371 updateClockAndService(1.5); |
| 374 | 372 |
| 375 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); | 373 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); |
| 376 wake(); | 374 wake(); |
| 377 | 375 |
| 378 platformTiming->expectNextFrameAction(); | 376 platformTiming->expectNextFrameAction(); |
| 379 updateClockAndService(4.98); | 377 updateClockAndService(4.98); |
| 380 } | 378 } |
| 381 | 379 |
| 382 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref) | 380 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref) |
| 383 { | 381 { |
| 384 timing.iterationDuration = 2; | 382 timing.iterationDuration = 2; |
| 385 timing.startDelay = 5; | 383 timing.startDelay = 5; |
| 386 | 384 |
| 387 timeline = &document->timeline(); | 385 timeline = &document->timeline(); |
| 388 element = nullptr; | 386 element = nullptr; |
| 389 document = nullptr; | 387 document = nullptr; |
| 390 | 388 |
| 391 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0
, nullptr, timing); | 389 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing); |
| 392 // Test passes if this does not crash. | 390 // Test passes if this does not crash. |
| 393 timeline->play(keyframeEffect.get()); | 391 timeline->play(keyframeEffect); |
| 394 } | 392 } |
| 395 | 393 |
| 396 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) | 394 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) |
| 397 { | 395 { |
| 398 RefPtrWillBeRawPtr<Animation> animation = timeline->play(0); | 396 Animation* animation = timeline->play(0); |
| 399 timeline.clear(); | 397 timeline.clear(); |
| 400 // Test passes if this does not crash. | 398 // Test passes if this does not crash. |
| 401 animation->setStartTime(0); | 399 animation->setStartTime(0); |
| 402 } | 400 } |
| 403 | 401 |
| 404 } | 402 } |
| OLD | NEW |