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

Side by Side Diff: ash/test/test_session_state_animator.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « ash/test/test_session_state_animator.h ('k') | ash/test/test_session_state_delegate.cc » ('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 2014 The Chromium Authors. All rights reserved. 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 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 "ash/test/test_session_state_animator.h" 5 #include "ash/test/test_session_state_animator.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 10
11 namespace ash { 11 namespace ash {
12 namespace test { 12 namespace test {
13 13
14 namespace { 14 namespace {
15 // A no-op callback that can be used when managing an animation that didn't 15 // A no-op callback that can be used when managing an animation that didn't
16 // actually have a callback given. 16 // actually have a callback given.
17 void DummyCallback() {} 17 void DummyCallback() {}
18 } 18 }
19 19
20 const SessionStateAnimator::Container 20 const SessionStateAnimator::Container
21 TestSessionStateAnimator::kAllContainers[] = { 21 TestSessionStateAnimator::kAllContainers[] = {
22 SessionStateAnimator::DESKTOP_BACKGROUND, 22 SessionStateAnimator::DESKTOP_BACKGROUND,
23 SessionStateAnimator::LAUNCHER, 23 SessionStateAnimator::LAUNCHER,
24 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 24 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
25 SessionStateAnimator::LOCK_SCREEN_BACKGROUND, 25 SessionStateAnimator::LOCK_SCREEN_BACKGROUND,
26 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 26 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
27 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS, 27 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS,
28 SessionStateAnimator::ROOT_CONTAINER 28 SessionStateAnimator::ROOT_CONTAINER};
29 };
30 29
31 // A simple SessionStateAnimator::AnimationSequence that tracks the number of 30 // A simple SessionStateAnimator::AnimationSequence that tracks the number of
32 // attached sequences. The callback will be invoked if all animations complete 31 // attached sequences. The callback will be invoked if all animations complete
33 // successfully. 32 // successfully.
34 class TestSessionStateAnimator::AnimationSequence 33 class TestSessionStateAnimator::AnimationSequence
35 : public SessionStateAnimator::AnimationSequence { 34 : public SessionStateAnimator::AnimationSequence {
36 public: 35 public:
37 AnimationSequence(base::Closure callback, TestSessionStateAnimator* animator) 36 AnimationSequence(base::Closure callback, TestSessionStateAnimator* animator)
38 : SessionStateAnimator::AnimationSequence(callback), 37 : SessionStateAnimator::AnimationSequence(callback),
39 sequence_count_(0), 38 sequence_count_(0),
40 sequence_aborted_(false), 39 sequence_aborted_(false),
41 animator_(animator) { 40 animator_(animator) {}
42 }
43 41
44 ~AnimationSequence() override {} 42 ~AnimationSequence() override {}
45 43
46 virtual void SequenceAttached() { 44 virtual void SequenceAttached() { ++sequence_count_; }
47 ++sequence_count_;
48 }
49 45
50 // Notify the sequence that is has completed. 46 // Notify the sequence that is has completed.
51 virtual void SequenceFinished(bool successfully) { 47 virtual void SequenceFinished(bool successfully) {
52 DCHECK_GT(sequence_count_, 0); 48 DCHECK_GT(sequence_count_, 0);
53 --sequence_count_; 49 --sequence_count_;
54 sequence_aborted_ |= !successfully; 50 sequence_aborted_ |= !successfully;
55 if (sequence_count_ == 0) { 51 if (sequence_count_ == 0) {
56 if (sequence_aborted_) 52 if (sequence_aborted_)
57 OnAnimationAborted(); 53 OnAnimationAborted();
58 else 54 else
(...skipping 28 matching lines...) Expand all
87 AnimationType type, 83 AnimationType type,
88 AnimationSpeed speed, 84 AnimationSpeed speed,
89 base::Closure success_callback, 85 base::Closure success_callback,
90 base::Closure failed_callback) 86 base::Closure failed_callback)
91 : animation_epoch(animation_epoch), 87 : animation_epoch(animation_epoch),
92 remaining_duration(duration), 88 remaining_duration(duration),
93 container(container), 89 container(container),
94 type(type), 90 type(type),
95 speed(speed), 91 speed(speed),
96 success_callback(success_callback), 92 success_callback(success_callback),
97 failed_callback(failed_callback) { 93 failed_callback(failed_callback) {}
98 }
99 94
100 TestSessionStateAnimator::ActiveAnimation::ActiveAnimation( 95 TestSessionStateAnimator::ActiveAnimation::ActiveAnimation(
101 const ActiveAnimation& other) = default; 96 const ActiveAnimation& other) = default;
102 97
103 TestSessionStateAnimator::ActiveAnimation::~ActiveAnimation() { 98 TestSessionStateAnimator::ActiveAnimation::~ActiveAnimation() {}
104 }
105 99
106 TestSessionStateAnimator::TestSessionStateAnimator() 100 TestSessionStateAnimator::TestSessionStateAnimator()
107 : last_animation_epoch_(0), 101 : last_animation_epoch_(0), is_background_hidden_(false) {}
108 is_background_hidden_(false) {
109 }
110 102
111 TestSessionStateAnimator::~TestSessionStateAnimator() { 103 TestSessionStateAnimator::~TestSessionStateAnimator() {
112 CompleteAllAnimations(false); 104 CompleteAllAnimations(false);
113 } 105 }
114 106
115 void TestSessionStateAnimator::ResetAnimationEpoch() { 107 void TestSessionStateAnimator::ResetAnimationEpoch() {
116 CompleteAllAnimations(false); 108 CompleteAllAnimations(false);
117 last_animation_epoch_ = 0; 109 last_animation_epoch_ = 0;
118 } 110 }
119 111
120 void TestSessionStateAnimator::Advance(const base::TimeDelta& duration) { 112 void TestSessionStateAnimator::Advance(const base::TimeDelta& duration) {
121 for (ActiveAnimationsMap::iterator container_iter = 113 for (ActiveAnimationsMap::iterator container_iter =
122 active_animations_.begin(); 114 active_animations_.begin();
123 container_iter != active_animations_.end(); 115 container_iter != active_animations_.end(); ++container_iter) {
124 ++container_iter) {
125 AnimationList::iterator animation_iter = (*container_iter).second.begin(); 116 AnimationList::iterator animation_iter = (*container_iter).second.begin();
126 while (animation_iter != (*container_iter).second.end()) { 117 while (animation_iter != (*container_iter).second.end()) {
127 ActiveAnimation& active_animation = *animation_iter; 118 ActiveAnimation& active_animation = *animation_iter;
128 active_animation.remaining_duration -= duration; 119 active_animation.remaining_duration -= duration;
129 if (active_animation.remaining_duration <= base::TimeDelta()) { 120 if (active_animation.remaining_duration <= base::TimeDelta()) {
130 active_animation.success_callback.Run(); 121 active_animation.success_callback.Run();
131 animation_iter = (*container_iter).second.erase(animation_iter); 122 animation_iter = (*container_iter).second.erase(animation_iter);
132 } else { 123 } else {
133 ++animation_iter; 124 ++animation_iter;
134 } 125 }
135 } 126 }
136 } 127 }
137 } 128 }
138 129
139 void TestSessionStateAnimator::CompleteAnimations(int animation_epoch, 130 void TestSessionStateAnimator::CompleteAnimations(int animation_epoch,
140 bool completed_successfully) { 131 bool completed_successfully) {
141 for (ActiveAnimationsMap::iterator container_iter = 132 for (ActiveAnimationsMap::iterator container_iter =
142 active_animations_.begin(); 133 active_animations_.begin();
143 container_iter != active_animations_.end(); 134 container_iter != active_animations_.end(); ++container_iter) {
144 ++container_iter) {
145 AnimationList::iterator animation_iter = (*container_iter).second.begin(); 135 AnimationList::iterator animation_iter = (*container_iter).second.begin();
146 while (animation_iter != (*container_iter).second.end()) { 136 while (animation_iter != (*container_iter).second.end()) {
147 ActiveAnimation active_animation = *animation_iter; 137 ActiveAnimation active_animation = *animation_iter;
148 if (active_animation.animation_epoch <= animation_epoch) { 138 if (active_animation.animation_epoch <= animation_epoch) {
149 if (completed_successfully) 139 if (completed_successfully)
150 active_animation.success_callback.Run(); 140 active_animation.success_callback.Run();
151 else 141 else
152 active_animation.failed_callback.Run(); 142 active_animation.failed_callback.Run();
153 animation_iter = (*container_iter).second.erase(animation_iter); 143 animation_iter = (*container_iter).second.erase(animation_iter);
154 } else { 144 } else {
155 ++animation_iter; 145 ++animation_iter;
156 } 146 }
157 } 147 }
158 } 148 }
159 } 149 }
160 150
161 void TestSessionStateAnimator::CompleteAllAnimations( 151 void TestSessionStateAnimator::CompleteAllAnimations(
162 bool completed_successfully) { 152 bool completed_successfully) {
163 CompleteAnimations(last_animation_epoch_, completed_successfully); 153 CompleteAnimations(last_animation_epoch_, completed_successfully);
164 } 154 }
165 155
166 bool TestSessionStateAnimator::IsContainerAnimated( 156 bool TestSessionStateAnimator::IsContainerAnimated(
167 SessionStateAnimator::Container container, 157 SessionStateAnimator::Container container,
168 SessionStateAnimator::AnimationType type) const { 158 SessionStateAnimator::AnimationType type) const {
169 ActiveAnimationsMap::const_iterator container_iter = 159 ActiveAnimationsMap::const_iterator container_iter =
170 active_animations_.find(container); 160 active_animations_.find(container);
171 if (container_iter != active_animations_.end()) { 161 if (container_iter != active_animations_.end()) {
172 for (AnimationList::const_iterator animation_iter = 162 for (AnimationList::const_iterator animation_iter =
173 (*container_iter).second.begin(); 163 (*container_iter).second.begin();
174 animation_iter != (*container_iter).second.end(); 164 animation_iter != (*container_iter).second.end(); ++animation_iter) {
175 ++animation_iter) {
176 const ActiveAnimation& active_animation = *animation_iter; 165 const ActiveAnimation& active_animation = *animation_iter;
177 if (active_animation.type == type) 166 if (active_animation.type == type)
178 return true; 167 return true;
179 } 168 }
180 } 169 }
181 return false; 170 return false;
182 } 171 }
183 172
184 bool TestSessionStateAnimator::AreContainersAnimated( 173 bool TestSessionStateAnimator::AreContainersAnimated(
185 int container_mask, SessionStateAnimator::AnimationType type) const { 174 int container_mask,
175 SessionStateAnimator::AnimationType type) const {
186 for (size_t i = 0; i < arraysize(kAllContainers); ++i) { 176 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
187 if (container_mask & kAllContainers[i] && 177 if (container_mask & kAllContainers[i] &&
188 !IsContainerAnimated(kAllContainers[i], type)) { 178 !IsContainerAnimated(kAllContainers[i], type)) {
189 return false; 179 return false;
190 } 180 }
191 } 181 }
192 return true; 182 return true;
193 } 183 }
194 184
195 size_t TestSessionStateAnimator::GetAnimationCount() const { 185 size_t TestSessionStateAnimator::GetAnimationCount() const {
196 size_t count = 0; 186 size_t count = 0;
197 for (ActiveAnimationsMap::const_iterator container_iter = 187 for (ActiveAnimationsMap::const_iterator container_iter =
198 active_animations_.begin(); 188 active_animations_.begin();
199 container_iter != active_animations_.end(); 189 container_iter != active_animations_.end(); ++container_iter) {
200 ++container_iter) {
201 count += (*container_iter).second.size(); 190 count += (*container_iter).second.size();
202 } 191 }
203 return count; 192 return count;
204 } 193 }
205 194
206 void TestSessionStateAnimator::StartAnimation(int container_mask, 195 void TestSessionStateAnimator::StartAnimation(int container_mask,
207 AnimationType type, 196 AnimationType type,
208 AnimationSpeed speed) { 197 AnimationSpeed speed) {
209 ++last_animation_epoch_; 198 ++last_animation_epoch_;
210 for (size_t i = 0; i < arraysize(kAllContainers); ++i) { 199 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
(...skipping 14 matching lines...) Expand all
225 ++last_animation_epoch_; 214 ++last_animation_epoch_;
226 for (size_t i = 0; i < arraysize(kAllContainers); ++i) 215 for (size_t i = 0; i < arraysize(kAllContainers); ++i)
227 if (container_mask & kAllContainers[i]) { 216 if (container_mask & kAllContainers[i]) {
228 // ash::SessionStateAnimatorImpl invokes the callback whether or not the 217 // ash::SessionStateAnimatorImpl invokes the callback whether or not the
229 // animation was completed successfully or not. 218 // animation was completed successfully or not.
230 AddAnimation(kAllContainers[i], type, speed, callback, callback); 219 AddAnimation(kAllContainers[i], type, speed, callback, callback);
231 } 220 }
232 } 221 }
233 222
234 ash::SessionStateAnimator::AnimationSequence* 223 ash::SessionStateAnimator::AnimationSequence*
235 TestSessionStateAnimator::BeginAnimationSequence(base::Closure callback) { 224 TestSessionStateAnimator::BeginAnimationSequence(base::Closure callback) {
236 return new AnimationSequence(callback, this); 225 return new AnimationSequence(callback, this);
237 } 226 }
238 227
239 bool TestSessionStateAnimator::IsBackgroundHidden() const { 228 bool TestSessionStateAnimator::IsBackgroundHidden() const {
240 return is_background_hidden_; 229 return is_background_hidden_;
241 } 230 }
242 231
243 void TestSessionStateAnimator::ShowBackground() { 232 void TestSessionStateAnimator::ShowBackground() {
244 is_background_hidden_ = false; 233 is_background_hidden_ = false;
245 } 234 }
(...skipping 11 matching lines...) Expand all
257 for (size_t i = 0; i < arraysize(kAllContainers); ++i) { 246 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
258 if (container_mask & kAllContainers[i]) { 247 if (container_mask & kAllContainers[i]) {
259 base::Closure success_callback = 248 base::Closure success_callback =
260 base::Bind(&AnimationSequence::SequenceFinished, 249 base::Bind(&AnimationSequence::SequenceFinished,
261 base::Unretained(animation_sequence), true); 250 base::Unretained(animation_sequence), true);
262 base::Closure failed_callback = 251 base::Closure failed_callback =
263 base::Bind(&AnimationSequence::SequenceFinished, 252 base::Bind(&AnimationSequence::SequenceFinished,
264 base::Unretained(animation_sequence), false); 253 base::Unretained(animation_sequence), false);
265 animation_sequence->SequenceAttached(); 254 animation_sequence->SequenceAttached();
266 AddAnimation(kAllContainers[i], type, speed, success_callback, 255 AddAnimation(kAllContainers[i], type, speed, success_callback,
267 failed_callback); 256 failed_callback);
268 } 257 }
269 } 258 }
270 } 259 }
271 260
272 void TestSessionStateAnimator::AddAnimation( 261 void TestSessionStateAnimator::AddAnimation(
273 SessionStateAnimator::Container container, 262 SessionStateAnimator::Container container,
274 AnimationType type, 263 AnimationType type,
275 AnimationSpeed speed, 264 AnimationSpeed speed,
276 base::Closure success_callback, 265 base::Closure success_callback,
277 base::Closure failed_callback) { 266 base::Closure failed_callback) {
278 base::TimeDelta duration = GetDuration(speed); 267 base::TimeDelta duration = GetDuration(speed);
279 ActiveAnimation active_animation(last_animation_epoch_, 268 ActiveAnimation active_animation(last_animation_epoch_, duration, container,
280 duration, 269 type, speed, success_callback,
281 container,
282 type,
283 speed,
284 success_callback,
285 failed_callback); 270 failed_callback);
286 // This test double is limited to only have one animation active for a given 271 // This test double is limited to only have one animation active for a given
287 // container at a time. 272 // container at a time.
288 AbortAnimation(container); 273 AbortAnimation(container);
289 active_animations_[container].push_back(active_animation); 274 active_animations_[container].push_back(active_animation);
290 } 275 }
291 276
292 void TestSessionStateAnimator::AbortAnimation( 277 void TestSessionStateAnimator::AbortAnimation(
293 SessionStateAnimator::Container container) { 278 SessionStateAnimator::Container container) {
294 ActiveAnimationsMap::iterator container_iter = 279 ActiveAnimationsMap::iterator container_iter =
295 active_animations_.find(container); 280 active_animations_.find(container);
296 if (container_iter != active_animations_.end()) { 281 if (container_iter != active_animations_.end()) {
297 AnimationList::iterator animation_iter = (*container_iter).second.begin(); 282 AnimationList::iterator animation_iter = (*container_iter).second.begin();
298 while (animation_iter != (*container_iter).second.end()) { 283 while (animation_iter != (*container_iter).second.end()) {
299 ActiveAnimation active_animation = *animation_iter; 284 ActiveAnimation active_animation = *animation_iter;
300 active_animation.failed_callback.Run(); 285 active_animation.failed_callback.Run();
301 animation_iter = (*container_iter).second.erase(animation_iter); 286 animation_iter = (*container_iter).second.erase(animation_iter);
302 } 287 }
303 } 288 }
304 } 289 }
305 290
306 } // namespace test 291 } // namespace test
307 } // namespace ash 292 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/test_session_state_animator.h ('k') | ash/test/test_session_state_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698