2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "core/animation/AnimatableValueTestHelper.h"
35 #include "core/rendering/ClipPathOperation.h"
36 #include "core/rendering/style/BasicShapes.h"
37 #include "core/svg/SVGLengthContext.h"
38 #include "platform/transforms/ScaleTransformOperation.h"
39 #include "platform/transforms/TranslateTransformOperation.h"
41 #include <gmock/gmock.h>
42 #include <gtest/gtest.h>
47 using namespace WebCore;
51 class AnimationAnimatableValueTestHelperTest : public ::testing::Test {
53 ::std::string PrintToString(PassRefPtrWillBeRawPtr<AnimatableValue> animValue)
55 return ::testing::PrintToString(*animValue.get());
59 TEST_F(AnimationAnimatableValueTestHelperTest, PrintTo)
62 PrintToString(AnimatableClipPathOperation::create(ShapeClipPathOperation::create(BasicShapeCircle::create().get()).get())),
63 testing::StartsWith("AnimatableClipPathOperation")
67 ::std::string("AnimatableColor(rgba(0, 0, 0, 0), #ff0000)"),
68 PrintToString(AnimatableColor::create(Color(0x000000FF), Color(0xFFFF0000))));
71 ::std::string("AnimatableDouble(1)"),
72 PrintToString(AnimatableDouble::create(1.0)));
75 ::std::string("AnimatableLength(5px)"),
76 PrintToString(AnimatableLength::create(CSSPrimitiveValue::create(5, CSSPrimitiveValue::CSS_PX).get())));
79 ::std::string("AnimatableLengthBox(AnimatableLength(1px), AnimatableLength(2em), AnimatableLength(3rem), AnimatableLength(4pt))"),
80 PrintToString(AnimatableLengthBox::create(
81 AnimatableLength::create(CSSPrimitiveValue::create(1, CSSPrimitiveValue::CSS_PX).get()),
82 AnimatableLength::create(CSSPrimitiveValue::create(2, CSSPrimitiveValue::CSS_EMS).get()),
83 AnimatableLength::create(CSSPrimitiveValue::create(3, CSSPrimitiveValue::CSS_REMS).get()),
84 AnimatableLength::create(CSSPrimitiveValue::create(4, CSSPrimitiveValue::CSS_PT).get())
88 ::std::string("AnimatableLengthPoint(AnimatableLength(5%), AnimatableLength(6px))"),
89 PrintToString(AnimatableLengthPoint::create(
90 AnimatableLength::create(CSSPrimitiveValue::create(5, CSSPrimitiveValue::CSS_PERCENTAGE).get()),
91 AnimatableLength::create(CSSPrimitiveValue::create(6, CSSPrimitiveValue::CSS_PX).get())
95 ::std::string("AnimatableLengthSize(AnimatableLength(3rem), AnimatableLength(4pt))"),
96 PrintToString(AnimatableLengthSize::create(
97 AnimatableLength::create(CSSPrimitiveValue::create(3, CSSPrimitiveValue::CSS_REMS).get()),
98 AnimatableLength::create(CSSPrimitiveValue::create(4, CSSPrimitiveValue::CSS_PT).get())
102 PrintToString(const_cast<AnimatableValue*>(AnimatableValue::neutralValue())),
103 testing::StartsWith("AnimatableNeutral@"));
105 WillBeHeapVector<RefPtrWillBeMember<AnimatableValue> > v1;
106 v1.append(AnimatableLength::create(CSSPrimitiveValue::create(3, CSSPrimitiveValue::CSS_REMS).get()));
107 v1.append(AnimatableLength::create(CSSPrimitiveValue::create(4, CSSPrimitiveValue::CSS_PT).get()));
109 ::std::string("AnimatableRepeatable(AnimatableLength(3rem), AnimatableLength(4pt))"),
110 PrintToString(AnimatableRepeatable::create(v1)));
112 RefPtr<SVGLength> length1cm = SVGLength::create(LengthModeOther);
113 RefPtr<SVGLength> length2cm = SVGLength::create(LengthModeOther);
114 length1cm->setValueAsString("1cm", ASSERT_NO_EXCEPTION);
115 length2cm->setValueAsString("2cm", ASSERT_NO_EXCEPTION);
118 ::std::string("AnimatableSVGLength(1cm)"),
119 PrintToString(AnimatableSVGLength::create(length1cm)));
122 ::std::string("AnimatableSVGPaint(#ff0000)"),
123 PrintToString(AnimatableSVGPaint::create(SVGPaint::SVG_PAINTTYPE_RGBCOLOR, Color(0xFFFF0000), "")));
126 ::std::string("AnimatableSVGPaint(url(abc))"),
127 PrintToString(AnimatableSVGPaint::create(SVGPaint::SVG_PAINTTYPE_URI, Color(0xFFFF0000), "abc")));
130 PrintToString(AnimatableShapeValue::create(ShapeValue::createShapeValue(BasicShapeCircle::create().get(), ContentBox).get())),
131 testing::StartsWith("AnimatableShapeValue@"));
133 RefPtr<SVGLengthList> l2 = SVGLengthList::create();
134 l2->append(length1cm);
135 l2->append(length2cm);
137 ::std::string("AnimatableStrokeDasharrayList(1cm, 2cm)"),
138 PrintToString(AnimatableStrokeDasharrayList::create(l2)));
140 TransformOperations operations1;
141 operations1.operations().append(TranslateTransformOperation::create(Length(2, WebCore::Fixed), Length(0, WebCore::Fixed), TransformOperation::TranslateX));
143 ::std::string("AnimatableTransform([1 0 0 1 2 0])"),
144 PrintToString(AnimatableTransform::create(operations1)));
146 TransformOperations operations2;
147 operations2.operations().append(ScaleTransformOperation::create(1, 1, 1, TransformOperation::Scale3D));
149 ::std::string("AnimatableTransform([1 0 0 1 0 0])"),
150 PrintToString(AnimatableTransform::create(operations2)));
153 ::std::string("AnimatableUnknown(none)"),
154 PrintToString(AnimatableUnknown::create(CSSPrimitiveValue::createIdentifier(CSSValueNone).get())));
157 ::std::string("AnimatableVisibility(VISIBLE)"),
158 PrintToString(AnimatableVisibility::create(VISIBLE)));