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/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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 form->action = GURL("http://myform.com/submit.html"); | 237 form->action = GURL("http://myform.com/submit.html"); |
238 form->user_submitted = true; | 238 form->user_submitted = true; |
239 | 239 |
240 FormFieldData field; | 240 FormFieldData field; |
241 test::CreateTestFormField("Shipping1", "option", "option1", "radio", &field); | 241 test::CreateTestFormField("Shipping1", "option", "option1", "radio", &field); |
242 form->fields.push_back(field); | 242 form->fields.push_back(field); |
243 test::CreateTestFormField("Shipping2", "option", "option2", "radio", &field); | 243 test::CreateTestFormField("Shipping2", "option", "option2", "radio", &field); |
244 form->fields.push_back(field); | 244 form->fields.push_back(field); |
245 } | 245 } |
246 | 246 |
247 // Populates |form| with data corresponding to a simple address form. | |
248 // Note that this actually appends fields to the form data, which can be useful | |
249 // for building up more complex test forms. | |
250 void CreateTestAddressFormData(FormData* form) { | |
251 form->name = ASCIIToUTF16("MyForm"); | |
252 form->method = ASCIIToUTF16("POST"); | |
253 form->origin = GURL("http://myform.com/form.html"); | |
254 form->action = GURL("http://myform.com/submit.html"); | |
255 form->user_submitted = true; | |
256 | |
257 FormFieldData field; | |
258 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | |
259 form->fields.push_back(field); | |
260 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); | |
261 form->fields.push_back(field); | |
262 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); | |
263 form->fields.push_back(field); | |
264 test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field); | |
265 form->fields.push_back(field); | |
266 test::CreateTestFormField("Address Line 2", "addr2", "", "text", &field); | |
267 form->fields.push_back(field); | |
268 test::CreateTestFormField("City", "city", "", "text", &field); | |
269 form->fields.push_back(field); | |
270 test::CreateTestFormField("State", "state", "", "text", &field); | |
271 form->fields.push_back(field); | |
272 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); | |
273 form->fields.push_back(field); | |
274 test::CreateTestFormField("Country", "country", "", "text", &field); | |
275 form->fields.push_back(field); | |
276 test::CreateTestFormField("Phone Number", "phonenumber", "", "tel", &field); | |
277 form->fields.push_back(field); | |
278 test::CreateTestFormField("Email", "email", "", "email", &field); | |
279 form->fields.push_back(field); | |
280 } | |
281 | |
282 // Populates |form| with data corresponding to a simple credit card form. | 247 // Populates |form| with data corresponding to a simple credit card form. |
283 // Note that this actually appends fields to the form data, which can be useful | 248 // Note that this actually appends fields to the form data, which can be useful |
284 // for building up more complex test forms. | 249 // for building up more complex test forms. |
285 void CreateTestCreditCardFormData(FormData* form, | 250 void CreateTestCreditCardFormData(FormData* form, |
286 bool is_https, | 251 bool is_https, |
287 bool use_month_type) { | 252 bool use_month_type) { |
288 form->name = ASCIIToUTF16("MyForm"); | 253 form->name = ASCIIToUTF16("MyForm"); |
289 form->method = ASCIIToUTF16("POST"); | 254 form->method = ASCIIToUTF16("POST"); |
290 if (is_https) { | 255 if (is_https) { |
291 form->origin = GURL("https://myform.com/form.html"); | 256 form->origin = GURL("https://myform.com/form.html"); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 autofill_manager_->WaitForAsyncFormSubmit(); | 719 autofill_manager_->WaitForAsyncFormSubmit(); |
755 } | 720 } |
756 | 721 |
757 void FillAutofillFormData(int query_id, | 722 void FillAutofillFormData(int query_id, |
758 const FormData& form, | 723 const FormData& form, |
759 const FormFieldData& field, | 724 const FormFieldData& field, |
760 int unique_id) { | 725 int unique_id) { |
761 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 726 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
762 } | 727 } |
763 | 728 |
729 void FillAutofillFormDataAndSaveResults(int input_query_id, | |
blundell
2013/06/25 16:11:04
This was the cleanest approach I found to the test
Ilya Sherman
2013/06/26 22:54:58
nit: Docs, please.
Ilya Sherman
2013/06/26 22:54:58
The approach you're using now seems pretty good to
blundell
2013/06/27 21:58:27
Done.
| |
730 const FormData& input_form, | |
731 const FormFieldData& input_field, | |
732 int unique_id, | |
733 int* response_query_id, | |
734 FormData* response_data) { | |
735 EXPECT_CALL(*autofill_driver_, SendFormDataToRenderer(_, _)). | |
736 WillOnce((DoAll(testing::SaveArg<0>(response_query_id), | |
737 testing::SaveArg<1>(response_data)))); | |
738 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); | |
739 } | |
740 | |
764 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 741 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { |
765 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 742 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); |
766 } | 743 } |
767 | 744 |
768 bool GetAutofillSuggestionsMessage(int* page_id, | 745 bool GetAutofillSuggestionsMessage(int* page_id, |
769 std::vector<base::string16>* values, | 746 std::vector<base::string16>* values, |
770 std::vector<base::string16>* labels, | 747 std::vector<base::string16>* labels, |
771 std::vector<base::string16>* icons, | 748 std::vector<base::string16>* icons, |
772 std::vector<int>* unique_ids) { | 749 std::vector<int>* unique_ids) { |
773 const uint32 kMsgID = AutofillMsg_SuggestionsReturned::ID; | 750 const uint32 kMsgID = AutofillMsg_SuggestionsReturned::ID; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 UpdateAutofillCount(); | 826 UpdateAutofillCount(); |
850 } | 827 } |
851 | 828 |
852 private: | 829 private: |
853 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 830 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
854 }; | 831 }; |
855 | 832 |
856 // Test that browser asks for all forms when Autocheckout is enabled. | 833 // Test that browser asks for all forms when Autocheckout is enabled. |
857 TEST_F(AutofillManagerTest, GetAllForms) { | 834 TEST_F(AutofillManagerTest, GetAllForms) { |
858 FormData form; | 835 FormData form; |
859 CreateTestAddressFormData(&form); | 836 test::CreateTestAddressFormData(&form); |
860 std::vector<FormData> forms(1, form); | 837 std::vector<FormData> forms(1, form); |
861 // Enable autocheckout. | 838 // Enable autocheckout. |
862 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 839 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
863 | 840 |
864 PartialFormsSeen(forms); | 841 PartialFormsSeen(forms); |
865 | 842 |
866 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | 843 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
867 } | 844 } |
868 | 845 |
869 // Test that we return all address profile suggestions when all form fields are | 846 // Test that we return all address profile suggestions when all form fields are |
870 // empty. | 847 // empty. |
871 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 848 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
872 // Set up our form data. | 849 // Set up our form data. |
873 FormData form; | 850 FormData form; |
874 CreateTestAddressFormData(&form); | 851 test::CreateTestAddressFormData(&form); |
875 std::vector<FormData> forms(1, form); | 852 std::vector<FormData> forms(1, form); |
876 FormsSeen(forms); | 853 FormsSeen(forms); |
877 | 854 |
878 const FormFieldData& field = form.fields[0]; | 855 const FormFieldData& field = form.fields[0]; |
879 GetAutofillSuggestions(form, field); | 856 GetAutofillSuggestions(form, field); |
880 | 857 |
881 // No suggestions provided, so send an empty vector as the results. | 858 // No suggestions provided, so send an empty vector as the results. |
882 // This triggers the combined message send. | 859 // This triggers the combined message send. |
883 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 860 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
884 | 861 |
(...skipping 23 matching lines...) Expand all Loading... | |
908 expected_labels, expected_icons, expected_unique_ids); | 885 expected_labels, expected_icons, expected_unique_ids); |
909 } | 886 } |
910 | 887 |
911 // Test that in the case of Autocheckout, forms seen are in order supplied. | 888 // Test that in the case of Autocheckout, forms seen are in order supplied. |
912 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { | 889 TEST_F(AutofillManagerTest, AutocheckoutFormsSeen) { |
913 FormData shipping_options; | 890 FormData shipping_options; |
914 CreateTestShippingOptionsFormData(&shipping_options); | 891 CreateTestShippingOptionsFormData(&shipping_options); |
915 FormData user_supplied; | 892 FormData user_supplied; |
916 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 893 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
917 FormData address; | 894 FormData address; |
918 CreateTestAddressFormData(&address); | 895 test::CreateTestAddressFormData(&address); |
919 | 896 |
920 // Push user_supplied before address and observe order changing when | 897 // Push user_supplied before address and observe order changing when |
921 // Autocheckout is not enabled.. | 898 // Autocheckout is not enabled.. |
922 std::vector<FormData> forms; | 899 std::vector<FormData> forms; |
923 forms.push_back(shipping_options); | 900 forms.push_back(shipping_options); |
924 forms.push_back(user_supplied); | 901 forms.push_back(user_supplied); |
925 forms.push_back(address); | 902 forms.push_back(address); |
926 | 903 |
927 // Test without enabling Autocheckout. FormStructure should only contain | 904 // Test without enabling Autocheckout. FormStructure should only contain |
928 // form1. Shipping Options form will not qualify as parsable form. | 905 // form1. Shipping Options form will not qualify as parsable form. |
(...skipping 16 matching lines...) Expand all Loading... | |
945 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 922 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
946 } | 923 } |
947 | 924 |
948 // Test that in the case of Autocheckout, forms seen are in order supplied. | 925 // Test that in the case of Autocheckout, forms seen are in order supplied. |
949 TEST_F(AutofillManagerTest, DynamicFormsSeen) { | 926 TEST_F(AutofillManagerTest, DynamicFormsSeen) { |
950 FormData shipping_options; | 927 FormData shipping_options; |
951 CreateTestShippingOptionsFormData(&shipping_options); | 928 CreateTestShippingOptionsFormData(&shipping_options); |
952 FormData user_supplied; | 929 FormData user_supplied; |
953 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 930 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
954 FormData address; | 931 FormData address; |
955 CreateTestAddressFormData(&address); | 932 test::CreateTestAddressFormData(&address); |
956 | 933 |
957 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 934 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
958 // Push user_supplied only | 935 // Push user_supplied only |
959 std::vector<FormData> forms; | 936 std::vector<FormData> forms; |
960 forms.push_back(user_supplied); | 937 forms.push_back(user_supplied); |
961 | 938 |
962 // Make sure normal form is handled correctly. | 939 // Make sure normal form is handled correctly. |
963 FormsSeen(forms); | 940 FormsSeen(forms); |
964 std::vector<FormStructure*> form_structures; | 941 std::vector<FormStructure*> form_structures; |
965 form_structures = autofill_manager_->GetFormStructures(); | 942 form_structures = autofill_manager_->GetFormStructures(); |
(...skipping 13 matching lines...) Expand all Loading... | |
979 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); | 956 EXPECT_EQ("/userspecified.html", form_structures[0]->source_url().path()); |
980 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); | 957 EXPECT_EQ("/shipping.html", form_structures[1]->source_url().path()); |
981 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); | 958 EXPECT_EQ("/form.html", form_structures[2]->source_url().path()); |
982 } | 959 } |
983 | 960 |
984 // Test that we return only matching address profile suggestions when the | 961 // Test that we return only matching address profile suggestions when the |
985 // selected form field has been partially filled out. | 962 // selected form field has been partially filled out. |
986 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { | 963 TEST_F(AutofillManagerTest, GetProfileSuggestionsMatchCharacter) { |
987 // Set up our form data. | 964 // Set up our form data. |
988 FormData form; | 965 FormData form; |
989 CreateTestAddressFormData(&form); | 966 test::CreateTestAddressFormData(&form); |
990 std::vector<FormData> forms(1, form); | 967 std::vector<FormData> forms(1, form); |
991 FormsSeen(forms); | 968 FormsSeen(forms); |
992 | 969 |
993 FormFieldData field; | 970 FormFieldData field; |
994 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); | 971 test::CreateTestFormField("First Name", "firstname", "E", "text",&field); |
995 GetAutofillSuggestions(form, field); | 972 GetAutofillSuggestions(form, field); |
996 | 973 |
997 // No suggestions provided, so send an empty vector as the results. | 974 // No suggestions provided, so send an empty vector as the results. |
998 // This triggers the combined message send. | 975 // This triggers the combined message send. |
999 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 976 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 FormsSeen(forms); | 1017 FormsSeen(forms); |
1041 | 1018 |
1042 GetAutofillSuggestions(form, field); | 1019 GetAutofillSuggestions(form, field); |
1043 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1020 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
1044 } | 1021 } |
1045 | 1022 |
1046 // Test that we cull duplicate profile suggestions. | 1023 // Test that we cull duplicate profile suggestions. |
1047 TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) { | 1024 TEST_F(AutofillManagerTest, GetProfileSuggestionsWithDuplicates) { |
1048 // Set up our form data. | 1025 // Set up our form data. |
1049 FormData form; | 1026 FormData form; |
1050 CreateTestAddressFormData(&form); | 1027 test::CreateTestAddressFormData(&form); |
1051 std::vector<FormData> forms(1, form); | 1028 std::vector<FormData> forms(1, form); |
1052 FormsSeen(forms); | 1029 FormsSeen(forms); |
1053 | 1030 |
1054 // Add a duplicate profile. | 1031 // Add a duplicate profile. |
1055 AutofillProfile* duplicate_profile = | 1032 AutofillProfile* duplicate_profile = |
1056 new AutofillProfile( | 1033 new AutofillProfile( |
1057 *(autofill_manager_->GetProfileWithGUID( | 1034 *(autofill_manager_->GetProfileWithGUID( |
1058 "00000000-0000-0000-0000-000000000001"))); | 1035 "00000000-0000-0000-0000-000000000001"))); |
1059 autofill_manager_->AddProfile(duplicate_profile); | 1036 autofill_manager_->AddProfile(duplicate_profile); |
1060 | 1037 |
(...skipping 25 matching lines...) Expand all Loading... | |
1086 int expected_unique_ids[] = {1, 2}; | 1063 int expected_unique_ids[] = {1, 2}; |
1087 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1064 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1088 kDefaultPageID, arraysize(expected_values), expected_values, | 1065 kDefaultPageID, arraysize(expected_values), expected_values, |
1089 expected_labels, expected_icons, expected_unique_ids); | 1066 expected_labels, expected_icons, expected_unique_ids); |
1090 } | 1067 } |
1091 | 1068 |
1092 // Test that we return no suggestions when autofill is disabled. | 1069 // Test that we return no suggestions when autofill is disabled. |
1093 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { | 1070 TEST_F(AutofillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) { |
1094 // Set up our form data. | 1071 // Set up our form data. |
1095 FormData form; | 1072 FormData form; |
1096 CreateTestAddressFormData(&form); | 1073 test::CreateTestAddressFormData(&form); |
1097 std::vector<FormData> forms(1, form); | 1074 std::vector<FormData> forms(1, form); |
1098 FormsSeen(forms); | 1075 FormsSeen(forms); |
1099 | 1076 |
1100 // Disable Autofill. | 1077 // Disable Autofill. |
1101 autofill_manager_->set_autofill_enabled(false); | 1078 autofill_manager_->set_autofill_enabled(false); |
1102 | 1079 |
1103 const FormFieldData& field = form.fields[0]; | 1080 const FormFieldData& field = form.fields[0]; |
1104 GetAutofillSuggestions(form, field); | 1081 GetAutofillSuggestions(form, field); |
1105 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1082 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
1106 } | 1083 } |
1107 | 1084 |
1108 // Test that we return a warning explaining that autofill suggestions are | 1085 // Test that we return a warning explaining that autofill suggestions are |
1109 // unavailable when the form method is GET rather than POST. | 1086 // unavailable when the form method is GET rather than POST. |
1110 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { | 1087 TEST_F(AutofillManagerTest, GetProfileSuggestionsMethodGet) { |
1111 // Set up our form data. | 1088 // Set up our form data. |
1112 FormData form; | 1089 FormData form; |
1113 CreateTestAddressFormData(&form); | 1090 test::CreateTestAddressFormData(&form); |
1114 form.method = ASCIIToUTF16("GET"); | 1091 form.method = ASCIIToUTF16("GET"); |
1115 std::vector<FormData> forms(1, form); | 1092 std::vector<FormData> forms(1, form); |
1116 FormsSeen(forms); | 1093 FormsSeen(forms); |
1117 | 1094 |
1118 const FormFieldData& field = form.fields[0]; | 1095 const FormFieldData& field = form.fields[0]; |
1119 GetAutofillSuggestions(form, field); | 1096 GetAutofillSuggestions(form, field); |
1120 | 1097 |
1121 // No suggestions provided, so send an empty vector as the results. | 1098 // No suggestions provided, so send an empty vector as the results. |
1122 // This triggers the combined message send. | 1099 // This triggers the combined message send. |
1123 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1100 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1421 }; | 1398 }; |
1422 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1399 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1423 kDefaultPageID, arraysize(expected_values), expected_values, | 1400 kDefaultPageID, arraysize(expected_values), expected_values, |
1424 expected_labels, expected_icons, expected_unique_ids); | 1401 expected_labels, expected_icons, expected_unique_ids); |
1425 } | 1402 } |
1426 | 1403 |
1427 // Test that we return profile and credit card suggestions for combined forms. | 1404 // Test that we return profile and credit card suggestions for combined forms. |
1428 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { | 1405 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestions) { |
1429 // Set up our form data. | 1406 // Set up our form data. |
1430 FormData form; | 1407 FormData form; |
1431 CreateTestAddressFormData(&form); | 1408 test::CreateTestAddressFormData(&form); |
1432 CreateTestCreditCardFormData(&form, true, false); | 1409 CreateTestCreditCardFormData(&form, true, false); |
1433 std::vector<FormData> forms(1, form); | 1410 std::vector<FormData> forms(1, form); |
1434 FormsSeen(forms); | 1411 FormsSeen(forms); |
1435 | 1412 |
1436 FormFieldData field = form.fields[0]; | 1413 FormFieldData field = form.fields[0]; |
1437 GetAutofillSuggestions(form, field); | 1414 GetAutofillSuggestions(form, field); |
1438 | 1415 |
1439 // No suggestions provided, so send an empty vector as the results. | 1416 // No suggestions provided, so send an empty vector as the results. |
1440 // This triggers the combined message send. | 1417 // This triggers the combined message send. |
1441 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1418 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1495 expected_labels2, expected_icons2, expected_unique_ids2); | 1472 expected_labels2, expected_icons2, expected_unique_ids2); |
1496 } | 1473 } |
1497 | 1474 |
1498 // Test that for non-https forms with both address and credit card fields, we | 1475 // Test that for non-https forms with both address and credit card fields, we |
1499 // only return address suggestions. Instead of credit card suggestions, we | 1476 // only return address suggestions. Instead of credit card suggestions, we |
1500 // should return a warning explaining that credit card profile suggestions are | 1477 // should return a warning explaining that credit card profile suggestions are |
1501 // unavailable when the form is not https. | 1478 // unavailable when the form is not https. |
1502 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 1479 TEST_F(AutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
1503 // Set up our form data. | 1480 // Set up our form data. |
1504 FormData form; | 1481 FormData form; |
1505 CreateTestAddressFormData(&form); | 1482 test::CreateTestAddressFormData(&form); |
1506 CreateTestCreditCardFormData(&form, false, false); | 1483 CreateTestCreditCardFormData(&form, false, false); |
1507 std::vector<FormData> forms(1, form); | 1484 std::vector<FormData> forms(1, form); |
1508 FormsSeen(forms); | 1485 FormsSeen(forms); |
1509 | 1486 |
1510 FormFieldData field = form.fields[0]; | 1487 FormFieldData field = form.fields[0]; |
1511 GetAutofillSuggestions(form, field); | 1488 GetAutofillSuggestions(form, field); |
1512 | 1489 |
1513 // No suggestions provided, so send an empty vector as the results. | 1490 // No suggestions provided, so send an empty vector as the results. |
1514 // This triggers the combined message send. | 1491 // This triggers the combined message send. |
1515 AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 1492 AutocompleteSuggestionsReturned(std::vector<base::string16>()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1539 // Clear the test credit cards and try again -- we shouldn't return a warning. |
1563 personal_data_.ClearCreditCards(); | 1540 personal_data_.ClearCreditCards(); |
1564 GetAutofillSuggestions(form, field); | 1541 GetAutofillSuggestions(form, field); |
1565 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); | 1542 EXPECT_FALSE(GetAutofillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL)); |
1566 } | 1543 } |
1567 | 1544 |
1568 // Test that we correctly combine autofill and autocomplete suggestions. | 1545 // Test that we correctly combine autofill and autocomplete suggestions. |
1569 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { | 1546 TEST_F(AutofillManagerTest, GetCombinedAutofillAndAutocompleteSuggestions) { |
1570 // Set up our form data. | 1547 // Set up our form data. |
1571 FormData form; | 1548 FormData form; |
1572 CreateTestAddressFormData(&form); | 1549 test::CreateTestAddressFormData(&form); |
1573 std::vector<FormData> forms(1, form); | 1550 std::vector<FormData> forms(1, form); |
1574 FormsSeen(forms); | 1551 FormsSeen(forms); |
1575 | 1552 |
1576 const FormFieldData& field = form.fields[0]; | 1553 const FormFieldData& field = form.fields[0]; |
1577 GetAutofillSuggestions(form, field); | 1554 GetAutofillSuggestions(form, field); |
1578 | 1555 |
1579 // Add some Autocomplete suggestions. | 1556 // Add some Autocomplete suggestions. |
1580 // This triggers the combined message send. | 1557 // This triggers the combined message send. |
1581 std::vector<base::string16> suggestions; | 1558 std::vector<base::string16> suggestions; |
1582 suggestions.push_back(ASCIIToUTF16("Jay")); | 1559 suggestions.push_back(ASCIIToUTF16("Jay")); |
(...skipping 29 matching lines...) Expand all Loading... | |
1612 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1589 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1613 kDefaultPageID, arraysize(expected_values), expected_values, | 1590 kDefaultPageID, arraysize(expected_values), expected_values, |
1614 expected_labels, expected_icons, expected_unique_ids); | 1591 expected_labels, expected_icons, expected_unique_ids); |
1615 } | 1592 } |
1616 | 1593 |
1617 // Test that we return autocomplete-like suggestions when trying to autofill | 1594 // Test that we return autocomplete-like suggestions when trying to autofill |
1618 // already filled forms. | 1595 // already filled forms. |
1619 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { | 1596 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutofilled) { |
1620 // Set up our form data. | 1597 // Set up our form data. |
1621 FormData form; | 1598 FormData form; |
1622 CreateTestAddressFormData(&form); | 1599 test::CreateTestAddressFormData(&form); |
1623 std::vector<FormData> forms(1, form); | 1600 std::vector<FormData> forms(1, form); |
1624 FormsSeen(forms); | 1601 FormsSeen(forms); |
1625 | 1602 |
1626 // Mark one of the fields as filled. | 1603 // Mark one of the fields as filled. |
1627 form.fields[2].is_autofilled = true; | 1604 form.fields[2].is_autofilled = true; |
1628 const FormFieldData& field = form.fields[0]; | 1605 const FormFieldData& field = form.fields[0]; |
1629 GetAutofillSuggestions(form, field); | 1606 GetAutofillSuggestions(form, field); |
1630 | 1607 |
1631 // No suggestions provided, so send an empty vector as the results. | 1608 // No suggestions provided, so send an empty vector as the results. |
1632 // This triggers the combined message send. | 1609 // This triggers the combined message send. |
(...skipping 17 matching lines...) Expand all Loading... | |
1650 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1627 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1651 kDefaultPageID, arraysize(expected_values), expected_values, | 1628 kDefaultPageID, arraysize(expected_values), expected_values, |
1652 expected_labels, expected_icons, expected_unique_ids); | 1629 expected_labels, expected_icons, expected_unique_ids); |
1653 } | 1630 } |
1654 | 1631 |
1655 // Test that nothing breaks when there are autocomplete suggestions but no | 1632 // Test that nothing breaks when there are autocomplete suggestions but no |
1656 // autofill suggestions. | 1633 // autofill suggestions. |
1657 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { | 1634 TEST_F(AutofillManagerTest, GetFieldSuggestionsForAutocompleteOnly) { |
1658 // Set up our form data. | 1635 // Set up our form data. |
1659 FormData form; | 1636 FormData form; |
1660 CreateTestAddressFormData(&form); | 1637 test::CreateTestAddressFormData(&form); |
1661 FormFieldData field; | 1638 FormFieldData field; |
1662 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); | 1639 test::CreateTestFormField("Some Field", "somefield", "", "text", &field); |
1663 form.fields.push_back(field); | 1640 form.fields.push_back(field); |
1664 std::vector<FormData> forms(1, form); | 1641 std::vector<FormData> forms(1, form); |
1665 FormsSeen(forms); | 1642 FormsSeen(forms); |
1666 | 1643 |
1667 GetAutofillSuggestions(form, field); | 1644 GetAutofillSuggestions(form, field); |
1668 | 1645 |
1669 // Add some Autocomplete suggestions. | 1646 // Add some Autocomplete suggestions. |
1670 // This triggers the combined message send. | 1647 // This triggers the combined message send. |
(...skipping 21 matching lines...) Expand all Loading... | |
1692 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1669 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1693 kDefaultPageID, arraysize(expected_values), expected_values, | 1670 kDefaultPageID, arraysize(expected_values), expected_values, |
1694 expected_labels, expected_icons, expected_unique_ids); | 1671 expected_labels, expected_icons, expected_unique_ids); |
1695 } | 1672 } |
1696 | 1673 |
1697 // Test that we do not return duplicate values drawn from multiple profiles when | 1674 // Test that we do not return duplicate values drawn from multiple profiles when |
1698 // filling an already filled field. | 1675 // filling an already filled field. |
1699 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { | 1676 TEST_F(AutofillManagerTest, GetFieldSuggestionsWithDuplicateValues) { |
1700 // Set up our form data. | 1677 // Set up our form data. |
1701 FormData form; | 1678 FormData form; |
1702 CreateTestAddressFormData(&form); | 1679 test::CreateTestAddressFormData(&form); |
1703 std::vector<FormData> forms(1, form); | 1680 std::vector<FormData> forms(1, form); |
1704 FormsSeen(forms); | 1681 FormsSeen(forms); |
1705 | 1682 |
1706 // |profile| will be owned by the mock PersonalDataManager. | 1683 // |profile| will be owned by the mock PersonalDataManager. |
1707 AutofillProfile* profile = new AutofillProfile; | 1684 AutofillProfile* profile = new AutofillProfile; |
1708 test::SetProfileInfo( | 1685 test::SetProfileInfo( |
1709 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); | 1686 profile, "Elvis", "", "", "", "", "", "", "", "", "", "", ""); |
1710 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1687 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
1711 autofill_manager_->AddProfile(profile); | 1688 autofill_manager_->AddProfile(profile); |
1712 | 1689 |
(...skipping 22 matching lines...) Expand all Loading... | |
1735 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1712 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1736 kDefaultPageID, arraysize(expected_values), expected_values, | 1713 kDefaultPageID, arraysize(expected_values), expected_values, |
1737 expected_labels, expected_icons, expected_unique_ids); | 1714 expected_labels, expected_icons, expected_unique_ids); |
1738 } | 1715 } |
1739 | 1716 |
1740 // Test that a non-default value is suggested for multi-valued profile, on an | 1717 // Test that a non-default value is suggested for multi-valued profile, on an |
1741 // unfilled form. | 1718 // unfilled form. |
1742 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { | 1719 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileUnfilled) { |
1743 // Set up our form data. | 1720 // Set up our form data. |
1744 FormData form; | 1721 FormData form; |
1745 CreateTestAddressFormData(&form); | 1722 test::CreateTestAddressFormData(&form); |
1746 std::vector<FormData> forms(1, form); | 1723 std::vector<FormData> forms(1, form); |
1747 FormsSeen(forms); | 1724 FormsSeen(forms); |
1748 | 1725 |
1749 // |profile| will be owned by the mock PersonalDataManager. | 1726 // |profile| will be owned by the mock PersonalDataManager. |
1750 AutofillProfile* profile = new AutofillProfile; | 1727 AutofillProfile* profile = new AutofillProfile; |
1751 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", | 1728 test::SetProfileInfo(profile, "Elvis", "", "Presley", "me@x.com", "", |
1752 "", "", "", "", "", "", ""); | 1729 "", "", "", "", "", "", ""); |
1753 profile->set_guid("00000000-0000-0000-0000-000000000101"); | 1730 profile->set_guid("00000000-0000-0000-0000-000000000101"); |
1754 std::vector<base::string16> multi_values(2); | 1731 std::vector<base::string16> multi_values(2); |
1755 multi_values[0] = ASCIIToUTF16("Elvis Presley"); | 1732 multi_values[0] = ASCIIToUTF16("Elvis Presley"); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1822 expected_values, expected_labels, expected_icons, | 1799 expected_values, expected_labels, expected_icons, |
1823 expected_unique_ids); | 1800 expected_unique_ids); |
1824 } | 1801 } |
1825 } | 1802 } |
1826 | 1803 |
1827 // Test that all values are suggested for multi-valued profile, on a filled | 1804 // Test that all values are suggested for multi-valued profile, on a filled |
1828 // form. This is the per-field "override" case. | 1805 // form. This is the per-field "override" case. |
1829 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { | 1806 TEST_F(AutofillManagerTest, GetFieldSuggestionsForMultiValuedProfileFilled) { |
1830 // Set up our form data. | 1807 // Set up our form data. |
1831 FormData form; | 1808 FormData form; |
1832 CreateTestAddressFormData(&form); | 1809 test::CreateTestAddressFormData(&form); |
1833 std::vector<FormData> forms(1, form); | 1810 std::vector<FormData> forms(1, form); |
1834 FormsSeen(forms); | 1811 FormsSeen(forms); |
1835 | 1812 |
1836 // |profile| will be owned by the mock PersonalDataManager. | 1813 // |profile| will be owned by the mock PersonalDataManager. |
1837 AutofillProfile* profile = new AutofillProfile; | 1814 AutofillProfile* profile = new AutofillProfile; |
1838 profile->set_guid("00000000-0000-0000-0000-000000000102"); | 1815 profile->set_guid("00000000-0000-0000-0000-000000000102"); |
1839 std::vector<base::string16> multi_values(3); | 1816 std::vector<base::string16> multi_values(3); |
1840 multi_values[0] = ASCIIToUTF16("Travis Smith"); | 1817 multi_values[0] = ASCIIToUTF16("Travis Smith"); |
1841 multi_values[1] = ASCIIToUTF16("Cynthia Love"); | 1818 multi_values[1] = ASCIIToUTF16("Cynthia Love"); |
1842 multi_values[2] = ASCIIToUTF16("Zac Mango"); | 1819 multi_values[2] = ASCIIToUTF16("Zac Mango"); |
(...skipping 30 matching lines...) Expand all Loading... | |
1873 base::string16() }; | 1850 base::string16() }; |
1874 int expected_unique_ids[] = { 1, 2, 3 }; | 1851 int expected_unique_ids[] = { 1, 2, 3 }; |
1875 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1852 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1876 kDefaultPageID, arraysize(expected_values), expected_values, | 1853 kDefaultPageID, arraysize(expected_values), expected_values, |
1877 expected_labels, expected_icons, expected_unique_ids); | 1854 expected_labels, expected_icons, expected_unique_ids); |
1878 } | 1855 } |
1879 | 1856 |
1880 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { | 1857 TEST_F(AutofillManagerTest, GetProfileSuggestionsFancyPhone) { |
1881 // Set up our form data. | 1858 // Set up our form data. |
1882 FormData form; | 1859 FormData form; |
1883 CreateTestAddressFormData(&form); | 1860 test::CreateTestAddressFormData(&form); |
1884 std::vector<FormData> forms(1, form); | 1861 std::vector<FormData> forms(1, form); |
1885 FormsSeen(forms); | 1862 FormsSeen(forms); |
1886 | 1863 |
1887 AutofillProfile* profile = new AutofillProfile; | 1864 AutofillProfile* profile = new AutofillProfile; |
1888 profile->set_guid("00000000-0000-0000-0000-000000000103"); | 1865 profile->set_guid("00000000-0000-0000-0000-000000000103"); |
1889 std::vector<base::string16> multi_values(1); | 1866 std::vector<base::string16> multi_values(1); |
1890 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); | 1867 multi_values[0] = ASCIIToUTF16("Natty Bumppo"); |
1891 profile->SetRawMultiInfo(NAME_FULL, multi_values); | 1868 profile->SetRawMultiInfo(NAME_FULL, multi_values); |
1892 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); | 1869 multi_values[0] = ASCIIToUTF16("1800PRAIRIE"); |
1893 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); | 1870 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, multi_values); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1926 int expected_unique_ids[] = {1, 2, 3}; | 1903 int expected_unique_ids[] = {1, 2, 3}; |
1927 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 1904 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
1928 kDefaultPageID, arraysize(expected_values), expected_values, | 1905 kDefaultPageID, arraysize(expected_values), expected_values, |
1929 expected_labels, expected_icons, expected_unique_ids); | 1906 expected_labels, expected_icons, expected_unique_ids); |
1930 } | 1907 } |
1931 | 1908 |
1932 // Test that we correctly fill an address form. | 1909 // Test that we correctly fill an address form. |
1933 TEST_F(AutofillManagerTest, FillAddressForm) { | 1910 TEST_F(AutofillManagerTest, FillAddressForm) { |
1934 // Set up our form data. | 1911 // Set up our form data. |
1935 FormData form; | 1912 FormData form; |
1936 CreateTestAddressFormData(&form); | 1913 test::CreateTestAddressFormData(&form); |
1937 std::vector<FormData> forms(1, form); | 1914 std::vector<FormData> forms(1, form); |
1938 FormsSeen(forms); | 1915 FormsSeen(forms); |
1939 | 1916 |
1940 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1917 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
1941 GUIDPair empty(std::string(), 0); | 1918 GUIDPair empty(std::string(), 0); |
1942 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 1919 int response_page_id = 0; |
1943 PackGUIDs(empty, guid)); | 1920 FormData response_data; |
1944 | 1921 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
1945 int page_id = 0; | 1922 PackGUIDs(empty, guid), &response_page_id, &response_data); |
1946 FormData results; | 1923 ExpectFilledAddressFormElvis( |
1947 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1924 response_page_id, response_data, kDefaultPageID, false); |
1948 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | |
1949 } | 1925 } |
1950 | 1926 |
1951 // Test that we correctly fill an address form from an auxiliary profile. | 1927 // Test that we correctly fill an address form from an auxiliary profile. |
1952 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1928 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
1953 personal_data_.ClearAutofillProfiles(); | 1929 personal_data_.ClearAutofillProfiles(); |
1954 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); | 1930 PrefService* prefs = user_prefs::UserPrefs::Get(profile()); |
1955 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1931 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); |
1956 personal_data_.CreateTestAuxiliaryProfiles(); | 1932 personal_data_.CreateTestAuxiliaryProfiles(); |
1957 | 1933 |
1958 // Set up our form data. | 1934 // Set up our form data. |
1959 FormData form; | 1935 FormData form; |
1960 CreateTestAddressFormData(&form); | 1936 test::CreateTestAddressFormData(&form); |
1961 std::vector<FormData> forms(1, form); | 1937 std::vector<FormData> forms(1, form); |
1962 FormsSeen(forms); | 1938 FormsSeen(forms); |
1963 | 1939 |
1964 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 1940 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
1965 GUIDPair empty(std::string(), 0); | 1941 GUIDPair empty(std::string(), 0); |
1966 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 1942 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
1967 PackGUIDs(empty, guid)); | 1943 PackGUIDs(empty, guid)); |
1968 | 1944 |
1969 int page_id = 0; | 1945 int page_id = 0; |
1970 FormData results; | 1946 FormData results; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2086 FormData results; | 2062 FormData results; |
2087 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2063 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
2088 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, | 2064 ExpectFilledCreditCardYearMonthWithYearMonth(page_id, results, |
2089 kDefaultPageID, false, "2012", "04"); | 2065 kDefaultPageID, false, "2012", "04"); |
2090 } | 2066 } |
2091 | 2067 |
2092 // Test that we correctly fill a combined address and credit card form. | 2068 // Test that we correctly fill a combined address and credit card form. |
2093 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { | 2069 TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { |
2094 // Set up our form data. | 2070 // Set up our form data. |
2095 FormData form; | 2071 FormData form; |
2096 CreateTestAddressFormData(&form); | 2072 test::CreateTestAddressFormData(&form); |
2097 CreateTestCreditCardFormData(&form, true, false); | 2073 CreateTestCreditCardFormData(&form, true, false); |
2098 std::vector<FormData> forms(1, form); | 2074 std::vector<FormData> forms(1, form); |
2099 FormsSeen(forms); | 2075 FormsSeen(forms); |
2100 | 2076 |
2101 // First fill the address data. | 2077 // First fill the address data. |
2102 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2078 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2103 GUIDPair empty(std::string(), 0); | 2079 GUIDPair empty(std::string(), 0); |
2104 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2080 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
2105 PackGUIDs(empty, guid)); | 2081 PackGUIDs(empty, guid)); |
2106 | 2082 |
(...skipping 17 matching lines...) Expand all Loading... | |
2124 SCOPED_TRACE("Credit card"); | 2100 SCOPED_TRACE("Credit card"); |
2125 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); | 2101 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); |
2126 } | 2102 } |
2127 } | 2103 } |
2128 | 2104 |
2129 // Test that we correctly fill a form that has multiple logical sections, e.g. | 2105 // Test that we correctly fill a form that has multiple logical sections, e.g. |
2130 // both a billing and a shipping address. | 2106 // both a billing and a shipping address. |
2131 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) { | 2107 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) { |
2132 // Set up our form data. | 2108 // Set up our form data. |
2133 FormData form; | 2109 FormData form; |
2134 CreateTestAddressFormData(&form); | 2110 test::CreateTestAddressFormData(&form); |
2135 const size_t kAddressFormSize = form.fields.size(); | 2111 const size_t kAddressFormSize = form.fields.size(); |
2136 CreateTestAddressFormData(&form); | 2112 test::CreateTestAddressFormData(&form); |
2137 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { | 2113 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { |
2138 // Make sure the fields have distinct names. | 2114 // Make sure the fields have distinct names. |
2139 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); | 2115 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_"); |
2140 } | 2116 } |
2141 std::vector<FormData> forms(1, form); | 2117 std::vector<FormData> forms(1, form); |
2142 FormsSeen(forms); | 2118 FormsSeen(forms); |
2143 | 2119 |
2144 // Fill the first section. | 2120 // Fill the first section. |
2145 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2121 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2146 GUIDPair empty(std::string(), 0); | 2122 GUIDPair empty(std::string(), 0); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2356 ExpectFilledField("", "ccexp", "04/2012", "text", results.fields[9]); | 2332 ExpectFilledField("", "ccexp", "04/2012", "text", results.fields[9]); |
2357 ExpectFilledField("", "email", "", "text", results.fields[10]); | 2333 ExpectFilledField("", "email", "", "text", results.fields[10]); |
2358 } | 2334 } |
2359 } | 2335 } |
2360 | 2336 |
2361 // Test that we correctly fill a form that has a single logical section with | 2337 // Test that we correctly fill a form that has a single logical section with |
2362 // multiple email address fields. | 2338 // multiple email address fields. |
2363 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { | 2339 TEST_F(AutofillManagerTest, FillFormWithMultipleEmails) { |
2364 // Set up our form data. | 2340 // Set up our form data. |
2365 FormData form; | 2341 FormData form; |
2366 CreateTestAddressFormData(&form); | 2342 test::CreateTestAddressFormData(&form); |
2367 FormFieldData field; | 2343 FormFieldData field; |
2368 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); | 2344 test::CreateTestFormField("Confirm email", "email2", "", "text", &field); |
2369 form.fields.push_back(field); | 2345 form.fields.push_back(field); |
2370 | 2346 |
2371 std::vector<FormData> forms(1, form); | 2347 std::vector<FormData> forms(1, form); |
2372 FormsSeen(forms); | 2348 FormsSeen(forms); |
2373 | 2349 |
2374 // Fill the form. | 2350 // Fill the form. |
2375 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2351 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2376 GUIDPair empty(std::string(), 0); | 2352 GUIDPair empty(std::string(), 0); |
2377 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2353 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
2378 PackGUIDs(empty, guid)); | 2354 PackGUIDs(empty, guid)); |
2379 | 2355 |
2380 int page_id = 0; | 2356 int page_id = 0; |
2381 FormData results; | 2357 FormData results; |
2382 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2358 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
2383 | 2359 |
2384 // The second email address should be filled. | 2360 // The second email address should be filled. |
2385 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), results.fields.back().value); | 2361 EXPECT_EQ(ASCIIToUTF16("theking@gmail.com"), results.fields.back().value); |
2386 | 2362 |
2387 // The remainder of the form should be filled as usual. | 2363 // The remainder of the form should be filled as usual. |
2388 results.fields.pop_back(); | 2364 results.fields.pop_back(); |
2389 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2365 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
2390 } | 2366 } |
2391 | 2367 |
2392 // Test that we correctly fill a previously auto-filled form. | 2368 // Test that we correctly fill a previously auto-filled form. |
2393 TEST_F(AutofillManagerTest, FillAutofilledForm) { | 2369 TEST_F(AutofillManagerTest, FillAutofilledForm) { |
2394 // Set up our form data. | 2370 // Set up our form data. |
2395 FormData form; | 2371 FormData form; |
2396 CreateTestAddressFormData(&form); | 2372 test::CreateTestAddressFormData(&form); |
2397 // Mark one of the address fields as autofilled. | 2373 // Mark one of the address fields as autofilled. |
2398 form.fields[4].is_autofilled = true; | 2374 form.fields[4].is_autofilled = true; |
2399 CreateTestCreditCardFormData(&form, true, false); | 2375 CreateTestCreditCardFormData(&form, true, false); |
2400 std::vector<FormData> forms(1, form); | 2376 std::vector<FormData> forms(1, form); |
2401 FormsSeen(forms); | 2377 FormsSeen(forms); |
2402 | 2378 |
2403 // First fill the address data. | 2379 // First fill the address data. |
2404 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2380 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2405 GUIDPair empty(std::string(), 0); | 2381 GUIDPair empty(std::string(), 0); |
2406 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 2382 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2449 "", "", "", "", "", "", "", "", "", "", "", "", "", "", | 2425 "", "", "", "", "", "", "", "", "", "", "", "", "", "", |
2450 "2012", true, true, false); | 2426 "2012", true, true, false); |
2451 } | 2427 } |
2452 } | 2428 } |
2453 | 2429 |
2454 // Test that we correctly fill an address form with a non-default variant for a | 2430 // Test that we correctly fill an address form with a non-default variant for a |
2455 // multi-valued field. | 2431 // multi-valued field. |
2456 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { | 2432 TEST_F(AutofillManagerTest, FillAddressFormWithVariantType) { |
2457 // Set up our form data. | 2433 // Set up our form data. |
2458 FormData form; | 2434 FormData form; |
2459 CreateTestAddressFormData(&form); | 2435 test::CreateTestAddressFormData(&form); |
2460 std::vector<FormData> forms(1, form); | 2436 std::vector<FormData> forms(1, form); |
2461 FormsSeen(forms); | 2437 FormsSeen(forms); |
2462 | 2438 |
2463 // Add a name variant to the Elvis profile. | 2439 // Add a name variant to the Elvis profile. |
2464 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( | 2440 AutofillProfile* profile = autofill_manager_->GetProfileWithGUID( |
2465 "00000000-0000-0000-0000-000000000001"); | 2441 "00000000-0000-0000-0000-000000000001"); |
2466 const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL); | 2442 const base::string16 elvis_name = profile->GetRawInfo(NAME_FULL); |
2467 | 2443 |
2468 std::vector<base::string16> name_variants; | 2444 std::vector<base::string16> name_variants; |
2469 name_variants.push_back(ASCIIToUTF16("Some Other Guy")); | 2445 name_variants.push_back(ASCIIToUTF16("Some Other Guy")); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2648 EXPECT_EQ(ASCIIToUTF16("888"), results5.fields[1].value); | 2624 EXPECT_EQ(ASCIIToUTF16("888"), results5.fields[1].value); |
2649 EXPECT_EQ(ASCIIToUTF16("777"), results5.fields[2].value); | 2625 EXPECT_EQ(ASCIIToUTF16("777"), results5.fields[2].value); |
2650 EXPECT_EQ(ASCIIToUTF16("1234"), results5.fields[3].value); | 2626 EXPECT_EQ(ASCIIToUTF16("1234"), results5.fields[3].value); |
2651 EXPECT_EQ(base::string16(), results5.fields[4].value); | 2627 EXPECT_EQ(base::string16(), results5.fields[4].value); |
2652 } | 2628 } |
2653 | 2629 |
2654 // Test that we can still fill a form when a field has been removed from it. | 2630 // Test that we can still fill a form when a field has been removed from it. |
2655 TEST_F(AutofillManagerTest, FormChangesRemoveField) { | 2631 TEST_F(AutofillManagerTest, FormChangesRemoveField) { |
2656 // Set up our form data. | 2632 // Set up our form data. |
2657 FormData form; | 2633 FormData form; |
2658 CreateTestAddressFormData(&form); | 2634 test::CreateTestAddressFormData(&form); |
2659 | 2635 |
2660 // Add a field -- we'll remove it again later. | 2636 // Add a field -- we'll remove it again later. |
2661 FormFieldData field; | 2637 FormFieldData field; |
2662 test::CreateTestFormField("Some", "field", "", "text", &field); | 2638 test::CreateTestFormField("Some", "field", "", "text", &field); |
2663 form.fields.insert(form.fields.begin() + 3, field); | 2639 form.fields.insert(form.fields.begin() + 3, field); |
2664 | 2640 |
2665 std::vector<FormData> forms(1, form); | 2641 std::vector<FormData> forms(1, form); |
2666 FormsSeen(forms); | 2642 FormsSeen(forms); |
2667 | 2643 |
2668 // Now, after the call to |FormsSeen|, we remove the field before filling. | 2644 // Now, after the call to |FormsSeen|, we remove the field before filling. |
(...skipping 10 matching lines...) Expand all Loading... | |
2679 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2655 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
2680 } | 2656 } |
2681 | 2657 |
2682 // Test that we can still fill a form when a field has been added to it. | 2658 // Test that we can still fill a form when a field has been added to it. |
2683 TEST_F(AutofillManagerTest, FormChangesAddField) { | 2659 TEST_F(AutofillManagerTest, FormChangesAddField) { |
2684 // The offset of the phone field in the address form. | 2660 // The offset of the phone field in the address form. |
2685 const int kPhoneFieldOffset = 9; | 2661 const int kPhoneFieldOffset = 9; |
2686 | 2662 |
2687 // Set up our form data. | 2663 // Set up our form data. |
2688 FormData form; | 2664 FormData form; |
2689 CreateTestAddressFormData(&form); | 2665 test::CreateTestAddressFormData(&form); |
2690 | 2666 |
2691 // Remove the phone field -- we'll add it back later. | 2667 // Remove the phone field -- we'll add it back later. |
2692 std::vector<FormFieldData>::iterator pos = | 2668 std::vector<FormFieldData>::iterator pos = |
2693 form.fields.begin() + kPhoneFieldOffset; | 2669 form.fields.begin() + kPhoneFieldOffset; |
2694 FormFieldData field = *pos; | 2670 FormFieldData field = *pos; |
2695 pos = form.fields.erase(pos); | 2671 pos = form.fields.erase(pos); |
2696 | 2672 |
2697 std::vector<FormData> forms(1, form); | 2673 std::vector<FormData> forms(1, form); |
2698 FormsSeen(forms); | 2674 FormsSeen(forms); |
2699 | 2675 |
2700 // Now, after the call to |FormsSeen|, we restore the field before filling. | 2676 // Now, after the call to |FormsSeen|, we restore the field before filling. |
2701 form.fields.insert(pos, field); | 2677 form.fields.insert(pos, field); |
2702 | 2678 |
2703 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2679 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2704 GUIDPair empty(std::string(), 0); | 2680 GUIDPair empty(std::string(), 0); |
2705 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2681 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
2706 PackGUIDs(empty, guid)); | 2682 PackGUIDs(empty, guid)); |
2707 | 2683 |
2708 int page_id = 0; | 2684 int page_id = 0; |
2709 FormData results; | 2685 FormData results; |
2710 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 2686 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
2711 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); | 2687 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); |
2712 } | 2688 } |
2713 | 2689 |
2714 // Test that we are able to save form data when forms are submitted. | 2690 // Test that we are able to save form data when forms are submitted. |
2715 TEST_F(AutofillManagerTest, FormSubmitted) { | 2691 TEST_F(AutofillManagerTest, FormSubmitted) { |
2716 // Set up our form data. | 2692 // Set up our form data. |
2717 FormData form; | 2693 FormData form; |
2718 CreateTestAddressFormData(&form); | 2694 test::CreateTestAddressFormData(&form); |
2719 std::vector<FormData> forms(1, form); | 2695 std::vector<FormData> forms(1, form); |
2720 FormsSeen(forms); | 2696 FormsSeen(forms); |
2721 | 2697 |
2722 // Fill the form. | 2698 // Fill the form. |
2723 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2699 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
2724 GUIDPair empty(std::string(), 0); | 2700 GUIDPair empty(std::string(), 0); |
2725 FillAutofillFormData(kDefaultPageID, form, form.fields[0], | 2701 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
2726 PackGUIDs(empty, guid)); | 2702 PackGUIDs(empty, guid)); |
2727 | 2703 |
2728 int page_id = 0; | 2704 int page_id = 0; |
(...skipping 17 matching lines...) Expand all Loading... | |
2746 NULL)); | 2722 NULL)); |
2747 autofill_manager_->set_autofill_enabled(false); | 2723 autofill_manager_->set_autofill_enabled(false); |
2748 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2724 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
2749 autocomplete_history_manager.reset( | 2725 autocomplete_history_manager.reset( |
2750 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); | 2726 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); |
2751 autofill_manager_->autocomplete_history_manager_ = | 2727 autofill_manager_->autocomplete_history_manager_ = |
2752 autocomplete_history_manager.Pass(); | 2728 autocomplete_history_manager.Pass(); |
2753 | 2729 |
2754 // Set up our form data. | 2730 // Set up our form data. |
2755 FormData form; | 2731 FormData form; |
2756 CreateTestAddressFormData(&form); | 2732 test::CreateTestAddressFormData(&form); |
2757 form.method = ASCIIToUTF16("GET"); | 2733 form.method = ASCIIToUTF16("GET"); |
2758 MockAutocompleteHistoryManager* m = static_cast< | 2734 MockAutocompleteHistoryManager* m = static_cast< |
2759 MockAutocompleteHistoryManager*>( | 2735 MockAutocompleteHistoryManager*>( |
2760 autofill_manager_->autocomplete_history_manager_.get()); | 2736 autofill_manager_->autocomplete_history_manager_.get()); |
2761 EXPECT_CALL(*m, | 2737 EXPECT_CALL(*m, |
2762 OnFormSubmitted(_)).Times(1); | 2738 OnFormSubmitted(_)).Times(1); |
2763 FormSubmitted(form); | 2739 FormSubmitted(form); |
2764 } | 2740 } |
2765 | 2741 |
2766 // Test that when Autocomplete is enabled and Autofill is disabled, | 2742 // Test that when Autocomplete is enabled and Autofill is disabled, |
2767 // Autocomplete suggestions are still received. | 2743 // Autocomplete suggestions are still received. |
2768 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { | 2744 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { |
2769 TestAutofillManagerDelegate delegate; | 2745 TestAutofillManagerDelegate delegate; |
2770 autofill_manager_.reset(new TestAutofillManager( | 2746 autofill_manager_.reset(new TestAutofillManager( |
2771 autofill_driver_.get(), | 2747 autofill_driver_.get(), |
2772 &delegate, | 2748 &delegate, |
2773 NULL)); | 2749 NULL)); |
2774 autofill_manager_->set_autofill_enabled(false); | 2750 autofill_manager_->set_autofill_enabled(false); |
2775 | 2751 |
2776 // Set up our form data. | 2752 // Set up our form data. |
2777 FormData form; | 2753 FormData form; |
2778 CreateTestAddressFormData(&form); | 2754 test::CreateTestAddressFormData(&form); |
2779 form.method = ASCIIToUTF16("GET"); | 2755 form.method = ASCIIToUTF16("GET"); |
2780 std::vector<FormData> forms(1, form); | 2756 std::vector<FormData> forms(1, form); |
2781 FormsSeen(forms); | 2757 FormsSeen(forms); |
2782 const FormFieldData& field = form.fields[0]; | 2758 const FormFieldData& field = form.fields[0]; |
2783 GetAutofillSuggestions(form, field); | 2759 GetAutofillSuggestions(form, field); |
2784 | 2760 |
2785 // Add some Autocomplete suggestions. We should return the autocomplete | 2761 // Add some Autocomplete suggestions. We should return the autocomplete |
2786 // suggestions, these will be culled by the renderer. | 2762 // suggestions, these will be culled by the renderer. |
2787 std::vector<base::string16> suggestions; | 2763 std::vector<base::string16> suggestions; |
2788 suggestions.push_back(ASCIIToUTF16("Jay")); | 2764 suggestions.push_back(ASCIIToUTF16("Jay")); |
(...skipping 18 matching lines...) Expand all Loading... | |
2807 ExpectSuggestions(page_id, values, labels, icons, unique_ids, | 2783 ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
2808 kDefaultPageID, arraysize(expected_values), expected_values, | 2784 kDefaultPageID, arraysize(expected_values), expected_values, |
2809 expected_labels, expected_icons, expected_unique_ids); | 2785 expected_labels, expected_icons, expected_unique_ids); |
2810 } | 2786 } |
2811 | 2787 |
2812 // Test that we are able to save form data when forms are submitted and we only | 2788 // Test that we are able to save form data when forms are submitted and we only |
2813 // have server data for the field types. | 2789 // have server data for the field types. |
2814 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { | 2790 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { |
2815 // Set up our form data. | 2791 // Set up our form data. |
2816 FormData form; | 2792 FormData form; |
2817 CreateTestAddressFormData(&form); | 2793 test::CreateTestAddressFormData(&form); |
2818 | 2794 |
2819 // Simulate having seen this form on page load. | 2795 // Simulate having seen this form on page load. |
2820 // |form_structure| will be owned by |autofill_manager_|. | 2796 // |form_structure| will be owned by |autofill_manager_|. |
2821 TestFormStructure* form_structure = new TestFormStructure(form); | 2797 TestFormStructure* form_structure = new TestFormStructure(form); |
2822 AutofillMetrics metrics_logger; // ignored | 2798 AutofillMetrics metrics_logger; // ignored |
2823 form_structure->DetermineHeuristicTypes(metrics_logger); | 2799 form_structure->DetermineHeuristicTypes(metrics_logger); |
2824 | 2800 |
2825 // Clear the heuristic types, and instead set the appropriate server types. | 2801 // Clear the heuristic types, and instead set the appropriate server types. |
2826 std::vector<AutofillFieldType> heuristic_types, server_types; | 2802 std::vector<AutofillFieldType> heuristic_types, server_types; |
2827 for (size_t i = 0; i < form.fields.size(); ++i) { | 2803 for (size_t i = 0; i < form.fields.size(); ++i) { |
(...skipping 18 matching lines...) Expand all Loading... | |
2846 // filled data. | 2822 // filled data. |
2847 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2823 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
2848 FormSubmitted(results); | 2824 FormSubmitted(results); |
2849 } | 2825 } |
2850 | 2826 |
2851 // Test that the form signature for an uploaded form always matches the form | 2827 // Test that the form signature for an uploaded form always matches the form |
2852 // signature from the query. | 2828 // signature from the query. |
2853 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { | 2829 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { |
2854 // Set up our form data. | 2830 // Set up our form data. |
2855 FormData form; | 2831 FormData form; |
2856 CreateTestAddressFormData(&form); | 2832 test::CreateTestAddressFormData(&form); |
2857 std::vector<FormData> forms(1, form); | 2833 std::vector<FormData> forms(1, form); |
2858 FormsSeen(forms); | 2834 FormsSeen(forms); |
2859 | 2835 |
2860 // Cache the expected form signature. | 2836 // Cache the expected form signature. |
2861 std::string signature = FormStructure(form, std::string()).FormSignature(); | 2837 std::string signature = FormStructure(form, std::string()).FormSignature(); |
2862 | 2838 |
2863 // Change the structure of the form prior to submission. | 2839 // Change the structure of the form prior to submission. |
2864 // Websites would typically invoke JavaScript either on page load or on form | 2840 // Websites would typically invoke JavaScript either on page load or on form |
2865 // submit to achieve this. | 2841 // submit to achieve this. |
2866 form.fields.pop_back(); | 2842 form.fields.pop_back(); |
2867 FormFieldData field = form.fields[3]; | 2843 FormFieldData field = form.fields[3]; |
2868 form.fields[3] = form.fields[7]; | 2844 form.fields[3] = form.fields[7]; |
2869 form.fields[7] = field; | 2845 form.fields[7] = field; |
2870 | 2846 |
2871 // Simulate form submission. | 2847 // Simulate form submission. |
2872 FormSubmitted(form); | 2848 FormSubmitted(form); |
2873 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 2849 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
2874 } | 2850 } |
2875 | 2851 |
2876 // Test that we do not save form data when submitted fields contain default | 2852 // Test that we do not save form data when submitted fields contain default |
2877 // values. | 2853 // values. |
2878 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { | 2854 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { |
2879 // Set up our form data. | 2855 // Set up our form data. |
2880 FormData form; | 2856 FormData form; |
2881 CreateTestAddressFormData(&form); | 2857 test::CreateTestAddressFormData(&form); |
2882 form.fields[3].value = ASCIIToUTF16("Enter your address"); | 2858 form.fields[3].value = ASCIIToUTF16("Enter your address"); |
2883 | 2859 |
2884 // Convert the state field to a <select> popup, to make sure that we only | 2860 // Convert the state field to a <select> popup, to make sure that we only |
2885 // reject default values for text fields. | 2861 // reject default values for text fields. |
2886 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); | 2862 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); |
2887 form.fields[6].form_control_type = "select-one"; | 2863 form.fields[6].form_control_type = "select-one"; |
2888 form.fields[6].value = ASCIIToUTF16("Tennessee"); | 2864 form.fields[6].value = ASCIIToUTF16("Tennessee"); |
2889 | 2865 |
2890 std::vector<FormData> forms(1, form); | 2866 std::vector<FormData> forms(1, form); |
2891 FormsSeen(forms); | 2867 FormsSeen(forms); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3343 | 3319 |
3344 // Test that Autocheckout bubble is offered when server specifies field types. | 3320 // Test that Autocheckout bubble is offered when server specifies field types. |
3345 TEST_F(AutofillManagerTest, TestBubbleShown) { | 3321 TEST_F(AutofillManagerTest, TestBubbleShown) { |
3346 MockAutofillManagerDelegate delegate; | 3322 MockAutofillManagerDelegate delegate; |
3347 autofill_manager_.reset(new TestAutofillManager( | 3323 autofill_manager_.reset(new TestAutofillManager( |
3348 autofill_driver_.get(), &delegate, &personal_data_)); | 3324 autofill_driver_.get(), &delegate, &personal_data_)); |
3349 autofill_manager_->set_autofill_enabled(true); | 3325 autofill_manager_->set_autofill_enabled(true); |
3350 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3326 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
3351 | 3327 |
3352 FormData form; | 3328 FormData form; |
3353 CreateTestAddressFormData(&form); | 3329 test::CreateTestAddressFormData(&form); |
3354 | 3330 |
3355 TestFormStructure* form_structure = new TestFormStructure(form); | 3331 TestFormStructure* form_structure = new TestFormStructure(form); |
3356 AutofillMetrics metrics_logger; // ignored | 3332 AutofillMetrics metrics_logger; // ignored |
3357 form_structure->DetermineHeuristicTypes(metrics_logger); | 3333 form_structure->DetermineHeuristicTypes(metrics_logger); |
3358 | 3334 |
3359 // Build and add form structure with server data. | 3335 // Build and add form structure with server data. |
3360 std::vector<AutofillFieldType> heuristic_types, server_types; | 3336 std::vector<AutofillFieldType> heuristic_types, server_types; |
3361 for (size_t i = 0; i < form.fields.size(); ++i) { | 3337 for (size_t i = 0; i < form.fields.size(); ++i) { |
3362 heuristic_types.push_back(UNKNOWN_TYPE); | 3338 heuristic_types.push_back(UNKNOWN_TYPE); |
3363 server_types.push_back(form_structure->field(i)->type()); | 3339 server_types.push_back(form_structure->field(i)->type()); |
3364 } | 3340 } |
3365 form_structure->SetFieldTypes(heuristic_types, server_types); | 3341 form_structure->SetFieldTypes(heuristic_types, server_types); |
3366 autofill_manager_->AddSeenForm(form_structure); | 3342 autofill_manager_->AddSeenForm(form_structure); |
3367 | 3343 |
3368 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3344 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
3369 | 3345 |
3370 EXPECT_TRUE(delegate.autocheckout_bubble_shown()); | 3346 EXPECT_TRUE(delegate.autocheckout_bubble_shown()); |
3371 } | 3347 } |
3372 | 3348 |
3373 // Test that Autocheckout bubble is not offered when server doesn't have data | 3349 // Test that Autocheckout bubble is not offered when server doesn't have data |
3374 // for the form. | 3350 // for the form. |
3375 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { | 3351 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { |
3376 MockAutofillManagerDelegate delegate; | 3352 MockAutofillManagerDelegate delegate; |
3377 autofill_manager_.reset(new TestAutofillManager( | 3353 autofill_manager_.reset(new TestAutofillManager( |
3378 autofill_driver_.get(), &delegate, &personal_data_)); | 3354 autofill_driver_.get(), &delegate, &personal_data_)); |
3379 autofill_manager_->set_autofill_enabled(true); | 3355 autofill_manager_->set_autofill_enabled(true); |
3380 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3356 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
3381 | 3357 |
3382 FormData form; | 3358 FormData form; |
3383 CreateTestAddressFormData(&form); | 3359 test::CreateTestAddressFormData(&form); |
3384 | 3360 |
3385 TestFormStructure* form_structure = new TestFormStructure(form); | 3361 TestFormStructure* form_structure = new TestFormStructure(form); |
3386 AutofillMetrics metrics_logger; // ignored | 3362 AutofillMetrics metrics_logger; // ignored |
3387 form_structure->DetermineHeuristicTypes(metrics_logger); | 3363 form_structure->DetermineHeuristicTypes(metrics_logger); |
3388 | 3364 |
3389 // Build form structure without server data. | 3365 // Build form structure without server data. |
3390 std::vector<AutofillFieldType> heuristic_types, server_types; | 3366 std::vector<AutofillFieldType> heuristic_types, server_types; |
3391 for (size_t i = 0; i < form.fields.size(); ++i) { | 3367 for (size_t i = 0; i < form.fields.size(); ++i) { |
3392 heuristic_types.push_back(form_structure->field(i)->type()); | 3368 heuristic_types.push_back(form_structure->field(i)->type()); |
3393 server_types.push_back(NO_SERVER_DATA); | 3369 server_types.push_back(NO_SERVER_DATA); |
3394 } | 3370 } |
3395 form_structure->SetFieldTypes(heuristic_types, server_types); | 3371 form_structure->SetFieldTypes(heuristic_types, server_types); |
3396 autofill_manager_->AddSeenForm(form_structure); | 3372 autofill_manager_->AddSeenForm(form_structure); |
3397 | 3373 |
3398 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3374 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
3399 | 3375 |
3400 EXPECT_FALSE(delegate.autocheckout_bubble_shown()); | 3376 EXPECT_FALSE(delegate.autocheckout_bubble_shown()); |
3401 } | 3377 } |
3402 | 3378 |
3403 // Test our external delegate is called at the right time. | 3379 // Test our external delegate is called at the right time. |
3404 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3380 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
3405 MockAutofillExternalDelegate external_delegate(web_contents(), | 3381 MockAutofillExternalDelegate external_delegate(web_contents(), |
3406 autofill_manager_.get()); | 3382 autofill_manager_.get()); |
3407 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); | 3383 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); |
3408 autofill_manager_->SetExternalDelegate(&external_delegate); | 3384 autofill_manager_->SetExternalDelegate(&external_delegate); |
3409 | 3385 |
3410 FormData form; | 3386 FormData form; |
3411 CreateTestAddressFormData(&form); | 3387 test::CreateTestAddressFormData(&form); |
3412 std::vector<FormData> forms(1, form); | 3388 std::vector<FormData> forms(1, form); |
3413 FormsSeen(forms); | 3389 FormsSeen(forms); |
3414 const FormFieldData& field = form.fields[0]; | 3390 const FormFieldData& field = form.fields[0]; |
3415 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3391 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3416 | 3392 |
3417 autofill_manager_->SetExternalDelegate(NULL); | 3393 autofill_manager_->SetExternalDelegate(NULL); |
3418 } | 3394 } |
3419 | 3395 |
3420 // Test that in the case of Autocheckout, forms seen are in order supplied. | 3396 // Test that in the case of Autocheckout, forms seen are in order supplied. |
3421 TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) { | 3397 TEST_F(AutofillManagerTest, DynamicFormsSeenAndIgnored) { |
3422 MockAutofillManagerDelegate delegate; | 3398 MockAutofillManagerDelegate delegate; |
3423 autofill_manager_.reset(new TestAutofillManager( | 3399 autofill_manager_.reset(new TestAutofillManager( |
3424 autofill_driver_.get(), &delegate, &personal_data_)); | 3400 autofill_driver_.get(), &delegate, &personal_data_)); |
3425 FormData shipping_options; | 3401 FormData shipping_options; |
3426 CreateTestShippingOptionsFormData(&shipping_options); | 3402 CreateTestShippingOptionsFormData(&shipping_options); |
3427 FormData user_supplied; | 3403 FormData user_supplied; |
3428 CreateTestFormWithAutocompleteAttribute(&user_supplied); | 3404 CreateTestFormWithAutocompleteAttribute(&user_supplied); |
3429 FormData address; | 3405 FormData address; |
3430 CreateTestAddressFormData(&address); | 3406 test::CreateTestAddressFormData(&address); |
3431 | 3407 |
3432 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 3408 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
3433 // Push address only | 3409 // Push address only |
3434 std::vector<FormData> forms; | 3410 std::vector<FormData> forms; |
3435 forms.push_back(address); | 3411 forms.push_back(address); |
3436 | 3412 |
3437 // Build and add form structure with server data. | 3413 // Build and add form structure with server data. |
3438 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address)); | 3414 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address)); |
3439 std::vector<AutofillFieldType> heuristic_types, server_types; | 3415 std::vector<AutofillFieldType> heuristic_types, server_types; |
3440 for (size_t i = 0; i < address.fields.size(); ++i) { | 3416 for (size_t i = 0; i < address.fields.size(); ++i) { |
(...skipping 19 matching lines...) Expand all Loading... | |
3460 forms.push_back(user_supplied); | 3436 forms.push_back(user_supplied); |
3461 | 3437 |
3462 // FormStructure should contain the same forms as before. | 3438 // FormStructure should contain the same forms as before. |
3463 DynamicFormsSeen(forms); | 3439 DynamicFormsSeen(forms); |
3464 form_structures = autofill_manager_->GetFormStructures(); | 3440 form_structures = autofill_manager_->GetFormStructures(); |
3465 ASSERT_EQ(1U, form_structures.size()); | 3441 ASSERT_EQ(1U, form_structures.size()); |
3466 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); | 3442 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); |
3467 } | 3443 } |
3468 | 3444 |
3469 } // namespace autofill | 3445 } // namespace autofill |
OLD | NEW |