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

Side by Side Diff: cc/animation/animation_unittest.cc

Issue 220403002: Revert "Handle direction control in compositor Animations" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/animation/animation.cc ('k') | webkit/renderer/compositor_bindings/web_animation_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 "cc/animation/animation.h" 5 #include "cc/animation/animation.h"
6 6
7 #include "cc/test/animation_test_common.h" 7 #include "cc/test/animation_test_common.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 TEST(AnimationTest, TrimTimeInfiniteIterations) { 44 TEST(AnimationTest, TrimTimeInfiniteIterations) {
45 scoped_ptr<Animation> anim(CreateAnimation(-1)); 45 scoped_ptr<Animation> anim(CreateAnimation(-1));
46 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 46 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
47 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 47 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
48 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0)); 48 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
49 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5)); 49 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5));
50 } 50 }
51 51
52 TEST(AnimationTest, TrimTimeReverse) { 52 TEST(AnimationTest, TrimTimeAlternating) {
53 scoped_ptr<Animation> anim(CreateAnimation(-1)); 53 scoped_ptr<Animation> anim(CreateAnimation(-1));
54 anim->set_direction(Animation::Reverse); 54 anim->set_alternates_direction(true);
55 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0)); 55 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
56 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
57 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 56 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
58 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
59 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(1.0));
60 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
61 }
62
63 TEST(AnimationTest, TrimTimeAlternate) {
64 scoped_ptr<Animation> anim(CreateAnimation(-1));
65 anim->set_direction(Animation::Alternate);
66 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
67 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.25));
68 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
69 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.75));
70 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 57 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
71 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25)); 58 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
72 } 59 }
73 60
74 TEST(AnimationTest, TrimTimeAlternateReverse) {
75 scoped_ptr<Animation> anim(CreateAnimation(-1));
76 anim->set_direction(Animation::AlternateReverse);
77 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
78 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
79 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
80 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
81 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
82 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1.25));
83 }
84
85 TEST(AnimationTest, TrimTimeStartTime) { 61 TEST(AnimationTest, TrimTimeStartTime) {
86 scoped_ptr<Animation> anim(CreateAnimation(1)); 62 scoped_ptr<Animation> anim(CreateAnimation(1));
87 anim->set_start_time(4); 63 anim->set_start_time(4);
88 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 64 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
89 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0)); 65 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
90 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5)); 66 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
91 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0)); 67 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
92 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0)); 68 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
93 } 69 }
94 70
95 TEST(AnimationTest, TrimTimeStartTimeReverse) {
96 scoped_ptr<Animation> anim(CreateAnimation(1));
97 anim->set_start_time(4);
98 anim->set_direction(Animation::Reverse);
99 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
100 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
101 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
102 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
103 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(6.0));
104 }
105
106 TEST(AnimationTest, TrimTimeTimeOffset) { 71 TEST(AnimationTest, TrimTimeTimeOffset) {
107 scoped_ptr<Animation> anim(CreateAnimation(1)); 72 scoped_ptr<Animation> anim(CreateAnimation(1));
108 anim->set_time_offset(4); 73 anim->set_time_offset(4);
109 anim->set_start_time(4); 74 anim->set_start_time(4);
110 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 75 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
111 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 76 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
112 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 77 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
113 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 78 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
114 } 79 }
115 80
116 TEST(AnimationTest, TrimTimeTimeOffsetReverse) {
117 scoped_ptr<Animation> anim(CreateAnimation(1));
118 anim->set_time_offset(4);
119 anim->set_start_time(4);
120 anim->set_direction(Animation::Reverse);
121 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
122 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
123 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
124 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
125 }
126
127 TEST(AnimationTest, TrimTimeNegativeTimeOffset) { 81 TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
128 scoped_ptr<Animation> anim(CreateAnimation(1)); 82 scoped_ptr<Animation> anim(CreateAnimation(1));
129 anim->set_time_offset(-4); 83 anim->set_time_offset(-4);
130 84
131 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 85 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
132 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0)); 86 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
133 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5)); 87 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
134 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0)); 88 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
135 } 89 }
136 90
137 TEST(AnimationTest, TrimTimeNegativeTimeOffsetReverse) {
138 scoped_ptr<Animation> anim(CreateAnimation(1));
139 anim->set_time_offset(-4);
140 anim->set_direction(Animation::Reverse);
141
142 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
143 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
144 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
145 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
146 }
147
148 TEST(AnimationTest, TrimTimePauseResume) { 91 TEST(AnimationTest, TrimTimePauseResume) {
149 scoped_ptr<Animation> anim(CreateAnimation(1)); 92 scoped_ptr<Animation> anim(CreateAnimation(1));
150 anim->SetRunState(Animation::Running, 0.0); 93 anim->SetRunState(Animation::Running, 0.0);
151 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 94 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
152 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 95 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
153 anim->SetRunState(Animation::Paused, 0.5); 96 anim->SetRunState(Animation::Paused, 0.5);
154 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 97 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
155 anim->SetRunState(Animation::Running, 1024.0); 98 anim->SetRunState(Animation::Running, 1024.0);
156 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 99 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
157 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5)); 100 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
158 } 101 }
159 102
160 TEST(AnimationTest, TrimTimePauseResumeReverse) {
161 scoped_ptr<Animation> anim(CreateAnimation(1));
162 anim->set_direction(Animation::Reverse);
163 anim->SetRunState(Animation::Running, 0.0);
164 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
165 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
166 anim->SetRunState(Animation::Paused, 0.25);
167 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
168 anim->SetRunState(Animation::Running, 1024.0);
169 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
170 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.75));
171 }
172
173 TEST(AnimationTest, TrimTimeSuspendResume) { 103 TEST(AnimationTest, TrimTimeSuspendResume) {
174 scoped_ptr<Animation> anim(CreateAnimation(1)); 104 scoped_ptr<Animation> anim(CreateAnimation(1));
175 anim->SetRunState(Animation::Running, 0.0); 105 anim->SetRunState(Animation::Running, 0.0);
176 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 106 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
177 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 107 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
178 anim->Suspend(0.5); 108 anim->Suspend(0.5);
179 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 109 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
180 anim->Resume(1024); 110 anim->Resume(1024);
181 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 111 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
182 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5)); 112 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
183 } 113 }
184 114
185 TEST(AnimationTest, TrimTimeSuspendResumeReverse) {
186 scoped_ptr<Animation> anim(CreateAnimation(1));
187 anim->set_direction(Animation::Reverse);
188 anim->SetRunState(Animation::Running, 0.0);
189 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
190 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
191 anim->Suspend(0.75);
192 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
193 anim->Resume(1024);
194 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
195 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.25));
196 }
197
198 TEST(AnimationTest, TrimTimeZeroDuration) { 115 TEST(AnimationTest, TrimTimeZeroDuration) {
199 scoped_ptr<Animation> anim(CreateAnimation(0, 0)); 116 scoped_ptr<Animation> anim(CreateAnimation(0, 0));
200 anim->SetRunState(Animation::Running, 0.0); 117 anim->SetRunState(Animation::Running, 0.0);
201 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0)); 118 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
202 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 119 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
203 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0)); 120 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
204 } 121 }
205 122
206 TEST(AnimationTest, TrimTimeStarting) { 123 TEST(AnimationTest, TrimTimeStarting) {
207 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0)); 124 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 EXPECT_EQ(Animation::Paused, anim->run_state()); 254 EXPECT_EQ(Animation::Paused, anim->run_state());
338 anim->SetRunState(Animation::Running, 0.0); 255 anim->SetRunState(Animation::Running, 0.0);
339 EXPECT_EQ(Animation::Paused, anim->run_state()); 256 EXPECT_EQ(Animation::Paused, anim->run_state());
340 anim->Resume(0); 257 anim->Resume(0);
341 anim->SetRunState(Animation::Running, 0.0); 258 anim->SetRunState(Animation::Running, 0.0);
342 EXPECT_EQ(Animation::Running, anim->run_state()); 259 EXPECT_EQ(Animation::Running, anim->run_state());
343 } 260 }
344 261
345 } // namespace 262 } // namespace
346 } // namespace cc 263 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation.cc ('k') | webkit/renderer/compositor_bindings/web_animation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698