| 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/DictionarySequenceOrDictionary.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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); | 36 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); |
| 37 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); | 37 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); |
| 38 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px"); | 38 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "0px"); |
| 39 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1"); | 39 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "1"); |
| 40 | 40 |
| 41 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); | 41 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); |
| 42 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); | 42 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); |
| 43 | 43 |
| 44 Element* element = appendElement(scope.document()); | 44 Element* element = appendElement(scope.document()); |
| 45 EffectModel* animationEffect = EffectInput::convert(element, EffectModelOrDi
ctionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), nullptr, scop
e.getExceptionState()); | 45 EffectModel* animationEffect = EffectInput::convert(element, DictionarySeque
nceOrDictionary::fromDictionarySequence(jsKeyframes), nullptr, scope.getExceptio
nState()); |
| 46 EXPECT_FALSE(scope.getExceptionState().hadException()); | 46 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 47 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect); | 47 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect); |
| 48 EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); | 48 EXPECT_EQ(1.0, keyframeEffect.getFrames()[1]->offset()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(AnimationEffectInputTest, UnsortedOffsets) | 51 TEST(AnimationEffectInputTest, UnsortedOffsets) |
| 52 { | 52 { |
| 53 V8TestingScope scope; | 53 V8TestingScope scope; |
| 54 Vector<Dictionary> jsKeyframes; | 54 Vector<Dictionary> jsKeyframes; |
| 55 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 55 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
| 56 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 56 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
| 57 | 57 |
| 58 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); | 58 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); |
| 59 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); | 59 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); |
| 60 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "100px"); | 60 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "100px"); |
| 61 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "0"); | 61 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "offset", "0"); |
| 62 | 62 |
| 63 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); | 63 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); |
| 64 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); | 64 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); |
| 65 | 65 |
| 66 Element* element = appendElement(scope.document()); | 66 Element* element = appendElement(scope.document()); |
| 67 EffectInput::convert(element, EffectModelOrDictionarySequenceOrDictionary::f
romDictionarySequence(jsKeyframes), nullptr, scope.getExceptionState()); | 67 EffectInput::convert(element, DictionarySequenceOrDictionary::fromDictionary
Sequence(jsKeyframes), nullptr, scope.getExceptionState()); |
| 68 EXPECT_TRUE(scope.getExceptionState().hadException()); | 68 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 69 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 69 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(AnimationEffectInputTest, LooslySorted) | 72 TEST(AnimationEffectInputTest, LooslySorted) |
| 73 { | 73 { |
| 74 V8TestingScope scope; | 74 V8TestingScope scope; |
| 75 Vector<Dictionary> jsKeyframes; | 75 Vector<Dictionary> jsKeyframes; |
| 76 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 76 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
| 77 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 77 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
| 78 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 78 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
| 79 | 79 |
| 80 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); | 80 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "100px"); |
| 81 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); | 81 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0"); |
| 82 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); | 82 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); |
| 83 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "0px"); | 83 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "0px"); |
| 84 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "1"); | 84 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "1"); |
| 85 | 85 |
| 86 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); | 86 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); |
| 87 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); | 87 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); |
| 88 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); | 88 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); |
| 89 | 89 |
| 90 Element* element = appendElement(scope.document()); | 90 Element* element = appendElement(scope.document()); |
| 91 EffectModel* animationEffect = EffectInput::convert(element, EffectModelOrDi
ctionarySequenceOrDictionary::fromDictionarySequence(jsKeyframes), nullptr, scop
e.getExceptionState()); | 91 EffectModel* animationEffect = EffectInput::convert(element, DictionarySeque
nceOrDictionary::fromDictionarySequence(jsKeyframes), nullptr, scope.getExceptio
nState()); |
| 92 EXPECT_FALSE(scope.getExceptionState().hadException()); | 92 EXPECT_FALSE(scope.getExceptionState().hadException()); |
| 93 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect); | 93 const KeyframeEffectModelBase& keyframeEffect = *toKeyframeEffectModelBase(a
nimationEffect); |
| 94 EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); | 94 EXPECT_EQ(1, keyframeEffect.getFrames()[2]->offset()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST(AnimationEffectInputTest, OutOfOrderWithNullOffsets) | 97 TEST(AnimationEffectInputTest, OutOfOrderWithNullOffsets) |
| 98 { | 98 { |
| 99 V8TestingScope scope; | 99 V8TestingScope scope; |
| 100 Vector<Dictionary> jsKeyframes; | 100 Vector<Dictionary> jsKeyframes; |
| 101 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 101 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
| 102 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 102 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
| 103 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 103 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
| 104 v8::Local<v8::Object> keyframe4 = v8::Object::New(scope.isolate()); | 104 v8::Local<v8::Object> keyframe4 = v8::Object::New(scope.isolate()); |
| 105 | 105 |
| 106 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "height", "100px"); | 106 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "height", "100px"); |
| 107 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0.5"); | 107 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "0.5"); |
| 108 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "height", "150px"); | 108 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "height", "150px"); |
| 109 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "height", "200px"); | 109 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "height", "200px"); |
| 110 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); | 110 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); |
| 111 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "height", "300px"); | 111 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "height", "300px"); |
| 112 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "offset", "1"); | 112 setV8ObjectPropertyAsString(scope.isolate(), keyframe4, "offset", "1"); |
| 113 | 113 |
| 114 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); | 114 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); |
| 115 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); | 115 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); |
| 116 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); | 116 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); |
| 117 jsKeyframes.append(Dictionary(keyframe4, scope.isolate(), scope.getException
State())); | 117 jsKeyframes.append(Dictionary(keyframe4, scope.isolate(), scope.getException
State())); |
| 118 | 118 |
| 119 Element* element = appendElement(scope.document()); | 119 Element* element = appendElement(scope.document()); |
| 120 EffectInput::convert(element, EffectModelOrDictionarySequenceOrDictionary::f
romDictionarySequence(jsKeyframes), nullptr, scope.getExceptionState()); | 120 EffectInput::convert(element, DictionarySequenceOrDictionary::fromDictionary
Sequence(jsKeyframes), nullptr, scope.getExceptionState()); |
| 121 EXPECT_TRUE(scope.getExceptionState().hadException()); | 121 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST(AnimationEffectInputTest, Invalid) | 124 TEST(AnimationEffectInputTest, Invalid) |
| 125 { | 125 { |
| 126 V8TestingScope scope; | 126 V8TestingScope scope; |
| 127 // Not loosely sorted by offset, and there exists a keyframe with null offse
t. | 127 // Not loosely sorted by offset, and there exists a keyframe with null offse
t. |
| 128 Vector<Dictionary> jsKeyframes; | 128 Vector<Dictionary> jsKeyframes; |
| 129 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); | 129 v8::Local<v8::Object> keyframe1 = v8::Object::New(scope.isolate()); |
| 130 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); | 130 v8::Local<v8::Object> keyframe2 = v8::Object::New(scope.isolate()); |
| 131 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); | 131 v8::Local<v8::Object> keyframe3 = v8::Object::New(scope.isolate()); |
| 132 | 132 |
| 133 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); | 133 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "width", "0px"); |
| 134 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); | 134 setV8ObjectPropertyAsString(scope.isolate(), keyframe1, "offset", "1"); |
| 135 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); | 135 setV8ObjectPropertyAsString(scope.isolate(), keyframe2, "width", "200px"); |
| 136 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "100px"); | 136 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "width", "100px"); |
| 137 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); | 137 setV8ObjectPropertyAsString(scope.isolate(), keyframe3, "offset", "0"); |
| 138 | 138 |
| 139 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); | 139 jsKeyframes.append(Dictionary(keyframe1, scope.isolate(), scope.getException
State())); |
| 140 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); | 140 jsKeyframes.append(Dictionary(keyframe2, scope.isolate(), scope.getException
State())); |
| 141 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); | 141 jsKeyframes.append(Dictionary(keyframe3, scope.isolate(), scope.getException
State())); |
| 142 | 142 |
| 143 Element* element = appendElement(scope.document()); | 143 Element* element = appendElement(scope.document()); |
| 144 EffectInput::convert(element, EffectModelOrDictionarySequenceOrDictionary::f
romDictionarySequence(jsKeyframes), nullptr, scope.getExceptionState()); | 144 EffectInput::convert(element, DictionarySequenceOrDictionary::fromDictionary
Sequence(jsKeyframes), nullptr, scope.getExceptionState()); |
| 145 EXPECT_TRUE(scope.getExceptionState().hadException()); | 145 EXPECT_TRUE(scope.getExceptionState().hadException()); |
| 146 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); | 146 EXPECT_EQ(V8TypeError, scope.getExceptionState().code()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |