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 Autocheckout is e nabled. | |
ahutter
2013/03/29 19:48:31
DOM
Dane Wallinga
2013/03/29 21:41:12
Done.
| |
892 TEST_F(AutofillManagerTest, GetAllDynamicForms) { | |
893 FormData form; | |
894 CreateTestAddressFormData(&form); | |
895 std::vector<FormData> forms(1, form); | |
896 // Enable autocheckout. | |
897 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | |
898 | |
899 PartialDynamicFormsSeen(forms); | |
900 | |
901 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | |
ahutter
2013/03/29 19:48:31
EXPECT_TRUE
Dane Wallinga
2013/03/29 21:41:12
Done.
| |
902 } | |
903 | |
883 // Test that we return all address profile suggestions when all form fields are | 904 // Test that we return all address profile suggestions when all form fields are |
884 // empty. | 905 // empty. |
885 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 906 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
886 // Set up our form data. | 907 // Set up our form data. |
887 FormData form; | 908 FormData form; |
888 CreateTestAddressFormData(&form); | 909 CreateTestAddressFormData(&form); |
889 std::vector<FormData> forms(1, form); | 910 std::vector<FormData> forms(1, form); |
890 FormsSeen(forms); | 911 FormsSeen(forms); |
891 | 912 |
892 const FormFieldData& field = form.fields[0]; | 913 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. | 973 // userspecified and then address form. |
953 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); | 974 autofill_manager_->set_autocheckout_url_prefix("yes-autocheckout"); |
954 FormsSeen(forms); | 975 FormsSeen(forms); |
955 form_structures = autofill_manager_->GetFormStructures(); | 976 form_structures = autofill_manager_->GetFormStructures(); |
956 ASSERT_EQ(3U, form_structures.size()); | 977 ASSERT_EQ(3U, form_structures.size()); |
957 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); | 978 EXPECT_EQ("/shipping.html", form_structures[0]->source_url().path()); |
958 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); | 979 EXPECT_EQ("/userspecified.html", form_structures[1]->source_url().path()); |
959 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 980 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
960 } | 981 } |
961 | 982 |
983 // Test that in the case of Autocheckout, forms seen are in order supplied. | |
984 TEST_F(AutofillManagerTest, DynamicFormsSeen) { | |
985 FormData shipping_options; | |
986 CreateTestShippingOptionsFormData(&shipping_options); | |
987 FormData user_supplied; | |
988 CreateTestFormWithAutocompleteAttribute(&user_supplied); | |
989 FormData address; | |
990 CreateTestAddressFormData(&address); | |
991 | |
992 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | |
993 // Push user_supplied only | |
994 std::vector<FormData> forms; | |
995 forms.push_back(user_supplied); | |
996 | |
997 // Make sure normal form is handled correctly. | |
998 FormsSeen(forms); | |
999 std::vector<FormStructure*> form_structures; | |
1000 form_structures = autofill_manager_->GetFormStructures(); | |
1001 ASSERT_EQ(1U, form_structures.size()); | |
1002 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); | |
1003 | |
1004 // Push other forms | |
1005 forms.push_back(shipping_options); | |
1006 forms.push_back(address); | |
1007 | |
1008 // FormStructure should contain three and only three forms. Otherwise, it | |
1009 // would indicate that the manager didn't reset upon being notified of | |
1010 // the new forms; | |
1011 DynamicFormsSeen(forms); | |
1012 form_structures = autofill_manager_->GetFormStructures(); | |
1013 ASSERT_EQ(3U, form_structures.size()); | |
1014 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); | |
1015 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); | |
1016 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | |
1017 } | |
1018 | |
962 // Test that we return only matching address profile suggestions when the | 1019 // Test that we return only matching address profile suggestions when the |
963 // selected form field has been partially filled out. | 1020 // selected form field has been partially filled out. |
964 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 1021 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
965 // Set up our form data. | 1022 // Set up our form data. |
966 FormData form; | 1023 FormData form; |
967 CreateTestAddressFormData(&form); | 1024 CreateTestAddressFormData(&form); |
968 std::vector<FormData> forms(1, form); | 1025 std::vector<FormData> forms(1, form); |
969 FormsSeen(forms); | 1026 FormsSeen(forms); |
970 | 1027 |
971 FormFieldData field; | 1028 FormFieldData field; |
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3336 | 3393 |
3337 FormData form; | 3394 FormData form; |
3338 CreateTestAddressFormData(&form); | 3395 CreateTestAddressFormData(&form); |
3339 std::vector<FormData> forms(1, form); | 3396 std::vector<FormData> forms(1, form); |
3340 FormsSeen(forms); | 3397 FormsSeen(forms); |
3341 const FormFieldData& field = form.fields[0]; | 3398 const FormFieldData& field = form.fields[0]; |
3342 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3399 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3343 | 3400 |
3344 autofill_manager_->SetExternalDelegate(NULL); | 3401 autofill_manager_->SetExternalDelegate(NULL); |
3345 } | 3402 } |
OLD | NEW |