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 |
| 15 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 16 using webkit::WebTransformOperationsImpl; |
| 17 #endif |
| 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 // Tests that a transform animation with one keyframe works as expected. | 21 // Tests that a transform animation with one keyframe works as expected. |
17 TEST(WebTransformAnimationCurveTest, OneTransformKeyframe) | 22 TEST(WebTransformAnimationCurveTest, OneTransformKeyframe) |
18 { | 23 { |
19 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 24 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
20 WebKit::WebTransformOperations operations; | 25 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 26 scoped_ptr<WebTransformOperations> operations(new WebTransformOperationsImpl
()); |
| 27 operations->appendTranslate(2, 0, 0); |
| 28 curve->add(WebTransformKeyframe(0, operations.release()), WebAnimationCurve:
:TimingFunctionTypeLinear); |
| 29 #else |
| 30 WebTransformOperations operations; |
21 operations.appendTranslate(2, 0, 0); | 31 operations.appendTranslate(2, 0, 0); |
22 curve->add(WebTransformKeyframe(0, operations), WebAnimationCurve::TimingFun
ctionTypeLinear); | 32 curve->add(WebTransformKeyframe(0, operations), WebAnimationCurve::TimingFun
ctionTypeLinear); |
| 33 #endif |
23 | 34 |
24 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 35 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
25 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 36 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
26 EXPECT_FLOAT_EQ(2, curve->getValue(0.5).m41()); | 37 EXPECT_FLOAT_EQ(2, curve->getValue(0.5).m41()); |
27 EXPECT_FLOAT_EQ(2, curve->getValue(1).m41()); | 38 EXPECT_FLOAT_EQ(2, curve->getValue(1).m41()); |
28 EXPECT_FLOAT_EQ(2, curve->getValue(2).m41()); | 39 EXPECT_FLOAT_EQ(2, curve->getValue(2).m41()); |
29 } | 40 } |
30 | 41 |
31 // Tests that a transform animation with two keyframes works as expected. | 42 // Tests that a transform animation with two keyframes works as expected. |
32 TEST(WebTransformAnimationCurveTest, TwoTransformKeyframe) | 43 TEST(WebTransformAnimationCurveTest, TwoTransformKeyframe) |
33 { | 44 { |
34 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 45 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
35 WebKit::WebTransformOperations operations1; | 46 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 47 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 48 operations1->appendTranslate(2, 0, 0); |
| 49 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 50 operations2->appendTranslate(4, 0, 0); |
| 51 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 52 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 53 #else |
| 54 WebTransformOperations operations1; |
36 operations1.appendTranslate(2, 0, 0); | 55 operations1.appendTranslate(2, 0, 0); |
37 WebKit::WebTransformOperations operations2; | 56 WebTransformOperations operations2; |
38 operations2.appendTranslate(4, 0, 0); | 57 operations2.appendTranslate(4, 0, 0); |
39 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 58 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); |
40 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 59 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 60 #endif |
41 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 61 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
42 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 62 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
43 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 63 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
44 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 64 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
45 EXPECT_FLOAT_EQ(4, curve->getValue(2).m41()); | 65 EXPECT_FLOAT_EQ(4, curve->getValue(2).m41()); |
46 } | 66 } |
47 | 67 |
48 // Tests that a transform animation with three keyframes works as expected. | 68 // Tests that a transform animation with three keyframes works as expected. |
49 TEST(WebTransformAnimationCurveTest, ThreeTransformKeyframe) | 69 TEST(WebTransformAnimationCurveTest, ThreeTransformKeyframe) |
50 { | 70 { |
51 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 71 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
52 WebKit::WebTransformOperations operations1; | 72 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 73 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 74 operations1->appendTranslate(2, 0, 0); |
| 75 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 76 operations2->appendTranslate(4, 0, 0); |
| 77 scoped_ptr<WebTransformOperations> operations3(new WebTransformOperationsImp
l()); |
| 78 operations3->appendTranslate(8, 0, 0); |
| 79 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 80 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 81 curve->add(WebTransformKeyframe(2, operations3.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 82 #else |
| 83 WebTransformOperations operations1; |
53 operations1.appendTranslate(2, 0, 0); | 84 operations1.appendTranslate(2, 0, 0); |
54 WebKit::WebTransformOperations operations2; | 85 WebTransformOperations operations2; |
55 operations2.appendTranslate(4, 0, 0); | 86 operations2.appendTranslate(4, 0, 0); |
56 WebKit::WebTransformOperations operations3; | 87 WebTransformOperations operations3; |
57 operations3.appendTranslate(8, 0, 0); | 88 operations3.appendTranslate(8, 0, 0); |
58 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 89 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); |
59 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 90 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
60 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 91 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 92 #endif |
61 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 93 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
62 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 94 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
63 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 95 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
64 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 96 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
65 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 97 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
66 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); | 98 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); |
67 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); | 99 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); |
68 } | 100 } |
69 | 101 |
70 // Tests that a transform animation with multiple keys at a given time works san
ely. | 102 // Tests that a transform animation with multiple keys at a given time works san
ely. |
71 TEST(WebTransformAnimationCurveTest, RepeatedTransformKeyTimes) | 103 TEST(WebTransformAnimationCurveTest, RepeatedTransformKeyTimes) |
72 { | 104 { |
73 // A step function. | 105 // A step function. |
74 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 106 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
75 WebKit::WebTransformOperations operations1; | 107 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 108 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 109 operations1->appendTranslate(4, 0, 0); |
| 110 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 111 operations2->appendTranslate(4, 0, 0); |
| 112 scoped_ptr<WebTransformOperations> operations3(new WebTransformOperationsImp
l()); |
| 113 operations3->appendTranslate(6, 0, 0); |
| 114 scoped_ptr<WebTransformOperations> operations4(new WebTransformOperationsImp
l()); |
| 115 operations4->appendTranslate(6, 0, 0); |
| 116 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 117 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 118 curve->add(WebTransformKeyframe(1, operations3.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 119 curve->add(WebTransformKeyframe(2, operations4.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 120 #else |
| 121 WebTransformOperations operations1; |
76 operations1.appendTranslate(4, 0, 0); | 122 operations1.appendTranslate(4, 0, 0); |
77 WebKit::WebTransformOperations operations2; | 123 WebTransformOperations operations2; |
78 operations2.appendTranslate(4, 0, 0); | 124 operations2.appendTranslate(4, 0, 0); |
79 WebKit::WebTransformOperations operations3; | 125 WebTransformOperations operations3; |
80 operations3.appendTranslate(6, 0, 0); | 126 operations3.appendTranslate(6, 0, 0); |
81 WebKit::WebTransformOperations operations4; | 127 WebTransformOperations operations4; |
82 operations4.appendTranslate(6, 0, 0); | 128 operations4.appendTranslate(6, 0, 0); |
83 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 129 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); |
84 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 130 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
85 curve->add(WebTransformKeyframe(1, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 131 curve->add(WebTransformKeyframe(1, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); |
86 curve->add(WebTransformKeyframe(2, operations4), WebAnimationCurve::TimingFu
nctionTypeLinear); | 132 curve->add(WebTransformKeyframe(2, operations4), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 133 #endif |
87 | 134 |
88 EXPECT_FLOAT_EQ(4, curve->getValue(-1).m41()); | 135 EXPECT_FLOAT_EQ(4, curve->getValue(-1).m41()); |
89 EXPECT_FLOAT_EQ(4, curve->getValue(0).m41()); | 136 EXPECT_FLOAT_EQ(4, curve->getValue(0).m41()); |
90 EXPECT_FLOAT_EQ(4, curve->getValue(0.5).m41()); | 137 EXPECT_FLOAT_EQ(4, curve->getValue(0.5).m41()); |
91 | 138 |
92 // There is a discontinuity at 1. Any value between 4 and 6 is valid. | 139 // There is a discontinuity at 1. Any value between 4 and 6 is valid. |
93 WebTransformationMatrix value = curve->getValue(1); | 140 WebTransformationMatrix value = curve->getValue(1); |
94 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); | 141 EXPECT_TRUE(value.m41() >= 4 && value.m41() <= 6); |
95 | 142 |
96 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 143 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
97 EXPECT_FLOAT_EQ(6, curve->getValue(2).m41()); | 144 EXPECT_FLOAT_EQ(6, curve->getValue(2).m41()); |
98 EXPECT_FLOAT_EQ(6, curve->getValue(3).m41()); | 145 EXPECT_FLOAT_EQ(6, curve->getValue(3).m41()); |
99 } | 146 } |
100 | 147 |
101 // Tests that the keyframes may be added out of order. | 148 // Tests that the keyframes may be added out of order. |
102 TEST(WebTransformAnimationCurveTest, UnsortedKeyframes) | 149 TEST(WebTransformAnimationCurveTest, UnsortedKeyframes) |
103 { | 150 { |
104 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 151 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
105 WebKit::WebTransformOperations operations1; | 152 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 153 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 154 operations1->appendTranslate(2, 0, 0); |
| 155 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 156 operations2->appendTranslate(4, 0, 0); |
| 157 scoped_ptr<WebTransformOperations> operations3(new WebTransformOperationsImp
l()); |
| 158 operations3->appendTranslate(8, 0, 0); |
| 159 curve->add(WebTransformKeyframe(2, operations3.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 160 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 161 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 162 #else |
| 163 WebTransformOperations operations1; |
106 operations1.appendTranslate(2, 0, 0); | 164 operations1.appendTranslate(2, 0, 0); |
107 WebKit::WebTransformOperations operations2; | 165 WebTransformOperations operations2; |
108 operations2.appendTranslate(4, 0, 0); | 166 operations2.appendTranslate(4, 0, 0); |
109 WebKit::WebTransformOperations operations3; | 167 WebTransformOperations operations3; |
110 operations3.appendTranslate(8, 0, 0); | 168 operations3.appendTranslate(8, 0, 0); |
111 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); | 169 curve->add(WebTransformKeyframe(2, operations3), WebAnimationCurve::TimingFu
nctionTypeLinear); |
112 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 170 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); |
113 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 171 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 172 #endif |
114 | 173 |
115 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); | 174 EXPECT_FLOAT_EQ(2, curve->getValue(-1).m41()); |
116 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); | 175 EXPECT_FLOAT_EQ(2, curve->getValue(0).m41()); |
117 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); | 176 EXPECT_FLOAT_EQ(3, curve->getValue(0.5).m41()); |
118 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); | 177 EXPECT_FLOAT_EQ(4, curve->getValue(1).m41()); |
119 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); | 178 EXPECT_FLOAT_EQ(6, curve->getValue(1.5).m41()); |
120 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); | 179 EXPECT_FLOAT_EQ(8, curve->getValue(2).m41()); |
121 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); | 180 EXPECT_FLOAT_EQ(8, curve->getValue(3).m41()); |
122 } | 181 } |
123 | 182 |
124 // Tests that a cubic bezier timing function works as expected. | 183 // Tests that a cubic bezier timing function works as expected. |
125 TEST(WebTransformAnimationCurveTest, CubicBezierTimingFunction) | 184 TEST(WebTransformAnimationCurveTest, CubicBezierTimingFunction) |
126 { | 185 { |
127 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 186 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
128 WebKit::WebTransformOperations operations1; | 187 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 188 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 189 operations1->appendTranslate(0, 0, 0); |
| 190 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 191 operations2->appendTranslate(1, 0, 0); |
| 192 curve->add(WebTransformKeyframe(0, operations1.release()), 0.25, 0, 0.75, 1)
; |
| 193 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 194 #else |
| 195 WebTransformOperations operations1; |
129 operations1.appendTranslate(0, 0, 0); | 196 operations1.appendTranslate(0, 0, 0); |
130 WebKit::WebTransformOperations operations2; | 197 WebTransformOperations operations2; |
131 operations2.appendTranslate(1, 0, 0); | 198 operations2.appendTranslate(1, 0, 0); |
132 curve->add(WebTransformKeyframe(0, operations1), 0.25, 0, 0.75, 1); | 199 curve->add(WebTransformKeyframe(0, operations1), 0.25, 0, 0.75, 1); |
133 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 200 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 201 #endif |
134 EXPECT_FLOAT_EQ(0, curve->getValue(0).m41()); | 202 EXPECT_FLOAT_EQ(0, curve->getValue(0).m41()); |
135 EXPECT_LT(0, curve->getValue(0.25).m41()); | 203 EXPECT_LT(0, curve->getValue(0.25).m41()); |
136 EXPECT_GT(0.25, curve->getValue(0.25).m41()); | 204 EXPECT_GT(0.25, curve->getValue(0.25).m41()); |
137 EXPECT_NEAR(curve->getValue(0.5).m41(), 0.5, 0.00015); | 205 EXPECT_NEAR(curve->getValue(0.5).m41(), 0.5, 0.00015); |
138 EXPECT_LT(0.75, curve->getValue(0.75).m41()); | 206 EXPECT_LT(0.75, curve->getValue(0.75).m41()); |
139 EXPECT_GT(1, curve->getValue(0.75).m41()); | 207 EXPECT_GT(1, curve->getValue(0.75).m41()); |
140 EXPECT_FLOAT_EQ(1, curve->getValue(1).m41()); | 208 EXPECT_FLOAT_EQ(1, curve->getValue(1).m41()); |
141 } | 209 } |
142 | 210 |
143 // Tests that an ease timing function works as expected. | 211 // Tests that an ease timing function works as expected. |
144 TEST(WebTransformAnimationCurveTest, EaseTimingFunction) | 212 TEST(WebTransformAnimationCurveTest, EaseTimingFunction) |
145 { | 213 { |
146 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 214 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
147 WebKit::WebTransformOperations operations1; | 215 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 216 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 217 operations1->appendTranslate(0, 0, 0); |
| 218 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 219 operations2->appendTranslate(1, 0, 0); |
| 220 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeEase); |
| 221 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 222 #else |
| 223 WebTransformOperations operations1; |
148 operations1.appendTranslate(0, 0, 0); | 224 operations1.appendTranslate(0, 0, 0); |
149 WebKit::WebTransformOperations operations2; | 225 WebTransformOperations operations2; |
150 operations2.appendTranslate(1, 0, 0); | 226 operations2.appendTranslate(1, 0, 0); |
151 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEase); | 227 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEase); |
152 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 228 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 229 #endif |
153 | 230 |
154 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); | 231 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); |
155 for (int i = 0; i <= 4; ++i) { | 232 for (int i = 0; i <= 4; ++i) { |
156 const double time = i * 0.25; | 233 const double time = i * 0.25; |
157 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 234 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
158 } | 235 } |
159 } | 236 } |
160 | 237 |
161 // Tests using a linear timing function. | 238 // Tests using a linear timing function. |
162 TEST(WebTransformAnimationCurveTest, LinearTimingFunction) | 239 TEST(WebTransformAnimationCurveTest, LinearTimingFunction) |
163 { | 240 { |
164 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 241 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
165 WebKit::WebTransformOperations operations1; | 242 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 243 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 244 operations1->appendTranslate(0, 0, 0); |
| 245 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 246 operations2->appendTranslate(1, 0, 0); |
| 247 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 248 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 249 #else |
| 250 WebTransformOperations operations1; |
166 operations1.appendTranslate(0, 0, 0); | 251 operations1.appendTranslate(0, 0, 0); |
167 WebKit::WebTransformOperations operations2; | 252 WebTransformOperations operations2; |
168 operations2.appendTranslate(1, 0, 0); | 253 operations2.appendTranslate(1, 0, 0); |
169 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); | 254 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeLinear); |
170 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 255 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 256 #endif |
171 | 257 |
172 for (int i = 0; i <= 4; ++i) { | 258 for (int i = 0; i <= 4; ++i) { |
173 const double time = i * 0.25; | 259 const double time = i * 0.25; |
174 EXPECT_FLOAT_EQ(time, curve->getValue(time).m41()); | 260 EXPECT_FLOAT_EQ(time, curve->getValue(time).m41()); |
175 } | 261 } |
176 } | 262 } |
177 | 263 |
178 // Tests that an ease in timing function works as expected. | 264 // Tests that an ease in timing function works as expected. |
179 TEST(WebTransformAnimationCurveTest, EaseInTimingFunction) | 265 TEST(WebTransformAnimationCurveTest, EaseInTimingFunction) |
180 { | 266 { |
181 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 267 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
182 WebKit::WebTransformOperations operations1; | 268 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 269 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 270 operations1->appendTranslate(0, 0, 0); |
| 271 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 272 operations2->appendTranslate(1, 0, 0); |
| 273 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeEaseIn); |
| 274 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 275 #else |
| 276 WebTransformOperations operations1; |
183 operations1.appendTranslate(0, 0, 0); | 277 operations1.appendTranslate(0, 0, 0); |
184 WebKit::WebTransformOperations operations2; | 278 WebTransformOperations operations2; |
185 operations2.appendTranslate(1, 0, 0); | 279 operations2.appendTranslate(1, 0, 0); |
186 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseIn); | 280 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseIn); |
187 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 281 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 282 #endif |
188 | 283 |
189 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInTimingFunction::crea
te()); | 284 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInTimingFunction::crea
te()); |
190 for (int i = 0; i <= 4; ++i) { | 285 for (int i = 0; i <= 4; ++i) { |
191 const double time = i * 0.25; | 286 const double time = i * 0.25; |
192 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 287 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
193 } | 288 } |
194 } | 289 } |
195 | 290 |
196 // Tests that an ease in timing function works as expected. | 291 // Tests that an ease in timing function works as expected. |
197 TEST(WebTransformAnimationCurveTest, EaseOutTimingFunction) | 292 TEST(WebTransformAnimationCurveTest, EaseOutTimingFunction) |
198 { | 293 { |
199 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 294 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
200 WebKit::WebTransformOperations operations1; | 295 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 296 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 297 operations1->appendTranslate(0, 0, 0); |
| 298 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 299 operations2->appendTranslate(1, 0, 0); |
| 300 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeEaseOut); |
| 301 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 302 #else |
| 303 WebTransformOperations operations1; |
201 operations1.appendTranslate(0, 0, 0); | 304 operations1.appendTranslate(0, 0, 0); |
202 WebKit::WebTransformOperations operations2; | 305 WebTransformOperations operations2; |
203 operations2.appendTranslate(1, 0, 0); | 306 operations2.appendTranslate(1, 0, 0); |
204 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseOut); | 307 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseOut); |
205 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 308 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 309 #endif |
206 | 310 |
207 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseOutTimingFunction::cre
ate()); | 311 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseOutTimingFunction::cre
ate()); |
208 for (int i = 0; i <= 4; ++i) { | 312 for (int i = 0; i <= 4; ++i) { |
209 const double time = i * 0.25; | 313 const double time = i * 0.25; |
210 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 314 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
211 } | 315 } |
212 } | 316 } |
213 | 317 |
214 // Tests that an ease in timing function works as expected. | 318 // Tests that an ease in timing function works as expected. |
215 TEST(WebTransformAnimationCurveTest, EaseInOutTimingFunction) | 319 TEST(WebTransformAnimationCurveTest, EaseInOutTimingFunction) |
216 { | 320 { |
217 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 321 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
218 WebKit::WebTransformOperations operations1; | 322 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 323 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 324 operations1->appendTranslate(0, 0, 0); |
| 325 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 326 operations2->appendTranslate(1, 0, 0); |
| 327 curve->add(WebTransformKeyframe(0, operations1.release()), WebAnimationCurve
::TimingFunctionTypeEaseInOut); |
| 328 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 329 #else |
| 330 WebTransformOperations operations1; |
219 operations1.appendTranslate(0, 0, 0); | 331 operations1.appendTranslate(0, 0, 0); |
220 WebKit::WebTransformOperations operations2; | 332 WebTransformOperations operations2; |
221 operations2.appendTranslate(1, 0, 0); | 333 operations2.appendTranslate(1, 0, 0); |
222 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseInOut); | 334 curve->add(WebTransformKeyframe(0, operations1), WebAnimationCurve::TimingFu
nctionTypeEaseInOut); |
223 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 335 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 336 #endif |
224 | 337 |
225 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInOutTimingFunction::c
reate()); | 338 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseInOutTimingFunction::c
reate()); |
226 for (int i = 0; i <= 4; ++i) { | 339 for (int i = 0; i <= 4; ++i) { |
227 const double time = i * 0.25; | 340 const double time = i * 0.25; |
228 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 341 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
229 } | 342 } |
230 } | 343 } |
231 | 344 |
232 // Tests that an ease in timing function works as expected. | 345 // Tests that an ease in timing function works as expected. |
233 TEST(WebTransformAnimationCurveTest, CustomBezierTimingFunction) | 346 TEST(WebTransformAnimationCurveTest, CustomBezierTimingFunction) |
234 { | 347 { |
235 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 348 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
236 double x1 = 0.3; | 349 double x1 = 0.3; |
237 double y1 = 0.2; | 350 double y1 = 0.2; |
238 double x2 = 0.8; | 351 double x2 = 0.8; |
239 double y2 = 0.7; | 352 double y2 = 0.7; |
240 WebKit::WebTransformOperations operations1; | 353 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 354 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 355 operations1->appendTranslate(0, 0, 0); |
| 356 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 357 operations2->appendTranslate(1, 0, 0); |
| 358 curve->add(WebTransformKeyframe(0, operations1.release()), x1, y1, x2, y2); |
| 359 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 360 #else |
| 361 WebTransformOperations operations1; |
241 operations1.appendTranslate(0, 0, 0); | 362 operations1.appendTranslate(0, 0, 0); |
242 WebKit::WebTransformOperations operations2; | 363 WebTransformOperations operations2; |
243 operations2.appendTranslate(1, 0, 0); | 364 operations2.appendTranslate(1, 0, 0); |
244 curve->add(WebTransformKeyframe(0, operations1), x1, y1, x2, y2); | 365 curve->add(WebTransformKeyframe(0, operations1), x1, y1, x2, y2); |
245 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 366 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 367 #endif |
246 | 368 |
247 scoped_ptr<cc::TimingFunction> timingFunction(cc::CubicBezierTimingFunction:
:create(x1, y1, x2, y2)); | 369 scoped_ptr<cc::TimingFunction> timingFunction(cc::CubicBezierTimingFunction:
:create(x1, y1, x2, y2)); |
248 for (int i = 0; i <= 4; ++i) { | 370 for (int i = 0; i <= 4; ++i) { |
249 const double time = i * 0.25; | 371 const double time = i * 0.25; |
250 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 372 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
251 } | 373 } |
252 } | 374 } |
253 | 375 |
254 // Tests that the default timing function is indeed ease. | 376 // Tests that the default timing function is indeed ease. |
255 TEST(WebTransformAnimationCurveTest, DefaultTimingFunction) | 377 TEST(WebTransformAnimationCurveTest, DefaultTimingFunction) |
256 { | 378 { |
257 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); | 379 scoped_ptr<WebTransformAnimationCurve> curve(new WebTransformAnimationCurveI
mpl); |
258 WebKit::WebTransformOperations operations1; | 380 #if WEB_TRANSFORM_OPERATIONS_IS_VIRTUAL |
| 381 scoped_ptr<WebTransformOperations> operations1(new WebTransformOperationsImp
l()); |
| 382 operations1->appendTranslate(0, 0, 0); |
| 383 scoped_ptr<WebTransformOperations> operations2(new WebTransformOperationsImp
l()); |
| 384 operations2->appendTranslate(1, 0, 0); |
| 385 curve->add(WebTransformKeyframe(0, operations1.release())); |
| 386 curve->add(WebTransformKeyframe(1, operations2.release()), WebAnimationCurve
::TimingFunctionTypeLinear); |
| 387 #else |
| 388 WebTransformOperations operations1; |
259 operations1.appendTranslate(0, 0, 0); | 389 operations1.appendTranslate(0, 0, 0); |
260 WebKit::WebTransformOperations operations2; | 390 WebTransformOperations operations2; |
261 operations2.appendTranslate(1, 0, 0); | 391 operations2.appendTranslate(1, 0, 0); |
262 curve->add(WebTransformKeyframe(0, operations1)); | 392 curve->add(WebTransformKeyframe(0, operations1)); |
263 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); | 393 curve->add(WebTransformKeyframe(1, operations2), WebAnimationCurve::TimingFu
nctionTypeLinear); |
| 394 #endif |
264 | 395 |
265 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); | 396 scoped_ptr<cc::TimingFunction> timingFunction(cc::EaseTimingFunction::create
()); |
266 for (int i = 0; i <= 4; ++i) { | 397 for (int i = 0; i <= 4; ++i) { |
267 const double time = i * 0.25; | 398 const double time = i * 0.25; |
268 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); | 399 EXPECT_FLOAT_EQ(timingFunction->getValue(time), curve->getValue(time).m4
1()); |
269 } | 400 } |
270 } | 401 } |
271 | 402 |
272 } // namespace | 403 } // namespace |
OLD | NEW |