OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/compositor/layer_animation_element.h" | 5 #include "ui/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" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_FALSE(delegate.GetVisibilityForAnimation()); | 129 EXPECT_FALSE(delegate.GetVisibilityForAnimation()); |
130 } | 130 } |
131 | 131 |
132 LayerAnimationElement::TargetValue target_value(&delegate); | 132 LayerAnimationElement::TargetValue target_value(&delegate); |
133 element->GetTargetValue(&target_value); | 133 element->GetTargetValue(&target_value); |
134 EXPECT_FALSE(target_value.visibility); | 134 EXPECT_FALSE(target_value.visibility); |
135 | 135 |
136 EXPECT_EQ(delta, element->duration()); | 136 EXPECT_EQ(delta, element->duration()); |
137 } | 137 } |
138 | 138 |
| 139 // Check that the Brightness element progresses the delegate as expected and |
| 140 // that the element can be reused after it completes. |
| 141 TEST(LayerAnimationElementTest, BrightnessElement) { |
| 142 TestLayerAnimationDelegate delegate; |
| 143 float start = 0.0; |
| 144 float middle = 0.5; |
| 145 float target = 1.0; |
| 146 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 147 scoped_ptr<LayerAnimationElement> element( |
| 148 LayerAnimationElement::CreateBrightnessElement(target, delta)); |
| 149 |
| 150 for (int i = 0; i < 2; ++i) { |
| 151 delegate.SetBrightnessFromAnimation(start); |
| 152 element->Progress(0.0, &delegate); |
| 153 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation()); |
| 154 element->Progress(0.5, &delegate); |
| 155 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation()); |
| 156 element->Progress(1.0, &delegate); |
| 157 EXPECT_FLOAT_EQ(target, delegate.GetBrightnessForAnimation()); |
| 158 } |
| 159 |
| 160 LayerAnimationElement::TargetValue target_value(&delegate); |
| 161 element->GetTargetValue(&target_value); |
| 162 EXPECT_FLOAT_EQ(target, target_value.brightness); |
| 163 |
| 164 EXPECT_EQ(delta, element->duration()); |
| 165 } |
| 166 |
| 167 // Check that the Grayscale element progresses the delegate as expected and |
| 168 // that the element can be reused after it completes. |
| 169 TEST(LayerAnimationElementTest, GrayscaleElement) { |
| 170 TestLayerAnimationDelegate delegate; |
| 171 float start = 0.0; |
| 172 float middle = 0.5; |
| 173 float target = 1.0; |
| 174 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
| 175 scoped_ptr<LayerAnimationElement> element( |
| 176 LayerAnimationElement::CreateGrayscaleElement(target, delta)); |
| 177 |
| 178 for (int i = 0; i < 2; ++i) { |
| 179 delegate.SetGrayscaleFromAnimation(start); |
| 180 element->Progress(0.0, &delegate); |
| 181 EXPECT_FLOAT_EQ(start, delegate.GetGrayscaleForAnimation()); |
| 182 element->Progress(0.5, &delegate); |
| 183 EXPECT_FLOAT_EQ(middle, delegate.GetGrayscaleForAnimation()); |
| 184 element->Progress(1.0, &delegate); |
| 185 EXPECT_FLOAT_EQ(target, delegate.GetGrayscaleForAnimation()); |
| 186 } |
| 187 |
| 188 LayerAnimationElement::TargetValue target_value(&delegate); |
| 189 element->GetTargetValue(&target_value); |
| 190 EXPECT_FLOAT_EQ(target, target_value.grayscale); |
| 191 |
| 192 EXPECT_EQ(delta, element->duration()); |
| 193 } |
| 194 |
139 // Check that the pause element progresses the delegate as expected and | 195 // Check that the pause element progresses the delegate as expected and |
140 // that the element can be reused after it completes. | 196 // that the element can be reused after it completes. |
141 TEST(LayerAnimationElementTest, PauseElement) { | 197 TEST(LayerAnimationElementTest, PauseElement) { |
142 LayerAnimationElement::AnimatableProperties properties; | 198 LayerAnimationElement::AnimatableProperties properties; |
143 properties.insert(LayerAnimationElement::TRANSFORM); | 199 properties.insert(LayerAnimationElement::TRANSFORM); |
144 properties.insert(LayerAnimationElement::BOUNDS); | 200 properties.insert(LayerAnimationElement::BOUNDS); |
145 properties.insert(LayerAnimationElement::OPACITY); | 201 properties.insert(LayerAnimationElement::OPACITY); |
| 202 properties.insert(LayerAnimationElement::BRIGHTNESS); |
| 203 properties.insert(LayerAnimationElement::GRAYSCALE); |
146 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 204 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
147 | 205 |
148 scoped_ptr<LayerAnimationElement> element( | 206 scoped_ptr<LayerAnimationElement> element( |
149 LayerAnimationElement::CreatePauseElement(properties, delta)); | 207 LayerAnimationElement::CreatePauseElement(properties, delta)); |
150 | 208 |
151 TestLayerAnimationDelegate delegate; | 209 TestLayerAnimationDelegate delegate; |
152 TestLayerAnimationDelegate copy = delegate; | 210 TestLayerAnimationDelegate copy = delegate; |
153 | 211 |
154 element->Progress(1.0, &delegate); | 212 element->Progress(1.0, &delegate); |
155 | 213 |
156 // Nothing should have changed. | 214 // Nothing should have changed. |
157 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 215 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
158 copy.GetBoundsForAnimation()); | 216 copy.GetBoundsForAnimation()); |
159 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 217 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
160 copy.GetTransformForAnimation()); | 218 copy.GetTransformForAnimation()); |
161 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 219 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
162 copy.GetOpacityForAnimation()); | 220 copy.GetOpacityForAnimation()); |
| 221 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
| 222 copy.GetBrightnessForAnimation()); |
| 223 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
| 224 copy.GetGrayscaleForAnimation()); |
163 | 225 |
164 // Pause should last for |delta|. | 226 // Pause should last for |delta|. |
165 EXPECT_EQ(delta, element->duration()); | 227 EXPECT_EQ(delta, element->duration()); |
166 } | 228 } |
167 | 229 |
168 } // namespace | 230 } // namespace |
169 | 231 |
170 } // namespace ui | 232 } // namespace ui |
OLD | NEW |