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

Side by Side Diff: sky/engine/core/animation/AnimationTimelineTest.cpp

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
(Empty)
1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #include "sky/engine/core/animation/AnimationTimeline.h"
32
33 #include "sky/engine/core/animation/Animation.h"
34 #include "sky/engine/core/animation/AnimationClock.h"
35 #include "sky/engine/core/animation/AnimationNode.h"
36 #include "sky/engine/core/animation/KeyframeEffectModel.h"
37 #include "sky/engine/core/dom/Document.h"
38 #include "sky/engine/core/dom/Element.h"
39 #include "sky/engine/core/dom/QualifiedName.h"
40 #include "sky/engine/platform/weborigin/KURL.h"
41
42 #include <gmock/gmock.h>
43 #include <gtest/gtest.h>
44
45 namespace blink {
46
47 class MockPlatformTiming : public AnimationTimeline::PlatformTiming {
48 public:
49
50 MOCK_METHOD1(wakeAfter, void(double));
51 MOCK_METHOD0(cancelWake, void());
52 MOCK_METHOD0(serviceOnNextFrame, void());
53
54 /**
55 * AnimationTimelines should do one of the following things after servicing animations:
56 * - cancel the timer and not request to be woken again (expectNoMoreAction s)
57 * - cancel the timer and request to be woken on the next frame (expectNext FrameAction)
58 * - cancel the timer and request to be woken at some point in the future ( expectDelayedAction)
59 */
60
61 void expectNoMoreActions()
62 {
63 EXPECT_CALL(*this, cancelWake());
64 }
65
66 void expectNextFrameAction()
67 {
68 ::testing::Sequence sequence;
69 EXPECT_CALL(*this, cancelWake()).InSequence(sequence);
70 EXPECT_CALL(*this, serviceOnNextFrame()).InSequence(sequence);
71 }
72
73 void expectDelayedAction(double when)
74 {
75 ::testing::Sequence sequence;
76 EXPECT_CALL(*this, cancelWake()).InSequence(sequence);
77 EXPECT_CALL(*this, wakeAfter(when)).InSequence(sequence);
78 }
79 };
80
81 class AnimationAnimationTimelineTest : public ::testing::Test {
82 protected:
83 virtual void SetUp()
84 {
85 document = Document::create();
86 document->animationClock().resetTimeForTesting();
87 element = Element::create(nullName, document.get());
88 platformTiming = new MockPlatformTiming;
89 timeline = AnimationTimeline::create(document.get(), adoptPtr(platformTi ming));
90 ASSERT_EQ(0, timeline->currentTimeInternal());
91 }
92
93 virtual void TearDown()
94 {
95 document.release();
96 element.release();
97 timeline.release();
98 }
99
100 void updateClockAndService(double time)
101 {
102 document->animationClock().updateTime(time);
103 document->pendingAnimations().update(false);
104 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
105 }
106
107 RefPtr<Document> document;
108 RefPtr<Element> element;
109 RefPtr<AnimationTimeline> timeline;
110 Timing timing;
111 MockPlatformTiming* platformTiming;
112
113 void wake()
114 {
115 timeline->wake();
116 }
117
118 double minimumDelay()
119 {
120 return AnimationTimeline::s_minimumDelay;
121 }
122 };
123
124 TEST_F(AnimationAnimationTimelineTest, HasStarted)
125 {
126 timeline = AnimationTimeline::create(document.get());
127 }
128
129 TEST_F(AnimationAnimationTimelineTest, EmptyKeyframeAnimation)
130 {
131 RefPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeE ffectModel::create(AnimatableValueKeyframeVector());
132 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing);
133
134 timeline->play(anim.get());
135
136 platformTiming->expectNoMoreActions();
137 updateClockAndService(0);
138 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal());
139 EXPECT_FALSE(anim->isInEffect());
140
141 platformTiming->expectNoMoreActions();
142 updateClockAndService(100);
143 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal());
144 }
145
146 TEST_F(AnimationAnimationTimelineTest, EmptyForwardsKeyframeAnimation)
147 {
148 RefPtr<AnimatableValueKeyframeEffectModel> effect = AnimatableValueKeyframeE ffectModel::create(AnimatableValueKeyframeVector());
149 timing.fillMode = Timing::FillModeForwards;
150 RefPtr<Animation> anim = Animation::create(element.get(), effect, timing);
151
152 timeline->play(anim.get());
153
154 platformTiming->expectNoMoreActions();
155 updateClockAndService(0);
156 EXPECT_FLOAT_EQ(0, timeline->currentTimeInternal());
157 EXPECT_TRUE(anim->isInEffect());
158
159 platformTiming->expectNoMoreActions();
160 updateClockAndService(100);
161 EXPECT_FLOAT_EQ(100, timeline->currentTimeInternal());
162 }
163
164 TEST_F(AnimationAnimationTimelineTest, ZeroTime)
165 {
166 timeline = AnimationTimeline::create(document.get());
167 bool isNull;
168
169 document->animationClock().updateTime(100);
170 EXPECT_EQ(100, timeline->currentTimeInternal());
171 EXPECT_EQ(100, timeline->currentTimeInternal(isNull));
172 EXPECT_FALSE(isNull);
173
174 document->animationClock().updateTime(200);
175 EXPECT_EQ(200, timeline->currentTimeInternal());
176 EXPECT_EQ(200, timeline->currentTimeInternal(isNull));
177 EXPECT_FALSE(isNull);
178 }
179
180 TEST_F(AnimationAnimationTimelineTest, DelayBeforeAnimationStart)
181 {
182 timing.iterationDuration = 2;
183 timing.startDelay = 5;
184
185 RefPtr<Animation> anim = Animation::create(element.get(), nullptr, timing);
186
187 timeline->play(anim.get());
188
189 // TODO: Put the player startTime in the future when we add the capability t o change player startTime
190 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay());
191 updateClockAndService(0);
192
193 platformTiming->expectDelayedAction(timing.startDelay - minimumDelay() - 1.5 );
194 updateClockAndService(1.5);
195
196 EXPECT_CALL(*platformTiming, serviceOnNextFrame());
197 wake();
198
199 platformTiming->expectNextFrameAction();
200 updateClockAndService(4.98);
201 }
202
203 TEST_F(AnimationAnimationTimelineTest, PlayAfterDocumentDeref)
204 {
205 timing.iterationDuration = 2;
206 timing.startDelay = 5;
207
208 timeline = &document->timeline();
209 element = nullptr;
210 document = nullptr;
211
212 RefPtr<Animation> anim = Animation::create(0, nullptr, timing);
213 // Test passes if this does not crash.
214 timeline->play(anim.get());
215 }
216
217 TEST_F(AnimationAnimationTimelineTest, UseAnimationPlayerAfterTimelineDeref)
218 {
219 RefPtr<AnimationPlayer> player = timeline->createAnimationPlayer(0);
220 timeline.clear();
221 // Test passes if this does not crash.
222 player->setStartTime(0);
223 }
224
225 }
OLDNEW
« no previous file with comments | « sky/engine/core/animation/AnimationTimeline.idl ('k') | sky/engine/core/animation/DefaultStyleInterpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698