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