| OLD | NEW |
| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 local_credit_cards_.clear(); | 226 local_credit_cards_.clear(); |
| 227 server_credit_cards_.clear(); | 227 server_credit_cards_.clear(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Create Elvis card with whitespace in the credit card number. | 230 // Create Elvis card with whitespace in the credit card number. |
| 231 void CreateTestCreditCardWithWhitespace() { | 231 void CreateTestCreditCardWithWhitespace() { |
| 232 ClearCreditCards(); | 232 ClearCreditCards(); |
| 233 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 233 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 234 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 234 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 235 "4234 5678 9012 3456", // Visa | 235 "4234 5678 9012 3456", // Visa |
| 236 "04", "2999"); | 236 "04", "2999", "1"); |
| 237 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 237 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); |
| 238 local_credit_cards_.push_back(std::move(credit_card)); | 238 local_credit_cards_.push_back(std::move(credit_card)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Create Elvis card with separator characters in the credit card number. | 241 // Create Elvis card with separator characters in the credit card number. |
| 242 void CreateTestCreditCardWithSeparators() { | 242 void CreateTestCreditCardWithSeparators() { |
| 243 ClearCreditCards(); | 243 ClearCreditCards(); |
| 244 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 244 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 245 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 245 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 246 "4234-5678-9012-3456", // Visa | 246 "4234-5678-9012-3456", // Visa |
| 247 "04", "2999"); | 247 "04", "2999", "1"); |
| 248 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | 248 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 249 local_credit_cards_.push_back(std::move(credit_card)); | 249 local_credit_cards_.push_back(std::move(credit_card)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { | 252 void CreateTestCreditCardsYearAndMonth(const char* year, const char* month) { |
| 253 ClearCreditCards(); | 253 ClearCreditCards(); |
| 254 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 254 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 255 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune", | 255 test::SetCreditCardInfo(credit_card.get(), "Miku Hatsune", |
| 256 "4234567890654321", // Visa | 256 "4234567890654321", // Visa |
| 257 month, year); | 257 month, year, "1"); |
| 258 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 258 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 259 local_credit_cards_.push_back(std::move(credit_card)); | 259 local_credit_cards_.push_back(std::move(credit_card)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void CreateTestExpiredCreditCard() { | 262 void CreateTestExpiredCreditCard() { |
| 263 ClearCreditCards(); | 263 ClearCreditCards(); |
| 264 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 264 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 265 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson", | 265 test::SetCreditCardInfo(credit_card.get(), "Homer Simpson", |
| 266 "4234567890654321", // Visa | 266 "4234567890654321", // Visa |
| 267 "05", "2000"); | 267 "05", "2000", "1"); |
| 268 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); | 268 credit_card->set_guid("00000000-0000-0000-0000-000000000009"); |
| 269 local_credit_cards_.push_back(std::move(credit_card)); | 269 local_credit_cards_.push_back(std::move(credit_card)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 private: | 272 private: |
| 273 void CreateTestAutofillProfiles( | 273 void CreateTestAutofillProfiles( |
| 274 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { | 274 std::vector<std::unique_ptr<AutofillProfile>>* profiles) { |
| 275 std::unique_ptr<AutofillProfile> profile = | 275 std::unique_ptr<AutofillProfile> profile = |
| 276 base::MakeUnique<AutofillProfile>(); | 276 base::MakeUnique<AutofillProfile>(); |
| 277 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", | 277 test::SetProfileInfo(profile.get(), "Elvis", "Aaron", "Presley", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 291 "", ""); | 291 "", ""); |
| 292 profile->set_guid("00000000-0000-0000-0000-000000000003"); | 292 profile->set_guid("00000000-0000-0000-0000-000000000003"); |
| 293 profiles->push_back(std::move(profile)); | 293 profiles->push_back(std::move(profile)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void CreateTestCreditCards( | 296 void CreateTestCreditCards( |
| 297 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { | 297 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { |
| 298 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 298 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 299 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 299 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 300 "4234567890123456", // Visa | 300 "4234567890123456", // Visa |
| 301 "04", "2999"); | 301 "04", "2999", "1"); |
| 302 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 302 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 303 credit_card->set_use_count(10); | 303 credit_card->set_use_count(10); |
| 304 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 304 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); |
| 305 credit_cards->push_back(std::move(credit_card)); | 305 credit_cards->push_back(std::move(credit_card)); |
| 306 | 306 |
| 307 credit_card = base::MakeUnique<CreditCard>(); | 307 credit_card = base::MakeUnique<CreditCard>(); |
| 308 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", | 308 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", |
| 309 "5187654321098765", // Mastercard | 309 "5187654321098765", // Mastercard |
| 310 "10", "2998"); | 310 "10", "2998", "1"); |
| 311 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 311 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 312 credit_card->set_use_count(5); | 312 credit_card->set_use_count(5); |
| 313 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 313 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); |
| 314 credit_cards->push_back(std::move(credit_card)); | 314 credit_cards->push_back(std::move(credit_card)); |
| 315 | 315 |
| 316 credit_card = base::MakeUnique<CreditCard>(); | 316 credit_card = base::MakeUnique<CreditCard>(); |
| 317 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); | 317 test::SetCreditCardInfo(credit_card.get(), "", "", "", "", ""); |
| 318 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 318 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
| 319 credit_cards->push_back(std::move(credit_card)); | 319 credit_cards->push_back(std::move(credit_card)); |
| 320 } | 320 } |
| 321 | 321 |
| 322 size_t num_times_save_imported_profile_called_; | 322 size_t num_times_save_imported_profile_called_; |
| 323 | 323 |
| 324 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); | 324 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); |
| 325 }; | 325 }; |
| 326 | 326 |
| 327 class TestAutofillDownloadManager : public AutofillDownloadManager { | 327 class TestAutofillDownloadManager : public AutofillDownloadManager { |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { | 1021 void PrepareForRealPanResponse(FormData* form, CreditCard* card) { |
| 1022 // This line silences the warning from PaymentsClient about matching sync | 1022 // This line silences the warning from PaymentsClient about matching sync |
| 1023 // and Payments server types. | 1023 // and Payments server types. |
| 1024 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1024 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1025 "sync-url", "https://google.com"); | 1025 "sync-url", "https://google.com"); |
| 1026 | 1026 |
| 1027 CreateTestCreditCardFormData(form, true, false); | 1027 CreateTestCreditCardFormData(form, true, false); |
| 1028 FormsSeen(std::vector<FormData>(1, *form)); | 1028 FormsSeen(std::vector<FormData>(1, *form)); |
| 1029 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); | 1029 *card = CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 1030 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", | 1030 test::SetCreditCardInfo(card, "John Dillinger", "1881" /* Visa */, "01", |
| 1031 "2017"); | 1031 "2017", "1"); |
| 1032 card->SetNetworkForMaskedCard(kVisaCard); | 1032 card->SetNetworkForMaskedCard(kVisaCard); |
| 1033 | 1033 |
| 1034 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) | 1034 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _, _)) |
| 1035 .Times(AtLeast(1)); | 1035 .Times(AtLeast(1)); |
| 1036 autofill_manager_->FillOrPreviewCreditCardForm( | 1036 autofill_manager_->FillOrPreviewCreditCardForm( |
| 1037 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, | 1037 AutofillDriver::FORM_DATA_ACTION_FILL, kDefaultPageID, *form, |
| 1038 form->fields[0], *card); | 1038 form->fields[0], *card); |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 // Convenience method for using and retrieving a mock autocomplete history | 1041 // Convenience method for using and retrieving a mock autocomplete history |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 autofill_manager_->GetPackedCreditCardID(5))); | 1633 autofill_manager_->GetPackedCreditCardID(5))); |
| 1634 } | 1634 } |
| 1635 | 1635 |
| 1636 // Test that we return all credit card profile suggestions when the triggering | 1636 // Test that we return all credit card profile suggestions when the triggering |
| 1637 // field has stop characters in it and some input. | 1637 // field has stop characters in it and some input. |
| 1638 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { | 1638 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_StopCharsWithInput) { |
| 1639 // Add a credit card with particular numbers that we will attempt to recall. | 1639 // Add a credit card with particular numbers that we will attempt to recall. |
| 1640 CreditCard credit_card; | 1640 CreditCard credit_card; |
| 1641 test::SetCreditCardInfo(&credit_card, "John Smith", | 1641 test::SetCreditCardInfo(&credit_card, "John Smith", |
| 1642 "5255667890123123", // Mastercard | 1642 "5255667890123123", // Mastercard |
| 1643 "08", "2017"); | 1643 "08", "2017", "1"); |
| 1644 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1644 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| 1645 autofill_manager_->AddCreditCard(credit_card); | 1645 autofill_manager_->AddCreditCard(credit_card); |
| 1646 | 1646 |
| 1647 // Set up our form data. | 1647 // Set up our form data. |
| 1648 FormData form; | 1648 FormData form; |
| 1649 CreateTestCreditCardFormData(&form, true, false); | 1649 CreateTestCreditCardFormData(&form, true, false); |
| 1650 std::vector<FormData> forms(1, form); | 1650 std::vector<FormData> forms(1, form); |
| 1651 FormsSeen(forms); | 1651 FormsSeen(forms); |
| 1652 | 1652 |
| 1653 FormFieldData field = form.fields[1]; | 1653 FormFieldData field = form.fields[1]; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 } | 1917 } |
| 1918 | 1918 |
| 1919 // Test that we return all credit card suggestions in the case that two cards | 1919 // Test that we return all credit card suggestions in the case that two cards |
| 1920 // have the same obfuscated number. | 1920 // have the same obfuscated number. |
| 1921 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1921 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1922 // Add a credit card with the same obfuscated number as Elvis's. | 1922 // Add a credit card with the same obfuscated number as Elvis's. |
| 1923 // |credit_card| will be owned by the mock PersonalDataManager. | 1923 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1924 CreditCard credit_card; | 1924 CreditCard credit_card; |
| 1925 test::SetCreditCardInfo(&credit_card, "Elvis Presley", | 1925 test::SetCreditCardInfo(&credit_card, "Elvis Presley", |
| 1926 "5231567890123456", // Mastercard | 1926 "5231567890123456", // Mastercard |
| 1927 "05", "2999"); | 1927 "05", "2999", "1"); |
| 1928 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1928 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| 1929 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1929 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); |
| 1930 autofill_manager_->AddCreditCard(credit_card); | 1930 autofill_manager_->AddCreditCard(credit_card); |
| 1931 | 1931 |
| 1932 // Set up our form data. | 1932 // Set up our form data. |
| 1933 FormData form; | 1933 FormData form; |
| 1934 CreateTestCreditCardFormData(&form, true, false); | 1934 CreateTestCreditCardFormData(&form, true, false); |
| 1935 std::vector<FormData> forms(1, form); | 1935 std::vector<FormData> forms(1, form); |
| 1936 FormsSeen(forms); | 1936 FormsSeen(forms); |
| 1937 | 1937 |
| (...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3869 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", | 3869 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare", |
| 3870 "Apt. 10", "Paris", "Île de France", "75008", "FR", | 3870 "Apt. 10", "Paris", "Île de France", "75008", "FR", |
| 3871 "+33 2 49 19 70 70"); | 3871 "+33 2 49 19 70 70"); |
| 3872 profile.set_guid("00000000-0000-0000-0000-000000000001"); | 3872 profile.set_guid("00000000-0000-0000-0000-000000000001"); |
| 3873 profiles.push_back(profile); | 3873 profiles.push_back(profile); |
| 3874 | 3874 |
| 3875 // Set up the test credit cards. | 3875 // Set up the test credit cards. |
| 3876 std::vector<CreditCard> credit_cards; | 3876 std::vector<CreditCard> credit_cards; |
| 3877 CreditCard credit_card; | 3877 CreditCard credit_card; |
| 3878 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", | 3878 test::SetCreditCardInfo(&credit_card, "John Doe", "4234-5678-9012-3456", "04", |
| 3879 "2999"); | 3879 "2999", "1"); |
| 3880 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); | 3880 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); |
| 3881 credit_cards.push_back(credit_card); | 3881 credit_cards.push_back(credit_card); |
| 3882 | 3882 |
| 3883 typedef struct { | 3883 typedef struct { |
| 3884 std::string input_value; // The value to input in the field. | 3884 std::string input_value; // The value to input in the field. |
| 3885 ServerFieldType field_type; // The expected field type to be determined. | 3885 ServerFieldType field_type; // The expected field type to be determined. |
| 3886 } TestCase; | 3886 } TestCase; |
| 3887 | 3887 |
| 3888 TestCase test_cases[] = { | 3888 TestCase test_cases[] = { |
| 3889 // Profile fields matches. | 3889 // Profile fields matches. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4056 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", | 4056 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", |
| 4057 "", "Memphis", "Tennessee", "38116", "US", | 4057 "", "Memphis", "Tennessee", "38116", "US", |
| 4058 "(234) 567-8901"); | 4058 "(234) 567-8901"); |
| 4059 profile.set_guid("00000000-0000-0000-0000-000000000001"); | 4059 profile.set_guid("00000000-0000-0000-0000-000000000001"); |
| 4060 profiles.push_back(profile); | 4060 profiles.push_back(profile); |
| 4061 | 4061 |
| 4062 // Set up the test credit card. | 4062 // Set up the test credit card. |
| 4063 std::vector<CreditCard> credit_cards; | 4063 std::vector<CreditCard> credit_cards; |
| 4064 CreditCard credit_card; | 4064 CreditCard credit_card; |
| 4065 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", | 4065 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", |
| 4066 "04", "2999"); | 4066 "04", "2999", "1"); |
| 4067 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); | 4067 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); |
| 4068 credit_cards.push_back(credit_card); | 4068 credit_cards.push_back(credit_card); |
| 4069 | 4069 |
| 4070 typedef struct { | 4070 typedef struct { |
| 4071 std::string input_value; | 4071 std::string input_value; |
| 4072 ServerFieldType predicted_type; | 4072 ServerFieldType predicted_type; |
| 4073 bool expect_disambiguation; | 4073 bool expect_disambiguation; |
| 4074 ServerFieldType expected_upload_type; | 4074 ServerFieldType expected_upload_type; |
| 4075 } TestFieldData; | 4075 } TestFieldData; |
| 4076 | 4076 |
| (...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6190 | 6190 |
| 6191 // Wait for upload to complete (will check expected types as well). | 6191 // Wait for upload to complete (will check expected types as well). |
| 6192 autofill_manager_->WaitForAsyncUploadProcess(); | 6192 autofill_manager_->WaitForAsyncUploadProcess(); |
| 6193 | 6193 |
| 6194 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6194 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 6195 EXPECT_NE(uploaded_available_types.end(), | 6195 EXPECT_NE(uploaded_available_types.end(), |
| 6196 uploaded_available_types.find(autofill::PASSWORD)); | 6196 uploaded_available_types.find(autofill::PASSWORD)); |
| 6197 } | 6197 } |
| 6198 | 6198 |
| 6199 } // namespace autofill | 6199 } // namespace autofill |
| OLD | NEW |