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

Side by Side Diff: ui/compositor/layer_animator_unittest.cc

Issue 1381463002: Added LayerAnimationObserver::OnLayerAnimationStarted() notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polish after self review. Created 5 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ui/compositor/layer_animator.h" 5 #include "ui/compositor/layer_animator.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 first_sequence->AddElement(first); 47 first_sequence->AddElement(first);
48 LayerAnimationSequence* second_sequence = new LayerAnimationSequence(); 48 LayerAnimationSequence* second_sequence = new LayerAnimationSequence();
49 second_sequence->AddElement(second); 49 second_sequence->AddElement(second);
50 50
51 std::vector<ui::LayerAnimationSequence*> animations; 51 std::vector<ui::LayerAnimationSequence*> animations;
52 animations.push_back(first_sequence); 52 animations.push_back(first_sequence);
53 animations.push_back(second_sequence); 53 animations.push_back(second_sequence);
54 return animations; 54 return animations;
55 } 55 }
56 56
57 // Creates a default animator with timers disabled for test. |delegate| and
58 // |observer| are attached if non-null.
59 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate,
60 LayerAnimationObserver* observer) {
61 LayerAnimator* animator(LayerAnimator::CreateDefaultAnimator());
62 animator->set_disable_timer_for_test(true);
63 if (delegate)
64 animator->SetDelegate(delegate);
65 if (observer)
66 animator->AddObserver(observer);
67 return animator;
68 }
69
70 // Creates a default animator with timers disabled for test. |delegate| is
71 // attached if non-null.
72 LayerAnimator* CreateDefaultTestAnimator(LayerAnimationDelegate* delegate) {
73 return CreateDefaultTestAnimator(delegate, nullptr);
74 }
75
76 // Creates a default animator with timers disabled for test.
77 LayerAnimator* CreateDefaultTestAnimator() {
78 return CreateDefaultTestAnimator(nullptr, nullptr);
79 }
80
81 // Creates an implicit animator with timers disabled for test. |delegate| and
82 // |observer| are attached if non-null.
83 LayerAnimator* CreateImplicitTestAnimator(LayerAnimationDelegate* delegate,
84 LayerAnimationObserver* observer) {
85 LayerAnimator* animator(LayerAnimator::CreateImplicitAnimator());
86 animator->set_disable_timer_for_test(true);
87 if (delegate)
88 animator->SetDelegate(delegate);
89 if (observer)
90 animator->AddObserver(observer);
91 return animator;
92 }
93
94 // Creates an implicit animator with timers disabled for test. |delegate| is
95 // attached if non-null.
96 LayerAnimator* CreateImplicitTestAnimator(LayerAnimationDelegate* delegate) {
97 return CreateImplicitTestAnimator(delegate, nullptr);
98 }
99
100 // Creates an implicit animator with timers disabled for test.
101 LayerAnimator* CreateImplicitTestAnimator() {
102 return CreateImplicitTestAnimator(nullptr, nullptr);
103 }
104
57 class TestImplicitAnimationObserver : public ImplicitAnimationObserver { 105 class TestImplicitAnimationObserver : public ImplicitAnimationObserver {
58 public: 106 public:
59 explicit TestImplicitAnimationObserver(bool notify_when_animator_destructed) 107 explicit TestImplicitAnimationObserver(bool notify_when_animator_destructed)
60 : animations_completed_(false), 108 : animations_completed_(false),
61 notify_when_animator_destructed_(notify_when_animator_destructed) { 109 notify_when_animator_destructed_(notify_when_animator_destructed) {
62 } 110 }
63 111
64 bool animations_completed() const { return animations_completed_; } 112 bool animations_completed() const { return animations_completed_; }
65 void set_animations_completed(bool completed) { 113 void set_animations_completed(bool completed) {
66 animations_completed_ = completed; 114 animations_completed_ = completed;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 int* num_live_instances_; 229 int* num_live_instances_;
182 230
183 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); 231 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence);
184 }; 232 };
185 233
186 } // namespace 234 } // namespace
187 235
188 // Checks that setting a property on an implicit animator causes an animation to 236 // Checks that setting a property on an implicit animator causes an animation to
189 // happen. 237 // happen.
190 TEST(LayerAnimatorTest, ImplicitAnimation) { 238 TEST(LayerAnimatorTest, ImplicitAnimation) {
191 scoped_refptr<LayerAnimator> animator(
192 LayerAnimator::CreateImplicitAnimator());
193 animator->set_disable_timer_for_test(true);
194 TestLayerAnimationDelegate delegate; 239 TestLayerAnimationDelegate delegate;
195 animator->SetDelegate(&delegate); 240 scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
196 base::TimeTicks now = base::TimeTicks::Now(); 241 base::TimeTicks now = base::TimeTicks::Now();
197 animator->SetBrightness(0.5); 242 animator->SetBrightness(0.5);
198 EXPECT_TRUE(animator->is_animating()); 243 EXPECT_TRUE(animator->is_animating());
199 animator->Step(now + base::TimeDelta::FromSeconds(1)); 244 animator->Step(now + base::TimeDelta::FromSeconds(1));
200 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); 245 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
201 } 246 }
202 247
203 // Checks that if the animator is a default animator, that implicit animations 248 // Checks that if the animator is a default animator, that implicit animations
204 // are not started. 249 // are not started.
205 TEST(LayerAnimatorTest, NoImplicitAnimation) { 250 TEST(LayerAnimatorTest, NoImplicitAnimation) {
206 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
207 animator->set_disable_timer_for_test(true);
208 TestLayerAnimationDelegate delegate; 251 TestLayerAnimationDelegate delegate;
209 animator->SetDelegate(&delegate); 252 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
210 animator->SetBrightness(0.5); 253 animator->SetBrightness(0.5);
211 EXPECT_FALSE(animator->is_animating()); 254 EXPECT_FALSE(animator->is_animating());
212 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); 255 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
213 } 256 }
214 257
215 // Checks that StopAnimatingProperty stops animation for that property, and also 258 // Checks that StopAnimatingProperty stops animation for that property, and also
216 // skips the stopped animation to the end. 259 // skips the stopped animation to the end.
217 TEST(LayerAnimatorTest, StopAnimatingProperty) { 260 TEST(LayerAnimatorTest, StopAnimatingProperty) {
218 scoped_refptr<LayerAnimator> animator(
219 LayerAnimator::CreateImplicitAnimator());
220 animator->set_disable_timer_for_test(true);
221 TestLayerAnimationDelegate delegate; 261 TestLayerAnimationDelegate delegate;
222 animator->SetDelegate(&delegate); 262 scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
223 double target_opacity(0.5); 263 double target_opacity(0.5);
224 gfx::Rect target_bounds(0, 0, 50, 50); 264 gfx::Rect target_bounds(0, 0, 50, 50);
225 animator->SetOpacity(target_opacity); 265 animator->SetOpacity(target_opacity);
226 animator->SetBounds(target_bounds); 266 animator->SetBounds(target_bounds);
227 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); 267 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY);
228 EXPECT_TRUE(animator->is_animating()); 268 EXPECT_TRUE(animator->is_animating());
229 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); 269 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5);
230 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); 270 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS);
231 EXPECT_FALSE(animator->is_animating()); 271 EXPECT_FALSE(animator->is_animating());
232 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 272 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
233 } 273 }
234 274
235 // Checks that multiple running animation for separate properties can be stopped 275 // Checks that multiple running animations for separate properties can be
236 // simultaneously and that all animations are advanced to their target values. 276 // stopped simultaneously and that all animations are advanced to their target
277 // values.
237 TEST(LayerAnimatorTest, StopAnimating) { 278 TEST(LayerAnimatorTest, StopAnimating) {
238 scoped_refptr<LayerAnimator> animator(
239 LayerAnimator::CreateImplicitAnimator());
240 animator->set_disable_timer_for_test(true);
241 TestLayerAnimationDelegate delegate; 279 TestLayerAnimationDelegate delegate;
242 animator->SetDelegate(&delegate); 280 scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
243 double target_opacity(0.5); 281 double target_opacity(0.5);
244 gfx::Rect target_bounds(0, 0, 50, 50); 282 gfx::Rect target_bounds(0, 0, 50, 50);
245 animator->SetOpacity(target_opacity); 283 animator->SetOpacity(target_opacity);
246 animator->SetBounds(target_bounds); 284 animator->SetBounds(target_bounds);
247 EXPECT_TRUE(animator->is_animating()); 285 EXPECT_TRUE(animator->is_animating());
248 animator->StopAnimating(); 286 animator->StopAnimating();
249 EXPECT_FALSE(animator->is_animating()); 287 EXPECT_FALSE(animator->is_animating());
250 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); 288 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5);
251 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 289 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
252 } 290 }
253 291
254 // Checks that multiple running animation for separate properties can be stopped 292 // Checks that multiple running animations for separate properties can be
255 // simultaneously and that all animations are advanced to their target values. 293 // stopped simultaneously and that aborted animations are NOT advanced to their
294 // target values.
256 TEST(LayerAnimatorTest, AbortAllAnimations) { 295 TEST(LayerAnimatorTest, AbortAllAnimations) {
257 scoped_refptr<LayerAnimator> animator(
258 LayerAnimator::CreateImplicitAnimator());
259 animator->set_disable_timer_for_test(true);
260 TestLayerAnimationDelegate delegate; 296 TestLayerAnimationDelegate delegate;
261 double initial_opacity(1.0); 297 double initial_opacity(1.0);
262 gfx::Rect initial_bounds(0, 0, 10, 10); 298 gfx::Rect initial_bounds(0, 0, 10, 10);
263 delegate.SetOpacityFromAnimation(initial_opacity); 299 delegate.SetOpacityFromAnimation(initial_opacity);
264 delegate.SetBoundsFromAnimation(initial_bounds); 300 delegate.SetBoundsFromAnimation(initial_bounds);
265 animator->SetDelegate(&delegate); 301 scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator(&delegate));
266 double target_opacity(0.5); 302 double target_opacity(0.5);
267 gfx::Rect target_bounds(0, 0, 50, 50); 303 gfx::Rect target_bounds(0, 0, 50, 50);
268 animator->SetOpacity(target_opacity); 304 animator->SetOpacity(target_opacity);
269 animator->SetBounds(target_bounds); 305 animator->SetBounds(target_bounds);
270 EXPECT_TRUE(animator->is_animating()); 306 EXPECT_TRUE(animator->is_animating());
271 animator->AbortAllAnimations(); 307 animator->AbortAllAnimations();
272 EXPECT_FALSE(animator->is_animating()); 308 EXPECT_FALSE(animator->is_animating());
273 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); 309 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation());
274 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); 310 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation());
275 } 311 }
276 312
277 // Schedule a non-threaded animation that can run immediately. This is the 313 // Schedule a non-threaded animation that can run immediately. This is the
278 // trivial case and should result in the animation being started immediately. 314 // trivial case and should result in the animation being started immediately.
279 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { 315 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
280 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
281 animator->set_disable_timer_for_test(true);
282 TestLayerAnimationDelegate delegate; 316 TestLayerAnimationDelegate delegate;
283 animator->SetDelegate(&delegate); 317 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
284 318
285 double start_brightness(0.0); 319 double start_brightness(0.0);
286 double middle_brightness(0.5); 320 double middle_brightness(0.5);
287 double target_brightness(1.0); 321 double target_brightness(1.0);
288 322
289 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 323 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
290 324
291 delegate.SetBrightnessFromAnimation(start_brightness); 325 delegate.SetBrightnessFromAnimation(start_brightness);
292 326
293 animator->ScheduleAnimation( 327 animator->ScheduleAnimation(
(...skipping 13 matching lines...) Expand all
307 341
308 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 342 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
309 343
310 EXPECT_FALSE(animator->is_animating()); 344 EXPECT_FALSE(animator->is_animating());
311 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 345 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
312 } 346 }
313 347
314 // Schedule a threaded animation that can run immediately. 348 // Schedule a threaded animation that can run immediately.
315 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { 349 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
316 double epsilon = 0.00001; 350 double epsilon = 0.00001;
351 TestLayerAnimationDelegate delegate;
317 LayerAnimatorTestController test_controller( 352 LayerAnimatorTestController test_controller(
318 LayerAnimator::CreateDefaultAnimator()); 353 CreateDefaultTestAnimator(&delegate));
319 LayerAnimator* animator = test_controller.animator(); 354 LayerAnimator* animator = test_controller.animator();
320 test_controller.animator()->set_disable_timer_for_test(true);
321 TestLayerAnimationDelegate delegate;
322 test_controller.animator()->SetDelegate(&delegate);
323 355
324 double start_opacity(0.0); 356 double start_opacity(0.0);
325 double target_opacity(1.0); 357 double target_opacity(1.0);
326 358
327 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 359 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
328 360
329 delegate.SetOpacityFromAnimation(start_opacity); 361 delegate.SetOpacityFromAnimation(start_opacity);
330 362
331 test_controller.animator()->ScheduleAnimation( 363 test_controller.animator()->ScheduleAnimation(
332 new LayerAnimationSequence( 364 new LayerAnimationSequence(
(...skipping 22 matching lines...) Expand all
355 387
356 animator->Step(effective_start + delta); 388 animator->Step(effective_start + delta);
357 389
358 EXPECT_FALSE(test_controller.animator()->is_animating()); 390 EXPECT_FALSE(test_controller.animator()->is_animating());
359 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 391 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
360 } 392 }
361 393
362 // Schedule two non-threaded animations on separate properties. Both animations 394 // Schedule two non-threaded animations on separate properties. Both animations
363 // should start immediately and should progress in lock step. 395 // should start immediately and should progress in lock step.
364 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { 396 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
365 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
366 animator->set_disable_timer_for_test(true);
367 TestLayerAnimationDelegate delegate; 397 TestLayerAnimationDelegate delegate;
368 animator->SetDelegate(&delegate); 398 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
369 399
370 double start_brightness(0.0); 400 double start_brightness(0.0);
371 double middle_brightness(0.5); 401 double middle_brightness(0.5);
372 double target_brightness(1.0); 402 double target_brightness(1.0);
373 403
374 gfx::Rect start_bounds, target_bounds, middle_bounds; 404 gfx::Rect start_bounds, target_bounds, middle_bounds;
375 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 405 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
376 start_bounds.set_x(-90); 406 start_bounds.set_x(-90);
377 target_bounds.set_x(90); 407 target_bounds.set_x(90);
378 408
(...skipping 27 matching lines...) Expand all
406 436
407 EXPECT_FALSE(animator->is_animating()); 437 EXPECT_FALSE(animator->is_animating());
408 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 438 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
409 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 439 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
410 } 440 }
411 441
412 // Schedule a threaded and a non-threaded animation on separate properties. Both 442 // Schedule a threaded and a non-threaded animation on separate properties. Both
413 // animations should progress in lock step. 443 // animations should progress in lock step.
414 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { 444 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
415 double epsilon = 0.00001; 445 double epsilon = 0.00001;
446 TestLayerAnimationDelegate delegate;
416 LayerAnimatorTestController test_controller( 447 LayerAnimatorTestController test_controller(
417 LayerAnimator::CreateDefaultAnimator()); 448 CreateDefaultTestAnimator(&delegate));
418 LayerAnimator* animator = test_controller.animator(); 449 LayerAnimator* animator = test_controller.animator();
419 test_controller.animator()->set_disable_timer_for_test(true);
420 TestLayerAnimationDelegate delegate;
421 test_controller.animator()->SetDelegate(&delegate);
422 450
423 double start_opacity(0.0); 451 double start_opacity(0.0);
424 double target_opacity(1.0); 452 double target_opacity(1.0);
425 453
426 gfx::Rect start_bounds, target_bounds, middle_bounds; 454 gfx::Rect start_bounds, target_bounds, middle_bounds;
427 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 455 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
428 start_bounds.set_x(-90); 456 start_bounds.set_x(-90);
429 target_bounds.set_x(90); 457 target_bounds.set_x(90);
430 458
431 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 459 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 animator->Step(effective_start + delta); 498 animator->Step(effective_start + delta);
471 499
472 EXPECT_FALSE(test_controller.animator()->is_animating()); 500 EXPECT_FALSE(test_controller.animator()->is_animating());
473 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 501 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
474 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 502 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
475 } 503 }
476 504
477 // Schedule two animations on the same property. In this case, the two 505 // Schedule two animations on the same property. In this case, the two
478 // animations should run one after another. 506 // animations should run one after another.
479 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { 507 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
480 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
481 animator->set_disable_timer_for_test(true);
482 TestLayerAnimationDelegate delegate; 508 TestLayerAnimationDelegate delegate;
483 animator->SetDelegate(&delegate); 509 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
484 510
485 double start_brightness(0.0); 511 double start_brightness(0.0);
486 double middle_brightness(0.5); 512 double middle_brightness(0.5);
487 double target_brightness(1.0); 513 double target_brightness(1.0);
488 514
489 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 515 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
490 516
491 delegate.SetBrightnessFromAnimation(start_brightness); 517 delegate.SetBrightnessFromAnimation(start_brightness);
492 518
493 animator->ScheduleAnimation( 519 animator->ScheduleAnimation(
(...skipping 29 matching lines...) Expand all
523 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 549 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
524 550
525 EXPECT_FALSE(animator->is_animating()); 551 EXPECT_FALSE(animator->is_animating());
526 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 552 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
527 } 553 }
528 554
529 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That 555 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That
530 // is, ensure that all animations targetting a particular property are run in 556 // is, ensure that all animations targetting a particular property are run in
531 // order. 557 // order.
532 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { 558 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
533 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
534 animator->set_disable_timer_for_test(true);
535 TestLayerAnimationDelegate delegate; 559 TestLayerAnimationDelegate delegate;
536 animator->SetDelegate(&delegate); 560 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
537 561
538 double start_grayscale(0.0); 562 double start_grayscale(0.0);
539 double middle_grayscale(0.5); 563 double middle_grayscale(0.5);
540 double target_grayscale(1.0); 564 double target_grayscale(1.0);
541 565
542 gfx::Rect start_bounds, target_bounds, middle_bounds; 566 gfx::Rect start_bounds, target_bounds, middle_bounds;
543 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 567 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
544 start_bounds.set_x(-90); 568 start_bounds.set_x(-90);
545 target_bounds.set_x(90); 569 target_bounds.set_x(90);
546 570
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 626
603 EXPECT_FALSE(animator->is_animating()); 627 EXPECT_FALSE(animator->is_animating());
604 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 628 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
605 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 629 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
606 } 630 }
607 631
608 // Schedule {g} and then schedule {g} and {b} together. In this case, since 632 // Schedule {g} and then schedule {g} and {b} together. In this case, since
609 // ScheduleTogether is being used, the bounds animation should not start until 633 // ScheduleTogether is being used, the bounds animation should not start until
610 // the second grayscale animation starts. 634 // the second grayscale animation starts.
611 TEST(LayerAnimatorTest, ScheduleTogether) { 635 TEST(LayerAnimatorTest, ScheduleTogether) {
612 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
613 animator->set_disable_timer_for_test(true);
614 TestLayerAnimationDelegate delegate; 636 TestLayerAnimationDelegate delegate;
615 animator->SetDelegate(&delegate); 637 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
616 638
617 double start_grayscale(0.0); 639 double start_grayscale(0.0);
618 double target_grayscale(1.0); 640 double target_grayscale(1.0);
619 641
620 gfx::Rect start_bounds, target_bounds, middle_bounds; 642 gfx::Rect start_bounds, target_bounds, middle_bounds;
621 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); 643 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50);
622 start_bounds.set_x(-90); 644 start_bounds.set_x(-90);
623 target_bounds.set_x(90); 645 target_bounds.set_x(90);
624 646
625 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 647 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 29 matching lines...) Expand all
655 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 677 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
656 678
657 EXPECT_FALSE(animator->is_animating()); 679 EXPECT_FALSE(animator->is_animating());
658 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 680 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
659 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 681 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
660 } 682 }
661 683
662 // Start non-threaded animation (that can run immediately). This is the trivial 684 // Start non-threaded animation (that can run immediately). This is the trivial
663 // case (see the trival case for ScheduleAnimation). 685 // case (see the trival case for ScheduleAnimation).
664 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { 686 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
665 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
666 animator->set_disable_timer_for_test(true);
667 TestLayerAnimationDelegate delegate; 687 TestLayerAnimationDelegate delegate;
668 animator->SetDelegate(&delegate); 688 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
669 689
670 double start_brightness(0.0); 690 double start_brightness(0.0);
671 double middle_brightness(0.5); 691 double middle_brightness(0.5);
672 double target_brightness(1.0); 692 double target_brightness(1.0);
673 693
674 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 694 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
675 695
676 delegate.SetBrightnessFromAnimation(start_brightness); 696 delegate.SetBrightnessFromAnimation(start_brightness);
677 697
678 animator->StartAnimation( 698 animator->StartAnimation(
(...skipping 13 matching lines...) Expand all
692 712
693 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 713 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
694 714
695 EXPECT_FALSE(animator->is_animating()); 715 EXPECT_FALSE(animator->is_animating());
696 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 716 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
697 } 717 }
698 718
699 // Start threaded animation (that can run immediately). 719 // Start threaded animation (that can run immediately).
700 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { 720 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
701 double epsilon = 0.00001; 721 double epsilon = 0.00001;
722 TestLayerAnimationDelegate delegate;
702 LayerAnimatorTestController test_controller( 723 LayerAnimatorTestController test_controller(
703 LayerAnimator::CreateDefaultAnimator()); 724 CreateDefaultTestAnimator(&delegate));
704 LayerAnimator* animator = test_controller.animator(); 725 LayerAnimator* animator = test_controller.animator();
705 test_controller.animator()->set_disable_timer_for_test(true);
706 TestLayerAnimationDelegate delegate;
707 test_controller.animator()->SetDelegate(&delegate);
708 726
709 double start_opacity(0.0); 727 double start_opacity(0.0);
710 double target_opacity(1.0); 728 double target_opacity(1.0);
711 729
712 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 730 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
713 731
714 delegate.SetOpacityFromAnimation(start_opacity); 732 delegate.SetOpacityFromAnimation(start_opacity);
715 733
716 test_controller.animator()->StartAnimation( 734 test_controller.animator()->StartAnimation(
717 new LayerAnimationSequence( 735 new LayerAnimationSequence(
(...skipping 20 matching lines...) Expand all
738 last_progressed_fraction(), 756 last_progressed_fraction(),
739 epsilon); 757 epsilon);
740 758
741 animator->Step(effective_start + delta); 759 animator->Step(effective_start + delta);
742 EXPECT_FALSE(test_controller.animator()->is_animating()); 760 EXPECT_FALSE(test_controller.animator()->is_animating());
743 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 761 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
744 } 762 }
745 763
746 // Preempt by immediately setting new target. 764 // Preempt by immediately setting new target.
747 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { 765 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
748 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
749 animator->set_disable_timer_for_test(true);
750 TestLayerAnimationDelegate delegate; 766 TestLayerAnimationDelegate delegate;
751 animator->SetDelegate(&delegate); 767 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
752 768
753 double start_opacity(0.0); 769 double start_opacity(0.0);
754 double target_opacity(1.0); 770 double target_opacity(1.0);
755 771
756 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 772 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
757 773
758 delegate.SetOpacityFromAnimation(start_opacity); 774 delegate.SetOpacityFromAnimation(start_opacity);
759 775
760 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 776 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
761 777
762 animator->StartAnimation( 778 animator->StartAnimation(
763 new LayerAnimationSequence( 779 new LayerAnimationSequence(
764 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 780 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
765 781
766 animator->StartAnimation( 782 animator->StartAnimation(
767 new LayerAnimationSequence( 783 new LayerAnimationSequence(
768 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 784 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
769 785
770 EXPECT_FALSE(animator->is_animating()); 786 EXPECT_FALSE(animator->is_animating());
771 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 787 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
772 } 788 }
773 789
774 // Preempt by animating to new target, with a non-threaded animation. 790 // Preempt by animating to new target, with a non-threaded animation.
775 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { 791 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
776 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
777 animator->set_disable_timer_for_test(true);
778 TestLayerAnimationDelegate delegate; 792 TestLayerAnimationDelegate delegate;
779 animator->SetDelegate(&delegate); 793 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
780 794
781 double start_brightness(0.0); 795 double start_brightness(0.0);
782 double middle_brightness(0.5); 796 double middle_brightness(0.5);
783 double target_brightness(1.0); 797 double target_brightness(1.0);
784 798
785 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 799 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
786 800
787 delegate.SetBrightnessFromAnimation(start_brightness); 801 delegate.SetBrightnessFromAnimation(start_brightness);
788 802
789 animator->set_preemption_strategy( 803 animator->set_preemption_strategy(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 835
822 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 836 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
823 837
824 EXPECT_FALSE(animator->is_animating()); 838 EXPECT_FALSE(animator->is_animating());
825 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 839 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
826 } 840 }
827 841
828 // Preempt by animating to new target, with a threaded animation. 842 // Preempt by animating to new target, with a threaded animation.
829 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { 843 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
830 double epsilon = 0.00001; 844 double epsilon = 0.00001;
845 TestLayerAnimationDelegate delegate;
831 LayerAnimatorTestController test_controller( 846 LayerAnimatorTestController test_controller(
832 LayerAnimator::CreateDefaultAnimator()); 847 CreateDefaultTestAnimator(&delegate));
833 LayerAnimator* animator = test_controller.animator(); 848 LayerAnimator* animator = test_controller.animator();
834 test_controller.animator()->set_disable_timer_for_test(true);
835 TestLayerAnimationDelegate delegate;
836 test_controller.animator()->SetDelegate(&delegate);
837 849
838 double start_opacity(0.0); 850 double start_opacity(0.0);
839 double middle_opacity(0.5); 851 double middle_opacity(0.5);
840 double target_opacity(1.0); 852 double target_opacity(1.0);
841 853
842 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 854 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
843 855
844 delegate.SetOpacityFromAnimation(start_opacity); 856 delegate.SetOpacityFromAnimation(start_opacity);
845 857
846 test_controller.animator()->set_preemption_strategy( 858 test_controller.animator()->set_preemption_strategy(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 epsilon); 904 epsilon);
893 905
894 animator->Step(second_effective_start + delta); 906 animator->Step(second_effective_start + delta);
895 907
896 EXPECT_FALSE(test_controller.animator()->is_animating()); 908 EXPECT_FALSE(test_controller.animator()->is_animating());
897 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 909 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
898 } 910 }
899 911
900 // Preempt by enqueuing the new animation. 912 // Preempt by enqueuing the new animation.
901 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { 913 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
902 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
903 animator->set_disable_timer_for_test(true);
904 TestLayerAnimationDelegate delegate; 914 TestLayerAnimationDelegate delegate;
905 animator->SetDelegate(&delegate); 915 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
906 916
907 double start_brightness(0.0); 917 double start_brightness(0.0);
908 double middle_brightness(0.5); 918 double middle_brightness(0.5);
909 double target_brightness(1.0); 919 double target_brightness(1.0);
910 920
911 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 921 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
912 922
913 delegate.SetBrightnessFromAnimation(start_brightness); 923 delegate.SetBrightnessFromAnimation(start_brightness);
914 924
915 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 925 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
(...skipping 30 matching lines...) Expand all
946 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 956 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
947 957
948 EXPECT_FALSE(animator->is_animating()); 958 EXPECT_FALSE(animator->is_animating());
949 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 959 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
950 } 960 }
951 961
952 // Start an animation when there are sequences waiting in the queue. In this 962 // Start an animation when there are sequences waiting in the queue. In this
953 // case, all pending and running animations should be finished, and the new 963 // case, all pending and running animations should be finished, and the new
954 // animation started. 964 // animation started.
955 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { 965 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
956 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
957 animator->set_disable_timer_for_test(true);
958 TestLayerAnimationDelegate delegate; 966 TestLayerAnimationDelegate delegate;
959 animator->SetDelegate(&delegate); 967 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
960 968
961 double start_brightness(0.0); 969 double start_brightness(0.0);
962 double middle_brightness(0.5); 970 double middle_brightness(0.5);
963 double target_brightness(1.0); 971 double target_brightness(1.0);
964 972
965 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 973 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
966 974
967 delegate.SetBrightnessFromAnimation(start_brightness); 975 delegate.SetBrightnessFromAnimation(start_brightness);
968 976
969 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 977 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 EXPECT_TRUE(animator->is_animating()); 1010 EXPECT_TRUE(animator->is_animating());
1003 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1011 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1004 1012
1005 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1013 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1006 1014
1007 EXPECT_FALSE(animator->is_animating()); 1015 EXPECT_FALSE(animator->is_animating());
1008 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1016 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1009 } 1017 }
1010 1018
1011 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { 1019 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
1012 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1013 animator->set_disable_timer_for_test(true);
1014 TestLayerAnimationDelegate delegate; 1020 TestLayerAnimationDelegate delegate;
1015 animator->SetDelegate(&delegate); 1021 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1016 1022
1017 double start_grayscale(0.0); 1023 double start_grayscale(0.0);
1018 double target_grayscale(1.0); 1024 double target_grayscale(1.0);
1019 double start_brightness(0.1); 1025 double start_brightness(0.1);
1020 double target_brightness(0.9); 1026 double target_brightness(0.9);
1021 1027
1022 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1028 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1023 1029
1024 delegate.SetGrayscaleFromAnimation(start_grayscale); 1030 delegate.SetGrayscaleFromAnimation(start_grayscale);
1025 delegate.SetBrightnessFromAnimation(start_brightness); 1031 delegate.SetBrightnessFromAnimation(start_brightness);
(...skipping 15 matching lines...) Expand all
1041 // miniscule (fractions of a millisecond). If set correctly, then the delta 1047 // miniscule (fractions of a millisecond). If set correctly, then the delta
1042 // should be enormous. Arbitrarily choosing 1 minute as the threshold, 1048 // should be enormous. Arbitrarily choosing 1 minute as the threshold,
1043 // though a much smaller value would probably have sufficed. 1049 // though a much smaller value would probably have sufficed.
1044 delta = base::TimeTicks::Now() - animator->last_step_time(); 1050 delta = base::TimeTicks::Now() - animator->last_step_time();
1045 EXPECT_GT(60.0, delta.InSecondsF()); 1051 EXPECT_GT(60.0, delta.InSecondsF());
1046 } 1052 }
1047 1053
1048 //------------------------------------------------------- 1054 //-------------------------------------------------------
1049 // Preempt by immediately setting new target. 1055 // Preempt by immediately setting new target.
1050 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) { 1056 TEST(LayerAnimatorTest, MultiPreemptBySettingNewTarget) {
1051 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1052 animator->set_disable_timer_for_test(true);
1053 TestLayerAnimationDelegate delegate; 1057 TestLayerAnimationDelegate delegate;
1054 animator->SetDelegate(&delegate); 1058 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1055 1059
1056 double start_opacity(0.0); 1060 double start_opacity(0.0);
1057 double target_opacity(1.0); 1061 double target_opacity(1.0);
1058 double start_brightness(0.1); 1062 double start_brightness(0.1);
1059 double target_brightness(0.9); 1063 double target_brightness(0.9);
1060 1064
1061 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1065 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1062 1066
1063 delegate.SetOpacityFromAnimation(start_opacity); 1067 delegate.SetOpacityFromAnimation(start_opacity);
1064 delegate.SetBrightnessFromAnimation(start_brightness); 1068 delegate.SetBrightnessFromAnimation(start_brightness);
(...skipping 14 matching lines...) Expand all
1079 delta) 1083 delta)
1080 )); 1084 ));
1081 1085
1082 EXPECT_FALSE(animator->is_animating()); 1086 EXPECT_FALSE(animator->is_animating());
1083 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1087 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1084 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1088 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1085 } 1089 }
1086 1090
1087 // Preempt by animating to new target. 1091 // Preempt by animating to new target.
1088 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { 1092 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
1089 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1090 animator->set_disable_timer_for_test(true);
1091 TestLayerAnimationDelegate delegate; 1093 TestLayerAnimationDelegate delegate;
1092 animator->SetDelegate(&delegate); 1094 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1093 1095
1094 double start_grayscale(0.0); 1096 double start_grayscale(0.0);
1095 double middle_grayscale(0.5); 1097 double middle_grayscale(0.5);
1096 double target_grayscale(1.0); 1098 double target_grayscale(1.0);
1097 1099
1098 double start_brightness(0.1); 1100 double start_brightness(0.1);
1099 double middle_brightness(0.2); 1101 double middle_brightness(0.2);
1100 double target_brightness(0.3); 1102 double target_brightness(0.3);
1101 1103
1102 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1104 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1150 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1149 1151
1150 EXPECT_FALSE(animator->is_animating()); 1152 EXPECT_FALSE(animator->is_animating());
1151 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1153 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1152 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1154 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1153 } 1155 }
1154 1156
1155 // Preempt a threaded animation by animating to new target. 1157 // Preempt a threaded animation by animating to new target.
1156 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { 1158 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
1157 double epsilon = 0.00001; 1159 double epsilon = 0.00001;
1160 TestLayerAnimationDelegate delegate;
1158 LayerAnimatorTestController test_controller( 1161 LayerAnimatorTestController test_controller(
1159 LayerAnimator::CreateDefaultAnimator()); 1162 CreateDefaultTestAnimator(&delegate));
1160 LayerAnimator* animator = test_controller.animator(); 1163 LayerAnimator* animator = test_controller.animator();
1161 test_controller.animator()->set_disable_timer_for_test(true);
1162 TestLayerAnimationDelegate delegate;
1163 test_controller.animator()->SetDelegate(&delegate);
1164 1164
1165 double start_opacity(0.0); 1165 double start_opacity(0.0);
1166 double middle_opacity(0.5); 1166 double middle_opacity(0.5);
1167 double target_opacity(1.0); 1167 double target_opacity(1.0);
1168 1168
1169 double start_brightness(0.1); 1169 double start_brightness(0.1);
1170 double middle_brightness(0.2); 1170 double middle_brightness(0.2);
1171 double target_brightness(0.3); 1171 double target_brightness(0.3);
1172 1172
1173 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1173 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1236
1237 animator->Step(second_effective_start + delta); 1237 animator->Step(second_effective_start + delta);
1238 1238
1239 EXPECT_FALSE(test_controller.animator()->is_animating()); 1239 EXPECT_FALSE(test_controller.animator()->is_animating());
1240 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1240 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1241 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1241 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1242 } 1242 }
1243 1243
1244 // Preempt by enqueuing the new animation. 1244 // Preempt by enqueuing the new animation.
1245 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { 1245 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
1246 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1247 animator->set_disable_timer_for_test(true);
1248 TestLayerAnimationDelegate delegate; 1246 TestLayerAnimationDelegate delegate;
1249 animator->SetDelegate(&delegate); 1247 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1250 1248
1251 double start_grayscale(0.0); 1249 double start_grayscale(0.0);
1252 double middle_grayscale(0.5); 1250 double middle_grayscale(0.5);
1253 double target_grayscale(1.0); 1251 double target_grayscale(1.0);
1254 1252
1255 double start_brightness(0.1); 1253 double start_brightness(0.1);
1256 double middle_brightness(0.2); 1254 double middle_brightness(0.2);
1257 double target_brightness(0.3); 1255 double target_brightness(0.3);
1258 1256
1259 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1257 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 1300
1303 EXPECT_FALSE(animator->is_animating()); 1301 EXPECT_FALSE(animator->is_animating());
1304 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1302 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1305 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1303 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1306 } 1304 }
1307 1305
1308 // Start an animation when there are sequences waiting in the queue. In this 1306 // Start an animation when there are sequences waiting in the queue. In this
1309 // case, all pending and running animations should be finished, and the new 1307 // case, all pending and running animations should be finished, and the new
1310 // animation started. 1308 // animation started.
1311 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { 1309 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
1312 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1313 animator->set_disable_timer_for_test(true);
1314 TestLayerAnimationDelegate delegate; 1310 TestLayerAnimationDelegate delegate;
1315 animator->SetDelegate(&delegate); 1311 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1316 1312
1317 double start_grayscale(0.0); 1313 double start_grayscale(0.0);
1318 double middle_grayscale(0.5); 1314 double middle_grayscale(0.5);
1319 double target_grayscale(1.0); 1315 double target_grayscale(1.0);
1320 1316
1321 double start_brightness(0.1); 1317 double start_brightness(0.1);
1322 double middle_brightness(0.2); 1318 double middle_brightness(0.2);
1323 double target_brightness(0.3); 1319 double target_brightness(0.3);
1324 1320
1325 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1321 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 1369
1374 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1370 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1375 1371
1376 EXPECT_FALSE(animator->is_animating()); 1372 EXPECT_FALSE(animator->is_animating());
1377 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1373 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1378 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1374 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1379 } 1375 }
1380 //------------------------------------------------------- 1376 //-------------------------------------------------------
1381 // Test that non-threaded cyclic sequences continue to animate. 1377 // Test that non-threaded cyclic sequences continue to animate.
1382 TEST(LayerAnimatorTest, CyclicSequences) { 1378 TEST(LayerAnimatorTest, CyclicSequences) {
1383 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1384 animator->set_disable_timer_for_test(true);
1385 TestLayerAnimationDelegate delegate; 1379 TestLayerAnimationDelegate delegate;
1386 animator->SetDelegate(&delegate); 1380 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1387 1381
1388 double start_brightness(0.0); 1382 double start_brightness(0.0);
1389 double target_brightness(1.0); 1383 double target_brightness(1.0);
1390 1384
1391 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1385 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1392 1386
1393 delegate.SetBrightnessFromAnimation(start_brightness); 1387 delegate.SetBrightnessFromAnimation(start_brightness);
1394 1388
1395 scoped_ptr<LayerAnimationSequence> sequence( 1389 scoped_ptr<LayerAnimationSequence> sequence(
1396 new LayerAnimationSequence( 1390 new LayerAnimationSequence(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 EXPECT_TRUE(animator->is_animating()); 1427 EXPECT_TRUE(animator->is_animating());
1434 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1428 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1435 1429
1436 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); 1430 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS);
1437 1431
1438 EXPECT_FALSE(animator->is_animating()); 1432 EXPECT_FALSE(animator->is_animating());
1439 } 1433 }
1440 1434
1441 // Test that threaded cyclic sequences continue to animate. 1435 // Test that threaded cyclic sequences continue to animate.
1442 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { 1436 TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
1437 TestLayerAnimationDelegate delegate;
1443 LayerAnimatorTestController test_controller( 1438 LayerAnimatorTestController test_controller(
1444 LayerAnimator::CreateDefaultAnimator()); 1439 CreateDefaultTestAnimator(&delegate));
1445 LayerAnimator* animator = test_controller.animator(); 1440 LayerAnimator* animator = test_controller.animator();
1446 test_controller.animator()->set_disable_timer_for_test(true);
1447 TestLayerAnimationDelegate delegate;
1448 test_controller.animator()->SetDelegate(&delegate);
1449 1441
1450 double start_opacity(0.0); 1442 double start_opacity(0.0);
1451 double target_opacity(1.0); 1443 double target_opacity(1.0);
1452 1444
1453 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1445 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1454 1446
1455 delegate.SetOpacityFromAnimation(start_opacity); 1447 delegate.SetOpacityFromAnimation(start_opacity);
1456 1448
1457 scoped_ptr<LayerAnimationSequence> sequence( 1449 scoped_ptr<LayerAnimationSequence> sequence(
1458 new LayerAnimationSequence( 1450 new LayerAnimationSequence(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 EXPECT_TRUE(test_controller.animator()->is_animating()); 1519 EXPECT_TRUE(test_controller.animator()->is_animating());
1528 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1520 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1529 1521
1530 test_controller.animator()->StopAnimatingProperty( 1522 test_controller.animator()->StopAnimatingProperty(
1531 LayerAnimationElement::OPACITY); 1523 LayerAnimationElement::OPACITY);
1532 1524
1533 EXPECT_FALSE(test_controller.animator()->is_animating()); 1525 EXPECT_FALSE(test_controller.animator()->is_animating());
1534 } 1526 }
1535 1527
1536 TEST(LayerAnimatorTest, AddObserverExplicit) { 1528 TEST(LayerAnimatorTest, AddObserverExplicit) {
1537 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1538 animator->set_disable_timer_for_test(true);
1539 TestLayerAnimationObserver observer; 1529 TestLayerAnimationObserver observer;
1540 TestLayerAnimationDelegate delegate; 1530 TestLayerAnimationDelegate delegate;
1541 animator->SetDelegate(&delegate); 1531 scoped_refptr<LayerAnimator> animator(
1542 animator->AddObserver(&observer); 1532 CreateDefaultTestAnimator(&delegate, &observer));
1543 observer.set_requires_notification_when_animator_destroyed(true); 1533 observer.set_requires_notification_when_animator_destroyed(true);
1544 1534
1545 EXPECT_TRUE(!observer.last_ended_sequence()); 1535 EXPECT_TRUE(!observer.last_ended_sequence());
1546 1536
1547 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1537 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1548 1538
1549 delegate.SetBrightnessFromAnimation(0.0f); 1539 delegate.SetBrightnessFromAnimation(0.0f);
1550 1540
1551 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1541 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1552 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1542 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
(...skipping 15 matching lines...) Expand all
1568 animator->StartAnimation(sequence); 1558 animator->StartAnimation(sequence);
1569 1559
1570 animator = NULL; 1560 animator = NULL;
1571 1561
1572 EXPECT_EQ(observer.last_aborted_sequence(), sequence); 1562 EXPECT_EQ(observer.last_aborted_sequence(), sequence);
1573 } 1563 }
1574 1564
1575 // Tests that an observer added to a scoped settings object is still notified 1565 // Tests that an observer added to a scoped settings object is still notified
1576 // when the object goes out of scope. 1566 // when the object goes out of scope.
1577 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { 1567 TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
1578 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1568 TestLayerAnimationDelegate delegate;
1579 animator->set_disable_timer_for_test(true); 1569 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1580 TestImplicitAnimationObserver observer(false); 1570 TestImplicitAnimationObserver observer(false);
1581 TestLayerAnimationDelegate delegate;
1582 animator->SetDelegate(&delegate);
1583 1571
1584 EXPECT_FALSE(observer.animations_completed()); 1572 EXPECT_FALSE(observer.animations_completed());
1585 animator->SetBrightness(1.0f); 1573 animator->SetBrightness(1.0f);
1586 1574
1587 { 1575 {
1588 ScopedLayerAnimationSettings settings(animator.get()); 1576 ScopedLayerAnimationSettings settings(animator.get());
1589 settings.AddObserver(&observer); 1577 settings.AddObserver(&observer);
1590 animator->SetBrightness(0.0f); 1578 animator->SetBrightness(0.0f);
1591 } 1579 }
1592 1580
1593 EXPECT_FALSE(observer.animations_completed()); 1581 EXPECT_FALSE(observer.animations_completed());
1594 base::TimeTicks start_time = animator->last_step_time(); 1582 base::TimeTicks start_time = animator->last_step_time();
1595 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1583 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1596 EXPECT_TRUE(observer.animations_completed()); 1584 EXPECT_TRUE(observer.animations_completed());
1597 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( 1585 EXPECT_TRUE(observer.WasAnimationCompletedForProperty(
1598 LayerAnimationElement::BRIGHTNESS)); 1586 LayerAnimationElement::BRIGHTNESS));
1599 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); 1587 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation());
1600 } 1588 }
1601 1589
1602 // Tests that an observer added to a scoped settings object is still notified 1590 // Tests that an observer added to a scoped settings object is still notified
1603 // when the object goes out of scope due to the animation being interrupted. 1591 // when the object goes out of scope due to the animation being interrupted.
1604 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { 1592 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
1605 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1593 TestLayerAnimationDelegate delegate;
1606 animator->set_disable_timer_for_test(true); 1594 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1607 TestImplicitAnimationObserver observer(false); 1595 TestImplicitAnimationObserver observer(false);
1608 TestLayerAnimationDelegate delegate;
1609 animator->SetDelegate(&delegate);
1610 1596
1611 EXPECT_FALSE(observer.animations_completed()); 1597 EXPECT_FALSE(observer.animations_completed());
1612 animator->SetBrightness(1.0f); 1598 animator->SetBrightness(1.0f);
1613 1599
1614 { 1600 {
1615 ScopedLayerAnimationSettings settings(animator.get()); 1601 ScopedLayerAnimationSettings settings(animator.get());
1616 settings.AddObserver(&observer); 1602 settings.AddObserver(&observer);
1617 animator->SetBrightness(0.0f); 1603 animator->SetBrightness(0.0f);
1618 } 1604 }
1619 1605
(...skipping 26 matching lines...) Expand all
1646 animator->Step(now + base::TimeDelta::FromSeconds(1)); 1632 animator->Step(now + base::TimeDelta::FromSeconds(1));
1647 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); 1633 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted());
1648 } 1634 }
1649 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. 1635 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted.
1650 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); 1636 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted());
1651 } 1637 }
1652 1638
1653 // Tests that an observer added to a scoped settings object is not notified 1639 // Tests that an observer added to a scoped settings object is not notified
1654 // when the animator is destroyed unless explicitly requested. 1640 // when the animator is destroyed unless explicitly requested.
1655 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { 1641 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
1656 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1642 TestLayerAnimationDelegate delegate;
1657 animator->set_disable_timer_for_test(true); 1643 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1658 TestImplicitAnimationObserver observer_notify(true); 1644 TestImplicitAnimationObserver observer_notify(true);
1659 TestImplicitAnimationObserver observer_do_not_notify(false); 1645 TestImplicitAnimationObserver observer_do_not_notify(false);
1660 TestLayerAnimationDelegate delegate;
1661 animator->SetDelegate(&delegate);
1662 1646
1663 EXPECT_FALSE(observer_notify.animations_completed()); 1647 EXPECT_FALSE(observer_notify.animations_completed());
1664 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1648 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1665 1649
1666 animator->SetBrightness(1.0f); 1650 animator->SetBrightness(1.0f);
1667 1651
1668 { 1652 {
1669 ScopedLayerAnimationSettings settings(animator.get()); 1653 ScopedLayerAnimationSettings settings(animator.get());
1670 settings.AddObserver(&observer_notify); 1654 settings.AddObserver(&observer_notify);
1671 settings.AddObserver(&observer_do_not_notify); 1655 settings.AddObserver(&observer_do_not_notify);
1672 animator->SetBrightness(0.0f); 1656 animator->SetBrightness(0.0f);
1673 } 1657 }
1674 1658
1675 EXPECT_FALSE(observer_notify.animations_completed()); 1659 EXPECT_FALSE(observer_notify.animations_completed());
1676 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1660 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1677 animator = NULL; 1661 animator = NULL;
1678 EXPECT_TRUE(observer_notify.animations_completed()); 1662 EXPECT_TRUE(observer_notify.animations_completed());
1679 EXPECT_TRUE(observer_notify.WasAnimationAbortedForProperty( 1663 EXPECT_TRUE(observer_notify.WasAnimationAbortedForProperty(
1680 LayerAnimationElement::BRIGHTNESS)); 1664 LayerAnimationElement::BRIGHTNESS));
1681 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1665 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1682 } 1666 }
1683 1667
1684 TEST(LayerAnimatorTest, AbortedAnimationStatusInImplicitObservers) { 1668 TEST(LayerAnimatorTest, AbortedAnimationStatusInImplicitObservers) {
1685 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1669 TestLayerAnimationDelegate delegate;
1686 animator->set_disable_timer_for_test(true); 1670 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1687 TestImplicitAnimationObserver observer(false); 1671 TestImplicitAnimationObserver observer(false);
1688 TestLayerAnimationDelegate delegate;
1689 animator->SetDelegate(&delegate);
1690 1672
1691 EXPECT_FALSE(observer.animations_completed()); 1673 EXPECT_FALSE(observer.animations_completed());
1692 animator->SetBrightness(1.0f); 1674 animator->SetBrightness(1.0f);
1693 1675
1694 { 1676 {
1695 ScopedLayerAnimationSettings settings(animator.get()); 1677 ScopedLayerAnimationSettings settings(animator.get());
1696 settings.AddObserver(&observer); 1678 settings.AddObserver(&observer);
1697 animator->SetBrightness(0.0f); 1679 animator->SetBrightness(0.0f);
1698 } 1680 }
1699 EXPECT_FALSE(observer.animations_completed()); 1681 EXPECT_FALSE(observer.animations_completed());
(...skipping 15 matching lines...) Expand all
1715 1697
1716 animator->AbortAllAnimations(); 1698 animator->AbortAllAnimations();
1717 EXPECT_TRUE(observer.animations_completed()); 1699 EXPECT_TRUE(observer.animations_completed());
1718 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( 1700 EXPECT_TRUE(observer.WasAnimationAbortedForProperty(
1719 LayerAnimationElement::BRIGHTNESS)); 1701 LayerAnimationElement::BRIGHTNESS));
1720 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( 1702 EXPECT_TRUE(observer.WasAnimationAbortedForProperty(
1721 LayerAnimationElement::OPACITY)); 1703 LayerAnimationElement::OPACITY));
1722 } 1704 }
1723 1705
1724 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { 1706 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
1725 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1707 TestLayerAnimationDelegate delegate;
1726 animator->set_disable_timer_for_test(true); 1708 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1727 TestLayerAnimationObserver observer; 1709 TestLayerAnimationObserver observer;
1728 TestLayerAnimationObserver removed_observer; 1710 TestLayerAnimationObserver removed_observer;
1729 TestLayerAnimationDelegate delegate;
1730 animator->SetDelegate(&delegate);
1731 1711
1732 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1712 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1733 1713
1734 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1714 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1735 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1715 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1736 1716
1737 sequence->AddObserver(&observer); 1717 sequence->AddObserver(&observer);
1738 sequence->AddObserver(&removed_observer); 1718 sequence->AddObserver(&removed_observer);
1739 1719
1740 animator->StartAnimation(sequence); 1720 animator->StartAnimation(sequence);
1741 1721
1742 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 1722 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
1743 EXPECT_TRUE(!observer.last_ended_sequence()); 1723 EXPECT_TRUE(!observer.last_ended_sequence());
1744 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); 1724 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence);
1745 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 1725 EXPECT_TRUE(!removed_observer.last_ended_sequence());
1746 1726
1747 // This should stop the observer from observing sequence. 1727 // This should stop the observer from observing sequence.
1748 animator->RemoveObserver(&removed_observer); 1728 animator->RemoveObserver(&removed_observer);
1749 1729
1750 base::TimeTicks start_time = animator->last_step_time(); 1730 base::TimeTicks start_time = animator->last_step_time();
1751 1731
1752 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1732 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1753 1733
1754 EXPECT_EQ(observer.last_ended_sequence(), sequence); 1734 EXPECT_EQ(observer.last_ended_sequence(), sequence);
1755 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 1735 EXPECT_TRUE(!removed_observer.last_ended_sequence());
1756 } 1736 }
1757 1737
1758 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { 1738 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
1759 TestLayerAnimationDelegate delegate; 1739 TestLayerAnimationDelegate delegate;
1760 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1761 animator->set_disable_timer_for_test(true);
1762
1763 scoped_ptr<TestLayerAnimationObserver> observer( 1740 scoped_ptr<TestLayerAnimationObserver> observer(
1764 new TestLayerAnimationObserver); 1741 new TestLayerAnimationObserver);
1765 animator->SetDelegate(&delegate); 1742 scoped_refptr<LayerAnimator> animator(
1766 animator->AddObserver(observer.get()); 1743 CreateDefaultTestAnimator(&delegate, observer.get()));
1767 1744
1768 delegate.SetOpacityFromAnimation(0.0f); 1745 delegate.SetOpacityFromAnimation(0.0f);
1769 1746
1770 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1747 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1771 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1748 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1772 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1749 LayerAnimationElement::CreateOpacityElement(1.0f, delta));
1773 1750
1774 animator->StartAnimation(sequence); 1751 animator->StartAnimation(sequence);
1775 1752
1776 // |observer| should be attached to |sequence|. 1753 // |observer| should be attached to |sequence|.
1777 EXPECT_TRUE(sequence->observers_.might_have_observers()); 1754 EXPECT_TRUE(sequence->observers_.might_have_observers());
1778 1755
1779 // Now, release |observer| 1756 // Now, release |observer|
1780 observer.reset(); 1757 observer.reset();
1781 1758
1782 // And |sequence| should no longer be attached to |observer|. 1759 // And |sequence| should no longer be attached to |observer|.
1783 EXPECT_FALSE(sequence->observers_.might_have_observers()); 1760 EXPECT_FALSE(sequence->observers_.might_have_observers());
1784 } 1761 }
1785 1762
1786 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { 1763 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
1787 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1764 TestLayerAnimationDelegate delegate;
1788 animator->set_disable_timer_for_test(true); 1765 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1789 1766
1790 TestImplicitAnimationObserver observer(false); 1767 TestImplicitAnimationObserver observer(false);
1791 TestLayerAnimationDelegate delegate;
1792 animator->SetDelegate(&delegate);
1793 1768
1794 delegate.SetBrightnessFromAnimation(0.0f); 1769 delegate.SetBrightnessFromAnimation(0.0f);
1795 1770
1796 { 1771 {
1797 ScopedLayerAnimationSettings setter(animator.get()); 1772 ScopedLayerAnimationSettings setter(animator.get());
1798 1773
1799 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1774 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1800 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1775 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1801 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1776 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1802 1777
1803 animator->StartAnimation(sequence); 1778 animator->StartAnimation(sequence);
1804 base::TimeTicks start_time = animator->last_step_time(); 1779 base::TimeTicks start_time = animator->last_step_time();
1805 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1780 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1806 1781
1807 setter.AddObserver(&observer); 1782 setter.AddObserver(&observer);
1808 1783
1809 // Start observing an in-flight animation. 1784 // Start observing an in-flight animation.
1810 sequence->AddObserver(&observer); 1785 sequence->AddObserver(&observer);
1811 1786
1812 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1787 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1813 } 1788 }
1814 1789
1815 EXPECT_TRUE(observer.animations_completed()); 1790 EXPECT_TRUE(observer.animations_completed());
1816 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( 1791 EXPECT_TRUE(observer.WasAnimationCompletedForProperty(
1817 LayerAnimationElement::BRIGHTNESS)); 1792 LayerAnimationElement::BRIGHTNESS));
1818 } 1793 }
1819 1794
1820 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { 1795 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
1821 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1796 TestLayerAnimationDelegate delegate;
1822 animator->set_disable_timer_for_test(true); 1797 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
1823 1798
1824 TestImplicitAnimationObserver observer(false); 1799 TestImplicitAnimationObserver observer(false);
1825 TestLayerAnimationDelegate delegate;
1826 animator->SetDelegate(&delegate);
1827 1800
1828 delegate.SetBrightnessFromAnimation(0.0f); 1801 delegate.SetBrightnessFromAnimation(0.0f);
1829 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1802 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1830 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1803 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1831 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1804 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1832 1805
1833 { 1806 {
1834 ScopedLayerAnimationSettings setter(animator.get()); 1807 ScopedLayerAnimationSettings setter(animator.get());
1835 setter.AddObserver(&observer); 1808 setter.AddObserver(&observer);
1836 1809
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 // brightness animation. |observer| should have stopped the bounds animation 1983 // brightness animation. |observer| should have stopped the bounds animation
2011 // as a result. 1984 // as a result.
2012 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1985 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2013 1986
2014 animator->RemoveObserver(observer.get()); 1987 animator->RemoveObserver(observer.get());
2015 } 1988 }
2016 1989
2017 // Check that setting a property during an animation with a default animator 1990 // Check that setting a property during an animation with a default animator
2018 // cancels the original animation. 1991 // cancels the original animation.
2019 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { 1992 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
2020 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
2021 animator->set_disable_timer_for_test(true);
2022 TestLayerAnimationDelegate delegate; 1993 TestLayerAnimationDelegate delegate;
2023 animator->SetDelegate(&delegate); 1994 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2024 1995
2025 double start_opacity(0.0); 1996 double start_opacity(0.0);
2026 double target_opacity(1.0); 1997 double target_opacity(1.0);
2027 1998
2028 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1999 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2029 2000
2030 delegate.SetOpacityFromAnimation(start_opacity); 2001 delegate.SetOpacityFromAnimation(start_opacity);
2031 2002
2032 scoped_ptr<LayerAnimationSequence> sequence( 2003 scoped_ptr<LayerAnimationSequence> sequence(
2033 new LayerAnimationSequence( 2004 new LayerAnimationSequence(
2034 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 2005 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
2035 2006
2036 animator->StartAnimation(sequence.release()); 2007 animator->StartAnimation(sequence.release());
2037 2008
2038 animator->SetOpacity(0.5); 2009 animator->SetOpacity(0.5);
2039 2010
2040 EXPECT_FALSE(animator->is_animating()); 2011 EXPECT_FALSE(animator->is_animating());
2041 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 2012 EXPECT_EQ(0.5, animator->GetTargetOpacity());
2042 } 2013 }
2043 2014
2044 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the 2015 // Tests that the preemption mode IMMEDIATELY_SET_NEW_TARGET, doesn't cause the
2045 // second sequence to be leaked. 2016 // second sequence to be leaked.
2046 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) { 2017 TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
2047 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2018 TestLayerAnimationDelegate delegate;
2019 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2048 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 2020 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
2049 animator->set_disable_timer_for_test(true);
2050 TestLayerAnimationDelegate delegate;
2051 animator->SetDelegate(&delegate);
2052 2021
2053 gfx::Rect start_bounds(0, 0, 50, 50); 2022 gfx::Rect start_bounds(0, 0, 50, 50);
2054 gfx::Rect middle_bounds(10, 10, 100, 100); 2023 gfx::Rect middle_bounds(10, 10, 100, 100);
2055 gfx::Rect target_bounds(5, 5, 5, 5); 2024 gfx::Rect target_bounds(5, 5, 5, 5);
2056 2025
2057 delegate.SetBoundsFromAnimation(start_bounds); 2026 delegate.SetBoundsFromAnimation(start_bounds);
2058 2027
2059 { 2028 {
2060 // start an implicit bounds animation. 2029 // start an implicit bounds animation.
2061 ScopedLayerAnimationSettings settings(animator.get()); 2030 ScopedLayerAnimationSettings settings(animator.get());
(...skipping 16 matching lines...) Expand all
2078 animator->StartAnimation(sequence.release()); 2047 animator->StartAnimation(sequence.release());
2079 2048
2080 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 2049 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2081 EXPECT_EQ(0, num_live_instances); 2050 EXPECT_EQ(0, num_live_instances);
2082 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 2051 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
2083 } 2052 }
2084 2053
2085 // Verifies GetTargetOpacity() works when multiple sequences are scheduled. 2054 // Verifies GetTargetOpacity() works when multiple sequences are scheduled.
2086 TEST(LayerAnimatorTest, GetTargetOpacity) { 2055 TEST(LayerAnimatorTest, GetTargetOpacity) {
2087 TestLayerAnimationDelegate delegate; 2056 TestLayerAnimationDelegate delegate;
2088 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2057 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2089 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 2058 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
2090 animator->set_disable_timer_for_test(true);
2091 animator->SetDelegate(&delegate);
2092 2059
2093 delegate.SetOpacityFromAnimation(0.0); 2060 delegate.SetOpacityFromAnimation(0.0);
2094 2061
2095 { 2062 {
2096 ScopedLayerAnimationSettings settings(animator.get()); 2063 ScopedLayerAnimationSettings settings(animator.get());
2097 animator->SetOpacity(0.5); 2064 animator->SetOpacity(0.5);
2098 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 2065 EXPECT_EQ(0.5, animator->GetTargetOpacity());
2099 2066
2100 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. 2067 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1.
2101 animator->SetOpacity(1.0); 2068 animator->SetOpacity(1.0);
2102 EXPECT_EQ(1.0, animator->GetTargetOpacity()); 2069 EXPECT_EQ(1.0, animator->GetTargetOpacity());
2103 } 2070 }
2104 } 2071 }
2105 2072
2106 // Verifies GetTargetBrightness() works when multiple sequences are scheduled. 2073 // Verifies GetTargetBrightness() works when multiple sequences are scheduled.
2107 TEST(LayerAnimatorTest, GetTargetBrightness) { 2074 TEST(LayerAnimatorTest, GetTargetBrightness) {
2108 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2075 TestLayerAnimationDelegate delegate;
2076 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2109 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 2077 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
2110 animator->set_disable_timer_for_test(true);
2111 TestLayerAnimationDelegate delegate;
2112 animator->SetDelegate(&delegate);
2113 2078
2114 delegate.SetBrightnessFromAnimation(0.0); 2079 delegate.SetBrightnessFromAnimation(0.0);
2115 2080
2116 { 2081 {
2117 ScopedLayerAnimationSettings settings(animator.get()); 2082 ScopedLayerAnimationSettings settings(animator.get());
2118 animator->SetBrightness(0.5); 2083 animator->SetBrightness(0.5);
2119 EXPECT_EQ(0.5, animator->GetTargetBrightness()); 2084 EXPECT_EQ(0.5, animator->GetTargetBrightness());
2120 2085
2121 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. 2086 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1.
2122 animator->SetBrightness(1.0); 2087 animator->SetBrightness(1.0);
2123 EXPECT_EQ(1.0, animator->GetTargetBrightness()); 2088 EXPECT_EQ(1.0, animator->GetTargetBrightness());
2124 } 2089 }
2125 } 2090 }
2126 2091
2127 // Verifies GetTargetGrayscale() works when multiple sequences are scheduled. 2092 // Verifies GetTargetGrayscale() works when multiple sequences are scheduled.
2128 TEST(LayerAnimatorTest, GetTargetGrayscale) { 2093 TEST(LayerAnimatorTest, GetTargetGrayscale) {
2129 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2094 TestLayerAnimationDelegate delegate;
2095 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2130 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 2096 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
2131 animator->set_disable_timer_for_test(true);
2132 TestLayerAnimationDelegate delegate;
2133 animator->SetDelegate(&delegate);
2134 2097
2135 delegate.SetGrayscaleFromAnimation(0.0); 2098 delegate.SetGrayscaleFromAnimation(0.0);
2136 2099
2137 { 2100 {
2138 ScopedLayerAnimationSettings settings(animator.get()); 2101 ScopedLayerAnimationSettings settings(animator.get());
2139 animator->SetGrayscale(0.5); 2102 animator->SetGrayscale(0.5);
2140 EXPECT_EQ(0.5, animator->GetTargetGrayscale()); 2103 EXPECT_EQ(0.5, animator->GetTargetGrayscale());
2141 2104
2142 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. 2105 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1.
2143 animator->SetGrayscale(1.0); 2106 animator->SetGrayscale(1.0);
2144 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); 2107 EXPECT_EQ(1.0, animator->GetTargetGrayscale());
2145 } 2108 }
2146 } 2109 }
2147 2110
2148 // Verifies color property is modified appropriately. 2111 // Verifies color property is modified appropriately.
2149 TEST(LayerAnimatorTest, Color) { 2112 TEST(LayerAnimatorTest, Color) {
2150 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
2151 animator->set_disable_timer_for_test(true);
2152 TestLayerAnimationDelegate delegate; 2113 TestLayerAnimationDelegate delegate;
2153 animator->SetDelegate(&delegate); 2114 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2154 2115
2155 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); 2116 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60);
2156 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); 2117 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120);
2157 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); 2118 SkColor target_color = SkColorSetARGB(192, 40, 80, 140);
2158 2119
2159 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2120 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2160 2121
2161 delegate.SetColorFromAnimation(start_color); 2122 delegate.SetColorFromAnimation(start_color);
2162 2123
2163 animator->ScheduleAnimation( 2124 animator->ScheduleAnimation(
(...skipping 14 matching lines...) Expand all
2178 2139
2179 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2140 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2180 2141
2181 EXPECT_FALSE(animator->is_animating()); 2142 EXPECT_FALSE(animator->is_animating());
2182 EXPECT_EQ(ColorToString(target_color), 2143 EXPECT_EQ(ColorToString(target_color),
2183 ColorToString(delegate.GetColorForAnimation())); 2144 ColorToString(delegate.GetColorForAnimation()));
2184 } 2145 }
2185 2146
2186 // Verifies SchedulePauseForProperties(). 2147 // Verifies SchedulePauseForProperties().
2187 TEST(LayerAnimatorTest, SchedulePauseForProperties) { 2148 TEST(LayerAnimatorTest, SchedulePauseForProperties) {
2188 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2149 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator());
2189 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 2150 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
2190 animator->SchedulePauseForProperties( 2151 animator->SchedulePauseForProperties(
2191 base::TimeDelta::FromMilliseconds(100), 2152 base::TimeDelta::FromMilliseconds(100),
2192 LayerAnimationElement::TRANSFORM | LayerAnimationElement::BOUNDS); 2153 LayerAnimationElement::TRANSFORM | LayerAnimationElement::BOUNDS);
2193 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::TRANSFORM)); 2154 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::TRANSFORM));
2194 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 2155 EXPECT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2195 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::OPACITY)); 2156 EXPECT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::OPACITY));
2196 } 2157 }
2197 2158
2198 2159
2199 class AnimatorOwner { 2160 class AnimatorOwner {
2200 public: 2161 public:
2201 AnimatorOwner() 2162 AnimatorOwner() : animator_(CreateDefaultTestAnimator()) {}
2202 : animator_(LayerAnimator::CreateDefaultAnimator()) {
2203 }
2204 2163
2205 LayerAnimator* animator() { return animator_.get(); } 2164 LayerAnimator* animator() { return animator_.get(); }
2206 2165
2207 private: 2166 private:
2208 scoped_refptr<LayerAnimator> animator_; 2167 scoped_refptr<LayerAnimator> animator_;
2209 2168
2210 DISALLOW_COPY_AND_ASSIGN(AnimatorOwner); 2169 DISALLOW_COPY_AND_ASSIGN(AnimatorOwner);
2211 }; 2170 };
2212 2171
2213 class DeletingObserver : public LayerAnimationObserver { 2172 class DeletingObserver : public LayerAnimationObserver {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 2233
2275 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); 2234 DISALLOW_COPY_AND_ASSIGN(DeletingObserver);
2276 }; 2235 };
2277 2236
2278 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { 2237 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) {
2279 bool observer_was_deleted = false; 2238 bool observer_was_deleted = false;
2280 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2239 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2281 observer->set_delete_on_animation_ended(true); 2240 observer->set_delete_on_animation_ended(true);
2282 observer->set_delete_on_animation_aborted(true); 2241 observer->set_delete_on_animation_aborted(true);
2283 LayerAnimator* animator = observer->animator(); 2242 LayerAnimator* animator = observer->animator();
2284 animator->set_disable_timer_for_test(true);
2285 TestLayerAnimationDelegate delegate; 2243 TestLayerAnimationDelegate delegate;
2286 animator->SetDelegate(&delegate); 2244 animator->SetDelegate(&delegate);
2287 2245
2288 delegate.SetBrightnessFromAnimation(0.0f); 2246 delegate.SetBrightnessFromAnimation(0.0f);
2289 2247
2290 gfx::Rect start_bounds(0, 0, 50, 50); 2248 gfx::Rect start_bounds(0, 0, 50, 50);
2291 gfx::Rect target_bounds(10, 10, 100, 100); 2249 gfx::Rect target_bounds(10, 10, 100, 100);
2292 2250
2293 delegate.SetBoundsFromAnimation(start_bounds); 2251 delegate.SetBoundsFromAnimation(start_bounds);
2294 2252
(...skipping 12 matching lines...) Expand all
2307 2265
2308 EXPECT_TRUE(observer_was_deleted); 2266 EXPECT_TRUE(observer_was_deleted);
2309 } 2267 }
2310 2268
2311 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { 2269 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) {
2312 bool observer_was_deleted = false; 2270 bool observer_was_deleted = false;
2313 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2271 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2314 observer->set_delete_on_animation_ended(true); 2272 observer->set_delete_on_animation_ended(true);
2315 observer->set_delete_on_animation_aborted(true); 2273 observer->set_delete_on_animation_aborted(true);
2316 LayerAnimator* animator = observer->animator(); 2274 LayerAnimator* animator = observer->animator();
2317 animator->set_disable_timer_for_test(true);
2318 TestLayerAnimationDelegate delegate; 2275 TestLayerAnimationDelegate delegate;
2319 animator->SetDelegate(&delegate); 2276 animator->SetDelegate(&delegate);
2320 2277
2321 delegate.SetOpacityFromAnimation(0.0f); 2278 delegate.SetOpacityFromAnimation(0.0f);
2322 2279
2323 gfx::Rect start_bounds(0, 0, 50, 50); 2280 gfx::Rect start_bounds(0, 0, 50, 50);
2324 gfx::Rect target_bounds(10, 10, 100, 100); 2281 gfx::Rect target_bounds(10, 10, 100, 100);
2325 2282
2326 delegate.SetBoundsFromAnimation(start_bounds); 2283 delegate.SetBoundsFromAnimation(start_bounds);
2327 2284
(...skipping 11 matching lines...) Expand all
2339 2296
2340 EXPECT_TRUE(observer_was_deleted); 2297 EXPECT_TRUE(observer_was_deleted);
2341 } 2298 }
2342 2299
2343 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) { 2300 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) {
2344 bool observer_was_deleted = false; 2301 bool observer_was_deleted = false;
2345 TestLayerAnimationDelegate delegate; 2302 TestLayerAnimationDelegate delegate;
2346 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2303 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2347 observer->set_delete_on_animation_scheduled(true); 2304 observer->set_delete_on_animation_scheduled(true);
2348 LayerAnimator* animator = observer->animator(); 2305 LayerAnimator* animator = observer->animator();
2349 animator->set_disable_timer_for_test(true);
2350 animator->SetDelegate(&delegate); 2306 animator->SetDelegate(&delegate);
2351 2307
2352 delegate.SetOpacityFromAnimation(0.0f); 2308 delegate.SetOpacityFromAnimation(0.0f);
2353 2309
2354 gfx::Rect start_bounds(0, 0, 50, 50); 2310 gfx::Rect start_bounds(0, 0, 50, 50);
2355 gfx::Rect target_bounds(10, 10, 100, 100); 2311 gfx::Rect target_bounds(10, 10, 100, 100);
2356 2312
2357 delegate.SetBoundsFromAnimation(start_bounds); 2313 delegate.SetBoundsFromAnimation(start_bounds);
2358 2314
2359 std::vector<LayerAnimationSequence*> to_start; 2315 std::vector<LayerAnimationSequence*> to_start;
(...skipping 12 matching lines...) Expand all
2372 } 2328 }
2373 2329
2374 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) { 2330 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) {
2375 bool observer_was_deleted = false; 2331 bool observer_was_deleted = false;
2376 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2332 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2377 TestLayerAnimationDelegate delegate; 2333 TestLayerAnimationDelegate delegate;
2378 observer->set_delete_on_animation_aborted(true); 2334 observer->set_delete_on_animation_aborted(true);
2379 LayerAnimator* animator = observer->animator(); 2335 LayerAnimator* animator = observer->animator();
2380 animator->set_preemption_strategy( 2336 animator->set_preemption_strategy(
2381 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 2337 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
2382 animator->set_disable_timer_for_test(true);
2383 animator->SetDelegate(&delegate); 2338 animator->SetDelegate(&delegate);
2384 2339
2385 delegate.SetOpacityFromAnimation(0.0f); 2340 delegate.SetOpacityFromAnimation(0.0f);
2386 2341
2387 gfx::Rect start_bounds(0, 0, 50, 50); 2342 gfx::Rect start_bounds(0, 0, 50, 50);
2388 gfx::Rect target_bounds(10, 10, 100, 100); 2343 gfx::Rect target_bounds(10, 10, 100, 100);
2389 2344
2390 delegate.SetBoundsFromAnimation(start_bounds); 2345 delegate.SetBoundsFromAnimation(start_bounds);
2391 2346
2392 std::vector<LayerAnimationSequence*> to_start; 2347 std::vector<LayerAnimationSequence*> to_start;
(...skipping 12 matching lines...) Expand all
2405 2360
2406 animator->StartAnimation(new LayerAnimationSequence( 2361 animator->StartAnimation(new LayerAnimationSequence(
2407 LayerAnimationElement::CreateOpacityElement(1.0f, delta))); 2362 LayerAnimationElement::CreateOpacityElement(1.0f, delta)));
2408 2363
2409 EXPECT_TRUE(observer_was_deleted); 2364 EXPECT_TRUE(observer_was_deleted);
2410 } 2365 }
2411 2366
2412 2367
2413 TEST(LayerAnimatorTest, TestSetterRespectEnqueueStrategy) { 2368 TEST(LayerAnimatorTest, TestSetterRespectEnqueueStrategy) {
2414 TestLayerAnimationDelegate delegate; 2369 TestLayerAnimationDelegate delegate;
2415 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2370 scoped_refptr<LayerAnimator> animator(CreateDefaultTestAnimator(&delegate));
2416 animator->set_disable_timer_for_test(true);
2417
2418 animator->SetDelegate(&delegate);
2419 2371
2420 float start_opacity = 0.0f; 2372 float start_opacity = 0.0f;
2421 float target_opacity = 1.0f; 2373 float target_opacity = 1.0f;
2422 float magic_opacity = 0.123f; 2374 float magic_opacity = 0.123f;
2423 2375
2424 delegate.SetOpacityFromAnimation(start_opacity); 2376 delegate.SetOpacityFromAnimation(start_opacity);
2425 2377
2426 ScopedLayerAnimationSettings settings(animator.get()); 2378 ScopedLayerAnimationSettings settings(animator.get());
2427 settings.SetPreemptionStrategy( 2379 settings.SetPreemptionStrategy(
2428 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 2380 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 2563
2612 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {} 2564 void OnLayerAnimationScheduled(LayerAnimationSequence* sequence) override {}
2613 2565
2614 private: 2566 private:
2615 scoped_ptr<Layer> animator_layer_; 2567 scoped_ptr<Layer> animator_layer_;
2616 2568
2617 DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver); 2569 DISALLOW_COPY_AND_ASSIGN(LayerOwnerAnimationObserver);
2618 }; 2570 };
2619 2571
2620 TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) { 2572 TEST(LayerAnimatorTest, ObserverDeletesLayerInStopAnimating) {
2621 scoped_refptr<LayerAnimator> animator( 2573 scoped_refptr<LayerAnimator> animator(CreateImplicitTestAnimator());
2622 LayerAnimator::CreateImplicitAnimator());
2623 animator->set_disable_timer_for_test(true);
2624 LayerOwnerAnimationObserver observer(animator.get()); 2574 LayerOwnerAnimationObserver observer(animator.get());
2625 LayerAnimationDelegate* delegate = observer.animator_layer(); 2575 LayerAnimationDelegate* delegate = observer.animator_layer();
2626 2576
2627 const gfx::Rect start_bounds(0, 0, 50, 50); 2577 const gfx::Rect start_bounds(0, 0, 50, 50);
2628 const gfx::Rect target_bounds(10, 10, 100, 100); 2578 const gfx::Rect target_bounds(10, 10, 100, 100);
2629 const double target_opacity = 1.0; 2579 const double target_opacity = 1.0;
2630 2580
2631 delegate->SetOpacityFromAnimation(0.0f); 2581 delegate->SetOpacityFromAnimation(0.0f);
2632 delegate->SetBoundsFromAnimation(start_bounds); 2582 delegate->SetBoundsFromAnimation(start_bounds);
2633 2583
2634 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); 2584 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1);
2635 LayerAnimationSequence* opacity = new LayerAnimationSequence( 2585 LayerAnimationSequence* opacity = new LayerAnimationSequence(
2636 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta)); 2586 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta));
2637 opacity->AddObserver(&observer); 2587 opacity->AddObserver(&observer);
2638 animator->ScheduleAnimation(opacity); 2588 animator->ScheduleAnimation(opacity);
2639 time_delta = base::TimeDelta::FromSeconds(2); 2589 time_delta = base::TimeDelta::FromSeconds(2);
2640 LayerAnimationSequence* move = new LayerAnimationSequence( 2590 LayerAnimationSequence* move = new LayerAnimationSequence(
2641 LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta)); 2591 LayerAnimationElement::CreateBoundsElement(target_bounds, time_delta));
2642 animator->ScheduleAnimation(move); 2592 animator->ScheduleAnimation(move);
2643 EXPECT_TRUE(animator->is_animating()); 2593 EXPECT_TRUE(animator->is_animating());
2644 animator->Step(animator->last_step_time() + 2594 animator->Step(animator->last_step_time() +
2645 base::TimeDelta::FromMilliseconds(500)); 2595 base::TimeDelta::FromMilliseconds(500));
2646 animator->StopAnimating(); 2596 animator->StopAnimating();
2647 2597
2648 EXPECT_EQ(nullptr, observer.animator_layer()); 2598 EXPECT_EQ(nullptr, observer.animator_layer());
2649 EXPECT_TRUE(animator->is_animating()); 2599 EXPECT_TRUE(animator->is_animating());
2650 } 2600 }
2651 2601
2602 // Verifies the LayerAnimatorObserver notification order for an animation
2603 // sequence that completes successfully.
2604 TEST(LayerAnimatorObserverNotificationOrderTest,
2605 SuccessfulCompletionOfSequence) {
2606 TestLayerAnimationObserver observer;
2607 TestLayerAnimationDelegate delegate;
2608 scoped_refptr<LayerAnimator> animator(
2609 CreateDefaultTestAnimator(&delegate, &observer));
2610 observer.set_requires_notification_when_animator_destroyed(true);
2611
2612 const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
2613
2614 LayerAnimationSequence* sequence = new LayerAnimationSequence(
2615 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2616
2617 EXPECT_TRUE(observer.NoEventsObserved());
2618
2619 animator->StartAnimation(sequence);
2620
2621 EXPECT_EQ(observer.last_attached_sequence(), sequence);
2622 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
2623 EXPECT_EQ(observer.last_started_sequence(), sequence);
2624 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2625 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2626 EXPECT_EQ(observer.last_detached_sequence(), nullptr);
2627
2628 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2629 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2630
2631 observer.ResetLayerAnimationObserverations();
2632
2633 const base::TimeTicks start_time = animator->last_step_time();
2634
2635 animator->Step(start_time + animation_duration);
2636
2637 EXPECT_EQ(observer.last_attached_sequence(), nullptr);
2638 EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
2639 EXPECT_EQ(observer.last_started_sequence(), nullptr);
2640 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2641 EXPECT_EQ(observer.last_ended_sequence(), sequence);
2642 EXPECT_EQ(observer.last_detached_sequence(), sequence);
2643
2644 EXPECT_TRUE(observer.EndedEpochIsBeforeDetachedEpoch());
2645 }
2646
2647 // Verifies the LayerAnimatorObserver notification order for an animation
2648 // sequence that is aborted after being scheduled.
2649 TEST(LayerAnimatorObserverNotificationOrderTest, AbortingAScheduledSequence) {
2650 TestLayerAnimationObserver observer;
2651 TestLayerAnimationDelegate delegate;
2652 scoped_refptr<LayerAnimator> animator(
2653 CreateDefaultTestAnimator(&delegate, &observer));
2654 observer.set_requires_notification_when_animator_destroyed(true);
2655
2656 const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
2657
2658 LayerAnimationSequence* sequence = new LayerAnimationSequence(
2659 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2660
2661 EXPECT_TRUE(observer.NoEventsObserved());
2662
2663 animator->StartAnimation(sequence);
2664
2665 EXPECT_EQ(observer.last_attached_sequence(), sequence);
2666 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
2667 EXPECT_EQ(observer.last_started_sequence(), sequence);
2668 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2669 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2670 EXPECT_EQ(observer.last_detached_sequence(), nullptr);
2671
2672 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2673 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2674
2675 observer.ResetLayerAnimationObserverations();
2676
2677 animator->AbortAllAnimations();
2678
2679 EXPECT_EQ(observer.last_attached_sequence(), nullptr);
2680 EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
2681 EXPECT_EQ(observer.last_started_sequence(), nullptr);
2682 EXPECT_EQ(observer.last_aborted_sequence(), sequence);
2683 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2684 EXPECT_EQ(observer.last_detached_sequence(), sequence);
2685
2686 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch());
2687 }
2688
2689 // Verifies the LayerAnimatorObserver notification order for an animation
2690 // sequence that is queued up after another sequence that
2691 // completes successfully.
2692 TEST(LayerAnimatorObserverNotificationOrderTest,
2693 RunningASequenceThatIsQueuedForLaterStartTime) {
2694 TestLayerAnimationObserver observer;
2695 TestLayerAnimationDelegate delegate;
2696 scoped_refptr<LayerAnimator> animator(
2697 CreateDefaultTestAnimator(&delegate, &observer));
2698 observer.set_requires_notification_when_animator_destroyed(true);
2699
2700 const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
2701
2702 LayerAnimationSequence* first_sequence = new LayerAnimationSequence(
2703 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2704
2705 LayerAnimationSequence* queued_sequence = new LayerAnimationSequence(
2706 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2707
2708 EXPECT_TRUE(observer.NoEventsObserved());
2709
2710 animator->StartAnimation(first_sequence);
2711
2712 EXPECT_EQ(observer.last_attached_sequence(), first_sequence);
2713 EXPECT_EQ(observer.last_scheduled_sequence(), first_sequence);
2714 EXPECT_EQ(observer.last_started_sequence(), first_sequence);
2715 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2716 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2717 EXPECT_EQ(observer.last_detached_sequence(), nullptr);
2718
2719 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2720 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2721
2722 observer.ResetLayerAnimationObserverations();
2723
2724 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
2725 animator->StartAnimation(queued_sequence);
2726
2727 EXPECT_EQ(observer.last_attached_sequence(), queued_sequence);
2728 EXPECT_EQ(observer.last_scheduled_sequence(), queued_sequence);
2729 EXPECT_EQ(observer.last_started_sequence(), nullptr);
2730 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2731 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2732 EXPECT_EQ(observer.last_detached_sequence(), nullptr);
2733
2734 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2735
2736 observer.ResetLayerAnimationObserverations();
2737
2738 base::TimeTicks start_time = animator->last_step_time();
2739
2740 animator->Step(start_time + animation_duration);
2741
2742 EXPECT_EQ(observer.last_attached_sequence(), nullptr);
2743 EXPECT_EQ(observer.last_scheduled_sequence(), nullptr);
2744 EXPECT_EQ(observer.last_started_sequence(), queued_sequence);
2745 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2746 EXPECT_EQ(observer.last_ended_sequence(), first_sequence);
2747 EXPECT_EQ(observer.last_detached_sequence(), first_sequence);
2748
2749 EXPECT_TRUE(observer.EndedEpochIsBeforeDetachedEpoch());
2750 EXPECT_TRUE(observer.EndedEpochIsBeforeStartedEpoch());
2751 }
2752
2753 // Verifies the LayerAnimatorObserver notification order for an animation
2754 // sequence that pre-empts another sequence.
2755 TEST(LayerAnimatorObserverNotificationOrderTest,
2756 RunningASequenceThatPreEmptsAnotherSequence) {
2757 TestLayerAnimationObserver observer;
2758 TestLayerAnimationDelegate delegate;
2759 scoped_refptr<LayerAnimator> animator(
2760 CreateDefaultTestAnimator(&delegate, &observer));
2761 observer.set_requires_notification_when_animator_destroyed(true);
2762
2763 const base::TimeDelta animation_duration = base::TimeDelta::FromSeconds(100);
2764
2765 LayerAnimationSequence* first_sequence = new LayerAnimationSequence(
2766 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2767
2768 LayerAnimationSequence* queued_sequence = new LayerAnimationSequence(
2769 LayerAnimationElement::CreateBrightnessElement(1.0f, animation_duration));
2770
2771 EXPECT_TRUE(observer.NoEventsObserved());
2772
2773 animator->StartAnimation(first_sequence);
2774
2775 EXPECT_EQ(observer.last_attached_sequence(), first_sequence);
2776 EXPECT_EQ(observer.last_scheduled_sequence(), first_sequence);
2777 EXPECT_EQ(observer.last_started_sequence(), first_sequence);
2778 EXPECT_EQ(observer.last_aborted_sequence(), nullptr);
2779 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2780 EXPECT_EQ(observer.last_detached_sequence(), nullptr);
2781
2782 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2783 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2784
2785 observer.ResetLayerAnimationObserverations();
2786
2787 animator->set_preemption_strategy(
2788 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
2789 animator->StartAnimation(queued_sequence);
2790
2791 EXPECT_EQ(observer.last_attached_sequence(), queued_sequence);
2792 EXPECT_EQ(observer.last_scheduled_sequence(), queued_sequence);
2793 EXPECT_EQ(observer.last_started_sequence(), queued_sequence);
2794 EXPECT_EQ(observer.last_aborted_sequence(), first_sequence);
2795 EXPECT_EQ(observer.last_ended_sequence(), nullptr);
2796 EXPECT_EQ(observer.last_detached_sequence(), first_sequence);
2797
2798 EXPECT_TRUE(observer.AbortedEpochIsBeforeDetachedEpoch());
2799 EXPECT_TRUE(observer.AbortedEpochIsBeforeStartedEpoch());
2800 EXPECT_TRUE(observer.AttachedEpochIsBeforeScheduledEpoch());
2801 EXPECT_TRUE(observer.ScheduledEpochIsBeforeStartedEpoch());
2802 }
2803
2652 } // namespace ui 2804 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698