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 { |
134 public: | 137 public: |
135 TestPersonalDataManager() | 138 TestPersonalDataManager() |
136 : PersonalDataManager("en-US"), | 139 : PersonalDataManager("en-US"), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 AddFullServerCreditCard(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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 546 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
536 }; | 547 }; |
537 | 548 |
538 class TestAutofillManager : public AutofillManager { | 549 class TestAutofillManager : public AutofillManager { |
539 public: | 550 public: |
540 TestAutofillManager(AutofillDriver* driver, | 551 TestAutofillManager(AutofillDriver* driver, |
541 AutofillClient* client, | 552 AutofillClient* client, |
542 TestPersonalDataManager* personal_data) | 553 TestPersonalDataManager* personal_data) |
543 : AutofillManager(driver, client, personal_data), | 554 : AutofillManager(driver, client, personal_data), |
544 personal_data_(personal_data), | 555 personal_data_(personal_data), |
| 556 context_getter_(driver->GetURLRequestContext()), |
545 autofill_enabled_(true), | 557 autofill_enabled_(true), |
546 credit_card_upload_enabled_(false), | 558 credit_card_upload_enabled_(false), |
547 credit_card_was_uploaded_(false), | 559 credit_card_was_uploaded_(false), |
548 expected_observed_submission_(true), | 560 expected_observed_submission_(true), |
549 call_parent_upload_form_data_(false) { | 561 call_parent_upload_form_data_(false) { |
550 set_payments_client( | 562 set_payments_client(new TestPaymentsClient(context_getter_, this)); |
551 new TestPaymentsClient(driver->GetURLRequestContext(), this)); | |
552 } | 563 } |
553 ~TestAutofillManager() override {} | 564 ~TestAutofillManager() override {} |
554 | 565 |
555 bool IsAutofillEnabled() const override { return autofill_enabled_; } | 566 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
556 | 567 |
557 void set_autofill_enabled(bool autofill_enabled) { | 568 void set_autofill_enabled(bool autofill_enabled) { |
558 autofill_enabled_ = autofill_enabled; | 569 autofill_enabled_ = autofill_enabled; |
559 } | 570 } |
560 | 571 |
561 bool IsCreditCardUploadEnabled() override { | 572 bool IsCreditCardUploadEnabled() override { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 } | 648 } |
638 | 649 |
639 AutofillProfile* GetProfileWithGUID(const char* guid) { | 650 AutofillProfile* GetProfileWithGUID(const char* guid) { |
640 return personal_data_->GetProfileWithGUID(guid); | 651 return personal_data_->GetProfileWithGUID(guid); |
641 } | 652 } |
642 | 653 |
643 CreditCard* GetCreditCardWithGUID(const char* guid) { | 654 CreditCard* GetCreditCardWithGUID(const char* guid) { |
644 return personal_data_->GetCreditCardWithGUID(guid); | 655 return personal_data_->GetCreditCardWithGUID(guid); |
645 } | 656 } |
646 | 657 |
| 658 std::vector<CreditCard*> GetLocalCreditCards() const { |
| 659 return personal_data_->GetLocalCreditCards(); |
| 660 } |
| 661 |
| 662 const std::vector<CreditCard*>& GetCreditCards() const { |
| 663 return personal_data_->GetCreditCards(); |
| 664 } |
| 665 |
647 void AddProfile(std::unique_ptr<AutofillProfile> profile) { | 666 void AddProfile(std::unique_ptr<AutofillProfile> profile) { |
648 personal_data_->AddProfile(std::move(profile)); | 667 personal_data_->AddProfile(std::move(profile)); |
649 } | 668 } |
650 | 669 |
651 void AddCreditCard(const CreditCard& credit_card) { | 670 void AddCreditCard(const CreditCard& credit_card) { |
652 personal_data_->AddCreditCard(credit_card); | 671 personal_data_->AddCreditCard(credit_card); |
653 } | 672 } |
654 | 673 |
655 int GetPackedCreditCardID(int credit_card_id) { | 674 int GetPackedCreditCardID(int credit_card_id) { |
656 std::string credit_card_guid = | 675 std::string credit_card_guid = |
657 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 676 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
658 | 677 |
659 return MakeFrontendID(credit_card_guid, std::string()); | 678 return MakeFrontendID(credit_card_guid, std::string()); |
660 } | 679 } |
661 | 680 |
662 void AddSeenForm(std::unique_ptr<FormStructure> form) { | 681 void AddSeenForm(std::unique_ptr<FormStructure> form) { |
663 form_structures()->push_back(std::move(form)); | 682 form_structures()->push_back(std::move(form)); |
664 } | 683 } |
665 | 684 |
666 void ClearFormStructures() { | 685 void ClearFormStructures() { |
667 form_structures()->clear(); | 686 form_structures()->clear(); |
668 } | 687 } |
669 | 688 |
| 689 void ResetPaymentsClientForCardUpload(const char* server_id) { |
| 690 TestPaymentsClient* payments_client = |
| 691 new TestPaymentsClient(context_getter_, this); |
| 692 payments_client->server_id_ = server_id; |
| 693 set_payments_client(payments_client); |
| 694 } |
| 695 |
670 private: | 696 private: |
671 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override { | 697 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result, |
| 698 const std::string& server_id) override { |
672 credit_card_was_uploaded_ = true; | 699 credit_card_was_uploaded_ = true; |
| 700 AutofillManager::OnDidUploadCard(result, server_id); |
673 }; | 701 }; |
674 | 702 |
675 // Weak reference. | 703 TestPersonalDataManager* personal_data_; // Weak reference. |
676 TestPersonalDataManager* personal_data_; | 704 net::URLRequestContextGetter* context_getter_; // Weak reference. |
677 | |
678 bool autofill_enabled_; | 705 bool autofill_enabled_; |
679 bool credit_card_upload_enabled_; | 706 bool credit_card_upload_enabled_; |
680 bool credit_card_was_uploaded_; | 707 bool credit_card_was_uploaded_; |
681 bool expected_observed_submission_; | 708 bool expected_observed_submission_; |
682 bool call_parent_upload_form_data_; | 709 bool call_parent_upload_form_data_; |
683 | 710 |
684 std::unique_ptr<base::RunLoop> run_loop_; | 711 std::unique_ptr<base::RunLoop> run_loop_; |
685 | 712 |
686 std::string submitted_form_signature_; | 713 std::string submitted_form_signature_; |
687 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; | 714 std::vector<ServerFieldTypeSet> expected_submitted_field_types_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 EXPECT_EQ(expected_suggestions[i].label, suggestions_[i].label); | 755 EXPECT_EQ(expected_suggestions[i].label, suggestions_[i].label); |
729 EXPECT_EQ(expected_suggestions[i].icon, suggestions_[i].icon); | 756 EXPECT_EQ(expected_suggestions[i].icon, suggestions_[i].icon); |
730 EXPECT_EQ(expected_suggestions[i].frontend_id, | 757 EXPECT_EQ(expected_suggestions[i].frontend_id, |
731 suggestions_[i].frontend_id); | 758 suggestions_[i].frontend_id); |
732 } | 759 } |
733 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); | 760 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
734 } | 761 } |
735 | 762 |
736 // Wrappers around the above GetSuggestions call that take a hardcoded number | 763 // Wrappers around the above GetSuggestions call that take a hardcoded number |
737 // of expected results so callsites are cleaner. | 764 // of expected results so callsites are cleaner. |
738 void CheckSuggestions(int expected_page_id, | 765 void CheckSuggestions(int expected_page_id, const Suggestion& suggestion0) { |
739 const Suggestion& suggestion0) { | |
740 std::vector<Suggestion> suggestion_vector; | 766 std::vector<Suggestion> suggestion_vector; |
741 suggestion_vector.push_back(suggestion0); | 767 suggestion_vector.push_back(suggestion0); |
742 CheckSuggestions(expected_page_id, 1, &suggestion_vector[0]); | 768 CheckSuggestions(expected_page_id, 1, &suggestion_vector[0]); |
743 } | 769 } |
744 void CheckSuggestions(int expected_page_id, | 770 void CheckSuggestions(int expected_page_id, |
745 const Suggestion& suggestion0, | 771 const Suggestion& suggestion0, |
746 const Suggestion& suggestion1) { | 772 const Suggestion& suggestion1) { |
747 std::vector<Suggestion> suggestion_vector; | 773 std::vector<Suggestion> suggestion_vector; |
748 suggestion_vector.push_back(suggestion0); | 774 suggestion_vector.push_back(suggestion0); |
749 suggestion_vector.push_back(suggestion1); | 775 suggestion_vector.push_back(suggestion1); |
(...skipping 18 matching lines...) Expand all Loading... |
768 // and contain a specific number of suggestions. | 794 // and contain a specific number of suggestions. |
769 void CheckSuggestionCount(int expected_page_id, | 795 void CheckSuggestionCount(int expected_page_id, |
770 size_t expected_num_suggestions) { | 796 size_t expected_num_suggestions) { |
771 // Ensure that these results are from the most recent query. | 797 // Ensure that these results are from the most recent query. |
772 EXPECT_TRUE(on_suggestions_returned_seen_); | 798 EXPECT_TRUE(on_suggestions_returned_seen_); |
773 | 799 |
774 EXPECT_EQ(expected_page_id, query_id_); | 800 EXPECT_EQ(expected_page_id, query_id_); |
775 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); | 801 ASSERT_EQ(expected_num_suggestions, suggestions_.size()); |
776 } | 802 } |
777 | 803 |
778 bool on_query_seen() const { | 804 bool on_query_seen() const { return on_query_seen_; } |
779 return on_query_seen_; | |
780 } | |
781 | 805 |
782 bool on_suggestions_returned_seen() const { | 806 bool on_suggestions_returned_seen() const { |
783 return on_suggestions_returned_seen_; | 807 return on_suggestions_returned_seen_; |
784 } | 808 } |
785 | 809 |
786 private: | 810 private: |
787 // Records if OnQuery has been called yet. | 811 // Records if OnQuery has been called yet. |
788 bool on_query_seen_; | 812 bool on_query_seen_; |
789 | 813 |
790 // Records if OnSuggestionsReturned has been called after the most recent | 814 // Records if OnSuggestionsReturned has been called after the most recent |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 void TearDown() override { | 876 void TearDown() override { |
853 // Order of destruction is important as AutofillManager relies on | 877 // Order of destruction is important as AutofillManager relies on |
854 // PersonalDataManager to be around when it gets destroyed. | 878 // PersonalDataManager to be around when it gets destroyed. |
855 autofill_manager_.reset(); | 879 autofill_manager_.reset(); |
856 autofill_driver_.reset(); | 880 autofill_driver_.reset(); |
857 | 881 |
858 // Remove the AutofillWebDataService so TestPersonalDataManager does not | 882 // Remove the AutofillWebDataService so TestPersonalDataManager does not |
859 // need to care about removing self as an observer in destruction. | 883 // need to care about removing self as an observer in destruction. |
860 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); | 884 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); |
861 personal_data_.SetPrefService(NULL); | 885 personal_data_.SetPrefService(NULL); |
| 886 personal_data_.ClearCreditCards(); |
862 | 887 |
863 request_context_ = nullptr; | 888 request_context_ = nullptr; |
864 } | 889 } |
865 | 890 |
866 void GetAutofillSuggestions(int query_id, | 891 void GetAutofillSuggestions(int query_id, |
867 const FormData& form, | 892 const FormData& form, |
868 const FormFieldData& field) { | 893 const FormFieldData& field) { |
869 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field, | 894 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field, |
870 gfx::RectF()); | 895 gfx::RectF()); |
871 } | 896 } |
872 | 897 |
873 void GetAutofillSuggestions(const FormData& form, | 898 void GetAutofillSuggestions(const FormData& form, |
874 const FormFieldData& field) { | 899 const FormFieldData& field) { |
875 GetAutofillSuggestions(kDefaultPageID, form, field); | 900 GetAutofillSuggestions(kDefaultPageID, form, field); |
876 } | 901 } |
877 | 902 |
878 void AutocompleteSuggestionsReturned( | 903 void AutocompleteSuggestionsReturned( |
879 const std::vector<base::string16>& result) { | 904 const std::vector<base::string16>& result) { |
880 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); | 905 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
881 } | 906 } |
882 | 907 |
883 void FormsSeen(const std::vector<FormData>& forms) { | 908 void FormsSeen(const std::vector<FormData>& forms) { |
884 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 909 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
885 } | 910 } |
886 | 911 |
887 void FormSubmitted(const FormData& form) { | 912 void FormSubmitted(const FormData& form) { |
888 autofill_manager_->ResetRunLoop(); | 913 autofill_manager_->ResetRunLoop(); |
889 if (autofill_manager_->OnWillSubmitForm(form, base::TimeTicks::Now())) | 914 if (autofill_manager_->OnWillSubmitForm(form, base::TimeTicks::Now()) && |
| 915 (!personal_data_.GetProfiles().empty() || |
| 916 !personal_data_.GetCreditCards().empty())) |
890 autofill_manager_->WaitForAsyncUploadProcess(); | 917 autofill_manager_->WaitForAsyncUploadProcess(); |
891 autofill_manager_->OnFormSubmitted(form); | 918 autofill_manager_->OnFormSubmitted(form); |
892 } | 919 } |
893 | 920 |
894 void FillAutofillFormData(int query_id, | 921 void FillAutofillFormData(int query_id, |
895 const FormData& form, | 922 const FormData& form, |
896 const FormFieldData& field, | 923 const FormFieldData& field, |
897 int unique_id) { | 924 int unique_id) { |
898 autofill_manager_->FillOrPreviewForm( | 925 autofill_manager_->FillOrPreviewForm( |
899 AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field, | 926 AutofillDriver::FORM_DATA_ACTION_FILL, query_id, form, field, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 EXPECT_EQ(expected_num_matching_entries, num_matching_entries); | 1155 EXPECT_EQ(expected_num_matching_entries, num_matching_entries); |
1129 } | 1156 } |
1130 | 1157 |
1131 protected: | 1158 protected: |
1132 base::test::ScopedTaskEnvironment scoped_task_environment_; | 1159 base::test::ScopedTaskEnvironment scoped_task_environment_; |
1133 MockAutofillClient autofill_client_; | 1160 MockAutofillClient autofill_client_; |
1134 std::unique_ptr<MockAutofillDriver> autofill_driver_; | 1161 std::unique_ptr<MockAutofillDriver> autofill_driver_; |
1135 std::unique_ptr<TestAutofillManager> autofill_manager_; | 1162 std::unique_ptr<TestAutofillManager> autofill_manager_; |
1136 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; | 1163 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; |
1137 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 1164 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
1138 TestPaymentsClient* payments_client_; | |
1139 TestAutofillDownloadManager* download_manager_; | 1165 TestAutofillDownloadManager* download_manager_; |
1140 TestPersonalDataManager personal_data_; | 1166 TestPersonalDataManager personal_data_; |
1141 base::FieldTrialList field_trial_list_; | 1167 base::FieldTrialList field_trial_list_; |
1142 base::test::ScopedFeatureList scoped_feature_list_; | 1168 base::test::ScopedFeatureList scoped_feature_list_; |
1143 }; | 1169 }; |
1144 | 1170 |
1145 class TestFormStructure : public FormStructure { | 1171 class TestFormStructure : public FormStructure { |
1146 public: | 1172 public: |
1147 explicit TestFormStructure(const FormData& form) | 1173 explicit TestFormStructure(const FormData& form) |
1148 : FormStructure(form) {} | 1174 : FormStructure(form) {} |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1787 "04/99", kVisaCard, | 1813 "04/99", kVisaCard, |
1788 autofill_manager_->GetPackedCreditCardID(4)), | 1814 autofill_manager_->GetPackedCreditCardID(4)), |
1789 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", | 1815 Suggestion("MasterCard" + kUTF8MidlineEllipsis + "8765", "10/98", |
1790 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); | 1816 kMasterCard, autofill_manager_->GetPackedCreditCardID(5))); |
1791 } | 1817 } |
1792 | 1818 |
1793 // Test that we will eventually return the credit card signin promo when there | 1819 // Test that we will eventually return the credit card signin promo when there |
1794 // are no credit card suggestions and the promo is active. See the tests in | 1820 // are no credit card suggestions and the promo is active. See the tests in |
1795 // AutofillExternalDelegateTest that test whether the promo is added. | 1821 // AutofillExternalDelegateTest that test whether the promo is added. |
1796 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { | 1822 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { |
1797 // Make sure there are no credit cards. | |
1798 personal_data_.ClearCreditCards(); | 1823 personal_data_.ClearCreditCards(); |
1799 | 1824 |
1800 // Set up our form data. | 1825 // Set up our form data. |
1801 FormData form; | 1826 FormData form; |
1802 CreateTestCreditCardFormData(&form, true, false); | 1827 CreateTestCreditCardFormData(&form, true, false); |
1803 std::vector<FormData> forms(1, form); | 1828 std::vector<FormData> forms(1, form); |
1804 FormsSeen(forms); | 1829 FormsSeen(forms); |
1805 FormFieldData field = form.fields[1]; | 1830 FormFieldData field = form.fields[1]; |
1806 | 1831 |
1807 ON_CALL(autofill_client_, ShouldShowSigninPromo()) | 1832 ON_CALL(autofill_client_, ShouldShowSigninPromo()) |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 &response_page_id, &response_data); | 2369 &response_page_id, &response_data); |
2345 ExpectFilledCreditCardYearMonthWithYearMonth( | 2370 ExpectFilledCreditCardYearMonthWithYearMonth( |
2346 response_page_id, response_data, kDefaultPageID, false, "2999", ""); | 2371 response_page_id, response_data, kDefaultPageID, false, "2999", ""); |
2347 } | 2372 } |
2348 | 2373 |
2349 // Test that we correctly fill a credit card form with month input type. | 2374 // Test that we correctly fill a credit card form with month input type. |
2350 // 4. year non-empty, month empty | 2375 // 4. year non-empty, month empty |
2351 TEST_F(AutofillManagerTest, FillCreditCardForm_YearMonth) { | 2376 TEST_F(AutofillManagerTest, FillCreditCardForm_YearMonth) { |
2352 // Same as the SetUp(), but generate 4 credit cards with year month | 2377 // Same as the SetUp(), but generate 4 credit cards with year month |
2353 // combination. | 2378 // combination. |
2354 personal_data_.ClearCreditCards(); | |
2355 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); | 2379 personal_data_.CreateTestCreditCardsYearAndMonth("2999", "04"); |
2356 // Set up our form data. | 2380 // Set up our form data. |
2357 FormData form; | 2381 FormData form; |
2358 CreateTestCreditCardFormData(&form, true, true); | 2382 CreateTestCreditCardFormData(&form, true, true); |
2359 std::vector<FormData> forms(1, form); | 2383 std::vector<FormData> forms(1, form); |
2360 FormsSeen(forms); | 2384 FormsSeen(forms); |
2361 | 2385 |
2362 const char guid[] = "00000000-0000-0000-0000-000000000007"; | 2386 const char guid[] = "00000000-0000-0000-0000-000000000007"; |
2363 int response_page_id = 0; | 2387 int response_page_id = 0; |
2364 FormData response_data; | 2388 FormData response_data; |
(...skipping 2227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4592 } | 4616 } |
4593 | 4617 |
4594 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4618 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
4595 #if defined(OS_ANDROID) | 4619 #if defined(OS_ANDROID) |
4596 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard | 4620 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard |
4597 #else | 4621 #else |
4598 #define MAYBE_UploadCreditCard UploadCreditCard | 4622 #define MAYBE_UploadCreditCard UploadCreditCard |
4599 #endif | 4623 #endif |
4600 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { | 4624 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { |
4601 EnableUkmLogging(); | 4625 EnableUkmLogging(); |
| 4626 personal_data_.ClearCreditCards(); |
4602 personal_data_.ClearAutofillProfiles(); | 4627 personal_data_.ClearAutofillProfiles(); |
4603 autofill_manager_->set_credit_card_upload_enabled(true); | 4628 autofill_manager_->set_credit_card_upload_enabled(true); |
4604 | 4629 |
4605 // Create, fill and submit an address form in order to establish a recent | 4630 // Create, fill and submit an address form in order to establish a recent |
4606 // profile which can be selected for the upload request. | 4631 // profile which can be selected for the upload request. |
4607 FormData address_form; | 4632 FormData address_form; |
4608 test::CreateTestAddressFormData(&address_form); | 4633 test::CreateTestAddressFormData(&address_form); |
4609 FormsSeen(std::vector<FormData>(1, address_form)); | 4634 FormsSeen(std::vector<FormData>(1, address_form)); |
4610 ExpectUniqueFillableFormParsedUkm(); | 4635 ExpectUniqueFillableFormParsedUkm(); |
4611 | 4636 |
(...skipping 11 matching lines...) Expand all Loading... |
4623 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); | 4648 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
4624 credit_card_form.fields[2].value = ASCIIToUTF16("11"); | 4649 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
4625 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); | 4650 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
4626 credit_card_form.fields[4].value = ASCIIToUTF16("123"); | 4651 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
4627 | 4652 |
4628 base::HistogramTester histogram_tester; | 4653 base::HistogramTester histogram_tester; |
4629 | 4654 |
4630 FormSubmitted(credit_card_form); | 4655 FormSubmitted(credit_card_form); |
4631 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); | 4656 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
4632 | 4657 |
| 4658 // Server did not send a server_id, expect copy of card is not stored. |
| 4659 EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); |
| 4660 |
4633 // Verify that the correct histogram entry (and only that) was logged. | 4661 // Verify that the correct histogram entry (and only that) was logged. |
4634 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", | 4662 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", |
4635 AutofillMetrics::UPLOAD_OFFERED, 1); | 4663 AutofillMetrics::UPLOAD_OFFERED, 1); |
4636 // Verify that the correct UKM was logged. | 4664 // Verify that the correct UKM was logged. |
4637 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 4665 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); |
4638 } | 4666 } |
4639 | 4667 |
4640 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. | 4668 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
4641 #if defined(OS_ANDROID) | 4669 #if defined(OS_ANDROID) |
| 4670 #define MAYBE_UploadCreditCardAndSaveCopy DISABLED_UploadCreditCardAndSaveCopy |
| 4671 #else |
| 4672 #define MAYBE_UploadCreditCardAndSaveCopy UploadCreditCardAndSaveCopy |
| 4673 #endif |
| 4674 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCardAndSaveCopy) { |
| 4675 personal_data_.ClearCreditCards(); |
| 4676 personal_data_.ClearAutofillProfiles(); |
| 4677 autofill_manager_->set_credit_card_upload_enabled(true); |
| 4678 |
| 4679 const char* const server_id = "InstrumentData:1234"; |
| 4680 autofill_manager_->ResetPaymentsClientForCardUpload(server_id); |
| 4681 |
| 4682 // Create, fill and submit an address form in order to establish a recent |
| 4683 // profile which can be selected for the upload request. |
| 4684 FormData address_form; |
| 4685 test::CreateTestAddressFormData(&address_form); |
| 4686 FormsSeen(std::vector<FormData>(1, address_form)); |
| 4687 |
| 4688 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| 4689 FormSubmitted(address_form); |
| 4690 |
| 4691 // Set up our credit card form data. |
| 4692 FormData credit_card_form; |
| 4693 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 4694 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
| 4695 |
| 4696 // Edit the data, and submit. |
| 4697 const char* const card_number = "4111111111111111"; |
| 4698 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 4699 credit_card_form.fields[1].value = ASCIIToUTF16(card_number); |
| 4700 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 4701 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 4702 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 4703 |
| 4704 FormSubmitted(credit_card_form); |
| 4705 |
| 4706 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 4707 EXPECT_TRUE(autofill_manager_->GetLocalCreditCards().empty()); |
| 4708 ASSERT_EQ(1U, autofill_manager_->GetCreditCards().size()); |
| 4709 const CreditCard* const saved_card = autofill_manager_->GetCreditCards()[0]; |
| 4710 EXPECT_EQ(CreditCard::OK, saved_card->GetServerStatus()); |
| 4711 EXPECT_EQ(base::ASCIIToUTF16("1111"), saved_card->LastFourDigits()); |
| 4712 EXPECT_EQ(kVisaCard, saved_card->type()); |
| 4713 EXPECT_EQ(11, saved_card->expiration_month()); |
| 4714 EXPECT_EQ(2017, saved_card->expiration_year()); |
| 4715 EXPECT_EQ(server_id, saved_card->server_id()); |
| 4716 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, saved_card->record_type()); |
| 4717 EXPECT_EQ(base::ASCIIToUTF16(card_number), saved_card->number()); |
| 4718 } |
| 4719 |
| 4720 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. |
| 4721 #if defined(OS_ANDROID) |
4642 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu
reNotEnabled | 4722 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu
reNotEnabled |
4643 #else | 4723 #else |
4644 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab
led | 4724 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab
led |
4645 #endif | 4725 #endif |
4646 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { | 4726 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { |
4647 personal_data_.ClearAutofillProfiles(); | 4727 personal_data_.ClearAutofillProfiles(); |
4648 autofill_manager_->set_credit_card_upload_enabled(false); | 4728 autofill_manager_->set_credit_card_upload_enabled(false); |
4649 | 4729 |
4650 // Create, fill and submit an address form in order to establish a recent | 4730 // Create, fill and submit an address form in order to establish a recent |
4651 // profile which can be selected for the upload request. | 4731 // profile which can be selected for the upload request. |
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6105 | 6185 |
6106 // Wait for upload to complete (will check expected types as well). | 6186 // Wait for upload to complete (will check expected types as well). |
6107 autofill_manager_->WaitForAsyncUploadProcess(); | 6187 autofill_manager_->WaitForAsyncUploadProcess(); |
6108 | 6188 |
6109 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 6189 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
6110 EXPECT_NE(uploaded_available_types.end(), | 6190 EXPECT_NE(uploaded_available_types.end(), |
6111 uploaded_available_types.find(autofill::PASSWORD)); | 6191 uploaded_available_types.find(autofill::PASSWORD)); |
6112 } | 6192 } |
6113 | 6193 |
6114 } // namespace autofill | 6194 } // namespace autofill |
OLD | NEW |