OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/animation/SVGLengthStyleInterpolation.h" | |
7 | |
8 #include "core/css/CSSPrimitiveValue.h" | |
9 | |
10 #include <gtest/gtest.h> | |
11 | |
12 namespace blink { | |
13 | |
14 class AnimationSVGLengthStyleInterpolationTest : public ::testing::Test { | |
15 protected: | |
16 static PassOwnPtrWillBeRawPtr<InterpolableValue> lengthToInterpolableValue(c
onst CSSPrimitiveValue& value) | |
17 { | |
18 return SVGLengthStyleInterpolation::lengthToInterpolableValue(value); | |
19 } | |
20 | |
21 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> interpolableValueToLength(c
onst InterpolableValue& value, CSSPrimitiveValue::UnitType type, InterpolationRa
nge range) | |
22 { | |
23 return SVGLengthStyleInterpolation::interpolableValueToLength(value, typ
e, range); | |
24 } | |
25 | |
26 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> roundTrip(const CSSPrimitiv
eValue& value, InterpolationRange range = RangeAll) | |
27 { | |
28 return interpolableValueToLength(*lengthToInterpolableValue(value), valu
e.primitiveType(), range); | |
29 } | |
30 | |
31 static void testPrimitiveValue(const CSSPrimitiveValue& primitiveValue, doub
le value, CSSPrimitiveValue::UnitType unitType) | |
32 { | |
33 EXPECT_EQ(primitiveValue.primitiveType(), unitType); | |
34 EXPECT_EQ(primitiveValue.getDoubleValue(), value); | |
35 } | |
36 }; | |
37 | |
38 TEST_F(AnimationSVGLengthStyleInterpolationTest, ZeroLength) | |
39 { | |
40 RefPtrWillBeRawPtr<CSSPrimitiveValue> value = roundTrip(*CSSPrimitiveValue::
create(0, CSSPrimitiveValue::CSS_PX)); | |
41 testPrimitiveValue(*value, 0, CSSPrimitiveValue::CSS_PX); | |
42 | |
43 value = roundTrip(*CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PERCE
NTAGE)); | |
44 testPrimitiveValue(*value, 0, CSSPrimitiveValue::CSS_PERCENTAGE); | |
45 | |
46 value = roundTrip(*CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_EMS))
; | |
47 testPrimitiveValue(*value, 0, CSSPrimitiveValue::CSS_EMS); | |
48 } | |
49 | |
50 TEST_F(AnimationSVGLengthStyleInterpolationTest, SingleUnit) | |
51 { | |
52 RefPtrWillBeRawPtr<CSSPrimitiveValue> value = roundTrip(*CSSPrimitiveValue::
create(10, CSSPrimitiveValue::CSS_PX)); | |
53 testPrimitiveValue(*value, 10, CSSPrimitiveValue::CSS_PX); | |
54 | |
55 value = roundTrip(*CSSPrimitiveValue::create(40, CSSPrimitiveValue::CSS_PERC
ENTAGE), RangeNonNegative); | |
56 testPrimitiveValue(*value, 40, CSSPrimitiveValue::CSS_PERCENTAGE); | |
57 | |
58 value = roundTrip(*CSSPrimitiveValue::create(-10, CSSPrimitiveValue::CSS_EMS
)); | |
59 testPrimitiveValue(*value, -10, CSSPrimitiveValue::CSS_EMS); | |
60 } | |
61 | |
62 TEST_F(AnimationSVGLengthStyleInterpolationTest, SingleClampedUnit) | |
63 { | |
64 RefPtrWillBeRawPtr<CSSPrimitiveValue> value = roundTrip(*CSSPrimitiveValue::
create(-10, CSSPrimitiveValue::CSS_PX), RangeNonNegative); | |
65 testPrimitiveValue(*value, 0, CSSPrimitiveValue::CSS_PX); | |
66 | |
67 value = roundTrip(*CSSPrimitiveValue::create(-40, CSSPrimitiveValue::CSS_PER
CENTAGE), RangeNonNegative); | |
68 testPrimitiveValue(*value, 0, CSSPrimitiveValue::CSS_PERCENTAGE); | |
69 } | |
70 | |
71 } | |
OLD | NEW |