diff options
author | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-20 00:09:00 +0000 |
---|---|---|
committer | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-20 00:09:00 +0000 |
commit | 0ac9c47d1863828ef490d459586a3389ac56b050 (patch) | |
tree | 64a545bf0eae8687776f27b942a61f5be55b2d45 | |
parent | 3b9de45a65e1d58fd921e48b4e0a88d57e87b049 (diff) | |
download | chromium_src-0ac9c47d1863828ef490d459586a3389ac56b050.zip chromium_src-0ac9c47d1863828ef490d459586a3389ac56b050.tar.gz chromium_src-0ac9c47d1863828ef490d459586a3389ac56b050.tar.bz2 |
[Autofill] Fix UpdateDataListValues to handle Data List only Popups
The UpdateDataListValues function was incorrectly assuming that there
would be non-data list values in the popup whenever it was called,
but it is entirely possible for a popup to only contain data list
values.
R=isherman@chromium.org
BUG=261898
Review URL: https://chromiumcodereview.appspot.com/19809002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212702 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/autofill/autofill_popup_controller_impl.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc | 30 |
2 files changed, 39 insertions, 1 deletions
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc index f0611ab..ac3b195 100644 --- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc @@ -175,7 +175,8 @@ void AutofillPopupControllerImpl::UpdateDataListValues( const std::vector<base::string16>& labels) { // Remove all the old data list values, which should always be at the top of // the list if they are present. - while (identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry) { + while (!identifiers_.empty() && + identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry) { names_.erase(names_.begin()); subtexts_.erase(subtexts_.begin()); icons_.erase(icons_.begin()); @@ -191,6 +192,13 @@ void AutofillPopupControllerImpl::UpdateDataListValues( icons_.erase(icons_.begin()); identifiers_.erase(identifiers_.begin()); } + + // The popup contents have changed, so either update the bounds or hide it. + if (HasSuggestions()) + UpdateBoundsAndRedrawPopup(); + else + Hide(); + return; } diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc index bda9769..8cbcdeb6 100644 --- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc @@ -424,6 +424,36 @@ TEST_F(AutofillPopupControllerUnitTest, UpdateDataListValues) { EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); } +TEST_F(AutofillPopupControllerUnitTest, PopupsWithOnlyDataLists) { + // Create the popup with a single datalist element. + std::vector<string16> items; + items.push_back(string16()); + std::vector<int> ids; + ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); + + autofill_popup_controller_->Show(items, items, items, ids); + + EXPECT_EQ(items, autofill_popup_controller_->names()); + EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); + + // Replace the datalist element with a new one. + std::vector<string16> data_list_values; + data_list_values.push_back(ASCIIToUTF16("data list value 1")); + + autofill_popup_controller_->UpdateDataListValues(data_list_values, + data_list_values); + + EXPECT_EQ(data_list_values, autofill_popup_controller_->names()); + // The id value should stay the same. + EXPECT_EQ(ids, autofill_popup_controller_->identifiers()); + + // Clear datalist values and check that the popup becomes hidden. + EXPECT_CALL(*autofill_popup_controller_, Hide()); + data_list_values.clear(); + autofill_popup_controller_->UpdateDataListValues(data_list_values, + data_list_values); +} + TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { AutofillDriverImpl* driver = AutofillDriverImpl::FromWebContents(web_contents()); |