| 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 12 matching lines...) Expand all Loading... |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/test/histogram_tester.h" | 27 #include "base/test/histogram_tester.h" |
| 28 #include "base/test/scoped_feature_list.h" | 28 #include "base/test/scoped_feature_list.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
| 30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 32 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 32 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 33 #include "components/autofill/core/browser/autofill_clock.h" |
| 33 #include "components/autofill/core/browser/autofill_download_manager.h" | 34 #include "components/autofill/core/browser/autofill_download_manager.h" |
| 34 #include "components/autofill/core/browser/autofill_experiments.h" | 35 #include "components/autofill/core/browser/autofill_experiments.h" |
| 35 #include "components/autofill/core/browser/autofill_profile.h" | 36 #include "components/autofill/core/browser/autofill_profile.h" |
| 36 #include "components/autofill/core/browser/autofill_test_utils.h" | 37 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 37 #include "components/autofill/core/browser/credit_card.h" | 38 #include "components/autofill/core/browser/credit_card.h" |
| 38 #include "components/autofill/core/browser/personal_data_manager.h" | 39 #include "components/autofill/core/browser/personal_data_manager.h" |
| 39 #include "components/autofill/core/browser/popup_item_ids.h" | 40 #include "components/autofill/core/browser/popup_item_ids.h" |
| 40 #include "components/autofill/core/browser/test_autofill_client.h" | 41 #include "components/autofill/core/browser/test_autofill_client.h" |
| 41 #include "components/autofill/core/browser/test_autofill_driver.h" | 42 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 42 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 43 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 155 |
| 155 CreditCard* GetCreditCardWithGUID(const char* guid) { | 156 CreditCard* GetCreditCardWithGUID(const char* guid) { |
| 156 for (CreditCard* card : GetCreditCards()) { | 157 for (CreditCard* card : GetCreditCards()) { |
| 157 if (!card->guid().compare(guid)) | 158 if (!card->guid().compare(guid)) |
| 158 return card; | 159 return card; |
| 159 } | 160 } |
| 160 return NULL; | 161 return NULL; |
| 161 } | 162 } |
| 162 | 163 |
| 163 void AddProfile(std::unique_ptr<AutofillProfile> profile) { | 164 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
| 164 profile->set_modification_date(base::Time::Now()); | 165 profile->set_modification_date(AutofillClock::Now()); |
| 165 web_profiles_.push_back(std::move(profile)); | 166 web_profiles_.push_back(std::move(profile)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void AddCreditCard(std::unique_ptr<CreditCard> credit_card) { | 169 void AddCreditCard(std::unique_ptr<CreditCard> credit_card) { |
| 169 credit_card->set_modification_date(base::Time::Now()); | 170 credit_card->set_modification_date(AutofillClock::Now()); |
| 170 local_credit_cards_.push_back(std::move(credit_card)); | 171 local_credit_cards_.push_back(std::move(credit_card)); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void RecordUseOf(const AutofillDataModel& data_model) override { | 174 void RecordUseOf(const AutofillDataModel& data_model) override { |
| 174 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 175 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); |
| 175 if (credit_card) | 176 if (credit_card) |
| 176 credit_card->RecordAndLogUse(); | 177 credit_card->RecordAndLogUse(); |
| 177 | 178 |
| 178 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); | 179 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); |
| 179 if (profile) | 180 if (profile) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 276 } |
| 276 | 277 |
| 277 void CreateTestCreditCards( | 278 void CreateTestCreditCards( |
| 278 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { | 279 std::vector<std::unique_ptr<CreditCard>>* credit_cards) { |
| 279 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 280 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 280 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 281 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 281 "4234567890123456", // Visa | 282 "4234567890123456", // Visa |
| 282 "04", "2999"); | 283 "04", "2999"); |
| 283 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); | 284 credit_card->set_guid("00000000-0000-0000-0000-000000000004"); |
| 284 credit_card->set_use_count(10); | 285 credit_card->set_use_count(10); |
| 285 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); | 286 credit_card->set_use_date(AutofillClock::Now() - |
| 287 base::TimeDelta::FromDays(5)); |
| 286 credit_cards->push_back(std::move(credit_card)); | 288 credit_cards->push_back(std::move(credit_card)); |
| 287 | 289 |
| 288 credit_card = base::MakeUnique<CreditCard>(); | 290 credit_card = base::MakeUnique<CreditCard>(); |
| 289 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", | 291 test::SetCreditCardInfo(credit_card.get(), "Buddy Holly", |
| 290 "5187654321098765", // Mastercard | 292 "5187654321098765", // Mastercard |
| 291 "10", "2998"); | 293 "10", "2998"); |
| 292 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); | 294 credit_card->set_guid("00000000-0000-0000-0000-000000000005"); |
| 293 credit_card->set_use_count(5); | 295 credit_card->set_use_count(5); |
| 294 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); | 296 credit_card->set_use_date(AutofillClock::Now() - |
| 297 base::TimeDelta::FromDays(4)); |
| 295 credit_cards->push_back(std::move(credit_card)); | 298 credit_cards->push_back(std::move(credit_card)); |
| 296 | 299 |
| 297 credit_card = base::MakeUnique<CreditCard>(); | 300 credit_card = base::MakeUnique<CreditCard>(); |
| 298 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); | 301 test::SetCreditCardInfo(credit_card.get(), "", "", "", ""); |
| 299 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); | 302 credit_card->set_guid("00000000-0000-0000-0000-000000000006"); |
| 300 credit_cards->push_back(std::move(credit_card)); | 303 credit_cards->push_back(std::move(credit_card)); |
| 301 } | 304 } |
| 302 | 305 |
| 303 size_t num_times_save_imported_profile_called_; | 306 size_t num_times_save_imported_profile_called_; |
| 304 | 307 |
| (...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 // Test that we return all credit card suggestions in the case that two cards | 1779 // Test that we return all credit card suggestions in the case that two cards |
| 1777 // have the same obfuscated number. | 1780 // have the same obfuscated number. |
| 1778 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { | 1781 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { |
| 1779 // Add a credit card with the same obfuscated number as Elvis's. | 1782 // Add a credit card with the same obfuscated number as Elvis's. |
| 1780 // |credit_card| will be owned by the mock PersonalDataManager. | 1783 // |credit_card| will be owned by the mock PersonalDataManager. |
| 1781 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 1784 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
| 1782 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 1785 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
| 1783 "5231567890123456", // Mastercard | 1786 "5231567890123456", // Mastercard |
| 1784 "05", "2999"); | 1787 "05", "2999"); |
| 1785 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); | 1788 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); |
| 1786 credit_card->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(15)); | 1789 credit_card->set_use_date(AutofillClock::Now() - |
| 1790 base::TimeDelta::FromDays(15)); |
| 1787 autofill_manager_->AddCreditCard(std::move(credit_card)); | 1791 autofill_manager_->AddCreditCard(std::move(credit_card)); |
| 1788 | 1792 |
| 1789 // Set up our form data. | 1793 // Set up our form data. |
| 1790 FormData form; | 1794 FormData form; |
| 1791 CreateTestCreditCardFormData(&form, true, false); | 1795 CreateTestCreditCardFormData(&form, true, false); |
| 1792 std::vector<FormData> forms(1, form); | 1796 std::vector<FormData> forms(1, form); |
| 1793 FormsSeen(forms); | 1797 FormsSeen(forms); |
| 1794 | 1798 |
| 1795 FormFieldData field = form.fields[1]; | 1799 FormFieldData field = form.fields[1]; |
| 1796 GetAutofillSuggestions(form, field); | 1800 GetAutofillSuggestions(form, field); |
| (...skipping 3786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5583 | 5587 |
| 5584 // The driver should always be notified. | 5588 // The driver should always be notified. |
| 5585 for (const FormFieldData& field : form.fields) { | 5589 for (const FormFieldData& field : form.fields) { |
| 5586 GetAutofillSuggestions(form, field); | 5590 GetAutofillSuggestions(form, field); |
| 5587 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); | 5591 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); |
| 5588 autofill_driver_->ClearDidInteractWithCreditCardForm(); | 5592 autofill_driver_->ClearDidInteractWithCreditCardForm(); |
| 5589 } | 5593 } |
| 5590 } | 5594 } |
| 5591 | 5595 |
| 5592 } // namespace autofill | 5596 } // namespace autofill |
| OLD | NEW |