| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "cc/timing_function.h" | 6 #include "cc/timing_function.h" |
| 7 #include "cc/transform_operations.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati
ons.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformOperati
ons.h" |
| 10 #include "web_transform_animation_curve_impl.h" | 11 #include "web_transform_animation_curve_impl.h" |
| 11 | 12 |
| 12 using namespace WebKit; | 13 using namespace WebKit; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Tests that a transform animation with one keyframe works as expected. | 17 // Tests that a transform animation with one keyframe works as expected. |
| 17 TEST(WebTransformAnimationCurveTest, OneTransformKeyframe) | 18 TEST(WebTransformAnimationCurveTest, OneTransformKeyframe) |
| 18 { | 19 { |
| 19 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 20 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 20 WebKit::WebTransformOperations operations; | 21 scoped_ptr<WebKit::WebTransformOperations> operations( |
| 21 operations.appendTranslate(2, 0, 0); | 22 cc::TransformOperations::Create()); |
| 22 curve->add(WebTransformKeyframe(0, operations), WebAnimationCurve::TimingFun
ctionTypeLinear); | 23 operations->appendTranslate(2, 0, 0); |
| 24 curve->add(WebTransformKeyframe(0, *operations), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 23 | 25 |
| 24 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 26 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
| 25 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 27 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
| 26 EXPECT_FLOAT_EQ(2, curve->getValue(0.5).m41()); | 28 EXPECT_FLOAT_EQ(2, curve->getValue(0.5).m41()); |
| 27 EXPECT_FLOAT_EQ(2, curve->getValue(1).m41()); | 29 EXPECT_FLOAT_EQ(2, curve->getValue(1).m41()); |
| 28 EXPECT_FLOAT_EQ(2, curve->getValue(2).m41()); | 30 EXPECT_FLOAT_EQ(2, curve->getValue(2).m41()); |
| 29 } | 31 } |
| 30 | 32 |
| 31 // Tests that a transform animation with two keyframes works as expected. | 33 // Tests that a transform animation with two keyframes works as expected. |
| 32 TEST(WebTransformAnimationCurveTest, TwoTransformKeyframe) | 34 TEST(WebTransformAnimationCurveTest, TwoTransformKeyframe) |
| 33 { | 35 { |
| 34 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 36 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 35 WebKit::WebTransformOperations operations1; | 37 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 36 operations1.appendTranslate(2, 0, 0); | 38 cc::TransformOperations::Create()); |
| 37 WebKit::WebTransformOperations operations2; | 39 operations1->appendTranslate(2, 0, 0); |
| 38 operations2.appendTranslate(4, 0, 0); | 40 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 39 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 41 cc::TransformOperations::Create()); |
| 40 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 42 operations2->appendTranslate(4, 0, 0); |
| 43 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 44 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 41 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 45 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
| 42 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 46 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
| 43 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 47 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
| 44 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 48 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
| 45 EXPECT_FLOAT_EQ(4, curve->getValue(2).m41()); | 49 EXPECT_FLOAT_EQ(4, curve->getValue(2).m41()); |
| 46 } | 50 } |
| 47 | 51 |
| 48 // Tests that a transform animation with three keyframes works as expected. | 52 // Tests that a transform animation with three keyframes works as expected. |
| 49 TEST(WebTransformAnimationCurveTest, ThreeTransformKeyframe) | 53 TEST(WebTransformAnimationCurveTest, ThreeTransformKeyframe) |
| 50 { | 54 { |
| 51 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 55 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 52 WebKit::WebTransformOperations operations1; | 56 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 53 operations1.appendTranslate(2, 0, 0); | 57 cc::TransformOperations::Create()); |
| 54 WebKit::WebTransformOperations operations2; | 58 operations1->appendTranslate(2, 0, 0); |
| 55 operations2.appendTranslate(4, 0, 0); | 59 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 56 WebKit::WebTransformOperations operations3; | 60 cc::TransformOperations::Create()); |
| 57 operations3.appendTranslate(8, 0, 0); | 61 operations2->appendTranslate(4, 0, 0); |
| 58 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 62 scoped_ptr<WebKit::WebTransformOperations> operations3( |
| 59 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 63 cc::TransformOperations::Create()); |
| 60 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 64 operations3->appendTranslate(8, 0, 0); |
| 65 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 66 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 67 curve->add(WebTransformKeyframe(2, *operations3), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 61 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 68 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
| 62 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 69 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
| 63 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 70 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
| 64 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 71 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
| 65 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 72 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
| 66 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); | 73 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); |
| 67 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); | 74 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); |
| 68 } | 75 } |
| 69 | 76 |
| 70 // Tests that a transform animation with multiple keys at a given time works san
ely. | 77 // Tests that a transform animation with multiple keys at a given time works san
ely. |
| 71 TEST(WebTransformAnimationCurveTest, RepeatedTransformKeyTimes) | 78 TEST(WebTransformAnimationCurveTest, RepeatedTransformKeyTimes) |
| 72 { | 79 { |
| 73 // A step function. | 80 // A step function. |
| 74 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 81 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 75 WebKit::WebTransformOperations operations1; | 82 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 76 operations1.appendTranslate(4, 0, 0); | 83 cc::TransformOperations::Create()); |
| 77 WebKit::WebTransformOperations operations2; | 84 operations1->appendTranslate(4, 0, 0); |
| 78 operations2.appendTranslate(4, 0, 0); | 85 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 79 WebKit::WebTransformOperations operations3; | 86 cc::TransformOperations::Create()); |
| 80 operations3.appendTranslate(6, 0, 0); | 87 operations2->appendTranslate(4, 0, 0); |
| 81 WebKit::WebTransformOperations operations4; | 88 scoped_ptr<WebKit::WebTransformOperations> operations3( |
| 82 operations4.appendTranslate(6, 0, 0); | 89 cc::TransformOperations::Create()); |
| 83 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 90 operations3->appendTranslate(6, 0, 0); |
| 84 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 91 scoped_ptr<WebKit::WebTransformOperations> operations4( |
| 85 curve->add(WebTransformKeyframe(1, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 92 cc::TransformOperations::Create()); |
| 86 curve->add(WebTransformKeyframe(2, operations4), WebAnimationCurve::TimingFu
nctionTypeLinear); | 93 operations4->appendTranslate(6, 0, 0); |
| 94 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 95 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 96 curve->add(WebTransformKeyframe(1, *operations3), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 97 curve->add(WebTransformKeyframe(2, *operations4), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 87 | 98 |
| 88 EXPECT_FLOAT_EQ(4, curve->getValue(-1).m41()); | 99 EXPECT_FLOAT_EQ(4, curve->getValue(-1).m41()); |
| 89 EXPECT_FLOAT_EQ(4, curve->getValue(0).m41()); | 100 EXPECT_FLOAT_EQ(4, curve->getValue(0).m41()); |
| 90 EXPECT_FLOAT_EQ(4, curve->getValue(0.5).m41()); | 101 EXPECT_FLOAT_EQ(4, curve->getValue(0.5).m41()); |
| 91 | 102 |
| 92 // There is a discontinuity at 1. Any value between 4 and 6 is valid. | 103 // There is a discontinuity at 1. Any value between 4 and 6 is valid. |
| 93 WebTransformationMatrix value = curve->getValue(1); | 104 WebTransformationMatrix value = curve->getValue(1); |
| 94 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); | 105 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); |
| 95 | 106 |
| 96 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 107 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
| 97 EXPECT_FLOAT_EQ(6, curve->getValue(2).m41()); | 108 EXPECT_FLOAT_EQ(6, curve->getValue(2).m41()); |
| 98 EXPECT_FLOAT_EQ(6, curve->getValue(3).m41()); | 109 EXPECT_FLOAT_EQ(6, curve->getValue(3).m41()); |
| 99 } | 110 } |
| 100 | 111 |
| 101 // Tests that the keyframes may be added out of order. | 112 // Tests that the keyframes may be added out of order. |
| 102 TEST(WebTransformAnimationCurveTest, UnsortedKeyframes) | 113 TEST(WebTransformAnimationCurveTest, UnsortedKeyframes) |
| 103 { | 114 { |
| 104 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 115 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 105 WebKit::WebTransformOperations operations1; | 116 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 106 operations1.appendTranslate(2, 0, 0); | 117 cc::TransformOperations::Create()); |
| 107 WebKit::WebTransformOperations operations2; | 118 operations1->appendTranslate(2, 0, 0); |
| 108 operations2.appendTranslate(4, 0, 0); | 119 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 109 WebKit::WebTransformOperations operations3; | 120 cc::TransformOperations::Create()); |
| 110 operations3.appendTranslate(8, 0, 0); | 121 operations2->appendTranslate(4, 0, 0); |
| 111 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 122 scoped_ptr<WebKit::WebTransformOperations> operations3( |
| 112 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 123 cc::TransformOperations::Create()); |
| 113 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 124 operations3->appendTranslate(8, 0, 0); |
| 125 curve->add(WebTransformKeyframe(2, *operations3), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 126 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 127 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 114 | 128 |
| 115 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 129 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
| 116 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 130 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
| 117 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 131 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
| 118 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 132 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
| 119 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 133 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
| 120 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); | 134 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); |
| 121 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); | 135 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); |
| 122 } | 136 } |
| 123 | 137 |
| 124 // Tests that a cubic bezier timing function works as expected. | 138 // Tests that a cubic bezier timing function works as expected. |
| 125 TEST(WebTransformAnimationCurveTest, CubicBezierTimingFunction) | 139 TEST(WebTransformAnimationCurveTest, CubicBezierTimingFunction) |
| 126 { | 140 { |
| 127 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 141 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 128 WebKit::WebTransformOperations operations1; | 142 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 129 operations1.appendTranslate(0, 0, 0); | 143 cc::TransformOperations::Create()); |
| 130 WebKit::WebTransformOperations operations2; | 144 operations1->appendTranslate(0, 0, 0); |
| 131 operations2.appendTranslate(1, 0, 0); | 145 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 132 curve->add(WebTransformKeyframe(0, operations1), 0.25, 0, 0.75, 1); | 146 cc::TransformOperations::Create()); |
| 133 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 147 operations2->appendTranslate(1, 0, 0); |
| 148 curve->add(WebTransformKeyframe(0, *operations1), 0.25, 0, 0.75, 1); |
| 149 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 134 EXPECT_FLOAT_EQ(0, curve->getValue(0).m41()); | 150 EXPECT_FLOAT_EQ(0, curve->getValue(0).m41()); |
| 135 EXPECT_LT(0, curve->getValue(0.25).m41()); | 151 EXPECT_LT(0, curve->getValue(0.25).m41()); |
| 136 EXPECT_GT(0.25, curve->getValue(0.25).m41()); | 152 EXPECT_GT(0.25, curve->getValue(0.25).m41()); |
| 137 EXPECT_NEAR(curve->getValue(0.5).m41(), 0.5, 0.00015); | 153 EXPECT_NEAR(curve->getValue(0.5).m41(), 0.5, 0.00015); |
| 138 EXPECT_LT(0.75, curve->getValue(0.75).m41()); | 154 EXPECT_LT(0.75, curve->getValue(0.75).m41()); |
| 139 EXPECT_GT(1, curve->getValue(0.75).m41()); | 155 EXPECT_GT(1, curve->getValue(0.75).m41()); |
| 140 EXPECT_FLOAT_EQ(1, curve->getValue(1).m41()); | 156 EXPECT_FLOAT_EQ(1, curve->getValue(1).m41()); |
| 141 } | 157 } |
| 142 | 158 |
| 143 // Tests that an ease timing function works as expected. | 159 // Tests that an ease timing function works as expected. |
| 144 TEST(WebTransformAnimationCurveTest, EaseTimingFunction) | 160 TEST(WebTransformAnimationCurveTest, EaseTimingFunction) |
| 145 { | 161 { |
| 146 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 162 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 147 WebKit::WebTransformOperations operations1; | 163 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 148 operations1.appendTranslate(0, 0, 0); | 164 cc::TransformOperations::Create()); |
| 149 WebKit::WebTransformOperations operations2; | 165 operations1->appendTranslate(0, 0, 0); |
| 150 operations2.appendTranslate(1, 0, 0); | 166 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 151 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEase); | 167 cc::TransformOperations::Create()); |
| 152 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 168 operations2->appendTranslate(1, 0, 0); |
| 169 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeEase); |
| 170 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 153 | 171 |
| 154 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); | 172 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); |
| 155 for (int i = 0; i <= 4; ++i) { | 173 for (int i = 0; i <= 4; ++i) { |
| 156 const double time = i * 0.25; | 174 const double time = i * 0.25; |
| 157 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 175 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 158 } | 176 } |
| 159 } | 177 } |
| 160 | 178 |
| 161 // Tests using a linear timing function. | 179 // Tests using a linear timing function. |
| 162 TEST(WebTransformAnimationCurveTest, LinearTimingFunction) | 180 TEST(WebTransformAnimationCurveTest, LinearTimingFunction) |
| 163 { | 181 { |
| 164 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 182 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 165 WebKit::WebTransformOperations operations1; | 183 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 166 operations1.appendTranslate(0, 0, 0); | 184 cc::TransformOperations::Create()); |
| 167 WebKit::WebTransformOperations operations2; | 185 operations1->appendTranslate(0, 0, 0); |
| 168 operations2.appendTranslate(1, 0, 0); | 186 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 169 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 187 cc::TransformOperations::Create()); |
| 170 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 188 operations2->appendTranslate(1, 0, 0); |
| 189 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 190 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 171 | 191 |
| 172 for (int i = 0; i <= 4; ++i) { | 192 for (int i = 0; i <= 4; ++i) { |
| 173 const double time = i * 0.25; | 193 const double time = i * 0.25; |
| 174 EXPECT_FLOAT_EQ(time, curve->getValue(time).m41()); | 194 EXPECT_FLOAT_EQ(time, curve->getValue(time).m41()); |
| 175 } | 195 } |
| 176 } | 196 } |
| 177 | 197 |
| 178 // Tests that an ease in timing function works as expected. | 198 // Tests that an ease in timing function works as expected. |
| 179 TEST(WebTransformAnimationCurveTest, EaseInTimingFunction) | 199 TEST(WebTransformAnimationCurveTest, EaseInTimingFunction) |
| 180 { | 200 { |
| 181 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 201 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 182 WebKit::WebTransformOperations operations1; | 202 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 183 operations1.appendTranslate(0, 0, 0); | 203 cc::TransformOperations::Create()); |
| 184 WebKit::WebTransformOperations operations2; | 204 operations1->appendTranslate(0, 0, 0); |
| 185 operations2.appendTranslate(1, 0, 0); | 205 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 186 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseIn); | 206 cc::TransformOperations::Create()); |
| 187 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 207 operations2->appendTranslate(1, 0, 0); |
| 208 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeEaseIn); |
| 209 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 188 | 210 |
| 189 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInTimingFunction::crea
te()); | 211 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInTimingFunction::crea
te()); |
| 190 for (int i = 0; i <= 4; ++i) { | 212 for (int i = 0; i <= 4; ++i) { |
| 191 const double time = i * 0.25; | 213 const double time = i * 0.25; |
| 192 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 214 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 193 } | 215 } |
| 194 } | 216 } |
| 195 | 217 |
| 196 // Tests that an ease in timing function works as expected. | 218 // Tests that an ease in timing function works as expected. |
| 197 TEST(WebTransformAnimationCurveTest, EaseOutTimingFunction) | 219 TEST(WebTransformAnimationCurveTest, EaseOutTimingFunction) |
| 198 { | 220 { |
| 199 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 221 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 200 WebKit::WebTransformOperations operations1; | 222 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 201 operations1.appendTranslate(0, 0, 0); | 223 cc::TransformOperations::Create()); |
| 202 WebKit::WebTransformOperations operations2; | 224 operations1->appendTranslate(0, 0, 0); |
| 203 operations2.appendTranslate(1, 0, 0); | 225 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 204 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseOut); | 226 cc::TransformOperations::Create()); |
| 205 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 227 operations2->appendTranslate(1, 0, 0); |
| 228 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeEaseOut); |
| 229 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 206 | 230 |
| 207 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseOutTimingFunction::cre
ate()); | 231 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseOutTimingFunction::cre
ate()); |
| 208 for (int i = 0; i <= 4; ++i) { | 232 for (int i = 0; i <= 4; ++i) { |
| 209 const double time = i * 0.25; | 233 const double time = i * 0.25; |
| 210 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 234 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 211 } | 235 } |
| 212 } | 236 } |
| 213 | 237 |
| 214 // Tests that an ease in timing function works as expected. | 238 // Tests that an ease in timing function works as expected. |
| 215 TEST(WebTransformAnimationCurveTest, EaseInOutTimingFunction) | 239 TEST(WebTransformAnimationCurveTest, EaseInOutTimingFunction) |
| 216 { | 240 { |
| 217 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 241 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 218 WebKit::WebTransformOperations operations1; | 242 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 219 operations1.appendTranslate(0, 0, 0); | 243 cc::TransformOperations::Create()); |
| 220 WebKit::WebTransformOperations operations2; | 244 operations1->appendTranslate(0, 0, 0); |
| 221 operations2.appendTranslate(1, 0, 0); | 245 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 222 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseInOut); | 246 cc::TransformOperations::Create()); |
| 223 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 247 operations2->appendTranslate(1, 0, 0); |
| 248 curve->add(WebTransformKeyframe(0, *operations1), WebAnimationCurve::TimingF
unctionTypeEaseInOut); |
| 249 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 224 | 250 |
| 225 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInOutTimingFunction::c
reate()); | 251 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInOutTimingFunction::c
reate()); |
| 226 for (int i = 0; i <= 4; ++i) { | 252 for (int i = 0; i <= 4; ++i) { |
| 227 const double time = i * 0.25; | 253 const double time = i * 0.25; |
| 228 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 254 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 229 } | 255 } |
| 230 } | 256 } |
| 231 | 257 |
| 232 // Tests that an ease in timing function works as expected. | 258 // Tests that an ease in timing function works as expected. |
| 233 TEST(WebTransformAnimationCurveTest, CustomBezierTimingFunction) | 259 TEST(WebTransformAnimationCurveTest, CustomBezierTimingFunction) |
| 234 { | 260 { |
| 235 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 261 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 236 double x1 = 0.3; | 262 double x1 = 0.3; |
| 237 double y1 = 0.2; | 263 double y1 = 0.2; |
| 238 double x2 = 0.8; | 264 double x2 = 0.8; |
| 239 double y2 = 0.7; | 265 double y2 = 0.7; |
| 240 WebKit::WebTransformOperations operations1; | 266 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 241 operations1.appendTranslate(0, 0, 0); | 267 cc::TransformOperations::Create()); |
| 242 WebKit::WebTransformOperations operations2; | 268 operations1->appendTranslate(0, 0, 0); |
| 243 operations2.appendTranslate(1, 0, 0); | 269 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 244 curve->add(WebTransformKeyframe(0, operations1), x1, y1, x2, y2); | 270 cc::TransformOperations::Create()); |
| 245 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 271 operations2->appendTranslate(1, 0, 0); |
| 272 curve->add(WebTransformKeyframe(0, *operations1), x1, y1, x2, y2); |
| 273 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 246 | 274 |
| 247 scoped_ptr<cc::TimingFunction> timingFunction(cc::CubicBezierTimingFunction:
:create(x1, y1, x2, y2)); | 275 scoped_ptr<cc::TimingFunction> timingFunction(cc::CubicBezierTimingFunction:
:create(x1, y1, x2, y2)); |
| 248 for (int i = 0; i <= 4; ++i) { | 276 for (int i = 0; i <= 4; ++i) { |
| 249 const double time = i * 0.25; | 277 const double time = i * 0.25; |
| 250 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 278 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 251 } | 279 } |
| 252 } | 280 } |
| 253 | 281 |
| 254 // Tests that the default timing function is indeed ease. | 282 // Tests that the default timing function is indeed ease. |
| 255 TEST(WebTransformAnimationCurveTest, DefaultTimingFunction) | 283 TEST(WebTransformAnimationCurveTest, DefaultTimingFunction) |
| 256 { | 284 { |
| 257 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 285 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
| 258 WebKit::WebTransformOperations operations1; | 286 scoped_ptr<WebKit::WebTransformOperations> operations1( |
| 259 operations1.appendTranslate(0, 0, 0); | 287 cc::TransformOperations::Create()); |
| 260 WebKit::WebTransformOperations operations2; | 288 operations1->appendTranslate(0, 0, 0); |
| 261 operations2.appendTranslate(1, 0, 0); | 289 scoped_ptr<WebKit::WebTransformOperations> operations2( |
| 262 curve->add(WebTransformKeyframe(0, operations1)); | 290 cc::TransformOperations::Create()); |
| 263 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 291 operations2->appendTranslate(1, 0, 0); |
| 292 curve->add(WebTransformKeyframe(0, *operations1)); |
| 293 curve->add(WebTransformKeyframe(1, *operations2), WebAnimationCurve::TimingF
unctionTypeLinear); |
| 264 | 294 |
| 265 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); | 295 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); |
| 266 for (int i = 0; i <= 4; ++i) { | 296 for (int i = 0; i <= 4; ++i) { |
| 267 const double time = i * 0.25; | 297 const double time = i * 0.25; |
| 268 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 298 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
| 269 } | 299 } |
| 270 } | 300 } |
| 271 | 301 |
| 272 } // namespace | 302 } // namespace |
| OLD | NEW |