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

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 136793007: Add Autofill preview support for <select> input fields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 // Validate an Autofilled field. 227 // Validate an Autofilled field.
228 void ValidteFilledField(const AutofillFieldCase& field_case, 228 void ValidteFilledField(const AutofillFieldCase& field_case,
229 GetValueFunction get_value_function) { 229 GetValueFunction get_value_function) {
230 SCOPED_TRACE(base::StringPrintf("Verify autofilled value for field %s", 230 SCOPED_TRACE(base::StringPrintf("Verify autofilled value for field %s",
231 field_case.name)); 231 field_case.name));
232 WebString value; 232 WebString value;
233 WebFormControlElement element = GetMainFrame()->document().getElementById( 233 WebFormControlElement element = GetMainFrame()->document().getElementById(
234 ASCIIToUTF16(field_case.name)).to<WebFormControlElement>(); 234 ASCIIToUTF16(field_case.name)).to<WebFormControlElement>();
235 if (element.formControlType() == "select-one") { 235 if ((element.formControlType() == "select-one") ||
236 value = element.to<WebSelectElement>().value(); 236 (element.formControlType() == "textarea"))
237 } else if (element.formControlType() == "textarea") {
238 value = get_value_function(element); 237 value = get_value_function(element);
239 } else { 238 else
239 {
Ilya Sherman 2014/02/08 01:40:41 nit: Please keep all the curly braces as they were
240 ASSERT_TRUE(element.formControlType() == "text" || 240 ASSERT_TRUE(element.formControlType() == "text" ||
241 element.formControlType() == "month"); 241 element.formControlType() == "month");
242 value = get_value_function(element); 242 value = get_value_function(element);
243 } 243 }
244 244
245 const WebString expected_value = ASCIIToUTF16(field_case.expected_value); 245 const WebString expected_value = ASCIIToUTF16(field_case.expected_value);
246 if (expected_value.isEmpty()) 246 if (expected_value.isEmpty())
247 EXPECT_TRUE(value.isEmpty()); 247 EXPECT_TRUE(value.isEmpty());
248 else 248 else
249 EXPECT_EQ(expected_value, value); 249 EXPECT_EQ(expected_value, value);
250 250
251 EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled()); 251 EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled());
252 } 252 }
253 253
254 static void FillFormForAllFieldsWrapper(const FormData& form, 254 static void FillFormForAllFieldsWrapper(const FormData& form,
255 const WebInputElement& element) { 255 const WebInputElement& element) {
256 FillFormForAllElements(form, element.form()); 256 FillFormForAllElements(form, element.form());
257 } 257 }
258 258
259 static void FillFormIncludingNonFocusableElementsWrapper( 259 static void FillFormIncludingNonFocusableElementsWrapper(
260 const FormData& form, 260 const FormData& form,
261 const WebInputElement& element) { 261 const WebInputElement& element) {
262 FillFormIncludingNonFocusableElements(form, element.form()); 262 FillFormIncludingNonFocusableElements(form, element.form());
263 } 263 }
264 264
265 static WebString GetValueWrapper(WebFormControlElement element) { 265 static WebString GetValueWrapper(WebFormControlElement element) {
266 if (element.formControlType() == "textarea") 266 if (element.formControlType() == "textarea")
267 return element.to<WebTextAreaElement>().value(); 267 return element.to<WebTextAreaElement>().value();
268 268
269 if (element.formControlType() == "select-one")
270 return element.to<WebSelectElement>().value();
271
269 return element.to<WebInputElement>().value(); 272 return element.to<WebInputElement>().value();
270 } 273 }
271 274
272 static WebString GetSuggestedValueWrapper(WebFormControlElement element) { 275 static WebString GetSuggestedValueWrapper(WebFormControlElement element) {
273 if (element.formControlType() == "textarea") 276 if (element.formControlType() == "textarea")
274 return element.to<WebTextAreaElement>().suggestedValue(); 277 return element.to<WebTextAreaElement>().suggestedValue();
275 278
279 if (element.formControlType() == "select-one")
280 return element.to<WebSelectElement>().suggestedValue();
281
276 return element.to<WebInputElement>().suggestedValue(); 282 return element.to<WebInputElement>().suggestedValue();
277 } 283 }
278 284
279 private: 285 private:
280 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); 286 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest);
281 }; 287 };
282 288
283 // We should be able to extract a normal text field. 289 // We should be able to extract a normal text field.
284 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { 290 TEST_F(FormAutofillTest, WebFormControlElementToFormField) {
285 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); 291 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 // Fields with "visibility: hidden" should not be previewed. 1204 // Fields with "visibility: hidden" should not be previewed.
1199 {"text", "invisible", "", "", false, "suggested invisible", 1205 {"text", "invisible", "", "", false, "suggested invisible",
1200 ""}, 1206 ""},
1201 // Fields with "display:none" should not previewed. 1207 // Fields with "display:none" should not previewed.
1202 {"text", "displaynone", "", "", false, "suggested displaynone", 1208 {"text", "displaynone", "", "", false, "suggested displaynone",
1203 ""}, 1209 ""},
1204 // Regular <input type="month"> should not be previewed. 1210 // Regular <input type="month"> should not be previewed.
1205 {"month", "month", "", "", false, "2017-11", ""}, 1211 {"month", "month", "", "", false, "2017-11", ""},
1206 // Non-empty <input type="month"> should not be previewed. 1212 // Non-empty <input type="month"> should not be previewed.
1207 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, 1213 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""},
1208 // Regular select fields preview is not yet supported 1214 // Regular select fields should be previewed.
1209 {"select-one", "select", "", "", false, "TX", ""}, 1215 {"select-one", "select", "", "", true, "TX", "TX"},
1210 // Select fields preview is not yet supported 1216 // Select fields should be previewed even if they already have a
1211 {"select-one", "select-nonempty", "CA", "", false, "TX", "CA"}, 1217 // non-empty value.
1218 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1212 // Normal textarea elements should be previewed. 1219 // Normal textarea elements should be previewed.
1213 {"textarea", "textarea", "", "", true, "suggested multi-\nline value", 1220 {"textarea", "textarea", "", "", true, "suggested multi-\nline value",
1214 "suggested multi-\nline value"}, 1221 "suggested multi-\nline value"},
1215 // Nonempty textarea elements should not be previewed. 1222 // Nonempty textarea elements should not be previewed.
1216 {"textarea", "textarea-nonempty", "Go\naway!", "", false, 1223 {"textarea", "textarea-nonempty", "Go\naway!", "", false,
1217 "suggested multi-\nline value", ""}, 1224 "suggested multi-\nline value", ""},
1218 }; 1225 };
1219 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), 1226 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1220 &PreviewForm, &GetSuggestedValueWrapper); 1227 &PreviewForm, &GetSuggestedValueWrapper);
1221 1228
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 3221 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3215 3222
3216 expected.name = ASCIIToUTF16("country"); 3223 expected.name = ASCIIToUTF16("country");
3217 expected.value = ASCIIToUTF16("AL"); 3224 expected.value = ASCIIToUTF16("AL");
3218 expected.form_control_type = "select-one"; 3225 expected.form_control_type = "select-one";
3219 expected.max_length = 0; 3226 expected.max_length = 0;
3220 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3227 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3221 } 3228 }
3222 3229
3223 } // namespace autofill 3230 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698