OLD | NEW |
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 #include "ash/wm/session_state_animator.h" | 6 #include "ash/wm/session_state_animator.h" |
7 #include "ash/wm/session_state_controller.h" | 7 #include "ash/wm/session_state_controller.h" |
8 #include "ash/wm/session_state_controller_impl.h" | 8 #include "ash/wm/session_state_controller_impl.h" |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 109 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
110 state_controller_->OnLockStateChanged(false); | 110 state_controller_->OnLockStateChanged(false); |
111 | 111 |
112 // We should request that the screen be locked immediately after seeing the | 112 // We should request that the screen be locked immediately after seeing the |
113 // power button get pressed. | 113 // power button get pressed. |
114 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 114 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
115 EXPECT_TRUE( | 115 EXPECT_TRUE( |
116 animator_api_->ContainersAreAnimated( | 116 animator_api_->ContainersAreAnimated( |
117 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 117 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
118 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 118 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
119 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
120 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); | |
121 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 119 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
122 EXPECT_EQ(1, delegate_->num_lock_requests()); | 120 EXPECT_EQ(1, delegate_->num_lock_requests()); |
123 | 121 |
124 // Notify that we locked successfully. | 122 // Notify that we locked successfully. |
125 state_controller_->OnStartingLock(); | 123 state_controller_->OnStartingLock(); |
126 EXPECT_TRUE( | 124 EXPECT_TRUE( |
127 animator_api_->ContainersAreAnimated( | 125 animator_api_->ContainersAreAnimated( |
128 internal::SessionStateAnimator::LAUNCHER, | 126 internal::SessionStateAnimator::LAUNCHER, |
129 internal::SessionStateAnimator::ANIMATION_HIDE)); | 127 internal::SessionStateAnimator::ANIMATION_HIDE)); |
130 EXPECT_TRUE( | 128 EXPECT_TRUE( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 190 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
193 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 191 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
194 } | 192 } |
195 | 193 |
196 // When we hold the power button while the user isn't logged in, we should shut | 194 // When we hold the power button while the user isn't logged in, we should shut |
197 // down the machine directly. | 195 // down the machine directly. |
198 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { | 196 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { |
199 controller_->set_has_legacy_power_button_for_test(false); | 197 controller_->set_has_legacy_power_button_for_test(false); |
200 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 198 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
201 state_controller_->OnLockStateChanged(false); | 199 state_controller_->OnLockStateChanged(false); |
202 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
203 | 200 |
204 // Press the power button and check that we start the shutdown timer. | 201 // Press the power button and check that we start the shutdown timer. |
205 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 202 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
206 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 203 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
207 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 204 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
208 EXPECT_TRUE( | 205 EXPECT_TRUE( |
209 animator_api_->ContainersAreAnimated( | 206 animator_api_->ContainersAreAnimated( |
210 internal::SessionStateAnimator::kAllContainersMask, | 207 internal::SessionStateAnimator::kAllContainersMask, |
211 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 208 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
212 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
213 | 209 |
214 // Release the power button before the shutdown timer fires. | 210 // Release the power button before the shutdown timer fires. |
215 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 211 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
216 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 212 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
217 EXPECT_TRUE( | 213 EXPECT_TRUE( |
218 animator_api_->ContainersAreAnimated( | 214 animator_api_->ContainersAreAnimated( |
219 internal::SessionStateAnimator::kAllContainersMask, | 215 internal::SessionStateAnimator::kAllContainersMask, |
220 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); | 216 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
221 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
222 | |
223 // We should re-hide the black layer after waiting long enough for | |
224 // the animation to finish. | |
225 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | |
226 animator_api_->TriggerHideBlackLayerTimeout(); | |
227 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
228 | 217 |
229 // Press the button again and make the shutdown timeout fire this time. | 218 // Press the button again and make the shutdown timeout fire this time. |
230 // Check that we start the timer for actually requesting the shutdown. | 219 // Check that we start the timer for actually requesting the shutdown. |
231 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 220 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
232 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 221 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
233 test_api_->trigger_shutdown_timeout(); | 222 test_api_->trigger_shutdown_timeout(); |
234 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 223 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
235 EXPECT_EQ(0, NumShutdownRequests()); | 224 EXPECT_EQ(0, NumShutdownRequests()); |
236 EXPECT_TRUE( | 225 EXPECT_TRUE( |
237 animator_api_->ContainersAreAnimated( | 226 animator_api_->ContainersAreAnimated( |
238 internal::SessionStateAnimator::LAUNCHER | | 227 internal::SessionStateAnimator::LAUNCHER | |
239 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 228 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
240 internal::SessionStateAnimator::ANIMATION_HIDE)); | 229 internal::SessionStateAnimator::ANIMATION_HIDE)); |
241 EXPECT_TRUE( | 230 EXPECT_TRUE( |
242 animator_api_->ContainersAreAnimated( | 231 animator_api_->ContainersAreAnimated( |
243 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 232 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
244 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 233 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
245 | 234 |
246 // When the timout fires, we should request a shutdown. | 235 // When the timout fires, we should request a shutdown. |
247 test_api_->trigger_real_shutdown_timeout(); | 236 test_api_->trigger_real_shutdown_timeout(); |
248 EXPECT_EQ(1, NumShutdownRequests()); | 237 EXPECT_EQ(1, NumShutdownRequests()); |
249 } | 238 } |
250 | 239 |
251 // Test that we lock the screen and deal with unlocking correctly. | 240 // Test that we lock the screen and deal with unlocking correctly. |
252 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 241 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
253 controller_->set_has_legacy_power_button_for_test(false); | 242 controller_->set_has_legacy_power_button_for_test(false); |
254 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 243 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
255 state_controller_->OnLockStateChanged(false); | 244 state_controller_->OnLockStateChanged(false); |
256 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
257 | 245 |
258 // We should initially be showing the screen locker containers, since they | 246 // We should initially be showing the screen locker containers, since they |
259 // also contain login-related windows that we want to show during the | 247 // also contain login-related windows that we want to show during the |
260 // logging-in animation. | 248 // logging-in animation. |
261 EXPECT_TRUE( | 249 EXPECT_TRUE( |
262 animator_api_->ContainersAreAnimated( | 250 animator_api_->ContainersAreAnimated( |
263 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 251 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
264 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 252 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
265 | 253 |
266 // Press the power button and check that the lock timer is started and that we | 254 // Press the power button and check that the lock timer is started and that we |
267 // start scaling the non-screen-locker containers. | 255 // start scaling the non-screen-locker containers. |
268 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 256 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
269 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 257 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
270 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 258 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
271 EXPECT_TRUE( | 259 EXPECT_TRUE( |
272 animator_api_->ContainersAreAnimated( | 260 animator_api_->ContainersAreAnimated( |
273 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 261 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
274 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 262 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
275 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
276 | 263 |
277 // Release the button before the lock timer fires. | 264 // Release the button before the lock timer fires. |
278 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 265 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
279 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 266 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
280 EXPECT_TRUE( | 267 EXPECT_TRUE( |
281 animator_api_->ContainersAreAnimated( | 268 animator_api_->ContainersAreAnimated( |
282 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 269 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
283 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); | 270 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
284 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
285 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | |
286 animator_api_->TriggerHideBlackLayerTimeout(); | |
287 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
288 | 271 |
289 // Press the button and fire the lock timer. We should request that the | 272 // Press the button and fire the lock timer. We should request that the |
290 // screen be locked, but we should still be in the slow-close animation. | 273 // screen be locked, but we should still be in the slow-close animation. |
291 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 274 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
292 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 275 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
293 EXPECT_EQ(0, delegate_->num_lock_requests()); | 276 EXPECT_EQ(0, delegate_->num_lock_requests()); |
294 test_api_->trigger_lock_timeout(); | 277 test_api_->trigger_lock_timeout(); |
295 EXPECT_EQ(1, delegate_->num_lock_requests()); | 278 EXPECT_EQ(1, delegate_->num_lock_requests()); |
296 EXPECT_TRUE( | 279 EXPECT_TRUE( |
297 animator_api_->ContainersAreAnimated( | 280 animator_api_->ContainersAreAnimated( |
298 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 281 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
299 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 282 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
300 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
301 | 283 |
302 // Notify that we locked successfully. | 284 // Notify that we locked successfully. |
303 state_controller_->OnStartingLock(); | 285 state_controller_->OnStartingLock(); |
304 EXPECT_TRUE( | 286 EXPECT_TRUE( |
305 animator_api_->ContainersAreAnimated( | 287 animator_api_->ContainersAreAnimated( |
306 internal::SessionStateAnimator::LAUNCHER, | 288 internal::SessionStateAnimator::LAUNCHER, |
307 internal::SessionStateAnimator::ANIMATION_HIDE)); | 289 internal::SessionStateAnimator::ANIMATION_HIDE)); |
308 EXPECT_TRUE( | 290 EXPECT_TRUE( |
309 animator_api_->ContainersAreAnimated( | 291 animator_api_->ContainersAreAnimated( |
310 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 292 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
(...skipping 10 matching lines...) Expand all Loading... |
321 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 303 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
322 internal::SessionStateAnimator::ANIMATION_FADE_IN)); | 304 internal::SessionStateAnimator::ANIMATION_FADE_IN)); |
323 | 305 |
324 // When we release the power button, the lock-to-shutdown timer should be | 306 // When we release the power button, the lock-to-shutdown timer should be |
325 // stopped. | 307 // stopped. |
326 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 308 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
327 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 309 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
328 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 310 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
329 | 311 |
330 // Notify that the screen has been unlocked. We should show the | 312 // Notify that the screen has been unlocked. We should show the |
331 // non-screen-locker windows and hide the black layer. | 313 // non-screen-locker windows. |
332 state_controller_->OnLockStateChanged(false); | 314 state_controller_->OnLockStateChanged(false); |
333 EXPECT_TRUE( | 315 EXPECT_TRUE( |
334 animator_api_->ContainersAreAnimated( | 316 animator_api_->ContainersAreAnimated( |
335 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 317 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
336 internal::SessionStateAnimator::LAUNCHER | | 318 internal::SessionStateAnimator::LAUNCHER | |
337 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 319 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
338 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 320 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
339 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
340 } | 321 } |
341 | 322 |
342 // Hold the power button down from the unlocked state to eventual shutdown. | 323 // Hold the power button down from the unlocked state to eventual shutdown. |
343 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 324 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
344 controller_->set_has_legacy_power_button_for_test(false); | 325 controller_->set_has_legacy_power_button_for_test(false); |
345 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 326 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
346 state_controller_->OnLockStateChanged(false); | 327 state_controller_->OnLockStateChanged(false); |
347 | 328 |
348 // Hold the power button and lock the screen. | 329 // Hold the power button and lock the screen. |
349 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 330 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
350 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 331 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
351 test_api_->trigger_lock_timeout(); | 332 test_api_->trigger_lock_timeout(); |
352 state_controller_->OnStartingLock(); | 333 state_controller_->OnStartingLock(); |
353 state_controller_->OnLockStateChanged(true); | 334 state_controller_->OnLockStateChanged(true); |
354 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
355 | 335 |
356 // When the lock-to-shutdown timeout fires, we should start the shutdown | 336 // When the lock-to-shutdown timeout fires, we should start the shutdown |
357 // timer. | 337 // timer. |
358 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 338 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
359 test_api_->trigger_lock_to_shutdown_timeout(); | 339 test_api_->trigger_lock_to_shutdown_timeout(); |
360 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 340 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
361 EXPECT_TRUE( | 341 EXPECT_TRUE( |
362 animator_api_->ContainersAreAnimated( | 342 animator_api_->ContainersAreAnimated( |
363 internal::SessionStateAnimator::kAllContainersMask, | 343 internal::SessionStateAnimator::kAllContainersMask, |
364 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 344 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
365 | 345 |
366 // Fire the shutdown timeout and check that we request shutdown. | 346 // Fire the shutdown timeout and check that we request shutdown. |
367 test_api_->trigger_shutdown_timeout(); | 347 test_api_->trigger_shutdown_timeout(); |
368 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 348 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
369 EXPECT_EQ(0, NumShutdownRequests()); | 349 EXPECT_EQ(0, NumShutdownRequests()); |
370 test_api_->trigger_real_shutdown_timeout(); | 350 test_api_->trigger_real_shutdown_timeout(); |
371 EXPECT_EQ(1, NumShutdownRequests()); | 351 EXPECT_EQ(1, NumShutdownRequests()); |
372 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
373 } | 352 } |
374 | 353 |
375 | 354 |
376 // Hold the power button down from the unlocked state to eventual shutdown, | 355 // Hold the power button down from the unlocked state to eventual shutdown, |
377 // then release the button while system does locking. | 356 // then release the button while system does locking. |
378 TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { | 357 TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { |
379 controller_->set_has_legacy_power_button_for_test(false); | 358 controller_->set_has_legacy_power_button_for_test(false); |
380 | 359 |
381 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 360 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
382 state_controller_->OnLockStateChanged(false); | 361 state_controller_->OnLockStateChanged(false); |
(...skipping 24 matching lines...) Expand all Loading... |
407 | 386 |
408 // Hold the power button and lock the screen. | 387 // Hold the power button and lock the screen. |
409 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 388 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
410 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 389 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
411 EXPECT_TRUE( | 390 EXPECT_TRUE( |
412 animator_api_->ContainersAreAnimated( | 391 animator_api_->ContainersAreAnimated( |
413 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 392 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
414 internal::SessionStateAnimator::LAUNCHER | | 393 internal::SessionStateAnimator::LAUNCHER | |
415 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 394 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
416 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 395 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
417 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
418 test_api_->trigger_lock_timeout(); | 396 test_api_->trigger_lock_timeout(); |
419 EXPECT_EQ(1, delegate_->num_lock_requests()); | 397 EXPECT_EQ(1, delegate_->num_lock_requests()); |
420 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 398 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
421 | 399 |
422 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 400 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
423 // been locked. | 401 // been locked. |
424 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 402 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
425 | 403 |
426 // Act as if the request timed out. We should restore the windows. | 404 // Act as if the request timed out. We should restore the windows. |
427 test_api_->trigger_lock_fail_timeout(); | 405 test_api_->trigger_lock_fail_timeout(); |
428 EXPECT_TRUE( | 406 EXPECT_TRUE( |
429 animator_api_->ContainersAreAnimated( | 407 animator_api_->ContainersAreAnimated( |
430 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 408 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
431 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 409 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
432 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
433 } | |
434 | |
435 // Test that we start the timer to hide the black layer when the power | |
436 // button is released, but that we cancel the timer if the button is pressed | |
437 // again before the timer has fired. | |
438 TEST_F(PowerButtonControllerTest, CancelHideBackground) { | |
439 controller_->set_has_legacy_power_button_for_test(false); | |
440 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | |
441 state_controller_->OnLockStateChanged(false); | |
442 | |
443 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
444 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | |
445 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | |
446 | |
447 // We should cancel the timer if we get another button-down event. | |
448 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
449 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); | |
450 } | 410 } |
451 | 411 |
452 // Test the basic operation of the lock button. | 412 // Test the basic operation of the lock button. |
453 TEST_F(PowerButtonControllerTest, LockButtonBasic) { | 413 TEST_F(PowerButtonControllerTest, LockButtonBasic) { |
454 controller_->set_has_legacy_power_button_for_test(false); | 414 controller_->set_has_legacy_power_button_for_test(false); |
455 // The lock button shouldn't do anything if we aren't logged in. | 415 // The lock button shouldn't do anything if we aren't logged in. |
456 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 416 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
457 state_controller_->OnLockStateChanged(false); | 417 state_controller_->OnLockStateChanged(false); |
458 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 418 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
459 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 419 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
460 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 420 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
461 EXPECT_EQ(0, delegate_->num_lock_requests()); | 421 EXPECT_EQ(0, delegate_->num_lock_requests()); |
462 | 422 |
463 // Ditto for when we're logged in as a guest. | 423 // Ditto for when we're logged in as a guest. |
464 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 424 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
465 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 425 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
466 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 426 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
467 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 427 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
468 EXPECT_EQ(0, delegate_->num_lock_requests()); | 428 EXPECT_EQ(0, delegate_->num_lock_requests()); |
469 | 429 |
470 // If we're logged in as a regular user, we should start the lock timer and | 430 // If we're logged in as a regular user, we should start the lock timer and |
471 // the pre-lock animation. | 431 // the pre-lock animation. |
472 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 432 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
473 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 433 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
474 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 434 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
475 EXPECT_TRUE( | 435 EXPECT_TRUE( |
476 animator_api_->ContainersAreAnimated( | 436 animator_api_->ContainersAreAnimated( |
477 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 437 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
478 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 438 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
479 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
480 | 439 |
481 // If the button is released immediately, we shouldn't lock the screen. | 440 // If the button is released immediately, we shouldn't lock the screen. |
482 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 441 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
483 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 442 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
484 EXPECT_TRUE( | 443 EXPECT_TRUE( |
485 animator_api_->ContainersAreAnimated( | 444 animator_api_->ContainersAreAnimated( |
486 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 445 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
487 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); | 446 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
488 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
489 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | |
490 animator_api_->TriggerHideBlackLayerTimeout(); | |
491 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | |
492 EXPECT_EQ(0, delegate_->num_lock_requests()); | 447 EXPECT_EQ(0, delegate_->num_lock_requests()); |
493 | 448 |
494 // Press the button again and let the lock timeout fire. We should request | 449 // Press the button again and let the lock timeout fire. We should request |
495 // that the screen be locked. | 450 // that the screen be locked. |
496 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 451 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
497 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 452 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
498 test_api_->trigger_lock_timeout(); | 453 test_api_->trigger_lock_timeout(); |
499 EXPECT_EQ(1, delegate_->num_lock_requests()); | 454 EXPECT_EQ(1, delegate_->num_lock_requests()); |
500 | 455 |
501 // Pressing the lock button while we have a pending lock request shouldn't do | 456 // Pressing the lock button while we have a pending lock request shouldn't do |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 494 |
540 // Releasing the power button should stop the lock timer. | 495 // Releasing the power button should stop the lock timer. |
541 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 496 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
542 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 497 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
543 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 498 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
544 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 499 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
545 } | 500 } |
546 | 501 |
547 // When the screen is locked without going through the usual power-button | 502 // When the screen is locked without going through the usual power-button |
548 // slow-close path (e.g. via the wrench menu), test that we still show the | 503 // slow-close path (e.g. via the wrench menu), test that we still show the |
549 // fast-close animation and display the black layer. | 504 // fast-close animation. |
550 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 505 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
551 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 506 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
552 state_controller_->OnStartingLock(); | 507 state_controller_->OnStartingLock(); |
553 EXPECT_TRUE( | 508 EXPECT_TRUE( |
554 animator_api_->ContainersAreAnimated( | 509 animator_api_->ContainersAreAnimated( |
555 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 510 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
556 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 511 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
557 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
558 } | 512 } |
559 | 513 |
560 // When we hear that the process is exiting but we haven't had a chance to | 514 // When we hear that the process is exiting but we haven't had a chance to |
561 // display an animation, we should just blank the screen. | 515 // display an animation, we should just blank the screen. |
562 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 516 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
563 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 517 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
564 state_controller_->OnAppTerminating(); | 518 state_controller_->OnAppTerminating(); |
565 EXPECT_TRUE( | 519 EXPECT_TRUE( |
566 animator_api_->ContainersAreAnimated( | 520 animator_api_->ContainersAreAnimated( |
567 internal::SessionStateAnimator::kAllContainersMask, | 521 internal::SessionStateAnimator::kAllContainersMask, |
568 internal::SessionStateAnimator::ANIMATION_HIDE)); | 522 internal::SessionStateAnimator::ANIMATION_HIDE)); |
569 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
570 GenerateMouseMoveEvent(); | 523 GenerateMouseMoveEvent(); |
571 EXPECT_FALSE(cursor_visible()); | 524 EXPECT_FALSE(cursor_visible()); |
572 } | 525 } |
573 | 526 |
574 // 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 |
575 // 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). |
576 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 529 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
577 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 530 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
578 state_controller_->RequestShutdown(); | 531 state_controller_->RequestShutdown(); |
579 EXPECT_TRUE( | 532 EXPECT_TRUE( |
580 animator_api_->ContainersAreAnimated( | 533 animator_api_->ContainersAreAnimated( |
581 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 534 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
582 internal::SessionStateAnimator::ANIMATION_HIDE)); | 535 internal::SessionStateAnimator::ANIMATION_HIDE)); |
583 EXPECT_TRUE( | 536 EXPECT_TRUE( |
584 animator_api_->ContainersAreAnimated( | 537 animator_api_->ContainersAreAnimated( |
585 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 538 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
586 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 539 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
587 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
588 GenerateMouseMoveEvent(); | 540 GenerateMouseMoveEvent(); |
589 EXPECT_FALSE(cursor_visible()); | 541 EXPECT_FALSE(cursor_visible()); |
590 | 542 |
591 EXPECT_EQ(0, NumShutdownRequests()); | 543 EXPECT_EQ(0, NumShutdownRequests()); |
592 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 544 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
593 test_api_->trigger_real_shutdown_timeout(); | 545 test_api_->trigger_real_shutdown_timeout(); |
594 EXPECT_EQ(1, NumShutdownRequests()); | 546 EXPECT_EQ(1, NumShutdownRequests()); |
595 } | 547 } |
596 | 548 |
597 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 549 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
598 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 550 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
599 state_controller_->OnLockStateChanged(true); | 551 state_controller_->OnLockStateChanged(true); |
600 state_controller_->RequestShutdown(); | 552 state_controller_->RequestShutdown(); |
601 EXPECT_TRUE( | 553 EXPECT_TRUE( |
602 animator_api_->ContainersAreAnimated( | 554 animator_api_->ContainersAreAnimated( |
603 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 555 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
604 internal::SessionStateAnimator::ANIMATION_HIDE)); | 556 internal::SessionStateAnimator::ANIMATION_HIDE)); |
605 EXPECT_TRUE( | 557 EXPECT_TRUE( |
606 animator_api_->ContainersAreAnimated( | 558 animator_api_->ContainersAreAnimated( |
607 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 559 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
608 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 560 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
609 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
610 GenerateMouseMoveEvent(); | 561 GenerateMouseMoveEvent(); |
611 EXPECT_FALSE(cursor_visible()); | 562 EXPECT_FALSE(cursor_visible()); |
612 | 563 |
613 EXPECT_EQ(0, NumShutdownRequests()); | 564 EXPECT_EQ(0, NumShutdownRequests()); |
614 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 565 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
615 test_api_->trigger_real_shutdown_timeout(); | 566 test_api_->trigger_real_shutdown_timeout(); |
616 EXPECT_EQ(1, NumShutdownRequests()); | 567 EXPECT_EQ(1, NumShutdownRequests()); |
617 } | 568 } |
618 | 569 |
619 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { | 570 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { |
620 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 571 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
621 state_controller_->OnLockStateChanged(true); | 572 state_controller_->OnLockStateChanged(true); |
622 | 573 |
623 // Press the power button and check that we start the shutdown timer. | 574 // Press the power button and check that we start the shutdown timer. |
624 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 575 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
625 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 576 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
626 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 577 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
627 EXPECT_TRUE( | 578 EXPECT_TRUE( |
628 animator_api_->ContainersAreAnimated( | 579 animator_api_->ContainersAreAnimated( |
629 internal::SessionStateAnimator::kAllContainersMask, | 580 internal::SessionStateAnimator::kAllContainersMask, |
630 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 581 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
631 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
632 | 582 |
633 // Release the power button before the shutdown timer fires. | 583 // Release the power button before the shutdown timer fires. |
634 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 584 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
635 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 585 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
636 EXPECT_TRUE( | 586 EXPECT_TRUE( |
637 animator_api_->ContainersAreAnimated( | 587 animator_api_->ContainersAreAnimated( |
638 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 588 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
639 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); | 589 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
640 EXPECT_TRUE( | 590 EXPECT_TRUE( |
641 animator_api_->ContainersAreAnimated( | 591 animator_api_->ContainersAreAnimated( |
642 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | 592 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
643 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 593 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
644 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | |
645 } | |
646 | |
647 // Test that the black layer is resized in response to root window resizes. | |
648 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { | |
649 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
650 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), | |
651 animator_api_->GetBlackLayerBounds().ToString()); | |
652 | |
653 const gfx::Size kNewSize(400, 300); | |
654 Shell::GetPrimaryRootWindow()->SetHostSize(kNewSize); | |
655 EXPECT_EQ(gfx::Rect(kNewSize).ToString(), | |
656 animator_api_->GetBlackLayerBounds().ToString()); | |
657 } | 594 } |
658 | 595 |
659 // Test that we ignore power button presses when the screen is turned off. | 596 // Test that we ignore power button presses when the screen is turned off. |
660 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { | 597 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { |
661 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 598 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
662 | 599 |
663 // When the screen brightness is at 0%, we shouldn't do anything in response | 600 // When the screen brightness is at 0%, we shouldn't do anything in response |
664 // to power button presses. | 601 // to power button presses. |
665 controller_->OnScreenBrightnessChanged(0.0); | 602 controller_->OnScreenBrightnessChanged(0.0); |
666 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 603 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
667 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 604 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
668 | 605 |
669 // After increasing the brightness to 10%, we should start the timer like | 606 // After increasing the brightness to 10%, we should start the timer like |
670 // usual. | 607 // usual. |
671 controller_->OnScreenBrightnessChanged(10.0); | 608 controller_->OnScreenBrightnessChanged(10.0); |
672 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 609 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
673 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 610 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
674 } | 611 } |
675 | 612 |
676 } // namespace test | 613 } // namespace test |
677 } // namespace ash | 614 } // namespace ash |
OLD | NEW |