diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 08:26:12 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 08:26:12 +0000 |
commit | 29886f2b400761609b11c892a061dd813c9a77a7 (patch) | |
tree | 660f23b6c1bdd65bd23ae9c0a411073ee13d1c7c | |
parent | b3123ce43d0753023d44a56ee392d817ca5e1194 (diff) | |
download | chromium_src-29886f2b400761609b11c892a061dd813c9a77a7.zip chromium_src-29886f2b400761609b11c892a061dd813c9a77a7.tar.gz chromium_src-29886f2b400761609b11c892a061dd813c9a77a7.tar.bz2 |
Don't try to de-dup Autofill credit card suggestions.
We only have the obfuscated number to go on when de-duping credit card suggestions, which can lead to false-duplicates being removed. To be safe, just avoid de-duping credit cards -- there's not much pragmatic reason to do so anyway.
BUG=78500
TEST=unit_tests --gtest_filter=AutofillManagerTest.GetCreditCardSuggestionsRepeatedObfuscatedNumber
Review URL: http://codereview.chromium.org/6814010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80908 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 7 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 67 |
2 files changed, 73 insertions, 1 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index c7424c8..64447b6 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -392,7 +392,12 @@ void AutofillManager::OnQueryFormFieldAutofill( icons.assign(icons.size(), string16()); } - RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); + // When filling credit card suggestions, the values and labels are + // typically obfuscated, which makes detecting duplicates hard. Since + // duplicates only tend to be a problem when filling address forms + // anyway, only don't de-dup credit card suggestions. + if (!is_filling_credit_card) + RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); // The first time we show suggestions on this page, log the number of // suggestions shown. diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index 3850e3e..04c5cc8 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -73,6 +73,10 @@ class TestPersonalDataManager : public PersonalDataManager { web_profiles_->push_back(profile); } + void AddCreditCard(CreditCard* credit_card) { + credit_cards_->push_back(credit_card); + } + void ClearAutofillProfiles() { web_profiles_.reset(); } @@ -425,6 +429,10 @@ class TestAutofillManager : public AutofillManager { test_personal_data_->AddProfile(profile); } + void AddCreditCard(CreditCard* credit_card) { + test_personal_data_->AddCreditCard(credit_card); + } + int GetPackedCreditCardID(int credit_card_id) { return PackGUIDs(IDToGUID(credit_card_id), std::string()); } @@ -982,6 +990,65 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonHTTPS) { EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); } +// Test that we return all credit card suggestions in the case that two cards +// have the same obfuscated number. +TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { + // Add a credit card with the same obfuscated number as Elvis's. + // |credit_card| will be owned by the mock PersonalDataManager. + CreditCard* credit_card = new CreditCard; + autofill_test::SetCreditCardInfo(credit_card, "Elvis Presley", + "5231567890123456", // Mastercard + "04", "2012"); + credit_card->set_guid("00000000-0000-0000-0000-000000000007"); + autofill_manager_->AddCreditCard(credit_card); + + // Set up our form data. + FormData form; + CreateTestCreditCardFormData(&form, true, false); + std::vector<FormData> forms(1, form); + FormsSeen(forms); + + FormField field = form.fields[1]; + GetAutofillSuggestions(form, field); + + // No suggestions provided, so send an empty vector as the results. + // This triggers the combined message send. + AutocompleteSuggestionsReturned(std::vector<string16>()); + + // Test that we sent the right message to the renderer. + int page_id = 0; + std::vector<string16> values; + std::vector<string16> labels; + std::vector<string16> icons; + std::vector<int> unique_ids; + EXPECT_TRUE(GetAutofillSuggestionsMessage(&page_id, &values, &labels, &icons, + &unique_ids)); + + string16 expected_values[] = { + ASCIIToUTF16("************3456"), + ASCIIToUTF16("************8765"), + ASCIIToUTF16("************3456") + }; + string16 expected_labels[] = { + ASCIIToUTF16("*3456"), + ASCIIToUTF16("*8765"), + ASCIIToUTF16("*3456"), + }; + string16 expected_icons[] = { + ASCIIToUTF16("visaCC"), + ASCIIToUTF16("genericCC"), + ASCIIToUTF16("masterCardCC") + }; + int expected_unique_ids[] = { + autofill_manager_->GetPackedCreditCardID(4), + autofill_manager_->GetPackedCreditCardID(5), + autofill_manager_->GetPackedCreditCardID(7) + }; + ExpectSuggestions(page_id, values, labels, icons, unique_ids, + kDefaultPageID, arraysize(expected_values), expected_values, + expected_labels, expected_icons, expected_unique_ids); +} + // Test that we return profile and credit card suggestions for combined forms. TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { // Set up our form data. |