Commit 86c83ee8 authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Fix crash in EditableCombobox when opening the menu.

The dropdown should not open directly after construction.

Bug: 987360
Change-Id: I15fe1a319cc00308c926e4d5adac7db1126bd822
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1718328Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681865}
parent b2f6e48d
...@@ -511,6 +511,8 @@ void EditableCombobox::ShowDropDownMenu(ui::MenuSourceType source_type) { ...@@ -511,6 +511,8 @@ void EditableCombobox::ShowDropDownMenu(ui::MenuSourceType source_type) {
} }
if (menu_runner_ && menu_runner_->IsRunning()) if (menu_runner_ && menu_runner_->IsRunning())
return; return;
if (!GetWidget())
return;
// Since we don't capture the mouse, we want to see the events that happen in // Since we don't capture the mouse, we want to see the events that happen in
// the EditableCombobox's RootView to get a chance to close the menu if they // the EditableCombobox's RootView to get a chance to close the menu if they
......
...@@ -230,7 +230,7 @@ void EditableComboboxTest::DragMouseTo(const gfx::Point& location) { ...@@ -230,7 +230,7 @@ void EditableComboboxTest::DragMouseTo(const gfx::Point& location) {
} }
bool EditableComboboxTest::IsMenuOpen() { bool EditableComboboxTest::IsMenuOpen() {
return combobox_->GetMenuRunnerForTest() && return combobox_ && combobox_->GetMenuRunnerForTest() &&
combobox_->GetMenuRunnerForTest()->IsRunning(); combobox_->GetMenuRunnerForTest()->IsRunning();
} }
...@@ -797,5 +797,16 @@ TEST_F(EditableComboboxTest, DragToSelectDoesntOpenTheMenu) { ...@@ -797,5 +797,16 @@ TEST_F(EditableComboboxTest, DragToSelectDoesntOpenTheMenu) {
EXPECT_FALSE(IsMenuOpen()); EXPECT_FALSE(IsMenuOpen());
} }
TEST_F(EditableComboboxTest, NoCrashWithoutWidget) {
std::vector<base::string16> items = {ASCIIToUTF16("item0"),
ASCIIToUTF16("item1")};
auto combobox = std::make_unique<EditableCombobox>(
std::make_unique<ui::SimpleComboboxModel>(items),
/*filter_on_edit=*/false,
/*show_on_empty=*/true, EditableCombobox::Type::kPassword);
// Showing the dropdown should silently fail.
combobox->RevealPasswords(true);
}
} // namespace } // namespace
} // namespace views } // namespace views
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