| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 void AddProfile(AutofillProfile* profile) { | 82 void AddProfile(AutofillProfile* profile) { |
| 83 web_profiles_.push_back(profile); | 83 web_profiles_.push_back(profile); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void AddCreditCard(CreditCard* credit_card) { | 86 void AddCreditCard(CreditCard* credit_card) { |
| 87 local_credit_cards_.push_back(credit_card); | 87 local_credit_cards_.push_back(credit_card); |
| 88 } | 88 } |
| 89 | 89 |
| 90 virtual void RemoveByGUID(const std::string& guid) override { | 90 void RemoveByGUID(const std::string& guid) override { |
| 91 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); | 91 CreditCard* credit_card = GetCreditCardWithGUID(guid.c_str()); |
| 92 if (credit_card) { | 92 if (credit_card) { |
| 93 local_credit_cards_.erase( | 93 local_credit_cards_.erase( |
| 94 std::find(local_credit_cards_.begin(), local_credit_cards_.end(), | 94 std::find(local_credit_cards_.begin(), local_credit_cards_.end(), |
| 95 credit_card)); | 95 credit_card)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); | 98 AutofillProfile* profile = GetProfileWithGUID(guid.c_str()); |
| 99 if (profile) { | 99 if (profile) { |
| 100 web_profiles_.erase( | 100 web_profiles_.erase( |
| 101 std::find(web_profiles_.begin(), web_profiles_.end(), profile)); | 101 std::find(web_profiles_.begin(), web_profiles_.end(), profile)); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Do nothing (auxiliary profiles will be created in | 105 // Do nothing (auxiliary profiles will be created in |
| 106 // CreateTestAuxiliaryProfile). | 106 // CreateTestAuxiliaryProfile). |
| 107 virtual void LoadAuxiliaryProfiles(bool record_metrics) const override {} | 107 void LoadAuxiliaryProfiles(bool record_metrics) const override {} |
| 108 | 108 |
| 109 void ClearAutofillProfiles() { | 109 void ClearAutofillProfiles() { |
| 110 web_profiles_.clear(); | 110 web_profiles_.clear(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void ClearCreditCards() { | 113 void ClearCreditCards() { |
| 114 local_credit_cards_.clear(); | 114 local_credit_cards_.clear(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CreateTestAuxiliaryProfiles() { | 117 void CreateTestAuxiliaryProfiles() { |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 const FormFieldData& field) { | 638 const FormFieldData& field) { |
| 639 GetAutofillSuggestions(kDefaultPageID, form, field); | 639 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void AutocompleteSuggestionsReturned( | 642 void AutocompleteSuggestionsReturned( |
| 643 const std::vector<base::string16>& result) { | 643 const std::vector<base::string16>& result) { |
| 644 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); | 644 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
| 645 } | 645 } |
| 646 | 646 |
| 647 void FormsSeen(const std::vector<FormData>& forms) { | 647 void FormsSeen(const std::vector<FormData>& forms) { |
| 648 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 648 autofill_manager_->OnFormsSeen(forms, false, base::TimeTicks()); |
| 649 } | 649 } |
| 650 | 650 |
| 651 void FormSubmitted(const FormData& form) { | 651 void FormSubmitted(const FormData& form) { |
| 652 autofill_manager_->ResetRunLoop(); | 652 autofill_manager_->ResetRunLoop(); |
| 653 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 653 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
| 654 autofill_manager_->WaitForAsyncFormSubmit(); | 654 autofill_manager_->WaitForAsyncFormSubmit(); |
| 655 } | 655 } |
| 656 | 656 |
| 657 void FillAutofillFormData(int query_id, | 657 void FillAutofillFormData(int query_id, |
| 658 const FormData& form, | 658 const FormData& form, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // Test that we return only matching address profile suggestions when the | 747 // Test that we return only matching address profile suggestions when the |
| 748 // selected form field has been partially filled out. | 748 // selected form field has been partially filled out. |
| 749 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 749 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
| 750 // Set up our form data. | 750 // Set up our form data. |
| 751 FormData form; | 751 FormData form; |
| 752 test::CreateTestAddressFormData(&form); | 752 test::CreateTestAddressFormData(&form); |
| 753 std::vector<FormData> forms(1, form); | 753 std::vector<FormData> forms(1, form); |
| 754 FormsSeen(forms); | 754 FormsSeen(forms); |
| 755 | 755 |
| 756 FormFieldData field; | 756 FormFieldData field; |
| 757 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); | 757 test::CreateTestFormField("First Name", "firstname", "E", "text", &field); |
| 758 GetAutofillSuggestions(form, field); | 758 GetAutofillSuggestions(form, field); |
| 759 | 759 |
| 760 // No suggestions provided, so send an empty vector as the results. | 760 // No suggestions provided, so send an empty vector as the results. |
| 761 // This triggers the combined message send. | 761 // This triggers the combined message send. |
| 762 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 762 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 763 | 763 |
| 764 // Test that we sent the right values to the external delegate. | 764 // Test that we sent the right values to the external delegate. |
| 765 external_delegate_->CheckSuggestions( | 765 external_delegate_->CheckSuggestions( |
| 766 kDefaultPageID, | 766 kDefaultPageID, |
| 767 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1)); | 767 Suggestion("Elvis", "3734 Elvis Presley Blvd.", "", 1)); |
| 768 } | 768 } |
| 769 | 769 |
| 770 // Test that we return no suggestions when the form has no relevant fields. | 770 // Test that we return no suggestions when the form has no relevant fields. |
| 771 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { | 771 TEST_F(AutofillManagerTest, GetProfileSuggestionsUnknownFields) { |
| 772 // Set up our form data. | 772 // Set up our form data. |
| 773 FormData form; | 773 FormData form; |
| 774 form.name = ASCIIToUTF16("MyForm"); | 774 form.name = ASCIIToUTF16("MyForm"); |
| 775 form.origin = GURL("http://myform.com/form.html"); | 775 form.origin = GURL("http://myform.com/form.html"); |
| 776 form.action = GURL("http://myform.com/submit.html"); | 776 form.action = GURL("http://myform.com/submit.html"); |
| 777 form.user_submitted = true; | 777 form.user_submitted = true; |
| 778 | 778 |
| 779 FormFieldData field; | 779 FormFieldData field; |
| 780 test::CreateTestFormField("Username", "username", "", "text",&field); | 780 test::CreateTestFormField("Username", "username", "", "text", &field); |
| 781 form.fields.push_back(field); | 781 form.fields.push_back(field); |
| 782 test::CreateTestFormField("Password", "password", "", "password",&field); | 782 test::CreateTestFormField("Password", "password", "", "password", &field); |
| 783 form.fields.push_back(field); | 783 form.fields.push_back(field); |
| 784 test::CreateTestFormField("Quest", "quest", "", "quest", &field); | 784 test::CreateTestFormField("Quest", "quest", "", "quest", &field); |
| 785 form.fields.push_back(field); | 785 form.fields.push_back(field); |
| 786 test::CreateTestFormField("Color", "color", "", "text", &field); | 786 test::CreateTestFormField("Color", "color", "", "text", &field); |
| 787 form.fields.push_back(field); | 787 form.fields.push_back(field); |
| 788 | 788 |
| 789 std::vector<FormData> forms(1, form); | 789 std::vector<FormData> forms(1, form); |
| 790 FormsSeen(forms); | 790 FormsSeen(forms); |
| 791 | 791 |
| 792 GetAutofillSuggestions(form, field); | 792 GetAutofillSuggestions(form, field); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1319 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 1320 | 1320 |
| 1321 // Test that we sent the right values to the external delegate. Inferred | 1321 // Test that we sent the right values to the external delegate. Inferred |
| 1322 // labels include full first relevant field, which in this case is the | 1322 // labels include full first relevant field, which in this case is the |
| 1323 // address line 1. | 1323 // address line 1. |
| 1324 external_delegate_->CheckSuggestions( | 1324 external_delegate_->CheckSuggestions( |
| 1325 kDefaultPageID, | 1325 kDefaultPageID, |
| 1326 Suggestion("12345678901", "Elvis Aaron Presley", "", 1), | 1326 Suggestion("12345678901", "Elvis Aaron Presley", "", 1), |
| 1327 Suggestion("23456789012", "Charles Hardin Holley", "", 2), | 1327 Suggestion("23456789012", "Charles Hardin Holley", "", 2), |
| 1328 Suggestion("18007724743", "Natty Bumppo", "", 3)); // 1800PRAIRIE | 1328 Suggestion("18007724743", "Natty Bumppo", "", 3)); // 1800PRAIRIE |
| 1329 | |
| 1330 } | 1329 } |
| 1331 | 1330 |
| 1332 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { | 1331 TEST_F(AutofillManagerTest, GetProfileSuggestionsForPhonePrefixOrSuffix) { |
| 1333 // Set up our form data. | 1332 // Set up our form data. |
| 1334 FormData form; | 1333 FormData form; |
| 1335 form.name = ASCIIToUTF16("MyForm"); | 1334 form.name = ASCIIToUTF16("MyForm"); |
| 1336 form.origin = GURL("http://myform.com/form.html"); | 1335 form.origin = GURL("http://myform.com/form.html"); |
| 1337 form.action = GURL("http://myform.com/submit.html"); | 1336 form.action = GURL("http://myform.com/submit.html"); |
| 1338 form.user_submitted = true; | 1337 form.user_submitted = true; |
| 1339 | 1338 |
| (...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2765 | 2764 |
| 2766 SuggestionBackendID guid_pair(guid, 0); | 2765 SuggestionBackendID guid_pair(guid, 0); |
| 2767 SuggestionBackendID empty(std::string(), 0); | 2766 SuggestionBackendID empty(std::string(), 0); |
| 2768 int id = MakeFrontendID(empty, guid_pair); | 2767 int id = MakeFrontendID(empty, guid_pair); |
| 2769 | 2768 |
| 2770 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 2769 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 2771 | 2770 |
| 2772 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 2771 EXPECT_FALSE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
| 2773 } | 2772 } |
| 2774 | 2773 |
| 2775 TEST_F(AutofillManagerTest, RemoveCreditCard){ | 2774 TEST_F(AutofillManagerTest, RemoveCreditCard) { |
| 2776 // Add and remove an Autofill credit card. | 2775 // Add and remove an Autofill credit card. |
| 2777 CreditCard* credit_card = new CreditCard; | 2776 CreditCard* credit_card = new CreditCard; |
| 2778 std::string guid = "00000000-0000-0000-0000-000000100007"; | 2777 std::string guid = "00000000-0000-0000-0000-000000100007"; |
| 2779 credit_card->set_guid(guid.c_str()); | 2778 credit_card->set_guid(guid.c_str()); |
| 2780 autofill_manager_->AddCreditCard(credit_card); | 2779 autofill_manager_->AddCreditCard(credit_card); |
| 2781 | 2780 |
| 2782 SuggestionBackendID guid_pair(guid, 0); | 2781 SuggestionBackendID guid_pair(guid, 0); |
| 2783 SuggestionBackendID empty(std::string(), 0); | 2782 SuggestionBackendID empty(std::string(), 0); |
| 2784 int id = MakeFrontendID(guid_pair, empty); | 2783 int id = MakeFrontendID(guid_pair, empty); |
| 2785 | 2784 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2926 // results. This triggers the combined message send. | 2925 // results. This triggers the combined message send. |
| 2927 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 2926 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
| 2928 | 2927 |
| 2929 external_delegate_->CheckSuggestions( | 2928 external_delegate_->CheckSuggestions( |
| 2930 kDefaultPageID, | 2929 kDefaultPageID, |
| 2931 Suggestion("Visa - 3456", "04/12", kVisaCard, | 2930 Suggestion("Visa - 3456", "04/12", kVisaCard, |
| 2932 autofill_manager_->GetPackedCreditCardID(4))); | 2931 autofill_manager_->GetPackedCreditCardID(4))); |
| 2933 } | 2932 } |
| 2934 | 2933 |
| 2935 } // namespace autofill | 2934 } // namespace autofill |
| OLD | NEW |