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

Side by Side Diff: components/autofill/core/browser/autofill_field_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 "components/autofill/core/browser/autofill_field.h" 5 #include "components/autofill/core/browser/autofill_field.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_type.h" 10 #include "components/autofill/core/browser/autofill_type.h"
11 #include "components/autofill/core/browser/field_types.h" 11 #include "components/autofill/core/browser/field_types.h"
12 #include "components/autofill/core/common/autofill_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 using base::ASCIIToUTF16; 15 using base::ASCIIToUTF16;
15 using base::UTF8ToUTF16; 16 using base::UTF8ToUTF16;
16 17
17 namespace autofill { 18 namespace autofill {
18 namespace { 19 namespace {
19 20
20 // Returns a FormFieldData object corresponding to a <select> field populated 21 // Returns a FormFieldData object corresponding to a <select> field populated
21 // with the given |options|. 22 // with the given |options|.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Only server type is set. 123 // Only server type is set.
123 field.set_heuristic_type(UNKNOWN_TYPE); 124 field.set_heuristic_type(UNKNOWN_TYPE);
124 field.set_server_type(NAME_LAST); 125 field.set_server_type(NAME_LAST);
125 EXPECT_TRUE(field.IsFieldFillable()); 126 EXPECT_TRUE(field.IsFieldFillable());
126 127
127 // Both types set. 128 // Both types set.
128 field.set_heuristic_type(NAME_FIRST); 129 field.set_heuristic_type(NAME_FIRST);
129 field.set_server_type(NAME_LAST); 130 field.set_server_type(NAME_LAST);
130 EXPECT_TRUE(field.IsFieldFillable()); 131 EXPECT_TRUE(field.IsFieldFillable());
131 132
132 // Field has autocomplete="off" set. Chrome ignores the attribute. 133 // Field has autocomplete="off" set. It is still fillable.
vabr (Chromium) 2015/11/30 16:26:09 nit: Perhaps mention the reason. I expect this is
sebsg 2015/12/01 16:37:00 Done.
133 field.should_autocomplete = false; 134 field.should_autocomplete = false;
134 EXPECT_TRUE(field.IsFieldFillable()); 135 EXPECT_TRUE(field.IsFieldFillable());
135 } 136 }
136 137
138 // Verify that non credit card related fields with the autocomplete attribute
139 // set to off don't get filled on desktop.
140 TEST(AutofillFieldTest, FillFormField_AutocompleteOff_AddressField) {
141 AutofillField field;
142 field.should_autocomplete = false;
143
144 // Non credit card related field.
145 AutofillField::FillFormField(field, ASCIIToUTF16("Test"), "en-US", "en-US",
146 &field);
147
148 // Verifiy that the field is filled on mobile but not on desktop.
149 if (IsDesktopPlatform()) {
150 EXPECT_EQ(base::string16(), field.value);
151 } else {
152 EXPECT_EQ(ASCIIToUTF16("Test"), field.value);
153 }
154 }
155
156 // Verify that credit card related fields with the autocomplete attribute
157 // set to off get filled.
158 TEST(AutofillFieldTest, FillFormField_AutocompleteOff_CreditCardField) {
159 AutofillField field;
160 field.should_autocomplete = false;
161
162 // Credit card related field.
163 field.set_heuristic_type(CREDIT_CARD_NUMBER);
164 AutofillField::FillFormField(field, ASCIIToUTF16("4111111111111111"), "en-US",
165 "en-US", &field);
166
167 // Verify that the field is filled.
168 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), field.value);
169 }
170
137 TEST(AutofillFieldTest, FillPhoneNumber) { 171 TEST(AutofillFieldTest, FillPhoneNumber) {
138 AutofillField field; 172 AutofillField field;
139 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode()); 173 field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode());
140 174
141 // Fill with a non-phone number; should fill normally. 175 // Fill with a non-phone number; should fill normally.
142 AutofillField::FillFormField( 176 AutofillField::FillFormField(
143 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field); 177 field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field);
144 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value); 178 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value);
145 179
146 // Fill with a phone number; should fill just the prefix. 180 // Fill with a phone number; should fill just the prefix.
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 index = kBadIndex; 723 index = kBadIndex;
690 ret = AutofillField::FindValueInSelectControl( 724 ret = AutofillField::FindValueInSelectControl(
691 field, UTF8ToUTF16("NoVaScOtIa"), &index); 725 field, UTF8ToUTF16("NoVaScOtIa"), &index);
692 EXPECT_TRUE(ret); 726 EXPECT_TRUE(ret);
693 EXPECT_EQ(2U, index); 727 EXPECT_EQ(2U, index);
694 } 728 }
695 } 729 }
696 730
697 } // namespace 731 } // namespace
698 } // namespace autofill 732 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698