| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 EXPECT_CALL(*this, cancelWake()).InSequence(sequence); | 70 EXPECT_CALL(*this, cancelWake()).InSequence(sequence); |
| 71 EXPECT_CALL(*this, serviceOnNextFrame()).InSequence(sequence); | 71 EXPECT_CALL(*this, serviceOnNextFrame()).InSequence(sequence); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void expectDelayedAction(double when) | 74 void expectDelayedAction(double when) |
| 75 { | 75 { |
| 76 ::testing::Sequence sequence; | 76 ::testing::Sequence sequence; |
| 77 EXPECT_CALL(*this, cancelWake()).InSequence(sequence); | 77 EXPECT_CALL(*this, cancelWake()).InSequence(sequence); |
| 78 EXPECT_CALL(*this, wakeAfter(when)).InSequence(sequence); | 78 EXPECT_CALL(*this, wakeAfter(when)).InSequence(sequence); |
| 79 } | 79 } |
| 80 |
| 81 void trace(Visitor* visitor) |
| 82 { |
| 83 DocumentTimeline::PlatformTiming::trace(visitor); |
| 84 } |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 class AnimationDocumentTimelineTest : public ::testing::Test { | 87 class AnimationDocumentTimelineTest : public ::testing::Test { |
| 83 protected: | 88 protected: |
| 84 virtual void SetUp() | 89 virtual void SetUp() |
| 85 { | 90 { |
| 86 document = Document::create(); | 91 document = Document::create(); |
| 87 document->animationClock().resetTimeForTesting(); | 92 document->animationClock().resetTimeForTesting(); |
| 88 element = Element::create(nullQName() , document.get()); | 93 element = Element::create(nullQName() , document.get()); |
| 89 platformTiming = new MockPlatformTiming; | 94 platformTiming = new MockPlatformTiming; |
| 90 timeline = DocumentTimeline::create(document.get(), adoptPtr(platformTim
ing)); | 95 timeline = DocumentTimeline::create(document.get(), adoptPtrWillBeNoop(p
latformTiming)); |
| 91 timeline->setZeroTime(0); | 96 timeline->setZeroTime(0); |
| 92 ASSERT_EQ(0, timeline->currentTimeInternal()); | 97 ASSERT_EQ(0, timeline->currentTimeInternal()); |
| 93 } | 98 } |
| 94 | 99 |
| 95 virtual void TearDown() | 100 virtual void TearDown() |
| 96 { | 101 { |
| 97 timeline.release(); | 102 timeline.release(); |
| 98 document.release(); | 103 document.release(); |
| 99 element.release(); | 104 element.release(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void updateClockAndService(double time) | 107 void updateClockAndService(double time) |
| 103 { | 108 { |
| 104 document->animationClock().updateTime(time); | 109 document->animationClock().updateTime(time); |
| 105 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 110 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 106 } | 111 } |
| 107 | 112 |
| 108 RefPtr<Document> document; | 113 RefPtr<Document> document; |
| 109 RefPtr<Element> element; | 114 RefPtr<Element> element; |
| 110 RefPtr<DocumentTimeline> timeline; | 115 RefPtrWillBePersistent<DocumentTimeline> timeline; |
| 111 Timing timing; | 116 Timing timing; |
| 112 MockPlatformTiming* platformTiming; | 117 MockPlatformTiming* platformTiming; |
| 113 | 118 |
| 114 void wake() | 119 void wake() |
| 115 { | 120 { |
| 116 timeline->wake(); | 121 timeline->wake(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 double minimumDelay() | 124 double minimumDelay() |
| 120 { | 125 { |
| 121 return DocumentTimeline::s_minimumDelay; | 126 return DocumentTimeline::s_minimumDelay; |
| 122 } | 127 } |
| 123 }; | 128 }; |
| 124 | 129 |
| 125 TEST_F(AnimationDocumentTimelineTest, HasStarted) | 130 TEST_F(AnimationDocumentTimelineTest, HasStarted) |
| 126 { | 131 { |
| 127 timeline = DocumentTimeline::create(document.get()); | 132 timeline = DocumentTimeline::create(document.get()); |
| 128 EXPECT_FALSE(timeline->hasStarted()); | 133 EXPECT_FALSE(timeline->hasStarted()); |
| 129 timeline->setZeroTime(0); | 134 timeline->setZeroTime(0); |
| 130 EXPECT_TRUE(timeline->hasStarted()); | 135 EXPECT_TRUE(timeline->hasStarted()); |
| 131 } | 136 } |
| 132 | 137 |
| 133 TEST_F(AnimationDocumentTimelineTest, EmptyKeyframeAnimation) | 138 TEST_F(AnimationDocumentTimelineTest, EmptyKeyframeAnimation) |
| 134 { | 139 { |
| 135 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 140 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); |
| 136 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing); | 141 RefPtrWillBeRawPtr<Animation> anim = Animation::create(element.get(), effect
, timing); |
| 137 | 142 |
| 138 timeline->play(anim.get()); | 143 timeline->play(anim.get()); |
| 139 | 144 |
| 140 platformTiming->expectNoMoreActions(); | 145 platformTiming->expectNoMoreActions(); |
| 141 updateClockAndService(0); | 146 updateClockAndService(0); |
| 142 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 147 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 143 EXPECT_FALSE(anim->isInEffect()); | 148 EXPECT_FALSE(anim->isInEffect()); |
| 144 | 149 |
| 145 platformTiming->expectNoMoreActions(); | 150 platformTiming->expectNoMoreActions(); |
| 146 updateClockAndService(100); | 151 updateClockAndService(100); |
| 147 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 152 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
| 148 } | 153 } |
| 149 | 154 |
| 150 TEST_F(AnimationDocumentTimelineTest, EmptyForwardsKeyframeAnimation) | 155 TEST_F(AnimationDocumentTimelineTest, EmptyForwardsKeyframeAnimation) |
| 151 { | 156 { |
| 152 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); | 157 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa
lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); |
| 153 timing.fillMode = Timing::FillModeForwards; | 158 timing.fillMode = Timing::FillModeForwards; |
| 154 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing); | 159 RefPtrWillBeRawPtr<Animation> anim = Animation::create(element.get(), effect
, timing); |
| 155 | 160 |
| 156 timeline->play(anim.get()); | 161 timeline->play(anim.get()); |
| 157 | 162 |
| 158 platformTiming->expectNoMoreActions(); | 163 platformTiming->expectNoMoreActions(); |
| 159 updateClockAndService(0); | 164 updateClockAndService(0); |
| 160 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 165 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
| 161 EXPECT_TRUE(anim->isInEffect()); | 166 EXPECT_TRUE(anim->isInEffect()); |
| 162 | 167 |
| 163 platformTiming->expectNoMoreActions(); | 168 platformTiming->expectNoMoreActions(); |
| 164 updateClockAndService(100); | 169 updateClockAndService(100); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 185 EXPECT_FALSE(isNull); | 190 EXPECT_FALSE(isNull); |
| 186 | 191 |
| 187 document->animationClock().updateTime(400); | 192 document->animationClock().updateTime(400); |
| 188 EXPECT_EQ(100, timeline->currentTimeInternal()); | 193 EXPECT_EQ(100, timeline->currentTimeInternal()); |
| 189 } | 194 } |
| 190 | 195 |
| 191 TEST_F(AnimationDocumentTimelineTest, PauseForTesting) | 196 TEST_F(AnimationDocumentTimelineTest, PauseForTesting) |
| 192 { | 197 { |
| 193 float seekTime = 1; | 198 float seekTime = 1; |
| 194 timing.fillMode = Timing::FillModeForwards; | 199 timing.fillMode = Timing::FillModeForwards; |
| 195 RefPtr<Animation> anim1 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timing); | 200 RefPtrWillBeRawPtr<Animation> anim1 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); |
| 196 RefPtr<Animation> anim2 = Animation::create(element.get(), AnimatableValueK
eyframeEffectModel::create(AnimatableValueKeyframeVector()), timing); | 201 RefPtrWillBeRawPtr<Animation> anim2 = Animation::create(element.get(), Anim
atableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing)
; |
| 197 AnimationPlayer* player1 = timeline->play(anim1.get()); | 202 AnimationPlayer* player1 = timeline->play(anim1.get()); |
| 198 AnimationPlayer* player2 = timeline->play(anim2.get()); | 203 AnimationPlayer* player2 = timeline->play(anim2.get()); |
| 199 timeline->pauseAnimationsForTesting(seekTime); | 204 timeline->pauseAnimationsForTesting(seekTime); |
| 200 | 205 |
| 201 EXPECT_FLOAT_EQ(seekTime, player1->currentTimeInternal()); | 206 EXPECT_FLOAT_EQ(seekTime, player1->currentTimeInternal()); |
| 202 EXPECT_FLOAT_EQ(seekTime, player2->currentTimeInternal()); | 207 EXPECT_FLOAT_EQ(seekTime, player2->currentTimeInternal()); |
| 203 } | 208 } |
| 204 | 209 |
| 205 TEST_F(AnimationDocumentTimelineTest, NumberOfActiveAnimations) | 210 TEST_F(AnimationDocumentTimelineTest, NumberOfActiveAnimations) |
| 206 { | 211 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 218 timingBackwardFillDelay.startDelay = 1; | 223 timingBackwardFillDelay.startDelay = 1; |
| 219 | 224 |
| 220 Timing timingNoFillDelay; | 225 Timing timingNoFillDelay; |
| 221 timingNoFillDelay.iterationDuration = 1; | 226 timingNoFillDelay.iterationDuration = 1; |
| 222 timingNoFillDelay.fillMode = Timing::FillModeNone; | 227 timingNoFillDelay.fillMode = Timing::FillModeNone; |
| 223 timingNoFillDelay.startDelay = 1; | 228 timingNoFillDelay.startDelay = 1; |
| 224 | 229 |
| 225 Timing timingAutoFill; | 230 Timing timingAutoFill; |
| 226 timingAutoFill.iterationDuration = 2; | 231 timingAutoFill.iterationDuration = 2; |
| 227 | 232 |
| 228 RefPtr<Animation> anim1 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timingForwardFill); | 233 RefPtrWillBeRawPtr<Animation> anim1 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timingFo
rwardFill); |
| 229 RefPtr<Animation> anim2 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timingNoFill); | 234 RefPtrWillBeRawPtr<Animation> anim2 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timingNo
Fill); |
| 230 RefPtr<Animation> anim3 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timingBackwardFillDe
lay); | 235 RefPtrWillBeRawPtr<Animation> anim3 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timingBa
ckwardFillDelay); |
| 231 RefPtr<Animation> anim4 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timingNoFillDelay); | 236 RefPtrWillBeRawPtr<Animation> anim4 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timingNo
FillDelay); |
| 232 RefPtr<Animation> anim5 = Animation::create(element.get(), AnimatableValueKe
yframeEffectModel::create(AnimatableValueKeyframeVector()), timingAutoFill); | 237 RefPtrWillBeRawPtr<Animation> anim5 = Animation::create(element.get(), Anima
tableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timingAu
toFill); |
| 233 | 238 |
| 234 timeline->play(anim1.get()); | 239 timeline->play(anim1.get()); |
| 235 timeline->play(anim2.get()); | 240 timeline->play(anim2.get()); |
| 236 timeline->play(anim3.get()); | 241 timeline->play(anim3.get()); |
| 237 timeline->play(anim4.get()); | 242 timeline->play(anim4.get()); |
| 238 timeline->play(anim5.get()); | 243 timeline->play(anim5.get()); |
| 239 | 244 |
| 240 platformTiming->expectNextFrameAction(); | 245 platformTiming->expectNextFrameAction(); |
| 241 updateClockAndService(0); | 246 updateClockAndService(0); |
| 242 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); | 247 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); |
| 243 platformTiming->expectNextFrameAction(); | 248 platformTiming->expectNextFrameAction(); |
| 244 updateClockAndService(0.5); | 249 updateClockAndService(0.5); |
| 245 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); | 250 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); |
| 246 platformTiming->expectNextFrameAction(); | 251 platformTiming->expectNextFrameAction(); |
| 247 updateClockAndService(1.5); | 252 updateClockAndService(1.5); |
| 248 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); | 253 EXPECT_EQ(5U, timeline->numberOfActiveAnimationsForTesting()); |
| 249 platformTiming->expectNoMoreActions(); | 254 platformTiming->expectNoMoreActions(); |
| 250 updateClockAndService(3); | 255 updateClockAndService(3); |
| 251 EXPECT_EQ(0U, timeline->numberOfActiveAnimationsForTesting()); | 256 EXPECT_EQ(0U, timeline->numberOfActiveAnimationsForTesting()); |
| 252 } | 257 } |
| 253 | 258 |
| 254 TEST_F(AnimationDocumentTimelineTest, DelayBeforeAnimationStart) | 259 TEST_F(AnimationDocumentTimelineTest, DelayBeforeAnimationStart) |
| 255 { | 260 { |
| 256 timing.iterationDuration = 2; | 261 timing.iterationDuration = 2; |
| 257 timing.startDelay = 5; | 262 timing.startDelay = 5; |
| 258 | 263 |
| 259 RefPtr<Animation> anim = Animation::create(element.get(), nullptr, timing); | 264 RefPtrWillBeRawPtr<Animation> anim = Animation::create(element.get(), nullpt
r, timing); |
| 260 | 265 |
| 261 timeline->play(anim.get()); | 266 timeline->play(anim.get()); |
| 262 | 267 |
| 263 // TODO: Put the player startTime in the future when we add the capability t
o change player startTime | 268 // TODO: Put the player startTime in the future when we add the capability t
o change player startTime |
| 264 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); | 269 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); |
| 265 updateClockAndService(0); | 270 updateClockAndService(0); |
| 266 | 271 |
| 267 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); | 272 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); |
| 268 updateClockAndService(1.5); | 273 updateClockAndService(1.5); |
| 269 | 274 |
| 270 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); | 275 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); |
| 271 wake(); | 276 wake(); |
| 272 | 277 |
| 273 platformTiming->expectNextFrameAction(); | 278 platformTiming->expectNextFrameAction(); |
| 274 updateClockAndService(4.98); | 279 updateClockAndService(4.98); |
| 275 } | 280 } |
| 276 | 281 |
| 277 TEST_F(AnimationDocumentTimelineTest, PlayAfterDocumentDeref) | 282 TEST_F(AnimationDocumentTimelineTest, PlayAfterDocumentDeref) |
| 278 { | 283 { |
| 279 timing.iterationDuration = 2; | 284 timing.iterationDuration = 2; |
| 280 timing.startDelay = 5; | 285 timing.startDelay = 5; |
| 281 | 286 |
| 282 timeline = &document->timeline(); | 287 timeline = &document->timeline(); |
| 283 element = nullptr; | 288 element = nullptr; |
| 284 document = nullptr; | 289 document = nullptr; |
| 285 | 290 |
| 286 RefPtr<Animation> anim = Animation::create(0, nullptr, timing); | 291 RefPtrWillBeRawPtr<Animation> anim = Animation::create(0, nullptr, timing); |
| 287 // Test passes if this does not crash. | 292 // Test passes if this does not crash. |
| 288 timeline->play(anim.get()); | 293 timeline->play(anim.get()); |
| 289 } | 294 } |
| 290 | 295 |
| 291 TEST_F(AnimationDocumentTimelineTest, UseAnimationPlayerAfterTimelineDeref) | 296 TEST_F(AnimationDocumentTimelineTest, UseAnimationPlayerAfterTimelineDeref) |
| 292 { | 297 { |
| 293 RefPtr<AnimationPlayer> player = timeline->createAnimationPlayer(0); | 298 RefPtrWillBeRawPtr<AnimationPlayer> player = timeline->createAnimationPlayer
(0); |
| 294 timeline.clear(); | 299 timeline.clear(); |
| 295 // Test passes if this does not crash. | 300 // Test passes if this does not crash. |
| 296 player->setStartTime(0); | 301 player->setStartTime(0); |
| 297 } | 302 } |
| 298 | 303 |
| 299 } | 304 } |
| OLD | NEW |