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

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

Issue 11091023: ash : Decouple power button controller and session state controller. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initialize variable Created 8 years, 2 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
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 #include "ash/wm/session_state_animator.h"
7 #include "ash/wm/session_state_controller.h"
6 8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/cursor_manager.h" 11 #include "ash/wm/cursor_manager.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/time.h" 13 #include "base/time.h"
12 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
13 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
14 #include "ui/aura/test/event_generator.h" 16 #include "ui/aura/test/event_generator.h"
15 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
16 #include "ui/gfx/size.h" 18 #include "ui/gfx/size.h"
17 19
18 namespace ash { 20 namespace ash {
19 namespace test { 21 namespace test {
20 namespace { 22 namespace {
21 bool cursor_visible() { 23 bool cursor_visible() {
22 return ash::Shell::GetInstance()->cursor_manager()->cursor_visible(); 24 return ash::Shell::GetInstance()->cursor_manager()->cursor_visible();
23 } 25 }
24 } 26 }
25 27
26 // Fake implementation of PowerButtonControllerDelegate that just logs requests 28 // Fake implementation of PowerButtonControllerDelegate that just logs requests
27 // to lock the screen and shut down the device. 29 // to lock the screen and shut down the device.
28 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate { 30 class TestPowerButtonControllerDelegate :
31 public SessionStateControllerDelegate {
29 public: 32 public:
30 TestPowerButtonControllerDelegate() 33 TestPowerButtonControllerDelegate()
31 : num_lock_requests_(0), 34 : num_lock_requests_(0),
32 num_shutdown_requests_(0) {} 35 num_shutdown_requests_(0) {}
33 36
34 int num_lock_requests() const { return num_lock_requests_; } 37 int num_lock_requests() const { return num_lock_requests_; }
35 int num_shutdown_requests() const { return num_shutdown_requests_; } 38 int num_shutdown_requests() const { return num_shutdown_requests_; }
36 39
37 // PowerButtonControllerDelegate implementation. 40 // PowerButtonControllerDelegate implementation.
38 virtual void RequestLockScreen() OVERRIDE { 41 virtual void RequestLockScreen() OVERRIDE {
(...skipping 12 matching lines...) Expand all
51 54
52 class PowerButtonControllerTest : public AshTestBase { 55 class PowerButtonControllerTest : public AshTestBase {
53 public: 56 public:
54 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} 57 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {}
55 virtual ~PowerButtonControllerTest() {} 58 virtual ~PowerButtonControllerTest() {}
56 59
57 void SetUp() OVERRIDE { 60 void SetUp() OVERRIDE {
58 AshTestBase::SetUp(); 61 AshTestBase::SetUp();
59 delegate_ = new TestPowerButtonControllerDelegate; 62 delegate_ = new TestPowerButtonControllerDelegate;
60 controller_ = Shell::GetInstance()->power_button_controller(); 63 controller_ = Shell::GetInstance()->power_button_controller();
61 controller_->set_delegate(delegate_); // transfers ownership 64 state_controller_ = Shell::GetInstance()->session_state_controller();
62 test_api_.reset(new PowerButtonController::TestApi(controller_)); 65 state_controller_->set_delegate(delegate_); // transfers ownership
66 test_api_.reset(new SessionStateController::TestApi(state_controller_));
67 animator_api_.reset(
68 new internal::SessionStateAnimator::TestApi(state_controller_->
69 animator_.get()));
63 } 70 }
64 71
65 protected: 72 protected:
66 void GenerateMouseMoveEvent() { 73 void GenerateMouseMoveEvent() {
67 aura::test::EventGenerator generator( 74 aura::test::EventGenerator generator(
68 Shell::GetPrimaryRootWindow()); 75 Shell::GetPrimaryRootWindow());
69 generator.MoveMouseTo(10, 10); 76 generator.MoveMouseTo(10, 10);
70 } 77 }
71 78
72 PowerButtonController* controller_; // not owned 79 PowerButtonController* controller_; // not owned
80 SessionStateController* state_controller_; // not owned
73 TestPowerButtonControllerDelegate* delegate_; // not owned 81 TestPowerButtonControllerDelegate* delegate_; // not owned
74 scoped_ptr<PowerButtonController::TestApi> test_api_; 82
83 scoped_ptr<SessionStateController::TestApi> test_api_;
84 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_;
75 85
76 private: 86 private:
77 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); 87 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest);
78 }; 88 };
79 89
80 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't 90 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
81 // correctly report power button releases. We should lock immediately the first 91 // correctly report power button releases. We should lock immediately the first
82 // time the button is pressed and shut down when it's pressed from the locked 92 // time the button is pressed and shut down when it's pressed from the locked
83 // state. 93 // state.
84 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { 94 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
85 controller_->set_has_legacy_power_button_for_test(true); 95 controller_->set_has_legacy_power_button_for_test(true);
86 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 96 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
87 controller_->OnLockStateChanged(false); 97 state_controller_->OnLockStateChanged(false);
88 98
89 // We should request that the screen be locked immediately after seeing the 99 // We should request that the screen be locked immediately after seeing the
90 // power button get pressed. 100 // power button get pressed.
91 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 101 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
92 EXPECT_TRUE( 102 EXPECT_TRUE(
93 test_api_->ContainersAreAnimated( 103 animator_api_->ContainersAreAnimated(
94 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 104 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
95 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 105 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
96 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 106 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
97 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); 107 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running());
98 EXPECT_FALSE(test_api_->lock_timer_is_running()); 108 EXPECT_FALSE(test_api_->lock_timer_is_running());
99 EXPECT_EQ(1, delegate_->num_lock_requests()); 109 EXPECT_EQ(1, delegate_->num_lock_requests());
100 110
101 // Notify that we locked successfully. 111 // Notify that we locked successfully.
102 controller_->OnStartingLock(); 112 state_controller_->OnStartingLock();
103 EXPECT_TRUE( 113 EXPECT_TRUE(
104 test_api_->ContainersAreAnimated( 114 animator_api_->ContainersAreAnimated(
105 internal::SessionStateAnimator::LAUNCHER, 115 internal::SessionStateAnimator::LAUNCHER,
106 internal::SessionStateAnimator::ANIMATION_HIDE)); 116 internal::SessionStateAnimator::ANIMATION_HIDE));
107 EXPECT_TRUE( 117 EXPECT_TRUE(
108 test_api_->ContainersAreAnimated( 118 animator_api_->ContainersAreAnimated(
109 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 119 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
110 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 120 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
111 EXPECT_TRUE( 121 EXPECT_TRUE(
112 test_api_->ContainersAreAnimated( 122 animator_api_->ContainersAreAnimated(
113 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 123 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
114 internal::SessionStateAnimator::ANIMATION_HIDE)); 124 internal::SessionStateAnimator::ANIMATION_HIDE));
115 125
116 // Notify that the lock window is visible. We should make it fade in. 126 // Notify that the lock window is visible. We should make it fade in.
117 controller_->OnLockStateChanged(true); 127 state_controller_->OnLockStateChanged(true);
118 EXPECT_TRUE( 128 EXPECT_TRUE(
119 test_api_->ContainersAreAnimated( 129 animator_api_->ContainersAreAnimated(
120 internal::SessionStateAnimator::kAllLockScreenContainersMask, 130 internal::SessionStateAnimator::kAllLockScreenContainersMask,
121 internal::SessionStateAnimator::ANIMATION_FADE_IN)); 131 internal::SessionStateAnimator::ANIMATION_FADE_IN));
122 132
123 // We shouldn't progress towards the shutdown state, however. 133 // We shouldn't progress towards the shutdown state, however.
124 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 134 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
125 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 135 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
126 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 136 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
127 137
128 // Hold the button again and check that we start shutting down. 138 // Hold the button again and check that we start shutting down.
129 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 139 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
130 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 140 EXPECT_EQ(0, delegate_->num_shutdown_requests());
131 141
132 // Previously we're checking that the all containers group was animated which 142 // Previously we're checking that the all containers group was animated which
133 // was in fact checking that 143 // was in fact checking that
134 // 1. All user session containers have transform (including wallpaper). 144 // 1. All user session containers have transform (including wallpaper).
135 // They're in this state after lock. 145 // They're in this state after lock.
136 // 2. Screen locker and related containers are in fact animating 146 // 2. Screen locker and related containers are in fact animating
137 // (as shutdown is in progress). 147 // (as shutdown is in progress).
138 // With http://crbug.com/144737 we no longer animate user session wallpaper 148 // With http://crbug.com/144737 we no longer animate user session wallpaper
139 // during lock so it makes sense only to check that screen lock and related 149 // during lock so it makes sense only to check that screen lock and related
140 // containers are animated during shutdown. 150 // containers are animated during shutdown.
141 EXPECT_TRUE( 151 EXPECT_TRUE(
142 test_api_->ContainersAreAnimated( 152 animator_api_->ContainersAreAnimated(
143 internal::SessionStateAnimator::kAllLockScreenContainersMask, 153 internal::SessionStateAnimator::kAllLockScreenContainersMask,
144 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 154 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
145 // Make sure a mouse move event won't show the cursor. 155 // Make sure a mouse move event won't show the cursor.
146 GenerateMouseMoveEvent(); 156 GenerateMouseMoveEvent();
147 EXPECT_FALSE(cursor_visible()); 157 EXPECT_FALSE(cursor_visible());
148 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 158 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
149 test_api_->trigger_real_shutdown_timeout(); 159 test_api_->trigger_real_shutdown_timeout();
150 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 160 EXPECT_EQ(1, delegate_->num_shutdown_requests());
151 } 161 }
152 162
153 // Test that we start shutting down immediately if the power button is pressed 163 // Test that we start shutting down immediately if the power button is pressed
154 // while we're not logged in on an unofficial system. 164 // while we're not logged in on an unofficial system.
155 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { 165 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) {
156 controller_->set_has_legacy_power_button_for_test(true); 166 controller_->set_has_legacy_power_button_for_test(true);
157 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 167 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
158 controller_->OnLockStateChanged(false); 168 state_controller_->OnLockStateChanged(false);
159 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
160 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
161 } 171 }
162 172
163 // Test that we start shutting down immediately if the power button is pressed 173 // Test that we start shutting down immediately if the power button is pressed
164 // while we're logged in as a guest on an unofficial system. 174 // while we're logged in as a guest on an unofficial system.
165 TEST_F(PowerButtonControllerTest, LegacyGuest) { 175 TEST_F(PowerButtonControllerTest, LegacyGuest) {
166 controller_->set_has_legacy_power_button_for_test(true); 176 controller_->set_has_legacy_power_button_for_test(true);
167 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); 177 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
168 controller_->OnLockStateChanged(false); 178 state_controller_->OnLockStateChanged(false);
169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 179 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 180 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
171 } 181 }
172 182
173 // When we hold the power button while the user isn't logged in, we should shut 183 // When we hold the power button while the user isn't logged in, we should shut
174 // down the machine directly. 184 // down the machine directly.
175 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { 185 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) {
176 controller_->set_has_legacy_power_button_for_test(false); 186 controller_->set_has_legacy_power_button_for_test(false);
177 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 187 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
178 controller_->OnLockStateChanged(false); 188 state_controller_->OnLockStateChanged(false);
179 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 189 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
180 190
181 // Press the power button and check that we start the shutdown timer. 191 // Press the power button and check that we start the shutdown timer.
182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 192 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
183 EXPECT_FALSE(test_api_->lock_timer_is_running()); 193 EXPECT_FALSE(test_api_->lock_timer_is_running());
184 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 194 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
185 EXPECT_TRUE( 195 EXPECT_TRUE(
186 test_api_->ContainersAreAnimated( 196 animator_api_->ContainersAreAnimated(
187 internal::SessionStateAnimator::kAllContainersMask, 197 internal::SessionStateAnimator::kAllContainersMask,
188 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 198 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
189 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 199 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
190 200
191 // Release the power button before the shutdown timer fires. 201 // Release the power button before the shutdown timer fires.
192 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 202 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
193 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 203 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
194 EXPECT_TRUE( 204 EXPECT_TRUE(
195 test_api_->ContainersAreAnimated( 205 animator_api_->ContainersAreAnimated(
196 internal::SessionStateAnimator::kAllContainersMask, 206 internal::SessionStateAnimator::kAllContainersMask,
197 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); 207 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
198 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 208 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
199 209
200 // We should re-hide the black layer after waiting long enough for 210 // We should re-hide the black layer after waiting long enough for
201 // the animation to finish. 211 // the animation to finish.
202 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 212 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running());
203 test_api_->TriggerHideBlackLayerTimeout(); 213 animator_api_->TriggerHideBlackLayerTimeout();
204 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 214 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
205 215
206 // Press the button again and make the shutdown timeout fire this time. 216 // Press the button again and make the shutdown timeout fire this time.
207 // Check that we start the timer for actually requesting the shutdown. 217 // Check that we start the timer for actually requesting the shutdown.
208 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 218 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
209 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 219 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
210 test_api_->trigger_shutdown_timeout(); 220 test_api_->trigger_shutdown_timeout();
211 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 221 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
212 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 222 EXPECT_EQ(0, delegate_->num_shutdown_requests());
213 EXPECT_TRUE( 223 EXPECT_TRUE(
214 test_api_->ContainersAreAnimated( 224 animator_api_->ContainersAreAnimated(
215 internal::SessionStateAnimator::LAUNCHER | 225 internal::SessionStateAnimator::LAUNCHER |
216 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 226 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
217 internal::SessionStateAnimator::ANIMATION_HIDE)); 227 internal::SessionStateAnimator::ANIMATION_HIDE));
218 EXPECT_TRUE( 228 EXPECT_TRUE(
219 test_api_->ContainersAreAnimated( 229 animator_api_->ContainersAreAnimated(
220 internal::SessionStateAnimator::kAllLockScreenContainersMask, 230 internal::SessionStateAnimator::kAllLockScreenContainersMask,
221 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 231 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
222 232
223 // When the timout fires, we should request a shutdown. 233 // When the timout fires, we should request a shutdown.
224 test_api_->trigger_real_shutdown_timeout(); 234 test_api_->trigger_real_shutdown_timeout();
225 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 235 EXPECT_EQ(1, delegate_->num_shutdown_requests());
226 } 236 }
227 237
228 // Test that we lock the screen and deal with unlocking correctly. 238 // Test that we lock the screen and deal with unlocking correctly.
229 TEST_F(PowerButtonControllerTest, LockAndUnlock) { 239 TEST_F(PowerButtonControllerTest, LockAndUnlock) {
230 controller_->set_has_legacy_power_button_for_test(false); 240 controller_->set_has_legacy_power_button_for_test(false);
231 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 241 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
232 controller_->OnLockStateChanged(false); 242 state_controller_->OnLockStateChanged(false);
233 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 243 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
234 244
235 // We should initially be showing the screen locker containers, since they 245 // We should initially be showing the screen locker containers, since they
236 // also contain login-related windows that we want to show during the 246 // also contain login-related windows that we want to show during the
237 // logging-in animation. 247 // logging-in animation.
238 EXPECT_TRUE( 248 EXPECT_TRUE(
239 test_api_->ContainersAreAnimated( 249 animator_api_->ContainersAreAnimated(
240 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 250 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
241 internal::SessionStateAnimator::ANIMATION_RESTORE)); 251 internal::SessionStateAnimator::ANIMATION_RESTORE));
242 252
243 // Press the power button and check that the lock timer is started and that we 253 // Press the power button and check that the lock timer is started and that we
244 // start scaling the non-screen-locker containers. 254 // start scaling the non-screen-locker containers.
245 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 255 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
246 EXPECT_TRUE(test_api_->lock_timer_is_running()); 256 EXPECT_TRUE(test_api_->lock_timer_is_running());
247 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 257 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
248 EXPECT_TRUE( 258 EXPECT_TRUE(
249 test_api_->ContainersAreAnimated( 259 animator_api_->ContainersAreAnimated(
250 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 260 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
251 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 261 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
252 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 262 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
253 263
254 // Release the button before the lock timer fires. 264 // Release the button before the lock timer fires.
255 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 265 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
256 EXPECT_FALSE(test_api_->lock_timer_is_running()); 266 EXPECT_FALSE(test_api_->lock_timer_is_running());
257 EXPECT_TRUE( 267 EXPECT_TRUE(
258 test_api_->ContainersAreAnimated( 268 animator_api_->ContainersAreAnimated(
259 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 269 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
260 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); 270 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
261 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 271 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
262 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 272 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running());
263 test_api_->TriggerHideBlackLayerTimeout(); 273 animator_api_->TriggerHideBlackLayerTimeout();
264 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 274 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
265 275
266 // Press the button and fire the lock timer. We should request that the 276 // Press the button and fire the lock timer. We should request that the
267 // screen be locked, but we should still be in the slow-close animation. 277 // screen be locked, but we should still be in the slow-close animation.
268 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 278 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
269 EXPECT_TRUE(test_api_->lock_timer_is_running()); 279 EXPECT_TRUE(test_api_->lock_timer_is_running());
270 EXPECT_EQ(0, delegate_->num_lock_requests()); 280 EXPECT_EQ(0, delegate_->num_lock_requests());
271 test_api_->trigger_lock_timeout(); 281 test_api_->trigger_lock_timeout();
272 EXPECT_EQ(1, delegate_->num_lock_requests()); 282 EXPECT_EQ(1, delegate_->num_lock_requests());
273 EXPECT_TRUE( 283 EXPECT_TRUE(
274 test_api_->ContainersAreAnimated( 284 animator_api_->ContainersAreAnimated(
275 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 285 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
276 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 286 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
277 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 287 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
278 288
279 // Notify that we locked successfully. 289 // Notify that we locked successfully.
280 controller_->OnStartingLock(); 290 state_controller_->OnStartingLock();
281 EXPECT_TRUE( 291 EXPECT_TRUE(
282 test_api_->ContainersAreAnimated( 292 animator_api_->ContainersAreAnimated(
283 internal::SessionStateAnimator::LAUNCHER, 293 internal::SessionStateAnimator::LAUNCHER,
284 internal::SessionStateAnimator::ANIMATION_HIDE)); 294 internal::SessionStateAnimator::ANIMATION_HIDE));
285 EXPECT_TRUE( 295 EXPECT_TRUE(
286 test_api_->ContainersAreAnimated( 296 animator_api_->ContainersAreAnimated(
287 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 297 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
288 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 298 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
289 EXPECT_TRUE( 299 EXPECT_TRUE(
290 test_api_->ContainersAreAnimated( 300 animator_api_->ContainersAreAnimated(
291 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 301 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
292 internal::SessionStateAnimator::ANIMATION_HIDE)); 302 internal::SessionStateAnimator::ANIMATION_HIDE));
293 303
294 // Notify that the lock window is visible. We should make it fade in. 304 // Notify that the lock window is visible. We should make it fade in.
295 controller_->OnLockStateChanged(true); 305 state_controller_->OnLockStateChanged(true);
296 EXPECT_TRUE( 306 EXPECT_TRUE(
297 test_api_->ContainersAreAnimated( 307 animator_api_->ContainersAreAnimated(
298 internal::SessionStateAnimator::kAllLockScreenContainersMask, 308 internal::SessionStateAnimator::kAllLockScreenContainersMask,
299 internal::SessionStateAnimator::ANIMATION_FADE_IN)); 309 internal::SessionStateAnimator::ANIMATION_FADE_IN));
300 310
301 // When we release the power button, the lock-to-shutdown timer should be 311 // When we release the power button, the lock-to-shutdown timer should be
302 // stopped. 312 // stopped.
303 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 313 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
304 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 314 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
305 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 315 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
306 316
307 // Notify that the screen has been unlocked. We should show the 317 // Notify that the screen has been unlocked. We should show the
308 // non-screen-locker windows and hide the black layer. 318 // non-screen-locker windows and hide the black layer.
309 controller_->OnLockStateChanged(false); 319 state_controller_->OnLockStateChanged(false);
310 EXPECT_TRUE( 320 EXPECT_TRUE(
311 test_api_->ContainersAreAnimated( 321 animator_api_->ContainersAreAnimated(
312 internal::SessionStateAnimator::DESKTOP_BACKGROUND | 322 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
313 internal::SessionStateAnimator::LAUNCHER | 323 internal::SessionStateAnimator::LAUNCHER |
314 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 324 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
315 internal::SessionStateAnimator::ANIMATION_RESTORE)); 325 internal::SessionStateAnimator::ANIMATION_RESTORE));
316 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 326 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
317 } 327 }
318 328
319 // Hold the power button down from the unlocked state to eventual shutdown. 329 // Hold the power button down from the unlocked state to eventual shutdown.
320 TEST_F(PowerButtonControllerTest, LockToShutdown) { 330 TEST_F(PowerButtonControllerTest, LockToShutdown) {
321 controller_->set_has_legacy_power_button_for_test(false); 331 controller_->set_has_legacy_power_button_for_test(false);
322 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 332 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
323 controller_->OnLockStateChanged(false); 333 state_controller_->OnLockStateChanged(false);
324 334
325 // Hold the power button and lock the screen. 335 // Hold the power button and lock the screen.
326 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 336 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
327 EXPECT_TRUE(test_api_->lock_timer_is_running()); 337 EXPECT_TRUE(test_api_->lock_timer_is_running());
328 test_api_->trigger_lock_timeout(); 338 test_api_->trigger_lock_timeout();
329 controller_->OnStartingLock(); 339 state_controller_->OnStartingLock();
330 controller_->OnLockStateChanged(true); 340 state_controller_->OnLockStateChanged(true);
331 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 341 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
332 342
333 // When the lock-to-shutdown timeout fires, we should start the shutdown 343 // When the lock-to-shutdown timeout fires, we should start the shutdown
334 // timer. 344 // timer.
335 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); 345 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
336 test_api_->trigger_lock_to_shutdown_timeout(); 346 test_api_->trigger_lock_to_shutdown_timeout();
337 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 347 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
338 EXPECT_TRUE( 348 EXPECT_TRUE(
339 test_api_->ContainersAreAnimated( 349 animator_api_->ContainersAreAnimated(
340 internal::SessionStateAnimator::kAllContainersMask, 350 internal::SessionStateAnimator::kAllContainersMask,
341 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 351 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
342 352
343 // Fire the shutdown timeout and check that we request shutdown. 353 // Fire the shutdown timeout and check that we request shutdown.
344 test_api_->trigger_shutdown_timeout(); 354 test_api_->trigger_shutdown_timeout();
345 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 355 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
346 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 356 EXPECT_EQ(0, delegate_->num_shutdown_requests());
347 test_api_->trigger_real_shutdown_timeout(); 357 test_api_->trigger_real_shutdown_timeout();
348 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 358 EXPECT_EQ(1, delegate_->num_shutdown_requests());
349 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 359 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
350 } 360 }
351 361
352 // Test that we handle the case where lock requests are ignored. 362 // Test that we handle the case where lock requests are ignored.
353 TEST_F(PowerButtonControllerTest, LockFail) { 363 TEST_F(PowerButtonControllerTest, LockFail) {
354 // We require animations to have a duration for this test. 364 // We require animations to have a duration for this test.
355 ui::LayerAnimator::set_disable_animations_for_test(false); 365 ui::LayerAnimator::set_disable_animations_for_test(false);
356 366
357 controller_->set_has_legacy_power_button_for_test(false); 367 controller_->set_has_legacy_power_button_for_test(false);
358 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 368 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
359 controller_->OnLockStateChanged(false); 369 state_controller_->OnLockStateChanged(false);
360 370
361 // Hold the power button and lock the screen. 371 // Hold the power button and lock the screen.
362 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 372 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
363 EXPECT_TRUE(test_api_->lock_timer_is_running()); 373 EXPECT_TRUE(test_api_->lock_timer_is_running());
364 EXPECT_TRUE( 374 EXPECT_TRUE(
365 test_api_->ContainersAreAnimated( 375 animator_api_->ContainersAreAnimated(
366 internal::SessionStateAnimator::DESKTOP_BACKGROUND | 376 internal::SessionStateAnimator::DESKTOP_BACKGROUND |
367 internal::SessionStateAnimator::LAUNCHER | 377 internal::SessionStateAnimator::LAUNCHER |
368 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 378 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
369 internal::SessionStateAnimator::ANIMATION_RESTORE)); 379 internal::SessionStateAnimator::ANIMATION_RESTORE));
370 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 380 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
371 test_api_->trigger_lock_timeout(); 381 test_api_->trigger_lock_timeout();
372 EXPECT_EQ(1, delegate_->num_lock_requests()); 382 EXPECT_EQ(1, delegate_->num_lock_requests());
373 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); 383 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
374 384
375 // We shouldn't start the lock-to-shutdown timer until the screen has actually 385 // We shouldn't start the lock-to-shutdown timer until the screen has actually
376 // been locked. 386 // been locked.
377 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 387 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
378 388
379 // Act as if the request timed out. We should restore the windows. 389 // Act as if the request timed out. We should restore the windows.
380 test_api_->trigger_lock_fail_timeout(); 390 test_api_->trigger_lock_fail_timeout();
381 EXPECT_TRUE( 391 EXPECT_TRUE(
382 test_api_->ContainersAreAnimated( 392 animator_api_->ContainersAreAnimated(
383 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 393 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
384 internal::SessionStateAnimator::ANIMATION_RESTORE)); 394 internal::SessionStateAnimator::ANIMATION_RESTORE));
385 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 395 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
386 } 396 }
387 397
388 // Test that we start the timer to hide the black layer when the power 398 // Test that we start the timer to hide the black layer when the power
389 // button is released, but that we cancel the timer if the button is pressed 399 // button is released, but that we cancel the timer if the button is pressed
390 // again before the timer has fired. 400 // again before the timer has fired.
391 TEST_F(PowerButtonControllerTest, CancelHideBackground) { 401 TEST_F(PowerButtonControllerTest, CancelHideBackground) {
392 controller_->set_has_legacy_power_button_for_test(false); 402 controller_->set_has_legacy_power_button_for_test(false);
393 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 403 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
394 controller_->OnLockStateChanged(false); 404 state_controller_->OnLockStateChanged(false);
395 405
396 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 406 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
397 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 407 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
398 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 408 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running());
399 409
400 // We should cancel the timer if we get another button-down event. 410 // We should cancel the timer if we get another button-down event.
401 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 411 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
402 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); 412 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running());
403 } 413 }
404 414
405 // Test the basic operation of the lock button. 415 // Test the basic operation of the lock button.
406 TEST_F(PowerButtonControllerTest, LockButtonBasic) { 416 TEST_F(PowerButtonControllerTest, LockButtonBasic) {
407 controller_->set_has_legacy_power_button_for_test(false); 417 controller_->set_has_legacy_power_button_for_test(false);
408 // The lock button shouldn't do anything if we aren't logged in. 418 // The lock button shouldn't do anything if we aren't logged in.
409 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 419 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
410 controller_->OnLockStateChanged(false); 420 state_controller_->OnLockStateChanged(false);
411 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 421 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
412 EXPECT_FALSE(test_api_->lock_timer_is_running()); 422 EXPECT_FALSE(test_api_->lock_timer_is_running());
413 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 423 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
414 EXPECT_EQ(0, delegate_->num_lock_requests()); 424 EXPECT_EQ(0, delegate_->num_lock_requests());
415 425
416 // Ditto for when we're logged in as a guest. 426 // Ditto for when we're logged in as a guest.
417 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); 427 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST);
418 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 428 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
419 EXPECT_FALSE(test_api_->lock_timer_is_running()); 429 EXPECT_FALSE(test_api_->lock_timer_is_running());
420 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 430 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
421 EXPECT_EQ(0, delegate_->num_lock_requests()); 431 EXPECT_EQ(0, delegate_->num_lock_requests());
422 432
423 // If we're logged in as a regular user, we should start the lock timer and 433 // If we're logged in as a regular user, we should start the lock timer and
424 // the pre-lock animation. 434 // the pre-lock animation.
425 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 435 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 436 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
427 EXPECT_TRUE(test_api_->lock_timer_is_running()); 437 EXPECT_TRUE(test_api_->lock_timer_is_running());
428 EXPECT_TRUE( 438 EXPECT_TRUE(
429 test_api_->ContainersAreAnimated( 439 animator_api_->ContainersAreAnimated(
430 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 440 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
431 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 441 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
432 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 442 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
433 443
434 // If the button is released immediately, we shouldn't lock the screen. 444 // If the button is released immediately, we shouldn't lock the screen.
435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 445 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
436 EXPECT_FALSE(test_api_->lock_timer_is_running()); 446 EXPECT_FALSE(test_api_->lock_timer_is_running());
437 EXPECT_TRUE( 447 EXPECT_TRUE(
438 test_api_->ContainersAreAnimated( 448 animator_api_->ContainersAreAnimated(
439 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 449 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
440 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); 450 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
441 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 451 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
442 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); 452 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running());
443 test_api_->TriggerHideBlackLayerTimeout(); 453 animator_api_->TriggerHideBlackLayerTimeout();
444 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); 454 EXPECT_FALSE(animator_api_->BlackLayerIsVisible());
445 EXPECT_EQ(0, delegate_->num_lock_requests()); 455 EXPECT_EQ(0, delegate_->num_lock_requests());
446 456
447 // Press the button again and let the lock timeout fire. We should request 457 // Press the button again and let the lock timeout fire. We should request
448 // that the screen be locked. 458 // that the screen be locked.
449 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 459 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
450 EXPECT_TRUE(test_api_->lock_timer_is_running()); 460 EXPECT_TRUE(test_api_->lock_timer_is_running());
451 test_api_->trigger_lock_timeout(); 461 test_api_->trigger_lock_timeout();
452 EXPECT_EQ(1, delegate_->num_lock_requests()); 462 EXPECT_EQ(1, delegate_->num_lock_requests());
453 463
454 // Pressing the lock button while we have a pending lock request shouldn't do 464 // Pressing the lock button while we have a pending lock request shouldn't do
455 // anything. 465 // anything.
456 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 466 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
457 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 467 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
458 EXPECT_FALSE(test_api_->lock_timer_is_running()); 468 EXPECT_FALSE(test_api_->lock_timer_is_running());
459 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 469 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
460 470
461 // Pressing the button also shouldn't do anything after the screen is locked. 471 // Pressing the button also shouldn't do anything after the screen is locked.
462 controller_->OnStartingLock(); 472 state_controller_->OnStartingLock();
463 controller_->OnLockStateChanged(true); 473 state_controller_->OnLockStateChanged(true);
464 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 474 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
465 EXPECT_FALSE(test_api_->lock_timer_is_running()); 475 EXPECT_FALSE(test_api_->lock_timer_is_running());
466 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 476 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
467 } 477 }
468 478
469 // Test that the power button takes priority over the lock button. 479 // Test that the power button takes priority over the lock button.
470 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { 480 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) {
471 controller_->set_has_legacy_power_button_for_test(false); 481 controller_->set_has_legacy_power_button_for_test(false);
472 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 482 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
473 controller_->OnLockStateChanged(false); 483 state_controller_->OnLockStateChanged(false);
474 484
475 // While the lock button is down, hold the power button. 485 // While the lock button is down, hold the power button.
476 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); 486 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
477 EXPECT_TRUE(test_api_->lock_timer_is_running()); 487 EXPECT_TRUE(test_api_->lock_timer_is_running());
478 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 488 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
479 EXPECT_TRUE(test_api_->lock_timer_is_running()); 489 EXPECT_TRUE(test_api_->lock_timer_is_running());
480 490
481 // The lock timer shouldn't be stopped when the lock button is released. 491 // The lock timer shouldn't be stopped when the lock button is released.
482 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 492 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
483 EXPECT_TRUE(test_api_->lock_timer_is_running()); 493 EXPECT_TRUE(test_api_->lock_timer_is_running());
(...skipping 10 matching lines...) Expand all
494 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 504 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
495 EXPECT_FALSE(test_api_->lock_timer_is_running()); 505 EXPECT_FALSE(test_api_->lock_timer_is_running());
496 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); 506 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
497 EXPECT_FALSE(test_api_->lock_timer_is_running()); 507 EXPECT_FALSE(test_api_->lock_timer_is_running());
498 } 508 }
499 509
500 // When the screen is locked without going through the usual power-button 510 // When the screen is locked without going through the usual power-button
501 // slow-close path (e.g. via the wrench menu), test that we still show the 511 // slow-close path (e.g. via the wrench menu), test that we still show the
502 // fast-close animation and display the black layer. 512 // fast-close animation and display the black layer.
503 TEST_F(PowerButtonControllerTest, LockWithoutButton) { 513 TEST_F(PowerButtonControllerTest, LockWithoutButton) {
504 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 514 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
505 controller_->OnStartingLock(); 515 state_controller_->OnStartingLock();
506 EXPECT_TRUE( 516 EXPECT_TRUE(
507 test_api_->ContainersAreAnimated( 517 animator_api_->ContainersAreAnimated(
508 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 518 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
509 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 519 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
510 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 520 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
511 } 521 }
512 522
513 // When we hear that the process is exiting but we haven't had a chance to 523 // When we hear that the process is exiting but we haven't had a chance to
514 // display an animation, we should just blank the screen. 524 // display an animation, we should just blank the screen.
515 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { 525 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) {
516 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 526 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
517 controller_->OnAppTerminating(); 527 state_controller_->OnAppTerminating();
518 EXPECT_TRUE( 528 EXPECT_TRUE(
519 test_api_->ContainersAreAnimated( 529 animator_api_->ContainersAreAnimated(
520 internal::SessionStateAnimator::kAllContainersMask, 530 internal::SessionStateAnimator::kAllContainersMask,
521 internal::SessionStateAnimator::ANIMATION_HIDE)); 531 internal::SessionStateAnimator::ANIMATION_HIDE));
522 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 532 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
523 GenerateMouseMoveEvent(); 533 GenerateMouseMoveEvent();
524 EXPECT_FALSE(cursor_visible()); 534 EXPECT_FALSE(cursor_visible());
525 } 535 }
526 536
527 // Test that we display the fast-close animation and shut down when we get an 537 // Test that we display the fast-close animation and shut down when we get an
528 // outside request to shut down (e.g. from the login or lock screen). 538 // outside request to shut down (e.g. from the login or lock screen).
529 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { 539 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) {
530 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); 540 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE);
531 controller_->RequestShutdown(); 541 state_controller_->RequestShutdown();
532 EXPECT_TRUE( 542 EXPECT_TRUE(
533 test_api_->ContainersAreAnimated( 543 animator_api_->ContainersAreAnimated(
534 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 544 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
535 internal::SessionStateAnimator::ANIMATION_HIDE)); 545 internal::SessionStateAnimator::ANIMATION_HIDE));
536 EXPECT_TRUE( 546 EXPECT_TRUE(
537 test_api_->ContainersAreAnimated( 547 animator_api_->ContainersAreAnimated(
538 internal::SessionStateAnimator::kAllLockScreenContainersMask, 548 internal::SessionStateAnimator::kAllLockScreenContainersMask,
539 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 549 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
540 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 550 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
541 GenerateMouseMoveEvent(); 551 GenerateMouseMoveEvent();
542 EXPECT_FALSE(cursor_visible()); 552 EXPECT_FALSE(cursor_visible());
543 553
544 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 554 EXPECT_EQ(0, delegate_->num_shutdown_requests());
545 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 555 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
546 test_api_->trigger_real_shutdown_timeout(); 556 test_api_->trigger_real_shutdown_timeout();
547 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 557 EXPECT_EQ(1, delegate_->num_shutdown_requests());
548 } 558 }
549 559
550 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { 560 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
551 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 561 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
552 controller_->OnLockStateChanged(true); 562 state_controller_->OnLockStateChanged(true);
553 controller_->RequestShutdown(); 563 state_controller_->RequestShutdown();
554 EXPECT_TRUE( 564 EXPECT_TRUE(
555 test_api_->ContainersAreAnimated( 565 animator_api_->ContainersAreAnimated(
556 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 566 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
557 internal::SessionStateAnimator::ANIMATION_HIDE)); 567 internal::SessionStateAnimator::ANIMATION_HIDE));
558 EXPECT_TRUE( 568 EXPECT_TRUE(
559 test_api_->ContainersAreAnimated( 569 animator_api_->ContainersAreAnimated(
560 internal::SessionStateAnimator::kAllLockScreenContainersMask, 570 internal::SessionStateAnimator::kAllLockScreenContainersMask,
561 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); 571 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE));
562 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 572 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
563 GenerateMouseMoveEvent(); 573 GenerateMouseMoveEvent();
564 EXPECT_FALSE(cursor_visible()); 574 EXPECT_FALSE(cursor_visible());
565 575
566 EXPECT_EQ(0, delegate_->num_shutdown_requests()); 576 EXPECT_EQ(0, delegate_->num_shutdown_requests());
567 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 577 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
568 test_api_->trigger_real_shutdown_timeout(); 578 test_api_->trigger_real_shutdown_timeout();
569 EXPECT_EQ(1, delegate_->num_shutdown_requests()); 579 EXPECT_EQ(1, delegate_->num_shutdown_requests());
570 } 580 }
571 581
572 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { 582 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) {
573 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 583 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
574 controller_->OnLockStateChanged(true); 584 state_controller_->OnLockStateChanged(true);
575 585
576 // Press the power button and check that we start the shutdown timer. 586 // Press the power button and check that we start the shutdown timer.
577 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 587 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
578 EXPECT_FALSE(test_api_->lock_timer_is_running()); 588 EXPECT_FALSE(test_api_->lock_timer_is_running());
579 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 589 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
580 EXPECT_TRUE( 590 EXPECT_TRUE(
581 test_api_->ContainersAreAnimated( 591 animator_api_->ContainersAreAnimated(
582 internal::SessionStateAnimator::kAllContainersMask, 592 internal::SessionStateAnimator::kAllContainersMask,
583 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); 593 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE));
584 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 594 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
585 595
586 // Release the power button before the shutdown timer fires. 596 // Release the power button before the shutdown timer fires.
587 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); 597 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
588 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 598 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
589 EXPECT_TRUE( 599 EXPECT_TRUE(
590 test_api_->ContainersAreAnimated( 600 animator_api_->ContainersAreAnimated(
591 internal::SessionStateAnimator::kAllLockScreenContainersMask, 601 internal::SessionStateAnimator::kAllLockScreenContainersMask,
592 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); 602 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE));
593 EXPECT_TRUE( 603 EXPECT_TRUE(
594 test_api_->ContainersAreAnimated( 604 animator_api_->ContainersAreAnimated(
595 internal::SessionStateAnimator::DESKTOP_BACKGROUND, 605 internal::SessionStateAnimator::DESKTOP_BACKGROUND,
596 internal::SessionStateAnimator::ANIMATION_RESTORE)); 606 internal::SessionStateAnimator::ANIMATION_RESTORE));
597 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); 607 EXPECT_TRUE(animator_api_->BlackLayerIsVisible());
598 } 608 }
599 609
600 // Test that the black layer is resized in response to root window resizes. 610 // Test that the black layer is resized in response to root window resizes.
601 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { 611 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) {
602 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 612 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
603 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), 613 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(),
604 test_api_->GetBlackLayerBounds().ToString()); 614 animator_api_->GetBlackLayerBounds().ToString());
605 615
606 const gfx::Size kNewSize(400, 300); 616 const gfx::Size kNewSize(400, 300);
607 Shell::GetPrimaryRootWindow()->SetHostSize(kNewSize); 617 Shell::GetPrimaryRootWindow()->SetHostSize(kNewSize);
608 EXPECT_EQ(gfx::Rect(kNewSize).ToString(), 618 EXPECT_EQ(gfx::Rect(kNewSize).ToString(),
609 test_api_->GetBlackLayerBounds().ToString()); 619 animator_api_->GetBlackLayerBounds().ToString());
610 } 620 }
611 621
612 // Test that we ignore power button presses when the screen is turned off. 622 // Test that we ignore power button presses when the screen is turned off.
613 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { 623 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) {
614 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); 624 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
615 625
616 // When the screen brightness is at 0%, we shouldn't do anything in response 626 // When the screen brightness is at 0%, we shouldn't do anything in response
617 // to power button presses. 627 // to power button presses.
618 controller_->OnScreenBrightnessChanged(0.0); 628 controller_->OnScreenBrightnessChanged(0.0);
619 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 629 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
620 EXPECT_FALSE(test_api_->lock_timer_is_running()); 630 EXPECT_FALSE(test_api_->lock_timer_is_running());
621 631
622 // After increasing the brightness to 10%, we should start the timer like 632 // After increasing the brightness to 10%, we should start the timer like
623 // usual. 633 // usual.
624 controller_->OnScreenBrightnessChanged(10.0); 634 controller_->OnScreenBrightnessChanged(10.0);
625 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 635 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
626 EXPECT_TRUE(test_api_->lock_timer_is_running()); 636 EXPECT_TRUE(test_api_->lock_timer_is_running());
627 } 637 }
628 638
629 } // namespace test 639 } // namespace test
630 } // namespace ash 640 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698