OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/compositor/layer_animation_element.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/transform.h" |
| 14 #include "ui/gfx/compositor/layer_animation_delegate.h" |
| 15 #include "ui/gfx/compositor/test_utils.h" |
| 16 #include "ui/gfx/compositor/test_layer_animation_delegate.h" |
| 17 |
| 18 namespace ui { |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Check that the transformation element progresses the delegate as expected and |
| 23 // that the element can be reused after it completes. |
| 24 TEST(LayerAnimationElementTest, TransformElement) { |
| 25 TestLayerAnimationDelegate delegate; |
| 26 Transform start_transform, target_transform, middle_transform; |
| 27 start_transform.SetRotate(-90); |
| 28 target_transform.SetRotate(90); |
| 29 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 30 |
| 31 scoped_ptr<LayerAnimationElement> element( |
| 32 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
| 33 |
| 34 for (int i = 0; i < 2; ++i) { |
| 35 delegate.SetTransformFromAnimation(start_transform); |
| 36 element->Progress(0.0, &delegate); |
| 37 CheckApproximatelyEqual(start_transform, |
| 38 delegate.GetTransformForAnimation()); |
| 39 element->Progress(0.5, &delegate); |
| 40 CheckApproximatelyEqual(middle_transform, |
| 41 delegate.GetTransformForAnimation()); |
| 42 element->Progress(1.0, &delegate); |
| 43 CheckApproximatelyEqual(target_transform, |
| 44 delegate.GetTransformForAnimation()); |
| 45 } |
| 46 |
| 47 EXPECT_EQ(delta, element->duration()); |
| 48 } |
| 49 |
| 50 // Check that the bounds element progresses the delegate as expected and |
| 51 // that the element can be reused after it completes. |
| 52 TEST(LayerAnimationElementTest, BoundsElement) { |
| 53 TestLayerAnimationDelegate delegate; |
| 54 gfx::Rect start, target, middle; |
| 55 start = target = middle = gfx::Rect(0, 0, 50, 50); |
| 56 start.set_x(-90); |
| 57 target.set_x(90); |
| 58 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 59 |
| 60 scoped_ptr<LayerAnimationElement> element( |
| 61 LayerAnimationElement::CreateBoundsElement(target, delta)); |
| 62 |
| 63 for (int i = 0; i < 2; ++i) { |
| 64 delegate.SetBoundsFromAnimation(start); |
| 65 element->Progress(0.0, &delegate); |
| 66 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); |
| 67 element->Progress(0.5, &delegate); |
| 68 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); |
| 69 element->Progress(1.0, &delegate); |
| 70 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); |
| 71 } |
| 72 |
| 73 EXPECT_EQ(delta, element->duration()); |
| 74 } |
| 75 |
| 76 // Check that the opacity element progresses the delegate as expected and |
| 77 // that the element can be reused after it completes. |
| 78 TEST(LayerAnimationElementTest, OpacityElement) { |
| 79 TestLayerAnimationDelegate delegate; |
| 80 float start = 0.0; |
| 81 float middle = 0.5; |
| 82 float target = 1.0; |
| 83 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 84 scoped_ptr<LayerAnimationElement> element( |
| 85 LayerAnimationElement::CreateOpacityElement(target, delta)); |
| 86 |
| 87 for (int i = 0; i < 2; ++i) { |
| 88 delegate.SetOpacityFromAnimation(start); |
| 89 element->Progress(0.0, &delegate); |
| 90 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); |
| 91 element->Progress(0.5, &delegate); |
| 92 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); |
| 93 element->Progress(1.0, &delegate); |
| 94 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); |
| 95 } |
| 96 |
| 97 EXPECT_EQ(delta, element->duration()); |
| 98 } |
| 99 |
| 100 // Check that the pause element progresses the delegate as expected and |
| 101 // that the element can be reused after it completes. |
| 102 TEST(LayerAnimationElementTest, PauseElement) { |
| 103 LayerAnimationElement::AnimatableProperties properties; |
| 104 properties.insert(LayerAnimationElement::TRANSFORM); |
| 105 properties.insert(LayerAnimationElement::BOUNDS); |
| 106 properties.insert(LayerAnimationElement::OPACITY); |
| 107 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 108 |
| 109 scoped_ptr<LayerAnimationElement> element( |
| 110 LayerAnimationElement::CreatePauseElement(properties, delta)); |
| 111 |
| 112 TestLayerAnimationDelegate delegate; |
| 113 TestLayerAnimationDelegate copy = delegate; |
| 114 |
| 115 element->Progress(1.0, &delegate); |
| 116 |
| 117 // Nothing should have changed. |
| 118 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
| 119 copy.GetBoundsForAnimation()); |
| 120 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
| 121 copy.GetTransformForAnimation()); |
| 122 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
| 123 copy.GetOpacityForAnimation()); |
| 124 |
| 125 // Pause should last for |delta|. |
| 126 EXPECT_EQ(delta, element->duration()); |
| 127 } |
| 128 |
| 129 } // namespace |
| 130 |
| 131 } // namespace ui |
OLD | NEW |