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/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 void GetAutofillSuggestions(const FormData& form, | 729 void GetAutofillSuggestions(const FormData& form, |
730 const FormFieldData& field) { | 730 const FormFieldData& field) { |
731 GetAutofillSuggestions(kDefaultPageID, form, field); | 731 GetAutofillSuggestions(kDefaultPageID, form, field); |
732 } | 732 } |
733 | 733 |
734 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 734 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
735 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); | 735 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); |
736 } | 736 } |
737 | 737 |
738 void FormsSeen(const std::vector<FormData>& forms) { | 738 void FormsSeen(const std::vector<FormData>& forms) { |
739 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); | 739 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false, false); |
740 } | 740 } |
741 | 741 |
742 void PartialFormsSeen(const std::vector<FormData>& forms) { | 742 void PartialFormsSeen(const std::vector<FormData>& forms) { |
743 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); | 743 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true, false); |
| 744 } |
| 745 |
| 746 void DynamicFormsSeen(const std::vector<FormData>& forms) { |
| 747 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false, true); |
| 748 } |
| 749 |
| 750 void PartialDynamicFormsSeen(const std::vector<FormData>& forms) { |
| 751 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true, true); |
744 } | 752 } |
745 | 753 |
746 void FormSubmitted(const FormData& form) { | 754 void FormSubmitted(const FormData& form) { |
747 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 755 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
748 autofill_manager_->WaitForAsyncFormSubmit(); | 756 autofill_manager_->WaitForAsyncFormSubmit(); |
749 } | 757 } |
750 | 758 |
751 void FillAutofillFormData(int query_id, | 759 void FillAutofillFormData(int query_id, |
752 const FormData& form, | 760 const FormData& form, |
753 const FormFieldData& field, | 761 const FormFieldData& field, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 CreateTestAddressFormData(&form); | 881 CreateTestAddressFormData(&form); |
874 std::vector<FormData> forms(1, form); | 882 std::vector<FormData> forms(1, form); |
875 // Enable autocheckout. | 883 // Enable autocheckout. |
876 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 884 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
877 | 885 |
878 PartialFormsSeen(forms); | 886 PartialFormsSeen(forms); |
879 | 887 |
880 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | 888 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
881 } | 889 } |
882 | 890 |
| 891 // Test that browser asks for all forms after DOM changes when |
| 892 // Autocheckout is enabled. |
| 893 TEST_F(AutofillManagerTest, GetAllDynamicForms) { |
| 894 FormData form; |
| 895 CreateTestAddressFormData(&form); |
| 896 std::vector<FormData> forms(1, form); |
| 897 // Enable autocheckout. |
| 898 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 899 |
| 900 PartialDynamicFormsSeen(forms); |
| 901 |
| 902 EXPECT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
| 903 } |
| 904 |
883 // Test that we return all address profile suggestions when all form fields are | 905 // Test that we return all address profile suggestions when all form fields are |
884 // empty. | 906 // empty. |
885 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 907 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
886 // Set up our form data. | 908 // Set up our form data. |
887 FormData form; | 909 FormData form; |
888 CreateTestAddressFormData(&form); | 910 CreateTestAddressFormData(&form); |
889 std::vector<FormData> forms(1, form); | 911 std::vector<FormData> forms(1, form); |
890 FormsSeen(forms); | 912 FormsSeen(forms); |
891 | 913 |
892 const FormFieldData& field = form.fields[0]; | 914 const FormFieldData& field = form.fields[0]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 // userspecified and then address form. | 974 // userspecified and then address form. |
953 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); | 975 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); |
954 FormsSeen(forms); | 976 FormsSeen(forms); |
955 form_structures = autofill_manager_->GetFormStructures(); | 977 form_structures = autofill_manager_->GetFormStructures(); |
956 ASSERT_EQ(3U, form_structures.size()); | 978 ASSERT_EQ(3U, form_structures.size()); |
957 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); | 979 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); |
958 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); | 980 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); |
959 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 981 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
960 } | 982 } |
961 | 983 |
| 984 // Test that in the case of Autocheckout, forms seen are in order supplied. |
| 985 TEST_F(AutofillManagerTest, DynamicFormsSeen) { |
| 986 FormData shipping_options; |
| 987 CreateTestShippingOptionsFormData(&shipping_options); |
| 988 FormData user_supplied; |
| 989 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
| 990 FormData address; |
| 991 CreateTestAddressFormData(&address); |
| 992 |
| 993 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 994 // Push user_supplied only |
| 995 std::vector<FormData> forms; |
| 996 forms.push_back(user_supplied); |
| 997 |
| 998 // Make sure normal form is handled correctly. |
| 999 FormsSeen(forms); |
| 1000 std::vector<FormStructure*> form_structures; |
| 1001 form_structures = autofill_manager_->GetFormStructures(); |
| 1002 ASSERT_EQ(1U, form_structures.size()); |
| 1003 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
| 1004 |
| 1005 // Push other forms |
| 1006 forms.push_back(shipping_options); |
| 1007 forms.push_back(address); |
| 1008 |
| 1009 // FormStructure should contain three and only three forms. Otherwise, it |
| 1010 // would indicate that the manager didn't reset upon being notified of |
| 1011 // the new forms; |
| 1012 DynamicFormsSeen(forms); |
| 1013 form_structures = autofill_manager_->GetFormStructures(); |
| 1014 ASSERT_EQ(3U, form_structures.size()); |
| 1015 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
| 1016 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); |
| 1017 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
| 1018 } |
| 1019 |
962 // Test that we return only matching address profile suggestions when the | 1020 // Test that we return only matching address profile suggestions when the |
963 // selected form field has been partially filled out. | 1021 // selected form field has been partially filled out. |
964 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 1022 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
965 // Set up our form data. | 1023 // Set up our form data. |
966 FormData form; | 1024 FormData form; |
967 CreateTestAddressFormData(&form); | 1025 CreateTestAddressFormData(&form); |
968 std::vector<FormData> forms(1, form); | 1026 std::vector<FormData> forms(1, form); |
969 FormsSeen(forms); | 1027 FormsSeen(forms); |
970 | 1028 |
971 FormFieldData field; | 1029 FormFieldData field; |
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 | 3394 |
3337 FormData form; | 3395 FormData form; |
3338 CreateTestAddressFormData(&form); | 3396 CreateTestAddressFormData(&form); |
3339 std::vector<FormData> forms(1, form); | 3397 std::vector<FormData> forms(1, form); |
3340 FormsSeen(forms); | 3398 FormsSeen(forms); |
3341 const FormFieldData& field = form.fields[0]; | 3399 const FormFieldData& field = form.fields[0]; |
3342 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3400 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3343 | 3401 |
3344 autofill_manager_->SetExternalDelegate(NULL); | 3402 autofill_manager_->SetExternalDelegate(NULL); |
3345 } | 3403 } |
OLD | NEW |