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

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

Issue 9264025: aura: Replace UI-feature GYP flags with switches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 11 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
« no previous file with comments | « ash/wm/power_button_controller.cc ('k') | build/common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/aura_shell_test_base.h" 8 #include "ash/test/aura_shell_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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 protected: 55 protected:
56 PowerButtonController* controller_; // not owned 56 PowerButtonController* controller_; // not owned
57 TestPowerButtonControllerDelegate* delegate_; // not owned 57 TestPowerButtonControllerDelegate* delegate_; // not owned
58 scoped_ptr<PowerButtonController::TestApi> test_api_; 58 scoped_ptr<PowerButtonController::TestApi> test_api_;
59 59
60 private: 60 private:
61 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); 61 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest);
62 }; 62 };
63 63
64 #if defined(CHROMEOS_LEGACY_POWER_BUTTON)
65 // 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
66 // correctly report power button releases. We should lock immediately the first 65 // correctly report power button releases. We should lock immediately the first
67 // 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
68 // state. 67 // state.
69 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { 68 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
69 controller_->set_has_legacy_power_button_for_test(true);
70 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 70 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
71 controller_->OnLockStateChange(false); 71 controller_->OnLockStateChange(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));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 PowerButtonController::ALL_CONTAINERS, 113 PowerButtonController::ALL_CONTAINERS,
114 PowerButtonController::ANIMATION_FAST_CLOSE)); 114 PowerButtonController::ANIMATION_FAST_CLOSE));
115 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 115 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
116 test_api_->trigger_real_shutdown_timeout(); 116 test_api_->trigger_real_shutdown_timeout();
117 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 117 EXPECT_EQ(1, delegate_->num_shutdown_requests());
118 } 118 }
119 119
120 // Test that we start shutting down immediately if the power button is pressed 120 // Test that we start shutting down immediately if the power button is pressed
121 // while we're not logged in on an unofficial system. 121 // while we're not logged in on an unofficial system.
122 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { 122 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) {
123 controller_->set_has_legacy_power_button_for_test(true);
123 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 124 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
124 controller_->OnLockStateChange(false); 125 controller_->OnLockStateChange(false);
125 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 126 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
126 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 127 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
127 } 128 }
128 129
129 // Test that we start shutting down immediately if the power button is pressed 130 // Test that we start shutting down immediately if the power button is pressed
130 // while we're logged in as a guest on an unofficial system. 131 // while we're logged in as a guest on an unofficial system.
131 TEST_F(PowerButtonControllerTest, LegacyGuest) { 132 TEST_F(PowerButtonControllerTest, LegacyGuest) {
133 controller_->set_has_legacy_power_button_for_test(true);
132 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); 134 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/);
133 controller_->OnLockStateChange(false); 135 controller_->OnLockStateChange(false);
134 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 136 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
135 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 137 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
136 } 138 }
137 #else 139
138 // When we hold the power button while the user isn't logged in, we should shut 140 // When we hold the power button while the user isn't logged in, we should shut
139 // down the machine directly. 141 // down the machine directly.
140 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { 142 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) {
143 controller_->set_has_legacy_power_button_for_test(false);
141 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 144 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
142 controller_->OnLockStateChange(false); 145 controller_->OnLockStateChange(false);
143 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 146 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
144 147
145 // Press the power button and check that we start the shutdown timer. 148 // Press the power button and check that we start the shutdown timer.
146 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 149 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
147 EXPECT_FALSE(test_api_->lock_timer_is_running()); 150 EXPECT_FALSE(test_api_->lock_timer_is_running());
148 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 151 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
149 EXPECT_TRUE( 152 EXPECT_TRUE(
150 test_api_->ContainerGroupIsAnimated( 153 test_api_->ContainerGroupIsAnimated(
(...skipping 28 matching lines...) Expand all
179 PowerButtonController::ALL_CONTAINERS, 182 PowerButtonController::ALL_CONTAINERS,
180 PowerButtonController::ANIMATION_FAST_CLOSE)); 183 PowerButtonController::ANIMATION_FAST_CLOSE));
181 184
182 // When the timout fires, we should request a shutdown. 185 // When the timout fires, we should request a shutdown.
183 test_api_->trigger_real_shutdown_timeout(); 186 test_api_->trigger_real_shutdown_timeout();
184 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 187 EXPECT_EQ(1, delegate_->num_shutdown_requests());
185 } 188 }
186 189
187 // Test that we lock the screen and deal with unlocking correctly. 190 // Test that we lock the screen and deal with unlocking correctly.
188 TEST_F(PowerButtonControllerTest, LockAndUnlock) { 191 TEST_F(PowerButtonControllerTest, LockAndUnlock) {
192 controller_->set_has_legacy_power_button_for_test(false);
189 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 193 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
190 controller_->OnLockStateChange(false); 194 controller_->OnLockStateChange(false);
191 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 195 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
192 196
193 // We should initially be showing the screen locker containers, since they 197 // We should initially be showing the screen locker containers, since they
194 // also contain login-related windows that we want to show during the 198 // also contain login-related windows that we want to show during the
195 // logging-in animation. 199 // logging-in animation.
196 EXPECT_TRUE( 200 EXPECT_TRUE(
197 test_api_->ContainerGroupIsAnimated( 201 test_api_->ContainerGroupIsAnimated(
198 PowerButtonController::SCREEN_LOCKER_CONTAINERS, 202 PowerButtonController::SCREEN_LOCKER_CONTAINERS,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 controller_->OnLockStateChange(false); 267 controller_->OnLockStateChange(false);
264 EXPECT_TRUE( 268 EXPECT_TRUE(
265 test_api_->ContainerGroupIsAnimated( 269 test_api_->ContainerGroupIsAnimated(
266 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 270 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
267 PowerButtonController::ANIMATION_RESTORE)); 271 PowerButtonController::ANIMATION_RESTORE));
268 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 272 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
269 } 273 }
270 274
271 // Hold the power button down from the unlocked state to eventual shutdown. 275 // Hold the power button down from the unlocked state to eventual shutdown.
272 TEST_F(PowerButtonControllerTest, LockToShutdown) { 276 TEST_F(PowerButtonControllerTest, LockToShutdown) {
277 controller_->set_has_legacy_power_button_for_test(false);
273 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 278 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
274 controller_->OnLockStateChange(false); 279 controller_->OnLockStateChange(false);
275 280
276 // Hold the power button and lock the screen. 281 // Hold the power button and lock the screen.
277 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 282 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
278 EXPECT_TRUE(test_api_->lock_timer_is_running()); 283 EXPECT_TRUE(test_api_->lock_timer_is_running());
279 test_api_->trigger_lock_timeout(); 284 test_api_->trigger_lock_timeout();
280 controller_->OnStartingLock(); 285 controller_->OnStartingLock();
281 controller_->OnLockStateChange(true); 286 controller_->OnLockStateChange(true);
282 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 287 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
(...skipping 12 matching lines...) Expand all
295 test_api_->trigger_shutdown_timeout(); 300 test_api_->trigger_shutdown_timeout();
296 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 301 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
297 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 302 EXPECT_EQ(0, delegate_->num_shutdown_requests());
298 test_api_->trigger_real_shutdown_timeout(); 303 test_api_->trigger_real_shutdown_timeout();
299 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 304 EXPECT_EQ(1, delegate_->num_shutdown_requests());
300 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 305 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
301 } 306 }
302 307
303 // Test that we handle the case where lock requests are ignored. 308 // Test that we handle the case where lock requests are ignored.
304 TEST_F(PowerButtonControllerTest, LockFail) { 309 TEST_F(PowerButtonControllerTest, LockFail) {
310 controller_->set_has_legacy_power_button_for_test(false);
305 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 311 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
306 controller_->OnLockStateChange(false); 312 controller_->OnLockStateChange(false);
307 313
308 // Hold the power button and lock the screen. 314 // Hold the power button and lock the screen.
309 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 315 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
310 EXPECT_TRUE(test_api_->lock_timer_is_running()); 316 EXPECT_TRUE(test_api_->lock_timer_is_running());
311 EXPECT_TRUE( 317 EXPECT_TRUE(
312 test_api_->ContainerGroupIsAnimated( 318 test_api_->ContainerGroupIsAnimated(
313 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 319 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
314 PowerButtonController::ANIMATION_RESTORE)); 320 PowerButtonController::ANIMATION_RESTORE));
(...skipping 12 matching lines...) Expand all
327 test_api_->ContainerGroupIsAnimated( 333 test_api_->ContainerGroupIsAnimated(
328 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 334 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
329 PowerButtonController::ANIMATION_RESTORE)); 335 PowerButtonController::ANIMATION_RESTORE));
330 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 336 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
331 } 337 }
332 338
333 // Test that we start the timer to hide the background layer when the power 339 // Test that we start the timer to hide the background layer when the power
334 // button is released, but that we cancel the timer if the button is pressed 340 // button is released, but that we cancel the timer if the button is pressed
335 // again before the timer has fired. 341 // again before the timer has fired.
336 TEST_F(PowerButtonControllerTest, CancelHideBackground) { 342 TEST_F(PowerButtonControllerTest, CancelHideBackground) {
343 controller_->set_has_legacy_power_button_for_test(false);
337 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 344 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
338 controller_->OnLockStateChange(false); 345 controller_->OnLockStateChange(false);
339 346
340 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 347 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
341 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 348 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
342 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running()); 349 EXPECT_TRUE(test_api_->hide_background_layer_timer_is_running());
343 350
344 // We should cancel the timer if we get another button-down event. 351 // We should cancel the timer if we get another button-down event.
345 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 352 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
346 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running()); 353 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running());
347 } 354 }
348 355
349 // Test the basic operation of the lock button. 356 // Test the basic operation of the lock button.
350 TEST_F(PowerButtonControllerTest, LockButtonBasic) { 357 TEST_F(PowerButtonControllerTest, LockButtonBasic) {
358 controller_->set_has_legacy_power_button_for_test(false);
351 // The lock button shouldn't do anything if we aren't logged in. 359 // The lock button shouldn't do anything if we aren't logged in.
352 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 360 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
353 controller_->OnLockStateChange(false); 361 controller_->OnLockStateChange(false);
354 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 362 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
355 EXPECT_FALSE(test_api_->lock_timer_is_running()); 363 EXPECT_FALSE(test_api_->lock_timer_is_running());
356 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 364 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
357 EXPECT_EQ(0, delegate_->num_lock_requests()); 365 EXPECT_EQ(0, delegate_->num_lock_requests());
358 366
359 // Ditto for when we're logged in as a guest. 367 // Ditto for when we're logged in as a guest.
360 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/); 368 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // Pressing the button also shouldn't do anything after the screen is locked. 412 // Pressing the button also shouldn't do anything after the screen is locked.
405 controller_->OnStartingLock(); 413 controller_->OnStartingLock();
406 controller_->OnLockStateChange(true); 414 controller_->OnLockStateChange(true);
407 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 415 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
408 EXPECT_FALSE(test_api_->lock_timer_is_running()); 416 EXPECT_FALSE(test_api_->lock_timer_is_running());
409 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 417 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
410 } 418 }
411 419
412 // Test that the power button takes priority over the lock button. 420 // Test that the power button takes priority over the lock button.
413 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { 421 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) {
422 controller_->set_has_legacy_power_button_for_test(false);
414 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 423 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
415 controller_->OnLockStateChange(false); 424 controller_->OnLockStateChange(false);
416 425
417 // While the lock button is down, hold the power button. 426 // While the lock button is down, hold the power button.
418 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 427 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
419 EXPECT_TRUE(test_api_->lock_timer_is_running()); 428 EXPECT_TRUE(test_api_->lock_timer_is_running());
420 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 429 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
421 EXPECT_TRUE(test_api_->lock_timer_is_running()); 430 EXPECT_TRUE(test_api_->lock_timer_is_running());
422 431
423 // The lock timer shouldn't be stopped when the lock button is released. 432 // The lock timer shouldn't be stopped when the lock button is released.
424 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 433 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
425 EXPECT_TRUE(test_api_->lock_timer_is_running()); 434 EXPECT_TRUE(test_api_->lock_timer_is_running());
426 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 435 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
427 EXPECT_FALSE(test_api_->lock_timer_is_running()); 436 EXPECT_FALSE(test_api_->lock_timer_is_running());
428 437
429 // Now press the power button first and then the lock button. 438 // Now press the power button first and then the lock button.
430 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 439 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
431 EXPECT_TRUE(test_api_->lock_timer_is_running()); 440 EXPECT_TRUE(test_api_->lock_timer_is_running());
432 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 441 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
433 EXPECT_TRUE(test_api_->lock_timer_is_running()); 442 EXPECT_TRUE(test_api_->lock_timer_is_running());
434 443
435 // Releasing the power button should stop the lock timer. 444 // Releasing the power button should stop the lock timer.
436 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 445 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
437 EXPECT_FALSE(test_api_->lock_timer_is_running()); 446 EXPECT_FALSE(test_api_->lock_timer_is_running());
438 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 447 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
439 EXPECT_FALSE(test_api_->lock_timer_is_running()); 448 EXPECT_FALSE(test_api_->lock_timer_is_running());
440 } 449 }
441 #endif
442 450
443 } // namespace test 451 } // namespace test
444 } // namespace ash 452 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/power_button_controller.cc ('k') | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698