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/animation.h" | 7 #include "cc/animation.h" |
8 #include "cc/animation_curve.h" | 8 #include "cc/animation_curve.h" |
9 #include "cc/keyframed_animation_curve.h" | 9 #include "cc/keyframed_animation_curve.h" |
10 #include "cc/test/animation_test_common.h" | 10 #include "cc/test/animation_test_common.h" |
11 #include "cc/transform_operations.h" | 11 #include "cc/transform_operations.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 void expectTranslateX(double translateX, const gfx::Transform& matrix) | 19 void ExpectTranslateX(double translate_x, const gfx::Transform& matrix) { |
20 { | 20 EXPECT_FLOAT_EQ(translate_x, matrix.matrix().getDouble(0, 3)); } |
21 EXPECT_FLOAT_EQ(translateX, matrix.matrix().getDouble(0, 3)); | 21 |
22 } | 22 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, |
23 | 23 int id, |
24 scoped_ptr<Animation> createAnimation(scoped_ptr<AnimationCurve> curve, int id, Animation::TargetProperty property) | 24 Animation::TargetProperty property) { |
25 { | 25 return Animation::Create(curve.Pass(), 0, id, property); |
26 return Animation::create(curve.Pass(), 0, id, property); | 26 } |
27 } | 27 |
28 | 28 TEST(LayerAnimationControllerTest, SyncNewAnimation) { |
29 TEST(LayerAnimationControllerTest, syncNewAnimation) | 29 FakeLayerAnimationValueObserver dummy_impl; |
30 { | 30 scoped_refptr<LayerAnimationController> controller_impl( |
31 FakeLayerAnimationValueObserver dummyImpl; | 31 LayerAnimationController::Create(0)); |
32 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 32 controller_impl->AddObserver(&dummy_impl); |
33 controllerImpl->addObserver(&dummyImpl); | 33 FakeLayerAnimationValueObserver dummy; |
34 FakeLayerAnimationValueObserver dummy; | 34 scoped_refptr<LayerAnimationController> controller( |
35 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 35 LayerAnimationController::Create(0)); |
36 controller->addObserver(&dummy); | 36 controller->AddObserver(&dummy); |
37 | 37 |
38 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); | 38 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); |
39 | 39 |
40 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 40 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
41 | 41 |
42 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 42 controller->PushAnimationUpdatesTo(controller_impl.get()); |
43 | 43 |
44 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); | 44 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); |
45 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); | 45 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
46 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); | |
46 } | 47 } |
47 | 48 |
48 // If an animation is started on the impl thread before it is ticked on the main | 49 // If an animation is started on the impl thread before it is ticked on the main |
49 // thread, we must be sure to respect the synchronized start time. | 50 // thread, we must be sure to respect the synchronized start time. |
50 TEST(LayerAnimationControllerTest, doNotClobberStartTimes) | 51 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { |
51 { | 52 FakeLayerAnimationValueObserver dummy_impl; |
52 FakeLayerAnimationValueObserver dummyImpl; | 53 scoped_refptr<LayerAnimationController> controller_impl( |
53 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 54 LayerAnimationController::Create(0)); |
54 controllerImpl->addObserver(&dummyImpl); | 55 controller_impl->AddObserver(&dummy_impl); |
55 FakeLayerAnimationValueObserver dummy; | 56 FakeLayerAnimationValueObserver dummy; |
56 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 57 scoped_refptr<LayerAnimationController> controller( |
57 controller->addObserver(&dummy); | 58 LayerAnimationController::Create(0)); |
58 | 59 controller->AddObserver(&dummy); |
59 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); | 60 |
60 | 61 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); |
61 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 62 |
62 | 63 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
63 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 64 |
64 | 65 controller->PushAnimationUpdatesTo(controller_impl.get()); |
65 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); | 66 |
66 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); | 67 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); |
67 | 68 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
68 AnimationEventsVector events; | 69 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); |
69 controllerImpl->animate(1); | 70 |
70 controllerImpl->updateState(&events); | 71 AnimationEventsVector events; |
71 | 72 controller_impl->Animate(1.0); |
72 // Synchronize the start times. | 73 controller_impl->UpdateState(&events); |
73 EXPECT_EQ(1u, events.size()); | 74 |
74 controller->OnAnimationStarted(events[0]); | 75 // Synchronize the start times. |
75 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); | 76 EXPECT_EQ(1u, events.size()); |
76 | 77 controller->OnAnimationStarted(events[0]); |
77 // Start the animation on the main thread. Should not affect the start time. | 78 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), |
78 controller->animate(1.5); | 79 controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); |
79 controller->updateState(0); | 80 |
80 EXPECT_EQ(controller->getAnimation(0, Animation::Opacity)->startTime(), cont rollerImpl->getAnimation(0, Animation::Opacity)->startTime()); | 81 // Start the animation on the main thread. Should not affect the start time. |
81 } | 82 controller->Animate(1.5); |
82 | 83 controller->UpdateState(NULL); |
83 TEST(LayerAnimationControllerTest, syncPauseAndResume) | 84 EXPECT_EQ(controller->GetAnimation(0, Animation::Opacity)->start_time(), |
84 { | 85 controller_impl->GetAnimation(0, Animation::Opacity)->start_time()); |
85 FakeLayerAnimationValueObserver dummyImpl; | 86 } |
86 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 87 |
87 controllerImpl->addObserver(&dummyImpl); | 88 TEST(LayerAnimationControllerTest, SyncPauseAndResume) { |
88 FakeLayerAnimationValueObserver dummy; | 89 FakeLayerAnimationValueObserver dummy_impl; |
89 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 90 scoped_refptr<LayerAnimationController> controller_impl( |
90 controller->addObserver(&dummy); | 91 LayerAnimationController::Create(0)); |
91 | 92 controller_impl->AddObserver(&dummy_impl); |
92 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); | 93 FakeLayerAnimationValueObserver dummy; |
93 | 94 scoped_refptr<LayerAnimationController> controller( |
94 addOpacityTransitionToController(*controller, 1, 0, 1, false); | 95 LayerAnimationController::Create(0)); |
95 | 96 controller->AddObserver(&dummy); |
96 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 97 |
97 | 98 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); |
98 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); | 99 |
99 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); | 100 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
100 | 101 |
101 // Start the animations on each controller. | 102 controller->PushAnimationUpdatesTo(controller_impl.get()); |
102 AnimationEventsVector events; | 103 |
103 controllerImpl->animate(0); | 104 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); |
104 controllerImpl->updateState(&events); | 105 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
105 controller->animate(0); | 106 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); |
106 controller->updateState(0); | 107 |
107 EXPECT_EQ(Animation::Running, controllerImpl->getAnimation(0, Animation::Opa city)->runState()); | 108 // Start the animations on each controller. |
108 EXPECT_EQ(Animation::Running, controller->getAnimation(0, Animation::Opacity )->runState()); | 109 AnimationEventsVector events; |
109 | 110 controller_impl->Animate(0.0); |
110 // Pause the main-thread animation. | 111 controller_impl->UpdateState(&events); |
111 controller->suspendAnimations(1); | 112 controller->Animate(0.0); |
112 EXPECT_EQ(Animation::Paused, controller->getAnimation(0, Animation::Opacity) ->runState()); | 113 controller->UpdateState(NULL); |
113 | 114 EXPECT_EQ(Animation::Running, |
114 // The pause run state change should make it to the impl thread controller. | 115 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); |
115 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 116 EXPECT_EQ(Animation::Running, |
116 EXPECT_EQ(Animation::Paused, controllerImpl->getAnimation(0, Animation::Opac ity)->runState()); | 117 controller->GetAnimation(0, Animation::Opacity)->run_state()); |
117 | 118 |
118 // Resume the main-thread animation. | 119 // Pause the main-thread animation. |
119 controller->resumeAnimations(2); | 120 controller->SuspendAnimations(1.0); |
120 EXPECT_EQ(Animation::Running, controller->getAnimation(0, Animation::Opacity )->runState()); | 121 EXPECT_EQ(Animation::Paused, |
121 | 122 controller->GetAnimation(0, Animation::Opacity)->run_state()); |
122 // The pause run state change should make it to the impl thread controller. | 123 |
123 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 124 // The pause run state change should make it to the impl thread controller. |
124 EXPECT_EQ(Animation::Running, controllerImpl->getAnimation(0, Animation::Opa city)->runState()); | 125 controller->PushAnimationUpdatesTo(controller_impl.get()); |
125 } | 126 EXPECT_EQ(Animation::Paused, |
126 | 127 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); |
127 TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation) | 128 |
128 { | 129 // Resume the main-thread animation. |
129 FakeLayerAnimationValueObserver dummyImpl; | 130 controller->ResumeAnimations(2.0); |
130 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 131 EXPECT_EQ(Animation::Running, |
131 controllerImpl->addObserver(&dummyImpl); | 132 controller->GetAnimation(0, Animation::Opacity)->run_state()); |
132 FakeLayerAnimationValueObserver dummy; | 133 |
133 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 134 // The pause run state change should make it to the impl thread controller. |
134 controller->addObserver(&dummy); | 135 controller->PushAnimationUpdatesTo(controller_impl.get()); |
135 | 136 EXPECT_EQ(Animation::Running, |
136 EXPECT_FALSE(controllerImpl->getAnimation(0, Animation::Opacity)); | 137 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); |
137 | 138 } |
138 int animationId = addOpacityTransitionToController(*controller, 1, 0, 1, fal se); | 139 |
139 | 140 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { |
140 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 141 FakeLayerAnimationValueObserver dummy_impl; |
141 | 142 scoped_refptr<LayerAnimationController> controller_impl( |
142 EXPECT_TRUE(controllerImpl->getAnimation(0, Animation::Opacity)); | 143 LayerAnimationController::Create(0)); |
143 EXPECT_EQ(Animation::WaitingForTargetAvailability, controllerImpl->getAnimat ion(0, Animation::Opacity)->runState()); | 144 controller_impl->AddObserver(&dummy_impl); |
144 | 145 FakeLayerAnimationValueObserver dummy; |
145 // Notify main thread controller that the animation has started. | 146 scoped_refptr<LayerAnimationController> controller( |
146 AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, Animatio n::Opacity, 0); | 147 LayerAnimationController::Create(0)); |
147 controller->OnAnimationStarted(animationStartedEvent); | 148 controller->AddObserver(&dummy); |
148 | 149 |
149 // Force animation to complete on impl thread. | 150 EXPECT_FALSE(controller_impl->GetAnimation(0, Animation::Opacity)); |
150 controllerImpl->removeAnimation(animationId); | 151 |
151 | 152 int animation_id = |
152 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 153 addOpacityTransitionToController(*controller, 1, 0, 1, false); |
153 | 154 |
154 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 155 controller->PushAnimationUpdatesTo(controller_impl.get()); |
155 | 156 |
156 // 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. | 157 EXPECT_TRUE(controller_impl->GetAnimation(0, Animation::Opacity)); |
157 EXPECT_FALSE(controllerImpl->getAnimation(animationId, Animation::Opacity)); | 158 EXPECT_EQ(Animation::WaitingForTargetAvailability, |
159 controller_impl->GetAnimation(0, Animation::Opacity)->run_state()); | |
160 | |
161 // Notify main thread controller that the animation has started. | |
162 AnimationEvent animation_started_event( | |
163 AnimationEvent::Started, 0, 0, Animation::Opacity, 0); | |
164 controller->OnAnimationStarted(animation_started_event); | |
165 | |
166 // Force animation to complete on impl thread. | |
167 controller_impl->RemoveAnimation(animation_id); | |
168 | |
169 EXPECT_FALSE(controller_impl->GetAnimation(animation_id, Animation::Opacity)); | |
170 | |
171 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
172 | |
173 // Even though the main thread has a 'new' animation, it should not be pushed | |
174 // because the animation has already completed on the impl thread. | |
175 EXPECT_FALSE(controller_impl->GetAnimation(animation_id, Animation::Opacity)); | |
158 } | 176 } |
159 | 177 |
160 // Tests that transitioning opacity from 0 to 1 works as expected. | 178 // Tests that transitioning opacity from 0 to 1 works as expected. |
161 | 179 |
162 static const AnimationEvent* getMostRecentPropertyUpdateEvent(const AnimationEve ntsVector* events) | 180 static const AnimationEvent* GetMostRecentPropertyUpdateEvent( |
163 { | 181 const AnimationEventsVector* events) { |
164 const AnimationEvent* event = 0; | 182 const AnimationEvent* event = 0; |
165 for (size_t i = 0; i < events->size(); ++i) | 183 for (size_t i = 0; i < events->size(); ++i) |
166 if ((*events)[i].type == AnimationEvent::PropertyUpdate) | 184 if ((*events)[i].type == AnimationEvent::PropertyUpdate) |
167 event = &(*events)[i]; | 185 event = &(*events)[i]; |
168 | 186 |
169 return event; | 187 return event; |
170 } | 188 } |
171 | 189 |
172 TEST(LayerAnimationControllerTest, TrivialTransition) | 190 TEST(LayerAnimationControllerTest, TrivialTransition) { |
173 { | 191 scoped_ptr<AnimationEventsVector> events( |
174 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 192 make_scoped_ptr(new AnimationEventsVector)); |
175 FakeLayerAnimationValueObserver dummy; | 193 FakeLayerAnimationValueObserver dummy; |
176 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 194 scoped_refptr<LayerAnimationController> controller( |
177 controller->addObserver(&dummy); | 195 LayerAnimationController::Create(0)); |
178 | 196 controller->AddObserver(&dummy); |
179 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 197 |
180 | 198 scoped_ptr<Animation> to_add(CreateAnimation( |
181 controller->addAnimation(toAdd.Pass()); | 199 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
182 controller->animate(0); | 200 1, |
183 controller->updateState(events.get()); | 201 Animation::Opacity)); |
184 EXPECT_TRUE(controller->hasActiveAnimation()); | 202 |
185 EXPECT_EQ(0, dummy.opacity()); | 203 controller->AddAnimation(to_add.Pass()); |
186 // A non-implOnly animation should not generate property updates. | 204 controller->Animate(0.0); |
187 const AnimationEvent* event = getMostRecentPropertyUpdateEvent(events.get()) ; | 205 controller->UpdateState(events.get()); |
188 EXPECT_FALSE(event); | 206 EXPECT_TRUE(controller->HasActiveAnimation()); |
189 controller->animate(1); | 207 EXPECT_EQ(0, dummy.opacity()); |
190 controller->updateState(events.get()); | 208 // A non-implOnly animation should not generate property updates. |
191 EXPECT_EQ(1, dummy.opacity()); | 209 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
192 EXPECT_FALSE(controller->hasActiveAnimation()); | 210 EXPECT_FALSE(event); |
193 event = getMostRecentPropertyUpdateEvent(events.get()); | 211 controller->Animate(1.0); |
194 EXPECT_FALSE(event); | 212 controller->UpdateState(events.get()); |
195 } | 213 EXPECT_EQ(1, dummy.opacity()); |
196 | 214 EXPECT_FALSE(controller->HasActiveAnimation()); |
197 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) | 215 event = GetMostRecentPropertyUpdateEvent(events.get()); |
198 { | 216 EXPECT_FALSE(event); |
199 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 217 } |
200 FakeLayerAnimationValueObserver dummyImpl; | 218 |
201 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 219 TEST(LayerAnimationControllerTest, TrivialTransitionOnImpl) { |
202 controllerImpl->addObserver(&dummyImpl); | 220 scoped_ptr<AnimationEventsVector> events( |
203 | 221 make_scoped_ptr(new AnimationEventsVector)); |
204 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 222 FakeLayerAnimationValueObserver dummy_impl; |
205 toAdd->setIsImplOnly(true); | 223 scoped_refptr<LayerAnimationController> controller_impl( |
206 | 224 LayerAnimationController::Create(0)); |
207 controllerImpl->addAnimation(toAdd.Pass()); | 225 controller_impl->AddObserver(&dummy_impl); |
208 controllerImpl->animate(0); | 226 |
209 controllerImpl->updateState(events.get()); | 227 scoped_ptr<Animation> to_add(CreateAnimation( |
210 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); | 228 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
211 EXPECT_EQ(0, dummyImpl.opacity()); | 229 1, |
212 EXPECT_EQ(2, events->size()); | 230 Animation::Opacity)); |
213 const AnimationEvent* startOpacityEvent = getMostRecentPropertyUpdateEvent(e vents.get()); | 231 to_add->set_is_impl_only(true); |
214 EXPECT_EQ(0, startOpacityEvent->opacity); | 232 |
215 | 233 controller_impl->AddAnimation(to_add.Pass()); |
216 controllerImpl->animate(1); | 234 controller_impl->Animate(0.0); |
217 controllerImpl->updateState(events.get()); | 235 controller_impl->UpdateState(events.get()); |
218 EXPECT_EQ(1, dummyImpl.opacity()); | 236 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
219 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); | 237 EXPECT_EQ(0, dummy_impl.opacity()); |
220 EXPECT_EQ(4, events->size()); | 238 EXPECT_EQ(2, events->size()); |
221 const AnimationEvent* endOpacityEvent = getMostRecentPropertyUpdateEvent(eve nts.get()); | 239 const AnimationEvent* start_opacity_event = |
222 EXPECT_EQ(1, endOpacityEvent->opacity); | 240 GetMostRecentPropertyUpdateEvent(events.get()); |
223 } | 241 EXPECT_EQ(0, start_opacity_event->opacity); |
224 | 242 |
225 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) | 243 controller_impl->Animate(1.0); |
226 { | 244 controller_impl->UpdateState(events.get()); |
227 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 245 EXPECT_EQ(1, dummy_impl.opacity()); |
228 FakeLayerAnimationValueObserver dummyImpl; | 246 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
229 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 247 EXPECT_EQ(4, events->size()); |
230 controllerImpl->addObserver(&dummyImpl); | 248 const AnimationEvent* end_opacity_event = |
231 | 249 GetMostRecentPropertyUpdateEvent(events.get()); |
232 // Choose different values for x and y to avoid coincidental values in the | 250 EXPECT_EQ(1, end_opacity_event->opacity); |
233 // observed transforms. | 251 } |
234 const float deltaX = 3; | 252 |
235 const float deltaY = 4; | 253 TEST(LayerAnimationControllerTest, TrivialTransformOnImpl) { |
236 | 254 scoped_ptr<AnimationEventsVector> events( |
237 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); | 255 make_scoped_ptr(new AnimationEventsVector)); |
238 | 256 FakeLayerAnimationValueObserver dummy_impl; |
239 // Create simple Transform animation. | 257 scoped_refptr<LayerAnimationController> controller_impl( |
240 TransformOperations operations; | 258 LayerAnimationController::Create(0)); |
241 curve->addKeyframe(TransformKeyframe::create(0, operations, scoped_ptr<cc::T imingFunction>())); | 259 controller_impl->AddObserver(&dummy_impl); |
242 operations.AppendTranslate(deltaX, deltaY, 0); | 260 |
243 curve->addKeyframe(TransformKeyframe::create(1, operations, scoped_ptr<cc::T imingFunction>())); | 261 // Choose different values for x and y to avoid coincidental values in the |
244 | 262 // observed transforms. |
245 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv e>(), 1, 0, Animation::Transform)); | 263 const float delta_x = 3; |
246 animation->setIsImplOnly(true); | 264 const float delta_y = 4; |
247 controllerImpl->addAnimation(animation.Pass()); | 265 |
248 | 266 scoped_ptr<KeyframedTransformAnimationCurve> curve( |
249 // Run animation. | 267 KeyframedTransformAnimationCurve::Create()); |
250 controllerImpl->animate(0); | 268 |
251 controllerImpl->updateState(events.get()); | 269 // Create simple Transform animation. |
252 EXPECT_TRUE(controllerImpl->hasActiveAnimation()); | 270 TransformOperations operations; |
253 EXPECT_EQ(gfx::Transform(), dummyImpl.transform()); | 271 curve->AddKeyframe(TransformKeyframe::Create( |
254 EXPECT_EQ(2, events->size()); | 272 0, operations, scoped_ptr<cc::TimingFunction>())); |
255 const AnimationEvent* startTransformEvent = getMostRecentPropertyUpdateEvent (events.get()); | 273 operations.AppendTranslate(delta_x, delta_y, 0); |
256 ASSERT_TRUE(startTransformEvent); | 274 curve->AddKeyframe(TransformKeyframe::Create( |
257 EXPECT_EQ(gfx::Transform(), startTransformEvent->transform); | 275 1, operations, scoped_ptr<cc::TimingFunction>())); |
258 | 276 |
259 gfx::Transform expectedTransform; | 277 scoped_ptr<Animation> animation(Animation::Create( |
260 expectedTransform.Translate(deltaX, deltaY); | 278 curve.PassAs<AnimationCurve>(), 1, 0, Animation::Transform)); |
261 | 279 animation->set_is_impl_only(true); |
262 controllerImpl->animate(1); | 280 controller_impl->AddAnimation(animation.Pass()); |
263 controllerImpl->updateState(events.get()); | 281 |
264 EXPECT_EQ(expectedTransform, dummyImpl.transform()); | 282 // Run animation. |
265 EXPECT_FALSE(controllerImpl->hasActiveAnimation()); | 283 controller_impl->Animate(0.0); |
266 EXPECT_EQ(4, events->size()); | 284 controller_impl->UpdateState(events.get()); |
267 const AnimationEvent* endTransformEvent = getMostRecentPropertyUpdateEvent(e vents.get()); | 285 EXPECT_TRUE(controller_impl->HasActiveAnimation()); |
268 EXPECT_EQ(expectedTransform, endTransformEvent->transform); | 286 EXPECT_EQ(gfx::Transform(), dummy_impl.transform()); |
269 } | 287 EXPECT_EQ(2, events->size()); |
270 | 288 const AnimationEvent* start_transform_event = |
271 // Tests animations that are waiting for a synchronized start time do not finish . | 289 GetMostRecentPropertyUpdateEvent(events.get()); |
272 TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe yWaitLongerToStartThanTheirDuration) | 290 ASSERT_TRUE(start_transform_event); |
273 { | 291 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); |
274 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 292 |
275 FakeLayerAnimationValueObserver dummy; | 293 gfx::Transform expected_transform; |
276 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 294 expected_transform.Translate(delta_x, delta_y); |
277 controller->addObserver(&dummy); | 295 |
278 | 296 controller_impl->Animate(1.0); |
279 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 297 controller_impl->UpdateState(events.get()); |
280 toAdd->setNeedsSynchronizedStartTime(true); | 298 EXPECT_EQ(expected_transform, dummy_impl.transform()); |
281 | 299 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
282 // We should pause at the first keyframe indefinitely waiting for that anima tion to start. | 300 EXPECT_EQ(4, events->size()); |
283 controller->addAnimation(toAdd.Pass()); | 301 const AnimationEvent* end_transform_event = |
284 controller->animate(0); | 302 GetMostRecentPropertyUpdateEvent(events.get()); |
285 controller->updateState(events.get()); | 303 EXPECT_EQ(expected_transform, end_transform_event->transform); |
286 EXPECT_TRUE(controller->hasActiveAnimation()); | 304 } |
287 EXPECT_EQ(0, dummy.opacity()); | 305 |
288 controller->animate(1); | 306 // Tests animations that are waiting for a synchronized start time do not |
289 controller->updateState(events.get()); | 307 // finish. |
290 EXPECT_TRUE(controller->hasActiveAnimation()); | 308 TEST(LayerAnimationControllerTest, |
291 EXPECT_EQ(0, dummy.opacity()); | 309 AnimationsWaitingForStartTimeDoNotFinishIfTheyWaitLongerToStartThanTheirDur ation) { |
292 controller->animate(2); | 310 scoped_ptr<AnimationEventsVector> events( |
293 controller->updateState(events.get()); | 311 make_scoped_ptr(new AnimationEventsVector)); |
294 EXPECT_TRUE(controller->hasActiveAnimation()); | 312 FakeLayerAnimationValueObserver dummy; |
295 EXPECT_EQ(0, dummy.opacity()); | 313 scoped_refptr<LayerAnimationController> controller( |
296 | 314 LayerAnimationController::Create(0)); |
297 // Send the synchronized start time. | 315 controller->AddObserver(&dummy); |
298 controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1, Animation::Opacity, 2)); | 316 |
299 controller->animate(5); | 317 scoped_ptr<Animation> to_add(CreateAnimation( |
300 controller->updateState(events.get()); | 318 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
301 EXPECT_EQ(1, dummy.opacity()); | 319 1, |
302 EXPECT_FALSE(controller->hasActiveAnimation()); | 320 Animation::Opacity)); |
321 to_add->set_needs_synchronized_start_time(true); | |
322 | |
323 // We should pause at the first keyframe indefinitely waiting for that | |
324 // animation to start. | |
325 controller->AddAnimation(to_add.Pass()); | |
326 controller->Animate(0.0); | |
327 controller->UpdateState(events.get()); | |
328 EXPECT_TRUE(controller->HasActiveAnimation()); | |
329 EXPECT_EQ(0, dummy.opacity()); | |
330 controller->Animate(1.0); | |
331 controller->UpdateState(events.get()); | |
332 EXPECT_TRUE(controller->HasActiveAnimation()); | |
333 EXPECT_EQ(0, dummy.opacity()); | |
334 controller->Animate(2.0); | |
335 controller->UpdateState(events.get()); | |
336 EXPECT_TRUE(controller->HasActiveAnimation()); | |
337 EXPECT_EQ(0, dummy.opacity()); | |
338 | |
339 // Send the synchronized start time. | |
340 controller->OnAnimationStarted(AnimationEvent( | |
341 AnimationEvent::Started, 0, 1, Animation::Opacity, 2)); | |
342 controller->Animate(5.0); | |
343 controller->UpdateState(events.get()); | |
344 EXPECT_EQ(1, dummy.opacity()); | |
345 EXPECT_FALSE(controller->HasActiveAnimation()); | |
303 } | 346 } |
304 | 347 |
305 // Tests that two queued animations affecting the same property run in sequence. | 348 // Tests that two queued animations affecting the same property run in sequence. |
306 TEST(LayerAnimationControllerTest, TrivialQueuing) | 349 TEST(LayerAnimationControllerTest, TrivialQueuing) { |
307 { | 350 scoped_ptr<AnimationEventsVector> events( |
308 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 351 make_scoped_ptr(new AnimationEventsVector)); |
309 FakeLayerAnimationValueObserver dummy; | 352 FakeLayerAnimationValueObserver dummy; |
310 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 353 scoped_refptr<LayerAnimationController> controller( |
311 controller->addObserver(&dummy); | 354 LayerAnimationController::Create(0)); |
312 | 355 controller->AddObserver(&dummy); |
313 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 356 |
314 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 357 controller->AddAnimation(CreateAnimation( |
315 | 358 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
316 controller->animate(0); | 359 1, |
317 controller->updateState(events.get()); | 360 Animation::Opacity)); |
318 EXPECT_TRUE(controller->hasActiveAnimation()); | 361 controller->AddAnimation(CreateAnimation( |
319 EXPECT_EQ(0, dummy.opacity()); | 362 scoped_ptr<AnimationCurve>( |
320 controller->animate(1); | 363 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
321 controller->updateState(events.get()); | 364 2, |
322 EXPECT_TRUE(controller->hasActiveAnimation()); | 365 Animation::Opacity)); |
323 EXPECT_EQ(1, dummy.opacity()); | 366 |
324 controller->animate(2); | 367 controller->Animate(0.0); |
325 controller->updateState(events.get()); | 368 controller->UpdateState(events.get()); |
326 EXPECT_EQ(0.5, dummy.opacity()); | 369 EXPECT_TRUE(controller->HasActiveAnimation()); |
327 EXPECT_FALSE(controller->hasActiveAnimation()); | 370 EXPECT_EQ(0, dummy.opacity()); |
371 controller->Animate(1.0); | |
372 controller->UpdateState(events.get()); | |
373 EXPECT_TRUE(controller->HasActiveAnimation()); | |
374 EXPECT_EQ(1, dummy.opacity()); | |
375 controller->Animate(2.0); | |
376 controller->UpdateState(events.get()); | |
377 EXPECT_EQ(0.5, dummy.opacity()); | |
378 EXPECT_FALSE(controller->HasActiveAnimation()); | |
328 } | 379 } |
329 | 380 |
330 // Tests interrupting a transition with another transition. | 381 // Tests interrupting a transition with another transition. |
331 TEST(LayerAnimationControllerTest, Interrupt) | 382 TEST(LayerAnimationControllerTest, Interrupt) { |
332 { | 383 scoped_ptr<AnimationEventsVector> events( |
333 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 384 make_scoped_ptr(new AnimationEventsVector)); |
334 FakeLayerAnimationValueObserver dummy; | 385 FakeLayerAnimationValueObserver dummy; |
335 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 386 scoped_refptr<LayerAnimationController> controller( |
336 controller->addObserver(&dummy); | 387 LayerAnimationController::Create(0)); |
337 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 388 controller->AddObserver(&dummy); |
338 controller->animate(0); | 389 controller->AddAnimation(CreateAnimation( |
339 controller->updateState(events.get()); | 390 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
340 EXPECT_TRUE(controller->hasActiveAnimation()); | 391 1, |
341 EXPECT_EQ(0, dummy.opacity()); | 392 Animation::Opacity)); |
342 | 393 controller->Animate(0.0); |
343 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 394 controller->UpdateState(events.get()); |
344 toAdd->setRunState(Animation::WaitingForNextTick, 0); | 395 EXPECT_TRUE(controller->HasActiveAnimation()); |
345 controller->addAnimation(toAdd.Pass()); | 396 EXPECT_EQ(0, dummy.opacity()); |
346 | 397 |
347 // Since the animation was in the WaitingForNextTick state, it should start right in | 398 scoped_ptr<Animation> to_add(CreateAnimation( |
348 // this call to animate. | 399 scoped_ptr<AnimationCurve>( |
349 controller->animate(0.5); | 400 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), |
350 controller->updateState(events.get()); | 401 2, |
351 EXPECT_TRUE(controller->hasActiveAnimation()); | 402 Animation::Opacity)); |
352 EXPECT_EQ(1, dummy.opacity()); | 403 to_add->SetRunState(Animation::WaitingForNextTick, 0); |
353 controller->animate(1.5); | 404 controller->AddAnimation(to_add.Pass()); |
354 controller->updateState(events.get()); | 405 |
355 EXPECT_EQ(0.5, dummy.opacity()); | 406 // Since the animation was in the WaitingForNextTick state, it should start |
356 EXPECT_FALSE(controller->hasActiveAnimation()); | 407 // right in this call to animate. |
357 } | 408 controller->Animate(0.5); |
358 | 409 controller->UpdateState(events.get()); |
359 // Tests scheduling two animations to run together when only one property is fre e. | 410 EXPECT_TRUE(controller->HasActiveAnimation()); |
360 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) | 411 EXPECT_EQ(1, dummy.opacity()); |
361 { | 412 controller->Animate(1.5); |
362 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 413 controller->UpdateState(events.get()); |
363 FakeLayerAnimationValueObserver dummy; | 414 EXPECT_EQ(0.5, dummy.opacity()); |
enne (OOO)
2013/03/11 21:17:43
opacity is a float, here and elsewhere in this fil
danakj
2013/03/11 23:14:50
Done.
| |
364 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 415 EXPECT_FALSE(controller->HasActiveAnimation()); |
365 controller->addObserver(&dummy); | 416 } |
366 | 417 |
367 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr ansition(1)).PassAs<AnimationCurve>(), 1, Animation::Transform)); | 418 // Tests scheduling two animations to run together when only one property is |
368 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr ansition(1)).PassAs<AnimationCurve>(), 2, Animation::Transform)); | 419 // free. |
369 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 420 TEST(LayerAnimationControllerTest, ScheduleTogetherWhenAPropertyIsBlocked) { |
370 | 421 scoped_ptr<AnimationEventsVector> events( |
371 controller->animate(0); | 422 make_scoped_ptr(new AnimationEventsVector)); |
372 controller->updateState(events.get()); | 423 FakeLayerAnimationValueObserver dummy; |
373 EXPECT_EQ(0, dummy.opacity()); | 424 scoped_refptr<LayerAnimationController> controller( |
374 EXPECT_TRUE(controller->hasActiveAnimation()); | 425 LayerAnimationController::Create(0)); |
375 controller->animate(1); | 426 controller->AddObserver(&dummy); |
376 controller->updateState(events.get()); | 427 |
377 // Should not have started the float transition yet. | 428 controller->AddAnimation(CreateAnimation( |
378 EXPECT_TRUE(controller->hasActiveAnimation()); | 429 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
379 EXPECT_EQ(0, dummy.opacity()); | 430 1, |
380 // The float animation should have started at time 1 and should be done. | 431 Animation::Transform)); |
381 controller->animate(2); | 432 controller->AddAnimation(CreateAnimation( |
382 controller->updateState(events.get()); | 433 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
383 EXPECT_EQ(1, dummy.opacity()); | 434 2, |
384 EXPECT_FALSE(controller->hasActiveAnimation()); | 435 Animation::Transform)); |
385 } | 436 controller->AddAnimation(CreateAnimation( |
386 | 437 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
387 // Tests scheduling two animations to run together with different lengths and an other | 438 2, |
388 // animation queued to start when the shorter animation finishes (should wait | 439 Animation::Opacity)); |
389 // for both to finish). | 440 |
390 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) | 441 controller->Animate(0.0); |
391 { | 442 controller->UpdateState(events.get()); |
392 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 443 EXPECT_EQ(0, dummy.opacity()); |
393 FakeLayerAnimationValueObserver dummy; | 444 EXPECT_TRUE(controller->HasActiveAnimation()); |
394 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 445 controller->Animate(1.0); |
395 controller->addObserver(&dummy); | 446 controller->UpdateState(events.get()); |
396 | 447 // Should not have started the float transition yet. |
397 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr ansition(2)).PassAs<AnimationCurve>(), 1, Animation::Transform)); | 448 EXPECT_TRUE(controller->HasActiveAnimation()); |
398 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 449 EXPECT_EQ(0, dummy.opacity()); |
399 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 1, 0.5)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 450 // The float animation should have started at time 1 and should be done. |
400 | 451 controller->Animate(2.0); |
401 // Animations with id 1 should both start now. | 452 controller->UpdateState(events.get()); |
402 controller->animate(0); | 453 EXPECT_EQ(1, dummy.opacity()); |
403 controller->updateState(events.get()); | 454 EXPECT_FALSE(controller->HasActiveAnimation()); |
404 EXPECT_TRUE(controller->hasActiveAnimation()); | 455 } |
405 EXPECT_EQ(0, dummy.opacity()); | 456 |
406 // The opacity animation should have finished at time 1, but the group | 457 // Tests scheduling two animations to run together with different lengths and |
407 // of animations with id 1 don't finish until time 2 because of the length | 458 // another animation queued to start when the shorter animation finishes (should |
408 // of the transform animation. | 459 // wait for both to finish). |
409 controller->animate(2); | 460 TEST(LayerAnimationControllerTest, ScheduleTogetherWithAnAnimWaiting) { |
410 controller->updateState(events.get()); | 461 scoped_ptr<AnimationEventsVector> events( |
411 // Should not have started the float transition yet. | 462 make_scoped_ptr(new AnimationEventsVector)); |
412 EXPECT_TRUE(controller->hasActiveAnimation()); | 463 FakeLayerAnimationValueObserver dummy; |
413 EXPECT_EQ(1, dummy.opacity()); | 464 scoped_refptr<LayerAnimationController> controller( |
414 | 465 LayerAnimationController::Create(0)); |
415 // The second opacity animation should start at time 2 and should be done by time 3 | 466 controller->AddObserver(&dummy); |
416 controller->animate(3); | 467 |
417 controller->updateState(events.get()); | 468 controller->AddAnimation(CreateAnimation( |
418 EXPECT_EQ(0.5, dummy.opacity()); | 469 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2)).Pass(), |
419 EXPECT_FALSE(controller->hasActiveAnimation()); | 470 1, |
471 Animation::Transform)); | |
472 controller->AddAnimation(CreateAnimation( | |
473 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), | |
474 1, | |
475 Animation::Opacity)); | |
476 controller->AddAnimation(CreateAnimation( | |
477 scoped_ptr<AnimationCurve>( | |
478 new FakeFloatTransition(1.0, 1.f, 0.5f)).Pass(), | |
479 2, | |
480 Animation::Opacity)); | |
481 | |
482 // Animations with id 1 should both start now. | |
483 controller->Animate(0.0); | |
484 controller->UpdateState(events.get()); | |
485 EXPECT_TRUE(controller->HasActiveAnimation()); | |
486 EXPECT_EQ(0, dummy.opacity()); | |
487 // The opacity animation should have finished at time 1, but the group | |
488 // of animations with id 1 don't finish until time 2 because of the length | |
489 // of the transform animation. | |
490 controller->Animate(2.0); | |
491 controller->UpdateState(events.get()); | |
492 // Should not have started the float transition yet. | |
493 EXPECT_TRUE(controller->HasActiveAnimation()); | |
494 EXPECT_EQ(1, dummy.opacity()); | |
495 | |
496 // The second opacity animation should start at time 2 and should be done by | |
497 // time 3. | |
498 controller->Animate(3.0); | |
499 controller->UpdateState(events.get()); | |
500 EXPECT_EQ(0.5, dummy.opacity()); | |
501 EXPECT_FALSE(controller->HasActiveAnimation()); | |
420 } | 502 } |
421 | 503 |
422 // Tests scheduling an animation to start in the future. | 504 // Tests scheduling an animation to start in the future. |
423 TEST(LayerAnimationControllerTest, ScheduleAnimation) | 505 TEST(LayerAnimationControllerTest, ScheduleAnimation) { |
424 { | 506 scoped_ptr<AnimationEventsVector> events( |
425 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 507 make_scoped_ptr(new AnimationEventsVector)); |
426 FakeLayerAnimationValueObserver dummy; | 508 FakeLayerAnimationValueObserver dummy; |
427 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 509 scoped_refptr<LayerAnimationController> controller( |
428 controller->addObserver(&dummy); | 510 LayerAnimationController::Create(0)); |
429 | 511 controller->AddObserver(&dummy); |
430 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 512 |
431 toAdd->setRunState(Animation::WaitingForStartTime, 0); | 513 scoped_ptr<Animation> to_add(CreateAnimation( |
432 toAdd->setStartTime(1); | 514 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
433 controller->addAnimation(toAdd.Pass()); | 515 1, |
434 | 516 Animation::Opacity)); |
435 controller->animate(0); | 517 to_add->SetRunState(Animation::WaitingForStartTime, 0); |
436 controller->updateState(events.get()); | 518 to_add->set_start_time(1.f); |
437 EXPECT_TRUE(controller->hasActiveAnimation()); | 519 controller->AddAnimation(to_add.Pass()); |
438 EXPECT_EQ(0, dummy.opacity()); | 520 |
439 controller->animate(1); | 521 controller->Animate(0.0); |
440 controller->updateState(events.get()); | 522 controller->UpdateState(events.get()); |
441 EXPECT_TRUE(controller->hasActiveAnimation()); | 523 EXPECT_TRUE(controller->HasActiveAnimation()); |
442 EXPECT_EQ(0, dummy.opacity()); | 524 EXPECT_EQ(0, dummy.opacity()); |
443 controller->animate(2); | 525 controller->Animate(1.0); |
444 controller->updateState(events.get()); | 526 controller->UpdateState(events.get()); |
445 EXPECT_EQ(1, dummy.opacity()); | 527 EXPECT_TRUE(controller->HasActiveAnimation()); |
446 EXPECT_FALSE(controller->hasActiveAnimation()); | 528 EXPECT_EQ(0, dummy.opacity()); |
447 } | 529 controller->Animate(2.0); |
448 | 530 controller->UpdateState(events.get()); |
449 // Tests scheduling an animation to start in the future that's interrupting a ru nning animation. | 531 EXPECT_EQ(1, dummy.opacity()); |
450 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimation) | 532 EXPECT_FALSE(controller->HasActiveAnimation()); |
451 { | 533 } |
452 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 534 |
453 FakeLayerAnimationValueObserver dummy; | 535 // Tests scheduling an animation to start in the future that's interrupting a |
454 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 536 // running animation. |
455 controller->addObserver(&dummy); | 537 TEST(LayerAnimationControllerTest, |
456 | 538 ScheduledAnimationInterruptsRunningAnimation) { |
457 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(2, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 539 scoped_ptr<AnimationEventsVector> events( |
458 | 540 make_scoped_ptr(new AnimationEventsVector)); |
459 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0.5, 0)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 541 FakeLayerAnimationValueObserver dummy; |
460 toAdd->setRunState(Animation::WaitingForStartTime, 0); | 542 scoped_refptr<LayerAnimationController> controller( |
461 toAdd->setStartTime(1); | 543 LayerAnimationController::Create(0)); |
462 controller->addAnimation(toAdd.Pass()); | 544 controller->AddObserver(&dummy); |
463 | 545 |
464 // First 2s opacity transition should start immediately. | 546 controller->AddAnimation(CreateAnimation( |
465 controller->animate(0); | 547 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
466 controller->updateState(events.get()); | 548 1, |
467 EXPECT_TRUE(controller->hasActiveAnimation()); | 549 Animation::Opacity)); |
468 EXPECT_EQ(0, dummy.opacity()); | 550 |
469 controller->animate(0.5); | 551 scoped_ptr<Animation> to_add(CreateAnimation( |
470 controller->updateState(events.get()); | 552 scoped_ptr<AnimationCurve>( |
471 EXPECT_TRUE(controller->hasActiveAnimation()); | 553 new FakeFloatTransition(1.0, 0.5f, 0.f)).Pass(), |
472 EXPECT_EQ(0.25, dummy.opacity()); | 554 2, |
473 controller->animate(1); | 555 Animation::Opacity)); |
474 controller->updateState(events.get()); | 556 to_add->SetRunState(Animation::WaitingForStartTime, 0); |
475 EXPECT_TRUE(controller->hasActiveAnimation()); | 557 to_add->set_start_time(1.f); |
476 EXPECT_EQ(0.5, dummy.opacity()); | 558 controller->AddAnimation(to_add.Pass()); |
477 controller->animate(2); | 559 |
478 controller->updateState(events.get()); | 560 // First 2s opacity transition should start immediately. |
479 EXPECT_EQ(0, dummy.opacity()); | 561 controller->Animate(0.0); |
480 EXPECT_FALSE(controller->hasActiveAnimation()); | 562 controller->UpdateState(events.get()); |
481 } | 563 EXPECT_TRUE(controller->HasActiveAnimation()); |
482 | 564 EXPECT_EQ(0, dummy.opacity()); |
483 // Tests scheduling an animation to start in the future that interrupts a runnin g animation | 565 controller->Animate(0.5); |
484 // and there is yet another animation queued to start later. | 566 controller->UpdateState(events.get()); |
485 TEST(LayerAnimationControllerTest, ScheduledAnimationInterruptsRunningAnimationW ithAnimInQueue) | 567 EXPECT_TRUE(controller->HasActiveAnimation()); |
486 { | 568 EXPECT_EQ(0.25, dummy.opacity()); |
487 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 569 controller->Animate(1.0); |
488 FakeLayerAnimationValueObserver dummy; | 570 controller->UpdateState(events.get()); |
489 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 571 EXPECT_TRUE(controller->HasActiveAnimation()); |
490 controller->addObserver(&dummy); | 572 EXPECT_EQ(0.5, dummy.opacity()); |
491 | 573 controller->Animate(2.0); |
492 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(2, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 574 controller->UpdateState(events.get()); |
493 | 575 EXPECT_EQ(0, dummy.opacity()); |
494 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(2, 0.5, 0)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 576 EXPECT_FALSE(controller->HasActiveAnimation()); |
495 toAdd->setRunState(Animation::WaitingForStartTime, 0); | 577 } |
496 toAdd->setStartTime(1); | 578 |
497 controller->addAnimation(toAdd.Pass()); | 579 // Tests scheduling an animation to start in the future that interrupts a |
498 | 580 // running animation and there is yet another animation queued to start later. |
499 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 0.75)).PassAs<AnimationCurve>(), 3, Animation::Opacity)); | 581 TEST(LayerAnimationControllerTest, |
500 | 582 ScheduledAnimationInterruptsRunningAnimationWithAnimInQueue) { |
501 // First 2s opacity transition should start immediately. | 583 scoped_ptr<AnimationEventsVector> events( |
502 controller->animate(0); | 584 make_scoped_ptr(new AnimationEventsVector)); |
503 controller->updateState(events.get()); | 585 FakeLayerAnimationValueObserver dummy; |
504 EXPECT_TRUE(controller->hasActiveAnimation()); | 586 scoped_refptr<LayerAnimationController> controller( |
505 EXPECT_EQ(0, dummy.opacity()); | 587 LayerAnimationController::Create(0)); |
506 controller->animate(0.5); | 588 controller->AddObserver(&dummy); |
507 controller->updateState(events.get()); | 589 |
508 EXPECT_TRUE(controller->hasActiveAnimation()); | 590 controller->AddAnimation(CreateAnimation( |
509 EXPECT_EQ(0.25, dummy.opacity()); | 591 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
510 EXPECT_TRUE(controller->hasActiveAnimation()); | 592 1, |
511 controller->animate(1); | 593 Animation::Opacity)); |
512 controller->updateState(events.get()); | 594 |
513 EXPECT_TRUE(controller->hasActiveAnimation()); | 595 scoped_ptr<Animation> to_add(CreateAnimation( |
514 EXPECT_EQ(0.5, dummy.opacity()); | 596 scoped_ptr<AnimationCurve>( |
515 controller->animate(3); | 597 new FakeFloatTransition(2.0, 0.5f, 0.f)).Pass(), |
516 controller->updateState(events.get()); | 598 2, |
517 EXPECT_TRUE(controller->hasActiveAnimation()); | 599 Animation::Opacity)); |
518 EXPECT_EQ(0, dummy.opacity()); | 600 to_add->SetRunState(Animation::WaitingForStartTime, 0); |
519 controller->animate(4); | 601 to_add->set_start_time(1.f); |
520 controller->updateState(events.get()); | 602 controller->AddAnimation(to_add.Pass()); |
521 EXPECT_EQ(0.75, dummy.opacity()); | 603 |
522 EXPECT_FALSE(controller->hasActiveAnimation()); | 604 controller->AddAnimation(CreateAnimation( |
605 scoped_ptr<AnimationCurve>( | |
606 new FakeFloatTransition(1.0, 0.f, 0.75f)).Pass(), | |
607 3, | |
608 Animation::Opacity)); | |
609 | |
610 // First 2s opacity transition should start immediately. | |
611 controller->Animate(0.0); | |
612 controller->UpdateState(events.get()); | |
613 EXPECT_TRUE(controller->HasActiveAnimation()); | |
614 EXPECT_EQ(0, dummy.opacity()); | |
615 controller->Animate(0.5); | |
616 controller->UpdateState(events.get()); | |
617 EXPECT_TRUE(controller->HasActiveAnimation()); | |
618 EXPECT_EQ(0.25, dummy.opacity()); | |
619 EXPECT_TRUE(controller->HasActiveAnimation()); | |
620 controller->Animate(1.0); | |
621 controller->UpdateState(events.get()); | |
622 EXPECT_TRUE(controller->HasActiveAnimation()); | |
623 EXPECT_EQ(0.5, dummy.opacity()); | |
624 controller->Animate(3.0); | |
625 controller->UpdateState(events.get()); | |
626 EXPECT_TRUE(controller->HasActiveAnimation()); | |
627 EXPECT_EQ(0, dummy.opacity()); | |
628 controller->Animate(4.0); | |
629 controller->UpdateState(events.get()); | |
630 EXPECT_EQ(0.75, dummy.opacity()); | |
631 EXPECT_FALSE(controller->HasActiveAnimation()); | |
523 } | 632 } |
524 | 633 |
525 // Test that a looping animation loops and for the correct number of iterations. | 634 // Test that a looping animation loops and for the correct number of iterations. |
526 TEST(LayerAnimationControllerTest, TrivialLooping) | 635 TEST(LayerAnimationControllerTest, TrivialLooping) { |
527 { | 636 scoped_ptr<AnimationEventsVector> events( |
528 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 637 make_scoped_ptr(new AnimationEventsVector)); |
529 FakeLayerAnimationValueObserver dummy; | 638 FakeLayerAnimationValueObserver dummy; |
530 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 639 scoped_refptr<LayerAnimationController> controller( |
531 controller->addObserver(&dummy); | 640 LayerAnimationController::Create(0)); |
532 | 641 controller->AddObserver(&dummy); |
533 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), 1, Animation::Opacity)); | 642 |
534 toAdd->setIterations(3); | 643 scoped_ptr<Animation> to_add(CreateAnimation( |
535 controller->addAnimation(toAdd.Pass()); | 644 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
536 | 645 1, |
537 controller->animate(0); | 646 Animation::Opacity)); |
538 controller->updateState(events.get()); | 647 to_add->set_iterations(3); |
539 EXPECT_TRUE(controller->hasActiveAnimation()); | 648 controller->AddAnimation(to_add.Pass()); |
540 EXPECT_EQ(0, dummy.opacity()); | 649 |
541 controller->animate(1.25); | 650 controller->Animate(0.0); |
542 controller->updateState(events.get()); | 651 controller->UpdateState(events.get()); |
543 EXPECT_TRUE(controller->hasActiveAnimation()); | 652 EXPECT_TRUE(controller->HasActiveAnimation()); |
544 EXPECT_EQ(0.25, dummy.opacity()); | 653 EXPECT_EQ(0, dummy.opacity()); |
545 controller->animate(1.75); | 654 controller->Animate(1.25); |
546 controller->updateState(events.get()); | 655 controller->UpdateState(events.get()); |
547 EXPECT_TRUE(controller->hasActiveAnimation()); | 656 EXPECT_TRUE(controller->HasActiveAnimation()); |
548 EXPECT_EQ(0.75, dummy.opacity()); | 657 EXPECT_EQ(0.25, dummy.opacity()); |
549 controller->animate(2.25); | 658 controller->Animate(1.75); |
550 controller->updateState(events.get()); | 659 controller->UpdateState(events.get()); |
551 EXPECT_TRUE(controller->hasActiveAnimation()); | 660 EXPECT_TRUE(controller->HasActiveAnimation()); |
552 EXPECT_EQ(0.25, dummy.opacity()); | 661 EXPECT_EQ(0.75, dummy.opacity()); |
553 controller->animate(2.75); | 662 controller->Animate(2.25); |
554 controller->updateState(events.get()); | 663 controller->UpdateState(events.get()); |
555 EXPECT_TRUE(controller->hasActiveAnimation()); | 664 EXPECT_TRUE(controller->HasActiveAnimation()); |
556 EXPECT_EQ(0.75, dummy.opacity()); | 665 EXPECT_EQ(0.25, dummy.opacity()); |
557 controller->animate(3); | 666 controller->Animate(2.75); |
558 controller->updateState(events.get()); | 667 controller->UpdateState(events.get()); |
559 EXPECT_FALSE(controller->hasActiveAnimation()); | 668 EXPECT_TRUE(controller->HasActiveAnimation()); |
560 EXPECT_EQ(1, dummy.opacity()); | 669 EXPECT_EQ(0.75, dummy.opacity()); |
561 | 670 controller->Animate(3.0); |
562 // Just be extra sure. | 671 controller->UpdateState(events.get()); |
563 controller->animate(4); | 672 EXPECT_FALSE(controller->HasActiveAnimation()); |
564 controller->updateState(events.get()); | 673 EXPECT_EQ(1, dummy.opacity()); |
565 EXPECT_EQ(1, dummy.opacity()); | 674 |
675 // Just be extra sure. | |
676 controller->Animate(4.0); | |
677 controller->UpdateState(events.get()); | |
678 EXPECT_EQ(1, dummy.opacity()); | |
566 } | 679 } |
567 | 680 |
568 // Test that an infinitely looping animation does indeed go until aborted. | 681 // Test that an infinitely looping animation does indeed go until aborted. |
569 TEST(LayerAnimationControllerTest, InfiniteLooping) | 682 TEST(LayerAnimationControllerTest, InfiniteLooping) { |
570 { | 683 scoped_ptr<AnimationEventsVector> events( |
571 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 684 make_scoped_ptr(new AnimationEventsVector)); |
572 FakeLayerAnimationValueObserver dummy; | 685 FakeLayerAnimationValueObserver dummy; |
573 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 686 scoped_refptr<LayerAnimationController> controller( |
574 controller->addObserver(&dummy); | 687 LayerAnimationController::Create(0)); |
575 | 688 controller->AddObserver(&dummy); |
576 const int id = 1; | 689 |
577 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(1, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); | 690 const int id = 1; |
578 toAdd->setIterations(-1); | 691 scoped_ptr<Animation> to_add(CreateAnimation( |
579 controller->addAnimation(toAdd.Pass()); | 692 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
580 | 693 id, |
581 controller->animate(0); | 694 Animation::Opacity)); |
582 controller->updateState(events.get()); | 695 to_add->set_iterations(-1); |
583 EXPECT_TRUE(controller->hasActiveAnimation()); | 696 controller->AddAnimation(to_add.Pass()); |
584 EXPECT_EQ(0, dummy.opacity()); | 697 |
585 controller->animate(1.25); | 698 controller->Animate(0.0); |
586 controller->updateState(events.get()); | 699 controller->UpdateState(events.get()); |
587 EXPECT_TRUE(controller->hasActiveAnimation()); | 700 EXPECT_TRUE(controller->HasActiveAnimation()); |
588 EXPECT_EQ(0.25, dummy.opacity()); | 701 EXPECT_EQ(0, dummy.opacity()); |
589 controller->animate(1.75); | 702 controller->Animate(1.25); |
590 controller->updateState(events.get()); | 703 controller->UpdateState(events.get()); |
591 EXPECT_TRUE(controller->hasActiveAnimation()); | 704 EXPECT_TRUE(controller->HasActiveAnimation()); |
592 EXPECT_EQ(0.75, dummy.opacity()); | 705 EXPECT_EQ(0.25, dummy.opacity()); |
593 | 706 controller->Animate(1.75); |
594 controller->animate(1073741824.25); | 707 controller->UpdateState(events.get()); |
595 controller->updateState(events.get()); | 708 EXPECT_TRUE(controller->HasActiveAnimation()); |
596 EXPECT_TRUE(controller->hasActiveAnimation()); | 709 EXPECT_EQ(0.75, dummy.opacity()); |
597 EXPECT_EQ(0.25, dummy.opacity()); | 710 |
598 controller->animate(1073741824.75); | 711 controller->Animate(1073741824.25); |
599 controller->updateState(events.get()); | 712 controller->UpdateState(events.get()); |
600 EXPECT_TRUE(controller->hasActiveAnimation()); | 713 EXPECT_TRUE(controller->HasActiveAnimation()); |
601 EXPECT_EQ(0.75, dummy.opacity()); | 714 EXPECT_EQ(0.25, dummy.opacity()); |
602 | 715 controller->Animate(1073741824.75); |
603 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); | 716 controller->UpdateState(events.get()); |
604 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Abo rted, 0.75); | 717 EXPECT_TRUE(controller->HasActiveAnimation()); |
605 EXPECT_FALSE(controller->hasActiveAnimation()); | 718 EXPECT_EQ(0.75, dummy.opacity()); |
606 EXPECT_EQ(0.75, dummy.opacity()); | 719 |
720 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); | |
721 controller->GetAnimation(id, Animation::Opacity)->SetRunState( | |
722 Animation::Aborted, 0.75); | |
723 EXPECT_FALSE(controller->HasActiveAnimation()); | |
724 EXPECT_EQ(0.75, dummy.opacity()); | |
607 } | 725 } |
608 | 726 |
609 // Test that pausing and resuming work as expected. | 727 // Test that pausing and resuming work as expected. |
610 TEST(LayerAnimationControllerTest, PauseResume) | 728 TEST(LayerAnimationControllerTest, PauseResume) { |
611 { | 729 scoped_ptr<AnimationEventsVector> events( |
612 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 730 make_scoped_ptr(new AnimationEventsVector)); |
613 FakeLayerAnimationValueObserver dummy; | 731 FakeLayerAnimationValueObserver dummy; |
614 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 732 scoped_refptr<LayerAnimationController> controller( |
615 controller->addObserver(&dummy); | 733 LayerAnimationController::Create(0)); |
616 | 734 controller->AddObserver(&dummy); |
617 const int id = 1; | 735 |
618 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); | 736 const int id = 1; |
619 | 737 controller->AddAnimation(CreateAnimation( |
620 controller->animate(0); | 738 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
621 controller->updateState(events.get()); | 739 id, |
622 EXPECT_TRUE(controller->hasActiveAnimation()); | 740 Animation::Opacity)); |
623 EXPECT_EQ(0, dummy.opacity()); | 741 |
624 controller->animate(0.5); | 742 controller->Animate(0.0); |
625 controller->updateState(events.get()); | 743 controller->UpdateState(events.get()); |
626 EXPECT_TRUE(controller->hasActiveAnimation()); | 744 EXPECT_TRUE(controller->HasActiveAnimation()); |
627 EXPECT_EQ(0.5, dummy.opacity()); | 745 EXPECT_EQ(0, dummy.opacity()); |
628 | 746 controller->Animate(0.5); |
629 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); | 747 controller->UpdateState(events.get()); |
630 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Pau sed, 0.5); | 748 EXPECT_TRUE(controller->HasActiveAnimation()); |
631 | 749 EXPECT_EQ(0.5, dummy.opacity()); |
632 controller->animate(1024); | 750 |
633 controller->updateState(events.get()); | 751 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
634 EXPECT_TRUE(controller->hasActiveAnimation()); | 752 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
635 EXPECT_EQ(0.5, dummy.opacity()); | 753 Animation::Paused, 0.5); |
636 | 754 |
637 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); | 755 controller->Animate(1024); |
638 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Run ning, 1024); | 756 controller->UpdateState(events.get()); |
639 | 757 EXPECT_TRUE(controller->HasActiveAnimation()); |
640 controller->animate(1024.25); | 758 EXPECT_EQ(0.5, dummy.opacity()); |
641 controller->updateState(events.get()); | 759 |
642 EXPECT_TRUE(controller->hasActiveAnimation()); | 760 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
643 EXPECT_EQ(0.75, dummy.opacity()); | 761 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
644 controller->animate(1024.5); | 762 Animation::Running, 1024); |
645 controller->updateState(events.get()); | 763 |
646 EXPECT_FALSE(controller->hasActiveAnimation()); | 764 controller->Animate(1024.25); |
647 EXPECT_EQ(1, dummy.opacity()); | 765 controller->UpdateState(events.get()); |
648 } | 766 EXPECT_TRUE(controller->HasActiveAnimation()); |
649 | 767 EXPECT_EQ(0.75, dummy.opacity()); |
650 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) | 768 controller->Animate(1024.5); |
651 { | 769 controller->UpdateState(events.get()); |
652 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 770 EXPECT_FALSE(controller->HasActiveAnimation()); |
653 FakeLayerAnimationValueObserver dummy; | 771 EXPECT_EQ(1, dummy.opacity()); |
654 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 772 } |
655 controller->addObserver(&dummy); | 773 |
656 | 774 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { |
657 const int id = 1; | 775 scoped_ptr<AnimationEventsVector> events( |
658 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr ansition(1)).PassAs<AnimationCurve>(), id, Animation::Transform)); | 776 make_scoped_ptr(new AnimationEventsVector)); |
659 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(2, 0, 1)).PassAs<AnimationCurve>(), id, Animation::Opacity)); | 777 FakeLayerAnimationValueObserver dummy; |
660 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 1, 0.75)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 778 scoped_refptr<LayerAnimationController> controller( |
661 | 779 LayerAnimationController::Create(0)); |
662 controller->animate(0); | 780 controller->AddObserver(&dummy); |
663 controller->updateState(events.get()); | 781 |
664 EXPECT_TRUE(controller->hasActiveAnimation()); | 782 const int id = 1; |
665 EXPECT_EQ(0, dummy.opacity()); | 783 controller->AddAnimation(CreateAnimation( |
666 controller->animate(1); | 784 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
667 controller->updateState(events.get()); | 785 id, |
668 EXPECT_TRUE(controller->hasActiveAnimation()); | 786 Animation::Transform)); |
669 EXPECT_EQ(0.5, dummy.opacity()); | 787 controller->AddAnimation(CreateAnimation( |
670 | 788 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), |
671 EXPECT_TRUE(controller->getAnimation(id, Animation::Opacity)); | 789 id, |
672 controller->getAnimation(id, Animation::Opacity)->setRunState(Animation::Abo rted, 1); | 790 Animation::Opacity)); |
673 controller->animate(1); | 791 controller->AddAnimation(CreateAnimation( |
674 controller->updateState(events.get()); | 792 scoped_ptr<AnimationCurve>( |
675 EXPECT_TRUE(controller->hasActiveAnimation()); | 793 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), |
676 EXPECT_EQ(1, dummy.opacity()); | 794 2, |
677 controller->animate(2); | 795 Animation::Opacity)); |
678 controller->updateState(events.get()); | 796 |
679 EXPECT_TRUE(!controller->hasActiveAnimation()); | 797 controller->Animate(0.0); |
680 EXPECT_EQ(0.75, dummy.opacity()); | 798 controller->UpdateState(events.get()); |
681 } | 799 EXPECT_TRUE(controller->HasActiveAnimation()); |
682 | 800 EXPECT_EQ(0, dummy.opacity()); |
683 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) | 801 controller->Animate(1.0); |
684 { | 802 controller->UpdateState(events.get()); |
685 FakeLayerAnimationValueObserver dummyImpl; | 803 EXPECT_TRUE(controller->HasActiveAnimation()); |
686 scoped_refptr<LayerAnimationController> controllerImpl(LayerAnimationControl ler::create(0)); | 804 EXPECT_EQ(0.5, dummy.opacity()); |
687 controllerImpl->addObserver(&dummyImpl); | 805 |
688 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 806 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); |
689 FakeLayerAnimationValueObserver dummy; | 807 controller->GetAnimation(id, Animation::Opacity)->SetRunState( |
690 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 808 Animation::Aborted, 1); |
691 controller->addObserver(&dummy); | 809 controller->Animate(1.0); |
692 | 810 controller->UpdateState(events.get()); |
693 scoped_ptr<Animation> toAdd(createAnimation(make_scoped_ptr(new FakeFloatTra nsition(2, 0, 1)).PassAs<AnimationCurve>(), 0, Animation::Opacity)); | 811 EXPECT_TRUE(controller->HasActiveAnimation()); |
694 toAdd->setNeedsSynchronizedStartTime(true); | 812 EXPECT_EQ(1, dummy.opacity()); |
695 controller->addAnimation(toAdd.Pass()); | 813 controller->Animate(2.0); |
696 | 814 controller->UpdateState(events.get()); |
697 controller->animate(0); | 815 EXPECT_TRUE(!controller->HasActiveAnimation()); |
698 controller->updateState(events.get()); | 816 EXPECT_EQ(0.75, dummy.opacity()); |
699 EXPECT_TRUE(controller->hasActiveAnimation()); | 817 } |
700 Animation* activeAnimation = controller->getAnimation(0, Animation::Opacity) ; | 818 |
701 EXPECT_TRUE(activeAnimation); | 819 TEST(LayerAnimationControllerTest, ForceSyncWhenSynchronizedStartTimeNeeded) { |
702 EXPECT_TRUE(activeAnimation->needsSynchronizedStartTime()); | 820 FakeLayerAnimationValueObserver dummy_impl; |
703 | 821 scoped_refptr<LayerAnimationController> controller_impl( |
704 controller->setForceSync(); | 822 LayerAnimationController::Create(0)); |
705 | 823 controller_impl->AddObserver(&dummy_impl); |
706 controller->pushAnimationUpdatesTo(controllerImpl.get()); | 824 scoped_ptr<AnimationEventsVector> events( |
707 | 825 make_scoped_ptr(new AnimationEventsVector)); |
708 activeAnimation = controllerImpl->getAnimation(0, Animation::Opacity); | 826 FakeLayerAnimationValueObserver dummy; |
709 EXPECT_TRUE(activeAnimation); | 827 scoped_refptr<LayerAnimationController> controller( |
710 EXPECT_EQ(Animation::WaitingForTargetAvailability, activeAnimation->runState ()); | 828 LayerAnimationController::Create(0)); |
829 controller->AddObserver(&dummy); | |
830 | |
831 scoped_ptr<Animation> to_add(CreateAnimation( | |
832 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), | |
833 0, | |
834 Animation::Opacity)); | |
835 to_add->set_needs_synchronized_start_time(true); | |
836 controller->AddAnimation(to_add.Pass()); | |
837 | |
838 controller->Animate(0.0); | |
839 controller->UpdateState(events.get()); | |
840 EXPECT_TRUE(controller->HasActiveAnimation()); | |
841 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); | |
842 EXPECT_TRUE(active_animation); | |
843 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); | |
844 | |
845 controller->set_force_sync(); | |
846 | |
847 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
848 | |
849 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); | |
850 EXPECT_TRUE(active_animation); | |
851 EXPECT_EQ(Animation::WaitingForTargetAvailability, | |
852 active_animation->run_state()); | |
711 } | 853 } |
712 | 854 |
713 // Tests that skipping a call to updateState works as expected. | 855 // Tests that skipping a call to updateState works as expected. |
714 TEST(LayerAnimationControllerTest, SkipUpdateState) | 856 TEST(LayerAnimationControllerTest, SkipUpdateState) { |
715 { | 857 scoped_ptr<AnimationEventsVector> events( |
716 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); | 858 make_scoped_ptr(new AnimationEventsVector)); |
717 FakeLayerAnimationValueObserver dummy; | 859 FakeLayerAnimationValueObserver dummy; |
718 scoped_refptr<LayerAnimationController> controller(LayerAnimationController: :create(0)); | 860 scoped_refptr<LayerAnimationController> controller( |
719 controller->addObserver(&dummy); | 861 LayerAnimationController::Create(0)); |
720 | 862 controller->AddObserver(&dummy); |
721 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeTransformTr ansition(1)).PassAs<AnimationCurve>(), 1, Animation::Transform)); | 863 |
722 | 864 controller->AddAnimation(CreateAnimation( |
723 controller->animate(0); | 865 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), |
724 controller->updateState(events.get()); | 866 1, |
725 | 867 Animation::Transform)); |
726 controller->addAnimation(createAnimation(make_scoped_ptr(new FakeFloatTransi tion(1, 0, 1)).PassAs<AnimationCurve>(), 2, Animation::Opacity)); | 868 |
727 | 869 controller->Animate(0.0); |
728 // Animate but don't updateState. | 870 controller->UpdateState(events.get()); |
729 controller->animate(1); | 871 |
730 | 872 controller->AddAnimation(CreateAnimation( |
731 controller->animate(2); | 873 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), |
732 events.reset(new AnimationEventsVector); | 874 2, |
733 controller->updateState(events.get()); | 875 Animation::Opacity)); |
734 | 876 |
735 // Should have one Started event and one Finished event. | 877 // Animate but don't updateState. |
736 EXPECT_EQ(2, events->size()); | 878 controller->Animate(1.0); |
737 EXPECT_NE((*events)[0].type, (*events)[1].type); | 879 |
738 | 880 controller->Animate(2.0); |
739 // The float transition should still be at its starting point. | 881 events.reset(new AnimationEventsVector); |
740 EXPECT_TRUE(controller->hasActiveAnimation()); | 882 controller->UpdateState(events.get()); |
741 EXPECT_EQ(0, dummy.opacity()); | 883 |
742 | 884 // Should have one Started event and one Finished event. |
743 controller->animate(3); | 885 EXPECT_EQ(2, events->size()); |
744 controller->updateState(events.get()); | 886 EXPECT_NE((*events)[0].type, (*events)[1].type); |
745 | 887 |
746 // The float tranisition should now be done. | 888 // The float transition should still be at its starting point. |
747 EXPECT_EQ(1, dummy.opacity()); | 889 EXPECT_TRUE(controller->HasActiveAnimation()); |
748 EXPECT_FALSE(controller->hasActiveAnimation()); | 890 EXPECT_EQ(0, dummy.opacity()); |
891 | |
892 controller->Animate(3.0); | |
893 controller->UpdateState(events.get()); | |
894 | |
895 // The float tranisition should now be done. | |
896 EXPECT_EQ(1, dummy.opacity()); | |
897 EXPECT_FALSE(controller->HasActiveAnimation()); | |
749 } | 898 } |
750 | 899 |
751 } // namespace | 900 } // namespace |
752 } // namespace cc | 901 } // namespace cc |
OLD | NEW |