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 "config.h" | 5 #include "config.h" |
6 #include "core/animation/AnimationStack.h" | 6 #include "core/animation/AnimationStack.h" |
7 | 7 |
8 #include "core/animation/AnimationClock.h" | 8 #include "core/animation/AnimationClock.h" |
9 #include "core/animation/AnimationTimeline.h" | 9 #include "core/animation/AnimationTimeline.h" |
10 #include "core/animation/ElementAnimations.h" | 10 #include "core/animation/ElementAnimations.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 KeyframeEffect* makeKeyframeEffect(EffectModel* effect, double duration = 10
) | 66 KeyframeEffect* makeKeyframeEffect(EffectModel* effect, double duration = 10
) |
67 { | 67 { |
68 Timing timing; | 68 Timing timing; |
69 timing.fillMode = Timing::FillModeBoth; | 69 timing.fillMode = Timing::FillModeBoth; |
70 timing.iterationDuration = duration; | 70 timing.iterationDuration = duration; |
71 return KeyframeEffect::create(element.get(), effect, timing); | 71 return KeyframeEffect::create(element.get(), effect, timing); |
72 } | 72 } |
73 | 73 |
74 AnimatableValue* interpolationValue(const ActiveInterpolationMap& activeInte
rpolations, CSSPropertyID id) | 74 AnimatableValue* interpolationValue(const ActiveInterpolationsMap& activeInt
erpolations, CSSPropertyID id) |
75 { | 75 { |
76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)); | 76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)).at(0); |
77 return toLegacyStyleInterpolation(interpolation).currentValue().get(); | 77 return toLegacyStyleInterpolation(interpolation).currentValue().get(); |
78 } | 78 } |
79 | 79 |
80 RefPtrWillBePersistent<Document> document; | 80 RefPtrWillBePersistent<Document> document; |
81 Persistent<AnimationTimeline> timeline; | 81 Persistent<AnimationTimeline> timeline; |
82 RefPtrWillBePersistent<Element> element; | 82 RefPtrWillBePersistent<Element> element; |
83 }; | 83 }; |
84 | 84 |
85 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) | 85 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) |
86 { | 86 { |
87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); | 87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); |
88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); | 88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); |
89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); | 89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); |
90 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); | 90 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority,
0); |
91 EXPECT_EQ(1u, result.size()); | 91 EXPECT_EQ(1u, result.size()); |
92 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 92 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
93 } | 93 } |
94 | 94 |
95 TEST_F(AnimationAnimationStackTest, NewAnimations) | 95 TEST_F(AnimationAnimationStackTest, NewAnimations) |
96 { | 96 { |
97 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 15); | 97 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 15); |
98 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 10); | 98 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 10); |
99 HeapVector<Member<InertEffect>> newAnimations; | 99 HeapVector<Member<InertEffect>> newAnimations; |
100 InertEffect* inert1 = makeInertEffect(makeEffectModel(CSSPropertyFontSize, A
nimatableDouble::create(3))); | 100 InertEffect* inert1 = makeInertEffect(makeEffectModel(CSSPropertyFontSize, A
nimatableDouble::create(3))); |
101 InertEffect* inert2 = makeInertEffect(makeEffectModel(CSSPropertyZIndex, Ani
matableDouble::create(4))); | 101 InertEffect* inert2 = makeInertEffect(makeEffectModel(CSSPropertyZIndex, Ani
matableDouble::create(4))); |
102 newAnimations.append(inert1); | 102 newAnimations.append(inert1); |
103 newAnimations.append(inert2); | 103 newAnimations.append(inert2); |
104 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), &newAnimations, 0, KeyframeEffect::Defau
ltPriority, 10); | 104 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->defaultStack(), &newAnimations, 0, KeyframeEffect::Defa
ultPriority, 10); |
105 EXPECT_EQ(2u, result.size()); | 105 EXPECT_EQ(2u, result.size()); |
106 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 106 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
107 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); | 107 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); |
108 } | 108 } |
109 | 109 |
110 TEST_F(AnimationAnimationStackTest, CancelledAnimations) | 110 TEST_F(AnimationAnimationStackTest, CancelledAnimations) |
111 { | 111 { |
112 HeapHashSet<Member<const Animation>> cancelledAnimations; | 112 HeapHashSet<Member<const Animation>> cancelledAnimations; |
113 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 0); | 113 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 0); |
114 cancelledAnimations.add(animation); | 114 cancelledAnimations.add(animation); |
115 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 0); | 115 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 0); |
116 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, &cancelledAnimations, KeyframeEffect:
:DefaultPriority, 0); | 116 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->defaultStack(), 0, &cancelledAnimations, KeyframeEffect
::DefaultPriority, 0); |
117 EXPECT_EQ(1u, result.size()); | 117 EXPECT_EQ(1u, result.size()); |
118 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); | 118 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); |
119 } | 119 } |
120 | 120 |
121 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) | 121 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) |
122 { | 122 { |
123 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 10); | 123 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 10); |
124 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0
); | 124 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->defaultStack(), 0, 0, KeyframeEffect::DefaultPriority,
0); |
125 EXPECT_EQ(1u, result.size()); | 125 EXPECT_EQ(1u, result.size()); |
126 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); | 126 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); |
127 | 127 |
128 animation->setEffect(0); | 128 animation->setEffect(0); |
129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0); | 129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>defaultStack(), 0, 0, KeyframeEffect::DefaultPriority, 0); |
130 EXPECT_EQ(0u, result.size()); | 130 EXPECT_EQ(0u, result.size()); |
131 } | 131 } |
132 | 132 |
133 } | 133 } |
OLD | NEW |