| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/config.h" | |
| 6 #include "sky/engine/core/animation/EffectInput.h" | |
| 7 | |
| 8 #include <gtest/gtest.h> | |
| 9 | |
| 10 #include "sky/engine/bindings/core/v8/Dictionary.h" | |
| 11 #include "sky/engine/core/animation/AnimationTestHelper.h" | |
| 12 #include "sky/engine/core/animation/KeyframeEffectModel.h" | |
| 13 #include "sky/engine/core/dom/Document.h" | |
| 14 #include "sky/engine/core/dom/Element.h" | |
| 15 #include "v8/include/v8.h" | |
| 16 | |
| 17 using namespace blink; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class AnimationEffectInputTest : public ::testing::Test { | |
| 22 protected: | |
| 23 AnimationEffectInputTest() | |
| 24 : document(Document::create()) | |
| 25 , element(document->createElement("foo", ASSERT_NO_EXCEPTION)) | |
| 26 , m_isolate(v8::Isolate::GetCurrent()) | |
| 27 , m_scope(m_isolate) | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 RefPtr<Document> document; | |
| 32 RefPtr<Element> element; | |
| 33 TrackExceptionState exceptionState; | |
| 34 v8::Isolate* m_isolate; | |
| 35 | |
| 36 private: | |
| 37 V8TestingScope m_scope; | |
| 38 }; | |
| 39 | |
| 40 TEST_F(AnimationEffectInputTest, SortedOffsets) | |
| 41 { | |
| 42 Vector<Dictionary> jsKeyframes; | |
| 43 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); | |
| 44 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); | |
| 45 | |
| 46 setV8ObjectPropertyAsString(keyframe1, "width", "100px"); | |
| 47 setV8ObjectPropertyAsString(keyframe1, "offset", "0"); | |
| 48 setV8ObjectPropertyAsString(keyframe2, "width", "0px"); | |
| 49 setV8ObjectPropertyAsString(keyframe2, "offset", "1"); | |
| 50 | |
| 51 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); | |
| 52 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); | |
| 53 | |
| 54 RefPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get()
, jsKeyframes, exceptionState); | |
| 55 EXPECT_FALSE(exceptionState.hadException()); | |
| 56 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect.get()); | |
| 57 EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); | |
| 58 } | |
| 59 | |
| 60 TEST_F(AnimationEffectInputTest, UnsortedOffsets) | |
| 61 { | |
| 62 Vector<Dictionary> jsKeyframes; | |
| 63 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); | |
| 64 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); | |
| 65 | |
| 66 setV8ObjectPropertyAsString(keyframe1, "width", "0px"); | |
| 67 setV8ObjectPropertyAsString(keyframe1, "offset", "1"); | |
| 68 setV8ObjectPropertyAsString(keyframe2, "width", "100px"); | |
| 69 setV8ObjectPropertyAsString(keyframe2, "offset", "0"); | |
| 70 | |
| 71 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); | |
| 72 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); | |
| 73 | |
| 74 EffectInput::convert(element.get(), jsKeyframes, exceptionState); | |
| 75 EXPECT_TRUE(exceptionState.hadException()); | |
| 76 EXPECT_EQ(InvalidModificationError, exceptionState.code()); | |
| 77 } | |
| 78 | |
| 79 TEST_F(AnimationEffectInputTest, LooslySorted) | |
| 80 { | |
| 81 Vector<Dictionary> jsKeyframes; | |
| 82 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); | |
| 83 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); | |
| 84 v8::Handle<v8::Object> keyframe3 = v8::Object::New(m_isolate); | |
| 85 | |
| 86 setV8ObjectPropertyAsString(keyframe1, "width", "100px"); | |
| 87 setV8ObjectPropertyAsString(keyframe1, "offset", "0"); | |
| 88 setV8ObjectPropertyAsString(keyframe2, "width", "200px"); | |
| 89 setV8ObjectPropertyAsString(keyframe3, "width", "0px"); | |
| 90 setV8ObjectPropertyAsString(keyframe3, "offset", "1"); | |
| 91 | |
| 92 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); | |
| 93 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); | |
| 94 jsKeyframes.append(Dictionary(keyframe3, m_isolate)); | |
| 95 | |
| 96 RefPtr<AnimationEffect> animationEffect = EffectInput::convert(element.get()
, jsKeyframes, exceptionState); | |
| 97 EXPECT_FALSE(exceptionState.hadException()); | |
| 98 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect.get()); | |
| 99 EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); | |
| 100 } | |
| 101 | |
| 102 TEST_F(AnimationEffectInputTest, OutOfOrderWithNullOffsets) | |
| 103 { | |
| 104 Vector<Dictionary> jsKeyframes; | |
| 105 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); | |
| 106 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); | |
| 107 v8::Handle<v8::Object> keyframe3 = v8::Object::New(m_isolate); | |
| 108 v8::Handle<v8::Object> keyframe4 = v8::Object::New(m_isolate); | |
| 109 | |
| 110 setV8ObjectPropertyAsString(keyframe1, "height", "100px"); | |
| 111 setV8ObjectPropertyAsString(keyframe1, "offset", "0.5"); | |
| 112 setV8ObjectPropertyAsString(keyframe2, "height", "150px"); | |
| 113 setV8ObjectPropertyAsString(keyframe3, "height", "200px"); | |
| 114 setV8ObjectPropertyAsString(keyframe3, "offset", "0"); | |
| 115 setV8ObjectPropertyAsString(keyframe4, "height", "300px"); | |
| 116 setV8ObjectPropertyAsString(keyframe4, "offset", "1"); | |
| 117 | |
| 118 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); | |
| 119 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); | |
| 120 jsKeyframes.append(Dictionary(keyframe3, m_isolate)); | |
| 121 jsKeyframes.append(Dictionary(keyframe4, m_isolate)); | |
| 122 | |
| 123 EffectInput::convert(element.get(), jsKeyframes, exceptionState); | |
| 124 EXPECT_TRUE(exceptionState.hadException()); | |
| 125 } | |
| 126 | |
| 127 TEST_F(AnimationEffectInputTest, Invalid) | |
| 128 { | |
| 129 // Not loosely sorted by offset, and there exists a keyframe with null offse
t. | |
| 130 Vector<Dictionary> jsKeyframes; | |
| 131 v8::Handle<v8::Object> keyframe1 = v8::Object::New(m_isolate); | |
| 132 v8::Handle<v8::Object> keyframe2 = v8::Object::New(m_isolate); | |
| 133 v8::Handle<v8::Object> keyframe3 = v8::Object::New(m_isolate); | |
| 134 | |
| 135 setV8ObjectPropertyAsString(keyframe1, "width", "0px"); | |
| 136 setV8ObjectPropertyAsString(keyframe1, "offset", "1"); | |
| 137 setV8ObjectPropertyAsString(keyframe2, "width", "200px"); | |
| 138 setV8ObjectPropertyAsString(keyframe3, "width", "100px"); | |
| 139 setV8ObjectPropertyAsString(keyframe3, "offset", "0"); | |
| 140 | |
| 141 jsKeyframes.append(Dictionary(keyframe1, m_isolate)); | |
| 142 jsKeyframes.append(Dictionary(keyframe2, m_isolate)); | |
| 143 jsKeyframes.append(Dictionary(keyframe3, m_isolate)); | |
| 144 | |
| 145 EffectInput::convert(element.get(), jsKeyframes, exceptionState); | |
| 146 EXPECT_TRUE(exceptionState.hadException()); | |
| 147 EXPECT_EQ(InvalidModificationError, exceptionState.code()); | |
| 148 } | |
| 149 | |
| 150 } | |
| OLD | NEW |