Commit 16f95218 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

Fix ash shell child modal window example

Attempting to use this example crashes otherwise:
[233814:233814:0703/151833.248652:FATAL:native_widget_aura.cc(151)] Check failed: params.parent || params.context.
#0 0x7f45424a2f7c base::debug::StackTrace::StackTrace()
#1 0x7f45423f23bb logging::LogMessage::~LogMessage()
#2 0x7f453db8604b views::NativeWidgetAura::InitNativeWidget()
#3 0x7f453db68157 views::Widget::Init()
#4 0x0000004e76bd ash::TestChildModalParent::TestChildModalParent()
#5 0x0000004e74ee ash::TestChildModalParent::Create()
#6 0x7f453daefbed views::Button::OnMouseReleased()

Bug: NONE
Test: No ash_shell_with_content crash showing child modal window.
Change-Id: Ic6a2382676d54ea47fd1a6a70b0209c26fd3d87f
Reviewed-on: https://chromium-review.googlesource.com/1125294Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572414}
parent b58fea0e
...@@ -285,7 +285,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, ...@@ -285,7 +285,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(),
ui::MODAL_TYPE_WINDOW); ui::MODAL_TYPE_WINDOW);
} else if (sender == child_modal_button_) { } else if (sender == child_modal_button_) {
TestChildModalParent::Create(); TestChildModalParent::Create(GetWidget()->GetNativeView()->GetRootWindow());
} else if (sender == transient_button_) { } else if (sender == transient_button_) {
NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView()); NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView());
} else if (sender == show_hide_window_button_) { } else if (sender == show_hide_window_button_) {
......
...@@ -96,14 +96,14 @@ ui::ModalType ChildModalWindow::GetModalType() const { ...@@ -96,14 +96,14 @@ ui::ModalType ChildModalWindow::GetModalType() const {
} }
// static // static
void TestChildModalParent::Create() { void TestChildModalParent::Create(aura::Window* context) {
Widget::CreateWindowWithContextAndBounds( Widget::CreateWindowWithContextAndBounds(
new TestChildModalParent(), /*context=*/nullptr, new TestChildModalParent(context), context,
gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight)) gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))
->Show(); ->Show();
} }
TestChildModalParent::TestChildModalParent() TestChildModalParent::TestChildModalParent(aura::Window* context)
: widget_(std::make_unique<Widget>()), : widget_(std::make_unique<Widget>()),
button_(new views::LabelButton( button_(new views::LabelButton(
this, this,
...@@ -113,6 +113,7 @@ TestChildModalParent::TestChildModalParent() ...@@ -113,6 +113,7 @@ TestChildModalParent::TestChildModalParent()
child_(nullptr) { child_(nullptr) {
Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = context;
widget_->Init(params); widget_->Init(params);
widget_->GetRootView()->SetBackground( widget_->GetRootView()->SetBackground(
views::CreateSolidBackground(kModalParentColor)); views::CreateSolidBackground(kModalParentColor));
......
...@@ -28,9 +28,9 @@ class TestChildModalParent : public views::WidgetDelegateView, ...@@ -28,9 +28,9 @@ class TestChildModalParent : public views::WidgetDelegateView,
public views::WidgetObserver { public views::WidgetObserver {
public: public:
// Creates the test window. // Creates the test window.
static void Create(); static void Create(aura::Window* context);
TestChildModalParent(); explicit TestChildModalParent(aura::Window* context);
~TestChildModalParent() override; ~TestChildModalParent() override;
void ShowChild(); void ShowChild();
......
...@@ -253,7 +253,7 @@ TEST_F(WindowModalityControllerTest, GetModalTransient) { ...@@ -253,7 +253,7 @@ TEST_F(WindowModalityControllerTest, GetModalTransient) {
aura::Window* wt; aura::Window* wt;
wt = ::wm::GetModalTransient(w1.get()); wt = ::wm::GetModalTransient(w1.get());
ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); ASSERT_EQ(nullptr, wt);
// Parent w2 to w1. It should get parented to the parent of w1. // Parent w2 to w1. It should get parented to the parent of w1.
::wm::AddTransientChild(w1.get(), w2.get()); ::wm::AddTransientChild(w1.get(), w2.get());
...@@ -262,12 +262,12 @@ TEST_F(WindowModalityControllerTest, GetModalTransient) { ...@@ -262,12 +262,12 @@ TEST_F(WindowModalityControllerTest, GetModalTransient) {
// Request the modal transient window for w1, it should be w2. // Request the modal transient window for w1, it should be w2.
wt = ::wm::GetModalTransient(w1.get()); wt = ::wm::GetModalTransient(w1.get());
ASSERT_NE(static_cast<aura::Window*>(NULL), wt); ASSERT_NE(nullptr, wt);
EXPECT_EQ(-2, wt->id()); EXPECT_EQ(-2, wt->id());
// Request the modal transient window for w11, it should also be w2. // Request the modal transient window for w11, it should also be w2.
wt = ::wm::GetModalTransient(w11.get()); wt = ::wm::GetModalTransient(w11.get());
ASSERT_NE(static_cast<aura::Window*>(NULL), wt); ASSERT_NE(nullptr, wt);
EXPECT_EQ(-2, wt->id()); EXPECT_EQ(-2, wt->id());
} }
...@@ -463,7 +463,7 @@ TEST_F(WindowModalityControllerTest, TouchEvent) { ...@@ -463,7 +463,7 @@ TEST_F(WindowModalityControllerTest, TouchEvent) {
// |child| window. // |child| window.
// - Focus should follow the active window. // - Focus should follow the active window.
TEST_F(WindowModalityControllerTest, ChildModal) { TEST_F(WindowModalityControllerTest, ChildModal) {
TestChildModalParent* delegate = new TestChildModalParent(); TestChildModalParent* delegate = new TestChildModalParent(nullptr);
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, nullptr /* context */, gfx::Rect(0, 0, 400, 400)); delegate, nullptr /* context */, gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
...@@ -472,7 +472,7 @@ TEST_F(WindowModalityControllerTest, ChildModal) { ...@@ -472,7 +472,7 @@ TEST_F(WindowModalityControllerTest, ChildModal) {
EXPECT_TRUE(wm::IsActiveWindow(parent)); EXPECT_TRUE(wm::IsActiveWindow(parent));
aura::Window* modal_parent = delegate->GetModalParent(); aura::Window* modal_parent = delegate->GetModalParent();
EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); EXPECT_NE(nullptr, modal_parent);
EXPECT_NE(parent, modal_parent); EXPECT_NE(parent, modal_parent);
EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
...@@ -522,7 +522,7 @@ TEST_F(WindowModalityControllerTest, ChildModal) { ...@@ -522,7 +522,7 @@ TEST_F(WindowModalityControllerTest, ChildModal) {
// Same as |ChildModal| test, but using |EventGenerator| rather than bypassing // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing
// it by calling |ActivateWindow|. // it by calling |ActivateWindow|.
TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
TestChildModalParent* delegate = new TestChildModalParent(); TestChildModalParent* delegate = new TestChildModalParent(nullptr);
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
delegate, nullptr /* context */, gfx::Rect(0, 0, 400, 400)); delegate, nullptr /* context */, gfx::Rect(0, 0, 400, 400));
widget->Show(); widget->Show();
...@@ -531,13 +531,13 @@ TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { ...@@ -531,13 +531,13 @@ TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
EXPECT_TRUE(wm::IsActiveWindow(parent)); EXPECT_TRUE(wm::IsActiveWindow(parent));
aura::Window* modal_parent = delegate->GetModalParent(); aura::Window* modal_parent = delegate->GetModalParent();
EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); EXPECT_NE(nullptr, modal_parent);
EXPECT_NE(parent, modal_parent); EXPECT_NE(parent, modal_parent);
EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
delegate->ShowChild(); delegate->ShowChild();
aura::Window* child = delegate->GetChild(); aura::Window* child = delegate->GetChild();
EXPECT_NE(static_cast<aura::Window*>(NULL), child); EXPECT_NE(nullptr, child);
EXPECT_TRUE(wm::IsActiveWindow(child)); EXPECT_TRUE(wm::IsActiveWindow(child));
EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
......
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