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" | |
15 #include "ui/gfx/compositor/layer_animation_delegate.h" | 14 #include "ui/gfx/compositor/layer_animation_delegate.h" |
| 15 #include "ui/gfx/compositor/test_layer_animation_delegate.h" |
16 #include "ui/gfx/compositor/test_utils.h" | 16 #include "ui/gfx/compositor/test_utils.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 DummyLayerAnimationDelegate delegate; | 25 TestLayerAnimationDelegate 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); |
(...skipping 11 matching lines...) Expand all Loading... |
47 LayerAnimationElement::TargetValue target_value; | 47 LayerAnimationElement::TargetValue target_value; |
48 element->GetTargetValue(&target_value); | 48 element->GetTargetValue(&target_value); |
49 CheckApproximatelyEqual(target_transform, target_value.transform); | 49 CheckApproximatelyEqual(target_transform, target_value.transform); |
50 | 50 |
51 EXPECT_EQ(delta, element->duration()); | 51 EXPECT_EQ(delta, element->duration()); |
52 } | 52 } |
53 | 53 |
54 // Check that the bounds element progresses the delegate as expected and | 54 // Check that the bounds element progresses the delegate as expected and |
55 // that the element can be reused after it completes. | 55 // that the element can be reused after it completes. |
56 TEST(LayerAnimationElementTest, BoundsElement) { | 56 TEST(LayerAnimationElementTest, BoundsElement) { |
57 DummyLayerAnimationDelegate delegate; | 57 TestLayerAnimationDelegate delegate; |
58 gfx::Rect start, target, middle; | 58 gfx::Rect start, target, middle; |
59 start = target = middle = gfx::Rect(0, 0, 50, 50); | 59 start = target = middle = gfx::Rect(0, 0, 50, 50); |
60 start.set_x(-90); | 60 start.set_x(-90); |
61 target.set_x(90); | 61 target.set_x(90); |
62 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 62 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
63 | 63 |
64 scoped_ptr<LayerAnimationElement> element( | 64 scoped_ptr<LayerAnimationElement> element( |
65 LayerAnimationElement::CreateBoundsElement(target, delta)); | 65 LayerAnimationElement::CreateBoundsElement(target, delta)); |
66 | 66 |
67 for (int i = 0; i < 2; ++i) { | 67 for (int i = 0; i < 2; ++i) { |
68 delegate.SetBoundsFromAnimation(start); | 68 delegate.SetBoundsFromAnimation(start); |
69 element->Progress(0.0, &delegate); | 69 element->Progress(0.0, &delegate); |
70 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); | 70 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); |
71 element->Progress(0.5, &delegate); | 71 element->Progress(0.5, &delegate); |
72 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); | 72 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); |
73 element->Progress(1.0, &delegate); | 73 element->Progress(1.0, &delegate); |
74 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); | 74 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); |
75 } | 75 } |
76 | 76 |
77 LayerAnimationElement::TargetValue target_value; | 77 LayerAnimationElement::TargetValue target_value; |
78 element->GetTargetValue(&target_value); | 78 element->GetTargetValue(&target_value); |
79 CheckApproximatelyEqual(target, target_value.bounds); | 79 CheckApproximatelyEqual(target, target_value.bounds); |
80 | 80 |
81 EXPECT_EQ(delta, element->duration()); | 81 EXPECT_EQ(delta, element->duration()); |
82 } | 82 } |
83 | 83 |
84 // Check that the opacity element progresses the delegate as expected and | 84 // Check that the opacity element progresses the delegate as expected and |
85 // that the element can be reused after it completes. | 85 // that the element can be reused after it completes. |
86 TEST(LayerAnimationElementTest, OpacityElement) { | 86 TEST(LayerAnimationElementTest, OpacityElement) { |
87 DummyLayerAnimationDelegate delegate; | 87 TestLayerAnimationDelegate delegate; |
88 float start = 0.0; | 88 float start = 0.0; |
89 float middle = 0.5; | 89 float middle = 0.5; |
90 float target = 1.0; | 90 float target = 1.0; |
91 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 91 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
92 scoped_ptr<LayerAnimationElement> element( | 92 scoped_ptr<LayerAnimationElement> element( |
93 LayerAnimationElement::CreateOpacityElement(target, delta)); | 93 LayerAnimationElement::CreateOpacityElement(target, delta)); |
94 | 94 |
95 for (int i = 0; i < 2; ++i) { | 95 for (int i = 0; i < 2; ++i) { |
96 delegate.SetOpacityFromAnimation(start); | 96 delegate.SetOpacityFromAnimation(start); |
97 element->Progress(0.0, &delegate); | 97 element->Progress(0.0, &delegate); |
(...skipping 16 matching lines...) Expand all Loading... |
114 TEST(LayerAnimationElementTest, PauseElement) { | 114 TEST(LayerAnimationElementTest, PauseElement) { |
115 LayerAnimationElement::AnimatableProperties properties; | 115 LayerAnimationElement::AnimatableProperties properties; |
116 properties.insert(LayerAnimationElement::TRANSFORM); | 116 properties.insert(LayerAnimationElement::TRANSFORM); |
117 properties.insert(LayerAnimationElement::BOUNDS); | 117 properties.insert(LayerAnimationElement::BOUNDS); |
118 properties.insert(LayerAnimationElement::OPACITY); | 118 properties.insert(LayerAnimationElement::OPACITY); |
119 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 119 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
120 | 120 |
121 scoped_ptr<LayerAnimationElement> element( | 121 scoped_ptr<LayerAnimationElement> element( |
122 LayerAnimationElement::CreatePauseElement(properties, delta)); | 122 LayerAnimationElement::CreatePauseElement(properties, delta)); |
123 | 123 |
124 DummyLayerAnimationDelegate delegate; | 124 TestLayerAnimationDelegate delegate; |
125 DummyLayerAnimationDelegate copy = delegate; | 125 TestLayerAnimationDelegate copy = delegate; |
126 | 126 |
127 element->Progress(1.0, &delegate); | 127 element->Progress(1.0, &delegate); |
128 | 128 |
129 // Nothing should have changed. | 129 // Nothing should have changed. |
130 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 130 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
131 copy.GetBoundsForAnimation()); | 131 copy.GetBoundsForAnimation()); |
132 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 132 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
133 copy.GetTransformForAnimation()); | 133 copy.GetTransformForAnimation()); |
134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 134 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
135 copy.GetOpacityForAnimation()); | 135 copy.GetOpacityForAnimation()); |
136 | 136 |
137 // Pause should last for |delta|. | 137 // Pause should last for |delta|. |
138 EXPECT_EQ(delta, element->duration()); | 138 EXPECT_EQ(delta, element->duration()); |
139 } | 139 } |
140 | 140 |
141 } // namespace | 141 } // namespace |
142 | 142 |
143 } // namespace ui | 143 } // namespace ui |
OLD | NEW |