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

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

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
14 #include "ui/compositor/layer_animation_delegate.h" 14 #include "ui/compositor/layer_animation_delegate.h"
15 #include "ui/compositor/layer_animation_element.h" 15 #include "ui/compositor/layer_animation_element.h"
16 #include "ui/compositor/layer_animation_sequence.h" 16 #include "ui/compositor/layer_animation_sequence.h"
17 #include "ui/compositor/layer_animator_collection.h"
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/compositor/test/layer_animator_test_controller.h" 20 #include "ui/compositor/test/layer_animator_test_controller.h"
20 #include "ui/compositor/test/test_layer_animation_delegate.h" 21 #include "ui/compositor/test/test_layer_animation_delegate.h"
21 #include "ui/compositor/test/test_layer_animation_observer.h" 22 #include "ui/compositor/test/test_layer_animation_observer.h"
22 #include "ui/compositor/test/test_utils.h" 23 #include "ui/compositor/test/test_utils.h"
23 #include "ui/gfx/frame_time.h" 24 #include "ui/gfx/frame_time.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
25 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
26 27
27 using gfx::AnimationContainerElement;
28
29 namespace ui { 28 namespace ui {
30 29
31 namespace { 30 namespace {
32 31
33 // Converts |color| to a string. Each component of the color is separated by a 32 // Converts |color| to a string. Each component of the color is separated by a
34 // space and the order if A R G B. 33 // space and the order if A R G B.
35 std::string ColorToString(SkColor color) { 34 std::string ColorToString(SkColor color) {
36 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), 35 return base::StringPrintf("%d %d %d %d", SkColorGetA(color),
37 SkColorGetR(color), SkColorGetG(color), 36 SkColorGetR(color), SkColorGetG(color),
38 SkColorGetB(color)); 37 SkColorGetB(color));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); 188 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence);
190 }; 189 };
191 190
192 } // namespace 191 } // namespace
193 192
194 // Checks that setting a property on an implicit animator causes an animation to 193 // Checks that setting a property on an implicit animator causes an animation to
195 // happen. 194 // happen.
196 TEST(LayerAnimatorTest, ImplicitAnimation) { 195 TEST(LayerAnimatorTest, ImplicitAnimation) {
197 scoped_refptr<LayerAnimator> animator( 196 scoped_refptr<LayerAnimator> animator(
198 LayerAnimator::CreateImplicitAnimator()); 197 LayerAnimator::CreateImplicitAnimator());
199 AnimationContainerElement* element = animator.get();
200 animator->set_disable_timer_for_test(true); 198 animator->set_disable_timer_for_test(true);
201 TestLayerAnimationDelegate delegate; 199 TestLayerAnimationDelegate delegate;
202 animator->SetDelegate(&delegate); 200 animator->SetDelegate(&delegate);
203 base::TimeTicks now = gfx::FrameTime::Now(); 201 base::TimeTicks now = gfx::FrameTime::Now();
204 animator->SetBrightness(0.5); 202 animator->SetBrightness(0.5);
205 EXPECT_TRUE(animator->is_animating()); 203 EXPECT_TRUE(animator->is_animating());
206 element->Step(now + base::TimeDelta::FromSeconds(1)); 204 animator->Step(now + base::TimeDelta::FromSeconds(1));
207 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); 205 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
208 } 206 }
209 207
210 // Checks that if the animator is a default animator, that implicit animations 208 // Checks that if the animator is a default animator, that implicit animations
211 // are not started. 209 // are not started.
212 TEST(LayerAnimatorTest, NoImplicitAnimation) { 210 TEST(LayerAnimatorTest, NoImplicitAnimation) {
213 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 211 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
214 animator->set_disable_timer_for_test(true); 212 animator->set_disable_timer_for_test(true);
215 TestLayerAnimationDelegate delegate; 213 TestLayerAnimationDelegate delegate;
216 animator->SetDelegate(&delegate); 214 animator->SetDelegate(&delegate);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 animator->AbortAllAnimations(); 276 animator->AbortAllAnimations();
279 EXPECT_FALSE(animator->is_animating()); 277 EXPECT_FALSE(animator->is_animating());
280 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); 278 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation());
281 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); 279 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation());
282 } 280 }
283 281
284 // Schedule a non-threaded animation that can run immediately. This is the 282 // Schedule a non-threaded animation that can run immediately. This is the
285 // trivial case and should result in the animation being started immediately. 283 // trivial case and should result in the animation being started immediately.
286 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { 284 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
287 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 285 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
288 AnimationContainerElement* element = animator.get();
289 animator->set_disable_timer_for_test(true); 286 animator->set_disable_timer_for_test(true);
290 TestLayerAnimationDelegate delegate; 287 TestLayerAnimationDelegate delegate;
291 animator->SetDelegate(&delegate); 288 animator->SetDelegate(&delegate);
292 289
293 double start_brightness(0.0); 290 double start_brightness(0.0);
294 double middle_brightness(0.5); 291 double middle_brightness(0.5);
295 double target_brightness(1.0); 292 double target_brightness(1.0);
296 293
297 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 294 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
298 295
299 delegate.SetBrightnessFromAnimation(start_brightness); 296 delegate.SetBrightnessFromAnimation(start_brightness);
300 297
301 animator->ScheduleAnimation( 298 animator->ScheduleAnimation(
302 new LayerAnimationSequence( 299 new LayerAnimationSequence(
303 LayerAnimationElement::CreateBrightnessElement(target_brightness, 300 LayerAnimationElement::CreateBrightnessElement(target_brightness,
304 delta))); 301 delta)));
305 302
306 EXPECT_TRUE(animator->is_animating()); 303 EXPECT_TRUE(animator->is_animating());
307 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 304 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
308 305
309 base::TimeTicks start_time = animator->last_step_time(); 306 base::TimeTicks start_time = animator->last_step_time();
310 307
311 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 308 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
312 309
313 EXPECT_TRUE(animator->is_animating()); 310 EXPECT_TRUE(animator->is_animating());
314 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 311 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
315 312
316 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 313 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
317 314
318 EXPECT_FALSE(animator->is_animating()); 315 EXPECT_FALSE(animator->is_animating());
319 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 316 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
320 } 317 }
321 318
322 // Schedule a threaded animation that can run immediately. 319 // Schedule a threaded animation that can run immediately.
323 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { 320 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
324 double epsilon = 0.00001; 321 double epsilon = 0.00001;
325 LayerAnimatorTestController test_controller( 322 LayerAnimatorTestController test_controller(
326 LayerAnimator::CreateDefaultAnimator()); 323 LayerAnimator::CreateDefaultAnimator());
327 AnimationContainerElement* element = test_controller.animator(); 324 LayerAnimator* animator = test_controller.animator();
328 test_controller.animator()->set_disable_timer_for_test(true); 325 test_controller.animator()->set_disable_timer_for_test(true);
329 TestLayerAnimationDelegate delegate; 326 TestLayerAnimationDelegate delegate;
330 test_controller.animator()->SetDelegate(&delegate); 327 test_controller.animator()->SetDelegate(&delegate);
331 328
332 double start_opacity(0.0); 329 double start_opacity(0.0);
333 double target_opacity(1.0); 330 double target_opacity(1.0);
334 331
335 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 332 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
336 333
337 delegate.SetOpacityFromAnimation(start_opacity); 334 delegate.SetOpacityFromAnimation(start_opacity);
338 335
339 test_controller.animator()->ScheduleAnimation( 336 test_controller.animator()->ScheduleAnimation(
340 new LayerAnimationSequence( 337 new LayerAnimationSequence(
341 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 338 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
342 339
343 EXPECT_TRUE(test_controller.animator()->is_animating()); 340 EXPECT_TRUE(test_controller.animator()->is_animating());
344 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 341 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
345 342
346 base::TimeTicks start_time = test_controller.animator()->last_step_time(); 343 base::TimeTicks start_time = test_controller.animator()->last_step_time();
347 base::TimeTicks effective_start = start_time + delta; 344 base::TimeTicks effective_start = start_time + delta;
348 345
349 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 346 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
350 cc::AnimationEvent::Started, 347 cc::AnimationEvent::Started,
351 0, 348 0,
352 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 349 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
353 ->animation_group_id(), 350 ->animation_group_id(),
354 cc::Animation::Opacity, 351 cc::Animation::Opacity,
355 effective_start)); 352 effective_start));
356 353
357 element->Step(effective_start + delta/2); 354 animator->Step(effective_start + delta / 2);
358 355
359 EXPECT_TRUE(test_controller.animator()->is_animating()); 356 EXPECT_TRUE(test_controller.animator()->is_animating());
360 EXPECT_NEAR( 357 EXPECT_NEAR(
361 0.5, 358 0.5,
362 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> 359 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
363 last_progressed_fraction(), 360 last_progressed_fraction(),
364 epsilon); 361 epsilon);
365 362
366 element->Step(effective_start + delta); 363 animator->Step(effective_start + delta);
367 364
368 EXPECT_FALSE(test_controller.animator()->is_animating()); 365 EXPECT_FALSE(test_controller.animator()->is_animating());
369 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 366 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
370 } 367 }
371 368
372 // Schedule two non-threaded animations on separate properties. Both animations 369 // Schedule two non-threaded animations on separate properties. Both animations
373 // should start immediately and should progress in lock step. 370 // should start immediately and should progress in lock step.
374 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { 371 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
375 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 372 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
376 AnimationContainerElement* element = animator.get();
377 animator->set_disable_timer_for_test(true); 373 animator->set_disable_timer_for_test(true);
378 TestLayerAnimationDelegate delegate; 374 TestLayerAnimationDelegate delegate;
379 animator->SetDelegate(&delegate); 375 animator->SetDelegate(&delegate);
380 376
381 double start_brightness(0.0); 377 double start_brightness(0.0);
382 double middle_brightness(0.5); 378 double middle_brightness(0.5);
383 double target_brightness(1.0); 379 double target_brightness(1.0);
384 380
385 gfx::Rect start_bounds, target_bounds, middle_bounds; 381 gfx::Rect start_bounds, target_bounds, middle_bounds;
386 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 382 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
(...skipping 13 matching lines...) Expand all
400 animator->ScheduleAnimation( 396 animator->ScheduleAnimation(
401 new LayerAnimationSequence( 397 new LayerAnimationSequence(
402 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 398 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
403 399
404 EXPECT_TRUE(animator->is_animating()); 400 EXPECT_TRUE(animator->is_animating());
405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 401 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
406 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 402 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
407 403
408 base::TimeTicks start_time = animator->last_step_time(); 404 base::TimeTicks start_time = animator->last_step_time();
409 405
410 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 406 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
411 407
412 EXPECT_TRUE(animator->is_animating()); 408 EXPECT_TRUE(animator->is_animating());
413 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 409 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
414 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); 410 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
415 411
416 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 412 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
417 413
418 EXPECT_FALSE(animator->is_animating()); 414 EXPECT_FALSE(animator->is_animating());
419 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 415 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
420 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 416 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
421 } 417 }
422 418
423 // Schedule a threaded and a non-threaded animation on separate properties. Both 419 // Schedule a threaded and a non-threaded animation on separate properties. Both
424 // animations should progress in lock step. 420 // animations should progress in lock step.
425 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { 421 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
426 double epsilon = 0.00001; 422 double epsilon = 0.00001;
427 LayerAnimatorTestController test_controller( 423 LayerAnimatorTestController test_controller(
428 LayerAnimator::CreateDefaultAnimator()); 424 LayerAnimator::CreateDefaultAnimator());
429 AnimationContainerElement* element = test_controller.animator(); 425 LayerAnimator* animator = test_controller.animator();
430 test_controller.animator()->set_disable_timer_for_test(true); 426 test_controller.animator()->set_disable_timer_for_test(true);
431 TestLayerAnimationDelegate delegate; 427 TestLayerAnimationDelegate delegate;
432 test_controller.animator()->SetDelegate(&delegate); 428 test_controller.animator()->SetDelegate(&delegate);
433 429
434 double start_opacity(0.0); 430 double start_opacity(0.0);
435 double target_opacity(1.0); 431 double target_opacity(1.0);
436 432
437 gfx::Rect start_bounds, target_bounds, middle_bounds; 433 gfx::Rect start_bounds, target_bounds, middle_bounds;
438 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 434 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
439 start_bounds.set_x(-90); 435 start_bounds.set_x(-90);
(...skipping 23 matching lines...) Expand all
463 base::TimeTicks effective_start = start_time + delta; 459 base::TimeTicks effective_start = start_time + delta;
464 460
465 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 461 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
466 cc::AnimationEvent::Started, 462 cc::AnimationEvent::Started,
467 0, 463 0,
468 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 464 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
469 ->animation_group_id(), 465 ->animation_group_id(),
470 cc::Animation::Opacity, 466 cc::Animation::Opacity,
471 effective_start)); 467 effective_start));
472 468
473 element->Step(effective_start + delta/2); 469 animator->Step(effective_start + delta / 2);
474 470
475 EXPECT_TRUE(test_controller.animator()->is_animating()); 471 EXPECT_TRUE(test_controller.animator()->is_animating());
476 EXPECT_NEAR( 472 EXPECT_NEAR(
477 0.5, 473 0.5,
478 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> 474 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
479 last_progressed_fraction(), 475 last_progressed_fraction(),
480 epsilon); 476 epsilon);
481 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); 477 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
482 478
483 element->Step(effective_start + delta); 479 animator->Step(effective_start + delta);
484 480
485 EXPECT_FALSE(test_controller.animator()->is_animating()); 481 EXPECT_FALSE(test_controller.animator()->is_animating());
486 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 482 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
487 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 483 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
488 } 484 }
489 485
490 // Schedule two animations on the same property. In this case, the two 486 // Schedule two animations on the same property. In this case, the two
491 // animations should run one after another. 487 // animations should run one after another.
492 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { 488 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
493 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 489 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
494 AnimationContainerElement* element = animator.get();
495 animator->set_disable_timer_for_test(true); 490 animator->set_disable_timer_for_test(true);
496 TestLayerAnimationDelegate delegate; 491 TestLayerAnimationDelegate delegate;
497 animator->SetDelegate(&delegate); 492 animator->SetDelegate(&delegate);
498 493
499 double start_brightness(0.0); 494 double start_brightness(0.0);
500 double middle_brightness(0.5); 495 double middle_brightness(0.5);
501 double target_brightness(1.0); 496 double target_brightness(1.0);
502 497
503 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 498 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
504 499
505 delegate.SetBrightnessFromAnimation(start_brightness); 500 delegate.SetBrightnessFromAnimation(start_brightness);
506 501
507 animator->ScheduleAnimation( 502 animator->ScheduleAnimation(
508 new LayerAnimationSequence( 503 new LayerAnimationSequence(
509 LayerAnimationElement::CreateBrightnessElement(target_brightness, 504 LayerAnimationElement::CreateBrightnessElement(target_brightness,
510 delta))); 505 delta)));
511 506
512 animator->ScheduleAnimation( 507 animator->ScheduleAnimation(
513 new LayerAnimationSequence( 508 new LayerAnimationSequence(
514 LayerAnimationElement::CreateBrightnessElement(start_brightness, 509 LayerAnimationElement::CreateBrightnessElement(start_brightness,
515 delta))); 510 delta)));
516 511
517 EXPECT_TRUE(animator->is_animating()); 512 EXPECT_TRUE(animator->is_animating());
518 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 513 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
519 514
520 base::TimeTicks start_time = animator->last_step_time(); 515 base::TimeTicks start_time = animator->last_step_time();
521 516
522 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 517 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
523 518
524 EXPECT_TRUE(animator->is_animating()); 519 EXPECT_TRUE(animator->is_animating());
525 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 520 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
526 521
527 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 522 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
528 523
529 EXPECT_TRUE(animator->is_animating()); 524 EXPECT_TRUE(animator->is_animating());
530 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 525 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
531 526
532 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 527 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
533 528
534 EXPECT_TRUE(animator->is_animating()); 529 EXPECT_TRUE(animator->is_animating());
535 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 530 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
536 531
537 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 532 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
538 533
539 EXPECT_FALSE(animator->is_animating()); 534 EXPECT_FALSE(animator->is_animating());
540 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 535 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
541 } 536 }
542 537
543 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That 538 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That
544 // is, ensure that all animations targetting a particular property are run in 539 // is, ensure that all animations targetting a particular property are run in
545 // order. 540 // order.
546 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { 541 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
547 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 542 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
548 AnimationContainerElement* element = animator.get();
549 animator->set_disable_timer_for_test(true); 543 animator->set_disable_timer_for_test(true);
550 TestLayerAnimationDelegate delegate; 544 TestLayerAnimationDelegate delegate;
551 animator->SetDelegate(&delegate); 545 animator->SetDelegate(&delegate);
552 546
553 double start_grayscale(0.0); 547 double start_grayscale(0.0);
554 double middle_grayscale(0.5); 548 double middle_grayscale(0.5);
555 double target_grayscale(1.0); 549 double target_grayscale(1.0);
556 550
557 gfx::Rect start_bounds, target_bounds, middle_bounds; 551 gfx::Rect start_bounds, target_bounds, middle_bounds;
558 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 552 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
(...skipping 23 matching lines...) Expand all
582 animator->ScheduleAnimation( 576 animator->ScheduleAnimation(
583 new LayerAnimationSequence( 577 new LayerAnimationSequence(
584 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); 578 LayerAnimationElement::CreateBoundsElement(start_bounds, delta)));
585 579
586 EXPECT_TRUE(animator->is_animating()); 580 EXPECT_TRUE(animator->is_animating());
587 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 581 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
588 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 582 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
589 583
590 base::TimeTicks start_time = animator->last_step_time(); 584 base::TimeTicks start_time = animator->last_step_time();
591 585
592 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 586 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
593 587
594 EXPECT_TRUE(animator->is_animating()); 588 EXPECT_TRUE(animator->is_animating());
595 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 589 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
596 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 590 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
597 591
598 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 592 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
599 593
600 EXPECT_TRUE(animator->is_animating()); 594 EXPECT_TRUE(animator->is_animating());
601 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); 595 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
602 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 596 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
603 597
604 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 598 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
605 599
606 EXPECT_TRUE(animator->is_animating()); 600 EXPECT_TRUE(animator->is_animating());
607 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 601 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
608 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 602 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
609 603
610 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); 604 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
611 605
612 EXPECT_TRUE(animator->is_animating()); 606 EXPECT_TRUE(animator->is_animating());
613 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 607 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
614 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 608 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
615 609
616 element->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); 610 animator->Step(start_time + base::TimeDelta::FromMilliseconds(4000));
617 611
618 EXPECT_FALSE(animator->is_animating()); 612 EXPECT_FALSE(animator->is_animating());
619 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 613 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
620 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 614 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
621 } 615 }
622 616
623 // Schedule {g} and then schedule {g} and {b} together. In this case, since 617 // Schedule {g} and then schedule {g} and {b} together. In this case, since
624 // ScheduleTogether is being used, the bounds animation should not start until 618 // ScheduleTogether is being used, the bounds animation should not start until
625 // the second grayscale animation starts. 619 // the second grayscale animation starts.
626 TEST(LayerAnimatorTest, ScheduleTogether) { 620 TEST(LayerAnimatorTest, ScheduleTogether) {
627 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 621 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
628 AnimationContainerElement* element = animator.get();
629 animator->set_disable_timer_for_test(true); 622 animator->set_disable_timer_for_test(true);
630 TestLayerAnimationDelegate delegate; 623 TestLayerAnimationDelegate delegate;
631 animator->SetDelegate(&delegate); 624 animator->SetDelegate(&delegate);
632 625
633 double start_grayscale(0.0); 626 double start_grayscale(0.0);
634 double target_grayscale(1.0); 627 double target_grayscale(1.0);
635 628
636 gfx::Rect start_bounds, target_bounds, middle_bounds; 629 gfx::Rect start_bounds, target_bounds, middle_bounds;
637 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); 630 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50);
638 start_bounds.set_x(-90); 631 start_bounds.set_x(-90);
(...skipping 16 matching lines...) Expand all
655 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 648 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
656 649
657 animator->ScheduleTogether(sequences); 650 animator->ScheduleTogether(sequences);
658 651
659 EXPECT_TRUE(animator->is_animating()); 652 EXPECT_TRUE(animator->is_animating());
660 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 653 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
661 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 654 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
662 655
663 base::TimeTicks start_time = animator->last_step_time(); 656 base::TimeTicks start_time = animator->last_step_time();
664 657
665 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 658 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
666 659
667 EXPECT_TRUE(animator->is_animating()); 660 EXPECT_TRUE(animator->is_animating());
668 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); 661 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
669 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 662 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
670 663
671 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 664 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
672 665
673 EXPECT_FALSE(animator->is_animating()); 666 EXPECT_FALSE(animator->is_animating());
674 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 667 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
675 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 668 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
676 } 669 }
677 670
678 // Start non-threaded animation (that can run immediately). This is the trivial 671 // Start non-threaded animation (that can run immediately). This is the trivial
679 // case (see the trival case for ScheduleAnimation). 672 // case (see the trival case for ScheduleAnimation).
680 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { 673 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
681 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 674 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
682 AnimationContainerElement* element = animator.get();
683 animator->set_disable_timer_for_test(true); 675 animator->set_disable_timer_for_test(true);
684 TestLayerAnimationDelegate delegate; 676 TestLayerAnimationDelegate delegate;
685 animator->SetDelegate(&delegate); 677 animator->SetDelegate(&delegate);
686 678
687 double start_brightness(0.0); 679 double start_brightness(0.0);
688 double middle_brightness(0.5); 680 double middle_brightness(0.5);
689 double target_brightness(1.0); 681 double target_brightness(1.0);
690 682
691 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 683 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
692 684
693 delegate.SetBrightnessFromAnimation(start_brightness); 685 delegate.SetBrightnessFromAnimation(start_brightness);
694 686
695 animator->StartAnimation( 687 animator->StartAnimation(
696 new LayerAnimationSequence( 688 new LayerAnimationSequence(
697 LayerAnimationElement::CreateBrightnessElement(target_brightness, 689 LayerAnimationElement::CreateBrightnessElement(target_brightness,
698 delta))); 690 delta)));
699 691
700 EXPECT_TRUE(animator->is_animating()); 692 EXPECT_TRUE(animator->is_animating());
701 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 693 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
702 694
703 base::TimeTicks start_time = animator->last_step_time(); 695 base::TimeTicks start_time = animator->last_step_time();
704 696
705 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 697 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
706 698
707 EXPECT_TRUE(animator->is_animating()); 699 EXPECT_TRUE(animator->is_animating());
708 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 700 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
709 701
710 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 702 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
711 703
712 EXPECT_FALSE(animator->is_animating()); 704 EXPECT_FALSE(animator->is_animating());
713 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 705 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
714 } 706 }
715 707
716 // Start threaded animation (that can run immediately). 708 // Start threaded animation (that can run immediately).
717 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { 709 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
718 double epsilon = 0.00001; 710 double epsilon = 0.00001;
719 LayerAnimatorTestController test_controller( 711 LayerAnimatorTestController test_controller(
720 LayerAnimator::CreateDefaultAnimator()); 712 LayerAnimator::CreateDefaultAnimator());
721 AnimationContainerElement* element = test_controller.animator(); 713 LayerAnimator* animator = test_controller.animator();
722 test_controller.animator()->set_disable_timer_for_test(true); 714 test_controller.animator()->set_disable_timer_for_test(true);
723 TestLayerAnimationDelegate delegate; 715 TestLayerAnimationDelegate delegate;
724 test_controller.animator()->SetDelegate(&delegate); 716 test_controller.animator()->SetDelegate(&delegate);
725 717
726 double start_opacity(0.0); 718 double start_opacity(0.0);
727 double target_opacity(1.0); 719 double target_opacity(1.0);
728 720
729 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 721 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
730 722
731 delegate.SetOpacityFromAnimation(start_opacity); 723 delegate.SetOpacityFromAnimation(start_opacity);
732 724
733 test_controller.animator()->StartAnimation( 725 test_controller.animator()->StartAnimation(
734 new LayerAnimationSequence( 726 new LayerAnimationSequence(
735 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 727 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
736 728
737 EXPECT_TRUE(test_controller.animator()->is_animating()); 729 EXPECT_TRUE(test_controller.animator()->is_animating());
738 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 730 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
739 731
740 base::TimeTicks start_time = test_controller.animator()->last_step_time(); 732 base::TimeTicks start_time = test_controller.animator()->last_step_time();
741 base::TimeTicks effective_start = start_time + delta; 733 base::TimeTicks effective_start = start_time + delta;
742 734
743 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 735 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
744 cc::AnimationEvent::Started, 736 cc::AnimationEvent::Started,
745 0, 737 0,
746 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 738 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
747 ->animation_group_id(), 739 ->animation_group_id(),
748 cc::Animation::Opacity, 740 cc::Animation::Opacity,
749 effective_start)); 741 effective_start));
750 742
751 element->Step(effective_start + delta/2); 743 animator->Step(effective_start + delta / 2);
752 744
753 EXPECT_TRUE(test_controller.animator()->is_animating()); 745 EXPECT_TRUE(test_controller.animator()->is_animating());
754 EXPECT_NEAR( 746 EXPECT_NEAR(
755 0.5, 747 0.5,
756 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> 748 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
757 last_progressed_fraction(), 749 last_progressed_fraction(),
758 epsilon); 750 epsilon);
759 751
760 element->Step(effective_start + delta); 752 animator->Step(effective_start + delta);
761 EXPECT_FALSE(test_controller.animator()->is_animating()); 753 EXPECT_FALSE(test_controller.animator()->is_animating());
762 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 754 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
763 } 755 }
764 756
765 // Preempt by immediately setting new target. 757 // Preempt by immediately setting new target.
766 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { 758 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
767 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 759 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
768 animator->set_disable_timer_for_test(true); 760 animator->set_disable_timer_for_test(true);
769 TestLayerAnimationDelegate delegate; 761 TestLayerAnimationDelegate delegate;
770 animator->SetDelegate(&delegate); 762 animator->SetDelegate(&delegate);
(...skipping 15 matching lines...) Expand all
786 new LayerAnimationSequence( 778 new LayerAnimationSequence(
787 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 779 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
788 780
789 EXPECT_FALSE(animator->is_animating()); 781 EXPECT_FALSE(animator->is_animating());
790 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 782 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
791 } 783 }
792 784
793 // Preempt by animating to new target, with a non-threaded animation. 785 // Preempt by animating to new target, with a non-threaded animation.
794 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { 786 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
795 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 787 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
796 AnimationContainerElement* element = animator.get();
797 animator->set_disable_timer_for_test(true); 788 animator->set_disable_timer_for_test(true);
798 TestLayerAnimationDelegate delegate; 789 TestLayerAnimationDelegate delegate;
799 animator->SetDelegate(&delegate); 790 animator->SetDelegate(&delegate);
800 791
801 double start_brightness(0.0); 792 double start_brightness(0.0);
802 double middle_brightness(0.5); 793 double middle_brightness(0.5);
803 double target_brightness(1.0); 794 double target_brightness(1.0);
804 795
805 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 796 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
806 797
807 delegate.SetBrightnessFromAnimation(start_brightness); 798 delegate.SetBrightnessFromAnimation(start_brightness);
808 799
809 animator->set_preemption_strategy( 800 animator->set_preemption_strategy(
810 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 801 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
811 802
812 animator->StartAnimation( 803 animator->StartAnimation(
813 new LayerAnimationSequence( 804 new LayerAnimationSequence(
814 LayerAnimationElement::CreateBrightnessElement(target_brightness, 805 LayerAnimationElement::CreateBrightnessElement(target_brightness,
815 delta))); 806 delta)));
816 807
817 base::TimeTicks start_time = animator->last_step_time(); 808 base::TimeTicks start_time = animator->last_step_time();
818 809
819 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 810 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
820 811
821 animator->StartAnimation( 812 animator->StartAnimation(
822 new LayerAnimationSequence( 813 new LayerAnimationSequence(
823 LayerAnimationElement::CreateBrightnessElement(start_brightness, 814 LayerAnimationElement::CreateBrightnessElement(start_brightness,
824 delta))); 815 delta)));
825 816
826 EXPECT_TRUE(animator->is_animating()); 817 EXPECT_TRUE(animator->is_animating());
827 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 818 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
828 819
829 animator->StartAnimation( 820 animator->StartAnimation(
830 new LayerAnimationSequence( 821 new LayerAnimationSequence(
831 LayerAnimationElement::CreateBrightnessElement(start_brightness, 822 LayerAnimationElement::CreateBrightnessElement(start_brightness,
832 delta))); 823 delta)));
833 824
834 EXPECT_TRUE(animator->is_animating()); 825 EXPECT_TRUE(animator->is_animating());
835 826
836 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 827 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
837 828
838 EXPECT_TRUE(animator->is_animating()); 829 EXPECT_TRUE(animator->is_animating());
839 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 830 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
840 0.5 * (start_brightness + middle_brightness)); 831 0.5 * (start_brightness + middle_brightness));
841 832
842 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 833 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
843 834
844 EXPECT_FALSE(animator->is_animating()); 835 EXPECT_FALSE(animator->is_animating());
845 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 836 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
846 } 837 }
847 838
848 // Preempt by animating to new target, with a threaded animation. 839 // Preempt by animating to new target, with a threaded animation.
849 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { 840 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
850 double epsilon = 0.00001; 841 double epsilon = 0.00001;
851 LayerAnimatorTestController test_controller( 842 LayerAnimatorTestController test_controller(
852 LayerAnimator::CreateDefaultAnimator()); 843 LayerAnimator::CreateDefaultAnimator());
853 AnimationContainerElement* element = test_controller.animator(); 844 LayerAnimator* animator = test_controller.animator();
854 test_controller.animator()->set_disable_timer_for_test(true); 845 test_controller.animator()->set_disable_timer_for_test(true);
855 TestLayerAnimationDelegate delegate; 846 TestLayerAnimationDelegate delegate;
856 test_controller.animator()->SetDelegate(&delegate); 847 test_controller.animator()->SetDelegate(&delegate);
857 848
858 double start_opacity(0.0); 849 double start_opacity(0.0);
859 double middle_opacity(0.5); 850 double middle_opacity(0.5);
860 double target_opacity(1.0); 851 double target_opacity(1.0);
861 852
862 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 853 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
863 854
(...skipping 10 matching lines...) Expand all
874 base::TimeTicks effective_start = start_time + delta; 865 base::TimeTicks effective_start = start_time + delta;
875 866
876 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 867 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
877 cc::AnimationEvent::Started, 868 cc::AnimationEvent::Started,
878 0, 869 0,
879 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 870 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
880 ->animation_group_id(), 871 ->animation_group_id(),
881 cc::Animation::Opacity, 872 cc::Animation::Opacity,
882 effective_start)); 873 effective_start));
883 874
884 element->Step(effective_start + delta/2); 875 animator->Step(effective_start + delta / 2);
885 876
886 test_controller.animator()->StartAnimation( 877 test_controller.animator()->StartAnimation(
887 new LayerAnimationSequence( 878 new LayerAnimationSequence(
888 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 879 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
889 880
890 EXPECT_TRUE(test_controller.animator()->is_animating()); 881 EXPECT_TRUE(test_controller.animator()->is_animating());
891 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); 882 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon);
892 883
893 test_controller.animator()->StartAnimation( 884 test_controller.animator()->StartAnimation(
894 new LayerAnimationSequence( 885 new LayerAnimationSequence(
895 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 886 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
896 887
897 EXPECT_TRUE(test_controller.animator()->is_animating()); 888 EXPECT_TRUE(test_controller.animator()->is_animating());
898 889
899 base::TimeTicks second_effective_start = effective_start + delta; 890 base::TimeTicks second_effective_start = effective_start + delta;
900 891
901 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 892 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
902 cc::AnimationEvent::Started, 893 cc::AnimationEvent::Started,
903 0, 894 0,
904 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 895 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
905 ->animation_group_id(), 896 ->animation_group_id(),
906 cc::Animation::Opacity, 897 cc::Animation::Opacity,
907 second_effective_start)); 898 second_effective_start));
908 899
909 element->Step(second_effective_start + delta/2); 900 animator->Step(second_effective_start + delta / 2);
910 901
911 EXPECT_TRUE(test_controller.animator()->is_animating()); 902 EXPECT_TRUE(test_controller.animator()->is_animating());
912 EXPECT_NEAR( 903 EXPECT_NEAR(
913 0.5, 904 0.5,
914 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> 905 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
915 last_progressed_fraction(), 906 last_progressed_fraction(),
916 epsilon); 907 epsilon);
917 908
918 element->Step(second_effective_start + delta); 909 animator->Step(second_effective_start + delta);
919 910
920 EXPECT_FALSE(test_controller.animator()->is_animating()); 911 EXPECT_FALSE(test_controller.animator()->is_animating());
921 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 912 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
922 } 913 }
923 914
924 // Preempt by enqueuing the new animation. 915 // Preempt by enqueuing the new animation.
925 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { 916 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
926 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 917 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
927 AnimationContainerElement* element = animator.get();
928 animator->set_disable_timer_for_test(true); 918 animator->set_disable_timer_for_test(true);
929 TestLayerAnimationDelegate delegate; 919 TestLayerAnimationDelegate delegate;
930 animator->SetDelegate(&delegate); 920 animator->SetDelegate(&delegate);
931 921
932 double start_brightness(0.0); 922 double start_brightness(0.0);
933 double middle_brightness(0.5); 923 double middle_brightness(0.5);
934 double target_brightness(1.0); 924 double target_brightness(1.0);
935 925
936 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 926 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
937 927
938 delegate.SetBrightnessFromAnimation(start_brightness); 928 delegate.SetBrightnessFromAnimation(start_brightness);
939 929
940 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 930 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
941 931
942 animator->StartAnimation( 932 animator->StartAnimation(
943 new LayerAnimationSequence( 933 new LayerAnimationSequence(
944 LayerAnimationElement::CreateBrightnessElement(target_brightness, 934 LayerAnimationElement::CreateBrightnessElement(target_brightness,
945 delta))); 935 delta)));
946 936
947 base::TimeTicks start_time = animator->last_step_time(); 937 base::TimeTicks start_time = animator->last_step_time();
948 938
949 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 939 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
950 940
951 animator->StartAnimation( 941 animator->StartAnimation(
952 new LayerAnimationSequence( 942 new LayerAnimationSequence(
953 LayerAnimationElement::CreateBrightnessElement(start_brightness, 943 LayerAnimationElement::CreateBrightnessElement(start_brightness,
954 delta))); 944 delta)));
955 945
956 EXPECT_TRUE(animator->is_animating()); 946 EXPECT_TRUE(animator->is_animating());
957 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 947 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
958 948
959 EXPECT_TRUE(animator->is_animating()); 949 EXPECT_TRUE(animator->is_animating());
960 950
961 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 951 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
962 952
963 EXPECT_TRUE(animator->is_animating()); 953 EXPECT_TRUE(animator->is_animating());
964 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 954 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
965 955
966 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 956 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
967 957
968 EXPECT_TRUE(animator->is_animating()); 958 EXPECT_TRUE(animator->is_animating());
969 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 959 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
970 960
971 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 961 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
972 962
973 EXPECT_FALSE(animator->is_animating()); 963 EXPECT_FALSE(animator->is_animating());
974 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 964 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
975 } 965 }
976 966
977 // Start an animation when there are sequences waiting in the queue. In this 967 // Start an animation when there are sequences waiting in the queue. In this
978 // case, all pending and running animations should be finished, and the new 968 // case, all pending and running animations should be finished, and the new
979 // animation started. 969 // animation started.
980 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { 970 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
981 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 971 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
982 AnimationContainerElement* element = animator.get();
983 animator->set_disable_timer_for_test(true); 972 animator->set_disable_timer_for_test(true);
984 TestLayerAnimationDelegate delegate; 973 TestLayerAnimationDelegate delegate;
985 animator->SetDelegate(&delegate); 974 animator->SetDelegate(&delegate);
986 975
987 double start_brightness(0.0); 976 double start_brightness(0.0);
988 double middle_brightness(0.5); 977 double middle_brightness(0.5);
989 double target_brightness(1.0); 978 double target_brightness(1.0);
990 979
991 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 980 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
992 981
993 delegate.SetBrightnessFromAnimation(start_brightness); 982 delegate.SetBrightnessFromAnimation(start_brightness);
994 983
995 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 984 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
996 985
997 animator->StartAnimation( 986 animator->StartAnimation(
998 new LayerAnimationSequence( 987 new LayerAnimationSequence(
999 LayerAnimationElement::CreateBrightnessElement(target_brightness, 988 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1000 delta))); 989 delta)));
1001 990
1002 base::TimeTicks start_time = animator->last_step_time(); 991 base::TimeTicks start_time = animator->last_step_time();
1003 992
1004 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 993 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1005 994
1006 animator->StartAnimation( 995 animator->StartAnimation(
1007 new LayerAnimationSequence( 996 new LayerAnimationSequence(
1008 LayerAnimationElement::CreateBrightnessElement(middle_brightness, 997 LayerAnimationElement::CreateBrightnessElement(middle_brightness,
1009 delta))); 998 delta)));
1010 999
1011 // Queue should now have two animations. Starting a third should replace the 1000 // Queue should now have two animations. Starting a third should replace the
1012 // second. 1001 // second.
1013 animator->StartAnimation( 1002 animator->StartAnimation(
1014 new LayerAnimationSequence( 1003 new LayerAnimationSequence(
1015 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1004 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1016 delta))); 1005 delta)));
1017 1006
1018 EXPECT_TRUE(animator->is_animating()); 1007 EXPECT_TRUE(animator->is_animating());
1019 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1008 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1020 1009
1021 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1010 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1022 1011
1023 EXPECT_TRUE(animator->is_animating()); 1012 EXPECT_TRUE(animator->is_animating());
1024 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1013 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1025 1014
1026 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1015 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1027 1016
1028 EXPECT_TRUE(animator->is_animating()); 1017 EXPECT_TRUE(animator->is_animating());
1029 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1018 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1030 1019
1031 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1020 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1032 1021
1033 EXPECT_FALSE(animator->is_animating()); 1022 EXPECT_FALSE(animator->is_animating());
1034 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1023 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1035 } 1024 }
1036 1025
1037 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { 1026 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
1038 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1027 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1039 animator->set_disable_timer_for_test(true); 1028 animator->set_disable_timer_for_test(true);
1040 TestLayerAnimationDelegate delegate; 1029 TestLayerAnimationDelegate delegate;
1041 animator->SetDelegate(&delegate); 1030 animator->SetDelegate(&delegate);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 )); 1095 ));
1107 1096
1108 EXPECT_FALSE(animator->is_animating()); 1097 EXPECT_FALSE(animator->is_animating());
1109 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1098 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1110 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1099 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1111 } 1100 }
1112 1101
1113 // Preempt by animating to new target. 1102 // Preempt by animating to new target.
1114 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { 1103 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
1115 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1104 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1116 AnimationContainerElement* element = animator.get();
1117 animator->set_disable_timer_for_test(true); 1105 animator->set_disable_timer_for_test(true);
1118 TestLayerAnimationDelegate delegate; 1106 TestLayerAnimationDelegate delegate;
1119 animator->SetDelegate(&delegate); 1107 animator->SetDelegate(&delegate);
1120 1108
1121 double start_grayscale(0.0); 1109 double start_grayscale(0.0);
1122 double middle_grayscale(0.5); 1110 double middle_grayscale(0.5);
1123 double target_grayscale(1.0); 1111 double target_grayscale(1.0);
1124 1112
1125 double start_brightness(0.1); 1113 double start_brightness(0.1);
1126 double middle_brightness(0.2); 1114 double middle_brightness(0.2);
(...skipping 10 matching lines...) Expand all
1137 animator->StartTogether( 1125 animator->StartTogether(
1138 CreateMultiSequence( 1126 CreateMultiSequence(
1139 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, 1127 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1140 delta), 1128 delta),
1141 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1129 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1142 delta) 1130 delta)
1143 )); 1131 ));
1144 1132
1145 base::TimeTicks start_time = animator->last_step_time(); 1133 base::TimeTicks start_time = animator->last_step_time();
1146 1134
1147 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1135 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1148 1136
1149 animator->StartTogether( 1137 animator->StartTogether(
1150 CreateMultiSequence( 1138 CreateMultiSequence(
1151 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), 1139 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
1152 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1140 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1153 delta))); 1141 delta)));
1154 1142
1155 EXPECT_TRUE(animator->is_animating()); 1143 EXPECT_TRUE(animator->is_animating());
1156 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 1144 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
1157 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1145 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1158 1146
1159 animator->StartTogether( 1147 animator->StartTogether(
1160 CreateMultiSequence( 1148 CreateMultiSequence(
1161 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), 1149 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
1162 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1150 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1163 delta))); 1151 delta)));
1164 1152
1165 EXPECT_TRUE(animator->is_animating()); 1153 EXPECT_TRUE(animator->is_animating());
1166 1154
1167 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1155 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1168 1156
1169 EXPECT_TRUE(animator->is_animating()); 1157 EXPECT_TRUE(animator->is_animating());
1170 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), 1158 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(),
1171 0.5 * (start_grayscale + middle_grayscale)); 1159 0.5 * (start_grayscale + middle_grayscale));
1172 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 1160 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
1173 0.5 * (start_brightness + middle_brightness)); 1161 0.5 * (start_brightness + middle_brightness));
1174 1162
1175 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1163 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1176 1164
1177 EXPECT_FALSE(animator->is_animating()); 1165 EXPECT_FALSE(animator->is_animating());
1178 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1166 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1179 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1167 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1180 } 1168 }
1181 1169
1182 // Preempt a threaded animation by animating to new target. 1170 // Preempt a threaded animation by animating to new target.
1183 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { 1171 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
1184 double epsilon = 0.00001; 1172 double epsilon = 0.00001;
1185 LayerAnimatorTestController test_controller( 1173 LayerAnimatorTestController test_controller(
1186 LayerAnimator::CreateDefaultAnimator()); 1174 LayerAnimator::CreateDefaultAnimator());
1187 AnimationContainerElement* element = test_controller.animator(); 1175 LayerAnimator* animator = test_controller.animator();
1188 test_controller.animator()->set_disable_timer_for_test(true); 1176 test_controller.animator()->set_disable_timer_for_test(true);
1189 TestLayerAnimationDelegate delegate; 1177 TestLayerAnimationDelegate delegate;
1190 test_controller.animator()->SetDelegate(&delegate); 1178 test_controller.animator()->SetDelegate(&delegate);
1191 1179
1192 double start_opacity(0.0); 1180 double start_opacity(0.0);
1193 double middle_opacity(0.5); 1181 double middle_opacity(0.5);
1194 double target_opacity(1.0); 1182 double target_opacity(1.0);
1195 1183
1196 double start_brightness(0.1); 1184 double start_brightness(0.1);
1197 double middle_brightness(0.2); 1185 double middle_brightness(0.2);
(...skipping 18 matching lines...) Expand all
1216 base::TimeTicks effective_start = start_time + delta; 1204 base::TimeTicks effective_start = start_time + delta;
1217 1205
1218 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1206 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1219 cc::AnimationEvent::Started, 1207 cc::AnimationEvent::Started,
1220 0, 1208 0,
1221 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1209 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1222 ->animation_group_id(), 1210 ->animation_group_id(),
1223 cc::Animation::Opacity, 1211 cc::Animation::Opacity,
1224 effective_start)); 1212 effective_start));
1225 1213
1226 element->Step(effective_start + delta/2); 1214 animator->Step(effective_start + delta / 2);
1227 1215
1228 test_controller.animator()->StartTogether( 1216 test_controller.animator()->StartTogether(
1229 CreateMultiSequence( 1217 CreateMultiSequence(
1230 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1218 LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
1231 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1219 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1232 delta))); 1220 delta)));
1233 1221
1234 EXPECT_TRUE(test_controller.animator()->is_animating()); 1222 EXPECT_TRUE(test_controller.animator()->is_animating());
1235 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); 1223 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon);
1236 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon); 1224 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon);
1237 1225
1238 test_controller.animator()->StartTogether( 1226 test_controller.animator()->StartTogether(
1239 CreateMultiSequence( 1227 CreateMultiSequence(
1240 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1228 LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
1241 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1229 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1242 delta))); 1230 delta)));
1243 1231
1244 EXPECT_TRUE(test_controller.animator()->is_animating()); 1232 EXPECT_TRUE(test_controller.animator()->is_animating());
1245 1233
1246 base::TimeTicks second_effective_start = effective_start + delta; 1234 base::TimeTicks second_effective_start = effective_start + delta;
1247 1235
1248 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1236 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1249 cc::AnimationEvent::Started, 1237 cc::AnimationEvent::Started,
1250 0, 1238 0,
1251 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1239 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1252 ->animation_group_id(), 1240 ->animation_group_id(),
1253 cc::Animation::Opacity, 1241 cc::Animation::Opacity,
1254 second_effective_start)); 1242 second_effective_start));
1255 1243
1256 element->Step(second_effective_start + delta/2); 1244 animator->Step(second_effective_start + delta / 2);
1257 1245
1258 EXPECT_TRUE(test_controller.animator()->is_animating()); 1246 EXPECT_TRUE(test_controller.animator()->is_animating());
1259 EXPECT_NEAR( 1247 EXPECT_NEAR(
1260 0.5, 1248 0.5,
1261 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> 1249 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1262 last_progressed_fraction(), 1250 last_progressed_fraction(),
1263 epsilon); 1251 epsilon);
1264 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), 1252 EXPECT_NEAR(delegate.GetBrightnessForAnimation(),
1265 0.5 * (start_brightness + middle_brightness), 1253 0.5 * (start_brightness + middle_brightness),
1266 epsilon); 1254 epsilon);
1267 1255
1268 element->Step(second_effective_start + delta); 1256 animator->Step(second_effective_start + delta);
1269 1257
1270 EXPECT_FALSE(test_controller.animator()->is_animating()); 1258 EXPECT_FALSE(test_controller.animator()->is_animating());
1271 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1259 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1272 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1260 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1273 } 1261 }
1274 1262
1275 // Preempt by enqueuing the new animation. 1263 // Preempt by enqueuing the new animation.
1276 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { 1264 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
1277 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1265 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1278 AnimationContainerElement* element = animator.get();
1279 animator->set_disable_timer_for_test(true); 1266 animator->set_disable_timer_for_test(true);
1280 TestLayerAnimationDelegate delegate; 1267 TestLayerAnimationDelegate delegate;
1281 animator->SetDelegate(&delegate); 1268 animator->SetDelegate(&delegate);
1282 1269
1283 double start_grayscale(0.0); 1270 double start_grayscale(0.0);
1284 double middle_grayscale(0.5); 1271 double middle_grayscale(0.5);
1285 double target_grayscale(1.0); 1272 double target_grayscale(1.0);
1286 1273
1287 double start_brightness(0.1); 1274 double start_brightness(0.1);
1288 double middle_brightness(0.2); 1275 double middle_brightness(0.2);
1289 double target_brightness(0.3); 1276 double target_brightness(0.3);
1290 1277
1291 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1278 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1292 1279
1293 delegate.SetGrayscaleFromAnimation(start_grayscale); 1280 delegate.SetGrayscaleFromAnimation(start_grayscale);
1294 delegate.SetBrightnessFromAnimation(start_brightness); 1281 delegate.SetBrightnessFromAnimation(start_brightness);
1295 1282
1296 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 1283 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
1297 1284
1298 animator->StartTogether( 1285 animator->StartTogether(
1299 CreateMultiSequence( 1286 CreateMultiSequence(
1300 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, 1287 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1301 delta), 1288 delta),
1302 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1289 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1303 delta))); 1290 delta)));
1304 1291
1305 base::TimeTicks start_time = animator->last_step_time(); 1292 base::TimeTicks start_time = animator->last_step_time();
1306 1293
1307 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1294 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1308 1295
1309 animator->StartTogether( 1296 animator->StartTogether(
1310 CreateMultiSequence( 1297 CreateMultiSequence(
1311 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), 1298 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
1312 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1299 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1313 delta))); 1300 delta)));
1314 1301
1315 EXPECT_TRUE(animator->is_animating()); 1302 EXPECT_TRUE(animator->is_animating());
1316 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 1303 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
1317 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1304 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1318 1305
1319 EXPECT_TRUE(animator->is_animating()); 1306 EXPECT_TRUE(animator->is_animating());
1320 1307
1321 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1308 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1322 1309
1323 EXPECT_TRUE(animator->is_animating()); 1310 EXPECT_TRUE(animator->is_animating());
1324 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); 1311 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
1325 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1312 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1326 1313
1327 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1314 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1328 1315
1329 EXPECT_TRUE(animator->is_animating()); 1316 EXPECT_TRUE(animator->is_animating());
1330 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 1317 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
1331 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1318 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1332 1319
1333 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1320 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1334 1321
1335 EXPECT_FALSE(animator->is_animating()); 1322 EXPECT_FALSE(animator->is_animating());
1336 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1323 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1337 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1324 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1338 } 1325 }
1339 1326
1340 // Start an animation when there are sequences waiting in the queue. In this 1327 // Start an animation when there are sequences waiting in the queue. In this
1341 // case, all pending and running animations should be finished, and the new 1328 // case, all pending and running animations should be finished, and the new
1342 // animation started. 1329 // animation started.
1343 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { 1330 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
1344 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1331 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1345 AnimationContainerElement* element = animator.get();
1346 animator->set_disable_timer_for_test(true); 1332 animator->set_disable_timer_for_test(true);
1347 TestLayerAnimationDelegate delegate; 1333 TestLayerAnimationDelegate delegate;
1348 animator->SetDelegate(&delegate); 1334 animator->SetDelegate(&delegate);
1349 1335
1350 double start_grayscale(0.0); 1336 double start_grayscale(0.0);
1351 double middle_grayscale(0.5); 1337 double middle_grayscale(0.5);
1352 double target_grayscale(1.0); 1338 double target_grayscale(1.0);
1353 1339
1354 double start_brightness(0.1); 1340 double start_brightness(0.1);
1355 double middle_brightness(0.2); 1341 double middle_brightness(0.2);
1356 double target_brightness(0.3); 1342 double target_brightness(0.3);
1357 1343
1358 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1344 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1359 1345
1360 delegate.SetGrayscaleFromAnimation(start_grayscale); 1346 delegate.SetGrayscaleFromAnimation(start_grayscale);
1361 delegate.SetBrightnessFromAnimation(start_brightness); 1347 delegate.SetBrightnessFromAnimation(start_brightness);
1362 1348
1363 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 1349 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
1364 1350
1365 animator->StartTogether( 1351 animator->StartTogether(
1366 CreateMultiSequence( 1352 CreateMultiSequence(
1367 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, 1353 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1368 delta), 1354 delta),
1369 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1355 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1370 delta))); 1356 delta)));
1371 1357
1372 base::TimeTicks start_time = animator->last_step_time(); 1358 base::TimeTicks start_time = animator->last_step_time();
1373 1359
1374 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1360 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1375 1361
1376 animator->StartTogether( 1362 animator->StartTogether(
1377 CreateMultiSequence( 1363 CreateMultiSequence(
1378 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale, 1364 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale,
1379 delta), 1365 delta),
1380 LayerAnimationElement::CreateBrightnessElement(middle_brightness, 1366 LayerAnimationElement::CreateBrightnessElement(middle_brightness,
1381 delta))); 1367 delta)));
1382 1368
1383 // Queue should now have two animations. Starting a third should replace the 1369 // Queue should now have two animations. Starting a third should replace the
1384 // second. 1370 // second.
1385 animator->StartTogether( 1371 animator->StartTogether(
1386 CreateMultiSequence( 1372 CreateMultiSequence(
1387 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), 1373 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
1388 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1374 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1389 delta))); 1375 delta)));
1390 1376
1391 EXPECT_TRUE(animator->is_animating()); 1377 EXPECT_TRUE(animator->is_animating());
1392 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 1378 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
1393 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1379 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1394 1380
1395 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1381 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1396 1382
1397 EXPECT_TRUE(animator->is_animating()); 1383 EXPECT_TRUE(animator->is_animating());
1398 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); 1384 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
1399 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1385 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1400 1386
1401 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1387 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1402 1388
1403 EXPECT_TRUE(animator->is_animating()); 1389 EXPECT_TRUE(animator->is_animating());
1404 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); 1390 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
1405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1391 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1406 1392
1407 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1393 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1408 1394
1409 EXPECT_FALSE(animator->is_animating()); 1395 EXPECT_FALSE(animator->is_animating());
1410 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); 1396 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1411 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1397 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1412 } 1398 }
1413 //------------------------------------------------------- 1399 //-------------------------------------------------------
1414 // Test that non-threaded cyclic sequences continue to animate. 1400 // Test that non-threaded cyclic sequences continue to animate.
1415 TEST(LayerAnimatorTest, CyclicSequences) { 1401 TEST(LayerAnimatorTest, CyclicSequences) {
1416 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1402 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1417 AnimationContainerElement* element = animator.get();
1418 animator->set_disable_timer_for_test(true); 1403 animator->set_disable_timer_for_test(true);
1419 TestLayerAnimationDelegate delegate; 1404 TestLayerAnimationDelegate delegate;
1420 animator->SetDelegate(&delegate); 1405 animator->SetDelegate(&delegate);
1421 1406
1422 double start_brightness(0.0); 1407 double start_brightness(0.0);
1423 double target_brightness(1.0); 1408 double target_brightness(1.0);
1424 1409
1425 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1410 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1426 1411
1427 delegate.SetBrightnessFromAnimation(start_brightness); 1412 delegate.SetBrightnessFromAnimation(start_brightness);
1428 1413
1429 scoped_ptr<LayerAnimationSequence> sequence( 1414 scoped_ptr<LayerAnimationSequence> sequence(
1430 new LayerAnimationSequence( 1415 new LayerAnimationSequence(
1431 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1416 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1432 delta))); 1417 delta)));
1433 1418
1434 sequence->AddElement( 1419 sequence->AddElement(
1435 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); 1420 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta));
1436 1421
1437 sequence->set_is_cyclic(true); 1422 sequence->set_is_cyclic(true);
1438 1423
1439 animator->StartAnimation(sequence.release()); 1424 animator->StartAnimation(sequence.release());
1440 1425
1441 base::TimeTicks start_time = animator->last_step_time(); 1426 base::TimeTicks start_time = animator->last_step_time();
1442 1427
1443 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1428 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1444 1429
1445 EXPECT_TRUE(animator->is_animating()); 1430 EXPECT_TRUE(animator->is_animating());
1446 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1431 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1447 1432
1448 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1433 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1449 1434
1450 EXPECT_TRUE(animator->is_animating()); 1435 EXPECT_TRUE(animator->is_animating());
1451 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1436 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1452 1437
1453 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); 1438 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
1454 1439
1455 EXPECT_TRUE(animator->is_animating()); 1440 EXPECT_TRUE(animator->is_animating());
1456 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1441 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1457 1442
1458 // Skip ahead by a lot. 1443 // Skip ahead by a lot.
1459 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); 1444 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000));
1460 1445
1461 EXPECT_TRUE(animator->is_animating()); 1446 EXPECT_TRUE(animator->is_animating());
1462 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1447 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1463 1448
1464 // Skip ahead by a lot. 1449 // Skip ahead by a lot.
1465 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); 1450 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000));
1466 1451
1467 EXPECT_TRUE(animator->is_animating()); 1452 EXPECT_TRUE(animator->is_animating());
1468 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1453 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1469 1454
1470 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); 1455 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS);
1471 1456
1472 EXPECT_FALSE(animator->is_animating()); 1457 EXPECT_FALSE(animator->is_animating());
1473 } 1458 }
1474 1459
1475 // Test that threaded cyclic sequences continue to animate. 1460 // Test that threaded cyclic sequences continue to animate.
1476 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { 1461 TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
1477 LayerAnimatorTestController test_controller( 1462 LayerAnimatorTestController test_controller(
1478 LayerAnimator::CreateDefaultAnimator()); 1463 LayerAnimator::CreateDefaultAnimator());
1479 AnimationContainerElement* element = test_controller.animator(); 1464 LayerAnimator* animator = test_controller.animator();
1480 test_controller.animator()->set_disable_timer_for_test(true); 1465 test_controller.animator()->set_disable_timer_for_test(true);
1481 TestLayerAnimationDelegate delegate; 1466 TestLayerAnimationDelegate delegate;
1482 test_controller.animator()->SetDelegate(&delegate); 1467 test_controller.animator()->SetDelegate(&delegate);
1483 1468
1484 double start_opacity(0.0); 1469 double start_opacity(0.0);
1485 double target_opacity(1.0); 1470 double target_opacity(1.0);
1486 1471
1487 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1472 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1488 1473
1489 delegate.SetOpacityFromAnimation(start_opacity); 1474 delegate.SetOpacityFromAnimation(start_opacity);
(...skipping 13 matching lines...) Expand all
1503 base::TimeTicks effective_start = start_time + delta; 1488 base::TimeTicks effective_start = start_time + delta;
1504 1489
1505 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1490 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1506 cc::AnimationEvent::Started, 1491 cc::AnimationEvent::Started,
1507 0, 1492 0,
1508 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1493 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1509 ->animation_group_id(), 1494 ->animation_group_id(),
1510 cc::Animation::Opacity, 1495 cc::Animation::Opacity,
1511 effective_start)); 1496 effective_start));
1512 1497
1513 element->Step(effective_start + delta); 1498 animator->Step(effective_start + delta);
1514 EXPECT_TRUE(test_controller.animator()->is_animating()); 1499 EXPECT_TRUE(test_controller.animator()->is_animating());
1515 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1500 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1516 1501
1517 base::TimeTicks second_effective_start = effective_start + 2 * delta; 1502 base::TimeTicks second_effective_start = effective_start + 2 * delta;
1518 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1503 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1519 cc::AnimationEvent::Started, 1504 cc::AnimationEvent::Started,
1520 0, 1505 0,
1521 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1506 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1522 ->animation_group_id(), 1507 ->animation_group_id(),
1523 cc::Animation::Opacity, 1508 cc::Animation::Opacity,
1524 second_effective_start)); 1509 second_effective_start));
1525 1510
1526 element->Step(second_effective_start + delta); 1511 animator->Step(second_effective_start + delta);
1527 1512
1528 EXPECT_TRUE(test_controller.animator()->is_animating()); 1513 EXPECT_TRUE(test_controller.animator()->is_animating());
1529 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1514 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1530 1515
1531 base::TimeTicks third_effective_start = second_effective_start + 2 * delta; 1516 base::TimeTicks third_effective_start = second_effective_start + 2 * delta;
1532 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1517 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1533 cc::AnimationEvent::Started, 1518 cc::AnimationEvent::Started,
1534 0, 1519 0,
1535 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1520 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1536 ->animation_group_id(), 1521 ->animation_group_id(),
1537 cc::Animation::Opacity, 1522 cc::Animation::Opacity,
1538 third_effective_start)); 1523 third_effective_start));
1539 1524
1540 element->Step(third_effective_start + delta); 1525 animator->Step(third_effective_start + delta);
1541 EXPECT_TRUE(test_controller.animator()->is_animating()); 1526 EXPECT_TRUE(test_controller.animator()->is_animating());
1542 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1527 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1543 1528
1544 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta; 1529 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta;
1545 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1530 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1546 cc::AnimationEvent::Started, 1531 cc::AnimationEvent::Started,
1547 0, 1532 0,
1548 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1533 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1549 ->animation_group_id(), 1534 ->animation_group_id(),
1550 cc::Animation::Opacity, 1535 cc::Animation::Opacity,
1551 fourth_effective_start)); 1536 fourth_effective_start));
1552 1537
1553 // Skip ahead by a lot. 1538 // Skip ahead by a lot.
1554 element->Step(fourth_effective_start + 1000 * delta); 1539 animator->Step(fourth_effective_start + 1000 * delta);
1555 1540
1556 EXPECT_TRUE(test_controller.animator()->is_animating()); 1541 EXPECT_TRUE(test_controller.animator()->is_animating());
1557 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1542 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1558 1543
1559 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta; 1544 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta;
1560 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( 1545 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1561 cc::AnimationEvent::Started, 1546 cc::AnimationEvent::Started,
1562 0, 1547 0,
1563 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) 1548 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)
1564 ->animation_group_id(), 1549 ->animation_group_id(),
1565 cc::Animation::Opacity, 1550 cc::Animation::Opacity,
1566 fifth_effective_start)); 1551 fifth_effective_start));
1567 1552
1568 // Skip ahead by a lot. 1553 // Skip ahead by a lot.
1569 element->Step(fifth_effective_start + 999 * delta); 1554 animator->Step(fifth_effective_start + 999 * delta);
1570 1555
1571 EXPECT_TRUE(test_controller.animator()->is_animating()); 1556 EXPECT_TRUE(test_controller.animator()->is_animating());
1572 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1557 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1573 1558
1574 test_controller.animator()->StopAnimatingProperty( 1559 test_controller.animator()->StopAnimatingProperty(
1575 LayerAnimationElement::OPACITY); 1560 LayerAnimationElement::OPACITY);
1576 1561
1577 EXPECT_FALSE(test_controller.animator()->is_animating()); 1562 EXPECT_FALSE(test_controller.animator()->is_animating());
1578 } 1563 }
1579 1564
1580 TEST(LayerAnimatorTest, AddObserverExplicit) { 1565 TEST(LayerAnimatorTest, AddObserverExplicit) {
1581 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1566 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1582 AnimationContainerElement* element = animator.get();
1583 animator->set_disable_timer_for_test(true); 1567 animator->set_disable_timer_for_test(true);
1584 TestLayerAnimationObserver observer; 1568 TestLayerAnimationObserver observer;
1585 TestLayerAnimationDelegate delegate; 1569 TestLayerAnimationDelegate delegate;
1586 animator->SetDelegate(&delegate); 1570 animator->SetDelegate(&delegate);
1587 animator->AddObserver(&observer); 1571 animator->AddObserver(&observer);
1588 observer.set_requires_notification_when_animator_destroyed(true); 1572 observer.set_requires_notification_when_animator_destroyed(true);
1589 1573
1590 EXPECT_TRUE(!observer.last_ended_sequence()); 1574 EXPECT_TRUE(!observer.last_ended_sequence());
1591 1575
1592 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1576 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1593 1577
1594 delegate.SetBrightnessFromAnimation(0.0f); 1578 delegate.SetBrightnessFromAnimation(0.0f);
1595 1579
1596 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1580 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1597 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1581 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1598 1582
1599 animator->StartAnimation(sequence); 1583 animator->StartAnimation(sequence);
1600 1584
1601 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 1585 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
1602 1586
1603 base::TimeTicks start_time = animator->last_step_time(); 1587 base::TimeTicks start_time = animator->last_step_time();
1604 1588
1605 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1589 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1606 1590
1607 EXPECT_EQ(observer.last_ended_sequence(), sequence); 1591 EXPECT_EQ(observer.last_ended_sequence(), sequence);
1608 1592
1609 // |sequence| has been destroyed. Recreate it to test abort. 1593 // |sequence| has been destroyed. Recreate it to test abort.
1610 sequence = new LayerAnimationSequence( 1594 sequence = new LayerAnimationSequence(
1611 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1595 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1612 1596
1613 animator->StartAnimation(sequence); 1597 animator->StartAnimation(sequence);
1614 1598
1615 animator = NULL; 1599 animator = NULL;
1616 1600
1617 EXPECT_EQ(observer.last_aborted_sequence(), sequence); 1601 EXPECT_EQ(observer.last_aborted_sequence(), sequence);
1618 } 1602 }
1619 1603
1620 // Tests that an observer added to a scoped settings object is still notified 1604 // Tests that an observer added to a scoped settings object is still notified
1621 // when the object goes out of scope. 1605 // when the object goes out of scope.
1622 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { 1606 TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
1623 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1607 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1624 AnimationContainerElement* element = animator.get();
1625 animator->set_disable_timer_for_test(true); 1608 animator->set_disable_timer_for_test(true);
1626 TestImplicitAnimationObserver observer(false); 1609 TestImplicitAnimationObserver observer(false);
1627 TestLayerAnimationDelegate delegate; 1610 TestLayerAnimationDelegate delegate;
1628 animator->SetDelegate(&delegate); 1611 animator->SetDelegate(&delegate);
1629 1612
1630 EXPECT_FALSE(observer.animations_completed()); 1613 EXPECT_FALSE(observer.animations_completed());
1631 animator->SetBrightness(1.0f); 1614 animator->SetBrightness(1.0f);
1632 1615
1633 { 1616 {
1634 ScopedLayerAnimationSettings settings(animator.get()); 1617 ScopedLayerAnimationSettings settings(animator.get());
1635 settings.AddObserver(&observer); 1618 settings.AddObserver(&observer);
1636 animator->SetBrightness(0.0f); 1619 animator->SetBrightness(0.0f);
1637 } 1620 }
1638 1621
1639 EXPECT_FALSE(observer.animations_completed()); 1622 EXPECT_FALSE(observer.animations_completed());
1640 base::TimeTicks start_time = animator->last_step_time(); 1623 base::TimeTicks start_time = animator->last_step_time();
1641 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1624 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1642 EXPECT_TRUE(observer.animations_completed()); 1625 EXPECT_TRUE(observer.animations_completed());
1643 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( 1626 EXPECT_TRUE(observer.WasAnimationCompletedForProperty(
1644 LayerAnimationElement::BRIGHTNESS)); 1627 LayerAnimationElement::BRIGHTNESS));
1645 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); 1628 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation());
1646 } 1629 }
1647 1630
1648 // Tests that an observer added to a scoped settings object is still notified 1631 // Tests that an observer added to a scoped settings object is still notified
1649 // when the object goes out of scope due to the animation being interrupted. 1632 // when the object goes out of scope due to the animation being interrupted.
1650 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { 1633 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
1651 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1634 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
(...skipping 21 matching lines...) Expand all
1673 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); 1656 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation());
1674 } 1657 }
1675 1658
1676 // Tests that LayerAnimator is not deleted after the animation completes as long 1659 // Tests that LayerAnimator is not deleted after the animation completes as long
1677 // as there is a live ScopedLayerAnimationSettings object wrapped around it. 1660 // as there is a live ScopedLayerAnimationSettings object wrapped around it.
1678 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { 1661 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) {
1679 // Note we are using a raw pointer unlike in other tests. 1662 // Note we are using a raw pointer unlike in other tests.
1680 TestLayerAnimator* animator = new TestLayerAnimator(); 1663 TestLayerAnimator* animator = new TestLayerAnimator();
1681 LayerAnimatorDestructionObserver destruction_observer; 1664 LayerAnimatorDestructionObserver destruction_observer;
1682 animator->SetDestructionObserver(&destruction_observer); 1665 animator->SetDestructionObserver(&destruction_observer);
1683 AnimationContainerElement* element = animator;
1684 animator->set_disable_timer_for_test(true); 1666 animator->set_disable_timer_for_test(true);
1685 TestLayerAnimationDelegate delegate; 1667 TestLayerAnimationDelegate delegate;
1686 animator->SetDelegate(&delegate); 1668 animator->SetDelegate(&delegate);
1687 { 1669 {
1688 // ScopedLayerAnimationSettings should keep the Animator alive as long as 1670 // ScopedLayerAnimationSettings should keep the Animator alive as long as
1689 // it is alive, even beyond the end of the animation. 1671 // it is alive, even beyond the end of the animation.
1690 ScopedLayerAnimationSettings settings(animator); 1672 ScopedLayerAnimationSettings settings(animator);
1691 base::TimeTicks now = gfx::FrameTime::Now(); 1673 base::TimeTicks now = gfx::FrameTime::Now();
1692 animator->SetBrightness(0.5); 1674 animator->SetBrightness(0.5);
1693 element->Step(now + base::TimeDelta::FromSeconds(1)); 1675 animator->Step(now + base::TimeDelta::FromSeconds(1));
1694 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); 1676 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted());
1695 } 1677 }
1696 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. 1678 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted.
1697 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); 1679 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted());
1698 } 1680 }
1699 1681
1700 // Tests that an observer added to a scoped settings object is not notified 1682 // Tests that an observer added to a scoped settings object is not notified
1701 // when the animator is destroyed unless explicitly requested. 1683 // when the animator is destroyed unless explicitly requested.
1702 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { 1684 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
1703 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1685 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 animator->AbortAllAnimations(); 1745 animator->AbortAllAnimations();
1764 EXPECT_TRUE(observer.animations_completed()); 1746 EXPECT_TRUE(observer.animations_completed());
1765 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( 1747 EXPECT_TRUE(observer.WasAnimationAbortedForProperty(
1766 LayerAnimationElement::BRIGHTNESS)); 1748 LayerAnimationElement::BRIGHTNESS));
1767 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( 1749 EXPECT_TRUE(observer.WasAnimationAbortedForProperty(
1768 LayerAnimationElement::OPACITY)); 1750 LayerAnimationElement::OPACITY));
1769 } 1751 }
1770 1752
1771 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { 1753 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
1772 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1754 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1773 AnimationContainerElement* element = animator.get();
1774 animator->set_disable_timer_for_test(true); 1755 animator->set_disable_timer_for_test(true);
1775 TestLayerAnimationObserver observer; 1756 TestLayerAnimationObserver observer;
1776 TestLayerAnimationObserver removed_observer; 1757 TestLayerAnimationObserver removed_observer;
1777 TestLayerAnimationDelegate delegate; 1758 TestLayerAnimationDelegate delegate;
1778 animator->SetDelegate(&delegate); 1759 animator->SetDelegate(&delegate);
1779 1760
1780 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1761 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1781 1762
1782 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1763 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1783 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1764 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1784 1765
1785 sequence->AddObserver(&observer); 1766 sequence->AddObserver(&observer);
1786 sequence->AddObserver(&removed_observer); 1767 sequence->AddObserver(&removed_observer);
1787 1768
1788 animator->StartAnimation(sequence); 1769 animator->StartAnimation(sequence);
1789 1770
1790 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 1771 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
1791 EXPECT_TRUE(!observer.last_ended_sequence()); 1772 EXPECT_TRUE(!observer.last_ended_sequence());
1792 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); 1773 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence);
1793 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 1774 EXPECT_TRUE(!removed_observer.last_ended_sequence());
1794 1775
1795 // This should stop the observer from observing sequence. 1776 // This should stop the observer from observing sequence.
1796 animator->RemoveObserver(&removed_observer); 1777 animator->RemoveObserver(&removed_observer);
1797 1778
1798 base::TimeTicks start_time = animator->last_step_time(); 1779 base::TimeTicks start_time = animator->last_step_time();
1799 1780
1800 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1781 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1801 1782
1802 EXPECT_EQ(observer.last_ended_sequence(), sequence); 1783 EXPECT_EQ(observer.last_ended_sequence(), sequence);
1803 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 1784 EXPECT_TRUE(!removed_observer.last_ended_sequence());
1804 } 1785 }
1805 1786
1806 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { 1787 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
1807 TestLayerAnimationDelegate delegate; 1788 TestLayerAnimationDelegate delegate;
1808 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1789 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1809 animator->set_disable_timer_for_test(true); 1790 animator->set_disable_timer_for_test(true);
1810 1791
(...skipping 15 matching lines...) Expand all
1826 1807
1827 // Now, release |observer| 1808 // Now, release |observer|
1828 observer.reset(); 1809 observer.reset();
1829 1810
1830 // And |sequence| should no longer be attached to |observer|. 1811 // And |sequence| should no longer be attached to |observer|.
1831 EXPECT_FALSE(sequence->observers_.might_have_observers()); 1812 EXPECT_FALSE(sequence->observers_.might_have_observers());
1832 } 1813 }
1833 1814
1834 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { 1815 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
1835 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1816 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1836 AnimationContainerElement* element = animator.get();
1837 animator->set_disable_timer_for_test(true); 1817 animator->set_disable_timer_for_test(true);
1838 1818
1839 TestImplicitAnimationObserver observer(false); 1819 TestImplicitAnimationObserver observer(false);
1840 TestLayerAnimationDelegate delegate; 1820 TestLayerAnimationDelegate delegate;
1841 animator->SetDelegate(&delegate); 1821 animator->SetDelegate(&delegate);
1842 1822
1843 delegate.SetBrightnessFromAnimation(0.0f); 1823 delegate.SetBrightnessFromAnimation(0.0f);
1844 1824
1845 { 1825 {
1846 ScopedLayerAnimationSettings setter(animator.get()); 1826 ScopedLayerAnimationSettings setter(animator.get());
1847 1827
1848 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1828 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1849 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1829 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1850 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1830 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1851 1831
1852 animator->StartAnimation(sequence); 1832 animator->StartAnimation(sequence);
1853 base::TimeTicks start_time = animator->last_step_time(); 1833 base::TimeTicks start_time = animator->last_step_time();
1854 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1834 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1855 1835
1856 setter.AddObserver(&observer); 1836 setter.AddObserver(&observer);
1857 1837
1858 // Start observing an in-flight animation. 1838 // Start observing an in-flight animation.
1859 sequence->AddObserver(&observer); 1839 sequence->AddObserver(&observer);
1860 1840
1861 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1841 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1862 } 1842 }
1863 1843
1864 EXPECT_TRUE(observer.animations_completed()); 1844 EXPECT_TRUE(observer.animations_completed());
1865 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( 1845 EXPECT_TRUE(observer.WasAnimationCompletedForProperty(
1866 LayerAnimationElement::BRIGHTNESS)); 1846 LayerAnimationElement::BRIGHTNESS));
1867 } 1847 }
1868 1848
1869 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { 1849 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
1870 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1850 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1871 AnimationContainerElement* element = animator.get();
1872 animator->set_disable_timer_for_test(true); 1851 animator->set_disable_timer_for_test(true);
1873 1852
1874 TestImplicitAnimationObserver observer(false); 1853 TestImplicitAnimationObserver observer(false);
1875 TestLayerAnimationDelegate delegate; 1854 TestLayerAnimationDelegate delegate;
1876 animator->SetDelegate(&delegate); 1855 animator->SetDelegate(&delegate);
1877 1856
1878 delegate.SetBrightnessFromAnimation(0.0f); 1857 delegate.SetBrightnessFromAnimation(0.0f);
1879 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1858 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1880 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1859 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1881 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 1860 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1882 1861
1883 { 1862 {
1884 ScopedLayerAnimationSettings setter(animator.get()); 1863 ScopedLayerAnimationSettings setter(animator.get());
1885 setter.AddObserver(&observer); 1864 setter.AddObserver(&observer);
1886 1865
1887 animator->StartAnimation(sequence); 1866 animator->StartAnimation(sequence);
1888 base::TimeTicks start_time = animator->last_step_time(); 1867 base::TimeTicks start_time = animator->last_step_time();
1889 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1868 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1890 } 1869 }
1891 1870
1892 EXPECT_FALSE(observer.animations_completed()); 1871 EXPECT_FALSE(observer.animations_completed());
1893 1872
1894 // Stop observing an in-flight animation. 1873 // Stop observing an in-flight animation.
1895 sequence->RemoveObserver(&observer); 1874 sequence->RemoveObserver(&observer);
1896 1875
1897 EXPECT_TRUE(observer.animations_completed()); 1876 EXPECT_TRUE(observer.animations_completed());
1898 1877
1899 // The animation didn't complete, and neither was it aborted. 1878 // The animation didn't complete, and neither was it aborted.
1900 EXPECT_FALSE(observer.WasAnimationCompletedForProperty( 1879 EXPECT_FALSE(observer.WasAnimationCompletedForProperty(
1901 LayerAnimationElement::BRIGHTNESS)); 1880 LayerAnimationElement::BRIGHTNESS));
1902 EXPECT_FALSE(observer.WasAnimationAbortedForProperty( 1881 EXPECT_FALSE(observer.WasAnimationAbortedForProperty(
1903 LayerAnimationElement::BRIGHTNESS)); 1882 LayerAnimationElement::BRIGHTNESS));
1904 } 1883 }
1905 1884
1906 // This checks that if an animation is deleted due to a callback, that the 1885 // This checks that if an animation is deleted due to a callback, that the
1907 // animator does not try to use the deleted animation. For example, if we have 1886 // animator does not try to use the deleted animation. For example, if we have
1908 // two running animations, and the first finishes and the resulting callback 1887 // two running animations, and the first finishes and the resulting callback
1909 // causes the second to be deleted, we should not attempt to animate the second 1888 // causes the second to be deleted, we should not attempt to animate the second
1910 // animation. 1889 // animation.
1911 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { 1890 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) {
1912 ScopedAnimationDurationScaleMode normal_duration_mode( 1891 ScopedAnimationDurationScaleMode normal_duration_mode(
1913 ScopedAnimationDurationScaleMode::NORMAL_DURATION); 1892 ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1914 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); 1893 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator());
1915 AnimationContainerElement* element = animator.get();
1916 animator->set_disable_timer_for_test(true); 1894 animator->set_disable_timer_for_test(true);
1917 TestLayerAnimationDelegate delegate; 1895 TestLayerAnimationDelegate delegate;
1918 animator->SetDelegate(&delegate); 1896 animator->SetDelegate(&delegate);
1919 1897
1920 double start_brightness(0.0); 1898 double start_brightness(0.0);
1921 double target_brightness(1.0); 1899 double target_brightness(1.0);
1922 1900
1923 gfx::Rect start_bounds(0, 0, 50, 50); 1901 gfx::Rect start_bounds(0, 0, 50, 50);
1924 gfx::Rect target_bounds(5, 5, 5, 5); 1902 gfx::Rect target_bounds(5, 5, 5, 5);
1925 1903
(...skipping 13 matching lines...) Expand all
1939 new LayerAnimationSequence( 1917 new LayerAnimationSequence(
1940 LayerAnimationElement::CreateBrightnessElement( 1918 LayerAnimationElement::CreateBrightnessElement(
1941 target_brightness, brightness_delta))); 1919 target_brightness, brightness_delta)));
1942 1920
1943 animator->StartAnimation(new LayerAnimationSequence( 1921 animator->StartAnimation(new LayerAnimationSequence(
1944 LayerAnimationElement::CreateBoundsElement( 1922 LayerAnimationElement::CreateBoundsElement(
1945 target_bounds, bounds_delta))); 1923 target_bounds, bounds_delta)));
1946 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1924 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
1947 1925
1948 base::TimeTicks start_time = animator->last_step_time(); 1926 base::TimeTicks start_time = animator->last_step_time();
1949 element->Step(start_time + halfway_delta); 1927 animator->Step(start_time + halfway_delta);
1950 1928
1951 // Completing the brightness animation should have stopped the bounds 1929 // Completing the brightness animation should have stopped the bounds
1952 // animation. 1930 // animation.
1953 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1931 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
1954 1932
1955 animator->RemoveObserver(observer.get()); 1933 animator->RemoveObserver(observer.get());
1956 } 1934 }
1957 1935
1958 // Ensure that stopping animation in a bounds change does not crash and that 1936 // Ensure that stopping animation in a bounds change does not crash and that
1959 // animation gets stopped correctly. 1937 // animation gets stopped correctly.
(...skipping 15 matching lines...) Expand all
1975 } 1953 }
1976 private: 1954 private:
1977 LayerAnimator* animator_; 1955 LayerAnimator* animator_;
1978 int max_width_; 1956 int max_width_;
1979 // Allow copy and assign. 1957 // Allow copy and assign.
1980 }; 1958 };
1981 1959
1982 ScopedAnimationDurationScaleMode normal_duration_mode( 1960 ScopedAnimationDurationScaleMode normal_duration_mode(
1983 ScopedAnimationDurationScaleMode::NORMAL_DURATION); 1961 ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1984 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); 1962 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator());
1985 AnimationContainerElement* element = animator.get();
1986 animator->set_disable_timer_for_test(true); 1963 animator->set_disable_timer_for_test(true);
1987 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); 1964 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30);
1988 animator->SetDelegate(&delegate); 1965 animator->SetDelegate(&delegate);
1989 1966
1990 gfx::Rect start_bounds(0, 0, 0, 0); 1967 gfx::Rect start_bounds(0, 0, 0, 0);
1991 gfx::Rect target_bounds(5, 5, 50, 50); 1968 gfx::Rect target_bounds(5, 5, 50, 50);
1992 1969
1993 delegate.SetBoundsFromAnimation(start_bounds); 1970 delegate.SetBoundsFromAnimation(start_bounds);
1994 1971
1995 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333); 1972 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333);
1996 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666); 1973 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666);
1997 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000); 1974 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000);
1998 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500); 1975 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500);
1999 1976
2000 animator->StartAnimation(new LayerAnimationSequence( 1977 animator->StartAnimation(new LayerAnimationSequence(
2001 LayerAnimationElement::CreateBoundsElement( 1978 LayerAnimationElement::CreateBoundsElement(
2002 target_bounds, bounds_delta))); 1979 target_bounds, bounds_delta)));
2003 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1980 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2004 1981
2005 base::TimeTicks start_time = animator->last_step_time(); 1982 base::TimeTicks start_time = animator->last_step_time();
2006 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta1)); 1983 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta1));
2007 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1984 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2008 1985
2009 // The next step should change the animated bounds past the threshold and 1986 // The next step should change the animated bounds past the threshold and
2010 // cause the animaton to stop. 1987 // cause the animaton to stop.
2011 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta2)); 1988 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta2));
2012 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1989 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2013 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + final_delta)); 1990 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + final_delta));
2014 1991
2015 // Completing the animation should have stopped the bounds 1992 // Completing the animation should have stopped the bounds
2016 // animation. 1993 // animation.
2017 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); 1994 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS));
2018 } 1995 }
2019 1996
2020 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it 1997 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it
2021 // tests the behavior when the OnLayerAnimationAborted() callback causes 1998 // tests the behavior when the OnLayerAnimationAborted() callback causes
2022 // all of the animator's other animations to be deleted. 1999 // all of the animator's other animations to be deleted.
2023 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) { 2000 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 2170
2194 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. 2171 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1.
2195 animator->SetGrayscale(1.0); 2172 animator->SetGrayscale(1.0);
2196 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); 2173 EXPECT_EQ(1.0, animator->GetTargetGrayscale());
2197 } 2174 }
2198 } 2175 }
2199 2176
2200 // Verifies color property is modified appropriately. 2177 // Verifies color property is modified appropriately.
2201 TEST(LayerAnimatorTest, Color) { 2178 TEST(LayerAnimatorTest, Color) {
2202 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2179 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
2203 AnimationContainerElement* element = animator.get();
2204 animator->set_disable_timer_for_test(true); 2180 animator->set_disable_timer_for_test(true);
2205 TestLayerAnimationDelegate delegate; 2181 TestLayerAnimationDelegate delegate;
2206 animator->SetDelegate(&delegate); 2182 animator->SetDelegate(&delegate);
2207 2183
2208 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); 2184 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60);
2209 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); 2185 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120);
2210 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); 2186 SkColor target_color = SkColorSetARGB(192, 40, 80, 140);
2211 2187
2212 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2188 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2213 2189
2214 delegate.SetColorFromAnimation(start_color); 2190 delegate.SetColorFromAnimation(start_color);
2215 2191
2216 animator->ScheduleAnimation( 2192 animator->ScheduleAnimation(
2217 new LayerAnimationSequence( 2193 new LayerAnimationSequence(
2218 LayerAnimationElement::CreateColorElement(target_color, delta))); 2194 LayerAnimationElement::CreateColorElement(target_color, delta)));
2219 2195
2220 EXPECT_TRUE(animator->is_animating()); 2196 EXPECT_TRUE(animator->is_animating());
2221 EXPECT_EQ(ColorToString(start_color), 2197 EXPECT_EQ(ColorToString(start_color),
2222 ColorToString(delegate.GetColorForAnimation())); 2198 ColorToString(delegate.GetColorForAnimation()));
2223 2199
2224 base::TimeTicks start_time = animator->last_step_time(); 2200 base::TimeTicks start_time = animator->last_step_time();
2225 2201
2226 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 2202 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500));
2227 2203
2228 EXPECT_TRUE(animator->is_animating()); 2204 EXPECT_TRUE(animator->is_animating());
2229 EXPECT_EQ(ColorToString(middle_color), 2205 EXPECT_EQ(ColorToString(middle_color),
2230 ColorToString(delegate.GetColorForAnimation())); 2206 ColorToString(delegate.GetColorForAnimation()));
2231 2207
2232 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2208 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2233 2209
2234 EXPECT_FALSE(animator->is_animating()); 2210 EXPECT_FALSE(animator->is_animating());
2235 EXPECT_EQ(ColorToString(target_color), 2211 EXPECT_EQ(ColorToString(target_color),
2236 ColorToString(delegate.GetColorForAnimation())); 2212 ColorToString(delegate.GetColorForAnimation()));
2237 } 2213 }
2238 2214
2239 // Verifies SchedulePauseForProperties(). 2215 // Verifies SchedulePauseForProperties().
2240 TEST(LayerAnimatorTest, SchedulePauseForProperties) { 2216 TEST(LayerAnimatorTest, SchedulePauseForProperties) {
2241 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 2217 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
2242 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 2218 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 2306
2331 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); 2307 DISALLOW_COPY_AND_ASSIGN(DeletingObserver);
2332 }; 2308 };
2333 2309
2334 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { 2310 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) {
2335 bool observer_was_deleted = false; 2311 bool observer_was_deleted = false;
2336 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2312 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2337 observer->set_delete_on_animation_ended(true); 2313 observer->set_delete_on_animation_ended(true);
2338 observer->set_delete_on_animation_aborted(true); 2314 observer->set_delete_on_animation_aborted(true);
2339 LayerAnimator* animator = observer->animator(); 2315 LayerAnimator* animator = observer->animator();
2340 AnimationContainerElement* element = observer->animator();
2341 animator->set_disable_timer_for_test(true); 2316 animator->set_disable_timer_for_test(true);
2342 TestLayerAnimationDelegate delegate; 2317 TestLayerAnimationDelegate delegate;
2343 animator->SetDelegate(&delegate); 2318 animator->SetDelegate(&delegate);
2344 2319
2345 delegate.SetBrightnessFromAnimation(0.0f); 2320 delegate.SetBrightnessFromAnimation(0.0f);
2346 2321
2347 gfx::Rect start_bounds(0, 0, 50, 50); 2322 gfx::Rect start_bounds(0, 0, 50, 50);
2348 gfx::Rect target_bounds(10, 10, 100, 100); 2323 gfx::Rect target_bounds(10, 10, 100, 100);
2349 2324
2350 delegate.SetBoundsFromAnimation(start_bounds); 2325 delegate.SetBoundsFromAnimation(start_bounds);
2351 2326
2352 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2327 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
2353 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence( 2328 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence(
2354 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); 2329 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
2355 animator->StartAnimation(brightness_sequence); 2330 animator->StartAnimation(brightness_sequence);
2356 2331
2357 delta = base::TimeDelta::FromSeconds(2); 2332 delta = base::TimeDelta::FromSeconds(2);
2358 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( 2333 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence(
2359 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); 2334 LayerAnimationElement::CreateBoundsElement(target_bounds, delta));
2360 animator->StartAnimation(bounds_sequence); 2335 animator->StartAnimation(bounds_sequence);
2361 2336
2362 base::TimeTicks start_time = animator->last_step_time(); 2337 base::TimeTicks start_time = animator->last_step_time();
2363 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 2338 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
2364 2339
2365 EXPECT_TRUE(observer_was_deleted); 2340 EXPECT_TRUE(observer_was_deleted);
2366 } 2341 }
2367 2342
2368 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { 2343 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) {
2369 bool observer_was_deleted = false; 2344 bool observer_was_deleted = false;
2370 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2345 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
2371 observer->set_delete_on_animation_ended(true); 2346 observer->set_delete_on_animation_ended(true);
2372 observer->set_delete_on_animation_aborted(true); 2347 observer->set_delete_on_animation_aborted(true);
2373 LayerAnimator* animator = observer->animator(); 2348 LayerAnimator* animator = observer->animator();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 settings.AddInverselyAnimatedLayer(&child); 2493 settings.AddInverselyAnimatedLayer(&child);
2519 2494
2520 parent.SetTransform(parent_end); 2495 parent.SetTransform(parent_end);
2521 2496
2522 EXPECT_TRUE(child.GetAnimator()->is_animating()); 2497 EXPECT_TRUE(child.GetAnimator()->is_animating());
2523 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) 2498 EXPECT_TRUE(child.GetTargetTransform().IsIdentity())
2524 << child.GetTargetTransform().ToString(); 2499 << child.GetTargetTransform().ToString();
2525 2500
2526 } 2501 }
2527 2502
2503 TEST(LayerAnimatorTest, LayerAnimatorCollectionTickTime) {
2504 LayerAnimatorCollection* collection = LayerAnimatorCollection::GetInstance();
2505 base::TimeTicks null;
2506 collection->Progress(null);
2507 EXPECT_TRUE(collection->last_tick_time().is_null());
2508
2509 // Adding an animator to the collection should update the last tick time.
2510 Layer layer;
2511 collection->StartAnimator(layer.GetAnimator());
2512 EXPECT_TRUE(collection->HasActiveAnimators());
2513 EXPECT_FALSE(collection->last_tick_time().is_null());
2514
2515 collection->StopAnimator(layer.GetAnimator());
2516 EXPECT_FALSE(collection->HasActiveAnimators());
2517 }
2518
2528 } // namespace ui 2519 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698