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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EXPECT_EQ(6.f, maximum_scale); | 538 EXPECT_EQ(6.f, maximum_scale); |
539 | 539 |
540 TransformOperations operations3; | 540 TransformOperations operations3; |
541 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); | 541 operations3.AppendRotate(1.f, 0.f, 0.f, 90.f); |
542 curve->AddKeyframe(TransformKeyframe::Create( | 542 curve->AddKeyframe(TransformKeyframe::Create( |
543 3.0, operations3, EaseTimingFunction::Create())); | 543 3.0, operations3, EaseTimingFunction::Create())); |
544 | 544 |
545 EXPECT_FALSE(curve->MaximumScale(&maximum_scale)); | 545 EXPECT_FALSE(curve->MaximumScale(&maximum_scale)); |
546 } | 546 } |
547 | 547 |
| 548 // Tests that an animation with a curve timing function works as expected. |
| 549 TEST(KeyframedAnimationCurveTest, CurveTiming) { |
| 550 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 551 KeyframedFloatAnimationCurve::Create()); |
| 552 curve->AddKeyframe( |
| 553 FloatKeyframe::Create(0.0, 0.f, scoped_ptr<TimingFunction>())); |
| 554 curve->AddKeyframe( |
| 555 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); |
| 556 curve->SetTimingFunction( |
| 557 CubicBezierTimingFunction::Create(0.75f, 0.f, 0.25f, 1.f) |
| 558 .PassAs<TimingFunction>()); |
| 559 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); |
| 560 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); |
| 561 EXPECT_NEAR(0.05f, curve->GetValue(0.25f), 0.005f); |
| 562 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f)); |
| 563 EXPECT_NEAR(0.95f, curve->GetValue(0.75f), 0.005f); |
| 564 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); |
| 565 EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f)); |
| 566 } |
| 567 |
| 568 // Tests that an animation with a curve and keyframe timing function works as |
| 569 // expected. |
| 570 TEST(KeyframedAnimationCurveTest, CurveAndKeyframeTiming) { |
| 571 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 572 KeyframedFloatAnimationCurve::Create()); |
| 573 curve->AddKeyframe(FloatKeyframe::Create( |
| 574 0.0, |
| 575 0.f, |
| 576 CubicBezierTimingFunction::Create(0.35f, 0.f, 0.65f, 1.f) |
| 577 .PassAs<TimingFunction>())); |
| 578 curve->AddKeyframe( |
| 579 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); |
| 580 // Curve timing function producing outputs outside of range [0,1]. |
| 581 curve->SetTimingFunction( |
| 582 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f) |
| 583 .PassAs<TimingFunction>()); |
| 584 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); |
| 585 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); |
| 586 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.25f)); // Clamped. c(.25) < 0 |
| 587 EXPECT_NEAR(0.17f, curve->GetValue(0.42f), 0.005f); // c(.42)=.27, k(.27)=.17 |
| 588 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f)); |
| 589 EXPECT_NEAR(0.83f, curve->GetValue(0.58f), 0.005f); // c(.58)=.73, k(.73)=.83 |
| 590 EXPECT_FLOAT_EQ(1.f, curve->GetValue(0.75f)); // Clamped. c(.75) > 1 |
| 591 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); |
| 592 EXPECT_FLOAT_EQ(1.f, curve->GetValue(2.f)); |
| 593 } |
| 594 |
| 595 // Tests that an animation with a curve timing function and multiple keyframes |
| 596 // works as expected. |
| 597 TEST(KeyframedAnimationCurveTest, CurveTimingMultipleKeyframes) { |
| 598 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 599 KeyframedFloatAnimationCurve::Create()); |
| 600 curve->AddKeyframe( |
| 601 FloatKeyframe::Create(0.0, 0.f, scoped_ptr<TimingFunction>())); |
| 602 curve->AddKeyframe( |
| 603 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); |
| 604 curve->AddKeyframe( |
| 605 FloatKeyframe::Create(2.0, 3.f, scoped_ptr<TimingFunction>())); |
| 606 curve->AddKeyframe( |
| 607 FloatKeyframe::Create(3.0, 6.f, scoped_ptr<TimingFunction>())); |
| 608 curve->AddKeyframe( |
| 609 FloatKeyframe::Create(4.0, 9.f, scoped_ptr<TimingFunction>())); |
| 610 curve->SetTimingFunction(CubicBezierTimingFunction::Create( |
| 611 0.5f, 0.f, 0.5f, 1.f).PassAs<TimingFunction>()); |
| 612 EXPECT_FLOAT_EQ(0.f, curve->GetValue(-1.f)); |
| 613 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); |
| 614 EXPECT_NEAR(0.42f, curve->GetValue(1.f), 0.005f); |
| 615 EXPECT_NEAR(1.f, curve->GetValue(1.455f), 0.005f); |
| 616 EXPECT_FLOAT_EQ(3.f, curve->GetValue(2.f)); |
| 617 EXPECT_NEAR(8.72f, curve->GetValue(3.5f), 0.01f); |
| 618 EXPECT_FLOAT_EQ(9.f, curve->GetValue(4.f)); |
| 619 EXPECT_FLOAT_EQ(9.f, curve->GetValue(5.f)); |
| 620 } |
| 621 |
| 622 // Tests that an animation with a curve timing function that overshoots works as |
| 623 // expected. |
| 624 TEST(KeyframedAnimationCurveTest, CurveTimingOvershootMultipeKeyframes) { |
| 625 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 626 KeyframedFloatAnimationCurve::Create()); |
| 627 curve->AddKeyframe( |
| 628 FloatKeyframe::Create(0.0, 0.f, scoped_ptr<TimingFunction>())); |
| 629 curve->AddKeyframe( |
| 630 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); |
| 631 curve->AddKeyframe( |
| 632 FloatKeyframe::Create(2.0, 3.f, scoped_ptr<TimingFunction>())); |
| 633 curve->AddKeyframe( |
| 634 FloatKeyframe::Create(3.0, 6.f, scoped_ptr<TimingFunction>())); |
| 635 curve->AddKeyframe( |
| 636 FloatKeyframe::Create(4.0, 9.f, scoped_ptr<TimingFunction>())); |
| 637 // Curve timing function producing outputs outside of range [0,1]. |
| 638 curve->SetTimingFunction( |
| 639 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f) |
| 640 .PassAs<TimingFunction>()); |
| 641 EXPECT_LE(curve->GetValue(1.f), 0.f); // c(.25) < 0 |
| 642 EXPECT_GE(curve->GetValue(3.f), 9.f); // c(.75) > 1 |
| 643 } |
| 644 |
548 } // namespace | 645 } // namespace |
549 } // namespace cc | 646 } // namespace cc |
OLD | NEW |