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