Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Side by Side Diff: ui/compositor/layer_animation_element_unittest.cc

Issue 2550933002: Make all LayerAnimationElement::Create*Element return unique_ptr (Closed)
Patch Set: Complete inclusion Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // that the element can be reused after it completes. 55 // that the element can be reused after it completes.
56 TEST(LayerAnimationElementTest, TransformElement) { 56 TEST(LayerAnimationElementTest, TransformElement) {
57 TestLayerAnimationDelegate delegate; 57 TestLayerAnimationDelegate delegate;
58 gfx::Transform start_transform, target_transform; 58 gfx::Transform start_transform, target_transform;
59 start_transform.Rotate(-30.0); 59 start_transform.Rotate(-30.0);
60 target_transform.Rotate(30.0); 60 target_transform.Rotate(30.0);
61 base::TimeTicks start_time; 61 base::TimeTicks start_time;
62 base::TimeTicks effective_start_time; 62 base::TimeTicks effective_start_time;
63 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 63 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
64 64
65 std::unique_ptr<LayerAnimationElement> element( 65 std::unique_ptr<LayerAnimationElement> element =
66 LayerAnimationElement::CreateTransformElement(target_transform, delta)); 66 LayerAnimationElement::CreateTransformElement(target_transform, delta);
67 element->set_animation_group_id(1); 67 element->set_animation_group_id(1);
68 68
69 for (int i = 0; i < 2; ++i) { 69 for (int i = 0; i < 2; ++i) {
70 start_time = effective_start_time + delta; 70 start_time = effective_start_time + delta;
71 element->set_requested_start_time(start_time); 71 element->set_requested_start_time(start_time);
72 delegate.SetTransformFromAnimation(start_transform); 72 delegate.SetTransformFromAnimation(start_transform);
73 element->Start(&delegate, 1); 73 element->Start(&delegate, 1);
74 element->Progress(start_time, &delegate); 74 element->Progress(start_time, &delegate);
75 CheckApproximatelyEqual(start_transform, 75 CheckApproximatelyEqual(start_transform,
76 delegate.GetTransformForAnimation()); 76 delegate.GetTransformForAnimation());
(...skipping 24 matching lines...) Expand all
101 // that the element can be reused after it completes. 101 // that the element can be reused after it completes.
102 TEST(LayerAnimationElementTest, BoundsElement) { 102 TEST(LayerAnimationElementTest, BoundsElement) {
103 TestLayerAnimationDelegate delegate; 103 TestLayerAnimationDelegate delegate;
104 gfx::Rect start, target, middle; 104 gfx::Rect start, target, middle;
105 start = target = middle = gfx::Rect(0, 0, 50, 50); 105 start = target = middle = gfx::Rect(0, 0, 50, 50);
106 start.set_x(-90); 106 start.set_x(-90);
107 target.set_x(90); 107 target.set_x(90);
108 base::TimeTicks start_time; 108 base::TimeTicks start_time;
109 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 109 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
110 110
111 std::unique_ptr<LayerAnimationElement> element( 111 std::unique_ptr<LayerAnimationElement> element =
112 LayerAnimationElement::CreateBoundsElement(target, delta)); 112 LayerAnimationElement::CreateBoundsElement(target, delta);
113 113
114 for (int i = 0; i < 2; ++i) { 114 for (int i = 0; i < 2; ++i) {
115 start_time += delta; 115 start_time += delta;
116 element->set_requested_start_time(start_time); 116 element->set_requested_start_time(start_time);
117 delegate.SetBoundsFromAnimation(start); 117 delegate.SetBoundsFromAnimation(start);
118 element->Start(&delegate, 1); 118 element->Start(&delegate, 1);
119 element->Progress(start_time, &delegate); 119 element->Progress(start_time, &delegate);
120 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); 120 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation());
121 element->Progress(start_time + delta/2, &delegate); 121 element->Progress(start_time + delta/2, &delegate);
122 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); 122 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation());
(...skipping 14 matching lines...) Expand all
137 // Check that the opacity element progresses the delegate as expected and 137 // Check that the opacity element progresses the delegate as expected and
138 // that the element can be reused after it completes. 138 // that the element can be reused after it completes.
139 TEST(LayerAnimationElementTest, OpacityElement) { 139 TEST(LayerAnimationElementTest, OpacityElement) {
140 TestLayerAnimationDelegate delegate; 140 TestLayerAnimationDelegate delegate;
141 float start = 0.0; 141 float start = 0.0;
142 float middle = 0.5; 142 float middle = 0.5;
143 float target = 1.0; 143 float target = 1.0;
144 base::TimeTicks start_time; 144 base::TimeTicks start_time;
145 base::TimeTicks effective_start_time; 145 base::TimeTicks effective_start_time;
146 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 146 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
147 std::unique_ptr<LayerAnimationElement> element( 147 std::unique_ptr<LayerAnimationElement> element =
148 LayerAnimationElement::CreateOpacityElement(target, delta)); 148 LayerAnimationElement::CreateOpacityElement(target, delta);
149 149
150 for (int i = 0; i < 2; ++i) { 150 for (int i = 0; i < 2; ++i) {
151 start_time = effective_start_time + delta; 151 start_time = effective_start_time + delta;
152 element->set_requested_start_time(start_time); 152 element->set_requested_start_time(start_time);
153 delegate.SetOpacityFromAnimation(start); 153 delegate.SetOpacityFromAnimation(start);
154 element->Start(&delegate, 1); 154 element->Start(&delegate, 1);
155 element->Progress(start_time, &delegate); 155 element->Progress(start_time, &delegate);
156 EXPECT_FLOAT_EQ(start, element->last_progressed_fraction()); 156 EXPECT_FLOAT_EQ(start, element->last_progressed_fraction());
157 effective_start_time = start_time + delta; 157 effective_start_time = start_time + delta;
158 element->set_effective_start_time(effective_start_time); 158 element->set_effective_start_time(effective_start_time);
(...skipping 18 matching lines...) Expand all
177 } 177 }
178 178
179 // Check that the visibility element progresses the delegate as expected and 179 // Check that the visibility element progresses the delegate as expected and
180 // that the element can be reused after it completes. 180 // that the element can be reused after it completes.
181 TEST(LayerAnimationElementTest, VisibilityElement) { 181 TEST(LayerAnimationElementTest, VisibilityElement) {
182 TestLayerAnimationDelegate delegate; 182 TestLayerAnimationDelegate delegate;
183 bool start = true; 183 bool start = true;
184 bool target = false; 184 bool target = false;
185 base::TimeTicks start_time; 185 base::TimeTicks start_time;
186 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 186 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
187 std::unique_ptr<LayerAnimationElement> element( 187 std::unique_ptr<LayerAnimationElement> element =
188 LayerAnimationElement::CreateVisibilityElement(target, delta)); 188 LayerAnimationElement::CreateVisibilityElement(target, delta);
189 189
190 for (int i = 0; i < 2; ++i) { 190 for (int i = 0; i < 2; ++i) {
191 start_time += delta; 191 start_time += delta;
192 element->set_requested_start_time(start_time); 192 element->set_requested_start_time(start_time);
193 delegate.SetVisibilityFromAnimation(start); 193 delegate.SetVisibilityFromAnimation(start);
194 element->Start(&delegate, 1); 194 element->Start(&delegate, 1);
195 element->Progress(start_time, &delegate); 195 element->Progress(start_time, &delegate);
196 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); 196 EXPECT_TRUE(delegate.GetVisibilityForAnimation());
197 element->Progress(start_time + delta/2, &delegate); 197 element->Progress(start_time + delta/2, &delegate);
198 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); 198 EXPECT_TRUE(delegate.GetVisibilityForAnimation());
(...skipping 13 matching lines...) Expand all
212 212
213 // Check that the Brightness element progresses the delegate as expected and 213 // Check that the Brightness element progresses the delegate as expected and
214 // that the element can be reused after it completes. 214 // that the element can be reused after it completes.
215 TEST(LayerAnimationElementTest, BrightnessElement) { 215 TEST(LayerAnimationElementTest, BrightnessElement) {
216 TestLayerAnimationDelegate delegate; 216 TestLayerAnimationDelegate delegate;
217 float start = 0.0; 217 float start = 0.0;
218 float middle = 0.5; 218 float middle = 0.5;
219 float target = 1.0; 219 float target = 1.0;
220 base::TimeTicks start_time; 220 base::TimeTicks start_time;
221 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 221 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
222 std::unique_ptr<LayerAnimationElement> element( 222 std::unique_ptr<LayerAnimationElement> element =
223 LayerAnimationElement::CreateBrightnessElement(target, delta)); 223 LayerAnimationElement::CreateBrightnessElement(target, delta);
224 224
225 for (int i = 0; i < 2; ++i) { 225 for (int i = 0; i < 2; ++i) {
226 start_time += delta; 226 start_time += delta;
227 element->set_requested_start_time(start_time); 227 element->set_requested_start_time(start_time);
228 delegate.SetBrightnessFromAnimation(start); 228 delegate.SetBrightnessFromAnimation(start);
229 element->Start(&delegate, 1); 229 element->Start(&delegate, 1);
230 element->Progress(start_time, &delegate); 230 element->Progress(start_time, &delegate);
231 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation()); 231 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation());
232 element->Progress(start_time + delta/2, &delegate); 232 element->Progress(start_time + delta/2, &delegate);
233 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation()); 233 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation());
(...skipping 13 matching lines...) Expand all
247 247
248 // Check that the Grayscale element progresses the delegate as expected and 248 // Check that the Grayscale element progresses the delegate as expected and
249 // that the element can be reused after it completes. 249 // that the element can be reused after it completes.
250 TEST(LayerAnimationElementTest, GrayscaleElement) { 250 TEST(LayerAnimationElementTest, GrayscaleElement) {
251 TestLayerAnimationDelegate delegate; 251 TestLayerAnimationDelegate delegate;
252 float start = 0.0; 252 float start = 0.0;
253 float middle = 0.5; 253 float middle = 0.5;
254 float target = 1.0; 254 float target = 1.0;
255 base::TimeTicks start_time; 255 base::TimeTicks start_time;
256 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 256 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
257 std::unique_ptr<LayerAnimationElement> element( 257 std::unique_ptr<LayerAnimationElement> element =
258 LayerAnimationElement::CreateGrayscaleElement(target, delta)); 258 LayerAnimationElement::CreateGrayscaleElement(target, delta);
259 259
260 for (int i = 0; i < 2; ++i) { 260 for (int i = 0; i < 2; ++i) {
261 start_time += delta; 261 start_time += delta;
262 element->set_requested_start_time(start_time); 262 element->set_requested_start_time(start_time);
263 delegate.SetGrayscaleFromAnimation(start); 263 delegate.SetGrayscaleFromAnimation(start);
264 element->Start(&delegate, 1); 264 element->Start(&delegate, 1);
265 element->Progress(start_time, &delegate); 265 element->Progress(start_time, &delegate);
266 EXPECT_FLOAT_EQ(start, delegate.GetGrayscaleForAnimation()); 266 EXPECT_FLOAT_EQ(start, delegate.GetGrayscaleForAnimation());
267 element->Progress(start_time + delta/2, &delegate); 267 element->Progress(start_time + delta/2, &delegate);
268 EXPECT_FLOAT_EQ(middle, delegate.GetGrayscaleForAnimation()); 268 EXPECT_FLOAT_EQ(middle, delegate.GetGrayscaleForAnimation());
(...skipping 15 matching lines...) Expand all
284 // that the element can be reused after it completes. 284 // that the element can be reused after it completes.
285 TEST(LayerAnimationElementTest, PauseElement) { 285 TEST(LayerAnimationElementTest, PauseElement) {
286 LayerAnimationElement::AnimatableProperties properties = 286 LayerAnimationElement::AnimatableProperties properties =
287 LayerAnimationElement::TRANSFORM | LayerAnimationElement::BOUNDS | 287 LayerAnimationElement::TRANSFORM | LayerAnimationElement::BOUNDS |
288 LayerAnimationElement::OPACITY | LayerAnimationElement::BRIGHTNESS | 288 LayerAnimationElement::OPACITY | LayerAnimationElement::BRIGHTNESS |
289 LayerAnimationElement::GRAYSCALE; 289 LayerAnimationElement::GRAYSCALE;
290 290
291 base::TimeTicks start_time; 291 base::TimeTicks start_time;
292 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 292 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
293 293
294 std::unique_ptr<LayerAnimationElement> element( 294 std::unique_ptr<LayerAnimationElement> element =
295 LayerAnimationElement::CreatePauseElement(properties, delta)); 295 LayerAnimationElement::CreatePauseElement(properties, delta);
296 296
297 TestLayerAnimationDelegate delegate; 297 TestLayerAnimationDelegate delegate;
298 TestLayerAnimationDelegate copy = delegate; 298 TestLayerAnimationDelegate copy = delegate;
299 299
300 start_time += delta; 300 start_time += delta;
301 element->set_requested_start_time(start_time); 301 element->set_requested_start_time(start_time);
302 element->Start(&delegate, 1); 302 element->Start(&delegate, 1);
303 303
304 // Pause should last for |delta|. 304 // Pause should last for |delta|.
305 base::TimeDelta element_duration; 305 base::TimeDelta element_duration;
(...skipping 17 matching lines...) Expand all
323 323
324 // Check that a threaded opacity element updates the delegate as expected when 324 // Check that a threaded opacity element updates the delegate as expected when
325 // aborted. 325 // aborted.
326 TEST(LayerAnimationElementTest, AbortOpacityElement) { 326 TEST(LayerAnimationElementTest, AbortOpacityElement) {
327 TestLayerAnimationDelegate delegate; 327 TestLayerAnimationDelegate delegate;
328 float start = 0.0; 328 float start = 0.0;
329 float target = 1.0; 329 float target = 1.0;
330 base::TimeTicks start_time; 330 base::TimeTicks start_time;
331 base::TimeTicks effective_start_time; 331 base::TimeTicks effective_start_time;
332 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 332 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
333 std::unique_ptr<LayerAnimationElement> element( 333 std::unique_ptr<LayerAnimationElement> element =
334 LayerAnimationElement::CreateOpacityElement(target, delta)); 334 LayerAnimationElement::CreateOpacityElement(target, delta);
335 335
336 // Choose a non-linear Tween type. 336 // Choose a non-linear Tween type.
337 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; 337 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN;
338 element->set_tween_type(tween_type); 338 element->set_tween_type(tween_type);
339 339
340 delegate.SetOpacityFromAnimation(start); 340 delegate.SetOpacityFromAnimation(start);
341 341
342 // Aborting the element before it has started should not update the delegate. 342 // Aborting the element before it has started should not update the delegate.
343 element->Abort(&delegate); 343 element->Abort(&delegate);
344 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); 344 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
(...skipping 17 matching lines...) Expand all
362 // Check that a threaded transform element updates the delegate as expected when 362 // Check that a threaded transform element updates the delegate as expected when
363 // aborted. 363 // aborted.
364 TEST(LayerAnimationElementTest, AbortTransformElement) { 364 TEST(LayerAnimationElementTest, AbortTransformElement) {
365 TestLayerAnimationDelegate delegate; 365 TestLayerAnimationDelegate delegate;
366 gfx::Transform start_transform, target_transform; 366 gfx::Transform start_transform, target_transform;
367 start_transform.Rotate(-30.0); 367 start_transform.Rotate(-30.0);
368 target_transform.Rotate(30.0); 368 target_transform.Rotate(30.0);
369 base::TimeTicks start_time; 369 base::TimeTicks start_time;
370 base::TimeTicks effective_start_time; 370 base::TimeTicks effective_start_time;
371 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 371 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
372 std::unique_ptr<LayerAnimationElement> element( 372 std::unique_ptr<LayerAnimationElement> element =
373 LayerAnimationElement::CreateTransformElement(target_transform, delta)); 373 LayerAnimationElement::CreateTransformElement(target_transform, delta);
374 374
375 // Choose a non-linear Tween type. 375 // Choose a non-linear Tween type.
376 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN; 376 gfx::Tween::Type tween_type = gfx::Tween::EASE_IN;
377 element->set_tween_type(tween_type); 377 element->set_tween_type(tween_type);
378 378
379 delegate.SetTransformFromAnimation(start_transform); 379 delegate.SetTransformFromAnimation(start_transform);
380 380
381 // Aborting the element before it has started should not update the delegate. 381 // Aborting the element before it has started should not update the delegate.
382 element->Abort(&delegate); 382 element->Abort(&delegate);
383 CheckApproximatelyEqual(start_transform, delegate.GetTransformForAnimation()); 383 CheckApproximatelyEqual(start_transform, delegate.GetTransformForAnimation());
(...skipping 12 matching lines...) Expand all
396 element->Abort(&delegate); 396 element->Abort(&delegate);
397 target_transform.Blend(start_transform, 397 target_transform.Blend(start_transform,
398 gfx::Tween::CalculateValue(tween_type, 0.5)); 398 gfx::Tween::CalculateValue(tween_type, 0.5));
399 CheckApproximatelyEqual(target_transform, 399 CheckApproximatelyEqual(target_transform,
400 delegate.GetTransformForAnimation()); 400 delegate.GetTransformForAnimation());
401 } 401 }
402 402
403 } // namespace 403 } // namespace
404 404
405 } // namespace ui 405 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698