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

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: Fix "liner"->"linear" typo in ui/file_manager js file 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 {
18 return AnimationInputHelpers::keyframeAttributeToCSSProperty(property, * document); 19 return AnimationInputHelpers::keyframeAttributeToCSSProperty(property, * document);
19 } 20 }
20 21
21 PassRefPtr<TimingFunction> parseTimingFunction(const String& string) 22 PassRefPtr<TimingFunction> parseTimingFunction(const String& string, Excepti onState& exceptionState)
22 { 23 {
23 return AnimationInputHelpers::parseTimingFunction(string, document); 24 return AnimationInputHelpers::parseTimingFunction(string, document, exce ptionState);
24 } 25 }
25 26
26 bool timingFunctionRoundTrips(const String& string) 27 void timingFunctionRoundTrips(const String& string, ExceptionState& exceptio nState)
27 { 28 {
28 RefPtr<TimingFunction> timingFunction = parseTimingFunction(string); 29 RefPtr<TimingFunction> timingFunction = parseTimingFunction(string, exce ptionState);
29 return timingFunction && string == timingFunction->toString(); 30 EXPECT_NE(nullptr, timingFunction);
31 EXPECT_EQ(string, timingFunction->toString());
30 } 32 }
31 33
34 void timingFunctionThrows(const String& string, ExceptionState& exceptionSta te)
35 {
36 RefPtr<TimingFunction> timingFunction = parseTimingFunction(string, exce ptionState);
37 EXPECT_TRUE(exceptionState.hadException());
38 EXPECT_EQ(V8TypeError, exceptionState.code());
39 }
40
41
32 protected: 42 protected:
33 void SetUp() override 43 void SetUp() override
34 { 44 {
35 pageHolder = DummyPageHolder::create(); 45 pageHolder = DummyPageHolder::create();
36 document = &pageHolder->document(); 46 document = &pageHolder->document();
37 } 47 }
38 48
39 void TearDown() override 49 void TearDown() override
40 { 50 {
41 document.release(); 51 document.release();
42 Heap::collectAllGarbage(); 52 Heap::collectAllGarbage();
43 } 53 }
44 54
45 OwnPtr<DummyPageHolder> pageHolder; 55 OwnPtr<DummyPageHolder> pageHolder;
46 Persistent<Document> document; 56 Persistent<Document> document;
57 TrackExceptionState exceptionState;
47 }; 58 };
48 59
49 TEST_F(AnimationAnimationInputHelpersTest, ParseKeyframePropertyAttributes) 60 TEST_F(AnimationAnimationInputHelpersTest, ParseKeyframePropertyAttributes)
50 { 61 {
51 EXPECT_EQ(CSSPropertyLineHeight, keyframeAttributeToCSSProperty("lineHeight" )); 62 EXPECT_EQ(CSSPropertyLineHeight, keyframeAttributeToCSSProperty("lineHeight" ));
52 EXPECT_EQ(CSSPropertyBorderTopWidth, keyframeAttributeToCSSProperty("borderT opWidth")); 63 EXPECT_EQ(CSSPropertyBorderTopWidth, keyframeAttributeToCSSProperty("borderT opWidth"));
53 EXPECT_EQ(CSSPropertyWidth, keyframeAttributeToCSSProperty("width")); 64 EXPECT_EQ(CSSPropertyWidth, keyframeAttributeToCSSProperty("width"));
54 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("float")); 65 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("float"));
55 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("cssFloat")); 66 EXPECT_EQ(CSSPropertyFloat, keyframeAttributeToCSSProperty("cssFloat"));
56 67
57 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("line-height")) ; 68 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("line-height")) ;
58 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("border-topWidt h")); 69 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("border-topWidt h"));
59 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("Width")); 70 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("Width"));
60 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-epub-text-tra nsform")); 71 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-epub-text-tra nsform"));
61 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("EpubTextTransf orm")); 72 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("EpubTextTransf orm"));
62 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-internal-marq uee-repetition")); 73 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-internal-marq uee-repetition"));
63 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("InternalMarque eRepetition")); 74 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("InternalMarque eRepetition"));
64 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-filter ")); 75 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-filter "));
65 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-transf orm")); 76 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("-webkit-transf orm"));
66 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("webkitTransfor m")); 77 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("webkitTransfor m"));
67 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("WebkitTransfor m")); 78 EXPECT_EQ(CSSPropertyInvalid, keyframeAttributeToCSSProperty("WebkitTransfor m"));
68 } 79 }
69 80
70 TEST_F(AnimationAnimationInputHelpersTest, ParseAnimationTimingFunction) 81 TEST_F(AnimationAnimationInputHelpersTest, ParseAnimationTimingFunction)
71 { 82 {
72 EXPECT_EQ(nullptr, parseTimingFunction("initial")); 83 timingFunctionThrows("", exceptionState);
73 EXPECT_EQ(nullptr, parseTimingFunction("inherit")); 84 timingFunctionThrows("initial", exceptionState);
74 EXPECT_EQ(nullptr, parseTimingFunction("unset")); 85 timingFunctionThrows("inherit", exceptionState);
86 timingFunctionThrows("unset", exceptionState);
75 87
76 EXPECT_TRUE(timingFunctionRoundTrips("ease")); 88 timingFunctionRoundTrips("ease", exceptionState);
77 EXPECT_TRUE(timingFunctionRoundTrips("linear")); 89 timingFunctionRoundTrips("linear", exceptionState);
78 EXPECT_TRUE(timingFunctionRoundTrips("ease-in")); 90 timingFunctionRoundTrips("ease-in", exceptionState);
79 EXPECT_TRUE(timingFunctionRoundTrips("ease-out")); 91 timingFunctionRoundTrips("ease-out", exceptionState);
80 EXPECT_TRUE(timingFunctionRoundTrips("ease-in-out")); 92 timingFunctionRoundTrips("ease-in-out", exceptionState);
81 EXPECT_TRUE(timingFunctionRoundTrips("step-start")); 93 timingFunctionRoundTrips("step-start", exceptionState);
82 EXPECT_TRUE(timingFunctionRoundTrips("step-middle")); 94 timingFunctionRoundTrips("step-middle", exceptionState);
83 EXPECT_TRUE(timingFunctionRoundTrips("step-end")); 95 timingFunctionRoundTrips("step-end", exceptionState);
84 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, start)")); 96 timingFunctionRoundTrips("steps(3, start)", exceptionState);
85 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, middle)")); 97 timingFunctionRoundTrips("steps(3, middle)", exceptionState);
86 EXPECT_TRUE(timingFunctionRoundTrips("steps(3, end)")); 98 timingFunctionRoundTrips("steps(3, end)", exceptionState);
87 EXPECT_TRUE(timingFunctionRoundTrips("cubic-bezier(0.1, 5, 0.23, 0)")); 99 timingFunctionRoundTrips("cubic-bezier(0.1, 5, 0.23, 0)", exceptionState);
88 100
89 EXPECT_EQ("steps(3, end)", parseTimingFunction("steps(3)")->toString()); 101 EXPECT_EQ("steps(3, end)", parseTimingFunction("steps(3)", exceptionState)-> toString());
90 102
91 EXPECT_EQ(nullptr, parseTimingFunction("steps(3, nowhere)")); 103 timingFunctionThrows("steps(3, nowhere)", exceptionState);
92 EXPECT_EQ(nullptr, parseTimingFunction("steps(-3, end)")); 104 timingFunctionThrows("steps(-3, end)", exceptionState);
93 EXPECT_EQ(nullptr, parseTimingFunction("cubic-bezier(0.1, 0, 4, 0.4)")); 105 timingFunctionThrows("cubic-bezier(0.1, 0, 4, 0.4)", exceptionState);
94 } 106 }
95 107
96 } // namespace blink 108 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698