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

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

Issue 1029233002: Autofill - don't prompt to unmask a credit card if the number isn't needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update histograms.xml Created 5 years, 9 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
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 9945243bcedd5ea18bc0dccf7f5c1f34c8d62df6..8778990ef781f579cee6028a5f533b66b8159ee0 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -711,6 +711,11 @@ class AutofillManagerTest : public testing::Test {
return autofill_manager_->MakeFrontendID(cc_sid, profile_sid);
}
+ bool WillFillCreditCardNumber(const FormData& form,
+ const FormFieldData& field) {
+ return autofill_manager_->WillFillCreditCardNumber(form, field);
+ }
+
protected:
base::MessageLoop message_loop_;
TestAutofillClient autofill_client_;
@@ -1472,6 +1477,41 @@ TEST_F(AutofillManagerTest, FillAddressForm) {
EXPECT_NE(base::Time(), profile->use_date());
}
+TEST_F(AutofillManagerTest, WillFillCreditCardNumber) {
+ // Set up our form data.
+ FormData form;
+ CreateTestCreditCardFormData(&form, true, false);
+ std::vector<FormData> forms(1, form);
+ FormsSeen(forms);
+
+ FormFieldData* number_field = nullptr;
+ FormFieldData* name_field = nullptr;
+ FormFieldData* month_field = nullptr;
+ for (size_t i = 0; i < form.fields.size(); ++i) {
+ if (form.fields[i].name == ASCIIToUTF16("cardnumber"))
+ number_field = &form.fields[i];
+ else if (form.fields[i].name == ASCIIToUTF16("nameoncard"))
+ name_field = &form.fields[i];
+ else if (form.fields[i].name == ASCIIToUTF16("ccmonth"))
+ month_field = &form.fields[i];
+ }
+
+ // Empty form - whole form is Autofilled.
+ EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
+ EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field));
+ // If the user has entered a value, it won't be overridden.
+ number_field->value = ASCIIToUTF16("gibberish");
+ EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
+ EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
+ number_field->value.clear();
+ EXPECT_TRUE(WillFillCreditCardNumber(form, *name_field));
+
+ // When part of the section is Autofilled, only fill the initiating field.
+ month_field->is_autofilled = true;
+ EXPECT_FALSE(WillFillCreditCardNumber(form, *name_field));
+ EXPECT_TRUE(WillFillCreditCardNumber(form, *number_field));
+}
+
// Test that we correctly fill an address form from an auxiliary profile.
TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) {
personal_data_.ClearAutofillProfiles();

Powered by Google App Engine
This is Rietveld 408576698