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

Side by Side Diff: Source/core/animation/AnimationStackTest.cpp

Issue 210703002: Web Animations: Sort Animations in the AnimationStack (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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 "config.h"
6 #include "core/animation/AnimationStack.h"
7
8 #include "core/animation/ActiveAnimations.h"
9 #include "core/animation/AnimatableDouble.h"
10 #include "core/animation/AnimationClock.h"
11 #include "core/animation/DocumentTimeline.h"
12 #include "core/animation/KeyframeEffectModel.h"
13 #include <gtest/gtest.h>
14
15 using namespace WebCore;
16
17 namespace {
18
19 class AnimationAnimationStackTest : public ::testing::Test {
20 protected:
21 virtual void SetUp()
22 {
23 document = Document::create();
24 document->animationClock().resetTimeForTesting();
25 timeline = DocumentTimeline::create(document.get());
26 timeline->setZeroTime(0);
27 element = document->createElement("foo", ASSERT_NO_EXCEPTION);
28 }
29
30 PassRefPtr<AnimationPlayer> play(Animation* animation, double startTime)
31 {
32 RefPtr<AnimationPlayer> player = timeline->createAnimationPlayer(animati on);
33 player->setStartTime(startTime);
34 player->update();
35 return player.release();
36 }
37
38 PassRefPtr<AnimationEffect> makeAnimationEffect(CSSPropertyID id, PassRefPtr <AnimatableValue> value)
39 {
40 KeyframeEffectModel::KeyframeVector keyframes(2);
41 keyframes[0] = Keyframe::create();
42 keyframes[0]->setOffset(0.0);
43 keyframes[0]->setPropertyValue(id, value.get());
44 keyframes[1] = Keyframe::create();
45 keyframes[1]->setOffset(1.0);
46 keyframes[1]->setPropertyValue(id, value.get());
47 return KeyframeEffectModel::create(keyframes);
48 }
49
50 PassRefPtr<InertAnimation> makeInertAnimation(PassRefPtr<AnimationEffect> ef fect)
51 {
52 Timing timing;
53 timing.fillMode = Timing::FillModeBoth;
54 return InertAnimation::create(effect, timing, false);
55 }
56
57 PassRefPtr<Animation> makeAnimation(PassRefPtr<AnimationEffect> effect)
58 {
59 Timing timing;
60 timing.fillMode = Timing::FillModeBoth;
61 return Animation::create(element, effect, timing);
62 }
63
64 AnimatableValue* interpolationValue(Interpolation* interpolation)
65 {
66 return toLegacyStyleInterpolation(interpolation)->currentValue();
67 }
68
69 RefPtr<Document> document;
70 RefPtr<DocumentTimeline> timeline;
71 RefPtr<Element> element;
72 };
73
74 TEST_F(AnimationAnimationStackTest, ActiveAnimationsSorted)
75 {
76 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(1))).get(), 10);
77 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(2))).get(), 15);
78 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(3))).get(), 5);
79 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), 0, 0, Animation:: DefaultPriority, 0);
80 EXPECT_EQ(1, result.size());
81 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim atableDouble::create(2).get()));
82 }
83
84 TEST_F(AnimationAnimationStackTest, NewAnimations)
85 {
86 play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble ::create(1))).get(), 15);
87 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble:: create(2))).get(), 10);
88 Vector<InertAnimation*> newAnimations;
89 RefPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimationEffect(CSSPr opertyFontSize, AnimatableDouble::create(3)));
90 RefPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimationEffect(CSSPr opertyZIndex, AnimatableDouble::create(4)));
91 newAnimations.append(inert1.get());
92 newAnimations.append(inert2.get());
93 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), &newAnimations, 0 , Animation::DefaultPriority, 10);
94 EXPECT_EQ(2, result.size());
95 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(Anim atableDouble::create(1).get()));
96 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat ableDouble::create(4).get()));
97 }
98
99 TEST_F(AnimationAnimationStackTest, CancelledAnimationPlayers)
100 {
101 HashSet<const AnimationPlayer*> cancelledAnimationPlayers;
102 cancelledAnimationPlayers.add(play(makeAnimation(makeAnimationEffect(CSSProp ertyFontSize, AnimatableDouble::create(1))).get(), 0).get());
103 play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble:: create(2))).get(), 0);
104 HashMap<CSSPropertyID, RefPtr<Interpolation> > result = AnimationStack::acti veInterpolations(&element->activeAnimations()->defaultStack(), 0, &cancelledAnim ationPlayers, Animation::DefaultPriority, 0);
105 EXPECT_EQ(1, result.size());
106 EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(Animat ableDouble::create(2).get()));
107 }
108
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698