| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/ColorStyleInterpolation.h" | 6 #include "core/animation/ColorStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/StylePropertySet.h" | 9 #include "core/css/StylePropertySet.h" |
| 10 #include "platform/graphics/Color.h" | 10 #include "platform/graphics/Color.h" |
| 11 | 11 |
| 12 #include <gtest/gtest.h> | 12 #include <gtest/gtest.h> |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class AnimationColorStyleInterpolationTest : public ::testing::Test { | 16 class AnimationColorStyleInterpolationTest : public ::testing::Test { |
| 17 protected: | 17 protected: |
| 18 static PassOwnPtrWillBeRawPtr<InterpolableValue> colorToInterpolableValue(co
nst CSSValue& value) | 18 static PassOwnPtrWillBeRawPtr<InterpolableValue> colorToInterpolableValue(co
nst CSSValue& value) |
| 19 { | 19 { |
| 20 return ColorStyleInterpolation::colorToInterpolableValue(value); | 20 return ColorStyleInterpolation::colorToInterpolableValue(value); |
| 21 } | 21 } |
| 22 | 22 |
| 23 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToColor(Interpolabl
eValue* value) | 23 static PassRefPtr<CSSValue> interpolableValueToColor(InterpolableValue* valu
e) |
| 24 { | 24 { |
| 25 return ColorStyleInterpolation::interpolableValueToColor(*value); | 25 return ColorStyleInterpolation::interpolableValueToColor(*value); |
| 26 } | 26 } |
| 27 | 27 |
| 28 static PassRefPtrWillBeRawPtr<CSSValue> roundTrip(PassRefPtrWillBeRawPtr<CSS
Value> value) | 28 static PassRefPtr<CSSValue> roundTrip(PassRefPtr<CSSValue> value) |
| 29 { | 29 { |
| 30 return interpolableValueToColor(colorToInterpolableValue(*value).get()); | 30 return interpolableValueToColor(colorToInterpolableValue(*value).get()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void testPrimitiveValue(PassRefPtrWillBeRawPtr<CSSValue> value, RGBA3
2 rgbaValue) | 33 static void testPrimitiveValue(PassRefPtr<CSSValue> value, RGBA32 rgbaValue) |
| 34 { | 34 { |
| 35 EXPECT_TRUE(value->isPrimitiveValue()); | 35 EXPECT_TRUE(value->isPrimitiveValue()); |
| 36 EXPECT_EQ(toCSSPrimitiveValue(value.get())->getRGBA32Value(), rgbaValue)
; | 36 EXPECT_EQ(toCSSPrimitiveValue(value.get())->getRGBA32Value(), rgbaValue)
; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static InterpolableValue* interpolationValue(Interpolation& interpolation) | 39 static InterpolableValue* interpolationValue(Interpolation& interpolation) |
| 40 { | 40 { |
| 41 return interpolation.getCachedValueForTesting(); | 41 return interpolation.getCachedValueForTesting(); |
| 42 } | 42 } |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 TEST_F(AnimationColorStyleInterpolationTest, Color) | 45 TEST_F(AnimationColorStyleInterpolationTest, Color) |
| 46 { | 46 { |
| 47 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColo
r(makeRGBA(54, 48, 214, 64))); | 47 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColor(makeRGBA(5
4, 48, 214, 64))); |
| 48 testPrimitiveValue(value, makeRGBA(54, 48, 214, 64)); | 48 testPrimitiveValue(value, makeRGBA(54, 48, 214, 64)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST_F(AnimationColorStyleInterpolationTest, ClampedColor) | 51 TEST_F(AnimationColorStyleInterpolationTest, ClampedColor) |
| 52 { | 52 { |
| 53 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColo
r(makeRGBA(-10, -10, -10, -10))); | 53 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColor(makeRGBA(-
10, -10, -10, -10))); |
| 54 testPrimitiveValue(value, makeRGBA(-10, -10, -10, -10)); | 54 testPrimitiveValue(value, makeRGBA(-10, -10, -10, -10)); |
| 55 | 55 |
| 56 value = roundTrip(CSSPrimitiveValue::createColor(makeRGBA(-260, -260, -260,
-260))); | 56 value = roundTrip(CSSPrimitiveValue::createColor(makeRGBA(-260, -260, -260,
-260))); |
| 57 testPrimitiveValue(value, makeRGBA(-260, -260, -260, -260)); | 57 testPrimitiveValue(value, makeRGBA(-260, -260, -260, -260)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST_F(AnimationColorStyleInterpolationTest, ZeroAlpha) | 60 TEST_F(AnimationColorStyleInterpolationTest, ZeroAlpha) |
| 61 { | 61 { |
| 62 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColo
r(makeRGBA(54, 58, 214, 0))); | 62 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createColor(makeRGBA(5
4, 58, 214, 0))); |
| 63 testPrimitiveValue(value, Color::transparent); | 63 testPrimitiveValue(value, Color::transparent); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(AnimationColorStyleInterpolationTest, ValueIDColor) | 66 TEST_F(AnimationColorStyleInterpolationTest, ValueIDColor) |
| 67 { | 67 { |
| 68 RefPtrWillBeRawPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createIden
tifier(CSSValueID::CSSValueBlue)); | 68 RefPtr<CSSValue> value = roundTrip(CSSPrimitiveValue::createIdentifier(CSSVa
lueID::CSSValueBlue)); |
| 69 testPrimitiveValue(value, makeRGB(0, 0, 255)); | 69 testPrimitiveValue(value, makeRGB(0, 0, 255)); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST_F(AnimationColorStyleInterpolationTest, Interpolation) | 72 TEST_F(AnimationColorStyleInterpolationTest, Interpolation) |
| 73 { | 73 { |
| 74 RefPtrWillBeRawPtr<Interpolation> interpolation = ColorStyleInterpolation::c
reate( | 74 RefPtrWillBeRawPtr<Interpolation> interpolation = ColorStyleInterpolation::c
reate( |
| 75 *CSSPrimitiveValue::createColor(makeRGBA(0, 0, 0, 255)), | 75 *CSSPrimitiveValue::createColor(makeRGBA(0, 0, 0, 255)), |
| 76 *CSSPrimitiveValue::createColor(makeRGBA(255, 255, 255, 255)), | 76 *CSSPrimitiveValue::createColor(makeRGBA(255, 255, 255, 255)), |
| 77 CSSPropertyColor | 77 CSSPropertyColor |
| 78 ); | 78 ); |
| 79 | 79 |
| 80 interpolation->interpolate(0, 0.5); | 80 interpolation->interpolate(0, 0.5); |
| 81 RefPtrWillBeRawPtr<CSSValue> value = interpolableValueToColor(interpolationV
alue(*interpolation)); | 81 RefPtr<CSSValue> value = interpolableValueToColor(interpolationValue(*interp
olation)); |
| 82 | 82 |
| 83 testPrimitiveValue(value, makeRGBA(128, 128, 128, 255)); | 83 testPrimitiveValue(value, makeRGBA(128, 128, 128, 255)); |
| 84 } | 84 } |
| 85 } | 85 } |
| OLD | NEW |