Commit 129ff747 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Autofill] Fix crash in AutofillPopupViewNativeViews

This CL checks body_container_ for nullness.
body_container_ could be null if there are only footer items.

Bug: 1113255,1108181
Change-Id: I9ed145c1d18baf8b13deab8c44cc510b3bb781eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339479
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795409}
parent 6e145aaa
...@@ -1227,7 +1227,7 @@ bool AutofillPopupViewNativeViews::DoUpdateBoundsAndRedrawPopup() { ...@@ -1227,7 +1227,7 @@ bool AutofillPopupViewNativeViews::DoUpdateBoundsAndRedrawPopup() {
element_bounds.Inset(/*horizontal=*/0, /*vertical=*/-kElementBorderPadding); element_bounds.Inset(/*horizontal=*/0, /*vertical=*/-kElementBorderPadding);
int item_height = int item_height =
body_container_->children().size() > 0 body_container_ && body_container_->children().size() > 0
? body_container_->children()[0]->GetPreferredSize().height() ? body_container_->children()[0]->GetPreferredSize().height()
: 0; : 0;
if (!HasEnoughHeightForOneRow(item_height, GetContentAreaBounds(), if (!HasEnoughHeightForOneRow(item_height, GetContentAreaBounds(),
...@@ -1242,7 +1242,7 @@ bool AutofillPopupViewNativeViews::DoUpdateBoundsAndRedrawPopup() { ...@@ -1242,7 +1242,7 @@ bool AutofillPopupViewNativeViews::DoUpdateBoundsAndRedrawPopup() {
// Adjust the width to compensate for a scroll bar, if necessary, and for // Adjust the width to compensate for a scroll bar, if necessary, and for
// other rules. // other rules.
int scroll_width = 0; int scroll_width = 0;
if (preferred_size.height() > popup_bounds.height()) { if (scroll_view_ && preferred_size.height() > popup_bounds.height()) {
preferred_size.set_height(popup_bounds.height()); preferred_size.set_height(popup_bounds.height());
// Because the preferred size is greater than the bounds available, the // Because the preferred size is greater than the bounds available, the
......
...@@ -124,6 +124,19 @@ TEST_F(AutofillPopupViewNativeViewsTest, ShowHideTest) { ...@@ -124,6 +124,19 @@ TEST_F(AutofillPopupViewNativeViewsTest, ShowHideTest) {
view()->Hide(); view()->Hide();
} }
// This is a regression test for crbug.com/1113255
TEST_F(AutofillPopupViewNativeViewsTest,
ShowViewWithOnlyFooterItemsShouldNotCrash) {
// Set suggestions to have only a footer item.
autofill_popup_controller_.set_suggestions(
{autofill::PopupItemId::POPUP_ITEM_ID_CLEAR_FORM});
view_ = std::make_unique<autofill::AutofillPopupViewNativeViews>(
&autofill_popup_controller_, widget_.get());
widget_->SetContentsView(view_.get());
widget_->Show();
view_->Show();
}
TEST_F(AutofillPopupViewNativeViewsTest, AccessibilitySelectedEvent) { TEST_F(AutofillPopupViewNativeViewsTest, AccessibilitySelectedEvent) {
TestAXEventObserver observer; TestAXEventObserver observer;
CreateAndShowView({autofill::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, CreateAndShowView({autofill::POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY,
......
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