diff options
Diffstat (limited to 'components/autofill')
11 files changed, 82 insertions, 31 deletions
diff --git a/components/autofill/core/browser/autofill_common_test.cc b/components/autofill/core/browser/autofill_common_test.cc index f477b25..2187d8b 100644 --- a/components/autofill/core/browser/autofill_common_test.cc +++ b/components/autofill/core/browser/autofill_common_test.cc @@ -128,12 +128,25 @@ CreditCard GetCreditCard() { return credit_card; } +CreditCard GetCreditCard2() { + CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); + SetCreditCardInfo( + &credit_card, "Someone Else", "378282246310005" /* AmEx */, "07", "2019"); + return credit_card; +} + CreditCard GetVerifiedCreditCard() { CreditCard credit_card(GetCreditCard()); credit_card.set_origin(kSettingsOrigin); return credit_card; } +CreditCard GetVerifiedCreditCard2() { + CreditCard credit_card(GetCreditCard2()); + credit_card.set_origin(kSettingsOrigin); + return credit_card; +} + void SetProfileInfo(AutofillProfile* profile, const char* first_name, const char* middle_name, const char* last_name, const char* email, const char* company, diff --git a/components/autofill/core/browser/autofill_common_test.h b/components/autofill/core/browser/autofill_common_test.h index b0818f7..8d6a56f 100644 --- a/components/autofill/core/browser/autofill_common_test.h +++ b/components/autofill/core/browser/autofill_common_test.h @@ -46,9 +46,15 @@ AutofillProfile GetVerifiedProfile2(); // Returns a credit card full of dummy info. CreditCard GetCreditCard(); +// Returns a credit card full of dummy info, different to the above. +CreditCard GetCreditCard2(); + // Returns a verified credit card full of dummy info. CreditCard GetVerifiedCreditCard(); +// Returns a verified credit card full of dummy info, different to the above. +CreditCard GetVerifiedCreditCard2(); + // A unit testing utility that is common to a number of the Autofill unit // tests. |SetProfileInfo| provides a quick way to populate a profile with // c-strings. diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc index d5e05ef..60c863f 100644 --- a/components/autofill/core/browser/autofill_manager.cc +++ b/components/autofill/core/browser/autofill_manager.cc @@ -739,8 +739,9 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { manager_delegate_->ConfirmSaveCreditCard( *metric_logger_, *imported_credit_card, - base::Bind(&PersonalDataManager::SaveImportedCreditCard, - base::Unretained(personal_data_), *imported_credit_card)); + base::Bind( + base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard), + base::Unretained(personal_data_), *imported_credit_card)); } } diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc index 7581e56..d32286d 100644 --- a/components/autofill/core/browser/autofill_manager_unittest.cc +++ b/components/autofill/core/browser/autofill_manager_unittest.cc @@ -84,7 +84,7 @@ class TestPersonalDataManager : public PersonalDataManager { return NULL; } - MOCK_METHOD1(SaveImportedProfile, void(const AutofillProfile&)); + MOCK_METHOD1(SaveImportedProfile, std::string(const AutofillProfile&)); AutofillProfile* GetProfileWithGUID(const char* guid) { for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); diff --git a/components/autofill/core/browser/autofill_merge_unittest.cc b/components/autofill/core/browser/autofill_merge_unittest.cc index 37a5a87..ef60bf7 100644 --- a/components/autofill/core/browser/autofill_merge_unittest.cc +++ b/components/autofill/core/browser/autofill_merge_unittest.cc @@ -88,7 +88,8 @@ class PersonalDataManagerMock : public PersonalDataManager { void Reset(); // PersonalDataManager: - virtual void SaveImportedProfile(const AutofillProfile& profile) OVERRIDE; + virtual std::string SaveImportedProfile( + const AutofillProfile& profile) OVERRIDE; virtual const std::vector<AutofillProfile*>& web_profiles() const OVERRIDE; private: @@ -108,11 +109,14 @@ void PersonalDataManagerMock::Reset() { profiles_.clear(); } -void PersonalDataManagerMock::SaveImportedProfile( +std::string PersonalDataManagerMock::SaveImportedProfile( const AutofillProfile& profile) { std::vector<AutofillProfile> profiles; - if (!MergeProfile(profile, profiles_.get(), "en-US", &profiles)) + std::string merged_guid = + MergeProfile(profile, profiles_.get(), "en-US", &profiles); + if (merged_guid == profile.guid()) profiles_.push_back(new AutofillProfile(profile)); + return merged_guid; } const std::vector<AutofillProfile*>& PersonalDataManagerMock::web_profiles() diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc index 22b1318..c12b2ff 100644 --- a/components/autofill/core/browser/autofill_metrics_unittest.cc +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc @@ -125,7 +125,7 @@ class TestPersonalDataManager : public PersonalDataManager { } MOCK_METHOD1(SaveImportedCreditCard, - void(const CreditCard& imported_credit_card)); + std::string(const CreditCard& imported_credit_card)); private: void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { @@ -319,8 +319,9 @@ scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( CreditCard credit_card; return AutofillCCInfoBarDelegate::Create( metric_logger, - base::Bind(&TestPersonalDataManager::SaveImportedCreditCard, - base::Unretained(personal_data_.get()), credit_card)); + base::Bind( + base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), + base::Unretained(personal_data_.get()), credit_card)); } // Test that we log quality metrics appropriately. diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc index 9ddff25..c3bd991 100644 --- a/components/autofill/core/browser/personal_data_manager.cc +++ b/components/autofill/core/browser/personal_data_manager.cc @@ -726,7 +726,7 @@ bool PersonalDataManager::IsValidLearnableProfile( } // static -bool PersonalDataManager::MergeProfile( +std::string PersonalDataManager::MergeProfile( const AutofillProfile& new_profile, const std::vector<AutofillProfile*>& existing_profiles, const std::string& app_locale, @@ -735,6 +735,7 @@ bool PersonalDataManager::MergeProfile( // Set to true if |existing_profiles| already contains an equivalent profile. bool matching_profile_found = false; + std::string guid = new_profile.guid(); // If we have already saved this address, merge in any missing values. // Only merge with the first match. @@ -751,6 +752,7 @@ bool PersonalDataManager::MergeProfile( // data. If an automatically aggregated profile would overwrite a // verified profile, just drop it. matching_profile_found = true; + guid = existing_profile->guid(); if (!existing_profile->IsVerified() || new_profile.IsVerified()) existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); } @@ -761,7 +763,7 @@ bool PersonalDataManager::MergeProfile( if (!matching_profile_found) merged_profiles->push_back(new_profile); - return matching_profile_found; + return guid; } void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { @@ -962,10 +964,10 @@ void PersonalDataManager::CancelPendingQuery( *handle = 0; } -void PersonalDataManager::SaveImportedProfile( +std::string PersonalDataManager::SaveImportedProfile( const AutofillProfile& imported_profile) { if (browser_context_->IsOffTheRecord()) - return; + return std::string(); // Don't save a web profile if the data in the profile is a subset of an // auxiliary profile. @@ -973,32 +975,39 @@ void PersonalDataManager::SaveImportedProfile( auxiliary_profiles_.begin(); iter != auxiliary_profiles_.end(); ++iter) { if (imported_profile.IsSubsetOf(**iter, app_locale_)) - return; + return (*iter)->guid(); } std::vector<AutofillProfile> profiles; - MergeProfile(imported_profile, web_profiles_.get(), app_locale_, &profiles); + std::string guid = + MergeProfile(imported_profile, web_profiles_.get(), app_locale_, + &profiles); SetProfiles(&profiles); + return guid; } -void PersonalDataManager::SaveImportedCreditCard( +std::string PersonalDataManager::SaveImportedCreditCard( const CreditCard& imported_card) { DCHECK(!imported_card.number().empty()); if (browser_context_->IsOffTheRecord()) - return; + return std::string(); // Set to true if |imported_card| is merged into the credit card list. bool merged = false; + std::string guid = imported_card.guid(); std::vector<CreditCard> credit_cards; for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin(); card != credit_cards_.end(); ++card) { // If |imported_card| has not yet been merged, check whether it should be // with the current |card|. - if (!merged && (*card)->UpdateFromImportedCard(imported_card, app_locale_)) + if (!merged && + (*card)->UpdateFromImportedCard(imported_card, app_locale_)) { + guid = (*card)->guid(); merged = true; + } credit_cards.push_back(**card); } @@ -1007,6 +1016,7 @@ void PersonalDataManager::SaveImportedCreditCard( credit_cards.push_back(imported_card); SetCreditCards(&credit_cards); + return guid; } void PersonalDataManager::LogProfileCount() const { diff --git a/components/autofill/core/browser/personal_data_manager.h b/components/autofill/core/browser/personal_data_manager.h index 9b71aa55..d5dc85e 100644 --- a/components/autofill/core/browser/personal_data_manager.h +++ b/components/autofill/core/browser/personal_data_manager.h @@ -79,11 +79,15 @@ class PersonalDataManager : public WebDataServiceConsumer, bool ImportFormData(const FormStructure& form, const CreditCard** credit_card); - // Saves |imported_profile| to the WebDB if it exists. - virtual void SaveImportedProfile(const AutofillProfile& imported_profile); + // Saves |imported_profile| to the WebDB if it exists. Returns the guid of + // the new or updated profile, or the empty string if no profile was saved. + virtual std::string SaveImportedProfile( + const AutofillProfile& imported_profile); - // Saves a credit card value detected in |ImportedFormData|. - virtual void SaveImportedCreditCard(const CreditCard& imported_credit_card); + // Saves a credit card value detected in |ImportedFormData|. Returns the guid + // of the new or updated card, or the empty string if no card was saved. + virtual std::string SaveImportedCreditCard( + const CreditCard& imported_credit_card); // Adds |profile| to the web database. void AddProfile(const AutofillProfile& profile); @@ -169,8 +173,9 @@ class PersonalDataManager : public WebDataServiceConsumer, // Merges |new_profile| into one of the |existing_profiles| if possible; // otherwise appends |new_profile| to the end of that list. Fills - // |merged_profiles| with the result. - static bool MergeProfile( + // |merged_profiles| with the result. Returns the |guid| of the new or updated + // profile. + static std::string MergeProfile( const AutofillProfile& new_profile, const std::vector<AutofillProfile*>& existing_profiles, const std::string& app_locale, diff --git a/components/autofill/core/browser/test_personal_data_manager.cc b/components/autofill/core/browser/test_personal_data_manager.cc index 0a517d7..7ce487b 100644 --- a/components/autofill/core/browser/test_personal_data_manager.cc +++ b/components/autofill/core/browser/test_personal_data_manager.cc @@ -34,9 +34,16 @@ const std::vector<CreditCard*>& TestPersonalDataManager:: return credit_cards_; } -void TestPersonalDataManager::SaveImportedProfile( +std::string TestPersonalDataManager::SaveImportedProfile( const AutofillProfile& imported_profile) { imported_profile_ = imported_profile; + return imported_profile.guid(); +} + +std::string TestPersonalDataManager::SaveImportedCreditCard( + const CreditCard& imported_credit_card) { + imported_credit_card_ = imported_credit_card; + return imported_credit_card.guid(); } } // namespace autofill diff --git a/components/autofill/core/browser/test_personal_data_manager.h b/components/autofill/core/browser/test_personal_data_manager.h index c9f9a43..9d6767a 100644 --- a/components/autofill/core/browser/test_personal_data_manager.h +++ b/components/autofill/core/browser/test_personal_data_manager.h @@ -27,16 +27,21 @@ class TestPersonalDataManager : public PersonalDataManager { void AddTestingCreditCard(CreditCard* credit_card); virtual const std::vector<AutofillProfile*>& GetProfiles() OVERRIDE; - virtual void SaveImportedProfile(const AutofillProfile& imported_profile) - OVERRIDE; + virtual const std::vector<CreditCard*>& GetCreditCards() const OVERRIDE; + + virtual std::string SaveImportedProfile( + const AutofillProfile& imported_profile) OVERRIDE; + virtual std::string SaveImportedCreditCard( + const CreditCard& imported_credit_card) OVERRIDE; const AutofillProfile& imported_profile() { return imported_profile_; } - virtual const std::vector<CreditCard*>& GetCreditCards() const OVERRIDE; + const CreditCard& imported_credit_card() { return imported_credit_card_; } private: std::vector<AutofillProfile*> profiles_; std::vector<CreditCard*> credit_cards_; AutofillProfile imported_profile_; + CreditCard imported_credit_card_; }; } // namespace autofill diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc index 9066d9c..1f61bb3 100644 --- a/components/autofill/core/browser/webdata/autofill_table.cc +++ b/components/autofill/core/browser/webdata/autofill_table.cc @@ -2095,7 +2095,7 @@ bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) { std::vector<AutofillProfile> merged_profiles; - bool merged = PersonalDataManager::MergeProfile( + std::string merged_guid = PersonalDataManager::MergeProfile( *profile, accumulated_profiles_p, app_locale_, &merged_profiles); std::swap(accumulated_profiles, merged_profiles); @@ -2108,9 +2108,8 @@ bool AutofillTable::MigrateToVersion37MergeAndCullOlderProfiles() { address_of<AutofillProfile>); // If the profile got merged trash the original. - if (merged) + if (merged_guid != profile->guid()) AddAutofillGUIDToTrash(profile->guid()); - } else { // An invalid profile, so trash it. AddAutofillGUIDToTrash(profile->guid()); |