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

Side by Side Diff: Source/core/animation/ElementAnimationTest.cpp

Issue 96283002: Web Animations API: Start implementation of Element.animate(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix broken unit test Created 7 years 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
(Empty)
1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31 #include "config.h"
32 #include "core/animation/ElementAnimation.h"
33
34 #include "core/animation/AnimatableLength.h"
35 #include "core/animation/Animation.h"
36 #include "core/animation/AnimationClock.h"
37 #include "core/animation/DocumentTimeline.h"
38 #include "core/animation/KeyframeAnimationEffect.h"
39 #include "core/dom/Document.h"
40 #include "core/dom/Element.h"
41
42 #include <gmock/gmock.h>
43 #include <gtest/gtest.h>
44
45 namespace WebCore {
46
47 namespace {
48
49 v8::Handle<v8::Value> stringToV8Value(String string)
50 {
51 return v8::Handle<v8::Value>::Cast(v8String(v8::Isolate::GetCurrent(), strin g));
52 }
53
54 void setV8ObjectProperty(v8::Handle<v8::Object> object, String name, String valu e)
55 {
56 object->Set(stringToV8Value(name), stringToV8Value(value));
57 }
58
59 } // namespace
60
61 class AnimationElementAnimationTest : public ::testing::Test {
62 protected:
63 virtual void SetUp()
64 {
65 document = Document::create();
66 document->animationClock().resetTimeForTesting();
67 element = document->createElement("foo", ASSERT_NO_EXCEPTION);
68 document->timeline()->setZeroTime(0);
69 ASSERT_EQ(0, document->timeline()->currentTime());
70 }
71
72 RefPtr<Document> document;
73 RefPtr<Element> element;
74
75 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary Vector)
76 {
77 ElementAnimation::startAnimation(element, keyframesDictionaryVector);
78 }
79 };
80
81 TEST_F(AnimationElementAnimationTest, CanStartAnAnimation)
82 {
83 v8::Isolate* isolate = v8::Isolate::GetCurrent();
84 v8::HandleScope scope(isolate);
85 v8::Local<v8::Context> context = v8::Context::New(isolate);
86 v8::Context::Scope contextScope(context);
87
88 Vector<Dictionary> jsKeyframes;
89 v8::Handle<v8::Object> keyframe1 = v8::Object::New();
90 v8::Handle<v8::Object> keyframe2 = v8::Object::New();
91
92 setV8ObjectProperty(keyframe1, "width", "100px");
93 setV8ObjectProperty(keyframe1, "offset", "0");
94 setV8ObjectProperty(keyframe2, "width", "0px");
95 setV8ObjectProperty(keyframe2, "offset", "1");
96
97 jsKeyframes.append(Dictionary(keyframe1, isolate));
98 jsKeyframes.append(Dictionary(keyframe2, isolate));
99
100 String value1;
101 ASSERT_TRUE(jsKeyframes[0].get("width", value1));
102 ASSERT_EQ("100px", value1);
103
104 String value2;
105 ASSERT_TRUE(jsKeyframes[1].get("width", value2));
106 ASSERT_EQ("0px", value2);
107
108 startAnimation(element.get(), jsKeyframes);
109
110 ASSERT_EQ(1ul, document->timeline()->players().size());
111
112 Player* player = document->timeline()->players().at(0).get();
113
114 Animation* animation = toAnimation(player->source());
115
116 Element* target = animation->target();
117 EXPECT_EQ(*element.get(), *target);
118
119 const KeyframeAnimationEffect::KeyframeVector keyframes =
120 toKeyframeAnimationEffect(animation->effect())->getFrames();
121
122 ASSERT_EQ(2ul, keyframes.size());
123 EXPECT_EQ(0, keyframes[0]->offset());
124 EXPECT_EQ(1, keyframes[1]->offset());
125
126 const AnimatableValue* keyframe1Width = keyframes[0]->propertyValue(CSSPrope rtyWidth);
127 const AnimatableValue* keyframe2Width = keyframes[1]->propertyValue(CSSPrope rtyWidth);
128 ASSERT(keyframe1Width);
129 ASSERT(keyframe2Width);
130
131 EXPECT_TRUE(keyframe1Width->isLength());
132 EXPECT_TRUE(keyframe2Width->isLength());
133
134 EXPECT_EQ("100px", toAnimatableLength(keyframe1Width)->toCSSValue()->cssText ());
135 EXPECT_EQ("0px", toAnimatableLength(keyframe2Width)->toCSSValue()->cssText() );
136 }
137
138 TEST_F(AnimationElementAnimationTest, ParseCamelCasePropertyNames)
139 {
140 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("line-height").impl()));
141 EXPECT_EQ(CSSPropertyLineHeight, ElementAnimation::camelCaseCSSPropertyNameT oID(String("lineHeight").impl()));
142 EXPECT_EQ(CSSPropertyBorderTopWidth, ElementAnimation::camelCaseCSSPropertyN ameToID(String("borderTopWidth").impl()));
143 EXPECT_EQ(CSSPropertyWidth, ElementAnimation::camelCaseCSSPropertyNameToID(S tring("width").impl()));
144 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("Width").impl()));
145 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("-webkit-transform").impl()));
146 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("webkitTransform").impl()));
147 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("cssFloat").impl()));
148 }
149
150 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698