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_sequence.h" | 5 #include "ui/compositor/layer_animation_sequence.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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // Check that the sequence behaves sanely when it contains no elements. | 24 // Check that the sequence behaves sanely when it contains no elements. |
25 TEST(LayerAnimationSequenceTest, NoElement) { | 25 TEST(LayerAnimationSequenceTest, NoElement) { |
26 LayerAnimationSequence sequence; | 26 LayerAnimationSequence sequence; |
27 base::TimeTicks start_time; | 27 base::TimeTicks start_time; |
28 start_time += base::TimeDelta::FromSeconds(1); | 28 start_time += base::TimeDelta::FromSeconds(1); |
29 sequence.set_start_time(start_time); | 29 sequence.set_start_time(start_time); |
30 EXPECT_TRUE(sequence.IsFinished(start_time)); | 30 EXPECT_TRUE(sequence.IsFinished(start_time)); |
31 EXPECT_TRUE(sequence.properties().size() == 0); | 31 EXPECT_TRUE(sequence.properties().size() == 0); |
32 LayerAnimationElement::AnimatableProperties properties; | 32 LayerAnimationElement::AnimatableProperties properties; |
33 EXPECT_FALSE(sequence.HasCommonProperty(properties)); | 33 EXPECT_FALSE(sequence.HasConflictingProperty(properties)); |
34 } | 34 } |
35 | 35 |
36 // Check that the sequences progresses the delegate as expected when it contains | 36 // Check that the sequences progresses the delegate as expected when it contains |
37 // a single non-threaded element. | 37 // a single non-threaded element. |
38 TEST(LayerAnimationSequenceTest, SingleElement) { | 38 TEST(LayerAnimationSequenceTest, SingleElement) { |
39 LayerAnimationSequence sequence; | 39 LayerAnimationSequence sequence; |
40 TestLayerAnimationDelegate delegate; | 40 TestLayerAnimationDelegate delegate; |
41 float start = 0.0f; | 41 float start = 0.0f; |
42 float middle = 0.5f; | 42 float middle = 0.5f; |
43 float target = 1.0f; | 43 float target = 1.0f; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 // Check that the sequences progresses the delegate as expected when it contains | 113 // Check that the sequences progresses the delegate as expected when it contains |
114 // multiple elements. Note, see the layer animator tests for cyclic sequences. | 114 // multiple elements. Note, see the layer animator tests for cyclic sequences. |
115 TEST(LayerAnimationSequenceTest, MultipleElement) { | 115 TEST(LayerAnimationSequenceTest, MultipleElement) { |
116 LayerAnimationSequence sequence; | 116 LayerAnimationSequence sequence; |
117 TestLayerAnimationDelegate delegate; | 117 TestLayerAnimationDelegate delegate; |
118 float start_opacity = 0.0f; | 118 float start_opacity = 0.0f; |
119 float target_opacity = 1.0f; | 119 float target_opacity = 1.0f; |
120 base::TimeTicks start_time; | 120 base::TimeTicks start_time; |
121 base::TimeTicks effective_start; | 121 base::TimeTicks opacity_effective_start; |
| 122 base::TimeTicks transform_effective_start; |
122 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 123 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
123 sequence.AddElement( | 124 sequence.AddElement( |
124 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); | 125 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); |
125 | 126 |
126 // Pause bounds for a second. | 127 // Pause bounds for a second. |
127 LayerAnimationElement::AnimatableProperties properties; | 128 LayerAnimationElement::AnimatableProperties properties; |
128 properties.insert(LayerAnimationElement::BOUNDS); | 129 properties.insert(LayerAnimationElement::BOUNDS); |
129 | 130 |
130 sequence.AddElement( | 131 sequence.AddElement( |
131 LayerAnimationElement::CreatePauseElement(properties, delta)); | 132 LayerAnimationElement::CreatePauseElement(properties, delta)); |
132 | 133 |
133 gfx::Transform start_transform, target_transform, middle_transform; | 134 gfx::Transform start_transform, target_transform, middle_transform; |
134 start_transform.Rotate(-30.0); | 135 start_transform.Rotate(-30.0); |
135 target_transform.Rotate(30.0); | 136 target_transform.Rotate(30.0); |
136 | 137 |
137 sequence.AddElement( | 138 sequence.AddElement( |
138 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 139 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
139 | 140 |
140 for (int i = 0; i < 2; ++i) { | 141 for (int i = 0; i < 2; ++i) { |
141 int group_id = 1; | 142 int group_id = 1; |
142 sequence.set_animation_group_id(group_id); | 143 sequence.set_animation_group_id(group_id); |
143 start_time = effective_start + 3 * delta; | 144 start_time = opacity_effective_start + 4 * delta; |
144 sequence.set_start_time(start_time); | 145 sequence.set_start_time(start_time); |
145 delegate.SetOpacityFromAnimation(start_opacity); | 146 delegate.SetOpacityFromAnimation(start_opacity); |
146 delegate.SetTransformFromAnimation(start_transform); | 147 delegate.SetTransformFromAnimation(start_transform); |
147 | 148 |
148 sequence.Start(&delegate); | 149 sequence.Start(&delegate); |
149 sequence.Progress(start_time, &delegate); | 150 sequence.Progress(start_time, &delegate); |
150 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 151 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
151 effective_start = start_time + delta; | 152 opacity_effective_start = start_time + delta; |
152 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( | 153 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( |
153 cc::AnimationEvent::Started, | 154 cc::AnimationEvent::Started, |
154 0, | 155 0, |
155 group_id, | 156 group_id, |
156 cc::Animation::Opacity, | 157 cc::Animation::Opacity, |
157 (effective_start - base::TimeTicks()).InSecondsF())); | 158 (opacity_effective_start - base::TimeTicks()).InSecondsF())); |
158 sequence.Progress(effective_start + delta/2, &delegate); | 159 sequence.Progress(opacity_effective_start + delta/2, &delegate); |
159 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); | 160 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
160 sequence.Progress(effective_start + delta, &delegate); | 161 sequence.Progress(opacity_effective_start + delta, &delegate); |
161 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); | 162 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); |
162 | 163 |
163 // Now at the start of the pause. | 164 // Now at the start of the pause. |
164 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 165 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
165 TestLayerAnimationDelegate copy = delegate; | 166 TestLayerAnimationDelegate copy = delegate; |
166 | 167 |
167 // In the middle of the pause -- nothing should have changed. | 168 // In the middle of the pause -- nothing should have changed. |
168 sequence.Progress(effective_start + delta + delta/2, | 169 sequence.Progress(opacity_effective_start + delta + delta/2, |
169 &delegate); | 170 &delegate); |
170 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 171 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
171 copy.GetBoundsForAnimation()); | 172 copy.GetBoundsForAnimation()); |
172 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 173 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
173 copy.GetTransformForAnimation()); | 174 copy.GetTransformForAnimation()); |
174 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 175 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
175 copy.GetOpacityForAnimation()); | 176 copy.GetOpacityForAnimation()); |
176 | 177 |
177 | 178 sequence.Progress(opacity_effective_start + 2 * delta, &delegate); |
178 sequence.Progress(effective_start + 2 * delta, &delegate); | |
179 CheckApproximatelyEqual(start_transform, | 179 CheckApproximatelyEqual(start_transform, |
180 delegate.GetTransformForAnimation()); | 180 delegate.GetTransformForAnimation()); |
181 sequence.Progress(effective_start + 2 * delta + delta/2, &delegate); | 181 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
182 CheckApproximatelyEqual(middle_transform, | 182 transform_effective_start = opacity_effective_start + 3 * delta; |
183 delegate.GetTransformForAnimation()); | 183 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( |
184 EXPECT_TRUE(sequence.IsFinished(effective_start + 3 * delta)); | 184 cc::AnimationEvent::Started, |
185 sequence.Progress(effective_start + 3 * delta, &delegate); | 185 0, |
| 186 group_id, |
| 187 cc::Animation::Transform, |
| 188 (transform_effective_start - base::TimeTicks()).InSecondsF())); |
| 189 sequence.Progress(transform_effective_start + delta/2, &delegate); |
| 190 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
| 191 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); |
| 192 sequence.Progress(transform_effective_start + delta, &delegate); |
186 CheckApproximatelyEqual(target_transform, | 193 CheckApproximatelyEqual(target_transform, |
187 delegate.GetTransformForAnimation()); | 194 delegate.GetTransformForAnimation()); |
188 } | 195 } |
189 | 196 |
190 EXPECT_TRUE(sequence.properties().size() == 3); | 197 EXPECT_TRUE(sequence.properties().size() == 3); |
191 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != | 198 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != |
192 sequence.properties().end()); | 199 sequence.properties().end()); |
193 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) != | 200 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) != |
194 sequence.properties().end()); | 201 sequence.properties().end()); |
195 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) != | 202 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) != |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 EXPECT_TRUE(!observer.last_ended_sequence()); | 275 EXPECT_TRUE(!observer.last_ended_sequence()); |
269 sequence.Progress(start_time + delta, &delegate); | 276 sequence.Progress(start_time + delta, &delegate); |
270 EXPECT_EQ(observer.last_ended_sequence(), &sequence); | 277 EXPECT_EQ(observer.last_ended_sequence(), &sequence); |
271 sequence.RemoveObserver(&observer); | 278 sequence.RemoveObserver(&observer); |
272 } | 279 } |
273 } | 280 } |
274 | 281 |
275 } // namespace | 282 } // namespace |
276 | 283 |
277 } // namespace ui | 284 } // namespace ui |
OLD | NEW |