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

Side by Side Diff: Source/core/animation/AnimationTimelineTest.cpp

Issue 1120003002: [Oilpan] Migrate most classes under core/animations to Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Intentional nullptr access Created 5 years, 7 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 27 matching lines...) Expand all
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 "platform/weborigin/KURL.h" 41 #include "platform/weborigin/KURL.h"
42 42
43 #include <gmock/gmock.h> 43 #include <gmock/gmock.h>
44 #include <gtest/gtest.h> 44 #include <gtest/gtest.h>
45 45
46 namespace blink { 46 namespace blink {
47 47
48 class MockPlatformTiming : public AnimationTimeline::PlatformTiming { 48 class MockPlatformTiming final : public AnimationTimeline::PlatformTiming {
49 public: 49 public:
50 50
51 MOCK_METHOD1(wakeAfter, void(double)); 51 MOCK_METHOD1(wakeAfter, void(double));
52 MOCK_METHOD0(cancelWake, void()); 52 MOCK_METHOD0(cancelWake, void());
53 MOCK_METHOD0(serviceOnNextFrame, void()); 53 MOCK_METHOD0(serviceOnNextFrame, void());
54 54
55 /** 55 /**
56 * AnimationTimelines should do one of the following things after servicing animations: 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) 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) 58 * - cancel the timer and request to be woken on the next frame (expectNext FrameAction)
(...skipping 14 matching lines...) Expand all
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 DEFINE_INLINE_TRACE() 81 DEFINE_INLINE_TRACE()
82 { 82 {
83 // Null access to get a stack trace.
84 int* foo = nullptr;
85 *foo = 1;
peria 2015/05/11 10:27:54 This change is made to share how an instance of Mo
83 AnimationTimeline::PlatformTiming::trace(visitor); 86 AnimationTimeline::PlatformTiming::trace(visitor);
84 } 87 }
85 }; 88 };
86 89
87 class AnimationAnimationTimelineTest : public ::testing::Test { 90 class AnimationAnimationTimelineTest : public ::testing::Test {
88 protected: 91 protected:
89 virtual void SetUp() 92 virtual void SetUp()
90 { 93 {
91 document = Document::create(); 94 document = Document::create();
92 document->animationClock().resetTimeForTesting(); 95 document->animationClock().resetTimeForTesting();
93 element = Element::create(QualifiedName::null() , document.get()); 96 element = Element::create(QualifiedName::null() , document.get());
94 platformTiming = new MockPlatformTiming; 97 timeline = AnimationTimeline::create(document.get(), new MockPlatformTim ing);
95 timeline = AnimationTimeline::create(document.get(), adoptPtrWillBeNoop( platformTiming));
96 ASSERT_EQ(0, timeline->currentTimeInternal()); 98 ASSERT_EQ(0, timeline->currentTimeInternal());
97 } 99 }
98 100
99 virtual void TearDown() 101 virtual void TearDown()
100 { 102 {
101 document.release(); 103 document.release();
102 element.release(); 104 element.release();
103 timeline.release(); 105 timeline.release();
104 #if ENABLE(OILPAN)
105 Heap::collectAllGarbage(); 106 Heap::collectAllGarbage();
106 #endif
107 } 107 }
108 108
109 void updateClockAndService(double time) 109 void updateClockAndService(double time)
110 { 110 {
111 document->animationClock().updateTime(time); 111 document->animationClock().updateTime(time);
112 document->compositorPendingAnimations().update(false); 112 document->compositorPendingAnimations().update(false);
113 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 113 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
114 timeline->scheduleNextService(); 114 timeline->scheduleNextService();
115 } 115 }
116 116
117 MockPlatformTiming* platformTiming()
118 {
119 return static_cast<MockPlatformTiming*>(timeline->timing());
120 }
121
117 RefPtrWillBePersistent<Document> document; 122 RefPtrWillBePersistent<Document> document;
118 RefPtrWillBePersistent<Element> element; 123 RefPtrWillBePersistent<Element> element;
119 RefPtrWillBePersistent<AnimationTimeline> timeline; 124 Persistent<AnimationTimeline> timeline;
120 Timing timing; 125 Timing timing;
121 MockPlatformTiming* platformTiming;
122 126
123 void wake() 127 void wake()
124 { 128 {
125 timeline->wake(); 129 timeline->wake();
126 } 130 }
127 131
128 double minimumDelay() 132 double minimumDelay()
129 { 133 {
130 return AnimationTimeline::s_minimumDelay; 134 return AnimationTimeline::s_minimumDelay;
131 } 135 }
132 }; 136 };
133 137
134 TEST_F(AnimationAnimationTimelineTest, HasStarted) 138 TEST_F(AnimationAnimationTimelineTest, HasStarted)
135 { 139 {
136 timeline = AnimationTimeline::create(document.get()); 140 timeline = AnimationTimeline::create(document.get());
137 } 141 }
138 142
139 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation) 143 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation)
140 { 144 {
141 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); 145 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo del::create(AnimatableValueKeyframeVector());
142 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), effect, timing); 146 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec t, timing);
143 147
144 timeline->play(keyframeEffect.get()); 148 timeline->play(keyframeEffect);
145 149
146 platformTiming->expectNoMoreActions(); 150 platformTiming()->expectNoMoreActions();
147 updateClockAndService(0); 151 updateClockAndService(0);
148 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); 152 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal());
149 EXPECT_FALSE(keyframeEffect->isInEffect()); 153 EXPECT_FALSE(keyframeEffect->isInEffect());
150 154
151 platformTiming->expectNoMoreActions(); 155 platformTiming()->expectNoMoreActions();
152 updateClockAndService(100); 156 updateClockAndService(100);
153 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); 157 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal());
154 } 158 }
155 159
156 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation) 160 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation)
157 { 161 {
158 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableVa lueKeyframeEffectModel::create(AnimatableValueKeyframeVector()); 162 AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectMo del::create(AnimatableValueKeyframeVector());
159 timing.fillMode = Timing::FillModeForwards; 163 timing.fillMode = Timing::FillModeForwards;
160 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), effect, timing); 164 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), effec t, timing);
161 165
162 timeline->play(keyframeEffect.get()); 166 timeline->play(keyframeEffect);
163 167
164 platformTiming->expectNoMoreActions(); 168 platformTiming()->expectNoMoreActions();
165 updateClockAndService(0); 169 updateClockAndService(0);
166 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal()); 170 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal());
167 EXPECT_TRUE(keyframeEffect->isInEffect()); 171 EXPECT_TRUE(keyframeEffect->isInEffect());
168 172
169 platformTiming->expectNoMoreActions(); 173 platformTiming()->expectNoMoreActions();
170 updateClockAndService(100); 174 updateClockAndService(100);
171 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal()); 175 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal());
172 } 176 }
173 177
174 TEST_F(AnimationAnimationTimelineTest, ZeroTime) 178 TEST_F(AnimationAnimationTimelineTest, ZeroTime)
175 { 179 {
176 timeline = AnimationTimeline::create(document.get()); 180 timeline = AnimationTimeline::create(document.get());
177 bool isNull; 181 bool isNull;
178 182
179 document->animationClock().updateTime(100); 183 document->animationClock().updateTime(100);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 343
340 timeline->setCurrentTime(2000); 344 timeline->setCurrentTime(2000);
341 EXPECT_EQ(2000, timeline->currentTime()); 345 EXPECT_EQ(2000, timeline->currentTime());
342 EXPECT_EQ(zeroTime + 198, timeline->zeroTime()); 346 EXPECT_EQ(zeroTime + 198, timeline->zeroTime());
343 } 347 }
344 348
345 TEST_F(AnimationAnimationTimelineTest, PauseForTesting) 349 TEST_F(AnimationAnimationTimelineTest, PauseForTesting)
346 { 350 {
347 float seekTime = 1; 351 float seekTime = 1;
348 timing.fillMode = Timing::FillModeForwards; 352 timing.fillMode = Timing::FillModeForwards;
349 RefPtrWillBeRawPtr<KeyframeEffect> anim1 = KeyframeEffect::create(element.ge t(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector()) , timing); 353 KeyframeEffect* anim1 = KeyframeEffect::create(element.get(), AnimatableValu eKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing);
350 RefPtrWillBeRawPtr<KeyframeEffect> anim2 = KeyframeEffect::create(element.g et(), AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector() ), timing); 354 KeyframeEffect* anim2 = KeyframeEffect::create(element.get(), AnimatableVal ueKeyframeEffectModel::create(AnimatableValueKeyframeVector()), timing);
351 Animation* animation1 = timeline->play(anim1.get()); 355 Animation* animation1 = timeline->play(anim1);
352 Animation* animation2 = timeline->play(anim2.get()); 356 Animation* animation2 = timeline->play(anim2);
353 timeline->pauseAnimationsForTesting(seekTime); 357 timeline->pauseAnimationsForTesting(seekTime);
354 358
355 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0); 359 EXPECT_FLOAT_EQ(seekTime, animation1->currentTime() / 1000.0);
356 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0); 360 EXPECT_FLOAT_EQ(seekTime, animation2->currentTime() / 1000.0);
357 } 361 }
358 362
359 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart) 363 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart)
360 { 364 {
361 timing.iterationDuration = 2; 365 timing.iterationDuration = 2;
362 timing.startDelay = 5; 366 timing.startDelay = 5;
363 367
364 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), nullptr, timing); 368 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp tr, timing);
365 369
366 timeline->play(keyframeEffect.get()); 370 timeline->play(keyframeEffect);
367 371
368 // TODO: Put the animation startTime in the future when we add the capabilit y to change animation startTime 372 // TODO: Put the animation startTime in the future when we add the capabilit y to change animation startTime
369 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay()); 373 platformTiming()->expectDelayedAction(timing.startDelay - minimumDelay());
370 updateClockAndService(0); 374 updateClockAndService(0);
371 375
372 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5 ); 376 platformTiming()->expectDelayedAction(timing.startDelay - minimumDelay() - 1 .5);
373 updateClockAndService(1.5); 377 updateClockAndService(1.5);
374 378
375 EXPECT_CALL(*platformTiming, serviceOnNextFrame()); 379 EXPECT_CALL(*platformTiming(), serviceOnNextFrame());
376 wake(); 380 wake();
377 381
378 platformTiming->expectNextFrameAction(); 382 platformTiming()->expectNextFrameAction();
379 updateClockAndService(4.98); 383 updateClockAndService(4.98);
380 } 384 }
381 385
382 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref) 386 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref)
383 { 387 {
384 timing.iterationDuration = 2; 388 timing.iterationDuration = 2;
385 timing.startDelay = 5; 389 timing.startDelay = 5;
386 390
387 timeline = &document->timeline(); 391 timeline = &document->timeline();
388 element = nullptr; 392 element = nullptr;
389 document = nullptr; 393 document = nullptr;
390 394
391 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0 , nullptr, timing); 395 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing);
392 // Test passes if this does not crash. 396 // Test passes if this does not crash.
393 timeline->play(keyframeEffect.get()); 397 timeline->play(keyframeEffect);
394 } 398 }
395 399
396 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref) 400 TEST_F(AnimationAnimationTimelineTest, UseAnimationAfterTimelineDeref)
397 { 401 {
398 RefPtrWillBeRawPtr<Animation> animation = timeline->play(0); 402 RefPtrWillBeRawPtr<Animation> animation = timeline->play(0);
399 timeline.clear(); 403 timeline.clear();
400 // Test passes if this does not crash. 404 // Test passes if this does not crash.
401 animation->setStartTime(0); 405 animation->setStartTime(0);
402 } 406 }
403 407
404 } 408 }
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationTimeline.idl ('k') | Source/core/animation/ColorStyleInterpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698