Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Unified Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 1627843002: [Autofill] Sanitize the credit card field value before matching against user data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stop chars Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/autofill_manager_unittest.cc
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index 7d3b09b7ffe81ff4418408ab7b86960d4895b8d2..cf5e3286ffb87f47591114c555bdc41cb3912442 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -1312,7 +1312,7 @@ TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
// Test that we return all credit card profile suggestions when all form fields
// are empty.
-TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) {
+TEST_F(AutofillManagerTest, GetCreditCardSuggestions_EmptyValue) {
// Set up our form data.
FormData form;
CreateTestCreditCardFormData(&form, true, false);
@@ -1335,6 +1335,86 @@ TEST_F(AutofillManagerTest, GetCreditCardSuggestionsEmptyValue) {
"10/14", kMasterCard, autofill_manager_->GetPackedCreditCardID(5)));
}
+// Test that we return all credit card profile suggestions when the triggering
+// field has whitespace in it.
+TEST_F(AutofillManagerTest, GetCreditCardSuggestions_Whitespace) {
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, true, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ FormFieldData field = form.fields[1];
+ field.value = ASCIIToUTF16(" ");
+ GetAutofillSuggestions(form, field);
+
+ // Test that we sent the right values to the external delegate.
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF"
+ "3456",
+ "04/12", kVisaCard,
+ autofill_manager_->GetPackedCreditCardID(4)),
+ Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF"
+ "8765",
+ "10/14", kMasterCard,
+ autofill_manager_->GetPackedCreditCardID(5)));
+}
+
+// Test that we return all credit card profile suggestions when the triggering
+// field has stop characters in it, which should be removed.
+TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsOnly) {
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, true, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ FormFieldData field = form.fields[1];
+ field.value = ASCIIToUTF16("____-____-____-____");
+ GetAutofillSuggestions(form, field);
+
+ // Test that we sent the right values to the external delegate.
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF"
+ "3456",
+ "04/12", kVisaCard,
+ autofill_manager_->GetPackedCreditCardID(4)),
+ Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF"
+ "8765",
+ "10/14", kMasterCard,
+ autofill_manager_->GetPackedCreditCardID(5)));
+}
+
+// Test that we return all credit card profile suggestions when the triggering
+// field has stop characters in it and some input.
+TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) {
+ // Add a credit card with particular numbers that we will attempt to recall.
+ CreditCard* credit_card = new CreditCard;
+ test::SetCreditCardInfo(credit_card, "John Smith",
+ "5255667890123123", // Mastercard
+ "08", "2017");
+ 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);
+
+ FormFieldData field = form.fields[1];
+
+ field.value = ASCIIToUTF16("5255-66__-____-____");
+ GetAutofillSuggestions(form, field);
+
+ // Test that we sent the right value to the external delegate.
+ external_delegate_->CheckSuggestions(
+ kDefaultPageID, Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF"
+ "3123",
+ "08/17", kMasterCard,
+ autofill_manager_->GetPackedCreditCardID(7)));
+}
+
// Test that we return only matching credit card profile suggestions when the
// selected form field has been partially filled out.
TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698