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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 #include "components/metrics/proto/ukm/entry.pb.h" | 53 #include "components/metrics/proto/ukm/entry.pb.h" |
54 #include "components/prefs/pref_service.h" | 54 #include "components/prefs/pref_service.h" |
55 #include "components/rappor/test_rappor_service.h" | 55 #include "components/rappor/test_rappor_service.h" |
56 #include "components/security_state/core/security_state.h" | 56 #include "components/security_state/core/security_state.h" |
57 #include "components/strings/grit/components_strings.h" | 57 #include "components/strings/grit/components_strings.h" |
58 #include "components/ukm/test_ukm_service.h" | 58 #include "components/ukm/test_ukm_service.h" |
59 #include "components/ukm/ukm_entry.h" | 59 #include "components/ukm/ukm_entry.h" |
60 #include "components/ukm/ukm_source.h" | 60 #include "components/ukm/ukm_source.h" |
61 #include "components/variations/variations_associated_data.h" | 61 #include "components/variations/variations_associated_data.h" |
62 #include "net/base/url_util.h" | 62 #include "net/base/url_util.h" |
63 #include "net/url_request/url_request_context_getter.h" | |
63 #include "net/url_request/url_request_test_util.h" | 64 #include "net/url_request/url_request_test_util.h" |
64 #include "testing/gmock/include/gmock/gmock.h" | 65 #include "testing/gmock/include/gmock/gmock.h" |
65 #include "testing/gtest/include/gtest/gtest.h" | 66 #include "testing/gtest/include/gtest/gtest.h" |
66 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
67 #include "ui/gfx/geometry/rect.h" | 68 #include "ui/gfx/geometry/rect.h" |
68 #include "url/gurl.h" | 69 #include "url/gurl.h" |
69 | 70 |
70 using base::ASCIIToUTF16; | 71 using base::ASCIIToUTF16; |
71 using base::UTF8ToUTF16; | 72 using base::UTF8ToUTF16; |
72 using testing::_; | 73 using testing::_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 const std::string& app_locale) override { | 115 const std::string& app_locale) override { |
115 delegate_->OnDidGetUploadDetails( | 116 delegate_->OnDidGetUploadDetails( |
116 app_locale == "en-US" ? AutofillClient::SUCCESS | 117 app_locale == "en-US" ? AutofillClient::SUCCESS |
117 : AutofillClient::PERMANENT_FAILURE, | 118 : AutofillClient::PERMANENT_FAILURE, |
118 ASCIIToUTF16("this is a context token"), | 119 ASCIIToUTF16("this is a context token"), |
119 std::unique_ptr<base::DictionaryValue>(nullptr)); | 120 std::unique_ptr<base::DictionaryValue>(nullptr)); |
120 } | 121 } |
121 | 122 |
122 void UploadCard(const payments::PaymentsClient::UploadRequestDetails& | 123 void UploadCard(const payments::PaymentsClient::UploadRequestDetails& |
123 request_details) override { | 124 request_details) override { |
124 delegate_->OnDidUploadCard(AutofillClient::SUCCESS); | 125 delegate_->OnDidUploadCard(AutofillClient::SUCCESS, server_id_); |
125 } | 126 } |
126 | 127 |
128 std::string server_id_; | |
129 | |
127 private: | 130 private: |
128 payments::PaymentsClientDelegate* const delegate_; | 131 payments::PaymentsClientDelegate* const delegate_; |
129 | 132 |
130 DISALLOW_COPY_AND_ASSIGN(TestPaymentsClient); | 133 DISALLOW_COPY_AND_ASSIGN(TestPaymentsClient); |
131 }; | 134 }; |
132 | 135 |
133 class TestPersonalDataManager : public PersonalDataManager { | 136 class TestPersonalDataManager : public PersonalDataManager { |
Mathieu
2017/04/24 18:11:55
I wonder if we could subclass components/autofill/
csashi
2017/04/24 18:30:06
Looks like the savings would be minimal and we wou
| |
134 public: | 137 public: |
135 TestPersonalDataManager() | 138 TestPersonalDataManager() |
136 : PersonalDataManager("en-US"), | 139 : PersonalDataManager("en-US"), |
137 num_times_save_imported_profile_called_(0) { | 140 num_times_save_imported_profile_called_(0) { |
138 CreateTestAutofillProfiles(&web_profiles_); | 141 CreateTestAutofillProfiles(&web_profiles_); |
139 CreateTestCreditCards(&local_credit_cards_); | 142 CreateTestCreditCards(&local_credit_cards_); |
140 } | 143 } |
141 | 144 |
142 using PersonalDataManager::set_database; | 145 using PersonalDataManager::set_database; |
143 using PersonalDataManager::SetPrefService; | 146 using PersonalDataManager::SetPrefService; |
(...skipping 29 matching lines...) Expand all Loading... | |
173 web_profiles_.push_back(std::move(profile)); | 176 web_profiles_.push_back(std::move(profile)); |
174 } | 177 } |
175 | 178 |
176 void AddCreditCard(const CreditCard& credit_card) override { | 179 void AddCreditCard(const CreditCard& credit_card) override { |
177 std::unique_ptr<CreditCard> local_credit_card = | 180 std::unique_ptr<CreditCard> local_credit_card = |
178 base::MakeUnique<CreditCard>(credit_card); | 181 base::MakeUnique<CreditCard>(credit_card); |
179 local_credit_card->set_modification_date(base::Time::Now()); | 182 local_credit_card->set_modification_date(base::Time::Now()); |
180 local_credit_cards_.push_back(std::move(local_credit_card)); | 183 local_credit_cards_.push_back(std::move(local_credit_card)); |
181 } | 184 } |
182 | 185 |
186 void AddServerCreditCard(const CreditCard& credit_card) override { | |
187 std::unique_ptr<CreditCard> server_credit_card = | |
188 base::MakeUnique<CreditCard>(credit_card); | |
189 server_credit_card->set_modification_date(base::Time::Now()); | |
190 server_credit_cards_.push_back(std::move(server_credit_card)); | |
191 } | |
192 | |
183 void RecordUseOf(const AutofillDataModel& data_model) override { | 193 void RecordUseOf(const AutofillDataModel& data_model) override { |
184 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); | 194 CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); |
185 if (credit_card) | 195 if (credit_card) |
186 credit_card->RecordAndLogUse(); | 196 credit_card->RecordAndLogUse(); |
187 | 197 |
188 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); | 198 AutofillProfile* profile = GetProfileWithGUID(data_model.guid().c_str()); |
189 if (profile) | 199 if (profile) |
190 profile->RecordAndLogUse(); | 200 profile->RecordAndLogUse(); |
191 } | 201 } |
192 | 202 |
(...skipping 16 matching lines...) Expand all Loading... | |
209 })); | 219 })); |
210 } | 220 } |
211 } | 221 } |
212 | 222 |
213 void ClearAutofillProfiles() { | 223 void ClearAutofillProfiles() { |
214 web_profiles_.clear(); | 224 web_profiles_.clear(); |
215 } | 225 } |
216 | 226 |
217 void ClearCreditCards() { | 227 void ClearCreditCards() { |
218 local_credit_cards_.clear(); | 228 local_credit_cards_.clear(); |
229 server_credit_cards_.clear(); | |
219 } | 230 } |
220 | 231 |
221 // Create Elvis card with whitespace in the credit card number. | 232 // Create Elvis card with whitespace in the credit card number. |
222 void CreateTestCreditCardWithWhitespace() { | 233 void CreateTestCreditCardWithWhitespace() { |
223 ClearCreditCards(); | 234 ClearCreditCards(); |
224 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); | 235 std::unique_ptr<CreditCard> credit_card = base::MakeUnique<CreditCard>(); |
225 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", | 236 test::SetCreditCardInfo(credit_card.get(), "Elvis Presley", |
226 "4234 5678 9012 3456", // Visa | 237 "4234 5678 9012 3456", // Visa |
227 "04", "2999"); | 238 "04", "2999"); |
228 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); | 239 credit_card->set_guid("00000000-0000-0000-0000-000000000008"); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 539 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
529 }; | 540 }; |
530 | 541 |
531 class TestAutofillManager : public AutofillManager { | 542 class TestAutofillManager : public AutofillManager { |
532 public: | 543 public: |
533 TestAutofillManager(AutofillDriver* driver, | 544 TestAutofillManager(AutofillDriver* driver, |
534 AutofillClient* client, | 545 AutofillClient* client, |
535 TestPersonalDataManager* personal_data) | 546 TestPersonalDataManager* personal_data) |
536 : AutofillManager(driver, client, personal_data), | 547 : AutofillManager(driver, client, personal_data), |
537 personal_data_(personal_data), | 548 personal_data_(personal_data), |
549 context_getter_(driver->GetURLRequestContext()), | |
538 autofill_enabled_(true), | 550 autofill_enabled_(true), |
539 credit_card_upload_enabled_(false), | 551 credit_card_upload_enabled_(false), |
540 credit_card_was_uploaded_(false), | 552 credit_card_was_uploaded_(false), |
541 expected_observed_submission_(true) { | 553 expected_observed_submission_(true) { |
542 set_payments_client( | 554 set_payments_client(new TestPaymentsClient(context_getter_, this)); |
543 new TestPaymentsClient(driver->GetURLRequestContext(), this)); | |
544 } | 555 } |
545 ~TestAutofillManager() override {} | 556 ~TestAutofillManager() override {} |
546 | 557 |
547 bool IsAutofillEnabled() const override { return autofill_enabled_; } | 558 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
548 | 559 |
549 void set_autofill_enabled(bool autofill_enabled) { | 560 void set_autofill_enabled(bool autofill_enabled) { |
550 autofill_enabled_ = autofill_enabled; | 561 autofill_enabled_ = autofill_enabled; |
551 } | 562 } |
552 | 563 |
553 bool IsCreditCardUploadEnabled() override { | 564 bool IsCreditCardUploadEnabled() override { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 } | 633 } |
623 | 634 |
624 AutofillProfile* GetProfileWithGUID(const char* guid) { | 635 AutofillProfile* GetProfileWithGUID(const char* guid) { |
625 return personal_data_->GetProfileWithGUID(guid); | 636 return personal_data_->GetProfileWithGUID(guid); |
626 } | 637 } |
627 | 638 |
628 CreditCard* GetCreditCardWithGUID(const char* guid) { | 639 CreditCard* GetCreditCardWithGUID(const char* guid) { |
629 return personal_data_->GetCreditCardWithGUID(guid); | 640 return personal_data_->GetCreditCardWithGUID(guid); |
630 } | 641 } |
631 | 642 |
643 std::vector<CreditCard*> GetLocalCreditCards() const { | |
644 return personal_data_->GetLocalCreditCards(); | |
645 } | |
646 | |
647 const std::vector<CreditCard*>& GetCreditCards() const { | |
648 return personal_data_->GetCreditCards(); | |
649 } | |
650 | |
632 void AddProfile(std::unique_ptr<AutofillProfile> profile) { | 651 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
633 personal_data_->AddProfile(std::move(profile)); | 652 personal_data_->AddProfile(std::move(profile)); |
634 } | 653 } |
635 | 654 |
636 void AddCreditCard(const CreditCard& credit_card) { | 655 void AddCreditCard(const CreditCard& credit_card) { |
637 personal_data_->AddCreditCard(credit_card); | 656 personal_data_->AddCreditCard(credit_card); |
638 } | 657 } |
639 | 658 |
640 int GetPackedCreditCardID(int credit_card_id) { | 659 int GetPackedCreditCardID(int credit_card_id) { |
641 std::string credit_card_guid = | 660 std::string credit_card_guid = |
642 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 661 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
643 | 662 |
644 return MakeFrontendID(credit_card_guid, std::string()); | 663 return MakeFrontendID(credit_card_guid, std::string()); |
645 } | 664 } |
646 | 665 |
647 void AddSeenForm(std::unique_ptr<FormStructure> form) { | 666 void AddSeenForm(std::unique_ptr<FormStructure> form) { |
648 form_structures()->push_back(std::move(form)); | 667 form_structures()->push_back(std::move(form)); |
649 } | 668 } |
650 | 669 |
651 void ClearFormStructures() { | 670 void ClearFormStructures() { |
652 form_structures()->clear(); | 671 form_structures()->clear(); |
653 } | 672 } |
654 | 673 |
674 void ResetPaymentsClientForCardUpload(const char* server_id) { | |
675 TestPaymentsClient* payments_client = | |
676 new TestPaymentsClient(context_getter_, this); | |
677 payments_client->server_id_ = server_id; | |
678 set_payments_client(payments_client); | |
679 } | |
680 | |
655 private: | 681 private: |
656 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { | 682 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result, |
683 const std::string& server_id) override { | |
657 credit_card_was_uploaded_ = true; | 684 credit_card_was_uploaded_ = true; |
685 AutofillManager::OnDidUploadCard(result, server_id); | |
658 }; | 686 }; |
659 | 687 |
660 // Weak reference. | 688 TestPersonalDataManager* personal_data_; // Weak reference. |
661 TestPersonalDataManager* personal_data_; | 689 net::URLRequestContextGetter* context_getter_; // Weak reference. |
662 | |
663 bool autofill_enabled_; | 690 bool autofill_enabled_; |
664 bool credit_card_upload_enabled_; | 691 bool credit_card_upload_enabled_; |
665 bool credit_card_was_uploaded_; | 692 bool credit_card_was_uploaded_; |
666 bool expected_observed_submission_; | 693 bool expected_observed_submission_; |
667 | 694 |
668 std::unique_ptr<base::RunLoop> run_loop_; | 695 std::unique_ptr<base::RunLoop> run_loop_; |
669 | 696 |
670 std::string submitted_form_signature_; | 697 std::string submitted_form_signature_; |
671 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; | 698 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; |
672 | 699 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 EXPECT_EQ(expected_suggestions[i].label, suggestions_[i].label); | 739 EXPECT_EQ(expected_suggestions[i].label, suggestions_[i].label); |
713 EXPECT_EQ(expected_suggestions[i].icon, suggestions_[i].icon); | 740 EXPECT_EQ(expected_suggestions[i].icon, suggestions_[i].icon); |
714 EXPECT_EQ(expected_suggestions[i].frontend_id, | 741 EXPECT_EQ(expected_suggestions[i].frontend_id, |
715 suggestions_[i].frontend_id); | 742 suggestions_[i].frontend_id); |
716 } | 743 } |
717 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); | 744 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
718 } | 745 } |
719 | 746 |
720 // Wrappers around the above GetSuggestions call that take a hardcoded number | 747 // Wrappers around the above GetSuggestions call that take a hardcoded number |
721 // of expected results so callsites are cleaner. | 748 // of expected results so callsites are cleaner. |
722 void CheckSuggestions(int expected_page_id, | 749 void CheckSuggestions(int expected_page_id, const Suggestion& suggestion0) { |
723 const Suggestion& suggestion0) { | |
724 std::vector<Suggestion> suggestion_vector; | 750 std::vector<Suggestion> suggestion_vector; |
725 suggestion_vector.push_back(suggestion0); | 751 suggestion_vector.push_back(suggestion0); |
726 CheckSuggestions(expected_page_id, 1, &suggestion_vector[0]); | 752 CheckSuggestions(expected_page_id, 1, &suggestion_vector[0]); |
727 } | 753 } |
728 void CheckSuggestions(int expected_page_id, | 754 void CheckSuggestions(int expected_page_id, |
729 const Suggestion& suggestion0, | 755 const Suggestion& suggestion0, |
730 const Suggestion& suggestion1) { | 756 const Suggestion& suggestion1) { |
731 std::vector<Suggestion> suggestion_vector; | 757 std::vector<Suggestion> suggestion_vector; |
732 suggestion_vector.push_back(suggestion0); | 758 suggestion_vector.push_back(suggestion0); |
733 suggestion_vector.push_back(suggestion1); | 759 suggestion_vector.push_back(suggestion1); |
(...skipping 18 matching lines...) Expand all Loading... | |
752 // and contain a specific number of suggestions. | 778 // and contain a specific number of suggestions. |
753 void CheckSuggestionCount(int expected_page_id, | 779 void CheckSuggestionCount(int expected_page_id, |
754 size_t expected_num_suggestions) { | 780 size_t expected_num_suggestions) { |
755 // Ensure that these results are from the most recent query. | 781 // Ensure that these results are from the most recent query. |
756 EXPECT_TRUE(on_suggestions_returned_seen_); | 782 EXPECT_TRUE(on_suggestions_returned_seen_); |
757 | 783 |
758 EXPECT_EQ(expected_page_id, query_id_); | 784 EXPECT_EQ(expected_page_id, query_id_); |
759 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); | 785 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
760 } | 786 } |
761 | 787 |
762 bool on_query_seen() const { | 788 bool on_query_seen() const { return on_query_seen_; } |
763 return on_query_seen_; | |
764 } | |
765 | 789 |
766 bool on_suggestions_returned_seen() const { | 790 bool on_suggestions_returned_seen() const { |
767 return on_suggestions_returned_seen_; | 791 return on_suggestions_returned_seen_; |
768 } | 792 } |
769 | 793 |
770 private: | 794 private: |
771 // Records if OnQuery has been called yet. | 795 // Records if OnQuery has been called yet. |
772 bool on_query_seen_; | 796 bool on_query_seen_; |
773 | 797 |
774 // Records if OnSuggestionsReturned has been called after the most recent | 798 // Records if OnSuggestionsReturned has been called after the most recent |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 void TearDown() override { | 860 void TearDown() override { |
837 // Order of destruction is important as AutofillManager relies on | 861 // Order of destruction is important as AutofillManager relies on |
838 // PersonalDataManager to be around when it gets destroyed. | 862 // PersonalDataManager to be around when it gets destroyed. |
839 autofill_manager_.reset(); | 863 autofill_manager_.reset(); |
840 autofill_driver_.reset(); | 864 autofill_driver_.reset(); |
841 | 865 |
842 // Remove the AutofillWebDataService so TestPersonalDataManager does not | 866 // Remove the AutofillWebDataService so TestPersonalDataManager does not |
843 // need to care about removing self as an observer in destruction. | 867 // need to care about removing self as an observer in destruction. |
844 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); | 868 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); |
845 personal_data_.SetPrefService(NULL); | 869 personal_data_.SetPrefService(NULL); |
870 personal_data_.ClearCreditCards(); | |
846 | 871 |
847 request_context_ = nullptr; | 872 request_context_ = nullptr; |
848 } | 873 } |
849 | 874 |
850 void GetAutofillSuggestions(int query_id, | 875 void GetAutofillSuggestions(int query_id, |
851 const FormData& form, | 876 const FormData& form, |
852 const FormFieldData& field) { | 877 const FormFieldData& field) { |
853 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field, | 878 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field, |
854 gfx::RectF()); | 879 gfx::RectF()); |
855 } | 880 } |
856 | 881 |
857 void GetAutofillSuggestions(const FormData& form, | 882 void GetAutofillSuggestions(const FormData& form, |
858 const FormFieldData& field) { | 883 const FormFieldData& field) { |
859 GetAutofillSuggestions(kDefaultPageID, form, field); | 884 GetAutofillSuggestions(kDefaultPageID, form, field); |
860 } | 885 } |
861 | 886 |
862 void AutocompleteSuggestionsReturned( | 887 void AutocompleteSuggestionsReturned( |
863 const std::vector<base::string16>& result) { | 888 const std::vector<base::string16>& result) { |
864 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); | 889 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
865 } | 890 } |
866 | 891 |
867 void FormsSeen(const std::vector<FormData>& forms) { | 892 void FormsSeen(const std::vector<FormData>& forms) { |
868 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 893 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
869 } | 894 } |
870 | 895 |
871 void FormSubmitted(const FormData& form) { | 896 void FormSubmitted(const FormData& form) { |
872 autofill_manager_->ResetRunLoop(); | 897 autofill_manager_->ResetRunLoop(); |
873 if (autofill_manager_->OnWillSubmitForm(form, base::TimeTicks::Now())) | 898 if (autofill_manager_->OnWillSubmitForm(form, base::TimeTicks::Now()) && |
899 (!personal_data_.GetProfiles().empty() || | |
900 !personal_data_.GetCreditCards().empty())) | |
874 autofill_manager_->WaitForAsyncUploadProcess(); | 901 autofill_manager_->WaitForAsyncUploadProcess(); |
875 autofill_manager_->OnFormSubmitted(form); | 902 autofill_manager_->OnFormSubmitted(form); |
876 } | 903 } |
877 | 904 |
878 void FillAutofillFormData(int query_id, | 905 void FillAutofillFormData(int query_id, |
879 const FormData& form, | 906 const FormData& form, |
880 const FormFieldData& field, | 907 const FormFieldData& field, |
881 int unique_id) { | 908 int unique_id) { |
882 autofill_manager_->FillOrPreviewForm( | 909 autofill_manager_->FillOrPreviewForm( |
883 AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field, | 910 AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1112 EXPECT_EQ(expected_num_matching_entries, num_matching_entries); | 1139 EXPECT_EQ(expected_num_matching_entries, num_matching_entries); |
1113 } | 1140 } |
1114 | 1141 |
1115 protected: | 1142 protected: |
1116 base::test::ScopedTaskEnvironment scoped_task_environment_; | 1143 base::test::ScopedTaskEnvironment scoped_task_environment_; |
1117 MockAutofillClient autofill_client_; | 1144 MockAutofillClient autofill_client_; |
1118 std::unique_ptr<MockAutofillDriver> autofill_driver_; | 1145 std::unique_ptr<MockAutofillDriver> autofill_driver_; |
1119 std::unique_ptr<TestAutofillManager> autofill_manager_; | 1146 std::unique_ptr<TestAutofillManager> autofill_manager_; |
1120 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; | 1147 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; |
1121 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 1148 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
1122 TestPaymentsClient* payments_client_; | |
1123 TestAutofillDownloadManager* download_manager_; | 1149 TestAutofillDownloadManager* download_manager_; |
1124 TestPersonalDataManager personal_data_; | 1150 TestPersonalDataManager personal_data_; |
1125 base::FieldTrialList field_trial_list_; | 1151 base::FieldTrialList field_trial_list_; |
1126 base::test::ScopedFeatureList scoped_feature_list_; | 1152 base::test::ScopedFeatureList scoped_feature_list_; |
1127 }; | 1153 }; |
1128 | 1154 |
1129 class TestFormStructure : public FormStructure { | 1155 class TestFormStructure : public FormStructure { |
1130 public: | 1156 public: |
1131 explicit TestFormStructure(const FormData& form) | 1157 explicit TestFormStructure(const FormData& form) |
1132 : FormStructure(form) {} | 1158 : FormStructure(form) {} |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1771 "04/99", kVisaCard, | 1797 "04/99", kVisaCard, |
1772 autofill_manager_->GetPackedCreditCardID(4)), | 1798 autofill_manager_->GetPackedCreditCardID(4)), |
1773 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1799 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", |
1774 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1800 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); |
1775 } | 1801 } |
1776 | 1802 |
1777 // Test that we will eventually return the credit card signin promo when there | 1803 // Test that we will eventually return the credit card signin promo when there |
1778 // are no credit card suggestions and the promo is active. See the tests in | 1804 // are no credit card suggestions and the promo is active. See the tests in |
1779 // AutofillExternalDelegateTest that test whether the promo is added. | 1805 // AutofillExternalDelegateTest that test whether the promo is added. |
1780 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { | 1806 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { |
1781 // Make sure there are no credit cards. | |
1782 personal_data_.ClearCreditCards(); | 1807 personal_data_.ClearCreditCards(); |
1783 | 1808 |
1784 // Set up our form data. | 1809 // Set up our form data. |
1785 FormData form; | 1810 FormData form; |
1786 CreateTestCreditCardFormData(&form, true, false); | 1811 CreateTestCreditCardFormData(&form, true, false); |
1787 std::vector<FormData> forms(1, form); | 1812 std::vector<FormData> forms(1, form); |
1788 FormsSeen(forms); | 1813 FormsSeen(forms); |
1789 FormFieldData field = form.fields[1]; | 1814 FormFieldData field = form.fields[1]; |
1790 | 1815 |
1791 ON_CALL(autofill_client_, ShouldShowSigninPromo()) | 1816 ON_CALL(autofill_client_, ShouldShowSigninPromo()) |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2328 &response_page_id, &response_data); | 2353 &response_page_id, &response_data); |
2329 ExpectFilledCreditCardYearMonthWithYearMonth( | 2354 ExpectFilledCreditCardYearMonthWithYearMonth( |
2330 response_page_id, response_data, kDefaultPageID, false, "2999", ""); | 2355 response_page_id, response_data, kDefaultPageID, false, "2999", ""); |
2331 } | 2356 } |
2332 | 2357 |
2333 // Test that we correctly fill a credit card form with month input type. | 2358 // Test that we correctly fill a credit card form with month input type. |
2334 // 4. year non-empty, month empty | 2359 // 4. year non-empty, month empty |
2335 TEST_F(AutofillManagerTest, FillCreditCardForm_YearMonth) { | 2360 TEST_F(AutofillManagerTest, FillCreditCardForm_YearMonth) { |
2336 // Same as the SetUp(), but generate 4 credit cards with year month | 2361 // Same as the SetUp(), but generate 4 credit cards with year month |
2337 // combination. | 2362 // combination. |
2338 personal_data_.ClearCreditCards(); | |
2339 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); | 2363 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); |
2340 // Set up our form data. | 2364 // Set up our form data. |
2341 FormData form; | 2365 FormData form; |
2342 CreateTestCreditCardFormData(&form, true, true); | 2366 CreateTestCreditCardFormData(&form, true, true); |
2343 std::vector<FormData> forms(1, form); | 2367 std::vector<FormData> forms(1, form); |
2344 FormsSeen(forms); | 2368 FormsSeen(forms); |
2345 | 2369 |
2346 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2370 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
2347 int response_page_id = 0; | 2371 int response_page_id = 0; |
2348 FormData response_data; | 2372 FormData response_data; |
(...skipping 2227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4576 } | 4600 } |
4577 | 4601 |
4578 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4602 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
4579 #if defined(OS_ANDROID) | 4603 #if defined(OS_ANDROID) |
4580 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard | 4604 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard |
4581 #else | 4605 #else |
4582 #define MAYBE_UploadCreditCard UploadCreditCard | 4606 #define MAYBE_UploadCreditCard UploadCreditCard |
4583 #endif | 4607 #endif |
4584 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { | 4608 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { |
4585 EnableUkmLogging(); | 4609 EnableUkmLogging(); |
4610 personal_data_.ClearCreditCards(); | |
4586 personal_data_.ClearAutofillProfiles(); | 4611 personal_data_.ClearAutofillProfiles(); |
4587 autofill_manager_->set_credit_card_upload_enabled(true); | 4612 autofill_manager_->set_credit_card_upload_enabled(true); |
4588 | 4613 |
4589 // Create, fill and submit an address form in order to establish a recent | 4614 // Create, fill and submit an address form in order to establish a recent |
4590 // profile which can be selected for the upload request. | 4615 // profile which can be selected for the upload request. |
4591 FormData address_form; | 4616 FormData address_form; |
4592 test::CreateTestAddressFormData(&address_form); | 4617 test::CreateTestAddressFormData(&address_form); |
4593 FormsSeen(std::vector<FormData>(1, address_form)); | 4618 FormsSeen(std::vector<FormData>(1, address_form)); |
4594 ExpectUniqueFillableFormParsedUkm(); | 4619 ExpectUniqueFillableFormParsedUkm(); |
4595 | 4620 |
(...skipping 11 matching lines...) Expand all Loading... | |
4607 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 4632 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
4608 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 4633 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
4609 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 4634 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
4610 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4635 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
4611 | 4636 |
4612 base::HistogramTester histogram_tester; | 4637 base::HistogramTester histogram_tester; |
4613 | 4638 |
4614 FormSubmitted(credit_card_form); | 4639 FormSubmitted(credit_card_form); |
4615 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4640 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
4616 | 4641 |
4642 // Server did not send a server_id, expect copy of card is not stored. | |
4643 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); | |
4644 | |
4617 // Verify that the correct histogram entry (and only that) was logged. | 4645 // Verify that the correct histogram entry (and only that) was logged. |
4618 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", | 4646 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", |
4619 AutofillMetrics::UPLOAD_OFFERED, 1); | 4647 AutofillMetrics::UPLOAD_OFFERED, 1); |
4620 // Verify that the correct UKM was logged. | 4648 // Verify that the correct UKM was logged. |
4621 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 4649 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
4622 } | 4650 } |
4623 | 4651 |
4624 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4652 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
4625 #if defined(OS_ANDROID) | 4653 #if defined(OS_ANDROID) |
4654 #define MAYBE_UploadCreditCardAndSaveCopy DISABLED_UploadCreditCardAndSaveCopy | |
4655 #else | |
4656 #define MAYBE_UploadCreditCardAndSaveCopy UploadCreditCardAndSaveCopy | |
4657 #endif | |
4658 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCardAndSaveCopy) { | |
4659 personal_data_.ClearCreditCards(); | |
4660 personal_data_.ClearAutofillProfiles(); | |
4661 autofill_manager_->set_credit_card_upload_enabled(true); | |
4662 | |
4663 const char* const server_id = "InstrumentData:1234"; | |
4664 autofill_manager_->ResetPaymentsClientForCardUpload(server_id); | |
4665 | |
4666 // Create, fill and submit an address form in order to establish a recent | |
4667 // profile which can be selected for the upload request. | |
4668 FormData address_form; | |
4669 test::CreateTestAddressFormData(&address_form); | |
4670 FormsSeen(std::vector<FormData>(1, address_form)); | |
4671 | |
4672 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); | |
4673 FormSubmitted(address_form); | |
4674 | |
4675 // Set up our credit card form data. | |
4676 FormData credit_card_form; | |
4677 CreateTestCreditCardFormData(&credit_card_form, true, false); | |
4678 FormsSeen(std::vector<FormData>(1, credit_card_form)); | |
4679 | |
4680 // Edit the data, and submit. | |
4681 const char* const card_number = "4111111111111111"; | |
4682 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); | |
4683 credit_card_form.fields[1].value = ASCIIToUTF16(card_number); | |
4684 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | |
4685 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | |
4686 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | |
4687 | |
4688 FormSubmitted(credit_card_form); | |
4689 | |
4690 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | |
4691 EXPECT_TRUE(autofill_manager_->GetLocalCreditCards().empty()); | |
4692 ASSERT_EQ(1U, autofill_manager_->GetCreditCards().size()); | |
4693 const CreditCard* const saved_card = autofill_manager_->GetCreditCards()[0]; | |
4694 EXPECT_EQ(CreditCard::OK, saved_card->GetServerStatus()); | |
4695 EXPECT_EQ(base::ASCIIToUTF16("1111"), saved_card->LastFourDigits()); | |
4696 EXPECT_EQ(kVisaCard, saved_card->type()); | |
4697 EXPECT_EQ(11, saved_card->expiration_month()); | |
4698 EXPECT_EQ(2017, saved_card->expiration_year()); | |
4699 EXPECT_EQ(server_id, saved_card->server_id()); | |
4700 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, saved_card->record_type()); | |
4701 EXPECT_EQ(base::ASCIIToUTF16(card_number), saved_card->number()); | |
4702 } | |
4703 | |
4704 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | |
4705 #if defined(OS_ANDROID) | |
4626 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu reNotEnabled | 4706 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu reNotEnabled |
4627 #else | 4707 #else |
4628 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab led | 4708 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab led |
4629 #endif | 4709 #endif |
4630 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { | 4710 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { |
4631 personal_data_.ClearAutofillProfiles(); | 4711 personal_data_.ClearAutofillProfiles(); |
4632 autofill_manager_->set_credit_card_upload_enabled(false); | 4712 autofill_manager_->set_credit_card_upload_enabled(false); |
4633 | 4713 |
4634 // Create, fill and submit an address form in order to establish a recent | 4714 // Create, fill and submit an address form in order to establish a recent |
4635 // profile which can be selected for the upload request. | 4715 // profile which can be selected for the upload request. |
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6081 autofill_manager_->StartUploadProcess(std::move(form_structure), | 6161 autofill_manager_->StartUploadProcess(std::move(form_structure), |
6082 base::TimeTicks::Now(), true); | 6162 base::TimeTicks::Now(), true); |
6083 | 6163 |
6084 // Wait for upload to complete (will check expected types as well). | 6164 // Wait for upload to complete (will check expected types as well). |
6085 autofill_manager_->WaitForAsyncUploadProcess(); | 6165 autofill_manager_->WaitForAsyncUploadProcess(); |
6086 | 6166 |
6087 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6167 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
6088 } | 6168 } |
6089 | 6169 |
6090 } // namespace autofill | 6170 } // namespace autofill |
OLD | NEW |