| 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 | 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 "ash/wm/session_state_animator.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 14 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 namespace test { | 19 namespace test { |
| 19 namespace { | 20 namespace { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { | 78 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { |
| 78 controller_->set_has_legacy_power_button_for_test(true); | 79 controller_->set_has_legacy_power_button_for_test(true); |
| 79 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 80 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 80 controller_->OnLockStateChanged(false); | 81 controller_->OnLockStateChanged(false); |
| 81 | 82 |
| 82 // We should request that the screen be locked immediately after seeing the | 83 // We should request that the screen be locked immediately after seeing the |
| 83 // power button get pressed. | 84 // power button get pressed. |
| 84 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 85 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 85 EXPECT_TRUE( | 86 EXPECT_TRUE( |
| 86 test_api_->ContainerGroupIsAnimated( | 87 test_api_->ContainerGroupIsAnimated( |
| 87 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 88 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 88 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 89 SessionStateAnimator::SLOW_CLOSE)); |
| 89 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 90 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 90 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); | 91 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); |
| 91 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 92 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 92 EXPECT_EQ(1, delegate_->num_lock_requests()); | 93 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 93 | 94 |
| 94 // Notify that we locked successfully. | 95 // Notify that we locked successfully. |
| 95 controller_->OnStartingLock(); | 96 controller_->OnStartingLock(); |
| 96 EXPECT_TRUE( | 97 EXPECT_TRUE( |
| 97 test_api_->ContainerGroupIsAnimated( | 98 test_api_->ContainerGroupIsAnimated( |
| 98 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 99 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 99 PowerButtonController::ANIMATION_FAST_CLOSE)); | 100 SessionStateAnimator::FAST_CLOSE)); |
| 100 EXPECT_TRUE( | 101 EXPECT_TRUE( |
| 101 test_api_->ContainerGroupIsAnimated( | 102 test_api_->ContainerGroupIsAnimated( |
| 102 PowerButtonController::SCREEN_LOCKER_CONTAINERS, | 103 SessionStateAnimator::SCREEN_LOCKER_CONTAINERS, |
| 103 PowerButtonController::ANIMATION_HIDE)); | 104 SessionStateAnimator::HIDE)); |
| 104 | 105 |
| 105 // Notify that the lock window is visible. We should make it fade in. | 106 // Notify that the lock window is visible. We should make it fade in. |
| 106 controller_->OnLockStateChanged(true); | 107 controller_->OnLockStateChanged(true); |
| 107 EXPECT_TRUE( | 108 EXPECT_TRUE( |
| 108 test_api_->ContainerGroupIsAnimated( | 109 test_api_->ContainerGroupIsAnimated( |
| 109 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 110 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 110 PowerButtonController::ANIMATION_FADE_IN)); | 111 SessionStateAnimator::FADE_IN)); |
| 111 | 112 |
| 112 // We shouldn't progress towards the shutdown state, however. | 113 // We shouldn't progress towards the shutdown state, however. |
| 113 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 114 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 114 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 115 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 115 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 116 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 116 | 117 |
| 117 // Hold the button again and check that we start shutting down. | 118 // Hold the button again and check that we start shutting down. |
| 118 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 119 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 119 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 120 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 120 EXPECT_TRUE( | 121 EXPECT_TRUE( |
| 121 test_api_->ContainerGroupIsAnimated( | 122 test_api_->ContainerGroupIsAnimated( |
| 122 PowerButtonController::ALL_CONTAINERS, | 123 SessionStateAnimator::ALL_CONTAINERS, |
| 123 PowerButtonController::ANIMATION_FAST_CLOSE)); | 124 SessionStateAnimator::FAST_CLOSE)); |
| 124 EXPECT_FALSE(cursor_visible()); | 125 EXPECT_FALSE(cursor_visible()); |
| 125 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 126 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 126 test_api_->trigger_real_shutdown_timeout(); | 127 test_api_->trigger_real_shutdown_timeout(); |
| 127 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 128 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Test that we start shutting down immediately if the power button is pressed | 131 // Test that we start shutting down immediately if the power button is pressed |
| 131 // while we're not logged in on an unofficial system. | 132 // while we're not logged in on an unofficial system. |
| 132 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { | 133 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { |
| 133 controller_->set_has_legacy_power_button_for_test(true); | 134 controller_->set_has_legacy_power_button_for_test(true); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 154 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 155 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 155 controller_->OnLockStateChanged(false); | 156 controller_->OnLockStateChanged(false); |
| 156 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 157 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 157 | 158 |
| 158 // Press the power button and check that we start the shutdown timer. | 159 // Press the power button and check that we start the shutdown timer. |
| 159 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 160 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 160 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 161 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 161 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 162 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 162 EXPECT_TRUE( | 163 EXPECT_TRUE( |
| 163 test_api_->ContainerGroupIsAnimated( | 164 test_api_->ContainerGroupIsAnimated( |
| 164 PowerButtonController::ALL_CONTAINERS, | 165 SessionStateAnimator::ALL_CONTAINERS, |
| 165 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 166 SessionStateAnimator::SLOW_CLOSE)); |
| 166 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 167 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 167 | 168 |
| 168 // Release the power button before the shutdown timer fires. | 169 // Release the power button before the shutdown timer fires. |
| 169 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 170 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 170 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 171 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 171 EXPECT_TRUE( | 172 EXPECT_TRUE( |
| 172 test_api_->ContainerGroupIsAnimated( | 173 test_api_->ContainerGroupIsAnimated( |
| 173 PowerButtonController::ALL_CONTAINERS, | 174 SessionStateAnimator::ALL_CONTAINERS, |
| 174 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 175 SessionStateAnimator::UNDO_SLOW_CLOSE)); |
| 175 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 176 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 176 | 177 |
| 177 // We should re-hide the black background layer after waiting long enough for | 178 // We should re-hide the black background layer after waiting long enough for |
| 178 // the animation to finish. | 179 // the animation to finish. |
| 179 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); | 180 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); |
| 180 test_api_->trigger_hide_background_layer_timeout(); | 181 test_api_->trigger_hide_background_layer_timeout(); |
| 181 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 182 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 182 | 183 |
| 183 // Press the button again and make the shutdown timeout fire this time. | 184 // Press the button again and make the shutdown timeout fire this time. |
| 184 // Check that we start the timer for actually requesting the shutdown. | 185 // Check that we start the timer for actually requesting the shutdown. |
| 185 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 186 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 186 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 187 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 187 test_api_->trigger_shutdown_timeout(); | 188 test_api_->trigger_shutdown_timeout(); |
| 188 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 189 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 189 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 190 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 190 EXPECT_TRUE( | 191 EXPECT_TRUE( |
| 191 test_api_->ContainerGroupIsAnimated( | 192 test_api_->ContainerGroupIsAnimated( |
| 192 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 193 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 193 PowerButtonController::ANIMATION_HIDE)); | 194 SessionStateAnimator::HIDE)); |
| 194 EXPECT_TRUE( | 195 EXPECT_TRUE( |
| 195 test_api_->ContainerGroupIsAnimated( | 196 test_api_->ContainerGroupIsAnimated( |
| 196 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 197 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 197 PowerButtonController::ANIMATION_FAST_CLOSE)); | 198 SessionStateAnimator::FAST_CLOSE)); |
| 198 | 199 |
| 199 // When the timout fires, we should request a shutdown. | 200 // When the timout fires, we should request a shutdown. |
| 200 test_api_->trigger_real_shutdown_timeout(); | 201 test_api_->trigger_real_shutdown_timeout(); |
| 201 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 202 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 202 } | 203 } |
| 203 | 204 |
| 204 // Test that we lock the screen and deal with unlocking correctly. | 205 // Test that we lock the screen and deal with unlocking correctly. |
| 205 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 206 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
| 206 controller_->set_has_legacy_power_button_for_test(false); | 207 controller_->set_has_legacy_power_button_for_test(false); |
| 207 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 208 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 208 controller_->OnLockStateChanged(false); | 209 controller_->OnLockStateChanged(false); |
| 209 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 210 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 210 | 211 |
| 211 // We should initially be showing the screen locker containers, since they | 212 // We should initially be showing the screen locker containers, since they |
| 212 // also contain login-related windows that we want to show during the | 213 // also contain login-related windows that we want to show during the |
| 213 // logging-in animation. | 214 // logging-in animation. |
| 214 EXPECT_TRUE( | 215 EXPECT_TRUE( |
| 215 test_api_->ContainerGroupIsAnimated( | 216 test_api_->ContainerGroupIsAnimated( |
| 216 PowerButtonController::SCREEN_LOCKER_CONTAINERS, | 217 SessionStateAnimator::SCREEN_LOCKER_CONTAINERS, |
| 217 PowerButtonController::ANIMATION_RESTORE)); | 218 SessionStateAnimator::RESTORE)); |
| 218 | 219 |
| 219 // Press the power button and check that the lock timer is started and that we | 220 // Press the power button and check that the lock timer is started and that we |
| 220 // start scaling the non-screen-locker containers. | 221 // start scaling the non-screen-locker containers. |
| 221 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 222 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 222 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 223 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 223 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 224 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 224 EXPECT_TRUE( | 225 EXPECT_TRUE( |
| 225 test_api_->ContainerGroupIsAnimated( | 226 test_api_->ContainerGroupIsAnimated( |
| 226 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 227 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 227 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 228 SessionStateAnimator::SLOW_CLOSE)); |
| 228 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 229 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 229 | 230 |
| 230 // Release the button before the lock timer fires. | 231 // Release the button before the lock timer fires. |
| 231 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 232 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 232 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 233 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 233 EXPECT_TRUE( | 234 EXPECT_TRUE( |
| 234 test_api_->ContainerGroupIsAnimated( | 235 test_api_->ContainerGroupIsAnimated( |
| 235 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 236 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 236 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 237 SessionStateAnimator::UNDO_SLOW_CLOSE)); |
| 237 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 238 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 238 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); | 239 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); |
| 239 test_api_->trigger_hide_background_layer_timeout(); | 240 test_api_->trigger_hide_background_layer_timeout(); |
| 240 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 241 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 241 | 242 |
| 242 // Press the button and fire the lock timer. We should request that the | 243 // Press the button and fire the lock timer. We should request that the |
| 243 // screen be locked, but we should still be in the slow-close animation. | 244 // screen be locked, but we should still be in the slow-close animation. |
| 244 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 245 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 245 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 246 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 246 EXPECT_EQ(0, delegate_->num_lock_requests()); | 247 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 247 test_api_->trigger_lock_timeout(); | 248 test_api_->trigger_lock_timeout(); |
| 248 EXPECT_EQ(1, delegate_->num_lock_requests()); | 249 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 249 EXPECT_TRUE( | 250 EXPECT_TRUE( |
| 250 test_api_->ContainerGroupIsAnimated( | 251 test_api_->ContainerGroupIsAnimated( |
| 251 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 252 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 252 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 253 SessionStateAnimator::SLOW_CLOSE)); |
| 253 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 254 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 254 | 255 |
| 255 // Notify that we locked successfully. | 256 // Notify that we locked successfully. |
| 256 controller_->OnStartingLock(); | 257 controller_->OnStartingLock(); |
| 257 EXPECT_TRUE( | 258 EXPECT_TRUE( |
| 258 test_api_->ContainerGroupIsAnimated( | 259 test_api_->ContainerGroupIsAnimated( |
| 259 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 260 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 260 PowerButtonController::ANIMATION_FAST_CLOSE)); | 261 SessionStateAnimator::FAST_CLOSE)); |
| 261 EXPECT_TRUE( | 262 EXPECT_TRUE( |
| 262 test_api_->ContainerGroupIsAnimated( | 263 test_api_->ContainerGroupIsAnimated( |
| 263 PowerButtonController::SCREEN_LOCKER_CONTAINERS, | 264 SessionStateAnimator::SCREEN_LOCKER_CONTAINERS, |
| 264 PowerButtonController::ANIMATION_HIDE)); | 265 SessionStateAnimator::HIDE)); |
| 265 | 266 |
| 266 // Notify that the lock window is visible. We should make it fade in. | 267 // Notify that the lock window is visible. We should make it fade in. |
| 267 controller_->OnLockStateChanged(true); | 268 controller_->OnLockStateChanged(true); |
| 268 EXPECT_TRUE( | 269 EXPECT_TRUE( |
| 269 test_api_->ContainerGroupIsAnimated( | 270 test_api_->ContainerGroupIsAnimated( |
| 270 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 271 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 271 PowerButtonController::ANIMATION_FADE_IN)); | 272 SessionStateAnimator::FADE_IN)); |
| 272 | 273 |
| 273 // When we release the power button, the lock-to-shutdown timer should be | 274 // When we release the power button, the lock-to-shutdown timer should be |
| 274 // stopped. | 275 // stopped. |
| 275 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 276 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 276 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 277 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 277 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 278 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 278 | 279 |
| 279 // Notify that the screen has been unlocked. We should show the | 280 // Notify that the screen has been unlocked. We should show the |
| 280 // non-screen-locker windows and hide the background layer. | 281 // non-screen-locker windows and hide the background layer. |
| 281 controller_->OnLockStateChanged(false); | 282 controller_->OnLockStateChanged(false); |
| 282 EXPECT_TRUE( | 283 EXPECT_TRUE( |
| 283 test_api_->ContainerGroupIsAnimated( | 284 test_api_->ContainerGroupIsAnimated( |
| 284 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 285 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 285 PowerButtonController::ANIMATION_RESTORE)); | 286 SessionStateAnimator::RESTORE)); |
| 286 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 287 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 287 } | 288 } |
| 288 | 289 |
| 289 // Hold the power button down from the unlocked state to eventual shutdown. | 290 // Hold the power button down from the unlocked state to eventual shutdown. |
| 290 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 291 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
| 291 controller_->set_has_legacy_power_button_for_test(false); | 292 controller_->set_has_legacy_power_button_for_test(false); |
| 292 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 293 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 293 controller_->OnLockStateChanged(false); | 294 controller_->OnLockStateChanged(false); |
| 294 | 295 |
| 295 // Hold the power button and lock the screen. | 296 // Hold the power button and lock the screen. |
| 296 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 297 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 297 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 298 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 298 test_api_->trigger_lock_timeout(); | 299 test_api_->trigger_lock_timeout(); |
| 299 controller_->OnStartingLock(); | 300 controller_->OnStartingLock(); |
| 300 controller_->OnLockStateChanged(true); | 301 controller_->OnLockStateChanged(true); |
| 301 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 302 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 302 | 303 |
| 303 // When the lock-to-shutdown timeout fires, we should start the shutdown | 304 // When the lock-to-shutdown timeout fires, we should start the shutdown |
| 304 // timer. | 305 // timer. |
| 305 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 306 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 306 test_api_->trigger_lock_to_shutdown_timeout(); | 307 test_api_->trigger_lock_to_shutdown_timeout(); |
| 307 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 308 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 308 EXPECT_TRUE( | 309 EXPECT_TRUE( |
| 309 test_api_->ContainerGroupIsAnimated( | 310 test_api_->ContainerGroupIsAnimated( |
| 310 PowerButtonController::ALL_CONTAINERS, | 311 SessionStateAnimator::ALL_CONTAINERS, |
| 311 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 312 SessionStateAnimator::SLOW_CLOSE)); |
| 312 | 313 |
| 313 // Fire the shutdown timeout and check that we request shutdown. | 314 // Fire the shutdown timeout and check that we request shutdown. |
| 314 test_api_->trigger_shutdown_timeout(); | 315 test_api_->trigger_shutdown_timeout(); |
| 315 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 316 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 316 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 317 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 317 test_api_->trigger_real_shutdown_timeout(); | 318 test_api_->trigger_real_shutdown_timeout(); |
| 318 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 319 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 319 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 320 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 320 } | 321 } |
| 321 | 322 |
| 322 // Test that we handle the case where lock requests are ignored. | 323 // Test that we handle the case where lock requests are ignored. |
| 323 TEST_F(PowerButtonControllerTest, LockFail) { | 324 TEST_F(PowerButtonControllerTest, LockFail) { |
| 324 // We require animations to have a duration for this test. | 325 // We require animations to have a duration for this test. |
| 325 ui::LayerAnimator::set_disable_animations_for_test(false); | 326 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 326 | 327 |
| 327 controller_->set_has_legacy_power_button_for_test(false); | 328 controller_->set_has_legacy_power_button_for_test(false); |
| 328 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 329 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 329 controller_->OnLockStateChanged(false); | 330 controller_->OnLockStateChanged(false); |
| 330 | 331 |
| 331 // Hold the power button and lock the screen. | 332 // Hold the power button and lock the screen. |
| 332 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 333 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 333 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 334 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 334 EXPECT_TRUE( | 335 EXPECT_TRUE( |
| 335 test_api_->ContainerGroupIsAnimated( | 336 test_api_->ContainerGroupIsAnimated( |
| 336 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 337 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 337 PowerButtonController::ANIMATION_RESTORE)); | 338 SessionStateAnimator::RESTORE)); |
| 338 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 339 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 339 test_api_->trigger_lock_timeout(); | 340 test_api_->trigger_lock_timeout(); |
| 340 EXPECT_EQ(1, delegate_->num_lock_requests()); | 341 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 341 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 342 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
| 342 | 343 |
| 343 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 344 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
| 344 // been locked. | 345 // been locked. |
| 345 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 346 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 346 | 347 |
| 347 // Act as if the request timed out. We should restore the windows. | 348 // Act as if the request timed out. We should restore the windows. |
| 348 test_api_->trigger_lock_fail_timeout(); | 349 test_api_->trigger_lock_fail_timeout(); |
| 349 EXPECT_TRUE( | 350 EXPECT_TRUE( |
| 350 test_api_->ContainerGroupIsAnimated( | 351 test_api_->ContainerGroupIsAnimated( |
| 351 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 352 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 352 PowerButtonController::ANIMATION_RESTORE)); | 353 SessionStateAnimator::RESTORE)); |
| 353 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 354 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 354 } | 355 } |
| 355 | 356 |
| 356 // Test that we start the timer to hide the background layer when the power | 357 // Test that we start the timer to hide the background layer when the power |
| 357 // button is released, but that we cancel the timer if the button is pressed | 358 // button is released, but that we cancel the timer if the button is pressed |
| 358 // again before the timer has fired. | 359 // again before the timer has fired. |
| 359 TEST_F(PowerButtonControllerTest, CancelHideBackground) { | 360 TEST_F(PowerButtonControllerTest, CancelHideBackground) { |
| 360 controller_->set_has_legacy_power_button_for_test(false); | 361 controller_->set_has_legacy_power_button_for_test(false); |
| 361 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 362 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 362 controller_->OnLockStateChanged(false); | 363 controller_->OnLockStateChanged(false); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 388 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 389 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 389 EXPECT_EQ(0, delegate_->num_lock_requests()); | 390 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 390 | 391 |
| 391 // If we're logged in as a regular user, we should start the lock timer and | 392 // If we're logged in as a regular user, we should start the lock timer and |
| 392 // the pre-lock animation. | 393 // the pre-lock animation. |
| 393 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 394 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 394 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 395 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 395 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 396 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 396 EXPECT_TRUE( | 397 EXPECT_TRUE( |
| 397 test_api_->ContainerGroupIsAnimated( | 398 test_api_->ContainerGroupIsAnimated( |
| 398 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 399 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 399 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 400 SessionStateAnimator::SLOW_CLOSE)); |
| 400 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 401 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 401 | 402 |
| 402 // If the button is released immediately, we shouldn't lock the screen. | 403 // If the button is released immediately, we shouldn't lock the screen. |
| 403 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 404 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 404 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 405 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 405 EXPECT_TRUE( | 406 EXPECT_TRUE( |
| 406 test_api_->ContainerGroupIsAnimated( | 407 test_api_->ContainerGroupIsAnimated( |
| 407 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 408 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 408 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 409 SessionStateAnimator::UNDO_SLOW_CLOSE)); |
| 409 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 410 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 410 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); | 411 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); |
| 411 test_api_->trigger_hide_background_layer_timeout(); | 412 test_api_->trigger_hide_background_layer_timeout(); |
| 412 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 413 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 413 EXPECT_EQ(0, delegate_->num_lock_requests()); | 414 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 414 | 415 |
| 415 // Press the button again and let the lock timeout fire. We should request | 416 // Press the button again and let the lock timeout fire. We should request |
| 416 // that the screen be locked. | 417 // that the screen be locked. |
| 417 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 418 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 418 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 419 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 467 } |
| 467 | 468 |
| 468 // When the screen is locked without going through the usual power-button | 469 // When the screen is locked without going through the usual power-button |
| 469 // slow-close path (e.g. via the wrench menu), test that we still show the | 470 // slow-close path (e.g. via the wrench menu), test that we still show the |
| 470 // fast-close animation and display the background layer. | 471 // fast-close animation and display the background layer. |
| 471 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 472 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
| 472 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 473 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 473 controller_->OnStartingLock(); | 474 controller_->OnStartingLock(); |
| 474 EXPECT_TRUE( | 475 EXPECT_TRUE( |
| 475 test_api_->ContainerGroupIsAnimated( | 476 test_api_->ContainerGroupIsAnimated( |
| 476 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 477 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 477 PowerButtonController::ANIMATION_FAST_CLOSE)); | 478 SessionStateAnimator::FAST_CLOSE)); |
| 478 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 479 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 479 } | 480 } |
| 480 | 481 |
| 481 // When we hear that the process is exiting but we haven't had a chance to | 482 // When we hear that the process is exiting but we haven't had a chance to |
| 482 // display an animation, we should just blank the screen. | 483 // display an animation, we should just blank the screen. |
| 483 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 484 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
| 484 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 485 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 485 controller_->OnAppTerminating(); | 486 controller_->OnAppTerminating(); |
| 486 EXPECT_TRUE( | 487 EXPECT_TRUE( |
| 487 test_api_->ContainerGroupIsAnimated( | 488 test_api_->ContainerGroupIsAnimated( |
| 488 PowerButtonController::ALL_CONTAINERS, | 489 SessionStateAnimator::ALL_CONTAINERS, |
| 489 PowerButtonController::ANIMATION_HIDE)); | 490 SessionStateAnimator::HIDE)); |
| 490 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 491 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 491 EXPECT_FALSE(cursor_visible()); | 492 EXPECT_FALSE(cursor_visible()); |
| 492 } | 493 } |
| 493 | 494 |
| 494 // Test that we display the fast-close animation and shut down when we get an | 495 // Test that we display the fast-close animation and shut down when we get an |
| 495 // outside request to shut down (e.g. from the login or lock screen). | 496 // outside request to shut down (e.g. from the login or lock screen). |
| 496 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 497 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
| 497 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 498 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 498 controller_->RequestShutdown(); | 499 controller_->RequestShutdown(); |
| 499 EXPECT_TRUE( | 500 EXPECT_TRUE( |
| 500 test_api_->ContainerGroupIsAnimated( | 501 test_api_->ContainerGroupIsAnimated( |
| 501 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 502 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 502 PowerButtonController::ANIMATION_HIDE)); | 503 SessionStateAnimator::HIDE)); |
| 503 EXPECT_TRUE( | 504 EXPECT_TRUE( |
| 504 test_api_->ContainerGroupIsAnimated( | 505 test_api_->ContainerGroupIsAnimated( |
| 505 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 506 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 506 PowerButtonController::ANIMATION_FAST_CLOSE)); | 507 SessionStateAnimator::FAST_CLOSE)); |
| 507 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 508 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 508 EXPECT_FALSE(cursor_visible()); | 509 EXPECT_FALSE(cursor_visible()); |
| 509 | 510 |
| 510 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 511 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 511 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 512 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 512 test_api_->trigger_real_shutdown_timeout(); | 513 test_api_->trigger_real_shutdown_timeout(); |
| 513 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 514 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 514 } | 515 } |
| 515 | 516 |
| 516 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 517 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
| 517 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 518 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 518 controller_->OnLockStateChanged(true); | 519 controller_->OnLockStateChanged(true); |
| 519 controller_->RequestShutdown(); | 520 controller_->RequestShutdown(); |
| 520 EXPECT_TRUE( | 521 EXPECT_TRUE( |
| 521 test_api_->ContainerGroupIsAnimated( | 522 test_api_->ContainerGroupIsAnimated( |
| 522 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 523 SessionStateAnimator::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 523 PowerButtonController::ANIMATION_HIDE)); | 524 SessionStateAnimator::HIDE)); |
| 524 EXPECT_TRUE( | 525 EXPECT_TRUE( |
| 525 test_api_->ContainerGroupIsAnimated( | 526 test_api_->ContainerGroupIsAnimated( |
| 526 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 527 SessionStateAnimator::SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 527 PowerButtonController::ANIMATION_FAST_CLOSE)); | 528 SessionStateAnimator::FAST_CLOSE)); |
| 528 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); | 529 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); |
| 529 EXPECT_FALSE(cursor_visible()); | 530 EXPECT_FALSE(cursor_visible()); |
| 530 | 531 |
| 531 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 532 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 532 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 533 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 533 test_api_->trigger_real_shutdown_timeout(); | 534 test_api_->trigger_real_shutdown_timeout(); |
| 534 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 535 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 535 } | 536 } |
| 536 | 537 |
| 537 // Test that the background layer is resized in response to root window resizes. | 538 // Test that the background layer is resized in response to root window resizes. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 558 | 559 |
| 559 // After increasing the brightness to 10%, we should start the timer like | 560 // After increasing the brightness to 10%, we should start the timer like |
| 560 // usual. | 561 // usual. |
| 561 controller_->OnScreenBrightnessChanged(10.0); | 562 controller_->OnScreenBrightnessChanged(10.0); |
| 562 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 563 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 563 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 564 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 564 } | 565 } |
| 565 | 566 |
| 566 } // namespace test | 567 } // namespace test |
| 567 } // namespace ash | 568 } // namespace ash |
| OLD | NEW |