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

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: Merge branch 'master' into billing 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 server_credit_card->set_modification_date(base::Time::Now()); 234 server_credit_card->set_modification_date(base::Time::Now());
235 server_credit_cards_.push_back(std::move(server_credit_card)); 235 server_credit_cards_.push_back(std::move(server_credit_card));
236 } 236 }
237 237
238 // Create Elvis card with whitespace in the credit card number. 238 // Create Elvis card with whitespace in the credit card number.
239 void CreateTestCreditCardWithWhitespace() { 239 void CreateTestCreditCardWithWhitespace() {
240 ClearCreditCards(); 240 ClearCreditCards();
241 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 241 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
242 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 242 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
243 "4234 5678 9012 3456", // Visa 243 "4234 5678 9012 3456", // Visa
244 "04", "2999"); 244 "04", "2999", "1");
245 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); 245 credit_card->set_guid("00000000-0000-0000-0000-000000000008");
246 local_credit_cards_.push_back(std::move(credit_card)); 246 local_credit_cards_.push_back(std::move(credit_card));
247 } 247 }
248 248
249 // Create Elvis card with separator characters in the credit card number. 249 // Create Elvis card with separator characters in the credit card number.
250 void CreateTestCreditCardWithSeparators() { 250 void CreateTestCreditCardWithSeparators() {
251 ClearCreditCards(); 251 ClearCreditCards();
252 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 252 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
253 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 253 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
254 "4234-5678-9012-3456", // Visa 254 "4234-5678-9012-3456", // Visa
255 "04", "2999"); 255 "04", "2999", "1");
256 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); 256 credit_card->set_guid("00000000-0000-0000-0000-000000000009");
257 local_credit_cards_.push_back(std::move(credit_card)); 257 local_credit_cards_.push_back(std::move(credit_card));
258 } 258 }
259 259
260 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { 260 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) {
261 ClearCreditCards(); 261 ClearCreditCards();
262 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 262 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
263 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune", 263 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune",
264 "4234567890654321", // Visa 264 "4234567890654321", // Visa
265 month, year); 265 month, year, "1");
266 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 266 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
267 local_credit_cards_.push_back(std::move(credit_card)); 267 local_credit_cards_.push_back(std::move(credit_card));
268 } 268 }
269 269
270 void CreateTestExpiredCreditCard() { 270 void CreateTestExpiredCreditCard() {
271 ClearCreditCards(); 271 ClearCreditCards();
272 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 272 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
273 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson", 273 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson",
274 "4234567890654321", // Visa 274 "4234567890654321", // Visa
275 "05", "2000"); 275 "05", "2000", "1");
276 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); 276 credit_card->set_guid("00000000-0000-0000-0000-000000000009");
277 local_credit_cards_.push_back(std::move(credit_card)); 277 local_credit_cards_.push_back(std::move(credit_card));
278 } 278 }
279 279
280 private: 280 private:
281 void CreateTestAutofillProfiles( 281 void CreateTestAutofillProfiles(
282 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { 282 std::vector<std::unique_ptr<AutofillProfile>>* profiles) {
283 std::unique_ptr<AutofillProfile> profile = 283 std::unique_ptr<AutofillProfile> profile =
284 base::MakeUnique<AutofillProfile>(); 284 base::MakeUnique<AutofillProfile>();
285 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", 285 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley",
(...skipping 13 matching lines...) Expand all
299 "", ""); 299 "", "");
300 profile->set_guid("00000000-0000-0000-0000-000000000003"); 300 profile->set_guid("00000000-0000-0000-0000-000000000003");
301 profiles->push_back(std::move(profile)); 301 profiles->push_back(std::move(profile));
302 } 302 }
303 303
304 void CreateTestCreditCards( 304 void CreateTestCreditCards(
305 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { 305 std::vector<std::unique_ptr<CreditCard>>* credit_cards) {
306 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); 306 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>();
307 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", 307 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley",
308 "4234567890123456", // Visa 308 "4234567890123456", // Visa
309 "04", "2999"); 309 "04", "2999", "1");
310 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); 310 credit_card->set_guid("00000000-0000-0000-0000-000000000004");
311 credit_card->set_use_count(10); 311 credit_card->set_use_count(10);
312 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 312 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
313 credit_cards->push_back(std::move(credit_card)); 313 credit_cards->push_back(std::move(credit_card));
314 314
315 credit_card = base::MakeUnique<CreditCard>(); 315 credit_card = base::MakeUnique<CreditCard>();
316 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", 316 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly",
317 "5187654321098765", // Mastercard 317 "5187654321098765", // Mastercard
318 "10", "2998"); 318 "10", "2998", "1");
319 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); 319 credit_card->set_guid("00000000-0000-0000-0000-000000000005");
320 credit_card->set_use_count(5); 320 credit_card->set_use_count(5);
321 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); 321 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4));
322 credit_cards->push_back(std::move(credit_card)); 322 credit_cards->push_back(std::move(credit_card));
323 323
324 credit_card = base::MakeUnique<CreditCard>(); 324 credit_card = base::MakeUnique<CreditCard>();
325 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); 325 test::SetCreditCardInfo(credit_card.get(), "", "", "", "", "");
326 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); 326 credit_card->set_guid("00000000-0000-0000-0000-000000000006");
327 credit_cards->push_back(std::move(credit_card)); 327 credit_cards->push_back(std::move(credit_card));
328 } 328 }
329 329
330 size_t num_times_save_imported_profile_called_; 330 size_t num_times_save_imported_profile_called_;
331 331
332 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 332 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
333 }; 333 };
334 334
335 class TestAutofillDownloadManager : public AutofillDownloadManager { 335 class TestAutofillDownloadManager : public AutofillDownloadManager {
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { 1029 void PrepareForRealPanResponse(FormData* form, CreditCard* card) {
1030 // This line silences the warning from PaymentsClient about matching sync 1030 // This line silences the warning from PaymentsClient about matching sync
1031 // and Payments server types. 1031 // and Payments server types.
1032 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1032 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1033 "sync-url", "https://google.com"); 1033 "sync-url", "https://google.com");
1034 1034
1035 CreateTestCreditCardFormData(form, true, false); 1035 CreateTestCreditCardFormData(form, true, false);
1036 FormsSeen(std::vector<FormData>(1, *form)); 1036 FormsSeen(std::vector<FormData>(1, *form));
1037 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); 1037 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123");
1038 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", 1038 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01",
1039 "2017"); 1039 "2017", "1");
1040 card->SetNetworkForMaskedCard(kVisaCard); 1040 card->SetNetworkForMaskedCard(kVisaCard);
1041 1041
1042 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) 1042 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _))
1043 .Times(AtLeast(1)); 1043 .Times(AtLeast(1));
1044 autofill_manager_->FillOrPreviewCreditCardForm( 1044 autofill_manager_->FillOrPreviewCreditCardForm(
1045 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, 1045 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form,
1046 form->fields[0], *card); 1046 form->fields[0], *card);
1047 } 1047 }
1048 1048
1049 // Convenience method for using and retrieving a mock autocomplete history 1049 // Convenience method for using and retrieving a mock autocomplete history
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 autofill_manager_->GetPackedCreditCardID(5))); 1668 autofill_manager_->GetPackedCreditCardID(5)));
1669 } 1669 }
1670 1670
1671 // Test that we return all credit card profile suggestions when the triggering 1671 // Test that we return all credit card profile suggestions when the triggering
1672 // field has stop characters in it and some input. 1672 // field has stop characters in it and some input.
1673 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { 1673 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) {
1674 // Add a credit card with particular numbers that we will attempt to recall. 1674 // Add a credit card with particular numbers that we will attempt to recall.
1675 CreditCard credit_card; 1675 CreditCard credit_card;
1676 test::SetCreditCardInfo(&credit_card, "John Smith", 1676 test::SetCreditCardInfo(&credit_card, "John Smith",
1677 "5255667890123123", // Mastercard 1677 "5255667890123123", // Mastercard
1678 "08", "2017"); 1678 "08", "2017", "1");
1679 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); 1679 credit_card.set_guid("00000000-0000-0000-0000-000000000007");
1680 autofill_manager_->AddCreditCard(credit_card); 1680 autofill_manager_->AddCreditCard(credit_card);
1681 1681
1682 // Set up our form data. 1682 // Set up our form data.
1683 FormData form; 1683 FormData form;
1684 CreateTestCreditCardFormData(&form, true, false); 1684 CreateTestCreditCardFormData(&form, true, false);
1685 std::vector<FormData> forms(1, form); 1685 std::vector<FormData> forms(1, form);
1686 FormsSeen(forms); 1686 FormsSeen(forms);
1687 1687
1688 FormFieldData field = form.fields[1]; 1688 FormFieldData field = form.fields[1];
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 } 1952 }
1953 1953
1954 // Test that we return all credit card suggestions in the case that two cards 1954 // Test that we return all credit card suggestions in the case that two cards
1955 // have the same obfuscated number. 1955 // have the same obfuscated number.
1956 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { 1956 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) {
1957 // Add a credit card with the same obfuscated number as Elvis's. 1957 // Add a credit card with the same obfuscated number as Elvis's.
1958 // |credit_card| will be owned by the mock PersonalDataManager. 1958 // |credit_card| will be owned by the mock PersonalDataManager.
1959 CreditCard credit_card; 1959 CreditCard credit_card;
1960 test::SetCreditCardInfo(&credit_card, "Elvis Presley", 1960 test::SetCreditCardInfo(&credit_card, "Elvis Presley",
1961 "5231567890123456", // Mastercard 1961 "5231567890123456", // Mastercard
1962 "05", "2999"); 1962 "05", "2999", "1");
1963 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); 1963 credit_card.set_guid("00000000-0000-0000-0000-000000000007");
1964 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); 1964 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15));
1965 autofill_manager_->AddCreditCard(credit_card); 1965 autofill_manager_->AddCreditCard(credit_card);
1966 1966
1967 // Set up our form data. 1967 // Set up our form data.
1968 FormData form; 1968 FormData form;
1969 CreateTestCreditCardFormData(&form, true, false); 1969 CreateTestCreditCardFormData(&form, true, false);
1970 std::vector<FormData> forms(1, form); 1970 std::vector<FormData> forms(1, form);
1971 FormsSeen(forms); 1971 FormsSeen(forms);
1972 1972
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", 3904 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare",
3905 "Apt. 10", "Paris", "Île de France", "75008", "FR", 3905 "Apt. 10", "Paris", "Île de France", "75008", "FR",
3906 "+33 2 49 19 70 70"); 3906 "+33 2 49 19 70 70");
3907 profile.set_guid("00000000-0000-0000-0000-000000000001"); 3907 profile.set_guid("00000000-0000-0000-0000-000000000001");
3908 profiles.push_back(profile); 3908 profiles.push_back(profile);
3909 3909
3910 // Set up the test credit cards. 3910 // Set up the test credit cards.
3911 std::vector<CreditCard> credit_cards; 3911 std::vector<CreditCard> credit_cards;
3912 CreditCard credit_card; 3912 CreditCard credit_card;
3913 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", 3913 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04",
3914 "2999"); 3914 "2999", "1");
3915 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 3915 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
3916 credit_cards.push_back(credit_card); 3916 credit_cards.push_back(credit_card);
3917 3917
3918 typedef struct { 3918 typedef struct {
3919 std::string input_value; // The value to input in the field. 3919 std::string input_value; // The value to input in the field.
3920 ServerFieldType field_type; // The expected field type to be determined. 3920 ServerFieldType field_type; // The expected field type to be determined.
3921 } TestCase; 3921 } TestCase;
3922 3922
3923 TestCase test_cases[] = { 3923 TestCase test_cases[] = {
3924 // Profile fields matches. 3924 // Profile fields matches.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
4091 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", 4091 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.",
4092 "", "Memphis", "Tennessee", "38116", "US", 4092 "", "Memphis", "Tennessee", "38116", "US",
4093 "(234) 567-8901"); 4093 "(234) 567-8901");
4094 profile.set_guid("00000000-0000-0000-0000-000000000001"); 4094 profile.set_guid("00000000-0000-0000-0000-000000000001");
4095 profiles.push_back(profile); 4095 profiles.push_back(profile);
4096 4096
4097 // Set up the test credit card. 4097 // Set up the test credit card.
4098 std::vector<CreditCard> credit_cards; 4098 std::vector<CreditCard> credit_cards;
4099 CreditCard credit_card; 4099 CreditCard credit_card;
4100 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", 4100 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456",
4101 "04", "2999"); 4101 "04", "2999", "1");
4102 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 4102 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
4103 credit_cards.push_back(credit_card); 4103 credit_cards.push_back(credit_card);
4104 4104
4105 typedef struct { 4105 typedef struct {
4106 std::string input_value; 4106 std::string input_value;
4107 ServerFieldType predicted_type; 4107 ServerFieldType predicted_type;
4108 bool expect_disambiguation; 4108 bool expect_disambiguation;
4109 ServerFieldType expected_upload_type; 4109 ServerFieldType expected_upload_type;
4110 } TestFieldData; 4110 } TestFieldData;
4111 4111
(...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after
5943 // profile which can be selected for the upload request. 5943 // profile which can be selected for the upload request.
5944 FormData address_form; 5944 FormData address_form;
5945 test::CreateTestAddressFormData(&address_form); 5945 test::CreateTestAddressFormData(&address_form);
5946 FormsSeen(std::vector<FormData>(1, address_form)); 5946 FormsSeen(std::vector<FormData>(1, address_form));
5947 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); 5947 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
5948 FormSubmitted(address_form); 5948 FormSubmitted(address_form);
5949 5949
5950 // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will 5950 // Add a masked credit card whose |TypeAndLastFourDigits| matches what we will
5951 // below. 5951 // below.
5952 CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123"); 5952 CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123");
5953 test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017"); 5953 test::SetCreditCardInfo(&credit_card, "Flo Master", "1111", "11", "2017",
5954 "1");
5954 credit_card.SetNetworkForMaskedCard(kVisaCard); 5955 credit_card.SetNetworkForMaskedCard(kVisaCard);
5955 personal_data_.AddServerCreditCard(credit_card); 5956 personal_data_.AddServerCreditCard(credit_card);
5956 5957
5957 // Set up our credit card form data. 5958 // Set up our credit card form data.
5958 FormData credit_card_form; 5959 FormData credit_card_form;
5959 CreateTestCreditCardFormData(&credit_card_form, true, false); 5960 CreateTestCreditCardFormData(&credit_card_form, true, false);
5960 FormsSeen(std::vector<FormData>(1, credit_card_form)); 5961 FormsSeen(std::vector<FormData>(1, credit_card_form));
5961 5962
5962 // Edit the data, and submit. 5963 // Edit the data, and submit.
5963 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); 5964 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
6581 6582
6582 // Wait for upload to complete (will check expected types as well). 6583 // Wait for upload to complete (will check expected types as well).
6583 autofill_manager_->WaitForAsyncUploadProcess(); 6584 autofill_manager_->WaitForAsyncUploadProcess();
6584 6585
6585 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); 6586 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature());
6586 EXPECT_NE(uploaded_available_types.end(), 6587 EXPECT_NE(uploaded_available_types.end(),
6587 uploaded_available_types.find(autofill::PASSWORD)); 6588 uploaded_available_types.find(autofill::PASSWORD));
6588 } 6589 }
6589 6590
6590 } // namespace autofill 6591 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698