| Index: Source/core/animation/ElementAnimationTest.cpp
|
| diff --git a/Source/core/animation/ElementAnimationTest.cpp b/Source/core/animation/ElementAnimationTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8b203da1ebf1fa93cd5b710b19776c87002769b3
|
| --- /dev/null
|
| +++ b/Source/core/animation/ElementAnimationTest.cpp
|
| @@ -0,0 +1,135 @@
|
| +/*
|
| + * Copyright (c) 2013, Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "core/animation/ElementAnimation.h"
|
| +
|
| +#include "core/animation/AnimatableLength.h"
|
| +#include "core/animation/Animation.h"
|
| +#include "core/animation/AnimationClock.h"
|
| +#include "core/animation/DocumentTimeline.h"
|
| +#include "core/animation/KeyframeAnimationEffect.h"
|
| +#include "core/dom/Document.h"
|
| +#include "core/dom/Element.h"
|
| +
|
| +#include <gtest/gtest.h>
|
| +
|
| +namespace WebCore {
|
| +
|
| +namespace {
|
| +
|
| +v8::Handle<v8::Value> stringToV8Value(String string)
|
| +{
|
| + return v8::Handle<v8::Value>::Cast(v8String(v8::Isolate::GetCurrent(), string));
|
| +}
|
| +
|
| +void setV8ObjectProperty(v8::Handle<v8::Object> object, String name, String value)
|
| +{
|
| + object->Set(stringToV8Value(name), stringToV8Value(value));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class AnimationElementAnimationTest : public ::testing::Test {
|
| +protected:
|
| + virtual void SetUp()
|
| + {
|
| + document = Document::create();
|
| + document->animationClock().resetTimeForTesting();
|
| + element = Element::create(nullQName() , document.get());
|
| + document->timeline()->setZeroTime(0);
|
| + ASSERT_EQ(0, document->timeline()->currentTime());
|
| + }
|
| +
|
| + virtual void TearDown()
|
| + {
|
| + document.release();
|
| + element.release();
|
| + }
|
| +
|
| + RefPtr<Document> document;
|
| + RefPtr<Element> element;
|
| +};
|
| +
|
| +TEST_F(AnimationElementAnimationTest, CanStartAnAnimation)
|
| +{
|
| + v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
| + v8::HandleScope scope(isolate);
|
| + v8::Local<v8::Context> context = v8::Context::New(isolate);
|
| + v8::Context::Scope contextScope(context);
|
| +
|
| + Vector<Dictionary> jsData;
|
| + v8::Handle<v8::Object> keyframe1 = v8::Object::New();
|
| + v8::Handle<v8::Object> keyframe2 = v8::Object::New();
|
| +
|
| + setV8ObjectProperty(keyframe1, "width", "100px");
|
| + setV8ObjectProperty(keyframe1, "offset", "0");
|
| + setV8ObjectProperty(keyframe2, "width", "0px");
|
| + setV8ObjectProperty(keyframe2, "offset", "1");
|
| +
|
| + jsData.append(Dictionary(keyframe1, isolate));
|
| + jsData.append(Dictionary(keyframe2, isolate));
|
| +
|
| + String value1;
|
| + EXPECT_TRUE(jsData[0].get("width", value1));
|
| + EXPECT_EQ("100px", value1);
|
| +
|
| + String value2;
|
| + EXPECT_TRUE(jsData[1].get("width", value2));
|
| + EXPECT_EQ("0px", value2);
|
| +
|
| + ElementAnimation::animate(element.get(), jsData);
|
| +
|
| + Player* player = document->timeline()->players().at(0).get();
|
| +
|
| + Animation* animation = toAnimation(player->source());
|
| +
|
| + Element* target = animation->target();
|
| + EXPECT_EQ(*element.get(), *target);
|
| +
|
| + const KeyframeAnimationEffect::KeyframeVector keyframes =
|
| + toKeyframeAnimationEffect(animation->effect())->getFrames();
|
| +
|
| + EXPECT_EQ(0, keyframes[0]->offset());
|
| + EXPECT_EQ(1, keyframes[1]->offset());
|
| +
|
| + const AnimatableValue* k1Width = keyframes[0]->propertyValue(CSSPropertyWidth);
|
| + const AnimatableValue* k2Width = keyframes[1]->propertyValue(CSSPropertyWidth);
|
| + ASSERT(k1Width && k2Width);
|
| +
|
| + ASSERT(k1Width->isLength() && k2Width->isLength());
|
| + EXPECT_TRUE(k1Width->isLength());
|
| + EXPECT_TRUE(k2Width->isLength());
|
| +
|
| + EXPECT_EQ("100px", static_cast<const AnimatableLength*>(k1Width)->toCSSValue()->cssText());
|
| + EXPECT_EQ("0px", static_cast<const AnimatableLength*>(k2Width)->toCSSValue()->cssText());
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|