Chromium Code Reviews| 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 = Element::create(nullQName() , document.get()); | |
|
dstockwell
2013/12/11 00:04:28
Alternatively, just use the regular binding:
docum
rjwright
2013/12/11 02:16:38
Done.
| |
| 67 document->timeline()->setZeroTime(0); | |
| 68 ASSERT_EQ(0, document->timeline()->currentTime()); | |
| 69 } | |
| 70 | |
| 71 virtual void TearDown() | |
| 72 { | |
| 73 document.release(); | |
|
dstockwell
2013/12/11 00:04:28
is this needed?
rjwright
2013/12/11 02:16:38
I don't know. Do you?
| |
| 74 element.release(); | |
| 75 } | |
| 76 | |
| 77 RefPtr<Document> document; | |
| 78 RefPtr<Element> element; | |
| 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> jsData; | |
|
Steve Block
2013/12/10 23:26:45
jsKeyframes? jsKeyframesDictionary?
rjwright
2013/12/11 02:16:38
Done.
| |
| 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 jsData.append(Dictionary(keyframe1, isolate)); | |
| 98 jsData.append(Dictionary(keyframe2, isolate)); | |
| 99 | |
| 100 String value1; | |
| 101 EXPECT_TRUE(jsData[0].get("width", value1)); | |
| 102 EXPECT_EQ("100px", value1); | |
|
Steve Block
2013/12/10 23:26:45
These aren't testing anything to do with Web Anima
rjwright
2013/12/11 02:16:38
Done.
| |
| 103 | |
| 104 String value2; | |
| 105 EXPECT_TRUE(jsData[1].get("width", value2)); | |
| 106 EXPECT_EQ("0px", value2); | |
| 107 | |
| 108 ElementAnimation::animate(element.get(), jsData); | |
| 109 | |
| 110 Player* player = document->timeline()->players().at(0).get(); | |
| 111 | |
| 112 Animation* animation = toAnimation(player->source()); | |
| 113 | |
| 114 Element* target = animation->target(); | |
| 115 EXPECT_EQ(*element.get(), *target); | |
| 116 | |
| 117 const KeyframeAnimationEffect::KeyframeVector keyframes = | |
| 118 toKeyframeAnimationEffect(animation->effect())->getFrames(); | |
| 119 | |
| 120 EXPECT_EQ(0, keyframes[0]->offset()); | |
| 121 EXPECT_EQ(1, keyframes[1]->offset()); | |
| 122 | |
| 123 const AnimatableValue* k1Width = keyframes[0]->propertyValue(CSSPropertyWidt h); | |
|
Steve Block
2013/12/10 23:26:45
Don't abbreviate - keyframe1Width
rjwright
2013/12/11 02:16:38
Done.
| |
| 124 const AnimatableValue* k2Width = keyframes[1]->propertyValue(CSSPropertyWidt h); | |
| 125 ASSERT(k1Width && k2Width); | |
|
Steve Block
2013/12/10 23:26:45
Probably best to assert each separately
rjwright
2013/12/11 02:16:38
Done.
| |
| 126 | |
| 127 ASSERT(k1Width->isLength() && k2Width->isLength()); | |
| 128 EXPECT_TRUE(k1Width->isLength()); | |
| 129 EXPECT_TRUE(k2Width->isLength()); | |
|
Steve Block
2013/12/10 23:26:45
These 2 seem superfluous given the assertion above
dstockwell
2013/12/11 00:04:28
The assertion should be removed.
rjwright
2013/12/11 02:16:38
Done.
rjwright
2013/12/11 02:16:38
Done.
| |
| 130 | |
| 131 EXPECT_EQ("100px", static_cast<const AnimatableLength*>(k1Width)->toCSSValue ()->cssText()); | |
|
dstockwell
2013/12/11 00:04:28
toAnimatableLength
rjwright
2013/12/11 02:16:38
Done.
| |
| 132 EXPECT_EQ("0px", static_cast<const AnimatableLength*>(k2Width)->toCSSValue() ->cssText()); | |
|
Steve Block
2013/12/10 23:26:45
Use toAnimatableLength() (it also asserts isLength
rjwright
2013/12/11 02:16:38
Done.
| |
| 133 } | |
| 134 | |
| 135 } // namespace WebCore | |
| OLD | NEW |