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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 server_credit_card->set_modification_date(base::Time::Now()); 230 server_credit_card->set_modification_date(base::Time::Now());
231 server_credit_cards_.push_back(std::move(server_credit_card)); 231 server_credit_cards_.push_back(std::move(server_credit_card));
232 } 232 }
233 233
234 // Create Elvis card with whitespace in the credit card number. 234 // Create Elvis card with whitespace in the credit card number.
235 void CreateTestCreditCardWithWhitespace() { 235 void CreateTestCreditCardWithWhitespace() {
236 ClearCreditCards(); 236 ClearCreditCards();
237 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 237 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
238 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 238 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
239 "4234 5678 9012 3456", // Visa 239 "4234 5678 9012 3456", // Visa
240 "04", "2999"); 240 "04", "2999", "1");
241 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); 241 credit_card->set_guid("00000000-0000-0000-0000-000000000008");
242 local_credit_cards_.push_back(std::move(credit_card)); 242 local_credit_cards_.push_back(std::move(credit_card));
243 } 243 }
244 244
245 // Create Elvis card with separator characters in the credit card number. 245 // Create Elvis card with separator characters in the credit card number.
246 void CreateTestCreditCardWithSeparators() { 246 void CreateTestCreditCardWithSeparators() {
247 ClearCreditCards(); 247 ClearCreditCards();
248 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 248 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
249 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 249 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
250 "4234-5678-9012-3456", // Visa 250 "4234-5678-9012-3456", // Visa
251 "04", "2999"); 251 "04", "2999", "1");
252 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); 252 credit_card->set_guid("00000000-0000-0000-0000-000000000009");
253 local_credit_cards_.push_back(std::move(credit_card)); 253 local_credit_cards_.push_back(std::move(credit_card));
254 } 254 }
255 255
256 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { 256 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) {
257 ClearCreditCards(); 257 ClearCreditCards();
258 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 258 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
259 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune", 259 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune",
260 "4234567890654321", // Visa 260 "4234567890654321", // Visa
261 month, year); 261 month, year, "1");
262 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 262 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
263 local_credit_cards_.push_back(std::move(credit_card)); 263 local_credit_cards_.push_back(std::move(credit_card));
264 } 264 }
265 265
266 void CreateTestExpiredCreditCard() { 266 void CreateTestExpiredCreditCard() {
267 ClearCreditCards(); 267 ClearCreditCards();
268 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 268 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
269 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson", 269 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson",
270 "4234567890654321", // Visa 270 "4234567890654321", // Visa
271 "05", "2000"); 271 "05", "2000", "1");
272 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); 272 credit_card->set_guid("00000000-0000-0000-0000-000000000009");
273 local_credit_cards_.push_back(std::move(credit_card)); 273 local_credit_cards_.push_back(std::move(credit_card));
274 } 274 }
275 275
276 private: 276 private:
277 void CreateTestAutofillProfiles( 277 void CreateTestAutofillProfiles(
278 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { 278 std::vector<std::unique_ptr<AutofillProfile>>* profiles) {
279 std::unique_ptr<AutofillProfile> profile = 279 std::unique_ptr<AutofillProfile> profile =
280 base::MakeUnique<AutofillProfile>(); 280 base::MakeUnique<AutofillProfile>();
281 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", 281 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley",
(...skipping 13 matching lines...) Expand all
295 "", ""); 295 "", "");
296 profile->set_guid("00000000-0000-0000-0000-000000000003"); 296 profile->set_guid("00000000-0000-0000-0000-000000000003");
297 profiles->push_back(std::move(profile)); 297 profiles->push_back(std::move(profile));
298 } 298 }
299 299
300 void CreateTestCreditCards( 300 void CreateTestCreditCards(
301 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { 301 std::vector<std::unique_ptr<CreditCard>>* credit_cards) {
302 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 302 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
303 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 303 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
304 "4234567890123456", // Visa 304 "4234567890123456", // Visa
305 "04", "2999"); 305 "04", "2999", "1");
306 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); 306 credit_card->set_guid("00000000-0000-0000-0000-000000000004");
307 credit_card->set_use_count(10); 307 credit_card->set_use_count(10);
308 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 308 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
309 credit_cards->push_back(std::move(credit_card)); 309 credit_cards->push_back(std::move(credit_card));
310 310
311 credit_card = base::MakeUnique<CreditCard>(); 311 credit_card = base::MakeUnique<CreditCard>();
312 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", 312 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly",
313 "5187654321098765", // Mastercard 313 "5187654321098765", // Mastercard
314 "10", "2998"); 314 "10", "2998", "1");
315 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); 315 credit_card->set_guid("00000000-0000-0000-0000-000000000005");
316 credit_card->set_use_count(5); 316 credit_card->set_use_count(5);
317 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); 317 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4));
318 credit_cards->push_back(std::move(credit_card)); 318 credit_cards->push_back(std::move(credit_card));
319 319
320 credit_card = base::MakeUnique<CreditCard>(); 320 credit_card = base::MakeUnique<CreditCard>();
321 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); 321 test::SetCreditCardInfo(credit_card.get(), "", "", "", "", "");
322 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); 322 credit_card->set_guid("00000000-0000-0000-0000-000000000006");
323 credit_cards->push_back(std::move(credit_card)); 323 credit_cards->push_back(std::move(credit_card));
324 } 324 }
325 325
326 size_t num_times_save_imported_profile_called_; 326 size_t num_times_save_imported_profile_called_;
327 327
328 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 328 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
329 }; 329 };
330 330
331 class TestAutofillDownloadManager : public AutofillDownloadManager { 331 class TestAutofillDownloadManager : public AutofillDownloadManager {
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { 1025 void PrepareForRealPanResponse(FormData* form, CreditCard* card) {
1026 // This line silences the warning from PaymentsClient about matching sync 1026 // This line silences the warning from PaymentsClient about matching sync
1027 // and Payments server types. 1027 // and Payments server types.
1028 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1028 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1029 "sync-url", "https://google.com"); 1029 "sync-url", "https://google.com");
1030 1030
1031 CreateTestCreditCardFormData(form, true, false); 1031 CreateTestCreditCardFormData(form, true, false);
1032 FormsSeen(std::vector<FormData>(1, *form)); 1032 FormsSeen(std::vector<FormData>(1, *form));
1033 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); 1033 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123");
1034 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", 1034 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01",
1035 "2017"); 1035 "2017", "1");
1036 card->SetNetworkForMaskedCard(kVisaCard); 1036 card->SetNetworkForMaskedCard(kVisaCard);
1037 1037
1038 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) 1038 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _))
1039 .Times(AtLeast(1)); 1039 .Times(AtLeast(1));
1040 autofill_manager_->FillOrPreviewCreditCardForm( 1040 autofill_manager_->FillOrPreviewCreditCardForm(
1041 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, 1041 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form,
1042 form->fields[0], *card); 1042 form->fields[0], *card);
1043 } 1043 }
1044 1044
1045 // Convenience method for using and retrieving a mock autocomplete history 1045 // Convenience method for using and retrieving a mock autocomplete history
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 autofill_manager_->GetPackedCreditCardID(5))); 1659 autofill_manager_->GetPackedCreditCardID(5)));
1660 } 1660 }
1661 1661
1662 // Test that we return all credit card profile suggestions when the triggering 1662 // Test that we return all credit card profile suggestions when the triggering
1663 // field has stop characters in it and some input. 1663 // field has stop characters in it and some input.
1664 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { 1664 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) {
1665 // Add a credit card with particular numbers that we will attempt to recall. 1665 // Add a credit card with particular numbers that we will attempt to recall.
1666 CreditCard credit_card; 1666 CreditCard credit_card;
1667 test::SetCreditCardInfo(&credit_card, "John Smith", 1667 test::SetCreditCardInfo(&credit_card, "John Smith",
1668 "5255667890123123", // Mastercard 1668 "5255667890123123", // Mastercard
1669 "08", "2017"); 1669 "08", "2017", "1");
1670 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); 1670 credit_card.set_guid("00000000-0000-0000-0000-000000000007");
1671 autofill_manager_->AddCreditCard(credit_card); 1671 autofill_manager_->AddCreditCard(credit_card);
1672 1672
1673 // Set up our form data. 1673 // Set up our form data.
1674 FormData form; 1674 FormData form;
1675 CreateTestCreditCardFormData(&form, true, false); 1675 CreateTestCreditCardFormData(&form, true, false);
1676 std::vector<FormData> forms(1, form); 1676 std::vector<FormData> forms(1, form);
1677 FormsSeen(forms); 1677 FormsSeen(forms);
1678 1678
1679 FormFieldData field = form.fields[1]; 1679 FormFieldData field = form.fields[1];
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 } 1943 }
1944 1944
1945 // Test that we return all credit card suggestions in the case that two cards 1945 // Test that we return all credit card suggestions in the case that two cards
1946 // have the same obfuscated number. 1946 // have the same obfuscated number.
1947 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { 1947 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) {
1948 // Add a credit card with the same obfuscated number as Elvis's. 1948 // Add a credit card with the same obfuscated number as Elvis's.
1949 // |credit_card| will be owned by the mock PersonalDataManager. 1949 // |credit_card| will be owned by the mock PersonalDataManager.
1950 CreditCard credit_card; 1950 CreditCard credit_card;
1951 test::SetCreditCardInfo(&credit_card, "Elvis Presley", 1951 test::SetCreditCardInfo(&credit_card, "Elvis Presley",
1952 "5231567890123456", // Mastercard 1952 "5231567890123456", // Mastercard
1953 "05", "2999"); 1953 "05", "2999", "1");
1954 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); 1954 credit_card.set_guid("00000000-0000-0000-0000-000000000007");
1955 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); 1955 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
1956 autofill_manager_->AddCreditCard(credit_card); 1956 autofill_manager_->AddCreditCard(credit_card);
1957 1957
1958 // Set up our form data. 1958 // Set up our form data.
1959 FormData form; 1959 FormData form;
1960 CreateTestCreditCardFormData(&form, true, false); 1960 CreateTestCreditCardFormData(&form, true, false);
1961 std::vector<FormData> forms(1, form); 1961 std::vector<FormData> forms(1, form);
1962 FormsSeen(forms); 1962 FormsSeen(forms);
1963 1963
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
3895 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", 3895 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare",
3896 "Apt. 10", "Paris", "Île de France", "75008", "FR", 3896 "Apt. 10", "Paris", "Île de France", "75008", "FR",
3897 "+33 2 49 19 70 70"); 3897 "+33 2 49 19 70 70");
3898 profile.set_guid("00000000-0000-0000-0000-000000000001"); 3898 profile.set_guid("00000000-0000-0000-0000-000000000001");
3899 profiles.push_back(profile); 3899 profiles.push_back(profile);
3900 3900
3901 // Set up the test credit cards. 3901 // Set up the test credit cards.
3902 std::vector<CreditCard> credit_cards; 3902 std::vector<CreditCard> credit_cards;
3903 CreditCard credit_card; 3903 CreditCard credit_card;
3904 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", 3904 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04",
3905 "2999"); 3905 "2999", "1");
3906 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 3906 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
3907 credit_cards.push_back(credit_card); 3907 credit_cards.push_back(credit_card);
3908 3908
3909 typedef struct { 3909 typedef struct {
3910 std::string input_value; // The value to input in the field. 3910 std::string input_value; // The value to input in the field.
3911 ServerFieldType field_type; // The expected field type to be determined. 3911 ServerFieldType field_type; // The expected field type to be determined.
3912 } TestCase; 3912 } TestCase;
3913 3913
3914 TestCase test_cases[] = { 3914 TestCase test_cases[] = {
3915 // Profile fields matches. 3915 // Profile fields matches.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", 4082 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.",
4083 "", "Memphis", "Tennessee", "38116", "US", 4083 "", "Memphis", "Tennessee", "38116", "US",
4084 "(234) 567-8901"); 4084 "(234) 567-8901");
4085 profile.set_guid("00000000-0000-0000-0000-000000000001"); 4085 profile.set_guid("00000000-0000-0000-0000-000000000001");
4086 profiles.push_back(profile); 4086 profiles.push_back(profile);
4087 4087
4088 // Set up the test credit card. 4088 // Set up the test credit card.
4089 std::vector<CreditCard> credit_cards; 4089 std::vector<CreditCard> credit_cards;
4090 CreditCard credit_card; 4090 CreditCard credit_card;
4091 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", 4091 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456",
4092 "04", "2999"); 4092 "04", "2999", "1");
4093 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 4093 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
4094 credit_cards.push_back(credit_card); 4094 credit_cards.push_back(credit_card);
4095 4095
4096 typedef struct { 4096 typedef struct {
4097 std::string input_value; 4097 std::string input_value;
4098 ServerFieldType predicted_type; 4098 ServerFieldType predicted_type;
4099 bool expect_disambiguation; 4099 bool expect_disambiguation;
4100 ServerFieldType expected_upload_type; 4100 ServerFieldType expected_upload_type;
4101 } TestFieldData; 4101 } TestFieldData;
4102 4102
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after
5631 // profile which can be selected for the upload request. 5631 // profile which can be selected for the upload request.
5632 FormData address_form; 5632 FormData address_form;
5633 test::CreateTestAddressFormData(&address_form); 5633 test::CreateTestAddressFormData(&address_form);
5634 FormsSeen(std::vector<FormData>(1, address_form)); 5634 FormsSeen(std::vector<FormData>(1, address_form));
5635 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); 5635 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
5636 FormSubmitted(address_form); 5636 FormSubmitted(address_form);
5637 5637
5638 // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will 5638 // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will
5639 // below. 5639 // below.
5640 CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123"); 5640 CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123");
5641 test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017"); 5641 test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017",
5642 "1");
5642 credit_card.SetNetworkForMaskedCard(kVisaCard); 5643 credit_card.SetNetworkForMaskedCard(kVisaCard);
5643 personal_data_.AddServerCreditCard(credit_card); 5644 personal_data_.AddServerCreditCard(credit_card);
5644 5645
5645 // Set up our credit card form data. 5646 // Set up our credit card form data.
5646 FormData credit_card_form; 5647 FormData credit_card_form;
5647 CreateTestCreditCardFormData(&credit_card_form, true, false); 5648 CreateTestCreditCardFormData(&credit_card_form, true, false);
5648 FormsSeen(std::vector<FormData>(1, credit_card_form)); 5649 FormsSeen(std::vector<FormData>(1, credit_card_form));
5649 5650
5650 // Edit the data, and submit. 5651 // Edit the data, and submit.
5651 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); 5652 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
6269 6270
6270 // Wait for upload to complete (will check expected types as well). 6271 // Wait for upload to complete (will check expected types as well).
6271 autofill_manager_->WaitForAsyncUploadProcess(); 6272 autofill_manager_->WaitForAsyncUploadProcess();
6272 6273
6273 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); 6274 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature());
6274 EXPECT_NE(uploaded_available_types.end(), 6275 EXPECT_NE(uploaded_available_types.end(),
6275 uploaded_available_types.find(autofill::PASSWORD)); 6276 uploaded_available_types.find(autofill::PASSWORD));
6276 } 6277 }
6277 6278
6278 } // namespace autofill 6279 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698