Commit 16ebe376 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Fix unnecessary black shelf background issue when device boot

This CL is more lightweight solution compared with the previous
attempts:
https://crrev.com/c/1229695
(An overkill. "no wallpaper" is not a valid UI state we'll support.)
https://crrev.com/c/1187547
(A risky change. Large number of tests failed.)
https://crrev.com/c/1173433
(Doesn't quite handle the "no wallpaper" case.)

Bug: 874015
Change-Id: I7656856d1b631b7f6d2555f932116ea08e7d23ec
Reviewed-on: https://chromium-review.googlesource.com/1237149Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594504}
parent e7d1e30c
...@@ -358,28 +358,19 @@ class ShelfBackgroundTargetColorTest : public NoSessionAshTestBase { ...@@ -358,28 +358,19 @@ class ShelfBackgroundTargetColorTest : public NoSessionAshTestBase {
DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundTargetColorTest); DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundTargetColorTest);
}; };
// Verify the target colors of the shelf and item backgrounds are updated after // The tests only compare the base color, because different alpha values may be
// session state changes. Only compare the base color, because different alpha // applied based on |ShelfBackgroundType|, which is verifed by
// values may be applied based on |ShelfBackgroundType|, which is verifed by
// |ShelfBackgroundAnimatorTest|. // |ShelfBackgroundAnimatorTest|.
//
// Verify the target colors of the shelf and item backgrounds are updated based
// on session state, starting from LOGIN_PRIMARY.
TEST_F(ShelfBackgroundTargetColorTest, TEST_F(ShelfBackgroundTargetColorTest,
ShelfAndItemBackgroundColorUpdatedWithSessionState) { ShelfAndItemBackgroundColorUpdatedFromLogin) {
// Use the real ShelfBackgroundAnimator instance because it needs to update
// for session state changes.
ShelfBackgroundAnimatorTestApi test_api( ShelfBackgroundAnimatorTestApi test_api(
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow()) Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget() ->shelf_widget()
->background_animator_for_testing()); ->background_animator_for_testing());
// The shelf is not initialized until session state becomes active, so the
// following two cases don't have visible effects until we support views-based
// shelf for all session states, but it's still good to check them here.
NotifySessionStateChanged(session_manager::SessionState::OOBE);
EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()),
GetBaseColor(SK_ColorTRANSPARENT));
EXPECT_EQ(GetBaseColor(test_api.item_background_target_color()),
GetBaseColor(gfx::kGoogleGrey100));
NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY); NotifySessionStateChanged(session_manager::SessionState::LOGIN_PRIMARY);
EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()), EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()),
GetBaseColor(SK_ColorTRANSPARENT)); GetBaseColor(SK_ColorTRANSPARENT));
...@@ -431,4 +422,39 @@ TEST_F(ShelfBackgroundTargetColorTest, ...@@ -431,4 +422,39 @@ TEST_F(ShelfBackgroundTargetColorTest,
GetBaseColor(kShelfDefaultBaseColor)); GetBaseColor(kShelfDefaultBaseColor));
} }
// Verify the target colors of the shelf and item backgrounds are updated based
// on session state, starting from OOBE.
// Note: the shelf is not supported for OOBE yet but it's good to check it here.
// TODO(wzang|798869): The item backgrounds still keep the OOBE color if
// directly transitioned from OOBE to LOGIN_PRIMARY. Revisit this when OOBE
// shelf is supported.
TEST_F(ShelfBackgroundTargetColorTest,
ShelfAndItemBackgroundColorUpdatedFromOOBE) {
ShelfBackgroundAnimatorTestApi test_api(
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->background_animator_for_testing());
NotifySessionStateChanged(session_manager::SessionState::OOBE);
EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()),
GetBaseColor(SK_ColorTRANSPARENT));
EXPECT_EQ(GetBaseColor(test_api.item_background_target_color()),
GetBaseColor(gfx::kGoogleGrey100));
SimulateUserLogin("user1@test.com");
NotifySessionStateChanged(
session_manager::SessionState::LOGGED_IN_NOT_ACTIVE);
EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()),
GetBaseColor(SK_ColorTRANSPARENT));
EXPECT_EQ(GetBaseColor(test_api.item_background_target_color()),
GetBaseColor(SK_ColorTRANSPARENT));
NotifySessionStateChanged(session_manager::SessionState::ACTIVE);
EXPECT_EQ(GetBaseColor(test_api.shelf_background_target_color()),
GetBaseColor(kShelfDefaultBaseColor));
EXPECT_EQ(GetBaseColor(test_api.item_background_target_color()),
GetBaseColor(kShelfDefaultBaseColor));
}
} // namespace ash } // namespace ash
...@@ -541,8 +541,10 @@ ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { ...@@ -541,8 +541,10 @@ ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const {
if (state_.session_state == session_manager::SessionState::OOBE) if (state_.session_state == session_manager::SessionState::OOBE)
return SHELF_BACKGROUND_OOBE; return SHELF_BACKGROUND_OOBE;
if (state_.session_state != session_manager::SessionState::ACTIVE) { if (state_.session_state != session_manager::SessionState::ACTIVE) {
if (!Shell::Get()->wallpaper_controller()->IsWallpaperBlurred()) if (Shell::Get()->wallpaper_controller()->HasShownAnyWallpaper() &&
!Shell::Get()->wallpaper_controller()->IsWallpaperBlurred()) {
return SHELF_BACKGROUND_LOGIN_NONBLURRED_WALLPAPER; return SHELF_BACKGROUND_LOGIN_NONBLURRED_WALLPAPER;
}
return SHELF_BACKGROUND_LOGIN; return SHELF_BACKGROUND_LOGIN;
} }
...@@ -1143,6 +1145,10 @@ void ShelfLayoutManager::OnWallpaperBlurChanged() { ...@@ -1143,6 +1145,10 @@ void ShelfLayoutManager::OnWallpaperBlurChanged() {
MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE);
} }
void ShelfLayoutManager::OnFirstWallpaperShown() {
MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE);
}
void ShelfLayoutManager::OnLoginStatusChanged(LoginStatus loing_status) { void ShelfLayoutManager::OnLoginStatusChanged(LoginStatus loing_status) {
UpdateVisibilityState(); UpdateVisibilityState();
} }
......
...@@ -187,6 +187,7 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -187,6 +187,7 @@ class ASH_EXPORT ShelfLayoutManager
// Overridden from WallpaperControllerObserver: // Overridden from WallpaperControllerObserver:
void OnWallpaperBlurChanged() override; void OnWallpaperBlurChanged() override;
void OnFirstWallpaperShown() override;
// TODO(harrym|oshima): These templates will be moved to a new Shelf class. // TODO(harrym|oshima): These templates will be moved to a new Shelf class.
// A helper function for choosing values specific to a shelf alignment. // A helper function for choosing values specific to a shelf alignment.
......
...@@ -253,6 +253,29 @@ class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver { ...@@ -253,6 +253,29 @@ class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver {
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest); DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest);
}; };
class WallpaperShownWaiter : public WallpaperControllerObserver {
public:
WallpaperShownWaiter() {
Shell::Get()->wallpaper_controller()->AddObserver(this);
}
~WallpaperShownWaiter() override {
Shell::Get()->wallpaper_controller()->RemoveObserver(this);
}
// Note this could only be called once because RunLoop would not run after
// Quit is called. Create a new instance if there's need to wait again.
void Wait() { run_loop_.Run(); }
private:
// WallpaperControllerObserver:
void OnFirstWallpaperShown() override { run_loop_.Quit(); }
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(WallpaperShownWaiter);
};
} // namespace } // namespace
class ShelfLayoutManagerTest : public AshTestBase { class ShelfLayoutManagerTest : public AshTestBase {
...@@ -986,22 +1009,32 @@ TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) { ...@@ -986,22 +1009,32 @@ TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
// Assertions around the login screen. // Assertions around the login screen.
TEST_F(ShelfLayoutManagerTest, VisibleWhenLoginScreenShowing) { TEST_F(ShelfLayoutManagerTest, VisibleWhenLoginScreenShowing) {
Shelf* shelf = GetPrimaryShelf(); Shelf* shelf = GetPrimaryShelf();
WallpaperController* wallpaper_controller =
Shell::Get()->wallpaper_controller();
WallpaperShownWaiter waiter;
mojom::SessionInfoPtr info = mojom::SessionInfo::New(); mojom::SessionInfoPtr info = mojom::SessionInfo::New();
info->state = session_manager::SessionState::LOGIN_PRIMARY; info->state = session_manager::SessionState::LOGIN_PRIMARY;
ash::Shell::Get()->session_controller()->SetSessionInfo(std::move(info)); Shell::Get()->session_controller()->SetSessionInfo(std::move(info));
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Blurred wallpaper. // No wallpaper.
ash::Shell::Get()->wallpaper_controller()->UpdateWallpaperBlur(/*blur=*/true); ASSERT_FALSE(wallpaper_controller->HasShownAnyWallpaper());
EXPECT_EQ(SHELF_BACKGROUND_LOGIN, GetShelfWidget()->GetBackgroundType()); EXPECT_EQ(SHELF_BACKGROUND_LOGIN, GetShelfWidget()->GetBackgroundType());
// Showing wallpaper is asynchronous.
wallpaper_controller->ShowDefaultWallpaperForTesting();
waiter.Wait();
ASSERT_TRUE(wallpaper_controller->HasShownAnyWallpaper());
// Non-blurred wallpaper. // Non-blurred wallpaper.
base::CommandLine::ForCurrentProcess()->AppendSwitch( wallpaper_controller->UpdateWallpaperBlur(/*blur=*/false);
ash::switches::kAshDisableLoginDimAndBlur);
ash::Shell::Get()->wallpaper_controller()->UpdateWallpaperBlur(/*blur=*/true);
EXPECT_EQ(SHELF_BACKGROUND_LOGIN_NONBLURRED_WALLPAPER, EXPECT_EQ(SHELF_BACKGROUND_LOGIN_NONBLURRED_WALLPAPER,
GetShelfWidget()->GetBackgroundType()); GetShelfWidget()->GetBackgroundType());
// Blurred wallpaper.
wallpaper_controller->UpdateWallpaperBlur(/*blur=*/true);
EXPECT_EQ(SHELF_BACKGROUND_LOGIN, GetShelfWidget()->GetBackgroundType());
} }
// Assertions around the lock screen showing. // Assertions around the lock screen showing.
......
...@@ -645,6 +645,10 @@ bool WallpaperController::CanOpenWallpaperPicker() { ...@@ -645,6 +645,10 @@ bool WallpaperController::CanOpenWallpaperPicker() {
!IsActiveUserWallpaperControlledByPolicyImpl(); !IsActiveUserWallpaperControlledByPolicyImpl();
} }
bool WallpaperController::HasShownAnyWallpaper() const {
return !!current_wallpaper_;
}
void WallpaperController::ShowWallpaperImage(const gfx::ImageSkia& image, void WallpaperController::ShowWallpaperImage(const gfx::ImageSkia& image,
WallpaperInfo info, WallpaperInfo info,
bool preview_mode) { bool preview_mode) {
...@@ -686,6 +690,10 @@ void WallpaperController::ShowWallpaperImage(const gfx::ImageSkia& image, ...@@ -686,6 +690,10 @@ void WallpaperController::ShowWallpaperImage(const gfx::ImageSkia& image,
current_wallpaper_->AddObserver(this); current_wallpaper_->AddObserver(this);
current_wallpaper_->StartResize(); current_wallpaper_->StartResize();
if (is_first_wallpaper_) {
for (auto& observer : observers_)
observer.OnFirstWallpaperShown();
}
mojo_observers_.ForAllPtrs([this](mojom::WallpaperObserver* observer) { mojo_observers_.ForAllPtrs([this](mojom::WallpaperObserver* observer) {
observer->OnWallpaperChanged(current_wallpaper_->original_image_id()); observer->OnWallpaperChanged(current_wallpaper_->original_image_id());
}); });
...@@ -733,6 +741,10 @@ bool WallpaperController::IsBlurAllowed() const { ...@@ -733,6 +741,10 @@ bool WallpaperController::IsBlurAllowed() const {
switches::kAshDisableLoginDimAndBlur); switches::kAshDisableLoginDimAndBlur);
} }
bool WallpaperController::IsWallpaperBlurred() const {
return is_wallpaper_blurred_;
}
bool WallpaperController::SetUserWallpaperInfo(const AccountId& account_id, bool WallpaperController::SetUserWallpaperInfo(const AccountId& account_id,
const WallpaperInfo& info, const WallpaperInfo& info,
bool is_ephemeral) { bool is_ephemeral) {
......
...@@ -148,6 +148,11 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -148,6 +148,11 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
// Returns true if the active user is allowed to open the wallpaper picker. // Returns true if the active user is allowed to open the wallpaper picker.
bool CanOpenWallpaperPicker(); bool CanOpenWallpaperPicker();
// Returns whether any wallpaper has been shown. It returns false before the
// first wallpaper is set (which happens momentarily after startup), and will
// always return true thereafter.
bool HasShownAnyWallpaper() const;
// Shows the wallpaper and alerts observers of changes. Does not show the // Shows the wallpaper and alerts observers of changes. Does not show the
// image if |preview_mode| is false and the current wallpaper is still being // image if |preview_mode| is false and the current wallpaper is still being
// previewed. See comments for |confirm_preview_wallpaper_callback_|. // previewed. See comments for |confirm_preview_wallpaper_callback_|.
...@@ -172,7 +177,9 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController, ...@@ -172,7 +177,9 @@ class ASH_EXPORT WallpaperController : public mojom::WallpaperController,
bool IsBlurAllowed() const; bool IsBlurAllowed() const;
// Returns whether the current wallpaper is blurred. // Returns whether the current wallpaper is blurred.
bool IsWallpaperBlurred() const { return is_wallpaper_blurred_; } // Note: this returns false when there's no wallpaper yet. Check
// |HasShownAnyWallpaper| if there's need to distinguish.
bool IsWallpaperBlurred() const;
// Sets wallpaper info for |account_id| and saves it to local state if // Sets wallpaper info for |account_id| and saves it to local state if
// |is_ephemeral| is false. Returns false if it fails (which happens if local // |is_ephemeral| is false. Returns false if it fails (which happens if local
......
...@@ -23,6 +23,10 @@ class ASH_EXPORT WallpaperControllerObserver { ...@@ -23,6 +23,10 @@ class ASH_EXPORT WallpaperControllerObserver {
// Invoked when the wallpaper preview mode ends. // Invoked when the wallpaper preview mode ends.
virtual void OnWallpaperPreviewEnded() {} virtual void OnWallpaperPreviewEnded() {}
// Invoked when the first wallpaper is set. The first wallpaper is the one
// shown right after boot splash screen or after a session restart.
virtual void OnFirstWallpaperShown() {}
protected: protected:
virtual ~WallpaperControllerObserver() {} virtual ~WallpaperControllerObserver() {}
}; };
......
...@@ -268,10 +268,15 @@ class TestWallpaperControllerObserver : public WallpaperControllerObserver { ...@@ -268,10 +268,15 @@ class TestWallpaperControllerObserver : public WallpaperControllerObserver {
TestWallpaperControllerObserver() = default; TestWallpaperControllerObserver() = default;
void OnWallpaperBlurChanged() override { ++wallpaper_blur_changed_count_; } void OnWallpaperBlurChanged() override { ++wallpaper_blur_changed_count_; }
void OnFirstWallpaperShown() override { ++first_wallpaper_shown_count_; }
void Reset() { wallpaper_blur_changed_count_ = 0; } void Reset() { wallpaper_blur_changed_count_ = 0; }
int wallpaper_blur_changed_count_ = 0; int wallpaper_blur_changed_count_ = 0;
int first_wallpaper_shown_count_ = 0;
private:
DISALLOW_COPY_AND_ASSIGN(TestWallpaperControllerObserver);
}; };
} // namespace } // namespace
...@@ -2358,6 +2363,30 @@ TEST_F(WallpaperControllerTest, ShowOneShotWallpaper) { ...@@ -2358,6 +2363,30 @@ TEST_F(WallpaperControllerTest, ShowOneShotWallpaper) {
EXPECT_EQ(WallpaperType::CUSTOMIZED, controller_->GetWallpaperType()); EXPECT_EQ(WallpaperType::CUSTOMIZED, controller_->GetWallpaperType());
} }
TEST_F(WallpaperControllerTest, OnFirstWallpaperShown) {
TestWallpaperControllerObserver observer;
controller_->AddObserver(&observer);
EXPECT_EQ(0, GetWallpaperCount());
EXPECT_EQ(0, observer.first_wallpaper_shown_count_);
// Show the first wallpaper, verify the observer is notified.
controller_->ShowWallpaperImage(CreateImage(640, 480, SK_ColorBLUE),
CreateWallpaperInfo(WALLPAPER_LAYOUT_STRETCH),
false /*preview_mode=*/);
RunAllTasksUntilIdle();
EXPECT_EQ(SK_ColorBLUE, GetWallpaperColor());
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_EQ(1, observer.first_wallpaper_shown_count_);
// Show the second wallpaper, verify the observer is not notified.
controller_->ShowWallpaperImage(CreateImage(640, 480, SK_ColorCYAN),
CreateWallpaperInfo(WALLPAPER_LAYOUT_STRETCH),
false /*preview_mode=*/);
RunAllTasksUntilIdle();
EXPECT_EQ(SK_ColorCYAN, GetWallpaperColor());
EXPECT_EQ(2, GetWallpaperCount());
EXPECT_EQ(1, observer.first_wallpaper_shown_count_);
controller_->RemoveObserver(&observer);
}
// A test wallpaper controller client class. // A test wallpaper controller client class.
class TestWallpaperControllerClient : public mojom::WallpaperControllerClient { class TestWallpaperControllerClient : public mojom::WallpaperControllerClient {
public: public:
......
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