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