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

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

Issue 10008074: Cancel partial screenshot UI when lock happens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: coding style fix Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/power_button_controller.h" 5 #include "ash/wm/power_button_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 private: 60 private:
61 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); 61 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest);
62 }; 62 };
63 63
64 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't 64 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
65 // correctly report power button releases. We should lock immediately the first 65 // correctly report power button releases. We should lock immediately the first
66 // time the button is pressed and shut down when it's pressed from the locked 66 // time the button is pressed and shut down when it's pressed from the locked
67 // state. 67 // state.
68 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { 68 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
69 controller_->set_has_legacy_power_button_for_test(true); 69 controller_->set_has_legacy_power_button_for_test(true);
70 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 70 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
71 controller_->OnLockStateChange(false); 71 controller_->OnLockStateChanged(false);
72 72
73 // We should request that the screen be locked immediately after seeing the 73 // We should request that the screen be locked immediately after seeing the
74 // power button get pressed. 74 // power button get pressed.
75 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 75 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
76 EXPECT_TRUE( 76 EXPECT_TRUE(
77 test_api_->ContainerGroupIsAnimated( 77 test_api_->ContainerGroupIsAnimated(
78 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 78 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
79 PowerButtonController::ANIMATION_SLOW_CLOSE)); 79 PowerButtonController::ANIMATION_SLOW_CLOSE));
80 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 80 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
81 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); 81 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running());
82 EXPECT_FALSE(test_api_->lock_timer_is_running()); 82 EXPECT_FALSE(test_api_->lock_timer_is_running());
83 EXPECT_EQ(1, delegate_->num_lock_requests()); 83 EXPECT_EQ(1, delegate_->num_lock_requests());
84 84
85 // Notify that we locked successfully. 85 // Notify that we locked successfully.
86 controller_->OnStartingLock(); 86 controller_->OnStartingLock();
87 EXPECT_TRUE( 87 EXPECT_TRUE(
88 test_api_->ContainerGroupIsAnimated( 88 test_api_->ContainerGroupIsAnimated(
89 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 89 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
90 PowerButtonController::ANIMATION_FAST_CLOSE)); 90 PowerButtonController::ANIMATION_FAST_CLOSE));
91 EXPECT_TRUE( 91 EXPECT_TRUE(
92 test_api_->ContainerGroupIsAnimated( 92 test_api_->ContainerGroupIsAnimated(
93 PowerButtonController::SCREEN_LOCKER_CONTAINERS, 93 PowerButtonController::SCREEN_LOCKER_CONTAINERS,
94 PowerButtonController::ANIMATION_HIDE)); 94 PowerButtonController::ANIMATION_HIDE));
95 95
96 // Notify that the lock window is visible. We should make it fade in. 96 // Notify that the lock window is visible. We should make it fade in.
97 controller_->OnLockStateChange(true); 97 controller_->OnLockStateChanged(true);
98 EXPECT_TRUE( 98 EXPECT_TRUE(
99 test_api_->ContainerGroupIsAnimated( 99 test_api_->ContainerGroupIsAnimated(
100 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, 100 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS,
101 PowerButtonController::ANIMATION_FADE_IN)); 101 PowerButtonController::ANIMATION_FADE_IN));
102 102
103 // We shouldn't progress towards the shutdown state, however. 103 // We shouldn't progress towards the shutdown state, however.
104 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 104 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
105 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 105 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
106 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 106 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
107 107
108 // Hold the button again and check that we start shutting down. 108 // Hold the button again and check that we start shutting down.
109 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 109 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
110 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 110 EXPECT_EQ(0, delegate_->num_shutdown_requests());
111 EXPECT_TRUE( 111 EXPECT_TRUE(
112 test_api_->ContainerGroupIsAnimated( 112 test_api_->ContainerGroupIsAnimated(
113 PowerButtonController::ALL_CONTAINERS, 113 PowerButtonController::ALL_CONTAINERS,
114 PowerButtonController::ANIMATION_FAST_CLOSE)); 114 PowerButtonController::ANIMATION_FAST_CLOSE));
115 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown()); 115 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown());
116 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 116 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
117 test_api_->trigger_real_shutdown_timeout(); 117 test_api_->trigger_real_shutdown_timeout();
118 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 118 EXPECT_EQ(1, delegate_->num_shutdown_requests());
119 } 119 }
120 120
121 // Test that we start shutting down immediately if the power button is pressed 121 // Test that we start shutting down immediately if the power button is pressed
122 // while we're not logged in on an unofficial system. 122 // while we're not logged in on an unofficial system.
123 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { 123 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) {
124 controller_->set_has_legacy_power_button_for_test(true); 124 controller_->set_has_legacy_power_button_for_test(true);
125 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 125 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
126 controller_->OnLockStateChange(false); 126 controller_->OnLockStateChanged(false);
127 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 127 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
128 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 128 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
129 } 129 }
130 130
131 // 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
132 // while we're logged in as a guest on an unofficial system. 132 // while we're logged in as a guest on an unofficial system.
133 TEST_F(PowerButtonControllerTest, LegacyGuest) { 133 TEST_F(PowerButtonControllerTest, LegacyGuest) {
134 controller_->set_has_legacy_power_button_for_test(true); 134 controller_->set_has_legacy_power_button_for_test(true);
135 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); 135 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
136 controller_->OnLockStateChange(false); 136 controller_->OnLockStateChanged(false);
137 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 137 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
138 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 138 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
139 } 139 }
140 140
141 // When we hold the power button while the user isn't logged in, we should shut 141 // When we hold the power button while the user isn't logged in, we should shut
142 // down the machine directly. 142 // down the machine directly.
143 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { 143 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) {
144 controller_->set_has_legacy_power_button_for_test(false); 144 controller_->set_has_legacy_power_button_for_test(false);
145 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 145 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
146 controller_->OnLockStateChange(false); 146 controller_->OnLockStateChanged(false);
147 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 147 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
148 148
149 // Press the power button and check that we start the shutdown timer. 149 // Press the power button and check that we start the shutdown timer.
150 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 150 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
151 EXPECT_FALSE(test_api_->lock_timer_is_running()); 151 EXPECT_FALSE(test_api_->lock_timer_is_running());
152 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 152 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
153 EXPECT_TRUE( 153 EXPECT_TRUE(
154 test_api_->ContainerGroupIsAnimated( 154 test_api_->ContainerGroupIsAnimated(
155 PowerButtonController::ALL_CONTAINERS, 155 PowerButtonController::ALL_CONTAINERS,
156 PowerButtonController::ANIMATION_SLOW_CLOSE)); 156 PowerButtonController::ANIMATION_SLOW_CLOSE));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 PowerButtonController::ANIMATION_FAST_CLOSE)); 188 PowerButtonController::ANIMATION_FAST_CLOSE));
189 189
190 // When the timout fires, we should request a shutdown. 190 // When the timout fires, we should request a shutdown.
191 test_api_->trigger_real_shutdown_timeout(); 191 test_api_->trigger_real_shutdown_timeout();
192 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 192 EXPECT_EQ(1, delegate_->num_shutdown_requests());
193 } 193 }
194 194
195 // Test that we lock the screen and deal with unlocking correctly. 195 // Test that we lock the screen and deal with unlocking correctly.
196 TEST_F(PowerButtonControllerTest, LockAndUnlock) { 196 TEST_F(PowerButtonControllerTest, LockAndUnlock) {
197 controller_->set_has_legacy_power_button_for_test(false); 197 controller_->set_has_legacy_power_button_for_test(false);
198 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 198 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
199 controller_->OnLockStateChange(false); 199 controller_->OnLockStateChanged(false);
200 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 200 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
201 201
202 // We should initially be showing the screen locker containers, since they 202 // We should initially be showing the screen locker containers, since they
203 // also contain login-related windows that we want to show during the 203 // also contain login-related windows that we want to show during the
204 // logging-in animation. 204 // logging-in animation.
205 EXPECT_TRUE( 205 EXPECT_TRUE(
206 test_api_->ContainerGroupIsAnimated( 206 test_api_->ContainerGroupIsAnimated(
207 PowerButtonController::SCREEN_LOCKER_CONTAINERS, 207 PowerButtonController::SCREEN_LOCKER_CONTAINERS,
208 PowerButtonController::ANIMATION_RESTORE)); 208 PowerButtonController::ANIMATION_RESTORE));
209 209
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 EXPECT_TRUE( 248 EXPECT_TRUE(
249 test_api_->ContainerGroupIsAnimated( 249 test_api_->ContainerGroupIsAnimated(
250 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 250 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
251 PowerButtonController::ANIMATION_FAST_CLOSE)); 251 PowerButtonController::ANIMATION_FAST_CLOSE));
252 EXPECT_TRUE( 252 EXPECT_TRUE(
253 test_api_->ContainerGroupIsAnimated( 253 test_api_->ContainerGroupIsAnimated(
254 PowerButtonController::SCREEN_LOCKER_CONTAINERS, 254 PowerButtonController::SCREEN_LOCKER_CONTAINERS,
255 PowerButtonController::ANIMATION_HIDE)); 255 PowerButtonController::ANIMATION_HIDE));
256 256
257 // Notify that the lock window is visible. We should make it fade in. 257 // Notify that the lock window is visible. We should make it fade in.
258 controller_->OnLockStateChange(true); 258 controller_->OnLockStateChanged(true);
259 EXPECT_TRUE( 259 EXPECT_TRUE(
260 test_api_->ContainerGroupIsAnimated( 260 test_api_->ContainerGroupIsAnimated(
261 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, 261 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS,
262 PowerButtonController::ANIMATION_FADE_IN)); 262 PowerButtonController::ANIMATION_FADE_IN));
263 263
264 // When we release the power button, the lock-to-shutdown timer should be 264 // When we release the power button, the lock-to-shutdown timer should be
265 // stopped. 265 // stopped.
266 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 266 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
267 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 267 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
268 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 268 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
269 269
270 // Notify that the screen has been unlocked. We should show the 270 // Notify that the screen has been unlocked. We should show the
271 // non-screen-locker windows and hide the background layer. 271 // non-screen-locker windows and hide the background layer.
272 controller_->OnLockStateChange(false); 272 controller_->OnLockStateChanged(false);
273 EXPECT_TRUE( 273 EXPECT_TRUE(
274 test_api_->ContainerGroupIsAnimated( 274 test_api_->ContainerGroupIsAnimated(
275 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 275 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
276 PowerButtonController::ANIMATION_RESTORE)); 276 PowerButtonController::ANIMATION_RESTORE));
277 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 277 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
278 } 278 }
279 279
280 // Hold the power button down from the unlocked state to eventual shutdown. 280 // Hold the power button down from the unlocked state to eventual shutdown.
281 TEST_F(PowerButtonControllerTest, LockToShutdown) { 281 TEST_F(PowerButtonControllerTest, LockToShutdown) {
282 controller_->set_has_legacy_power_button_for_test(false); 282 controller_->set_has_legacy_power_button_for_test(false);
283 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 283 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
284 controller_->OnLockStateChange(false); 284 controller_->OnLockStateChanged(false);
285 285
286 // Hold the power button and lock the screen. 286 // Hold the power button and lock the screen.
287 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 287 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
288 EXPECT_TRUE(test_api_->lock_timer_is_running()); 288 EXPECT_TRUE(test_api_->lock_timer_is_running());
289 test_api_->trigger_lock_timeout(); 289 test_api_->trigger_lock_timeout();
290 controller_->OnStartingLock(); 290 controller_->OnStartingLock();
291 controller_->OnLockStateChange(true); 291 controller_->OnLockStateChanged(true);
292 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 292 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
293 293
294 // When the lock-to-shutdown timeout fires, we should start the shutdown 294 // When the lock-to-shutdown timeout fires, we should start the shutdown
295 // timer. 295 // timer.
296 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 296 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
297 test_api_->trigger_lock_to_shutdown_timeout(); 297 test_api_->trigger_lock_to_shutdown_timeout();
298 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 298 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
299 EXPECT_TRUE( 299 EXPECT_TRUE(
300 test_api_->ContainerGroupIsAnimated( 300 test_api_->ContainerGroupIsAnimated(
301 PowerButtonController::ALL_CONTAINERS, 301 PowerButtonController::ALL_CONTAINERS,
302 PowerButtonController::ANIMATION_SLOW_CLOSE)); 302 PowerButtonController::ANIMATION_SLOW_CLOSE));
303 303
304 // Fire the shutdown timeout and check that we request shutdown. 304 // Fire the shutdown timeout and check that we request shutdown.
305 test_api_->trigger_shutdown_timeout(); 305 test_api_->trigger_shutdown_timeout();
306 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 306 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
307 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 307 EXPECT_EQ(0, delegate_->num_shutdown_requests());
308 test_api_->trigger_real_shutdown_timeout(); 308 test_api_->trigger_real_shutdown_timeout();
309 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 309 EXPECT_EQ(1, delegate_->num_shutdown_requests());
310 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 310 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
311 } 311 }
312 312
313 // Test that we handle the case where lock requests are ignored. 313 // Test that we handle the case where lock requests are ignored.
314 TEST_F(PowerButtonControllerTest, LockFail) { 314 TEST_F(PowerButtonControllerTest, LockFail) {
315 // We require animations to have a duration for this test. 315 // We require animations to have a duration for this test.
316 ui::LayerAnimator::set_disable_animations_for_test(false); 316 ui::LayerAnimator::set_disable_animations_for_test(false);
317 317
318 controller_->set_has_legacy_power_button_for_test(false); 318 controller_->set_has_legacy_power_button_for_test(false);
319 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 319 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
320 controller_->OnLockStateChange(false); 320 controller_->OnLockStateChanged(false);
321 321
322 // Hold the power button and lock the screen. 322 // Hold the power button and lock the screen.
323 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 323 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
324 EXPECT_TRUE(test_api_->lock_timer_is_running()); 324 EXPECT_TRUE(test_api_->lock_timer_is_running());
325 EXPECT_TRUE( 325 EXPECT_TRUE(
326 test_api_->ContainerGroupIsAnimated( 326 test_api_->ContainerGroupIsAnimated(
327 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 327 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
328 PowerButtonController::ANIMATION_RESTORE)); 328 PowerButtonController::ANIMATION_RESTORE));
329 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 329 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
330 test_api_->trigger_lock_timeout(); 330 test_api_->trigger_lock_timeout();
(...skipping 11 matching lines...) Expand all
342 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 342 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
343 PowerButtonController::ANIMATION_RESTORE)); 343 PowerButtonController::ANIMATION_RESTORE));
344 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 344 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
345 } 345 }
346 346
347 // Test that we start the timer to hide the background layer when the power 347 // Test that we start the timer to hide the background layer when the power
348 // button is released, but that we cancel the timer if the button is pressed 348 // button is released, but that we cancel the timer if the button is pressed
349 // again before the timer has fired. 349 // again before the timer has fired.
350 TEST_F(PowerButtonControllerTest, CancelHideBackground) { 350 TEST_F(PowerButtonControllerTest, CancelHideBackground) {
351 controller_->set_has_legacy_power_button_for_test(false); 351 controller_->set_has_legacy_power_button_for_test(false);
352 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 352 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
353 controller_->OnLockStateChange(false); 353 controller_->OnLockStateChanged(false);
354 354
355 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 355 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
356 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 356 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
357 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); 357 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running());
358 358
359 // We should cancel the timer if we get another button-down event. 359 // We should cancel the timer if we get another button-down event.
360 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 360 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
361 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); 361 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running());
362 } 362 }
363 363
364 // Test the basic operation of the lock button. 364 // Test the basic operation of the lock button.
365 TEST_F(PowerButtonControllerTest, LockButtonBasic) { 365 TEST_F(PowerButtonControllerTest, LockButtonBasic) {
366 controller_->set_has_legacy_power_button_for_test(false); 366 controller_->set_has_legacy_power_button_for_test(false);
367 // The lock button shouldn't do anything if we aren't logged in. 367 // The lock button shouldn't do anything if we aren't logged in.
368 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 368 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
369 controller_->OnLockStateChange(false); 369 controller_->OnLockStateChanged(false);
370 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 370 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
371 EXPECT_FALSE(test_api_->lock_timer_is_running()); 371 EXPECT_FALSE(test_api_->lock_timer_is_running());
372 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 372 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
373 EXPECT_EQ(0, delegate_->num_lock_requests()); 373 EXPECT_EQ(0, delegate_->num_lock_requests());
374 374
375 // Ditto for when we're logged in as a guest. 375 // Ditto for when we're logged in as a guest.
376 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); 376 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
377 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 377 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
378 EXPECT_FALSE(test_api_->lock_timer_is_running()); 378 EXPECT_FALSE(test_api_->lock_timer_is_running());
379 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 379 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
380 EXPECT_EQ(0, delegate_->num_lock_requests()); 380 EXPECT_EQ(0, delegate_->num_lock_requests());
381 381
382 // If we're logged in as a regular user, we should start the lock timer and 382 // If we're logged in as a regular user, we should start the lock timer and
383 // the pre-lock animation. 383 // the pre-lock animation.
384 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 384 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
385 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 385 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
386 EXPECT_TRUE(test_api_->lock_timer_is_running()); 386 EXPECT_TRUE(test_api_->lock_timer_is_running());
387 EXPECT_TRUE( 387 EXPECT_TRUE(
388 test_api_->ContainerGroupIsAnimated( 388 test_api_->ContainerGroupIsAnimated(
389 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 389 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
390 PowerButtonController::ANIMATION_SLOW_CLOSE)); 390 PowerButtonController::ANIMATION_SLOW_CLOSE));
391 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 391 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
392 392
393 // If the button is released immediately, we shouldn't lock the screen. 393 // If the button is released immediately, we shouldn't lock the screen.
394 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 394 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
(...skipping 17 matching lines...) Expand all
412 412
413 // Pressing the lock button while we have a pending lock request shouldn't do 413 // Pressing the lock button while we have a pending lock request shouldn't do
414 // anything. 414 // anything.
415 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 415 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
416 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 416 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
417 EXPECT_FALSE(test_api_->lock_timer_is_running()); 417 EXPECT_FALSE(test_api_->lock_timer_is_running());
418 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 418 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
419 419
420 // Pressing the button also shouldn't do anything after the screen is locked. 420 // Pressing the button also shouldn't do anything after the screen is locked.
421 controller_->OnStartingLock(); 421 controller_->OnStartingLock();
422 controller_->OnLockStateChange(true); 422 controller_->OnLockStateChanged(true);
423 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 423 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
424 EXPECT_FALSE(test_api_->lock_timer_is_running()); 424 EXPECT_FALSE(test_api_->lock_timer_is_running());
425 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 425 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
426 } 426 }
427 427
428 // Test that the power button takes priority over the lock button. 428 // Test that the power button takes priority over the lock button.
429 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { 429 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) {
430 controller_->set_has_legacy_power_button_for_test(false); 430 controller_->set_has_legacy_power_button_for_test(false);
431 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 431 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
432 controller_->OnLockStateChange(false); 432 controller_->OnLockStateChanged(false);
433 433
434 // While the lock button is down, hold the power button. 434 // While the lock button is down, hold the power button.
435 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 435 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
436 EXPECT_TRUE(test_api_->lock_timer_is_running()); 436 EXPECT_TRUE(test_api_->lock_timer_is_running());
437 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 437 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
438 EXPECT_TRUE(test_api_->lock_timer_is_running()); 438 EXPECT_TRUE(test_api_->lock_timer_is_running());
439 439
440 // The lock timer shouldn't be stopped when the lock button is released. 440 // The lock timer shouldn't be stopped when the lock button is released.
441 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 441 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
442 EXPECT_TRUE(test_api_->lock_timer_is_running()); 442 EXPECT_TRUE(test_api_->lock_timer_is_running());
(...skipping 10 matching lines...) Expand all
453 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 453 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
454 EXPECT_FALSE(test_api_->lock_timer_is_running()); 454 EXPECT_FALSE(test_api_->lock_timer_is_running());
455 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 455 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
456 EXPECT_FALSE(test_api_->lock_timer_is_running()); 456 EXPECT_FALSE(test_api_->lock_timer_is_running());
457 } 457 }
458 458
459 // When the screen is locked without going through the usual power-button 459 // When the screen is locked without going through the usual power-button
460 // slow-close path (e.g. via the wrench menu), test that we still show the 460 // slow-close path (e.g. via the wrench menu), test that we still show the
461 // fast-close animation and display the background layer. 461 // fast-close animation and display the background layer.
462 TEST_F(PowerButtonControllerTest, LockWithoutButton) { 462 TEST_F(PowerButtonControllerTest, LockWithoutButton) {
463 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 463 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
464 controller_->OnStartingLock(); 464 controller_->OnStartingLock();
465 EXPECT_TRUE( 465 EXPECT_TRUE(
466 test_api_->ContainerGroupIsAnimated( 466 test_api_->ContainerGroupIsAnimated(
467 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 467 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
468 PowerButtonController::ANIMATION_FAST_CLOSE)); 468 PowerButtonController::ANIMATION_FAST_CLOSE));
469 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 469 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
470 } 470 }
471 471
472 // When we hear that the process is exiting but we haven't had a chance to 472 // When we hear that the process is exiting but we haven't had a chance to
473 // display an animation, we should just blank the screen. 473 // display an animation, we should just blank the screen.
474 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { 474 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) {
475 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 475 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
476 controller_->OnExit(); 476 controller_->OnAppTerminating();
477 EXPECT_TRUE( 477 EXPECT_TRUE(
478 test_api_->ContainerGroupIsAnimated( 478 test_api_->ContainerGroupIsAnimated(
479 PowerButtonController::ALL_CONTAINERS, 479 PowerButtonController::ALL_CONTAINERS,
480 PowerButtonController::ANIMATION_HIDE)); 480 PowerButtonController::ANIMATION_HIDE));
481 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 481 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
482 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown()); 482 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown());
483 } 483 }
484 484
485 // Test that we display the fast-close animation and shut down when we get an 485 // Test that we display the fast-close animation and shut down when we get an
486 // outside request to shut down (e.g. from the login or lock screen). 486 // outside request to shut down (e.g. from the login or lock screen).
487 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { 487 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) {
488 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 488 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
489 controller_->RequestShutdown(); 489 controller_->RequestShutdown();
490 EXPECT_TRUE( 490 EXPECT_TRUE(
491 test_api_->ContainerGroupIsAnimated( 491 test_api_->ContainerGroupIsAnimated(
492 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 492 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
493 PowerButtonController::ANIMATION_HIDE)); 493 PowerButtonController::ANIMATION_HIDE));
494 EXPECT_TRUE( 494 EXPECT_TRUE(
495 test_api_->ContainerGroupIsAnimated( 495 test_api_->ContainerGroupIsAnimated(
496 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, 496 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS,
497 PowerButtonController::ANIMATION_FAST_CLOSE)); 497 PowerButtonController::ANIMATION_FAST_CLOSE));
498 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 498 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
499 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown()); 499 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown());
500 500
501 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 501 EXPECT_EQ(0, delegate_->num_shutdown_requests());
502 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 502 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
503 test_api_->trigger_real_shutdown_timeout(); 503 test_api_->trigger_real_shutdown_timeout();
504 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 504 EXPECT_EQ(1, delegate_->num_shutdown_requests());
505 } 505 }
506 506
507 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { 507 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
508 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 508 controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
509 controller_->OnLockStateChange(true); 509 controller_->OnLockStateChanged(true);
510 controller_->RequestShutdown(); 510 controller_->RequestShutdown();
511 EXPECT_TRUE( 511 EXPECT_TRUE(
512 test_api_->ContainerGroupIsAnimated( 512 test_api_->ContainerGroupIsAnimated(
513 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 513 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
514 PowerButtonController::ANIMATION_HIDE)); 514 PowerButtonController::ANIMATION_HIDE));
515 EXPECT_TRUE( 515 EXPECT_TRUE(
516 test_api_->ContainerGroupIsAnimated( 516 test_api_->ContainerGroupIsAnimated(
517 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS, 517 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS,
518 PowerButtonController::ANIMATION_FAST_CLOSE)); 518 PowerButtonController::ANIMATION_FAST_CLOSE));
519 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 519 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
520 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown()); 520 EXPECT_FALSE(Shell::GetRootWindow()->cursor_shown());
521 521
522 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 522 EXPECT_EQ(0, delegate_->num_shutdown_requests());
523 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 523 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
524 test_api_->trigger_real_shutdown_timeout(); 524 test_api_->trigger_real_shutdown_timeout();
525 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 525 EXPECT_EQ(1, delegate_->num_shutdown_requests());
526 } 526 }
527 527
528 } // namespace test 528 } // namespace test
529 } // namespace ash 529 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/power_button_controller.cc ('k') | chrome/browser/chromeos/power/power_button_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698