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