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