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

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

Issue 9222018: reland -- Disable animations during aura tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 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/gfx/compositor/layer_animator.h" 5 #include "ui/gfx/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/time.h" 10 #include "base/time.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 delegate.SetOpacityFromAnimation(start_opacity); 127 delegate.SetOpacityFromAnimation(start_opacity);
128 128
129 animator->ScheduleAnimation( 129 animator->ScheduleAnimation(
130 new LayerAnimationSequence( 130 new LayerAnimationSequence(
131 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 131 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
132 132
133 EXPECT_TRUE(animator->is_animating()); 133 EXPECT_TRUE(animator->is_animating());
134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
135 135
136 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 136 base::TimeTicks start_time = animator->last_step_time();
137 137
138 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 138 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
139 139
140 EXPECT_TRUE(animator->is_animating()); 140 EXPECT_TRUE(animator->is_animating());
141 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 141 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
142 142
143 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 143 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
144 144
145 EXPECT_FALSE(animator->is_animating()); 145 EXPECT_FALSE(animator->is_animating());
146 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 146 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
(...skipping 27 matching lines...) Expand all
174 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 174 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
175 175
176 animator->ScheduleAnimation( 176 animator->ScheduleAnimation(
177 new LayerAnimationSequence( 177 new LayerAnimationSequence(
178 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 178 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
179 179
180 EXPECT_TRUE(animator->is_animating()); 180 EXPECT_TRUE(animator->is_animating());
181 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 181 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
182 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 182 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
183 183
184 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 184 base::TimeTicks start_time = animator->last_step_time();
185 185
186 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 186 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
187 187
188 EXPECT_TRUE(animator->is_animating()); 188 EXPECT_TRUE(animator->is_animating());
189 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 189 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
190 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); 190 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
191 191
192 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 192 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
193 193
194 EXPECT_FALSE(animator->is_animating()); 194 EXPECT_FALSE(animator->is_animating());
(...skipping 22 matching lines...) Expand all
217 new LayerAnimationSequence( 217 new LayerAnimationSequence(
218 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 218 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
219 219
220 animator->ScheduleAnimation( 220 animator->ScheduleAnimation(
221 new LayerAnimationSequence( 221 new LayerAnimationSequence(
222 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 222 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
223 223
224 EXPECT_TRUE(animator->is_animating()); 224 EXPECT_TRUE(animator->is_animating());
225 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 225 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
226 226
227 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 227 base::TimeTicks start_time = animator->last_step_time();
228 228
229 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 229 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
230 230
231 EXPECT_TRUE(animator->is_animating()); 231 EXPECT_TRUE(animator->is_animating());
232 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 232 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
233 233
234 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 234 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
235 235
236 EXPECT_TRUE(animator->is_animating()); 236 EXPECT_TRUE(animator->is_animating());
237 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 237 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 animator->ScheduleAnimation(bounds_and_opacity.release()); 285 animator->ScheduleAnimation(bounds_and_opacity.release());
286 286
287 animator->ScheduleAnimation( 287 animator->ScheduleAnimation(
288 new LayerAnimationSequence( 288 new LayerAnimationSequence(
289 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); 289 LayerAnimationElement::CreateBoundsElement(start_bounds, delta)));
290 290
291 EXPECT_TRUE(animator->is_animating()); 291 EXPECT_TRUE(animator->is_animating());
292 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 292 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
293 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 293 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
294 294
295 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 295 base::TimeTicks start_time = animator->last_step_time();
296 296
297 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 297 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
298 298
299 EXPECT_TRUE(animator->is_animating()); 299 EXPECT_TRUE(animator->is_animating());
300 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 300 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
301 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 301 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
302 302
303 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 303 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
304 304
305 EXPECT_TRUE(animator->is_animating()); 305 EXPECT_TRUE(animator->is_animating());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 357 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
358 sequences.push_back(new LayerAnimationSequence( 358 sequences.push_back(new LayerAnimationSequence(
359 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 359 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
360 360
361 animator->ScheduleTogether(sequences); 361 animator->ScheduleTogether(sequences);
362 362
363 EXPECT_TRUE(animator->is_animating()); 363 EXPECT_TRUE(animator->is_animating());
364 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 364 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
365 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 365 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
366 366
367 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 367 base::TimeTicks start_time = animator->last_step_time();
368 368
369 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 369 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
370 370
371 EXPECT_TRUE(animator->is_animating()); 371 EXPECT_TRUE(animator->is_animating());
372 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 372 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
373 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 373 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
374 374
375 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 375 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
376 376
377 EXPECT_FALSE(animator->is_animating()); 377 EXPECT_FALSE(animator->is_animating());
(...skipping 18 matching lines...) Expand all
396 396
397 delegate.SetOpacityFromAnimation(start_opacity); 397 delegate.SetOpacityFromAnimation(start_opacity);
398 398
399 animator->StartAnimation( 399 animator->StartAnimation(
400 new LayerAnimationSequence( 400 new LayerAnimationSequence(
401 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 401 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
402 402
403 EXPECT_TRUE(animator->is_animating()); 403 EXPECT_TRUE(animator->is_animating());
404 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 404 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
405 405
406 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 406 base::TimeTicks start_time = animator->last_step_time();
407 407
408 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 408 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
409 409
410 EXPECT_TRUE(animator->is_animating()); 410 EXPECT_TRUE(animator->is_animating());
411 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 411 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
412 412
413 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 413 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
414 414
415 EXPECT_FALSE(animator->is_animating()); 415 EXPECT_FALSE(animator->is_animating());
416 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 416 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 460
461 delegate.SetOpacityFromAnimation(start_opacity); 461 delegate.SetOpacityFromAnimation(start_opacity);
462 462
463 animator->set_preemption_strategy( 463 animator->set_preemption_strategy(
464 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 464 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
465 465
466 animator->StartAnimation( 466 animator->StartAnimation(
467 new LayerAnimationSequence( 467 new LayerAnimationSequence(
468 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 468 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
469 469
470 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 470 base::TimeTicks start_time = animator->last_step_time();
471 471
472 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 472 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
473 473
474 animator->StartAnimation( 474 animator->StartAnimation(
475 new LayerAnimationSequence( 475 new LayerAnimationSequence(
476 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 476 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
477 477
478 EXPECT_TRUE(animator->is_animating()); 478 EXPECT_TRUE(animator->is_animating());
479 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 479 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
480 480
(...skipping 30 matching lines...) Expand all
511 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 511 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
512 512
513 delegate.SetOpacityFromAnimation(start_opacity); 513 delegate.SetOpacityFromAnimation(start_opacity);
514 514
515 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 515 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
516 516
517 animator->StartAnimation( 517 animator->StartAnimation(
518 new LayerAnimationSequence( 518 new LayerAnimationSequence(
519 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 519 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
520 520
521 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 521 base::TimeTicks start_time = animator->last_step_time();
522 522
523 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 523 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
524 524
525 animator->StartAnimation( 525 animator->StartAnimation(
526 new LayerAnimationSequence( 526 new LayerAnimationSequence(
527 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 527 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
528 528
529 EXPECT_TRUE(animator->is_animating()); 529 EXPECT_TRUE(animator->is_animating());
530 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 530 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
531 531
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 564 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
565 565
566 delegate.SetOpacityFromAnimation(start_opacity); 566 delegate.SetOpacityFromAnimation(start_opacity);
567 567
568 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 568 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
569 569
570 animator->StartAnimation( 570 animator->StartAnimation(
571 new LayerAnimationSequence( 571 new LayerAnimationSequence(
572 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 572 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
573 573
574 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 574 base::TimeTicks start_time = animator->last_step_time();
575 575
576 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 576 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
577 577
578 animator->StartAnimation( 578 animator->StartAnimation(
579 new LayerAnimationSequence( 579 new LayerAnimationSequence(
580 LayerAnimationElement::CreateOpacityElement(middle_opacity, delta))); 580 LayerAnimationElement::CreateOpacityElement(middle_opacity, delta)));
581 581
582 // Queue should now have two animations. Starting a third should replace the 582 // Queue should now have two animations. Starting a third should replace the
583 // second. 583 // second.
584 animator->StartAnimation( 584 animator->StartAnimation(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 new LayerAnimationSequence( 623 new LayerAnimationSequence(
624 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 624 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
625 625
626 sequence->AddElement( 626 sequence->AddElement(
627 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)); 627 LayerAnimationElement::CreateOpacityElement(start_opacity, delta));
628 628
629 sequence->set_is_cyclic(true); 629 sequence->set_is_cyclic(true);
630 630
631 animator->StartAnimation(sequence.release()); 631 animator->StartAnimation(sequence.release());
632 632
633 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 633 base::TimeTicks start_time = animator->last_step_time();
634 634
635 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 635 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
636 636
637 EXPECT_TRUE(animator->is_animating()); 637 EXPECT_TRUE(animator->is_animating());
638 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 638 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
639 639
640 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 640 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
641 641
642 EXPECT_TRUE(animator->is_animating()); 642 EXPECT_TRUE(animator->is_animating());
643 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 643 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 680
681 delegate.SetOpacityFromAnimation(0.0f); 681 delegate.SetOpacityFromAnimation(0.0f);
682 682
683 LayerAnimationSequence* sequence = new LayerAnimationSequence( 683 LayerAnimationSequence* sequence = new LayerAnimationSequence(
684 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 684 LayerAnimationElement::CreateOpacityElement(1.0f, delta));
685 685
686 animator->StartAnimation(sequence); 686 animator->StartAnimation(sequence);
687 687
688 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 688 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
689 689
690 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 690 base::TimeTicks start_time = animator->last_step_time();
691 691
692 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 692 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
693 693
694 EXPECT_EQ(observer.last_ended_sequence(), sequence); 694 EXPECT_EQ(observer.last_ended_sequence(), sequence);
695 695
696 // |sequence| has been destroyed. Recreate it to test abort. 696 // |sequence| has been destroyed. Recreate it to test abort.
697 sequence = new LayerAnimationSequence( 697 sequence = new LayerAnimationSequence(
698 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 698 LayerAnimationElement::CreateOpacityElement(1.0f, delta));
699 699
700 animator->StartAnimation(sequence); 700 animator->StartAnimation(sequence);
701 701
702 animator.reset(); 702 animator.reset();
703 703
704 EXPECT_EQ(observer.last_aborted_sequence(), sequence); 704 EXPECT_EQ(observer.last_aborted_sequence(), sequence);
705 } 705 }
706 706
707 TEST(LayerAnimatorTest, AddObserverImplicit) {
708 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
709 AnimationContainerElement* element = animator.get();
710 animator->set_disable_timer_for_test(true);
711 TestLayerAnimationObserver observer;
712 TestLayerAnimationDelegate delegate;
713 animator->SetDelegate(&delegate);
714 animator->AddObserver(&observer);
715
716 // Should end a sequence with the default animator.
717 EXPECT_TRUE(!observer.last_ended_sequence());
718 animator->SetOpacity(1.0f);
719 base::TimeTicks start_time = base::TimeTicks::Now();
720 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
721 EXPECT_TRUE(observer.last_ended_sequence());
722
723 TestLayerAnimationObserver scoped_observer;
724 {
725 ScopedLayerAnimationSettings settings(animator.get());
726 settings.AddObserver(&scoped_observer);
727 for (int i = 0; i < 2; ++i) {
728 // reset the observer
729 scoped_observer = TestLayerAnimationObserver();
730 EXPECT_TRUE(!scoped_observer.last_ended_sequence());
731 animator->SetOpacity(1.0f);
732 start_time = animator->get_last_step_time_for_test();
733 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
734 EXPECT_FALSE(!scoped_observer.last_ended_sequence());
735 }
736 }
737
738 scoped_observer = TestLayerAnimationObserver();
739 EXPECT_TRUE(!scoped_observer.last_ended_sequence());
740 animator->SetOpacity(1.0f);
741 start_time = base::TimeTicks::Now();
742 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
743 EXPECT_TRUE(!scoped_observer.last_ended_sequence());
744 }
745
746 // Tests that an observer added to a scoped settings object is still notified 707 // Tests that an observer added to a scoped settings object is still notified
747 // when the object goes out of scope. 708 // when the object goes out of scope.
748 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { 709 TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
749 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 710 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
750 AnimationContainerElement* element = animator.get(); 711 AnimationContainerElement* element = animator.get();
751 animator->set_disable_timer_for_test(true); 712 animator->set_disable_timer_for_test(true);
752 TestImplicitAnimationObserver observer; 713 TestImplicitAnimationObserver observer;
753 TestLayerAnimationDelegate delegate; 714 TestLayerAnimationDelegate delegate;
754 animator->SetDelegate(&delegate); 715 animator->SetDelegate(&delegate);
755 716
756 EXPECT_FALSE(observer.animations_completed()); 717 EXPECT_FALSE(observer.animations_completed());
757 animator->SetOpacity(1.0f); 718 animator->SetOpacity(1.0f);
758 719
759 { 720 {
760 ScopedLayerAnimationSettings settings(animator.get()); 721 ScopedLayerAnimationSettings settings(animator.get());
761 settings.AddImplicitObserver(&observer); 722 settings.AddObserver(&observer);
762 animator->SetOpacity(0.0f); 723 animator->SetOpacity(0.0f);
763 } 724 }
764 725
765 EXPECT_FALSE(observer.animations_completed()); 726 EXPECT_FALSE(observer.animations_completed());
766 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 727 base::TimeTicks start_time = animator->last_step_time();
767 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 728 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
768 EXPECT_TRUE(observer.animations_completed()); 729 EXPECT_TRUE(observer.animations_completed());
769 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); 730 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation());
770 } 731 }
771 732
772 // Tests that an observer added to a scoped settings object is still notified 733 // Tests that an observer added to a scoped settings object is still notified
773 // when the object goes out of scope due to the animation being interrupted. 734 // when the object goes out of scope due to the animation being interrupted.
774 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { 735 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
775 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 736 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
776 animator->set_disable_timer_for_test(true); 737 animator->set_disable_timer_for_test(true);
777 TestImplicitAnimationObserver observer; 738 TestImplicitAnimationObserver observer;
778 TestLayerAnimationDelegate delegate; 739 TestLayerAnimationDelegate delegate;
779 animator->SetDelegate(&delegate); 740 animator->SetDelegate(&delegate);
780 741
781 EXPECT_FALSE(observer.animations_completed()); 742 EXPECT_FALSE(observer.animations_completed());
782 animator->SetOpacity(1.0f); 743 animator->SetOpacity(1.0f);
783 744
784 { 745 {
785 ScopedLayerAnimationSettings settings(animator.get()); 746 ScopedLayerAnimationSettings settings(animator.get());
786 settings.AddImplicitObserver(&observer); 747 settings.AddObserver(&observer);
787 animator->SetOpacity(0.0f); 748 animator->SetOpacity(0.0f);
788 } 749 }
789 750
790 EXPECT_FALSE(observer.animations_completed()); 751 EXPECT_FALSE(observer.animations_completed());
791 // This should interrupt the implicit animation causing the observer to be 752 // This should interrupt the implicit animation causing the observer to be
792 // notified immediately. 753 // notified immediately.
793 animator->SetOpacity(1.0f); 754 animator->SetOpacity(1.0f);
794 EXPECT_TRUE(observer.animations_completed()); 755 EXPECT_TRUE(observer.animations_completed());
795 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); 756 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation());
796 } 757 }
(...skipping 18 matching lines...) Expand all
815 animator->StartAnimation(sequence); 776 animator->StartAnimation(sequence);
816 777
817 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 778 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
818 EXPECT_TRUE(!observer.last_ended_sequence()); 779 EXPECT_TRUE(!observer.last_ended_sequence());
819 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); 780 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence);
820 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 781 EXPECT_TRUE(!removed_observer.last_ended_sequence());
821 782
822 // This should stop the observer from observing sequence. 783 // This should stop the observer from observing sequence.
823 animator->RemoveObserver(&removed_observer); 784 animator->RemoveObserver(&removed_observer);
824 785
825 base::TimeTicks start_time = animator->get_last_step_time_for_test(); 786 base::TimeTicks start_time = animator->last_step_time();
826 787
827 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 788 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
828 789
829 EXPECT_EQ(observer.last_ended_sequence(), sequence); 790 EXPECT_EQ(observer.last_ended_sequence(), sequence);
830 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 791 EXPECT_TRUE(!removed_observer.last_ended_sequence());
831 } 792 }
832 793
833 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { 794 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
834 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 795 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
835 animator->set_disable_timer_for_test(true); 796 animator->set_disable_timer_for_test(true);
(...skipping 15 matching lines...) Expand all
851 // |observer| should be attached to |sequence|. 812 // |observer| should be attached to |sequence|.
852 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size()); 813 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size());
853 814
854 // Now, release |observer| 815 // Now, release |observer|
855 observer.reset(); 816 observer.reset();
856 817
857 // And |sequence| should no longer be attached to |observer|. 818 // And |sequence| should no longer be attached to |observer|.
858 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size()); 819 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size());
859 } 820 }
860 821
822 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
823 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
824 AnimationContainerElement* element = animator.get();
825 animator->set_disable_timer_for_test(true);
826
827 TestImplicitAnimationObserver observer;
828 TestLayerAnimationDelegate delegate;
829 animator->SetDelegate(&delegate);
830
831 delegate.SetOpacityFromAnimation(0.0f);
832
833 {
834 ScopedLayerAnimationSettings setter(animator.get());
835
836 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
837 LayerAnimationSequence* sequence = new LayerAnimationSequence(
838 LayerAnimationElement::CreateOpacityElement(1.0f, delta));
839
840 animator->StartAnimation(sequence);
841 base::TimeTicks start_time = animator->last_step_time();
842 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
843
844 setter.AddObserver(&observer);
845
846 // Start observing an in-flight animation.
847 sequence->AddObserver(&observer);
848
849 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
850 }
851
852 EXPECT_TRUE(observer.animations_completed());
853 }
854
855 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
856 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
857 AnimationContainerElement* element = animator.get();
858 animator->set_disable_timer_for_test(true);
859
860 TestImplicitAnimationObserver observer;
861 TestLayerAnimationDelegate delegate;
862 animator->SetDelegate(&delegate);
863
864 delegate.SetOpacityFromAnimation(0.0f);
865 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
866 LayerAnimationSequence* sequence = new LayerAnimationSequence(
867 LayerAnimationElement::CreateOpacityElement(1.0f, delta));
868
869 {
870 ScopedLayerAnimationSettings setter(animator.get());
871 setter.AddObserver(&observer);
872
873 animator->StartAnimation(sequence);
874 base::TimeTicks start_time = animator->last_step_time();
875 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
876 }
877
878 EXPECT_FALSE(observer.animations_completed());
879
880 // Stop observing an in-flight animation.
881 sequence->RemoveObserver(&observer);
882
883 EXPECT_TRUE(observer.animations_completed());
884 }
885
861 // Check that setting a property during an animation with a default animator 886 // Check that setting a property during an animation with a default animator
862 // cancels the original animation. 887 // cancels the original animation.
863 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { 888 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
864 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 889 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
865 animator->set_disable_timer_for_test(true); 890 animator->set_disable_timer_for_test(true);
866 TestLayerAnimationDelegate delegate; 891 TestLayerAnimationDelegate delegate;
867 animator->SetDelegate(&delegate); 892 animator->SetDelegate(&delegate);
868 893
869 double start_opacity(0.0); 894 double start_opacity(0.0);
870 double target_opacity(1.0); 895 double target_opacity(1.0);
871 896
872 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 897 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
873 898
874 delegate.SetOpacityFromAnimation(start_opacity); 899 delegate.SetOpacityFromAnimation(start_opacity);
875 900
876 scoped_ptr<LayerAnimationSequence> sequence( 901 scoped_ptr<LayerAnimationSequence> sequence(
877 new LayerAnimationSequence( 902 new LayerAnimationSequence(
878 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 903 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
879 904
880 animator->StartAnimation(sequence.release()); 905 animator->StartAnimation(sequence.release());
881 906
882 animator->SetOpacity(0.5); 907 animator->SetOpacity(0.5);
883 908
884 EXPECT_FALSE(animator->is_animating()); 909 EXPECT_FALSE(animator->is_animating());
885 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 910 EXPECT_EQ(0.5, animator->GetTargetOpacity());
886 } 911 }
887 912
888 } // namespace ui 913 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animator.cc ('k') | ui/gfx/compositor/scoped_layer_animation_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698