OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "components/autofill/browser/autofill_common_test.h" | 31 #include "components/autofill/browser/autofill_common_test.h" |
32 #include "components/autofill/browser/autofill_manager.h" | 32 #include "components/autofill/browser/autofill_manager.h" |
33 #include "components/autofill/browser/autofill_metrics.h" | 33 #include "components/autofill/browser/autofill_metrics.h" |
34 #include "components/autofill/browser/autofill_profile.h" | 34 #include "components/autofill/browser/autofill_profile.h" |
35 #include "components/autofill/browser/credit_card.h" | 35 #include "components/autofill/browser/credit_card.h" |
36 #include "components/autofill/browser/personal_data_manager.h" | 36 #include "components/autofill/browser/personal_data_manager.h" |
37 #include "components/autofill/browser/test_autofill_external_delegate.h" | 37 #include "components/autofill/browser/test_autofill_external_delegate.h" |
38 #include "components/autofill/common/autofill_messages.h" | 38 #include "components/autofill/common/autofill_messages.h" |
39 #include "components/autofill/common/form_data.h" | 39 #include "components/autofill/common/form_data.h" |
40 #include "components/autofill/common/form_field_data.h" | 40 #include "components/autofill/common/form_field_data.h" |
| 41 #include "components/autofill/common/forms_seen_state.h" |
41 #include "components/user_prefs/user_prefs.h" | 42 #include "components/user_prefs/user_prefs.h" |
42 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
43 #include "content/public/test/mock_render_process_host.h" | 44 #include "content/public/test/mock_render_process_host.h" |
44 #include "content/public/test/test_browser_thread.h" | 45 #include "content/public/test/test_browser_thread.h" |
45 #include "content/public/test/test_utils.h" | 46 #include "content/public/test/test_utils.h" |
46 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
47 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
48 #include "ipc/ipc_test_sink.h" | 49 #include "ipc/ipc_test_sink.h" |
49 #include "testing/gmock/include/gmock/gmock.h" | 50 #include "testing/gmock/include/gmock/gmock.h" |
50 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 const FormFieldData& field) { | 709 const FormFieldData& field) { |
709 GetAutofillSuggestions(kDefaultPageID, form, field); | 710 GetAutofillSuggestions(kDefaultPageID, form, field); |
710 } | 711 } |
711 | 712 |
712 void AutocompleteSuggestionsReturned( | 713 void AutocompleteSuggestionsReturned( |
713 const std::vector<base::string16>& result) { | 714 const std::vector<base::string16>& result) { |
714 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); | 715 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); |
715 } | 716 } |
716 | 717 |
717 void FormsSeen(const std::vector<FormData>& forms) { | 718 void FormsSeen(const std::vector<FormData>& forms) { |
718 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); | 719 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 720 autofill::NO_SPECIAL_FORMS_SEEN); |
719 } | 721 } |
720 | 722 |
721 void PartialFormsSeen(const std::vector<FormData>& forms) { | 723 void PartialFormsSeen(const std::vector<FormData>& forms) { |
722 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); | 724 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 725 autofill::PARTIAL_FORMS_SEEN); |
| 726 } |
| 727 |
| 728 void DynamicFormsSeen(const std::vector<FormData>& forms) { |
| 729 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 730 autofill::DYNAMIC_FORMS_SEEN); |
| 731 } |
| 732 |
| 733 void PartialDynamicFormsSeen(const std::vector<FormData>& forms) { |
| 734 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), |
| 735 autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN); |
723 } | 736 } |
724 | 737 |
725 void FormSubmitted(const FormData& form) { | 738 void FormSubmitted(const FormData& form) { |
726 autofill_manager_->ResetMessageLoopRunner(); | 739 autofill_manager_->ResetMessageLoopRunner(); |
727 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 740 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
728 autofill_manager_->WaitForAsyncFormSubmit(); | 741 autofill_manager_->WaitForAsyncFormSubmit(); |
729 } | 742 } |
730 | 743 |
731 void FillAutofillFormData(int query_id, | 744 void FillAutofillFormData(int query_id, |
732 const FormData& form, | 745 const FormData& form, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 CreateTestAddressFormData(&form); | 866 CreateTestAddressFormData(&form); |
854 std::vector<FormData> forms(1, form); | 867 std::vector<FormData> forms(1, form); |
855 // Enable autocheckout. | 868 // Enable autocheckout. |
856 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 869 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
857 | 870 |
858 PartialFormsSeen(forms); | 871 PartialFormsSeen(forms); |
859 | 872 |
860 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | 873 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
861 } | 874 } |
862 | 875 |
| 876 // Test that browser asks for all forms after DOM changes when |
| 877 // Autocheckout is enabled. |
| 878 TEST_F(AutofillManagerTest, GetAllDynamicForms) { |
| 879 FormData form; |
| 880 CreateTestAddressFormData(&form); |
| 881 std::vector<FormData> forms(1, form); |
| 882 // Enable autocheckout. |
| 883 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 884 |
| 885 PartialDynamicFormsSeen(forms); |
| 886 |
| 887 EXPECT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
| 888 } |
| 889 |
863 // Test that we return all address profile suggestions when all form fields are | 890 // Test that we return all address profile suggestions when all form fields are |
864 // empty. | 891 // empty. |
865 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 892 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
866 // Set up our form data. | 893 // Set up our form data. |
867 FormData form; | 894 FormData form; |
868 CreateTestAddressFormData(&form); | 895 CreateTestAddressFormData(&form); |
869 std::vector<FormData> forms(1, form); | 896 std::vector<FormData> forms(1, form); |
870 FormsSeen(forms); | 897 FormsSeen(forms); |
871 | 898 |
872 const FormFieldData& field = form.fields[0]; | 899 const FormFieldData& field = form.fields[0]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 // userspecified and then address form. | 959 // userspecified and then address form. |
933 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); | 960 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); |
934 FormsSeen(forms); | 961 FormsSeen(forms); |
935 form_structures = autofill_manager_->GetFormStructures(); | 962 form_structures = autofill_manager_->GetFormStructures(); |
936 ASSERT_EQ(3U, form_structures.size()); | 963 ASSERT_EQ(3U, form_structures.size()); |
937 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); | 964 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); |
938 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); | 965 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); |
939 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 966 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
940 } | 967 } |
941 | 968 |
| 969 // Test that in the case of Autocheckout, forms seen are in order supplied. |
| 970 TEST_F(AutofillManagerTest, DynamicFormsSeen) { |
| 971 FormData shipping_options; |
| 972 CreateTestShippingOptionsFormData(&shipping_options); |
| 973 FormData user_supplied; |
| 974 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
| 975 FormData address; |
| 976 CreateTestAddressFormData(&address); |
| 977 |
| 978 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 979 // Push user_supplied only |
| 980 std::vector<FormData> forms; |
| 981 forms.push_back(user_supplied); |
| 982 |
| 983 // Make sure normal form is handled correctly. |
| 984 FormsSeen(forms); |
| 985 std::vector<FormStructure*> form_structures; |
| 986 form_structures = autofill_manager_->GetFormStructures(); |
| 987 ASSERT_EQ(1U, form_structures.size()); |
| 988 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
| 989 |
| 990 // Push other forms |
| 991 forms.push_back(shipping_options); |
| 992 forms.push_back(address); |
| 993 |
| 994 // FormStructure should contain three and only three forms. Otherwise, it |
| 995 // would indicate that the manager didn't reset upon being notified of |
| 996 // the new forms; |
| 997 DynamicFormsSeen(forms); |
| 998 form_structures = autofill_manager_->GetFormStructures(); |
| 999 ASSERT_EQ(3U, form_structures.size()); |
| 1000 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
| 1001 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); |
| 1002 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
| 1003 } |
| 1004 |
942 // Test that we return only matching address profile suggestions when the | 1005 // Test that we return only matching address profile suggestions when the |
943 // selected form field has been partially filled out. | 1006 // selected form field has been partially filled out. |
944 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 1007 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
945 // Set up our form data. | 1008 // Set up our form data. |
946 FormData form; | 1009 FormData form; |
947 CreateTestAddressFormData(&form); | 1010 CreateTestAddressFormData(&form); |
948 std::vector<FormData> forms(1, form); | 1011 std::vector<FormData> forms(1, form); |
949 FormsSeen(forms); | 1012 FormsSeen(forms); |
950 | 1013 |
951 FormFieldData field; | 1014 FormFieldData field; |
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3326 CreateTestAddressFormData(&form); | 3389 CreateTestAddressFormData(&form); |
3327 std::vector<FormData> forms(1, form); | 3390 std::vector<FormData> forms(1, form); |
3328 FormsSeen(forms); | 3391 FormsSeen(forms); |
3329 const FormFieldData& field = form.fields[0]; | 3392 const FormFieldData& field = form.fields[0]; |
3330 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3393 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3331 | 3394 |
3332 autofill_manager_->SetExternalDelegate(NULL); | 3395 autofill_manager_->SetExternalDelegate(NULL); |
3333 } | 3396 } |
3334 | 3397 |
3335 } // namespace autofill | 3398 } // namespace autofill |
OLD | NEW |