OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/animation/keyframed_animation_curve.h" | 5 #include "cc/animation/keyframed_animation_curve.h" |
6 | 6 |
7 #include "cc/animation/transform_operations.h" | 7 #include "cc/animation/transform_operations.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/animation/tween.h" | 10 #include "ui/gfx/animation/tween.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); | 433 EXPECT_FLOAT_EQ(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.f))); |
434 EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 434 EXPECT_LT(0.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
435 EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); | 435 EXPECT_GT(0.25f, curve->GetValue(base::TimeDelta::FromSecondsD(0.25f))); |
436 EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f, | 436 EXPECT_NEAR(curve->GetValue(base::TimeDelta::FromSecondsD(0.5f)), 0.5f, |
437 0.00015f); | 437 0.00015f); |
438 EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 438 EXPECT_LT(0.75f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
439 EXPECT_GT(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); | 439 EXPECT_GT(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(0.75f))); |
440 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); | 440 EXPECT_FLOAT_EQ(1.f, curve->GetValue(base::TimeDelta::FromSecondsD(1.f))); |
441 } | 441 } |
442 | 442 |
443 // Tests that a steps timing function works as expected. | |
ajuma
2014/12/17 16:32:55
Please add a few words so that it explains how thi
| |
444 TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtStart) { | |
ajuma
2014/12/17 16:32:55
Style nit: no underscore in the test name. (Same f
| |
445 scoped_ptr<KeyframedFloatAnimationCurve> curve( | |
446 KeyframedFloatAnimationCurve::Create()); | |
447 const int num_steps = 36; | |
448 const float steps_start_offset = 1.0f; | |
449 curve->AddKeyframe(FloatKeyframe::Create( | |
450 base::TimeDelta(), 0.f, | |
451 StepsTimingFunction::Create(num_steps, steps_start_offset))); | |
452 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
453 num_steps, nullptr)); | |
454 | |
455 const float time_threshold = 0.0001f; | |
456 | |
457 for (float i = 0; i < num_steps; i += 1.0f) { | |
ajuma
2014/12/17 16:32:56
0.f
loyso (OOO)
2014/12/18 01:53:05
Do we have a rationale behind it (any references t
ajuma
2014/12/18 02:15:41
Not sure if it's documented anywhere, but this is
loyso (OOO)
2014/12/18 03:17:30
Ok, I'll make it consistent to cc/ folder. Overall
| |
458 const base::TimeDelta time1 = | |
459 base::TimeDelta::FromSecondsD(i / num_steps - time_threshold); | |
460 const base::TimeDelta time2 = | |
461 base::TimeDelta::FromSecondsD(i / num_steps + time_threshold); | |
462 EXPECT_FLOAT_EQ(ceil(i), curve->GetValue(time1)); | |
463 EXPECT_FLOAT_EQ(ceil(i) + 1, curve->GetValue(time2)); | |
ajuma
2014/12/17 16:32:56
1.f
| |
464 } | |
465 EXPECT_FLOAT_EQ(num_steps, | |
466 curve->GetValue(base::TimeDelta::FromSecondsD(1.0f))); | |
467 | |
468 for (float i = 0.5f; i <= num_steps; i += 1.0f) { | |
469 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | |
470 EXPECT_FLOAT_EQ(ceil(i), curve->GetValue(time)); | |
471 } | |
472 } | |
473 | |
474 // Tests that a steps timing function works as expected. | |
475 TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtMiddle) { | |
476 scoped_ptr<KeyframedFloatAnimationCurve> curve( | |
477 KeyframedFloatAnimationCurve::Create()); | |
478 const int num_steps = 36; | |
479 const float steps_start_offset = 0.5f; | |
480 curve->AddKeyframe(FloatKeyframe::Create( | |
481 base::TimeDelta(), 0.f, | |
482 StepsTimingFunction::Create(num_steps, steps_start_offset))); | |
483 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
484 num_steps, nullptr)); | |
485 | |
486 const float time_threshold = 0.0001f; | |
487 | |
488 EXPECT_FLOAT_EQ(0, curve->GetValue(base::TimeDelta())); | |
ajuma
2014/12/17 16:32:55
0.f
| |
489 for (float i = 0.5f; i < num_steps; i += 1.0f) { | |
490 const base::TimeDelta time1 = | |
491 base::TimeDelta::FromSecondsD(i / num_steps - time_threshold); | |
492 const base::TimeDelta time2 = | |
493 base::TimeDelta::FromSecondsD(i / num_steps + time_threshold); | |
494 EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time1)); | |
495 EXPECT_FLOAT_EQ(floor(i) + 1.0f, curve->GetValue(time2)); | |
496 } | |
497 EXPECT_FLOAT_EQ(num_steps, | |
498 curve->GetValue(base::TimeDelta::FromSecondsD(1.0f))); | |
499 | |
500 for (float i = 0.25f; i <= num_steps; i += 1.0f) { | |
501 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | |
502 EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time)); | |
503 } | |
504 } | |
505 | |
506 // Tests that a steps timing function works as expected. | |
507 TEST(KeyframedAnimationCurveTest, StepsTimingFunction_StepAtEnd) { | |
508 scoped_ptr<KeyframedFloatAnimationCurve> curve( | |
509 KeyframedFloatAnimationCurve::Create()); | |
510 const int num_steps = 36; | |
511 const float steps_start_offset = 0.0f; | |
512 curve->AddKeyframe(FloatKeyframe::Create( | |
513 base::TimeDelta(), 0.f, | |
514 StepsTimingFunction::Create(num_steps, steps_start_offset))); | |
515 curve->AddKeyframe(FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
516 num_steps, nullptr)); | |
517 | |
518 const float time_threshold = 0.0001f; | |
519 | |
520 EXPECT_FLOAT_EQ(0, curve->GetValue(base::TimeDelta())); | |
ajuma
2014/12/17 16:32:55
0.f
| |
521 for (float i = 1; i <= num_steps; i += 1.0f) { | |
ajuma
2014/12/17 16:32:56
1.f
| |
522 const base::TimeDelta time1 = | |
523 base::TimeDelta::FromSecondsD(i / num_steps - time_threshold); | |
524 const base::TimeDelta time2 = | |
525 base::TimeDelta::FromSecondsD(i / num_steps + time_threshold); | |
526 EXPECT_FLOAT_EQ(floor(i) - 1, curve->GetValue(time1)); | |
ajuma
2014/12/17 16:32:55
1.f
| |
527 EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time2)); | |
528 } | |
529 EXPECT_FLOAT_EQ(num_steps, | |
530 curve->GetValue(base::TimeDelta::FromSecondsD(1.0f))); | |
531 | |
532 for (float i = 0.5f; i <= num_steps; i += 1.0f) { | |
533 const base::TimeDelta time = base::TimeDelta::FromSecondsD(i / num_steps); | |
534 EXPECT_FLOAT_EQ(floor(i), curve->GetValue(time)); | |
535 } | |
536 } | |
537 | |
443 // Tests that animated bounds are computed as expected. | 538 // Tests that animated bounds are computed as expected. |
444 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { | 539 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { |
445 scoped_ptr<KeyframedTransformAnimationCurve> curve( | 540 scoped_ptr<KeyframedTransformAnimationCurve> curve( |
446 KeyframedTransformAnimationCurve::Create()); | 541 KeyframedTransformAnimationCurve::Create()); |
447 | 542 |
448 TransformOperations operations1; | 543 TransformOperations operations1; |
449 curve->AddKeyframe( | 544 curve->AddKeyframe( |
450 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); | 545 TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr)); |
451 operations1.AppendTranslate(2.0, 3.0, -1.0); | 546 operations1.AppendTranslate(2.0, 3.0, -1.0); |
452 curve->AddKeyframe(TransformKeyframe::Create( | 547 curve->AddKeyframe(TransformKeyframe::Create( |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 curve->SetTimingFunction( | 772 curve->SetTimingFunction( |
678 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); | 773 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
679 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), | 774 EXPECT_LE(curve->GetValue(base::TimeDelta::FromSecondsD(1.f)), |
680 0.f); // c(.25) < 0 | 775 0.f); // c(.25) < 0 |
681 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), | 776 EXPECT_GE(curve->GetValue(base::TimeDelta::FromSecondsD(3.f)), |
682 9.f); // c(.75) > 1 | 777 9.f); // c(.75) > 1 |
683 } | 778 } |
684 | 779 |
685 } // namespace | 780 } // namespace |
686 } // namespace cc | 781 } // namespace cc |
OLD | NEW |