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)); | 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 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<Animation> anim = Animation::create(element.get(), effect
, timing); | 140 Animation* anim = Animation::create(element.get(), effect, timing); |
143 | 141 |
144 timeline->play(anim.get()); | 142 timeline->play(anim); |
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(anim->isInEffect()); | 147 EXPECT_FALSE(anim->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<Animation> anim = Animation::create(element.get(), effect
, timing); | 158 Animation* anim = Animation::create(element.get(), effect, timing); |
161 | 159 |
162 timeline->play(anim.get()); | 160 timeline->play(anim); |
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(anim->isInEffect()); | 165 EXPECT_TRUE(anim->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<Animation> anim1 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); | 347 Animation* anim1 = Animation::create(element.get(), AnimatableValueKeyframeE
ffectModel::create(AnimatableValueKeyframeVector()), timing); |
350 RefPtrWillBeRawPtr<Animation> anim2 = Animation::create(element.get(), Anim
atableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing)
; | 348 Animation* anim2 = Animation::create(element.get(), AnimatableValueKeyframe
EffectModel::create(AnimatableValueKeyframeVector()), timing); |
351 AnimationPlayer* player1 = timeline->play(anim1.get()); | 349 AnimationPlayer* player1 = timeline->play(anim1); |
352 AnimationPlayer* player2 = timeline->play(anim2.get()); | 350 AnimationPlayer* player2 = timeline->play(anim2); |
353 timeline->pauseAnimationsForTesting(seekTime); | 351 timeline->pauseAnimationsForTesting(seekTime); |
354 | 352 |
355 EXPECT_FLOAT_EQ(seekTime, player1->currentTime() / 1000.0); | 353 EXPECT_FLOAT_EQ(seekTime, player1->currentTime() / 1000.0); |
356 EXPECT_FLOAT_EQ(seekTime, player2->currentTime() / 1000.0); | 354 EXPECT_FLOAT_EQ(seekTime, player2->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<Animation> anim = Animation::create(element.get(), nullpt
r, timing); | 362 Animation* anim = Animation::create(element.get(), nullptr, timing); |
365 | 363 |
366 timeline->play(anim.get()); | 364 timeline->play(anim); |
367 | 365 |
368 // TODO: Put the player startTime in the future when we add the capability t
o change player startTime | 366 // TODO: Put the player startTime in the future when we add the capability t
o change player 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<Animation> anim = Animation::create(0, nullptr, timing); | 389 Animation* anim = Animation::create(0, nullptr, timing); |
392 // Test passes if this does not crash. | 390 // Test passes if this does not crash. |
393 timeline->play(anim.get()); | 391 timeline->play(anim); |
394 } | 392 } |
395 | 393 |
396 TEST_F(AnimationAnimationTimelineTest, UseAnimationPlayerAfterTimelineDeref) | 394 TEST_F(AnimationAnimationTimelineTest, UseAnimationPlayerAfterTimelineDeref) |
397 { | 395 { |
398 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->play(0); | 396 RefPtrWillBeRawPtr<AnimationPlayer> player = 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 player->setStartTime(0); | 399 player->setStartTime(0); |
402 } | 400 } |
403 | 401 |
404 } | 402 } |
OLD | NEW |