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

Side by Side Diff: sky/engine/core/animation/InterpolationEffectTest.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
« no previous file with comments | « sky/engine/core/animation/InterpolationEffect.cpp ('k') | sky/engine/core/animation/Keyframe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/InterpolationEffect.h"
6
7 #include <gtest/gtest.h>
8
9 namespace {
10
11 const double duration = 1.0;
12
13 } // namespace
14
15 namespace blink {
16
17 class AnimationInterpolationEffectTest : public ::testing::Test {
18 protected:
19 InterpolableValue* interpolationValue(Interpolation& interpolation)
20 {
21 return interpolation.getCachedValueForTesting();
22 }
23
24 double getInterpolableNumber(PassRefPtr<Interpolation> value)
25 {
26 return toInterpolableNumber(interpolationValue(*value.get()))->value();
27 }
28 };
29
30 TEST_F(AnimationInterpolationEffectTest, SingleInterpolation)
31 {
32 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e();
33 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(10)),
34 RefPtr<TimingFunction>(), 0, 1, -1, 2);
35
36 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-2, duration);
37 EXPECT_EQ(0ul, activeInterpolations->size());
38
39 activeInterpolations = interpolationEffect->getActiveInterpolations(-0.5, du ration);
40 EXPECT_EQ(1ul, activeInterpolations->size());
41 EXPECT_EQ(-5, getInterpolableNumber(activeInterpolations->at(0)));
42
43 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, dur ation);
44 EXPECT_EQ(1ul, activeInterpolations->size());
45 EXPECT_FLOAT_EQ(5, getInterpolableNumber(activeInterpolations->at(0)));
46
47 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, dur ation);
48 EXPECT_EQ(1ul, activeInterpolations->size());
49 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0)));
50
51 activeInterpolations = interpolationEffect->getActiveInterpolations(3, durat ion);
52 EXPECT_EQ(0ul, activeInterpolations->size());
53 }
54
55 TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations)
56 {
57 RefPtr<InterpolationEffect> interpolationEffect = InterpolationEffect::creat e();
58 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(10), InterpolableNumber::create(15)),
59 RefPtr<TimingFunction>(), 1, 2, 1, 3);
60 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(0), InterpolableNumber::create(1)),
61 LinearTimingFunction::shared(), 0, 1, 0, 1);
62 interpolationEffect->addInterpolation(Interpolation::create(InterpolableNumb er::create(1), InterpolableNumber::create(6)),
63 CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5, 1.5, 0.5, 1.5);
64
65 OwnPtr<Vector<RefPtr<Interpolation> > > activeInterpolations = interpolation Effect->getActiveInterpolations(-0.5, duration);
66 EXPECT_EQ(0ul, activeInterpolations->size());
67
68 activeInterpolations = interpolationEffect->getActiveInterpolations(0, durat ion);
69 EXPECT_EQ(1ul, activeInterpolations->size());
70 EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations->at(0)));
71
72 activeInterpolations = interpolationEffect->getActiveInterpolations(0.5, dur ation);
73 EXPECT_EQ(2ul, activeInterpolations->size());
74 EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations->at(0)));
75 EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations->at(1)));
76
77 activeInterpolations = interpolationEffect->getActiveInterpolations(1, durat ion);
78 EXPECT_EQ(2ul, activeInterpolations->size());
79 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0)));
80 EXPECT_FLOAT_EQ(5.0282884f, getInterpolableNumber(activeInterpolations->at(1 )));
81
82 activeInterpolations = interpolationEffect->getActiveInterpolations(1, durat ion * 1000);
83 EXPECT_EQ(2ul, activeInterpolations->size());
84 EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations->at(0)));
85 EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations->at(1 )));
86
87 activeInterpolations = interpolationEffect->getActiveInterpolations(1.5, dur ation);
88 EXPECT_EQ(1ul, activeInterpolations->size());
89 EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations->at(0)));
90
91 activeInterpolations = interpolationEffect->getActiveInterpolations(2, durat ion);
92 EXPECT_EQ(1ul, activeInterpolations->size());
93 EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations->at(0)));
94 }
95
96 }
97
OLDNEW
« no previous file with comments | « sky/engine/core/animation/InterpolationEffect.cpp ('k') | sky/engine/core/animation/Keyframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698