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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 176 } |
177 | 177 |
178 void AddProfile(std::unique_ptr<AutofillProfile> profile) { | 178 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
179 profile->set_modification_date(AutofillClock::Now()); | 179 profile->set_modification_date(AutofillClock::Now()); |
180 web_profiles_.push_back(std::move(profile)); | 180 web_profiles_.push_back(std::move(profile)); |
181 } | 181 } |
182 | 182 |
183 void AddCreditCard(const CreditCard& credit_card) override { | 183 void AddCreditCard(const CreditCard& credit_card) override { |
184 std::unique_ptr<CreditCard> local_credit_card = | 184 std::unique_ptr<CreditCard> local_credit_card = |
185 base::MakeUnique<CreditCard>(credit_card); | 185 base::MakeUnique<CreditCard>(credit_card); |
186 local_credit_card->set_modification_date(base::Time::Now()); | 186 local_credit_card->set_modification_date(AutofillClock::Now()); |
187 local_credit_cards_.push_back(std::move(local_credit_card)); | 187 local_credit_cards_.push_back(std::move(local_credit_card)); |
188 } | 188 } |
189 | 189 |
190 void AddFullServerCreditCard(const CreditCard& credit_card) override { | 190 void AddFullServerCreditCard(const CreditCard& credit_card) override { |
191 AddServerCreditCard(credit_card); | 191 AddServerCreditCard(credit_card); |
192 } | 192 } |
193 | 193 |
194 void RecordUseOf(const AutofillDataModel& data_model) override { | 194 void RecordUseOf(const AutofillDataModel& data_model) override { |
195 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 195 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); |
196 if (credit_card) | 196 if (credit_card) |
(...skipping 27 matching lines...) Expand all Loading... |
224 void ClearAutofillProfiles() { web_profiles_.clear(); } | 224 void ClearAutofillProfiles() { web_profiles_.clear(); } |
225 | 225 |
226 void ClearCreditCards() { | 226 void ClearCreditCards() { |
227 local_credit_cards_.clear(); | 227 local_credit_cards_.clear(); |
228 server_credit_cards_.clear(); | 228 server_credit_cards_.clear(); |
229 } | 229 } |
230 | 230 |
231 void AddServerCreditCard(const CreditCard& credit_card) { | 231 void AddServerCreditCard(const CreditCard& credit_card) { |
232 std::unique_ptr<CreditCard> server_credit_card = | 232 std::unique_ptr<CreditCard> server_credit_card = |
233 base::MakeUnique<CreditCard>(credit_card); | 233 base::MakeUnique<CreditCard>(credit_card); |
234 server_credit_card->set_modification_date(base::Time::Now()); | 234 server_credit_card->set_modification_date(AutofillClock::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"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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"); |
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(AutofillClock::Now() - |
| 313 base::TimeDelta::FromDays(5)); |
313 credit_cards->push_back(std::move(credit_card)); | 314 credit_cards->push_back(std::move(credit_card)); |
314 | 315 |
315 credit_card = base::MakeUnique<CreditCard>(); | 316 credit_card = base::MakeUnique<CreditCard>(); |
316 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", | 317 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", |
317 "5187654321098765", // Mastercard | 318 "5187654321098765", // Mastercard |
318 "10", "2998"); | 319 "10", "2998"); |
319 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 320 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
320 credit_card->set_use_count(5); | 321 credit_card->set_use_count(5); |
321 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 322 credit_card->set_use_date(AutofillClock::Now() - |
| 323 base::TimeDelta::FromDays(4)); |
322 credit_cards->push_back(std::move(credit_card)); | 324 credit_cards->push_back(std::move(credit_card)); |
323 | 325 |
324 credit_card = base::MakeUnique<CreditCard>(); | 326 credit_card = base::MakeUnique<CreditCard>(); |
325 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); | 327 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); |
326 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 328 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
327 credit_cards->push_back(std::move(credit_card)); | 329 credit_cards->push_back(std::move(credit_card)); |
328 } | 330 } |
329 | 331 |
330 size_t num_times_save_imported_profile_called_; | 332 size_t num_times_save_imported_profile_called_; |
331 | 333 |
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 // Test that we return all credit card suggestions in the case that two cards | 1956 // Test that we return all credit card suggestions in the case that two cards |
1955 // have the same obfuscated number. | 1957 // have the same obfuscated number. |
1956 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1958 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
1957 // Add a credit card with the same obfuscated number as Elvis's. | 1959 // Add a credit card with the same obfuscated number as Elvis's. |
1958 // |credit_card| will be owned by the mock PersonalDataManager. | 1960 // |credit_card| will be owned by the mock PersonalDataManager. |
1959 CreditCard credit_card; | 1961 CreditCard credit_card; |
1960 test::SetCreditCardInfo(&credit_card, "Elvis Presley", | 1962 test::SetCreditCardInfo(&credit_card, "Elvis Presley", |
1961 "5231567890123456", // Mastercard | 1963 "5231567890123456", // Mastercard |
1962 "05", "2999"); | 1964 "05", "2999"); |
1963 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1965 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
1964 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1966 credit_card.set_use_date(AutofillClock::Now() - |
| 1967 base::TimeDelta::FromDays(15)); |
1965 autofill_manager_->AddCreditCard(credit_card); | 1968 autofill_manager_->AddCreditCard(credit_card); |
1966 | 1969 |
1967 // Set up our form data. | 1970 // Set up our form data. |
1968 FormData form; | 1971 FormData form; |
1969 CreateTestCreditCardFormData(&form, true, false); | 1972 CreateTestCreditCardFormData(&form, true, false); |
1970 std::vector<FormData> forms(1, form); | 1973 std::vector<FormData> forms(1, form); |
1971 FormsSeen(forms); | 1974 FormsSeen(forms); |
1972 | 1975 |
1973 FormFieldData field = form.fields[1]; | 1976 FormFieldData field = form.fields[1]; |
1974 GetAutofillSuggestions(form, field); | 1977 GetAutofillSuggestions(form, field); |
(...skipping 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4664 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4667 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
4665 | 4668 |
4666 base::HistogramTester histogram_tester; | 4669 base::HistogramTester histogram_tester; |
4667 | 4670 |
4668 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4671 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
4669 FormSubmitted(credit_card_form); | 4672 FormSubmitted(credit_card_form); |
4670 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4673 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
4671 | 4674 |
4672 // Server did not send a server_id, expect copy of card is not stored. | 4675 // Server did not send a server_id, expect copy of card is not stored. |
4673 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); | 4676 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); |
4674 | |
4675 // Verify that the correct histogram entry (and only that) was logged. | 4677 // Verify that the correct histogram entry (and only that) was logged. |
4676 ExpectUniqueCardUploadDecision(histogram_tester, | 4678 ExpectUniqueCardUploadDecision(histogram_tester, |
4677 AutofillMetrics::UPLOAD_OFFERED); | 4679 AutofillMetrics::UPLOAD_OFFERED); |
4678 // Verify that the correct UKM was logged. | 4680 // Verify that the correct UKM was logged. |
4679 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 4681 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
4680 // Verify the histogram entry for recent profile modification. | 4682 // Verify the histogram entry for recent profile modification. |
4681 histogram_tester.ExpectUniqueSample( | 4683 histogram_tester.ExpectUniqueSample( |
4682 "Autofill.HasModifiedProfile.CreditCardFormSubmission", true, 1); | 4684 "Autofill.HasModifiedProfile.CreditCardFormSubmission", true, 1); |
| 4685 // Verify that UMA for "DaysSincePreviousUse" was not logged because we |
| 4686 // modified the profile. |
| 4687 histogram_tester.ExpectTotalCount( |
| 4688 "Autofill.DaysSincePreviousUseAtSubmission.Profile", 0); |
4683 } | 4689 } |
4684 | 4690 |
4685 TEST_F(AutofillManagerTest, UploadCreditCardAndSaveCopy) { | 4691 TEST_F(AutofillManagerTest, UploadCreditCardAndSaveCopy) { |
4686 personal_data_.ClearCreditCards(); | 4692 personal_data_.ClearCreditCards(); |
4687 personal_data_.ClearAutofillProfiles(); | 4693 personal_data_.ClearAutofillProfiles(); |
4688 autofill_manager_->set_credit_card_upload_enabled(true); | 4694 autofill_manager_->set_credit_card_upload_enabled(true); |
4689 | 4695 |
4690 const char* const server_id = "InstrumentData:1234"; | 4696 const char* const server_id = "InstrumentData:1234"; |
4691 autofill_manager_->ResetPaymentsClientForCardUpload(server_id); | 4697 autofill_manager_->ResetPaymentsClientForCardUpload(server_id); |
4692 | 4698 |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5867 | 5873 |
5868 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form1); | 5874 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form1); |
5869 FormSubmitted(address_form1); | 5875 FormSubmitted(address_form1); |
5870 | 5876 |
5871 ManuallyFillAddressForm("Master", "Blaster", "77401", "US", &address_form2); | 5877 ManuallyFillAddressForm("Master", "Blaster", "77401", "US", &address_form2); |
5872 FormSubmitted(address_form2); | 5878 FormSubmitted(address_form2); |
5873 | 5879 |
5874 // Set up our credit card form data. | 5880 // Set up our credit card form data. |
5875 FormData credit_card_form; | 5881 FormData credit_card_form; |
5876 CreateTestCreditCardFormData(&credit_card_form, true, false); | 5882 CreateTestCreditCardFormData(&credit_card_form, true, false); |
5877 FormsSeen(std::vector<FormData>(1, credit_card_form)); | 5883 FormsSeen({credit_card_form}); |
5878 | 5884 |
5879 // Edit the data, but use yet another name, and submit. | 5885 // Edit the data, but use yet another name, and submit. |
5880 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); | 5886 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); |
| 5887 FormsSeen({credit_card_form}); |
| 5888 |
| 5889 // Edit the credit card form and submit. |
| 5890 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
5881 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 5891 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
5882 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 5892 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
5883 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 5893 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
5884 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 5894 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
5885 | 5895 |
5886 base::HistogramTester histogram_tester; | 5896 base::HistogramTester histogram_tester; |
5887 | 5897 |
5888 // Names are required to match, upload should not happen. | 5898 // Names are required to match, upload should not happen. |
5889 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5899 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
5890 FormSubmitted(credit_card_form); | 5900 FormSubmitted(credit_card_form); |
5891 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 5901 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
5892 | 5902 |
5893 // Verify that the correct histogram entry (and only that) was logged. | 5903 // Verify that the correct histogram entry (and only that) was logged. |
5894 ExpectUniqueCardUploadDecision( | 5904 ExpectUniqueCardUploadDecision( |
5895 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); | 5905 histogram_tester, AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); |
5896 } | 5906 } |
5897 | 5907 |
| 5908 TEST_F(AutofillManagerTest, UploadCreditCard_LogPreviousUseDate) { |
| 5909 // Create the test clock and set the time to a specific value. |
| 5910 TestAutofillClock test_clock; |
| 5911 test_clock.SetNow(kArbitraryTime); |
| 5912 |
| 5913 personal_data_.ClearAutofillProfiles(); |
| 5914 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5915 |
| 5916 // Create, fill and submit an address form in order to establish a recent |
| 5917 // profile which can be selected for the upload request. |
| 5918 FormData address_form; |
| 5919 test::CreateTestAddressFormData(&address_form); |
| 5920 FormsSeen({address_form}); |
| 5921 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| 5922 FormSubmitted(address_form); |
| 5923 const std::vector<AutofillProfile*>& profiles = |
| 5924 personal_data_.GetProfilesToSuggest(); |
| 5925 ASSERT_EQ(1U, profiles.size()); |
| 5926 |
| 5927 // Advance the current time and simulate use of the address profile. |
| 5928 test_clock.SetNow(kMuchLaterTime); |
| 5929 profiles[0]->RecordAndLogUse(); |
| 5930 |
| 5931 // Set up our credit card form data. |
| 5932 FormData credit_card_form; |
| 5933 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5934 FormsSeen({credit_card_form}); |
| 5935 |
| 5936 // Edit the credit card form and submit. |
| 5937 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 5938 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5939 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5940 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5941 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5942 |
| 5943 base::HistogramTester histogram_tester; |
| 5944 |
| 5945 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5946 FormSubmitted(credit_card_form); |
| 5947 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5948 |
| 5949 // Verify that UMA for "DaysSincePreviousUse" is logged. |
| 5950 histogram_tester.ExpectUniqueSample( |
| 5951 "Autofill.DaysSincePreviousUseAtSubmission.Profile", |
| 5952 (kMuchLaterTime - kArbitraryTime).InDays(), |
| 5953 /*expected_count=*/1); |
| 5954 } |
| 5955 |
5898 TEST_F(AutofillManagerTest, UploadCreditCard_UploadDetailsFails) { | 5956 TEST_F(AutofillManagerTest, UploadCreditCard_UploadDetailsFails) { |
5899 EnableUkmLogging(); | 5957 EnableUkmLogging(); |
5900 personal_data_.ClearAutofillProfiles(); | 5958 personal_data_.ClearAutofillProfiles(); |
5901 autofill_manager_->set_credit_card_upload_enabled(true); | 5959 autofill_manager_->set_credit_card_upload_enabled(true); |
5902 | 5960 |
5903 // Anything other than "en-US" will cause GetUploadDetails to return a failure | 5961 // Anything other than "en-US" will cause GetUploadDetails to return a failure |
5904 // response. | 5962 // response. |
5905 autofill_manager_->set_app_locale("pt-BR"); | 5963 autofill_manager_->set_app_locale("pt-BR"); |
5906 | 5964 |
5907 // Create, fill and submit an address form in order to establish a recent | 5965 // Create, fill and submit an address form in order to establish a recent |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6587 | 6645 |
6588 // Wait for upload to complete (will check expected types as well). | 6646 // Wait for upload to complete (will check expected types as well). |
6589 autofill_manager_->WaitForAsyncUploadProcess(); | 6647 autofill_manager_->WaitForAsyncUploadProcess(); |
6590 | 6648 |
6591 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6649 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
6592 EXPECT_NE(uploaded_available_types.end(), | 6650 EXPECT_NE(uploaded_available_types.end(), |
6593 uploaded_available_types.find(autofill::PASSWORD)); | 6651 uploaded_available_types.find(autofill::PASSWORD)); |
6594 } | 6652 } |
6595 | 6653 |
6596 } // namespace autofill | 6654 } // namespace autofill |
OLD | NEW |