| 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 "core/animation/AnimationStack.h" | 5 #include "core/animation/AnimationStack.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/KeyframeEffect.h" |
| 11 #include "core/animation/KeyframeEffectModel.h" | 12 #include "core/animation/KeyframeEffectModel.h" |
| 13 #include "core/animation/KeyframeEffectReadOnly.h" |
| 12 #include "core/animation/LegacyStyleInterpolation.h" | 14 #include "core/animation/LegacyStyleInterpolation.h" |
| 13 #include "core/animation/animatable/AnimatableDouble.h" | 15 #include "core/animation/animatable/AnimatableDouble.h" |
| 14 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <memory> | 18 #include <memory> |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 class AnimationAnimationStackTest : public ::testing::Test { | 22 class AnimationAnimationStackTest : public ::testing::Test { |
| 21 protected: | 23 protected: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Persistent<Document> document; | 86 Persistent<Document> document; |
| 85 Persistent<DocumentTimeline> timeline; | 87 Persistent<DocumentTimeline> timeline; |
| 86 Persistent<Element> element; | 88 Persistent<Element> element; |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) | 91 TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) |
| 90 { | 92 { |
| 91 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); | 93 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 10); |
| 92 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); | 94 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 15); |
| 93 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); | 95 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 5); |
| 94 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffect::DefaultPriority
); | 96 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffectReadOnly::Default
Priority); |
| 95 EXPECT_EQ(1u, result.size()); | 97 EXPECT_EQ(1u, result.size()); |
| 96 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 98 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
| 97 } | 99 } |
| 98 | 100 |
| 99 TEST_F(AnimationAnimationStackTest, NewAnimations) | 101 TEST_F(AnimationAnimationStackTest, NewAnimations) |
| 100 { | 102 { |
| 101 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 15); | 103 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 15); |
| 102 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 10); | 104 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 10); |
| 103 HeapVector<Member<const InertEffect>> newAnimations; | 105 HeapVector<Member<const InertEffect>> newAnimations; |
| 104 InertEffect* inert1 = makeInertEffect(makeEffectModel(CSSPropertyFontSize, A
nimatableDouble::create(3))); | 106 InertEffect* inert1 = makeInertEffect(makeEffectModel(CSSPropertyFontSize, A
nimatableDouble::create(3))); |
| 105 InertEffect* inert2 = makeInertEffect(makeEffectModel(CSSPropertyZIndex, Ani
matableDouble::create(4))); | 107 InertEffect* inert2 = makeInertEffect(makeEffectModel(CSSPropertyZIndex, Ani
matableDouble::create(4))); |
| 106 newAnimations.append(inert1); | 108 newAnimations.append(inert1); |
| 107 newAnimations.append(inert2); | 109 newAnimations.append(inert2); |
| 108 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), &newAnimations, 0, KeyframeEffect::De
faultPriority); | 110 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), &newAnimations, 0, KeyframeEffectRead
Only::DefaultPriority); |
| 109 EXPECT_EQ(2u, result.size()); | 111 EXPECT_EQ(2u, result.size()); |
| 110 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); | 112 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(3).get())); |
| 111 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); | 113 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(4).get())); |
| 112 } | 114 } |
| 113 | 115 |
| 114 TEST_F(AnimationAnimationStackTest, CancelledAnimations) | 116 TEST_F(AnimationAnimationStackTest, CancelledAnimations) |
| 115 { | 117 { |
| 116 HeapHashSet<Member<const Animation>> cancelledAnimations; | 118 HeapHashSet<Member<const Animation>> cancelledAnimations; |
| 117 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 0); | 119 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 0); |
| 118 cancelledAnimations.add(animation); | 120 cancelledAnimations.add(animation); |
| 119 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 0); | 121 play(makeKeyframeEffect(makeEffectModel(CSSPropertyZIndex, AnimatableDouble:
:create(2))), 0); |
| 120 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, &cancelledAnimations, KeyframeEffe
ct::DefaultPriority); | 122 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, &cancelledAnimations, KeyframeEffe
ctReadOnly::DefaultPriority); |
| 121 EXPECT_EQ(1u, result.size()); | 123 EXPECT_EQ(1u, result.size()); |
| 122 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); | 124 EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex)->equals(Animatable
Double::create(2).get())); |
| 123 } | 125 } |
| 124 | 126 |
| 125 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) | 127 TEST_F(AnimationAnimationStackTest, ClearedEffectsRemoved) |
| 126 { | 128 { |
| 127 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 10); | 129 Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFo
ntSize, AnimatableDouble::create(1))), 10); |
| 128 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffect::DefaultPriority
); | 130 ActiveInterpolationsMap result = AnimationStack::activeInterpolations(&eleme
nt->elementAnimations()->animationStack(), 0, 0, KeyframeEffectReadOnly::Default
Priority); |
| 129 EXPECT_EQ(1u, result.size()); | 131 EXPECT_EQ(1u, result.size()); |
| 130 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); | 132 EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize)->equals(Animatab
leDouble::create(1).get())); |
| 131 | 133 |
| 132 animation->setEffect(0); | 134 animation->setEffect(0); |
| 133 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>animationStack(), 0, 0, KeyframeEffect::DefaultPriority); | 135 result = AnimationStack::activeInterpolations(&element->elementAnimations()-
>animationStack(), 0, 0, KeyframeEffectReadOnly::DefaultPriority); |
| 134 EXPECT_EQ(0u, result.size()); | 136 EXPECT_EQ(0u, result.size()); |
| 135 } | 137 } |
| 136 | 138 |
| 137 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding) | 139 TEST_F(AnimationAnimationStackTest, ForwardsFillDiscarding) |
| 138 { | 140 { |
| 139 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 2); | 141 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(1))), 2); |
| 140 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 6); | 142 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(2))), 6); |
| 141 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 4); | 143 play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDoubl
e::create(3))), 4); |
| 142 document->compositorPendingAnimations().update(); | 144 document->compositorPendingAnimations().update(); |
| 143 ActiveInterpolationsMap interpolations; | 145 ActiveInterpolationsMap interpolations; |
| 144 | 146 |
| 145 updateTimeline(11); | 147 updateTimeline(11); |
| 146 ThreadState::current()-> collectAllGarbage(); | 148 ThreadState::current()-> collectAllGarbage(); |
| 147 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffect::DefaultPriority); | 149 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPrio
rity); |
| 148 EXPECT_EQ(1u, interpolations.size()); | 150 EXPECT_EQ(1u, interpolations.size()); |
| 149 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); | 151 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); |
| 150 EXPECT_EQ(3u, sampledEffectCount()); | 152 EXPECT_EQ(3u, sampledEffectCount()); |
| 151 | 153 |
| 152 updateTimeline(13); | 154 updateTimeline(13); |
| 153 ThreadState::current()-> collectAllGarbage(); | 155 ThreadState::current()-> collectAllGarbage(); |
| 154 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffect::DefaultPriority); | 156 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPrio
rity); |
| 155 EXPECT_EQ(1u, interpolations.size()); | 157 EXPECT_EQ(1u, interpolations.size()); |
| 156 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); | 158 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); |
| 157 EXPECT_EQ(3u, sampledEffectCount()); | 159 EXPECT_EQ(3u, sampledEffectCount()); |
| 158 | 160 |
| 159 updateTimeline(15); | 161 updateTimeline(15); |
| 160 ThreadState::current()-> collectAllGarbage(); | 162 ThreadState::current()-> collectAllGarbage(); |
| 161 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffect::DefaultPriority); | 163 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPrio
rity); |
| 162 EXPECT_EQ(1u, interpolations.size()); | 164 EXPECT_EQ(1u, interpolations.size()); |
| 163 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); | 165 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); |
| 164 EXPECT_EQ(2u, sampledEffectCount()); | 166 EXPECT_EQ(2u, sampledEffectCount()); |
| 165 | 167 |
| 166 updateTimeline(17); | 168 updateTimeline(17); |
| 167 ThreadState::current()-> collectAllGarbage(); | 169 ThreadState::current()-> collectAllGarbage(); |
| 168 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffect::DefaultPriority); | 170 interpolations = AnimationStack::activeInterpolations(&element->elementAnima
tions()->animationStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPrio
rity); |
| 169 EXPECT_EQ(1u, interpolations.size()); | 171 EXPECT_EQ(1u, interpolations.size()); |
| 170 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); | 172 EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize)->equals(
AnimatableDouble::create(3).get())); |
| 171 EXPECT_EQ(1u, sampledEffectCount()); | 173 EXPECT_EQ(1u, sampledEffectCount()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |