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