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