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