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

Side by Side Diff: ash/wm/power_button_controller_unittest.cc

Issue 10914016: ash: Extract animator from PowerButtonController (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: restore ASH_EXPORT Created 8 years, 2 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/wm/power_button_controller.cc ('k') | ash/wm/session_state_animator.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ash/wm/power_button_controller.h" 5 #include "ash/wm/power_button_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/cursor_manager.h" 9 #include "ash/wm/cursor_manager.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { 84 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
85 controller_->set_has_legacy_power_button_for_test(true); 85 controller_->set_has_legacy_power_button_for_test(true);
86 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 86 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
87 controller_->OnLockStateChanged(false); 87 controller_->OnLockStateChanged(false);
88 88
89 // We should request that the screen be locked immediately after seeing the 89 // We should request that the screen be locked immediately after seeing the
90 // power button get pressed. 90 // power button get pressed.
91 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 91 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
92 EXPECT_TRUE( 92 EXPECT_TRUE(
93 test_api_->ContainersAreAnimated( 93 test_api_->ContainersAreAnimated(
94 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 94 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
95 PowerButtonController::ANIMATION_SLOW_CLOSE)); 95 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
96 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 96 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
97 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); 97 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running());
98 EXPECT_FALSE(test_api_->lock_timer_is_running()); 98 EXPECT_FALSE(test_api_->lock_timer_is_running());
99 EXPECT_EQ(1, delegate_->num_lock_requests()); 99 EXPECT_EQ(1, delegate_->num_lock_requests());
100 100
101 // Notify that we locked successfully. 101 // Notify that we locked successfully.
102 controller_->OnStartingLock(); 102 controller_->OnStartingLock();
103 EXPECT_TRUE( 103 EXPECT_TRUE(
104 test_api_->ContainersAreAnimated( 104 test_api_->ContainersAreAnimated(
105 PowerButtonController::LAUNCHER, 105 internal::SessionStateAnimator::LAUNCHER,
106 PowerButtonController::ANIMATION_HIDE)); 106 internal::SessionStateAnimator::ANIMATION_HIDE));
107 EXPECT_TRUE( 107 EXPECT_TRUE(
108 test_api_->ContainersAreAnimated( 108 test_api_->ContainersAreAnimated(
109 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 109 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
110 PowerButtonController::ANIMATION_FAST_CLOSE)); 110 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
111 EXPECT_TRUE( 111 EXPECT_TRUE(
112 test_api_->ContainersAreAnimated( 112 test_api_->ContainersAreAnimated(
113 PowerButtonController::LOCK_SCREEN_CONTAINERS, 113 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
114 PowerButtonController::ANIMATION_HIDE)); 114 internal::SessionStateAnimator::ANIMATION_HIDE));
115 115
116 // Notify that the lock window is visible. We should make it fade in. 116 // Notify that the lock window is visible. We should make it fade in.
117 controller_->OnLockStateChanged(true); 117 controller_->OnLockStateChanged(true);
118 EXPECT_TRUE( 118 EXPECT_TRUE(
119 test_api_->ContainersAreAnimated( 119 test_api_->ContainersAreAnimated(
120 PowerButtonController::GetAllLockScreenContainersMask(), 120 internal::SessionStateAnimator::kAllLockScreenContainersMask,
121 PowerButtonController::ANIMATION_FADE_IN)); 121 internal::SessionStateAnimator::ANIMATION_FADE_IN));
122 122
123 // We shouldn't progress towards the shutdown state, however. 123 // We shouldn't progress towards the shutdown state, however.
124 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 124 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
125 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 125 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
126 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 126 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
127 127
128 // Hold the button again and check that we start shutting down. 128 // Hold the button again and check that we start shutting down.
129 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 129 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
130 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 130 EXPECT_EQ(0, delegate_->num_shutdown_requests());
131 131
132 // Previously we're checking that the all containers group was animated which 132 // Previously we're checking that the all containers group was animated which
133 // was in fact checking that 133 // was in fact checking that
134 // 1. All user session containers have transform (including wallpaper). 134 // 1. All user session containers have transform (including wallpaper).
135 // They're in this state after lock. 135 // They're in this state after lock.
136 // 2. Screen locker and related containers are in fact animating 136 // 2. Screen locker and related containers are in fact animating
137 // (as shutdown is in progress). 137 // (as shutdown is in progress).
138 // With http://crbug.com/144737 we no longer animate user session wallpaper 138 // With http://crbug.com/144737 we no longer animate user session wallpaper
139 // during lock so it makes sense only to check that screen lock and related 139 // during lock so it makes sense only to check that screen lock and related
140 // containers are animated during shutdown. 140 // containers are animated during shutdown.
141 EXPECT_TRUE( 141 EXPECT_TRUE(
142 test_api_->ContainersAreAnimated( 142 test_api_->ContainersAreAnimated(
143 PowerButtonController::GetAllLockScreenContainersMask(), 143 internal::SessionStateAnimator::kAllLockScreenContainersMask,
144 PowerButtonController::ANIMATION_FAST_CLOSE)); 144 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
145 // Make sure a mouse move event won't show the cursor. 145 // Make sure a mouse move event won't show the cursor.
146 GenerateMouseMoveEvent(); 146 GenerateMouseMoveEvent();
147 EXPECT_FALSE(cursor_visible()); 147 EXPECT_FALSE(cursor_visible());
148 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 148 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
149 test_api_->trigger_real_shutdown_timeout(); 149 test_api_->trigger_real_shutdown_timeout();
150 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 150 EXPECT_EQ(1, delegate_->num_shutdown_requests());
151 } 151 }
152 152
153 // Test that we start shutting down immediately if the power button is pressed 153 // Test that we start shutting down immediately if the power button is pressed
154 // while we're not logged in on an unofficial system. 154 // while we're not logged in on an unofficial system.
(...skipping 22 matching lines...) Expand all
177 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 177 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
178 controller_->OnLockStateChanged(false); 178 controller_->OnLockStateChanged(false);
179 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 179 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
180 180
181 // Press the power button and check that we start the shutdown timer. 181 // Press the power button and check that we start the shutdown timer.
182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
183 EXPECT_FALSE(test_api_->lock_timer_is_running()); 183 EXPECT_FALSE(test_api_->lock_timer_is_running());
184 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 184 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
185 EXPECT_TRUE( 185 EXPECT_TRUE(
186 test_api_->ContainersAreAnimated( 186 test_api_->ContainersAreAnimated(
187 PowerButtonController::GetAllContainersMask(), 187 internal::SessionStateAnimator::kAllContainersMask,
188 PowerButtonController::ANIMATION_SLOW_CLOSE)); 188 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
189 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 189 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
190 190
191 // Release the power button before the shutdown timer fires. 191 // Release the power button before the shutdown timer fires.
192 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 192 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
193 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 193 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
194 EXPECT_TRUE( 194 EXPECT_TRUE(
195 test_api_->ContainersAreAnimated( 195 test_api_->ContainersAreAnimated(
196 PowerButtonController::GetAllContainersMask(), 196 internal::SessionStateAnimator::kAllContainersMask,
197 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); 197 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
198 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 198 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
199 199
200 // We should re-hide the black layer after waiting long enough for 200 // We should re-hide the black layer after waiting long enough for
201 // the animation to finish. 201 // the animation to finish.
202 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 202 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running());
203 test_api_->trigger_hide_black_layer_timeout(); 203 test_api_->TriggerHideBlackLayerTimeout();
204 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 204 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
205 205
206 // Press the button again and make the shutdown timeout fire this time. 206 // Press the button again and make the shutdown timeout fire this time.
207 // Check that we start the timer for actually requesting the shutdown. 207 // Check that we start the timer for actually requesting the shutdown.
208 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 208 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
209 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 209 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
210 test_api_->trigger_shutdown_timeout(); 210 test_api_->trigger_shutdown_timeout();
211 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 211 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
212 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 212 EXPECT_EQ(0, delegate_->num_shutdown_requests());
213 EXPECT_TRUE( 213 EXPECT_TRUE(
214 test_api_->ContainersAreAnimated( 214 test_api_->ContainersAreAnimated(
215 PowerButtonController::LAUNCHER | 215 internal::SessionStateAnimator::LAUNCHER |
216 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 216 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
217 PowerButtonController::ANIMATION_HIDE)); 217 internal::SessionStateAnimator::ANIMATION_HIDE));
218 EXPECT_TRUE( 218 EXPECT_TRUE(
219 test_api_->ContainersAreAnimated( 219 test_api_->ContainersAreAnimated(
220 PowerButtonController::GetAllLockScreenContainersMask(), 220 internal::SessionStateAnimator::kAllLockScreenContainersMask,
221 PowerButtonController::ANIMATION_FAST_CLOSE)); 221 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
222 222
223 // When the timout fires, we should request a shutdown. 223 // When the timout fires, we should request a shutdown.
224 test_api_->trigger_real_shutdown_timeout(); 224 test_api_->trigger_real_shutdown_timeout();
225 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 225 EXPECT_EQ(1, delegate_->num_shutdown_requests());
226 } 226 }
227 227
228 // Test that we lock the screen and deal with unlocking correctly. 228 // Test that we lock the screen and deal with unlocking correctly.
229 TEST_F(PowerButtonControllerTest, LockAndUnlock) { 229 TEST_F(PowerButtonControllerTest, LockAndUnlock) {
230 controller_->set_has_legacy_power_button_for_test(false); 230 controller_->set_has_legacy_power_button_for_test(false);
231 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 231 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
232 controller_->OnLockStateChanged(false); 232 controller_->OnLockStateChanged(false);
233 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 233 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
234 234
235 // We should initially be showing the screen locker containers, since they 235 // We should initially be showing the screen locker containers, since they
236 // also contain login-related windows that we want to show during the 236 // also contain login-related windows that we want to show during the
237 // logging-in animation. 237 // logging-in animation.
238 EXPECT_TRUE( 238 EXPECT_TRUE(
239 test_api_->ContainersAreAnimated( 239 test_api_->ContainersAreAnimated(
240 PowerButtonController::LOCK_SCREEN_CONTAINERS, 240 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
241 PowerButtonController::ANIMATION_RESTORE)); 241 internal::SessionStateAnimator::ANIMATION_RESTORE));
242 242
243 // Press the power button and check that the lock timer is started and that we 243 // Press the power button and check that the lock timer is started and that we
244 // start scaling the non-screen-locker containers. 244 // start scaling the non-screen-locker containers.
245 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 245 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
246 EXPECT_TRUE(test_api_->lock_timer_is_running()); 246 EXPECT_TRUE(test_api_->lock_timer_is_running());
247 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 247 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
248 EXPECT_TRUE( 248 EXPECT_TRUE(
249 test_api_->ContainersAreAnimated( 249 test_api_->ContainersAreAnimated(
250 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 250 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
251 PowerButtonController::ANIMATION_SLOW_CLOSE)); 251 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
252 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 252 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
253 253
254 // Release the button before the lock timer fires. 254 // Release the button before the lock timer fires.
255 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 255 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
256 EXPECT_FALSE(test_api_->lock_timer_is_running()); 256 EXPECT_FALSE(test_api_->lock_timer_is_running());
257 EXPECT_TRUE( 257 EXPECT_TRUE(
258 test_api_->ContainersAreAnimated( 258 test_api_->ContainersAreAnimated(
259 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 259 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
260 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); 260 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
261 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 261 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
262 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 262 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running());
263 test_api_->trigger_hide_black_layer_timeout(); 263 test_api_->TriggerHideBlackLayerTimeout();
264 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 264 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
265 265
266 // Press the button and fire the lock timer. We should request that the 266 // Press the button and fire the lock timer. We should request that the
267 // screen be locked, but we should still be in the slow-close animation. 267 // screen be locked, but we should still be in the slow-close animation.
268 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 268 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
269 EXPECT_TRUE(test_api_->lock_timer_is_running()); 269 EXPECT_TRUE(test_api_->lock_timer_is_running());
270 EXPECT_EQ(0, delegate_->num_lock_requests()); 270 EXPECT_EQ(0, delegate_->num_lock_requests());
271 test_api_->trigger_lock_timeout(); 271 test_api_->trigger_lock_timeout();
272 EXPECT_EQ(1, delegate_->num_lock_requests()); 272 EXPECT_EQ(1, delegate_->num_lock_requests());
273 EXPECT_TRUE( 273 EXPECT_TRUE(
274 test_api_->ContainersAreAnimated( 274 test_api_->ContainersAreAnimated(
275 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 275 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
276 PowerButtonController::ANIMATION_SLOW_CLOSE)); 276 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
277 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 277 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
278 278
279 // Notify that we locked successfully. 279 // Notify that we locked successfully.
280 controller_->OnStartingLock(); 280 controller_->OnStartingLock();
281 EXPECT_TRUE( 281 EXPECT_TRUE(
282 test_api_->ContainersAreAnimated( 282 test_api_->ContainersAreAnimated(
283 PowerButtonController::LAUNCHER, 283 internal::SessionStateAnimator::LAUNCHER,
284 PowerButtonController::ANIMATION_HIDE)); 284 internal::SessionStateAnimator::ANIMATION_HIDE));
285 EXPECT_TRUE( 285 EXPECT_TRUE(
286 test_api_->ContainersAreAnimated( 286 test_api_->ContainersAreAnimated(
287 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 287 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
288 PowerButtonController::ANIMATION_FAST_CLOSE)); 288 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
289 EXPECT_TRUE( 289 EXPECT_TRUE(
290 test_api_->ContainersAreAnimated( 290 test_api_->ContainersAreAnimated(
291 PowerButtonController::LOCK_SCREEN_CONTAINERS, 291 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
292 PowerButtonController::ANIMATION_HIDE)); 292 internal::SessionStateAnimator::ANIMATION_HIDE));
293 293
294 // Notify that the lock window is visible. We should make it fade in. 294 // Notify that the lock window is visible. We should make it fade in.
295 controller_->OnLockStateChanged(true); 295 controller_->OnLockStateChanged(true);
296 EXPECT_TRUE( 296 EXPECT_TRUE(
297 test_api_->ContainersAreAnimated( 297 test_api_->ContainersAreAnimated(
298 PowerButtonController::GetAllLockScreenContainersMask(), 298 internal::SessionStateAnimator::kAllLockScreenContainersMask,
299 PowerButtonController::ANIMATION_FADE_IN)); 299 internal::SessionStateAnimator::ANIMATION_FADE_IN));
300 300
301 // When we release the power button, the lock-to-shutdown timer should be 301 // When we release the power button, the lock-to-shutdown timer should be
302 // stopped. 302 // stopped.
303 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 303 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
304 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 304 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
305 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 305 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
306 306
307 // Notify that the screen has been unlocked. We should show the 307 // Notify that the screen has been unlocked. We should show the
308 // non-screen-locker windows and hide the black layer. 308 // non-screen-locker windows and hide the black layer.
309 controller_->OnLockStateChanged(false); 309 controller_->OnLockStateChanged(false);
310 EXPECT_TRUE( 310 EXPECT_TRUE(
311 test_api_->ContainersAreAnimated( 311 test_api_->ContainersAreAnimated(
312 PowerButtonController::DESKTOP_BACKGROUND | 312 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
313 PowerButtonController::LAUNCHER | 313 internal::SessionStateAnimator::LAUNCHER |
314 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 314 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
315 PowerButtonController::ANIMATION_RESTORE)); 315 internal::SessionStateAnimator::ANIMATION_RESTORE));
316 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 316 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
317 } 317 }
318 318
319 // Hold the power button down from the unlocked state to eventual shutdown. 319 // Hold the power button down from the unlocked state to eventual shutdown.
320 TEST_F(PowerButtonControllerTest, LockToShutdown) { 320 TEST_F(PowerButtonControllerTest, LockToShutdown) {
321 controller_->set_has_legacy_power_button_for_test(false); 321 controller_->set_has_legacy_power_button_for_test(false);
322 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 322 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
323 controller_->OnLockStateChanged(false); 323 controller_->OnLockStateChanged(false);
324 324
325 // Hold the power button and lock the screen. 325 // Hold the power button and lock the screen.
326 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 326 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
327 EXPECT_TRUE(test_api_->lock_timer_is_running()); 327 EXPECT_TRUE(test_api_->lock_timer_is_running());
328 test_api_->trigger_lock_timeout(); 328 test_api_->trigger_lock_timeout();
329 controller_->OnStartingLock(); 329 controller_->OnStartingLock();
330 controller_->OnLockStateChanged(true); 330 controller_->OnLockStateChanged(true);
331 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 331 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
332 332
333 // When the lock-to-shutdown timeout fires, we should start the shutdown 333 // When the lock-to-shutdown timeout fires, we should start the shutdown
334 // timer. 334 // timer.
335 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 335 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
336 test_api_->trigger_lock_to_shutdown_timeout(); 336 test_api_->trigger_lock_to_shutdown_timeout();
337 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 337 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
338 EXPECT_TRUE( 338 EXPECT_TRUE(
339 test_api_->ContainersAreAnimated( 339 test_api_->ContainersAreAnimated(
340 PowerButtonController::GetAllContainersMask(), 340 internal::SessionStateAnimator::kAllContainersMask,
341 PowerButtonController::ANIMATION_SLOW_CLOSE)); 341 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
342 342
343 // Fire the shutdown timeout and check that we request shutdown. 343 // Fire the shutdown timeout and check that we request shutdown.
344 test_api_->trigger_shutdown_timeout(); 344 test_api_->trigger_shutdown_timeout();
345 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 345 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
346 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 346 EXPECT_EQ(0, delegate_->num_shutdown_requests());
347 test_api_->trigger_real_shutdown_timeout(); 347 test_api_->trigger_real_shutdown_timeout();
348 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 348 EXPECT_EQ(1, delegate_->num_shutdown_requests());
349 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 349 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
350 } 350 }
351 351
352 // Test that we handle the case where lock requests are ignored. 352 // Test that we handle the case where lock requests are ignored.
353 TEST_F(PowerButtonControllerTest, LockFail) { 353 TEST_F(PowerButtonControllerTest, LockFail) {
354 // We require animations to have a duration for this test. 354 // We require animations to have a duration for this test.
355 ui::LayerAnimator::set_disable_animations_for_test(false); 355 ui::LayerAnimator::set_disable_animations_for_test(false);
356 356
357 controller_->set_has_legacy_power_button_for_test(false); 357 controller_->set_has_legacy_power_button_for_test(false);
358 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 358 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
359 controller_->OnLockStateChanged(false); 359 controller_->OnLockStateChanged(false);
360 360
361 // Hold the power button and lock the screen. 361 // Hold the power button and lock the screen.
362 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 362 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
363 EXPECT_TRUE(test_api_->lock_timer_is_running()); 363 EXPECT_TRUE(test_api_->lock_timer_is_running());
364 EXPECT_TRUE( 364 EXPECT_TRUE(
365 test_api_->ContainersAreAnimated( 365 test_api_->ContainersAreAnimated(
366 PowerButtonController::DESKTOP_BACKGROUND | 366 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
367 PowerButtonController::LAUNCHER | 367 internal::SessionStateAnimator::LAUNCHER |
368 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 368 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
369 PowerButtonController::ANIMATION_RESTORE)); 369 internal::SessionStateAnimator::ANIMATION_RESTORE));
370 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 370 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
371 test_api_->trigger_lock_timeout(); 371 test_api_->trigger_lock_timeout();
372 EXPECT_EQ(1, delegate_->num_lock_requests()); 372 EXPECT_EQ(1, delegate_->num_lock_requests());
373 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); 373 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
374 374
375 // We shouldn't start the lock-to-shutdown timer until the screen has actually 375 // We shouldn't start the lock-to-shutdown timer until the screen has actually
376 // been locked. 376 // been locked.
377 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 377 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
378 378
379 // Act as if the request timed out. We should restore the windows. 379 // Act as if the request timed out. We should restore the windows.
380 test_api_->trigger_lock_fail_timeout(); 380 test_api_->trigger_lock_fail_timeout();
381 EXPECT_TRUE( 381 EXPECT_TRUE(
382 test_api_->ContainersAreAnimated( 382 test_api_->ContainersAreAnimated(
383 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 383 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
384 PowerButtonController::ANIMATION_RESTORE)); 384 internal::SessionStateAnimator::ANIMATION_RESTORE));
385 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 385 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
386 } 386 }
387 387
388 // Test that we start the timer to hide the black layer when the power 388 // Test that we start the timer to hide the black layer when the power
389 // button is released, but that we cancel the timer if the button is pressed 389 // button is released, but that we cancel the timer if the button is pressed
390 // again before the timer has fired. 390 // again before the timer has fired.
391 TEST_F(PowerButtonControllerTest, CancelHideBackground) { 391 TEST_F(PowerButtonControllerTest, CancelHideBackground) {
392 controller_->set_has_legacy_power_button_for_test(false); 392 controller_->set_has_legacy_power_button_for_test(false);
393 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 393 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
394 controller_->OnLockStateChanged(false); 394 controller_->OnLockStateChanged(false);
(...skipping 25 matching lines...) Expand all
420 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 420 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
421 EXPECT_EQ(0, delegate_->num_lock_requests()); 421 EXPECT_EQ(0, delegate_->num_lock_requests());
422 422
423 // If we're logged in as a regular user, we should start the lock timer and 423 // If we're logged in as a regular user, we should start the lock timer and
424 // the pre-lock animation. 424 // the pre-lock animation.
425 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 425 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
427 EXPECT_TRUE(test_api_->lock_timer_is_running()); 427 EXPECT_TRUE(test_api_->lock_timer_is_running());
428 EXPECT_TRUE( 428 EXPECT_TRUE(
429 test_api_->ContainersAreAnimated( 429 test_api_->ContainersAreAnimated(
430 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 430 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
431 PowerButtonController::ANIMATION_SLOW_CLOSE)); 431 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
432 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 432 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
433 433
434 // If the button is released immediately, we shouldn't lock the screen. 434 // If the button is released immediately, we shouldn't lock the screen.
435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
436 EXPECT_FALSE(test_api_->lock_timer_is_running()); 436 EXPECT_FALSE(test_api_->lock_timer_is_running());
437 EXPECT_TRUE( 437 EXPECT_TRUE(
438 test_api_->ContainersAreAnimated( 438 test_api_->ContainersAreAnimated(
439 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 439 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
440 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); 440 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
441 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 441 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
442 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 442 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running());
443 test_api_->trigger_hide_black_layer_timeout(); 443 test_api_->TriggerHideBlackLayerTimeout();
444 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 444 EXPECT_FALSE(test_api_->BlackLayerIsVisible());
445 EXPECT_EQ(0, delegate_->num_lock_requests()); 445 EXPECT_EQ(0, delegate_->num_lock_requests());
446 446
447 // Press the button again and let the lock timeout fire. We should request 447 // Press the button again and let the lock timeout fire. We should request
448 // that the screen be locked. 448 // that the screen be locked.
449 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 449 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
450 EXPECT_TRUE(test_api_->lock_timer_is_running()); 450 EXPECT_TRUE(test_api_->lock_timer_is_running());
451 test_api_->trigger_lock_timeout(); 451 test_api_->trigger_lock_timeout();
452 EXPECT_EQ(1, delegate_->num_lock_requests()); 452 EXPECT_EQ(1, delegate_->num_lock_requests());
453 453
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 498 }
499 499
500 // When the screen is locked without going through the usual power-button 500 // When the screen is locked without going through the usual power-button
501 // slow-close path (e.g. via the wrench menu), test that we still show the 501 // slow-close path (e.g. via the wrench menu), test that we still show the
502 // fast-close animation and display the black layer. 502 // fast-close animation and display the black layer.
503 TEST_F(PowerButtonControllerTest, LockWithoutButton) { 503 TEST_F(PowerButtonControllerTest, LockWithoutButton) {
504 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 504 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
505 controller_->OnStartingLock(); 505 controller_->OnStartingLock();
506 EXPECT_TRUE( 506 EXPECT_TRUE(
507 test_api_->ContainersAreAnimated( 507 test_api_->ContainersAreAnimated(
508 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 508 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
509 PowerButtonController::ANIMATION_FAST_CLOSE)); 509 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
510 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 510 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
511 } 511 }
512 512
513 // When we hear that the process is exiting but we haven't had a chance to 513 // When we hear that the process is exiting but we haven't had a chance to
514 // display an animation, we should just blank the screen. 514 // display an animation, we should just blank the screen.
515 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { 515 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) {
516 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 516 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
517 controller_->OnAppTerminating(); 517 controller_->OnAppTerminating();
518 EXPECT_TRUE( 518 EXPECT_TRUE(
519 test_api_->ContainersAreAnimated( 519 test_api_->ContainersAreAnimated(
520 PowerButtonController::GetAllContainersMask(), 520 internal::SessionStateAnimator::kAllContainersMask,
521 PowerButtonController::ANIMATION_HIDE)); 521 internal::SessionStateAnimator::ANIMATION_HIDE));
522 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 522 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
523 GenerateMouseMoveEvent(); 523 GenerateMouseMoveEvent();
524 EXPECT_FALSE(cursor_visible()); 524 EXPECT_FALSE(cursor_visible());
525 } 525 }
526 526
527 // Test that we display the fast-close animation and shut down when we get an 527 // Test that we display the fast-close animation and shut down when we get an
528 // outside request to shut down (e.g. from the login or lock screen). 528 // outside request to shut down (e.g. from the login or lock screen).
529 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { 529 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) {
530 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 530 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
531 controller_->RequestShutdown(); 531 controller_->RequestShutdown();
532 EXPECT_TRUE( 532 EXPECT_TRUE(
533 test_api_->ContainersAreAnimated( 533 test_api_->ContainersAreAnimated(
534 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 534 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
535 PowerButtonController::ANIMATION_HIDE)); 535 internal::SessionStateAnimator::ANIMATION_HIDE));
536 EXPECT_TRUE( 536 EXPECT_TRUE(
537 test_api_->ContainersAreAnimated( 537 test_api_->ContainersAreAnimated(
538 PowerButtonController::GetAllLockScreenContainersMask(), 538 internal::SessionStateAnimator::kAllLockScreenContainersMask,
539 PowerButtonController::ANIMATION_FAST_CLOSE)); 539 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
540 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 540 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
541 GenerateMouseMoveEvent(); 541 GenerateMouseMoveEvent();
542 EXPECT_FALSE(cursor_visible()); 542 EXPECT_FALSE(cursor_visible());
543 543
544 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 544 EXPECT_EQ(0, delegate_->num_shutdown_requests());
545 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 545 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
546 test_api_->trigger_real_shutdown_timeout(); 546 test_api_->trigger_real_shutdown_timeout();
547 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 547 EXPECT_EQ(1, delegate_->num_shutdown_requests());
548 } 548 }
549 549
550 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { 550 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
551 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 551 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
552 controller_->OnLockStateChanged(true); 552 controller_->OnLockStateChanged(true);
553 controller_->RequestShutdown(); 553 controller_->RequestShutdown();
554 EXPECT_TRUE( 554 EXPECT_TRUE(
555 test_api_->ContainersAreAnimated( 555 test_api_->ContainersAreAnimated(
556 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, 556 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
557 PowerButtonController::ANIMATION_HIDE)); 557 internal::SessionStateAnimator::ANIMATION_HIDE));
558 EXPECT_TRUE( 558 EXPECT_TRUE(
559 test_api_->ContainersAreAnimated( 559 test_api_->ContainersAreAnimated(
560 PowerButtonController::GetAllLockScreenContainersMask(), 560 internal::SessionStateAnimator::kAllLockScreenContainersMask,
561 PowerButtonController::ANIMATION_FAST_CLOSE)); 561 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
562 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 562 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
563 GenerateMouseMoveEvent(); 563 GenerateMouseMoveEvent();
564 EXPECT_FALSE(cursor_visible()); 564 EXPECT_FALSE(cursor_visible());
565 565
566 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 566 EXPECT_EQ(0, delegate_->num_shutdown_requests());
567 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 567 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
568 test_api_->trigger_real_shutdown_timeout(); 568 test_api_->trigger_real_shutdown_timeout();
569 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 569 EXPECT_EQ(1, delegate_->num_shutdown_requests());
570 } 570 }
571 571
572 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { 572 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) {
573 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 573 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
574 controller_->OnLockStateChanged(true); 574 controller_->OnLockStateChanged(true);
575 575
576 // Press the power button and check that we start the shutdown timer. 576 // Press the power button and check that we start the shutdown timer.
577 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 577 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
578 EXPECT_FALSE(test_api_->lock_timer_is_running()); 578 EXPECT_FALSE(test_api_->lock_timer_is_running());
579 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 579 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
580 EXPECT_TRUE( 580 EXPECT_TRUE(
581 test_api_->ContainersAreAnimated( 581 test_api_->ContainersAreAnimated(
582 PowerButtonController::GetAllContainersMask(), 582 internal::SessionStateAnimator::kAllContainersMask,
583 PowerButtonController::ANIMATION_SLOW_CLOSE)); 583 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
584 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 584 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
585 585
586 // Release the power button before the shutdown timer fires. 586 // Release the power button before the shutdown timer fires.
587 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 587 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
588 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 588 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
589 EXPECT_TRUE( 589 EXPECT_TRUE(
590 test_api_->ContainersAreAnimated( 590 test_api_->ContainersAreAnimated(
591 PowerButtonController::GetAllLockScreenContainersMask(), 591 internal::SessionStateAnimator::kAllLockScreenContainersMask,
592 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); 592 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
593 EXPECT_TRUE( 593 EXPECT_TRUE(
594 test_api_->ContainersAreAnimated( 594 test_api_->ContainersAreAnimated(
595 PowerButtonController::DESKTOP_BACKGROUND, 595 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
596 PowerButtonController::ANIMATION_RESTORE)); 596 internal::SessionStateAnimator::ANIMATION_RESTORE));
597 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 597 EXPECT_TRUE(test_api_->BlackLayerIsVisible());
598 } 598 }
599 599
600 // Test that the black layer is resized in response to root window resizes. 600 // Test that the black layer is resized in response to root window resizes.
601 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { 601 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) {
602 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 602 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
603 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), 603 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(),
604 test_api_->GetBlackLayerBounds().ToString()); 604 test_api_->GetBlackLayerBounds().ToString());
605 605
606 const gfx::Size kNewSize(400, 300); 606 const gfx::Size kNewSize(400, 300);
(...skipping 14 matching lines...) Expand all
621 621
622 // After increasing the brightness to 10%, we should start the timer like 622 // After increasing the brightness to 10%, we should start the timer like
623 // usual. 623 // usual.
624 controller_->OnScreenBrightnessChanged(10.0); 624 controller_->OnScreenBrightnessChanged(10.0);
625 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 625 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
626 EXPECT_TRUE(test_api_->lock_timer_is_running()); 626 EXPECT_TRUE(test_api_->lock_timer_is_running());
627 } 627 }
628 628
629 } // namespace test 629 } // namespace test
630 } // namespace ash 630 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/power_button_controller.cc ('k') | ash/wm/session_state_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698