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/InterpolationEffect.h" 7 8#include <gtest/gtest.h> 9 10namespace { 11 12const double duration = 1.0; 13 14} // namespace 15 16namespace blink { 17 18class AnimationInterpolationEffectTest : public ::testing::Test { 19protected: 20 InterpolableValue* interpolationValue(Interpolation& interpolation) 21 { 22 return interpolation.getCachedValueForTesting(); 23 } 24 25 double getInterpolableNumber(PassRefPtrWillBeRawPtr<Interpolation> value) 26 { 27 return toInterpolableNumber(interpolationValue(*value.get()))->value(); 28 } 29}; 30 31TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) 32{ 33 RefPtrWillBeRawPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::create(); 34 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumber::create(0), InterpolableNumber::create(10)), 35 RefPtr<TimingFunction>(), 0, 1, -1, 2); 36 37 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation> > > activeInterpolations = interpolationEffect->getActiveInterpolations(-2, duration); 38 EXPECT_EQ(0ul, activeInterpolations->size()); 39 40 activeInterpolations = interpolationEffect->getActiveInterpolations(-0.5, duration); 41 EXPECT_EQ(1ul, activeInterpolations->size()); 42 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0))); 43 44 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, duration); 45 EXPECT_EQ(1ul, activeInterpolations->size()); 46 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0))); 47 48 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, duration); 49 EXPECT_EQ(1ul, activeInterpolations->size()); 50 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); 51 52 activeInterpolations = interpolationEffect->getActiveInterpolations(3, duration); 53 EXPECT_EQ(0ul, activeInterpolations->size()); 54} 55 56TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) 57{ 58 RefPtrWillBeRawPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::create(); 59 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumber::create(10), InterpolableNumber::create(15)), 60 RefPtr<TimingFunction>(), 1, 2, 1, 3); 61 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumber::create(0), InterpolableNumber::create(1)), 62 LinearTimingFunction::shared(), 0, 1, 0, 1); 63 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumber::create(1), InterpolableNumber::create(6)), 64 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5, 1.5, 0.5, 1.5); 65 66 OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation> > > activeInterpolations = interpolationEffect->getActiveInterpolations(-0.5, duration); 67 EXPECT_EQ(0ul, activeInterpolations->size()); 68 69 activeInterpolations = interpolationEffect->getActiveInterpolations(0, duration); 70 EXPECT_EQ(1ul, activeInterpolations->size()); 71 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0))); 72 73 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, duration); 74 EXPECT_EQ(2ul, activeInterpolations->size()); 75 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0))); 76 EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations->at(1))); 77 78 activeInterpolations = interpolationEffect->getActiveInterpolations(1, duration); 79 EXPECT_EQ(2ul, activeInterpolations->size()); 80 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0))); 81 EXPECT_FLOAT_EQ(5.0282884f, getInterpolableNumber(activeInterpolations->at(1))); 82 83 activeInterpolations = interpolationEffect->getActiveInterpolations(1, duration * 1000); 84 EXPECT_EQ(2ul, activeInterpolations->size()); 85 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0))); 86 EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations->at(1))); 87 88 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, duration); 89 EXPECT_EQ(1ul, activeInterpolations->size()); 90 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0))); 91 92 activeInterpolations = interpolationEffect->getActiveInterpolations(2, duration); 93 EXPECT_EQ(1ul, activeInterpolations->size()); 94 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0))); 95} 96 97} 98 99