Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: third_party/WebKit/Source/core/animation/EffectStackTest.cpp

Issue 2522823002: Blink Animation: Rename AnimationStack to EffectStack. (Closed)
Patch Set: Rename getter and data (and locals) Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/AnimationStack.h" 5 #include "core/animation/EffectStack.h"
6 6
7 #include "core/animation/AnimationClock.h" 7 #include "core/animation/AnimationClock.h"
8 #include "core/animation/CompositorPendingAnimations.h" 8 #include "core/animation/CompositorPendingAnimations.h"
9 #include "core/animation/DocumentTimeline.h" 9 #include "core/animation/DocumentTimeline.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 "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include <memory> 16 #include <memory>
17 17
18 namespace blink { 18 namespace blink {
19 19
20 class AnimationAnimationStackTest : public ::testing::Test { 20 class AnimationEffectStackTest : public ::testing::Test {
21 protected: 21 protected:
22 virtual void SetUp() { 22 virtual void SetUp() {
23 pageHolder = DummyPageHolder::create(); 23 pageHolder = DummyPageHolder::create();
24 document = &pageHolder->document(); 24 document = &pageHolder->document();
25 document->animationClock().resetTimeForTesting(); 25 document->animationClock().resetTimeForTesting();
26 timeline = DocumentTimeline::create(document.get()); 26 timeline = DocumentTimeline::create(document.get());
27 element = document->createElement("foo"); 27 element = document->createElement("foo");
28 } 28 }
29 29
30 Animation* play(KeyframeEffect* effect, double startTime) { 30 Animation* play(KeyframeEffect* effect, double startTime) {
31 Animation* animation = timeline->play(effect); 31 Animation* animation = timeline->play(effect);
32 animation->setStartTime(startTime * 1000); 32 animation->setStartTime(startTime * 1000);
33 animation->update(TimingUpdateOnDemand); 33 animation->update(TimingUpdateOnDemand);
34 return animation; 34 return animation;
35 } 35 }
36 36
37 void updateTimeline(double time) { 37 void updateTimeline(double time) {
38 document->animationClock().updateTime(document->timeline().zeroTime() + 38 document->animationClock().updateTime(document->timeline().zeroTime() +
39 time); 39 time);
40 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 40 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
41 } 41 }
42 42
43 size_t sampledEffectCount() { 43 size_t sampledEffectCount() {
44 return element->ensureElementAnimations() 44 return element->ensureElementAnimations()
45 .animationStack() 45 .effectStack()
46 .m_sampledEffects.size(); 46 .m_sampledEffects.size();
47 } 47 }
48 48
49 EffectModel* makeEffectModel(CSSPropertyID id, 49 EffectModel* makeEffectModel(CSSPropertyID id,
50 PassRefPtr<AnimatableValue> value) { 50 PassRefPtr<AnimatableValue> value) {
51 AnimatableValueKeyframeVector keyframes(2); 51 AnimatableValueKeyframeVector keyframes(2);
52 keyframes[0] = AnimatableValueKeyframe::create(); 52 keyframes[0] = AnimatableValueKeyframe::create();
53 keyframes[0]->setOffset(0.0); 53 keyframes[0]->setOffset(0.0);
54 keyframes[0]->setPropertyValue(id, value.get()); 54 keyframes[0]->setPropertyValue(id, value.get());
55 keyframes[1] = AnimatableValueKeyframe::create(); 55 keyframes[1] = AnimatableValueKeyframe::create();
(...skipping 23 matching lines...) Expand all
79 *activeInterpolations.get(PropertyHandle(id)).at(0); 79 *activeInterpolations.get(PropertyHandle(id)).at(0);
80 return toLegacyStyleInterpolation(interpolation).currentValue().get(); 80 return toLegacyStyleInterpolation(interpolation).currentValue().get();
81 } 81 }
82 82
83 std::unique_ptr<DummyPageHolder> pageHolder; 83 std::unique_ptr<DummyPageHolder> pageHolder;
84 Persistent<Document> document; 84 Persistent<Document> document;
85 Persistent<DocumentTimeline> timeline; 85 Persistent<DocumentTimeline> timeline;
86 Persistent<Element> element; 86 Persistent<Element> element;
87 }; 87 };
88 88
89 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) { 89 TEST_F(AnimationEffectStackTest, ElementAnimationsSorted) {
90 play(makeKeyframeEffect( 90 play(makeKeyframeEffect(
91 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 91 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))),
92 10); 92 10);
93 play(makeKeyframeEffect( 93 play(makeKeyframeEffect(
94 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))), 94 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))),
95 15); 95 15);
96 play(makeKeyframeEffect( 96 play(makeKeyframeEffect(
97 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))), 97 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))),
98 5); 98 5);
99 ActiveInterpolationsMap result = AnimationStack::activeInterpolations( 99 ActiveInterpolationsMap result = EffectStack::activeInterpolations(
100 &element->elementAnimations()->animationStack(), 0, 0, 100 &element->elementAnimations()->effectStack(), 0, 0,
101 KeyframeEffectReadOnly::DefaultPriority); 101 KeyframeEffectReadOnly::DefaultPriority);
102 EXPECT_EQ(1u, result.size()); 102 EXPECT_EQ(1u, result.size());
103 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) 103 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)
104 ->equals(AnimatableDouble::create(3).get())); 104 ->equals(AnimatableDouble::create(3).get()));
105 } 105 }
106 106
107 TEST_F(AnimationAnimationStackTest, NewAnimations) { 107 TEST_F(AnimationEffectStackTest, NewAnimations) {
108 play(makeKeyframeEffect( 108 play(makeKeyframeEffect(
109 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 109 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))),
110 15); 110 15);
111 play(makeKeyframeEffect( 111 play(makeKeyframeEffect(
112 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))), 112 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))),
113 10); 113 10);
114 HeapVector<Member<const InertEffect>> newAnimations; 114 HeapVector<Member<const InertEffect>> newAnimations;
115 InertEffect* inert1 = makeInertEffect( 115 InertEffect* inert1 = makeInertEffect(
116 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))); 116 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3)));
117 InertEffect* inert2 = makeInertEffect( 117 InertEffect* inert2 = makeInertEffect(
118 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(4))); 118 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(4)));
119 newAnimations.append(inert1); 119 newAnimations.append(inert1);
120 newAnimations.append(inert2); 120 newAnimations.append(inert2);
121 ActiveInterpolationsMap result = AnimationStack::activeInterpolations( 121 ActiveInterpolationsMap result = EffectStack::activeInterpolations(
122 &element->elementAnimations()->animationStack(), &newAnimations, 0, 122 &element->elementAnimations()->effectStack(), &newAnimations, 0,
123 KeyframeEffectReadOnly::DefaultPriority); 123 KeyframeEffectReadOnly::DefaultPriority);
124 EXPECT_EQ(2u, result.size()); 124 EXPECT_EQ(2u, result.size());
125 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) 125 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)
126 ->equals(AnimatableDouble::create(3).get())); 126 ->equals(AnimatableDouble::create(3).get()));
127 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex) 127 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)
128 ->equals(AnimatableDouble::create(4).get())); 128 ->equals(AnimatableDouble::create(4).get()));
129 } 129 }
130 130
131 TEST_F(AnimationAnimationStackTest, CancelledAnimations) { 131 TEST_F(AnimationEffectStackTest, CancelledAnimations) {
132 HeapHashSet<Member<const Animation>> cancelledAnimations; 132 HeapHashSet<Member<const Animation>> cancelledAnimations;
133 Animation* animation = 133 Animation* animation =
134 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, 134 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize,
135 AnimatableDouble::create(1))), 135 AnimatableDouble::create(1))),
136 0); 136 0);
137 cancelledAnimations.add(animation); 137 cancelledAnimations.add(animation);
138 play(makeKeyframeEffect( 138 play(makeKeyframeEffect(
139 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))), 139 makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))),
140 0); 140 0);
141 ActiveInterpolationsMap result = AnimationStack::activeInterpolations( 141 ActiveInterpolationsMap result = EffectStack::activeInterpolations(
142 &element->elementAnimations()->animationStack(), 0, &cancelledAnimations, 142 &element->elementAnimations()->effectStack(), 0, &cancelledAnimations,
143 KeyframeEffectReadOnly::DefaultPriority); 143 KeyframeEffectReadOnly::DefaultPriority);
144 EXPECT_EQ(1u, result.size()); 144 EXPECT_EQ(1u, result.size());
145 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex) 145 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)
146 ->equals(AnimatableDouble::create(2).get())); 146 ->equals(AnimatableDouble::create(2).get()));
147 } 147 }
148 148
149 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) { 149 TEST_F(AnimationEffectStackTest, ClearedEffectsRemoved) {
150 Animation* animation = 150 Animation* animation =
151 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, 151 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize,
152 AnimatableDouble::create(1))), 152 AnimatableDouble::create(1))),
153 10); 153 10);
154 ActiveInterpolationsMap result = AnimationStack::activeInterpolations( 154 ActiveInterpolationsMap result = EffectStack::activeInterpolations(
155 &element->elementAnimations()->animationStack(), 0, 0, 155 &element->elementAnimations()->effectStack(), 0, 0,
156 KeyframeEffectReadOnly::DefaultPriority); 156 KeyframeEffectReadOnly::DefaultPriority);
157 EXPECT_EQ(1u, result.size()); 157 EXPECT_EQ(1u, result.size());
158 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) 158 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)
159 ->equals(AnimatableDouble::create(1).get())); 159 ->equals(AnimatableDouble::create(1).get()));
160 160
161 animation->setEffect(0); 161 animation->setEffect(0);
162 result = AnimationStack::activeInterpolations( 162 result = EffectStack::activeInterpolations(
163 &element->elementAnimations()->animationStack(), 0, 0, 163 &element->elementAnimations()->effectStack(), 0, 0,
164 KeyframeEffectReadOnly::DefaultPriority); 164 KeyframeEffectReadOnly::DefaultPriority);
165 EXPECT_EQ(0u, result.size()); 165 EXPECT_EQ(0u, result.size());
166 } 166 }
167 167
168 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding) { 168 TEST_F(AnimationEffectStackTest, ForwardsFillDiscarding) {
169 play(makeKeyframeEffect( 169 play(makeKeyframeEffect(
170 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 170 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))),
171 2); 171 2);
172 play(makeKeyframeEffect( 172 play(makeKeyframeEffect(
173 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))), 173 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))),
174 6); 174 6);
175 play(makeKeyframeEffect( 175 play(makeKeyframeEffect(
176 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))), 176 makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))),
177 4); 177 4);
178 document->compositorPendingAnimations().update(); 178 document->compositorPendingAnimations().update();
179 ActiveInterpolationsMap interpolations; 179 ActiveInterpolationsMap interpolations;
180 180
181 updateTimeline(11); 181 updateTimeline(11);
182 ThreadState::current()->collectAllGarbage(); 182 ThreadState::current()->collectAllGarbage();
183 interpolations = AnimationStack::activeInterpolations( 183 interpolations = EffectStack::activeInterpolations(
184 &element->elementAnimations()->animationStack(), nullptr, nullptr, 184 &element->elementAnimations()->effectStack(), nullptr, nullptr,
185 KeyframeEffectReadOnly::DefaultPriority); 185 KeyframeEffectReadOnly::DefaultPriority);
186 EXPECT_EQ(1u, interpolations.size()); 186 EXPECT_EQ(1u, interpolations.size());
187 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) 187 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)
188 ->equals(AnimatableDouble::create(3).get())); 188 ->equals(AnimatableDouble::create(3).get()));
189 EXPECT_EQ(3u, sampledEffectCount()); 189 EXPECT_EQ(3u, sampledEffectCount());
190 190
191 updateTimeline(13); 191 updateTimeline(13);
192 ThreadState::current()->collectAllGarbage(); 192 ThreadState::current()->collectAllGarbage();
193 interpolations = AnimationStack::activeInterpolations( 193 interpolations = EffectStack::activeInterpolations(
194 &element->elementAnimations()->animationStack(), nullptr, nullptr, 194 &element->elementAnimations()->effectStack(), nullptr, nullptr,
195 KeyframeEffectReadOnly::DefaultPriority); 195 KeyframeEffectReadOnly::DefaultPriority);
196 EXPECT_EQ(1u, interpolations.size()); 196 EXPECT_EQ(1u, interpolations.size());
197 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) 197 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)
198 ->equals(AnimatableDouble::create(3).get())); 198 ->equals(AnimatableDouble::create(3).get()));
199 EXPECT_EQ(3u, sampledEffectCount()); 199 EXPECT_EQ(3u, sampledEffectCount());
200 200
201 updateTimeline(15); 201 updateTimeline(15);
202 ThreadState::current()->collectAllGarbage(); 202 ThreadState::current()->collectAllGarbage();
203 interpolations = AnimationStack::activeInterpolations( 203 interpolations = EffectStack::activeInterpolations(
204 &element->elementAnimations()->animationStack(), nullptr, nullptr, 204 &element->elementAnimations()->effectStack(), nullptr, nullptr,
205 KeyframeEffectReadOnly::DefaultPriority); 205 KeyframeEffectReadOnly::DefaultPriority);
206 EXPECT_EQ(1u, interpolations.size()); 206 EXPECT_EQ(1u, interpolations.size());
207 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) 207 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)
208 ->equals(AnimatableDouble::create(3).get())); 208 ->equals(AnimatableDouble::create(3).get()));
209 EXPECT_EQ(2u, sampledEffectCount()); 209 EXPECT_EQ(2u, sampledEffectCount());
210 210
211 updateTimeline(17); 211 updateTimeline(17);
212 ThreadState::current()->collectAllGarbage(); 212 ThreadState::current()->collectAllGarbage();
213 interpolations = AnimationStack::activeInterpolations( 213 interpolations = EffectStack::activeInterpolations(
214 &element->elementAnimations()->animationStack(), nullptr, nullptr, 214 &element->elementAnimations()->effectStack(), nullptr, nullptr,
215 KeyframeEffectReadOnly::DefaultPriority); 215 KeyframeEffectReadOnly::DefaultPriority);
216 EXPECT_EQ(1u, interpolations.size()); 216 EXPECT_EQ(1u, interpolations.size());
217 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) 217 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)
218 ->equals(AnimatableDouble::create(3).get())); 218 ->equals(AnimatableDouble::create(3).get()));
219 EXPECT_EQ(1u, sampledEffectCount()); 219 EXPECT_EQ(1u, sampledEffectCount());
220 } 220 }
221 221
222 } // namespace blink 222 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/EffectStack.cpp ('k') | third_party/WebKit/Source/core/animation/ElementAnimations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698