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

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 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/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/animation_registrar.h" 10 #include "cc/animation/animation_registrar.h"
(...skipping 16 matching lines...) Expand all
27 return base::TimeTicks::FromInternalValue(seconds * 27 return base::TimeTicks::FromInternalValue(seconds *
28 base::Time::kMicrosecondsPerSecond); 28 base::Time::kMicrosecondsPerSecond);
29 } 29 }
30 30
31 // A LayerAnimationController cannot be ticked at 0.0, since an animation 31 // A LayerAnimationController cannot be ticked at 0.0, since an animation
32 // with start time 0.0 is treated as an animation whose start time has 32 // with start time 0.0 is treated as an animation whose start time has
33 // not yet been set. 33 // not yet been set.
34 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0); 34 const TimeTicks kInitialTickTime = TicksFromSecondsF(1.0);
35 35
36 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve, 36 scoped_ptr<Animation> CreateAnimation(scoped_ptr<AnimationCurve> curve,
37 int id, 37 int group_id,
38 Animation::TargetProperty property) { 38 Animation::TargetProperty property) {
39 return Animation::Create(curve.Pass(), 0, id, property); 39 return Animation::Create(curve.Pass(), 0, group_id, property);
40 } 40 }
41 41
42 TEST(LayerAnimationControllerTest, SyncNewAnimation) { 42 TEST(LayerAnimationControllerTest, SyncNewAnimation) {
43 FakeLayerAnimationValueObserver dummy_impl; 43 FakeLayerAnimationValueObserver dummy_impl;
44 scoped_refptr<LayerAnimationController> controller_impl( 44 scoped_refptr<LayerAnimationController> controller_impl(
45 LayerAnimationController::Create(0)); 45 LayerAnimationController::Create(0));
46 controller_impl->AddValueObserver(&dummy_impl); 46 controller_impl->AddValueObserver(&dummy_impl);
47 FakeLayerAnimationValueObserver dummy; 47 FakeLayerAnimationValueObserver dummy;
48 scoped_refptr<LayerAnimationController> controller( 48 scoped_refptr<LayerAnimationController> controller(
49 LayerAnimationController::Create(0)); 49 LayerAnimationController::Create(0));
50 controller->AddValueObserver(&dummy); 50 controller->AddValueObserver(&dummy);
51 51
52 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); 52 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
53 53
54 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 54 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
55 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); 55 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
56 56
57 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 57 int animation_id =
58 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
58 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 59 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
59 int group_id = controller->GetAnimation(Animation::Opacity)->group();
60 60
61 controller->PushAnimationUpdatesTo(controller_impl.get()); 61 controller->PushAnimationUpdatesTo(controller_impl.get());
62 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); 62 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
63 controller_impl->ActivateAnimations(); 63 controller_impl->ActivateAnimations();
64 64
65 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 65 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
66 EXPECT_EQ(Animation::WaitingForTargetAvailability, 66 EXPECT_EQ(Animation::WaitingForTargetAvailability,
67 controller_impl->GetAnimation(group_id, 67 controller_impl->GetAnimationById(animation_id)->run_state());
68 Animation::Opacity)->run_state());
69 } 68 }
70 69
71 // If an animation is started on the impl thread before it is ticked on the main 70 // If an animation is started on the impl thread before it is ticked on the main
72 // thread, we must be sure to respect the synchronized start time. 71 // thread, we must be sure to respect the synchronized start time.
73 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) { 72 TEST(LayerAnimationControllerTest, DoNotClobberStartTimes) {
74 FakeLayerAnimationValueObserver dummy_impl; 73 FakeLayerAnimationValueObserver dummy_impl;
75 scoped_refptr<LayerAnimationController> controller_impl( 74 scoped_refptr<LayerAnimationController> controller_impl(
76 LayerAnimationController::Create(0)); 75 LayerAnimationController::Create(0));
77 controller_impl->AddValueObserver(&dummy_impl); 76 controller_impl->AddValueObserver(&dummy_impl);
78 FakeLayerAnimationValueObserver dummy; 77 FakeLayerAnimationValueObserver dummy;
79 scoped_refptr<LayerAnimationController> controller( 78 scoped_refptr<LayerAnimationController> controller(
80 LayerAnimationController::Create(0)); 79 LayerAnimationController::Create(0));
81 controller->AddValueObserver(&dummy); 80 controller->AddValueObserver(&dummy);
82 81
83 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); 82 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
84 83
85 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 84 int animation_id =
86 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 85 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
87 86
88 controller->PushAnimationUpdatesTo(controller_impl.get()); 87 controller->PushAnimationUpdatesTo(controller_impl.get());
89 controller_impl->ActivateAnimations(); 88 controller_impl->ActivateAnimations();
90 89
91 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 90 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
92 EXPECT_EQ(Animation::WaitingForTargetAvailability, 91 EXPECT_EQ(Animation::WaitingForTargetAvailability,
93 controller_impl->GetAnimation(group_id, 92 controller_impl->GetAnimationById(animation_id)->run_state());
94 Animation::Opacity)->run_state());
95 93
96 AnimationEventsVector events; 94 AnimationEventsVector events;
97 controller_impl->Animate(kInitialTickTime); 95 controller_impl->Animate(kInitialTickTime);
98 controller_impl->UpdateState(true, &events); 96 controller_impl->UpdateState(true, &events);
99 97
100 // Synchronize the start times. 98 // Synchronize the start times.
101 EXPECT_EQ(1u, events.size()); 99 EXPECT_EQ(1u, events.size());
102 controller->NotifyAnimationStarted(events[0]); 100 controller->NotifyAnimationStarted(events[0]);
103 EXPECT_EQ(controller->GetAnimation(group_id, 101 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
104 Animation::Opacity)->start_time(), 102 controller_impl->GetAnimationById(animation_id)->start_time());
105 controller_impl->GetAnimation(group_id,
106 Animation::Opacity)->start_time());
107 103
108 // Start the animation on the main thread. Should not affect the start time. 104 // Start the animation on the main thread. Should not affect the start time.
109 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 105 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
110 controller->UpdateState(true, nullptr); 106 controller->UpdateState(true, nullptr);
111 EXPECT_EQ(controller->GetAnimation(group_id, 107 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
112 Animation::Opacity)->start_time(), 108 controller_impl->GetAnimationById(animation_id)->start_time());
113 controller_impl->GetAnimation(group_id,
114 Animation::Opacity)->start_time());
115 } 109 }
116 110
117 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) { 111 TEST(LayerAnimationControllerTest, UseSpecifiedStartTimes) {
118 FakeLayerAnimationValueObserver dummy_impl; 112 FakeLayerAnimationValueObserver dummy_impl;
119 scoped_refptr<LayerAnimationController> controller_impl( 113 scoped_refptr<LayerAnimationController> controller_impl(
120 LayerAnimationController::Create(0)); 114 LayerAnimationController::Create(0));
121 controller_impl->AddValueObserver(&dummy_impl); 115 controller_impl->AddValueObserver(&dummy_impl);
122 FakeLayerAnimationValueObserver dummy; 116 FakeLayerAnimationValueObserver dummy;
123 scoped_refptr<LayerAnimationController> controller( 117 scoped_refptr<LayerAnimationController> controller(
124 LayerAnimationController::Create(0)); 118 LayerAnimationController::Create(0));
125 controller->AddValueObserver(&dummy); 119 controller->AddValueObserver(&dummy);
126 120
127 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 121 int animation_id =
128 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 122 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
129 123
130 const TimeTicks start_time = TicksFromSecondsF(123); 124 const TimeTicks start_time = TicksFromSecondsF(123);
131 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time); 125 controller->GetAnimation(Animation::Opacity)->set_start_time(start_time);
132 126
133 controller->PushAnimationUpdatesTo(controller_impl.get()); 127 controller->PushAnimationUpdatesTo(controller_impl.get());
134 controller_impl->ActivateAnimations(); 128 controller_impl->ActivateAnimations();
135 129
136 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 130 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
137 EXPECT_EQ(Animation::WaitingForTargetAvailability, 131 EXPECT_EQ(Animation::WaitingForTargetAvailability,
138 controller_impl->GetAnimation(group_id, 132 controller_impl->GetAnimationById(animation_id)->run_state());
139 Animation::Opacity)->run_state());
140 133
141 AnimationEventsVector events; 134 AnimationEventsVector events;
142 controller_impl->Animate(kInitialTickTime); 135 controller_impl->Animate(kInitialTickTime);
143 controller_impl->UpdateState(true, &events); 136 controller_impl->UpdateState(true, &events);
144 137
145 // Synchronize the start times. 138 // Synchronize the start times.
146 EXPECT_EQ(1u, events.size()); 139 EXPECT_EQ(1u, events.size());
147 controller->NotifyAnimationStarted(events[0]); 140 controller->NotifyAnimationStarted(events[0]);
148 141
149 EXPECT_EQ(start_time, 142 EXPECT_EQ(start_time,
150 controller->GetAnimation(group_id, 143 controller->GetAnimationById(animation_id)->start_time());
151 Animation::Opacity)->start_time()); 144 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
152 EXPECT_EQ(controller->GetAnimation(group_id, 145 controller_impl->GetAnimationById(animation_id)->start_time());
153 Animation::Opacity)->start_time(),
154 controller_impl->GetAnimation(group_id,
155 Animation::Opacity)->start_time());
156 146
157 // Start the animation on the main thread. Should not affect the start time. 147 // Start the animation on the main thread. Should not affect the start time.
158 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 148 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
159 controller->UpdateState(true, nullptr); 149 controller->UpdateState(true, nullptr);
160 EXPECT_EQ(start_time, 150 EXPECT_EQ(start_time,
161 controller->GetAnimation(group_id, 151 controller->GetAnimationById(animation_id)->start_time());
162 Animation::Opacity)->start_time()); 152 EXPECT_EQ(controller->GetAnimationById(animation_id)->start_time(),
163 EXPECT_EQ(controller->GetAnimation(group_id, 153 controller_impl->GetAnimationById(animation_id)->start_time());
164 Animation::Opacity)->start_time(),
165 controller_impl->GetAnimation(group_id,
166 Animation::Opacity)->start_time());
167 } 154 }
168 155
169 // Tests that controllers activate and deactivate as expected. 156 // Tests that controllers activate and deactivate as expected.
170 TEST(LayerAnimationControllerTest, Activation) { 157 TEST(LayerAnimationControllerTest, Activation) {
171 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create(); 158 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::Create();
172 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create(); 159 scoped_ptr<AnimationRegistrar> registrar_impl = AnimationRegistrar::Create();
173 160
174 FakeLayerAnimationValueObserver dummy_impl; 161 FakeLayerAnimationValueObserver dummy_impl;
175 scoped_refptr<LayerAnimationController> controller_impl( 162 scoped_refptr<LayerAnimationController> controller_impl(
176 LayerAnimationController::Create(0)); 163 LayerAnimationController::Create(0));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 scoped_refptr<LayerAnimationController> controller_impl( 242 scoped_refptr<LayerAnimationController> controller_impl(
256 LayerAnimationController::Create(0)); 243 LayerAnimationController::Create(0));
257 controller_impl->AddValueObserver(&dummy_impl); 244 controller_impl->AddValueObserver(&dummy_impl);
258 FakeLayerAnimationValueObserver dummy; 245 FakeLayerAnimationValueObserver dummy;
259 scoped_refptr<LayerAnimationController> controller( 246 scoped_refptr<LayerAnimationController> controller(
260 LayerAnimationController::Create(0)); 247 LayerAnimationController::Create(0));
261 controller->AddValueObserver(&dummy); 248 controller->AddValueObserver(&dummy);
262 249
263 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); 250 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
264 251
265 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 252 int animation_id =
266 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 253 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
267 int animation_id = controller->GetAnimation(Animation::Opacity)->id();
268 254
269 controller->PushAnimationUpdatesTo(controller_impl.get()); 255 controller->PushAnimationUpdatesTo(controller_impl.get());
270 controller_impl->ActivateAnimations(); 256 controller_impl->ActivateAnimations();
271 257
272 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 258 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
273 EXPECT_EQ(Animation::WaitingForTargetAvailability, 259 EXPECT_EQ(Animation::WaitingForTargetAvailability,
274 controller_impl->GetAnimation(group_id, 260 controller_impl->GetAnimationById(animation_id)->run_state());
275 Animation::Opacity)->run_state());
276 261
277 // Start the animations on each controller. 262 // Start the animations on each controller.
278 AnimationEventsVector events; 263 AnimationEventsVector events;
279 controller_impl->Animate(kInitialTickTime); 264 controller_impl->Animate(kInitialTickTime);
280 controller_impl->UpdateState(true, &events); 265 controller_impl->UpdateState(true, &events);
281 controller->Animate(kInitialTickTime); 266 controller->Animate(kInitialTickTime);
282 controller->UpdateState(true, nullptr); 267 controller->UpdateState(true, nullptr);
283 EXPECT_EQ(Animation::Running, 268 EXPECT_EQ(Animation::Running,
284 controller_impl->GetAnimation(group_id, 269 controller_impl->GetAnimationById(animation_id)->run_state());
285 Animation::Opacity)->run_state());
286 EXPECT_EQ(Animation::Running, 270 EXPECT_EQ(Animation::Running,
287 controller->GetAnimation(group_id, 271 controller->GetAnimationById(animation_id)->run_state());
288 Animation::Opacity)->run_state());
289 272
290 // Pause the main-thread animation. 273 // Pause the main-thread animation.
291 controller->PauseAnimation( 274 controller->PauseAnimation(
292 animation_id, 275 animation_id,
293 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000)); 276 TimeDelta::FromMilliseconds(1000) + TimeDelta::FromMilliseconds(1000));
294 EXPECT_EQ(Animation::Paused, 277 EXPECT_EQ(Animation::Paused,
295 controller->GetAnimation(group_id, 278 controller->GetAnimationById(animation_id)->run_state());
296 Animation::Opacity)->run_state());
297 279
298 // The pause run state change should make it to the impl thread controller. 280 // The pause run state change should make it to the impl thread controller.
299 controller->PushAnimationUpdatesTo(controller_impl.get()); 281 controller->PushAnimationUpdatesTo(controller_impl.get());
300 controller_impl->ActivateAnimations(); 282 controller_impl->ActivateAnimations();
301 EXPECT_EQ(Animation::Paused, 283 EXPECT_EQ(Animation::Paused,
302 controller_impl->GetAnimation(group_id, 284 controller_impl->GetAnimationById(animation_id)->run_state());
303 Animation::Opacity)->run_state());
304 } 285 }
305 286
306 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) { 287 TEST(LayerAnimationControllerTest, DoNotSyncFinishedAnimation) {
307 FakeLayerAnimationValueObserver dummy_impl; 288 FakeLayerAnimationValueObserver dummy_impl;
308 scoped_refptr<LayerAnimationController> controller_impl( 289 scoped_refptr<LayerAnimationController> controller_impl(
309 LayerAnimationController::Create(0)); 290 LayerAnimationController::Create(0));
310 controller_impl->AddValueObserver(&dummy_impl); 291 controller_impl->AddValueObserver(&dummy_impl);
311 FakeLayerAnimationValueObserver dummy; 292 FakeLayerAnimationValueObserver dummy;
312 scoped_refptr<LayerAnimationController> controller( 293 scoped_refptr<LayerAnimationController> controller(
313 LayerAnimationController::Create(0)); 294 LayerAnimationController::Create(0));
314 controller->AddValueObserver(&dummy); 295 controller->AddValueObserver(&dummy);
315 296
316 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity)); 297 EXPECT_FALSE(controller_impl->GetAnimation(Animation::Opacity));
317 298
318 int animation_id = 299 int animation_id =
319 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false); 300 AddOpacityTransitionToController(controller.get(), 1, 0, 1, false);
320 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 301 int group_id = controller->GetAnimationById(animation_id)->group();
321 302
322 controller->PushAnimationUpdatesTo(controller_impl.get()); 303 controller->PushAnimationUpdatesTo(controller_impl.get());
323 controller_impl->ActivateAnimations(); 304 controller_impl->ActivateAnimations();
324 305
325 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 306 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
326 EXPECT_EQ(Animation::WaitingForTargetAvailability, 307 EXPECT_EQ(Animation::WaitingForTargetAvailability,
327 controller_impl->GetAnimation(group_id, 308 controller_impl->GetAnimationById(animation_id)->run_state());
328 Animation::Opacity)->run_state());
329 309
330 // Notify main thread controller that the animation has started. 310 // Notify main thread controller that the animation has started.
331 AnimationEvent animation_started_event(AnimationEvent::Started, 311 AnimationEvent animation_started_event(AnimationEvent::Started,
332 0, 312 0,
333 group_id, 313 group_id,
334 Animation::Opacity, 314 Animation::Opacity,
335 kInitialTickTime); 315 kInitialTickTime);
336 controller->NotifyAnimationStarted(animation_started_event); 316 controller->NotifyAnimationStarted(animation_started_event);
337 317
338 // Force animation to complete on impl thread. 318 // Force animation to complete on impl thread.
339 controller_impl->RemoveAnimation(animation_id); 319 controller_impl->RemoveAnimation(animation_id);
340 320
341 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 321 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
342 322
343 controller->PushAnimationUpdatesTo(controller_impl.get()); 323 controller->PushAnimationUpdatesTo(controller_impl.get());
344 controller_impl->ActivateAnimations(); 324 controller_impl->ActivateAnimations();
345 325
346 // Even though the main thread has a 'new' animation, it should not be pushed 326 // Even though the main thread has a 'new' animation, it should not be pushed
347 // because the animation has already completed on the impl thread. 327 // because the animation has already completed on the impl thread.
348 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 328 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
349 } 329 }
350 330
351 // Ensure that a finished animation is eventually deleted by both the 331 // Ensure that a finished animation is eventually deleted by both the
352 // main-thread and the impl-thread controllers. 332 // main-thread and the impl-thread controllers.
353 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) { 333 TEST(LayerAnimationControllerTest, AnimationsAreDeleted) {
354 FakeLayerAnimationValueObserver dummy; 334 FakeLayerAnimationValueObserver dummy;
355 FakeLayerAnimationValueObserver dummy_impl; 335 FakeLayerAnimationValueObserver dummy_impl;
356 scoped_ptr<AnimationEventsVector> events( 336 scoped_ptr<AnimationEventsVector> events(
357 make_scoped_ptr(new AnimationEventsVector)); 337 make_scoped_ptr(new AnimationEventsVector));
358 scoped_refptr<LayerAnimationController> controller( 338 scoped_refptr<LayerAnimationController> controller(
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 EXPECT_FALSE(event); 826 EXPECT_FALSE(event);
847 827
848 controller_impl->Animate(kInitialTickTime + duration); 828 controller_impl->Animate(kInitialTickTime + duration);
849 controller_impl->UpdateState(true, events.get()); 829 controller_impl->UpdateState(true, events.get());
850 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); 830 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset());
851 EXPECT_FALSE(controller_impl->HasActiveAnimation()); 831 EXPECT_FALSE(controller_impl->HasActiveAnimation());
852 event = GetMostRecentPropertyUpdateEvent(events.get()); 832 event = GetMostRecentPropertyUpdateEvent(events.get());
853 EXPECT_FALSE(event); 833 EXPECT_FALSE(event);
854 } 834 }
855 835
836 TEST(LayerAnimationControllerTest, ScrollOffsetRemovalNotifiesObserver) {
837 FakeLayerAnimationValueObserver dummy;
838 scoped_refptr<LayerAnimationController> controller(
839 LayerAnimationController::Create(0));
840 controller->AddValueObserver(&dummy);
841
842 // First test the 1-argument version of RemoveAnimation.
843 gfx::ScrollOffset target_value(300.f, 200.f);
844 scoped_ptr<ScrollOffsetAnimationCurve> curve(
845 ScrollOffsetAnimationCurve::Create(
846 target_value, EaseInOutTimingFunction::Create().Pass()));
847
848 int animation_id = 1;
849 scoped_ptr<Animation> animation(Animation::Create(
850 curve.Pass(), animation_id, 0, Animation::ScrollOffset));
851 controller->AddAnimation(animation.Pass());
852
853 controller->RemoveAnimation(animation_id);
854 EXPECT_TRUE(dummy.scroll_offset_animation_removed());
855
856 // Now, test the 2-argument version of RemoveAnimation.
857 dummy.reset_scroll_offset_animation_removed();
858 curve = ScrollOffsetAnimationCurve::Create(
859 target_value, EaseInOutTimingFunction::Create().Pass());
860 animation =
861 Animation::Create(curve.Pass(), animation_id, 0, Animation::ScrollOffset);
862 controller->AddAnimation(animation.Pass());
863
864 controller->RemoveAnimation(animation_id, Animation::ScrollOffset);
865 EXPECT_TRUE(dummy.scroll_offset_animation_removed());
866
867 // Check that removing non-scroll-offset animations does not cause the
868 // observer to get notified.
869 dummy.reset_scroll_offset_animation_removed();
870 animation_id = AddAnimatedTransformToController(controller.get(), 1.0, 1, 2);
871 controller->RemoveAnimation(animation_id);
872 EXPECT_FALSE(dummy.scroll_offset_animation_removed());
873
874 dummy.reset_scroll_offset_animation_removed();
875 animation_id =
876 AddAnimatedFilterToController(controller.get(), 1.0, 0.1f, 0.2f);
877 controller->RemoveAnimation(animation_id, Animation::Filter);
878 EXPECT_FALSE(dummy.scroll_offset_animation_removed());
879 }
880
856 class FakeAnimationDelegate : public AnimationDelegate { 881 class FakeAnimationDelegate : public AnimationDelegate {
857 public: 882 public:
858 FakeAnimationDelegate() 883 FakeAnimationDelegate()
859 : started_(false), 884 : started_(false),
860 finished_(false) {} 885 finished_(false) {}
861 886
862 void NotifyAnimationStarted(TimeTicks monotonic_time, 887 void NotifyAnimationStarted(TimeTicks monotonic_time,
863 Animation::TargetProperty target_property, 888 Animation::TargetProperty target_property,
864 int group) override { 889 int group) override {
865 started_ = true; 890 started_ = true;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1206
1182 // Test that an infinitely looping animation does indeed go until aborted. 1207 // Test that an infinitely looping animation does indeed go until aborted.
1183 TEST(LayerAnimationControllerTest, InfiniteLooping) { 1208 TEST(LayerAnimationControllerTest, InfiniteLooping) {
1184 scoped_ptr<AnimationEventsVector> events( 1209 scoped_ptr<AnimationEventsVector> events(
1185 make_scoped_ptr(new AnimationEventsVector)); 1210 make_scoped_ptr(new AnimationEventsVector));
1186 FakeLayerAnimationValueObserver dummy; 1211 FakeLayerAnimationValueObserver dummy;
1187 scoped_refptr<LayerAnimationController> controller( 1212 scoped_refptr<LayerAnimationController> controller(
1188 LayerAnimationController::Create(0)); 1213 LayerAnimationController::Create(0));
1189 controller->AddValueObserver(&dummy); 1214 controller->AddValueObserver(&dummy);
1190 1215
1191 const int id = 1;
1192 scoped_ptr<Animation> to_add(CreateAnimation( 1216 scoped_ptr<Animation> to_add(CreateAnimation(
1193 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 1217 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1194 id, 1218 1, Animation::Opacity));
1195 Animation::Opacity));
1196 to_add->set_iterations(-1); 1219 to_add->set_iterations(-1);
1197 controller->AddAnimation(to_add.Pass()); 1220 controller->AddAnimation(to_add.Pass());
1198 1221
1199 controller->Animate(kInitialTickTime); 1222 controller->Animate(kInitialTickTime);
1200 controller->UpdateState(true, events.get()); 1223 controller->UpdateState(true, events.get());
1201 EXPECT_TRUE(controller->HasActiveAnimation()); 1224 EXPECT_TRUE(controller->HasActiveAnimation());
1202 EXPECT_EQ(0.f, dummy.opacity()); 1225 EXPECT_EQ(0.f, dummy.opacity());
1203 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250)); 1226 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
1204 controller->UpdateState(true, events.get()); 1227 controller->UpdateState(true, events.get());
1205 EXPECT_TRUE(controller->HasActiveAnimation()); 1228 EXPECT_TRUE(controller->HasActiveAnimation());
1206 EXPECT_EQ(0.25f, dummy.opacity()); 1229 EXPECT_EQ(0.25f, dummy.opacity());
1207 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750)); 1230 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
1208 controller->UpdateState(true, events.get()); 1231 controller->UpdateState(true, events.get());
1209 EXPECT_TRUE(controller->HasActiveAnimation()); 1232 EXPECT_TRUE(controller->HasActiveAnimation());
1210 EXPECT_EQ(0.75f, dummy.opacity()); 1233 EXPECT_EQ(0.75f, dummy.opacity());
1211 1234
1212 controller->Animate(kInitialTickTime + 1235 controller->Animate(kInitialTickTime +
1213 TimeDelta::FromMilliseconds(1073741824250)); 1236 TimeDelta::FromMilliseconds(1073741824250));
1214 controller->UpdateState(true, events.get()); 1237 controller->UpdateState(true, events.get());
1215 EXPECT_TRUE(controller->HasActiveAnimation()); 1238 EXPECT_TRUE(controller->HasActiveAnimation());
1216 EXPECT_EQ(0.25f, dummy.opacity()); 1239 EXPECT_EQ(0.25f, dummy.opacity());
1217 controller->Animate(kInitialTickTime + 1240 controller->Animate(kInitialTickTime +
1218 TimeDelta::FromMilliseconds(1073741824750)); 1241 TimeDelta::FromMilliseconds(1073741824750));
1219 controller->UpdateState(true, events.get()); 1242 controller->UpdateState(true, events.get());
1220 EXPECT_TRUE(controller->HasActiveAnimation()); 1243 EXPECT_TRUE(controller->HasActiveAnimation());
1221 EXPECT_EQ(0.75f, dummy.opacity()); 1244 EXPECT_EQ(0.75f, dummy.opacity());
1222 1245
1223 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 1246 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
1224 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 1247 controller->GetAnimation(Animation::Opacity)
1225 Animation::Aborted, kInitialTickTime + TimeDelta::FromMilliseconds(750)); 1248 ->SetRunState(Animation::Aborted,
1249 kInitialTickTime + TimeDelta::FromMilliseconds(750));
1226 EXPECT_FALSE(controller->HasActiveAnimation()); 1250 EXPECT_FALSE(controller->HasActiveAnimation());
1227 EXPECT_EQ(0.75f, dummy.opacity()); 1251 EXPECT_EQ(0.75f, dummy.opacity());
1228 } 1252 }
1229 1253
1230 // Test that pausing and resuming work as expected. 1254 // Test that pausing and resuming work as expected.
1231 TEST(LayerAnimationControllerTest, PauseResume) { 1255 TEST(LayerAnimationControllerTest, PauseResume) {
1232 scoped_ptr<AnimationEventsVector> events( 1256 scoped_ptr<AnimationEventsVector> events(
1233 make_scoped_ptr(new AnimationEventsVector)); 1257 make_scoped_ptr(new AnimationEventsVector));
1234 FakeLayerAnimationValueObserver dummy; 1258 FakeLayerAnimationValueObserver dummy;
1235 scoped_refptr<LayerAnimationController> controller( 1259 scoped_refptr<LayerAnimationController> controller(
1236 LayerAnimationController::Create(0)); 1260 LayerAnimationController::Create(0));
1237 controller->AddValueObserver(&dummy); 1261 controller->AddValueObserver(&dummy);
1238 1262
1239 const int id = 1;
1240 controller->AddAnimation(CreateAnimation( 1263 controller->AddAnimation(CreateAnimation(
1241 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 1264 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1242 id, 1265 1, Animation::Opacity));
1243 Animation::Opacity));
1244 1266
1245 controller->Animate(kInitialTickTime); 1267 controller->Animate(kInitialTickTime);
1246 controller->UpdateState(true, events.get()); 1268 controller->UpdateState(true, events.get());
1247 EXPECT_TRUE(controller->HasActiveAnimation()); 1269 EXPECT_TRUE(controller->HasActiveAnimation());
1248 EXPECT_EQ(0.f, dummy.opacity()); 1270 EXPECT_EQ(0.f, dummy.opacity());
1249 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1271 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1250 controller->UpdateState(true, events.get()); 1272 controller->UpdateState(true, events.get());
1251 EXPECT_TRUE(controller->HasActiveAnimation()); 1273 EXPECT_TRUE(controller->HasActiveAnimation());
1252 EXPECT_EQ(0.5f, dummy.opacity()); 1274 EXPECT_EQ(0.5f, dummy.opacity());
1253 1275
1254 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 1276 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
1255 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 1277 controller->GetAnimation(Animation::Opacity)
1256 Animation::Paused, kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1278 ->SetRunState(Animation::Paused,
1279 kInitialTickTime + TimeDelta::FromMilliseconds(500));
1257 1280
1258 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); 1281 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1259 controller->UpdateState(true, events.get()); 1282 controller->UpdateState(true, events.get());
1260 EXPECT_TRUE(controller->HasActiveAnimation()); 1283 EXPECT_TRUE(controller->HasActiveAnimation());
1261 EXPECT_EQ(0.5f, dummy.opacity()); 1284 EXPECT_EQ(0.5f, dummy.opacity());
1262 1285
1263 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 1286 EXPECT_TRUE(controller->GetAnimation(Animation::Opacity));
1264 controller->GetAnimation(id, Animation::Opacity) 1287 controller->GetAnimation(Animation::Opacity)
1265 ->SetRunState(Animation::Running, 1288 ->SetRunState(Animation::Running,
1266 kInitialTickTime + TimeDelta::FromMilliseconds(1024000)); 1289 kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
1267 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250)); 1290 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024250));
1268 controller->UpdateState(true, events.get()); 1291 controller->UpdateState(true, events.get());
1269 EXPECT_TRUE(controller->HasActiveAnimation()); 1292 EXPECT_TRUE(controller->HasActiveAnimation());
1270 EXPECT_EQ(0.75f, dummy.opacity()); 1293 EXPECT_EQ(0.75f, dummy.opacity());
1271 1294
1272 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500)); 1295 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1024500));
1273 controller->UpdateState(true, events.get()); 1296 controller->UpdateState(true, events.get());
1274 EXPECT_FALSE(controller->HasActiveAnimation()); 1297 EXPECT_FALSE(controller->HasActiveAnimation());
1275 EXPECT_EQ(1.f, dummy.opacity()); 1298 EXPECT_EQ(1.f, dummy.opacity());
1276 } 1299 }
1277 1300
1278 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) { 1301 TEST(LayerAnimationControllerTest, AbortAGroupedAnimation) {
1279 scoped_ptr<AnimationEventsVector> events( 1302 scoped_ptr<AnimationEventsVector> events(
1280 make_scoped_ptr(new AnimationEventsVector)); 1303 make_scoped_ptr(new AnimationEventsVector));
1281 FakeLayerAnimationValueObserver dummy; 1304 FakeLayerAnimationValueObserver dummy;
1282 scoped_refptr<LayerAnimationController> controller( 1305 scoped_refptr<LayerAnimationController> controller(
1283 LayerAnimationController::Create(0)); 1306 LayerAnimationController::Create(0));
1284 controller->AddValueObserver(&dummy); 1307 controller->AddValueObserver(&dummy);
1285 1308
1286 const int id = 1; 1309 const int animation_id = 2;
1287 controller->AddAnimation(CreateAnimation( 1310 controller->AddAnimation(Animation::Create(
1288 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1311 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1)).Pass(), 1, 1,
1289 id,
1290 Animation::Transform)); 1312 Animation::Transform));
1291 controller->AddAnimation(CreateAnimation( 1313 controller->AddAnimation(Animation::Create(
1292 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), 1314 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1293 id, 1315 animation_id, 1, Animation::Opacity));
1294 Animation::Opacity)); 1316 controller->AddAnimation(Animation::Create(
1295 controller->AddAnimation(CreateAnimation( 1317 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.75f))
1296 scoped_ptr<AnimationCurve>( 1318 .Pass(),
1297 new FakeFloatTransition(1.0, 1.f, 0.75f)).Pass(), 1319 3, 2, Animation::Opacity));
1298 2,
1299 Animation::Opacity));
1300 1320
1301 controller->Animate(kInitialTickTime); 1321 controller->Animate(kInitialTickTime);
1302 controller->UpdateState(true, events.get()); 1322 controller->UpdateState(true, events.get());
1303 EXPECT_TRUE(controller->HasActiveAnimation()); 1323 EXPECT_TRUE(controller->HasActiveAnimation());
1304 EXPECT_EQ(0.f, dummy.opacity()); 1324 EXPECT_EQ(0.f, dummy.opacity());
1305 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1325 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1306 controller->UpdateState(true, events.get()); 1326 controller->UpdateState(true, events.get());
1307 EXPECT_TRUE(controller->HasActiveAnimation()); 1327 EXPECT_TRUE(controller->HasActiveAnimation());
1308 EXPECT_EQ(0.5f, dummy.opacity()); 1328 EXPECT_EQ(0.5f, dummy.opacity());
1309 1329
1310 EXPECT_TRUE(controller->GetAnimation(id, Animation::Opacity)); 1330 EXPECT_TRUE(controller->GetAnimationById(animation_id));
1311 controller->GetAnimation(id, Animation::Opacity)->SetRunState( 1331 controller->GetAnimationById(animation_id)
1312 Animation::Aborted, kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1332 ->SetRunState(Animation::Aborted,
1333 kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1313 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1334 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1314 controller->UpdateState(true, events.get()); 1335 controller->UpdateState(true, events.get());
1315 EXPECT_TRUE(controller->HasActiveAnimation()); 1336 EXPECT_TRUE(controller->HasActiveAnimation());
1316 EXPECT_EQ(1.f, dummy.opacity()); 1337 EXPECT_EQ(1.f, dummy.opacity());
1317 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1338 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1318 controller->UpdateState(true, events.get()); 1339 controller->UpdateState(true, events.get());
1319 EXPECT_TRUE(!controller->HasActiveAnimation()); 1340 EXPECT_TRUE(!controller->HasActiveAnimation());
1320 EXPECT_EQ(0.75f, dummy.opacity()); 1341 EXPECT_EQ(0.75f, dummy.opacity());
1321 } 1342 }
1322 1343
(...skipping 12 matching lines...) Expand all
1335 scoped_ptr<Animation> to_add(CreateAnimation( 1356 scoped_ptr<Animation> to_add(CreateAnimation(
1336 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(), 1357 scoped_ptr<AnimationCurve>(new FakeFloatTransition(2.0, 0.f, 1.f)).Pass(),
1337 0, 1358 0,
1338 Animation::Opacity)); 1359 Animation::Opacity));
1339 to_add->set_needs_synchronized_start_time(true); 1360 to_add->set_needs_synchronized_start_time(true);
1340 controller->AddAnimation(to_add.Pass()); 1361 controller->AddAnimation(to_add.Pass());
1341 1362
1342 controller->Animate(kInitialTickTime); 1363 controller->Animate(kInitialTickTime);
1343 controller->UpdateState(true, events.get()); 1364 controller->UpdateState(true, events.get());
1344 EXPECT_TRUE(controller->HasActiveAnimation()); 1365 EXPECT_TRUE(controller->HasActiveAnimation());
1345 Animation* active_animation = controller->GetAnimation(0, Animation::Opacity); 1366 Animation* active_animation = controller->GetAnimation(Animation::Opacity);
1346 EXPECT_TRUE(active_animation); 1367 EXPECT_TRUE(active_animation);
1347 EXPECT_TRUE(active_animation->needs_synchronized_start_time()); 1368 EXPECT_TRUE(active_animation->needs_synchronized_start_time());
1348 1369
1349 controller->PushAnimationUpdatesTo(controller_impl.get()); 1370 controller->PushAnimationUpdatesTo(controller_impl.get());
1350 controller_impl->ActivateAnimations(); 1371 controller_impl->ActivateAnimations();
1351 1372
1352 active_animation = controller_impl->GetAnimation(0, Animation::Opacity); 1373 active_animation = controller_impl->GetAnimation(Animation::Opacity);
1353 EXPECT_TRUE(active_animation); 1374 EXPECT_TRUE(active_animation);
1354 EXPECT_EQ(Animation::WaitingForTargetAvailability, 1375 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1355 active_animation->run_state()); 1376 active_animation->run_state());
1356 } 1377 }
1357 1378
1358 // Tests that skipping a call to UpdateState works as expected. 1379 // Tests that skipping a call to UpdateState works as expected.
1359 TEST(LayerAnimationControllerTest, SkipUpdateState) { 1380 TEST(LayerAnimationControllerTest, SkipUpdateState) {
1360 scoped_ptr<AnimationEventsVector> events( 1381 scoped_ptr<AnimationEventsVector> events(
1361 make_scoped_ptr(new AnimationEventsVector)); 1382 make_scoped_ptr(new AnimationEventsVector));
1362 FakeLayerAnimationValueObserver dummy; 1383 FakeLayerAnimationValueObserver dummy;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(), 1436 new FakeFloatTransition(1.0, 0.5f, 1.f)).Pass(),
1416 id, 1437 id,
1417 Animation::Opacity)); 1438 Animation::Opacity));
1418 1439
1419 // Without an observer, the animation shouldn't progress to the Starting 1440 // Without an observer, the animation shouldn't progress to the Starting
1420 // state. 1441 // state.
1421 controller->Animate(kInitialTickTime); 1442 controller->Animate(kInitialTickTime);
1422 controller->UpdateState(true, events.get()); 1443 controller->UpdateState(true, events.get());
1423 EXPECT_EQ(0u, events->size()); 1444 EXPECT_EQ(0u, events->size());
1424 EXPECT_EQ(Animation::WaitingForTargetAvailability, 1445 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1425 controller->GetAnimation(id, Animation::Opacity)->run_state()); 1446 controller->GetAnimation(Animation::Opacity)->run_state());
1426 1447
1427 controller->AddValueObserver(&pending_dummy); 1448 controller->AddValueObserver(&pending_dummy);
1428 1449
1429 // With only a pending observer, the animation should progress to the 1450 // With only a pending observer, the animation should progress to the
1430 // Starting state and get ticked at its starting point, but should not 1451 // Starting state and get ticked at its starting point, but should not
1431 // progress to Running. 1452 // progress to Running.
1432 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1453 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1433 controller->UpdateState(true, events.get()); 1454 controller->UpdateState(true, events.get());
1434 EXPECT_EQ(0u, events->size()); 1455 EXPECT_EQ(0u, events->size());
1435 EXPECT_EQ(Animation::Starting, 1456 EXPECT_EQ(Animation::Starting,
1436 controller->GetAnimation(id, Animation::Opacity)->run_state()); 1457 controller->GetAnimation(Animation::Opacity)->run_state());
1437 EXPECT_EQ(0.5f, pending_dummy.opacity()); 1458 EXPECT_EQ(0.5f, pending_dummy.opacity());
1438 1459
1439 // Even when already in the Starting state, the animation should stay 1460 // Even when already in the Starting state, the animation should stay
1440 // there, and shouldn't be ticked past its starting point. 1461 // there, and shouldn't be ticked past its starting point.
1441 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 1462 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
1442 controller->UpdateState(true, events.get()); 1463 controller->UpdateState(true, events.get());
1443 EXPECT_EQ(0u, events->size()); 1464 EXPECT_EQ(0u, events->size());
1444 EXPECT_EQ(Animation::Starting, 1465 EXPECT_EQ(Animation::Starting,
1445 controller->GetAnimation(id, Animation::Opacity)->run_state()); 1466 controller->GetAnimation(Animation::Opacity)->run_state());
1446 EXPECT_EQ(0.5f, pending_dummy.opacity()); 1467 EXPECT_EQ(0.5f, pending_dummy.opacity());
1447 1468
1448 controller->AddValueObserver(&dummy); 1469 controller->AddValueObserver(&dummy);
1449 1470
1450 // Now that an active observer has been added, the animation should still 1471 // Now that an active observer has been added, the animation should still
1451 // initially tick at its starting point, but should now progress to Running. 1472 // initially tick at its starting point, but should now progress to Running.
1452 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000)); 1473 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
1453 controller->UpdateState(true, events.get()); 1474 controller->UpdateState(true, events.get());
1454 EXPECT_EQ(1u, events->size()); 1475 EXPECT_EQ(1u, events->size());
1455 EXPECT_EQ(Animation::Running, 1476 EXPECT_EQ(Animation::Running,
1456 controller->GetAnimation(id, Animation::Opacity)->run_state()); 1477 controller->GetAnimation(Animation::Opacity)->run_state());
1457 EXPECT_EQ(0.5f, pending_dummy.opacity()); 1478 EXPECT_EQ(0.5f, pending_dummy.opacity());
1458 EXPECT_EQ(0.5f, dummy.opacity()); 1479 EXPECT_EQ(0.5f, dummy.opacity());
1459 1480
1460 // The animation should now tick past its starting point. 1481 // The animation should now tick past its starting point.
1461 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500)); 1482 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(3500));
1462 EXPECT_NE(0.5f, pending_dummy.opacity()); 1483 EXPECT_NE(0.5f, pending_dummy.opacity());
1463 EXPECT_NE(0.5f, dummy.opacity()); 1484 EXPECT_NE(0.5f, dummy.opacity());
1464 } 1485 }
1465 1486
1466 TEST(LayerAnimationControllerTest, TransformAnimationBounds) { 1487 TEST(LayerAnimationControllerTest, TransformAnimationBounds) {
(...skipping 27 matching lines...) Expand all
1494 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform); 1515 animation = Animation::Create(curve2.Pass(), 2, 2, Animation::Transform);
1495 controller_impl->AddAnimation(animation.Pass()); 1516 controller_impl->AddAnimation(animation.Pass());
1496 1517
1497 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f); 1518 gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
1498 gfx::BoxF bounds; 1519 gfx::BoxF bounds;
1499 1520
1500 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); 1521 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1501 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(), 1522 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(),
1502 bounds.ToString()); 1523 bounds.ToString());
1503 1524
1504 controller_impl->GetAnimation(1, Animation::Transform) 1525 controller_impl->GetAnimationById(1)
1505 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1526 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1506 1527
1507 // Only the unfinished animation should affect the animated bounds. 1528 // Only the unfinished animation should affect the animated bounds.
1508 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds)); 1529 EXPECT_TRUE(controller_impl->TransformAnimationBoundsForBox(box, &bounds));
1509 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(), 1530 EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
1510 bounds.ToString()); 1531 bounds.ToString());
1511 1532
1512 controller_impl->GetAnimation(2, Animation::Transform) 1533 controller_impl->GetAnimationById(2)
1513 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1534 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1514 1535
1515 // There are no longer any running animations. 1536 // There are no longer any running animations.
1516 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds()); 1537 EXPECT_FALSE(controller_impl->HasTransformAnimationThatInflatesBounds());
1517 1538
1518 // Add an animation whose bounds we don't yet support computing. 1539 // Add an animation whose bounds we don't yet support computing.
1519 scoped_ptr<KeyframedTransformAnimationCurve> curve3( 1540 scoped_ptr<KeyframedTransformAnimationCurve> curve3(
1520 KeyframedTransformAnimationCurve::Create()); 1541 KeyframedTransformAnimationCurve::Create());
1521 TransformOperations operations3; 1542 TransformOperations operations3;
1522 gfx::Transform transform3; 1543 gfx::Transform transform3;
(...skipping 11 matching lines...) Expand all
1534 // Tests that AbortAnimations aborts all animations targeting the specified 1555 // Tests that AbortAnimations aborts all animations targeting the specified
1535 // property. 1556 // property.
1536 TEST(LayerAnimationControllerTest, AbortAnimations) { 1557 TEST(LayerAnimationControllerTest, AbortAnimations) {
1537 FakeLayerAnimationValueObserver dummy; 1558 FakeLayerAnimationValueObserver dummy;
1538 scoped_refptr<LayerAnimationController> controller( 1559 scoped_refptr<LayerAnimationController> controller(
1539 LayerAnimationController::Create(0)); 1560 LayerAnimationController::Create(0));
1540 controller->AddValueObserver(&dummy); 1561 controller->AddValueObserver(&dummy);
1541 1562
1542 // Start with several animations, and allow some of them to reach the finished 1563 // Start with several animations, and allow some of them to reach the finished
1543 // state. 1564 // state.
1544 controller->AddAnimation(CreateAnimation( 1565 controller->AddAnimation(Animation::Create(
1545 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1566 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 1, 1,
1546 1,
1547 Animation::Transform)); 1567 Animation::Transform));
1548 controller->AddAnimation(CreateAnimation( 1568 controller->AddAnimation(Animation::Create(
1549 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 1569 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1550 2, 1570 2, 2, Animation::Opacity));
1551 Animation::Opacity)); 1571 controller->AddAnimation(Animation::Create(
1552 controller->AddAnimation(CreateAnimation( 1572 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 3, 3,
1553 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1554 3,
1555 Animation::Transform)); 1573 Animation::Transform));
1556 controller->AddAnimation(CreateAnimation( 1574 controller->AddAnimation(Animation::Create(
1557 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1575 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 4, 4,
1558 4,
1559 Animation::Transform)); 1576 Animation::Transform));
1560 controller->AddAnimation(CreateAnimation( 1577 controller->AddAnimation(Animation::Create(
1561 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 1578 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1562 5, 1579 5, 5, Animation::Opacity));
1563 Animation::Opacity));
1564 1580
1565 controller->Animate(kInitialTickTime); 1581 controller->Animate(kInitialTickTime);
1566 controller->UpdateState(true, nullptr); 1582 controller->UpdateState(true, nullptr);
1567 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); 1583 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
1568 controller->UpdateState(true, nullptr); 1584 controller->UpdateState(true, nullptr);
1569 1585
1570 EXPECT_EQ(Animation::Finished, 1586 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(1)->run_state());
1571 controller->GetAnimation(1, Animation::Transform)->run_state()); 1587 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(2)->run_state());
1572 EXPECT_EQ(Animation::Finished, 1588 EXPECT_EQ(Animation::Running, controller->GetAnimationById(3)->run_state());
1573 controller->GetAnimation(2, Animation::Opacity)->run_state());
1574 EXPECT_EQ(Animation::Running,
1575 controller->GetAnimation(3, Animation::Transform)->run_state());
1576 EXPECT_EQ(Animation::WaitingForTargetAvailability, 1589 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1577 controller->GetAnimation(4, Animation::Transform)->run_state()); 1590 controller->GetAnimationById(4)->run_state());
1578 EXPECT_EQ(Animation::Running, 1591 EXPECT_EQ(Animation::Running, controller->GetAnimationById(5)->run_state());
1579 controller->GetAnimation(5, Animation::Opacity)->run_state());
1580 1592
1581 controller->AbortAnimations(Animation::Transform); 1593 controller->AbortAnimations(Animation::Transform);
1582 1594
1583 // Only un-finished Transform animations should have been aborted. 1595 // Only un-finished Transform animations should have been aborted.
1584 EXPECT_EQ(Animation::Finished, 1596 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(1)->run_state());
1585 controller->GetAnimation(1, Animation::Transform)->run_state()); 1597 EXPECT_EQ(Animation::Finished, controller->GetAnimationById(2)->run_state());
1586 EXPECT_EQ(Animation::Finished, 1598 EXPECT_EQ(Animation::Aborted, controller->GetAnimationById(3)->run_state());
1587 controller->GetAnimation(2, Animation::Opacity)->run_state()); 1599 EXPECT_EQ(Animation::Aborted, controller->GetAnimationById(4)->run_state());
1588 EXPECT_EQ(Animation::Aborted, 1600 EXPECT_EQ(Animation::Running, controller->GetAnimationById(5)->run_state());
1589 controller->GetAnimation(3, Animation::Transform)->run_state());
1590 EXPECT_EQ(Animation::Aborted,
1591 controller->GetAnimation(4, Animation::Transform)->run_state());
1592 EXPECT_EQ(Animation::Running,
1593 controller->GetAnimation(5, Animation::Opacity)->run_state());
1594 } 1601 }
1595 1602
1596 // An animation aborted on the main thread should get deleted on both threads. 1603 // An animation aborted on the main thread should get deleted on both threads.
1597 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) { 1604 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) {
1598 FakeLayerAnimationValueObserver dummy_impl; 1605 FakeLayerAnimationValueObserver dummy_impl;
1599 scoped_refptr<LayerAnimationController> controller_impl( 1606 scoped_refptr<LayerAnimationController> controller_impl(
1600 LayerAnimationController::Create(0)); 1607 LayerAnimationController::Create(0));
1601 controller_impl->AddValueObserver(&dummy_impl); 1608 controller_impl->AddValueObserver(&dummy_impl);
1602 FakeLayerAnimationValueObserver dummy; 1609 FakeLayerAnimationValueObserver dummy;
1603 scoped_refptr<LayerAnimationController> controller( 1610 scoped_refptr<LayerAnimationController> controller(
1604 LayerAnimationController::Create(0)); 1611 LayerAnimationController::Create(0));
1605 controller->AddValueObserver(&dummy); 1612 controller->AddValueObserver(&dummy);
1606 1613
1607 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); 1614 int animation_id =
1608 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 1615 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1609 1616
1610 controller->PushAnimationUpdatesTo(controller_impl.get()); 1617 controller->PushAnimationUpdatesTo(controller_impl.get());
1611 controller_impl->ActivateAnimations(); 1618 controller_impl->ActivateAnimations();
1612 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1619 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1613 1620
1614 controller->AbortAnimations(Animation::Opacity); 1621 controller->AbortAnimations(Animation::Opacity);
1615 EXPECT_EQ(Animation::Aborted, 1622 EXPECT_EQ(Animation::Aborted,
1616 controller->GetAnimation(Animation::Opacity)->run_state()); 1623 controller->GetAnimation(Animation::Opacity)->run_state());
1617 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); 1624 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1618 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); 1625 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1619 1626
1620 controller->Animate(kInitialTickTime); 1627 controller->Animate(kInitialTickTime);
1621 controller->UpdateState(true, nullptr); 1628 controller->UpdateState(true, nullptr);
1622 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); 1629 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1623 EXPECT_EQ(Animation::WaitingForDeletion, 1630 EXPECT_EQ(Animation::WaitingForDeletion,
1624 controller->GetAnimation(Animation::Opacity)->run_state()); 1631 controller->GetAnimation(Animation::Opacity)->run_state());
1625 1632
1626 controller->PushAnimationUpdatesTo(controller_impl.get()); 1633 controller->PushAnimationUpdatesTo(controller_impl.get());
1627 controller_impl->ActivateAnimations(); 1634 controller_impl->ActivateAnimations();
1628 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); 1635 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1629 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1636 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1630 } 1637 }
1631 1638
1632 // An animation aborted on the impl thread should get deleted on both threads. 1639 // An animation aborted on the impl thread should get deleted on both threads.
1633 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) { 1640 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1634 FakeLayerAnimationValueObserver dummy_impl; 1641 FakeLayerAnimationValueObserver dummy_impl;
1635 scoped_refptr<LayerAnimationController> controller_impl( 1642 scoped_refptr<LayerAnimationController> controller_impl(
1636 LayerAnimationController::Create(0)); 1643 LayerAnimationController::Create(0));
1637 controller_impl->AddValueObserver(&dummy_impl); 1644 controller_impl->AddValueObserver(&dummy_impl);
1638 FakeLayerAnimationValueObserver dummy; 1645 FakeLayerAnimationValueObserver dummy;
1639 scoped_refptr<LayerAnimationController> controller( 1646 scoped_refptr<LayerAnimationController> controller(
1640 LayerAnimationController::Create(0)); 1647 LayerAnimationController::Create(0));
1641 controller->AddValueObserver(&dummy); 1648 controller->AddValueObserver(&dummy);
1642 1649
1643 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false); 1650 int animation_id =
1644 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 1651 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1645 1652
1646 controller->PushAnimationUpdatesTo(controller_impl.get()); 1653 controller->PushAnimationUpdatesTo(controller_impl.get());
1647 controller_impl->ActivateAnimations(); 1654 controller_impl->ActivateAnimations();
1648 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1655 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1649 1656
1650 controller_impl->AbortAnimations(Animation::Opacity); 1657 controller_impl->AbortAnimations(Animation::Opacity);
1651 EXPECT_EQ(Animation::Aborted, 1658 EXPECT_EQ(Animation::Aborted,
1652 controller_impl->GetAnimation(Animation::Opacity)->run_state()); 1659 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1653 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); 1660 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1654 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); 1661 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1655 1662
1656 AnimationEventsVector events; 1663 AnimationEventsVector events;
1657 controller_impl->Animate(kInitialTickTime); 1664 controller_impl->Animate(kInitialTickTime);
1658 controller_impl->UpdateState(true, &events); 1665 controller_impl->UpdateState(true, &events);
1659 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); 1666 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1660 EXPECT_EQ(1u, events.size()); 1667 EXPECT_EQ(1u, events.size());
1661 EXPECT_EQ(AnimationEvent::Aborted, events[0].type); 1668 EXPECT_EQ(AnimationEvent::Aborted, events[0].type);
1662 EXPECT_EQ(Animation::WaitingForDeletion, 1669 EXPECT_EQ(Animation::WaitingForDeletion,
1663 controller_impl->GetAnimation(Animation::Opacity)->run_state()); 1670 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1664 1671
1665 controller->NotifyAnimationAborted(events[0]); 1672 controller->NotifyAnimationAborted(events[0]);
1666 EXPECT_EQ(Animation::Aborted, 1673 EXPECT_EQ(Animation::Aborted,
1667 controller->GetAnimation(Animation::Opacity)->run_state()); 1674 controller->GetAnimation(Animation::Opacity)->run_state());
1668 1675
1669 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 1676 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
1670 controller->UpdateState(true, nullptr); 1677 controller->UpdateState(true, nullptr);
1671 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); 1678 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1672 EXPECT_EQ(Animation::WaitingForDeletion, 1679 EXPECT_EQ(Animation::WaitingForDeletion,
1673 controller->GetAnimation(Animation::Opacity)->run_state()); 1680 controller->GetAnimation(Animation::Opacity)->run_state());
1674 1681
1675 controller->PushAnimationUpdatesTo(controller_impl.get()); 1682 controller->PushAnimationUpdatesTo(controller_impl.get());
1676 controller_impl->ActivateAnimations(); 1683 controller_impl->ActivateAnimations();
1677 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity)); 1684 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1678 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 1685 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1679 } 1686 }
1680 1687
1681 // Ensure that we only generate Finished events for animations in a group 1688 // Ensure that we only generate Finished events for animations in a group
1682 // once all animations in that group are finished. 1689 // once all animations in that group are finished.
1683 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { 1690 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1684 scoped_ptr<AnimationEventsVector> events( 1691 scoped_ptr<AnimationEventsVector> events(
1685 make_scoped_ptr(new AnimationEventsVector)); 1692 make_scoped_ptr(new AnimationEventsVector));
1686 FakeLayerAnimationValueObserver dummy_impl; 1693 FakeLayerAnimationValueObserver dummy_impl;
1687 scoped_refptr<LayerAnimationController> controller_impl( 1694 scoped_refptr<LayerAnimationController> controller_impl(
1688 LayerAnimationController::Create(0)); 1695 LayerAnimationController::Create(0));
1689 controller_impl->AddValueObserver(&dummy_impl); 1696 controller_impl->AddValueObserver(&dummy_impl);
1690 1697
1698 const int group_id = 1;
1699
1691 // Add two animations with the same group id but different durations. 1700 // Add two animations with the same group id but different durations.
1692 controller_impl->AddAnimation(CreateAnimation( 1701 controller_impl->AddAnimation(Animation::Create(
1693 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1702 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(), 1,
1694 1, 1703 group_id, Animation::Transform));
1695 Animation::Transform)); 1704 controller_impl->AddAnimation(Animation::Create(
1696 controller_impl->AddAnimation(CreateAnimation(
1697 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(), 1705 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1698 1, 1706 2, group_id, Animation::Opacity));
1699 Animation::Opacity));
1700 1707
1701 controller_impl->Animate(kInitialTickTime); 1708 controller_impl->Animate(kInitialTickTime);
1702 controller_impl->UpdateState(true, events.get()); 1709 controller_impl->UpdateState(true, events.get());
1703 1710
1704 // Both animations should have started. 1711 // Both animations should have started.
1705 EXPECT_EQ(2u, events->size()); 1712 EXPECT_EQ(2u, events->size());
1706 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type); 1713 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1707 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type); 1714 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1708 1715
1709 events.reset(new AnimationEventsVector); 1716 events.reset(new AnimationEventsVector);
1710 controller_impl->Animate(kInitialTickTime + 1717 controller_impl->Animate(kInitialTickTime +
1711 TimeDelta::FromMilliseconds(1000)); 1718 TimeDelta::FromMilliseconds(1000));
1712 controller_impl->UpdateState(true, events.get()); 1719 controller_impl->UpdateState(true, events.get());
1713 1720
1714 // The opacity animation should be finished, but should not have generated 1721 // The opacity animation should be finished, but should not have generated
1715 // a Finished event yet. 1722 // a Finished event yet.
1716 EXPECT_EQ(0u, events->size()); 1723 EXPECT_EQ(0u, events->size());
1717 EXPECT_EQ(Animation::Finished, 1724 EXPECT_EQ(Animation::Finished,
1718 controller_impl->GetAnimation(1, Animation::Opacity)->run_state()); 1725 controller_impl->GetAnimationById(2)->run_state());
1719 EXPECT_EQ(Animation::Running, 1726 EXPECT_EQ(Animation::Running,
1720 controller_impl->GetAnimation(1, 1727 controller_impl->GetAnimationById(1)->run_state());
1721 Animation::Transform)->run_state());
1722 1728
1723 controller_impl->Animate(kInitialTickTime + 1729 controller_impl->Animate(kInitialTickTime +
1724 TimeDelta::FromMilliseconds(2000)); 1730 TimeDelta::FromMilliseconds(2000));
1725 controller_impl->UpdateState(true, events.get()); 1731 controller_impl->UpdateState(true, events.get());
1726 1732
1727 // Both animations should have generated Finished events. 1733 // Both animations should have generated Finished events.
1728 EXPECT_EQ(2u, events->size()); 1734 EXPECT_EQ(2u, events->size());
1729 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); 1735 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1730 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type); 1736 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type);
1731 } 1737 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr)); 1820 TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
1815 operations2.AppendScale(2.0, 3.0, 4.0); 1821 operations2.AppendScale(2.0, 3.0, 4.0);
1816 curve2->AddKeyframe(TransformKeyframe::Create( 1822 curve2->AddKeyframe(TransformKeyframe::Create(
1817 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 1823 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
1818 1824
1819 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform); 1825 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform);
1820 controller_impl->AddAnimation(animation.Pass()); 1826 controller_impl->AddAnimation(animation.Pass());
1821 1827
1822 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale()); 1828 EXPECT_TRUE(controller_impl->HasAnimationThatAffectsScale());
1823 1829
1824 controller_impl->GetAnimation(3, Animation::Transform) 1830 controller_impl->GetAnimationById(3)
1825 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1831 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1826 1832
1827 // Only unfinished animations should be considered by 1833 // Only unfinished animations should be considered by
1828 // HasAnimationThatAffectsScale. 1834 // HasAnimationThatAffectsScale.
1829 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale()); 1835 EXPECT_FALSE(controller_impl->HasAnimationThatAffectsScale());
1830 } 1836 }
1831 1837
1832 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) { 1838 TEST(LayerAnimationControllerTest, HasOnlyTranslationTransforms) {
1833 scoped_refptr<LayerAnimationController> controller_impl( 1839 scoped_refptr<LayerAnimationController> controller_impl(
1834 LayerAnimationController::Create(0)); 1840 LayerAnimationController::Create(0));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 operations2.AppendScale(2.0, 3.0, 4.0); 1875 operations2.AppendScale(2.0, 3.0, 4.0);
1870 curve2->AddKeyframe(TransformKeyframe::Create( 1876 curve2->AddKeyframe(TransformKeyframe::Create(
1871 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr)); 1877 base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
1872 1878
1873 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform); 1879 animation = Animation::Create(curve2.Pass(), 3, 3, Animation::Transform);
1874 controller_impl->AddAnimation(animation.Pass()); 1880 controller_impl->AddAnimation(animation.Pass());
1875 1881
1876 // A scale animation is not a translation. 1882 // A scale animation is not a translation.
1877 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms()); 1883 EXPECT_FALSE(controller_impl->HasOnlyTranslationTransforms());
1878 1884
1879 controller_impl->GetAnimation(3, Animation::Transform) 1885 controller_impl->GetAnimationById(3)
1880 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1886 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1881 1887
1882 // Only unfinished animations should be considered by 1888 // Only unfinished animations should be considered by
1883 // HasOnlyTranslationTransforms. 1889 // HasOnlyTranslationTransforms.
1884 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms()); 1890 EXPECT_TRUE(controller_impl->HasOnlyTranslationTransforms());
1885 } 1891 }
1886 1892
1887 TEST(LayerAnimationControllerTest, MaximumTargetScale) { 1893 TEST(LayerAnimationControllerTest, MaximumTargetScale) {
1888 scoped_refptr<LayerAnimationController> controller_impl( 1894 scoped_refptr<LayerAnimationController> controller_impl(
1889 LayerAnimationController::Create(0)); 1895 LayerAnimationController::Create(0));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr)); 1939 TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
1934 operations3.AppendPerspective(6.0); 1940 operations3.AppendPerspective(6.0);
1935 curve3->AddKeyframe(TransformKeyframe::Create( 1941 curve3->AddKeyframe(TransformKeyframe::Create(
1936 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr)); 1942 base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
1937 1943
1938 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform); 1944 animation = Animation::Create(curve3.Pass(), 3, 3, Animation::Transform);
1939 controller_impl->AddAnimation(animation.Pass()); 1945 controller_impl->AddAnimation(animation.Pass());
1940 1946
1941 EXPECT_FALSE(controller_impl->MaximumTargetScale(&max_scale)); 1947 EXPECT_FALSE(controller_impl->MaximumTargetScale(&max_scale));
1942 1948
1943 controller_impl->GetAnimation(3, Animation::Transform) 1949 controller_impl->GetAnimationById(3)
1944 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1950 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1945 controller_impl->GetAnimation(2, Animation::Transform) 1951 controller_impl->GetAnimationById(2)
1946 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0)); 1952 ->SetRunState(Animation::Finished, TicksFromSecondsF(0.0));
1947 1953
1948 // Only unfinished animations should be considered by 1954 // Only unfinished animations should be considered by
1949 // MaximumTargetScale. 1955 // MaximumTargetScale.
1950 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale)); 1956 EXPECT_TRUE(controller_impl->MaximumTargetScale(&max_scale));
1951 EXPECT_EQ(4.f, max_scale); 1957 EXPECT_EQ(4.f, max_scale);
1952 } 1958 }
1953 1959
1954 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) { 1960 TEST(LayerAnimationControllerTest, MaximumTargetScaleWithDirection) {
1955 scoped_refptr<LayerAnimationController> controller_impl( 1961 scoped_refptr<LayerAnimationController> controller_impl(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 scoped_refptr<LayerAnimationController> controller_impl( 2032 scoped_refptr<LayerAnimationController> controller_impl(
2027 LayerAnimationController::Create(0)); 2033 LayerAnimationController::Create(0));
2028 controller_impl->AddValueObserver(&dummy_impl); 2034 controller_impl->AddValueObserver(&dummy_impl);
2029 controller_impl->AddValueObserver(&pending_dummy_impl); 2035 controller_impl->AddValueObserver(&pending_dummy_impl);
2030 FakeLayerAnimationValueObserver dummy; 2036 FakeLayerAnimationValueObserver dummy;
2031 scoped_refptr<LayerAnimationController> controller( 2037 scoped_refptr<LayerAnimationController> controller(
2032 LayerAnimationController::Create(0)); 2038 LayerAnimationController::Create(0));
2033 controller->AddValueObserver(&dummy); 2039 controller->AddValueObserver(&dummy);
2034 2040
2035 EXPECT_FALSE(controller->needs_to_start_animations_for_testing()); 2041 EXPECT_FALSE(controller->needs_to_start_animations_for_testing());
2036 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false); 2042 int animation_id =
2037 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 2043 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, false);
2038 EXPECT_TRUE(controller->needs_to_start_animations_for_testing()); 2044 EXPECT_TRUE(controller->needs_to_start_animations_for_testing());
2039 2045
2040 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); 2046 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
2041 controller->PushAnimationUpdatesTo(controller_impl.get()); 2047 controller->PushAnimationUpdatesTo(controller_impl.get());
2042 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing()); 2048 EXPECT_TRUE(controller_impl->needs_to_start_animations_for_testing());
2043 2049
2044 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 2050 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
2045 EXPECT_EQ( 2051 EXPECT_EQ(Animation::WaitingForTargetAvailability,
2046 Animation::WaitingForTargetAvailability, 2052 controller_impl->GetAnimationById(animation_id)->run_state());
2047 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state()); 2053 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2048 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2049 ->affects_pending_observers()); 2054 ->affects_pending_observers());
2050 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2055 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2051 ->affects_active_observers()); 2056 ->affects_active_observers());
2052 2057
2053 controller_impl->Animate(kInitialTickTime); 2058 controller_impl->Animate(kInitialTickTime);
2054 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing()); 2059 EXPECT_FALSE(controller_impl->needs_to_start_animations_for_testing());
2055 controller_impl->UpdateState(true, events.get()); 2060 controller_impl->UpdateState(true, events.get());
2056 2061
2057 // Since the animation hasn't been activated, it should still be Starting 2062 // Since the animation hasn't been activated, it should still be Starting
2058 // rather than Running. 2063 // rather than Running.
2059 EXPECT_EQ( 2064 EXPECT_EQ(Animation::Starting,
2060 Animation::Starting, 2065 controller_impl->GetAnimationById(animation_id)->run_state());
2061 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2062 2066
2063 // Since the animation hasn't been activated, only the pending observer 2067 // Since the animation hasn't been activated, only the pending observer
2064 // should have been ticked. 2068 // should have been ticked.
2065 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2069 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2066 EXPECT_EQ(0.f, dummy_impl.opacity()); 2070 EXPECT_EQ(0.f, dummy_impl.opacity());
2067 2071
2068 controller_impl->ActivateAnimations(); 2072 controller_impl->ActivateAnimations();
2069 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2073 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2070 ->affects_pending_observers()); 2074 ->affects_pending_observers());
2071 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2075 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2072 ->affects_active_observers()); 2076 ->affects_active_observers());
2073 2077
2074 controller_impl->Animate(kInitialTickTime + 2078 controller_impl->Animate(kInitialTickTime +
2075 TimeDelta::FromMilliseconds(1000)); 2079 TimeDelta::FromMilliseconds(1000));
2076 controller_impl->UpdateState(true, events.get()); 2080 controller_impl->UpdateState(true, events.get());
2077 2081
2078 // Since the animation has been activated, it should have reached the 2082 // Since the animation has been activated, it should have reached the
2079 // Running state and the active observer should start to get ticked. 2083 // Running state and the active observer should start to get ticked.
2080 EXPECT_EQ( 2084 EXPECT_EQ(Animation::Running,
2081 Animation::Running, 2085 controller_impl->GetAnimationById(animation_id)->run_state());
2082 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2083 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2086 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2084 EXPECT_EQ(0.5f, dummy_impl.opacity()); 2087 EXPECT_EQ(0.5f, dummy_impl.opacity());
2085 } 2088 }
2086 2089
2087 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) { 2090 TEST(LayerAnimationControllerTest, ActivationBetweenAnimateAndUpdateState) {
2088 scoped_ptr<AnimationEventsVector> events( 2091 scoped_ptr<AnimationEventsVector> events(
2089 make_scoped_ptr(new AnimationEventsVector)); 2092 make_scoped_ptr(new AnimationEventsVector));
2090 FakeLayerAnimationValueObserver dummy_impl; 2093 FakeLayerAnimationValueObserver dummy_impl;
2091 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2094 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2092 scoped_refptr<LayerAnimationController> controller_impl( 2095 scoped_refptr<LayerAnimationController> controller_impl(
2093 LayerAnimationController::Create(0)); 2096 LayerAnimationController::Create(0));
2094 controller_impl->AddValueObserver(&dummy_impl); 2097 controller_impl->AddValueObserver(&dummy_impl);
2095 controller_impl->AddValueObserver(&pending_dummy_impl); 2098 controller_impl->AddValueObserver(&pending_dummy_impl);
2096 FakeLayerAnimationValueObserver dummy; 2099 FakeLayerAnimationValueObserver dummy;
2097 scoped_refptr<LayerAnimationController> controller( 2100 scoped_refptr<LayerAnimationController> controller(
2098 LayerAnimationController::Create(0)); 2101 LayerAnimationController::Create(0));
2099 controller->AddValueObserver(&dummy); 2102 controller->AddValueObserver(&dummy);
2100 2103
2101 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); 2104 int animation_id =
2102 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 2105 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2103 2106
2104 controller->PushAnimationUpdatesTo(controller_impl.get()); 2107 controller->PushAnimationUpdatesTo(controller_impl.get());
2105 2108
2106 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)); 2109 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
2107 EXPECT_EQ( 2110 EXPECT_EQ(Animation::WaitingForTargetAvailability,
2108 Animation::WaitingForTargetAvailability, 2111 controller_impl->GetAnimationById(animation_id)->run_state());
2109 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state()); 2112 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2110 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity)
2111 ->affects_pending_observers()); 2113 ->affects_pending_observers());
2112 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2114 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2113 ->affects_active_observers()); 2115 ->affects_active_observers());
2114 2116
2115 controller_impl->Animate(kInitialTickTime); 2117 controller_impl->Animate(kInitialTickTime);
2116 2118
2117 // Since the animation hasn't been activated, only the pending observer 2119 // Since the animation hasn't been activated, only the pending observer
2118 // should have been ticked. 2120 // should have been ticked.
2119 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2121 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2120 EXPECT_EQ(0.f, dummy_impl.opacity()); 2122 EXPECT_EQ(0.f, dummy_impl.opacity());
2121 2123
2122 controller_impl->ActivateAnimations(); 2124 controller_impl->ActivateAnimations();
2123 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2125 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2124 ->affects_pending_observers()); 2126 ->affects_pending_observers());
2125 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2127 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2126 ->affects_active_observers()); 2128 ->affects_active_observers());
2127 2129
2128 controller_impl->UpdateState(true, events.get()); 2130 controller_impl->UpdateState(true, events.get());
2129 2131
2130 // Since the animation has been activated, it should have reached the 2132 // Since the animation has been activated, it should have reached the
2131 // Running state. 2133 // Running state.
2132 EXPECT_EQ( 2134 EXPECT_EQ(Animation::Running,
2133 Animation::Running, 2135 controller_impl->GetAnimationById(animation_id)->run_state());
2134 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2135 2136
2136 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 2137 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2137 2138
2138 // Both observers should have been ticked. 2139 // Both observers should have been ticked.
2139 EXPECT_EQ(0.75f, pending_dummy_impl.opacity()); 2140 EXPECT_EQ(0.75f, pending_dummy_impl.opacity());
2140 EXPECT_EQ(0.75f, dummy_impl.opacity()); 2141 EXPECT_EQ(0.75f, dummy_impl.opacity());
2141 } 2142 }
2142 2143
2143 TEST(LayerAnimationControllerTest, ClippedOpacityValues) { 2144 TEST(LayerAnimationControllerTest, ClippedOpacityValues) {
2144 FakeLayerAnimationValueObserver dummy; 2145 FakeLayerAnimationValueObserver dummy;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2180 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2180 scoped_refptr<LayerAnimationController> controller_impl( 2181 scoped_refptr<LayerAnimationController> controller_impl(
2181 LayerAnimationController::Create(0)); 2182 LayerAnimationController::Create(0));
2182 controller_impl->AddValueObserver(&dummy_impl); 2183 controller_impl->AddValueObserver(&dummy_impl);
2183 controller_impl->AddValueObserver(&pending_dummy_impl); 2184 controller_impl->AddValueObserver(&pending_dummy_impl);
2184 FakeLayerAnimationValueObserver dummy; 2185 FakeLayerAnimationValueObserver dummy;
2185 scoped_refptr<LayerAnimationController> controller( 2186 scoped_refptr<LayerAnimationController> controller(
2186 LayerAnimationController::Create(0)); 2187 LayerAnimationController::Create(0));
2187 controller->AddValueObserver(&dummy); 2188 controller->AddValueObserver(&dummy);
2188 2189
2189 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true); 2190 int animation_id =
2190 int group_id = controller->GetAnimation(Animation::Opacity)->group(); 2191 AddOpacityTransitionToController(controller.get(), 1, 0.5f, 1.f, true);
2191 2192
2192 controller->PushAnimationUpdatesTo(controller_impl.get()); 2193 controller->PushAnimationUpdatesTo(controller_impl.get());
2193 controller_impl->ActivateAnimations(); 2194 controller_impl->ActivateAnimations();
2194 controller_impl->Animate(kInitialTickTime); 2195 controller_impl->Animate(kInitialTickTime);
2195 controller_impl->UpdateState(true, events.get()); 2196 controller_impl->UpdateState(true, events.get());
2196 EXPECT_EQ( 2197 EXPECT_EQ(Animation::Running,
2197 Animation::Running, 2198 controller_impl->GetAnimationById(animation_id)->run_state());
2198 controller_impl->GetAnimation(group_id, Animation::Opacity)->run_state());
2199 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2199 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2200 EXPECT_EQ(0.5f, dummy_impl.opacity()); 2200 EXPECT_EQ(0.5f, dummy_impl.opacity());
2201 2201
2202 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2202 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2203 ->affects_pending_observers()); 2203 ->affects_pending_observers());
2204 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2204 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2205 ->affects_active_observers()); 2205 ->affects_active_observers());
2206 2206
2207 // Delete the animation on the main-thread controller. 2207 // Delete the animation on the main-thread controller.
2208 controller->RemoveAnimation( 2208 controller->RemoveAnimation(
2209 controller->GetAnimation(Animation::Opacity)->id()); 2209 controller->GetAnimation(Animation::Opacity)->id());
2210 controller->PushAnimationUpdatesTo(controller_impl.get()); 2210 controller->PushAnimationUpdatesTo(controller_impl.get());
2211 2211
2212 // The animation should no longer affect pending observers. 2212 // The animation should no longer affect pending observers.
2213 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2213 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)
2214 ->affects_pending_observers()); 2214 ->affects_pending_observers());
2215 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity) 2215 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)
2216 ->affects_active_observers()); 2216 ->affects_active_observers());
2217 2217
2218 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 2218 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2219 controller_impl->UpdateState(true, events.get()); 2219 controller_impl->UpdateState(true, events.get());
2220 2220
2221 // Only the active observer should have been ticked. 2221 // Only the active observer should have been ticked.
2222 EXPECT_EQ(0.5f, pending_dummy_impl.opacity()); 2222 EXPECT_EQ(0.5f, pending_dummy_impl.opacity());
2223 EXPECT_EQ(0.75f, dummy_impl.opacity()); 2223 EXPECT_EQ(0.75f, dummy_impl.opacity());
2224 2224
2225 controller_impl->ActivateAnimations(); 2225 controller_impl->ActivateAnimations();
(...skipping 11 matching lines...) Expand all
2237 FakeInactiveLayerAnimationValueObserver pending_dummy_impl; 2237 FakeInactiveLayerAnimationValueObserver pending_dummy_impl;
2238 scoped_refptr<LayerAnimationController> controller_impl( 2238 scoped_refptr<LayerAnimationController> controller_impl(
2239 LayerAnimationController::Create(0)); 2239 LayerAnimationController::Create(0));
2240 controller_impl->AddValueObserver(&dummy_impl); 2240 controller_impl->AddValueObserver(&dummy_impl);
2241 controller_impl->AddValueObserver(&pending_dummy_impl); 2241 controller_impl->AddValueObserver(&pending_dummy_impl);
2242 FakeLayerAnimationValueObserver dummy; 2242 FakeLayerAnimationValueObserver dummy;
2243 scoped_refptr<LayerAnimationController> controller( 2243 scoped_refptr<LayerAnimationController> controller(
2244 LayerAnimationController::Create(0)); 2244 LayerAnimationController::Create(0));
2245 controller->AddValueObserver(&dummy); 2245 controller->AddValueObserver(&dummy);
2246 2246
2247 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true); 2247 int first_animation_id =
2248 int first_animation_group_id = 2248 AddOpacityTransitionToController(controller.get(), 1, 0.f, 1.f, true);
2249 controller->GetAnimation(Animation::Opacity)->group();
2250 2249
2251 controller->PushAnimationUpdatesTo(controller_impl.get()); 2250 controller->PushAnimationUpdatesTo(controller_impl.get());
2252 controller_impl->ActivateAnimations(); 2251 controller_impl->ActivateAnimations();
2253 controller_impl->Animate(kInitialTickTime); 2252 controller_impl->Animate(kInitialTickTime);
2254 controller_impl->UpdateState(true, events.get()); 2253 controller_impl->UpdateState(true, events.get());
2255 2254
2256 // Remove the first animation from the main-thread controller, and add a 2255 // Remove the first animation from the main-thread controller, and add a
2257 // new animation affecting the same property. 2256 // new animation affecting the same property.
2258 controller->RemoveAnimation( 2257 controller->RemoveAnimation(
2259 controller->GetAnimation(Animation::Opacity)->id()); 2258 controller->GetAnimation(Animation::Opacity)->id());
2260 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true); 2259 int second_animation_id =
2261 int second_animation_group_id = 2260 AddOpacityTransitionToController(controller.get(), 1, 1.f, 0.5f, true);
2262 controller->GetAnimation(Animation::Opacity)->group();
2263 controller->PushAnimationUpdatesTo(controller_impl.get()); 2261 controller->PushAnimationUpdatesTo(controller_impl.get());
2264 2262
2265 // The original animation should only affect active observers, and the new 2263 // The original animation should only affect active observers, and the new
2266 // animation should only affect pending observers. 2264 // animation should only affect pending observers.
2267 EXPECT_FALSE(controller_impl->GetAnimation(first_animation_group_id, 2265 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id)
2268 Animation::Opacity)
2269 ->affects_pending_observers()); 2266 ->affects_pending_observers());
2270 EXPECT_TRUE(controller_impl->GetAnimation(first_animation_group_id, 2267 EXPECT_TRUE(controller_impl->GetAnimationById(first_animation_id)
2271 Animation::Opacity)
2272 ->affects_active_observers()); 2268 ->affects_active_observers());
2273 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id, 2269 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2274 Animation::Opacity)
2275 ->affects_pending_observers()); 2270 ->affects_pending_observers());
2276 EXPECT_FALSE(controller_impl->GetAnimation(second_animation_group_id, 2271 EXPECT_FALSE(controller_impl->GetAnimationById(second_animation_id)
2277 Animation::Opacity)
2278 ->affects_active_observers()); 2272 ->affects_active_observers());
2279 2273
2280 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500)); 2274 controller_impl->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(500));
2281 controller_impl->UpdateState(true, events.get()); 2275 controller_impl->UpdateState(true, events.get());
2282 2276
2283 // The original animation should still be running, and the new animation 2277 // The original animation should still be running, and the new animation
2284 // should be starting. 2278 // should be starting.
2285 EXPECT_EQ(Animation::Running, 2279 EXPECT_EQ(Animation::Running,
2286 controller_impl->GetAnimation(first_animation_group_id, 2280 controller_impl->GetAnimationById(first_animation_id)->run_state());
2287 Animation::Opacity)->run_state()); 2281 EXPECT_EQ(
2288 EXPECT_EQ(Animation::Starting, 2282 Animation::Starting,
2289 controller_impl->GetAnimation(second_animation_group_id, 2283 controller_impl->GetAnimationById(second_animation_id)->run_state());
2290 Animation::Opacity)->run_state());
2291 2284
2292 // The active observer should have been ticked by the original animation, 2285 // The active observer should have been ticked by the original animation,
2293 // and the pending observer should have been ticked by the new animation. 2286 // and the pending observer should have been ticked by the new animation.
2294 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); 2287 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2295 EXPECT_EQ(0.5f, dummy_impl.opacity()); 2288 EXPECT_EQ(0.5f, dummy_impl.opacity());
2296 2289
2297 controller_impl->ActivateAnimations(); 2290 controller_impl->ActivateAnimations();
2298 2291
2299 // The original animation should have been deleted, and the new animation 2292 // The original animation should have been deleted, and the new animation
2300 // should now affect both observers. 2293 // should now affect both observers.
2301 EXPECT_FALSE(controller_impl->GetAnimation(first_animation_group_id, 2294 EXPECT_FALSE(controller_impl->GetAnimationById(first_animation_id));
2302 Animation::Opacity)); 2295 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2303 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id,
2304 Animation::Opacity)
2305 ->affects_pending_observers()); 2296 ->affects_pending_observers());
2306 EXPECT_TRUE(controller_impl->GetAnimation(second_animation_group_id, 2297 EXPECT_TRUE(controller_impl->GetAnimationById(second_animation_id)
2307 Animation::Opacity)
2308 ->affects_active_observers()); 2298 ->affects_active_observers());
2309 2299
2310 controller_impl->Animate(kInitialTickTime + 2300 controller_impl->Animate(kInitialTickTime +
2311 TimeDelta::FromMilliseconds(1000)); 2301 TimeDelta::FromMilliseconds(1000));
2312 controller_impl->UpdateState(true, events.get()); 2302 controller_impl->UpdateState(true, events.get());
2313 2303
2314 // The new animation should be running, and the active observer should have 2304 // The new animation should be running, and the active observer should have
2315 // been ticked at the new animation's starting point. 2305 // been ticked at the new animation's starting point.
2316 EXPECT_EQ(Animation::Running, 2306 EXPECT_EQ(
2317 controller_impl->GetAnimation(second_animation_group_id, 2307 Animation::Running,
2318 Animation::Opacity)->run_state()); 2308 controller_impl->GetAnimationById(second_animation_id)->run_state());
2319 EXPECT_EQ(1.f, pending_dummy_impl.opacity()); 2309 EXPECT_EQ(1.f, pending_dummy_impl.opacity());
2320 EXPECT_EQ(1.f, dummy_impl.opacity()); 2310 EXPECT_EQ(1.f, dummy_impl.opacity());
2321 } 2311 }
2322 2312
2323 TEST(LayerAnimationControllerTest, TestIsAnimatingProperty) { 2313 TEST(LayerAnimationControllerTest, TestIsAnimatingProperty) {
2324 FakeLayerAnimationValueObserver dummy; 2314 FakeLayerAnimationValueObserver dummy;
2325 scoped_refptr<LayerAnimationController> controller( 2315 scoped_refptr<LayerAnimationController> controller(
2326 LayerAnimationController::Create(0)); 2316 LayerAnimationController::Create(0));
2327 controller->AddValueObserver(&dummy); 2317 controller->AddValueObserver(&dummy);
2328 2318
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity)); 2351 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Opacity));
2362 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter)); 2352 EXPECT_FALSE(controller->IsAnimatingProperty(Animation::Filter));
2363 2353
2364 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000)); 2354 controller->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
2365 controller->UpdateState(true, nullptr); 2355 controller->UpdateState(true, nullptr);
2366 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity)); 2356 EXPECT_TRUE(controller->IsAnimatingProperty(Animation::Opacity));
2367 } 2357 }
2368 2358
2369 } // namespace 2359 } // namespace
2370 } // namespace cc 2360 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698