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

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

Issue 18660005: Make ui::ThreadedTransformTransition::OnAbort correctly check whether the animation has started (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/compositor/layer_animation_element.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/time.h" 10 #include "base/time/time.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), 283 CheckApproximatelyEqual(delegate.GetTransformForAnimation(),
284 copy.GetTransformForAnimation()); 284 copy.GetTransformForAnimation());
285 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 285 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(),
286 copy.GetOpacityForAnimation()); 286 copy.GetOpacityForAnimation());
287 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 287 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
288 copy.GetBrightnessForAnimation()); 288 copy.GetBrightnessForAnimation());
289 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), 289 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(),
290 copy.GetGrayscaleForAnimation()); 290 copy.GetGrayscaleForAnimation());
291 } 291 }
292 292
293 // Check that a threaded element updates the delegate as expected when aborted. 293 // Check that a threaded opacity element updates the delegate as expected when
294 // aborted.
294 TEST(LayerAnimationElementTest, AbortOpacityElement) { 295 TEST(LayerAnimationElementTest, AbortOpacityElement) {
295 TestLayerAnimationDelegate delegate; 296 TestLayerAnimationDelegate delegate;
296 float start = 0.0; 297 float start = 0.0;
297 float target = 1.0; 298 float target = 1.0;
298 base::TimeTicks start_time; 299 base::TimeTicks start_time;
299 base::TimeTicks effective_start_time; 300 base::TimeTicks effective_start_time;
300 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 301 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
301 scoped_ptr<LayerAnimationElement> element( 302 scoped_ptr<LayerAnimationElement> element(
302 LayerAnimationElement::CreateOpacityElement(target, delta)); 303 LayerAnimationElement::CreateOpacityElement(target, delta));
303 304
304 // Choose a non-linear Tween type. 305 // Choose a non-linear Tween type.
305 Tween::Type tween_type = Tween::EASE_IN; 306 Tween::Type tween_type = Tween::EASE_IN;
306 element->set_tween_type(tween_type); 307 element->set_tween_type(tween_type);
307 308
309 delegate.SetOpacityFromAnimation(start);
310
311 // Aborting the element before it has started should not update the delegate.
312 element->Abort(&delegate);
313 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation());
314
308 start_time += delta; 315 start_time += delta;
309 element->set_requested_start_time(start_time); 316 element->set_requested_start_time(start_time);
310 delegate.SetOpacityFromAnimation(start);
311 element->Start(&delegate, 1); 317 element->Start(&delegate, 1);
312 element->Progress(start_time, &delegate); 318 element->Progress(start_time, &delegate);
313 effective_start_time = start_time + delta; 319 effective_start_time = start_time + delta;
314 element->set_effective_start_time(effective_start_time); 320 element->set_effective_start_time(effective_start_time);
315 element->Progress(effective_start_time, &delegate); 321 element->Progress(effective_start_time, &delegate);
316 element->Progress(effective_start_time + delta/2, &delegate); 322 element->Progress(effective_start_time + delta/2, &delegate);
317 323
324 // Since the element has started, it should update the delegate when
325 // aborted.
318 element->Abort(&delegate); 326 element->Abort(&delegate);
319 EXPECT_FLOAT_EQ(Tween::CalculateValue(tween_type, 0.5), 327 EXPECT_FLOAT_EQ(Tween::CalculateValue(tween_type, 0.5),
320 delegate.GetOpacityForAnimation()); 328 delegate.GetOpacityForAnimation());
321 } 329 }
322 330
331 // Check that a threaded transform element updates the delegate as expected when
332 // aborted.
333 TEST(LayerAnimationElementTest, AbortTransformElement) {
334 TestLayerAnimationDelegate delegate;
335 gfx::Transform start_transform, target_transform;
336 start_transform.Rotate(-30.0);
337 target_transform.Rotate(30.0);
338 base::TimeTicks start_time;
339 base::TimeTicks effective_start_time;
340 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
341 scoped_ptr<LayerAnimationElement> element(
342 LayerAnimationElement::CreateTransformElement(target_transform, delta));
343
344 // Choose a non-linear Tween type.
345 Tween::Type tween_type = Tween::EASE_IN;
346 element->set_tween_type(tween_type);
347
348 delegate.SetTransformFromAnimation(start_transform);
349
350 // Aborting the element before it has started should not update the delegate.
351 element->Abort(&delegate);
352 CheckApproximatelyEqual(start_transform, delegate.GetTransformForAnimation());
353
354 start_time += delta;
355 element->set_requested_start_time(start_time);
356 element->Start(&delegate, 1);
357 element->Progress(start_time, &delegate);
358 effective_start_time = start_time + delta;
359 element->set_effective_start_time(effective_start_time);
360 element->Progress(effective_start_time, &delegate);
361 element->Progress(effective_start_time + delta/2, &delegate);
362
363 // Since the element has started, it should update the delegate when
364 // aborted.
365 element->Abort(&delegate);
366 target_transform.Blend(start_transform,
367 Tween::CalculateValue(tween_type, 0.5));
368 CheckApproximatelyEqual(target_transform,
369 delegate.GetTransformForAnimation());
370 }
371
323 } // namespace 372 } // namespace
324 373
325 } // namespace ui 374 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_element.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698