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

Side by Side Diff: cc/layer_animation_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698