OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/session_state_controller_impl2.h" | 5 #include "ash/wm/session_state_controller_impl2.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" |
11 #include "ash/wm/cursor_manager.h" | 12 #include "ash/wm/cursor_manager.h" |
12 #include "ash/wm/power_button_controller.h" | 13 #include "ash/wm/power_button_controller.h" |
13 #include "ash/wm/session_state_animator.h" | 14 #include "ash/wm/session_state_animator.h" |
14 #include "ash/wm/session_state_controller.h" | 15 #include "ash/wm/session_state_controller.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
19 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
20 #include "ui/aura/test/event_generator.h" | 21 #include "ui/aura/test/event_generator.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/compositor/test/compositor_test_support.h" |
21 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
22 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
23 | 26 |
| 27 |
24 namespace ash { | 28 namespace ash { |
| 29 |
| 30 using internal::SessionStateAnimator; |
| 31 |
25 namespace test { | 32 namespace test { |
| 33 |
26 namespace { | 34 namespace { |
| 35 |
27 bool cursor_visible() { | 36 bool cursor_visible() { |
28 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); | 37 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
29 } | 38 } |
30 | 39 |
31 void CheckCalledCallback(bool* flag) { | 40 void CheckCalledCallback(bool* flag) { |
32 (*flag) = true; | 41 if (flag) |
| 42 (*flag) = true; |
33 } | 43 } |
| 44 |
| 45 aura::Window* GetContainer(int container ) { |
| 46 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 47 return Shell::GetContainer(root_window, container); |
34 } | 48 } |
35 | 49 |
| 50 bool IsBackgroundHidden() { |
| 51 return !GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
| 52 IsVisible(); |
| 53 } |
| 54 |
| 55 void ShowBackground() { |
| 56 ui::ScopedLayerAnimationSettings settings( |
| 57 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
| 58 layer()->GetAnimator()); |
| 59 settings.SetTransitionDuration(base::TimeDelta()); |
| 60 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->Show(); |
| 61 } |
| 62 |
| 63 void HideBackground() { |
| 64 ui::ScopedLayerAnimationSettings settings( |
| 65 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> |
| 66 layer()->GetAnimator()); |
| 67 settings.SetTransitionDuration(base::TimeDelta()); |
| 68 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->Hide(); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
36 // Fake implementation of PowerButtonControllerDelegate that just logs requests | 73 // Fake implementation of PowerButtonControllerDelegate that just logs requests |
37 // to lock the screen and shut down the device. | 74 // to lock the screen and shut down the device. |
38 class TestSessionStateControllerDelegate : | 75 class TestSessionStateControllerDelegate : |
39 public SessionStateControllerDelegate { | 76 public SessionStateControllerDelegate { |
40 public: | 77 public: |
41 TestSessionStateControllerDelegate() | 78 TestSessionStateControllerDelegate() |
42 : num_lock_requests_(0), | 79 : num_lock_requests_(0), |
43 num_shutdown_requests_(0) {} | 80 num_shutdown_requests_(0) {} |
44 | 81 |
45 int num_lock_requests() const { return num_lock_requests_; } | 82 int num_lock_requests() const { return num_lock_requests_; } |
(...skipping 17 matching lines...) Expand all Loading... |
63 class SessionStateControllerImpl2Test : public AshTestBase { | 100 class SessionStateControllerImpl2Test : public AshTestBase { |
64 public: | 101 public: |
65 SessionStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} | 102 SessionStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} |
66 virtual ~SessionStateControllerImpl2Test() {} | 103 virtual ~SessionStateControllerImpl2Test() {} |
67 | 104 |
68 virtual void SetUp() OVERRIDE { | 105 virtual void SetUp() OVERRIDE { |
69 CommandLine::ForCurrentProcess()->AppendSwitch( | 106 CommandLine::ForCurrentProcess()->AppendSwitch( |
70 ash::switches::kAshNewLockAnimationsEnabled); | 107 ash::switches::kAshNewLockAnimationsEnabled); |
71 | 108 |
72 AshTestBase::SetUp(); | 109 AshTestBase::SetUp(); |
| 110 |
| 111 // We would control animations in a fine way: |
| 112 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 113 //ToDo(antrim) : restore |
| 114 // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest(); |
| 115 |
73 delegate_ = new TestSessionStateControllerDelegate; | 116 delegate_ = new TestSessionStateControllerDelegate; |
74 controller_ = Shell::GetInstance()->power_button_controller(); | 117 controller_ = Shell::GetInstance()->power_button_controller(); |
75 state_controller_ = static_cast<SessionStateControllerImpl2*>( | 118 state_controller_ = static_cast<SessionStateControllerImpl2*>( |
76 Shell::GetInstance()->session_state_controller()); | 119 Shell::GetInstance()->session_state_controller()); |
77 state_controller_->SetDelegate(delegate_); // transfers ownership | 120 state_controller_->SetDelegate(delegate_); // transfers ownership |
78 test_api_.reset( | 121 test_api_.reset( |
79 new SessionStateControllerImpl2::TestApi(state_controller_)); | 122 new SessionStateControllerImpl2::TestApi(state_controller_)); |
80 animator_api_.reset( | 123 animator_api_.reset( |
81 new internal::SessionStateAnimator::TestApi(state_controller_-> | 124 new SessionStateAnimator::TestApi(state_controller_-> |
82 animator_.get())); | 125 animator_.get())); |
83 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( | 126 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( |
84 ash::Shell::GetInstance()->delegate()); | 127 ash::Shell::GetInstance()->delegate()); |
85 } | 128 } |
86 | 129 |
| 130 void TearDown() { |
| 131 //ToDo(antrim) : restore |
| 132 // animator_helper_->AdvanceUntilDone(); |
| 133 AshTestBase::TearDown(); |
| 134 } |
| 135 |
87 protected: | 136 protected: |
88 void GenerateMouseMoveEvent() { | 137 void GenerateMouseMoveEvent() { |
89 aura::test::EventGenerator generator( | 138 aura::test::EventGenerator generator( |
90 Shell::GetPrimaryRootWindow()); | 139 Shell::GetPrimaryRootWindow()); |
91 generator.MoveMouseTo(10, 10); | 140 generator.MoveMouseTo(10, 10); |
92 } | 141 } |
93 | 142 |
94 int NumShutdownRequests() { | 143 int NumShutdownRequests() { |
95 return delegate_->num_shutdown_requests() + | 144 return delegate_->num_shutdown_requests() + |
96 shell_delegate_->num_exit_requests(); | 145 shell_delegate_->num_exit_requests(); |
97 } | 146 } |
98 | 147 |
| 148 void Advance(SessionStateAnimator::AnimationSpeed speed) { |
| 149 // ToDo (antrim) : restore |
| 150 // animator_helper_->Advance(SessionStateAnimator::GetDuration(speed)); |
| 151 } |
| 152 |
| 153 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed, |
| 154 float factor) { |
| 155 // ToDo (antrim) : restore |
| 156 // base::TimeDelta duration = SessionStateAnimator::GetDuration(speed); |
| 157 // base::TimeDelta partial_duration = |
| 158 // base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor); |
| 159 // animator_helper_->Advance(partial_duration); |
| 160 } |
| 161 |
| 162 void ExpectPreLockAnimationStarted() { |
| 163 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 164 EXPECT_TRUE( |
| 165 animator_api_->ContainersAreAnimated( |
| 166 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 167 SessionStateAnimator::ANIMATION_LIFT)); |
| 168 EXPECT_TRUE( |
| 169 animator_api_->ContainersAreAnimated( |
| 170 SessionStateAnimator::LAUNCHER, |
| 171 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 172 EXPECT_TRUE( |
| 173 animator_api_->ContainersAreAnimated( |
| 174 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 175 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| 176 EXPECT_TRUE(test_api_->is_animating_lock()); |
| 177 } |
| 178 |
| 179 void ExpectPreLockAnimationCancel() { |
| 180 EXPECT_TRUE( |
| 181 animator_api_->ContainersAreAnimated( |
| 182 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 183 SessionStateAnimator::ANIMATION_DROP)); |
| 184 EXPECT_TRUE( |
| 185 animator_api_->ContainersAreAnimated( |
| 186 SessionStateAnimator::LAUNCHER, |
| 187 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 188 } |
| 189 |
| 190 void ExpectPreLockAnimationFinished() { |
| 191 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 192 EXPECT_TRUE( |
| 193 animator_api_->ContainersAreAnimated( |
| 194 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 195 SessionStateAnimator::ANIMATION_LIFT)); |
| 196 EXPECT_TRUE( |
| 197 animator_api_->ContainersAreAnimated( |
| 198 SessionStateAnimator::LAUNCHER, |
| 199 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 200 EXPECT_TRUE( |
| 201 animator_api_->ContainersAreAnimated( |
| 202 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 203 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| 204 } |
| 205 |
| 206 void ExpectPostLockAnimationStarted() { |
| 207 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 208 EXPECT_TRUE( |
| 209 animator_api_->ContainersAreAnimated( |
| 210 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 211 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| 212 } |
| 213 |
| 214 void ExpectPastLockAnimationFinished() { |
| 215 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 216 EXPECT_TRUE( |
| 217 animator_api_->ContainersAreAnimated( |
| 218 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 219 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| 220 } |
| 221 |
| 222 void ExpectUnlockBeforeUIDestroyedAnimationStarted() { |
| 223 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 224 EXPECT_TRUE( |
| 225 animator_api_->ContainersAreAnimated( |
| 226 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 227 SessionStateAnimator::ANIMATION_LIFT)); |
| 228 } |
| 229 |
| 230 void ExpectUnlockBeforeUIDestroyedAnimationFinished() { |
| 231 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 232 EXPECT_TRUE( |
| 233 animator_api_->ContainersAreAnimated( |
| 234 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 235 SessionStateAnimator::ANIMATION_LIFT)); |
| 236 } |
| 237 |
| 238 void ExpectUnlockAfterUIDestroyedAnimationStarted() { |
| 239 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 240 EXPECT_TRUE( |
| 241 animator_api_->ContainersAreAnimated( |
| 242 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 243 SessionStateAnimator::ANIMATION_DROP)); |
| 244 EXPECT_TRUE( |
| 245 animator_api_->ContainersAreAnimated( |
| 246 SessionStateAnimator::LAUNCHER, |
| 247 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 248 } |
| 249 |
| 250 void ExpectUnlockAfterUIDestroyedAnimationFinished() { |
| 251 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 252 EXPECT_TRUE( |
| 253 animator_api_->ContainersAreAnimated( |
| 254 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 255 SessionStateAnimator::ANIMATION_DROP)); |
| 256 EXPECT_TRUE( |
| 257 animator_api_->ContainersAreAnimated( |
| 258 SessionStateAnimator::LAUNCHER, |
| 259 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 260 } |
| 261 |
| 262 void ExpectShutdownAnimationStarted() { |
| 263 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 264 EXPECT_TRUE( |
| 265 animator_api_->RootWindowIsAnimated( |
| 266 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| 267 } |
| 268 |
| 269 void ExpectShutdownAnimationFinished() { |
| 270 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 271 EXPECT_TRUE( |
| 272 animator_api_->RootWindowIsAnimated( |
| 273 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| 274 } |
| 275 |
| 276 void ExpectShutdownAnimationCancel() { |
| 277 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 278 EXPECT_TRUE( |
| 279 animator_api_->RootWindowIsAnimated( |
| 280 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| 281 } |
| 282 |
| 283 void ExpectBackgroundIsShowing() { |
| 284 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 285 EXPECT_TRUE( |
| 286 animator_api_->ContainersAreAnimated( |
| 287 SessionStateAnimator::DESKTOP_BACKGROUND, |
| 288 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 289 } |
| 290 |
| 291 void ExpectBackgroundIsHiding() { |
| 292 //ToDo (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 293 EXPECT_TRUE( |
| 294 animator_api_->ContainersAreAnimated( |
| 295 SessionStateAnimator::DESKTOP_BACKGROUND, |
| 296 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 297 } |
| 298 |
| 299 void ExpectUnlockedState() { |
| 300 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 301 EXPECT_FALSE(shell_delegate_->IsScreenLocked()); |
| 302 |
| 303 aura::Window::Windows containers; |
| 304 |
| 305 SessionStateAnimator::GetContainers( |
| 306 SessionStateAnimator::LAUNCHER | |
| 307 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 308 &containers); |
| 309 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 310 it != containers.end(); ++it) { |
| 311 aura::Window* window = *it; |
| 312 ui::Layer* layer = window->layer(); |
| 313 EXPECT_EQ(1.0f, layer->opacity()); |
| 314 EXPECT_EQ(0.0f, layer->layer_brightness()); |
| 315 EXPECT_EQ(0.0f, layer->layer_saturation()); |
| 316 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 317 } |
| 318 } |
| 319 |
| 320 void ExpectLockedState() { |
| 321 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 322 EXPECT_TRUE(shell_delegate_->IsScreenLocked()); |
| 323 |
| 324 aura::Window::Windows containers; |
| 325 |
| 326 SessionStateAnimator::GetContainers( |
| 327 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS | |
| 328 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 329 &containers); |
| 330 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 331 it != containers.end(); ++it) { |
| 332 aura::Window* window = *it; |
| 333 ui::Layer* layer = window->layer(); |
| 334 EXPECT_EQ(1.0f, layer->opacity()); |
| 335 EXPECT_EQ(0.0f, layer->layer_brightness()); |
| 336 EXPECT_EQ(0.0f, layer->layer_saturation()); |
| 337 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 338 } |
| 339 } |
| 340 |
| 341 void PressPowerButton() { |
| 342 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 343 //ToDo (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| 344 } |
| 345 |
| 346 void ReleasePowerButton() { |
| 347 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 348 //ToDo (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| 349 } |
| 350 |
| 351 void PressLockButton() { |
| 352 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 353 } |
| 354 |
| 355 void ReleaseLockButton() { |
| 356 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 357 } |
| 358 |
| 359 void SystemLocks() { |
| 360 state_controller_->OnLockStateChanged(true); |
| 361 shell_delegate_->LockScreen(); |
| 362 //ToDo (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| 363 } |
| 364 |
| 365 void SuccessfulAuthentication(bool* call_flag) { |
| 366 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
| 367 state_controller_->OnLockScreenHide(closure); |
| 368 //ToDo (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| 369 } |
| 370 |
| 371 void SystemUnlocks() { |
| 372 state_controller_->OnLockStateChanged(false); |
| 373 shell_delegate_->UnlockScreen(); |
| 374 //ToDo (antrim) : restore animator_helper_->Advance(base::TimeDelta()); |
| 375 } |
| 376 |
| 377 void Initialize(bool legacy_button, user::LoginStatus status) { |
| 378 controller_->set_has_legacy_power_button_for_test(legacy_button); |
| 379 state_controller_->OnLoginStateChanged(status); |
| 380 SetUserLoggedIn(status != user::LOGGED_IN_NONE); |
| 381 if (status == user::LOGGED_IN_GUEST) |
| 382 SetCanLockScreen(false); |
| 383 state_controller_->OnLockStateChanged(false); |
| 384 } |
| 385 |
99 PowerButtonController* controller_; // not owned | 386 PowerButtonController* controller_; // not owned |
100 SessionStateControllerImpl2* state_controller_; // not owned | 387 SessionStateControllerImpl2* state_controller_; // not owned |
101 TestSessionStateControllerDelegate* delegate_; // not owned | 388 TestSessionStateControllerDelegate* delegate_; // not owned |
102 TestShellDelegate* shell_delegate_; // not owned | 389 TestShellDelegate* shell_delegate_; // not owned |
103 | 390 |
104 scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; | 391 scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; |
105 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; | 392 scoped_ptr<SessionStateAnimator::TestApi> animator_api_; |
| 393 //ToDo(antrim) : restore |
| 394 // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_; |
106 | 395 |
107 private: | 396 private: |
108 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test); | 397 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test); |
109 }; | 398 }; |
110 | 399 |
111 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 400 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
112 // correctly report power button releases. We should lock immediately the first | 401 // correctly report power button releases. We should lock immediately the first |
113 // time the button is pressed and shut down when it's pressed from the locked | 402 // time the button is pressed and shut down when it's pressed from the locked |
114 // state. | 403 // state. |
115 TEST_F(SessionStateControllerImpl2Test, LegacyLockAndShutDown) { | 404 TEST_F(SessionStateControllerImpl2Test, DISABLED_LegacyLockAndShutDown) { |
116 controller_->set_has_legacy_power_button_for_test(true); | 405 Initialize(true, user::LOGGED_IN_USER); |
117 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 406 |
118 state_controller_->OnLockStateChanged(false); | 407 ExpectUnlockedState(); |
119 | 408 |
120 // We should request that the screen be locked immediately after seeing the | 409 // We should request that the screen be locked immediately after seeing the |
121 // power button get pressed. | 410 // power button get pressed. |
122 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 411 PressPowerButton(); |
123 EXPECT_TRUE( | |
124 animator_api_->ContainersAreAnimated( | |
125 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
126 internal::SessionStateAnimator::LAUNCHER, | |
127 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
128 | 412 |
129 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 413 ExpectPreLockAnimationStarted(); |
| 414 |
| 415 EXPECT_FALSE(test_api_->is_lock_cancellable()); |
| 416 |
| 417 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 418 |
| 419 ExpectPreLockAnimationFinished(); |
130 EXPECT_EQ(1, delegate_->num_lock_requests()); | 420 EXPECT_EQ(1, delegate_->num_lock_requests()); |
131 | 421 |
132 // Notify that we locked successfully. | 422 // Notify that we locked successfully. |
133 state_controller_->OnStartingLock(); | 423 state_controller_->OnStartingLock(); |
| 424 // We had that animation already. |
| 425 //ToDo (antrim) : restore |
| 426 // EXPECT_FALSE(animator_helper_->IsAnimating()); |
134 | 427 |
135 EXPECT_TRUE( | 428 SystemLocks(); |
136 animator_api_->ContainersAreAnimated( | |
137 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
138 internal::SessionStateAnimator::LAUNCHER, | |
139 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
140 EXPECT_TRUE( | |
141 animator_api_->ContainersAreAnimated( | |
142 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
143 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | |
144 | 429 |
145 | 430 ExpectPostLockAnimationStarted(); |
146 // Notify that the lock window is visible. We should make it fade in. | 431 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
147 state_controller_->OnLockStateChanged(true); | 432 ExpectPastLockAnimationFinished(); |
148 shell_delegate_->LockScreen(); | |
149 | |
150 EXPECT_TRUE( | |
151 animator_api_->ContainersAreAnimated( | |
152 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
153 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
154 | 433 |
155 // We shouldn't progress towards the shutdown state, however. | 434 // We shouldn't progress towards the shutdown state, however. |
156 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 435 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
157 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 436 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
158 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 437 |
| 438 ReleasePowerButton(); |
159 | 439 |
160 // Hold the button again and check that we start shutting down. | 440 // Hold the button again and check that we start shutting down. |
161 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 441 PressPowerButton(); |
| 442 |
| 443 ExpectShutdownAnimationStarted(); |
| 444 |
162 EXPECT_EQ(0, NumShutdownRequests()); | 445 EXPECT_EQ(0, NumShutdownRequests()); |
163 | |
164 EXPECT_TRUE( | |
165 animator_api_->RootWindowIsAnimated( | |
166 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | |
167 // Make sure a mouse move event won't show the cursor. | 446 // Make sure a mouse move event won't show the cursor. |
168 GenerateMouseMoveEvent(); | 447 GenerateMouseMoveEvent(); |
169 EXPECT_FALSE(cursor_visible()); | 448 EXPECT_FALSE(cursor_visible()); |
| 449 |
170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 450 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
171 test_api_->trigger_real_shutdown_timeout(); | 451 test_api_->trigger_real_shutdown_timeout(); |
172 EXPECT_EQ(1, NumShutdownRequests()); | 452 EXPECT_EQ(1, NumShutdownRequests()); |
173 } | 453 } |
174 | 454 |
175 // Test that we start shutting down immediately if the power button is pressed | 455 // Test that we start shutting down immediately if the power button is pressed |
176 // while we're not logged in on an unofficial system. | 456 // while we're not logged in on an unofficial system. |
177 TEST_F(SessionStateControllerImpl2Test, LegacyNotLoggedIn) { | 457 TEST_F(SessionStateControllerImpl2Test, LegacyNotLoggedIn) { |
178 controller_->set_has_legacy_power_button_for_test(true); | 458 Initialize(true, user::LOGGED_IN_NONE); |
179 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 459 |
180 state_controller_->OnLockStateChanged(false); | 460 PressPowerButton(); |
181 SetUserLoggedIn(false); | 461 ExpectShutdownAnimationStarted(); |
182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 462 |
183 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 463 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
184 } | 464 } |
185 | 465 |
186 // Test that we start shutting down immediately if the power button is pressed | 466 // Test that we start shutting down immediately if the power button is pressed |
187 // while we're logged in as a guest on an unofficial system. | 467 // while we're logged in as a guest on an unofficial system. |
188 TEST_F(SessionStateControllerImpl2Test, LegacyGuest) { | 468 TEST_F(SessionStateControllerImpl2Test, LegacyGuest) { |
189 controller_->set_has_legacy_power_button_for_test(true); | 469 Initialize(true, user::LOGGED_IN_GUEST); |
190 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 470 |
191 state_controller_->OnLockStateChanged(false); | 471 PressPowerButton(); |
192 SetCanLockScreen(false); | 472 ExpectShutdownAnimationStarted(); |
193 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 473 |
194 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 474 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
195 } | 475 } |
196 | 476 |
197 // When we hold the power button while the user isn't logged in, we should shut | 477 // When we hold the power button while the user isn't logged in, we should shut |
198 // down the machine directly. | 478 // down the machine directly. |
199 TEST_F(SessionStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { | 479 TEST_F(SessionStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { |
200 controller_->set_has_legacy_power_button_for_test(false); | 480 Initialize(false, user::LOGGED_IN_NONE); |
201 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | |
202 state_controller_->OnLockStateChanged(false); | |
203 SetUserLoggedIn(false); | |
204 | 481 |
205 // Press the power button and check that we start the shutdown timer. | 482 // Press the power button and check that we start the shutdown timer. |
206 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 483 PressPowerButton(); |
207 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 484 EXPECT_FALSE(test_api_->is_animating_lock()); |
208 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 485 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
209 EXPECT_TRUE( | 486 ExpectShutdownAnimationStarted(); |
210 animator_api_->RootWindowIsAnimated( | 487 |
211 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 488 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
212 | 489 |
213 // Release the power button before the shutdown timer fires. | 490 // Release the power button before the shutdown timer fires. |
214 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 491 ReleasePowerButton(); |
| 492 |
215 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 493 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
216 EXPECT_TRUE( | 494 ExpectShutdownAnimationCancel(); |
217 animator_api_->RootWindowIsAnimated( | 495 |
218 internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); | 496 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f); |
219 | 497 |
220 // Press the button again and make the shutdown timeout fire this time. | 498 // Press the button again and make the shutdown timeout fire this time. |
221 // Check that we start the timer for actually requesting the shutdown. | 499 // Check that we start the timer for actually requesting the shutdown. |
222 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 500 PressPowerButton(); |
| 501 |
223 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 502 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 503 |
| 504 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 505 ExpectShutdownAnimationFinished(); |
224 test_api_->trigger_shutdown_timeout(); | 506 test_api_->trigger_shutdown_timeout(); |
| 507 |
225 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 508 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
226 EXPECT_EQ(0, NumShutdownRequests()); | 509 EXPECT_EQ(0, NumShutdownRequests()); |
227 EXPECT_TRUE( | |
228 animator_api_->RootWindowIsAnimated( | |
229 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | |
230 | 510 |
231 // When the timout fires, we should request a shutdown. | 511 // When the timout fires, we should request a shutdown. |
232 test_api_->trigger_real_shutdown_timeout(); | 512 test_api_->trigger_real_shutdown_timeout(); |
| 513 |
233 EXPECT_EQ(1, NumShutdownRequests()); | 514 EXPECT_EQ(1, NumShutdownRequests()); |
234 } | 515 } |
235 | 516 |
236 // Test that we lock the screen and deal with unlocking correctly. | 517 // Test that we lock the screen and deal with unlocking correctly. |
237 TEST_F(SessionStateControllerImpl2Test, LockAndUnlock) { | 518 TEST_F(SessionStateControllerImpl2Test, DISABLED_LockAndUnlock) { |
238 controller_->set_has_legacy_power_button_for_test(false); | 519 Initialize(false, user::LOGGED_IN_USER); |
239 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 520 |
240 state_controller_->OnLockStateChanged(false); | 521 ExpectUnlockedState(); |
241 | |
242 // We should initially be showing the screen locker containers, since they | |
243 // also contain login-related windows that we want to show during the | |
244 // logging-in animation. | |
245 EXPECT_TRUE( | |
246 animator_api_->ContainersAreAnimated( | |
247 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
248 internal::SessionStateAnimator::ANIMATION_RESTORE)); | |
249 | 522 |
250 // Press the power button and check that the lock timer is started and that we | 523 // Press the power button and check that the lock timer is started and that we |
251 // start lifting the non-screen-locker containers. | 524 // start lifting the non-screen-locker containers. |
252 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 525 PressPowerButton(); |
253 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 526 |
254 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 527 ExpectPreLockAnimationStarted(); |
255 EXPECT_TRUE( | 528 EXPECT_TRUE(test_api_->is_lock_cancellable()); |
256 animator_api_->ContainersAreAnimated( | |
257 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
258 internal::SessionStateAnimator::LAUNCHER, | |
259 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
260 | |
261 // Release the button before the lock timer fires. | |
262 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | |
263 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
264 EXPECT_TRUE( | |
265 animator_api_->ContainersAreAnimated( | |
266 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
267 internal::SessionStateAnimator::LAUNCHER, | |
268 internal::SessionStateAnimator::ANIMATION_DROP)); | |
269 | |
270 // Press the button and fire the lock timer. We should request that the | |
271 // screen be locked, but we should still be in the lift animation. | |
272 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
273 EXPECT_TRUE(test_api_->lock_timer_is_running()); | |
274 EXPECT_EQ(0, delegate_->num_lock_requests()); | 529 EXPECT_EQ(0, delegate_->num_lock_requests()); |
275 test_api_->trigger_lock_timeout(); | 530 |
| 531 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 532 ExpectPreLockAnimationFinished(); |
| 533 |
276 EXPECT_EQ(1, delegate_->num_lock_requests()); | 534 EXPECT_EQ(1, delegate_->num_lock_requests()); |
277 EXPECT_TRUE( | |
278 animator_api_->ContainersAreAnimated( | |
279 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
280 internal::SessionStateAnimator::LAUNCHER, | |
281 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
282 | 535 |
283 // Notify that we locked successfully. | 536 // Notify that we locked successfully. |
284 state_controller_->OnStartingLock(); | 537 state_controller_->OnStartingLock(); |
285 EXPECT_TRUE( | 538 // We had that animation already. |
286 animator_api_->ContainersAreAnimated( | 539 //ToDo (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); |
287 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 540 |
288 internal::SessionStateAnimator::LAUNCHER, | 541 SystemLocks(); |
289 internal::SessionStateAnimator::ANIMATION_LIFT)); | 542 |
290 EXPECT_TRUE( | 543 ExpectPostLockAnimationStarted(); |
291 animator_api_->ContainersAreAnimated( | 544 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
292 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 545 ExpectPastLockAnimationFinished(); |
293 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | |
294 | |
295 // Notify that the lock window is visible. We should make it raise in. | |
296 state_controller_->OnLockStateChanged(true); | |
297 shell_delegate_->LockScreen(); | |
298 EXPECT_TRUE( | |
299 animator_api_->ContainersAreAnimated( | |
300 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
301 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
302 | 546 |
303 // When we release the power button, the lock-to-shutdown timer should be | 547 // When we release the power button, the lock-to-shutdown timer should be |
304 // stopped. | 548 // stopped. |
| 549 ExpectLockedState(); |
305 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 550 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
306 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 551 ReleasePowerButton(); |
| 552 ExpectLockedState(); |
307 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 553 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
308 | 554 |
309 // Notify that the screen has been unlocked. We should show the | 555 // Notify that the screen has been unlocked. We should show the |
310 // non-screen-locker windows. | 556 // non-screen-locker windows. |
311 state_controller_->OnLockStateChanged(false); | |
312 shell_delegate_->UnlockScreen(); | |
313 bool called = false; | 557 bool called = false; |
314 base::Closure closure = base::Bind(&CheckCalledCallback, &called); | 558 SuccessfulAuthentication(&called); |
315 state_controller_->OnLockScreenHide(closure); | 559 |
316 EXPECT_TRUE( | 560 ExpectUnlockBeforeUIDestroyedAnimationStarted(); |
317 animator_api_->ContainersAreAnimated( | 561 EXPECT_FALSE(called); |
318 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 562 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
319 internal::SessionStateAnimator::ANIMATION_LIFT)); | 563 ExpectUnlockBeforeUIDestroyedAnimationFinished(); |
| 564 |
320 EXPECT_TRUE(called); | 565 EXPECT_TRUE(called); |
321 EXPECT_TRUE( | 566 |
322 animator_api_->ContainersAreAnimated( | 567 SystemUnlocks(); |
323 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 568 |
324 internal::SessionStateAnimator::LAUNCHER, | 569 ExpectUnlockAfterUIDestroyedAnimationStarted(); |
325 internal::SessionStateAnimator::ANIMATION_DROP)); | 570 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 571 ExpectUnlockAfterUIDestroyedAnimationFinished(); |
| 572 |
| 573 ExpectUnlockedState(); |
| 574 } |
| 575 |
| 576 // Test that we deal with cancelling lock correctly. |
| 577 TEST_F(SessionStateControllerImpl2Test, LockAndCancel) { |
| 578 Initialize(false, user::LOGGED_IN_USER); |
| 579 |
| 580 ExpectUnlockedState(); |
| 581 |
| 582 // Press the power button and check that the lock timer is started and that we |
| 583 // start lifting the non-screen-locker containers. |
| 584 PressPowerButton(); |
| 585 |
| 586 ExpectPreLockAnimationStarted(); |
| 587 EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 588 |
| 589 // forward only half way through |
| 590 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 591 |
| 592 gfx::Transform transform_before_button_released = |
| 593 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 594 layer()->transform(); |
| 595 |
| 596 // Release the button before the lock timer fires. |
| 597 ReleasePowerButton(); |
| 598 |
| 599 ExpectPreLockAnimationCancel(); |
| 600 |
| 601 gfx::Transform transform_after_button_released = |
| 602 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 603 layer()->transform(); |
| 604 // Expect no flickering, animation should proceed from mid-state. |
| 605 EXPECT_EQ(transform_before_button_released, transform_after_button_released); |
| 606 |
| 607 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 608 ExpectUnlockedState(); |
| 609 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 610 } |
| 611 |
| 612 // Test that we deal with cancelling lock correctly. |
| 613 TEST_F(SessionStateControllerImpl2Test, DISABLED_LockAndCancelAndLockAgain) { |
| 614 Initialize(false, user::LOGGED_IN_USER); |
| 615 |
| 616 ExpectUnlockedState(); |
| 617 |
| 618 // Press the power button and check that the lock timer is started and that we |
| 619 // start lifting the non-screen-locker containers. |
| 620 PressPowerButton(); |
| 621 |
| 622 ExpectPreLockAnimationStarted(); |
| 623 EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 624 |
| 625 // forward only half way through |
| 626 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 627 |
| 628 // Release the button before the lock timer fires. |
| 629 ReleasePowerButton(); |
| 630 ExpectPreLockAnimationCancel(); |
| 631 |
| 632 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); |
| 633 |
| 634 PressPowerButton(); |
| 635 ExpectPreLockAnimationStarted(); |
| 636 EXPECT_TRUE(test_api_->is_lock_cancellable()); |
| 637 |
| 638 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| 639 |
| 640 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 641 ExpectPreLockAnimationStarted(); |
| 642 |
| 643 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f); |
| 644 ExpectPreLockAnimationFinished(); |
| 645 EXPECT_EQ(1, delegate_->num_lock_requests()); |
326 } | 646 } |
327 | 647 |
328 // Hold the power button down from the unlocked state to eventual shutdown. | 648 // Hold the power button down from the unlocked state to eventual shutdown. |
329 TEST_F(SessionStateControllerImpl2Test, LockToShutdown) { | 649 TEST_F(SessionStateControllerImpl2Test, DISABLED_LockToShutdown) { |
330 controller_->set_has_legacy_power_button_for_test(false); | 650 Initialize(false, user::LOGGED_IN_USER); |
331 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
332 state_controller_->OnLockStateChanged(false); | |
333 | 651 |
334 // Hold the power button and lock the screen. | 652 // Hold the power button and lock the screen. |
335 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 653 PressPowerButton(); |
336 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 654 EXPECT_TRUE(test_api_->is_animating_lock()); |
337 test_api_->trigger_lock_timeout(); | 655 |
338 state_controller_->OnStartingLock(); | 656 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
339 state_controller_->OnLockStateChanged(true); | 657 SystemLocks(); |
340 shell_delegate_->LockScreen(); | 658 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
341 | 659 |
342 // When the lock-to-shutdown timeout fires, we should start the shutdown | 660 // When the lock-to-shutdown timeout fires, we should start the shutdown |
343 // timer. | 661 // timer. |
344 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 662 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 663 |
345 test_api_->trigger_lock_to_shutdown_timeout(); | 664 test_api_->trigger_lock_to_shutdown_timeout(); |
| 665 |
| 666 ExpectShutdownAnimationStarted(); |
346 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 667 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
347 EXPECT_TRUE( | |
348 animator_api_->ContainersAreAnimated( | |
349 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
350 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
351 | 668 |
352 // Fire the shutdown timeout and check that we request shutdown. | 669 // Fire the shutdown timeout and check that we request shutdown. |
| 670 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 671 ExpectShutdownAnimationFinished(); |
353 test_api_->trigger_shutdown_timeout(); | 672 test_api_->trigger_shutdown_timeout(); |
| 673 |
354 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 674 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
355 EXPECT_EQ(0, NumShutdownRequests()); | 675 EXPECT_EQ(0, NumShutdownRequests()); |
356 test_api_->trigger_real_shutdown_timeout(); | 676 test_api_->trigger_real_shutdown_timeout(); |
357 EXPECT_EQ(1, NumShutdownRequests()); | 677 EXPECT_EQ(1, NumShutdownRequests()); |
358 } | 678 } |
359 | 679 |
360 | |
361 // Hold the power button down from the unlocked state to eventual shutdown, | 680 // Hold the power button down from the unlocked state to eventual shutdown, |
362 // then release the button while system does locking. | 681 // then release the button while system does locking. |
363 TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { | 682 TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { |
364 controller_->set_has_legacy_power_button_for_test(false); | 683 Initialize(false, user::LOGGED_IN_USER); |
365 | 684 |
366 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 685 PressPowerButton(); |
367 state_controller_->OnLockStateChanged(false); | |
368 | 686 |
369 // Hold the power button and lock the screen. | 687 // Hold the power button and lock the screen. |
370 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 688 EXPECT_TRUE(test_api_->is_animating_lock()); |
371 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 689 |
372 test_api_->trigger_lock_timeout(); | 690 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
373 state_controller_->OnStartingLock(); | 691 SystemLocks(); |
| 692 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f); |
374 | 693 |
375 // Power button is released while system attempts to lock. | 694 // Power button is released while system attempts to lock. |
376 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 695 ReleasePowerButton(); |
377 state_controller_->OnLockStateChanged(true); | 696 |
378 shell_delegate_->LockScreen(); | 697 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
379 | 698 |
380 EXPECT_FALSE(state_controller_->ShutdownRequested()); | 699 EXPECT_FALSE(state_controller_->ShutdownRequested()); |
381 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 700 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
382 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 701 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
383 } | 702 } |
384 | 703 |
385 // Test that we handle the case where lock requests are ignored. | 704 // Test that we handle the case where lock requests are ignored. |
386 TEST_F(SessionStateControllerImpl2Test, Lock) { | 705 TEST_F(SessionStateControllerImpl2Test, DISABLED_Lock) { |
387 // We require animations to have a duration for this test. | 706 // We require animations to have a duration for this test. |
388 ui::LayerAnimator::set_disable_animations_for_test(false); | 707 ui::LayerAnimator::set_disable_animations_for_test(false); |
389 | 708 |
390 controller_->set_has_legacy_power_button_for_test(false); | 709 Initialize(false, user::LOGGED_IN_USER); |
391 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
392 state_controller_->OnLockStateChanged(false); | |
393 | 710 |
394 // Hold the power button and lock the screen. | 711 // Hold the power button and lock the screen. |
395 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 712 PressPowerButton(); |
396 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 713 ExpectPreLockAnimationStarted(); |
397 EXPECT_TRUE( | 714 |
398 animator_api_->ContainersAreAnimated( | 715 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
399 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 716 |
400 internal::SessionStateAnimator::LAUNCHER, | |
401 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
402 test_api_->trigger_lock_timeout(); | |
403 EXPECT_EQ(1, delegate_->num_lock_requests()); | 717 EXPECT_EQ(1, delegate_->num_lock_requests()); |
404 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 718 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
405 | |
406 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 719 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
407 // been locked. | 720 // been locked and this was animated. |
408 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 721 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
409 | 722 |
410 // Act as if the request timed out. We should restore the windows. | 723 // Act as if the request timed out. We should restore the windows. |
411 test_api_->trigger_lock_fail_timeout(); | 724 test_api_->trigger_lock_fail_timeout(); |
412 EXPECT_TRUE( | 725 |
413 animator_api_->ContainersAreAnimated( | 726 ExpectUnlockAfterUIDestroyedAnimationStarted(); |
414 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 727 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
415 internal::SessionStateAnimator::LAUNCHER, | 728 ExpectUnlockAfterUIDestroyedAnimationFinished(); |
416 internal::SessionStateAnimator::ANIMATION_DROP)); | 729 ExpectUnlockedState(); |
| 730 } |
| 731 |
| 732 // Test the basic operation of the lock button (not logged in). |
| 733 TEST_F(SessionStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { |
| 734 // The lock button shouldn't do anything if we aren't logged in. |
| 735 Initialize(false, user::LOGGED_IN_NONE); |
| 736 |
| 737 PressLockButton(); |
| 738 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 739 ReleaseLockButton(); |
| 740 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 741 } |
| 742 |
| 743 // Test the basic operation of the lock button (guest). |
| 744 TEST_F(SessionStateControllerImpl2Test, LockButtonBasicGuest) { |
| 745 // The lock button shouldn't do anything when we're logged in as a guest. |
| 746 Initialize(false, user::LOGGED_IN_GUEST); |
| 747 |
| 748 PressLockButton(); |
| 749 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 750 ReleaseLockButton(); |
| 751 EXPECT_EQ(0, delegate_->num_lock_requests()); |
417 } | 752 } |
418 | 753 |
419 // Test the basic operation of the lock button. | 754 // Test the basic operation of the lock button. |
420 TEST_F(SessionStateControllerImpl2Test, LockButtonBasic) { | 755 TEST_F(SessionStateControllerImpl2Test, DISABLED_LockButtonBasic) { |
421 controller_->set_has_legacy_power_button_for_test(false); | |
422 // The lock button shouldn't do anything if we aren't logged in. | |
423 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | |
424 state_controller_->OnLockStateChanged(false); | |
425 SetUserLoggedIn(false); | |
426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | |
427 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
428 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | |
429 EXPECT_EQ(0, delegate_->num_lock_requests()); | |
430 | |
431 // Ditto for when we're logged in as a guest. | |
432 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | |
433 SetUserLoggedIn(true); | |
434 SetCanLockScreen(false); | |
435 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | |
436 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
437 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | |
438 EXPECT_EQ(0, delegate_->num_lock_requests()); | |
439 | |
440 // If we're logged in as a regular user, we should start the lock timer and | 756 // If we're logged in as a regular user, we should start the lock timer and |
441 // the pre-lock animation. | 757 // the pre-lock animation. |
442 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 758 Initialize(false, user::LOGGED_IN_USER); |
443 SetCanLockScreen(true); | 759 |
444 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 760 PressLockButton(); |
445 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 761 ExpectPreLockAnimationStarted(); |
446 EXPECT_TRUE( | 762 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
447 animator_api_->ContainersAreAnimated( | |
448 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
449 internal::SessionStateAnimator::LAUNCHER, | |
450 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
451 | 763 |
452 // If the button is released immediately, we shouldn't lock the screen. | 764 // If the button is released immediately, we shouldn't lock the screen. |
453 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 765 ReleaseLockButton(); |
454 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 766 ExpectPreLockAnimationCancel(); |
455 EXPECT_TRUE( | 767 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
456 animator_api_->ContainersAreAnimated( | 768 |
457 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 769 ExpectUnlockedState(); |
458 internal::SessionStateAnimator::LAUNCHER, | |
459 internal::SessionStateAnimator::ANIMATION_DROP)); | |
460 EXPECT_EQ(0, delegate_->num_lock_requests()); | 770 EXPECT_EQ(0, delegate_->num_lock_requests()); |
461 | 771 |
462 // Press the button again and let the lock timeout fire. We should request | 772 // Press the button again and let the lock timeout fire. We should request |
463 // that the screen be locked. | 773 // that the screen be locked. |
464 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 774 PressLockButton(); |
465 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 775 ExpectPreLockAnimationStarted(); |
466 test_api_->trigger_lock_timeout(); | 776 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
467 EXPECT_EQ(1, delegate_->num_lock_requests()); | 777 EXPECT_EQ(1, delegate_->num_lock_requests()); |
468 | 778 |
469 // Pressing the lock button while we have a pending lock request shouldn't do | 779 // Pressing the lock button while we have a pending lock request shouldn't do |
470 // anything. | 780 // anything. |
471 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 781 ReleaseLockButton(); |
472 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 782 PressLockButton(); |
473 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 783 ExpectPreLockAnimationFinished(); |
474 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 784 ReleaseLockButton(); |
475 | 785 |
476 // Pressing the button also shouldn't do anything after the screen is locked. | 786 // Pressing the button also shouldn't do anything after the screen is locked. |
477 state_controller_->OnStartingLock(); | 787 SystemLocks(); |
478 state_controller_->OnLockStateChanged(true); | 788 ExpectPostLockAnimationStarted(); |
479 shell_delegate_->LockScreen(); | 789 |
480 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 790 PressLockButton(); |
481 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 791 ReleaseLockButton(); |
482 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 792 ExpectPostLockAnimationStarted(); |
| 793 |
| 794 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 795 ExpectPastLockAnimationFinished(); |
| 796 |
| 797 PressLockButton(); |
| 798 ReleaseLockButton(); |
| 799 ExpectPastLockAnimationFinished(); |
483 } | 800 } |
484 | 801 |
485 // Test that the power button takes priority over the lock button. | 802 // Test that the power button takes priority over the lock button. |
486 TEST_F(SessionStateControllerImpl2Test, PowerButtonPreemptsLockButton) { | 803 TEST_F(SessionStateControllerImpl2Test, PowerButtonPreemptsLockButton) { |
487 controller_->set_has_legacy_power_button_for_test(false); | 804 Initialize(false, user::LOGGED_IN_USER); |
488 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
489 state_controller_->OnLockStateChanged(false); | |
490 | 805 |
491 // While the lock button is down, hold the power button. | 806 // While the lock button is down, hold the power button. |
492 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 807 PressLockButton(); |
493 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 808 ExpectPreLockAnimationStarted(); |
494 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 809 PressPowerButton(); |
495 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 810 ExpectPreLockAnimationStarted(); |
| 811 |
| 812 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
496 | 813 |
497 // The lock timer shouldn't be stopped when the lock button is released. | 814 // The lock timer shouldn't be stopped when the lock button is released. |
498 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 815 ReleaseLockButton(); |
499 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 816 ExpectPreLockAnimationStarted(); |
500 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 817 ReleasePowerButton(); |
501 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 818 ExpectPreLockAnimationCancel(); |
| 819 |
| 820 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 821 ExpectUnlockedState(); |
502 | 822 |
503 // Now press the power button first and then the lock button. | 823 // Now press the power button first and then the lock button. |
504 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 824 PressPowerButton(); |
505 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 825 ExpectPreLockAnimationStarted(); |
506 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 826 PressLockButton(); |
507 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 827 ExpectPreLockAnimationStarted(); |
| 828 |
| 829 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
508 | 830 |
509 // Releasing the power button should stop the lock timer. | 831 // Releasing the power button should stop the lock timer. |
510 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 832 ReleasePowerButton(); |
511 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 833 ExpectPreLockAnimationCancel(); |
512 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 834 ReleaseLockButton(); |
513 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 835 ExpectPreLockAnimationCancel(); |
514 } | 836 } |
515 | 837 |
516 // When the screen is locked without going through the usual power-button | 838 // When the screen is locked without going through the usual power-button |
517 // slow-close path (e.g. via the wrench menu), test that we still show the | 839 // slow-close path (e.g. via the wrench menu), test that we still show the |
518 // fast-close animation. | 840 // fast-close animation. |
519 TEST_F(SessionStateControllerImpl2Test, LockWithoutButton) { | 841 TEST_F(SessionStateControllerImpl2Test, LockWithoutButton) { |
520 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 842 Initialize(false, user::LOGGED_IN_USER); |
521 state_controller_->OnStartingLock(); | 843 state_controller_->OnStartingLock(); |
522 EXPECT_TRUE( | 844 |
523 animator_api_->ContainersAreAnimated( | 845 ExpectPreLockAnimationStarted(); |
524 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 846 EXPECT_FALSE(test_api_->is_lock_cancellable()); |
525 internal::SessionStateAnimator::LAUNCHER, | |
526 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
527 } | 847 } |
528 | 848 |
529 // When we hear that the process is exiting but we haven't had a chance to | 849 // When we hear that the process is exiting but we haven't had a chance to |
530 // display an animation, we should just blank the screen. | 850 // display an animation, we should just blank the screen. |
531 TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { | 851 TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { |
532 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 852 Initialize(false, user::LOGGED_IN_USER); |
533 state_controller_->OnAppTerminating(); | 853 state_controller_->OnAppTerminating(); |
| 854 |
534 EXPECT_TRUE( | 855 EXPECT_TRUE( |
535 animator_api_->ContainersAreAnimated( | 856 animator_api_->ContainersAreAnimated( |
536 internal::SessionStateAnimator::kAllContainersMask, | 857 SessionStateAnimator::kAllContainersMask, |
537 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 858 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
538 GenerateMouseMoveEvent(); | 859 GenerateMouseMoveEvent(); |
539 EXPECT_FALSE(cursor_visible()); | 860 EXPECT_FALSE(cursor_visible()); |
540 } | 861 } |
541 | 862 |
542 // Test that we display the fast-close animation and shut down when we get an | 863 // Test that we display the fast-close animation and shut down when we get an |
543 // outside request to shut down (e.g. from the login or lock screen). | 864 // outside request to shut down (e.g. from the login or lock screen). |
544 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { | 865 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { |
545 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 866 Initialize(false, user::LOGGED_IN_NONE); |
546 state_controller_->OnLockStateChanged(false); | 867 |
547 SetUserLoggedIn(false); | |
548 state_controller_->RequestShutdown(); | 868 state_controller_->RequestShutdown(); |
549 EXPECT_TRUE( | 869 |
550 animator_api_->RootWindowIsAnimated( | 870 ExpectShutdownAnimationStarted(); |
551 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 871 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 872 |
552 GenerateMouseMoveEvent(); | 873 GenerateMouseMoveEvent(); |
553 EXPECT_FALSE(cursor_visible()); | 874 EXPECT_FALSE(cursor_visible()); |
554 | 875 |
555 EXPECT_EQ(0, NumShutdownRequests()); | 876 EXPECT_EQ(0, NumShutdownRequests()); |
556 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 877 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
557 test_api_->trigger_real_shutdown_timeout(); | 878 test_api_->trigger_real_shutdown_timeout(); |
558 EXPECT_EQ(1, NumShutdownRequests()); | 879 EXPECT_EQ(1, NumShutdownRequests()); |
559 } | 880 } |
560 | 881 |
561 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { | 882 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { |
562 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 883 Initialize(false, user::LOGGED_IN_USER); |
563 state_controller_->OnLockStateChanged(true); | 884 |
564 shell_delegate_->LockScreen(); | 885 SystemLocks(); |
| 886 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 887 ExpectPastLockAnimationFinished(); |
| 888 |
565 state_controller_->RequestShutdown(); | 889 state_controller_->RequestShutdown(); |
566 EXPECT_TRUE( | 890 |
567 animator_api_->RootWindowIsAnimated( | 891 ExpectShutdownAnimationStarted(); |
568 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 892 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 893 |
569 GenerateMouseMoveEvent(); | 894 GenerateMouseMoveEvent(); |
570 EXPECT_FALSE(cursor_visible()); | 895 EXPECT_FALSE(cursor_visible()); |
571 | 896 |
572 EXPECT_EQ(0, NumShutdownRequests()); | 897 EXPECT_EQ(0, NumShutdownRequests()); |
573 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 898 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
574 test_api_->trigger_real_shutdown_timeout(); | 899 test_api_->trigger_real_shutdown_timeout(); |
575 EXPECT_EQ(1, NumShutdownRequests()); | 900 EXPECT_EQ(1, NumShutdownRequests()); |
576 } | 901 } |
577 | 902 |
578 TEST_F(SessionStateControllerImpl2Test, | 903 TEST_F(SessionStateControllerImpl2Test, |
579 RequestAndCancelShutdownFromLockScreen) { | 904 DISABLED_RequestAndCancelShutdownFromLockScreen) { |
580 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 905 Initialize(false, user::LOGGED_IN_USER); |
581 state_controller_->OnLockStateChanged(true); | 906 |
582 shell_delegate_->LockScreen(); | 907 SystemLocks(); |
| 908 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 909 ExpectLockedState(); |
583 | 910 |
584 // Press the power button and check that we start the shutdown timer. | 911 // Press the power button and check that we start the shutdown timer. |
585 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 912 PressPowerButton(); |
586 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 913 EXPECT_FALSE(test_api_->is_animating_lock()); |
587 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 914 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
588 EXPECT_TRUE( | 915 |
589 animator_api_->RootWindowIsAnimated( | 916 ExpectShutdownAnimationStarted(); |
590 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 917 |
| 918 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); |
| 919 |
| 920 float grayscale_before_button_release = |
| 921 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale(); |
591 | 922 |
592 // Release the power button before the shutdown timer fires. | 923 // Release the power button before the shutdown timer fires. |
593 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 924 ReleasePowerButton(); |
| 925 |
594 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 926 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
595 EXPECT_TRUE( | 927 |
596 animator_api_->RootWindowIsAnimated( | 928 ExpectShutdownAnimationCancel(); |
597 internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); | 929 |
| 930 float grayscale_after_button_release = |
| 931 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale(); |
| 932 // Expect no flickering in undo animation. |
| 933 EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release); |
| 934 |
| 935 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT); |
| 936 ExpectLockedState(); |
598 } | 937 } |
599 | 938 |
600 // Test that we ignore power button presses when the screen is turned off. | 939 // Test that we ignore power button presses when the screen is turned off. |
601 TEST_F(SessionStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { | 940 TEST_F(SessionStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { |
602 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 941 Initialize(false, user::LOGGED_IN_USER); |
603 | 942 |
604 // When the screen brightness is at 0%, we shouldn't do anything in response | 943 // When the screen brightness is at 0%, we shouldn't do anything in response |
605 // to power button presses. | 944 // to power button presses. |
606 controller_->OnScreenBrightnessChanged(0.0); | 945 controller_->OnScreenBrightnessChanged(0.0); |
607 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 946 |
608 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 947 PressPowerButton(); |
| 948 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 949 ReleasePowerButton(); |
609 | 950 |
610 // After increasing the brightness to 10%, we should start the timer like | 951 // After increasing the brightness to 10%, we should start the timer like |
611 // usual. | 952 // usual. |
612 controller_->OnScreenBrightnessChanged(10.0); | 953 controller_->OnScreenBrightnessChanged(10.0); |
613 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 954 |
614 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 955 PressPowerButton(); |
| 956 EXPECT_TRUE(test_api_->is_animating_lock()); |
| 957 } |
| 958 |
| 959 // Test that hidden background appears and revers correctly on lock/cancel. |
| 960 TEST_F(SessionStateControllerImpl2Test, |
| 961 DISABLED_TestHiddenBackgroundLockCancel) { |
| 962 Initialize(false, user::LOGGED_IN_USER); |
| 963 HideBackground(); |
| 964 |
| 965 EXPECT_TRUE(IsBackgroundHidden()); |
| 966 ExpectUnlockedState(); |
| 967 PressPowerButton(); |
| 968 |
| 969 ExpectPreLockAnimationStarted(); |
| 970 EXPECT_FALSE(IsBackgroundHidden()); |
| 971 ExpectBackgroundIsShowing(); |
| 972 |
| 973 // Forward only half way through. |
| 974 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); |
| 975 |
| 976 // Release the button before the lock timer fires. |
| 977 ReleasePowerButton(); |
| 978 ExpectPreLockAnimationCancel(); |
| 979 ExpectBackgroundIsHiding(); |
| 980 EXPECT_FALSE(IsBackgroundHidden()); |
| 981 |
| 982 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 983 |
| 984 ExpectUnlockedState(); |
| 985 EXPECT_TRUE(IsBackgroundHidden()); |
| 986 } |
| 987 |
| 988 // Test that hidden background appears and revers correctly on lock/unlock. |
| 989 TEST_F(SessionStateControllerImpl2Test, |
| 990 DISABLED_TestHiddenBackgroundLockUnlock) { |
| 991 Initialize(false, user::LOGGED_IN_USER); |
| 992 HideBackground(); |
| 993 |
| 994 EXPECT_TRUE(IsBackgroundHidden()); |
| 995 ExpectUnlockedState(); |
| 996 |
| 997 // Press the power button and check that the lock timer is started and that we |
| 998 // start lifting the non-screen-locker containers. |
| 999 PressPowerButton(); |
| 1000 |
| 1001 ExpectPreLockAnimationStarted(); |
| 1002 EXPECT_FALSE(IsBackgroundHidden()); |
| 1003 ExpectBackgroundIsShowing(); |
| 1004 |
| 1005 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 1006 |
| 1007 ExpectPreLockAnimationFinished(); |
| 1008 |
| 1009 SystemLocks(); |
| 1010 |
| 1011 ReleasePowerButton(); |
| 1012 |
| 1013 ExpectPostLockAnimationStarted(); |
| 1014 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 1015 ExpectPastLockAnimationFinished(); |
| 1016 |
| 1017 ExpectLockedState(); |
| 1018 |
| 1019 SuccessfulAuthentication(NULL); |
| 1020 |
| 1021 ExpectUnlockBeforeUIDestroyedAnimationStarted(); |
| 1022 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 1023 ExpectUnlockBeforeUIDestroyedAnimationFinished(); |
| 1024 |
| 1025 SystemUnlocks(); |
| 1026 |
| 1027 ExpectUnlockAfterUIDestroyedAnimationStarted(); |
| 1028 ExpectBackgroundIsHiding(); |
| 1029 EXPECT_FALSE(IsBackgroundHidden()); |
| 1030 |
| 1031 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 1032 ExpectUnlockAfterUIDestroyedAnimationFinished(); |
| 1033 EXPECT_TRUE(IsBackgroundHidden()); |
| 1034 |
| 1035 ExpectUnlockedState(); |
615 } | 1036 } |
616 | 1037 |
617 } // namespace test | 1038 } // namespace test |
618 } // namespace ash | 1039 } // namespace ash |
OLD | NEW |