Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/WebKit/Source/core/animation/DocumentTimelineTest.cpp

Issue 2948193002: Merge AnimationTimeline and DocumentTimeline (Closed)
Patch Set: Fix rebase error Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/animation/DocumentTimeline.h" 31 #include "core/animation/DocumentTimeline.h"
32 32
33 #include <memory>
34 #include "core/animation/AnimationClock.h"
35 #include "core/animation/AnimationEffectReadOnly.h"
36 #include "core/animation/CompositorPendingAnimations.h"
33 #include "core/animation/KeyframeEffect.h" 37 #include "core/animation/KeyframeEffect.h"
38 #include "core/animation/KeyframeEffectModel.h"
34 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
40 #include "core/dom/Element.h"
41 #include "core/dom/QualifiedName.h"
35 #include "core/testing/DummyPageHolder.h" 42 #include "core/testing/DummyPageHolder.h"
43 #include "platform/weborigin/KURL.h"
44 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
37 #include <memory>
38 46
39 namespace blink { 47 namespace blink {
40 48
49 class MockPlatformTiming : public DocumentTimeline::PlatformTiming {
50 public:
51 MOCK_METHOD1(WakeAfter, void(double));
52 MOCK_METHOD0(ServiceOnNextFrame, void());
53
54 DEFINE_INLINE_TRACE() { DocumentTimeline::PlatformTiming::Trace(visitor); }
55 };
56
41 class AnimationDocumentTimelineTest : public ::testing::Test { 57 class AnimationDocumentTimelineTest : public ::testing::Test {
42 protected: 58 protected:
43 virtual void SetUp() { 59 virtual void SetUp() {
44 page_holder = DummyPageHolder::Create(); 60 page_holder = DummyPageHolder::Create();
45 document = &page_holder->GetDocument(); 61 document = &page_holder->GetDocument();
62 document->GetAnimationClock().ResetTimeForTesting();
63 element = Element::Create(QualifiedName::Null(), document.Get());
64 platform_timing = new MockPlatformTiming;
65 timeline = DocumentTimeline::Create(document.Get(), platform_timing);
66 timeline->ResetForTesting();
67 ASSERT_EQ(0, timeline->CurrentTimeInternal());
46 } 68 }
47 69
48 virtual void TearDown() { 70 virtual void TearDown() {
49 document.Release(); 71 document.Release();
72 element.Release();
73 timeline.Release();
50 ThreadState::Current()->CollectAllGarbage(); 74 ThreadState::Current()->CollectAllGarbage();
51 } 75 }
52 76
77 void UpdateClockAndService(double time) {
78 document->GetAnimationClock().UpdateTime(time);
79 document->GetCompositorPendingAnimations().Update(
80 Optional<CompositorElementIdSet>(), false);
81 timeline->ServiceAnimations(kTimingUpdateForAnimationFrame);
82 timeline->ScheduleNextService();
83 }
84
53 std::unique_ptr<DummyPageHolder> page_holder; 85 std::unique_ptr<DummyPageHolder> page_holder;
54 Persistent<Document> document; 86 Persistent<Document> document;
87 Persistent<Element> element;
55 Persistent<DocumentTimeline> timeline; 88 Persistent<DocumentTimeline> timeline;
56 Timing timing; 89 Timing timing;
90 Persistent<MockPlatformTiming> platform_timing;
91
92 void Wake() { timeline->Wake(); }
93
94 double MinimumDelay() { return DocumentTimeline::kMinimumDelay; }
57 }; 95 };
58 96
97 TEST_F(AnimationDocumentTimelineTest, EmptyKeyframeAnimation) {
98 AnimatableValueKeyframeEffectModel* effect =
99 AnimatableValueKeyframeEffectModel::Create(
100 AnimatableValueKeyframeVector());
101 KeyframeEffect* keyframe_effect =
102 KeyframeEffect::Create(element.Get(), effect, timing);
103
104 timeline->Play(keyframe_effect);
105
106 UpdateClockAndService(0);
107 EXPECT_FLOAT_EQ(0, timeline->CurrentTimeInternal());
108 EXPECT_FALSE(keyframe_effect->IsInEffect());
109
110 UpdateClockAndService(100);
111 EXPECT_FLOAT_EQ(100, timeline->CurrentTimeInternal());
112 }
113
114 TEST_F(AnimationDocumentTimelineTest, EmptyForwardsKeyframeAnimation) {
115 AnimatableValueKeyframeEffectModel* effect =
116 AnimatableValueKeyframeEffectModel::Create(
117 AnimatableValueKeyframeVector());
118 timing.fill_mode = Timing::FillMode::FORWARDS;
119 KeyframeEffect* keyframe_effect =
120 KeyframeEffect::Create(element.Get(), effect, timing);
121
122 timeline->Play(keyframe_effect);
123
124 UpdateClockAndService(0);
125 EXPECT_FLOAT_EQ(0, timeline->CurrentTimeInternal());
126 EXPECT_TRUE(keyframe_effect->IsInEffect());
127
128 UpdateClockAndService(100);
129 EXPECT_FLOAT_EQ(100, timeline->CurrentTimeInternal());
130 }
131
132 TEST_F(AnimationDocumentTimelineTest, ZeroTime) {
133 bool is_null;
134
135 document->GetAnimationClock().UpdateTime(100);
136 EXPECT_EQ(100, timeline->CurrentTimeInternal());
137 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
138 EXPECT_FALSE(is_null);
139
140 document->GetAnimationClock().UpdateTime(200);
141 EXPECT_EQ(200, timeline->CurrentTimeInternal());
142 EXPECT_EQ(200, timeline->CurrentTimeInternal(is_null));
143 EXPECT_FALSE(is_null);
144 }
145
146 TEST_F(AnimationDocumentTimelineTest, PlaybackRateNormal) {
147 double zero_time = timeline->ZeroTime();
148 bool is_null;
149
150 timeline->SetPlaybackRate(1.0);
151 EXPECT_EQ(1.0, timeline->PlaybackRate());
152 document->GetAnimationClock().UpdateTime(100);
153 EXPECT_EQ(zero_time, timeline->ZeroTime());
154 EXPECT_EQ(100, timeline->CurrentTimeInternal());
155 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
156 EXPECT_FALSE(is_null);
157
158 document->GetAnimationClock().UpdateTime(200);
159 EXPECT_EQ(zero_time, timeline->ZeroTime());
160 EXPECT_EQ(200, timeline->CurrentTimeInternal());
161 EXPECT_EQ(200, timeline->CurrentTimeInternal(is_null));
162 EXPECT_FALSE(is_null);
163 }
164
165 TEST_F(AnimationDocumentTimelineTest, PlaybackRatePause) {
166 bool is_null;
167
168 document->GetAnimationClock().UpdateTime(100);
169 EXPECT_EQ(0, timeline->ZeroTime());
170 EXPECT_EQ(100, timeline->CurrentTimeInternal());
171 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
172 EXPECT_FALSE(is_null);
173
174 timeline->SetPlaybackRate(0.0);
175 EXPECT_EQ(0.0, timeline->PlaybackRate());
176 document->GetAnimationClock().UpdateTime(200);
177 EXPECT_EQ(100, timeline->ZeroTime());
178 EXPECT_EQ(100, timeline->CurrentTimeInternal());
179 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
180
181 timeline->SetPlaybackRate(1.0);
182 EXPECT_EQ(1.0, timeline->PlaybackRate());
183 document->GetAnimationClock().UpdateTime(400);
184 EXPECT_EQ(100, timeline->ZeroTime());
185 EXPECT_EQ(300, timeline->CurrentTimeInternal());
186 EXPECT_EQ(300, timeline->CurrentTimeInternal(is_null));
187
188 EXPECT_FALSE(is_null);
189 }
190
191 TEST_F(AnimationDocumentTimelineTest, PlaybackRateSlow) {
192 bool is_null;
193
194 document->GetAnimationClock().UpdateTime(100);
195 EXPECT_EQ(0, timeline->ZeroTime());
196 EXPECT_EQ(100, timeline->CurrentTimeInternal());
197 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
198 EXPECT_FALSE(is_null);
199
200 timeline->SetPlaybackRate(0.5);
201 EXPECT_EQ(0.5, timeline->PlaybackRate());
202 document->GetAnimationClock().UpdateTime(300);
203 EXPECT_EQ(-100, timeline->ZeroTime());
204 EXPECT_EQ(200, timeline->CurrentTimeInternal());
205 EXPECT_EQ(200, timeline->CurrentTimeInternal(is_null));
206
207 timeline->SetPlaybackRate(1.0);
208 EXPECT_EQ(1.0, timeline->PlaybackRate());
209 document->GetAnimationClock().UpdateTime(400);
210 EXPECT_EQ(100, timeline->ZeroTime());
211 EXPECT_EQ(300, timeline->CurrentTimeInternal());
212 EXPECT_EQ(300, timeline->CurrentTimeInternal(is_null));
213
214 EXPECT_FALSE(is_null);
215 }
216
217 TEST_F(AnimationDocumentTimelineTest, PlaybackRateFast) {
218 bool is_null;
219
220 document->GetAnimationClock().UpdateTime(100);
221 EXPECT_EQ(0, timeline->ZeroTime());
222 EXPECT_EQ(100, timeline->CurrentTimeInternal());
223 EXPECT_EQ(100, timeline->CurrentTimeInternal(is_null));
224 EXPECT_FALSE(is_null);
225
226 timeline->SetPlaybackRate(2.0);
227 EXPECT_EQ(2.0, timeline->PlaybackRate());
228 document->GetAnimationClock().UpdateTime(300);
229 EXPECT_EQ(50, timeline->ZeroTime());
230 EXPECT_EQ(500, timeline->CurrentTimeInternal());
231 EXPECT_EQ(500, timeline->CurrentTimeInternal(is_null));
232
233 timeline->SetPlaybackRate(1.0);
234 EXPECT_EQ(1.0, timeline->PlaybackRate());
235 document->GetAnimationClock().UpdateTime(400);
236 EXPECT_EQ(-200, timeline->ZeroTime());
237 EXPECT_EQ(600, timeline->CurrentTimeInternal());
238 EXPECT_EQ(600, timeline->CurrentTimeInternal(is_null));
239
240 EXPECT_FALSE(is_null);
241 }
242
243 TEST_F(AnimationDocumentTimelineTest, PauseForTesting) {
244 float seek_time = 1;
245 timing.fill_mode = Timing::FillMode::FORWARDS;
246 KeyframeEffect* anim1 =
247 KeyframeEffect::Create(element.Get(),
248 AnimatableValueKeyframeEffectModel::Create(
249 AnimatableValueKeyframeVector()),
250 timing);
251 KeyframeEffect* anim2 =
252 KeyframeEffect::Create(element.Get(),
253 AnimatableValueKeyframeEffectModel::Create(
254 AnimatableValueKeyframeVector()),
255 timing);
256 Animation* animation1 = timeline->Play(anim1);
257 Animation* animation2 = timeline->Play(anim2);
258 timeline->PauseAnimationsForTesting(seek_time);
259
260 EXPECT_FLOAT_EQ(seek_time, animation1->CurrentTimeInternal());
261 EXPECT_FLOAT_EQ(seek_time, animation2->CurrentTimeInternal());
262 }
263
264 TEST_F(AnimationDocumentTimelineTest, DelayBeforeAnimationStart) {
265 timing.iteration_duration = 2;
266 timing.start_delay = 5;
267
268 KeyframeEffect* keyframe_effect =
269 KeyframeEffect::Create(element.Get(), nullptr, timing);
270
271 timeline->Play(keyframe_effect);
272
273 // TODO: Put the animation startTime in the future when we add the capability
274 // to change animation startTime
275 EXPECT_CALL(*platform_timing, WakeAfter(timing.start_delay - MinimumDelay()));
276 UpdateClockAndService(0);
277
278 EXPECT_CALL(*platform_timing,
279 WakeAfter(timing.start_delay - MinimumDelay() - 1.5));
280 UpdateClockAndService(1.5);
281
282 EXPECT_CALL(*platform_timing, ServiceOnNextFrame());
283 Wake();
284
285 EXPECT_CALL(*platform_timing, ServiceOnNextFrame());
286 UpdateClockAndService(4.98);
287 }
288
289 TEST_F(AnimationDocumentTimelineTest, UseAnimationAfterTimelineDeref) {
290 Animation* animation = timeline->Play(0);
291 timeline.Clear();
292 // Test passes if this does not crash.
293 animation->setStartTime(0, false);
294 }
295
59 TEST_F(AnimationDocumentTimelineTest, PlayAfterDocumentDeref) { 296 TEST_F(AnimationDocumentTimelineTest, PlayAfterDocumentDeref) {
60 timing.iteration_duration = 2; 297 timing.iteration_duration = 2;
61 timing.start_delay = 5; 298 timing.start_delay = 5;
62 299
63 timeline = &document->Timeline(); 300 timeline = &document->Timeline();
64 document = nullptr; 301 document = nullptr;
65 302
66 KeyframeEffect* keyframe_effect = KeyframeEffect::Create(0, nullptr, timing); 303 KeyframeEffect* keyframe_effect = KeyframeEffect::Create(0, nullptr, timing);
67 // Test passes if this does not crash. 304 // Test passes if this does not crash.
68 timeline->Play(keyframe_effect); 305 timeline->Play(keyframe_effect);
69 } 306 }
70 307
71 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698