diff options
4 files changed, 32 insertions, 8 deletions
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc index ae0a5f29..b9458b8 100644 --- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc @@ -530,7 +530,8 @@ bool AutofillPopupControllerImpl::HasSuggestions() { (identifiers_[0] > 0 || identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY || identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY || - identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY); + identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY || + identifiers_[0] == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); } void AutofillPopupControllerImpl::SetValues( diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc index 99faf6f..963da43 100644 --- a/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/components/autofill/core/browser/autofill_manager_unittest.cc @@ -95,15 +95,13 @@ class TestPersonalDataManager : public PersonalDataManager { CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); if (credit_card) { credit_cards_.erase( - std::remove(credit_cards_.begin(), credit_cards_.end(), credit_card), - credit_cards_.end()); + std::find(credit_cards_.begin(), credit_cards_.end(), credit_card)); } AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); if (profile) { web_profiles_.erase( - std::remove(web_profiles_.begin(), web_profiles_.end(), profile), - web_profiles_.end()); + std::find(web_profiles_.begin(), web_profiles_.end(), profile)); } } @@ -2787,14 +2785,20 @@ TEST_F(AutofillManagerTest, AccessAddressBookPrompt) { std::vector<FormData> forms(1, form); FormsSeen(forms); FormFieldData& field = form.fields[0]; + field.should_autocomplete = true; - field.should_autocomplete = false; + // A profile already exists. EXPECT_FALSE( autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field)); - field.should_autocomplete = true; + // Remove all profiles. + personal_data_.ClearAutofillProfiles(); EXPECT_TRUE( autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field)); + + field.should_autocomplete = false; + EXPECT_FALSE( + autofill_manager_->ShouldShowAccessAddressBookSuggestion(form, field)); } #endif // defined(OS_MACOSX) && !defined(OS_IOS) diff --git a/components/autofill/core/browser/personal_data_manager_mac.mm b/components/autofill/core/browser/personal_data_manager_mac.mm index 4080d3c..c6f8eef 100644 --- a/components/autofill/core/browser/personal_data_manager_mac.mm +++ b/components/autofill/core/browser/personal_data_manager_mac.mm @@ -363,6 +363,11 @@ bool PersonalDataManager::AccessAddressBook() { bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion( AutofillType type) { + // Don't show the access Address Book prompt if the user has built up any + // Autofill state. + if (!web_profiles_.empty()) + return false; + if (!enabled_pref_->GetValue()) return false; diff --git a/components/autofill/core/browser/personal_data_manager_unittest.cc b/components/autofill/core/browser/personal_data_manager_unittest.cc index c5e0065..50eb51e 100644 --- a/components/autofill/core/browser/personal_data_manager_unittest.cc +++ b/components/autofill/core/browser/personal_data_manager_unittest.cc @@ -2706,10 +2706,24 @@ TEST_F(PersonalDataManagerTest, ShowAddressBookPrompt) { AutofillType type(ADDRESS_HOME_STREET_ADDRESS); + prefs_->SetBoolean(prefs::kAutofillEnabled, false); + EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); + prefs_->SetBoolean(prefs::kAutofillEnabled, true); EXPECT_TRUE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); - prefs_->SetBoolean(prefs::kAutofillEnabled, false); + // Adding an Autofill Profile should prevent the prompt from appearing. + AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); + test::SetProfileInfo(&profile, + "Marion", "Mitchell", "Morrison", + "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", + "91601", "US", "12345678910"); + personal_data_->AddProfile(profile); + + EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) + .WillOnce(QuitMainMessageLoop()); + base::MessageLoop::current()->Run(); + EXPECT_FALSE(personal_data_->ShouldShowAccessAddressBookSuggestion(type)); } #endif // defined(OS_MACOSX) && !defined(OS_IOS) |