Chromium Code Reviews| 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 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1949 // Test that we return all credit card suggestions in the case that two cards | 1951 // Test that we return all credit card suggestions in the case that two cards |
| 1950 // have the same obfuscated number. | 1952 // have the same obfuscated number. |
| 1951 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1953 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1952 // Add a credit card with the same obfuscated number as Elvis's. | 1954 // Add a credit card with the same obfuscated number as Elvis's. |
| 1953 // |credit_card| will be owned by the mock PersonalDataManager. | 1955 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1954 CreditCard credit_card; | 1956 CreditCard credit_card; |
| 1955 test::SetCreditCardInfo(&credit_card, "Elvis Presley", | 1957 test::SetCreditCardInfo(&credit_card, "Elvis Presley", |
| 1956 "5231567890123456", // Mastercard | 1958 "5231567890123456", // Mastercard |
| 1957 "05", "2999"); | 1959 "05", "2999"); |
| 1958 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); | 1960 credit_card.set_guid("00000000-0000-0000-0000-000000000007"); |
| 1959 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1961 credit_card.set_use_date(AutofillClock::Now() - |
| 1962 base::TimeDelta::FromDays(15)); | |
| 1960 autofill_manager_->AddCreditCard(credit_card); | 1963 autofill_manager_->AddCreditCard(credit_card); |
| 1961 | 1964 |
| 1962 // Set up our form data. | 1965 // Set up our form data. |
| 1963 FormData form; | 1966 FormData form; |
| 1964 CreateTestCreditCardFormData(&form, true, false); | 1967 CreateTestCreditCardFormData(&form, true, false); |
| 1965 std::vector<FormData> forms(1, form); | 1968 std::vector<FormData> forms(1, form); |
| 1966 FormsSeen(forms); | 1969 FormsSeen(forms); |
| 1967 | 1970 |
| 1968 FormFieldData field = form.fields[1]; | 1971 FormFieldData field = form.fields[1]; |
| 1969 GetAutofillSuggestions(form, field); | 1972 GetAutofillSuggestions(form, field); |
| (...skipping 2695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4665 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4668 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 4666 | 4669 |
| 4667 base::HistogramTester histogram_tester; | 4670 base::HistogramTester histogram_tester; |
| 4668 | 4671 |
| 4669 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 4672 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 4670 FormSubmitted(credit_card_form); | 4673 FormSubmitted(credit_card_form); |
| 4671 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4674 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 4672 | 4675 |
| 4673 // Server did not send a server_id, expect copy of card is not stored. | 4676 // Server did not send a server_id, expect copy of card is not stored. |
| 4674 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); | 4677 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); |
| 4675 | |
| 4676 // Verify that the correct histogram entry (and only that) was logged. | 4678 // Verify that the correct histogram entry (and only that) was logged. |
| 4677 ExpectUniqueCardUploadDecision(histogram_tester, | 4679 ExpectUniqueCardUploadDecision(histogram_tester, |
| 4678 AutofillMetrics::UPLOAD_OFFERED); | 4680 AutofillMetrics::UPLOAD_OFFERED); |
| 4679 // Verify that the correct UKM was logged. | 4681 // Verify that the correct UKM was logged. |
| 4680 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 4682 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
| 4683 // Verify that UMA for "DaysSincePreviousUse" was not logged because we | |
| 4684 // modified the profile. | |
| 4685 histogram_tester.ExpectTotalCount( | |
| 4686 "Autofill.DaysSincePreviousUseAtSubmission.Profile", 0); | |
| 4681 } | 4687 } |
| 4682 | 4688 |
| 4683 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4689 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4684 #if defined(OS_ANDROID) | 4690 #if defined(OS_ANDROID) |
| 4685 #define MAYBE_UploadCreditCardAndSaveCopy DISABLED_UploadCreditCardAndSaveCopy | 4691 #define MAYBE_UploadCreditCardAndSaveCopy DISABLED_UploadCreditCardAndSaveCopy |
| 4686 #else | 4692 #else |
| 4687 #define MAYBE_UploadCreditCardAndSaveCopy UploadCreditCardAndSaveCopy | 4693 #define MAYBE_UploadCreditCardAndSaveCopy UploadCreditCardAndSaveCopy |
| 4688 #endif | 4694 #endif |
| 4689 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCardAndSaveCopy) { | 4695 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCardAndSaveCopy) { |
| 4690 personal_data_.ClearCreditCards(); | 4696 personal_data_.ClearCreditCards(); |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5865 // Name matches recently used profile, should offer upload. | 5871 // Name matches recently used profile, should offer upload. |
| 5866 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | 5872 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5867 FormSubmitted(credit_card_form); | 5873 FormSubmitted(credit_card_form); |
| 5868 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 5874 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5869 | 5875 |
| 5870 // Verify that the correct histogram entry (and only that) was logged. | 5876 // Verify that the correct histogram entry (and only that) was logged. |
| 5871 ExpectUniqueCardUploadDecision(histogram_tester, | 5877 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5872 AutofillMetrics::UPLOAD_OFFERED); | 5878 AutofillMetrics::UPLOAD_OFFERED); |
| 5873 } | 5879 } |
| 5874 | 5880 |
| 5881 TEST_F(AutofillManagerTest, UploadCreditCard_LogPreviousUseDate) { | |
| 5882 // Create the test clock and set the time to a specific value. | |
| 5883 TestAutofillClock test_clock; | |
| 5884 test_clock.SetNow(kArbitraryTime); | |
| 5885 | |
| 5886 personal_data_.ClearAutofillProfiles(); | |
| 5887 autofill_manager_->set_credit_card_upload_enabled(true); | |
| 5888 | |
| 5889 // Create, fill and submit an address form in order to establish a recent | |
| 5890 // profile which can be selected for the upload request. | |
| 5891 FormData address_form; | |
| 5892 test::CreateTestAddressFormData(&address_form); | |
| 5893 FormsSeen({address_form}); | |
| 5894 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); | |
| 5895 FormSubmitted(address_form); | |
| 5896 const std::vector<AutofillProfile*>& profiles = | |
| 5897 personal_data_.GetProfilesToSuggest(); | |
| 5898 ASSERT_EQ(1U, profiles.size()); | |
| 5899 | |
| 5900 // Advance the current time and simulate use of the address profile. | |
| 5901 test_clock.SetNow(kMuchLaterTime); | |
| 5902 profiles[0]->RecordAndLogUse(); | |
| 5903 | |
| 5904 // Set up our credit card form data. | |
| 5905 FormData credit_card_form; | |
| 5906 CreateTestCreditCardFormData(&credit_card_form, true, false); | |
| 5907 FormsSeen({credit_card_form}); | |
| 5908 | |
| 5909 // Edit the credit card form and submit. | |
| 5910 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | |
| 5911 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | |
| 5912 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | |
| 5913 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | |
| 5914 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | |
| 5915 | |
| 5916 base::HistogramTester histogram_tester; | |
| 5917 | |
| 5918 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); | |
| 5919 FormSubmitted(credit_card_form); | |
| 5920 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | |
| 5921 | |
| 5922 // Verify that UMA for "DaysSincePreviousUse" is logged. | |
| 5923 histogram_tester.ExpectUniqueSample( | |
| 5924 "Autofill.DaysSincePreviousUseAtSubmission.Profile", | |
| 5925 (kMuchLaterTime - kArbitraryTime).InDays(), | |
| 5926 /* expected_count= */ 1); | |
|
sebsg
2017/05/08 21:43:29
nit: /*expected_count=*/1. That makes sure they wi
csashi
2017/05/08 21:51:41
Done.
| |
| 5927 } | |
| 5928 | |
| 5875 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 5929 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 5876 #if defined(OS_ANDROID) | 5930 #if defined(OS_ANDROID) |
| 5877 #define MAYBE_UploadCreditCard_UploadDetailsFails \ | 5931 #define MAYBE_UploadCreditCard_UploadDetailsFails \ |
| 5878 DISABLED_UploadCreditCard_UploadDetailsFails | 5932 DISABLED_UploadCreditCard_UploadDetailsFails |
| 5879 #else | 5933 #else |
| 5880 #define MAYBE_UploadCreditCard_UploadDetailsFails \ | 5934 #define MAYBE_UploadCreditCard_UploadDetailsFails \ |
| 5881 UploadCreditCard_UploadDetailsFails | 5935 UploadCreditCard_UploadDetailsFails |
| 5882 #endif | 5936 #endif |
| 5883 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) { | 5937 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) { |
| 5884 EnableUkmLogging(); | 5938 EnableUkmLogging(); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6578 | 6632 |
| 6579 // Wait for upload to complete (will check expected types as well). | 6633 // Wait for upload to complete (will check expected types as well). |
| 6580 autofill_manager_->WaitForAsyncUploadProcess(); | 6634 autofill_manager_->WaitForAsyncUploadProcess(); |
| 6581 | 6635 |
| 6582 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6636 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 6583 EXPECT_NE(uploaded_available_types.end(), | 6637 EXPECT_NE(uploaded_available_types.end(), |
| 6584 uploaded_available_types.find(autofill::PASSWORD)); | 6638 uploaded_available_types.find(autofill::PASSWORD)); |
| 6585 } | 6639 } |
| 6586 | 6640 |
| 6587 } // namespace autofill | 6641 } // namespace autofill |
| OLD | NEW |