OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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); |
(...skipping 21 matching lines...) Expand all Loading... |
722 | 722 |
723 TestLayerAnimationObserver scoped_observer; | 723 TestLayerAnimationObserver scoped_observer; |
724 { | 724 { |
725 ScopedLayerAnimationSettings settings(animator.get()); | 725 ScopedLayerAnimationSettings settings(animator.get()); |
726 settings.AddObserver(&scoped_observer); | 726 settings.AddObserver(&scoped_observer); |
727 for (int i = 0; i < 2; ++i) { | 727 for (int i = 0; i < 2; ++i) { |
728 // reset the observer | 728 // reset the observer |
729 scoped_observer = TestLayerAnimationObserver(); | 729 scoped_observer = TestLayerAnimationObserver(); |
730 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); | 730 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
731 animator->SetOpacity(1.0f); | 731 animator->SetOpacity(1.0f); |
732 start_time = animator->get_last_step_time_for_test(); | 732 start_time = animator->last_step_time(); |
733 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 733 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
734 EXPECT_FALSE(!scoped_observer.last_ended_sequence()); | 734 EXPECT_FALSE(!scoped_observer.last_ended_sequence()); |
735 } | 735 } |
736 } | 736 } |
737 | 737 |
738 scoped_observer = TestLayerAnimationObserver(); | 738 scoped_observer = TestLayerAnimationObserver(); |
739 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); | 739 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
740 animator->SetOpacity(1.0f); | 740 animator->SetOpacity(1.0f); |
741 start_time = base::TimeTicks::Now(); | 741 start_time = base::TimeTicks::Now(); |
742 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 742 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
743 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); | 743 EXPECT_TRUE(!scoped_observer.last_ended_sequence()); |
744 } | 744 } |
745 | 745 |
746 // 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 |
747 // when the object goes out of scope. | 747 // when the object goes out of scope. |
748 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { | 748 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { |
749 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 749 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
750 AnimationContainerElement* element = animator.get(); | 750 AnimationContainerElement* element = animator.get(); |
751 animator->set_disable_timer_for_test(true); | 751 animator->set_disable_timer_for_test(true); |
752 TestImplicitAnimationObserver observer; | 752 TestImplicitAnimationObserver observer; |
753 TestLayerAnimationDelegate delegate; | 753 TestLayerAnimationDelegate delegate; |
754 animator->SetDelegate(&delegate); | 754 animator->SetDelegate(&delegate); |
755 | 755 |
756 EXPECT_FALSE(observer.animations_completed()); | 756 EXPECT_FALSE(observer.animations_completed()); |
757 animator->SetOpacity(1.0f); | 757 animator->SetOpacity(1.0f); |
758 | 758 |
759 { | 759 { |
760 ScopedLayerAnimationSettings settings(animator.get()); | 760 ScopedLayerAnimationSettings settings(animator.get()); |
761 settings.AddImplicitObserver(&observer); | 761 settings.AddObserver(&observer); |
762 animator->SetOpacity(0.0f); | 762 animator->SetOpacity(0.0f); |
763 } | 763 } |
764 | 764 |
765 EXPECT_FALSE(observer.animations_completed()); | 765 EXPECT_FALSE(observer.animations_completed()); |
766 base::TimeTicks start_time = animator->get_last_step_time_for_test(); | 766 base::TimeTicks start_time = animator->last_step_time(); |
767 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 767 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
768 EXPECT_TRUE(observer.animations_completed()); | 768 EXPECT_TRUE(observer.animations_completed()); |
769 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); | 769 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); |
770 } | 770 } |
771 | 771 |
772 // 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 |
773 // 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. |
774 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { | 774 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { |
775 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 775 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
776 animator->set_disable_timer_for_test(true); | 776 animator->set_disable_timer_for_test(true); |
777 TestImplicitAnimationObserver observer; | 777 TestImplicitAnimationObserver observer; |
778 TestLayerAnimationDelegate delegate; | 778 TestLayerAnimationDelegate delegate; |
779 animator->SetDelegate(&delegate); | 779 animator->SetDelegate(&delegate); |
780 | 780 |
781 EXPECT_FALSE(observer.animations_completed()); | 781 EXPECT_FALSE(observer.animations_completed()); |
782 animator->SetOpacity(1.0f); | 782 animator->SetOpacity(1.0f); |
783 | 783 |
784 { | 784 { |
785 ScopedLayerAnimationSettings settings(animator.get()); | 785 ScopedLayerAnimationSettings settings(animator.get()); |
786 settings.AddImplicitObserver(&observer); | 786 settings.AddObserver(&observer); |
787 animator->SetOpacity(0.0f); | 787 animator->SetOpacity(0.0f); |
788 } | 788 } |
789 | 789 |
790 EXPECT_FALSE(observer.animations_completed()); | 790 EXPECT_FALSE(observer.animations_completed()); |
791 // This should interrupt the implicit animation causing the observer to be | 791 // This should interrupt the implicit animation causing the observer to be |
792 // notified immediately. | 792 // notified immediately. |
793 animator->SetOpacity(1.0f); | 793 animator->SetOpacity(1.0f); |
794 EXPECT_TRUE(observer.animations_completed()); | 794 EXPECT_TRUE(observer.animations_completed()); |
795 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); | 795 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); |
796 } | 796 } |
(...skipping 18 matching lines...) Expand all Loading... |
815 animator->StartAnimation(sequence); | 815 animator->StartAnimation(sequence); |
816 | 816 |
817 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); | 817 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
818 EXPECT_TRUE(!observer.last_ended_sequence()); | 818 EXPECT_TRUE(!observer.last_ended_sequence()); |
819 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); | 819 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); |
820 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 820 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
821 | 821 |
822 // This should stop the observer from observing sequence. | 822 // This should stop the observer from observing sequence. |
823 animator->RemoveObserver(&removed_observer); | 823 animator->RemoveObserver(&removed_observer); |
824 | 824 |
825 base::TimeTicks start_time = animator->get_last_step_time_for_test(); | 825 base::TimeTicks start_time = animator->last_step_time(); |
826 | 826 |
827 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 827 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
828 | 828 |
829 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 829 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
830 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 830 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
831 } | 831 } |
832 | 832 |
833 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { | 833 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { |
834 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 834 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
835 animator->set_disable_timer_for_test(true); | 835 animator->set_disable_timer_for_test(true); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 | 879 |
880 animator->StartAnimation(sequence.release()); | 880 animator->StartAnimation(sequence.release()); |
881 | 881 |
882 animator->SetOpacity(0.5); | 882 animator->SetOpacity(0.5); |
883 | 883 |
884 EXPECT_FALSE(animator->is_animating()); | 884 EXPECT_FALSE(animator->is_animating()); |
885 EXPECT_EQ(0.5, animator->GetTargetOpacity()); | 885 EXPECT_EQ(0.5, animator->GetTargetOpacity()); |
886 } | 886 } |
887 | 887 |
888 } // namespace ui | 888 } // namespace ui |
OLD | NEW |