OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layer_animation_controller.h" | 5 #include "cc/layer_animation_controller.h" |
6 | 6 |
7 #include "cc/active_animation.h" | 7 #include "cc/animation.h" |
8 #include "cc/animation_curve.h" | 8 #include "cc/animation_curve.h" |
9 #include "cc/test/animation_test_common.h" | 9 #include "cc/test/animation_test_common.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 namespace { | 15 namespace { |
16 | 16 |
17 void expectTranslateX(double translateX, const gfx::Transform& matrix) | 17 void expectTranslateX(double translateX, const gfx::Transform& matrix) |
18 { | 18 { |
19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); | 19 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); |
20 } | 20 } |
21 | 21 |
22 scoped_ptr<ActiveAnimation> createActiveAnimation(scoped_ptr<AnimationCurve> cur
ve, int id, ActiveAnimation::TargetProperty property) | 22 scoped_ptr<Animation> createAnimation(scoped_ptr<AnimationCurve> curve, int id,
Animation::TargetProperty property) |
23 { | 23 { |
24 return ActiveAnimation::create(curve.Pass(), 0, id, property); | 24 return Animation::create(curve.Pass(), 0, id, property); |
25 } | 25 } |
26 | 26 |
27 TEST(LayerAnimationControllerTest, syncNewAnimation) | 27 TEST(LayerAnimationControllerTest, syncNewAnimation) |
28 { | 28 { |
29 FakeLayerAnimationValueObserver dummyImpl; | 29 FakeLayerAnimationValueObserver dummyImpl; |
30 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); | 30 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
31 controllerImpl->addObserver(&dummyImpl); | 31 controllerImpl->addObserver(&dummyImpl); |
32 FakeLayerAnimationValueObserver dummy; | 32 FakeLayerAnimationValueObserver dummy; |
33 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 33 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
34 controller->addObserver(&dummy); | 34 controller->addObserver(&dummy); |
35 | 35 |
36 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 36 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); |
37 | 37 |
38 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 38 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
39 | 39 |
40 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 40 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
41 | 41 |
42 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 42 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); |
43 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 43 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat
ion(0, Animation::Opacity)->runState()); |
44 } | 44 } |
45 | 45 |
46 // If an animation is started on the impl thread before it is ticked on the main | 46 // If an animation is started on the impl thread before it is ticked on the main |
47 // thread, we must be sure to respect the synchronized start time. | 47 // thread, we must be sure to respect the synchronized start time. |
48 TEST(LayerAnimationControllerTest, doNotClobberStartTimes) | 48 TEST(LayerAnimationControllerTest, doNotClobberStartTimes) |
49 { | 49 { |
50 FakeLayerAnimationValueObserver dummyImpl; | 50 FakeLayerAnimationValueObserver dummyImpl; |
51 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); | 51 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
52 controllerImpl->addObserver(&dummyImpl); | 52 controllerImpl->addObserver(&dummyImpl); |
53 FakeLayerAnimationValueObserver dummy; | 53 FakeLayerAnimationValueObserver dummy; |
54 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 54 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
55 controller->addObserver(&dummy); | 55 controller->addObserver(&dummy); |
56 | 56 |
57 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 57 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); |
58 | 58 |
59 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 59 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
60 | 60 |
61 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 61 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
62 | 62 |
63 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 63 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); |
64 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 64 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat
ion(0, Animation::Opacity)->runState()); |
65 | 65 |
66 AnimationEventsVector events; | 66 AnimationEventsVector events; |
67 controllerImpl->animate(1, &events); | 67 controllerImpl->animate(1, &events); |
68 | 68 |
69 // Synchronize the start times. | 69 // Synchronize the start times. |
70 EXPECT_EQ(1u, events.size()); | 70 EXPECT_EQ(1u, events.size()); |
71 controller->OnAnimationStarted(events[0]); | 71 controller->OnAnimationStarted(events[0]); |
72 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); | 72 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont
rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); |
73 | 73 |
74 // Start the animation on the main thread. Should not affect the start time. | 74 // Start the animation on the main thread. Should not affect the start time. |
75 controller->animate(1.5, 0); | 75 controller->animate(1.5, 0); |
76 EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->start
Time(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTi
me()); | 76 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont
rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); |
77 } | 77 } |
78 | 78 |
79 TEST(LayerAnimationControllerTest, syncPauseAndResume) | 79 TEST(LayerAnimationControllerTest, syncPauseAndResume) |
80 { | 80 { |
81 FakeLayerAnimationValueObserver dummyImpl; | 81 FakeLayerAnimationValueObserver dummyImpl; |
82 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); | 82 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
83 controllerImpl->addObserver(&dummyImpl); | 83 controllerImpl->addObserver(&dummyImpl); |
84 FakeLayerAnimationValueObserver dummy; | 84 FakeLayerAnimationValueObserver dummy; |
85 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 85 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
86 controller->addObserver(&dummy); | 86 controller->addObserver(&dummy); |
87 | 87 |
88 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 88 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); |
89 | 89 |
90 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 90 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
91 | 91 |
92 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 92 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
93 | 93 |
94 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 94 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); |
95 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 95 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat
ion(0, Animation::Opacity)->runState()); |
96 | 96 |
97 // Start the animations on each controller. | 97 // Start the animations on each controller. |
98 AnimationEventsVector events; | 98 AnimationEventsVector events; |
99 controllerImpl->animate(0, &events); | 99 controllerImpl->animate(0, &events); |
100 controller->animate(0, 0); | 100 controller->animate(0, 0); |
101 EXPECT_EQ(ActiveAnimation::Running, controllerImpl->getActiveAnimation(0, Ac
tiveAnimation::Opacity)->runState()); | 101 EXPECT_EQ(Animation::Running, controllerImpl->getAnimation(0, Animation::Opa
city)->runState()); |
102 EXPECT_EQ(ActiveAnimation::Running, controller->getActiveAnimation(0, Active
Animation::Opacity)->runState()); | 102 EXPECT_EQ(Animation::Running, controller->getAnimation(0, Animation::Opacity
)->runState()); |
103 | 103 |
104 // Pause the main-thread animation. | 104 // Pause the main-thread animation. |
105 controller->suspendAnimations(1); | 105 controller->suspendAnimations(1); |
106 EXPECT_EQ(ActiveAnimation::Paused, controller->getActiveAnimation(0, ActiveA
nimation::Opacity)->runState()); | 106 EXPECT_EQ(Animation::Paused, controller->getAnimation(0, Animation::Opacity)
->runState()); |
107 | 107 |
108 // The pause run state change should make it to the impl thread controller. | 108 // The pause run state change should make it to the impl thread controller. |
109 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 109 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
110 EXPECT_EQ(ActiveAnimation::Paused, controllerImpl->getActiveAnimation(0, Act
iveAnimation::Opacity)->runState()); | 110 EXPECT_EQ(Animation::Paused, controllerImpl->getAnimation(0, Animation::Opac
ity)->runState()); |
111 | 111 |
112 // Resume the main-thread animation. | 112 // Resume the main-thread animation. |
113 controller->resumeAnimations(2); | 113 controller->resumeAnimations(2); |
114 EXPECT_EQ(ActiveAnimation::Running, controller->getActiveAnimation(0, Active
Animation::Opacity)->runState()); | 114 EXPECT_EQ(Animation::Running, controller->getAnimation(0, Animation::Opacity
)->runState()); |
115 | 115 |
116 // The pause run state change should make it to the impl thread controller. | 116 // The pause run state change should make it to the impl thread controller. |
117 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 117 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
118 EXPECT_EQ(ActiveAnimation::Running, controllerImpl->getActiveAnimation(0, Ac
tiveAnimation::Opacity)->runState()); | 118 EXPECT_EQ(Animation::Running, controllerImpl->getAnimation(0, Animation::Opa
city)->runState()); |
119 } | 119 } |
120 | 120 |
121 TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation) | 121 TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation) |
122 { | 122 { |
123 FakeLayerAnimationValueObserver dummyImpl; | 123 FakeLayerAnimationValueObserver dummyImpl; |
124 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); | 124 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
125 controllerImpl->addObserver(&dummyImpl); | 125 controllerImpl->addObserver(&dummyImpl); |
126 FakeLayerAnimationValueObserver dummy; | 126 FakeLayerAnimationValueObserver dummy; |
127 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 127 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
128 controller->addObserver(&dummy); | 128 controller->addObserver(&dummy); |
129 | 129 |
130 EXPECT_FALSE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)
); | 130 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); |
131 | 131 |
132 int animationId = addOpacityTransitionToController(*controller, 1, 0, 1, fal
se); | 132 int animationId = addOpacityTransitionToController(*controller, 1, 0, 1, fal
se); |
133 | 133 |
134 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 134 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
135 | 135 |
136 EXPECT_TRUE(controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity))
; | 136 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); |
137 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, controllerImpl->get
ActiveAnimation(0, ActiveAnimation::Opacity)->runState()); | 137 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat
ion(0, Animation::Opacity)->runState()); |
138 | 138 |
139 // Notify main thread controller that the animation has started. | 139 // Notify main thread controller that the animation has started. |
140 AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, ActiveAn
imation::Opacity, 0); | 140 AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, Animatio
n::Opacity, 0); |
141 controller->OnAnimationStarted(animationStartedEvent); | 141 controller->OnAnimationStarted(animationStartedEvent); |
142 | 142 |
143 // Force animation to complete on impl thread. | 143 // Force animation to complete on impl thread. |
144 controllerImpl->removeAnimation(animationId); | 144 controllerImpl->removeAnimation(animationId); |
145 | 145 |
146 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); | 146 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
147 | 147 |
148 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 148 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
149 | 149 |
150 // Even though the main thread has a 'new' animation, it should not be pushe
d because the animation has already completed on the impl thread. | 150 // Even though the main thread has a 'new' animation, it should not be pushe
d because the animation has already completed on the impl thread. |
151 EXPECT_FALSE(controllerImpl->getActiveAnimation(animationId, ActiveAnimation
::Opacity)); | 151 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); |
152 } | 152 } |
153 | 153 |
154 // Tests that transitioning opacity from 0 to 1 works as expected. | 154 // Tests that transitioning opacity from 0 to 1 works as expected. |
155 TEST(LayerAnimationControllerTest, TrivialTransition) | 155 TEST(LayerAnimationControllerTest, TrivialTransition) |
156 { | 156 { |
157 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 157 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
158 FakeLayerAnimationValueObserver dummy; | 158 FakeLayerAnimationValueObserver dummy; |
159 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 159 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
160 controller->addObserver(&dummy); | 160 controller->addObserver(&dummy); |
161 | 161 |
162 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 162 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
163 | 163 |
164 controller->addAnimation(toAdd.Pass()); | 164 controller->addAnimation(toAdd.Pass()); |
165 controller->animate(0, events.get()); | 165 controller->animate(0, events.get()); |
166 EXPECT_TRUE(controller->hasActiveAnimation()); | 166 EXPECT_TRUE(controller->hasActiveAnimation()); |
167 EXPECT_EQ(0, dummy.opacity()); | 167 EXPECT_EQ(0, dummy.opacity()); |
168 controller->animate(1, events.get()); | 168 controller->animate(1, events.get()); |
169 EXPECT_EQ(1, dummy.opacity()); | 169 EXPECT_EQ(1, dummy.opacity()); |
170 EXPECT_FALSE(controller->hasActiveAnimation()); | 170 EXPECT_FALSE(controller->hasActiveAnimation()); |
171 } | 171 } |
172 | 172 |
173 // Tests animations that are waiting for a synchronized start time do not finish
. | 173 // Tests animations that are waiting for a synchronized start time do not finish
. |
174 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) | 174 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
yWaitLongerToStartThanTheirDuration) |
175 { | 175 { |
176 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 176 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
177 FakeLayerAnimationValueObserver dummy; | 177 FakeLayerAnimationValueObserver dummy; |
178 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 178 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
179 controller->addObserver(&dummy); | 179 controller->addObserver(&dummy); |
180 | 180 |
181 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 181 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
182 toAdd->setNeedsSynchronizedStartTime(true); | 182 toAdd->setNeedsSynchronizedStartTime(true); |
183 | 183 |
184 // We should pause at the first keyframe indefinitely waiting for that anima
tion to start. | 184 // We should pause at the first keyframe indefinitely waiting for that anima
tion to start. |
185 controller->addAnimation(toAdd.Pass()); | 185 controller->addAnimation(toAdd.Pass()); |
186 controller->animate(0, events.get()); | 186 controller->animate(0, events.get()); |
187 EXPECT_TRUE(controller->hasActiveAnimation()); | 187 EXPECT_TRUE(controller->hasActiveAnimation()); |
188 EXPECT_EQ(0, dummy.opacity()); | 188 EXPECT_EQ(0, dummy.opacity()); |
189 controller->animate(1, events.get()); | 189 controller->animate(1, events.get()); |
190 EXPECT_TRUE(controller->hasActiveAnimation()); | 190 EXPECT_TRUE(controller->hasActiveAnimation()); |
191 EXPECT_EQ(0, dummy.opacity()); | 191 EXPECT_EQ(0, dummy.opacity()); |
192 controller->animate(2, events.get()); | 192 controller->animate(2, events.get()); |
193 EXPECT_TRUE(controller->hasActiveAnimation()); | 193 EXPECT_TRUE(controller->hasActiveAnimation()); |
194 EXPECT_EQ(0, dummy.opacity()); | 194 EXPECT_EQ(0, dummy.opacity()); |
195 | 195 |
196 // Send the synchronized start time. | 196 // Send the synchronized start time. |
197 controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1,
ActiveAnimation::Opacity, 2)); | 197 controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1,
Animation::Opacity, 2)); |
198 controller->animate(5, events.get()); | 198 controller->animate(5, events.get()); |
199 EXPECT_EQ(1, dummy.opacity()); | 199 EXPECT_EQ(1, dummy.opacity()); |
200 EXPECT_FALSE(controller->hasActiveAnimation()); | 200 EXPECT_FALSE(controller->hasActiveAnimation()); |
201 } | 201 } |
202 | 202 |
203 // Tests that two queued animations affecting the same property run in sequence. | 203 // Tests that two queued animations affecting the same property run in sequence. |
204 TEST(LayerAnimationControllerTest, TrivialQueuing) | 204 TEST(LayerAnimationControllerTest, TrivialQueuing) |
205 { | 205 { |
206 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 206 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
207 FakeLayerAnimationValueObserver dummy; | 207 FakeLayerAnimationValueObserver dummy; |
208 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 208 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
209 controller->addObserver(&dummy); | 209 controller->addObserver(&dummy); |
210 | 210 |
211 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 211 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
212 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 212 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
213 | 213 |
214 controller->animate(0, events.get()); | 214 controller->animate(0, events.get()); |
215 EXPECT_TRUE(controller->hasActiveAnimation()); | 215 EXPECT_TRUE(controller->hasActiveAnimation()); |
216 EXPECT_EQ(0, dummy.opacity()); | 216 EXPECT_EQ(0, dummy.opacity()); |
217 controller->animate(1, events.get()); | 217 controller->animate(1, events.get()); |
218 EXPECT_TRUE(controller->hasActiveAnimation()); | 218 EXPECT_TRUE(controller->hasActiveAnimation()); |
219 EXPECT_EQ(1, dummy.opacity()); | 219 EXPECT_EQ(1, dummy.opacity()); |
220 controller->animate(2, events.get()); | 220 controller->animate(2, events.get()); |
221 EXPECT_EQ(0.5, dummy.opacity()); | 221 EXPECT_EQ(0.5, dummy.opacity()); |
222 EXPECT_FALSE(controller->hasActiveAnimation()); | 222 EXPECT_FALSE(controller->hasActiveAnimation()); |
223 } | 223 } |
224 | 224 |
225 // Tests interrupting a transition with another transition. | 225 // Tests interrupting a transition with another transition. |
226 TEST(LayerAnimationControllerTest, Interrupt) | 226 TEST(LayerAnimationControllerTest, Interrupt) |
227 { | 227 { |
228 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 228 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
229 FakeLayerAnimationValueObserver dummy; | 229 FakeLayerAnimationValueObserver dummy; |
230 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 230 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
231 controller->addObserver(&dummy); | 231 controller->addObserver(&dummy); |
232 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 232 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
233 controller->animate(0, events.get()); | 233 controller->animate(0, events.get()); |
234 EXPECT_TRUE(controller->hasActiveAnimation()); | 234 EXPECT_TRUE(controller->hasActiveAnimation()); |
235 EXPECT_EQ(0, dummy.opacity()); | 235 EXPECT_EQ(0, dummy.opacity()); |
236 | 236 |
237 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 237 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
238 toAdd->setRunState(ActiveAnimation::WaitingForNextTick, 0); | 238 toAdd->setRunState(Animation::WaitingForNextTick, 0); |
239 controller->addAnimation(toAdd.Pass()); | 239 controller->addAnimation(toAdd.Pass()); |
240 | 240 |
241 // Since the animation was in the WaitingForNextTick state, it should start
right in | 241 // Since the animation was in the WaitingForNextTick state, it should start
right in |
242 // this call to animate. | 242 // this call to animate. |
243 controller->animate(0.5, events.get()); | 243 controller->animate(0.5, events.get()); |
244 EXPECT_TRUE(controller->hasActiveAnimation()); | 244 EXPECT_TRUE(controller->hasActiveAnimation()); |
245 EXPECT_EQ(1, dummy.opacity()); | 245 EXPECT_EQ(1, dummy.opacity()); |
246 controller->animate(1.5, events.get()); | 246 controller->animate(1.5, events.get()); |
247 EXPECT_EQ(0.5, dummy.opacity()); | 247 EXPECT_EQ(0.5, dummy.opacity()); |
248 EXPECT_FALSE(controller->hasActiveAnimation()); | 248 EXPECT_FALSE(controller->hasActiveAnimation()); |
249 } | 249 } |
250 | 250 |
251 // Tests scheduling two animations to run together when only one property is fre
e. | 251 // Tests scheduling two animations to run together when only one property is fre
e. |
252 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) | 252 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) |
253 { | 253 { |
254 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 254 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
255 FakeLayerAnimationValueObserver dummy; | 255 FakeLayerAnimationValueObserver dummy; |
256 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 256 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
257 controller->addObserver(&dummy); | 257 controller->addObserver(&dummy); |
258 | 258 |
259 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); | 259 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr
ansition(1)).PassAs<AnimationCurve>(), 1, Animation::Transform)); |
260 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Transform)); | 260 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr
ansition(1)).PassAs<AnimationCurve>(), 2, Animation::Transform)); |
261 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 261 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 1)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
262 | 262 |
263 controller->animate(0, events.get()); | 263 controller->animate(0, events.get()); |
264 EXPECT_EQ(0, dummy.opacity()); | 264 EXPECT_EQ(0, dummy.opacity()); |
265 EXPECT_TRUE(controller->hasActiveAnimation()); | 265 EXPECT_TRUE(controller->hasActiveAnimation()); |
266 controller->animate(1, events.get()); | 266 controller->animate(1, events.get()); |
267 // Should not have started the float transition yet. | 267 // Should not have started the float transition yet. |
268 EXPECT_TRUE(controller->hasActiveAnimation()); | 268 EXPECT_TRUE(controller->hasActiveAnimation()); |
269 EXPECT_EQ(0, dummy.opacity()); | 269 EXPECT_EQ(0, dummy.opacity()); |
270 // The float animation should have started at time 1 and should be done. | 270 // The float animation should have started at time 1 and should be done. |
271 controller->animate(2, events.get()); | 271 controller->animate(2, events.get()); |
272 EXPECT_EQ(1, dummy.opacity()); | 272 EXPECT_EQ(1, dummy.opacity()); |
273 EXPECT_FALSE(controller->hasActiveAnimation()); | 273 EXPECT_FALSE(controller->hasActiveAnimation()); |
274 } | 274 } |
275 | 275 |
276 // Tests scheduling two animations to run together with different lengths and an
other | 276 // Tests scheduling two animations to run together with different lengths and an
other |
277 // animation queued to start when the shorter animation finishes (should wait | 277 // animation queued to start when the shorter animation finishes (should wait |
278 // for both to finish). | 278 // for both to finish). |
279 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) | 279 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) |
280 { | 280 { |
281 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 281 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
282 FakeLayerAnimationValueObserver dummy; | 282 FakeLayerAnimationValueObserver dummy; |
283 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 283 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
284 controller->addObserver(&dummy); | 284 controller->addObserver(&dummy); |
285 | 285 |
286 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(2)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Transform)); | 286 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr
ansition(2)).PassAs<AnimationCurve>(), 1, Animation::Transform)); |
287 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 287 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
288 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 288 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
289 | 289 |
290 // Animations with id 1 should both start now. | 290 // Animations with id 1 should both start now. |
291 controller->animate(0, events.get()); | 291 controller->animate(0, events.get()); |
292 EXPECT_TRUE(controller->hasActiveAnimation()); | 292 EXPECT_TRUE(controller->hasActiveAnimation()); |
293 EXPECT_EQ(0, dummy.opacity()); | 293 EXPECT_EQ(0, dummy.opacity()); |
294 // The opacity animation should have finished at time 1, but the group | 294 // The opacity animation should have finished at time 1, but the group |
295 // of animations with id 1 don't finish until time 2 because of the length | 295 // of animations with id 1 don't finish until time 2 because of the length |
296 // of the transform animation. | 296 // of the transform animation. |
297 controller->animate(2, events.get()); | 297 controller->animate(2, events.get()); |
298 // Should not have started the float transition yet. | 298 // Should not have started the float transition yet. |
299 EXPECT_TRUE(controller->hasActiveAnimation()); | 299 EXPECT_TRUE(controller->hasActiveAnimation()); |
300 EXPECT_EQ(1, dummy.opacity()); | 300 EXPECT_EQ(1, dummy.opacity()); |
301 | 301 |
302 // The second opacity animation should start at time 2 and should be done by
time 3 | 302 // The second opacity animation should start at time 2 and should be done by
time 3 |
303 controller->animate(3, events.get()); | 303 controller->animate(3, events.get()); |
304 EXPECT_EQ(0.5, dummy.opacity()); | 304 EXPECT_EQ(0.5, dummy.opacity()); |
305 EXPECT_FALSE(controller->hasActiveAnimation()); | 305 EXPECT_FALSE(controller->hasActiveAnimation()); |
306 } | 306 } |
307 | 307 |
308 // Tests scheduling an animation to start in the future. | 308 // Tests scheduling an animation to start in the future. |
309 TEST(LayerAnimationControllerTest, ScheduleAnimation) | 309 TEST(LayerAnimationControllerTest, ScheduleAnimation) |
310 { | 310 { |
311 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 311 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
312 FakeLayerAnimationValueObserver dummy; | 312 FakeLayerAnimationValueObserver dummy; |
313 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 313 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
314 controller->addObserver(&dummy); | 314 controller->addObserver(&dummy); |
315 | 315 |
316 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 316 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
317 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 317 toAdd->setRunState(Animation::WaitingForStartTime, 0); |
318 toAdd->setStartTime(1); | 318 toAdd->setStartTime(1); |
319 controller->addAnimation(toAdd.Pass()); | 319 controller->addAnimation(toAdd.Pass()); |
320 | 320 |
321 controller->animate(0, events.get()); | 321 controller->animate(0, events.get()); |
322 EXPECT_TRUE(controller->hasActiveAnimation()); | 322 EXPECT_TRUE(controller->hasActiveAnimation()); |
323 EXPECT_EQ(0, dummy.opacity()); | 323 EXPECT_EQ(0, dummy.opacity()); |
324 controller->animate(1, events.get()); | 324 controller->animate(1, events.get()); |
325 EXPECT_TRUE(controller->hasActiveAnimation()); | 325 EXPECT_TRUE(controller->hasActiveAnimation()); |
326 EXPECT_EQ(0, dummy.opacity()); | 326 EXPECT_EQ(0, dummy.opacity()); |
327 controller->animate(2, events.get()); | 327 controller->animate(2, events.get()); |
328 EXPECT_EQ(1, dummy.opacity()); | 328 EXPECT_EQ(1, dummy.opacity()); |
329 EXPECT_FALSE(controller->hasActiveAnimation()); | 329 EXPECT_FALSE(controller->hasActiveAnimation()); |
330 } | 330 } |
331 | 331 |
332 // Tests scheduling an animation to start in the future that's interrupting a ru
nning animation. | 332 // Tests scheduling an animation to start in the future that's interrupting a ru
nning animation. |
333 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) | 333 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) |
334 { | 334 { |
335 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 335 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
336 FakeLayerAnimationValueObserver dummy; | 336 FakeLayerAnimationValueObserver dummy; |
337 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 337 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
338 controller->addObserver(&dummy); | 338 controller->addObserver(&dummy); |
339 | 339 |
340 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 340 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(2, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
341 | 341 |
342 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 342 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
343 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 343 toAdd->setRunState(Animation::WaitingForStartTime, 0); |
344 toAdd->setStartTime(1); | 344 toAdd->setStartTime(1); |
345 controller->addAnimation(toAdd.Pass()); | 345 controller->addAnimation(toAdd.Pass()); |
346 | 346 |
347 // First 2s opacity transition should start immediately. | 347 // First 2s opacity transition should start immediately. |
348 controller->animate(0, events.get()); | 348 controller->animate(0, events.get()); |
349 EXPECT_TRUE(controller->hasActiveAnimation()); | 349 EXPECT_TRUE(controller->hasActiveAnimation()); |
350 EXPECT_EQ(0, dummy.opacity()); | 350 EXPECT_EQ(0, dummy.opacity()); |
351 controller->animate(0.5, events.get()); | 351 controller->animate(0.5, events.get()); |
352 EXPECT_TRUE(controller->hasActiveAnimation()); | 352 EXPECT_TRUE(controller->hasActiveAnimation()); |
353 EXPECT_EQ(0.25, dummy.opacity()); | 353 EXPECT_EQ(0.25, dummy.opacity()); |
354 controller->animate(1, events.get()); | 354 controller->animate(1, events.get()); |
355 EXPECT_TRUE(controller->hasActiveAnimation()); | 355 EXPECT_TRUE(controller->hasActiveAnimation()); |
356 EXPECT_EQ(0.5, dummy.opacity()); | 356 EXPECT_EQ(0.5, dummy.opacity()); |
357 controller->animate(2, events.get()); | 357 controller->animate(2, events.get()); |
358 EXPECT_EQ(0, dummy.opacity()); | 358 EXPECT_EQ(0, dummy.opacity()); |
359 EXPECT_FALSE(controller->hasActiveAnimation()); | 359 EXPECT_FALSE(controller->hasActiveAnimation()); |
360 } | 360 } |
361 | 361 |
362 // Tests scheduling an animation to start in the future that interrupts a runnin
g animation | 362 // Tests scheduling an animation to start in the future that interrupts a runnin
g animation |
363 // and there is yet another animation queued to start later. | 363 // and there is yet another animation queued to start later. |
364 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW
ithAnimInQueue) | 364 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW
ithAnimInQueue) |
365 { | 365 { |
366 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 366 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
367 FakeLayerAnimationValueObserver dummy; | 367 FakeLayerAnimationValueObserver dummy; |
368 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 368 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
369 controller->addObserver(&dummy); | 369 controller->addObserver(&dummy); |
370 | 370 |
371 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opacity)); | 371 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(2, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
372 | 372 |
373 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Op
acity)); | 373 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
374 toAdd->setRunState(ActiveAnimation::WaitingForStartTime, 0); | 374 toAdd->setRunState(Animation::WaitingForStartTime, 0); |
375 toAdd->setStartTime(1); | 375 toAdd->setStartTime(1); |
376 controller->addAnimation(toAdd.Pass()); | 376 controller->addAnimation(toAdd.Pass()); |
377 | 377 |
378 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, ActiveAnimation::Opacity)); | 378 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, Animation::Opacity)); |
379 | 379 |
380 // First 2s opacity transition should start immediately. | 380 // First 2s opacity transition should start immediately. |
381 controller->animate(0, events.get()); | 381 controller->animate(0, events.get()); |
382 EXPECT_TRUE(controller->hasActiveAnimation()); | 382 EXPECT_TRUE(controller->hasActiveAnimation()); |
383 EXPECT_EQ(0, dummy.opacity()); | 383 EXPECT_EQ(0, dummy.opacity()); |
384 controller->animate(0.5, events.get()); | 384 controller->animate(0.5, events.get()); |
385 EXPECT_TRUE(controller->hasActiveAnimation()); | 385 EXPECT_TRUE(controller->hasActiveAnimation()); |
386 EXPECT_EQ(0.25, dummy.opacity()); | 386 EXPECT_EQ(0.25, dummy.opacity()); |
387 EXPECT_TRUE(controller->hasActiveAnimation()); | 387 EXPECT_TRUE(controller->hasActiveAnimation()); |
388 controller->animate(1, events.get()); | 388 controller->animate(1, events.get()); |
389 EXPECT_TRUE(controller->hasActiveAnimation()); | 389 EXPECT_TRUE(controller->hasActiveAnimation()); |
390 EXPECT_EQ(0.5, dummy.opacity()); | 390 EXPECT_EQ(0.5, dummy.opacity()); |
391 controller->animate(3, events.get()); | 391 controller->animate(3, events.get()); |
392 EXPECT_TRUE(controller->hasActiveAnimation()); | 392 EXPECT_TRUE(controller->hasActiveAnimation()); |
393 EXPECT_EQ(0, dummy.opacity()); | 393 EXPECT_EQ(0, dummy.opacity()); |
394 controller->animate(4, events.get()); | 394 controller->animate(4, events.get()); |
395 EXPECT_EQ(0.75, dummy.opacity()); | 395 EXPECT_EQ(0.75, dummy.opacity()); |
396 EXPECT_FALSE(controller->hasActiveAnimation()); | 396 EXPECT_FALSE(controller->hasActiveAnimation()); |
397 } | 397 } |
398 | 398 |
399 // Test that a looping animation loops and for the correct number of iterations. | 399 // Test that a looping animation loops and for the correct number of iterations. |
400 TEST(LayerAnimationControllerTest, TrivialLooping) | 400 TEST(LayerAnimationControllerTest, TrivialLooping) |
401 { | 401 { |
402 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 402 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
403 FakeLayerAnimationValueObserver dummy; | 403 FakeLayerAnimationValueObserver dummy; |
404 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 404 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
405 controller->addObserver(&dummy); | 405 controller->addObserver(&dummy); |
406 | 406 |
407 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), 1, ActiveAnimation::Opac
ity)); | 407 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); |
408 toAdd->setIterations(3); | 408 toAdd->setIterations(3); |
409 controller->addAnimation(toAdd.Pass()); | 409 controller->addAnimation(toAdd.Pass()); |
410 | 410 |
411 controller->animate(0, events.get()); | 411 controller->animate(0, events.get()); |
412 EXPECT_TRUE(controller->hasActiveAnimation()); | 412 EXPECT_TRUE(controller->hasActiveAnimation()); |
413 EXPECT_EQ(0, dummy.opacity()); | 413 EXPECT_EQ(0, dummy.opacity()); |
414 controller->animate(1.25, events.get()); | 414 controller->animate(1.25, events.get()); |
415 EXPECT_TRUE(controller->hasActiveAnimation()); | 415 EXPECT_TRUE(controller->hasActiveAnimation()); |
416 EXPECT_EQ(0.25, dummy.opacity()); | 416 EXPECT_EQ(0.25, dummy.opacity()); |
417 controller->animate(1.75, events.get()); | 417 controller->animate(1.75, events.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
434 | 434 |
435 // Test that an infinitely looping animation does indeed go until aborted. | 435 // Test that an infinitely looping animation does indeed go until aborted. |
436 TEST(LayerAnimationControllerTest, InfiniteLooping) | 436 TEST(LayerAnimationControllerTest, InfiniteLooping) |
437 { | 437 { |
438 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 438 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
439 FakeLayerAnimationValueObserver dummy; | 439 FakeLayerAnimationValueObserver dummy; |
440 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 440 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
441 controller->addObserver(&dummy); | 441 controller->addObserver(&dummy); |
442 | 442 |
443 const int id = 1; | 443 const int id = 1; |
444 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opa
city)); | 444 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(1, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); |
445 toAdd->setIterations(-1); | 445 toAdd->setIterations(-1); |
446 controller->addAnimation(toAdd.Pass()); | 446 controller->addAnimation(toAdd.Pass()); |
447 | 447 |
448 controller->animate(0, events.get()); | 448 controller->animate(0, events.get()); |
449 EXPECT_TRUE(controller->hasActiveAnimation()); | 449 EXPECT_TRUE(controller->hasActiveAnimation()); |
450 EXPECT_EQ(0, dummy.opacity()); | 450 EXPECT_EQ(0, dummy.opacity()); |
451 controller->animate(1.25, events.get()); | 451 controller->animate(1.25, events.get()); |
452 EXPECT_TRUE(controller->hasActiveAnimation()); | 452 EXPECT_TRUE(controller->hasActiveAnimation()); |
453 EXPECT_EQ(0.25, dummy.opacity()); | 453 EXPECT_EQ(0.25, dummy.opacity()); |
454 controller->animate(1.75, events.get()); | 454 controller->animate(1.75, events.get()); |
455 EXPECT_TRUE(controller->hasActiveAnimation()); | 455 EXPECT_TRUE(controller->hasActiveAnimation()); |
456 EXPECT_EQ(0.75, dummy.opacity()); | 456 EXPECT_EQ(0.75, dummy.opacity()); |
457 | 457 |
458 controller->animate(1073741824.25, events.get()); | 458 controller->animate(1073741824.25, events.get()); |
459 EXPECT_TRUE(controller->hasActiveAnimation()); | 459 EXPECT_TRUE(controller->hasActiveAnimation()); |
460 EXPECT_EQ(0.25, dummy.opacity()); | 460 EXPECT_EQ(0.25, dummy.opacity()); |
461 controller->animate(1073741824.75, events.get()); | 461 controller->animate(1073741824.75, events.get()); |
462 EXPECT_TRUE(controller->hasActiveAnimation()); | 462 EXPECT_TRUE(controller->hasActiveAnimation()); |
463 EXPECT_EQ(0.75, dummy.opacity()); | 463 EXPECT_EQ(0.75, dummy.opacity()); |
464 | 464 |
465 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 465 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); |
466 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 0.75); | 466 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Abo
rted, 0.75); |
467 EXPECT_FALSE(controller->hasActiveAnimation()); | 467 EXPECT_FALSE(controller->hasActiveAnimation()); |
468 EXPECT_EQ(0.75, dummy.opacity()); | 468 EXPECT_EQ(0.75, dummy.opacity()); |
469 } | 469 } |
470 | 470 |
471 // Test that pausing and resuming work as expected. | 471 // Test that pausing and resuming work as expected. |
472 TEST(LayerAnimationControllerTest, PauseResume) | 472 TEST(LayerAnimationControllerTest, PauseResume) |
473 { | 473 { |
474 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 474 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
475 FakeLayerAnimationValueObserver dummy; | 475 FakeLayerAnimationValueObserver dummy; |
476 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 476 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
477 controller->addObserver(&dummy); | 477 controller->addObserver(&dummy); |
478 | 478 |
479 const int id = 1; | 479 const int id = 1; |
480 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); | 480 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); |
481 | 481 |
482 controller->animate(0, events.get()); | 482 controller->animate(0, events.get()); |
483 EXPECT_TRUE(controller->hasActiveAnimation()); | 483 EXPECT_TRUE(controller->hasActiveAnimation()); |
484 EXPECT_EQ(0, dummy.opacity()); | 484 EXPECT_EQ(0, dummy.opacity()); |
485 controller->animate(0.5, events.get()); | 485 controller->animate(0.5, events.get()); |
486 EXPECT_TRUE(controller->hasActiveAnimation()); | 486 EXPECT_TRUE(controller->hasActiveAnimation()); |
487 EXPECT_EQ(0.5, dummy.opacity()); | 487 EXPECT_EQ(0.5, dummy.opacity()); |
488 | 488 |
489 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 489 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); |
490 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Paused, 0.5); | 490 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Pau
sed, 0.5); |
491 | 491 |
492 controller->animate(1024, events.get()); | 492 controller->animate(1024, events.get()); |
493 EXPECT_TRUE(controller->hasActiveAnimation()); | 493 EXPECT_TRUE(controller->hasActiveAnimation()); |
494 EXPECT_EQ(0.5, dummy.opacity()); | 494 EXPECT_EQ(0.5, dummy.opacity()); |
495 | 495 |
496 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 496 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); |
497 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Running, 1024); | 497 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Run
ning, 1024); |
498 | 498 |
499 controller->animate(1024.25, events.get()); | 499 controller->animate(1024.25, events.get()); |
500 EXPECT_TRUE(controller->hasActiveAnimation()); | 500 EXPECT_TRUE(controller->hasActiveAnimation()); |
501 EXPECT_EQ(0.75, dummy.opacity()); | 501 EXPECT_EQ(0.75, dummy.opacity()); |
502 controller->animate(1024.5, events.get()); | 502 controller->animate(1024.5, events.get()); |
503 EXPECT_FALSE(controller->hasActiveAnimation()); | 503 EXPECT_FALSE(controller->hasActiveAnimation()); |
504 EXPECT_EQ(1, dummy.opacity()); | 504 EXPECT_EQ(1, dummy.opacity()); |
505 } | 505 } |
506 | 506 |
507 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) | 507 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) |
508 { | 508 { |
509 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 509 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
510 FakeLayerAnimationValueObserver dummy; | 510 FakeLayerAnimationValueObserver dummy; |
511 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 511 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
512 controller->addObserver(&dummy); | 512 controller->addObserver(&dummy); |
513 | 513 |
514 const int id = 1; | 514 const int id = 1; |
515 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeTrans
formTransition(1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Transform)); | 515 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr
ansition(1)).PassAs<AnimationCurve>(), id, Animation::Transform)); |
516 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(2, 0, 1)).PassAs<AnimationCurve>(), id, ActiveAnimation::Opacity)); | 516 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(2, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); |
517 controller->addAnimation(createActiveAnimation(make_scoped_ptr(new FakeFloat
Transition(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, ActiveAnimation::Opacity)); | 517 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi
tion(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); |
518 | 518 |
519 controller->animate(0, events.get()); | 519 controller->animate(0, events.get()); |
520 EXPECT_TRUE(controller->hasActiveAnimation()); | 520 EXPECT_TRUE(controller->hasActiveAnimation()); |
521 EXPECT_EQ(0, dummy.opacity()); | 521 EXPECT_EQ(0, dummy.opacity()); |
522 controller->animate(1, events.get()); | 522 controller->animate(1, events.get()); |
523 EXPECT_TRUE(controller->hasActiveAnimation()); | 523 EXPECT_TRUE(controller->hasActiveAnimation()); |
524 EXPECT_EQ(0.5, dummy.opacity()); | 524 EXPECT_EQ(0.5, dummy.opacity()); |
525 | 525 |
526 EXPECT_TRUE(controller->getActiveAnimation(id, ActiveAnimation::Opacity)); | 526 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); |
527 controller->getActiveAnimation(id, ActiveAnimation::Opacity)->setRunState(Ac
tiveAnimation::Aborted, 1); | 527 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Abo
rted, 1); |
528 controller->animate(1, events.get()); | 528 controller->animate(1, events.get()); |
529 EXPECT_TRUE(controller->hasActiveAnimation()); | 529 EXPECT_TRUE(controller->hasActiveAnimation()); |
530 EXPECT_EQ(1, dummy.opacity()); | 530 EXPECT_EQ(1, dummy.opacity()); |
531 controller->animate(2, events.get()); | 531 controller->animate(2, events.get()); |
532 EXPECT_TRUE(!controller->hasActiveAnimation()); | 532 EXPECT_TRUE(!controller->hasActiveAnimation()); |
533 EXPECT_EQ(0.75, dummy.opacity()); | 533 EXPECT_EQ(0.75, dummy.opacity()); |
534 } | 534 } |
535 | 535 |
536 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) | 536 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) |
537 { | 537 { |
538 FakeLayerAnimationValueObserver dummyImpl; | 538 FakeLayerAnimationValueObserver dummyImpl; |
539 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); | 539 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl
ler::create(0)); |
540 controllerImpl->addObserver(&dummyImpl); | 540 controllerImpl->addObserver(&dummyImpl); |
541 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 541 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
542 FakeLayerAnimationValueObserver dummy; | 542 FakeLayerAnimationValueObserver dummy; |
543 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); | 543 scoped_refptr<LayerAnimationController> controller(LayerAnimationController:
:create(0)); |
544 controller->addObserver(&dummy); | 544 controller->addObserver(&dummy); |
545 | 545 |
546 scoped_ptr<ActiveAnimation> toAdd(createActiveAnimation(make_scoped_ptr(new
FakeFloatTransition(2, 0, 1)).PassAs<AnimationCurve>(), 0, ActiveAnimation::Opac
ity)); | 546 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra
nsition(2, 0, 1)).PassAs<AnimationCurve>(), 0, Animation::Opacity)); |
547 toAdd->setNeedsSynchronizedStartTime(true); | 547 toAdd->setNeedsSynchronizedStartTime(true); |
548 controller->addAnimation(toAdd.Pass()); | 548 controller->addAnimation(toAdd.Pass()); |
549 | 549 |
550 controller->animate(0, 0); | 550 controller->animate(0, 0); |
551 EXPECT_TRUE(controller->hasActiveAnimation()); | 551 EXPECT_TRUE(controller->hasActiveAnimation()); |
552 ActiveAnimation* activeAnimation = controller->getActiveAnimation(0, ActiveA
nimation::Opacity); | 552 Animation* activeAnimation = controller->getAnimation(0, Animation::Opacity)
; |
553 EXPECT_TRUE(activeAnimation); | 553 EXPECT_TRUE(activeAnimation); |
554 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); | 554 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); |
555 | 555 |
556 controller->setForceSync(); | 556 controller->setForceSync(); |
557 | 557 |
558 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 558 controller->pushAnimationUpdatesTo(controllerImpl.get()); |
559 | 559 |
560 activeAnimation = controllerImpl->getActiveAnimation(0, ActiveAnimation::Opa
city); | 560 activeAnimation = controllerImpl->getAnimation(0, Animation::Opacity); |
561 EXPECT_TRUE(activeAnimation); | 561 EXPECT_TRUE(activeAnimation); |
562 EXPECT_EQ(ActiveAnimation::WaitingForTargetAvailability, activeAnimation->ru
nState()); | 562 EXPECT_EQ(Animation::WaitingForTargetAvailability, activeAnimation->runState
()); |
563 } | 563 } |
564 | 564 |
565 } // namespace | 565 } // namespace |
566 } // namespace cc | 566 } // namespace cc |
OLD | NEW |