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

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

Issue 9320018: Revert 120092 - Reland 120074 -- 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->last_step_time(); 136 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 184 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 227 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 295 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 367 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 406 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 470 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 521 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 574 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 633 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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->last_step_time(); 690 base::TimeTicks start_time = animator->get_last_step_time_for_test();
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
707 // Tests that an observer added to a scoped settings object is still notified 746 // Tests that an observer added to a scoped settings object is still notified
708 // when the object goes out of scope. 747 // when the object goes out of scope.
709 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { 748 TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
710 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 749 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
711 AnimationContainerElement* element = animator.get(); 750 AnimationContainerElement* element = animator.get();
712 animator->set_disable_timer_for_test(true); 751 animator->set_disable_timer_for_test(true);
713 TestImplicitAnimationObserver observer; 752 TestImplicitAnimationObserver observer;
714 TestLayerAnimationDelegate delegate; 753 TestLayerAnimationDelegate delegate;
715 animator->SetDelegate(&delegate); 754 animator->SetDelegate(&delegate);
716 755
717 EXPECT_FALSE(observer.animations_completed()); 756 EXPECT_FALSE(observer.animations_completed());
718 animator->SetOpacity(1.0f); 757 animator->SetOpacity(1.0f);
719 758
720 { 759 {
721 ScopedLayerAnimationSettings settings(animator.get()); 760 ScopedLayerAnimationSettings settings(animator.get());
722 settings.AddObserver(&observer); 761 settings.AddImplicitObserver(&observer);
723 animator->SetOpacity(0.0f); 762 animator->SetOpacity(0.0f);
724 } 763 }
725 764
726 EXPECT_FALSE(observer.animations_completed()); 765 EXPECT_FALSE(observer.animations_completed());
727 base::TimeTicks start_time = animator->last_step_time(); 766 base::TimeTicks start_time = animator->get_last_step_time_for_test();
728 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 767 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
729 EXPECT_TRUE(observer.animations_completed()); 768 EXPECT_TRUE(observer.animations_completed());
730 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); 769 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation());
731 } 770 }
732 771
733 // Tests that an observer added to a scoped settings object is still notified 772 // Tests that an observer added to a scoped settings object is still notified
734 // when the object goes out of scope due to the animation being interrupted. 773 // when the object goes out of scope due to the animation being interrupted.
735 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { 774 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
736 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 775 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
737 animator->set_disable_timer_for_test(true); 776 animator->set_disable_timer_for_test(true);
738 TestImplicitAnimationObserver observer; 777 TestImplicitAnimationObserver observer;
739 TestLayerAnimationDelegate delegate; 778 TestLayerAnimationDelegate delegate;
740 animator->SetDelegate(&delegate); 779 animator->SetDelegate(&delegate);
741 780
742 EXPECT_FALSE(observer.animations_completed()); 781 EXPECT_FALSE(observer.animations_completed());
743 animator->SetOpacity(1.0f); 782 animator->SetOpacity(1.0f);
744 783
745 { 784 {
746 ScopedLayerAnimationSettings settings(animator.get()); 785 ScopedLayerAnimationSettings settings(animator.get());
747 settings.AddObserver(&observer); 786 settings.AddImplicitObserver(&observer);
748 animator->SetOpacity(0.0f); 787 animator->SetOpacity(0.0f);
749 } 788 }
750 789
751 EXPECT_FALSE(observer.animations_completed()); 790 EXPECT_FALSE(observer.animations_completed());
752 // This should interrupt the implicit animation causing the observer to be 791 // This should interrupt the implicit animation causing the observer to be
753 // notified immediately. 792 // notified immediately.
754 animator->SetOpacity(1.0f); 793 animator->SetOpacity(1.0f);
755 EXPECT_TRUE(observer.animations_completed()); 794 EXPECT_TRUE(observer.animations_completed());
756 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); 795 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation());
757 } 796 }
(...skipping 18 matching lines...) Expand all
776 animator->StartAnimation(sequence); 815 animator->StartAnimation(sequence);
777 816
778 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 817 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
779 EXPECT_TRUE(!observer.last_ended_sequence()); 818 EXPECT_TRUE(!observer.last_ended_sequence());
780 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); 819 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence);
781 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 820 EXPECT_TRUE(!removed_observer.last_ended_sequence());
782 821
783 // This should stop the observer from observing sequence. 822 // This should stop the observer from observing sequence.
784 animator->RemoveObserver(&removed_observer); 823 animator->RemoveObserver(&removed_observer);
785 824
786 base::TimeTicks start_time = animator->last_step_time(); 825 base::TimeTicks start_time = animator->get_last_step_time_for_test();
787 826
788 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 827 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
789 828
790 EXPECT_EQ(observer.last_ended_sequence(), sequence); 829 EXPECT_EQ(observer.last_ended_sequence(), sequence);
791 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 830 EXPECT_TRUE(!removed_observer.last_ended_sequence());
792 } 831 }
793 832
794 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { 833 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
795 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 834 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
796 animator->set_disable_timer_for_test(true); 835 animator->set_disable_timer_for_test(true);
(...skipping 15 matching lines...) Expand all
812 // |observer| should be attached to |sequence|. 851 // |observer| should be attached to |sequence|.
813 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size()); 852 EXPECT_EQ(static_cast<size_t>(1), sequence->observers_.size());
814 853
815 // Now, release |observer| 854 // Now, release |observer|
816 observer.reset(); 855 observer.reset();
817 856
818 // And |sequence| should no longer be attached to |observer|. 857 // And |sequence| should no longer be attached to |observer|.
819 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size()); 858 EXPECT_EQ(static_cast<size_t>(0), sequence->observers_.size());
820 } 859 }
821 860
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
886 // Check that setting a property during an animation with a default animator 861 // Check that setting a property during an animation with a default animator
887 // cancels the original animation. 862 // cancels the original animation.
888 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) { 863 TEST(LayerAnimatorTest, SettingPropertyDuringAnAnimation) {
889 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 864 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
890 animator->set_disable_timer_for_test(true); 865 animator->set_disable_timer_for_test(true);
891 TestLayerAnimationDelegate delegate; 866 TestLayerAnimationDelegate delegate;
892 animator->SetDelegate(&delegate); 867 animator->SetDelegate(&delegate);
893 868
894 double start_opacity(0.0); 869 double start_opacity(0.0);
895 double target_opacity(1.0); 870 double target_opacity(1.0);
896 871
897 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 872 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
898 873
899 delegate.SetOpacityFromAnimation(start_opacity); 874 delegate.SetOpacityFromAnimation(start_opacity);
900 875
901 scoped_ptr<LayerAnimationSequence> sequence( 876 scoped_ptr<LayerAnimationSequence> sequence(
902 new LayerAnimationSequence( 877 new LayerAnimationSequence(
903 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 878 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
904 879
905 animator->StartAnimation(sequence.release()); 880 animator->StartAnimation(sequence.release());
906 881
907 animator->SetOpacity(0.5); 882 animator->SetOpacity(0.5);
908 883
909 EXPECT_FALSE(animator->is_animating()); 884 EXPECT_FALSE(animator->is_animating());
910 EXPECT_EQ(0.5, animator->GetTargetOpacity()); 885 EXPECT_EQ(0.5, animator->GetTargetOpacity());
911 } 886 }
912 887
913 } // namespace ui 888 } // 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