| Index: ui/compositor/layer_animator_unittest.cc
|
| diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc
|
| index c93d11735dcaa03f0390b72958b534d22d81afcc..5ecb031f72f085e72fa407a8610d9f079bd09675 100644
|
| --- a/ui/compositor/layer_animator_unittest.cc
|
| +++ b/ui/compositor/layer_animator_unittest.cc
|
| @@ -14,6 +14,7 @@
|
| #include "ui/compositor/layer_animation_element.h"
|
| #include "ui/compositor/layer_animation_sequence.h"
|
| #include "ui/compositor/scoped_layer_animation_settings.h"
|
| +#include "ui/compositor/test/layer_animator_test_controller.h"
|
| #include "ui/compositor/test/test_layer_animation_delegate.h"
|
| #include "ui/compositor/test/test_layer_animation_observer.h"
|
| #include "ui/compositor/test/test_utils.h"
|
| @@ -155,10 +156,10 @@ TEST(LayerAnimatorTest, ImplicitAnimation) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
| base::TimeTicks now = base::TimeTicks::Now();
|
| - animator->SetOpacity(0.5);
|
| + animator->SetBrightness(0.5);
|
| EXPECT_TRUE(animator->is_animating());
|
| element->Step(now + base::TimeDelta::FromSeconds(1));
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
|
| }
|
|
|
| // Checks that if the animator is a default animator, that implicit animations
|
| @@ -168,9 +169,9 @@ TEST(LayerAnimatorTest, NoImplicitAnimation) {
|
| animator->set_disable_timer_for_test(true);
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
| - animator->SetOpacity(0.5);
|
| + animator->SetBrightness(0.5);
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
|
| }
|
|
|
| // Checks that StopAnimatingProperty stops animation for that property, and also
|
| @@ -235,8 +236,8 @@ TEST(LayerAnimatorTest, AbortAllAnimations) {
|
| CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation());
|
| }
|
|
|
| -// Schedule an animation that can run immediately. This is the trivial case and
|
| -// should result in the animation being started immediately.
|
| +// Schedule a non-threaded animation that can run immediately. This is the
|
| +// trivial case and should result in the animation being started immediately.
|
| TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -244,36 +245,85 @@ TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
| +}
|
| +
|
| +// Schedule a threaded animation that can run immediately.
|
| +TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double target_opacity(1.0);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| +
|
| + test_controller.animator()->ScheduleAnimation(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta/2);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(
|
| + 0.5,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + last_progressed_fraction());
|
| +
|
| + element->Step(effective_start + delta);
|
| +
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| }
|
|
|
| -// Schedule two animations on separate properties. Both animations should
|
| -// start immediately and should progress in lock step.
|
| +// Schedule two non-threaded animations on separate properties. Both animations
|
| +// should start immediately and should progress in lock step.
|
| TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -281,9 +331,9 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| gfx::Rect start_bounds, target_bounds, middle_bounds;
|
| start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
|
| @@ -292,19 +342,20 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
| delegate.SetBoundsFromAnimation(start_bounds);
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
| @@ -312,12 +363,77 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
| + CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
|
| +}
|
| +
|
| +// Schedule a threaded and a non-threaded animation on separate properties. Both
|
| +// animations should progress in lock step.
|
| +TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double target_opacity(1.0);
|
| +
|
| + gfx::Rect start_bounds, target_bounds, middle_bounds;
|
| + start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
|
| + start_bounds.set_x(-90);
|
| + target_bounds.set_x(90);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBoundsFromAnimation(start_bounds);
|
| +
|
| + std::vector<LayerAnimationSequence*> animations;
|
| + animations.push_back(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| +
|
| + animations.push_back(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
|
| +
|
| + test_controller.animator()->ScheduleTogether(animations);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta/2);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(
|
| + 0.5,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + last_progressed_fraction());
|
| + CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
|
| +
|
| + element->Step(effective_start + delta);
|
| +
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
|
| }
|
| @@ -331,49 +447,51 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
|
|
| -// Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That
|
| +// Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That
|
| // is, ensure that all animations targetting a particular property are run in
|
| // order.
|
| TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
|
| @@ -383,9 +501,9 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double middle_grayscale(0.5);
|
| + double target_grayscale(1.0);
|
|
|
| gfx::Rect start_bounds, target_bounds, middle_bounds;
|
| start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
|
| @@ -394,28 +512,30 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBoundsFromAnimation(start_bounds);
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta)));
|
|
|
| - scoped_ptr<LayerAnimationSequence> bounds_and_opacity(
|
| + scoped_ptr<LayerAnimationSequence> bounds_and_grayscale(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale,
|
| + delta)));
|
|
|
| - bounds_and_opacity->AddElement(
|
| + bounds_and_grayscale->AddElement(
|
| LayerAnimationElement::CreateBoundsElement(target_bounds, delta));
|
|
|
| - animator->ScheduleAnimation(bounds_and_opacity.release());
|
| + animator->ScheduleAnimation(bounds_and_grayscale.release());
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| LayerAnimationElement::CreateBoundsElement(start_bounds, delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
| @@ -423,37 +543,37 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(4000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
| }
|
|
|
| -// Schedule {o} and then schedule {o} and {b} together. In this case, since
|
| +// Schedule {g} and then schedule {g} and {b} together. In this case, since
|
| // ScheduleTogether is being used, the bounds animation should not start until
|
| -// the second opacity animation starts.
|
| +// the second grayscale animation starts.
|
| TEST(LayerAnimatorTest, ScheduleTogether) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -461,8 +581,8 @@ TEST(LayerAnimatorTest, ScheduleTogether) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double target_grayscale(1.0);
|
|
|
| gfx::Rect start_bounds, target_bounds, middle_bounds;
|
| start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50);
|
| @@ -471,23 +591,24 @@ TEST(LayerAnimatorTest, ScheduleTogether) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBoundsFromAnimation(start_bounds);
|
|
|
| animator->ScheduleAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta)));
|
|
|
| std::vector<LayerAnimationSequence*> sequences;
|
| sequences.push_back(new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta)));
|
| sequences.push_back(new LayerAnimationSequence(
|
| LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
|
|
|
| animator->ScheduleTogether(sequences);
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
| @@ -495,18 +616,18 @@ TEST(LayerAnimatorTest, ScheduleTogether) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
|
| }
|
|
|
| -// Start animation (that can run immediately). This is the trivial case (see
|
| -// the trival case for ScheduleAnimation).
|
| +// Start non-threaded animation (that can run immediately). This is the trivial
|
| +// case (see the trival case for ScheduleAnimation).
|
| TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -514,31 +635,79 @@ TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
| +}
|
| +
|
| +// Start threaded animation (that can run immediately).
|
| +TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double target_opacity(1.0);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| +
|
| + test_controller.animator()->StartAnimation(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta/2);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(
|
| + 0.5,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + last_progressed_fraction());
|
| +
|
| + element->Step(effective_start + delta);
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| }
|
|
|
| @@ -570,7 +739,7 @@ TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| }
|
|
|
| -// Preempt by animating to new target.
|
| +// Preempt by animating to new target, with a non-threaded animation.
|
| TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -578,20 +747,21 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(
|
| LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| @@ -599,26 +769,102 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
|
| - 0.5 * (start_opacity + middle_opacity));
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
|
| + 0.5 * (start_brightness + middle_brightness));
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| +}
|
| +
|
| +// Preempt by animating to new target, with a threaded animation.
|
| +TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double middle_opacity(0.5);
|
| + double target_opacity(1.0);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| +
|
| + test_controller.animator()->set_preemption_strategy(
|
| + LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
| +
|
| + test_controller.animator()->StartAnimation(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta/2);
|
| +
|
| + test_controller.animator()->StartAnimation(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| +
|
| + test_controller.animator()->StartAnimation(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| +
|
| + base::TimeTicks second_effective_start = effective_start + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (second_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(second_effective_start + delta/2);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(
|
| + 0.5,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + last_progressed_fraction());
|
| +
|
| + element->Step(second_effective_start + delta);
|
| +
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| }
|
|
|
| @@ -630,19 +876,20 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| @@ -650,27 +897,28 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
|
|
| // Start an animation when there are sequences waiting in the queue. In this
|
| @@ -683,19 +931,20 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double middle_brightness(0.5);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| base::TimeTicks start_time = animator->last_step_time();
|
|
|
| @@ -703,31 +952,33 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(middle_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(middle_brightness,
|
| + delta)));
|
|
|
| // Queue should now have two animations. Starting a third should replace the
|
| // second.
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
|
|
| TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
|
| @@ -736,14 +987,14 @@ TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double target_grayscale(1.0);
|
| double start_brightness(0.1);
|
| double target_brightness(0.9);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(
|
| @@ -753,7 +1004,8 @@ TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta),
|
| LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| delta)
|
| ));
|
| @@ -813,9 +1065,9 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double middle_grayscale(0.5);
|
| + double target_grayscale(1.0);
|
|
|
| double start_brightness(0.1);
|
| double middle_brightness(0.2);
|
| @@ -823,7 +1075,7 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(
|
| @@ -831,7 +1083,8 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta),
|
| LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| delta)
|
| ));
|
| @@ -842,17 +1095,17 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
|
| LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
|
| LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| delta)));
|
|
|
| @@ -861,14 +1114,104 @@ TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
|
| - 0.5 * (start_opacity + middle_opacity));
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(),
|
| + 0.5 * (start_grayscale + middle_grayscale));
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
|
| 0.5 * (start_brightness + middle_brightness));
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| +}
|
| +
|
| +// Preempt a threaded animation by animating to new target.
|
| +TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double middle_opacity(0.5);
|
| + double target_opacity(1.0);
|
| +
|
| + double start_brightness(0.1);
|
| + double middle_brightness(0.2);
|
| + double target_brightness(0.3);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
| +
|
| + test_controller.animator()->set_preemption_strategy(
|
| + LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
| +
|
| + test_controller.animator()->StartTogether(
|
| + CreateMultiSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)
|
| + ));
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta/2);
|
| +
|
| + test_controller.animator()->StartTogether(
|
| + CreateMultiSequence(
|
| + LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
| +
|
| + test_controller.animator()->StartTogether(
|
| + CreateMultiSequence(
|
| + LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| + delta)));
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| +
|
| + base::TimeTicks second_effective_start = effective_start + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (second_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(second_effective_start + delta/2);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(
|
| + 0.5,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + last_progressed_fraction());
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
|
| + 0.5 * (start_brightness + middle_brightness));
|
| +
|
| + element->Step(second_effective_start + delta);
|
| +
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
| @@ -881,9 +1224,9 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double middle_grayscale(0.5);
|
| + double target_grayscale(1.0);
|
|
|
| double start_brightness(0.1);
|
| double middle_brightness(0.2);
|
| @@ -891,14 +1234,15 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta),
|
| LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| delta)));
|
|
|
| @@ -908,12 +1252,12 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
|
| LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| @@ -921,19 +1265,19 @@ TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
|
|
| @@ -947,9 +1291,9 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double middle_opacity(0.5);
|
| - double target_opacity(1.0);
|
| + double start_grayscale(0.0);
|
| + double middle_grayscale(0.5);
|
| + double target_grayscale(1.0);
|
|
|
| double start_brightness(0.1);
|
| double middle_brightness(0.2);
|
| @@ -957,14 +1301,15 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetGrayscaleFromAnimation(start_grayscale);
|
| delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
|
| + delta),
|
| LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| delta)));
|
|
|
| @@ -974,7 +1319,8 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
|
|
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(middle_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(middle_grayscale,
|
| + delta),
|
| LayerAnimationElement::CreateBrightnessElement(middle_brightness,
|
| delta)));
|
|
|
| @@ -982,34 +1328,34 @@ TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
|
| // second.
|
| animator->StartTogether(
|
| CreateMultiSequence(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
|
| + LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
|
| LayerAnimationElement::CreateBrightnessElement(start_brightness,
|
| delta)));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
|
| EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
| }
|
| //-------------------------------------------------------
|
| -// Test that cyclic sequences continue to animate.
|
| +// Test that non-threaded cyclic sequences continue to animate.
|
| TEST(LayerAnimatorTest, CyclicSequences) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -1017,19 +1363,20 @@ TEST(LayerAnimatorTest, CyclicSequences) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double target_brightness(1.0);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
|
|
| scoped_ptr<LayerAnimationSequence> sequence(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(target_brightness,
|
| + delta)));
|
|
|
| sequence->AddElement(
|
| - LayerAnimationElement::CreateOpacityElement(start_opacity, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(start_brightness, delta));
|
|
|
| sequence->set_is_cyclic(true);
|
|
|
| @@ -1040,35 +1387,140 @@ TEST(LayerAnimatorTest, CyclicSequences) {
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
|
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| // Skip ahead by a lot.
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
|
|
|
| // Skip ahead by a lot.
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000));
|
|
|
| EXPECT_TRUE(animator->is_animating());
|
| - EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| + EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
|
|
|
| - animator->StopAnimatingProperty(LayerAnimationElement::OPACITY);
|
| + animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS);
|
|
|
| EXPECT_FALSE(animator->is_animating());
|
| }
|
|
|
| +// Test that threaded cyclic sequences continue to animate.
|
| +TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
|
| + LayerAnimatorTestController test_controller(
|
| + LayerAnimator::CreateDefaultAnimator());
|
| + AnimationContainerElement* element = test_controller.animator();
|
| + test_controller.animator()->set_disable_timer_for_test(true);
|
| + TestLayerAnimationDelegate delegate;
|
| + test_controller.animator()->SetDelegate(&delegate);
|
| +
|
| + double start_opacity(0.0);
|
| + double target_opacity(1.0);
|
| +
|
| + base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| +
|
| + delegate.SetOpacityFromAnimation(start_opacity);
|
| +
|
| + scoped_ptr<LayerAnimationSequence> sequence(
|
| + new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
|
| +
|
| + sequence->AddElement(
|
| + LayerAnimationElement::CreateOpacityElement(start_opacity, delta));
|
| +
|
| + sequence->set_is_cyclic(true);
|
| +
|
| + test_controller.animator()->StartAnimation(sequence.release());
|
| +
|
| + base::TimeTicks start_time = test_controller.animator()->last_step_time();
|
| + base::TimeTicks effective_start = start_time + delta;
|
| +
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(effective_start + delta);
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| +
|
| + base::TimeTicks second_effective_start = effective_start + 2 * delta;
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (second_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(second_effective_start + delta);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| +
|
| + base::TimeTicks third_effective_start = second_effective_start + 2 * delta;
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (third_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + element->Step(third_effective_start + delta);
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| +
|
| + base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta;
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (fourth_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + // Skip ahead by a lot.
|
| + element->Step(fourth_effective_start + 1000 * delta);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
|
| +
|
| + base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta;
|
| + test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
|
| + cc::AnimationEvent::Started,
|
| + 0,
|
| + test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
|
| + animation_group_id(),
|
| + cc::Animation::Opacity,
|
| + (fifth_effective_start - base::TimeTicks()).InSecondsF()));
|
| +
|
| + // Skip ahead by a lot.
|
| + element->Step(fifth_effective_start + 999 * delta);
|
| +
|
| + EXPECT_TRUE(test_controller.animator()->is_animating());
|
| + EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
|
| +
|
| + test_controller.animator()->StopAnimatingProperty(
|
| + LayerAnimationElement::OPACITY);
|
| +
|
| + EXPECT_FALSE(test_controller.animator()->is_animating());
|
| +}
|
| +
|
| TEST(LayerAnimatorTest, AddObserverExplicit) {
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| AnimationContainerElement* element = animator.get();
|
| @@ -1083,10 +1535,10 @@ TEST(LayerAnimatorTest, AddObserverExplicit) {
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| - delegate.SetOpacityFromAnimation(0.0f);
|
| + delegate.SetBrightnessFromAnimation(0.0f);
|
|
|
| LayerAnimationSequence* sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
|
|
| animator->StartAnimation(sequence);
|
|
|
| @@ -1100,7 +1552,7 @@ TEST(LayerAnimatorTest, AddObserverExplicit) {
|
|
|
| // |sequence| has been destroyed. Recreate it to test abort.
|
| sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
|
|
| animator->StartAnimation(sequence);
|
|
|
| @@ -1120,19 +1572,19 @@ TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
|
| animator->SetDelegate(&delegate);
|
|
|
| EXPECT_FALSE(observer.animations_completed());
|
| - animator->SetOpacity(1.0f);
|
| + animator->SetBrightness(1.0f);
|
|
|
| {
|
| ScopedLayerAnimationSettings settings(animator.get());
|
| settings.AddObserver(&observer);
|
| - animator->SetOpacity(0.0f);
|
| + animator->SetBrightness(0.0f);
|
| }
|
|
|
| EXPECT_FALSE(observer.animations_completed());
|
| base::TimeTicks start_time = animator->last_step_time();
|
| element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
|
| EXPECT_TRUE(observer.animations_completed());
|
| - EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation());
|
| + EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation());
|
| }
|
|
|
| // Tests that an observer added to a scoped settings object is still notified
|
| @@ -1145,20 +1597,20 @@ TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
|
| animator->SetDelegate(&delegate);
|
|
|
| EXPECT_FALSE(observer.animations_completed());
|
| - animator->SetOpacity(1.0f);
|
| + animator->SetBrightness(1.0f);
|
|
|
| {
|
| ScopedLayerAnimationSettings settings(animator.get());
|
| settings.AddObserver(&observer);
|
| - animator->SetOpacity(0.0f);
|
| + animator->SetBrightness(0.0f);
|
| }
|
|
|
| EXPECT_FALSE(observer.animations_completed());
|
| // This should interrupt the implicit animation causing the observer to be
|
| // notified immediately.
|
| - animator->SetOpacity(1.0f);
|
| + animator->SetBrightness(1.0f);
|
| EXPECT_TRUE(observer.animations_completed());
|
| - EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation());
|
| + EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation());
|
| }
|
|
|
| // Tests that an observer added to a scoped settings object is not notified
|
| @@ -1174,13 +1626,13 @@ TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
|
| EXPECT_FALSE(observer_notify.animations_completed());
|
| EXPECT_FALSE(observer_do_not_notify.animations_completed());
|
|
|
| - animator->SetOpacity(1.0f);
|
| + animator->SetBrightness(1.0f);
|
|
|
| {
|
| ScopedLayerAnimationSettings settings(animator.get());
|
| settings.AddObserver(&observer_notify);
|
| settings.AddObserver(&observer_do_not_notify);
|
| - animator->SetOpacity(0.0f);
|
| + animator->SetBrightness(0.0f);
|
| }
|
|
|
| EXPECT_FALSE(observer_notify.animations_completed());
|
| @@ -1203,7 +1655,7 @@ TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
|
|
| LayerAnimationSequence* sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
|
|
| sequence->AddObserver(&observer);
|
| sequence->AddObserver(&removed_observer);
|
| @@ -1227,12 +1679,12 @@ TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
|
| }
|
|
|
| TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) {
|
| + TestLayerAnimationDelegate delegate;
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| animator->set_disable_timer_for_test(true);
|
|
|
| scoped_ptr<TestLayerAnimationObserver> observer(
|
| new TestLayerAnimationObserver);
|
| - TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
| animator->AddObserver(observer.get());
|
|
|
| @@ -1263,14 +1715,14 @@ TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - delegate.SetOpacityFromAnimation(0.0f);
|
| + delegate.SetBrightnessFromAnimation(0.0f);
|
|
|
| {
|
| ScopedLayerAnimationSettings setter(animator.get());
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| LayerAnimationSequence* sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
|
|
| animator->StartAnimation(sequence);
|
| base::TimeTicks start_time = animator->last_step_time();
|
| @@ -1296,10 +1748,10 @@ TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - delegate.SetOpacityFromAnimation(0.0f);
|
| + delegate.SetBrightnessFromAnimation(0.0f);
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| LayerAnimationSequence* sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
|
|
| {
|
| ScopedLayerAnimationSettings setter(animator.get());
|
| @@ -1331,16 +1783,16 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimations) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - double start_opacity(0.0);
|
| - double target_opacity(1.0);
|
| + double start_brightness(0.0);
|
| + double target_brightness(1.0);
|
|
|
| gfx::Rect start_bounds(0, 0, 50, 50);
|
| gfx::Rect target_bounds(5, 5, 5, 5);
|
|
|
| - delegate.SetOpacityFromAnimation(start_opacity);
|
| + delegate.SetBrightnessFromAnimation(start_brightness);
|
| delegate.SetBoundsFromAnimation(start_bounds);
|
|
|
| - base::TimeDelta opacity_delta = base::TimeDelta::FromSeconds(1);
|
| + base::TimeDelta brightness_delta = base::TimeDelta::FromSeconds(1);
|
| base::TimeDelta halfway_delta = base::TimeDelta::FromSeconds(2);
|
| base::TimeDelta bounds_delta = base::TimeDelta::FromSeconds(3);
|
|
|
| @@ -1354,8 +1806,8 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimations) {
|
|
|
| animator->StartAnimation(
|
| new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(
|
| - target_opacity, opacity_delta)));
|
| + LayerAnimationElement::CreateBrightnessElement(
|
| + target_brightness, brightness_delta)));
|
|
|
| animator->StartAnimation(to_delete);
|
|
|
| @@ -1435,10 +1887,10 @@ TEST(LayerAnimatorTest, ImmediatelySettingNewTargetDoesNotLeak) {
|
|
|
| // Verifies GetTargetOpacity() works when multiple sequences are scheduled.
|
| TEST(LayerAnimatorTest, GetTargetOpacity) {
|
| + TestLayerAnimationDelegate delegate;
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
|
| animator->set_disable_timer_for_test(true);
|
| - TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| delegate.SetOpacityFromAnimation(0.0);
|
| @@ -1641,7 +2093,7 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) {
|
| TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| - delegate.SetOpacityFromAnimation(0.0f);
|
| + delegate.SetBrightnessFromAnimation(0.0f);
|
|
|
| gfx::Rect start_bounds(0, 0, 50, 50);
|
| gfx::Rect target_bounds(10, 10, 100, 100);
|
| @@ -1649,9 +2101,9 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) {
|
| delegate.SetBoundsFromAnimation(start_bounds);
|
|
|
| base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
|
| - LayerAnimationSequence* opacity_sequence = new LayerAnimationSequence(
|
| - LayerAnimationElement::CreateOpacityElement(1.0f, delta));
|
| - animator->StartAnimation(opacity_sequence);
|
| + LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence(
|
| + LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
|
| + animator->StartAnimation(brightness_sequence);
|
|
|
| delta = base::TimeDelta::FromSeconds(2);
|
| LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence(
|
| @@ -1698,11 +2150,11 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) {
|
|
|
| TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) {
|
| bool observer_was_deleted = false;
|
| + TestLayerAnimationDelegate delegate;
|
| DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
|
| observer->set_delete_on_animation_scheduled(true);
|
| LayerAnimator* animator = observer->animator();
|
| animator->set_disable_timer_for_test(true);
|
| - TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| delegate.SetOpacityFromAnimation(0.0f);
|
| @@ -1730,12 +2182,12 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterScheduling) {
|
| TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) {
|
| bool observer_was_deleted = false;
|
| DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
|
| + TestLayerAnimationDelegate delegate;
|
| observer->set_delete_on_animation_aborted(true);
|
| LayerAnimator* animator = observer->animator();
|
| animator->set_preemption_strategy(
|
| LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
| animator->set_disable_timer_for_test(true);
|
| - TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| delegate.SetOpacityFromAnimation(0.0f);
|
| @@ -1767,10 +2219,10 @@ TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterAborted) {
|
|
|
|
|
| TEST(LayerAnimatorTest, TestSetterRespectEnqueueStrategy) {
|
| + TestLayerAnimationDelegate delegate;
|
| scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
|
| animator->set_disable_timer_for_test(true);
|
|
|
| - TestLayerAnimationDelegate delegate;
|
| animator->SetDelegate(&delegate);
|
|
|
| float start_opacity = 0.0f;
|
|
|