Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 1473733008: [Autofill] Respect the autocomplete=off attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 field has the "autocomplete" attribute set to
vabr (Chromium) 2015/11/30 16:26:09 typo: field field
sebsg 2015/12/01 16:37:00 Done.
3959 // off.
3960 TEST_F(AutofillManagerTest, DisplaySuggestions_AutocompleteOff_AddressField) {
3961 // Set up an address form.
3962 FormData mixed_form;
3963 mixed_form.name = ASCIIToUTF16("MyForm");
3964 mixed_form.origin = GURL("https://myform.com/form.html");
3965 mixed_form.action = GURL("https://myform.com/submit.html");
3966 FormFieldData field;
3967 test::CreateTestFormField("First name", "firstname", "", "text", &field);
3968 field.should_autocomplete = false;
3969 mixed_form.fields.push_back(field);
3970 test::CreateTestFormField("Last name", "lastname", "", "text", &field);
3971 field.should_autocomplete = true;
3972 mixed_form.fields.push_back(field);
3973 test::CreateTestFormField("Address", "address", "", "text", &field);
3974 field.should_autocomplete = true;
3975 mixed_form.fields.push_back(field);
3976 std::vector<FormData> mixed_forms(1, mixed_form);
3977 FormsSeen(mixed_forms);
3978
3979 // Suggestions should not be displayed on desktop for this field.
3980 GetAutofillSuggestions(mixed_form, mixed_form.fields[0]);
3981 if (IsDesktopPlatform()) {
3982 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
3983 } else {
3984 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
3985 }
3986
3987 // Suggestions should always be displayed for all the other fields.
3988 for (size_t i = 1U; i < mixed_form.fields.size(); ++i) {
3989 GetAutofillSuggestions(mixed_form, mixed_form.fields[i]);
3990 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
3991 }
3992 }
3993
3994 // Verify that suggestions are shown on desktop for credit card related fields
3995 // even if the initiating field field has the "autocomplete" attribute set to
3996 // off.
3997 TEST_F(AutofillManagerTest,
3998 DisplaySuggestions_AutocompleteOff_CreditCardField) {
3999 // Set up a credit card form.
4000 FormData mixed_form;
4001 mixed_form.name = ASCIIToUTF16("MyForm");
4002 mixed_form.origin = GURL("https://myform.com/form.html");
4003 mixed_form.action = GURL("https://myform.com/submit.html");
4004 FormFieldData field;
4005 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
4006 field.should_autocomplete = false;
4007 mixed_form.fields.push_back(field);
4008 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4009 field.should_autocomplete = true;
4010 mixed_form.fields.push_back(field);
4011 test::CreateTestFormField("Expiration Month", "ccexpiresmonth", "", "text",
4012 &field);
4013 field.should_autocomplete = false;
4014 mixed_form.fields.push_back(field);
4015 mixed_form.fields.push_back(field);
4016 std::vector<FormData> mixed_forms(1, mixed_form);
4017 FormsSeen(mixed_forms);
4018
4019 // Suggestions should always be displayed.
4020 for (size_t i = 0U; i < mixed_form.fields.size(); ++i) {
vabr (Chromium) 2015/11/30 16:26:09 nit: Could this be a range-based for-loop?
sebsg 2015/12/01 16:37:00 Done.
4021 GetAutofillSuggestions(mixed_form, mixed_form.fields[i]);
4022 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4023 }
4024 }
4025
3873 } // namespace autofill 4026 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698