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() { ...@@ -285,13 +285,17 @@ void AutofillManager::ShowAutofillSettings() {
bool AutofillManager::ShouldShowAccessAddressBookSuggestion( bool AutofillManager::ShouldShowAccessAddressBookSuggestion(
const FormData& form, const FormData& form,
const FormFieldData& field) { const FormFieldData& field) {
if (!personal_data_) if (!personal_data_ || !field.should_autocomplete)
return false; return false;
FormStructure* form_structure = NULL; FormStructure* form_structure = NULL;
AutofillField* autofill_field = NULL; AutofillField* autofill_field = NULL;
if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
return false; return false;
if (!form_structure->IsAutofillable())
return false;
return personal_data_->ShouldShowAccessAddressBookSuggestion( return personal_data_->ShouldShowAccessAddressBookSuggestion(
autofill_field->Type()); autofill_field->Type());
} }
......
...@@ -2780,6 +2780,24 @@ TEST_F(AutofillManagerTest, RemoveProfileVariant) { ...@@ -2780,6 +2780,24 @@ TEST_F(AutofillManagerTest, RemoveProfileVariant) {
EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); 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 { namespace {
class MockAutofillClient : public TestAutofillClient { class MockAutofillClient : public TestAutofillClient {
......
...@@ -363,6 +363,9 @@ bool PersonalDataManager::AccessAddressBook() { ...@@ -363,6 +363,9 @@ bool PersonalDataManager::AccessAddressBook() {
bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion( bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion(
AutofillType type) { AutofillType type) {
if (!enabled_pref_->GetValue())
return false;
if (HasPromptedForAccessToAddressBook(pref_service_)) if (HasPromptedForAccessToAddressBook(pref_service_))
return false; return false;
......
...@@ -2675,4 +2675,18 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) { ...@@ -2675,4 +2675,18 @@ TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions) {
EXPECT_EQ(base::string16(), labels[1]); 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 } // 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