| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 }; | 80 }; |
| 81 | 81 |
| 82 class CoreAnimationDocumentTimelineTest : public ::testing::Test { | 82 class AnimationDocumentTimelineTest : public ::testing::Test { |
| 83 protected: | 83 protected: |
| 84 virtual void SetUp() | 84 virtual void SetUp() |
| 85 { | 85 { |
| 86 document = Document::create(); | 86 document = Document::create(); |
| 87 document->animationClock().resetTimeForTesting(); | 87 document->animationClock().resetTimeForTesting(); |
| 88 element = Element::create(nullQName() , document.get()); | 88 element = Element::create(nullQName() , document.get()); |
| 89 platformTiming = new MockPlatformTiming; | 89 platformTiming = new MockPlatformTiming; |
| 90 timeline = DocumentTimeline::create(document.get(), adoptPtr(platformTim
ing)); | 90 timeline = DocumentTimeline::create(document.get(), adoptPtr(platformTim
ing)); |
| 91 timeline->setZeroTime(0); | 91 timeline->setZeroTime(0); |
| 92 ASSERT_EQ(0, timeline->currentTime()); | 92 ASSERT_EQ(0, timeline->currentTime()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 115 { | 115 { |
| 116 timeline->wake(); | 116 timeline->wake(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 double minimumDelay() | 119 double minimumDelay() |
| 120 { | 120 { |
| 121 return DocumentTimeline::s_minimumDelay; | 121 return DocumentTimeline::s_minimumDelay; |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 TEST_F(CoreAnimationDocumentTimelineTest, HasStarted) | 125 TEST_F(AnimationDocumentTimelineTest, HasStarted) |
| 126 { | 126 { |
| 127 timeline = DocumentTimeline::create(document.get()); | 127 timeline = DocumentTimeline::create(document.get()); |
| 128 EXPECT_FALSE(timeline->hasStarted()); | 128 EXPECT_FALSE(timeline->hasStarted()); |
| 129 timeline->setZeroTime(0); | 129 timeline->setZeroTime(0); |
| 130 EXPECT_TRUE(timeline->hasStarted()); | 130 EXPECT_TRUE(timeline->hasStarted()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST_F(CoreAnimationDocumentTimelineTest, EmptyKeyframeAnimation) | 133 TEST_F(AnimationDocumentTimelineTest, EmptyKeyframeAnimation) |
| 134 { | 134 { |
| 135 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(Key
frameAnimationEffect::KeyframeVector()); | 135 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(Key
frameAnimationEffect::KeyframeVector()); |
| 136 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing); | 136 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing); |
| 137 | 137 |
| 138 timeline->play(anim.get()); | 138 timeline->play(anim.get()); |
| 139 | 139 |
| 140 platformTiming->expectNoMoreActions(); | 140 platformTiming->expectNoMoreActions(); |
| 141 updateClockAndService(0); | 141 updateClockAndService(0); |
| 142 EXPECT_FLOAT_EQ(0, timeline->currentTime()); | 142 EXPECT_FLOAT_EQ(0, timeline->currentTime()); |
| 143 EXPECT_TRUE(anim->compositableValues()->isEmpty()); | 143 EXPECT_TRUE(anim->compositableValues()->isEmpty()); |
| 144 | 144 |
| 145 platformTiming->expectNoMoreActions(); | 145 platformTiming->expectNoMoreActions(); |
| 146 updateClockAndService(100); | 146 updateClockAndService(100); |
| 147 EXPECT_FLOAT_EQ(100, timeline->currentTime()); | 147 EXPECT_FLOAT_EQ(100, timeline->currentTime()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(CoreAnimationDocumentTimelineTest, EmptyTimelineDoesNotTriggerStyleRecalc
) | 150 TEST_F(AnimationDocumentTimelineTest, EmptyTimelineDoesNotTriggerStyleRecalc) |
| 151 { | 151 { |
| 152 document->animationClock().updateTime(100); | 152 document->animationClock().updateTime(100); |
| 153 EXPECT_FALSE(timeline->serviceAnimations()); | 153 EXPECT_FALSE(timeline->serviceAnimations()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(CoreAnimationDocumentTimelineTest, EmptyPlayerDoesNotTriggerStyleRecalc) | 156 TEST_F(AnimationDocumentTimelineTest, EmptyPlayerDoesNotTriggerStyleRecalc) |
| 157 { | 157 { |
| 158 timeline->play(0); | 158 timeline->play(0); |
| 159 document->animationClock().updateTime(100); | 159 document->animationClock().updateTime(100); |
| 160 EXPECT_FALSE(timeline->serviceAnimations()); | 160 EXPECT_FALSE(timeline->serviceAnimations()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(CoreAnimationDocumentTimelineTest, EmptyTargetDoesNotTriggerStyleRecalc) | 163 TEST_F(AnimationDocumentTimelineTest, EmptyTargetDoesNotTriggerStyleRecalc) |
| 164 { | 164 { |
| 165 timing.iterationDuration = 200; | 165 timing.iterationDuration = 200; |
| 166 timeline->play(Animation::create(0, KeyframeAnimationEffect::create(Keyframe
AnimationEffect::KeyframeVector()), timing).get()); | 166 timeline->play(Animation::create(0, KeyframeAnimationEffect::create(Keyframe
AnimationEffect::KeyframeVector()), timing).get()); |
| 167 document->animationClock().updateTime(100); | 167 document->animationClock().updateTime(100); |
| 168 EXPECT_FALSE(timeline->serviceAnimations()); | 168 EXPECT_FALSE(timeline->serviceAnimations()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(CoreAnimationDocumentTimelineTest, EmptyEffectDoesNotTriggerStyleRecalc) | 171 TEST_F(AnimationDocumentTimelineTest, EmptyEffectDoesNotTriggerStyleRecalc) |
| 172 { | 172 { |
| 173 timeline->play(Animation::create(element.get(), 0, timing).get()); | 173 timeline->play(Animation::create(element.get(), 0, timing).get()); |
| 174 document->animationClock().updateTime(100); | 174 document->animationClock().updateTime(100); |
| 175 EXPECT_FALSE(timeline->serviceAnimations()); | 175 EXPECT_FALSE(timeline->serviceAnimations()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(CoreAnimationDocumentTimelineTest, TriggerStyleRecalc) | 178 TEST_F(AnimationDocumentTimelineTest, TriggerStyleRecalc) |
| 179 { | 179 { |
| 180 timeline->play(Animation::create(element.get(), KeyframeAnimationEffect::cre
ate(KeyframeAnimationEffect::KeyframeVector()), timing).get()); | 180 timeline->play(Animation::create(element.get(), KeyframeAnimationEffect::cre
ate(KeyframeAnimationEffect::KeyframeVector()), timing).get()); |
| 181 document->animationClock().updateTime(100); | 181 document->animationClock().updateTime(100); |
| 182 EXPECT_TRUE(timeline->serviceAnimations()); | 182 EXPECT_TRUE(timeline->serviceAnimations()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(CoreAnimationDocumentTimelineTest, ZeroTime) | 185 TEST_F(AnimationDocumentTimelineTest, ZeroTime) |
| 186 { | 186 { |
| 187 timeline = DocumentTimeline::create(document.get()); | 187 timeline = DocumentTimeline::create(document.get()); |
| 188 | 188 |
| 189 document->animationClock().updateTime(100); | 189 document->animationClock().updateTime(100); |
| 190 EXPECT_TRUE(isNull(timeline->currentTime())); | 190 EXPECT_TRUE(isNull(timeline->currentTime())); |
| 191 | 191 |
| 192 document->animationClock().updateTime(200); | 192 document->animationClock().updateTime(200); |
| 193 EXPECT_TRUE(isNull(timeline->currentTime())); | 193 EXPECT_TRUE(isNull(timeline->currentTime())); |
| 194 | 194 |
| 195 timeline->setZeroTime(300); | 195 timeline->setZeroTime(300); |
| 196 document->animationClock().updateTime(300); | 196 document->animationClock().updateTime(300); |
| 197 EXPECT_EQ(0, timeline->currentTime()); | 197 EXPECT_EQ(0, timeline->currentTime()); |
| 198 | 198 |
| 199 document->animationClock().updateTime(400); | 199 document->animationClock().updateTime(400); |
| 200 EXPECT_EQ(100, timeline->currentTime()); | 200 EXPECT_EQ(100, timeline->currentTime()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(CoreAnimationDocumentTimelineTest, PauseForTesting) | 203 TEST_F(AnimationDocumentTimelineTest, PauseForTesting) |
| 204 { | 204 { |
| 205 float seekTime = 1; | 205 float seekTime = 1; |
| 206 RefPtr<Animation> anim1 = Animation::create(element.get(), KeyframeAnimation
Effect::create(KeyframeAnimationEffect::KeyframeVector()), timing); | 206 RefPtr<Animation> anim1 = Animation::create(element.get(), KeyframeAnimation
Effect::create(KeyframeAnimationEffect::KeyframeVector()), timing); |
| 207 RefPtr<Animation> anim2 = Animation::create(element.get(), KeyframeAnimatio
nEffect::create(KeyframeAnimationEffect::KeyframeVector()), timing); | 207 RefPtr<Animation> anim2 = Animation::create(element.get(), KeyframeAnimatio
nEffect::create(KeyframeAnimationEffect::KeyframeVector()), timing); |
| 208 RefPtr<Player> player1 = timeline->play(anim1.get()); | 208 RefPtr<Player> player1 = timeline->play(anim1.get()); |
| 209 RefPtr<Player> player2 = timeline->play(anim2.get()); | 209 RefPtr<Player> player2 = timeline->play(anim2.get()); |
| 210 timeline->pauseAnimationsForTesting(seekTime); | 210 timeline->pauseAnimationsForTesting(seekTime); |
| 211 | 211 |
| 212 EXPECT_FLOAT_EQ(seekTime, player1->currentTime()); | 212 EXPECT_FLOAT_EQ(seekTime, player1->currentTime()); |
| 213 EXPECT_FLOAT_EQ(seekTime, player2->currentTime()); | 213 EXPECT_FLOAT_EQ(seekTime, player2->currentTime()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST_F(CoreAnimationDocumentTimelineTest, NumberOfActiveAnimations) | 216 TEST_F(AnimationDocumentTimelineTest, NumberOfActiveAnimations) |
| 217 { | 217 { |
| 218 Timing timingForwardFill; | 218 Timing timingForwardFill; |
| 219 timingForwardFill.hasIterationDuration = true; | 219 timingForwardFill.hasIterationDuration = true; |
| 220 timingForwardFill.iterationDuration = 2; | 220 timingForwardFill.iterationDuration = 2; |
| 221 | 221 |
| 222 Timing timingNoFill; | 222 Timing timingNoFill; |
| 223 timingNoFill.hasIterationDuration = true; | 223 timingNoFill.hasIterationDuration = true; |
| 224 timingNoFill.iterationDuration = 2; | 224 timingNoFill.iterationDuration = 2; |
| 225 timingNoFill.fillMode = Timing::FillModeNone; | 225 timingNoFill.fillMode = Timing::FillModeNone; |
| 226 | 226 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 253 updateClockAndService(0.5); | 253 updateClockAndService(0.5); |
| 254 EXPECT_EQ(4U, timeline->numberOfActiveAnimationsForTesting()); | 254 EXPECT_EQ(4U, timeline->numberOfActiveAnimationsForTesting()); |
| 255 platformTiming->expectNextFrameAction(); | 255 platformTiming->expectNextFrameAction(); |
| 256 updateClockAndService(1.5); | 256 updateClockAndService(1.5); |
| 257 EXPECT_EQ(4U, timeline->numberOfActiveAnimationsForTesting()); | 257 EXPECT_EQ(4U, timeline->numberOfActiveAnimationsForTesting()); |
| 258 platformTiming->expectNoMoreActions(); | 258 platformTiming->expectNoMoreActions(); |
| 259 updateClockAndService(3); | 259 updateClockAndService(3); |
| 260 EXPECT_EQ(1U, timeline->numberOfActiveAnimationsForTesting()); | 260 EXPECT_EQ(1U, timeline->numberOfActiveAnimationsForTesting()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(CoreAnimationDocumentTimelineTest, DelayBeforeAnimationStart) | 263 TEST_F(AnimationDocumentTimelineTest, DelayBeforeAnimationStart) |
| 264 { | 264 { |
| 265 timing.hasIterationDuration = true; | 265 timing.hasIterationDuration = true; |
| 266 timing.iterationDuration = 2; | 266 timing.iterationDuration = 2; |
| 267 timing.startDelay = 5; | 267 timing.startDelay = 5; |
| 268 | 268 |
| 269 RefPtr<Animation> anim = Animation::create(element.get(), 0, timing); | 269 RefPtr<Animation> anim = Animation::create(element.get(), 0, timing); |
| 270 | 270 |
| 271 RefPtr<Player> player = timeline->play(anim.get()); | 271 RefPtr<Player> player = timeline->play(anim.get()); |
| 272 | 272 |
| 273 // TODO: Put the player startTime in the future when we add the capability t
o change player startTime | 273 // TODO: Put the player startTime in the future when we add the capability t
o change player startTime |
| 274 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); | 274 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); |
| 275 updateClockAndService(0); | 275 updateClockAndService(0); |
| 276 | 276 |
| 277 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); | 277 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5
); |
| 278 updateClockAndService(1.5); | 278 updateClockAndService(1.5); |
| 279 | 279 |
| 280 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); | 280 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); |
| 281 wake(); | 281 wake(); |
| 282 | 282 |
| 283 platformTiming->expectNextFrameAction(); | 283 platformTiming->expectNextFrameAction(); |
| 284 updateClockAndService(4.98); | 284 updateClockAndService(4.98); |
| 285 } | 285 } |
| 286 | 286 |
| 287 } | 287 } |
| OLD | NEW |