Pass CreateDirectory errors up to IndexedDB.
[chromium-blink-merge.git] / cc / animation / animation_unittest.cc
blob337d3eedb359ac3362d3a85be454791a58fd5aa8
1 // Copyright 2012 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.
5 #include "cc/animation/animation.h"
7 #include "cc/test/animation_test_common.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace cc {
12 namespace {
14 scoped_ptr<Animation> CreateAnimation(int iterations, double duration) {
15 scoped_ptr<Animation> to_return(Animation::Create(
16 make_scoped_ptr(
17 new FakeFloatAnimationCurve(duration)).PassAs<AnimationCurve>(),
20 Animation::Opacity));
21 to_return->set_iterations(iterations);
22 return to_return.Pass();
25 scoped_ptr<Animation> CreateAnimation(int iterations) {
26 return CreateAnimation(iterations, 1);
29 TEST(AnimationTest, TrimTimeZeroIterations) {
30 scoped_ptr<Animation> anim(CreateAnimation(0));
31 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
32 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
33 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
36 TEST(AnimationTest, TrimTimeOneIteration) {
37 scoped_ptr<Animation> anim(CreateAnimation(1));
38 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
39 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
40 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
41 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(2.0));
44 TEST(AnimationTest, TrimTimeInfiniteIterations) {
45 scoped_ptr<Animation> anim(CreateAnimation(-1));
46 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
47 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
48 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
49 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5));
52 TEST(AnimationTest, TrimTimeAlternating) {
53 scoped_ptr<Animation> anim(CreateAnimation(-1));
54 anim->set_alternates_direction(true);
55 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
56 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
57 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
58 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
61 TEST(AnimationTest, TrimTimeStartTime) {
62 scoped_ptr<Animation> anim(CreateAnimation(1));
63 anim->set_start_time(4);
64 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
65 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
66 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
67 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
68 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
71 TEST(AnimationTest, TrimTimeTimeOffset) {
72 scoped_ptr<Animation> anim(CreateAnimation(1));
73 anim->set_time_offset(4);
74 anim->set_start_time(4);
75 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
76 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
77 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
78 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
81 TEST(AnimationTest, TrimTimePauseResume) {
82 scoped_ptr<Animation> anim(CreateAnimation(1));
83 anim->SetRunState(Animation::Running, 0.0);
84 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
85 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
86 anim->SetRunState(Animation::Paused, 0.5);
87 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
88 anim->SetRunState(Animation::Running, 1024.0);
89 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
90 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
93 TEST(AnimationTest, TrimTimeSuspendResume) {
94 scoped_ptr<Animation> anim(CreateAnimation(1));
95 anim->SetRunState(Animation::Running, 0.0);
96 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
97 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
98 anim->Suspend(0.5);
99 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
100 anim->Resume(1024);
101 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
102 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
105 TEST(AnimationTest, TrimTimeZeroDuration) {
106 scoped_ptr<Animation> anim(CreateAnimation(0, 0));
107 anim->SetRunState(Animation::Running, 0.0);
108 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
109 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
110 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
113 TEST(AnimationTest, IsFinishedAtZeroIterations) {
114 scoped_ptr<Animation> anim(CreateAnimation(0));
115 anim->SetRunState(Animation::Running, 0.0);
116 EXPECT_FALSE(anim->IsFinishedAt(-1.0));
117 EXPECT_TRUE(anim->IsFinishedAt(0.0));
118 EXPECT_TRUE(anim->IsFinishedAt(1.0));
121 TEST(AnimationTest, IsFinishedAtOneIteration) {
122 scoped_ptr<Animation> anim(CreateAnimation(1));
123 anim->SetRunState(Animation::Running, 0.0);
124 EXPECT_FALSE(anim->IsFinishedAt(-1.0));
125 EXPECT_FALSE(anim->IsFinishedAt(0.0));
126 EXPECT_TRUE(anim->IsFinishedAt(1.0));
127 EXPECT_TRUE(anim->IsFinishedAt(2.0));
130 TEST(AnimationTest, IsFinishedAtInfiniteIterations) {
131 scoped_ptr<Animation> anim(CreateAnimation(-1));
132 anim->SetRunState(Animation::Running, 0.0);
133 EXPECT_FALSE(anim->IsFinishedAt(0.0));
134 EXPECT_FALSE(anim->IsFinishedAt(0.5));
135 EXPECT_FALSE(anim->IsFinishedAt(1.0));
136 EXPECT_FALSE(anim->IsFinishedAt(1.5));
139 TEST(AnimationTest, IsFinishedAtNotRunning) {
140 scoped_ptr<Animation> anim(CreateAnimation(0));
141 anim->SetRunState(Animation::Running, 0.0);
142 EXPECT_TRUE(anim->IsFinishedAt(0.0));
143 anim->SetRunState(Animation::Paused, 0.0);
144 EXPECT_FALSE(anim->IsFinishedAt(0.0));
145 anim->SetRunState(Animation::WaitingForNextTick, 0.0);
146 EXPECT_FALSE(anim->IsFinishedAt(0.0));
147 anim->SetRunState(Animation::WaitingForTargetAvailability, 0.0);
148 EXPECT_FALSE(anim->IsFinishedAt(0.0));
149 anim->SetRunState(Animation::WaitingForStartTime, 0.0);
150 EXPECT_FALSE(anim->IsFinishedAt(0.0));
151 anim->SetRunState(Animation::Finished, 0.0);
152 EXPECT_TRUE(anim->IsFinishedAt(0.0));
153 anim->SetRunState(Animation::Aborted, 0.0);
154 EXPECT_TRUE(anim->IsFinishedAt(0.0));
157 TEST(AnimationTest, IsFinished) {
158 scoped_ptr<Animation> anim(CreateAnimation(1));
159 anim->SetRunState(Animation::Running, 0.0);
160 EXPECT_FALSE(anim->is_finished());
161 anim->SetRunState(Animation::Paused, 0.0);
162 EXPECT_FALSE(anim->is_finished());
163 anim->SetRunState(Animation::WaitingForNextTick, 0.0);
164 EXPECT_FALSE(anim->is_finished());
165 anim->SetRunState(Animation::WaitingForTargetAvailability, 0.0);
166 EXPECT_FALSE(anim->is_finished());
167 anim->SetRunState(Animation::WaitingForStartTime, 0.0);
168 EXPECT_FALSE(anim->is_finished());
169 anim->SetRunState(Animation::Finished, 0.0);
170 EXPECT_TRUE(anim->is_finished());
171 anim->SetRunState(Animation::Aborted, 0.0);
172 EXPECT_TRUE(anim->is_finished());
175 TEST(AnimationTest, IsFinishedNeedsSynchronizedStartTime) {
176 scoped_ptr<Animation> anim(CreateAnimation(1));
177 anim->SetRunState(Animation::Running, 2.0);
178 EXPECT_FALSE(anim->is_finished());
179 anim->SetRunState(Animation::Paused, 2.0);
180 EXPECT_FALSE(anim->is_finished());
181 anim->SetRunState(Animation::WaitingForNextTick, 2.0);
182 EXPECT_FALSE(anim->is_finished());
183 anim->SetRunState(Animation::WaitingForTargetAvailability, 2.0);
184 EXPECT_FALSE(anim->is_finished());
185 anim->SetRunState(Animation::WaitingForStartTime, 2.0);
186 EXPECT_FALSE(anim->is_finished());
187 anim->SetRunState(Animation::Finished, 0.0);
188 EXPECT_TRUE(anim->is_finished());
189 anim->SetRunState(Animation::Aborted, 0.0);
190 EXPECT_TRUE(anim->is_finished());
193 TEST(AnimationTest, RunStateChangesIgnoredWhileSuspended) {
194 scoped_ptr<Animation> anim(CreateAnimation(1));
195 anim->Suspend(0);
196 EXPECT_EQ(Animation::Paused, anim->run_state());
197 anim->SetRunState(Animation::Running, 0.0);
198 EXPECT_EQ(Animation::Paused, anim->run_state());
199 anim->Resume(0);
200 anim->SetRunState(Animation::Running, 0.0);
201 EXPECT_EQ(Animation::Running, anim->run_state());
204 } // namespace
205 } // namespace cc