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

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

Issue 11896017: Thread ui opacity animations (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use cc layer's opacity instead of ui::Layer::opacity_ Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/layer_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/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Checks that setting a property on an implicit animator causes an animation to 143 // Checks that setting a property on an implicit animator causes an animation to
144 // happen. 144 // happen.
145 TEST(LayerAnimatorTest, ImplicitAnimation) { 145 TEST(LayerAnimatorTest, ImplicitAnimation) {
146 scoped_refptr<LayerAnimator> animator( 146 scoped_refptr<LayerAnimator> animator(
147 LayerAnimator::CreateImplicitAnimator()); 147 LayerAnimator::CreateImplicitAnimator());
148 AnimationContainerElement* element = animator.get(); 148 AnimationContainerElement* element = animator.get();
149 animator->set_disable_timer_for_test(true); 149 animator->set_disable_timer_for_test(true);
150 TestLayerAnimationDelegate delegate; 150 TestLayerAnimationDelegate delegate;
151 animator->SetDelegate(&delegate); 151 animator->SetDelegate(&delegate);
152 base::TimeTicks now = base::TimeTicks::Now(); 152 base::TimeTicks now = base::TimeTicks::Now();
153 animator->SetOpacity(0.5); 153 animator->SetBrightness(0.5);
154 EXPECT_TRUE(animator->is_animating()); 154 EXPECT_TRUE(animator->is_animating());
155 element->Step(now + base::TimeDelta::FromSeconds(1)); 155 element->Step(now + base::TimeDelta::FromSeconds(1));
156 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); 156 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
157 } 157 }
158 158
159 // Checks that if the animator is a default animator, that implicit animations 159 // Checks that if the animator is a default animator, that implicit animations
160 // are not started. 160 // are not started.
161 TEST(LayerAnimatorTest, NoImplicitAnimation) { 161 TEST(LayerAnimatorTest, NoImplicitAnimation) {
162 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 162 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
163 animator->set_disable_timer_for_test(true); 163 animator->set_disable_timer_for_test(true);
164 TestLayerAnimationDelegate delegate; 164 TestLayerAnimationDelegate delegate;
165 animator->SetDelegate(&delegate); 165 animator->SetDelegate(&delegate);
166 animator->SetOpacity(0.5); 166 animator->SetBrightness(0.5);
167 EXPECT_FALSE(animator->is_animating()); 167 EXPECT_FALSE(animator->is_animating());
168 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); 168 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5);
169 } 169 }
170 170
171 // Checks that StopAnimatingProperty stops animation for that property, and also 171 // Checks that StopAnimatingProperty stops animation for that property, and also
172 // skips the stopped animation to the end. 172 // skips the stopped animation to the end.
173 TEST(LayerAnimatorTest, StopAnimatingProperty) { 173 TEST(LayerAnimatorTest, StopAnimatingProperty) {
174 scoped_refptr<LayerAnimator> animator( 174 scoped_refptr<LayerAnimator> animator(
175 LayerAnimator::CreateImplicitAnimator()); 175 LayerAnimator::CreateImplicitAnimator());
176 animator->set_disable_timer_for_test(true); 176 animator->set_disable_timer_for_test(true);
177 TestLayerAnimationDelegate delegate; 177 TestLayerAnimationDelegate delegate;
178 animator->SetDelegate(&delegate); 178 animator->SetDelegate(&delegate);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 gfx::Rect target_bounds(0, 0, 50, 50); 223 gfx::Rect target_bounds(0, 0, 50, 50);
224 animator->SetOpacity(target_opacity); 224 animator->SetOpacity(target_opacity);
225 animator->SetBounds(target_bounds); 225 animator->SetBounds(target_bounds);
226 EXPECT_TRUE(animator->is_animating()); 226 EXPECT_TRUE(animator->is_animating());
227 animator->AbortAllAnimations(); 227 animator->AbortAllAnimations();
228 EXPECT_FALSE(animator->is_animating()); 228 EXPECT_FALSE(animator->is_animating());
229 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); 229 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation());
230 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); 230 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation());
231 } 231 }
232 232
233 // Schedule an animation that can run immediately. This is the trivial case and 233 // Schedule a non-threaded animation that can run immediately. This is the
234 // should result in the animation being started immediately. 234 // trivial case and should result in the animation being started immediately.
235 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { 235 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
236 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 236 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
237 AnimationContainerElement* element = animator.get(); 237 AnimationContainerElement* element = animator.get();
238 animator->set_disable_timer_for_test(true); 238 animator->set_disable_timer_for_test(true);
239 TestLayerAnimationDelegate delegate; 239 TestLayerAnimationDelegate delegate;
240 animator->SetDelegate(&delegate); 240 animator->SetDelegate(&delegate);
241 241
242 double start_brightness(0.0);
243 double middle_brightness(0.5);
244 double target_brightness(1.0);
245
246 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
247
248 delegate.SetBrightnessFromAnimation(start_brightness);
249
250 animator->ScheduleAnimation(
251 new LayerAnimationSequence(
252 LayerAnimationElement::CreateBrightnessElement(target_brightness,
253 delta)));
254
255 EXPECT_TRUE(animator->is_animating());
256 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
257
258 base::TimeTicks start_time = animator->last_step_time();
259
260 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
261
262 EXPECT_TRUE(animator->is_animating());
263 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
264
265 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
266
267 EXPECT_FALSE(animator->is_animating());
268 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
269 }
270
271 // Schedule a threaded animation that can run immediately.
272 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) {
273 LayerAnimator::TestController test_controller(
274 LayerAnimator::CreateDefaultAnimator());
275 AnimationContainerElement* element = test_controller.animator();
276 test_controller.animator()->set_disable_timer_for_test(true);
277 TestLayerAnimationDelegate delegate;
278 test_controller.animator()->SetDelegate(&delegate);
279
242 double start_opacity(0.0); 280 double start_opacity(0.0);
243 double middle_opacity(0.5);
244 double target_opacity(1.0); 281 double target_opacity(1.0);
245 282
246 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 283 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
247 284
248 delegate.SetOpacityFromAnimation(start_opacity); 285 delegate.SetOpacityFromAnimation(start_opacity);
249 286
250 animator->ScheduleAnimation( 287 test_controller.animator()->ScheduleAnimation(
251 new LayerAnimationSequence( 288 new LayerAnimationSequence(
252 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 289 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
253 290
254 EXPECT_TRUE(animator->is_animating()); 291 EXPECT_TRUE(test_controller.animator()->is_animating());
255 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 292 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
256 293
257 base::TimeTicks start_time = animator->last_step_time(); 294 base::TimeTicks start_time = test_controller.animator()->last_step_time();
295 base::TimeTicks effective_start = start_time + delta;
258 296
259 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 297 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
298 cc::AnimationEvent::Started,
299 0,
300 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
301 animation_group_id(),
302 cc::Animation::Opacity,
303 (effective_start - base::TimeTicks()).InSecondsF()));
260 304
261 EXPECT_TRUE(animator->is_animating()); 305 element->Step(effective_start + delta/2);
262 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
263 306
264 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 307 EXPECT_TRUE(test_controller.animator()->is_animating());
308 EXPECT_FLOAT_EQ(
309 0.5,
310 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
311 last_progressed_fraction());
265 312
266 EXPECT_FALSE(animator->is_animating()); 313 element->Step(effective_start + delta);
314
315 EXPECT_FALSE(test_controller.animator()->is_animating());
267 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 316 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
268 } 317 }
269 318
270 // Schedule two animations on separate properties. Both animations should 319 // Schedule two non-threaded animations on separate properties. Both animations
271 // start immediately and should progress in lock step. 320 // should start immediately and should progress in lock step.
272 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { 321 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
273 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 322 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
274 AnimationContainerElement* element = animator.get(); 323 AnimationContainerElement* element = animator.get();
275 animator->set_disable_timer_for_test(true); 324 animator->set_disable_timer_for_test(true);
276 TestLayerAnimationDelegate delegate; 325 TestLayerAnimationDelegate delegate;
277 animator->SetDelegate(&delegate); 326 animator->SetDelegate(&delegate);
278 327
279 double start_opacity(0.0); 328 double start_brightness(0.0);
280 double middle_opacity(0.5); 329 double middle_brightness(0.5);
281 double target_opacity(1.0); 330 double target_brightness(1.0);
282 331
283 gfx::Rect start_bounds, target_bounds, middle_bounds; 332 gfx::Rect start_bounds, target_bounds, middle_bounds;
284 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 333 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
285 start_bounds.set_x(-90); 334 start_bounds.set_x(-90);
286 target_bounds.set_x(90); 335 target_bounds.set_x(90);
287 336
288 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 337 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
289 338
290 delegate.SetOpacityFromAnimation(start_opacity); 339 delegate.SetBrightnessFromAnimation(start_brightness);
291 delegate.SetBoundsFromAnimation(start_bounds); 340 delegate.SetBoundsFromAnimation(start_bounds);
292 341
293 animator->ScheduleAnimation( 342 animator->ScheduleAnimation(
294 new LayerAnimationSequence( 343 new LayerAnimationSequence(
295 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 344 LayerAnimationElement::CreateBrightnessElement(target_brightness,
345 delta)));
296 346
297 animator->ScheduleAnimation( 347 animator->ScheduleAnimation(
298 new LayerAnimationSequence( 348 new LayerAnimationSequence(
299 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 349 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
300 350
301 EXPECT_TRUE(animator->is_animating()); 351 EXPECT_TRUE(animator->is_animating());
302 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 352 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
303 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 353 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
304 354
305 base::TimeTicks start_time = animator->last_step_time(); 355 base::TimeTicks start_time = animator->last_step_time();
306 356
307 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 357 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
308 358
309 EXPECT_TRUE(animator->is_animating()); 359 EXPECT_TRUE(animator->is_animating());
310 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 360 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
311 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); 361 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
312 362
313 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 363 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
314 364
315 EXPECT_FALSE(animator->is_animating()); 365 EXPECT_FALSE(animator->is_animating());
366 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
367 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
368 }
369
370 // Schedule a threaded and a non-threaded animation on separate properties. Both
371 // animations should progress in lock step.
372 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) {
373 LayerAnimator::TestController test_controller(
374 LayerAnimator::CreateDefaultAnimator());
375 AnimationContainerElement* element = test_controller.animator();
376 test_controller.animator()->set_disable_timer_for_test(true);
377 TestLayerAnimationDelegate delegate;
378 test_controller.animator()->SetDelegate(&delegate);
379
380 double start_opacity(0.0);
381 double target_opacity(1.0);
382
383 gfx::Rect start_bounds, target_bounds, middle_bounds;
384 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
385 start_bounds.set_x(-90);
386 target_bounds.set_x(90);
387
388 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
389
390 delegate.SetOpacityFromAnimation(start_opacity);
391 delegate.SetBoundsFromAnimation(start_bounds);
392
393 std::vector<LayerAnimationSequence*> animations;
394 animations.push_back(
395 new LayerAnimationSequence(
396 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
397
398 animations.push_back(
399 new LayerAnimationSequence(
400 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
401
402 test_controller.animator()->ScheduleTogether(animations);
403
404 EXPECT_TRUE(test_controller.animator()->is_animating());
405 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
406 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
407
408 base::TimeTicks start_time = test_controller.animator()->last_step_time();
409 base::TimeTicks effective_start = start_time + delta;
410
411 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
412 cc::AnimationEvent::Started,
413 0,
414 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
415 animation_group_id(),
416 cc::Animation::Opacity,
417 (effective_start - base::TimeTicks()).InSecondsF()));
418
419 element->Step(effective_start + delta/2);
420
421 EXPECT_TRUE(test_controller.animator()->is_animating());
422 EXPECT_FLOAT_EQ(
423 0.5,
424 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
425 last_progressed_fraction());
426 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds);
427
428 element->Step(effective_start + delta);
429
430 EXPECT_FALSE(test_controller.animator()->is_animating());
316 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 431 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
317 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 432 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
318 } 433 }
319 434
320 // Schedule two animations on the same property. In this case, the two 435 // Schedule two animations on the same property. In this case, the two
321 // animations should run one after another. 436 // animations should run one after another.
322 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { 437 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
323 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 438 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
324 AnimationContainerElement* element = animator.get(); 439 AnimationContainerElement* element = animator.get();
325 animator->set_disable_timer_for_test(true); 440 animator->set_disable_timer_for_test(true);
326 TestLayerAnimationDelegate delegate; 441 TestLayerAnimationDelegate delegate;
327 animator->SetDelegate(&delegate); 442 animator->SetDelegate(&delegate);
328 443
329 double start_opacity(0.0); 444 double start_brightness(0.0);
330 double middle_opacity(0.5); 445 double middle_brightness(0.5);
331 double target_opacity(1.0); 446 double target_brightness(1.0);
332 447
333 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 448 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
334 449
335 delegate.SetOpacityFromAnimation(start_opacity); 450 delegate.SetBrightnessFromAnimation(start_brightness);
336 451
337 animator->ScheduleAnimation( 452 animator->ScheduleAnimation(
338 new LayerAnimationSequence( 453 new LayerAnimationSequence(
339 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 454 LayerAnimationElement::CreateBrightnessElement(target_brightness,
455 delta)));
340 456
341 animator->ScheduleAnimation( 457 animator->ScheduleAnimation(
342 new LayerAnimationSequence( 458 new LayerAnimationSequence(
343 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 459 LayerAnimationElement::CreateBrightnessElement(start_brightness,
460 delta)));
344 461
345 EXPECT_TRUE(animator->is_animating()); 462 EXPECT_TRUE(animator->is_animating());
346 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 463 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
347 464
348 base::TimeTicks start_time = animator->last_step_time(); 465 base::TimeTicks start_time = animator->last_step_time();
349 466
350 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 467 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
351 468
352 EXPECT_TRUE(animator->is_animating()); 469 EXPECT_TRUE(animator->is_animating());
353 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 470 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
354 471
355 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 472 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
356 473
357 EXPECT_TRUE(animator->is_animating()); 474 EXPECT_TRUE(animator->is_animating());
358 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 475 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
359 476
360 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 477 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
361 478
362 EXPECT_TRUE(animator->is_animating()); 479 EXPECT_TRUE(animator->is_animating());
363 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 480 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
364 481
365 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 482 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
366 483
367 EXPECT_FALSE(animator->is_animating()); 484 EXPECT_FALSE(animator->is_animating());
368 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 485 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
369 } 486 }
370 487
371 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That 488 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That
372 // is, ensure that all animations targetting a particular property are run in 489 // is, ensure that all animations targetting a particular property are run in
373 // order. 490 // order.
374 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { 491 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
375 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 492 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
376 AnimationContainerElement* element = animator.get(); 493 AnimationContainerElement* element = animator.get();
377 animator->set_disable_timer_for_test(true); 494 animator->set_disable_timer_for_test(true);
378 TestLayerAnimationDelegate delegate; 495 TestLayerAnimationDelegate delegate;
379 animator->SetDelegate(&delegate); 496 animator->SetDelegate(&delegate);
380 497
381 double start_opacity(0.0); 498 double start_grayscale(0.0);
382 double middle_opacity(0.5); 499 double middle_grayscale(0.5);
383 double target_opacity(1.0); 500 double target_grayscale(1.0);
384 501
385 gfx::Rect start_bounds, target_bounds, middle_bounds; 502 gfx::Rect start_bounds, target_bounds, middle_bounds;
386 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); 503 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50);
387 start_bounds.set_x(-90); 504 start_bounds.set_x(-90);
388 target_bounds.set_x(90); 505 target_bounds.set_x(90);
389 506
390 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 507 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
391 508
392 delegate.SetOpacityFromAnimation(start_opacity); 509 delegate.SetGrayscaleFromAnimation(start_grayscale);
393 delegate.SetBoundsFromAnimation(start_bounds); 510 delegate.SetBoundsFromAnimation(start_bounds);
394 511
395 animator->ScheduleAnimation( 512 animator->ScheduleAnimation(
396 new LayerAnimationSequence( 513 new LayerAnimationSequence(
397 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 514 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
515 delta)));
398 516
399 scoped_ptr<LayerAnimationSequence> bounds_and_opacity( 517 scoped_ptr<LayerAnimationSequence> bounds_and_grayscale(
400 new LayerAnimationSequence( 518 new LayerAnimationSequence(
401 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 519 LayerAnimationElement::CreateGrayscaleElement(start_grayscale,
520 delta)));
402 521
403 bounds_and_opacity->AddElement( 522 bounds_and_grayscale->AddElement(
404 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); 523 LayerAnimationElement::CreateBoundsElement(target_bounds, delta));
405 524
406 animator->ScheduleAnimation(bounds_and_opacity.release()); 525 animator->ScheduleAnimation(bounds_and_grayscale.release());
407 526
408 animator->ScheduleAnimation( 527 animator->ScheduleAnimation(
409 new LayerAnimationSequence( 528 new LayerAnimationSequence(
410 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); 529 LayerAnimationElement::CreateBoundsElement(start_bounds, delta)));
411 530
412 EXPECT_TRUE(animator->is_animating()); 531 EXPECT_TRUE(animator->is_animating());
413 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 532 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
414 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 533 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
415 534
416 base::TimeTicks start_time = animator->last_step_time(); 535 base::TimeTicks start_time = animator->last_step_time();
417 536
418 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 537 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
419 538
420 EXPECT_TRUE(animator->is_animating()); 539 EXPECT_TRUE(animator->is_animating());
421 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 540 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
422 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 541 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
423 542
424 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 543 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
425 544
426 EXPECT_TRUE(animator->is_animating()); 545 EXPECT_TRUE(animator->is_animating());
427 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 546 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
428 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 547 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
429 548
430 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 549 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
431 550
432 EXPECT_TRUE(animator->is_animating()); 551 EXPECT_TRUE(animator->is_animating());
433 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 552 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
434 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 553 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
435 554
436 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); 555 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
437 556
438 EXPECT_TRUE(animator->is_animating()); 557 EXPECT_TRUE(animator->is_animating());
439 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 558 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
440 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 559 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
441 560
442 element->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); 561 element->Step(start_time + base::TimeDelta::FromMilliseconds(4000));
443 562
444 EXPECT_FALSE(animator->is_animating()); 563 EXPECT_FALSE(animator->is_animating());
445 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 564 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
446 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 565 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
447 } 566 }
448 567
449 // Schedule {o} and then schedule {o} and {b} together. In this case, since 568 // Schedule {g} and then schedule {g} and {b} together. In this case, since
450 // ScheduleTogether is being used, the bounds animation should not start until 569 // ScheduleTogether is being used, the bounds animation should not start until
451 // the second opacity animation starts. 570 // the second grayscale animation starts.
452 TEST(LayerAnimatorTest, ScheduleTogether) { 571 TEST(LayerAnimatorTest, ScheduleTogether) {
453 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 572 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
454 AnimationContainerElement* element = animator.get(); 573 AnimationContainerElement* element = animator.get();
455 animator->set_disable_timer_for_test(true); 574 animator->set_disable_timer_for_test(true);
456 TestLayerAnimationDelegate delegate; 575 TestLayerAnimationDelegate delegate;
457 animator->SetDelegate(&delegate); 576 animator->SetDelegate(&delegate);
458 577
459 double start_opacity(0.0); 578 double start_grayscale(0.0);
460 double target_opacity(1.0); 579 double target_grayscale(1.0);
461 580
462 gfx::Rect start_bounds, target_bounds, middle_bounds; 581 gfx::Rect start_bounds, target_bounds, middle_bounds;
463 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); 582 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50);
464 start_bounds.set_x(-90); 583 start_bounds.set_x(-90);
465 target_bounds.set_x(90); 584 target_bounds.set_x(90);
466 585
467 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 586 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
468 587
469 delegate.SetOpacityFromAnimation(start_opacity); 588 delegate.SetGrayscaleFromAnimation(start_grayscale);
470 delegate.SetBoundsFromAnimation(start_bounds); 589 delegate.SetBoundsFromAnimation(start_bounds);
471 590
472 animator->ScheduleAnimation( 591 animator->ScheduleAnimation(
473 new LayerAnimationSequence( 592 new LayerAnimationSequence(
474 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 593 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
594 delta)));
475 595
476 std::vector<LayerAnimationSequence*> sequences; 596 std::vector<LayerAnimationSequence*> sequences;
477 sequences.push_back(new LayerAnimationSequence( 597 sequences.push_back(new LayerAnimationSequence(
478 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 598 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta)));
479 sequences.push_back(new LayerAnimationSequence( 599 sequences.push_back(new LayerAnimationSequence(
480 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); 600 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)));
481 601
482 animator->ScheduleTogether(sequences); 602 animator->ScheduleTogether(sequences);
483 603
484 EXPECT_TRUE(animator->is_animating()); 604 EXPECT_TRUE(animator->is_animating());
485 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 605 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
486 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 606 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
487 607
488 base::TimeTicks start_time = animator->last_step_time(); 608 base::TimeTicks start_time = animator->last_step_time();
489 609
490 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 610 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
491 611
492 EXPECT_TRUE(animator->is_animating()); 612 EXPECT_TRUE(animator->is_animating());
493 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 613 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
494 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); 614 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds);
495 615
496 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 616 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
497 617
498 EXPECT_FALSE(animator->is_animating()); 618 EXPECT_FALSE(animator->is_animating());
499 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 619 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
500 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); 620 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds);
501 } 621 }
502 622
503 // Start animation (that can run immediately). This is the trivial case (see 623 // Start non-threaded animation (that can run immediately). This is the trivial
504 // the trival case for ScheduleAnimation). 624 // case (see the trival case for ScheduleAnimation).
505 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { 625 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
506 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 626 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
507 AnimationContainerElement* element = animator.get(); 627 AnimationContainerElement* element = animator.get();
508 animator->set_disable_timer_for_test(true); 628 animator->set_disable_timer_for_test(true);
509 TestLayerAnimationDelegate delegate; 629 TestLayerAnimationDelegate delegate;
510 animator->SetDelegate(&delegate); 630 animator->SetDelegate(&delegate);
511 631
632 double start_brightness(0.0);
633 double middle_brightness(0.5);
634 double target_brightness(1.0);
635
636 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
637
638 delegate.SetBrightnessFromAnimation(start_brightness);
639
640 animator->StartAnimation(
641 new LayerAnimationSequence(
642 LayerAnimationElement::CreateBrightnessElement(target_brightness,
643 delta)));
644
645 EXPECT_TRUE(animator->is_animating());
646 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
647
648 base::TimeTicks start_time = animator->last_step_time();
649
650 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
651
652 EXPECT_TRUE(animator->is_animating());
653 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
654
655 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
656
657 EXPECT_FALSE(animator->is_animating());
658 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
659 }
660
661 // Start threaded animation (that can run immediately).
662 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) {
663 LayerAnimator::TestController test_controller(
664 LayerAnimator::CreateDefaultAnimator());
665 AnimationContainerElement* element = test_controller.animator();
666 test_controller.animator()->set_disable_timer_for_test(true);
667 TestLayerAnimationDelegate delegate;
668 test_controller.animator()->SetDelegate(&delegate);
669
512 double start_opacity(0.0); 670 double start_opacity(0.0);
513 double middle_opacity(0.5);
514 double target_opacity(1.0); 671 double target_opacity(1.0);
515 672
516 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 673 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
517 674
518 delegate.SetOpacityFromAnimation(start_opacity); 675 delegate.SetOpacityFromAnimation(start_opacity);
519 676
520 animator->StartAnimation( 677 test_controller.animator()->StartAnimation(
521 new LayerAnimationSequence( 678 new LayerAnimationSequence(
522 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 679 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
523 680
524 EXPECT_TRUE(animator->is_animating()); 681 EXPECT_TRUE(test_controller.animator()->is_animating());
525 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 682 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
526 683
527 base::TimeTicks start_time = animator->last_step_time(); 684 base::TimeTicks start_time = test_controller.animator()->last_step_time();
685 base::TimeTicks effective_start = start_time + delta;
528 686
529 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 687 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
688 cc::AnimationEvent::Started,
689 0,
690 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
691 animation_group_id(),
692 cc::Animation::Opacity,
693 (effective_start - base::TimeTicks()).InSecondsF()));
530 694
531 EXPECT_TRUE(animator->is_animating()); 695 element->Step(effective_start + delta/2);
532 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
533 696
534 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 697 EXPECT_TRUE(test_controller.animator()->is_animating());
698 EXPECT_FLOAT_EQ(
699 0.5,
700 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
701 last_progressed_fraction());
535 702
536 EXPECT_FALSE(animator->is_animating()); 703 element->Step(effective_start + delta);
704 EXPECT_FALSE(test_controller.animator()->is_animating());
537 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 705 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
538 } 706 }
539 707
540 // Preempt by immediately setting new target. 708 // Preempt by immediately setting new target.
541 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { 709 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
542 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 710 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
543 animator->set_disable_timer_for_test(true); 711 animator->set_disable_timer_for_test(true);
544 TestLayerAnimationDelegate delegate; 712 TestLayerAnimationDelegate delegate;
545 animator->SetDelegate(&delegate); 713 animator->SetDelegate(&delegate);
546 714
(...skipping 11 matching lines...) Expand all
558 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 726 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
559 727
560 animator->StartAnimation( 728 animator->StartAnimation(
561 new LayerAnimationSequence( 729 new LayerAnimationSequence(
562 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 730 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
563 731
564 EXPECT_FALSE(animator->is_animating()); 732 EXPECT_FALSE(animator->is_animating());
565 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 733 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
566 } 734 }
567 735
568 // Preempt by animating to new target. 736 // Preempt by animating to new target, with a non-threaded animation.
569 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { 737 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
570 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 738 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
571 AnimationContainerElement* element = animator.get(); 739 AnimationContainerElement* element = animator.get();
572 animator->set_disable_timer_for_test(true); 740 animator->set_disable_timer_for_test(true);
573 TestLayerAnimationDelegate delegate; 741 TestLayerAnimationDelegate delegate;
574 animator->SetDelegate(&delegate); 742 animator->SetDelegate(&delegate);
575 743
576 double start_opacity(0.0); 744 double start_brightness(0.0);
577 double middle_opacity(0.5); 745 double middle_brightness(0.5);
578 double target_opacity(1.0); 746 double target_brightness(1.0);
579 747
580 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 748 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
581 749
582 delegate.SetOpacityFromAnimation(start_opacity); 750 delegate.SetBrightnessFromAnimation(start_brightness);
583 751
584 animator->set_preemption_strategy( 752 animator->set_preemption_strategy(
585 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 753 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
586 754
587 animator->StartAnimation( 755 animator->StartAnimation(
588 new LayerAnimationSequence( 756 new LayerAnimationSequence(
589 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 757 LayerAnimationElement::CreateBrightnessElement(target_brightness,
758 delta)));
590 759
591 base::TimeTicks start_time = animator->last_step_time(); 760 base::TimeTicks start_time = animator->last_step_time();
592 761
593 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 762 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
594 763
595 animator->StartAnimation( 764 animator->StartAnimation(
596 new LayerAnimationSequence( 765 new LayerAnimationSequence(
597 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 766 LayerAnimationElement::CreateBrightnessElement(start_brightness,
767 delta)));
598 768
599 EXPECT_TRUE(animator->is_animating()); 769 EXPECT_TRUE(animator->is_animating());
600 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 770 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
601 771
602 animator->StartAnimation( 772 animator->StartAnimation(
603 new LayerAnimationSequence( 773 new LayerAnimationSequence(
604 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 774 LayerAnimationElement::CreateBrightnessElement(start_brightness,
775 delta)));
605 776
606 EXPECT_TRUE(animator->is_animating()); 777 EXPECT_TRUE(animator->is_animating());
607 778
608 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 779 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
609 780
610 EXPECT_TRUE(animator->is_animating()); 781 EXPECT_TRUE(animator->is_animating());
611 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 782 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
612 0.5 * (start_opacity + middle_opacity)); 783 0.5 * (start_brightness + middle_brightness));
613 784
614 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 785 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
615 786
616 EXPECT_FALSE(animator->is_animating()); 787 EXPECT_FALSE(animator->is_animating());
788 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
789 }
790
791 // Preempt by animating to new target, with a threaded animation.
792 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) {
793 LayerAnimator::TestController test_controller(
794 LayerAnimator::CreateDefaultAnimator());
795 AnimationContainerElement* element = test_controller.animator();
796 test_controller.animator()->set_disable_timer_for_test(true);
797 TestLayerAnimationDelegate delegate;
798 test_controller.animator()->SetDelegate(&delegate);
799
800 double start_opacity(0.0);
801 double middle_opacity(0.5);
802 double target_opacity(1.0);
803
804 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
805
806 delegate.SetOpacityFromAnimation(start_opacity);
807
808 test_controller.animator()->set_preemption_strategy(
809 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
810
811 test_controller.animator()->StartAnimation(
812 new LayerAnimationSequence(
813 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
814
815 base::TimeTicks start_time = test_controller.animator()->last_step_time();
816 base::TimeTicks effective_start = start_time + delta;
817
818 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
819 cc::AnimationEvent::Started,
820 0,
821 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
822 animation_group_id(),
823 cc::Animation::Opacity,
824 (effective_start - base::TimeTicks()).InSecondsF()));
825
826 element->Step(effective_start + delta/2);
827
828 test_controller.animator()->StartAnimation(
829 new LayerAnimationSequence(
830 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
831
832 EXPECT_TRUE(test_controller.animator()->is_animating());
833 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
834
835 test_controller.animator()->StartAnimation(
836 new LayerAnimationSequence(
837 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)));
838
839 EXPECT_TRUE(test_controller.animator()->is_animating());
840
841 base::TimeTicks second_effective_start = effective_start + delta;
842
843 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
844 cc::AnimationEvent::Started,
845 0,
846 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
847 animation_group_id(),
848 cc::Animation::Opacity,
849 (second_effective_start - base::TimeTicks()).InSecondsF()));
850
851 element->Step(second_effective_start + delta/2);
852
853 EXPECT_TRUE(test_controller.animator()->is_animating());
854 EXPECT_FLOAT_EQ(
855 0.5,
856 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
857 last_progressed_fraction());
858
859 element->Step(second_effective_start + delta);
860
861 EXPECT_FALSE(test_controller.animator()->is_animating());
617 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 862 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
618 } 863 }
619 864
620 // Preempt by enqueuing the new animation. 865 // Preempt by enqueuing the new animation.
621 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { 866 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
622 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 867 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
623 AnimationContainerElement* element = animator.get(); 868 AnimationContainerElement* element = animator.get();
624 animator->set_disable_timer_for_test(true); 869 animator->set_disable_timer_for_test(true);
625 TestLayerAnimationDelegate delegate; 870 TestLayerAnimationDelegate delegate;
626 animator->SetDelegate(&delegate); 871 animator->SetDelegate(&delegate);
627 872
628 double start_opacity(0.0); 873 double start_brightness(0.0);
629 double middle_opacity(0.5); 874 double middle_brightness(0.5);
630 double target_opacity(1.0); 875 double target_brightness(1.0);
631 876
632 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 877 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
633 878
634 delegate.SetOpacityFromAnimation(start_opacity); 879 delegate.SetBrightnessFromAnimation(start_brightness);
635 880
636 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 881 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
637 882
638 animator->StartAnimation( 883 animator->StartAnimation(
639 new LayerAnimationSequence( 884 new LayerAnimationSequence(
640 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 885 LayerAnimationElement::CreateBrightnessElement(target_brightness,
886 delta)));
641 887
642 base::TimeTicks start_time = animator->last_step_time(); 888 base::TimeTicks start_time = animator->last_step_time();
643 889
644 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 890 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
645 891
646 animator->StartAnimation( 892 animator->StartAnimation(
647 new LayerAnimationSequence( 893 new LayerAnimationSequence(
648 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 894 LayerAnimationElement::CreateBrightnessElement(start_brightness,
895 delta)));
649 896
650 EXPECT_TRUE(animator->is_animating()); 897 EXPECT_TRUE(animator->is_animating());
651 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 898 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
652 899
653 EXPECT_TRUE(animator->is_animating()); 900 EXPECT_TRUE(animator->is_animating());
654 901
655 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 902 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
656 903
657 EXPECT_TRUE(animator->is_animating()); 904 EXPECT_TRUE(animator->is_animating());
658 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 905 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
659 906
660 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 907 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
661 908
662 EXPECT_TRUE(animator->is_animating()); 909 EXPECT_TRUE(animator->is_animating());
663 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 910 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
664 911
665 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 912 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
666 913
667 EXPECT_FALSE(animator->is_animating()); 914 EXPECT_FALSE(animator->is_animating());
668 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 915 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
669 } 916 }
670 917
671 // Start an animation when there are sequences waiting in the queue. In this 918 // Start an animation when there are sequences waiting in the queue. In this
672 // case, all pending and running animations should be finished, and the new 919 // case, all pending and running animations should be finished, and the new
673 // animation started. 920 // animation started.
674 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { 921 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
675 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 922 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
676 AnimationContainerElement* element = animator.get(); 923 AnimationContainerElement* element = animator.get();
677 animator->set_disable_timer_for_test(true); 924 animator->set_disable_timer_for_test(true);
678 TestLayerAnimationDelegate delegate; 925 TestLayerAnimationDelegate delegate;
679 animator->SetDelegate(&delegate); 926 animator->SetDelegate(&delegate);
680 927
681 double start_opacity(0.0); 928 double start_brightness(0.0);
682 double middle_opacity(0.5); 929 double middle_brightness(0.5);
683 double target_opacity(1.0); 930 double target_brightness(1.0);
684 931
685 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 932 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
686 933
687 delegate.SetOpacityFromAnimation(start_opacity); 934 delegate.SetBrightnessFromAnimation(start_brightness);
688 935
689 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 936 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
690 937
691 animator->StartAnimation( 938 animator->StartAnimation(
692 new LayerAnimationSequence( 939 new LayerAnimationSequence(
693 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 940 LayerAnimationElement::CreateBrightnessElement(target_brightness,
941 delta)));
694 942
695 base::TimeTicks start_time = animator->last_step_time(); 943 base::TimeTicks start_time = animator->last_step_time();
696 944
697 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 945 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
698 946
699 animator->StartAnimation( 947 animator->StartAnimation(
700 new LayerAnimationSequence( 948 new LayerAnimationSequence(
701 LayerAnimationElement::CreateOpacityElement(middle_opacity, delta))); 949 LayerAnimationElement::CreateBrightnessElement(middle_brightness,
950 delta)));
702 951
703 // Queue should now have two animations. Starting a third should replace the 952 // Queue should now have two animations. Starting a third should replace the
704 // second. 953 // second.
705 animator->StartAnimation( 954 animator->StartAnimation(
706 new LayerAnimationSequence( 955 new LayerAnimationSequence(
707 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); 956 LayerAnimationElement::CreateBrightnessElement(start_brightness,
957 delta)));
708 958
709 EXPECT_TRUE(animator->is_animating()); 959 EXPECT_TRUE(animator->is_animating());
710 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 960 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
711 961
712 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 962 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
713 963
714 EXPECT_TRUE(animator->is_animating()); 964 EXPECT_TRUE(animator->is_animating());
715 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 965 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
716 966
717 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 967 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
718 968
719 EXPECT_TRUE(animator->is_animating()); 969 EXPECT_TRUE(animator->is_animating());
720 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 970 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
721 971
722 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 972 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
723 973
724 EXPECT_FALSE(animator->is_animating()); 974 EXPECT_FALSE(animator->is_animating());
725 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 975 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
726 } 976 }
727 977
728 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { 978 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) {
729 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 979 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
730 animator->set_disable_timer_for_test(true); 980 animator->set_disable_timer_for_test(true);
731 TestLayerAnimationDelegate delegate; 981 TestLayerAnimationDelegate delegate;
732 animator->SetDelegate(&delegate); 982 animator->SetDelegate(&delegate);
733 983
734 double start_opacity(0.0); 984 double start_grayscale(0.0);
735 double target_opacity(1.0); 985 double target_grayscale(1.0);
736 double start_brightness(0.1); 986 double start_brightness(0.1);
737 double target_brightness(0.9); 987 double target_brightness(0.9);
738 988
739 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 989 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
740 990
741 delegate.SetOpacityFromAnimation(start_opacity); 991 delegate.SetGrayscaleFromAnimation(start_grayscale);
742 delegate.SetBrightnessFromAnimation(start_brightness); 992 delegate.SetBrightnessFromAnimation(start_brightness);
743 993
744 animator->set_preemption_strategy( 994 animator->set_preemption_strategy(
745 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 995 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
746 996
747 animator->set_last_step_time(base::TimeTicks()); 997 animator->set_last_step_time(base::TimeTicks());
748 998
749 animator->StartTogether( 999 animator->StartTogether(
750 CreateMultiSequence( 1000 CreateMultiSequence(
751 LayerAnimationElement::CreateOpacityElement(target_opacity, delta), 1001 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1002 delta),
752 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1003 LayerAnimationElement::CreateBrightnessElement(target_brightness,
753 delta) 1004 delta)
754 )); 1005 ));
755 1006
756 // If last step time was not set correctly, the resulting delta should be 1007 // If last step time was not set correctly, the resulting delta should be
757 // miniscule (fractions of a millisecond). If set correctly, then the delta 1008 // miniscule (fractions of a millisecond). If set correctly, then the delta
758 // should be enormous. Arbitrarily choosing 1 minute as the threshold, 1009 // should be enormous. Arbitrarily choosing 1 minute as the threshold,
759 // though a much smaller value would probably have sufficed. 1010 // though a much smaller value would probably have sufficed.
760 delta = base::TimeTicks::Now() - animator->last_step_time(); 1011 delta = base::TimeTicks::Now() - animator->last_step_time();
761 EXPECT_GT(60.0, delta.InSecondsF()); 1012 EXPECT_GT(60.0, delta.InSecondsF());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 1052 }
802 1053
803 // Preempt by animating to new target. 1054 // Preempt by animating to new target.
804 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { 1055 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) {
805 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1056 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
806 AnimationContainerElement* element = animator.get(); 1057 AnimationContainerElement* element = animator.get();
807 animator->set_disable_timer_for_test(true); 1058 animator->set_disable_timer_for_test(true);
808 TestLayerAnimationDelegate delegate; 1059 TestLayerAnimationDelegate delegate;
809 animator->SetDelegate(&delegate); 1060 animator->SetDelegate(&delegate);
810 1061
811 double start_opacity(0.0); 1062 double start_grayscale(0.0);
812 double middle_opacity(0.5); 1063 double middle_grayscale(0.5);
813 double target_opacity(1.0); 1064 double target_grayscale(1.0);
814 1065
815 double start_brightness(0.1); 1066 double start_brightness(0.1);
816 double middle_brightness(0.2); 1067 double middle_brightness(0.2);
817 double target_brightness(0.3); 1068 double target_brightness(0.3);
818 1069
819 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1070 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
820 1071
821 delegate.SetOpacityFromAnimation(start_opacity); 1072 delegate.SetGrayscaleFromAnimation(start_grayscale);
822 delegate.SetBrightnessFromAnimation(start_brightness); 1073 delegate.SetBrightnessFromAnimation(start_brightness);
823 1074
824 animator->set_preemption_strategy( 1075 animator->set_preemption_strategy(
825 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 1076 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
826 1077
827 animator->StartTogether( 1078 animator->StartTogether(
828 CreateMultiSequence( 1079 CreateMultiSequence(
829 LayerAnimationElement::CreateOpacityElement(target_opacity, delta), 1080 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1081 delta),
830 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1082 LayerAnimationElement::CreateBrightnessElement(target_brightness,
831 delta) 1083 delta)
832 )); 1084 ));
833 1085
834 base::TimeTicks start_time = animator->last_step_time(); 1086 base::TimeTicks start_time = animator->last_step_time();
835 1087
836 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1088 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
837 1089
838 animator->StartTogether( 1090 animator->StartTogether(
839 CreateMultiSequence( 1091 CreateMultiSequence(
840 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1092 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
841 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1093 LayerAnimationElement::CreateBrightnessElement(start_brightness,
842 delta))); 1094 delta)));
843 1095
844 EXPECT_TRUE(animator->is_animating()); 1096 EXPECT_TRUE(animator->is_animating());
845 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 1097 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
846 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1098 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
847 1099
848 animator->StartTogether( 1100 animator->StartTogether(
849 CreateMultiSequence( 1101 CreateMultiSequence(
850 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1102 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
851 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1103 LayerAnimationElement::CreateBrightnessElement(start_brightness,
852 delta))); 1104 delta)));
853 1105
854 EXPECT_TRUE(animator->is_animating()); 1106 EXPECT_TRUE(animator->is_animating());
855 1107
856 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1108 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
857 1109
858 EXPECT_TRUE(animator->is_animating()); 1110 EXPECT_TRUE(animator->is_animating());
859 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 1111 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(),
860 0.5 * (start_opacity + middle_opacity)); 1112 0.5 * (start_grayscale + middle_grayscale));
861 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 1113 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
862 0.5 * (start_brightness + middle_brightness)); 1114 0.5 * (start_brightness + middle_brightness));
863 1115
864 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1116 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
865 1117
866 EXPECT_FALSE(animator->is_animating()); 1118 EXPECT_FALSE(animator->is_animating());
1119 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1120 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1121 }
1122
1123 // Preempt a threaded animation by animating to new target.
1124 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) {
1125 LayerAnimator::TestController test_controller(
1126 LayerAnimator::CreateDefaultAnimator());
1127 AnimationContainerElement* element = test_controller.animator();
1128 test_controller.animator()->set_disable_timer_for_test(true);
1129 TestLayerAnimationDelegate delegate;
1130 test_controller.animator()->SetDelegate(&delegate);
1131
1132 double start_opacity(0.0);
1133 double middle_opacity(0.5);
1134 double target_opacity(1.0);
1135
1136 double start_brightness(0.1);
1137 double middle_brightness(0.2);
1138 double target_brightness(0.3);
1139
1140 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1141
1142 delegate.SetOpacityFromAnimation(start_opacity);
1143 delegate.SetBrightnessFromAnimation(start_brightness);
1144
1145 test_controller.animator()->set_preemption_strategy(
1146 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
1147
1148 test_controller.animator()->StartTogether(
1149 CreateMultiSequence(
1150 LayerAnimationElement::CreateOpacityElement(target_opacity, delta),
1151 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1152 delta)
1153 ));
1154
1155 base::TimeTicks start_time = test_controller.animator()->last_step_time();
1156 base::TimeTicks effective_start = start_time + delta;
1157
1158 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1159 cc::AnimationEvent::Started,
1160 0,
1161 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1162 animation_group_id(),
1163 cc::Animation::Opacity,
1164 (effective_start - base::TimeTicks()).InSecondsF()));
1165
1166 element->Step(effective_start + delta/2);
1167
1168 test_controller.animator()->StartTogether(
1169 CreateMultiSequence(
1170 LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
1171 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1172 delta)));
1173
1174 EXPECT_TRUE(test_controller.animator()->is_animating());
1175 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity);
1176 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
1177
1178 test_controller.animator()->StartTogether(
1179 CreateMultiSequence(
1180 LayerAnimationElement::CreateOpacityElement(start_opacity, delta),
1181 LayerAnimationElement::CreateBrightnessElement(start_brightness,
1182 delta)));
1183
1184 EXPECT_TRUE(test_controller.animator()->is_animating());
1185
1186 base::TimeTicks second_effective_start = effective_start + delta;
1187
1188 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1189 cc::AnimationEvent::Started,
1190 0,
1191 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1192 animation_group_id(),
1193 cc::Animation::Opacity,
1194 (second_effective_start - base::TimeTicks()).InSecondsF()));
1195
1196 element->Step(second_effective_start + delta/2);
1197
1198 EXPECT_TRUE(test_controller.animator()->is_animating());
1199 EXPECT_FLOAT_EQ(
1200 0.5,
1201 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1202 last_progressed_fraction());
1203 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(),
1204 0.5 * (start_brightness + middle_brightness));
1205
1206 element->Step(second_effective_start + delta);
1207
1208 EXPECT_FALSE(test_controller.animator()->is_animating());
867 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1209 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
868 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1210 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
869 } 1211 }
870 1212
871 // Preempt by enqueuing the new animation. 1213 // Preempt by enqueuing the new animation.
872 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { 1214 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) {
873 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1215 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
874 AnimationContainerElement* element = animator.get(); 1216 AnimationContainerElement* element = animator.get();
875 animator->set_disable_timer_for_test(true); 1217 animator->set_disable_timer_for_test(true);
876 TestLayerAnimationDelegate delegate; 1218 TestLayerAnimationDelegate delegate;
877 animator->SetDelegate(&delegate); 1219 animator->SetDelegate(&delegate);
878 1220
879 double start_opacity(0.0); 1221 double start_grayscale(0.0);
880 double middle_opacity(0.5); 1222 double middle_grayscale(0.5);
881 double target_opacity(1.0); 1223 double target_grayscale(1.0);
882 1224
883 double start_brightness(0.1); 1225 double start_brightness(0.1);
884 double middle_brightness(0.2); 1226 double middle_brightness(0.2);
885 double target_brightness(0.3); 1227 double target_brightness(0.3);
886 1228
887 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1229 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
888 1230
889 delegate.SetOpacityFromAnimation(start_opacity); 1231 delegate.SetGrayscaleFromAnimation(start_grayscale);
890 delegate.SetBrightnessFromAnimation(start_brightness); 1232 delegate.SetBrightnessFromAnimation(start_brightness);
891 1233
892 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); 1234 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION);
893 1235
894 animator->StartTogether( 1236 animator->StartTogether(
895 CreateMultiSequence( 1237 CreateMultiSequence(
896 LayerAnimationElement::CreateOpacityElement(target_opacity, delta), 1238 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1239 delta),
897 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1240 LayerAnimationElement::CreateBrightnessElement(target_brightness,
898 delta))); 1241 delta)));
899 1242
900 base::TimeTicks start_time = animator->last_step_time(); 1243 base::TimeTicks start_time = animator->last_step_time();
901 1244
902 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1245 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
903 1246
904 animator->StartTogether( 1247 animator->StartTogether(
905 CreateMultiSequence( 1248 CreateMultiSequence(
906 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1249 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
907 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1250 LayerAnimationElement::CreateBrightnessElement(start_brightness,
908 delta))); 1251 delta)));
909 1252
910 EXPECT_TRUE(animator->is_animating()); 1253 EXPECT_TRUE(animator->is_animating());
911 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 1254 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
912 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1255 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
913 1256
914 EXPECT_TRUE(animator->is_animating()); 1257 EXPECT_TRUE(animator->is_animating());
915 1258
916 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1259 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
917 1260
918 EXPECT_TRUE(animator->is_animating()); 1261 EXPECT_TRUE(animator->is_animating());
919 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1262 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
920 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1263 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
921 1264
922 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1265 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
923 1266
924 EXPECT_TRUE(animator->is_animating()); 1267 EXPECT_TRUE(animator->is_animating());
925 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 1268 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
926 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1269 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
927 1270
928 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1271 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
929 1272
930 EXPECT_FALSE(animator->is_animating()); 1273 EXPECT_FALSE(animator->is_animating());
931 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1274 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
932 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1275 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
933 } 1276 }
934 1277
935 // Start an animation when there are sequences waiting in the queue. In this 1278 // Start an animation when there are sequences waiting in the queue. In this
936 // case, all pending and running animations should be finished, and the new 1279 // case, all pending and running animations should be finished, and the new
937 // animation started. 1280 // animation started.
938 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { 1281 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) {
939 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1282 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
940 AnimationContainerElement* element = animator.get(); 1283 AnimationContainerElement* element = animator.get();
941 animator->set_disable_timer_for_test(true); 1284 animator->set_disable_timer_for_test(true);
942 TestLayerAnimationDelegate delegate; 1285 TestLayerAnimationDelegate delegate;
943 animator->SetDelegate(&delegate); 1286 animator->SetDelegate(&delegate);
944 1287
945 double start_opacity(0.0); 1288 double start_grayscale(0.0);
946 double middle_opacity(0.5); 1289 double middle_grayscale(0.5);
947 double target_opacity(1.0); 1290 double target_grayscale(1.0);
948 1291
949 double start_brightness(0.1); 1292 double start_brightness(0.1);
950 double middle_brightness(0.2); 1293 double middle_brightness(0.2);
951 double target_brightness(0.3); 1294 double target_brightness(0.3);
952 1295
953 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1296 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
954 1297
955 delegate.SetOpacityFromAnimation(start_opacity); 1298 delegate.SetGrayscaleFromAnimation(start_grayscale);
956 delegate.SetBrightnessFromAnimation(start_brightness); 1299 delegate.SetBrightnessFromAnimation(start_brightness);
957 1300
958 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 1301 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
959 1302
960 animator->StartTogether( 1303 animator->StartTogether(
961 CreateMultiSequence( 1304 CreateMultiSequence(
962 LayerAnimationElement::CreateOpacityElement(target_opacity, delta), 1305 LayerAnimationElement::CreateGrayscaleElement(target_grayscale,
1306 delta),
963 LayerAnimationElement::CreateBrightnessElement(target_brightness, 1307 LayerAnimationElement::CreateBrightnessElement(target_brightness,
964 delta))); 1308 delta)));
965 1309
966 base::TimeTicks start_time = animator->last_step_time(); 1310 base::TimeTicks start_time = animator->last_step_time();
967 1311
968 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1312 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
969 1313
970 animator->StartTogether( 1314 animator->StartTogether(
971 CreateMultiSequence( 1315 CreateMultiSequence(
972 LayerAnimationElement::CreateOpacityElement(middle_opacity, delta), 1316 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale,
1317 delta),
973 LayerAnimationElement::CreateBrightnessElement(middle_brightness, 1318 LayerAnimationElement::CreateBrightnessElement(middle_brightness,
974 delta))); 1319 delta)));
975 1320
976 // Queue should now have two animations. Starting a third should replace the 1321 // Queue should now have two animations. Starting a third should replace the
977 // second. 1322 // second.
978 animator->StartTogether( 1323 animator->StartTogether(
979 CreateMultiSequence( 1324 CreateMultiSequence(
980 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), 1325 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta),
981 LayerAnimationElement::CreateBrightnessElement(start_brightness, 1326 LayerAnimationElement::CreateBrightnessElement(start_brightness,
982 delta))); 1327 delta)));
983 1328
984 EXPECT_TRUE(animator->is_animating()); 1329 EXPECT_TRUE(animator->is_animating());
985 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 1330 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
986 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1331 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
987 1332
988 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1333 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
989 1334
990 EXPECT_TRUE(animator->is_animating()); 1335 EXPECT_TRUE(animator->is_animating());
991 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1336 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale);
992 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); 1337 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
993 1338
994 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 1339 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
995 1340
996 EXPECT_TRUE(animator->is_animating()); 1341 EXPECT_TRUE(animator->is_animating());
997 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), middle_opacity); 1342 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale);
998 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); 1343 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness);
999 1344
1000 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1345 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1001 1346
1002 EXPECT_FALSE(animator->is_animating()); 1347 EXPECT_FALSE(animator->is_animating());
1003 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1348 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale);
1004 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); 1349 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1005 } 1350 }
1006 //------------------------------------------------------- 1351 //-------------------------------------------------------
1007 // Test that cyclic sequences continue to animate. 1352 // Test that non-threaded cyclic sequences continue to animate.
1008 TEST(LayerAnimatorTest, CyclicSequences) { 1353 TEST(LayerAnimatorTest, CyclicSequences) {
1009 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1354 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1010 AnimationContainerElement* element = animator.get(); 1355 AnimationContainerElement* element = animator.get();
1011 animator->set_disable_timer_for_test(true); 1356 animator->set_disable_timer_for_test(true);
1012 TestLayerAnimationDelegate delegate; 1357 TestLayerAnimationDelegate delegate;
1013 animator->SetDelegate(&delegate); 1358 animator->SetDelegate(&delegate);
1014 1359
1015 double start_opacity(0.0); 1360 double start_brightness(0.0);
1016 double target_opacity(1.0); 1361 double target_brightness(1.0);
1017 1362
1018 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1363 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1019 1364
1020 delegate.SetOpacityFromAnimation(start_opacity); 1365 delegate.SetBrightnessFromAnimation(start_brightness);
1021 1366
1022 scoped_ptr<LayerAnimationSequence> sequence( 1367 scoped_ptr<LayerAnimationSequence> sequence(
1023 new LayerAnimationSequence( 1368 new LayerAnimationSequence(
1024 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); 1369 LayerAnimationElement::CreateBrightnessElement(target_brightness,
1370 delta)));
1025 1371
1026 sequence->AddElement( 1372 sequence->AddElement(
1027 LayerAnimationElement::CreateOpacityElement(start_opacity, delta)); 1373 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta));
1028 1374
1029 sequence->set_is_cyclic(true); 1375 sequence->set_is_cyclic(true);
1030 1376
1031 animator->StartAnimation(sequence.release()); 1377 animator->StartAnimation(sequence.release());
1032 1378
1033 base::TimeTicks start_time = animator->last_step_time(); 1379 base::TimeTicks start_time = animator->last_step_time();
1034 1380
1035 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1381 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1036 1382
1037 EXPECT_TRUE(animator->is_animating()); 1383 EXPECT_TRUE(animator->is_animating());
1038 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1384 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1039 1385
1040 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); 1386 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000));
1041 1387
1042 EXPECT_TRUE(animator->is_animating()); 1388 EXPECT_TRUE(animator->is_animating());
1043 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1389 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1044 1390
1045 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); 1391 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000));
1046 1392
1047 EXPECT_TRUE(animator->is_animating()); 1393 EXPECT_TRUE(animator->is_animating());
1048 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1394 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1049 1395
1050 // Skip ahead by a lot. 1396 // Skip ahead by a lot.
1051 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); 1397 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000));
1052 1398
1053 EXPECT_TRUE(animator->is_animating()); 1399 EXPECT_TRUE(animator->is_animating());
1054 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); 1400 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness);
1055 1401
1056 // Skip ahead by a lot. 1402 // Skip ahead by a lot.
1057 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); 1403 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000));
1058 1404
1059 EXPECT_TRUE(animator->is_animating()); 1405 EXPECT_TRUE(animator->is_animating());
1406 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness);
1407
1408 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS);
1409
1410 EXPECT_FALSE(animator->is_animating());
1411 }
1412
1413 // Test that threaded cyclic sequences continue to animate.
1414 TEST(LayerAnimatorTest, ThreadedCyclicSequences) {
1415 LayerAnimator::TestController test_controller(
1416 LayerAnimator::CreateDefaultAnimator());
1417 AnimationContainerElement* element = test_controller.animator();
1418 test_controller.animator()->set_disable_timer_for_test(true);
1419 TestLayerAnimationDelegate delegate;
1420 test_controller.animator()->SetDelegate(&delegate);
1421
1422 double start_opacity(0.0);
1423 double target_opacity(1.0);
1424
1425 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1426
1427 delegate.SetOpacityFromAnimation(start_opacity);
1428
1429 scoped_ptr<LayerAnimationSequence> sequence(
1430 new LayerAnimationSequence(
1431 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)));
1432
1433 sequence->AddElement(
1434 LayerAnimationElement::CreateOpacityElement(start_opacity, delta));
1435
1436 sequence->set_is_cyclic(true);
1437
1438 test_controller.animator()->StartAnimation(sequence.release());
1439
1440 base::TimeTicks start_time = test_controller.animator()->last_step_time();
1441 base::TimeTicks effective_start = start_time + delta;
1442
1443 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1444 cc::AnimationEvent::Started,
1445 0,
1446 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1447 animation_group_id(),
1448 cc::Animation::Opacity,
1449 (effective_start - base::TimeTicks()).InSecondsF()));
1450
1451 element->Step(effective_start + delta);
1452 EXPECT_TRUE(test_controller.animator()->is_animating());
1060 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); 1453 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1061 1454
1062 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); 1455 base::TimeTicks second_effective_start = effective_start + 2 * delta;
1456 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1457 cc::AnimationEvent::Started,
1458 0,
1459 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1460 animation_group_id(),
1461 cc::Animation::Opacity,
1462 (second_effective_start - base::TimeTicks()).InSecondsF()));
1063 1463
1064 EXPECT_FALSE(animator->is_animating()); 1464 element->Step(second_effective_start + delta);
1465
1466 EXPECT_TRUE(test_controller.animator()->is_animating());
1467 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1468
1469 base::TimeTicks third_effective_start = second_effective_start + 2 * delta;
1470 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1471 cc::AnimationEvent::Started,
1472 0,
1473 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1474 animation_group_id(),
1475 cc::Animation::Opacity,
1476 (third_effective_start - base::TimeTicks()).InSecondsF()));
1477
1478 element->Step(third_effective_start + delta);
1479 EXPECT_TRUE(test_controller.animator()->is_animating());
1480 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1481
1482 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta;
1483 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1484 cc::AnimationEvent::Started,
1485 0,
1486 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1487 animation_group_id(),
1488 cc::Animation::Opacity,
1489 (fourth_effective_start - base::TimeTicks()).InSecondsF()));
1490
1491 // Skip ahead by a lot.
1492 element->Step(fourth_effective_start + 1000 * delta);
1493
1494 EXPECT_TRUE(test_controller.animator()->is_animating());
1495 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity);
1496
1497 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta;
1498 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent(
1499 cc::AnimationEvent::Started,
1500 0,
1501 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)->
1502 animation_group_id(),
1503 cc::Animation::Opacity,
1504 (fifth_effective_start - base::TimeTicks()).InSecondsF()));
1505
1506 // Skip ahead by a lot.
1507 element->Step(fifth_effective_start + 999 * delta);
1508
1509 EXPECT_TRUE(test_controller.animator()->is_animating());
1510 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity);
1511
1512 test_controller.animator()->StopAnimatingProperty(
1513 LayerAnimationElement::OPACITY);
1514
1515 EXPECT_FALSE(test_controller.animator()->is_animating());
1065 } 1516 }
1066 1517
1067 TEST(LayerAnimatorTest, AddObserverExplicit) { 1518 TEST(LayerAnimatorTest, AddObserverExplicit) {
1068 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1519 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1069 AnimationContainerElement* element = animator.get(); 1520 AnimationContainerElement* element = animator.get();
1070 animator->set_disable_timer_for_test(true); 1521 animator->set_disable_timer_for_test(true);
1071 TestLayerAnimationObserver observer; 1522 TestLayerAnimationObserver observer;
1072 TestLayerAnimationDelegate delegate; 1523 TestLayerAnimationDelegate delegate;
1073 animator->SetDelegate(&delegate); 1524 animator->SetDelegate(&delegate);
1074 animator->AddObserver(&observer); 1525 animator->AddObserver(&observer);
1075 observer.set_requires_notification_when_animator_destroyed(true); 1526 observer.set_requires_notification_when_animator_destroyed(true);
1076 1527
1077 EXPECT_TRUE(!observer.last_ended_sequence()); 1528 EXPECT_TRUE(!observer.last_ended_sequence());
1078 1529
1079 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1530 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1080 1531
1081 delegate.SetOpacityFromAnimation(0.0f); 1532 delegate.SetBrightnessFromAnimation(0.0f);
1082 1533
1083 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1534 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1084 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1535 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1085 1536
1086 animator->StartAnimation(sequence); 1537 animator->StartAnimation(sequence);
1087 1538
1088 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 1539 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
1089 1540
1090 base::TimeTicks start_time = animator->last_step_time(); 1541 base::TimeTicks start_time = animator->last_step_time();
1091 1542
1092 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1543 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1093 1544
1094 EXPECT_EQ(observer.last_ended_sequence(), sequence); 1545 EXPECT_EQ(observer.last_ended_sequence(), sequence);
1095 1546
1096 // |sequence| has been destroyed. Recreate it to test abort. 1547 // |sequence| has been destroyed. Recreate it to test abort.
1097 sequence = new LayerAnimationSequence( 1548 sequence = new LayerAnimationSequence(
1098 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1549 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1099 1550
1100 animator->StartAnimation(sequence); 1551 animator->StartAnimation(sequence);
1101 1552
1102 animator = NULL; 1553 animator = NULL;
1103 1554
1104 EXPECT_EQ(observer.last_aborted_sequence(), sequence); 1555 EXPECT_EQ(observer.last_aborted_sequence(), sequence);
1105 } 1556 }
1106 1557
1107 // Tests that an observer added to a scoped settings object is still notified 1558 // Tests that an observer added to a scoped settings object is still notified
1108 // when the object goes out of scope. 1559 // when the object goes out of scope.
1109 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { 1560 TEST(LayerAnimatorTest, ImplicitAnimationObservers) {
1110 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1561 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1111 AnimationContainerElement* element = animator.get(); 1562 AnimationContainerElement* element = animator.get();
1112 animator->set_disable_timer_for_test(true); 1563 animator->set_disable_timer_for_test(true);
1113 TestImplicitAnimationObserver observer(false); 1564 TestImplicitAnimationObserver observer(false);
1114 TestLayerAnimationDelegate delegate; 1565 TestLayerAnimationDelegate delegate;
1115 animator->SetDelegate(&delegate); 1566 animator->SetDelegate(&delegate);
1116 1567
1117 EXPECT_FALSE(observer.animations_completed()); 1568 EXPECT_FALSE(observer.animations_completed());
1118 animator->SetOpacity(1.0f); 1569 animator->SetBrightness(1.0f);
1119 1570
1120 { 1571 {
1121 ScopedLayerAnimationSettings settings(animator.get()); 1572 ScopedLayerAnimationSettings settings(animator.get());
1122 settings.AddObserver(&observer); 1573 settings.AddObserver(&observer);
1123 animator->SetOpacity(0.0f); 1574 animator->SetBrightness(0.0f);
1124 } 1575 }
1125 1576
1126 EXPECT_FALSE(observer.animations_completed()); 1577 EXPECT_FALSE(observer.animations_completed());
1127 base::TimeTicks start_time = animator->last_step_time(); 1578 base::TimeTicks start_time = animator->last_step_time();
1128 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1579 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1129 EXPECT_TRUE(observer.animations_completed()); 1580 EXPECT_TRUE(observer.animations_completed());
1130 EXPECT_FLOAT_EQ(0.0f, delegate.GetOpacityForAnimation()); 1581 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation());
1131 } 1582 }
1132 1583
1133 // Tests that an observer added to a scoped settings object is still notified 1584 // Tests that an observer added to a scoped settings object is still notified
1134 // when the object goes out of scope due to the animation being interrupted. 1585 // when the object goes out of scope due to the animation being interrupted.
1135 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { 1586 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) {
1136 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1587 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1137 animator->set_disable_timer_for_test(true); 1588 animator->set_disable_timer_for_test(true);
1138 TestImplicitAnimationObserver observer(false); 1589 TestImplicitAnimationObserver observer(false);
1139 TestLayerAnimationDelegate delegate; 1590 TestLayerAnimationDelegate delegate;
1140 animator->SetDelegate(&delegate); 1591 animator->SetDelegate(&delegate);
1141 1592
1142 EXPECT_FALSE(observer.animations_completed()); 1593 EXPECT_FALSE(observer.animations_completed());
1143 animator->SetOpacity(1.0f); 1594 animator->SetBrightness(1.0f);
1144 1595
1145 { 1596 {
1146 ScopedLayerAnimationSettings settings(animator.get()); 1597 ScopedLayerAnimationSettings settings(animator.get());
1147 settings.AddObserver(&observer); 1598 settings.AddObserver(&observer);
1148 animator->SetOpacity(0.0f); 1599 animator->SetBrightness(0.0f);
1149 } 1600 }
1150 1601
1151 EXPECT_FALSE(observer.animations_completed()); 1602 EXPECT_FALSE(observer.animations_completed());
1152 // This should interrupt the implicit animation causing the observer to be 1603 // This should interrupt the implicit animation causing the observer to be
1153 // notified immediately. 1604 // notified immediately.
1154 animator->SetOpacity(1.0f); 1605 animator->SetBrightness(1.0f);
1155 EXPECT_TRUE(observer.animations_completed()); 1606 EXPECT_TRUE(observer.animations_completed());
1156 EXPECT_FLOAT_EQ(1.0f, delegate.GetOpacityForAnimation()); 1607 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation());
1157 } 1608 }
1158 1609
1159 // Tests that an observer added to a scoped settings object is not notified 1610 // Tests that an observer added to a scoped settings object is not notified
1160 // when the animator is destroyed unless explicitly requested. 1611 // when the animator is destroyed unless explicitly requested.
1161 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { 1612 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) {
1162 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1613 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1163 animator->set_disable_timer_for_test(true); 1614 animator->set_disable_timer_for_test(true);
1164 TestImplicitAnimationObserver observer_notify(true); 1615 TestImplicitAnimationObserver observer_notify(true);
1165 TestImplicitAnimationObserver observer_do_not_notify(false); 1616 TestImplicitAnimationObserver observer_do_not_notify(false);
1166 TestLayerAnimationDelegate delegate; 1617 TestLayerAnimationDelegate delegate;
1167 animator->SetDelegate(&delegate); 1618 animator->SetDelegate(&delegate);
1168 1619
1169 EXPECT_FALSE(observer_notify.animations_completed()); 1620 EXPECT_FALSE(observer_notify.animations_completed());
1170 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1621 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1171 1622
1172 animator->SetOpacity(1.0f); 1623 animator->SetBrightness(1.0f);
1173 1624
1174 { 1625 {
1175 ScopedLayerAnimationSettings settings(animator.get()); 1626 ScopedLayerAnimationSettings settings(animator.get());
1176 settings.AddObserver(&observer_notify); 1627 settings.AddObserver(&observer_notify);
1177 settings.AddObserver(&observer_do_not_notify); 1628 settings.AddObserver(&observer_do_not_notify);
1178 animator->SetOpacity(0.0f); 1629 animator->SetBrightness(0.0f);
1179 } 1630 }
1180 1631
1181 EXPECT_FALSE(observer_notify.animations_completed()); 1632 EXPECT_FALSE(observer_notify.animations_completed());
1182 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1633 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1183 animator = NULL; 1634 animator = NULL;
1184 EXPECT_TRUE(observer_notify.animations_completed()); 1635 EXPECT_TRUE(observer_notify.animations_completed());
1185 EXPECT_FALSE(observer_do_not_notify.animations_completed()); 1636 EXPECT_FALSE(observer_do_not_notify.animations_completed());
1186 } 1637 }
1187 1638
1188 1639
1189 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { 1640 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) {
1190 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1641 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1191 AnimationContainerElement* element = animator.get(); 1642 AnimationContainerElement* element = animator.get();
1192 animator->set_disable_timer_for_test(true); 1643 animator->set_disable_timer_for_test(true);
1193 TestLayerAnimationObserver observer; 1644 TestLayerAnimationObserver observer;
1194 TestLayerAnimationObserver removed_observer; 1645 TestLayerAnimationObserver removed_observer;
1195 TestLayerAnimationDelegate delegate; 1646 TestLayerAnimationDelegate delegate;
1196 animator->SetDelegate(&delegate); 1647 animator->SetDelegate(&delegate);
1197 1648
1198 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1649 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1199 1650
1200 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1651 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1201 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1652 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1202 1653
1203 sequence->AddObserver(&observer); 1654 sequence->AddObserver(&observer);
1204 sequence->AddObserver(&removed_observer); 1655 sequence->AddObserver(&removed_observer);
1205 1656
1206 animator->StartAnimation(sequence); 1657 animator->StartAnimation(sequence);
1207 1658
1208 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); 1659 EXPECT_EQ(observer.last_scheduled_sequence(), sequence);
1209 EXPECT_TRUE(!observer.last_ended_sequence()); 1660 EXPECT_TRUE(!observer.last_ended_sequence());
1210 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); 1661 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence);
1211 EXPECT_TRUE(!removed_observer.last_ended_sequence()); 1662 EXPECT_TRUE(!removed_observer.last_ended_sequence());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 1702
1252 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { 1703 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) {
1253 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1704 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1254 AnimationContainerElement* element = animator.get(); 1705 AnimationContainerElement* element = animator.get();
1255 animator->set_disable_timer_for_test(true); 1706 animator->set_disable_timer_for_test(true);
1256 1707
1257 TestImplicitAnimationObserver observer(false); 1708 TestImplicitAnimationObserver observer(false);
1258 TestLayerAnimationDelegate delegate; 1709 TestLayerAnimationDelegate delegate;
1259 animator->SetDelegate(&delegate); 1710 animator->SetDelegate(&delegate);
1260 1711
1261 delegate.SetOpacityFromAnimation(0.0f); 1712 delegate.SetBrightnessFromAnimation(0.0f);
1262 1713
1263 { 1714 {
1264 ScopedLayerAnimationSettings setter(animator.get()); 1715 ScopedLayerAnimationSettings setter(animator.get());
1265 1716
1266 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1717 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1267 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1718 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1268 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1719 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1269 1720
1270 animator->StartAnimation(sequence); 1721 animator->StartAnimation(sequence);
1271 base::TimeTicks start_time = animator->last_step_time(); 1722 base::TimeTicks start_time = animator->last_step_time();
1272 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1723 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1273 1724
1274 setter.AddObserver(&observer); 1725 setter.AddObserver(&observer);
1275 1726
1276 // Start observing an in-flight animation. 1727 // Start observing an in-flight animation.
1277 sequence->AddObserver(&observer); 1728 sequence->AddObserver(&observer);
1278 1729
1279 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1730 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1280 } 1731 }
1281 1732
1282 EXPECT_TRUE(observer.animations_completed()); 1733 EXPECT_TRUE(observer.animations_completed());
1283 } 1734 }
1284 1735
1285 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { 1736 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) {
1286 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); 1737 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
1287 AnimationContainerElement* element = animator.get(); 1738 AnimationContainerElement* element = animator.get();
1288 animator->set_disable_timer_for_test(true); 1739 animator->set_disable_timer_for_test(true);
1289 1740
1290 TestImplicitAnimationObserver observer(false); 1741 TestImplicitAnimationObserver observer(false);
1291 TestLayerAnimationDelegate delegate; 1742 TestLayerAnimationDelegate delegate;
1292 animator->SetDelegate(&delegate); 1743 animator->SetDelegate(&delegate);
1293 1744
1294 delegate.SetOpacityFromAnimation(0.0f); 1745 delegate.SetBrightnessFromAnimation(0.0f);
1295 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 1746 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1296 LayerAnimationSequence* sequence = new LayerAnimationSequence( 1747 LayerAnimationSequence* sequence = new LayerAnimationSequence(
1297 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 1748 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1298 1749
1299 { 1750 {
1300 ScopedLayerAnimationSettings setter(animator.get()); 1751 ScopedLayerAnimationSettings setter(animator.get());
1301 setter.AddObserver(&observer); 1752 setter.AddObserver(&observer);
1302 1753
1303 animator->StartAnimation(sequence); 1754 animator->StartAnimation(sequence);
1304 base::TimeTicks start_time = animator->last_step_time(); 1755 base::TimeTicks start_time = animator->last_step_time();
1305 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); 1756 element->Step(start_time + base::TimeDelta::FromMilliseconds(500));
1306 } 1757 }
1307 1758
(...skipping 11 matching lines...) Expand all
1319 // causes the second to be deleted, we should not attempt to animate the second 1770 // causes the second to be deleted, we should not attempt to animate the second
1320 // animation. 1771 // animation.
1321 TEST(LayerAnimatorTest, ObserverDeletesAnimations) { 1772 TEST(LayerAnimatorTest, ObserverDeletesAnimations) {
1322 LayerAnimator::set_disable_animations_for_test(false); 1773 LayerAnimator::set_disable_animations_for_test(false);
1323 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); 1774 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator());
1324 AnimationContainerElement* element = animator.get(); 1775 AnimationContainerElement* element = animator.get();
1325 animator->set_disable_timer_for_test(true); 1776 animator->set_disable_timer_for_test(true);
1326 TestLayerAnimationDelegate delegate; 1777 TestLayerAnimationDelegate delegate;
1327 animator->SetDelegate(&delegate); 1778 animator->SetDelegate(&delegate);
1328 1779
1329 double start_opacity(0.0); 1780 double start_brightness(0.0);
1330 double target_opacity(1.0); 1781 double target_brightness(1.0);
1331 1782
1332 gfx::Rect start_bounds(0, 0, 50, 50); 1783 gfx::Rect start_bounds(0, 0, 50, 50);
1333 gfx::Rect target_bounds(5, 5, 5, 5); 1784 gfx::Rect target_bounds(5, 5, 5, 5);
1334 1785
1335 delegate.SetOpacityFromAnimation(start_opacity); 1786 delegate.SetBrightnessFromAnimation(start_brightness);
1336 delegate.SetBoundsFromAnimation(start_bounds); 1787 delegate.SetBoundsFromAnimation(start_bounds);
1337 1788
1338 base::TimeDelta opacity_delta = base::TimeDelta::FromSeconds(1); 1789 base::TimeDelta brightness_delta = base::TimeDelta::FromSeconds(1);
1339 base::TimeDelta halfway_delta = base::TimeDelta::FromSeconds(2); 1790 base::TimeDelta halfway_delta = base::TimeDelta::FromSeconds(2);
1340 base::TimeDelta bounds_delta = base::TimeDelta::FromSeconds(3); 1791 base::TimeDelta bounds_delta = base::TimeDelta::FromSeconds(3);
1341 1792
1342 LayerAnimationSequence* to_delete = new LayerAnimationSequence( 1793 LayerAnimationSequence* to_delete = new LayerAnimationSequence(
1343 LayerAnimationElement::CreateBoundsElement(target_bounds, bounds_delta)); 1794 LayerAnimationElement::CreateBoundsElement(target_bounds, bounds_delta));
1344 1795
1345 scoped_ptr<DeletingLayerAnimationObserver> observer( 1796 scoped_ptr<DeletingLayerAnimationObserver> observer(
1346 new DeletingLayerAnimationObserver(animator.get(), to_delete)); 1797 new DeletingLayerAnimationObserver(animator.get(), to_delete));
1347 1798
1348 animator->AddObserver(observer.get()); 1799 animator->AddObserver(observer.get());
1349 1800
1350 animator->StartAnimation( 1801 animator->StartAnimation(
1351 new LayerAnimationSequence( 1802 new LayerAnimationSequence(
1352 LayerAnimationElement::CreateOpacityElement( 1803 LayerAnimationElement::CreateBrightnessElement(
1353 target_opacity, opacity_delta))); 1804 target_brightness, brightness_delta)));
1354 1805
1355 animator->StartAnimation(to_delete); 1806 animator->StartAnimation(to_delete);
1356 1807
1357 base::TimeTicks start_time = animator->last_step_time(); 1808 base::TimeTicks start_time = animator->last_step_time();
1358 element->Step(start_time + halfway_delta); 1809 element->Step(start_time + halfway_delta);
1359 1810
1360 animator->RemoveObserver(observer.get()); 1811 animator->RemoveObserver(observer.get());
1361 } 1812 }
1362 1813
1363 // Check that setting a property during an animation with a default animator 1814 // Check that setting a property during an animation with a default animator
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 bool observer_was_deleted = false; 2080 bool observer_was_deleted = false;
1630 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); 2081 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted);
1631 observer->set_delete_on_animation_ended(true); 2082 observer->set_delete_on_animation_ended(true);
1632 observer->set_delete_on_animation_aborted(true); 2083 observer->set_delete_on_animation_aborted(true);
1633 LayerAnimator* animator = observer->animator(); 2084 LayerAnimator* animator = observer->animator();
1634 AnimationContainerElement* element = observer->animator(); 2085 AnimationContainerElement* element = observer->animator();
1635 animator->set_disable_timer_for_test(true); 2086 animator->set_disable_timer_for_test(true);
1636 TestLayerAnimationDelegate delegate; 2087 TestLayerAnimationDelegate delegate;
1637 animator->SetDelegate(&delegate); 2088 animator->SetDelegate(&delegate);
1638 2089
1639 delegate.SetOpacityFromAnimation(0.0f); 2090 delegate.SetBrightnessFromAnimation(0.0f);
1640 2091
1641 gfx::Rect start_bounds(0, 0, 50, 50); 2092 gfx::Rect start_bounds(0, 0, 50, 50);
1642 gfx::Rect target_bounds(10, 10, 100, 100); 2093 gfx::Rect target_bounds(10, 10, 100, 100);
1643 2094
1644 delegate.SetBoundsFromAnimation(start_bounds); 2095 delegate.SetBoundsFromAnimation(start_bounds);
1645 2096
1646 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 2097 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
1647 LayerAnimationSequence* opacity_sequence = new LayerAnimationSequence( 2098 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence(
1648 LayerAnimationElement::CreateOpacityElement(1.0f, delta)); 2099 LayerAnimationElement::CreateBrightnessElement(1.0f, delta));
1649 animator->StartAnimation(opacity_sequence); 2100 animator->StartAnimation(brightness_sequence);
1650 2101
1651 delta = base::TimeDelta::FromSeconds(2); 2102 delta = base::TimeDelta::FromSeconds(2);
1652 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( 2103 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence(
1653 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); 2104 LayerAnimationElement::CreateBoundsElement(target_bounds, delta));
1654 animator->StartAnimation(bounds_sequence); 2105 animator->StartAnimation(bounds_sequence);
1655 2106
1656 base::TimeTicks start_time = animator->last_step_time(); 2107 base::TimeTicks start_time = animator->last_step_time();
1657 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); 2108 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500));
1658 2109
1659 EXPECT_TRUE(observer_was_deleted); 2110 EXPECT_TRUE(observer_was_deleted);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 2235
1785 settings.SetPreemptionStrategy( 2236 settings.SetPreemptionStrategy(
1786 LayerAnimator::ENQUEUE_NEW_ANIMATION); 2237 LayerAnimator::ENQUEUE_NEW_ANIMATION);
1787 settings.SetTransitionDuration(base::TimeDelta()); 2238 settings.SetTransitionDuration(base::TimeDelta());
1788 animator->SetOpacity(magic_opacity); 2239 animator->SetOpacity(magic_opacity);
1789 2240
1790 EXPECT_EQ(start_opacity, delegate.GetOpacityForAnimation()); 2241 EXPECT_EQ(start_opacity, delegate.GetOpacityForAnimation());
1791 } 2242 }
1792 2243
1793 } // namespace ui 2244 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698