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" |
11 #include "core/animation/KeyframeEffectModel.h" | 11 #include "core/animation/KeyframeEffectModel.h" |
12 #include "core/animation/LegacyStyleInterpolation.h" | 12 #include "core/animation/LegacyStyleInterpolation.h" |
13 #include "core/animation/animatable/AnimatableDouble.h" | 13 #include "core/animation/animatable/AnimatableDouble.h" |
14 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 class AnimationAnimationStackTest : public ::testing::Test { | 18 class AnimationAnimationStackTest : public ::testing::Test { |
19 protected: | 19 protected: |
20 virtual void SetUp() | 20 virtual void SetUp() |
21 { | 21 { |
22 document = Document::create(); | 22 document = Document::create(); |
23 document->animationClock().resetTimeForTesting(); | 23 document->animationClock().resetTimeForTesting(); |
24 timeline = AnimationTimeline::create(document.get()); | 24 timeline = AnimationTimeline::create(document.get()); |
25 element = document->createElement("foo", ASSERT_NO_EXCEPTION); | 25 element = document->createElement("foo", ASSERT_NO_EXCEPTION); |
26 } | 26 } |
27 | 27 |
28 AnimationPlayer* play(Animation* animation, double startTime) | 28 Animation* play(KeyframeEffect* effect, double startTime) |
29 { | 29 { |
30 AnimationPlayer* player = timeline->play(animation); | 30 Animation* animation = timeline->play(effect); |
31 player->setStartTime(startTime * 1000); | 31 animation->setStartTime(startTime * 1000); |
32 player->update(TimingUpdateOnDemand); | 32 animation->update(TimingUpdateOnDemand); |
33 return player; | 33 return animation; |
34 } | 34 } |
35 | 35 |
36 void updateTimeline(double time) | 36 void updateTimeline(double time) |
37 { | 37 { |
38 document->animationClock().updateTime(time); | 38 document->animationClock().updateTime(time); |
39 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 39 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
40 } | 40 } |
41 | 41 |
42 const WillBeHeapVector<OwnPtrWillBeMember<SampledEffect>>& effects() | 42 const WillBeHeapVector<OwnPtrWillBeMember<SampledEffect>>& effects() |
43 { | 43 { |
44 return element->ensureElementAnimations().defaultStack().m_effects; | 44 return element->ensureElementAnimations().defaultStack().m_effects; |
45 } | 45 } |
46 | 46 |
47 PassRefPtrWillBeRawPtr<AnimationEffect> makeAnimationEffect(CSSPropertyID id
, PassRefPtrWillBeRawPtr<AnimatableValue> value) | 47 PassRefPtrWillBeRawPtr<EffectModel> makeEffectModel(CSSPropertyID id, PassRe
fPtrWillBeRawPtr<AnimatableValue> value) |
48 { | 48 { |
49 AnimatableValueKeyframeVector keyframes(2); | 49 AnimatableValueKeyframeVector keyframes(2); |
50 keyframes[0] = AnimatableValueKeyframe::create(); | 50 keyframes[0] = AnimatableValueKeyframe::create(); |
51 keyframes[0]->setOffset(0.0); | 51 keyframes[0]->setOffset(0.0); |
52 keyframes[0]->setPropertyValue(id, value.get()); | 52 keyframes[0]->setPropertyValue(id, value.get()); |
53 keyframes[1] = AnimatableValueKeyframe::create(); | 53 keyframes[1] = AnimatableValueKeyframe::create(); |
54 keyframes[1]->setOffset(1.0); | 54 keyframes[1]->setOffset(1.0); |
55 keyframes[1]->setPropertyValue(id, value.get()); | 55 keyframes[1]->setPropertyValue(id, value.get()); |
56 return AnimatableValueKeyframeEffectModel::create(keyframes); | 56 return AnimatableValueKeyframeEffectModel::create(keyframes); |
57 } | 57 } |
58 | 58 |
59 PassRefPtrWillBeRawPtr<InertAnimation> makeInertAnimation(PassRefPtrWillBeRa
wPtr<AnimationEffect> effect) | 59 PassRefPtrWillBeRawPtr<InertAnimation> makeInertAnimation(PassRefPtrWillBeRa
wPtr<EffectModel> effect) |
60 { | 60 { |
61 Timing timing; | 61 Timing timing; |
62 timing.fillMode = Timing::FillModeBoth; | 62 timing.fillMode = Timing::FillModeBoth; |
63 return InertAnimation::create(effect, timing, false, 0); | 63 return InertAnimation::create(effect, timing, false, 0); |
64 } | 64 } |
65 | 65 |
66 PassRefPtrWillBeRawPtr<Animation> makeAnimation(PassRefPtrWillBeRawPtr<Anima
tionEffect> effect, double duration = 10) | 66 PassRefPtrWillBeRawPtr<KeyframeEffect> makeKeyframeEffect(PassRefPtrWillBeRa
wPtr<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 Animation::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 ActiveInterpolationMap& activeInte
rpolations, CSSPropertyID id) |
75 { | 75 { |
76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)); | 76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)); |
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 RefPtrWillBePersistent<AnimationTimeline> timeline; | 81 RefPtrWillBePersistent<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(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 10); | 87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))).get(), 10); |
88 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(2))).get(), 15); | 88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))).get(), 15); |
89 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(3))).get(), 5); | 89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))).get(), 5); |
90 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, Animation::DefaultPriority, 0); | 90 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->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(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble
::create(1))).get(), 15); | 97 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))).get(), 15); |
98 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 10); | 98 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))).get(), 10); |
99 WillBeHeapVector<RawPtrWillBeMember<InertAnimation>> newAnimations; | 99 WillBeHeapVector<RawPtrWillBeMember<InertAnimation>> newAnimations; |
100 RefPtrWillBeRawPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimation
Effect(CSSPropertyFontSize, AnimatableDouble::create(3))); | 100 RefPtrWillBeRawPtr<InertAnimation> inert1 = makeInertAnimation(makeEffectMod
el(CSSPropertyFontSize, AnimatableDouble::create(3))); |
101 RefPtrWillBeRawPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimation
Effect(CSSPropertyZIndex, AnimatableDouble::create(4))); | 101 RefPtrWillBeRawPtr<InertAnimation> inert2 = makeInertAnimation(makeEffectMod
el(CSSPropertyZIndex, AnimatableDouble::create(4))); |
102 newAnimations.append(inert1.get()); | 102 newAnimations.append(inert1.get()); |
103 newAnimations.append(inert2.get()); | 103 newAnimations.append(inert2.get()); |
104 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), &newAnimations, 0, Animation::DefaultPri
ority, 10); | 104 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), &newAnimations, 0, KeyframeEffect::Defau
ltPriority, 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, CancelledAnimationPlayers) | 110 TEST_F(AnimationAnimationStackTest, CancelledAnimations) |
111 { | 111 { |
112 WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> cancelledAnimat
ionPlayers; | 112 WillBeHeapHashSet<RawPtrWillBeMember<const Animation>> cancelledAnimations; |
113 RefPtrWillBeRawPtr<AnimationPlayer> player = play(makeAnimation(makeAnimatio
nEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 0); | 113 RefPtrWillBeRawPtr<Animation> animation = play(makeKeyframeEffect(makeEffect
Model(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 0); |
114 cancelledAnimationPlayers.add(player.get()); | 114 cancelledAnimations.add(animation.get()); |
115 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::
create(2))).get(), 0); | 115 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))).get(), 0); |
116 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, &cancelledAnimationPlayers, Animation
::DefaultPriority, 0); | 116 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->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 RefPtrWillBeRawPtr<AnimationPlayer> player = play(makeAnimation(makeAnimatio
nEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 10); | 123 RefPtrWillBeRawPtr<Animation> animation = play(makeKeyframeEffect(makeEffect
Model(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 10); |
124 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->elementAnimations()->defaultStack(), 0, 0, Animation::DefaultPriority, 0); | 124 ActiveInterpolationMap result = AnimationStack::activeInterpolations(&elemen
t->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 player->setSource(0); | 128 animation->setSource(0); |
129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>defaultStack(), 0, 0, Animation::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 |