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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 KeyframedTransformAnimationCurve::Create()); | 516 KeyframedTransformAnimationCurve::Create()); |
517 | 517 |
518 TransformOperations operations1; | 518 TransformOperations operations1; |
519 curve->AddKeyframe(TransformKeyframe::Create( | 519 curve->AddKeyframe(TransformKeyframe::Create( |
520 0.0, operations1, scoped_ptr<TimingFunction>())); | 520 0.0, operations1, scoped_ptr<TimingFunction>())); |
521 operations1.AppendScale(2.f, -3.f, 1.f); | 521 operations1.AppendScale(2.f, -3.f, 1.f); |
522 curve->AddKeyframe(TransformKeyframe::Create( | 522 curve->AddKeyframe(TransformKeyframe::Create( |
523 1.0, operations1, EaseTimingFunction::Create())); | 523 1.0, operations1, EaseTimingFunction::Create())); |
524 | 524 |
525 float maximum_scale = 0.f; | 525 float maximum_scale = 0.f; |
526 EXPECT_TRUE(curve->MaximumScale(&maximum_scale)); | 526 EXPECT_TRUE(curve->MaximumTargetScale(&maximum_scale)); |
527 EXPECT_EQ(3.f, maximum_scale); | 527 EXPECT_EQ(3.f, maximum_scale); |
528 | 528 |
529 TransformOperations operations2; | 529 TransformOperations operations2; |
530 operations2.AppendScale(6.f, 3.f, 2.f); | 530 operations2.AppendScale(6.f, 3.f, 2.f); |
531 curve->AddKeyframe(TransformKeyframe::Create( | 531 curve->AddKeyframe(TransformKeyframe::Create( |
532 2.0, operations2, EaseTimingFunction::Create())); | 532 2.0, operations2, EaseTimingFunction::Create())); |
533 | 533 |
534 EXPECT_TRUE(curve->MaximumScale(&maximum_scale)); | 534 EXPECT_TRUE(curve->MaximumTargetScale(&maximum_scale)); |
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->MaximumTargetScale(&maximum_scale)); |
| 543 |
| 544 // The original scale is not used in computing the max. |
| 545 scoped_ptr<KeyframedTransformAnimationCurve> curve2( |
| 546 KeyframedTransformAnimationCurve::Create()); |
| 547 |
| 548 TransformOperations operations4; |
| 549 curve2->AddKeyframe(TransformKeyframe::Create( |
| 550 0.0, operations4, EaseTimingFunction::Create())); |
| 551 operations4.AppendScale(0.5f, 0.3f, -0.8f); |
| 552 curve2->AddKeyframe(TransformKeyframe::Create( |
| 553 1.0, operations4, EaseTimingFunction::Create())); |
| 554 |
| 555 EXPECT_TRUE(curve2->MaximumTargetScale(&maximum_scale)); |
| 556 EXPECT_EQ(0.8f, maximum_scale); |
543 } | 557 } |
544 | 558 |
545 // Tests that an animation with a curve timing function works as expected. | 559 // Tests that an animation with a curve timing function works as expected. |
546 TEST(KeyframedAnimationCurveTest, CurveTiming) { | 560 TEST(KeyframedAnimationCurveTest, CurveTiming) { |
547 scoped_ptr<KeyframedFloatAnimationCurve> curve( | 561 scoped_ptr<KeyframedFloatAnimationCurve> curve( |
548 KeyframedFloatAnimationCurve::Create()); | 562 KeyframedFloatAnimationCurve::Create()); |
549 curve->AddKeyframe( | 563 curve->AddKeyframe( |
550 FloatKeyframe::Create(0.0, 0.f, scoped_ptr<TimingFunction>())); | 564 FloatKeyframe::Create(0.0, 0.f, scoped_ptr<TimingFunction>())); |
551 curve->AddKeyframe( | 565 curve->AddKeyframe( |
552 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); | 566 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>())); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 FloatKeyframe::Create(4.0, 9.f, scoped_ptr<TimingFunction>())); | 644 FloatKeyframe::Create(4.0, 9.f, scoped_ptr<TimingFunction>())); |
631 // Curve timing function producing outputs outside of range [0,1]. | 645 // Curve timing function producing outputs outside of range [0,1]. |
632 curve->SetTimingFunction( | 646 curve->SetTimingFunction( |
633 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); | 647 CubicBezierTimingFunction::Create(0.5f, -0.5f, 0.5f, 1.5f).Pass()); |
634 EXPECT_LE(curve->GetValue(1.f), 0.f); // c(.25) < 0 | 648 EXPECT_LE(curve->GetValue(1.f), 0.f); // c(.25) < 0 |
635 EXPECT_GE(curve->GetValue(3.f), 9.f); // c(.75) > 1 | 649 EXPECT_GE(curve->GetValue(3.f), 9.f); // c(.75) > 1 |
636 } | 650 } |
637 | 651 |
638 } // namespace | 652 } // namespace |
639 } // namespace cc | 653 } // namespace cc |
OLD | NEW |