| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/animation/CompositorFloatAnimationCurve.h" | 5 #include "platform/animation/CompositorFloatAnimationCurve.h" |
| 6 | 6 |
| 7 #include "cc/animation/timing_function.h" | 7 #include "cc/animation/timing_function.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Tests that an ease timing function works as expected. | 114 // Tests that an ease timing function works as expected. |
| 115 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) | 115 TEST(WebFloatAnimationCurveTest, EaseTimingFunction) |
| 116 { | 116 { |
| 117 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 117 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 118 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE); | 118 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE); |
| 119 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 119 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 120 | 120 |
| 121 std::unique_ptr<cc::TimingFunction> timingFunction( | 121 std::unique_ptr<cc::TimingFunction> timingFunction( |
| 122 cc::EaseTimingFunction::Create()); | 122 cc::CubicBezierTimingFunction::CreatePreset(CubicBezierTimingFunction::E
aseType::EASE)); |
| 123 for (int i = 0; i <= 4; ++i) { | 123 for (int i = 0; i <= 4; ++i) { |
| 124 const double time = i * 0.25; | 124 const double time = i * 0.25; |
| 125 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 125 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Tests using a linear timing function. | 129 // Tests using a linear timing function. |
| 130 TEST(WebFloatAnimationCurveTest, LinearTimingFunction) | 130 TEST(WebFloatAnimationCurveTest, LinearTimingFunction) |
| 131 { | 131 { |
| 132 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 132 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 133 curve->addLinearKeyframe(CompositorFloatKeyframe(0, 0)); | 133 curve->addLinearKeyframe(CompositorFloatKeyframe(0, 0)); |
| 134 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 134 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 135 | 135 |
| 136 for (int i = 0; i <= 4; ++i) { | 136 for (int i = 0; i <= 4; ++i) { |
| 137 const double time = i * 0.25; | 137 const double time = i * 0.25; |
| 138 EXPECT_FLOAT_EQ(time, curve->getValue(time)); | 138 EXPECT_FLOAT_EQ(time, curve->getValue(time)); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Tests that an ease in timing function works as expected. | 142 // Tests that an ease in timing function works as expected. |
| 143 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) | 143 TEST(WebFloatAnimationCurveTest, EaseInTimingFunction) |
| 144 { | 144 { |
| 145 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 145 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 146 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_IN); | 146 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_IN); |
| 147 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 147 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 148 | 148 |
| 149 std::unique_ptr<cc::TimingFunction> timingFunction( | 149 std::unique_ptr<cc::TimingFunction> timingFunction( |
| 150 cc::EaseInTimingFunction::Create()); | 150 cc::CubicBezierTimingFunction::CreatePreset(CubicBezierTimingFunction::E
aseType::EASE_IN)); |
| 151 for (int i = 0; i <= 4; ++i) { | 151 for (int i = 0; i <= 4; ++i) { |
| 152 const double time = i * 0.25; | 152 const double time = i * 0.25; |
| 153 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 153 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Tests that an ease in timing function works as expected. | 157 // Tests that an ease in timing function works as expected. |
| 158 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) | 158 TEST(WebFloatAnimationCurveTest, EaseOutTimingFunction) |
| 159 { | 159 { |
| 160 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 160 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 161 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_OUT); | 161 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_OUT); |
| 162 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 162 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 163 | 163 |
| 164 std::unique_ptr<cc::TimingFunction> timingFunction( | 164 std::unique_ptr<cc::TimingFunction> timingFunction( |
| 165 cc::EaseOutTimingFunction::Create()); | 165 cc::CubicBezierTimingFunction::CreatePreset(CubicBezierTimingFunction::E
aseType::EASE_OUT)); |
| 166 for (int i = 0; i <= 4; ++i) { | 166 for (int i = 0; i <= 4; ++i) { |
| 167 const double time = i * 0.25; | 167 const double time = i * 0.25; |
| 168 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 168 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Tests that an ease in timing function works as expected. | 172 // Tests that an ease in timing function works as expected. |
| 173 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) | 173 TEST(WebFloatAnimationCurveTest, EaseInOutTimingFunction) |
| 174 { | 174 { |
| 175 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 175 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 176 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_IN_OUT); | 176 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE_IN_OUT); |
| 177 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 177 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 178 | 178 |
| 179 std::unique_ptr<cc::TimingFunction> timingFunction( | 179 std::unique_ptr<cc::TimingFunction> timingFunction( |
| 180 cc::EaseInOutTimingFunction::Create()); | 180 cc::CubicBezierTimingFunction::CreatePreset(CubicBezierTimingFunction::E
aseType::EASE_IN_OUT)); |
| 181 for (int i = 0; i <= 4; ++i) { | 181 for (int i = 0; i <= 4; ++i) { |
| 182 const double time = i * 0.25; | 182 const double time = i * 0.25; |
| 183 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 183 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Tests that an ease in timing function works as expected. | 187 // Tests that an ease in timing function works as expected. |
| 188 TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) | 188 TEST(WebFloatAnimationCurveTest, CustomBezierTimingFunction) |
| 189 { | 189 { |
| 190 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 190 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Tests that the default timing function is indeed ease. | 206 // Tests that the default timing function is indeed ease. |
| 207 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) | 207 TEST(WebFloatAnimationCurveTest, DefaultTimingFunction) |
| 208 { | 208 { |
| 209 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); | 209 std::unique_ptr<CompositorFloatAnimationCurve> curve(new CompositorFloatAnim
ationCurve); |
| 210 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE); | 210 curve->addCubicBezierKeyframe(CompositorFloatKeyframe(0, 0), CubicBezierTimi
ngFunction::EaseType::EASE); |
| 211 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); | 211 curve->addLinearKeyframe(CompositorFloatKeyframe(1, 1)); |
| 212 | 212 |
| 213 std::unique_ptr<cc::TimingFunction> timingFunction( | 213 std::unique_ptr<cc::TimingFunction> timingFunction( |
| 214 cc::EaseTimingFunction::Create()); | 214 cc::CubicBezierTimingFunction::CreatePreset(CubicBezierTimingFunction::E
aseType::EASE)); |
| 215 for (int i = 0; i <= 4; ++i) { | 215 for (int i = 0; i <= 4; ++i) { |
| 216 const double time = i * 0.25; | 216 const double time = i * 0.25; |
| 217 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); | 217 EXPECT_FLOAT_EQ(timingFunction->GetValue(time), curve->getValue(time)); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |