| 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 "webkit/compositor_bindings/web_float_animation_curve_impl.h" | 8 #include "webkit/compositor_bindings/web_float_animation_curve_impl.h" |
| 9 | 9 |
| 10 using namespace WebKit; | 10 using namespace WebKit; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) { | 119 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) { |
| 120 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 120 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 121 curve->add(WebFloatKeyframe(0, 0), WebAnimationCurve::TimingFunctionTypeEase); | 121 curve->add(WebFloatKeyframe(0, 0), WebAnimationCurve::TimingFunctionTypeEase); |
| 122 curve->add(WebFloatKeyframe(1, 1), | 122 curve->add(WebFloatKeyframe(1, 1), |
| 123 WebAnimationCurve::TimingFunctionTypeLinear); | 123 WebAnimationCurve::TimingFunctionTypeLinear); |
| 124 | 124 |
| 125 scoped_ptr<cc::TimingFunction> timing_function( | 125 scoped_ptr<cc::TimingFunction> timing_function( |
| 126 cc::EaseTimingFunction::create()); | 126 cc::EaseTimingFunction::create()); |
| 127 for (int i = 0; i <= 4; ++i) { | 127 for (int i = 0; i <= 4; ++i) { |
| 128 const double time = i * 0.25; | 128 const double time = i * 0.25; |
| 129 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 129 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Tests using a linear timing function. | 133 // Tests using a linear timing function. |
| 134 TEST(WebFloatAnimationCurveTest, LinearTimingFunction) { | 134 TEST(WebFloatAnimationCurveTest, LinearTimingFunction) { |
| 135 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 135 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 136 curve->add(WebFloatKeyframe(0, 0), | 136 curve->add(WebFloatKeyframe(0, 0), |
| 137 WebAnimationCurve::TimingFunctionTypeLinear); | 137 WebAnimationCurve::TimingFunctionTypeLinear); |
| 138 curve->add(WebFloatKeyframe(1, 1), | 138 curve->add(WebFloatKeyframe(1, 1), |
| 139 WebAnimationCurve::TimingFunctionTypeLinear); | 139 WebAnimationCurve::TimingFunctionTypeLinear); |
| 140 | 140 |
| 141 for (int i = 0; i <= 4; ++i) { | 141 for (int i = 0; i <= 4; ++i) { |
| 142 const double time = i * 0.25; | 142 const double time = i * 0.25; |
| 143 EXPECT_FLOAT_EQ(time, curve->getValue(time)); | 143 EXPECT_FLOAT_EQ(time, curve->getValue(time)); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Tests that an ease in timing function works as expected. | 147 // Tests that an ease in timing function works as expected. |
| 148 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) { | 148 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) { |
| 149 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 149 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 150 curve->add(WebFloatKeyframe(0, 0), | 150 curve->add(WebFloatKeyframe(0, 0), |
| 151 WebAnimationCurve::TimingFunctionTypeEaseIn); | 151 WebAnimationCurve::TimingFunctionTypeEaseIn); |
| 152 curve->add(WebFloatKeyframe(1, 1), | 152 curve->add(WebFloatKeyframe(1, 1), |
| 153 WebAnimationCurve::TimingFunctionTypeLinear); | 153 WebAnimationCurve::TimingFunctionTypeLinear); |
| 154 | 154 |
| 155 scoped_ptr<cc::TimingFunction> timing_function( | 155 scoped_ptr<cc::TimingFunction> timing_function( |
| 156 cc::EaseInTimingFunction::create()); | 156 cc::EaseInTimingFunction::create()); |
| 157 for (int i = 0; i <= 4; ++i) { | 157 for (int i = 0; i <= 4; ++i) { |
| 158 const double time = i * 0.25; | 158 const double time = i * 0.25; |
| 159 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 159 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Tests that an ease in timing function works as expected. | 163 // Tests that an ease in timing function works as expected. |
| 164 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) { | 164 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) { |
| 165 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 165 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 166 curve->add(WebFloatKeyframe(0, 0), | 166 curve->add(WebFloatKeyframe(0, 0), |
| 167 WebAnimationCurve::TimingFunctionTypeEaseOut); | 167 WebAnimationCurve::TimingFunctionTypeEaseOut); |
| 168 curve->add(WebFloatKeyframe(1, 1), | 168 curve->add(WebFloatKeyframe(1, 1), |
| 169 WebAnimationCurve::TimingFunctionTypeLinear); | 169 WebAnimationCurve::TimingFunctionTypeLinear); |
| 170 | 170 |
| 171 scoped_ptr<cc::TimingFunction> timing_function( | 171 scoped_ptr<cc::TimingFunction> timing_function( |
| 172 cc::EaseOutTimingFunction::create()); | 172 cc::EaseOutTimingFunction::create()); |
| 173 for (int i = 0; i <= 4; ++i) { | 173 for (int i = 0; i <= 4; ++i) { |
| 174 const double time = i * 0.25; | 174 const double time = i * 0.25; |
| 175 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 175 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Tests that an ease in timing function works as expected. | 179 // Tests that an ease in timing function works as expected. |
| 180 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) { | 180 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) { |
| 181 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 181 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 182 curve->add(WebFloatKeyframe(0, 0), | 182 curve->add(WebFloatKeyframe(0, 0), |
| 183 WebAnimationCurve::TimingFunctionTypeEaseInOut); | 183 WebAnimationCurve::TimingFunctionTypeEaseInOut); |
| 184 curve->add(WebFloatKeyframe(1, 1), | 184 curve->add(WebFloatKeyframe(1, 1), |
| 185 WebAnimationCurve::TimingFunctionTypeLinear); | 185 WebAnimationCurve::TimingFunctionTypeLinear); |
| 186 | 186 |
| 187 scoped_ptr<cc::TimingFunction> timing_function( | 187 scoped_ptr<cc::TimingFunction> timing_function( |
| 188 cc::EaseInOutTimingFunction::create()); | 188 cc::EaseInOutTimingFunction::create()); |
| 189 for (int i = 0; i <= 4; ++i) { | 189 for (int i = 0; i <= 4; ++i) { |
| 190 const double time = i * 0.25; | 190 const double time = i * 0.25; |
| 191 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 191 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Tests that an ease in timing function works as expected. | 195 // Tests that an ease in timing function works as expected. |
| 196 TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) { | 196 TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) { |
| 197 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 197 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 198 double x1 = 0.3; | 198 double x1 = 0.3; |
| 199 double y1 = 0.2; | 199 double y1 = 0.2; |
| 200 double x2 = 0.8; | 200 double x2 = 0.8; |
| 201 double y2 = 0.7; | 201 double y2 = 0.7; |
| 202 curve->add(WebFloatKeyframe(0, 0), x1, y1, x2, y2); | 202 curve->add(WebFloatKeyframe(0, 0), x1, y1, x2, y2); |
| 203 curve->add(WebFloatKeyframe(1, 1), | 203 curve->add(WebFloatKeyframe(1, 1), |
| 204 WebAnimationCurve::TimingFunctionTypeLinear); | 204 WebAnimationCurve::TimingFunctionTypeLinear); |
| 205 | 205 |
| 206 scoped_ptr<cc::TimingFunction> timing_function( | 206 scoped_ptr<cc::TimingFunction> timing_function( |
| 207 cc::CubicBezierTimingFunction::create(x1, y1, x2, y2)); | 207 cc::CubicBezierTimingFunction::create(x1, y1, x2, y2)); |
| 208 for (int i = 0; i <= 4; ++i) { | 208 for (int i = 0; i <= 4; ++i) { |
| 209 const double time = i * 0.25; | 209 const double time = i * 0.25; |
| 210 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 210 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Tests that the default timing function is indeed ease. | 214 // Tests that the default timing function is indeed ease. |
| 215 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) { | 215 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) { |
| 216 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); | 216 scoped_ptr<WebFloatAnimationCurve> curve(new WebFloatAnimationCurveImpl); |
| 217 curve->add(WebFloatKeyframe(0, 0)); | 217 curve->add(WebFloatKeyframe(0, 0)); |
| 218 curve->add(WebFloatKeyframe(1, 1), | 218 curve->add(WebFloatKeyframe(1, 1), |
| 219 WebAnimationCurve::TimingFunctionTypeLinear); | 219 WebAnimationCurve::TimingFunctionTypeLinear); |
| 220 | 220 |
| 221 scoped_ptr<cc::TimingFunction> timing_function( | 221 scoped_ptr<cc::TimingFunction> timing_function( |
| 222 cc::EaseTimingFunction::create()); | 222 cc::EaseTimingFunction::create()); |
| 223 for (int i = 0; i <= 4; ++i) { | 223 for (int i = 0; i <= 4; ++i) { |
| 224 const double time = i * 0.25; | 224 const double time = i * 0.25; |
| 225 EXPECT_FLOAT_EQ(timing_function->getValue(time), curve->getValue(time)); | 225 EXPECT_FLOAT_EQ(timing_function->GetValue(time), curve->getValue(time)); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace | 229 } // namespace |
| OLD | NEW |