Commit 70693f1c authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

cros: Detect race when going to tablet mode with no windows

When going to tablet mode ShelfWidget/ShelfConfig
gets updated before the AppListController gets to notify observers
that AppList will be visible. This means ShelfWidget will update
thinking that the AppList is not visible, when it actually is.

To fix this race, check whether the AppList *should* be visible at
ShelfConfig::is_in_app().


Change-Id: I7d82b6ca5bd8933146dad75c0c1edb3257e41a67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903595
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714829}
parent 828daaf8
......@@ -195,8 +195,17 @@ bool ShelfConfig::is_in_app() const {
const auto* session = shell->session_controller();
if (!session)
return false;
bool is_app_list_visible = is_app_list_visible_;
if (IsTabletMode()) {
// When transitioning to tablet mode, dependents may request in-app state
// before the AppListController knows it is tablet mode. Check whether the
// AppList will be visible in this case.
is_app_list_visible |=
Shell::Get()->app_list_controller()->ShouldHomeLauncherBeVisible();
}
return session->GetSessionState() == session_manager::SessionState::ACTIVE &&
!is_app_list_visible_;
!is_app_list_visible;
}
void ShelfConfig::UpdateIsDense() {
......
......@@ -4270,6 +4270,25 @@ TEST_F(HotseatShelfLayoutManagerTest,
EXPECT_EQ(0, counter.count());
}
// Tests that the shelf opaque background is properly updated after a tablet
// mode transition with no apps.
TEST_F(HotseatShelfLayoutManagerTest,
ShelfBackgroundNotVisibleInTabletModeNoApps) {
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackgroundForTest()->visible());
}
// Tests that the shelf opaque background is properly updated after a tablet
// mode transition with no apps with dense shelf.
TEST_F(HotseatShelfLayoutManagerTest,
DenseShelfBackgroundNotVisibleInTabletModeNoApps) {
UpdateDisplay("300x1000");
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackgroundForTest()->visible());
}
class ShelfLayoutManagerWindowDraggingTest : public ShelfLayoutManagerTestBase {
public:
ShelfLayoutManagerWindowDraggingTest() = default;
......
......@@ -142,6 +142,8 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
ui::Layer* opaque_background() { return &opaque_background_; }
ui::Layer* animating_background() { return &animating_background_; }
ui::Layer* GetOpaqueBackgroundForTest();
private:
// Whether |opaque_background_| is explicitly hidden during an animation.
// Prevents calls to UpdateOpaqueBackground from inadvertently showing
......@@ -294,6 +296,7 @@ void ShelfWidget::DelegateView::UpdateOpaqueBackground() {
bool show_opaque_background =
!tablet_mode || in_app || !chromeos::switches::ShouldShowShelfHotseat();
if (show_opaque_background != opaque_background_.visible())
opaque_background_.SetVisible(show_opaque_background);
......@@ -397,6 +400,10 @@ SkColor ShelfWidget::DelegateView::GetShelfBackgroundColor() const {
return opaque_background_.background_color();
}
ui::Layer* ShelfWidget::DelegateView::GetOpaqueBackgroundForTest() {
return &opaque_background_;
}
bool ShelfWidget::GetHitTestRects(aura::Window* target,
gfx::Rect* hit_test_rect_mouse,
gfx::Rect* hit_test_rect_touch) {
......@@ -433,6 +440,10 @@ ui::Layer* ShelfWidget::GetAnimatingBackground() {
return delegate_view_->animating_background();
}
ui::Layer* ShelfWidget::GetOpaqueBackgroundForTest() {
return delegate_view_->GetOpaqueBackgroundForTest();
}
ShelfWidget::ShelfWidget(Shelf* shelf)
: shelf_(shelf),
background_animator_(shelf_, Shell::Get()->wallpaper_controller()),
......
......@@ -152,6 +152,8 @@ class ASH_EXPORT ShelfWidget : public views::Widget,
return &background_animator_;
}
ui::Layer* GetOpaqueBackgroundForTest();
private:
class DelegateView;
friend class DelegateView;
......
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