Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: third_party/WebKit/Source/core/animation/AnimationInputHelpersTest.cpp

Issue 1851003002: Throw TypeError if easing string is invalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/animation/AnimationInputHelpers.h" 5 #include "core/animation/AnimationInputHelpers.h"
6 6
7 #include "core/dom/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/dom/ExceptionCode.h"
8 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
9 #include "platform/animation/TimingFunction.h" 10 #include "platform/animation/TimingFunction.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 class AnimationAnimationInputHelpersTest : public ::testing::Test { 15 class AnimationAnimationInputHelpersTest : public ::testing::Test {
15 public: 16 public:
16 CSSPropertyID keyframeAttributeToCSSProperty(const String& property) 17 CSSPropertyID keyframeAttributeToCSSProperty(const String& property)
17 { 18 {
(...skipping 10 matching lines...) Expand all
28 void TearDown() override 29 void TearDown() override
29 { 30 {
30 document.release(); 31 document.release();
31 #if ENABLE(OILPAN) 32 #if ENABLE(OILPAN)
32 Heap::collectAllGarbage(); 33 Heap::collectAllGarbage();
33 #endif 34 #endif
34 } 35 }
35 36
36 OwnPtr<DummyPageHolder> pageHolder; 37 OwnPtr<DummyPageHolder> pageHolder;
37 Persistent<Document> document; 38 Persistent<Document> document;
39 TrackExceptionState exceptionState;
38 }; 40 };
39 41
40 TEST_F(AnimationAnimationInputHelpersTest, ParseKeyframePropertyAttributes) 42 TEST_F(AnimationAnimationInputHelpersTest, ParseKeyframePropertyAttributes)
41 { 43 {
42 EXPECT_EQ(CSSPropertyLineHeight, keyframeAttributeToCSSProperty("lineHeight" )); 44 EXPECT_EQ(CSSPropertyLineHeight, keyframeAttributeToCSSProperty("lineHeight" ));
43 EXPECT_EQ(CSSPropertyBorderTopWidth, keyframeAttributeToCSSProperty("borderT opWidth")); 45 EXPECT_EQ(CSSPropertyBorderTopWidth, keyframeAttributeToCSSProperty("borderT opWidth"));
44 EXPECT_EQ(CSSPropertyWidth, keyframeAttributeToCSSProperty("width")); 46 EXPECT_EQ(CSSPropertyWidth, keyframeAttributeToCSSProperty("width"));
45 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("float")); 47 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("float"));
46 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("cssFloat")); 48 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("cssFloat"));
47 49
48 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("line-height")) ; 50 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("line-height")) ;
49 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("border-topWidt h")); 51 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("border-topWidt h"));
50 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("Width")); 52 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("Width"));
51 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-epub-text-tra nsform")); 53 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-epub-text-tra nsform"));
52 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("EpubTextTransf orm")); 54 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("EpubTextTransf orm"));
53 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-internal-marq uee-repetition")); 55 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-internal-marq uee-repetition"));
54 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("InternalMarque eRepetition")); 56 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("InternalMarque eRepetition"));
55 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-filter ")); 57 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-filter "));
56 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-transf orm")); 58 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-transf orm"));
57 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("webkitTransfor m")); 59 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("webkitTransfor m"));
58 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("WebkitTransfor m")); 60 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("WebkitTransfor m"));
59 } 61 }
60 62
61 static bool timingFunctionRoundTrips(const String& string) 63 static bool timingFunctionRoundTrips(const String& string, ExceptionState& excep tionState)
62 { 64 {
63 RefPtr<TimingFunction> timingFunction = AnimationInputHelpers::parseTimingFu nction(string); 65 RefPtr<TimingFunction> timingFunction = AnimationInputHelpers::parseTimingFu nction(string, exceptionState);
64 return timingFunction && string == timingFunction->toString(); 66 return timingFunction && string == timingFunction->toString();
alancutter (OOO until 2018) 2016/04/05 04:50:06 It's probably better to EXPECT_EQ here for informa
suzyh_UTC10 (ex-contributor) 2016/04/12 08:04:23 Done.
65 } 67 }
66 68
69 static void timingFunctionThrows(const String& string, ExceptionState& exception State)
70 {
71 RefPtr<TimingFunction> timingFunction = AnimationInputHelpers::parseTimingFu nction(string, exceptionState);
72 EXPECT_TRUE(exceptionState.hadException());
73 EXPECT_EQ(V8TypeError, exceptionState.code());
74 }
75
67 TEST_F(AnimationAnimationInputHelpersTest, ParseAnimationTimingFunction) 76 TEST_F(AnimationAnimationInputHelpersTest, ParseAnimationTimingFunction)
68 { 77 {
69 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("initial")); 78 timingFunctionThrows("", exceptionState);
70 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("inherit")); 79 timingFunctionThrows("initial", exceptionState);
71 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("unset")); 80 timingFunctionThrows("inherit", exceptionState);
81 timingFunctionThrows("unset", exceptionState);
72 82
73 EXPECT_TRUE(timingFunctionRoundTrips("ease")); 83 EXPECT_TRUE(timingFunctionRoundTrips("ease", exceptionState));
74 EXPECT_TRUE(timingFunctionRoundTrips("linear")); 84 EXPECT_TRUE(timingFunctionRoundTrips("linear", exceptionState));
75 EXPECT_TRUE(timingFunctionRoundTrips("ease-in")); 85 EXPECT_TRUE(timingFunctionRoundTrips("ease-in", exceptionState));
76 EXPECT_TRUE(timingFunctionRoundTrips("ease-out")); 86 EXPECT_TRUE(timingFunctionRoundTrips("ease-out", exceptionState));
77 EXPECT_TRUE(timingFunctionRoundTrips("ease-in-out")); 87 EXPECT_TRUE(timingFunctionRoundTrips("ease-in-out", exceptionState));
78 EXPECT_TRUE(timingFunctionRoundTrips("step-start")); 88 EXPECT_TRUE(timingFunctionRoundTrips("step-start", exceptionState));
79 EXPECT_TRUE(timingFunctionRoundTrips("step-middle")); 89 EXPECT_TRUE(timingFunctionRoundTrips("step-middle", exceptionState));
80 EXPECT_TRUE(timingFunctionRoundTrips("step-end")); 90 EXPECT_TRUE(timingFunctionRoundTrips("step-end", exceptionState));
81 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, start)")); 91 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, start)", exceptionState));
82 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, middle)")); 92 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, middle)", exceptionState));
83 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, end)")); 93 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, end)", exceptionState));
84 EXPECT_TRUE(timingFunctionRoundTrips("cubic-bezier(0.1, 5, 0.23, 0)")); 94 EXPECT_TRUE(timingFunctionRoundTrips("cubic-bezier(0.1, 5, 0.23, 0)", except ionState));
85 95
86 EXPECT_EQ("steps(3, end)", AnimationInputHelpers::parseTimingFunction("steps (3)")->toString()); 96 EXPECT_EQ("steps(3, end)", AnimationInputHelpers::parseTimingFunction("steps (3)", exceptionState)->toString());
87 97
88 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("steps(3, nowh ere)")); 98 timingFunctionThrows("steps(3, nowhere)", exceptionState);
89 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("steps(-3, end )")); 99 timingFunctionThrows("steps(-3, end)", exceptionState);
90 EXPECT_EQ(nullptr, AnimationInputHelpers::parseTimingFunction("cubic-bezier( 0.1, 0, 4, 0.4)")); 100 timingFunctionThrows("cubic-bezier(0.1, 0, 4, 0.4)", exceptionState);
91 } 101 }
92 102
93 } // namespace blink 103 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698