diff options
author | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 05:35:31 +0000 |
---|---|---|
committer | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 05:35:31 +0000 |
commit | 205ab445370f249af1702567cd59712dbe7fdae9 (patch) | |
tree | 833cba74a79dd89ecb8dea1502731ca5798b1059 /cc/animation/keyframed_animation_curve_unittest.cc | |
parent | e7d6ebf0e5a8ab46b7f0e3b934a54b728d52657e (diff) | |
download | chromium_src-205ab445370f249af1702567cd59712dbe7fdae9.zip chromium_src-205ab445370f249af1702567cd59712dbe7fdae9.tar.gz chromium_src-205ab445370f249af1702567cd59712dbe7fdae9.tar.bz2 |
Define cc::FilterKeyframe and cc::KeyframedFilterAnimationCurve
These are needed for threading filter animations.
BUG=181613
Review URL: https://chromiumcodereview.appspot.com/19114002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation/keyframed_animation_curve_unittest.cc')
-rw-r--r-- | cc/animation/keyframed_animation_curve_unittest.cc | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/cc/animation/keyframed_animation_curve_unittest.cc b/cc/animation/keyframed_animation_curve_unittest.cc index dac393e..32efc14 100644 --- a/cc/animation/keyframed_animation_curve_unittest.cc +++ b/cc/animation/keyframed_animation_curve_unittest.cc @@ -15,6 +15,12 @@ void ExpectTranslateX(double translate_x, const gfx::Transform& transform) { EXPECT_FLOAT_EQ(translate_x, transform.matrix().getDouble(0, 3)); } +void ExpectBrightness(double brightness, const FilterOperations& filter) { + EXPECT_EQ(1u, filter.size()); + EXPECT_EQ(FilterOperation::BRIGHTNESS, filter.at(0).type()); + EXPECT_FLOAT_EQ(brightness, filter.at(0).amount()); +} + // Tests that a float animation with one keyframe works as expected. TEST(KeyframedAnimationCurveTest, OneFloatKeyframe) { scoped_ptr<KeyframedFloatAnimationCurve> curve( @@ -186,6 +192,106 @@ TEST(KeyframedAnimationCurveTest, RepeatedTransformKeyTimes) { ExpectTranslateX(6.f, curve->GetValue(3.f)); } +// Tests that a filter animation with one keyframe works as expected. +TEST(KeyframedAnimationCurveTest, OneFilterKeyframe) { + scoped_ptr<KeyframedFilterAnimationCurve> curve( + KeyframedFilterAnimationCurve::Create()); + FilterOperations operations; + operations.Append(FilterOperation::CreateBrightnessFilter(2.f)); + curve->AddKeyframe( + FilterKeyframe::Create(0.f, operations, scoped_ptr<TimingFunction>())); + + ExpectBrightness(2.f, curve->GetValue(-1.f)); + ExpectBrightness(2.f, curve->GetValue(0.f)); + ExpectBrightness(2.f, curve->GetValue(0.5f)); + ExpectBrightness(2.f, curve->GetValue(1.f)); + ExpectBrightness(2.f, curve->GetValue(2.f)); +} + +// Tests that a filter animation with two keyframes works as expected. +TEST(KeyframedAnimationCurveTest, TwoFilterKeyframe) { + scoped_ptr<KeyframedFilterAnimationCurve> curve( + KeyframedFilterAnimationCurve::Create()); + FilterOperations operations1; + operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); + FilterOperations operations2; + operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); + + curve->AddKeyframe(FilterKeyframe::Create( + 0.f, operations1, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 1.f, operations2, scoped_ptr<TimingFunction>())); + ExpectBrightness(2.f, curve->GetValue(-1.f)); + ExpectBrightness(2.f, curve->GetValue(0.f)); + ExpectBrightness(3.f, curve->GetValue(0.5f)); + ExpectBrightness(4.f, curve->GetValue(1.f)); + ExpectBrightness(4.f, curve->GetValue(2.f)); +} + +// Tests that a filter animation with three keyframes works as expected. +TEST(KeyframedAnimationCurveTest, ThreeFilterKeyframe) { + scoped_ptr<KeyframedFilterAnimationCurve> curve( + KeyframedFilterAnimationCurve::Create()); + FilterOperations operations1; + operations1.Append(FilterOperation::CreateBrightnessFilter(2.f)); + FilterOperations operations2; + operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); + FilterOperations operations3; + operations3.Append(FilterOperation::CreateBrightnessFilter(8.f)); + curve->AddKeyframe(FilterKeyframe::Create( + 0.f, operations1, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 1.f, operations2, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 2.f, operations3, scoped_ptr<TimingFunction>())); + ExpectBrightness(2.f, curve->GetValue(-1.f)); + ExpectBrightness(2.f, curve->GetValue(0.f)); + ExpectBrightness(3.f, curve->GetValue(0.5f)); + ExpectBrightness(4.f, curve->GetValue(1.f)); + ExpectBrightness(6.f, curve->GetValue(1.5f)); + ExpectBrightness(8.f, curve->GetValue(2.f)); + ExpectBrightness(8.f, curve->GetValue(3.f)); +} + +// Tests that a filter animation with multiple keys at a given time works +// sanely. +TEST(KeyframedAnimationCurveTest, RepeatedFilterKeyTimes) { + scoped_ptr<KeyframedFilterAnimationCurve> curve( + KeyframedFilterAnimationCurve::Create()); + // A step function. + FilterOperations operations1; + operations1.Append(FilterOperation::CreateBrightnessFilter(4.f)); + FilterOperations operations2; + operations2.Append(FilterOperation::CreateBrightnessFilter(4.f)); + FilterOperations operations3; + operations3.Append(FilterOperation::CreateBrightnessFilter(6.f)); + FilterOperations operations4; + operations4.Append(FilterOperation::CreateBrightnessFilter(6.f)); + curve->AddKeyframe(FilterKeyframe::Create( + 0.f, operations1, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 1.f, operations2, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 1.f, operations3, scoped_ptr<TimingFunction>())); + curve->AddKeyframe(FilterKeyframe::Create( + 2.f, operations4, scoped_ptr<TimingFunction>())); + + ExpectBrightness(4.f, curve->GetValue(-1.f)); + ExpectBrightness(4.f, curve->GetValue(0.f)); + ExpectBrightness(4.f, curve->GetValue(0.5f)); + + // There is a discontinuity at 1. Any value between 4 and 6 is valid. + FilterOperations value = curve->GetValue(1.f); + EXPECT_EQ(1u, value.size()); + EXPECT_EQ(FilterOperation::BRIGHTNESS, value.at(0).type()); + EXPECT_GE(value.at(0).amount(), 4); + EXPECT_LE(value.at(0).amount(), 6); + + ExpectBrightness(6.f, curve->GetValue(1.5f)); + ExpectBrightness(6.f, curve->GetValue(2.f)); + ExpectBrightness(6.f, curve->GetValue(3.f)); +} + // Tests that the keyframes may be added out of order. TEST(KeyframedAnimationCurveTest, UnsortedKeyframes) { scoped_ptr<KeyframedFloatAnimationCurve> curve( |