Commit d4dd2df0 authored by erikchen's avatar erikchen Committed by Commit bot

mac: Fix 2 bugs where "Access Address Book" prompt is incorrectly shown.

Don't show "Access Address Book" prompt if Autofill is disabled, the form has
the attribute autocomplete="off", or if Chrome doesn't think the form is
Autofillable.

BUG=398476

Review URL: https://codereview.chromium.org/512933004

Cr-Commit-Position: refs/heads/master@{#292538}
parent e22312d2
......@@ -285,13 +285,17 @@ void AutofillManager::ShowAutofillSettings() {
bool AutofillManager::ShouldShowAccessAddressBookSuggestion(
const FormData& form,
const FormFieldData& field) {
if (!personal_data_)
if (!personal_data_ || !field.should_autocomplete)
return false;
FormStructure* form_structure = NULL;
AutofillField* autofill_field = NULL;
if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
return false;
if (!form_structure->IsAutofillable())
return false;
return personal_data_->ShouldShowAccessAddressBookSuggestion(
autofill_field->Type());
}
......
......@@ -2780,6 +2780,24 @@ TEST_F(AutofillManagerTest, RemoveProfileVariant) {
EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str()));
}
#if defined(OS_MACOSX) && !defined(OS_IOS)
TEST_F(AutofillManagerTest, AccessAddressBookPrompt) {
FormData form;
test::CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
FormsSeen(forms);
FormFieldData& field = form.fields[0];
field.should_autocomplete = false;
EXPECT_FALSE(
autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
field.should_autocomplete = true;
EXPECT_TRUE(
autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field));
}
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
namespace {
class MockAutofillClient : public TestAutofillClient {
......
......@@ -363,6 +363,9 @@ bool PersonalDataManager::AccessAddressBook() {
bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion(
AutofillType type) {
if (!enabled_pref_->GetValue())
return false;
if (HasPromptedForAccessToAddressBook(pref_service_))
return false;
......
......@@ -2675,4 +2675,18 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) {
EXPECT_EQ(base::string16(), labels[1]);
}
#if defined(OS_MACOSX) && !defined(OS_IOS)
TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) {
EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2);
AutofillType type(ADDRESS_HOME_STREET_ADDRESS);
prefs_->SetBoolean(prefs::kAutofillEnabled, true);
EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
prefs_->SetBoolean(prefs::kAutofillEnabled, false);
EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type));
}
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
} // namespace autofill
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