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

Side by Side Diff: sky/engine/core/animation/AnimationStackTest.cpp

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sky/engine/core/animation/AnimationStack.h"
6
7 #include <gtest/gtest.h>
8 #include "sky/engine/core/animation/ActiveAnimations.h"
9 #include "sky/engine/core/animation/AnimationClock.h"
10 #include "sky/engine/core/animation/AnimationTimeline.h"
11 #include "sky/engine/core/animation/KeyframeEffectModel.h"
12 #include "sky/engine/core/animation/LegacyStyleInterpolation.h"
13 #include "sky/engine/core/animation/animatable/AnimatableDouble.h"
14
15 namespace blink {
16
17 class AnimationAnimationStackTest : public ::testing::Test {
18 protected:
19 virtual void SetUp()
20 {
21 document = Document::create();
22 document->animationClock().resetTimeForTesting();
23 timeline = AnimationTimeline::create(document.get());
24 element = document->createElement("foo", ASSERT_NO_EXCEPTION);
25 }
26
27 AnimationPlayer* play(Animation* animation, double startTime)
28 {
29 AnimationPlayer* player = timeline->createAnimationPlayer(animation);
30 player->setStartTimeInternal(startTime);
31 player->update(TimingUpdateOnDemand);
32 return player;
33 }
34
35 void updateTimeline(double time)
36 {
37 document->animationClock().updateTime(time);
38 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
39 }
40
41 const Vector<OwnPtr<SampledEffect> >& effects()
42 {
43 return element->ensureActiveAnimations().defaultStack().m_effects;
44 }
45
46 PassRefPtr<AnimationEffect> makeAnimationEffect(CSSPropertyID id, PassRefPtr <AnimatableValue> value)
47 {
48 AnimatableValueKeyframeVector keyframes(2);
49 keyframes[0] = AnimatableValueKeyframe::create();
50 keyframes[0]->setOffset(0.0);
51 keyframes[0]->setPropertyValue(id, value.get());
52 keyframes[1] = AnimatableValueKeyframe::create();
53 keyframes[1]->setOffset(1.0);
54 keyframes[1]->setPropertyValue(id, value.get());
55 return AnimatableValueKeyframeEffectModel::create(keyframes);
56 }
57
58 PassRefPtr<InertAnimation> makeInertAnimation(PassRefPtr<AnimationEffect> ef fect)
59 {
60 Timing timing;
61 timing.fillMode = Timing::FillModeBoth;
62 return InertAnimation::create(effect, timing, false);
63 }
64
65 PassRefPtr<Animation> makeAnimation(PassRefPtr<AnimationEffect> effect, doub le duration = 10)
66 {
67 Timing timing;
68 timing.fillMode = Timing::FillModeBoth;
69 timing.iterationDuration = duration;
70 return Animation::create(element.get(), effect, timing);
71 }
72
73 AnimatableValue* interpolationValue(Interpolation* interpolation)
74 {
75 return toLegacyStyleInterpolation(interpolation)->currentValue().get();
76 }
77
78 RefPtr<Document> document;
79 RefPtr<AnimationTimeline> timeline;
80 RefPtr<Element> element;
81 };
82
83 TEST_F(AnimationAnimationStackTest, ActiveAnimationsSorted)
84 {
85 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(1))).get(), 10);
86 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(2))).get(), 15);
87 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(3))).get(), 5);
88 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), 0, 0, Animation:: DefaultPriority, 0);
89 EXPECT_EQ(1u, result.size());
90 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim atableDouble::create(3).get()));
91 }
92
93 TEST_F(AnimationAnimationStackTest, NewAnimations)
94 {
95 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(1))).get(), 15);
96 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble:: create(2))).get(), 10);
97 Vector<RawPtr<InertAnimation> > newAnimations;
98 RefPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimationEffect(CSSPr opertyFontSize, AnimatableDouble::create(3)));
99 RefPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimationEffect(CSSPr opertyZIndex, AnimatableDouble::create(4)));
100 newAnimations.append(inert1.get());
101 newAnimations.append(inert2.get());
102 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), &newAnimations, 0 , Animation::DefaultPriority, 10);
103 EXPECT_EQ(2u, result.size());
104 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim atableDouble::create(3).get()));
105 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat ableDouble::create(4).get()));
106 }
107
108 TEST_F(AnimationAnimationStackTest, CancelledAnimationPlayers)
109 {
110 HashSet<RawPtr<const AnimationPlayer> > cancelledAnimationPlayers;
111 RefPtr<AnimationPlayer> player = play(makeAnimation(makeAnimationEffect(CSSP ropertyFontSize, AnimatableDouble::create(1))).get(), 0);
112 cancelledAnimationPlayers.add(player.get());
113 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble:: create(2))).get(), 0);
114 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), 0, &cancelledAnim ationPlayers, Animation::DefaultPriority, 0);
115 EXPECT_EQ(1u, result.size());
116 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat ableDouble::create(2).get()));
117 }
118
119 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding)
120 {
121 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(1))).get(), 2);
122 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(2))).get(), 6);
123 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(3))).get(), 4);
124 document->pendingAnimations().update();
125 HashMap<CSSPropertyID, RefPtr<Interpolation> > interpolations;
126
127 updateTimeline(11);
128 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0);
129 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ als(AnimatableDouble::create(3).get()));
130 EXPECT_EQ(3u, effects().size());
131 EXPECT_EQ(1u, interpolations.size());
132
133 updateTimeline(13);
134 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0);
135 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ als(AnimatableDouble::create(3).get()));
136 EXPECT_EQ(3u, effects().size());
137
138 updateTimeline(15);
139 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0);
140 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ als(AnimatableDouble::create(3).get()));
141 EXPECT_EQ(2u, effects().size());
142
143 updateTimeline(17);
144 interpolations = AnimationStack::activeInterpolations(&element->activeAnimat ions()->defaultStack(), 0, 0, Animation::DefaultPriority, 0);
145 EXPECT_TRUE(interpolationValue(interpolations.get(CSSPropertyFontSize))->equ als(AnimatableDouble::create(3).get()));
146 EXPECT_EQ(1u, effects().size());
147 }
148
149 }
OLDNEW
« no previous file with comments | « sky/engine/core/animation/AnimationStack.cpp ('k') | sky/engine/core/animation/AnimationTimeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698