| OLD | NEW |
| (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 void startAnimation(Element* element, Vector<Dictionary> keyframesDictionary
Vector) |
| 75 { |
| 76 ElementAnimation::startAnimation(element, keyframesDictionaryVector); |
| 77 } |
| 78 }; |
| 79 |
| 80 TEST_F(AnimationElementAnimationTest, CanStartAnAnimation) |
| 81 { |
| 82 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 83 v8::HandleScope scope(isolate); |
| 84 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 85 v8::Context::Scope contextScope(context); |
| 86 |
| 87 Vector<Dictionary> jsKeyframes; |
| 88 v8::Handle<v8::Object> keyframe1 = v8::Object::New(); |
| 89 v8::Handle<v8::Object> keyframe2 = v8::Object::New(); |
| 90 |
| 91 setV8ObjectProperty(keyframe1, "width", "100px"); |
| 92 setV8ObjectProperty(keyframe1, "offset", "0"); |
| 93 setV8ObjectProperty(keyframe2, "width", "0px"); |
| 94 setV8ObjectProperty(keyframe2, "offset", "1"); |
| 95 |
| 96 jsKeyframes.append(Dictionary(keyframe1, isolate)); |
| 97 jsKeyframes.append(Dictionary(keyframe2, isolate)); |
| 98 |
| 99 String value1; |
| 100 ASSERT_TRUE(jsKeyframes[0].get("width", value1)); |
| 101 ASSERT_EQ("100px", value1); |
| 102 |
| 103 String value2; |
| 104 ASSERT_TRUE(jsKeyframes[1].get("width", value2)); |
| 105 ASSERT_EQ("0px", value2); |
| 106 |
| 107 startAnimation(element.get(), jsKeyframes); |
| 108 |
| 109 Player* player = document->timeline()->players().at(0).get(); |
| 110 |
| 111 Animation* animation = toAnimation(player->source()); |
| 112 |
| 113 Element* target = animation->target(); |
| 114 EXPECT_EQ(*element.get(), *target); |
| 115 |
| 116 const KeyframeAnimationEffect::KeyframeVector keyframes = |
| 117 toKeyframeAnimationEffect(animation->effect())->getFrames(); |
| 118 |
| 119 EXPECT_EQ(0, keyframes[0]->offset()); |
| 120 EXPECT_EQ(1, keyframes[1]->offset()); |
| 121 |
| 122 const AnimatableValue* keyframe1Width = keyframes[0]->propertyValue(CSSPrope
rtyWidth); |
| 123 const AnimatableValue* keyframe2Width = keyframes[1]->propertyValue(CSSPrope
rtyWidth); |
| 124 ASSERT(keyframe1Width); |
| 125 ASSERT(keyframe2Width); |
| 126 |
| 127 EXPECT_TRUE(keyframe1Width->isLength()); |
| 128 EXPECT_TRUE(keyframe2Width->isLength()); |
| 129 |
| 130 EXPECT_EQ("100px", toAnimatableLength(keyframe1Width)->toCSSValue()->cssText
()); |
| 131 EXPECT_EQ("0px", toAnimatableLength(keyframe2Width)->toCSSValue()->cssText()
); |
| 132 } |
| 133 |
| 134 TEST_F(AnimationElementAnimationTest, ParseCamelCasePropertyNames) |
| 135 { |
| 136 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID
(String("line-height").impl())); |
| 137 EXPECT_EQ(CSSPropertyLineHeight, ElementAnimation::camelCaseCSSPropertyNameT
oID(String("lineHeight").impl())); |
| 138 EXPECT_EQ(CSSPropertyBorderTopWidth, ElementAnimation::camelCaseCSSPropertyN
ameToID(String("borderTopWidth").impl())); |
| 139 EXPECT_EQ(CSSPropertyWidth, ElementAnimation::camelCaseCSSPropertyNameToID(S
tring("width").impl())); |
| 140 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID
(String("Width").impl())); |
| 141 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID
(String("-webkit-transform").impl())); |
| 142 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID
(String("webkitTransform").impl())); |
| 143 EXPECT_EQ(CSSPropertyInvalid, ElementAnimation::camelCaseCSSPropertyNameToID
(String("cssFloat").impl())); |
| 144 } |
| 145 |
| 146 } // namespace WebCore |
| OLD | NEW |