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