From 29886f2b400761609b11c892a061dd813c9a77a7 Mon Sep 17 00:00:00 2001 From: "isherman@chromium.org" Date: Fri, 8 Apr 2011 08:26:12 +0000 Subject: 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 --- chrome/browser/autofill/autofill_manager.cc | 7 ++- .../browser/autofill/autofill_manager_unittest.cc | 67 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) 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 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()); + + // Test that we sent the right message to the renderer. + int page_id = 0; + std::vector values; + std::vector labels; + std::vector icons; + std::vector 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. -- cgit v1.1