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

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

Powered by Google App Engine
This is Rietveld 408576698