[Autofill] Fix popup delegate to show warnings correctly.
BUG=247880 TEST=out/Debug/unit_tests --gtest_filter=AutofillExternalDelegateUnitTest.AutofillWarnings R=csharp@chromium.org Review URL: https://chromiumcodereview.appspot.com/16344003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205502 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
components/autofill/browser
@ -91,14 +91,15 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
|
||||
std::vector<base::string16> icons(autofill_icons);
|
||||
std::vector<int> ids(autofill_unique_ids);
|
||||
|
||||
// Add or hide warnings as appropriate.
|
||||
ApplyAutofillWarnings(&values, &labels, &icons, &ids);
|
||||
|
||||
// Add a separator to go between the values and menu items.
|
||||
values.push_back(base::string16());
|
||||
labels.push_back(base::string16());
|
||||
icons.push_back(base::string16());
|
||||
ids.push_back(WebAutofillClient::MenuItemIDSeparator);
|
||||
|
||||
ApplyAutofillWarnings(&values, &labels, &icons, &ids);
|
||||
|
||||
// Only include "Autofill Options" special menu item if we have Autofill
|
||||
// suggestions.
|
||||
has_autofill_suggestion_ = false;
|
||||
@ -113,10 +114,8 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
|
||||
ApplyAutofillOptions(&values, &labels, &icons, &ids);
|
||||
|
||||
// Remove the separator if it is the last element.
|
||||
// It is possible for ids to be empty at this point if the vectors were
|
||||
// cleared by ApplyAutofillWarnings (which can occur if we shouldn't
|
||||
// autocomplete or display warnings for this field).
|
||||
if (!ids.empty() && ids.back() == WebAutofillClient::MenuItemIDSeparator) {
|
||||
DCHECK_GT(ids.size(), 0U);
|
||||
if (ids.back() == WebAutofillClient::MenuItemIDSeparator) {
|
||||
values.pop_back();
|
||||
labels.pop_back();
|
||||
icons.pop_back();
|
||||
|
@ -119,7 +119,7 @@ class AutofillExternalDelegateUnitTest
|
||||
field.should_autocomplete = true;
|
||||
const gfx::RectF element_bounds;
|
||||
|
||||
external_delegate_->OnQuery(query_id, form, field, element_bounds, false);
|
||||
external_delegate_->OnQuery(query_id, form, field, element_bounds, true);
|
||||
}
|
||||
|
||||
MockAutofillManagerDelegate manager_delegate_;
|
||||
@ -223,6 +223,33 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
|
||||
autofill_ids);
|
||||
}
|
||||
|
||||
// Test that the Autofill popup is able to display warnings explaining why
|
||||
// Autofill is disabled for a website.
|
||||
// Regression test for http://crbug.com/247880
|
||||
TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) {
|
||||
IssueOnQuery(kQueryId);
|
||||
|
||||
// The enums must be cast to ints to prevent compile errors on linux_rel.
|
||||
EXPECT_CALL(manager_delegate_,
|
||||
ShowAutofillPopup(
|
||||
_, _, _, _,
|
||||
testing::ElementsAre(
|
||||
static_cast<int>(
|
||||
WebAutofillClient::MenuItemIDWarningMessage)),
|
||||
_));
|
||||
|
||||
// This should call ShowAutofillPopup.
|
||||
std::vector<base::string16> autofill_item;
|
||||
autofill_item.push_back(base::string16());
|
||||
std::vector<int> autofill_ids;
|
||||
autofill_ids.push_back(WebAutofillClient::MenuItemIDWarningMessage);
|
||||
external_delegate_->OnSuggestionsReturned(kQueryId,
|
||||
autofill_item,
|
||||
autofill_item,
|
||||
autofill_item,
|
||||
autofill_ids);
|
||||
}
|
||||
|
||||
// Test that the Autofill delegate doesn't try and fill a form with a
|
||||
// negative unique id.
|
||||
TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
|
||||
|
Reference in New Issue
Block a user