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.
4
5#include "config.h"
6#include "core/animation/DeferredLegacyStyleInterpolation.h"
7
8#include "core/css/CSSInheritedValue.h"
9#include "core/css/CSSPrimitiveValue.h"
10#include "core/css/CSSValueList.h"
11#include "core/css/StylePropertySet.h"
12#include "core/css/parser/CSSParser.h"
13
14#include <gtest/gtest.h>
15
16namespace blink {
17
18class AnimationDeferredLegacyStyleInterpolationTest : public ::testing::Test {
19protected:
20    static bool test(CSSPropertyID propertyID, const String& string)
21    {
22        CSSParserMode parserMode = HTMLStandardMode;
23        if (propertyID == CSSPropertyFloodColor)
24            parserMode = SVGAttributeMode;
25        RefPtrWillBeRawPtr<CSSValue> value = CSSParser::parseSingleValue(propertyID, string, CSSParserContext(parserMode, 0));
26        ASSERT(value);
27        return DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*value);
28    }
29};
30
31TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Inherit)
32{
33    EXPECT_TRUE(test(CSSPropertyCaptionSide, "inherit"));
34}
35
36TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Color)
37{
38    EXPECT_FALSE(test(CSSPropertyColor, "rgb(10, 20, 30)"));
39    EXPECT_FALSE(test(CSSPropertyColor, "aqua"));
40    EXPECT_FALSE(test(CSSPropertyColor, "yellow"));
41    EXPECT_FALSE(test(CSSPropertyColor, "transparent"));
42    EXPECT_FALSE(test(CSSPropertyFloodColor, "aliceblue"));
43    EXPECT_FALSE(test(CSSPropertyFloodColor, "yellowgreen"));
44    EXPECT_FALSE(test(CSSPropertyFloodColor, "grey"));
45    EXPECT_TRUE(test(CSSPropertyColor, "currentcolor"));
46}
47
48TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Relative)
49{
50    EXPECT_TRUE(test(CSSPropertyFontWeight, "bolder"));
51    EXPECT_TRUE(test(CSSPropertyFontWeight, "lighter"));
52    EXPECT_TRUE(test(CSSPropertyFontSize, "smaller"));
53    EXPECT_TRUE(test(CSSPropertyFontSize, "larger"));
54}
55
56TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Length)
57{
58    EXPECT_FALSE(test(CSSPropertyWidth, "10px"));
59    EXPECT_TRUE(test(CSSPropertyWidth, "10em"));
60    EXPECT_TRUE(test(CSSPropertyWidth, "10vh"));
61}
62
63TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Number)
64{
65    EXPECT_FALSE(test(CSSPropertyOpacity, "0.5"));
66}
67
68TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Transform)
69{
70    EXPECT_TRUE(test(CSSPropertyTransform, "translateX(1em)"));
71    EXPECT_FALSE(test(CSSPropertyTransform, "translateY(20px)"));
72    EXPECT_FALSE(test(CSSPropertyTransform, "skewX(10rad) perspective(400px)"));
73    EXPECT_TRUE(test(CSSPropertyTransform, "skewX(20rad) perspective(50em)"));
74}
75
76TEST_F(AnimationDeferredLegacyStyleInterpolationTest, Filter)
77{
78    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "hue-rotate(180deg) blur(6px)"));
79    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "grayscale(0) blur(0px)"));
80    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "none"));
81    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "brightness(0) contrast(0)"));
82    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "drop-shadow(20px 10px green)"));
83    EXPECT_TRUE(test(CSSPropertyWebkitFilter, "drop-shadow(20px 10vw green)"));
84    EXPECT_TRUE(test(CSSPropertyWebkitFilter, "drop-shadow(0px 0px 0px currentcolor)"));
85    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "opacity(1)"));
86    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "saturate(0)"));
87    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "grayscale(1)"));
88    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "invert(1)"));
89    EXPECT_FALSE(test(CSSPropertyWebkitFilter, "sepia(1)"));
90    EXPECT_TRUE(test(CSSPropertyWebkitFilter, "url(#svgfilter)"));
91}
92
93}
94