Chromium Code Reviews| 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 (IsOnDesktop()) { | |
| 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 (IsOnDesktop()) { | |
| 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 form has the autocomplete attribute set to off. | |
|
Mathieu
2015/11/27 16:14:33
fix comment. "if the initiating field has autocomp
sebsg
2015/11/27 19:26:21
Done.
| |
| 3959 TEST_F(AutofillManagerTest, DisplaySuggestions_AutocompleteOffOnField) { | |
|
Mathieu
2015/11/27 16:14:33
Let's have this test be non-credit card only, and
sebsg
2015/11/27 19:26:21
Done.
| |
| 3960 // Set up a mixed 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 = false; | |
| 3971 mixed_form.fields.push_back(field); | |
| 3972 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); | |
| 3973 mixed_form.fields.push_back(field); | |
| 3974 field.should_autocomplete = false; | |
| 3975 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); | |
| 3976 field.should_autocomplete = false; | |
| 3977 mixed_form.fields.push_back(field); | |
| 3978 std::vector<FormData> mixed_forms(1, mixed_form); | |
| 3979 FormsSeen(mixed_forms); | |
| 3980 | |
| 3981 GetAutofillSuggestions(mixed_form, mixed_form.fields[0]); | |
| 3982 if (IsOnDesktop()) { | |
| 3983 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
| 3984 } else { | |
| 3985 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | |
| 3986 } | |
| 3987 | |
| 3988 GetAutofillSuggestions(mixed_form, mixed_form.fields[1]); | |
| 3989 if (IsOnDesktop()) { | |
| 3990 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
| 3991 } else { | |
| 3992 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | |
| 3993 } | |
| 3994 | |
| 3995 GetAutofillSuggestions(mixed_form, mixed_form.fields[2]); | |
| 3996 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | |
| 3997 | |
| 3998 GetAutofillSuggestions(mixed_form, mixed_form.fields[3]); | |
| 3999 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | |
| 4000 } | |
| 4001 | |
| 3873 } // namespace autofill | 4002 } // namespace autofill |
| OLD | NEW |