1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/animation/animation.h"
#include "cc/test/animation_test_common.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
scoped_ptr<Animation> CreateAnimation(int iterations, double duration) {
scoped_ptr<Animation> to_return(Animation::Create(
make_scoped_ptr(
new FakeFloatAnimationCurve(duration)).PassAs<AnimationCurve>(),
0,
1,
Animation::Opacity));
to_return->set_iterations(iterations);
return to_return.Pass();
}
scoped_ptr<Animation> CreateAnimation(int iterations) {
return CreateAnimation(iterations, 1);
}
TEST(AnimationTest, TrimTimeZeroIterations) {
scoped_ptr<Animation> anim(CreateAnimation(0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
}
TEST(AnimationTest, TrimTimeOneIteration) {
scoped_ptr<Animation> anim(CreateAnimation(1));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(2.0));
}
TEST(AnimationTest, TrimTimeInfiniteIterations) {
scoped_ptr<Animation> anim(CreateAnimation(-1));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5));
}
TEST(AnimationTest, TrimTimeAlternating) {
scoped_ptr<Animation> anim(CreateAnimation(-1));
anim->set_alternates_direction(true);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
}
TEST(AnimationTest, TrimTimeStartTime) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_start_time(4);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
}
TEST(AnimationTest, TrimTimeTimeOffset) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_time_offset(4);
anim->set_start_time(4);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
}
TEST(AnimationTest, TrimTimePauseResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
anim->SetRunState(Animation::Paused, 0.5);
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
anim->SetRunState(Animation::Running, 1024.0);
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
TEST(AnimationTest, TrimTimeSuspendResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
anim->Suspend(0.5);
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
anim->Resume(1024);
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
TEST(AnimationTest, TrimTimeZeroDuration) {
scoped_ptr<Animation> anim(CreateAnimation(0, 0));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
}
TEST(AnimationTest, IsFinishedAtZeroIterations) {
scoped_ptr<Animation> anim(CreateAnimation(0));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(-1.0));
EXPECT_TRUE(anim->IsFinishedAt(0.0));
EXPECT_TRUE(anim->IsFinishedAt(1.0));
}
TEST(AnimationTest, IsFinishedAtOneIteration) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(-1.0));
EXPECT_FALSE(anim->IsFinishedAt(0.0));
EXPECT_TRUE(anim->IsFinishedAt(1.0));
EXPECT_TRUE(anim->IsFinishedAt(2.0));
}
TEST(AnimationTest, IsFinishedAtInfiniteIterations) {
scoped_ptr<Animation> anim(CreateAnimation(-1));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(0.0));
EXPECT_FALSE(anim->IsFinishedAt(0.5));
EXPECT_FALSE(anim->IsFinishedAt(1.0));
EXPECT_FALSE(anim->IsFinishedAt(1.5));
}
TEST(AnimationTest, IsFinishedAtNotRunning) {
scoped_ptr<Animation> anim(CreateAnimation(0));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_TRUE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::Paused, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::WaitingForNextTick, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::WaitingForTargetAvailability, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::WaitingForStartTime, 0.0);
EXPECT_FALSE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::Finished, 0.0);
EXPECT_TRUE(anim->IsFinishedAt(0.0));
anim->SetRunState(Animation::Aborted, 0.0);
EXPECT_TRUE(anim->IsFinishedAt(0.0));
}
TEST(AnimationTest, IsFinished) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::Paused, 0.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForNextTick, 0.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForTargetAvailability, 0.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForStartTime, 0.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::Finished, 0.0);
EXPECT_TRUE(anim->is_finished());
anim->SetRunState(Animation::Aborted, 0.0);
EXPECT_TRUE(anim->is_finished());
}
TEST(AnimationTest, IsFinishedNeedsSynchronizedStartTime) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 2.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::Paused, 2.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForNextTick, 2.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForTargetAvailability, 2.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::WaitingForStartTime, 2.0);
EXPECT_FALSE(anim->is_finished());
anim->SetRunState(Animation::Finished, 0.0);
EXPECT_TRUE(anim->is_finished());
anim->SetRunState(Animation::Aborted, 0.0);
EXPECT_TRUE(anim->is_finished());
}
TEST(AnimationTest, RunStateChangesIgnoredWhileSuspended) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->Suspend(0);
EXPECT_EQ(Animation::Paused, anim->run_state());
anim->SetRunState(Animation::Running, 0.0);
EXPECT_EQ(Animation::Paused, anim->run_state());
anim->Resume(0);
anim->SetRunState(Animation::Running, 0.0);
EXPECT_EQ(Animation::Running, anim->run_state());
}
} // namespace
} // namespace cc
|