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

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

Issue 9110044: chromeos/aura: Handle power button on unofficial hardware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: show background on shutdown and move gyp variable to a different scope 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
66 // 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
68 // state.
69 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
70 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
71 controller_->OnLockStateChange(false);
72
73 // We should request that the screen be locked immediately after seeing the
74 // power button get pressed.
75 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
76 EXPECT_TRUE(
77 test_api_->ContainerGroupIsAnimated(
78 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
79 PowerButtonController::ANIMATION_SLOW_CLOSE));
80 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
81 EXPECT_FALSE(test_api_->hide_background_layer_timer_is_running());
82 EXPECT_FALSE(test_api_->lock_timer_is_running());
83 EXPECT_EQ(1, delegate_->num_lock_requests());
84
85 // Notify that we locked successfully.
86 controller_->OnStartingLock();
87 EXPECT_TRUE(
88 test_api_->ContainerGroupIsAnimated(
89 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
90 PowerButtonController::ANIMATION_FAST_CLOSE));
91 EXPECT_TRUE(
92 test_api_->ContainerGroupIsAnimated(
93 PowerButtonController::SCREEN_LOCKER_CONTAINERS,
94 PowerButtonController::ANIMATION_HIDE));
95
96 // Notify that the lock window is visible. We should make it fade in.
97 controller_->OnLockStateChange(true);
98 EXPECT_TRUE(
99 test_api_->ContainerGroupIsAnimated(
100 PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS,
101 PowerButtonController::ANIMATION_FADE_IN));
102
103 // We shouldn't progress towards the shutdown state, however.
104 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
105 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
106 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
107
108 // Hold the button again and check that we start shutting down.
109 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
110 EXPECT_EQ(0, delegate_->num_shutdown_requests());
111 EXPECT_TRUE(
112 test_api_->ContainerGroupIsAnimated(
113 PowerButtonController::ALL_CONTAINERS,
114 PowerButtonController::ANIMATION_FAST_CLOSE));
115 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
116 test_api_->trigger_real_shutdown_timeout();
117 EXPECT_EQ(1, delegate_->num_shutdown_requests());
118 }
119
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.
122 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) {
123 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
124 controller_->OnLockStateChange(false);
125 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
126 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
127 }
128
129 // 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 TEST_F(PowerButtonControllerTest, LegacyGuest) {
132 controller_->OnLoginStateChange(true /*logged_in*/, true /*is_guest*/);
133 controller_->OnLockStateChange(false);
134 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
135 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
136 }
137 #else
64 // When we hold the power button while the user isn't logged in, we should shut 138 // When we hold the power button while the user isn't logged in, we should shut
65 // down the machine directly. 139 // down the machine directly.
66 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { 140 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) {
67 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/); 141 controller_->OnLoginStateChange(false /*logged_in*/, false /*is_guest*/);
68 controller_->OnLockStateChange(false); 142 controller_->OnLockStateChange(false);
69 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 143 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
70 144
71 // Press the power button and check that we start the shutdown timer. 145 // Press the power button and check that we start the shutdown timer.
72 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 146 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
73 EXPECT_FALSE(test_api_->lock_timer_is_running()); 147 EXPECT_FALSE(test_api_->lock_timer_is_running());
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 EXPECT_TRUE(test_api_->lock_timer_is_running()); 431 EXPECT_TRUE(test_api_->lock_timer_is_running());
358 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 432 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
359 EXPECT_TRUE(test_api_->lock_timer_is_running()); 433 EXPECT_TRUE(test_api_->lock_timer_is_running());
360 434
361 // Releasing the power button should stop the lock timer. 435 // Releasing the power button should stop the lock timer.
362 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 436 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
363 EXPECT_FALSE(test_api_->lock_timer_is_running()); 437 EXPECT_FALSE(test_api_->lock_timer_is_running());
364 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 438 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
365 EXPECT_FALSE(test_api_->lock_timer_is_running()); 439 EXPECT_FALSE(test_api_->lock_timer_is_running());
366 } 440 }
441 #endif
367 442
368 } // namespace test 443 } // namespace test
369 } // namespace ash 444 } // 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