| Index: chrome/browser/autofill/autofill_manager_unittest.cc
|
| diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
|
| index b4541432843268906f37f62fff19f16fe656a6c2..5014dee7dfb2b14f1bbb1e8865ac5e9eb064068c 100644
|
| --- a/chrome/browser/autofill/autofill_manager_unittest.cc
|
| +++ b/chrome/browser/autofill/autofill_manager_unittest.cc
|
| @@ -181,12 +181,20 @@ void CreateTestAddressFormData(FormData* form) {
|
| autofill_test::CreateTestFormField(
|
| "Email", "email", "", "text", &field);
|
| form->fields.push_back(field);
|
| -}
|
| + autofill_test::CreateTestFormField(
|
| + "Email", "email2", "", "email", &field);
|
| + form->fields.push_back(field);
|
| + autofill_test::CreateTestFormField(
|
| + "Phone Number", "phonenumber2", "", "tel", &field);
|
| + form->fields.push_back(field);
|
| + }
|
|
|
| // Populates |form| with data corresponding to a simple credit card form.
|
| // Note that this actually appends fields to the form data, which can be useful
|
| // for building up more complex test forms.
|
| -void CreateTestCreditCardFormData(FormData* form, bool is_https) {
|
| +void CreateTestCreditCardFormData(FormData* form,
|
| + bool is_https,
|
| + bool use_month_type) {
|
| form->name = ASCIIToUTF16("MyForm");
|
| form->method = ASCIIToUTF16("POST");
|
| if (is_https) {
|
| @@ -205,12 +213,18 @@ void CreateTestCreditCardFormData(FormData* form, bool is_https) {
|
| autofill_test::CreateTestFormField(
|
| "Card Number", "cardnumber", "", "text", &field);
|
| form->fields.push_back(field);
|
| - autofill_test::CreateTestFormField(
|
| - "Expiration Date", "ccmonth", "", "text", &field);
|
| - form->fields.push_back(field);
|
| - autofill_test::CreateTestFormField(
|
| - "", "ccyear", "", "text", &field);
|
| - form->fields.push_back(field);
|
| + if (use_month_type) {
|
| + autofill_test::CreateTestFormField(
|
| + "Expiration Date", "ccmonth", "", "month", &field);
|
| + form->fields.push_back(field);
|
| + } else {
|
| + autofill_test::CreateTestFormField(
|
| + "Expiration Date", "ccmonth", "", "text", &field);
|
| + form->fields.push_back(field);
|
| + autofill_test::CreateTestFormField(
|
| + "", "ccyear", "", "text", &field);
|
| + form->fields.push_back(field);
|
| + }
|
| }
|
|
|
| void ExpectSuggestions(int page_id,
|
| @@ -241,7 +255,7 @@ void ExpectSuggestions(int page_id,
|
| // Verifies that the |filled_form| has been filled with the given data.
|
| // Verifies address fields if |has_address_fields| is true, and verifies
|
| // credit card fields if |has_credit_card_fields| is true. Verifies both if both
|
| -// are true.
|
| +// are true. |use_month_type| is used for credit card input month type.
|
| void ExpectFilledForm(int page_id,
|
| const FormData& filled_form,
|
| int expected_page_id,
|
| @@ -262,10 +276,11 @@ void ExpectFilledForm(int page_id,
|
| const char* expiration_month,
|
| const char* expiration_year,
|
| bool has_address_fields,
|
| - bool has_credit_card_fields) {
|
| + bool has_credit_card_fields,
|
| + int use_month_type) {
|
| // The number of fields in the address and credit card forms created above.
|
| - const size_t kAddressFormSize = 12;
|
| - const size_t kCreditCardFormSize = 4;
|
| + const size_t kAddressFormSize = 14;
|
| + const size_t kCreditCardFormSize = use_month_type ? 3 : 4;
|
|
|
| EXPECT_EQ(expected_page_id, page_id);
|
| EXPECT_EQ(ASCIIToUTF16("MyForm"), filled_form.name);
|
| @@ -324,7 +339,13 @@ void ExpectFilledForm(int page_id,
|
| autofill_test::CreateTestFormField(
|
| "Email", "email", email, "text", &field);
|
| EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11]));
|
| - }
|
| + autofill_test::CreateTestFormField(
|
| + "Email", "email2", email, "email", &field);
|
| + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[12]));
|
| + autofill_test::CreateTestFormField(
|
| + "Phone Number", "phonenumber2", phone, "tel", &field);
|
| + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[13]));
|
| + }
|
|
|
| if (has_credit_card_fields) {
|
| size_t offset = has_address_fields? kAddressFormSize : 0;
|
| @@ -334,12 +355,19 @@ void ExpectFilledForm(int page_id,
|
| autofill_test::CreateTestFormField(
|
| "Card Number", "cardnumber", card_number, "text", &field);
|
| EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1]));
|
| - autofill_test::CreateTestFormField(
|
| - "Expiration Date", "ccmonth", expiration_month, "text", &field);
|
| - EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
|
| - autofill_test::CreateTestFormField(
|
| - "", "ccyear", expiration_year, "text", &field);
|
| - EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3]));
|
| + if (use_month_type) {
|
| + autofill_test::CreateTestFormField("Expiration Date", "ccmonth",
|
| + (expiration_year + std::string("-") + expiration_month).c_str(),
|
| + "month", &field);
|
| + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
|
| + } else {
|
| + autofill_test::CreateTestFormField(
|
| + "Expiration Date", "ccmonth", expiration_month, "text", &field);
|
| + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2]));
|
| + autofill_test::CreateTestFormField(
|
| + "", "ccyear", expiration_year, "text", &field);
|
| + EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3]));
|
| + }
|
| }
|
| }
|
|
|
| @@ -351,17 +379,18 @@ void ExpectFilledAddressFormElvis(int page_id,
|
| "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis",
|
| "Tennessee", "38116", "USA", "12345678901", "",
|
| "theking@gmail.com", "", "", "", "", true,
|
| - has_credit_card_fields);
|
| + has_credit_card_fields, false);
|
| }
|
|
|
| void ExpectFilledCreditCardFormElvis(int page_id,
|
| const FormData& filled_form,
|
| int expected_page_id,
|
| - bool has_address_fields) {
|
| + bool has_address_fields,
|
| + bool use_month_type) {
|
| ExpectFilledForm(page_id, filled_form, expected_page_id,
|
| "", "", "", "", "", "", "", "", "", "", "", "",
|
| "Elvis Presley", "4234567890123456", "04", "2012",
|
| - has_address_fields, true);
|
| + has_address_fields, true, use_month_type);
|
| }
|
|
|
| class TestAutoFillManager : public AutoFillManager {
|
| @@ -733,7 +762,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
|
| TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
|
| // Set up our form data.
|
| FormData form;
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -777,7 +806,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
|
| TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
|
| // Set up our form data.
|
| FormData form;
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -814,7 +843,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
|
| TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
|
| // Set up our form data.
|
| FormData form;
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -858,7 +887,7 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
|
| TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
|
| // Set up our form data.
|
| FormData form;
|
| - CreateTestCreditCardFormData(&form, false);
|
| + CreateTestCreditCardFormData(&form, false, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -925,7 +954,7 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
|
| // Set up our form data.
|
| FormData form;
|
| CreateTestAddressFormData(&form);
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -1002,7 +1031,7 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
|
| // Set up our form data.
|
| FormData form;
|
| CreateTestAddressFormData(&form);
|
| - CreateTestCreditCardFormData(&form, false);
|
| + CreateTestCreditCardFormData(&form, false, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -1268,7 +1297,27 @@ TEST_F(AutoFillManagerTest, FillAddressForm) {
|
| TEST_F(AutoFillManagerTest, FillCreditCardForm) {
|
| // Set up our form data.
|
| FormData form;
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| + std::vector<FormData> forms(1, form);
|
| + autofill_manager_->FormsSeen(forms);
|
| +
|
| + std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
|
| + EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
|
| + kDefaultPageID, form, *form.fields.begin(),
|
| + autofill_manager_->PackGUIDs(guid, std::string())));
|
| +
|
| + int page_id = 0;
|
| + FormData results;
|
| + EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
|
| + ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false,
|
| + false);
|
| +}
|
| +
|
| +// Test that we correctly fill a credit card form with month input type.
|
| +TEST_F(AutoFillManagerTest, FillCreditCardFormWithMonthInput) {
|
| + // Set up our form data.
|
| + FormData form;
|
| + CreateTestCreditCardFormData(&form, true, true);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -1280,7 +1329,8 @@ TEST_F(AutoFillManagerTest, FillCreditCardForm) {
|
| int page_id = 0;
|
| FormData results;
|
| EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
|
| - ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false);
|
| + ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false,
|
| + true);
|
| }
|
|
|
| // Test that we correctly fill a combined address and credit card form.
|
| @@ -1288,7 +1338,7 @@ TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
|
| // Set up our form data.
|
| FormData form;
|
| CreateTestAddressFormData(&form);
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -1318,7 +1368,7 @@ TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
|
| EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
|
| {
|
| SCOPED_TRACE("Credit card");
|
| - ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true);
|
| + ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true, false);
|
| }
|
| }
|
|
|
| @@ -1329,7 +1379,7 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
|
| CreateTestAddressFormData(&form);
|
| // Mark one of the address fields as autofilled.
|
| form.fields[4].set_autofilled(true);
|
| - CreateTestCreditCardFormData(&form, true);
|
| + CreateTestCreditCardFormData(&form, true, false);
|
| std::vector<FormData> forms(1, form);
|
| autofill_manager_->FormsSeen(forms);
|
|
|
| @@ -1346,7 +1396,7 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
|
| SCOPED_TRACE("Address");
|
| ExpectFilledForm(page_id, results, kDefaultPageID,
|
| "Elvis", "", "", "", "", "", "", "", "", "", "", "",
|
| - "", "", "", "", true, true);
|
| + "", "", "", "", true, true, false);
|
| }
|
|
|
| // Now fill the credit card data.
|
| @@ -1361,7 +1411,7 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
|
| EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
|
| {
|
| SCOPED_TRACE("Credit card 1");
|
| - ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true);
|
| + ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true, false);
|
| }
|
|
|
| // Now set the credit card fields to also be auto-filled, and try again to
|
| @@ -1384,7 +1434,7 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
|
| SCOPED_TRACE("Credit card 2");
|
| ExpectFilledForm(page_id, results, kPageID3,
|
| "", "", "", "", "", "", "", "", "", "", "", "",
|
| - "", "", "", "2012", true, true);
|
| + "", "", "", "2012", true, true, false);
|
| }
|
| }
|
|
|
|
|