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 20 matching lines...) Expand all Loading... |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/animation/AnimationTimeline.h" | 32 #include "core/animation/AnimationTimeline.h" |
33 | 33 |
34 #include "core/animation/AnimationClock.h" | 34 #include "core/animation/AnimationClock.h" |
35 #include "core/animation/AnimationEffect.h" | 35 #include "core/animation/AnimationEffect.h" |
36 #include "core/animation/KeyframeEffect.h" | 36 #include "core/animation/KeyframeEffect.h" |
37 #include "core/animation/KeyframeEffectModel.h" | 37 #include "core/animation/KeyframeEffectModel.h" |
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 "core/testing/DummyPageHolder.h" |
41 #include "platform/weborigin/KURL.h" | 42 #include "platform/weborigin/KURL.h" |
42 | 43 |
43 #include <gmock/gmock.h> | 44 #include <gmock/gmock.h> |
44 #include <gtest/gtest.h> | 45 #include <gtest/gtest.h> |
45 | 46 |
46 namespace blink { | 47 namespace blink { |
47 | 48 |
48 class MockPlatformTiming : public AnimationTimeline::PlatformTiming { | 49 class MockPlatformTiming : public AnimationTimeline::PlatformTiming { |
49 public: | 50 public: |
50 | 51 |
51 MOCK_METHOD1(wakeAfter, void(double)); | 52 MOCK_METHOD1(wakeAfter, void(double)); |
52 MOCK_METHOD0(cancelWake, void()); | |
53 MOCK_METHOD0(serviceOnNextFrame, void()); | 53 MOCK_METHOD0(serviceOnNextFrame, void()); |
54 | 54 |
55 /** | |
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) | |
58 * - cancel the timer and request to be woken on the next frame (expectNext
FrameAction) | |
59 * - cancel the timer and request to be woken at some point in the future (
expectDelayedAction) | |
60 */ | |
61 | |
62 void expectNoMoreActions() | |
63 { | |
64 EXPECT_CALL(*this, cancelWake()); | |
65 } | |
66 | |
67 DEFINE_INLINE_TRACE() | 55 DEFINE_INLINE_TRACE() |
68 { | 56 { |
69 AnimationTimeline::PlatformTiming::trace(visitor); | 57 AnimationTimeline::PlatformTiming::trace(visitor); |
70 } | 58 } |
71 }; | 59 }; |
72 | 60 |
73 class AnimationAnimationTimelineTest : public ::testing::Test { | 61 class AnimationAnimationTimelineTest : public ::testing::Test { |
74 protected: | 62 protected: |
75 virtual void SetUp() | 63 virtual void SetUp() |
76 { | 64 { |
77 document = Document::create(); | 65 pageHolder = DummyPageHolder::create(); |
| 66 document = &pageHolder->document(); |
78 document->animationClock().resetTimeForTesting(); | 67 document->animationClock().resetTimeForTesting(); |
79 element = Element::create(QualifiedName::null() , document.get()); | 68 element = Element::create(QualifiedName::null() , document.get()); |
80 platformTiming = new MockPlatformTiming; | 69 platformTiming = new MockPlatformTiming; |
81 timeline = AnimationTimeline::create(document.get(), platformTiming); | 70 timeline = AnimationTimeline::create(document.get(), platformTiming); |
| 71 timeline->resetForTesting(); |
82 ASSERT_EQ(0, timeline->currentTimeInternal()); | 72 ASSERT_EQ(0, timeline->currentTimeInternal()); |
83 } | 73 } |
84 | 74 |
85 virtual void TearDown() | 75 virtual void TearDown() |
86 { | 76 { |
87 document.release(); | 77 document.release(); |
88 element.release(); | 78 element.release(); |
89 timeline.release(); | 79 timeline.release(); |
90 #if ENABLE(OILPAN) | 80 #if ENABLE(OILPAN) |
91 Heap::collectAllGarbage(); | 81 Heap::collectAllGarbage(); |
92 #endif | 82 #endif |
93 } | 83 } |
94 | 84 |
95 void updateClockAndService(double time) | 85 void updateClockAndService(double time) |
96 { | 86 { |
97 document->animationClock().updateTime(time); | 87 document->animationClock().updateTime(time); |
98 document->compositorPendingAnimations().update(false); | 88 document->compositorPendingAnimations().update(false); |
99 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 89 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
100 timeline->scheduleNextService(); | 90 timeline->scheduleNextService(); |
101 } | 91 } |
102 | 92 |
| 93 OwnPtr<DummyPageHolder> pageHolder; |
103 RefPtrWillBePersistent<Document> document; | 94 RefPtrWillBePersistent<Document> document; |
104 RefPtrWillBePersistent<Element> element; | 95 RefPtrWillBePersistent<Element> element; |
105 Persistent<AnimationTimeline> timeline; | 96 Persistent<AnimationTimeline> timeline; |
106 Timing timing; | 97 Timing timing; |
107 Persistent<MockPlatformTiming> platformTiming; | 98 Persistent<MockPlatformTiming> platformTiming; |
108 | 99 |
109 void wake() | 100 void wake() |
110 { | 101 { |
111 timeline->wake(); | 102 timeline->wake(); |
112 } | 103 } |
113 | 104 |
114 double minimumDelay() | 105 double minimumDelay() |
115 { | 106 { |
116 return AnimationTimeline::s_minimumDelay; | 107 return AnimationTimeline::s_minimumDelay; |
117 } | 108 } |
118 }; | 109 }; |
119 | 110 |
120 TEST_F(AnimationAnimationTimelineTest, HasStarted) | |
121 { | |
122 timeline = AnimationTimeline::create(document.get()); | |
123 } | |
124 | |
125 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) | 111 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) |
126 { | 112 { |
127 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); | 113 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
128 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); | 114 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
129 | 115 |
130 timeline->play(keyframeEffect); | 116 timeline->play(keyframeEffect); |
131 | 117 |
132 platformTiming->expectNoMoreActions(); | |
133 updateClockAndService(0); | 118 updateClockAndService(0); |
134 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 119 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
135 EXPECT_FALSE(keyframeEffect->isInEffect()); | 120 EXPECT_FALSE(keyframeEffect->isInEffect()); |
136 | 121 |
137 platformTiming->expectNoMoreActions(); | |
138 updateClockAndService(100); | 122 updateClockAndService(100); |
139 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 123 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
140 } | 124 } |
141 | 125 |
142 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) | 126 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) |
143 { | 127 { |
144 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); | 128 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo
del::create(AnimatableValueKeyframeVector()); |
145 timing.fillMode = Timing::FillModeForwards; | 129 timing.fillMode = Timing::FillModeForwards; |
146 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); | 130 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec
t, timing); |
147 | 131 |
148 timeline->play(keyframeEffect); | 132 timeline->play(keyframeEffect); |
149 | 133 |
150 platformTiming->expectNoMoreActions(); | |
151 updateClockAndService(0); | 134 updateClockAndService(0); |
152 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); | 135 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); |
153 EXPECT_TRUE(keyframeEffect->isInEffect()); | 136 EXPECT_TRUE(keyframeEffect->isInEffect()); |
154 | 137 |
155 platformTiming->expectNoMoreActions(); | |
156 updateClockAndService(100); | 138 updateClockAndService(100); |
157 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); | 139 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); |
158 } | 140 } |
159 | 141 |
160 TEST_F(AnimationAnimationTimelineTest, ZeroTime) | 142 TEST_F(AnimationAnimationTimelineTest, ZeroTime) |
161 { | 143 { |
162 timeline = AnimationTimeline::create(document.get()); | |
163 bool isNull; | 144 bool isNull; |
164 | 145 |
165 document->animationClock().updateTime(100); | 146 document->animationClock().updateTime(100); |
166 EXPECT_EQ(100, timeline->currentTimeInternal()); | 147 EXPECT_EQ(100, timeline->currentTimeInternal()); |
167 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 148 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
168 EXPECT_FALSE(isNull); | 149 EXPECT_FALSE(isNull); |
169 | 150 |
170 document->animationClock().updateTime(200); | 151 document->animationClock().updateTime(200); |
171 EXPECT_EQ(200, timeline->currentTimeInternal()); | 152 EXPECT_EQ(200, timeline->currentTimeInternal()); |
172 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); | 153 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); |
173 EXPECT_FALSE(isNull); | 154 EXPECT_FALSE(isNull); |
174 } | 155 } |
175 | 156 |
176 TEST_F(AnimationAnimationTimelineTest, PlaybackRateNormal) | 157 TEST_F(AnimationAnimationTimelineTest, PlaybackRateNormal) |
177 { | 158 { |
178 timeline = AnimationTimeline::create(document.get()); | |
179 double zeroTime = timeline->zeroTime(); | 159 double zeroTime = timeline->zeroTime(); |
180 bool isNull; | 160 bool isNull; |
181 | 161 |
182 timeline->setPlaybackRate(1.0); | 162 timeline->setPlaybackRate(1.0); |
183 EXPECT_EQ(1.0, timeline->playbackRate()); | 163 EXPECT_EQ(1.0, timeline->playbackRate()); |
184 document->animationClock().updateTime(100); | 164 document->animationClock().updateTime(100); |
185 EXPECT_EQ(zeroTime, timeline->zeroTime()); | 165 EXPECT_EQ(zeroTime, timeline->zeroTime()); |
186 EXPECT_EQ(100, timeline->currentTimeInternal()); | 166 EXPECT_EQ(100, timeline->currentTimeInternal()); |
187 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 167 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
188 EXPECT_FALSE(isNull); | 168 EXPECT_FALSE(isNull); |
189 | 169 |
190 document->animationClock().updateTime(200); | 170 document->animationClock().updateTime(200); |
191 EXPECT_EQ(zeroTime, timeline->zeroTime()); | 171 EXPECT_EQ(zeroTime, timeline->zeroTime()); |
192 EXPECT_EQ(200, timeline->currentTimeInternal()); | 172 EXPECT_EQ(200, timeline->currentTimeInternal()); |
193 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); | 173 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); |
194 EXPECT_FALSE(isNull); | 174 EXPECT_FALSE(isNull); |
195 } | 175 } |
196 | 176 |
197 TEST_F(AnimationAnimationTimelineTest, PlaybackRatePause) | 177 TEST_F(AnimationAnimationTimelineTest, PlaybackRatePause) |
198 { | 178 { |
199 timeline = AnimationTimeline::create(document.get()); | |
200 bool isNull; | 179 bool isNull; |
201 | 180 |
202 document->animationClock().updateTime(100); | 181 document->animationClock().updateTime(100); |
203 EXPECT_EQ(0, timeline->zeroTime()); | 182 EXPECT_EQ(0, timeline->zeroTime()); |
204 EXPECT_EQ(100, timeline->currentTimeInternal()); | 183 EXPECT_EQ(100, timeline->currentTimeInternal()); |
205 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 184 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
206 EXPECT_FALSE(isNull); | 185 EXPECT_FALSE(isNull); |
207 | 186 |
208 timeline->setPlaybackRate(0.0); | 187 timeline->setPlaybackRate(0.0); |
209 EXPECT_EQ(0.0, timeline->playbackRate()); | 188 EXPECT_EQ(0.0, timeline->playbackRate()); |
210 document->animationClock().updateTime(200); | 189 document->animationClock().updateTime(200); |
211 EXPECT_EQ(100, timeline->zeroTime()); | 190 EXPECT_EQ(100, timeline->zeroTime()); |
212 EXPECT_EQ(100, timeline->currentTimeInternal()); | 191 EXPECT_EQ(100, timeline->currentTimeInternal()); |
213 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 192 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
214 | 193 |
215 timeline->setPlaybackRate(1.0); | 194 timeline->setPlaybackRate(1.0); |
216 EXPECT_EQ(1.0, timeline->playbackRate()); | 195 EXPECT_EQ(1.0, timeline->playbackRate()); |
217 document->animationClock().updateTime(400); | 196 document->animationClock().updateTime(400); |
218 EXPECT_EQ(100, timeline->zeroTime()); | 197 EXPECT_EQ(100, timeline->zeroTime()); |
219 EXPECT_EQ(300, timeline->currentTimeInternal()); | 198 EXPECT_EQ(300, timeline->currentTimeInternal()); |
220 EXPECT_EQ(300, timeline->currentTimeInternal(isNull)); | 199 EXPECT_EQ(300, timeline->currentTimeInternal(isNull)); |
221 | 200 |
222 EXPECT_FALSE(isNull); | 201 EXPECT_FALSE(isNull); |
223 } | 202 } |
224 | 203 |
225 TEST_F(AnimationAnimationTimelineTest, PlaybackRateSlow) | 204 TEST_F(AnimationAnimationTimelineTest, PlaybackRateSlow) |
226 { | 205 { |
227 timeline = AnimationTimeline::create(document.get()); | |
228 bool isNull; | 206 bool isNull; |
229 | 207 |
230 document->animationClock().updateTime(100); | 208 document->animationClock().updateTime(100); |
231 EXPECT_EQ(0, timeline->zeroTime()); | 209 EXPECT_EQ(0, timeline->zeroTime()); |
232 EXPECT_EQ(100, timeline->currentTimeInternal()); | 210 EXPECT_EQ(100, timeline->currentTimeInternal()); |
233 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 211 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
234 EXPECT_FALSE(isNull); | 212 EXPECT_FALSE(isNull); |
235 | 213 |
236 timeline->setPlaybackRate(0.5); | 214 timeline->setPlaybackRate(0.5); |
237 EXPECT_EQ(0.5, timeline->playbackRate()); | 215 EXPECT_EQ(0.5, timeline->playbackRate()); |
238 document->animationClock().updateTime(300); | 216 document->animationClock().updateTime(300); |
239 EXPECT_EQ(-100, timeline->zeroTime()); | 217 EXPECT_EQ(-100, timeline->zeroTime()); |
240 EXPECT_EQ(200, timeline->currentTimeInternal()); | 218 EXPECT_EQ(200, timeline->currentTimeInternal()); |
241 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); | 219 EXPECT_EQ(200, timeline->currentTimeInternal(isNull)); |
242 | 220 |
243 timeline->setPlaybackRate(1.0); | 221 timeline->setPlaybackRate(1.0); |
244 EXPECT_EQ(1.0, timeline->playbackRate()); | 222 EXPECT_EQ(1.0, timeline->playbackRate()); |
245 document->animationClock().updateTime(400); | 223 document->animationClock().updateTime(400); |
246 EXPECT_EQ(100, timeline->zeroTime()); | 224 EXPECT_EQ(100, timeline->zeroTime()); |
247 EXPECT_EQ(300, timeline->currentTimeInternal()); | 225 EXPECT_EQ(300, timeline->currentTimeInternal()); |
248 EXPECT_EQ(300, timeline->currentTimeInternal(isNull)); | 226 EXPECT_EQ(300, timeline->currentTimeInternal(isNull)); |
249 | 227 |
250 EXPECT_FALSE(isNull); | 228 EXPECT_FALSE(isNull); |
251 } | 229 } |
252 | 230 |
253 TEST_F(AnimationAnimationTimelineTest, PlaybackRateFast) | 231 TEST_F(AnimationAnimationTimelineTest, PlaybackRateFast) |
254 { | 232 { |
255 timeline = AnimationTimeline::create(document.get()); | |
256 bool isNull; | 233 bool isNull; |
257 | 234 |
258 document->animationClock().updateTime(100); | 235 document->animationClock().updateTime(100); |
259 EXPECT_EQ(0, timeline->zeroTime()); | 236 EXPECT_EQ(0, timeline->zeroTime()); |
260 EXPECT_EQ(100, timeline->currentTimeInternal()); | 237 EXPECT_EQ(100, timeline->currentTimeInternal()); |
261 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); | 238 EXPECT_EQ(100, timeline->currentTimeInternal(isNull)); |
262 EXPECT_FALSE(isNull); | 239 EXPECT_FALSE(isNull); |
263 | 240 |
264 timeline->setPlaybackRate(2.0); | 241 timeline->setPlaybackRate(2.0); |
265 EXPECT_EQ(2.0, timeline->playbackRate()); | 242 EXPECT_EQ(2.0, timeline->playbackRate()); |
266 document->animationClock().updateTime(300); | 243 document->animationClock().updateTime(300); |
267 EXPECT_EQ(50, timeline->zeroTime()); | 244 EXPECT_EQ(50, timeline->zeroTime()); |
268 EXPECT_EQ(500, timeline->currentTimeInternal()); | 245 EXPECT_EQ(500, timeline->currentTimeInternal()); |
269 EXPECT_EQ(500, timeline->currentTimeInternal(isNull)); | 246 EXPECT_EQ(500, timeline->currentTimeInternal(isNull)); |
270 | 247 |
271 timeline->setPlaybackRate(1.0); | 248 timeline->setPlaybackRate(1.0); |
272 EXPECT_EQ(1.0, timeline->playbackRate()); | 249 EXPECT_EQ(1.0, timeline->playbackRate()); |
273 document->animationClock().updateTime(400); | 250 document->animationClock().updateTime(400); |
274 EXPECT_EQ(-200, timeline->zeroTime()); | 251 EXPECT_EQ(-200, timeline->zeroTime()); |
275 EXPECT_EQ(600, timeline->currentTimeInternal()); | 252 EXPECT_EQ(600, timeline->currentTimeInternal()); |
276 EXPECT_EQ(600, timeline->currentTimeInternal(isNull)); | 253 EXPECT_EQ(600, timeline->currentTimeInternal(isNull)); |
277 | 254 |
278 EXPECT_FALSE(isNull); | 255 EXPECT_FALSE(isNull); |
279 } | 256 } |
280 | 257 |
281 TEST_F(AnimationAnimationTimelineTest, SetCurrentTime) | 258 TEST_F(AnimationAnimationTimelineTest, SetCurrentTime) |
282 { | 259 { |
283 timeline = AnimationTimeline::create(document.get()); | |
284 double zeroTime = timeline->zeroTime(); | 260 double zeroTime = timeline->zeroTime(); |
285 | 261 |
286 document->animationClock().updateTime(100); | 262 document->animationClock().updateTime(100); |
287 EXPECT_EQ(zeroTime, timeline->zeroTime()); | 263 EXPECT_EQ(zeroTime, timeline->zeroTime()); |
288 EXPECT_EQ(100, timeline->currentTimeInternal()); | 264 EXPECT_EQ(100, timeline->currentTimeInternal()); |
289 | 265 |
290 timeline->setCurrentTimeInternal(0); | 266 timeline->setCurrentTimeInternal(0); |
291 EXPECT_EQ(0, timeline->currentTimeInternal()); | 267 EXPECT_EQ(0, timeline->currentTimeInternal()); |
292 EXPECT_EQ(zeroTime + 100, timeline->zeroTime()); | 268 EXPECT_EQ(zeroTime + 100, timeline->zeroTime()); |
293 | 269 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 357 |
382 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) | 358 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) |
383 { | 359 { |
384 Animation* animation = timeline->play(0); | 360 Animation* animation = timeline->play(0); |
385 timeline.clear(); | 361 timeline.clear(); |
386 // Test passes if this does not crash. | 362 // Test passes if this does not crash. |
387 animation->setStartTime(0); | 363 animation->setStartTime(0); |
388 } | 364 } |
389 | 365 |
390 } | 366 } |
OLD | NEW |