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_animator.h" | 5 #include "ui/compositor/layer_animator.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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_delegate.h" | 14 #include "ui/compositor/layer_animation_delegate.h" |
15 #include "ui/compositor/layer_animation_element.h" | 15 #include "ui/compositor/layer_animation_element.h" |
16 #include "ui/compositor/layer_animation_sequence.h" | 16 #include "ui/compositor/layer_animation_sequence.h" |
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
19 #include "ui/compositor/test/layer_animator_test_controller.h" | 19 #include "ui/compositor/test/layer_animator_test_controller.h" |
20 #include "ui/compositor/test/test_layer_animation_delegate.h" | 20 #include "ui/compositor/test/test_layer_animation_delegate.h" |
21 #include "ui/compositor/test/test_layer_animation_observer.h" | 21 #include "ui/compositor/test/test_layer_animation_observer.h" |
22 #include "ui/compositor/test/test_utils.h" | 22 #include "ui/compositor/test/test_utils.h" |
23 #include "ui/gfx/frame_time.h" | 23 #include "ui/gfx/frame_time.h" |
24 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
26 | 26 |
27 using gfx::AnimationContainerElement; | |
28 | |
29 namespace ui { | 27 namespace ui { |
30 | 28 |
31 namespace { | 29 namespace { |
32 | 30 |
33 // Converts |color| to a string. Each component of the color is separated by a | 31 // Converts |color| to a string. Each component of the color is separated by a |
34 // space and the order if A R G B. | 32 // space and the order if A R G B. |
35 std::string ColorToString(SkColor color) { | 33 std::string ColorToString(SkColor color) { |
36 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), | 34 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), |
37 SkColorGetR(color), SkColorGetG(color), | 35 SkColorGetR(color), SkColorGetG(color), |
38 SkColorGetB(color)); | 36 SkColorGetB(color)); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); | 187 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); |
190 }; | 188 }; |
191 | 189 |
192 } // namespace | 190 } // namespace |
193 | 191 |
194 // Checks that setting a property on an implicit animator causes an animation to | 192 // Checks that setting a property on an implicit animator causes an animation to |
195 // happen. | 193 // happen. |
196 TEST(LayerAnimatorTest, ImplicitAnimation) { | 194 TEST(LayerAnimatorTest, ImplicitAnimation) { |
197 scoped_refptr<LayerAnimator> animator( | 195 scoped_refptr<LayerAnimator> animator( |
198 LayerAnimator::CreateImplicitAnimator()); | 196 LayerAnimator::CreateImplicitAnimator()); |
199 AnimationContainerElement* element = animator.get(); | |
200 animator->set_disable_timer_for_test(true); | 197 animator->set_disable_timer_for_test(true); |
201 TestLayerAnimationDelegate delegate; | 198 TestLayerAnimationDelegate delegate; |
202 animator->SetDelegate(&delegate); | 199 animator->SetDelegate(&delegate); |
203 base::TimeTicks now = gfx::FrameTime::Now(); | 200 base::TimeTicks now = gfx::FrameTime::Now(); |
204 animator->SetBrightness(0.5); | 201 animator->SetBrightness(0.5); |
205 EXPECT_TRUE(animator->is_animating()); | 202 EXPECT_TRUE(animator->is_animating()); |
206 element->Step(now + base::TimeDelta::FromSeconds(1)); | 203 animator->Step(now + base::TimeDelta::FromSeconds(1)); |
207 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); | 204 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); |
208 } | 205 } |
209 | 206 |
210 // Checks that if the animator is a default animator, that implicit animations | 207 // Checks that if the animator is a default animator, that implicit animations |
211 // are not started. | 208 // are not started. |
212 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 209 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
213 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 210 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
214 animator->set_disable_timer_for_test(true); | 211 animator->set_disable_timer_for_test(true); |
215 TestLayerAnimationDelegate delegate; | 212 TestLayerAnimationDelegate delegate; |
216 animator->SetDelegate(&delegate); | 213 animator->SetDelegate(&delegate); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 animator->AbortAllAnimations(); | 275 animator->AbortAllAnimations(); |
279 EXPECT_FALSE(animator->is_animating()); | 276 EXPECT_FALSE(animator->is_animating()); |
280 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); | 277 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); |
281 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); | 278 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); |
282 } | 279 } |
283 | 280 |
284 // Schedule a non-threaded animation that can run immediately. This is the | 281 // Schedule a non-threaded animation that can run immediately. This is the |
285 // trivial case and should result in the animation being started immediately. | 282 // trivial case and should result in the animation being started immediately. |
286 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { | 283 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { |
287 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 284 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
288 AnimationContainerElement* element = animator.get(); | |
289 animator->set_disable_timer_for_test(true); | 285 animator->set_disable_timer_for_test(true); |
290 TestLayerAnimationDelegate delegate; | 286 TestLayerAnimationDelegate delegate; |
291 animator->SetDelegate(&delegate); | 287 animator->SetDelegate(&delegate); |
292 | 288 |
293 double start_brightness(0.0); | 289 double start_brightness(0.0); |
294 double middle_brightness(0.5); | 290 double middle_brightness(0.5); |
295 double target_brightness(1.0); | 291 double target_brightness(1.0); |
296 | 292 |
297 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 293 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
298 | 294 |
299 delegate.SetBrightnessFromAnimation(start_brightness); | 295 delegate.SetBrightnessFromAnimation(start_brightness); |
300 | 296 |
301 animator->ScheduleAnimation( | 297 animator->ScheduleAnimation( |
302 new LayerAnimationSequence( | 298 new LayerAnimationSequence( |
303 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 299 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
304 delta))); | 300 delta))); |
305 | 301 |
306 EXPECT_TRUE(animator->is_animating()); | 302 EXPECT_TRUE(animator->is_animating()); |
307 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 303 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
308 | 304 |
309 base::TimeTicks start_time = animator->last_step_time(); | 305 base::TimeTicks start_time = animator->last_step_time(); |
310 | 306 |
311 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 307 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
312 | 308 |
313 EXPECT_TRUE(animator->is_animating()); | 309 EXPECT_TRUE(animator->is_animating()); |
314 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 310 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
315 | 311 |
316 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 312 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
317 | 313 |
318 EXPECT_FALSE(animator->is_animating()); | 314 EXPECT_FALSE(animator->is_animating()); |
319 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 315 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
320 } | 316 } |
321 | 317 |
322 // Schedule a threaded animation that can run immediately. | 318 // Schedule a threaded animation that can run immediately. |
323 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { | 319 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { |
324 double epsilon = 0.00001; | 320 double epsilon = 0.00001; |
325 LayerAnimatorTestController test_controller( | 321 LayerAnimatorTestController test_controller( |
326 LayerAnimator::CreateDefaultAnimator()); | 322 LayerAnimator::CreateDefaultAnimator()); |
327 AnimationContainerElement* element = test_controller.animator(); | 323 LayerAnimator* animator = test_controller.animator(); |
328 test_controller.animator()->set_disable_timer_for_test(true); | 324 test_controller.animator()->set_disable_timer_for_test(true); |
329 TestLayerAnimationDelegate delegate; | 325 TestLayerAnimationDelegate delegate; |
330 test_controller.animator()->SetDelegate(&delegate); | 326 test_controller.animator()->SetDelegate(&delegate); |
331 | 327 |
332 double start_opacity(0.0); | 328 double start_opacity(0.0); |
333 double target_opacity(1.0); | 329 double target_opacity(1.0); |
334 | 330 |
335 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 331 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
336 | 332 |
337 delegate.SetOpacityFromAnimation(start_opacity); | 333 delegate.SetOpacityFromAnimation(start_opacity); |
338 | 334 |
339 test_controller.animator()->ScheduleAnimation( | 335 test_controller.animator()->ScheduleAnimation( |
340 new LayerAnimationSequence( | 336 new LayerAnimationSequence( |
341 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 337 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
342 | 338 |
343 EXPECT_TRUE(test_controller.animator()->is_animating()); | 339 EXPECT_TRUE(test_controller.animator()->is_animating()); |
344 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 340 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
345 | 341 |
346 base::TimeTicks start_time = test_controller.animator()->last_step_time(); | 342 base::TimeTicks start_time = test_controller.animator()->last_step_time(); |
347 base::TimeTicks effective_start = start_time + delta; | 343 base::TimeTicks effective_start = start_time + delta; |
348 | 344 |
349 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 345 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
350 cc::AnimationEvent::Started, | 346 cc::AnimationEvent::Started, |
351 0, | 347 0, |
352 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 348 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
353 ->animation_group_id(), | 349 ->animation_group_id(), |
354 cc::Animation::Opacity, | 350 cc::Animation::Opacity, |
355 effective_start)); | 351 effective_start)); |
356 | 352 |
357 element->Step(effective_start + delta/2); | 353 animator->Step(effective_start + delta / 2); |
358 | 354 |
359 EXPECT_TRUE(test_controller.animator()->is_animating()); | 355 EXPECT_TRUE(test_controller.animator()->is_animating()); |
360 EXPECT_NEAR( | 356 EXPECT_NEAR( |
361 0.5, | 357 0.5, |
362 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 358 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
363 last_progressed_fraction(), | 359 last_progressed_fraction(), |
364 epsilon); | 360 epsilon); |
365 | 361 |
366 element->Step(effective_start + delta); | 362 animator->Step(effective_start + delta); |
367 | 363 |
368 EXPECT_FALSE(test_controller.animator()->is_animating()); | 364 EXPECT_FALSE(test_controller.animator()->is_animating()); |
369 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 365 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
370 } | 366 } |
371 | 367 |
372 // Schedule two non-threaded animations on separate properties. Both animations | 368 // Schedule two non-threaded animations on separate properties. Both animations |
373 // should start immediately and should progress in lock step. | 369 // should start immediately and should progress in lock step. |
374 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { | 370 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { |
375 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 371 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
376 AnimationContainerElement* element = animator.get(); | |
377 animator->set_disable_timer_for_test(true); | 372 animator->set_disable_timer_for_test(true); |
378 TestLayerAnimationDelegate delegate; | 373 TestLayerAnimationDelegate delegate; |
379 animator->SetDelegate(&delegate); | 374 animator->SetDelegate(&delegate); |
380 | 375 |
381 double start_brightness(0.0); | 376 double start_brightness(0.0); |
382 double middle_brightness(0.5); | 377 double middle_brightness(0.5); |
383 double target_brightness(1.0); | 378 double target_brightness(1.0); |
384 | 379 |
385 gfx::Rect start_bounds, target_bounds, middle_bounds; | 380 gfx::Rect start_bounds, target_bounds, middle_bounds; |
386 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 381 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
(...skipping 13 matching lines...) Expand all Loading... |
400 animator->ScheduleAnimation( | 395 animator->ScheduleAnimation( |
401 new LayerAnimationSequence( | 396 new LayerAnimationSequence( |
402 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); | 397 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
403 | 398 |
404 EXPECT_TRUE(animator->is_animating()); | 399 EXPECT_TRUE(animator->is_animating()); |
405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 400 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
406 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 401 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
407 | 402 |
408 base::TimeTicks start_time = animator->last_step_time(); | 403 base::TimeTicks start_time = animator->last_step_time(); |
409 | 404 |
410 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 405 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
411 | 406 |
412 EXPECT_TRUE(animator->is_animating()); | 407 EXPECT_TRUE(animator->is_animating()); |
413 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 408 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
414 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); | 409 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); |
415 | 410 |
416 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 411 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
417 | 412 |
418 EXPECT_FALSE(animator->is_animating()); | 413 EXPECT_FALSE(animator->is_animating()); |
419 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 414 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
420 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 415 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
421 } | 416 } |
422 | 417 |
423 // Schedule a threaded and a non-threaded animation on separate properties. Both | 418 // Schedule a threaded and a non-threaded animation on separate properties. Both |
424 // animations should progress in lock step. | 419 // animations should progress in lock step. |
425 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { | 420 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { |
426 double epsilon = 0.00001; | 421 double epsilon = 0.00001; |
427 LayerAnimatorTestController test_controller( | 422 LayerAnimatorTestController test_controller( |
428 LayerAnimator::CreateDefaultAnimator()); | 423 LayerAnimator::CreateDefaultAnimator()); |
429 AnimationContainerElement* element = test_controller.animator(); | 424 LayerAnimator* animator = test_controller.animator(); |
430 test_controller.animator()->set_disable_timer_for_test(true); | 425 test_controller.animator()->set_disable_timer_for_test(true); |
431 TestLayerAnimationDelegate delegate; | 426 TestLayerAnimationDelegate delegate; |
432 test_controller.animator()->SetDelegate(&delegate); | 427 test_controller.animator()->SetDelegate(&delegate); |
433 | 428 |
434 double start_opacity(0.0); | 429 double start_opacity(0.0); |
435 double target_opacity(1.0); | 430 double target_opacity(1.0); |
436 | 431 |
437 gfx::Rect start_bounds, target_bounds, middle_bounds; | 432 gfx::Rect start_bounds, target_bounds, middle_bounds; |
438 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 433 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
439 start_bounds.set_x(-90); | 434 start_bounds.set_x(-90); |
(...skipping 23 matching lines...) Expand all Loading... |
463 base::TimeTicks effective_start = start_time + delta; | 458 base::TimeTicks effective_start = start_time + delta; |
464 | 459 |
465 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 460 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
466 cc::AnimationEvent::Started, | 461 cc::AnimationEvent::Started, |
467 0, | 462 0, |
468 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 463 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
469 ->animation_group_id(), | 464 ->animation_group_id(), |
470 cc::Animation::Opacity, | 465 cc::Animation::Opacity, |
471 effective_start)); | 466 effective_start)); |
472 | 467 |
473 element->Step(effective_start + delta/2); | 468 animator->Step(effective_start + delta / 2); |
474 | 469 |
475 EXPECT_TRUE(test_controller.animator()->is_animating()); | 470 EXPECT_TRUE(test_controller.animator()->is_animating()); |
476 EXPECT_NEAR( | 471 EXPECT_NEAR( |
477 0.5, | 472 0.5, |
478 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 473 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
479 last_progressed_fraction(), | 474 last_progressed_fraction(), |
480 epsilon); | 475 epsilon); |
481 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); | 476 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); |
482 | 477 |
483 element->Step(effective_start + delta); | 478 animator->Step(effective_start + delta); |
484 | 479 |
485 EXPECT_FALSE(test_controller.animator()->is_animating()); | 480 EXPECT_FALSE(test_controller.animator()->is_animating()); |
486 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 481 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
487 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 482 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
488 } | 483 } |
489 | 484 |
490 // Schedule two animations on the same property. In this case, the two | 485 // Schedule two animations on the same property. In this case, the two |
491 // animations should run one after another. | 486 // animations should run one after another. |
492 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { | 487 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { |
493 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 488 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
494 AnimationContainerElement* element = animator.get(); | |
495 animator->set_disable_timer_for_test(true); | 489 animator->set_disable_timer_for_test(true); |
496 TestLayerAnimationDelegate delegate; | 490 TestLayerAnimationDelegate delegate; |
497 animator->SetDelegate(&delegate); | 491 animator->SetDelegate(&delegate); |
498 | 492 |
499 double start_brightness(0.0); | 493 double start_brightness(0.0); |
500 double middle_brightness(0.5); | 494 double middle_brightness(0.5); |
501 double target_brightness(1.0); | 495 double target_brightness(1.0); |
502 | 496 |
503 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 497 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
504 | 498 |
505 delegate.SetBrightnessFromAnimation(start_brightness); | 499 delegate.SetBrightnessFromAnimation(start_brightness); |
506 | 500 |
507 animator->ScheduleAnimation( | 501 animator->ScheduleAnimation( |
508 new LayerAnimationSequence( | 502 new LayerAnimationSequence( |
509 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 503 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
510 delta))); | 504 delta))); |
511 | 505 |
512 animator->ScheduleAnimation( | 506 animator->ScheduleAnimation( |
513 new LayerAnimationSequence( | 507 new LayerAnimationSequence( |
514 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 508 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
515 delta))); | 509 delta))); |
516 | 510 |
517 EXPECT_TRUE(animator->is_animating()); | 511 EXPECT_TRUE(animator->is_animating()); |
518 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 512 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
519 | 513 |
520 base::TimeTicks start_time = animator->last_step_time(); | 514 base::TimeTicks start_time = animator->last_step_time(); |
521 | 515 |
522 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 516 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
523 | 517 |
524 EXPECT_TRUE(animator->is_animating()); | 518 EXPECT_TRUE(animator->is_animating()); |
525 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 519 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
526 | 520 |
527 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 521 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
528 | 522 |
529 EXPECT_TRUE(animator->is_animating()); | 523 EXPECT_TRUE(animator->is_animating()); |
530 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 524 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
531 | 525 |
532 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 526 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
533 | 527 |
534 EXPECT_TRUE(animator->is_animating()); | 528 EXPECT_TRUE(animator->is_animating()); |
535 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 529 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
536 | 530 |
537 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 531 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
538 | 532 |
539 EXPECT_FALSE(animator->is_animating()); | 533 EXPECT_FALSE(animator->is_animating()); |
540 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 534 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
541 } | 535 } |
542 | 536 |
543 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That | 537 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That |
544 // is, ensure that all animations targetting a particular property are run in | 538 // is, ensure that all animations targetting a particular property are run in |
545 // order. | 539 // order. |
546 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { | 540 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { |
547 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 541 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
548 AnimationContainerElement* element = animator.get(); | |
549 animator->set_disable_timer_for_test(true); | 542 animator->set_disable_timer_for_test(true); |
550 TestLayerAnimationDelegate delegate; | 543 TestLayerAnimationDelegate delegate; |
551 animator->SetDelegate(&delegate); | 544 animator->SetDelegate(&delegate); |
552 | 545 |
553 double start_grayscale(0.0); | 546 double start_grayscale(0.0); |
554 double middle_grayscale(0.5); | 547 double middle_grayscale(0.5); |
555 double target_grayscale(1.0); | 548 double target_grayscale(1.0); |
556 | 549 |
557 gfx::Rect start_bounds, target_bounds, middle_bounds; | 550 gfx::Rect start_bounds, target_bounds, middle_bounds; |
558 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 551 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
(...skipping 23 matching lines...) Expand all Loading... |
582 animator->ScheduleAnimation( | 575 animator->ScheduleAnimation( |
583 new LayerAnimationSequence( | 576 new LayerAnimationSequence( |
584 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); | 577 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); |
585 | 578 |
586 EXPECT_TRUE(animator->is_animating()); | 579 EXPECT_TRUE(animator->is_animating()); |
587 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 580 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
588 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 581 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
589 | 582 |
590 base::TimeTicks start_time = animator->last_step_time(); | 583 base::TimeTicks start_time = animator->last_step_time(); |
591 | 584 |
592 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 585 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
593 | 586 |
594 EXPECT_TRUE(animator->is_animating()); | 587 EXPECT_TRUE(animator->is_animating()); |
595 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 588 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
596 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 589 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
597 | 590 |
598 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 591 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
599 | 592 |
600 EXPECT_TRUE(animator->is_animating()); | 593 EXPECT_TRUE(animator->is_animating()); |
601 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 594 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
602 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 595 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
603 | 596 |
604 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 597 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
605 | 598 |
606 EXPECT_TRUE(animator->is_animating()); | 599 EXPECT_TRUE(animator->is_animating()); |
607 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 600 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
608 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 601 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
609 | 602 |
610 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); | 603 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); |
611 | 604 |
612 EXPECT_TRUE(animator->is_animating()); | 605 EXPECT_TRUE(animator->is_animating()); |
613 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 606 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
614 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 607 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
615 | 608 |
616 element->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); | 609 animator->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); |
617 | 610 |
618 EXPECT_FALSE(animator->is_animating()); | 611 EXPECT_FALSE(animator->is_animating()); |
619 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 612 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
620 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 613 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
621 } | 614 } |
622 | 615 |
623 // Schedule {g} and then schedule {g} and {b} together. In this case, since | 616 // Schedule {g} and then schedule {g} and {b} together. In this case, since |
624 // ScheduleTogether is being used, the bounds animation should not start until | 617 // ScheduleTogether is being used, the bounds animation should not start until |
625 // the second grayscale animation starts. | 618 // the second grayscale animation starts. |
626 TEST(LayerAnimatorTest, ScheduleTogether) { | 619 TEST(LayerAnimatorTest, ScheduleTogether) { |
627 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 620 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
628 AnimationContainerElement* element = animator.get(); | |
629 animator->set_disable_timer_for_test(true); | 621 animator->set_disable_timer_for_test(true); |
630 TestLayerAnimationDelegate delegate; | 622 TestLayerAnimationDelegate delegate; |
631 animator->SetDelegate(&delegate); | 623 animator->SetDelegate(&delegate); |
632 | 624 |
633 double start_grayscale(0.0); | 625 double start_grayscale(0.0); |
634 double target_grayscale(1.0); | 626 double target_grayscale(1.0); |
635 | 627 |
636 gfx::Rect start_bounds, target_bounds, middle_bounds; | 628 gfx::Rect start_bounds, target_bounds, middle_bounds; |
637 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); | 629 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); |
638 start_bounds.set_x(-90); | 630 start_bounds.set_x(-90); |
(...skipping 16 matching lines...) Expand all Loading... |
655 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); | 647 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
656 | 648 |
657 animator->ScheduleTogether(sequences); | 649 animator->ScheduleTogether(sequences); |
658 | 650 |
659 EXPECT_TRUE(animator->is_animating()); | 651 EXPECT_TRUE(animator->is_animating()); |
660 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 652 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
661 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 653 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
662 | 654 |
663 base::TimeTicks start_time = animator->last_step_time(); | 655 base::TimeTicks start_time = animator->last_step_time(); |
664 | 656 |
665 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 657 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
666 | 658 |
667 EXPECT_TRUE(animator->is_animating()); | 659 EXPECT_TRUE(animator->is_animating()); |
668 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 660 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
669 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 661 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
670 | 662 |
671 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 663 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
672 | 664 |
673 EXPECT_FALSE(animator->is_animating()); | 665 EXPECT_FALSE(animator->is_animating()); |
674 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 666 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
675 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 667 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
676 } | 668 } |
677 | 669 |
678 // Start non-threaded animation (that can run immediately). This is the trivial | 670 // Start non-threaded animation (that can run immediately). This is the trivial |
679 // case (see the trival case for ScheduleAnimation). | 671 // case (see the trival case for ScheduleAnimation). |
680 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { | 672 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { |
681 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 673 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
682 AnimationContainerElement* element = animator.get(); | |
683 animator->set_disable_timer_for_test(true); | 674 animator->set_disable_timer_for_test(true); |
684 TestLayerAnimationDelegate delegate; | 675 TestLayerAnimationDelegate delegate; |
685 animator->SetDelegate(&delegate); | 676 animator->SetDelegate(&delegate); |
686 | 677 |
687 double start_brightness(0.0); | 678 double start_brightness(0.0); |
688 double middle_brightness(0.5); | 679 double middle_brightness(0.5); |
689 double target_brightness(1.0); | 680 double target_brightness(1.0); |
690 | 681 |
691 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 682 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
692 | 683 |
693 delegate.SetBrightnessFromAnimation(start_brightness); | 684 delegate.SetBrightnessFromAnimation(start_brightness); |
694 | 685 |
695 animator->StartAnimation( | 686 animator->StartAnimation( |
696 new LayerAnimationSequence( | 687 new LayerAnimationSequence( |
697 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 688 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
698 delta))); | 689 delta))); |
699 | 690 |
700 EXPECT_TRUE(animator->is_animating()); | 691 EXPECT_TRUE(animator->is_animating()); |
701 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 692 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
702 | 693 |
703 base::TimeTicks start_time = animator->last_step_time(); | 694 base::TimeTicks start_time = animator->last_step_time(); |
704 | 695 |
705 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 696 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
706 | 697 |
707 EXPECT_TRUE(animator->is_animating()); | 698 EXPECT_TRUE(animator->is_animating()); |
708 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 699 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
709 | 700 |
710 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 701 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
711 | 702 |
712 EXPECT_FALSE(animator->is_animating()); | 703 EXPECT_FALSE(animator->is_animating()); |
713 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 704 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
714 } | 705 } |
715 | 706 |
716 // Start threaded animation (that can run immediately). | 707 // Start threaded animation (that can run immediately). |
717 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { | 708 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { |
718 double epsilon = 0.00001; | 709 double epsilon = 0.00001; |
719 LayerAnimatorTestController test_controller( | 710 LayerAnimatorTestController test_controller( |
720 LayerAnimator::CreateDefaultAnimator()); | 711 LayerAnimator::CreateDefaultAnimator()); |
721 AnimationContainerElement* element = test_controller.animator(); | 712 LayerAnimator* animator = test_controller.animator(); |
722 test_controller.animator()->set_disable_timer_for_test(true); | 713 test_controller.animator()->set_disable_timer_for_test(true); |
723 TestLayerAnimationDelegate delegate; | 714 TestLayerAnimationDelegate delegate; |
724 test_controller.animator()->SetDelegate(&delegate); | 715 test_controller.animator()->SetDelegate(&delegate); |
725 | 716 |
726 double start_opacity(0.0); | 717 double start_opacity(0.0); |
727 double target_opacity(1.0); | 718 double target_opacity(1.0); |
728 | 719 |
729 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 720 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
730 | 721 |
731 delegate.SetOpacityFromAnimation(start_opacity); | 722 delegate.SetOpacityFromAnimation(start_opacity); |
732 | 723 |
733 test_controller.animator()->StartAnimation( | 724 test_controller.animator()->StartAnimation( |
734 new LayerAnimationSequence( | 725 new LayerAnimationSequence( |
735 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 726 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
736 | 727 |
737 EXPECT_TRUE(test_controller.animator()->is_animating()); | 728 EXPECT_TRUE(test_controller.animator()->is_animating()); |
738 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 729 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
739 | 730 |
740 base::TimeTicks start_time = test_controller.animator()->last_step_time(); | 731 base::TimeTicks start_time = test_controller.animator()->last_step_time(); |
741 base::TimeTicks effective_start = start_time + delta; | 732 base::TimeTicks effective_start = start_time + delta; |
742 | 733 |
743 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 734 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
744 cc::AnimationEvent::Started, | 735 cc::AnimationEvent::Started, |
745 0, | 736 0, |
746 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 737 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
747 ->animation_group_id(), | 738 ->animation_group_id(), |
748 cc::Animation::Opacity, | 739 cc::Animation::Opacity, |
749 effective_start)); | 740 effective_start)); |
750 | 741 |
751 element->Step(effective_start + delta/2); | 742 animator->Step(effective_start + delta / 2); |
752 | 743 |
753 EXPECT_TRUE(test_controller.animator()->is_animating()); | 744 EXPECT_TRUE(test_controller.animator()->is_animating()); |
754 EXPECT_NEAR( | 745 EXPECT_NEAR( |
755 0.5, | 746 0.5, |
756 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 747 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
757 last_progressed_fraction(), | 748 last_progressed_fraction(), |
758 epsilon); | 749 epsilon); |
759 | 750 |
760 element->Step(effective_start + delta); | 751 animator->Step(effective_start + delta); |
761 EXPECT_FALSE(test_controller.animator()->is_animating()); | 752 EXPECT_FALSE(test_controller.animator()->is_animating()); |
762 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 753 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
763 } | 754 } |
764 | 755 |
765 // Preempt by immediately setting new target. | 756 // Preempt by immediately setting new target. |
766 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { | 757 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { |
767 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 758 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
768 animator->set_disable_timer_for_test(true); | 759 animator->set_disable_timer_for_test(true); |
769 TestLayerAnimationDelegate delegate; | 760 TestLayerAnimationDelegate delegate; |
770 animator->SetDelegate(&delegate); | 761 animator->SetDelegate(&delegate); |
(...skipping 15 matching lines...) Expand all Loading... |
786 new LayerAnimationSequence( | 777 new LayerAnimationSequence( |
787 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 778 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
788 | 779 |
789 EXPECT_FALSE(animator->is_animating()); | 780 EXPECT_FALSE(animator->is_animating()); |
790 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 781 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
791 } | 782 } |
792 | 783 |
793 // Preempt by animating to new target, with a non-threaded animation. | 784 // Preempt by animating to new target, with a non-threaded animation. |
794 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { | 785 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { |
795 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 786 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
796 AnimationContainerElement* element = animator.get(); | |
797 animator->set_disable_timer_for_test(true); | 787 animator->set_disable_timer_for_test(true); |
798 TestLayerAnimationDelegate delegate; | 788 TestLayerAnimationDelegate delegate; |
799 animator->SetDelegate(&delegate); | 789 animator->SetDelegate(&delegate); |
800 | 790 |
801 double start_brightness(0.0); | 791 double start_brightness(0.0); |
802 double middle_brightness(0.5); | 792 double middle_brightness(0.5); |
803 double target_brightness(1.0); | 793 double target_brightness(1.0); |
804 | 794 |
805 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 795 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
806 | 796 |
807 delegate.SetBrightnessFromAnimation(start_brightness); | 797 delegate.SetBrightnessFromAnimation(start_brightness); |
808 | 798 |
809 animator->set_preemption_strategy( | 799 animator->set_preemption_strategy( |
810 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 800 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
811 | 801 |
812 animator->StartAnimation( | 802 animator->StartAnimation( |
813 new LayerAnimationSequence( | 803 new LayerAnimationSequence( |
814 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 804 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
815 delta))); | 805 delta))); |
816 | 806 |
817 base::TimeTicks start_time = animator->last_step_time(); | 807 base::TimeTicks start_time = animator->last_step_time(); |
818 | 808 |
819 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 809 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
820 | 810 |
821 animator->StartAnimation( | 811 animator->StartAnimation( |
822 new LayerAnimationSequence( | 812 new LayerAnimationSequence( |
823 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 813 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
824 delta))); | 814 delta))); |
825 | 815 |
826 EXPECT_TRUE(animator->is_animating()); | 816 EXPECT_TRUE(animator->is_animating()); |
827 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 817 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
828 | 818 |
829 animator->StartAnimation( | 819 animator->StartAnimation( |
830 new LayerAnimationSequence( | 820 new LayerAnimationSequence( |
831 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 821 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
832 delta))); | 822 delta))); |
833 | 823 |
834 EXPECT_TRUE(animator->is_animating()); | 824 EXPECT_TRUE(animator->is_animating()); |
835 | 825 |
836 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 826 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
837 | 827 |
838 EXPECT_TRUE(animator->is_animating()); | 828 EXPECT_TRUE(animator->is_animating()); |
839 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 829 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
840 0.5 * (start_brightness + middle_brightness)); | 830 0.5 * (start_brightness + middle_brightness)); |
841 | 831 |
842 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 832 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
843 | 833 |
844 EXPECT_FALSE(animator->is_animating()); | 834 EXPECT_FALSE(animator->is_animating()); |
845 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 835 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
846 } | 836 } |
847 | 837 |
848 // Preempt by animating to new target, with a threaded animation. | 838 // Preempt by animating to new target, with a threaded animation. |
849 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { | 839 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { |
850 double epsilon = 0.00001; | 840 double epsilon = 0.00001; |
851 LayerAnimatorTestController test_controller( | 841 LayerAnimatorTestController test_controller( |
852 LayerAnimator::CreateDefaultAnimator()); | 842 LayerAnimator::CreateDefaultAnimator()); |
853 AnimationContainerElement* element = test_controller.animator(); | 843 LayerAnimator* animator = test_controller.animator(); |
854 test_controller.animator()->set_disable_timer_for_test(true); | 844 test_controller.animator()->set_disable_timer_for_test(true); |
855 TestLayerAnimationDelegate delegate; | 845 TestLayerAnimationDelegate delegate; |
856 test_controller.animator()->SetDelegate(&delegate); | 846 test_controller.animator()->SetDelegate(&delegate); |
857 | 847 |
858 double start_opacity(0.0); | 848 double start_opacity(0.0); |
859 double middle_opacity(0.5); | 849 double middle_opacity(0.5); |
860 double target_opacity(1.0); | 850 double target_opacity(1.0); |
861 | 851 |
862 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 852 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
863 | 853 |
(...skipping 10 matching lines...) Expand all Loading... |
874 base::TimeTicks effective_start = start_time + delta; | 864 base::TimeTicks effective_start = start_time + delta; |
875 | 865 |
876 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 866 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
877 cc::AnimationEvent::Started, | 867 cc::AnimationEvent::Started, |
878 0, | 868 0, |
879 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 869 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
880 ->animation_group_id(), | 870 ->animation_group_id(), |
881 cc::Animation::Opacity, | 871 cc::Animation::Opacity, |
882 effective_start)); | 872 effective_start)); |
883 | 873 |
884 element->Step(effective_start + delta/2); | 874 animator->Step(effective_start + delta / 2); |
885 | 875 |
886 test_controller.animator()->StartAnimation( | 876 test_controller.animator()->StartAnimation( |
887 new LayerAnimationSequence( | 877 new LayerAnimationSequence( |
888 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 878 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
889 | 879 |
890 EXPECT_TRUE(test_controller.animator()->is_animating()); | 880 EXPECT_TRUE(test_controller.animator()->is_animating()); |
891 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); | 881 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); |
892 | 882 |
893 test_controller.animator()->StartAnimation( | 883 test_controller.animator()->StartAnimation( |
894 new LayerAnimationSequence( | 884 new LayerAnimationSequence( |
895 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 885 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
896 | 886 |
897 EXPECT_TRUE(test_controller.animator()->is_animating()); | 887 EXPECT_TRUE(test_controller.animator()->is_animating()); |
898 | 888 |
899 base::TimeTicks second_effective_start = effective_start + delta; | 889 base::TimeTicks second_effective_start = effective_start + delta; |
900 | 890 |
901 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 891 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
902 cc::AnimationEvent::Started, | 892 cc::AnimationEvent::Started, |
903 0, | 893 0, |
904 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 894 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
905 ->animation_group_id(), | 895 ->animation_group_id(), |
906 cc::Animation::Opacity, | 896 cc::Animation::Opacity, |
907 second_effective_start)); | 897 second_effective_start)); |
908 | 898 |
909 element->Step(second_effective_start + delta/2); | 899 animator->Step(second_effective_start + delta / 2); |
910 | 900 |
911 EXPECT_TRUE(test_controller.animator()->is_animating()); | 901 EXPECT_TRUE(test_controller.animator()->is_animating()); |
912 EXPECT_NEAR( | 902 EXPECT_NEAR( |
913 0.5, | 903 0.5, |
914 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 904 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
915 last_progressed_fraction(), | 905 last_progressed_fraction(), |
916 epsilon); | 906 epsilon); |
917 | 907 |
918 element->Step(second_effective_start + delta); | 908 animator->Step(second_effective_start + delta); |
919 | 909 |
920 EXPECT_FALSE(test_controller.animator()->is_animating()); | 910 EXPECT_FALSE(test_controller.animator()->is_animating()); |
921 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 911 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
922 } | 912 } |
923 | 913 |
924 // Preempt by enqueuing the new animation. | 914 // Preempt by enqueuing the new animation. |
925 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { | 915 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { |
926 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 916 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
927 AnimationContainerElement* element = animator.get(); | |
928 animator->set_disable_timer_for_test(true); | 917 animator->set_disable_timer_for_test(true); |
929 TestLayerAnimationDelegate delegate; | 918 TestLayerAnimationDelegate delegate; |
930 animator->SetDelegate(&delegate); | 919 animator->SetDelegate(&delegate); |
931 | 920 |
932 double start_brightness(0.0); | 921 double start_brightness(0.0); |
933 double middle_brightness(0.5); | 922 double middle_brightness(0.5); |
934 double target_brightness(1.0); | 923 double target_brightness(1.0); |
935 | 924 |
936 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 925 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
937 | 926 |
938 delegate.SetBrightnessFromAnimation(start_brightness); | 927 delegate.SetBrightnessFromAnimation(start_brightness); |
939 | 928 |
940 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 929 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
941 | 930 |
942 animator->StartAnimation( | 931 animator->StartAnimation( |
943 new LayerAnimationSequence( | 932 new LayerAnimationSequence( |
944 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 933 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
945 delta))); | 934 delta))); |
946 | 935 |
947 base::TimeTicks start_time = animator->last_step_time(); | 936 base::TimeTicks start_time = animator->last_step_time(); |
948 | 937 |
949 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 938 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
950 | 939 |
951 animator->StartAnimation( | 940 animator->StartAnimation( |
952 new LayerAnimationSequence( | 941 new LayerAnimationSequence( |
953 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 942 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
954 delta))); | 943 delta))); |
955 | 944 |
956 EXPECT_TRUE(animator->is_animating()); | 945 EXPECT_TRUE(animator->is_animating()); |
957 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 946 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
958 | 947 |
959 EXPECT_TRUE(animator->is_animating()); | 948 EXPECT_TRUE(animator->is_animating()); |
960 | 949 |
961 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 950 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
962 | 951 |
963 EXPECT_TRUE(animator->is_animating()); | 952 EXPECT_TRUE(animator->is_animating()); |
964 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 953 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
965 | 954 |
966 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 955 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
967 | 956 |
968 EXPECT_TRUE(animator->is_animating()); | 957 EXPECT_TRUE(animator->is_animating()); |
969 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 958 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
970 | 959 |
971 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 960 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
972 | 961 |
973 EXPECT_FALSE(animator->is_animating()); | 962 EXPECT_FALSE(animator->is_animating()); |
974 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 963 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
975 } | 964 } |
976 | 965 |
977 // Start an animation when there are sequences waiting in the queue. In this | 966 // Start an animation when there are sequences waiting in the queue. In this |
978 // case, all pending and running animations should be finished, and the new | 967 // case, all pending and running animations should be finished, and the new |
979 // animation started. | 968 // animation started. |
980 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { | 969 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { |
981 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 970 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
982 AnimationContainerElement* element = animator.get(); | |
983 animator->set_disable_timer_for_test(true); | 971 animator->set_disable_timer_for_test(true); |
984 TestLayerAnimationDelegate delegate; | 972 TestLayerAnimationDelegate delegate; |
985 animator->SetDelegate(&delegate); | 973 animator->SetDelegate(&delegate); |
986 | 974 |
987 double start_brightness(0.0); | 975 double start_brightness(0.0); |
988 double middle_brightness(0.5); | 976 double middle_brightness(0.5); |
989 double target_brightness(1.0); | 977 double target_brightness(1.0); |
990 | 978 |
991 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 979 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
992 | 980 |
993 delegate.SetBrightnessFromAnimation(start_brightness); | 981 delegate.SetBrightnessFromAnimation(start_brightness); |
994 | 982 |
995 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 983 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
996 | 984 |
997 animator->StartAnimation( | 985 animator->StartAnimation( |
998 new LayerAnimationSequence( | 986 new LayerAnimationSequence( |
999 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 987 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1000 delta))); | 988 delta))); |
1001 | 989 |
1002 base::TimeTicks start_time = animator->last_step_time(); | 990 base::TimeTicks start_time = animator->last_step_time(); |
1003 | 991 |
1004 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 992 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1005 | 993 |
1006 animator->StartAnimation( | 994 animator->StartAnimation( |
1007 new LayerAnimationSequence( | 995 new LayerAnimationSequence( |
1008 LayerAnimationElement::CreateBrightnessElement(middle_brightness, | 996 LayerAnimationElement::CreateBrightnessElement(middle_brightness, |
1009 delta))); | 997 delta))); |
1010 | 998 |
1011 // Queue should now have two animations. Starting a third should replace the | 999 // Queue should now have two animations. Starting a third should replace the |
1012 // second. | 1000 // second. |
1013 animator->StartAnimation( | 1001 animator->StartAnimation( |
1014 new LayerAnimationSequence( | 1002 new LayerAnimationSequence( |
1015 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1003 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1016 delta))); | 1004 delta))); |
1017 | 1005 |
1018 EXPECT_TRUE(animator->is_animating()); | 1006 EXPECT_TRUE(animator->is_animating()); |
1019 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1007 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1020 | 1008 |
1021 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1009 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1022 | 1010 |
1023 EXPECT_TRUE(animator->is_animating()); | 1011 EXPECT_TRUE(animator->is_animating()); |
1024 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1012 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1025 | 1013 |
1026 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1014 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1027 | 1015 |
1028 EXPECT_TRUE(animator->is_animating()); | 1016 EXPECT_TRUE(animator->is_animating()); |
1029 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1017 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1030 | 1018 |
1031 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1019 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1032 | 1020 |
1033 EXPECT_FALSE(animator->is_animating()); | 1021 EXPECT_FALSE(animator->is_animating()); |
1034 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1022 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1035 } | 1023 } |
1036 | 1024 |
1037 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { | 1025 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { |
1038 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1026 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1039 animator->set_disable_timer_for_test(true); | 1027 animator->set_disable_timer_for_test(true); |
1040 TestLayerAnimationDelegate delegate; | 1028 TestLayerAnimationDelegate delegate; |
1041 animator->SetDelegate(&delegate); | 1029 animator->SetDelegate(&delegate); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 )); | 1094 )); |
1107 | 1095 |
1108 EXPECT_FALSE(animator->is_animating()); | 1096 EXPECT_FALSE(animator->is_animating()); |
1109 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1097 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1110 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1098 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1111 } | 1099 } |
1112 | 1100 |
1113 // Preempt by animating to new target. | 1101 // Preempt by animating to new target. |
1114 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { | 1102 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { |
1115 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1103 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1116 AnimationContainerElement* element = animator.get(); | |
1117 animator->set_disable_timer_for_test(true); | 1104 animator->set_disable_timer_for_test(true); |
1118 TestLayerAnimationDelegate delegate; | 1105 TestLayerAnimationDelegate delegate; |
1119 animator->SetDelegate(&delegate); | 1106 animator->SetDelegate(&delegate); |
1120 | 1107 |
1121 double start_grayscale(0.0); | 1108 double start_grayscale(0.0); |
1122 double middle_grayscale(0.5); | 1109 double middle_grayscale(0.5); |
1123 double target_grayscale(1.0); | 1110 double target_grayscale(1.0); |
1124 | 1111 |
1125 double start_brightness(0.1); | 1112 double start_brightness(0.1); |
1126 double middle_brightness(0.2); | 1113 double middle_brightness(0.2); |
(...skipping 10 matching lines...) Expand all Loading... |
1137 animator->StartTogether( | 1124 animator->StartTogether( |
1138 CreateMultiSequence( | 1125 CreateMultiSequence( |
1139 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1126 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1140 delta), | 1127 delta), |
1141 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1128 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1142 delta) | 1129 delta) |
1143 )); | 1130 )); |
1144 | 1131 |
1145 base::TimeTicks start_time = animator->last_step_time(); | 1132 base::TimeTicks start_time = animator->last_step_time(); |
1146 | 1133 |
1147 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1134 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1148 | 1135 |
1149 animator->StartTogether( | 1136 animator->StartTogether( |
1150 CreateMultiSequence( | 1137 CreateMultiSequence( |
1151 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1138 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1152 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1139 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1153 delta))); | 1140 delta))); |
1154 | 1141 |
1155 EXPECT_TRUE(animator->is_animating()); | 1142 EXPECT_TRUE(animator->is_animating()); |
1156 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1143 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1157 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1144 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1158 | 1145 |
1159 animator->StartTogether( | 1146 animator->StartTogether( |
1160 CreateMultiSequence( | 1147 CreateMultiSequence( |
1161 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1148 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1162 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1149 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1163 delta))); | 1150 delta))); |
1164 | 1151 |
1165 EXPECT_TRUE(animator->is_animating()); | 1152 EXPECT_TRUE(animator->is_animating()); |
1166 | 1153 |
1167 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1154 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1168 | 1155 |
1169 EXPECT_TRUE(animator->is_animating()); | 1156 EXPECT_TRUE(animator->is_animating()); |
1170 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), | 1157 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
1171 0.5 * (start_grayscale + middle_grayscale)); | 1158 0.5 * (start_grayscale + middle_grayscale)); |
1172 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 1159 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
1173 0.5 * (start_brightness + middle_brightness)); | 1160 0.5 * (start_brightness + middle_brightness)); |
1174 | 1161 |
1175 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1162 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1176 | 1163 |
1177 EXPECT_FALSE(animator->is_animating()); | 1164 EXPECT_FALSE(animator->is_animating()); |
1178 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1165 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1179 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1166 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1180 } | 1167 } |
1181 | 1168 |
1182 // Preempt a threaded animation by animating to new target. | 1169 // Preempt a threaded animation by animating to new target. |
1183 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { | 1170 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { |
1184 double epsilon = 0.00001; | 1171 double epsilon = 0.00001; |
1185 LayerAnimatorTestController test_controller( | 1172 LayerAnimatorTestController test_controller( |
1186 LayerAnimator::CreateDefaultAnimator()); | 1173 LayerAnimator::CreateDefaultAnimator()); |
1187 AnimationContainerElement* element = test_controller.animator(); | 1174 LayerAnimator* animator = test_controller.animator(); |
1188 test_controller.animator()->set_disable_timer_for_test(true); | 1175 test_controller.animator()->set_disable_timer_for_test(true); |
1189 TestLayerAnimationDelegate delegate; | 1176 TestLayerAnimationDelegate delegate; |
1190 test_controller.animator()->SetDelegate(&delegate); | 1177 test_controller.animator()->SetDelegate(&delegate); |
1191 | 1178 |
1192 double start_opacity(0.0); | 1179 double start_opacity(0.0); |
1193 double middle_opacity(0.5); | 1180 double middle_opacity(0.5); |
1194 double target_opacity(1.0); | 1181 double target_opacity(1.0); |
1195 | 1182 |
1196 double start_brightness(0.1); | 1183 double start_brightness(0.1); |
1197 double middle_brightness(0.2); | 1184 double middle_brightness(0.2); |
(...skipping 18 matching lines...) Expand all Loading... |
1216 base::TimeTicks effective_start = start_time + delta; | 1203 base::TimeTicks effective_start = start_time + delta; |
1217 | 1204 |
1218 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1205 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1219 cc::AnimationEvent::Started, | 1206 cc::AnimationEvent::Started, |
1220 0, | 1207 0, |
1221 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1208 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1222 ->animation_group_id(), | 1209 ->animation_group_id(), |
1223 cc::Animation::Opacity, | 1210 cc::Animation::Opacity, |
1224 effective_start)); | 1211 effective_start)); |
1225 | 1212 |
1226 element->Step(effective_start + delta/2); | 1213 animator->Step(effective_start + delta / 2); |
1227 | 1214 |
1228 test_controller.animator()->StartTogether( | 1215 test_controller.animator()->StartTogether( |
1229 CreateMultiSequence( | 1216 CreateMultiSequence( |
1230 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), | 1217 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), |
1231 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1218 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1232 delta))); | 1219 delta))); |
1233 | 1220 |
1234 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1221 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1235 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); | 1222 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); |
1236 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon); | 1223 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon); |
1237 | 1224 |
1238 test_controller.animator()->StartTogether( | 1225 test_controller.animator()->StartTogether( |
1239 CreateMultiSequence( | 1226 CreateMultiSequence( |
1240 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), | 1227 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), |
1241 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1228 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1242 delta))); | 1229 delta))); |
1243 | 1230 |
1244 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1231 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1245 | 1232 |
1246 base::TimeTicks second_effective_start = effective_start + delta; | 1233 base::TimeTicks second_effective_start = effective_start + delta; |
1247 | 1234 |
1248 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1235 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1249 cc::AnimationEvent::Started, | 1236 cc::AnimationEvent::Started, |
1250 0, | 1237 0, |
1251 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1238 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1252 ->animation_group_id(), | 1239 ->animation_group_id(), |
1253 cc::Animation::Opacity, | 1240 cc::Animation::Opacity, |
1254 second_effective_start)); | 1241 second_effective_start)); |
1255 | 1242 |
1256 element->Step(second_effective_start + delta/2); | 1243 animator->Step(second_effective_start + delta / 2); |
1257 | 1244 |
1258 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1245 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1259 EXPECT_NEAR( | 1246 EXPECT_NEAR( |
1260 0.5, | 1247 0.5, |
1261 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 1248 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
1262 last_progressed_fraction(), | 1249 last_progressed_fraction(), |
1263 epsilon); | 1250 epsilon); |
1264 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), | 1251 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), |
1265 0.5 * (start_brightness + middle_brightness), | 1252 0.5 * (start_brightness + middle_brightness), |
1266 epsilon); | 1253 epsilon); |
1267 | 1254 |
1268 element->Step(second_effective_start + delta); | 1255 animator->Step(second_effective_start + delta); |
1269 | 1256 |
1270 EXPECT_FALSE(test_controller.animator()->is_animating()); | 1257 EXPECT_FALSE(test_controller.animator()->is_animating()); |
1271 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1258 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1272 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1259 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1273 } | 1260 } |
1274 | 1261 |
1275 // Preempt by enqueuing the new animation. | 1262 // Preempt by enqueuing the new animation. |
1276 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { | 1263 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { |
1277 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1264 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1278 AnimationContainerElement* element = animator.get(); | |
1279 animator->set_disable_timer_for_test(true); | 1265 animator->set_disable_timer_for_test(true); |
1280 TestLayerAnimationDelegate delegate; | 1266 TestLayerAnimationDelegate delegate; |
1281 animator->SetDelegate(&delegate); | 1267 animator->SetDelegate(&delegate); |
1282 | 1268 |
1283 double start_grayscale(0.0); | 1269 double start_grayscale(0.0); |
1284 double middle_grayscale(0.5); | 1270 double middle_grayscale(0.5); |
1285 double target_grayscale(1.0); | 1271 double target_grayscale(1.0); |
1286 | 1272 |
1287 double start_brightness(0.1); | 1273 double start_brightness(0.1); |
1288 double middle_brightness(0.2); | 1274 double middle_brightness(0.2); |
1289 double target_brightness(0.3); | 1275 double target_brightness(0.3); |
1290 | 1276 |
1291 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1277 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1292 | 1278 |
1293 delegate.SetGrayscaleFromAnimation(start_grayscale); | 1279 delegate.SetGrayscaleFromAnimation(start_grayscale); |
1294 delegate.SetBrightnessFromAnimation(start_brightness); | 1280 delegate.SetBrightnessFromAnimation(start_brightness); |
1295 | 1281 |
1296 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1282 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
1297 | 1283 |
1298 animator->StartTogether( | 1284 animator->StartTogether( |
1299 CreateMultiSequence( | 1285 CreateMultiSequence( |
1300 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1286 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1301 delta), | 1287 delta), |
1302 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1288 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1303 delta))); | 1289 delta))); |
1304 | 1290 |
1305 base::TimeTicks start_time = animator->last_step_time(); | 1291 base::TimeTicks start_time = animator->last_step_time(); |
1306 | 1292 |
1307 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1293 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1308 | 1294 |
1309 animator->StartTogether( | 1295 animator->StartTogether( |
1310 CreateMultiSequence( | 1296 CreateMultiSequence( |
1311 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1297 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1312 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1298 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1313 delta))); | 1299 delta))); |
1314 | 1300 |
1315 EXPECT_TRUE(animator->is_animating()); | 1301 EXPECT_TRUE(animator->is_animating()); |
1316 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1302 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1317 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1303 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1318 | 1304 |
1319 EXPECT_TRUE(animator->is_animating()); | 1305 EXPECT_TRUE(animator->is_animating()); |
1320 | 1306 |
1321 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1307 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1322 | 1308 |
1323 EXPECT_TRUE(animator->is_animating()); | 1309 EXPECT_TRUE(animator->is_animating()); |
1324 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 1310 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
1325 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1311 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1326 | 1312 |
1327 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1313 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1328 | 1314 |
1329 EXPECT_TRUE(animator->is_animating()); | 1315 EXPECT_TRUE(animator->is_animating()); |
1330 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1316 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1331 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1317 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1332 | 1318 |
1333 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1319 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1334 | 1320 |
1335 EXPECT_FALSE(animator->is_animating()); | 1321 EXPECT_FALSE(animator->is_animating()); |
1336 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1322 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1337 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1323 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1338 } | 1324 } |
1339 | 1325 |
1340 // Start an animation when there are sequences waiting in the queue. In this | 1326 // Start an animation when there are sequences waiting in the queue. In this |
1341 // case, all pending and running animations should be finished, and the new | 1327 // case, all pending and running animations should be finished, and the new |
1342 // animation started. | 1328 // animation started. |
1343 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { | 1329 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { |
1344 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1330 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1345 AnimationContainerElement* element = animator.get(); | |
1346 animator->set_disable_timer_for_test(true); | 1331 animator->set_disable_timer_for_test(true); |
1347 TestLayerAnimationDelegate delegate; | 1332 TestLayerAnimationDelegate delegate; |
1348 animator->SetDelegate(&delegate); | 1333 animator->SetDelegate(&delegate); |
1349 | 1334 |
1350 double start_grayscale(0.0); | 1335 double start_grayscale(0.0); |
1351 double middle_grayscale(0.5); | 1336 double middle_grayscale(0.5); |
1352 double target_grayscale(1.0); | 1337 double target_grayscale(1.0); |
1353 | 1338 |
1354 double start_brightness(0.1); | 1339 double start_brightness(0.1); |
1355 double middle_brightness(0.2); | 1340 double middle_brightness(0.2); |
1356 double target_brightness(0.3); | 1341 double target_brightness(0.3); |
1357 | 1342 |
1358 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1343 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1359 | 1344 |
1360 delegate.SetGrayscaleFromAnimation(start_grayscale); | 1345 delegate.SetGrayscaleFromAnimation(start_grayscale); |
1361 delegate.SetBrightnessFromAnimation(start_brightness); | 1346 delegate.SetBrightnessFromAnimation(start_brightness); |
1362 | 1347 |
1363 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 1348 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
1364 | 1349 |
1365 animator->StartTogether( | 1350 animator->StartTogether( |
1366 CreateMultiSequence( | 1351 CreateMultiSequence( |
1367 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1352 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1368 delta), | 1353 delta), |
1369 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1354 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1370 delta))); | 1355 delta))); |
1371 | 1356 |
1372 base::TimeTicks start_time = animator->last_step_time(); | 1357 base::TimeTicks start_time = animator->last_step_time(); |
1373 | 1358 |
1374 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1359 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1375 | 1360 |
1376 animator->StartTogether( | 1361 animator->StartTogether( |
1377 CreateMultiSequence( | 1362 CreateMultiSequence( |
1378 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale, | 1363 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale, |
1379 delta), | 1364 delta), |
1380 LayerAnimationElement::CreateBrightnessElement(middle_brightness, | 1365 LayerAnimationElement::CreateBrightnessElement(middle_brightness, |
1381 delta))); | 1366 delta))); |
1382 | 1367 |
1383 // Queue should now have two animations. Starting a third should replace the | 1368 // Queue should now have two animations. Starting a third should replace the |
1384 // second. | 1369 // second. |
1385 animator->StartTogether( | 1370 animator->StartTogether( |
1386 CreateMultiSequence( | 1371 CreateMultiSequence( |
1387 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1372 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1388 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1373 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1389 delta))); | 1374 delta))); |
1390 | 1375 |
1391 EXPECT_TRUE(animator->is_animating()); | 1376 EXPECT_TRUE(animator->is_animating()); |
1392 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1377 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1393 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1378 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1394 | 1379 |
1395 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1380 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1396 | 1381 |
1397 EXPECT_TRUE(animator->is_animating()); | 1382 EXPECT_TRUE(animator->is_animating()); |
1398 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 1383 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
1399 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1384 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1400 | 1385 |
1401 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1386 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1402 | 1387 |
1403 EXPECT_TRUE(animator->is_animating()); | 1388 EXPECT_TRUE(animator->is_animating()); |
1404 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1389 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1390 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1406 | 1391 |
1407 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1392 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1408 | 1393 |
1409 EXPECT_FALSE(animator->is_animating()); | 1394 EXPECT_FALSE(animator->is_animating()); |
1410 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1395 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1411 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1396 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1412 } | 1397 } |
1413 //------------------------------------------------------- | 1398 //------------------------------------------------------- |
1414 // Test that non-threaded cyclic sequences continue to animate. | 1399 // Test that non-threaded cyclic sequences continue to animate. |
1415 TEST(LayerAnimatorTest, CyclicSequences) { | 1400 TEST(LayerAnimatorTest, CyclicSequences) { |
1416 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1401 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1417 AnimationContainerElement* element = animator.get(); | |
1418 animator->set_disable_timer_for_test(true); | 1402 animator->set_disable_timer_for_test(true); |
1419 TestLayerAnimationDelegate delegate; | 1403 TestLayerAnimationDelegate delegate; |
1420 animator->SetDelegate(&delegate); | 1404 animator->SetDelegate(&delegate); |
1421 | 1405 |
1422 double start_brightness(0.0); | 1406 double start_brightness(0.0); |
1423 double target_brightness(1.0); | 1407 double target_brightness(1.0); |
1424 | 1408 |
1425 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1409 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1426 | 1410 |
1427 delegate.SetBrightnessFromAnimation(start_brightness); | 1411 delegate.SetBrightnessFromAnimation(start_brightness); |
1428 | 1412 |
1429 scoped_ptr<LayerAnimationSequence> sequence( | 1413 scoped_ptr<LayerAnimationSequence> sequence( |
1430 new LayerAnimationSequence( | 1414 new LayerAnimationSequence( |
1431 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1415 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1432 delta))); | 1416 delta))); |
1433 | 1417 |
1434 sequence->AddElement( | 1418 sequence->AddElement( |
1435 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); | 1419 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); |
1436 | 1420 |
1437 sequence->set_is_cyclic(true); | 1421 sequence->set_is_cyclic(true); |
1438 | 1422 |
1439 animator->StartAnimation(sequence.release()); | 1423 animator->StartAnimation(sequence.release()); |
1440 | 1424 |
1441 base::TimeTicks start_time = animator->last_step_time(); | 1425 base::TimeTicks start_time = animator->last_step_time(); |
1442 | 1426 |
1443 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1427 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1444 | 1428 |
1445 EXPECT_TRUE(animator->is_animating()); | 1429 EXPECT_TRUE(animator->is_animating()); |
1446 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1430 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1447 | 1431 |
1448 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1432 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1449 | 1433 |
1450 EXPECT_TRUE(animator->is_animating()); | 1434 EXPECT_TRUE(animator->is_animating()); |
1451 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1435 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1452 | 1436 |
1453 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); | 1437 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); |
1454 | 1438 |
1455 EXPECT_TRUE(animator->is_animating()); | 1439 EXPECT_TRUE(animator->is_animating()); |
1456 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1440 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1457 | 1441 |
1458 // Skip ahead by a lot. | 1442 // Skip ahead by a lot. |
1459 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); | 1443 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); |
1460 | 1444 |
1461 EXPECT_TRUE(animator->is_animating()); | 1445 EXPECT_TRUE(animator->is_animating()); |
1462 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1446 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1463 | 1447 |
1464 // Skip ahead by a lot. | 1448 // Skip ahead by a lot. |
1465 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); | 1449 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); |
1466 | 1450 |
1467 EXPECT_TRUE(animator->is_animating()); | 1451 EXPECT_TRUE(animator->is_animating()); |
1468 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1452 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1469 | 1453 |
1470 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); | 1454 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); |
1471 | 1455 |
1472 EXPECT_FALSE(animator->is_animating()); | 1456 EXPECT_FALSE(animator->is_animating()); |
1473 } | 1457 } |
1474 | 1458 |
1475 // Test that threaded cyclic sequences continue to animate. | 1459 // Test that threaded cyclic sequences continue to animate. |
1476 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { | 1460 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { |
1477 LayerAnimatorTestController test_controller( | 1461 LayerAnimatorTestController test_controller( |
1478 LayerAnimator::CreateDefaultAnimator()); | 1462 LayerAnimator::CreateDefaultAnimator()); |
1479 AnimationContainerElement* element = test_controller.animator(); | 1463 LayerAnimator* animator = test_controller.animator(); |
1480 test_controller.animator()->set_disable_timer_for_test(true); | 1464 test_controller.animator()->set_disable_timer_for_test(true); |
1481 TestLayerAnimationDelegate delegate; | 1465 TestLayerAnimationDelegate delegate; |
1482 test_controller.animator()->SetDelegate(&delegate); | 1466 test_controller.animator()->SetDelegate(&delegate); |
1483 | 1467 |
1484 double start_opacity(0.0); | 1468 double start_opacity(0.0); |
1485 double target_opacity(1.0); | 1469 double target_opacity(1.0); |
1486 | 1470 |
1487 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1471 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1488 | 1472 |
1489 delegate.SetOpacityFromAnimation(start_opacity); | 1473 delegate.SetOpacityFromAnimation(start_opacity); |
(...skipping 13 matching lines...) Expand all Loading... |
1503 base::TimeTicks effective_start = start_time + delta; | 1487 base::TimeTicks effective_start = start_time + delta; |
1504 | 1488 |
1505 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1489 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1506 cc::AnimationEvent::Started, | 1490 cc::AnimationEvent::Started, |
1507 0, | 1491 0, |
1508 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1492 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1509 ->animation_group_id(), | 1493 ->animation_group_id(), |
1510 cc::Animation::Opacity, | 1494 cc::Animation::Opacity, |
1511 effective_start)); | 1495 effective_start)); |
1512 | 1496 |
1513 element->Step(effective_start + delta); | 1497 animator->Step(effective_start + delta); |
1514 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1498 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1515 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1499 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1516 | 1500 |
1517 base::TimeTicks second_effective_start = effective_start + 2 * delta; | 1501 base::TimeTicks second_effective_start = effective_start + 2 * delta; |
1518 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1502 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1519 cc::AnimationEvent::Started, | 1503 cc::AnimationEvent::Started, |
1520 0, | 1504 0, |
1521 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1505 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1522 ->animation_group_id(), | 1506 ->animation_group_id(), |
1523 cc::Animation::Opacity, | 1507 cc::Animation::Opacity, |
1524 second_effective_start)); | 1508 second_effective_start)); |
1525 | 1509 |
1526 element->Step(second_effective_start + delta); | 1510 animator->Step(second_effective_start + delta); |
1527 | 1511 |
1528 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1512 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1529 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1513 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1530 | 1514 |
1531 base::TimeTicks third_effective_start = second_effective_start + 2 * delta; | 1515 base::TimeTicks third_effective_start = second_effective_start + 2 * delta; |
1532 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1516 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1533 cc::AnimationEvent::Started, | 1517 cc::AnimationEvent::Started, |
1534 0, | 1518 0, |
1535 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1519 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1536 ->animation_group_id(), | 1520 ->animation_group_id(), |
1537 cc::Animation::Opacity, | 1521 cc::Animation::Opacity, |
1538 third_effective_start)); | 1522 third_effective_start)); |
1539 | 1523 |
1540 element->Step(third_effective_start + delta); | 1524 animator->Step(third_effective_start + delta); |
1541 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1525 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1542 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1526 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1543 | 1527 |
1544 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta; | 1528 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta; |
1545 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1529 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1546 cc::AnimationEvent::Started, | 1530 cc::AnimationEvent::Started, |
1547 0, | 1531 0, |
1548 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1532 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1549 ->animation_group_id(), | 1533 ->animation_group_id(), |
1550 cc::Animation::Opacity, | 1534 cc::Animation::Opacity, |
1551 fourth_effective_start)); | 1535 fourth_effective_start)); |
1552 | 1536 |
1553 // Skip ahead by a lot. | 1537 // Skip ahead by a lot. |
1554 element->Step(fourth_effective_start + 1000 * delta); | 1538 animator->Step(fourth_effective_start + 1000 * delta); |
1555 | 1539 |
1556 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1540 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1557 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1541 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1558 | 1542 |
1559 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta; | 1543 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta; |
1560 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1544 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1561 cc::AnimationEvent::Started, | 1545 cc::AnimationEvent::Started, |
1562 0, | 1546 0, |
1563 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1547 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1564 ->animation_group_id(), | 1548 ->animation_group_id(), |
1565 cc::Animation::Opacity, | 1549 cc::Animation::Opacity, |
1566 fifth_effective_start)); | 1550 fifth_effective_start)); |
1567 | 1551 |
1568 // Skip ahead by a lot. | 1552 // Skip ahead by a lot. |
1569 element->Step(fifth_effective_start + 999 * delta); | 1553 animator->Step(fifth_effective_start + 999 * delta); |
1570 | 1554 |
1571 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1555 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1572 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1556 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1573 | 1557 |
1574 test_controller.animator()->StopAnimatingProperty( | 1558 test_controller.animator()->StopAnimatingProperty( |
1575 LayerAnimationElement::OPACITY); | 1559 LayerAnimationElement::OPACITY); |
1576 | 1560 |
1577 EXPECT_FALSE(test_controller.animator()->is_animating()); | 1561 EXPECT_FALSE(test_controller.animator()->is_animating()); |
1578 } | 1562 } |
1579 | 1563 |
1580 TEST(LayerAnimatorTest, AddObserverExplicit) { | 1564 TEST(LayerAnimatorTest, AddObserverExplicit) { |
1581 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1565 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1582 AnimationContainerElement* element = animator.get(); | |
1583 animator->set_disable_timer_for_test(true); | 1566 animator->set_disable_timer_for_test(true); |
1584 TestLayerAnimationObserver observer; | 1567 TestLayerAnimationObserver observer; |
1585 TestLayerAnimationDelegate delegate; | 1568 TestLayerAnimationDelegate delegate; |
1586 animator->SetDelegate(&delegate); | 1569 animator->SetDelegate(&delegate); |
1587 animator->AddObserver(&observer); | 1570 animator->AddObserver(&observer); |
1588 observer.set_requires_notification_when_animator_destroyed(true); | 1571 observer.set_requires_notification_when_animator_destroyed(true); |
1589 | 1572 |
1590 EXPECT_TRUE(!observer.last_ended_sequence()); | 1573 EXPECT_TRUE(!observer.last_ended_sequence()); |
1591 | 1574 |
1592 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1575 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1593 | 1576 |
1594 delegate.SetBrightnessFromAnimation(0.0f); | 1577 delegate.SetBrightnessFromAnimation(0.0f); |
1595 | 1578 |
1596 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1579 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1597 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1580 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1598 | 1581 |
1599 animator->StartAnimation(sequence); | 1582 animator->StartAnimation(sequence); |
1600 | 1583 |
1601 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); | 1584 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
1602 | 1585 |
1603 base::TimeTicks start_time = animator->last_step_time(); | 1586 base::TimeTicks start_time = animator->last_step_time(); |
1604 | 1587 |
1605 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1588 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1606 | 1589 |
1607 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 1590 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
1608 | 1591 |
1609 // |sequence| has been destroyed. Recreate it to test abort. | 1592 // |sequence| has been destroyed. Recreate it to test abort. |
1610 sequence = new LayerAnimationSequence( | 1593 sequence = new LayerAnimationSequence( |
1611 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1594 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1612 | 1595 |
1613 animator->StartAnimation(sequence); | 1596 animator->StartAnimation(sequence); |
1614 | 1597 |
1615 animator = NULL; | 1598 animator = NULL; |
1616 | 1599 |
1617 EXPECT_EQ(observer.last_aborted_sequence(), sequence); | 1600 EXPECT_EQ(observer.last_aborted_sequence(), sequence); |
1618 } | 1601 } |
1619 | 1602 |
1620 // Tests that an observer added to a scoped settings object is still notified | 1603 // Tests that an observer added to a scoped settings object is still notified |
1621 // when the object goes out of scope. | 1604 // when the object goes out of scope. |
1622 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { | 1605 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { |
1623 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1606 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1624 AnimationContainerElement* element = animator.get(); | |
1625 animator->set_disable_timer_for_test(true); | 1607 animator->set_disable_timer_for_test(true); |
1626 TestImplicitAnimationObserver observer(false); | 1608 TestImplicitAnimationObserver observer(false); |
1627 TestLayerAnimationDelegate delegate; | 1609 TestLayerAnimationDelegate delegate; |
1628 animator->SetDelegate(&delegate); | 1610 animator->SetDelegate(&delegate); |
1629 | 1611 |
1630 EXPECT_FALSE(observer.animations_completed()); | 1612 EXPECT_FALSE(observer.animations_completed()); |
1631 animator->SetBrightness(1.0f); | 1613 animator->SetBrightness(1.0f); |
1632 | 1614 |
1633 { | 1615 { |
1634 ScopedLayerAnimationSettings settings(animator.get()); | 1616 ScopedLayerAnimationSettings settings(animator.get()); |
1635 settings.AddObserver(&observer); | 1617 settings.AddObserver(&observer); |
1636 animator->SetBrightness(0.0f); | 1618 animator->SetBrightness(0.0f); |
1637 } | 1619 } |
1638 | 1620 |
1639 EXPECT_FALSE(observer.animations_completed()); | 1621 EXPECT_FALSE(observer.animations_completed()); |
1640 base::TimeTicks start_time = animator->last_step_time(); | 1622 base::TimeTicks start_time = animator->last_step_time(); |
1641 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1623 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1642 EXPECT_TRUE(observer.animations_completed()); | 1624 EXPECT_TRUE(observer.animations_completed()); |
1643 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( | 1625 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( |
1644 LayerAnimationElement::BRIGHTNESS)); | 1626 LayerAnimationElement::BRIGHTNESS)); |
1645 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); | 1627 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); |
1646 } | 1628 } |
1647 | 1629 |
1648 // Tests that an observer added to a scoped settings object is still notified | 1630 // Tests that an observer added to a scoped settings object is still notified |
1649 // when the object goes out of scope due to the animation being interrupted. | 1631 // when the object goes out of scope due to the animation being interrupted. |
1650 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { | 1632 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { |
1651 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1633 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
(...skipping 21 matching lines...) Expand all Loading... |
1673 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); | 1655 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); |
1674 } | 1656 } |
1675 | 1657 |
1676 // Tests that LayerAnimator is not deleted after the animation completes as long | 1658 // Tests that LayerAnimator is not deleted after the animation completes as long |
1677 // as there is a live ScopedLayerAnimationSettings object wrapped around it. | 1659 // as there is a live ScopedLayerAnimationSettings object wrapped around it. |
1678 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { | 1660 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { |
1679 // Note we are using a raw pointer unlike in other tests. | 1661 // Note we are using a raw pointer unlike in other tests. |
1680 TestLayerAnimator* animator = new TestLayerAnimator(); | 1662 TestLayerAnimator* animator = new TestLayerAnimator(); |
1681 LayerAnimatorDestructionObserver destruction_observer; | 1663 LayerAnimatorDestructionObserver destruction_observer; |
1682 animator->SetDestructionObserver(&destruction_observer); | 1664 animator->SetDestructionObserver(&destruction_observer); |
1683 AnimationContainerElement* element = animator; | |
1684 animator->set_disable_timer_for_test(true); | 1665 animator->set_disable_timer_for_test(true); |
1685 TestLayerAnimationDelegate delegate; | 1666 TestLayerAnimationDelegate delegate; |
1686 animator->SetDelegate(&delegate); | 1667 animator->SetDelegate(&delegate); |
1687 { | 1668 { |
1688 // ScopedLayerAnimationSettings should keep the Animator alive as long as | 1669 // ScopedLayerAnimationSettings should keep the Animator alive as long as |
1689 // it is alive, even beyond the end of the animation. | 1670 // it is alive, even beyond the end of the animation. |
1690 ScopedLayerAnimationSettings settings(animator); | 1671 ScopedLayerAnimationSettings settings(animator); |
1691 base::TimeTicks now = gfx::FrameTime::Now(); | 1672 base::TimeTicks now = gfx::FrameTime::Now(); |
1692 animator->SetBrightness(0.5); | 1673 animator->SetBrightness(0.5); |
1693 element->Step(now + base::TimeDelta::FromSeconds(1)); | 1674 animator->Step(now + base::TimeDelta::FromSeconds(1)); |
1694 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); | 1675 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); |
1695 } | 1676 } |
1696 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. | 1677 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. |
1697 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); | 1678 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); |
1698 } | 1679 } |
1699 | 1680 |
1700 // Tests that an observer added to a scoped settings object is not notified | 1681 // Tests that an observer added to a scoped settings object is not notified |
1701 // when the animator is destroyed unless explicitly requested. | 1682 // when the animator is destroyed unless explicitly requested. |
1702 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { | 1683 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { |
1703 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1684 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 animator->AbortAllAnimations(); | 1744 animator->AbortAllAnimations(); |
1764 EXPECT_TRUE(observer.animations_completed()); | 1745 EXPECT_TRUE(observer.animations_completed()); |
1765 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( | 1746 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( |
1766 LayerAnimationElement::BRIGHTNESS)); | 1747 LayerAnimationElement::BRIGHTNESS)); |
1767 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( | 1748 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( |
1768 LayerAnimationElement::OPACITY)); | 1749 LayerAnimationElement::OPACITY)); |
1769 } | 1750 } |
1770 | 1751 |
1771 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { | 1752 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { |
1772 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1753 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1773 AnimationContainerElement* element = animator.get(); | |
1774 animator->set_disable_timer_for_test(true); | 1754 animator->set_disable_timer_for_test(true); |
1775 TestLayerAnimationObserver observer; | 1755 TestLayerAnimationObserver observer; |
1776 TestLayerAnimationObserver removed_observer; | 1756 TestLayerAnimationObserver removed_observer; |
1777 TestLayerAnimationDelegate delegate; | 1757 TestLayerAnimationDelegate delegate; |
1778 animator->SetDelegate(&delegate); | 1758 animator->SetDelegate(&delegate); |
1779 | 1759 |
1780 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1760 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1781 | 1761 |
1782 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1762 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1783 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1763 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1784 | 1764 |
1785 sequence->AddObserver(&observer); | 1765 sequence->AddObserver(&observer); |
1786 sequence->AddObserver(&removed_observer); | 1766 sequence->AddObserver(&removed_observer); |
1787 | 1767 |
1788 animator->StartAnimation(sequence); | 1768 animator->StartAnimation(sequence); |
1789 | 1769 |
1790 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); | 1770 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
1791 EXPECT_TRUE(!observer.last_ended_sequence()); | 1771 EXPECT_TRUE(!observer.last_ended_sequence()); |
1792 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); | 1772 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); |
1793 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 1773 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
1794 | 1774 |
1795 // This should stop the observer from observing sequence. | 1775 // This should stop the observer from observing sequence. |
1796 animator->RemoveObserver(&removed_observer); | 1776 animator->RemoveObserver(&removed_observer); |
1797 | 1777 |
1798 base::TimeTicks start_time = animator->last_step_time(); | 1778 base::TimeTicks start_time = animator->last_step_time(); |
1799 | 1779 |
1800 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1780 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1801 | 1781 |
1802 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 1782 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
1803 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 1783 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
1804 } | 1784 } |
1805 | 1785 |
1806 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { | 1786 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { |
1807 TestLayerAnimationDelegate delegate; | 1787 TestLayerAnimationDelegate delegate; |
1808 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1788 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1809 animator->set_disable_timer_for_test(true); | 1789 animator->set_disable_timer_for_test(true); |
1810 | 1790 |
(...skipping 15 matching lines...) Expand all Loading... |
1826 | 1806 |
1827 // Now, release |observer| | 1807 // Now, release |observer| |
1828 observer.reset(); | 1808 observer.reset(); |
1829 | 1809 |
1830 // And |sequence| should no longer be attached to |observer|. | 1810 // And |sequence| should no longer be attached to |observer|. |
1831 EXPECT_FALSE(sequence->observers_.might_have_observers()); | 1811 EXPECT_FALSE(sequence->observers_.might_have_observers()); |
1832 } | 1812 } |
1833 | 1813 |
1834 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { | 1814 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { |
1835 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1815 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1836 AnimationContainerElement* element = animator.get(); | |
1837 animator->set_disable_timer_for_test(true); | 1816 animator->set_disable_timer_for_test(true); |
1838 | 1817 |
1839 TestImplicitAnimationObserver observer(false); | 1818 TestImplicitAnimationObserver observer(false); |
1840 TestLayerAnimationDelegate delegate; | 1819 TestLayerAnimationDelegate delegate; |
1841 animator->SetDelegate(&delegate); | 1820 animator->SetDelegate(&delegate); |
1842 | 1821 |
1843 delegate.SetBrightnessFromAnimation(0.0f); | 1822 delegate.SetBrightnessFromAnimation(0.0f); |
1844 | 1823 |
1845 { | 1824 { |
1846 ScopedLayerAnimationSettings setter(animator.get()); | 1825 ScopedLayerAnimationSettings setter(animator.get()); |
1847 | 1826 |
1848 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1827 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1849 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1828 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1850 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1829 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1851 | 1830 |
1852 animator->StartAnimation(sequence); | 1831 animator->StartAnimation(sequence); |
1853 base::TimeTicks start_time = animator->last_step_time(); | 1832 base::TimeTicks start_time = animator->last_step_time(); |
1854 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1833 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1855 | 1834 |
1856 setter.AddObserver(&observer); | 1835 setter.AddObserver(&observer); |
1857 | 1836 |
1858 // Start observing an in-flight animation. | 1837 // Start observing an in-flight animation. |
1859 sequence->AddObserver(&observer); | 1838 sequence->AddObserver(&observer); |
1860 | 1839 |
1861 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1840 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1862 } | 1841 } |
1863 | 1842 |
1864 EXPECT_TRUE(observer.animations_completed()); | 1843 EXPECT_TRUE(observer.animations_completed()); |
1865 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( | 1844 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( |
1866 LayerAnimationElement::BRIGHTNESS)); | 1845 LayerAnimationElement::BRIGHTNESS)); |
1867 } | 1846 } |
1868 | 1847 |
1869 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { | 1848 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { |
1870 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1849 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1871 AnimationContainerElement* element = animator.get(); | |
1872 animator->set_disable_timer_for_test(true); | 1850 animator->set_disable_timer_for_test(true); |
1873 | 1851 |
1874 TestImplicitAnimationObserver observer(false); | 1852 TestImplicitAnimationObserver observer(false); |
1875 TestLayerAnimationDelegate delegate; | 1853 TestLayerAnimationDelegate delegate; |
1876 animator->SetDelegate(&delegate); | 1854 animator->SetDelegate(&delegate); |
1877 | 1855 |
1878 delegate.SetBrightnessFromAnimation(0.0f); | 1856 delegate.SetBrightnessFromAnimation(0.0f); |
1879 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1857 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1880 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1858 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1881 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1859 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1882 | 1860 |
1883 { | 1861 { |
1884 ScopedLayerAnimationSettings setter(animator.get()); | 1862 ScopedLayerAnimationSettings setter(animator.get()); |
1885 setter.AddObserver(&observer); | 1863 setter.AddObserver(&observer); |
1886 | 1864 |
1887 animator->StartAnimation(sequence); | 1865 animator->StartAnimation(sequence); |
1888 base::TimeTicks start_time = animator->last_step_time(); | 1866 base::TimeTicks start_time = animator->last_step_time(); |
1889 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1867 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1890 } | 1868 } |
1891 | 1869 |
1892 EXPECT_FALSE(observer.animations_completed()); | 1870 EXPECT_FALSE(observer.animations_completed()); |
1893 | 1871 |
1894 // Stop observing an in-flight animation. | 1872 // Stop observing an in-flight animation. |
1895 sequence->RemoveObserver(&observer); | 1873 sequence->RemoveObserver(&observer); |
1896 | 1874 |
1897 EXPECT_TRUE(observer.animations_completed()); | 1875 EXPECT_TRUE(observer.animations_completed()); |
1898 | 1876 |
1899 // The animation didn't complete, and neither was it aborted. | 1877 // The animation didn't complete, and neither was it aborted. |
1900 EXPECT_FALSE(observer.WasAnimationCompletedForProperty( | 1878 EXPECT_FALSE(observer.WasAnimationCompletedForProperty( |
1901 LayerAnimationElement::BRIGHTNESS)); | 1879 LayerAnimationElement::BRIGHTNESS)); |
1902 EXPECT_FALSE(observer.WasAnimationAbortedForProperty( | 1880 EXPECT_FALSE(observer.WasAnimationAbortedForProperty( |
1903 LayerAnimationElement::BRIGHTNESS)); | 1881 LayerAnimationElement::BRIGHTNESS)); |
1904 } | 1882 } |
1905 | 1883 |
1906 // This checks that if an animation is deleted due to a callback, that the | 1884 // This checks that if an animation is deleted due to a callback, that the |
1907 // animator does not try to use the deleted animation. For example, if we have | 1885 // animator does not try to use the deleted animation. For example, if we have |
1908 // two running animations, and the first finishes and the resulting callback | 1886 // two running animations, and the first finishes and the resulting callback |
1909 // causes the second to be deleted, we should not attempt to animate the second | 1887 // causes the second to be deleted, we should not attempt to animate the second |
1910 // animation. | 1888 // animation. |
1911 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { | 1889 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { |
1912 ScopedAnimationDurationScaleMode normal_duration_mode( | 1890 ScopedAnimationDurationScaleMode normal_duration_mode( |
1913 ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 1891 ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
1914 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); | 1892 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); |
1915 AnimationContainerElement* element = animator.get(); | |
1916 animator->set_disable_timer_for_test(true); | 1893 animator->set_disable_timer_for_test(true); |
1917 TestLayerAnimationDelegate delegate; | 1894 TestLayerAnimationDelegate delegate; |
1918 animator->SetDelegate(&delegate); | 1895 animator->SetDelegate(&delegate); |
1919 | 1896 |
1920 double start_brightness(0.0); | 1897 double start_brightness(0.0); |
1921 double target_brightness(1.0); | 1898 double target_brightness(1.0); |
1922 | 1899 |
1923 gfx::Rect start_bounds(0, 0, 50, 50); | 1900 gfx::Rect start_bounds(0, 0, 50, 50); |
1924 gfx::Rect target_bounds(5, 5, 5, 5); | 1901 gfx::Rect target_bounds(5, 5, 5, 5); |
1925 | 1902 |
(...skipping 13 matching lines...) Expand all Loading... |
1939 new LayerAnimationSequence( | 1916 new LayerAnimationSequence( |
1940 LayerAnimationElement::CreateBrightnessElement( | 1917 LayerAnimationElement::CreateBrightnessElement( |
1941 target_brightness, brightness_delta))); | 1918 target_brightness, brightness_delta))); |
1942 | 1919 |
1943 animator->StartAnimation(new LayerAnimationSequence( | 1920 animator->StartAnimation(new LayerAnimationSequence( |
1944 LayerAnimationElement::CreateBoundsElement( | 1921 LayerAnimationElement::CreateBoundsElement( |
1945 target_bounds, bounds_delta))); | 1922 target_bounds, bounds_delta))); |
1946 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1923 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
1947 | 1924 |
1948 base::TimeTicks start_time = animator->last_step_time(); | 1925 base::TimeTicks start_time = animator->last_step_time(); |
1949 element->Step(start_time + halfway_delta); | 1926 animator->Step(start_time + halfway_delta); |
1950 | 1927 |
1951 // Completing the brightness animation should have stopped the bounds | 1928 // Completing the brightness animation should have stopped the bounds |
1952 // animation. | 1929 // animation. |
1953 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1930 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
1954 | 1931 |
1955 animator->RemoveObserver(observer.get()); | 1932 animator->RemoveObserver(observer.get()); |
1956 } | 1933 } |
1957 | 1934 |
1958 // Ensure that stopping animation in a bounds change does not crash and that | 1935 // Ensure that stopping animation in a bounds change does not crash and that |
1959 // animation gets stopped correctly. | 1936 // animation gets stopped correctly. |
(...skipping 15 matching lines...) Expand all Loading... |
1975 } | 1952 } |
1976 private: | 1953 private: |
1977 LayerAnimator* animator_; | 1954 LayerAnimator* animator_; |
1978 int max_width_; | 1955 int max_width_; |
1979 // Allow copy and assign. | 1956 // Allow copy and assign. |
1980 }; | 1957 }; |
1981 | 1958 |
1982 ScopedAnimationDurationScaleMode normal_duration_mode( | 1959 ScopedAnimationDurationScaleMode normal_duration_mode( |
1983 ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 1960 ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
1984 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); | 1961 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); |
1985 AnimationContainerElement* element = animator.get(); | |
1986 animator->set_disable_timer_for_test(true); | 1962 animator->set_disable_timer_for_test(true); |
1987 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); | 1963 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); |
1988 animator->SetDelegate(&delegate); | 1964 animator->SetDelegate(&delegate); |
1989 | 1965 |
1990 gfx::Rect start_bounds(0, 0, 0, 0); | 1966 gfx::Rect start_bounds(0, 0, 0, 0); |
1991 gfx::Rect target_bounds(5, 5, 50, 50); | 1967 gfx::Rect target_bounds(5, 5, 50, 50); |
1992 | 1968 |
1993 delegate.SetBoundsFromAnimation(start_bounds); | 1969 delegate.SetBoundsFromAnimation(start_bounds); |
1994 | 1970 |
1995 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333); | 1971 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333); |
1996 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666); | 1972 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666); |
1997 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000); | 1973 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000); |
1998 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500); | 1974 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500); |
1999 | 1975 |
2000 animator->StartAnimation(new LayerAnimationSequence( | 1976 animator->StartAnimation(new LayerAnimationSequence( |
2001 LayerAnimationElement::CreateBoundsElement( | 1977 LayerAnimationElement::CreateBoundsElement( |
2002 target_bounds, bounds_delta))); | 1978 target_bounds, bounds_delta))); |
2003 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1979 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2004 | 1980 |
2005 base::TimeTicks start_time = animator->last_step_time(); | 1981 base::TimeTicks start_time = animator->last_step_time(); |
2006 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta1)); | 1982 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta1)); |
2007 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1983 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2008 | 1984 |
2009 // The next step should change the animated bounds past the threshold and | 1985 // The next step should change the animated bounds past the threshold and |
2010 // cause the animaton to stop. | 1986 // cause the animaton to stop. |
2011 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta2)); | 1987 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta2)); |
2012 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1988 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2013 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + final_delta)); | 1989 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + final_delta)); |
2014 | 1990 |
2015 // Completing the animation should have stopped the bounds | 1991 // Completing the animation should have stopped the bounds |
2016 // animation. | 1992 // animation. |
2017 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1993 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2018 } | 1994 } |
2019 | 1995 |
2020 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it | 1996 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it |
2021 // tests the behavior when the OnLayerAnimationAborted() callback causes | 1997 // tests the behavior when the OnLayerAnimationAborted() callback causes |
2022 // all of the animator's other animations to be deleted. | 1998 // all of the animator's other animations to be deleted. |
2023 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) { | 1999 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 | 2169 |
2194 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. | 2170 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. |
2195 animator->SetGrayscale(1.0); | 2171 animator->SetGrayscale(1.0); |
2196 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); | 2172 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); |
2197 } | 2173 } |
2198 } | 2174 } |
2199 | 2175 |
2200 // Verifies color property is modified appropriately. | 2176 // Verifies color property is modified appropriately. |
2201 TEST(LayerAnimatorTest, Color) { | 2177 TEST(LayerAnimatorTest, Color) { |
2202 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 2178 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
2203 AnimationContainerElement* element = animator.get(); | |
2204 animator->set_disable_timer_for_test(true); | 2179 animator->set_disable_timer_for_test(true); |
2205 TestLayerAnimationDelegate delegate; | 2180 TestLayerAnimationDelegate delegate; |
2206 animator->SetDelegate(&delegate); | 2181 animator->SetDelegate(&delegate); |
2207 | 2182 |
2208 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); | 2183 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); |
2209 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); | 2184 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); |
2210 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); | 2185 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); |
2211 | 2186 |
2212 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2187 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2213 | 2188 |
2214 delegate.SetColorFromAnimation(start_color); | 2189 delegate.SetColorFromAnimation(start_color); |
2215 | 2190 |
2216 animator->ScheduleAnimation( | 2191 animator->ScheduleAnimation( |
2217 new LayerAnimationSequence( | 2192 new LayerAnimationSequence( |
2218 LayerAnimationElement::CreateColorElement(target_color, delta))); | 2193 LayerAnimationElement::CreateColorElement(target_color, delta))); |
2219 | 2194 |
2220 EXPECT_TRUE(animator->is_animating()); | 2195 EXPECT_TRUE(animator->is_animating()); |
2221 EXPECT_EQ(ColorToString(start_color), | 2196 EXPECT_EQ(ColorToString(start_color), |
2222 ColorToString(delegate.GetColorForAnimation())); | 2197 ColorToString(delegate.GetColorForAnimation())); |
2223 | 2198 |
2224 base::TimeTicks start_time = animator->last_step_time(); | 2199 base::TimeTicks start_time = animator->last_step_time(); |
2225 | 2200 |
2226 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 2201 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
2227 | 2202 |
2228 EXPECT_TRUE(animator->is_animating()); | 2203 EXPECT_TRUE(animator->is_animating()); |
2229 EXPECT_EQ(ColorToString(middle_color), | 2204 EXPECT_EQ(ColorToString(middle_color), |
2230 ColorToString(delegate.GetColorForAnimation())); | 2205 ColorToString(delegate.GetColorForAnimation())); |
2231 | 2206 |
2232 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2207 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
2233 | 2208 |
2234 EXPECT_FALSE(animator->is_animating()); | 2209 EXPECT_FALSE(animator->is_animating()); |
2235 EXPECT_EQ(ColorToString(target_color), | 2210 EXPECT_EQ(ColorToString(target_color), |
2236 ColorToString(delegate.GetColorForAnimation())); | 2211 ColorToString(delegate.GetColorForAnimation())); |
2237 } | 2212 } |
2238 | 2213 |
2239 // Verifies SchedulePauseForProperties(). | 2214 // Verifies SchedulePauseForProperties(). |
2240 TEST(LayerAnimatorTest, SchedulePauseForProperties) { | 2215 TEST(LayerAnimatorTest, SchedulePauseForProperties) { |
2241 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 2216 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
2242 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 2217 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 | 2305 |
2331 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); | 2306 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); |
2332 }; | 2307 }; |
2333 | 2308 |
2334 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { | 2309 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { |
2335 bool observer_was_deleted = false; | 2310 bool observer_was_deleted = false; |
2336 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); | 2311 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
2337 observer->set_delete_on_animation_ended(true); | 2312 observer->set_delete_on_animation_ended(true); |
2338 observer->set_delete_on_animation_aborted(true); | 2313 observer->set_delete_on_animation_aborted(true); |
2339 LayerAnimator* animator = observer->animator(); | 2314 LayerAnimator* animator = observer->animator(); |
2340 AnimationContainerElement* element = observer->animator(); | |
2341 animator->set_disable_timer_for_test(true); | 2315 animator->set_disable_timer_for_test(true); |
2342 TestLayerAnimationDelegate delegate; | 2316 TestLayerAnimationDelegate delegate; |
2343 animator->SetDelegate(&delegate); | 2317 animator->SetDelegate(&delegate); |
2344 | 2318 |
2345 delegate.SetBrightnessFromAnimation(0.0f); | 2319 delegate.SetBrightnessFromAnimation(0.0f); |
2346 | 2320 |
2347 gfx::Rect start_bounds(0, 0, 50, 50); | 2321 gfx::Rect start_bounds(0, 0, 50, 50); |
2348 gfx::Rect target_bounds(10, 10, 100, 100); | 2322 gfx::Rect target_bounds(10, 10, 100, 100); |
2349 | 2323 |
2350 delegate.SetBoundsFromAnimation(start_bounds); | 2324 delegate.SetBoundsFromAnimation(start_bounds); |
2351 | 2325 |
2352 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2326 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2353 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence( | 2327 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence( |
2354 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 2328 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
2355 animator->StartAnimation(brightness_sequence); | 2329 animator->StartAnimation(brightness_sequence); |
2356 | 2330 |
2357 delta = base::TimeDelta::FromSeconds(2); | 2331 delta = base::TimeDelta::FromSeconds(2); |
2358 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( | 2332 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( |
2359 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); | 2333 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); |
2360 animator->StartAnimation(bounds_sequence); | 2334 animator->StartAnimation(bounds_sequence); |
2361 | 2335 |
2362 base::TimeTicks start_time = animator->last_step_time(); | 2336 base::TimeTicks start_time = animator->last_step_time(); |
2363 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 2337 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
2364 | 2338 |
2365 EXPECT_TRUE(observer_was_deleted); | 2339 EXPECT_TRUE(observer_was_deleted); |
2366 } | 2340 } |
2367 | 2341 |
2368 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { | 2342 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { |
2369 bool observer_was_deleted = false; | 2343 bool observer_was_deleted = false; |
2370 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); | 2344 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
2371 observer->set_delete_on_animation_ended(true); | 2345 observer->set_delete_on_animation_ended(true); |
2372 observer->set_delete_on_animation_aborted(true); | 2346 observer->set_delete_on_animation_aborted(true); |
2373 LayerAnimator* animator = observer->animator(); | 2347 LayerAnimator* animator = observer->animator(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2519 | 2493 |
2520 parent.SetTransform(parent_end); | 2494 parent.SetTransform(parent_end); |
2521 | 2495 |
2522 EXPECT_TRUE(child.GetAnimator()->is_animating()); | 2496 EXPECT_TRUE(child.GetAnimator()->is_animating()); |
2523 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) | 2497 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) |
2524 << child.GetTargetTransform().ToString(); | 2498 << child.GetTargetTransform().ToString(); |
2525 | 2499 |
2526 } | 2500 } |
2527 | 2501 |
2528 } // namespace ui | 2502 } // namespace ui |
OLD | NEW |