This source file includes following definitions.
- cursor_visible
- CheckCalledCallback
- GetContainer
- IsBackgroundHidden
- HideBackground
- num_shutdown_requests_
- num_lock_requests
- num_shutdown_requests
- RequestLockScreen
- RequestShutdown
- delegate_
- SetUp
- TearDown
- GenerateMouseMoveEvent
- NumShutdownRequests
- Advance
- AdvancePartially
- ExpectPreLockAnimationStarted
- ExpectPreLockAnimationCancel
- ExpectPreLockAnimationFinished
- ExpectPostLockAnimationStarted
- ExpectPastLockAnimationFinished
- ExpectUnlockBeforeUIDestroyedAnimationStarted
- ExpectUnlockBeforeUIDestroyedAnimationFinished
- ExpectUnlockAfterUIDestroyedAnimationStarted
- ExpectUnlockAfterUIDestroyedAnimationFinished
- ExpectShutdownAnimationStarted
- ExpectShutdownAnimationFinished
- ExpectShutdownAnimationCancel
- ExpectBackgroundIsShowing
- ExpectBackgroundIsHiding
- ExpectUnlockedState
- ExpectLockedState
- PressPowerButton
- ReleasePowerButton
- PressLockButton
- ReleaseLockButton
- SystemLocks
- SuccessfulAuthentication
- SystemUnlocks
- Initialize
- CreateWindowForLockscreen
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/wm/lock_state_controller.h"
#include "ash/ash_switches.h"
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/session_state_animator.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/aura/env.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#if defined(OS_CHROMEOS)
#include "ui/display/chromeos/output_configurator.h"
#include "ui/display/chromeos/test/test_display_snapshot.h"
#include "ui/display/display_constants.h"
#endif
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
namespace ash {
namespace test {
namespace {
bool cursor_visible() {
return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible();
}
void CheckCalledCallback(bool* flag) {
if (flag)
(*flag) = true;
}
aura::Window* GetContainer(int container ) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
return Shell::GetContainer(root_window, container);
}
bool IsBackgroundHidden() {
return !GetContainer(kShellWindowId_DesktopBackgroundContainer)->IsVisible();
}
void HideBackground() {
ui::ScopedLayerAnimationSettings settings(
GetContainer(kShellWindowId_DesktopBackgroundContainer)
->layer()
->GetAnimator());
settings.SetTransitionDuration(base::TimeDelta());
GetContainer(kShellWindowId_DesktopBackgroundContainer)->Hide();
}
}
class TestLockStateControllerDelegate : public LockStateControllerDelegate {
public:
TestLockStateControllerDelegate()
: num_lock_requests_(0),
num_shutdown_requests_(0) {}
int num_lock_requests() const { return num_lock_requests_; }
int num_shutdown_requests() const { return num_shutdown_requests_; }
virtual void RequestLockScreen() OVERRIDE {
num_lock_requests_++;
}
virtual void RequestShutdown() OVERRIDE {
num_shutdown_requests_++;
}
private:
int num_lock_requests_;
int num_shutdown_requests_;
DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate);
};
class LockStateControllerTest : public AshTestBase {
public:
LockStateControllerTest() : controller_(NULL), delegate_(NULL) {}
virtual ~LockStateControllerTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION));
animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
delegate_ = new TestLockStateControllerDelegate;
controller_ = Shell::GetInstance()->power_button_controller();
lock_state_controller_ = static_cast<LockStateController*>(
Shell::GetInstance()->lock_state_controller());
lock_state_controller_->SetDelegate(delegate_);
test_api_.reset(new LockStateController::TestApi(lock_state_controller_));
animator_api_.reset(
new SessionStateAnimator::TestApi(lock_state_controller_->
animator_.get()));
shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
session_state_delegate_ = Shell::GetInstance()->session_state_delegate();
}
virtual void TearDown() {
window_.reset();
AshTestBase::TearDown();
}
protected:
void GenerateMouseMoveEvent() {
aura::test::EventGenerator generator(
Shell::GetPrimaryRootWindow());
generator.MoveMouseTo(10, 10);
}
int NumShutdownRequests() {
return delegate_->num_shutdown_requests() +
shell_delegate_->num_exit_requests();
}
void Advance(SessionStateAnimator::AnimationSpeed speed) {
}
void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
float factor) {
}
void ExpectPreLockAnimationStarted() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_LIFT));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LAUNCHER,
SessionStateAnimator::ANIMATION_FADE_OUT));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
EXPECT_TRUE(test_api_->is_animating_lock());
}
void ExpectPreLockAnimationCancel() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_DROP));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LAUNCHER,
SessionStateAnimator::ANIMATION_FADE_IN));
}
void ExpectPreLockAnimationFinished() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_LIFT));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LAUNCHER,
SessionStateAnimator::ANIMATION_FADE_OUT));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
}
void ExpectPostLockAnimationStarted() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
}
void ExpectPastLockAnimationFinished() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
}
void ExpectUnlockBeforeUIDestroyedAnimationStarted() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_LIFT));
}
void ExpectUnlockBeforeUIDestroyedAnimationFinished() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_LIFT));
}
void ExpectUnlockAfterUIDestroyedAnimationStarted() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_DROP));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LAUNCHER,
SessionStateAnimator::ANIMATION_FADE_IN));
}
void ExpectUnlockAfterUIDestroyedAnimationFinished() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_DROP));
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::LAUNCHER,
SessionStateAnimator::ANIMATION_FADE_IN));
}
void ExpectShutdownAnimationStarted() {
EXPECT_TRUE(
animator_api_->RootWindowIsAnimated(
SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
}
void ExpectShutdownAnimationFinished() {
EXPECT_TRUE(
animator_api_->RootWindowIsAnimated(
SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
}
void ExpectShutdownAnimationCancel() {
EXPECT_TRUE(
animator_api_->RootWindowIsAnimated(
SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS));
}
void ExpectBackgroundIsShowing() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::DESKTOP_BACKGROUND,
SessionStateAnimator::ANIMATION_FADE_IN));
}
void ExpectBackgroundIsHiding() {
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::DESKTOP_BACKGROUND,
SessionStateAnimator::ANIMATION_FADE_OUT));
}
void ExpectUnlockedState() {
EXPECT_FALSE(session_state_delegate_->IsScreenLocked());
aura::Window::Windows containers;
SessionStateAnimator::GetContainers(
SessionStateAnimator::LAUNCHER |
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
&containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
it != containers.end(); ++it) {
aura::Window* window = *it;
ui::Layer* layer = window->layer();
EXPECT_EQ(1.0f, layer->opacity());
EXPECT_EQ(0.0f, layer->layer_brightness());
EXPECT_EQ(0.0f, layer->layer_saturation());
EXPECT_EQ(gfx::Transform(), layer->transform());
}
}
void ExpectLockedState() {
EXPECT_TRUE(session_state_delegate_->IsScreenLocked());
aura::Window::Windows containers;
SessionStateAnimator::GetContainers(
SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS |
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
&containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
it != containers.end(); ++it) {
aura::Window* window = *it;
ui::Layer* layer = window->layer();
EXPECT_EQ(1.0f, layer->opacity());
EXPECT_EQ(0.0f, layer->layer_brightness());
EXPECT_EQ(0.0f, layer->layer_saturation());
EXPECT_EQ(gfx::Transform(), layer->transform());
}
}
void PressPowerButton() {
controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
}
void ReleasePowerButton() {
controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
}
void PressLockButton() {
controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
}
void ReleaseLockButton() {
controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
}
void SystemLocks() {
lock_state_controller_->OnLockStateChanged(true);
session_state_delegate_->LockScreen();
}
void SuccessfulAuthentication(bool* call_flag) {
base::Closure closure = base::Bind(&CheckCalledCallback, call_flag);
lock_state_controller_->OnLockScreenHide(closure);
}
void SystemUnlocks() {
lock_state_controller_->OnLockStateChanged(false);
session_state_delegate_->UnlockScreen();
}
void Initialize(bool legacy_button, user::LoginStatus status) {
controller_->set_has_legacy_power_button_for_test(legacy_button);
lock_state_controller_->OnLoginStateChanged(status);
SetUserLoggedIn(status != user::LOGGED_IN_NONE);
if (status == user::LOGGED_IN_GUEST)
SetCanLockScreen(false);
lock_state_controller_->OnLockStateChanged(false);
}
void CreateWindowForLockscreen() {
window_.reset(new aura::Window(&window_delegate_));
window_->SetBounds(gfx::Rect(0, 0, 100, 100));
window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window_->Init(aura::WINDOW_LAYER_TEXTURED);
window_->SetName("WINDOW");
aura::Window* container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
ASSERT_TRUE(container);
container->AddChild(window_.get());
window_->Show();
}
PowerButtonController* controller_;
LockStateController* lock_state_controller_;
TestLockStateControllerDelegate* delegate_;
TestShellDelegate* shell_delegate_;
SessionStateDelegate* session_state_delegate_;
aura::test::TestWindowDelegate window_delegate_;
scoped_ptr<aura::Window> window_;
scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_;
scoped_ptr<LockStateController::TestApi> test_api_;
scoped_ptr<SessionStateAnimator::TestApi> animator_api_;
private:
DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
};
TEST_F(LockStateControllerTest, DISABLED_LegacyLockAndShutDown) {
Initialize(true, user::LOGGED_IN_USER);
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_FALSE(test_api_->is_lock_cancellable());
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectPreLockAnimationFinished();
EXPECT_EQ(1, delegate_->num_lock_requests());
lock_state_controller_->OnStartingLock();
SystemLocks();
ExpectPostLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectPastLockAnimationFinished();
EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
EXPECT_FALSE(test_api_->shutdown_timer_is_running());
ReleasePowerButton();
PressPowerButton();
ExpectShutdownAnimationStarted();
EXPECT_EQ(0, NumShutdownRequests());
GenerateMouseMoveEvent();
EXPECT_FALSE(cursor_visible());
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests());
}
TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
Initialize(true, user::LOGGED_IN_NONE);
PressPowerButton();
ExpectShutdownAnimationStarted();
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
}
TEST_F(LockStateControllerTest, LegacyGuest) {
Initialize(true, user::LOGGED_IN_GUEST);
PressPowerButton();
ExpectShutdownAnimationStarted();
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
}
TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
Initialize(false, user::LOGGED_IN_NONE);
PressPowerButton();
EXPECT_FALSE(test_api_->is_animating_lock());
EXPECT_TRUE(test_api_->shutdown_timer_is_running());
ExpectShutdownAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
ReleasePowerButton();
EXPECT_FALSE(test_api_->shutdown_timer_is_running());
ExpectShutdownAnimationCancel();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f);
PressPowerButton();
EXPECT_TRUE(test_api_->shutdown_timer_is_running());
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
ExpectShutdownAnimationFinished();
test_api_->trigger_shutdown_timeout();
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
EXPECT_EQ(0, NumShutdownRequests());
test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests());
}
TEST_F(LockStateControllerTest, DISABLED_LockAndUnlock) {
Initialize(false, user::LOGGED_IN_USER);
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_TRUE(test_api_->is_lock_cancellable());
EXPECT_EQ(0, delegate_->num_lock_requests());
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
ExpectPreLockAnimationFinished();
EXPECT_EQ(1, delegate_->num_lock_requests());
lock_state_controller_->OnStartingLock();
SystemLocks();
ExpectPostLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectPastLockAnimationFinished();
ExpectLockedState();
EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
ReleasePowerButton();
ExpectLockedState();
EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
bool called = false;
SuccessfulAuthentication(&called);
ExpectUnlockBeforeUIDestroyedAnimationStarted();
EXPECT_FALSE(called);
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockBeforeUIDestroyedAnimationFinished();
EXPECT_TRUE(called);
SystemUnlocks();
ExpectUnlockAfterUIDestroyedAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockAfterUIDestroyedAnimationFinished();
ExpectUnlockedState();
}
TEST_F(LockStateControllerTest, DISABLED_LockAndCancel) {
Initialize(false, user::LOGGED_IN_USER);
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_TRUE(test_api_->is_lock_cancellable());
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
gfx::Transform transform_before_button_released =
GetContainer(kShellWindowId_DefaultContainer)->layer()->transform();
ReleasePowerButton();
ExpectPreLockAnimationCancel();
gfx::Transform transform_after_button_released =
GetContainer(kShellWindowId_DefaultContainer)->layer()->transform();
EXPECT_EQ(transform_before_button_released, transform_after_button_released);
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockedState();
EXPECT_EQ(0, delegate_->num_lock_requests());
}
TEST_F(LockStateControllerTest,
DISABLED_LockAndCancelAndLockAgain) {
Initialize(false, user::LOGGED_IN_USER);
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_TRUE(test_api_->is_lock_cancellable());
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
ReleasePowerButton();
ExpectPreLockAnimationCancel();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_TRUE(test_api_->is_lock_cancellable());
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
EXPECT_EQ(0, delegate_->num_lock_requests());
ExpectPreLockAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
ExpectPreLockAnimationFinished();
EXPECT_EQ(1, delegate_->num_lock_requests());
}
TEST_F(LockStateControllerTest, DISABLED_LockToShutdown) {
Initialize(false, user::LOGGED_IN_USER);
PressPowerButton();
EXPECT_TRUE(test_api_->is_animating_lock());
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
SystemLocks();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
test_api_->trigger_lock_to_shutdown_timeout();
ExpectShutdownAnimationStarted();
EXPECT_TRUE(test_api_->shutdown_timer_is_running());
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
ExpectShutdownAnimationFinished();
test_api_->trigger_shutdown_timeout();
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
EXPECT_EQ(0, NumShutdownRequests());
test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests());
}
TEST_F(LockStateControllerTest, CancelLockToShutdown) {
Initialize(false, user::LOGGED_IN_USER);
PressPowerButton();
EXPECT_TRUE(test_api_->is_animating_lock());
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
SystemLocks();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
ReleasePowerButton();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
EXPECT_FALSE(test_api_->shutdown_timer_is_running());
}
TEST_F(LockStateControllerTest, DISABLED_Lock) {
ui::ScopedAnimationDurationScaleMode normal_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
Initialize(false, user::LOGGED_IN_USER);
PressPowerButton();
ExpectPreLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
EXPECT_EQ(1, delegate_->num_lock_requests());
EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
test_api_->trigger_lock_fail_timeout();
ExpectUnlockAfterUIDestroyedAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockAfterUIDestroyedAnimationFinished();
ExpectUnlockedState();
}
TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
Initialize(false, user::LOGGED_IN_NONE);
PressLockButton();
EXPECT_FALSE(test_api_->is_animating_lock());
ReleaseLockButton();
EXPECT_EQ(0, delegate_->num_lock_requests());
}
TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
Initialize(false, user::LOGGED_IN_GUEST);
PressLockButton();
EXPECT_FALSE(test_api_->is_animating_lock());
ReleaseLockButton();
EXPECT_EQ(0, delegate_->num_lock_requests());
}
TEST_F(LockStateControllerTest, DISABLED_LockButtonBasic) {
Initialize(false, user::LOGGED_IN_USER);
PressLockButton();
ExpectPreLockAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
ReleaseLockButton();
ExpectPreLockAnimationCancel();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockedState();
EXPECT_EQ(0, delegate_->num_lock_requests());
PressLockButton();
ExpectPreLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
EXPECT_EQ(1, delegate_->num_lock_requests());
ReleaseLockButton();
PressLockButton();
ExpectPreLockAnimationFinished();
ReleaseLockButton();
SystemLocks();
ExpectPostLockAnimationStarted();
PressLockButton();
ReleaseLockButton();
ExpectPostLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectPastLockAnimationFinished();
PressLockButton();
ReleaseLockButton();
ExpectPastLockAnimationFinished();
}
TEST_F(LockStateControllerTest,
DISABLED_PowerButtonPreemptsLockButton) {
Initialize(false, user::LOGGED_IN_USER);
PressLockButton();
ExpectPreLockAnimationStarted();
PressPowerButton();
ExpectPreLockAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
ReleaseLockButton();
ExpectPreLockAnimationStarted();
ReleasePowerButton();
ExpectPreLockAnimationCancel();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
PressLockButton();
ExpectPreLockAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
ReleasePowerButton();
ExpectPreLockAnimationCancel();
ReleaseLockButton();
ExpectPreLockAnimationCancel();
}
TEST_F(LockStateControllerTest, LockWithoutButton) {
Initialize(false, user::LOGGED_IN_USER);
lock_state_controller_->OnStartingLock();
ExpectPreLockAnimationStarted();
EXPECT_FALSE(test_api_->is_lock_cancellable());
}
TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
Initialize(false, user::LOGGED_IN_USER);
lock_state_controller_->OnAppTerminating();
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
SessionStateAnimator::kAllContainersMask,
SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
GenerateMouseMoveEvent();
EXPECT_FALSE(cursor_visible());
}
TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
Initialize(false, user::LOGGED_IN_NONE);
CreateWindowForLockscreen();
lock_state_controller_->RequestShutdown();
ExpectShutdownAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
GenerateMouseMoveEvent();
EXPECT_FALSE(cursor_visible());
EXPECT_EQ(0, NumShutdownRequests());
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests());
}
TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
Initialize(false, user::LOGGED_IN_USER);
SystemLocks();
CreateWindowForLockscreen();
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
ExpectPastLockAnimationFinished();
lock_state_controller_->RequestShutdown();
ExpectShutdownAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
GenerateMouseMoveEvent();
EXPECT_FALSE(cursor_visible());
EXPECT_EQ(0, NumShutdownRequests());
EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests());
}
TEST_F(LockStateControllerTest,
DISABLED_RequestAndCancelShutdownFromLockScreen) {
Initialize(false, user::LOGGED_IN_USER);
SystemLocks();
Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
ExpectLockedState();
PressPowerButton();
EXPECT_FALSE(test_api_->is_animating_lock());
EXPECT_TRUE(test_api_->shutdown_timer_is_running());
ExpectShutdownAnimationStarted();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
float grayscale_before_button_release =
Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
ReleasePowerButton();
EXPECT_FALSE(test_api_->shutdown_timer_is_running());
ExpectShutdownAnimationCancel();
float grayscale_after_button_release =
Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release);
Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT);
ExpectLockedState();
}
TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
Initialize(false, user::LOGGED_IN_USER);
controller_->OnScreenBrightnessChanged(0.0);
PressPowerButton();
EXPECT_FALSE(test_api_->is_animating_lock());
ReleasePowerButton();
controller_->OnScreenBrightnessChanged(10.0);
PressPowerButton();
EXPECT_TRUE(test_api_->is_animating_lock());
ReleasePowerButton();
}
#if defined(OS_CHROMEOS) && defined(USE_X11)
TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) {
ScopedVector<const ui::DisplayMode> modes;
modes.push_back(new ui::DisplayMode(gfx::Size(1, 1), false, 60.0f));
ui::OutputConfigurator::DisplayStateList outputs;
ui::OutputConfigurator::DisplayState internal_output;
ui::TestDisplaySnapshot internal_display;
internal_display.set_type(ui::OUTPUT_TYPE_INTERNAL);
internal_display.set_modes(modes.get());
internal_output.display = &internal_display;
outputs.push_back(internal_output);
ui::OutputConfigurator::DisplayState external_output;
ui::TestDisplaySnapshot external_display;
external_display.set_type(ui::OUTPUT_TYPE_HDMI);
external_display.set_modes(modes.get());
external_output.display = &external_display;
outputs.push_back(external_output);
controller_->OnScreenBrightnessChanged(0.0);
static_cast<ui::TestDisplaySnapshot*>(outputs[0].display)
->set_current_mode(NULL);
static_cast<ui::TestDisplaySnapshot*>(outputs[1].display)
->set_current_mode(NULL);
controller_->OnDisplayModeChanged(outputs);
PressPowerButton();
EXPECT_FALSE(test_api_->is_animating_lock());
ReleasePowerButton();
static_cast<ui::TestDisplaySnapshot*>(outputs[1].display)
->set_current_mode(modes[0]);
controller_->OnDisplayModeChanged(outputs);
PressPowerButton();
EXPECT_TRUE(test_api_->is_animating_lock());
ReleasePowerButton();
}
#endif
TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockCancel) {
Initialize(false, user::LOGGED_IN_USER);
HideBackground();
EXPECT_TRUE(IsBackgroundHidden());
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_FALSE(IsBackgroundHidden());
ExpectBackgroundIsShowing();
AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
ReleasePowerButton();
ExpectPreLockAnimationCancel();
ExpectBackgroundIsHiding();
EXPECT_FALSE(IsBackgroundHidden());
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockedState();
EXPECT_TRUE(IsBackgroundHidden());
}
TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) {
Initialize(false, user::LOGGED_IN_USER);
HideBackground();
EXPECT_TRUE(IsBackgroundHidden());
ExpectUnlockedState();
PressPowerButton();
ExpectPreLockAnimationStarted();
EXPECT_FALSE(IsBackgroundHidden());
ExpectBackgroundIsShowing();
Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
ExpectPreLockAnimationFinished();
SystemLocks();
ReleasePowerButton();
ExpectPostLockAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectPastLockAnimationFinished();
ExpectLockedState();
SuccessfulAuthentication(NULL);
ExpectUnlockBeforeUIDestroyedAnimationStarted();
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockBeforeUIDestroyedAnimationFinished();
SystemUnlocks();
ExpectUnlockAfterUIDestroyedAnimationStarted();
ExpectBackgroundIsHiding();
EXPECT_FALSE(IsBackgroundHidden());
Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
ExpectUnlockAfterUIDestroyedAnimationFinished();
EXPECT_TRUE(IsBackgroundHidden());
ExpectUnlockedState();
}
}
}