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 "core/testing/DummyPageHolder.h" |
14 #include <gtest/gtest.h> | 15 #include <gtest/gtest.h> |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 class AnimationAnimationStackTest : public ::testing::Test { | 19 class AnimationAnimationStackTest : public ::testing::Test { |
19 protected: | 20 protected: |
20 virtual void SetUp() | 21 virtual void SetUp() |
21 { | 22 { |
22 document = Document::create(); | 23 pageHolder = DummyPageHolder::create(); |
| 24 document = &pageHolder->document(); |
23 document->animationClock().resetTimeForTesting(); | 25 document->animationClock().resetTimeForTesting(); |
24 timeline = AnimationTimeline::create(document.get()); | 26 timeline = AnimationTimeline::create(document.get()); |
25 element = document->createElement("foo", ASSERT_NO_EXCEPTION); | 27 element = document->createElement("foo", ASSERT_NO_EXCEPTION); |
26 } | 28 } |
27 | 29 |
28 Animation* play(KeyframeEffect* effect, double startTime) | 30 Animation* play(KeyframeEffect* effect, double startTime) |
29 { | 31 { |
30 Animation* animation = timeline->play(effect); | 32 Animation* animation = timeline->play(effect); |
31 animation->setStartTime(startTime * 1000); | 33 animation->setStartTime(startTime * 1000); |
32 animation->update(TimingUpdateOnDemand); | 34 animation->update(TimingUpdateOnDemand); |
33 return animation; | 35 return animation; |
34 } | 36 } |
35 | 37 |
36 void updateTimeline(double time) | 38 void updateTimeline(double time) |
37 { | 39 { |
38 document->animationClock().updateTime(time); | 40 document->animationClock().updateTime(document->timeline().zeroTime() +
time); |
39 timeline->serviceAnimations(TimingUpdateForAnimationFrame); | 41 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
40 } | 42 } |
41 | 43 |
42 const HeapVector<Member<SampledEffect>>& effects() | 44 const HeapVector<Member<SampledEffect>>& effects() |
43 { | 45 { |
44 return element->ensureElementAnimations().animationStack().m_effects; | 46 return element->ensureElementAnimations().animationStack().m_effects; |
45 } | 47 } |
46 | 48 |
47 EffectModel* makeEffectModel(CSSPropertyID id, PassRefPtr<AnimatableValue> v
alue) | 49 EffectModel* makeEffectModel(CSSPropertyID id, PassRefPtr<AnimatableValue> v
alue) |
48 { | 50 { |
(...skipping 21 matching lines...) Expand all Loading... |
70 timing.iterationDuration = duration; | 72 timing.iterationDuration = duration; |
71 return KeyframeEffect::create(element.get(), effect, timing); | 73 return KeyframeEffect::create(element.get(), effect, timing); |
72 } | 74 } |
73 | 75 |
74 AnimatableValue* interpolationValue(const ActiveInterpolationsMap& activeInt
erpolations, CSSPropertyID id) | 76 AnimatableValue* interpolationValue(const ActiveInterpolationsMap& activeInt
erpolations, CSSPropertyID id) |
75 { | 77 { |
76 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)).at(0); | 78 Interpolation& interpolation = *activeInterpolations.get(PropertyHandle(
id)).at(0); |
77 return toLegacyStyleInterpolation(interpolation).currentValue().get(); | 79 return toLegacyStyleInterpolation(interpolation).currentValue().get(); |
78 } | 80 } |
79 | 81 |
| 82 OwnPtr<DummyPageHolder> pageHolder; |
80 RefPtrWillBePersistent<Document> document; | 83 RefPtrWillBePersistent<Document> document; |
81 Persistent<AnimationTimeline> timeline; | 84 Persistent<AnimationTimeline> timeline; |
82 RefPtrWillBePersistent<Element> element; | 85 RefPtrWillBePersistent<Element> element; |
83 }; | 86 }; |
84 | 87 |
85 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) | 88 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) |
86 { | 89 { |
87 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); | 90 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); |
88 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); | 91 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); |
89 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); | 92 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffect::DefaultPriority
); | 127 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffect::DefaultPriority
); |
125 EXPECT_EQ(1u, result.size()); | 128 EXPECT_EQ(1u, result.size()); |
126 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); | 129 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); |
127 | 130 |
128 animation->setEffect(0); | 131 animation->setEffect(0); |
129 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>animationStack(), 0, 0, KeyframeEffect::DefaultPriority); | 132 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>animationStack(), 0, 0, KeyframeEffect::DefaultPriority); |
130 EXPECT_EQ(0u, result.size()); | 133 EXPECT_EQ(0u, result.size()); |
131 } | 134 } |
132 | 135 |
133 } | 136 } |
OLD | NEW |