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/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" |
29 #include "components/autofill/core/browser/personal_data_manager.h" | 29 #include "components/autofill/core/browser/personal_data_manager.h" |
30 #include "components/autofill/core/browser/popup_item_ids.h" | 30 #include "components/autofill/core/browser/popup_item_ids.h" |
31 #include "components/autofill/core/browser/test_autofill_client.h" | 31 #include "components/autofill/core/browser/test_autofill_client.h" |
32 #include "components/autofill/core/browser/test_autofill_driver.h" | 32 #include "components/autofill/core/browser/test_autofill_driver.h" |
33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 33 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
34 #include "components/autofill/core/browser/validation.h" | 34 #include "components/autofill/core/browser/validation.h" |
35 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 35 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
36 #include "components/autofill/core/common/autofill_pref_names.h" | 36 #include "components/autofill/core/common/autofill_pref_names.h" |
37 #include "components/autofill/core/common/autofill_switches.h" | 37 #include "components/autofill/core/common/autofill_switches.h" |
| 38 #include "components/autofill/core/common/autofill_util.h" |
38 #include "components/autofill/core/common/form_data.h" | 39 #include "components/autofill/core/common/form_data.h" |
39 #include "components/autofill/core/common/form_field_data.h" | 40 #include "components/autofill/core/common/form_field_data.h" |
40 #include "grit/components_strings.h" | 41 #include "grit/components_strings.h" |
41 #include "net/url_request/url_request_test_util.h" | 42 #include "net/url_request/url_request_test_util.h" |
42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
44 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
45 #include "ui/gfx/geometry/rect.h" | 46 #include "ui/gfx/geometry/rect.h" |
46 #include "url/gurl.h" | 47 #include "url/gurl.h" |
47 | 48 |
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 { | 1889 { |
1889 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), | 1890 FillAutofillFormDataAndSaveResults(kPageID2, form, form.fields.back(), |
1890 MakeFrontendID(guid2, std::string()), | 1891 MakeFrontendID(guid2, std::string()), |
1891 &response_page_id, &response_data); | 1892 &response_page_id, &response_data); |
1892 SCOPED_TRACE("Credit card"); | 1893 SCOPED_TRACE("Credit card"); |
1893 ExpectFilledCreditCardFormElvis( | 1894 ExpectFilledCreditCardFormElvis( |
1894 response_page_id, response_data, kPageID2, true); | 1895 response_page_id, response_data, kPageID2, true); |
1895 } | 1896 } |
1896 } | 1897 } |
1897 | 1898 |
| 1899 // Test that non credit card related fields with the autocomplete attribute set |
| 1900 // to off are not filled on desktop. |
| 1901 TEST_F(AutofillManagerTest, FillAddressForm_AutocompleteOff) { |
| 1902 FormData address_form; |
| 1903 address_form.name = ASCIIToUTF16("MyForm"); |
| 1904 address_form.origin = GURL("https://myform.com/form.html"); |
| 1905 address_form.action = GURL("https://myform.com/submit.html"); |
| 1906 FormFieldData field; |
| 1907 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 1908 address_form.fields.push_back(field); |
| 1909 test::CreateTestFormField("Middle name", "middle", "", "text", &field); |
| 1910 field.should_autocomplete = false; |
| 1911 address_form.fields.push_back(field); |
| 1912 test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| 1913 field.should_autocomplete = true; |
| 1914 address_form.fields.push_back(field); |
| 1915 test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field); |
| 1916 field.should_autocomplete = false; |
| 1917 address_form.fields.push_back(field); |
| 1918 std::vector<FormData> address_forms(1, address_form); |
| 1919 FormsSeen(address_forms); |
| 1920 |
| 1921 // Fill the address form. |
| 1922 const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| 1923 int response_page_id = 0; |
| 1924 FormData response_data; |
| 1925 FillAutofillFormDataAndSaveResults( |
| 1926 kDefaultPageID, address_form, address_form.fields[0], |
| 1927 MakeFrontendID(std::string(), guid), &response_page_id, &response_data); |
| 1928 |
| 1929 // The fist name should be filled. |
| 1930 ExpectFilledField("First name", "firstname", "Elvis", "text", |
| 1931 response_data.fields[0]); |
| 1932 |
| 1933 // The middle name should not be filled on desktop. |
| 1934 if (IsDesktopPlatform()) { |
| 1935 ExpectFilledField("Middle name", "middle", "", "text", |
| 1936 response_data.fields[1]); |
| 1937 } else { |
| 1938 ExpectFilledField("Middle name", "middle", "Aaron", "text", |
| 1939 response_data.fields[1]); |
| 1940 } |
| 1941 |
| 1942 // The last name should be filled. |
| 1943 ExpectFilledField("Last name", "lastname", "Presley", "text", |
| 1944 response_data.fields[2]); |
| 1945 |
| 1946 // The address line 1 should not be filled on desktop. |
| 1947 if (IsDesktopPlatform()) { |
| 1948 ExpectFilledField("Address Line 1", "addr1", "", "text", |
| 1949 response_data.fields[3]); |
| 1950 } else { |
| 1951 ExpectFilledField("Address Line 1", "addr1", "3734 Elvis Presley Blvd.", |
| 1952 "text", response_data.fields[3]); |
| 1953 } |
| 1954 } |
| 1955 |
| 1956 // Test that credit card fields are filled even if they have the autocomplete |
| 1957 // attribute set to off. |
| 1958 TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { |
| 1959 // Set up our form data. |
| 1960 FormData form; |
| 1961 CreateTestCreditCardFormData(&form, true, false); |
| 1962 |
| 1963 // Set the autocomplete=off on all fields. |
| 1964 for (FormFieldData field : form.fields) |
| 1965 field.should_autocomplete = false; |
| 1966 |
| 1967 std::vector<FormData> forms(1, form); |
| 1968 FormsSeen(forms); |
| 1969 |
| 1970 const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| 1971 int response_page_id = 0; |
| 1972 FormData response_data; |
| 1973 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| 1974 MakeFrontendID(guid, std::string()), |
| 1975 &response_page_id, &response_data); |
| 1976 |
| 1977 // All fields should be filled. |
| 1978 ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| 1979 kDefaultPageID, false); |
| 1980 } |
| 1981 |
1898 // Test that non-focusable field is ignored while inferring boundaries between | 1982 // Test that non-focusable field is ignored while inferring boundaries between |
1899 // sections: http://crbug.com/231160 | 1983 // sections: http://crbug.com/231160 |
1900 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { | 1984 TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { |
1901 // Create a form with both focusable and non-focusable fields. | 1985 // Create a form with both focusable and non-focusable fields. |
1902 FormData form; | 1986 FormData form; |
1903 form.name = ASCIIToUTF16("MyForm"); | 1987 form.name = ASCIIToUTF16("MyForm"); |
1904 form.origin = GURL("https://myform.com/form.html"); | 1988 form.origin = GURL("https://myform.com/form.html"); |
1905 form.action = GURL("https://myform.com/submit.html"); | 1989 form.action = GURL("https://myform.com/submit.html"); |
1906 | 1990 |
1907 FormFieldData field; | 1991 FormFieldData field; |
(...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3863 | 3947 |
3864 // Make sure it's reset for the next test case. | 3948 // Make sure it's reset for the next test case. |
3865 autofill_driver_->SetIsOffTheRecord(false); | 3949 autofill_driver_->SetIsOffTheRecord(false); |
3866 EXPECT_TRUE(autofill_manager_->ShouldUploadForm(form_structure_4)); | 3950 EXPECT_TRUE(autofill_manager_->ShouldUploadForm(form_structure_4)); |
3867 | 3951 |
3868 // Autofill disabled. | 3952 // Autofill disabled. |
3869 autofill_manager_->set_autofill_enabled(false); | 3953 autofill_manager_->set_autofill_enabled(false); |
3870 EXPECT_FALSE(autofill_manager_->ShouldUploadForm(form_structure_3)); | 3954 EXPECT_FALSE(autofill_manager_->ShouldUploadForm(form_structure_3)); |
3871 } | 3955 } |
3872 | 3956 |
| 3957 // Verify that no suggestions are shown on desktop for non credit card related |
| 3958 // fields if the initiating field has the "autocomplete" attribute set to off. |
| 3959 TEST_F(AutofillManagerTest, DisplaySuggestions_AutocompleteOff_AddressField) { |
| 3960 // Set up an address form. |
| 3961 FormData mixed_form; |
| 3962 mixed_form.name = ASCIIToUTF16("MyForm"); |
| 3963 mixed_form.origin = GURL("https://myform.com/form.html"); |
| 3964 mixed_form.action = GURL("https://myform.com/submit.html"); |
| 3965 FormFieldData field; |
| 3966 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 3967 field.should_autocomplete = false; |
| 3968 mixed_form.fields.push_back(field); |
| 3969 test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| 3970 field.should_autocomplete = true; |
| 3971 mixed_form.fields.push_back(field); |
| 3972 test::CreateTestFormField("Address", "address", "", "text", &field); |
| 3973 field.should_autocomplete = true; |
| 3974 mixed_form.fields.push_back(field); |
| 3975 std::vector<FormData> mixed_forms(1, mixed_form); |
| 3976 FormsSeen(mixed_forms); |
| 3977 |
| 3978 // Suggestions should not be displayed on desktop for this field. |
| 3979 GetAutofillSuggestions(mixed_form, mixed_form.fields[0]); |
| 3980 if (IsDesktopPlatform()) { |
| 3981 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 3982 } else { |
| 3983 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 3984 } |
| 3985 |
| 3986 // Suggestions should always be displayed for all the other fields. |
| 3987 for (size_t i = 1U; i < mixed_form.fields.size(); ++i) { |
| 3988 GetAutofillSuggestions(mixed_form, mixed_form.fields[i]); |
| 3989 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 3990 } |
| 3991 } |
| 3992 |
| 3993 // Verify that suggestions are shown on desktop for credit card related fields |
| 3994 // even if the initiating field field has the "autocomplete" attribute set to |
| 3995 // off. |
| 3996 TEST_F(AutofillManagerTest, |
| 3997 DisplaySuggestions_AutocompleteOff_CreditCardField) { |
| 3998 // Set up a credit card form. |
| 3999 FormData mixed_form; |
| 4000 mixed_form.name = ASCIIToUTF16("MyForm"); |
| 4001 mixed_form.origin = GURL("https://myform.com/form.html"); |
| 4002 mixed_form.action = GURL("https://myform.com/submit.html"); |
| 4003 FormFieldData field; |
| 4004 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| 4005 field.should_autocomplete = false; |
| 4006 mixed_form.fields.push_back(field); |
| 4007 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| 4008 field.should_autocomplete = true; |
| 4009 mixed_form.fields.push_back(field); |
| 4010 test::CreateTestFormField("Expiration Month", "ccexpiresmonth", "", "text", |
| 4011 &field); |
| 4012 field.should_autocomplete = false; |
| 4013 mixed_form.fields.push_back(field); |
| 4014 mixed_form.fields.push_back(field); |
| 4015 std::vector<FormData> mixed_forms(1, mixed_form); |
| 4016 FormsSeen(mixed_forms); |
| 4017 |
| 4018 // Suggestions should always be displayed. |
| 4019 for (const FormFieldData& field : mixed_form.fields) { |
| 4020 GetAutofillSuggestions(mixed_form, field); |
| 4021 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 4022 } |
| 4023 } |
| 4024 |
3873 } // namespace autofill | 4025 } // namespace autofill |
OLD | NEW |