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

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: Added test to check that animate() does not leak into stable. 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 <gtest/gtest.h>
43
44 namespace WebCore {
45
46 namespace {
47
48 v8::Handle<v8::Value> stringToV8Value(String string)
49 {
50 return v8::Handle<v8::Value>::Cast(v8String(v8::Isolate::GetCurrent(), strin g));
51 }
52
53 void setV8ObjectProperty(v8::Handle<v8::Object> object, String name, String valu e)
54 {
55 object->Set(stringToV8Value(name), stringToV8Value(value));
56 }
57
58 } // namespace
59
60 class AnimationElementAnimationTest : public ::testing::Test {
61 protected:
62 virtual void SetUp()
63 {
64 document = Document::create();
65 document->animationClock().resetTimeForTesting();
66 element = document->createElement("foo", ASSERT_NO_EXCEPTION);
67 document->timeline()->setZeroTime(0);
68 ASSERT_EQ(0, document->timeline()->currentTime());
69 }
70
71 RefPtr<Document> document;
72 RefPtr<Element> element;
73 };
74
75 TEST_F(AnimationElementAnimationTest, CanStartAnAnimation)
76 {
77 v8::Isolate* isolate = v8::Isolate::GetCurrent();
78 v8::HandleScope scope(isolate);
79 v8::Local<v8::Context> context = v8::Context::New(isolate);
80 v8::Context::Scope contextScope(context);
81
82 Vector<Dictionary> jsKeyframes;
83 v8::Handle<v8::Object> keyframe1 = v8::Object::New();
84 v8::Handle<v8::Object> keyframe2 = v8::Object::New();
85
86 setV8ObjectProperty(keyframe1, "width", "100px");
87 setV8ObjectProperty(keyframe1, "offset", "0");
88 setV8ObjectProperty(keyframe2, "width", "0px");
89 setV8ObjectProperty(keyframe2, "offset", "1");
90
91 jsKeyframes.append(Dictionary(keyframe1, isolate));
92 jsKeyframes.append(Dictionary(keyframe2, isolate));
93
94 String value1;
95 ASSERT_TRUE(jsKeyframes[0].get("width", value1));
96 ASSERT_EQ("100px", value1);
97
98 String value2;
99 ASSERT_TRUE(jsKeyframes[1].get("width", value2));
100 ASSERT_EQ("0px", value2);
101
102 ElementAnimation::animate(element.get(), jsKeyframes);
103
104 Player* player = document->timeline()->players().at(0).get();
105
106 Animation* animation = toAnimation(player->source());
107
108 Element* target = animation->target();
109 EXPECT_EQ(*element.get(), *target);
110
111 const KeyframeAnimationEffect::KeyframeVector keyframes =
112 toKeyframeAnimationEffect(animation->effect())->getFrames();
113
114 EXPECT_EQ(0, keyframes[0]->offset());
115 EXPECT_EQ(1, keyframes[1]->offset());
116
117 const AnimatableValue* keyframe1Width = keyframes[0]->propertyValue(CSSPrope rtyWidth);
118 const AnimatableValue* keyframe2Width = keyframes[1]->propertyValue(CSSPrope rtyWidth);
119 ASSERT(keyframe1Width);
120 ASSERT(keyframe2Width);
121
122 EXPECT_TRUE(keyframe1Width->isLength());
123 EXPECT_TRUE(keyframe2Width->isLength());
124
125 EXPECT_EQ("100px", toAnimatableLength(keyframe1Width)->toCSSValue()->cssText ());
126 EXPECT_EQ("0px", toAnimatableLength(keyframe2Width)->toCSSValue()->cssText() );
127 }
128
129 TEST_F(AnimationElementAnimationTest, ParseCamelCasePropertyNames)
130 {
131 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("line-height").impl()));
132 EXPECT_EQ(CSSPropertyLineHeight, ElementAnimation::camelCaseCSSPropertyNameT oID(String("lineHeight").impl()));
133 EXPECT_EQ(CSSPropertyBorderTopWidth, ElementAnimation::camelCaseCSSPropertyN ameToID(String("borderTopWidth").impl()));
134 EXPECT_EQ(CSSPropertyWidth, ElementAnimation::camelCaseCSSPropertyNameToID(S tring("width").impl()));
135 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("Width").impl()));
136 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("-webkit-transform").impl()));
137 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("webkitTransform").impl()));
138 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID (String("cssFloat").impl()));
139 }
140
141 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698