Commit b2af1539 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by Commit Bot

Fix crash when exiting mirror mode on tablet

Attempting to create ShelfWidget while shelf is in-app is causing
a crash because ShelfWidget::DelegateView::UpdateOpaqueBackground is
called before the widget is initialized.

Moving that call from ShelfWidget::DelegateView constructor into
ShelfWidget::DelegateView::OnWidgetInitialized.

Added a unit test.

Bug: 1021662
Test: manual, DisplayManagerTest.ExitMirrorModeInTabletMode
Change-Id: I32a5f91c834d673b109ab518bc2600908d8dea5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902273Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Commit-Queue: Vladislav Kaznacheev <kaznacheev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713464}
parent a179d833
...@@ -4612,4 +4612,24 @@ TEST_F(DisplayManagerTest, UpdateRootWindowForNewWindows) { ...@@ -4612,4 +4612,24 @@ TEST_F(DisplayManagerTest, UpdateRootWindowForNewWindows) {
} }
} }
// Test that exiting mirror mode in tablet mode with a fullscreen window
// does not cause a crash (crbug.com/1021662).
TEST_F(DisplayManagerTest, ExitMirrorModeInTabletMode) {
// Simulate a tablet with and external display connected.
display::test::DisplayManagerTestApi(display_manager())
.SetFirstDisplayAsInternalDisplay();
UpdateDisplay("800x600,800x600");
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
// Create a window to force in-app shelf.
std::unique_ptr<aura::Window> window = CreateTestWindow();
// Exit mirror mode.
display_manager()->SetMirrorMode(display::MirrorMode::kOff, base::nullopt);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(display_manager()->IsInSoftwareMirrorMode());
}
} // namespace ash } // namespace ash
...@@ -108,6 +108,8 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate, ...@@ -108,6 +108,8 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
bool CanActivate() const override; bool CanActivate() const override;
void ReorderChildLayers(ui::Layer* parent_layer) override; void ReorderChildLayers(ui::Layer* parent_layer) override;
void OnWidgetInitialized() override;
void UpdateBackgroundBlur(); void UpdateBackgroundBlur();
void UpdateOpaqueBackground(); void UpdateOpaqueBackground();
void UpdateDragHandle(); void UpdateDragHandle();
...@@ -169,8 +171,6 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget) ...@@ -169,8 +171,6 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget)
drag_handle_->layer()->SetRoundedCornerRadius( drag_handle_->layer()->SetRoundedCornerRadius(
{radius, radius, radius, radius}); {radius, radius, radius, radius});
drag_handle_->SetSize(kDragHandleSize); drag_handle_->SetSize(kDragHandleSize);
UpdateOpaqueBackground();
} }
ShelfWidget::DelegateView::~DelegateView() = default; ShelfWidget::DelegateView::~DelegateView() = default;
...@@ -211,6 +211,10 @@ void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { ...@@ -211,6 +211,10 @@ void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
parent_layer->StackAtBottom(&opaque_background_); parent_layer->StackAtBottom(&opaque_background_);
} }
void ShelfWidget::DelegateView::OnWidgetInitialized() {
UpdateOpaqueBackground();
}
void ShelfWidget::DelegateView::UpdateBackgroundBlur() { void ShelfWidget::DelegateView::UpdateBackgroundBlur() {
// Blur only if the background is visible. // Blur only if the background is visible.
const bool should_blur_background = const bool should_blur_background =
......
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