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_->ContainersAreAnimated( | 86 test_api_->ContainersAreAnimated( |
87 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 87 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
88 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 88 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
89 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 89 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
90 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); | 90 EXPECT_FALSE(test_api_->hide_black_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_->ContainersAreAnimated( | 97 test_api_->ContainersAreAnimated( |
98 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 98 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
99 PowerButtonController::ANIMATION_FAST_CLOSE)); | 99 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
100 EXPECT_TRUE( | 100 EXPECT_TRUE( |
101 test_api_->ContainersAreAnimated( | 101 test_api_->ContainersAreAnimated( |
102 PowerButtonController::LOCK_SCREEN_CONTAINERS, | 102 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
103 PowerButtonController::ANIMATION_HIDE)); | 103 SessionStateAnimator::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_->ContainersAreAnimated( | 108 test_api_->ContainersAreAnimated( |
109 PowerButtonController::GetAllLockScreenContainersMask(), | 109 SessionStateAnimator::GetAllLockScreenContainersMask(), |
110 PowerButtonController::ANIMATION_FADE_IN)); | 110 SessionStateAnimator::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 | 120 |
121 // Previously we're checking that the all containers group was animated which | 121 // Previously we're checking that the all containers group was animated which |
122 // was in fact checking that | 122 // was in fact checking that |
123 // 1. All user session containers have transform (including wallpaper). | 123 // 1. All user session containers have transform (including wallpaper). |
124 // They're in this state after lock. | 124 // They're in this state after lock. |
125 // 2. Screen locker and related containers are in fact animating | 125 // 2. Screen locker and related containers are in fact animating |
126 // (as shutdown is in progress). | 126 // (as shutdown is in progress). |
127 // With http://crbug.com/144737 we no longer animate user session wallpaper | 127 // With http://crbug.com/144737 we no longer animate user session wallpaper |
128 // during lock so it makes sense only to check that screen lock and related | 128 // during lock so it makes sense only to check that screen lock and related |
129 // containers are animated during shutdown. | 129 // containers are animated during shutdown. |
130 EXPECT_TRUE( | 130 EXPECT_TRUE( |
131 test_api_->ContainersAreAnimated( | 131 test_api_->ContainersAreAnimated( |
132 PowerButtonController::GetAllLockScreenContainersMask(), | 132 SessionStateAnimator::GetAllLockScreenContainersMask(), |
133 PowerButtonController::ANIMATION_FAST_CLOSE)); | 133 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
134 EXPECT_FALSE(cursor_visible()); | 134 EXPECT_FALSE(cursor_visible()); |
135 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 135 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
136 test_api_->trigger_real_shutdown_timeout(); | 136 test_api_->trigger_real_shutdown_timeout(); |
137 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 137 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
138 } | 138 } |
139 | 139 |
140 // Test that we start shutting down immediately if the power button is pressed | 140 // Test that we start shutting down immediately if the power button is pressed |
141 // while we're not logged in on an unofficial system. | 141 // while we're not logged in on an unofficial system. |
142 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { | 142 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { |
143 controller_->set_has_legacy_power_button_for_test(true); | 143 controller_->set_has_legacy_power_button_for_test(true); |
(...skipping 20 matching lines...) Expand all Loading... |
164 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 164 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
165 controller_->OnLockStateChanged(false); | 165 controller_->OnLockStateChanged(false); |
166 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 166 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
167 | 167 |
168 // Press the power button and check that we start the shutdown timer. | 168 // Press the power button and check that we start the shutdown timer. |
169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
170 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 170 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
171 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 171 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
172 EXPECT_TRUE( | 172 EXPECT_TRUE( |
173 test_api_->ContainersAreAnimated( | 173 test_api_->ContainersAreAnimated( |
174 PowerButtonController::GetAllContainersMask(), | 174 SessionStateAnimator::GetAllContainersMask(), |
175 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 175 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
176 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 176 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
177 | 177 |
178 // Release the power button before the shutdown timer fires. | 178 // Release the power button before the shutdown timer fires. |
179 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 179 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
180 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 180 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
181 EXPECT_TRUE( | 181 EXPECT_TRUE( |
182 test_api_->ContainersAreAnimated( | 182 test_api_->ContainersAreAnimated( |
183 PowerButtonController::GetAllContainersMask(), | 183 SessionStateAnimator::GetAllContainersMask(), |
184 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 184 SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
185 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 185 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
186 | 186 |
187 // We should re-hide the black layer after waiting long enough for | 187 // We should re-hide the black layer after waiting long enough for |
188 // the animation to finish. | 188 // the animation to finish. |
189 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); | 189 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
190 test_api_->trigger_hide_black_layer_timeout(); | 190 test_api_->TriggerHideBlackLayerTimeout(); |
191 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 191 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
192 | 192 |
193 // Press the button again and make the shutdown timeout fire this time. | 193 // Press the button again and make the shutdown timeout fire this time. |
194 // Check that we start the timer for actually requesting the shutdown. | 194 // Check that we start the timer for actually requesting the shutdown. |
195 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 195 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
196 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 196 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
197 test_api_->trigger_shutdown_timeout(); | 197 test_api_->trigger_shutdown_timeout(); |
198 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 198 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
199 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 199 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
200 EXPECT_TRUE( | 200 EXPECT_TRUE( |
201 test_api_->ContainersAreAnimated( | 201 test_api_->ContainersAreAnimated( |
202 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 202 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
203 PowerButtonController::ANIMATION_HIDE)); | 203 SessionStateAnimator::ANIMATION_HIDE)); |
204 EXPECT_TRUE( | 204 EXPECT_TRUE( |
205 test_api_->ContainersAreAnimated( | 205 test_api_->ContainersAreAnimated( |
206 PowerButtonController::GetAllLockScreenContainersMask(), | 206 SessionStateAnimator::GetAllLockScreenContainersMask(), |
207 PowerButtonController::ANIMATION_FAST_CLOSE)); | 207 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
208 | 208 |
209 // When the timout fires, we should request a shutdown. | 209 // When the timout fires, we should request a shutdown. |
210 test_api_->trigger_real_shutdown_timeout(); | 210 test_api_->trigger_real_shutdown_timeout(); |
211 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 211 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
212 } | 212 } |
213 | 213 |
214 // Test that we lock the screen and deal with unlocking correctly. | 214 // Test that we lock the screen and deal with unlocking correctly. |
215 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 215 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
216 controller_->set_has_legacy_power_button_for_test(false); | 216 controller_->set_has_legacy_power_button_for_test(false); |
217 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 217 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
218 controller_->OnLockStateChanged(false); | 218 controller_->OnLockStateChanged(false); |
219 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 219 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
220 | 220 |
221 // We should initially be showing the screen locker containers, since they | 221 // We should initially be showing the screen locker containers, since they |
222 // also contain login-related windows that we want to show during the | 222 // also contain login-related windows that we want to show during the |
223 // logging-in animation. | 223 // logging-in animation. |
224 EXPECT_TRUE( | 224 EXPECT_TRUE( |
225 test_api_->ContainersAreAnimated( | 225 test_api_->ContainersAreAnimated( |
226 PowerButtonController::LOCK_SCREEN_CONTAINERS, | 226 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
227 PowerButtonController::ANIMATION_RESTORE)); | 227 SessionStateAnimator::ANIMATION_RESTORE)); |
228 | 228 |
229 // Press the power button and check that the lock timer is started and that we | 229 // Press the power button and check that the lock timer is started and that we |
230 // start scaling the non-screen-locker containers. | 230 // start scaling the non-screen-locker containers. |
231 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 231 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
232 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 232 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
233 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 233 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
234 EXPECT_TRUE( | 234 EXPECT_TRUE( |
235 test_api_->ContainersAreAnimated( | 235 test_api_->ContainersAreAnimated( |
236 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 236 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
237 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 237 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
238 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 238 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
239 | 239 |
240 // Release the button before the lock timer fires. | 240 // Release the button before the lock timer fires. |
241 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 241 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
242 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 242 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
243 EXPECT_TRUE( | 243 EXPECT_TRUE( |
244 test_api_->ContainersAreAnimated( | 244 test_api_->ContainersAreAnimated( |
245 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 245 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
246 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 246 SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
247 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 247 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
248 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); | 248 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
249 test_api_->trigger_hide_black_layer_timeout(); | 249 test_api_->trigger_hide_black_layer_timeout(); |
250 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 250 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
251 | 251 |
252 // Press the button and fire the lock timer. We should request that the | 252 // Press the button and fire the lock timer. We should request that the |
253 // screen be locked, but we should still be in the slow-close animation. | 253 // screen be locked, but we should still be in the slow-close animation. |
254 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 254 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
255 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 255 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
256 EXPECT_EQ(0, delegate_->num_lock_requests()); | 256 EXPECT_EQ(0, delegate_->num_lock_requests()); |
257 test_api_->trigger_lock_timeout(); | 257 test_api_->trigger_lock_timeout(); |
258 EXPECT_EQ(1, delegate_->num_lock_requests()); | 258 EXPECT_EQ(1, delegate_->num_lock_requests()); |
259 EXPECT_TRUE( | 259 EXPECT_TRUE( |
260 test_api_->ContainersAreAnimated( | 260 test_api_->ContainersAreAnimated( |
261 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 261 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
262 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 262 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
263 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 263 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
264 | 264 |
265 // Notify that we locked successfully. | 265 // Notify that we locked successfully. |
266 controller_->OnStartingLock(); | 266 controller_->OnStartingLock(); |
267 EXPECT_TRUE( | 267 EXPECT_TRUE( |
268 test_api_->ContainersAreAnimated( | 268 test_api_->ContainersAreAnimated( |
269 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 269 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
270 PowerButtonController::ANIMATION_FAST_CLOSE)); | 270 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
271 EXPECT_TRUE( | 271 EXPECT_TRUE( |
272 test_api_->ContainersAreAnimated( | 272 test_api_->ContainersAreAnimated( |
273 PowerButtonController::LOCK_SCREEN_CONTAINERS, | 273 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
274 PowerButtonController::ANIMATION_HIDE)); | 274 SessionStateAnimator::ANIMATION_HIDE)); |
275 | 275 |
276 // Notify that the lock window is visible. We should make it fade in. | 276 // Notify that the lock window is visible. We should make it fade in. |
277 controller_->OnLockStateChanged(true); | 277 controller_->OnLockStateChanged(true); |
278 EXPECT_TRUE( | 278 EXPECT_TRUE( |
279 test_api_->ContainersAreAnimated( | 279 test_api_->ContainersAreAnimated( |
280 PowerButtonController::GetAllLockScreenContainersMask(), | 280 SessionStateAnimator::GetAllLockScreenContainersMask(), |
281 PowerButtonController::ANIMATION_FADE_IN)); | 281 SessionStateAnimator::ANIMATION_FADE_IN)); |
282 | 282 |
283 // When we release the power button, the lock-to-shutdown timer should be | 283 // When we release the power button, the lock-to-shutdown timer should be |
284 // stopped. | 284 // stopped. |
285 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 285 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
286 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 286 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
287 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 287 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
288 | 288 |
289 // Notify that the screen has been unlocked. We should show the | 289 // Notify that the screen has been unlocked. We should show the |
290 // non-screen-locker windows and hide the black layer. | 290 // non-screen-locker windows and hide the black layer. |
291 controller_->OnLockStateChanged(false); | 291 controller_->OnLockStateChanged(false); |
292 EXPECT_TRUE( | 292 EXPECT_TRUE( |
293 test_api_->ContainersAreAnimated( | 293 test_api_->ContainersAreAnimated( |
294 PowerButtonController::DESKTOP_BACKGROUND | | 294 SessionStateAnimator::DESKTOP_BACKGROUND | |
295 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 295 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
296 PowerButtonController::ANIMATION_RESTORE)); | 296 SessionStateAnimator::ANIMATION_RESTORE)); |
297 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 297 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
298 } | 298 } |
299 | 299 |
300 // Hold the power button down from the unlocked state to eventual shutdown. | 300 // Hold the power button down from the unlocked state to eventual shutdown. |
301 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 301 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
302 controller_->set_has_legacy_power_button_for_test(false); | 302 controller_->set_has_legacy_power_button_for_test(false); |
303 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 303 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
304 controller_->OnLockStateChanged(false); | 304 controller_->OnLockStateChanged(false); |
305 | 305 |
306 // Hold the power button and lock the screen. | 306 // Hold the power button and lock the screen. |
307 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 307 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
308 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 308 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
309 test_api_->trigger_lock_timeout(); | 309 test_api_->trigger_lock_timeout(); |
310 controller_->OnStartingLock(); | 310 controller_->OnStartingLock(); |
311 controller_->OnLockStateChanged(true); | 311 controller_->OnLockStateChanged(true); |
312 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 312 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
313 | 313 |
314 // When the lock-to-shutdown timeout fires, we should start the shutdown | 314 // When the lock-to-shutdown timeout fires, we should start the shutdown |
315 // timer. | 315 // timer. |
316 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 316 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
317 test_api_->trigger_lock_to_shutdown_timeout(); | 317 test_api_->trigger_lock_to_shutdown_timeout(); |
318 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 318 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
319 EXPECT_TRUE( | 319 EXPECT_TRUE( |
320 test_api_->ContainersAreAnimated( | 320 test_api_->ContainersAreAnimated( |
321 PowerButtonController::GetAllContainersMask(), | 321 SessionStateAnimator::GetAllContainersMask(), |
322 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 322 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
323 | 323 |
324 // Fire the shutdown timeout and check that we request shutdown. | 324 // Fire the shutdown timeout and check that we request shutdown. |
325 test_api_->trigger_shutdown_timeout(); | 325 test_api_->trigger_shutdown_timeout(); |
326 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 326 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
327 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 327 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
328 test_api_->trigger_real_shutdown_timeout(); | 328 test_api_->trigger_real_shutdown_timeout(); |
329 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 329 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
330 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 330 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
331 } | 331 } |
332 | 332 |
333 // Test that we handle the case where lock requests are ignored. | 333 // Test that we handle the case where lock requests are ignored. |
334 TEST_F(PowerButtonControllerTest, LockFail) { | 334 TEST_F(PowerButtonControllerTest, LockFail) { |
335 // We require animations to have a duration for this test. | 335 // We require animations to have a duration for this test. |
336 ui::LayerAnimator::set_disable_animations_for_test(false); | 336 ui::LayerAnimator::set_disable_animations_for_test(false); |
337 | 337 |
338 controller_->set_has_legacy_power_button_for_test(false); | 338 controller_->set_has_legacy_power_button_for_test(false); |
339 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 339 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
340 controller_->OnLockStateChanged(false); | 340 controller_->OnLockStateChanged(false); |
341 | 341 |
342 // Hold the power button and lock the screen. | 342 // Hold the power button and lock the screen. |
343 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 343 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
344 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 344 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
345 EXPECT_TRUE( | 345 EXPECT_TRUE( |
346 test_api_->ContainersAreAnimated( | 346 test_api_->ContainersAreAnimated( |
347 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 347 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
348 PowerButtonController::ANIMATION_RESTORE)); | 348 SessionStateAnimator::ANIMATION_RESTORE)); |
349 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 349 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
350 test_api_->trigger_lock_timeout(); | 350 test_api_->trigger_lock_timeout(); |
351 EXPECT_EQ(1, delegate_->num_lock_requests()); | 351 EXPECT_EQ(1, delegate_->num_lock_requests()); |
352 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 352 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
353 | 353 |
354 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 354 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
355 // been locked. | 355 // been locked. |
356 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 356 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
357 | 357 |
358 // Act as if the request timed out. We should restore the windows. | 358 // Act as if the request timed out. We should restore the windows. |
359 test_api_->trigger_lock_fail_timeout(); | 359 test_api_->trigger_lock_fail_timeout(); |
360 EXPECT_TRUE( | 360 EXPECT_TRUE( |
361 test_api_->ContainersAreAnimated( | 361 test_api_->ContainersAreAnimated( |
362 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 362 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
363 PowerButtonController::ANIMATION_RESTORE)); | 363 SessionStateAnimator::ANIMATION_RESTORE)); |
364 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 364 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
365 } | 365 } |
366 | 366 |
367 // Test that we start the timer to hide the black layer when the power | 367 // Test that we start the timer to hide the black layer when the power |
368 // button is released, but that we cancel the timer if the button is pressed | 368 // button is released, but that we cancel the timer if the button is pressed |
369 // again before the timer has fired. | 369 // again before the timer has fired. |
370 TEST_F(PowerButtonControllerTest, CancelHideBackground) { | 370 TEST_F(PowerButtonControllerTest, CancelHideBackground) { |
371 controller_->set_has_legacy_power_button_for_test(false); | 371 controller_->set_has_legacy_power_button_for_test(false); |
372 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 372 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
373 controller_->OnLockStateChanged(false); | 373 controller_->OnLockStateChanged(false); |
(...skipping 25 matching lines...) Expand all Loading... |
399 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 399 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
400 EXPECT_EQ(0, delegate_->num_lock_requests()); | 400 EXPECT_EQ(0, delegate_->num_lock_requests()); |
401 | 401 |
402 // If we're logged in as a regular user, we should start the lock timer and | 402 // If we're logged in as a regular user, we should start the lock timer and |
403 // the pre-lock animation. | 403 // the pre-lock animation. |
404 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 404 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
405 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 405 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
406 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 406 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
407 EXPECT_TRUE( | 407 EXPECT_TRUE( |
408 test_api_->ContainersAreAnimated( | 408 test_api_->ContainersAreAnimated( |
409 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 409 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
410 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 410 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
411 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 411 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
412 | 412 |
413 // If the button is released immediately, we shouldn't lock the screen. | 413 // If the button is released immediately, we shouldn't lock the screen. |
414 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 414 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
415 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 415 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
416 EXPECT_TRUE( | 416 EXPECT_TRUE( |
417 test_api_->ContainersAreAnimated( | 417 test_api_->ContainersAreAnimated( |
418 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 418 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
419 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 419 SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
420 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 420 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
421 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); | 421 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
422 test_api_->trigger_hide_black_layer_timeout(); | 422 test_api_->trigger_hide_black_layer_timeout(); |
423 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); | 423 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
424 EXPECT_EQ(0, delegate_->num_lock_requests()); | 424 EXPECT_EQ(0, delegate_->num_lock_requests()); |
425 | 425 |
426 // Press the button again and let the lock timeout fire. We should request | 426 // Press the button again and let the lock timeout fire. We should request |
427 // that the screen be locked. | 427 // that the screen be locked. |
428 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 428 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
429 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 429 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 477 } |
478 | 478 |
479 // When the screen is locked without going through the usual power-button | 479 // When the screen is locked without going through the usual power-button |
480 // slow-close path (e.g. via the wrench menu), test that we still show the | 480 // slow-close path (e.g. via the wrench menu), test that we still show the |
481 // fast-close animation and display the black layer. | 481 // fast-close animation and display the black layer. |
482 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 482 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
483 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 483 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
484 controller_->OnStartingLock(); | 484 controller_->OnStartingLock(); |
485 EXPECT_TRUE( | 485 EXPECT_TRUE( |
486 test_api_->ContainersAreAnimated( | 486 test_api_->ContainersAreAnimated( |
487 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 487 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
488 PowerButtonController::ANIMATION_FAST_CLOSE)); | 488 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
489 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 489 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
490 } | 490 } |
491 | 491 |
492 // When we hear that the process is exiting but we haven't had a chance to | 492 // When we hear that the process is exiting but we haven't had a chance to |
493 // display an animation, we should just blank the screen. | 493 // display an animation, we should just blank the screen. |
494 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 494 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
495 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 495 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
496 controller_->OnAppTerminating(); | 496 controller_->OnAppTerminating(); |
497 EXPECT_TRUE( | 497 EXPECT_TRUE( |
498 test_api_->ContainersAreAnimated( | 498 test_api_->ContainersAreAnimated( |
499 PowerButtonController::GetAllContainersMask(), | 499 SessionStateAnimator::GetAllContainersMask(), |
500 PowerButtonController::ANIMATION_HIDE)); | 500 SessionStateAnimator::ANIMATION_HIDE)); |
501 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 501 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
502 EXPECT_FALSE(cursor_visible()); | 502 EXPECT_FALSE(cursor_visible()); |
503 } | 503 } |
504 | 504 |
505 // Test that we display the fast-close animation and shut down when we get an | 505 // Test that we display the fast-close animation and shut down when we get an |
506 // outside request to shut down (e.g. from the login or lock screen). | 506 // outside request to shut down (e.g. from the login or lock screen). |
507 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 507 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
508 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 508 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
509 controller_->RequestShutdown(); | 509 controller_->RequestShutdown(); |
510 EXPECT_TRUE( | 510 EXPECT_TRUE( |
511 test_api_->ContainersAreAnimated( | 511 test_api_->ContainersAreAnimated( |
512 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 512 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
513 PowerButtonController::ANIMATION_HIDE)); | 513 SessionStateAnimator::ANIMATION_HIDE)); |
514 EXPECT_TRUE( | 514 EXPECT_TRUE( |
515 test_api_->ContainersAreAnimated( | 515 test_api_->ContainersAreAnimated( |
516 PowerButtonController::GetAllLockScreenContainersMask(), | 516 SessionStateAnimator::GetAllLockScreenContainersMask(), |
517 PowerButtonController::ANIMATION_FAST_CLOSE)); | 517 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
518 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 518 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
519 EXPECT_FALSE(cursor_visible()); | 519 EXPECT_FALSE(cursor_visible()); |
520 | 520 |
521 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 521 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
522 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 522 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
523 test_api_->trigger_real_shutdown_timeout(); | 523 test_api_->trigger_real_shutdown_timeout(); |
524 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 524 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
525 } | 525 } |
526 | 526 |
527 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 527 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
528 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 528 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
529 controller_->OnLockStateChanged(true); | 529 controller_->OnLockStateChanged(true); |
530 controller_->RequestShutdown(); | 530 controller_->RequestShutdown(); |
531 EXPECT_TRUE( | 531 EXPECT_TRUE( |
532 test_api_->ContainersAreAnimated( | 532 test_api_->ContainersAreAnimated( |
533 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS, | 533 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
534 PowerButtonController::ANIMATION_HIDE)); | 534 SessionStateAnimator::ANIMATION_HIDE)); |
535 EXPECT_TRUE( | 535 EXPECT_TRUE( |
536 test_api_->ContainersAreAnimated( | 536 test_api_->ContainersAreAnimated( |
537 PowerButtonController::GetAllLockScreenContainersMask(), | 537 SessionStateAnimator::GetAllLockScreenContainersMask(), |
538 PowerButtonController::ANIMATION_FAST_CLOSE)); | 538 SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
539 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 539 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
540 EXPECT_FALSE(cursor_visible()); | 540 EXPECT_FALSE(cursor_visible()); |
541 | 541 |
542 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 542 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
543 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 543 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
544 test_api_->trigger_real_shutdown_timeout(); | 544 test_api_->trigger_real_shutdown_timeout(); |
545 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 545 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
546 } | 546 } |
547 | 547 |
548 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { | 548 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { |
549 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 549 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
550 controller_->OnLockStateChanged(true); | 550 controller_->OnLockStateChanged(true); |
551 | 551 |
552 // Press the power button and check that we start the shutdown timer. | 552 // Press the power button and check that we start the shutdown timer. |
553 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 553 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
554 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 554 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
555 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 555 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
556 EXPECT_TRUE( | 556 EXPECT_TRUE( |
557 test_api_->ContainersAreAnimated( | 557 test_api_->ContainersAreAnimated( |
558 PowerButtonController::GetAllContainersMask(), | 558 SessionStateAnimator::GetAllContainersMask(), |
559 PowerButtonController::ANIMATION_SLOW_CLOSE)); | 559 SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
560 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 560 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
561 | 561 |
562 // Release the power button before the shutdown timer fires. | 562 // Release the power button before the shutdown timer fires. |
563 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 563 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
564 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 564 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
565 EXPECT_TRUE( | 565 EXPECT_TRUE( |
566 test_api_->ContainersAreAnimated( | 566 test_api_->ContainersAreAnimated( |
567 PowerButtonController::GetAllLockScreenContainersMask(), | 567 SessionStateAnimator::GetAllLockScreenContainersMask(), |
568 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | 568 SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
569 EXPECT_TRUE( | 569 EXPECT_TRUE( |
570 test_api_->ContainersAreAnimated( | 570 test_api_->ContainersAreAnimated( |
571 PowerButtonController::DESKTOP_BACKGROUND, | 571 SessionStateAnimator::DESKTOP_BACKGROUND, |
572 PowerButtonController::ANIMATION_RESTORE)); | 572 SessionStateAnimator::ANIMATION_RESTORE)); |
573 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); | 573 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
574 } | 574 } |
575 | 575 |
576 // Test that the black layer is resized in response to root window resizes. | 576 // Test that the black layer is resized in response to root window resizes. |
577 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { | 577 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { |
578 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 578 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
579 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), | 579 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), |
580 test_api_->GetBlackLayerBounds().ToString()); | 580 test_api_->GetBlackLayerBounds().ToString()); |
581 | 581 |
582 const gfx::Size kNewSize(400, 300); | 582 const gfx::Size kNewSize(400, 300); |
(...skipping 14 matching lines...) Expand all Loading... |
597 | 597 |
598 // After increasing the brightness to 10%, we should start the timer like | 598 // After increasing the brightness to 10%, we should start the timer like |
599 // usual. | 599 // usual. |
600 controller_->OnScreenBrightnessChanged(10.0); | 600 controller_->OnScreenBrightnessChanged(10.0); |
601 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 601 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
602 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 602 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
603 } | 603 } |
604 | 604 |
605 } // namespace test | 605 } // namespace test |
606 } // namespace ash | 606 } // namespace ash |
OLD | NEW |