Commit a2420700 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Close UI when unlock screen

When the secondary user logs in, the OnLockStateChanged() was returned
due to the Ambient mode is not allowed, therefore the ambient UI is not
closed. This patch moves the close ui logic before the ambient enabled
check.

Bug: 1136302
Test: Added new unittest
Change-Id: I2d9c93087b8e8139936271db2a797f6322bb55ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462246Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815463}
parent fbfc9e4a
...@@ -285,12 +285,18 @@ void AmbientController::OnAutoShowTimeOut() { ...@@ -285,12 +285,18 @@ void AmbientController::OnAutoShowTimeOut() {
} }
void AmbientController::OnLockStateChanged(bool locked) { void AmbientController::OnLockStateChanged(bool locked) {
if (!locked) {
// Ambient screen will be destroyed along with the lock screen when user
// logs in.
CloseUi();
return;
}
if (!IsAmbientModeEnabled()) { if (!IsAmbientModeEnabled()) {
VLOG(1) << "Ambient mode is not allowed."; VLOG(1) << "Ambient mode is not allowed.";
return; return;
} }
if (locked) {
// We have 3 options to manage the token for lock screen. Here use option 1. // We have 3 options to manage the token for lock screen. Here use option 1.
// 1. Request only one time after entering lock screen. We will use it once // 1. Request only one time after entering lock screen. We will use it once
// to request all the image links and no more requests. // to request all the image links and no more requests.
...@@ -316,11 +322,6 @@ void AmbientController::OnLockStateChanged(bool locked) { ...@@ -316,11 +322,6 @@ void AmbientController::OnLockStateChanged(bool locked) {
// hidden and will show after a delay. // hidden and will show after a delay.
ShowHiddenUi(); ShowHiddenUi();
} }
} else {
// Ambient screen will be destroyed along with the lock screen when user
// logs in.
CloseUi();
}
} }
void AmbientController::OnFirstSessionStarted() { void AmbientController::OnFirstSessionStarted() {
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
namespace ash { namespace ash {
constexpr char kUser1[] = "user1@gmail.com";
constexpr char kUser2[] = "user2@gmail.com";
class AmbientControllerTest : public AmbientAshTestBase { class AmbientControllerTest : public AmbientAshTestBase {
public: public:
AmbientControllerTest() : AmbientAshTestBase() {} AmbientControllerTest() : AmbientAshTestBase() {}
...@@ -117,6 +120,70 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) { ...@@ -117,6 +120,70 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) {
EXPECT_FALSE(container_view()); EXPECT_FALSE(container_view());
} }
TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
// Simulate the login screen.
ClearLogin();
SimulateUserLogin(kUser1);
SetAmbientModeEnabled(true);
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
SimulateUserLogin(kUser2);
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
FastForwardToInactivity();
FastForwardTiny();
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
}
TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
// Simulate the login screen.
ClearLogin();
SimulateUserLogin(kUser1);
SetAmbientModeEnabled(true);
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
SimulateUserLogin(kUser2);
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
}
TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) { TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) {
EXPECT_FALSE(IsAccessTokenRequestPending()); EXPECT_FALSE(IsAccessTokenRequestPending());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment