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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 form2.fields.push_back(field); | 1003 form2.fields.push_back(field); |
1004 | 1004 |
1005 forms.clear(); | 1005 forms.clear(); |
1006 forms.push_back(form2); | 1006 forms.push_back(form2); |
1007 FormsSeen(forms); | 1007 FormsSeen(forms); |
1008 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", | 1008 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
1009 0 /* FORMS_LOADED */, 2); | 1009 0 /* FORMS_LOADED */, 2); |
1010 download_manager_->VerifyLastQueriedForms(forms); | 1010 download_manager_->VerifyLastQueriedForms(forms); |
1011 } | 1011 } |
1012 | 1012 |
| 1013 // Test that no suggestions are returned for a field with an unrecognized |
| 1014 // autocomplete attribute. |
| 1015 TEST_F(AutofillManagerTest, GetProfileSuggestions_UnrecognizedAttribute) { |
| 1016 FormData form; |
| 1017 form.name = ASCIIToUTF16("MyForm"); |
| 1018 form.origin = GURL("https://myform.com/form.html"); |
| 1019 form.action = GURL("https://myform.com/submit.html"); |
| 1020 FormFieldData field; |
| 1021 // Set a valid autocomplete attribute for the first name. |
| 1022 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 1023 field.autocomplete_attribute = "given-name"; |
| 1024 form.fields.push_back(field); |
| 1025 // Set no autocomplete attribute for the middle name. |
| 1026 test::CreateTestFormField("Middle name", "middle", "", "text", &field); |
| 1027 field.autocomplete_attribute = ""; |
| 1028 form.fields.push_back(field); |
| 1029 // Set an unrecognized autocomplete attribute for the last name. |
| 1030 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); |
| 1031 field.autocomplete_attribute = "unrecognized"; |
| 1032 form.fields.push_back(field); |
| 1033 std::vector<FormData> forms(1, form); |
| 1034 FormsSeen(forms); |
| 1035 |
| 1036 // Suggestions should be returned for the first two fields |
| 1037 GetAutofillSuggestions(form, form.fields[0]); |
| 1038 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 1039 GetAutofillSuggestions(form, form.fields[1]); |
| 1040 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 1041 |
| 1042 // Suggestions should not be returned for the third field because of its |
| 1043 // unrecognized autocomplete attribute. |
| 1044 GetAutofillSuggestions(form, form.fields[2]); |
| 1045 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1046 } |
| 1047 |
1013 // Test that no suggestions are returned when there are less than three fields | 1048 // Test that no suggestions are returned when there are less than three fields |
1014 // and none of them have an autocomplete attribute. | 1049 // and none of them have an autocomplete attribute. |
1015 TEST_F(AutofillManagerTest, GetProfileSuggestions_SmallFormNoAutocomplete) { | 1050 TEST_F(AutofillManagerTest, GetProfileSuggestions_SmallFormNoAutocomplete) { |
1016 FormData form; | 1051 FormData form; |
1017 form.name = ASCIIToUTF16("MyForm"); | 1052 form.name = ASCIIToUTF16("MyForm"); |
1018 form.origin = GURL("https://myform.com/form.html"); | 1053 form.origin = GURL("https://myform.com/form.html"); |
1019 form.action = GURL("https://myform.com/submit.html"); | 1054 form.action = GURL("https://myform.com/submit.html"); |
1020 FormFieldData field; | 1055 FormFieldData field; |
1021 test::CreateTestFormField("First Name", "firstname", "", "text", &field); | 1056 test::CreateTestFormField("First Name", "firstname", "", "text", &field); |
1022 form.fields.push_back(field); | 1057 form.fields.push_back(field); |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 { | 1926 { |
1892 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 1927 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
1893 MakeFrontendID(guid2, std::string()), | 1928 MakeFrontendID(guid2, std::string()), |
1894 &response_page_id, &response_data); | 1929 &response_page_id, &response_data); |
1895 SCOPED_TRACE("Credit card"); | 1930 SCOPED_TRACE("Credit card"); |
1896 ExpectFilledCreditCardFormElvis( | 1931 ExpectFilledCreditCardFormElvis( |
1897 response_page_id, response_data, kPageID2, true); | 1932 response_page_id, response_data, kPageID2, true); |
1898 } | 1933 } |
1899 } | 1934 } |
1900 | 1935 |
| 1936 // Test that a field with an unrecognized autocomplete attribute is not filled. |
| 1937 TEST_F(AutofillManagerTest, FillAddressForm_UnrecognizedAttribute) { |
| 1938 FormData address_form; |
| 1939 address_form.name = ASCIIToUTF16("MyForm"); |
| 1940 address_form.origin = GURL("https://myform.com/form.html"); |
| 1941 address_form.action = GURL("https://myform.com/submit.html"); |
| 1942 FormFieldData field; |
| 1943 // Set a valid autocomplete attribute for the first name. |
| 1944 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 1945 field.autocomplete_attribute = "given-name"; |
| 1946 address_form.fields.push_back(field); |
| 1947 // Set no autocomplete attribute for the middle name. |
| 1948 test::CreateTestFormField("Middle name", "middle", "", "text", &field); |
| 1949 field.autocomplete_attribute = ""; |
| 1950 address_form.fields.push_back(field); |
| 1951 // Set an unrecognized autocomplete attribute for the last name. |
| 1952 test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| 1953 field.autocomplete_attribute = "unrecognized"; |
| 1954 address_form.fields.push_back(field); |
| 1955 std::vector<FormData> address_forms(1, address_form); |
| 1956 FormsSeen(address_forms); |
| 1957 |
| 1958 // Fill the address form. |
| 1959 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 1960 int response_page_id = 0; |
| 1961 FormData response_data; |
| 1962 FillAutofillFormDataAndSaveResults( |
| 1963 kDefaultPageID, address_form, address_form.fields[0], |
| 1964 MakeFrontendID(std::string(), guid), &response_page_id, &response_data); |
| 1965 |
| 1966 // The fist and middle names should be filled. |
| 1967 ExpectFilledField("First name", "firstname", "Elvis", "text", |
| 1968 response_data.fields[0]); |
| 1969 ExpectFilledField("Middle name", "middle", "Aaron", "text", |
| 1970 response_data.fields[1]); |
| 1971 |
| 1972 // The last name should not be filled. |
| 1973 ExpectFilledField("Last name", "lastname", "", "text", |
| 1974 response_data.fields[2]); |
| 1975 } |
| 1976 |
1901 // Test that non credit card related fields with the autocomplete attribute set | 1977 // Test that non credit card related fields with the autocomplete attribute set |
1902 // to off are not filled on desktop. | 1978 // to off are not filled on desktop. |
1903 TEST_F(AutofillManagerTest, FillAddressForm_AutocompleteOff) { | 1979 TEST_F(AutofillManagerTest, FillAddressForm_AutocompleteOff) { |
1904 FormData address_form; | 1980 FormData address_form; |
1905 address_form.name = ASCIIToUTF16("MyForm"); | 1981 address_form.name = ASCIIToUTF16("MyForm"); |
1906 address_form.origin = GURL("https://myform.com/form.html"); | 1982 address_form.origin = GURL("https://myform.com/form.html"); |
1907 address_form.action = GURL("https://myform.com/submit.html"); | 1983 address_form.action = GURL("https://myform.com/submit.html"); |
1908 FormFieldData field; | 1984 FormFieldData field; |
1909 test::CreateTestFormField("First name", "firstname", "", "text", &field); | 1985 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
1910 address_form.fields.push_back(field); | 1986 address_form.fields.push_back(field); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 // The address line 1 should not be filled on desktop. | 2024 // The address line 1 should not be filled on desktop. |
1949 if (IsDesktopPlatform()) { | 2025 if (IsDesktopPlatform()) { |
1950 ExpectFilledField("Address Line 1", "addr1", "", "text", | 2026 ExpectFilledField("Address Line 1", "addr1", "", "text", |
1951 response_data.fields[3]); | 2027 response_data.fields[3]); |
1952 } else { | 2028 } else { |
1953 ExpectFilledField("Address Line 1", "addr1", "3734 Elvis Presley Blvd.", | 2029 ExpectFilledField("Address Line 1", "addr1", "3734 Elvis Presley Blvd.", |
1954 "text", response_data.fields[3]); | 2030 "text", response_data.fields[3]); |
1955 } | 2031 } |
1956 } | 2032 } |
1957 | 2033 |
| 2034 // Test that a field with an unrecognized autocomplete attribute is not filled. |
| 2035 TEST_F(AutofillManagerTest, FillCreditCardForm_UnrecognizedAttribute) { |
| 2036 // Set up the form data. |
| 2037 FormData form; |
| 2038 form.name = ASCIIToUTF16("MyForm"); |
| 2039 form.origin = GURL("https://myform.com/form.html"); |
| 2040 form.action = GURL("https://myform.com/submit.html"); |
| 2041 |
| 2042 FormFieldData field; |
| 2043 // Set a valid autocomplete attribute on the card name. |
| 2044 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 2045 field.autocomplete_attribute = "cc-name"; |
| 2046 form.fields.push_back(field); |
| 2047 // Set no autocomplete attribute on the card number. |
| 2048 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 2049 field.autocomplete_attribute = ""; |
| 2050 form.fields.push_back(field); |
| 2051 // Set an unrecognized autocomplete attribute on the expiration month. |
| 2052 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
| 2053 field.autocomplete_attribute = "unrecognized"; |
| 2054 form.fields.push_back(field); |
| 2055 std::vector<FormData> forms(1, form); |
| 2056 FormsSeen(forms); |
| 2057 |
| 2058 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 2059 int response_page_id = 0; |
| 2060 FormData response_data; |
| 2061 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 2062 MakeFrontendID(guid, std::string()), |
| 2063 &response_page_id, &response_data); |
| 2064 |
| 2065 // The credit card name and number should be filled. |
| 2066 ExpectFilledField("Name on Card", "nameoncard", "Elvis Presley", "text", |
| 2067 response_data.fields[0]); |
| 2068 ExpectFilledField("Card Number", "cardnumber", "4234567890123456", "text", |
| 2069 response_data.fields[1]); |
| 2070 |
| 2071 // The expiration month should not be filled. |
| 2072 ExpectFilledField("Expiration Date", "ccmonth", "", "text", |
| 2073 response_data.fields[2]); |
| 2074 } |
| 2075 |
1958 // Test that credit card fields are filled even if they have the autocomplete | 2076 // Test that credit card fields are filled even if they have the autocomplete |
1959 // attribute set to off. | 2077 // attribute set to off. |
1960 TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { | 2078 TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { |
1961 // Set up our form data. | 2079 // Set up our form data. |
1962 FormData form; | 2080 FormData form; |
1963 CreateTestCreditCardFormData(&form, true, false); | 2081 CreateTestCreditCardFormData(&form, true, false); |
1964 | 2082 |
1965 // Set the autocomplete=off on all fields. | 2083 // Set the autocomplete=off on all fields. |
1966 for (FormFieldData field : form.fields) | 2084 for (FormFieldData field : form.fields) |
1967 field.should_autocomplete = false; | 2085 field.should_autocomplete = false; |
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3427 form.fields[2].value = ASCIIToUTF16("theking@gmail.com"); | 3545 form.fields[2].value = ASCIIToUTF16("theking@gmail.com"); |
3428 autofill_manager_->OnDidFillAutofillFormData(form, base::TimeTicks::Now()); | 3546 autofill_manager_->OnDidFillAutofillFormData(form, base::TimeTicks::Now()); |
3429 | 3547 |
3430 autofill_manager_->ResetRunLoop(); | 3548 autofill_manager_->ResetRunLoop(); |
3431 // Simulate lost of focus on the form. | 3549 // Simulate lost of focus on the form. |
3432 autofill_manager_->OnFocusNoLongerOnForm(); | 3550 autofill_manager_->OnFocusNoLongerOnForm(); |
3433 // Wait for upload to complete. | 3551 // Wait for upload to complete. |
3434 autofill_manager_->WaitForAsyncUploadProcess(); | 3552 autofill_manager_->WaitForAsyncUploadProcess(); |
3435 } | 3553 } |
3436 | 3554 |
| 3555 // Test that no suggestions are returned for a field with an unrecognized |
| 3556 // autocomplete attribute. |
| 3557 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_UnrecognizedAttribute) { |
| 3558 // Set up the form data. |
| 3559 FormData form; |
| 3560 form.name = ASCIIToUTF16("MyForm"); |
| 3561 form.origin = GURL("https://myform.com/form.html"); |
| 3562 form.action = GURL("https://myform.com/submit.html"); |
| 3563 |
| 3564 FormFieldData field; |
| 3565 // Set a valid autocomplete attribute on the card name. |
| 3566 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 3567 field.autocomplete_attribute = "cc-name"; |
| 3568 form.fields.push_back(field); |
| 3569 // Set no autocomplete attribute on the card number. |
| 3570 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 3571 field.autocomplete_attribute = ""; |
| 3572 form.fields.push_back(field); |
| 3573 // Set an unrecognized autocomplete attribute on the expiration month. |
| 3574 test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", &field); |
| 3575 field.autocomplete_attribute = "unrecognized"; |
| 3576 form.fields.push_back(field); |
| 3577 std::vector<FormData> forms(1, form); |
| 3578 FormsSeen(forms); |
| 3579 |
| 3580 // Suggestions should be returned for the first two fields |
| 3581 GetAutofillSuggestions(form, form.fields[0]); |
| 3582 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 3583 GetAutofillSuggestions(form, form.fields[1]); |
| 3584 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 3585 |
| 3586 // Suggestions should not be returned for the third field because of its |
| 3587 // unrecognized autocomplete attribute. |
| 3588 GetAutofillSuggestions(form, form.fields[2]); |
| 3589 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3590 } |
| 3591 |
3437 // Test to verify suggestions appears for forms having credit card number split | 3592 // Test to verify suggestions appears for forms having credit card number split |
3438 // across fields. | 3593 // across fields. |
3439 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | 3594 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { |
3440 // Set up our form data with credit card number split across fields. | 3595 // Set up our form data with credit card number split across fields. |
3441 FormData form; | 3596 FormData form; |
3442 form.name = ASCIIToUTF16("MyForm"); | 3597 form.name = ASCIIToUTF16("MyForm"); |
3443 form.origin = GURL("https://myform.com/form.html"); | 3598 form.origin = GURL("https://myform.com/form.html"); |
3444 form.action = GURL("https://myform.com/submit.html"); | 3599 form.action = GURL("https://myform.com/submit.html"); |
3445 | 3600 |
3446 FormFieldData name_field; | 3601 FormFieldData name_field; |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4056 FormsSeen(mixed_forms); | 4211 FormsSeen(mixed_forms); |
4057 | 4212 |
4058 // Suggestions should always be displayed. | 4213 // Suggestions should always be displayed. |
4059 for (const FormFieldData& field : mixed_form.fields) { | 4214 for (const FormFieldData& field : mixed_form.fields) { |
4060 GetAutofillSuggestions(mixed_form, field); | 4215 GetAutofillSuggestions(mixed_form, field); |
4061 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 4216 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
4062 } | 4217 } |
4063 } | 4218 } |
4064 | 4219 |
4065 } // namespace autofill | 4220 } // namespace autofill |
OLD | NEW |