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

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

Issue 180153010: Handle direction control in compositor Animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add myself to src/AUTHORS Created 6 years, 9 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 | « 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, TrimTimeAlternating) { 52 TEST(AnimationTest, TrimTimeReverse) {
53 scoped_ptr<Animation> anim(CreateAnimation(-1)); 53 scoped_ptr<Animation> anim(CreateAnimation(-1));
54 anim->set_alternates_direction(true); 54 anim->set_direction(Animation::Reverse);
55 EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0));
56 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
57 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);
55 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 66 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
67 EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.25));
56 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 68 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
69 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.75));
57 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 70 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
58 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25)); 71 EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
59 } 72 }
60 73
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
61 TEST(AnimationTest, TrimTimeStartTime) { 85 TEST(AnimationTest, TrimTimeStartTime) {
62 scoped_ptr<Animation> anim(CreateAnimation(1)); 86 scoped_ptr<Animation> anim(CreateAnimation(1));
63 anim->set_start_time(4); 87 anim->set_start_time(4);
64 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 88 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
65 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0)); 89 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
66 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5)); 90 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
67 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0)); 91 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
68 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0)); 92 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
69 } 93 }
70 94
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
71 TEST(AnimationTest, TrimTimeTimeOffset) { 106 TEST(AnimationTest, TrimTimeTimeOffset) {
72 scoped_ptr<Animation> anim(CreateAnimation(1)); 107 scoped_ptr<Animation> anim(CreateAnimation(1));
73 anim->set_time_offset(4); 108 anim->set_time_offset(4);
74 anim->set_start_time(4); 109 anim->set_start_time(4);
75 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 110 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
76 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 111 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
77 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 112 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
78 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0)); 113 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
79 } 114 }
80 115
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
81 TEST(AnimationTest, TrimTimeNegativeTimeOffset) { 127 TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
82 scoped_ptr<Animation> anim(CreateAnimation(1)); 128 scoped_ptr<Animation> anim(CreateAnimation(1));
83 anim->set_time_offset(-4); 129 anim->set_time_offset(-4);
84 130
85 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 131 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
86 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0)); 132 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(4.0));
87 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5)); 133 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
88 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0)); 134 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
89 } 135 }
90 136
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
91 TEST(AnimationTest, TrimTimePauseResume) { 148 TEST(AnimationTest, TrimTimePauseResume) {
92 scoped_ptr<Animation> anim(CreateAnimation(1)); 149 scoped_ptr<Animation> anim(CreateAnimation(1));
93 anim->SetRunState(Animation::Running, 0.0); 150 anim->SetRunState(Animation::Running, 0.0);
94 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 151 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
95 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 152 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
96 anim->SetRunState(Animation::Paused, 0.5); 153 anim->SetRunState(Animation::Paused, 0.5);
97 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 154 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
98 anim->SetRunState(Animation::Running, 1024.0); 155 anim->SetRunState(Animation::Running, 1024.0);
99 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 156 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
100 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5)); 157 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
101 } 158 }
102 159
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
103 TEST(AnimationTest, TrimTimeSuspendResume) { 173 TEST(AnimationTest, TrimTimeSuspendResume) {
104 scoped_ptr<Animation> anim(CreateAnimation(1)); 174 scoped_ptr<Animation> anim(CreateAnimation(1));
105 anim->SetRunState(Animation::Running, 0.0); 175 anim->SetRunState(Animation::Running, 0.0);
106 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 176 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
107 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5)); 177 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
108 anim->Suspend(0.5); 178 anim->Suspend(0.5);
109 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 179 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
110 anim->Resume(1024); 180 anim->Resume(1024);
111 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0)); 181 EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1024.0));
112 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5)); 182 EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
113 } 183 }
114 184
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
115 TEST(AnimationTest, TrimTimeZeroDuration) { 198 TEST(AnimationTest, TrimTimeZeroDuration) {
116 scoped_ptr<Animation> anim(CreateAnimation(0, 0)); 199 scoped_ptr<Animation> anim(CreateAnimation(0, 0));
117 anim->SetRunState(Animation::Running, 0.0); 200 anim->SetRunState(Animation::Running, 0.0);
118 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0)); 201 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(-1.0));
119 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0)); 202 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
120 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0)); 203 EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
121 } 204 }
122 205
123 TEST(AnimationTest, TrimTimeStarting) { 206 TEST(AnimationTest, TrimTimeStarting) {
124 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0)); 207 scoped_ptr<Animation> anim(CreateAnimation(1, 5.0));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 EXPECT_EQ(Animation::Paused, anim->run_state()); 337 EXPECT_EQ(Animation::Paused, anim->run_state());
255 anim->SetRunState(Animation::Running, 0.0); 338 anim->SetRunState(Animation::Running, 0.0);
256 EXPECT_EQ(Animation::Paused, anim->run_state()); 339 EXPECT_EQ(Animation::Paused, anim->run_state());
257 anim->Resume(0); 340 anim->Resume(0);
258 anim->SetRunState(Animation::Running, 0.0); 341 anim->SetRunState(Animation::Running, 0.0);
259 EXPECT_EQ(Animation::Running, anim->run_state()); 342 EXPECT_EQ(Animation::Running, anim->run_state());
260 } 343 }
261 344
262 } // namespace 345 } // namespace
263 } // namespace cc 346 } // 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