Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / animation / DoubleStyleInterpolationTest.cpp
blobe23842883624fd1089076772b5004fbbd55fbdc6
1 // Copyright 2014 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.
5 #include "config.h"
6 #include "core/animation/DoubleStyleInterpolation.h"
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/CSSValueList.h"
10 #include "core/css/StylePropertySet.h"
11 #include "wtf/MathExtras.h"
13 #include <gtest/gtest.h>
15 namespace blink {
17 class AnimationDoubleStyleInterpolationTest : public ::testing::Test {
18 protected:
19 static PassOwnPtr<InterpolableValue> doubleToInterpolableValue(const CSSValue& value)
21 return DoubleStyleInterpolation::doubleToInterpolableValue(value);
24 static PassOwnPtr<InterpolableValue> motionRotationToInterpolableValue(const CSSValue& value)
26 return DoubleStyleInterpolation::motionRotationToInterpolableValue(value);
29 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToDouble(InterpolableValue* value, bool isNumber, InterpolationRange clamp)
31 return DoubleStyleInterpolation::interpolableValueToDouble(value, isNumber, clamp);
34 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToMotionRotation(InterpolableValue* value, bool flag)
36 return DoubleStyleInterpolation::interpolableValueToMotionRotation(value, flag);
39 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSSValue> value)
41 return interpolableValueToDouble(doubleToInterpolableValue(*value).get(), toCSSPrimitiveValue(value.get())->isNumber(), RangeAll);
44 static PassRefPtrWillBeRawPtr<CSSValue> roundTripMotionRotation(PassRefPtrWillBeRawPtr<CSSValue> value, bool flag)
46 return interpolableValueToMotionRotation(motionRotationToInterpolableValue(*value).get(), flag);
49 static void testPrimitiveValue(RefPtrWillBeRawPtr<CSSValue> value, double doubleValue, CSSPrimitiveValue::UnitType unitType)
51 EXPECT_TRUE(value->isPrimitiveValue());
52 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(value.get())->getDoubleValue());
53 EXPECT_EQ(unitType, toCSSPrimitiveValue(value.get())->typeWithCalcResolved());
56 static void testValueListMotionRotation(RefPtrWillBeRawPtr<CSSValue> value, double doubleValue, bool flag)
58 EXPECT_TRUE(value->isValueList());
59 const CSSValueList& list = toCSSValueList(*value);
60 const CSSValue* item;
61 if (flag) {
62 EXPECT_EQ(2U, list.length());
63 item = list.item(0);
64 EXPECT_TRUE(item->isPrimitiveValue());
65 EXPECT_EQ(CSSValueAuto, toCSSPrimitiveValue(item)->getValueID());
66 item = list.item(1);
67 } else {
68 EXPECT_EQ(1U, list.length());
69 item = list.item(0);
71 EXPECT_TRUE(item->isPrimitiveValue());
72 EXPECT_EQ(doubleValue, toCSSPrimitiveValue(item)->getDoubleValue());
73 EXPECT_EQ(CSSPrimitiveValue::UnitType::Degrees, toCSSPrimitiveValue(item)->typeWithCalcResolved());
76 static InterpolableValue* getCachedValue(Interpolation& interpolation)
78 return interpolation.getCachedValueForTesting();
82 TEST_F(AnimationDoubleStyleInterpolationTest, ZeroValue)
84 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Number));
85 testPrimitiveValue(value, 0, CSSPrimitiveValue::UnitType::Number);
88 TEST_F(AnimationDoubleStyleInterpolationTest, AngleValue)
90 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Degrees));
91 testPrimitiveValue(value, 10, CSSPrimitiveValue::UnitType::Degrees);
93 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Radians));
94 testPrimitiveValue(value, rad2deg(10.0), CSSPrimitiveValue::UnitType::Degrees);
96 value = roundTrip(CSSPrimitiveValue::create(10, CSSPrimitiveValue::UnitType::Gradians));
97 testPrimitiveValue(value, grad2deg(10.0), CSSPrimitiveValue::UnitType::Degrees);
100 TEST_F(AnimationDoubleStyleInterpolationTest, Clamping)
102 RefPtr<Interpolation> interpolableDouble = DoubleStyleInterpolation::create(
103 *CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Number),
104 *CSSPrimitiveValue::create(0.6, CSSPrimitiveValue::UnitType::Number),
105 CSSPropertyLineHeight,
106 true,
107 RangeAll);
108 interpolableDouble->interpolate(0, 0.4);
109 // progVal = start*(1-prog) + end*prog
110 EXPECT_EQ(0.24, toInterpolableNumber(getCachedValue(*interpolableDouble))->value());
113 TEST_F(AnimationDoubleStyleInterpolationTest, ZeroValueFixedMotionRotation)
115 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
116 list->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Degrees));
117 RefPtrWillBeRawPtr<CSSValue> value = roundTripMotionRotation(list.release(), false);
118 testValueListMotionRotation(value, 0, false);
121 TEST_F(AnimationDoubleStyleInterpolationTest, ZeroValueAutoMotionRotation)
123 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
124 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto));
125 list->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Degrees));
126 RefPtrWillBeRawPtr<CSSValue> value = roundTripMotionRotation(list.release(), true);
127 testValueListMotionRotation(value, 0, true);
130 TEST_F(AnimationDoubleStyleInterpolationTest, ValueFixedMotionRotation)
132 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
133 list->append(CSSPrimitiveValue::create(90, CSSPrimitiveValue::UnitType::Degrees));
134 RefPtrWillBeRawPtr<CSSValue> value = roundTripMotionRotation(list.release(), false);
135 testValueListMotionRotation(value, 90, false);
138 TEST_F(AnimationDoubleStyleInterpolationTest, ValueAutoMotionRotation)
140 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
141 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto));
142 list->append(CSSPrimitiveValue::create(90, CSSPrimitiveValue::UnitType::Degrees));
143 RefPtrWillBeRawPtr<CSSValue> value = roundTripMotionRotation(list.release(), true);
144 testValueListMotionRotation(value, 90, true);