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
3 // found in the LICENSE file.
7 #include "base/format_macros.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/test/base/chrome_render_view_test.h"
14 #include "components/autofill/content/renderer/form_autofill_util.h"
15 #include "components/autofill/content/renderer/form_cache.h"
16 #include "components/autofill/core/common/autofill_data_validation.h"
17 #include "components/autofill/core/common/form_data.h"
18 #include "components/autofill/core/common/web_element_descriptor.h"
19 #include "components/variations/entropy_provider.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/WebKit/public/platform/WebString.h"
22 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebElement.h"
25 #include "third_party/WebKit/public/web/WebFormControlElement.h"
26 #include "third_party/WebKit/public/web/WebFormElement.h"
27 #include "third_party/WebKit/public/web/WebInputElement.h"
28 #include "third_party/WebKit/public/web/WebLocalFrame.h"
29 #include "third_party/WebKit/public/web/WebNode.h"
30 #include "third_party/WebKit/public/web/WebSelectElement.h"
31 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
33 using base::ASCIIToUTF16;
34 using blink::WebDocument;
35 using blink::WebElement;
36 using blink::WebFormControlElement;
37 using blink::WebFormElement;
38 using blink::WebFrame;
39 using blink::WebInputElement;
41 using blink::WebSelectElement;
42 using blink::WebString;
43 using blink::WebTextAreaElement;
44 using blink::WebVector;
48 struct AutofillFieldCase {
49 const char* const form_control_type;
50 const char* const name;
51 const char* const initial_value;
52 const char* const autocomplete_attribute; // The autocomplete attribute of
54 bool should_be_autofilled; // Whether the filed should be autofilled.
55 const char* const autofill_value; // The value being used to fill the field.
56 const char* const expected_value; // The expected value after Autofill
60 static const char kFormHtml[] =
61 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
62 " <INPUT type=\"text\" id=\"firstname\"/>"
63 " <INPUT type=\"text\" id=\"lastname\"/>"
64 " <INPUT type=\"hidden\" id=\"imhidden\"/>"
65 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>"
66 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>"
67 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>"
68 " <INPUT type=\"text\" readonly id=\"readonly\"/>"
69 " <INPUT type=\"text\" style=\"visibility: hidden\""
71 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>"
72 " <INPUT type=\"month\" id=\"month\"/>"
73 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>"
74 " <SELECT id=\"select\">"
76 " <OPTION value=\"CA\">California</OPTION>"
77 " <OPTION value=\"TX\">Texas</OPTION>"
79 " <SELECT id=\"select-nonempty\">"
80 " <OPTION value=\"CA\" selected>California</OPTION>"
81 " <OPTION value=\"TX\">Texas</OPTION>"
83 " <SELECT id=\"select-unchanged\">"
84 " <OPTION value=\"CA\" selected>California</OPTION>"
85 " <OPTION value=\"TX\">Texas</OPTION>"
87 " <TEXTAREA id=\"textarea\"></TEXTAREA>"
88 " <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>"
89 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
96 class FormAutofillTest : public ChromeRenderViewTest {
98 FormAutofillTest() : ChromeRenderViewTest() {}
99 virtual ~FormAutofillTest() {}
101 void ExpectLabels(const char* html,
102 const std::vector<base::string16>& labels,
103 const std::vector<base::string16>& names,
104 const std::vector<base::string16>& values) {
105 std::vector<std::string> control_types(labels.size(), "text");
106 ExpectLabelsAndTypes(html, labels, names, values, control_types);
109 void ExpectLabelsAndTypes(const char* html,
110 const std::vector<base::string16>& labels,
111 const std::vector<base::string16>& names,
112 const std::vector<base::string16>& values,
113 const std::vector<std::string>& control_types) {
114 ASSERT_EQ(labels.size(), names.size());
115 ASSERT_EQ(labels.size(), values.size());
116 ASSERT_EQ(labels.size(), control_types.size());
120 WebFrame* web_frame = GetMainFrame();
121 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
123 FormCache form_cache;
124 std::vector<FormData> forms;
125 form_cache.ExtractNewForms(*web_frame, &forms);
126 ASSERT_EQ(1U, forms.size());
128 const FormData& form = forms[0];
129 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
130 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
131 EXPECT_EQ(GURL("http://cnn.com"), form.action);
133 const std::vector<FormFieldData>& fields = form.fields;
134 ASSERT_EQ(labels.size(), fields.size());
135 for (size_t i = 0; i < labels.size(); ++i) {
136 int max_length = control_types[i] == "text" ?
137 WebInputElement::defaultMaxLength() : 0;
138 FormFieldData expected;
139 expected.label = labels[i];
140 expected.name = names[i];
141 expected.value = values[i];
142 expected.form_control_type = control_types[i];
143 expected.max_length = max_length;
144 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i));
145 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]);
149 void ExpectJohnSmithLabels(const char* html) {
150 std::vector<base::string16> labels, names, values;
152 labels.push_back(ASCIIToUTF16("First name:"));
153 names.push_back(ASCIIToUTF16("firstname"));
154 values.push_back(ASCIIToUTF16("John"));
156 labels.push_back(ASCIIToUTF16("Last name:"));
157 names.push_back(ASCIIToUTF16("lastname"));
158 values.push_back(ASCIIToUTF16("Smith"));
160 labels.push_back(ASCIIToUTF16("Email:"));
161 names.push_back(ASCIIToUTF16("email"));
162 values.push_back(ASCIIToUTF16("john@example.com"));
164 ExpectLabels(html, labels, names, values);
167 typedef void (*FillFormFunction)(const FormData& form,
168 const WebFormControlElement& element);
170 typedef WebString (*GetValueFunction)(WebFormControlElement element);
172 // Test FormFillxxx functions.
173 void TestFormFillFunctions(const char* html,
174 const AutofillFieldCase* field_cases,
175 size_t number_of_field_cases,
176 FillFormFunction fill_form_function,
177 GetValueFunction get_value_function) {
180 WebFrame* web_frame = GetMainFrame();
181 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
183 FormCache form_cache;
184 std::vector<FormData> forms;
185 form_cache.ExtractNewForms(*web_frame, &forms);
186 ASSERT_EQ(1U, forms.size());
188 // Get the input element we want to find.
189 WebElement element = web_frame->document().getElementById("firstname");
190 WebInputElement input_element = element.to<WebInputElement>();
192 // Find the form that contains the input element.
196 FindFormAndFieldForFormControlElement(input_element,
199 autofill::REQUIRE_AUTOCOMPLETE));
200 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name);
201 EXPECT_EQ(GURL(web_frame->document().url()), form_data.origin);
202 EXPECT_EQ(GURL("http://buh.com"), form_data.action);
204 const std::vector<FormFieldData>& fields = form_data.fields;
205 ASSERT_EQ(number_of_field_cases, fields.size());
207 FormFieldData expected;
208 // Verify field's initial value.
209 for (size_t i = 0; i < number_of_field_cases; ++i) {
210 SCOPED_TRACE(base::StringPrintf("Verify initial value for field %s",
211 field_cases[i].name));
212 expected.form_control_type = field_cases[i].form_control_type;
213 expected.max_length =
214 expected.form_control_type == "text" ?
215 WebInputElement::defaultMaxLength() : 0;
216 expected.name = ASCIIToUTF16(field_cases[i].name);
217 expected.value = ASCIIToUTF16(field_cases[i].initial_value);
218 expected.autocomplete_attribute = field_cases[i].autocomplete_attribute;
219 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]);
220 // Fill the form_data for the field.
221 form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value);
222 // Set the is_autofilled property for the field.
223 form_data.fields[i].is_autofilled = field_cases[i].should_be_autofilled;
226 // Autofill the form using the given fill form function.
227 fill_form_function(form_data, input_element);
229 // Validate Autofill or Preview results.
230 for (size_t i = 0; i < number_of_field_cases; ++i) {
231 ValidteFilledField(field_cases[i], get_value_function);
235 // Validate an Autofilled field.
236 void ValidteFilledField(const AutofillFieldCase& field_case,
237 GetValueFunction get_value_function) {
238 SCOPED_TRACE(base::StringPrintf("Verify autofilled value for field %s",
241 WebFormControlElement element = GetMainFrame()->document().getElementById(
242 ASCIIToUTF16(field_case.name)).to<WebFormControlElement>();
243 if ((element.formControlType() == "select-one") ||
244 (element.formControlType() == "textarea")) {
245 value = get_value_function(element);
247 ASSERT_TRUE(element.formControlType() == "text" ||
248 element.formControlType() == "month");
249 value = get_value_function(element);
252 const WebString expected_value = ASCIIToUTF16(field_case.expected_value);
253 if (expected_value.isEmpty())
254 EXPECT_TRUE(value.isEmpty());
256 EXPECT_EQ(expected_value, value);
258 EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled());
261 static void FillFormForAllFieldsWrapper(const FormData& form,
262 const WebInputElement& element) {
263 FillFormForAllElements(form, element.form());
266 static void FillFormIncludingNonFocusableElementsWrapper(
267 const FormData& form,
268 const WebFormControlElement& element) {
269 FillFormIncludingNonFocusableElements(form, element.form());
272 static WebString GetValueWrapper(WebFormControlElement element) {
273 if (element.formControlType() == "textarea")
274 return element.to<WebTextAreaElement>().value();
276 if (element.formControlType() == "select-one")
277 return element.to<WebSelectElement>().value();
279 return element.to<WebInputElement>().value();
282 static WebString GetSuggestedValueWrapper(WebFormControlElement element) {
283 if (element.formControlType() == "textarea")
284 return element.to<WebTextAreaElement>().suggestedValue();
286 if (element.formControlType() == "select-one")
287 return element.to<WebSelectElement>().suggestedValue();
289 return element.to<WebInputElement>().suggestedValue();
293 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest);
296 // We should be able to extract a normal text field.
297 TEST_F(FormAutofillTest, WebFormControlElementToFormField) {
298 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
300 WebFrame* frame = GetMainFrame();
301 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
303 WebElement web_element = frame->document().getElementById("element");
304 WebFormControlElement element = web_element.to<WebFormControlElement>();
305 FormFieldData result1;
306 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1);
308 FormFieldData expected;
309 expected.form_control_type = "text";
310 expected.max_length = WebInputElement::defaultMaxLength();
312 expected.name = ASCIIToUTF16("element");
313 expected.value = base::string16();
314 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1);
316 FormFieldData result2;
317 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2);
319 expected.name = ASCIIToUTF16("element");
320 expected.value = ASCIIToUTF16("value");
321 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2);
324 // We should be able to extract a text field with autocomplete="off".
325 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) {
326 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
327 " autocomplete=\"off\"/>");
329 WebFrame* frame = GetMainFrame();
330 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
332 WebElement web_element = frame->document().getElementById("element");
333 WebFormControlElement element = web_element.to<WebFormControlElement>();
334 FormFieldData result;
335 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
337 FormFieldData expected;
338 expected.name = ASCIIToUTF16("element");
339 expected.value = ASCIIToUTF16("value");
340 expected.form_control_type = "text";
341 expected.autocomplete_attribute = "off";
342 expected.max_length = WebInputElement::defaultMaxLength();
343 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
346 // We should be able to extract a text field with maxlength specified.
347 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) {
348 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
349 " maxlength=\"5\"/>");
351 WebFrame* frame = GetMainFrame();
352 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
354 WebElement web_element = frame->document().getElementById("element");
355 WebFormControlElement element = web_element.to<WebFormControlElement>();
356 FormFieldData result;
357 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
359 FormFieldData expected;
360 expected.name = ASCIIToUTF16("element");
361 expected.value = ASCIIToUTF16("value");
362 expected.form_control_type = "text";
363 expected.max_length = 5;
364 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
367 // We should be able to extract a text field that has been autofilled.
368 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) {
369 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
371 WebFrame* frame = GetMainFrame();
372 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
374 WebElement web_element = frame->document().getElementById("element");
375 WebInputElement element = web_element.to<WebInputElement>();
376 element.setAutofilled(true);
377 FormFieldData result;
378 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
380 FormFieldData expected;
381 expected.name = ASCIIToUTF16("element");
382 expected.value = ASCIIToUTF16("value");
383 expected.form_control_type = "text";
384 expected.max_length = WebInputElement::defaultMaxLength();
385 expected.is_autofilled = true;
386 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
389 // We should be able to extract a radio or a checkbox field that has been
391 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) {
392 LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\" checked/>"
393 "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>");
395 WebFrame* frame = GetMainFrame();
396 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
398 WebElement web_element = frame->document().getElementById("checkbox");
399 WebInputElement element = web_element.to<WebInputElement>();
400 element.setAutofilled(true);
401 FormFieldData result;
402 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
404 FormFieldData expected;
405 expected.name = ASCIIToUTF16("checkbox");
406 expected.value = ASCIIToUTF16("mail");
407 expected.form_control_type = "checkbox";
408 expected.is_autofilled = true;
409 expected.is_checkable = true;
410 expected.is_checked = true;
411 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
413 web_element = frame->document().getElementById("radio");
414 element = web_element.to<WebInputElement>();
415 element.setAutofilled(true);
416 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
417 expected.name = ASCIIToUTF16("radio");
418 expected.value = ASCIIToUTF16("male");
419 expected.form_control_type = "radio";
420 expected.is_autofilled = true;
421 expected.is_checkable = true;
422 expected.is_checked = false;
423 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
426 // We should be able to extract a <select> field.
427 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) {
428 LoadHTML("<SELECT id=\"element\"/>"
429 " <OPTION value=\"CA\">California</OPTION>"
430 " <OPTION value=\"TX\">Texas</OPTION>"
433 WebFrame* frame = GetMainFrame();
434 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
436 WebElement web_element = frame->document().getElementById("element");
437 WebFormControlElement element = web_element.to<WebFormControlElement>();
438 FormFieldData result1;
439 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1);
441 FormFieldData expected;
442 expected.name = ASCIIToUTF16("element");
443 expected.max_length = 0;
444 expected.form_control_type = "select-one";
446 expected.value = ASCIIToUTF16("CA");
447 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1);
449 FormFieldData result2;
450 WebFormControlElementToFormField(
452 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE |
453 autofill::EXTRACT_OPTION_TEXT),
455 expected.value = ASCIIToUTF16("California");
456 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2);
458 FormFieldData result3;
459 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS,
461 expected.value = base::string16();
462 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3);
464 ASSERT_EQ(2U, result3.option_values.size());
465 ASSERT_EQ(2U, result3.option_contents.size());
466 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]);
467 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]);
468 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]);
469 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]);
472 // When faced with <select> field with *many* options, we should trim them to a
473 // reasonable number.
474 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) {
475 std::string html = "<SELECT id=\"element\"/>";
476 for (size_t i = 0; i < 2 * kMaxListSize; ++i) {
477 html += base::StringPrintf("<OPTION value=\"%" PRIuS "\">"
478 "%" PRIuS "</OPTION>", i, i);
481 LoadHTML(html.c_str());
483 WebFrame* frame = GetMainFrame();
486 WebElement web_element = frame->document().getElementById("element");
487 WebFormControlElement element = web_element.to<WebFormControlElement>();
488 FormFieldData result;
489 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result);
491 EXPECT_EQ(0U, result.option_values.size());
492 EXPECT_EQ(0U, result.option_contents.size());
495 // We should be able to extract a <textarea> field.
496 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) {
497 LoadHTML("<TEXTAREA id=\"element\">"
498 "This element's value "
499 "spans multiple lines."
502 WebFrame* frame = GetMainFrame();
503 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
505 WebElement web_element = frame->document().getElementById("element");
506 WebFormControlElement element = web_element.to<WebFormControlElement>();
507 FormFieldData result_sans_value;
508 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE,
511 FormFieldData expected;
512 expected.name = ASCIIToUTF16("element");
513 expected.max_length = 0;
514 expected.form_control_type = "textarea";
515 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value);
517 FormFieldData result_with_value;
518 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE,
520 expected.value = ASCIIToUTF16("This element's value\n"
521 "spans multiple lines.");
522 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value);
525 // We should be able to extract an <input type="month"> field.
526 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) {
527 LoadHTML("<INPUT type=\"month\" id=\"element\" value=\"2011-12\">");
529 WebFrame* frame = GetMainFrame();
530 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
532 WebElement web_element = frame->document().getElementById("element");
533 WebFormControlElement element = web_element.to<WebFormControlElement>();
534 FormFieldData result_sans_value;
535 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE,
538 FormFieldData expected;
539 expected.name = ASCIIToUTF16("element");
540 expected.max_length = 0;
541 expected.form_control_type = "month";
542 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value);
544 FormFieldData result_with_value;
545 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE,
547 expected.value = ASCIIToUTF16("2011-12");
548 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value);
551 // We should not extract the value for non-text and non-select fields.
552 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) {
553 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
554 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>"
555 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>"
558 WebFrame* frame = GetMainFrame();
559 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
561 WebElement web_element = frame->document().getElementById("hidden");
562 WebFormControlElement element = web_element.to<WebFormControlElement>();
563 FormFieldData result;
564 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
566 FormFieldData expected;
567 expected.max_length = 0;
569 expected.name = ASCIIToUTF16("hidden");
570 expected.form_control_type = "hidden";
571 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
573 web_element = frame->document().getElementById("submit");
574 element = web_element.to<WebFormControlElement>();
575 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
576 expected.name = ASCIIToUTF16("submit");
577 expected.form_control_type = "submit";
578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
581 // We should be able to extract password fields.
582 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) {
583 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
584 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>"
587 WebFrame* frame = GetMainFrame();
588 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
590 WebElement web_element = frame->document().getElementById("password");
591 WebFormControlElement element = web_element.to<WebFormControlElement>();
592 FormFieldData result;
593 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
595 FormFieldData expected;
596 expected.max_length = WebInputElement::defaultMaxLength();
597 expected.name = ASCIIToUTF16("password");
598 expected.form_control_type = "password";
599 expected.value = ASCIIToUTF16("secret");
600 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
603 // We should be able to extract the autocompletetype attribute.
604 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) {
606 "<INPUT type=\"text\" id=\"absent\"/>"
607 "<INPUT type=\"text\" id=\"empty\" autocomplete=\"\"/>"
608 "<INPUT type=\"text\" id=\"off\" autocomplete=\"off\"/>"
609 "<INPUT type=\"text\" id=\"regular\" autocomplete=\"email\"/>"
610 "<INPUT type=\"text\" id=\"multi-valued\" "
611 " autocomplete=\"billing email\"/>"
612 "<INPUT type=\"text\" id=\"experimental\" x-autocompletetype=\"email\"/>"
613 "<INPUT type=\"month\" id=\"month\" autocomplete=\"cc-exp\"/>"
614 "<SELECT id=\"select\" autocomplete=\"state\"/>"
615 " <OPTION value=\"CA\">California</OPTION>"
616 " <OPTION value=\"TX\">Texas</OPTION>"
618 "<TEXTAREA id=\"textarea\" autocomplete=\"street-address\">"
623 "<INPUT type=\"text\" id=\"malicious\" autocomplete=\"" +
624 std::string(10000, 'x') + "\"/>";
625 LoadHTML(html.c_str());
627 WebFrame* frame = GetMainFrame();
628 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
631 const std::string element_id;
632 const std::string form_control_type;
633 const std::string autocomplete_attribute;
635 TestCase test_cases[] = {
636 // An absent attribute is equivalent to an empty one.
637 { "absent", "text", "" },
638 // Make sure there are no issues parsing an empty attribute.
639 { "empty", "text", "" },
640 // Make sure there are no issues parsing an attribute value that isn't a
642 { "off", "text", "off" },
643 // Common case: exactly one type specified.
644 { "regular", "text", "email" },
645 // Verify that we correctly extract multiple tokens as well.
646 { "multi-valued", "text", "billing email" },
647 // Verify that <input type="month"> fields are supported.
648 { "month", "month", "cc-exp" },
649 // We previously extracted this data from the experimental
650 // 'x-autocompletetype' attribute. Now that the field type hints are part
651 // of the spec under the autocomplete attribute, we no longer support the
652 // experimental version.
653 { "experimental", "text", "" },
654 // <select> elements should behave no differently from text fields here.
655 { "select", "select-one", "state" },
656 // <textarea> elements should also behave no differently from text fields.
657 { "textarea", "textarea", "street-address" },
658 // Very long attribute values should be replaced by a default string, to
659 // prevent malicious websites from DOSing the browser process.
660 { "malicious", "text", "x-max-data-length-exceeded" },
663 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
664 WebElement web_element = frame->document().getElementById(
665 ASCIIToUTF16(test_cases[i].element_id));
666 WebFormControlElement element = web_element.to<WebFormControlElement>();
667 FormFieldData result;
668 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result);
670 FormFieldData expected;
671 expected.name = ASCIIToUTF16(test_cases[i].element_id);
672 expected.form_control_type = test_cases[i].form_control_type;
673 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute;
674 if (test_cases[i].form_control_type == "text")
675 expected.max_length = WebInputElement::defaultMaxLength();
677 expected.max_length = 0;
679 SCOPED_TRACE(test_cases[i].element_id);
680 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result);
684 TEST_F(FormAutofillTest, WebFormElementToFormData) {
685 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
686 " <LABEL for=\"firstname\">First name:</LABEL>"
687 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
688 " <LABEL for=\"lastname\">Last name:</LABEL>"
689 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
690 " <LABEL for=\"street-address\">Address:</LABEL>"
691 " <TEXTAREA id=\"street-address\">"
692 "123 Fantasy Ln. "
695 " <LABEL for=\"state\">State:</LABEL>"
696 " <SELECT id=\"state\"/>"
697 " <OPTION value=\"CA\">California</OPTION>"
698 " <OPTION value=\"TX\">Texas</OPTION>"
700 " <LABEL for=\"password\">Password:</LABEL>"
701 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>"
702 " <LABEL for=\"month\">Card expiration:</LABEL>"
703 " <INPUT type=\"month\" id=\"month\" value=\"2011-12\"/>"
704 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
705 // The below inputs should be ignored
706 " <LABEL for=\"notvisible\">Hidden:</LABEL>"
707 " <INPUT type=\"hidden\" id=\"notvisible\" value=\"apple\"/>"
710 WebFrame* frame = GetMainFrame();
711 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
713 WebVector<WebFormElement> forms;
714 frame->document().forms(forms);
715 ASSERT_EQ(1U, forms.size());
717 WebElement element = frame->document().getElementById("firstname");
718 WebInputElement input_element = element.to<WebInputElement>();
722 EXPECT_TRUE(WebFormElementToFormData(forms[0],
724 autofill::REQUIRE_NONE,
725 autofill::EXTRACT_VALUE,
728 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
729 EXPECT_EQ(GURL(frame->document().url()), form.origin);
730 EXPECT_EQ(GURL("http://cnn.com"), form.action);
732 const std::vector<FormFieldData>& fields = form.fields;
733 ASSERT_EQ(6U, fields.size());
735 FormFieldData expected;
736 expected.name = ASCIIToUTF16("firstname");
737 expected.value = ASCIIToUTF16("John");
738 expected.label = ASCIIToUTF16("First name:");
739 expected.form_control_type = "text";
740 expected.max_length = WebInputElement::defaultMaxLength();
741 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
743 expected.name = ASCIIToUTF16("lastname");
744 expected.value = ASCIIToUTF16("Smith");
745 expected.label = ASCIIToUTF16("Last name:");
746 expected.form_control_type = "text";
747 expected.max_length = WebInputElement::defaultMaxLength();
748 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
750 expected.name = ASCIIToUTF16("street-address");
751 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42");
752 expected.label = ASCIIToUTF16("Address:");
753 expected.form_control_type = "textarea";
754 expected.max_length = 0;
755 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
757 expected.name = ASCIIToUTF16("state");
758 expected.value = ASCIIToUTF16("CA");
759 expected.label = ASCIIToUTF16("State:");
760 expected.form_control_type = "select-one";
761 expected.max_length = 0;
762 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
764 expected.name = ASCIIToUTF16("password");
765 expected.value = ASCIIToUTF16("secret");
766 expected.label = ASCIIToUTF16("Password:");
767 expected.form_control_type = "password";
768 expected.max_length = WebInputElement::defaultMaxLength();
769 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]);
771 expected.name = ASCIIToUTF16("month");
772 expected.value = ASCIIToUTF16("2011-12");
773 expected.label = ASCIIToUTF16("Card expiration:");
774 expected.form_control_type = "month";
775 expected.max_length = 0;
776 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]);
779 // We should not be able to serialize a form with too many fillable fields.
780 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) {
782 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">";
783 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) {
784 html += "<INPUT type=\"text\"/>";
787 LoadHTML(html.c_str());
789 WebFrame* frame = GetMainFrame();
790 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
792 WebVector<WebFormElement> forms;
793 frame->document().forms(forms);
794 ASSERT_EQ(1U, forms.size());
796 WebElement element = frame->document().getElementById("firstname");
797 WebInputElement input_element = element.to<WebInputElement>();
801 EXPECT_FALSE(WebFormElementToFormData(forms[0],
803 autofill::REQUIRE_NONE,
804 autofill::EXTRACT_VALUE,
809 TEST_F(FormAutofillTest, ExtractForms) {
810 ExpectJohnSmithLabels(
811 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
812 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
813 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
814 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
815 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
819 TEST_F(FormAutofillTest, ExtractMultipleForms) {
820 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
821 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
822 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
823 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
824 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
826 "<FORM name=\"TestForm2\" action=\"http://zoo.com\" method=\"post\">"
827 " <INPUT type=\"text\" id=\"firstname\" value=\"Jack\"/>"
828 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>"
829 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>"
830 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
833 WebFrame* web_frame = GetMainFrame();
834 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
836 FormCache form_cache;
837 std::vector<FormData> forms;
838 form_cache.ExtractNewForms(*web_frame, &forms);
839 ASSERT_EQ(2U, forms.size());
842 const FormData& form = forms[0];
843 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
844 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
845 EXPECT_EQ(GURL("http://cnn.com"), form.action);
847 const std::vector<FormFieldData>& fields = form.fields;
848 ASSERT_EQ(3U, fields.size());
850 FormFieldData expected;
851 expected.form_control_type = "text";
852 expected.max_length = WebInputElement::defaultMaxLength();
854 expected.name = ASCIIToUTF16("firstname");
855 expected.value = ASCIIToUTF16("John");
856 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
858 expected.name = ASCIIToUTF16("lastname");
859 expected.value = ASCIIToUTF16("Smith");
860 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
862 expected.name = ASCIIToUTF16("email");
863 expected.value = ASCIIToUTF16("john@example.com");
864 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
867 const FormData& form2 = forms[1];
868 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name);
869 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
870 EXPECT_EQ(GURL("http://zoo.com"), form2.action);
872 const std::vector<FormFieldData>& fields2 = form2.fields;
873 ASSERT_EQ(3U, fields2.size());
875 expected.name = ASCIIToUTF16("firstname");
876 expected.value = ASCIIToUTF16("Jack");
877 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
879 expected.name = ASCIIToUTF16("lastname");
880 expected.value = ASCIIToUTF16("Adams");
881 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
883 expected.name = ASCIIToUTF16("email");
884 expected.value = ASCIIToUTF16("jack@example.com");
885 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
888 TEST_F(FormAutofillTest, OnlyExtractNewForms) {
890 "<FORM id='testform' action='http://cnn.com' method='post'>"
891 " <INPUT type='text' id='firstname' value='John'/>"
892 " <INPUT type='text' id='lastname' value='Smith'/>"
893 " <INPUT type='text' id='email' value='john@example.com'/>"
894 " <INPUT type='submit' name='reply-send' value='Send'/>"
897 WebFrame* web_frame = GetMainFrame();
898 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
900 FormCache form_cache;
901 std::vector<FormData> forms;
902 form_cache.ExtractNewForms(*web_frame, &forms);
903 ASSERT_EQ(1U, forms.size());
906 // Second call should give nothing as there are no new forms.
907 form_cache.ExtractNewForms(*web_frame, &forms);
908 ASSERT_EQ(0U, forms.size());
910 // Append to the current form will re-extract.
912 "var newInput = document.createElement('input');"
913 "newInput.setAttribute('type', 'text');"
914 "newInput.setAttribute('id', 'telephone');"
915 "newInput.value = '12345';"
916 "document.getElementById('testform').appendChild(newInput);");
917 msg_loop_.RunUntilIdle();
919 form_cache.ExtractNewForms(*web_frame, &forms);
920 ASSERT_EQ(1U, forms.size());
922 const std::vector<FormFieldData>& fields = forms[0].fields;
923 ASSERT_EQ(4U, fields.size());
925 FormFieldData expected;
926 expected.form_control_type = "text";
927 expected.max_length = WebInputElement::defaultMaxLength();
929 expected.name = ASCIIToUTF16("firstname");
930 expected.value = ASCIIToUTF16("John");
931 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
933 expected.name = ASCIIToUTF16("lastname");
934 expected.value = ASCIIToUTF16("Smith");
935 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
937 expected.name = ASCIIToUTF16("email");
938 expected.value = ASCIIToUTF16("john@example.com");
939 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
941 expected.name = ASCIIToUTF16("telephone");
942 expected.value = ASCIIToUTF16("12345");
943 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
947 // Completely new form will also be extracted.
949 "var newForm=document.createElement('form');"
950 "newForm.id='new_testform';"
951 "newForm.action='http://google.com';"
952 "newForm.method='post';"
953 "var newFirstname=document.createElement('input');"
954 "newFirstname.setAttribute('type', 'text');"
955 "newFirstname.setAttribute('id', 'second_firstname');"
956 "newFirstname.value = 'Bob';"
957 "var newLastname=document.createElement('input');"
958 "newLastname.setAttribute('type', 'text');"
959 "newLastname.setAttribute('id', 'second_lastname');"
960 "newLastname.value = 'Hope';"
961 "var newEmail=document.createElement('input');"
962 "newEmail.setAttribute('type', 'text');"
963 "newEmail.setAttribute('id', 'second_email');"
964 "newEmail.value = 'bobhope@example.com';"
965 "newForm.appendChild(newFirstname);"
966 "newForm.appendChild(newLastname);"
967 "newForm.appendChild(newEmail);"
968 "document.body.appendChild(newForm);");
969 msg_loop_.RunUntilIdle();
971 web_frame = GetMainFrame();
972 form_cache.ExtractNewForms(*web_frame, &forms);
973 ASSERT_EQ(1U, forms.size());
975 const std::vector<FormFieldData>& fields2 = forms[0].fields;
976 ASSERT_EQ(3U, fields2.size());
978 expected.name = ASCIIToUTF16("second_firstname");
979 expected.value = ASCIIToUTF16("Bob");
980 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
982 expected.name = ASCIIToUTF16("second_lastname");
983 expected.value = ASCIIToUTF16("Hope");
984 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
986 expected.name = ASCIIToUTF16("second_email");
987 expected.value = ASCIIToUTF16("bobhope@example.com");
988 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
991 // We should not extract a form if it has too few fillable fields.
992 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
993 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
994 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
995 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
996 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
999 WebFrame* web_frame = GetMainFrame();
1000 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1002 FormCache form_cache;
1003 std::vector<FormData> forms;
1004 form_cache.ExtractNewForms(*web_frame, &forms);
1005 EXPECT_EQ(0U, forms.size());
1008 // We should not report additional forms for empty forms.
1009 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) {
1010 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1011 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1012 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1015 WebFrame* web_frame = GetMainFrame();
1016 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1018 FormCache form_cache;
1019 std::vector<FormData> forms;
1020 form_cache.ExtractNewForms(*web_frame, &forms);
1021 EXPECT_EQ(0U, forms.size());
1024 // We should not report additional forms for empty forms.
1025 TEST_F(FormAutofillTest, ExtractFormsNoFields) {
1026 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1029 WebFrame* web_frame = GetMainFrame();
1030 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1032 FormCache form_cache;
1033 std::vector<FormData> forms;
1034 form_cache.ExtractNewForms(*web_frame, &forms);
1035 EXPECT_EQ(0U, forms.size());
1038 // We should not extract a form if it has too few fillable fields.
1039 // Make sure radio and checkbox fields don't count.
1040 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
1041 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1042 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1043 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1044 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>"
1045 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>"
1046 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1049 WebFrame* web_frame = GetMainFrame();
1050 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1052 FormCache form_cache;
1053 std::vector<FormData> forms;
1054 form_cache.ExtractNewForms(*web_frame, &forms);
1055 EXPECT_EQ(0U, forms.size());
1058 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) {
1060 // Form is not auto-completable due to autocomplete=off.
1061 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\""
1062 " autocomplete=off>"
1063 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1064 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1065 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1066 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1069 WebFrame* web_frame = GetMainFrame();
1070 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1072 WebVector<WebFormElement> web_forms;
1073 web_frame->document().forms(web_forms);
1074 ASSERT_EQ(1U, web_forms.size());
1075 WebFormElement web_form = web_forms[0];
1078 EXPECT_TRUE(WebFormElementToFormData(
1079 web_form, WebFormControlElement(), autofill::REQUIRE_NONE,
1080 autofill::EXTRACT_NONE, &form, NULL));
1081 EXPECT_FALSE(WebFormElementToFormData(
1082 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE,
1083 autofill::EXTRACT_NONE, &form, NULL));
1087 // The firstname element is not auto-completable due to autocomplete=off.
1088 LoadHTML("<FORM name=\"TestForm\" action=\"http://abc.com\" "
1090 " <INPUT type=\"text\" id=\"firstname\" value=\"John\""
1091 " autocomplete=off>"
1092 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>"
1093 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1094 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1095 " <INPUT type=\"submit\" name=\"reply\" value=\"Send\"/>"
1098 WebFrame* web_frame = GetMainFrame();
1099 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1101 WebVector<WebFormElement> web_forms;
1102 web_frame->document().forms(web_forms);
1103 ASSERT_EQ(1U, web_forms.size());
1104 WebFormElement web_form = web_forms[0];
1107 EXPECT_TRUE(WebFormElementToFormData(
1108 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE,
1109 autofill::EXTRACT_VALUE, &form, NULL));
1111 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1112 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1113 EXPECT_EQ(GURL("http://abc.com"), form.action);
1115 const std::vector<FormFieldData>& fields = form.fields;
1116 ASSERT_EQ(3U, fields.size());
1118 FormFieldData expected;
1119 expected.form_control_type = "text";
1120 expected.max_length = WebInputElement::defaultMaxLength();
1122 expected.name = ASCIIToUTF16("middlename");
1123 expected.value = ASCIIToUTF16("Jack");
1124 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
1126 expected.name = ASCIIToUTF16("lastname");
1127 expected.value = ASCIIToUTF16("Smith");
1128 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
1130 expected.name = ASCIIToUTF16("email");
1131 expected.value = ASCIIToUTF16("john@example.com");
1132 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
1136 TEST_F(FormAutofillTest, FindFormForInputElement) {
1137 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1138 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1139 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1140 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\""
1141 "autocomplete=\"off\" />"
1142 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>"
1143 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1146 WebFrame* web_frame = GetMainFrame();
1147 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1149 FormCache form_cache;
1150 std::vector<FormData> forms;
1151 form_cache.ExtractNewForms(*web_frame, &forms);
1152 ASSERT_EQ(1U, forms.size());
1154 // Get the input element we want to find.
1155 WebElement element = web_frame->document().getElementById("firstname");
1156 WebInputElement input_element = element.to<WebInputElement>();
1158 // Find the form and verify it's the correct form.
1160 FormFieldData field;
1161 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
1164 autofill::REQUIRE_NONE));
1165 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1166 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1167 EXPECT_EQ(GURL("http://buh.com"), form.action);
1169 const std::vector<FormFieldData>& fields = form.fields;
1170 ASSERT_EQ(4U, fields.size());
1172 FormFieldData expected;
1173 expected.form_control_type = "text";
1174 expected.max_length = WebInputElement::defaultMaxLength();
1176 expected.name = ASCIIToUTF16("firstname");
1177 expected.value = ASCIIToUTF16("John");
1178 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
1179 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
1181 expected.name = ASCIIToUTF16("lastname");
1182 expected.value = ASCIIToUTF16("Smith");
1183 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
1185 expected.name = ASCIIToUTF16("email");
1186 expected.value = ASCIIToUTF16("john@example.com");
1187 expected.autocomplete_attribute = "off";
1188 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
1189 expected.autocomplete_attribute = std::string(); // reset
1191 expected.name = ASCIIToUTF16("phone");
1192 expected.value = ASCIIToUTF16("1.800.555.1234");
1193 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
1195 // Try again, but require autocomplete.
1197 FormFieldData field2;
1198 EXPECT_TRUE(FindFormAndFieldForFormControlElement(
1202 autofill::REQUIRE_AUTOCOMPLETE));
1203 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1204 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
1205 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1207 const std::vector<FormFieldData>& fields2 = form2.fields;
1208 ASSERT_EQ(3U, fields2.size());
1210 expected.form_control_type = "text";
1211 expected.max_length = WebInputElement::defaultMaxLength();
1213 expected.name = ASCIIToUTF16("firstname");
1214 expected.value = ASCIIToUTF16("John");
1215 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
1216 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
1218 expected.name = ASCIIToUTF16("lastname");
1219 expected.value = ASCIIToUTF16("Smith");
1220 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
1222 expected.name = ASCIIToUTF16("phone");
1223 expected.value = ASCIIToUTF16("1.800.555.1234");
1224 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
1227 TEST_F(FormAutofillTest, FindFormForTextAreaElement) {
1228 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1229 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1230 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1231 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\""
1232 "autocomplete=\"off\" />"
1233 " <TEXTAREA id=\"street-address\">"
1234 "123 Fantasy Ln. "
1237 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1240 WebFrame* web_frame = GetMainFrame();
1241 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1243 FormCache form_cache;
1244 std::vector<FormData> forms;
1245 form_cache.ExtractNewForms(*web_frame, &forms);
1246 ASSERT_EQ(1U, forms.size());
1248 // Get the textarea element we want to find.
1249 WebElement element = web_frame->document().getElementById("street-address");
1250 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>();
1252 // Find the form and verify it's the correct form.
1254 FormFieldData field;
1255 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element,
1258 autofill::REQUIRE_NONE));
1259 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1260 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1261 EXPECT_EQ(GURL("http://buh.com"), form.action);
1263 const std::vector<FormFieldData>& fields = form.fields;
1264 ASSERT_EQ(4U, fields.size());
1266 FormFieldData expected;
1268 expected.name = ASCIIToUTF16("firstname");
1269 expected.value = ASCIIToUTF16("John");
1270 expected.form_control_type = "text";
1271 expected.max_length = WebInputElement::defaultMaxLength();
1272 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
1274 expected.name = ASCIIToUTF16("lastname");
1275 expected.value = ASCIIToUTF16("Smith");
1276 expected.form_control_type = "text";
1277 expected.max_length = WebInputElement::defaultMaxLength();
1278 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
1280 expected.name = ASCIIToUTF16("email");
1281 expected.value = ASCIIToUTF16("john@example.com");
1282 expected.autocomplete_attribute = "off";
1283 expected.form_control_type = "text";
1284 expected.max_length = WebInputElement::defaultMaxLength();
1285 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
1286 expected.autocomplete_attribute = std::string(); // reset
1288 expected.name = ASCIIToUTF16("street-address");
1289 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42");
1290 expected.form_control_type = "textarea";
1291 expected.max_length = 0;
1292 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
1293 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
1295 // Try again, but require autocomplete.
1297 FormFieldData field2;
1298 EXPECT_TRUE(FindFormAndFieldForFormControlElement(
1302 autofill::REQUIRE_AUTOCOMPLETE));
1303 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1304 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
1305 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1307 const std::vector<FormFieldData>& fields2 = form2.fields;
1308 ASSERT_EQ(3U, fields2.size());
1310 expected.name = ASCIIToUTF16("firstname");
1311 expected.value = ASCIIToUTF16("John");
1312 expected.form_control_type = "text";
1313 expected.max_length = WebInputElement::defaultMaxLength();
1314 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
1316 expected.name = ASCIIToUTF16("lastname");
1317 expected.value = ASCIIToUTF16("Smith");
1318 expected.form_control_type = "text";
1319 expected.max_length = WebInputElement::defaultMaxLength();
1320 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
1322 expected.name = ASCIIToUTF16("street-address");
1323 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42");
1324 expected.form_control_type = "textarea";
1325 expected.max_length = 0;
1326 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
1327 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
1330 // Test regular FillForm function.
1331 TEST_F(FormAutofillTest, FillForm) {
1332 static const AutofillFieldCase field_cases[] = {
1333 // fields: form_control_type, name, initial_value, autocomplete_attribute,
1334 // should_be_autofilled, autofill_value, expected_value
1336 // Regular empty fields (firstname & lastname) should be autofilled.
1337 {"text", "firstname", "", "", true, "filled firstname",
1338 "filled firstname"},
1339 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"},
1340 // hidden fields should not be extracted to form_data.
1341 // Non empty fields should not be autofilled.
1342 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"},
1343 // "noautocomplete" should not be extracted to form_data.
1344 // Disabled fields should not be autofilled.
1345 {"text", "notenabled", "", "", false, "filled notenabled", ""},
1346 // Readonly fields should not be autofilled.
1347 {"text", "readonly", "", "", false, "filled readonly", ""},
1348 // Fields with "visibility: hidden" should not be autofilled.
1349 {"text", "invisible", "", "", false, "filled invisible", ""},
1350 // Fields with "display:none" should not be autofilled.
1351 {"text", "displaynone", "", "", false, "filled displaynone", ""},
1352 // Regular <input type="month"> should be autofilled.
1353 {"month", "month", "", "", true, "2017-11", "2017-11"},
1354 // Non-empty <input type="month"> should not be autofilled.
1355 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"},
1356 // Regular select fields should be autofilled.
1357 {"select-one", "select", "", "", true, "TX", "TX"},
1358 // Select fields should be autofilled even if they already have a
1360 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1361 // Select fields should not be autofilled if no new value is passed from
1362 // autofill profile. The existing value should not be overriden.
1363 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
1364 // Regular textarea elements should be autofilled.
1365 {"textarea", "textarea", "", "", true, "some multi-\nline value",
1366 "some multi-\nline value"},
1367 // Non-empty textarea elements should not be autofilled.
1368 {"textarea", "textarea-nonempty", "Go\naway!", "", false,
1369 "some multi-\nline value", "Go\naway!"},
1371 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1372 FillForm, &GetValueWrapper);
1373 // Verify preview selection.
1374 WebInputElement firstname = GetMainFrame()->document().
1375 getElementById("firstname").to<WebInputElement>();
1376 EXPECT_EQ(16, firstname.selectionStart());
1377 EXPECT_EQ(16, firstname.selectionEnd());
1380 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) {
1381 static const AutofillFieldCase field_cases[] = {
1382 // fields: form_control_type, name, initial_value, autocomplete_attribute,
1383 // should_be_autofilled, autofill_value, expected_value
1385 // Regular empty fields (firstname & lastname) should be autofilled.
1386 {"text", "firstname", "", "", true, "filled firstname",
1387 "filled firstname"},
1388 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"},
1389 // hidden fields should not be extracted to form_data.
1390 // Non empty fields should be overriden.
1391 {"text", "notempty", "Hi", "", true, "filled notempty",
1393 // "noautocomplete" should not be extracted to form_data.
1394 // Disabled fields should not be autofilled.
1395 {"text", "notenabled", "", "", false, "filled notenabled", ""},
1396 // Readonly fields should not be autofilled.
1397 {"text", "readonly", "", "", false, "filled readonly", ""},
1398 // Fields with "visibility: hidden" should also be autofilled.
1399 {"text", "invisible", "", "", true, "filled invisible",
1400 "filled invisible"},
1401 // Fields with "display:none" should also be autofilled.
1402 {"text", "displaynone", "", "", true, "filled displaynone",
1403 "filled displaynone"},
1404 // Regular <input type="month"> should be autofilled.
1405 {"month", "month", "", "", true, "2017-11", "2017-11"},
1406 // Non-empty <input type="month"> should be overridden.
1407 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"},
1408 // Regular select fields should be autofilled.
1409 {"select-one", "select", "", "", true, "TX", "TX"},
1410 // Select fields should be autofilled even if they already have a
1412 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1413 // Select fields should not be autofilled if no new value is passed from
1414 // autofill profile. The existing value should not be overriden.
1415 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
1416 // Regular textarea elements should be autofilled.
1417 {"textarea", "textarea", "", "", true, "some multi-\nline value",
1418 "some multi-\nline value"},
1419 // Nonempty textarea elements should be overridden.
1420 {"textarea", "textarea-nonempty", "Go\naway!", "", true,
1421 "some multi-\nline value", "some multi-\nline value"},
1423 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1424 &FillFormIncludingNonFocusableElementsWrapper,
1428 TEST_F(FormAutofillTest, PreviewForm) {
1429 static const AutofillFieldCase field_cases[] = {
1430 // Normal empty fields should be previewed.
1431 {"text", "firstname", "", "", true, "suggested firstname",
1432 "suggested firstname"},
1433 {"text", "lastname", "", "", true, "suggested lastname",
1434 "suggested lastname"},
1435 // Hidden fields should not be extracted to form_data.
1436 // Non empty fields should not be previewed.
1437 {"text", "notempty", "Hi", "", false, "suggested notempty", ""},
1438 // "noautocomplete" should not be extracted to form_data.
1439 // Disabled fields should not be previewed.
1440 {"text", "notenabled", "", "", false, "suggested notenabled", ""},
1441 // Readonly fields should not be previewed.
1442 {"text", "readonly", "", "", false, "suggested readonly", ""},
1443 // Fields with "visibility: hidden" should not be previewed.
1444 {"text", "invisible", "", "", false, "suggested invisible",
1446 // Fields with "display:none" should not previewed.
1447 {"text", "displaynone", "", "", false, "suggested displaynone",
1449 // Regular <input type="month"> should be previewed.
1450 {"month", "month", "", "", true, "2017-11", "2017-11"},
1451 // Non-empty <input type="month"> should not be previewed.
1452 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""},
1453 // Regular select fields should be previewed.
1454 {"select-one", "select", "", "", true, "TX", "TX"},
1455 // Select fields should be previewed even if they already have a
1457 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1458 // Select fields should not be previewed if no suggestion is passed from
1459 // autofill profile.
1460 {"select-one", "select-unchanged", "CA", "", false, "", ""},
1461 // Normal textarea elements should be previewed.
1462 {"textarea", "textarea", "", "", true, "suggested multi-\nline value",
1463 "suggested multi-\nline value"},
1464 // Nonempty textarea elements should not be previewed.
1465 {"textarea", "textarea-nonempty", "Go\naway!", "", false,
1466 "suggested multi-\nline value", ""},
1468 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1469 &PreviewForm, &GetSuggestedValueWrapper);
1471 // Verify preview selection.
1472 WebInputElement firstname = GetMainFrame()->document().
1473 getElementById("firstname").to<WebInputElement>();
1474 EXPECT_EQ(0, firstname.selectionStart());
1475 EXPECT_EQ(19, firstname.selectionEnd());
1478 TEST_F(FormAutofillTest, Labels) {
1479 ExpectJohnSmithLabels(
1480 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1481 " <LABEL for=\"firstname\"> First name: </LABEL>"
1482 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1483 " <LABEL for=\"lastname\"> Last name: </LABEL>"
1484 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1485 " <LABEL for=\"email\"> Email: </LABEL>"
1486 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1487 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1491 TEST_F(FormAutofillTest, LabelsWithSpans) {
1492 ExpectJohnSmithLabels(
1493 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1494 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>"
1495 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1496 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>"
1497 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1498 " <LABEL for=\"email\"><span>Email: </span></LABEL>"
1499 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1500 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1504 // This test is different from FormAutofillTest.Labels in that the label
1505 // elements for= attribute is set to the name of the form control element it is
1506 // a label for instead of the id of the form control element. This is invalid
1507 // because the for= attribute must be set to the id of the form control element;
1508 // however, current label parsing code will extract the text from the previous
1509 // label element and apply it to the following input field.
1510 TEST_F(FormAutofillTest, InvalidLabels) {
1511 ExpectJohnSmithLabels(
1512 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1513 " <LABEL for=\"firstname\"> First name: </LABEL>"
1514 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>"
1515 " <LABEL for=\"lastname\"> Last name: </LABEL>"
1516 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>"
1517 " <LABEL for=\"email\"> Email: </LABEL>"
1518 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\"/>"
1519 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1523 // This test has three form control elements, only one of which has a label
1524 // element associated with it.
1525 TEST_F(FormAutofillTest, OneLabelElement) {
1526 ExpectJohnSmithLabels(
1527 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1529 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1530 " <LABEL for=\"lastname\">Last name: </LABEL>"
1531 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1533 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1534 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1538 TEST_F(FormAutofillTest, LabelsInferredFromText) {
1539 ExpectJohnSmithLabels(
1540 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1542 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1544 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1546 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1547 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1551 TEST_F(FormAutofillTest, LabelsInferredFromParagraph) {
1552 ExpectJohnSmithLabels(
1553 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1554 " <P>First name:</P><INPUT type=\"text\" "
1555 " id=\"firstname\" value=\"John\"/>"
1556 " <P>Last name:</P>"
1557 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1559 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1560 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1564 TEST_F(FormAutofillTest, LabelsInferredFromBold) {
1565 ExpectJohnSmithLabels(
1566 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1567 " <B>First name:</B><INPUT type=\"text\" "
1568 " id=\"firstname\" value=\"John\"/>"
1569 " <B>Last name:</B>"
1570 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1572 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1573 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1577 TEST_F(FormAutofillTest, LabelsInferredPriorToImgOrBr) {
1578 ExpectJohnSmithLabels(
1579 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1580 " First name:<IMG/><INPUT type=\"text\" "
1581 " id=\"firstname\" value=\"John\"/>"
1583 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1585 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1586 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1590 TEST_F(FormAutofillTest, LabelsInferredFromTableCell) {
1591 ExpectJohnSmithLabels(
1592 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1595 " <TD>First name:</TD>"
1596 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
1599 " <TD>Last name:</TD>"
1600 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
1604 " <TD><INPUT type=\"text\" id=\"email\""
1605 " value=\"john@example.com\"/></TD>"
1610 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1617 TEST_F(FormAutofillTest, LabelsInferredFromTableCellTH) {
1618 ExpectJohnSmithLabels(
1619 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1622 " <TH>First name:</TH>"
1623 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
1626 " <TH>Last name:</TH>"
1627 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
1631 " <TD><INPUT type=\"text\" id=\"email\""
1632 " value=\"john@example.com\"/></TD>"
1637 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1644 TEST_F(FormAutofillTest, LabelsInferredFromTableCellNested) {
1645 std::vector<base::string16> labels, names, values;
1647 labels.push_back(ASCIIToUTF16("First name: Bogus"));
1648 names.push_back(ASCIIToUTF16("firstname"));
1649 values.push_back(ASCIIToUTF16("John"));
1651 labels.push_back(ASCIIToUTF16("Last name:"));
1652 names.push_back(ASCIIToUTF16("lastname"));
1653 values.push_back(ASCIIToUTF16("Smith"));
1655 labels.push_back(ASCIIToUTF16("Email:"));
1656 names.push_back(ASCIIToUTF16("email"));
1657 values.push_back(ASCIIToUTF16("john@example.com"));
1660 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1673 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1685 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1697 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1704 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1709 labels, names, values);
1712 TEST_F(FormAutofillTest, LabelsInferredFromTableEmptyTDs) {
1713 std::vector<base::string16> labels, names, values;
1715 labels.push_back(ASCIIToUTF16("* First Name"));
1716 names.push_back(ASCIIToUTF16("firstname"));
1717 values.push_back(ASCIIToUTF16("John"));
1719 labels.push_back(ASCIIToUTF16("* Last Name"));
1720 names.push_back(ASCIIToUTF16("lastname"));
1721 values.push_back(ASCIIToUTF16("Smith"));
1723 labels.push_back(ASCIIToUTF16("* Email"));
1724 names.push_back(ASCIIToUTF16("email"));
1725 values.push_back(ASCIIToUTF16("john@example.com"));
1728 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1733 " <B>First Name</B>"
1737 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1747 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1757 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1763 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1768 labels, names, values);
1771 TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) {
1772 std::vector<base::string16> labels, names, values;
1774 labels.push_back(ASCIIToUTF16("* First Name"));
1775 names.push_back(ASCIIToUTF16("firstname"));
1776 values.push_back(ASCIIToUTF16("John"));
1778 labels.push_back(ASCIIToUTF16("* Last Name"));
1779 names.push_back(ASCIIToUTF16("lastname"));
1780 values.push_back(ASCIIToUTF16("Smith"));
1782 labels.push_back(ASCIIToUTF16("* Email"));
1783 names.push_back(ASCIIToUTF16("email"));
1784 values.push_back(ASCIIToUTF16("john@example.com"));
1787 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1790 " <TD>* First Name</TD>"
1793 " <INPUT type=\"hidden\"/>"
1794 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1798 " <TD>* Last Name</TD>"
1800 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1806 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1812 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1817 labels, names, values);
1820 // <script>, <noscript> and <option> tags are excluded when the labels are
1822 // Also <!-- comment --> is excluded.
1823 TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) {
1824 std::vector<base::string16> labels, names, values;
1825 std::vector<std::string> control_types;
1827 labels.push_back(ASCIIToUTF16("* First Name"));
1828 names.push_back(ASCIIToUTF16("firstname"));
1829 values.push_back(ASCIIToUTF16("John"));
1830 control_types.push_back("text");
1832 labels.push_back(ASCIIToUTF16("* Middle Name"));
1833 names.push_back(ASCIIToUTF16("middlename"));
1834 values.push_back(ASCIIToUTF16("Joe"));
1835 control_types.push_back("text");
1837 labels.push_back(ASCIIToUTF16("* Last Name"));
1838 names.push_back(ASCIIToUTF16("lastname"));
1839 values.push_back(ASCIIToUTF16("Smith"));
1840 control_types.push_back("text");
1842 labels.push_back(ASCIIToUTF16("* Country"));
1843 names.push_back(ASCIIToUTF16("country"));
1844 values.push_back(ASCIIToUTF16("US"));
1845 control_types.push_back("select-one");
1847 labels.push_back(ASCIIToUTF16("* Email"));
1848 names.push_back(ASCIIToUTF16("email"));
1849 values.push_back(ASCIIToUTF16("john@example.com"));
1850 control_types.push_back("text");
1852 ExpectLabelsAndTypes(
1853 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1858 " <B>First Name</B>"
1861 " <SCRIPT> <!-- function test() { alert('ignored as label'); } -->"
1863 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1869 " <B>Middle Name</B>"
1875 " <INPUT type=\"text\" id=\"middlename\" value=\"Joe\"/>"
1884 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1893 " <SELECT id=\"country\">"
1894 " <OPTION VALUE=\"US\">The value should be ignored as label."
1896 " <OPTION VALUE=\"JP\">JAPAN</OPTION>"
1906 " <!-- This comment should be ignored as inferred label.-->"
1907 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1913 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1918 labels, names, values, control_types);
1921 TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) {
1922 ExpectJohnSmithLabels(
1923 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1927 " <LABEL>First name:</LABEL>"
1928 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1933 " <LABEL>Last name:</LABEL>"
1934 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1939 " <LABEL>Email:</LABEL>"
1940 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1944 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1948 TEST_F(FormAutofillTest, LabelsInferredFromTableTDInterveningElements) {
1949 ExpectJohnSmithLabels(
1950 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1956 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1963 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1970 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1974 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1978 // Verify that we correctly infer labels when the label text spans multiple
1979 // adjacent HTML elements, not separated by whitespace.
1980 TEST_F(FormAutofillTest, LabelsInferredFromTableAdjacentElements) {
1981 std::vector<base::string16> labels, names, values;
1983 labels.push_back(ASCIIToUTF16("*First Name"));
1984 names.push_back(ASCIIToUTF16("firstname"));
1985 values.push_back(ASCIIToUTF16("John"));
1987 labels.push_back(ASCIIToUTF16("*Last Name"));
1988 names.push_back(ASCIIToUTF16("lastname"));
1989 values.push_back(ASCIIToUTF16("Smith"));
1991 labels.push_back(ASCIIToUTF16("*Email"));
1992 names.push_back(ASCIIToUTF16("email"));
1993 values.push_back(ASCIIToUTF16("john@example.com"));
1996 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2000 " <SPAN>*</SPAN><B>First Name</B>"
2003 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
2008 " <SPAN>*</SPAN><B>Last Name</B>"
2011 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2016 " <SPAN>*</SPAN><B>Email</B>"
2019 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
2024 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2029 labels, names, values);
2032 // Verify that we correctly infer labels when the label text resides in the
2034 TEST_F(FormAutofillTest, LabelsInferredFromTableRow) {
2035 std::vector<base::string16> labels, names, values;
2037 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email"));
2038 names.push_back(ASCIIToUTF16("firstname"));
2039 values.push_back(ASCIIToUTF16("John"));
2041 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email"));
2042 names.push_back(ASCIIToUTF16("lastname"));
2043 values.push_back(ASCIIToUTF16("Smith"));
2045 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email"));
2046 names.push_back(ASCIIToUTF16("email"));
2047 values.push_back(ASCIIToUTF16("john@example.com"));
2050 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2053 " <TD>*First Name</TD>"
2054 " <TD>*Last Name</TD>"
2059 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
2062 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2065 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
2070 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2074 labels, names, values);
2077 // Verify that we correctly infer labels when enclosed within a list item.
2078 TEST_F(FormAutofillTest, LabelsInferredFromListItem) {
2079 std::vector<base::string16> labels, names, values;
2081 labels.push_back(ASCIIToUTF16("* Home Phone"));
2082 names.push_back(ASCIIToUTF16("areacode"));
2083 values.push_back(ASCIIToUTF16("415"));
2085 labels.push_back(ASCIIToUTF16("* Home Phone"));
2086 names.push_back(ASCIIToUTF16("prefix"));
2087 values.push_back(ASCIIToUTF16("555"));
2089 labels.push_back(ASCIIToUTF16("* Home Phone"));
2090 names.push_back(ASCIIToUTF16("suffix"));
2091 values.push_back(ASCIIToUTF16("1212"));
2094 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2097 " <SPAN>Bogus</SPAN>"
2100 " <LABEL><EM>*</EM> Home Phone</LABEL>"
2101 " <INPUT type=\"text\" id=\"areacode\" value=\"415\"/>"
2102 " <INPUT type=\"text\" id=\"prefix\" value=\"555\"/>"
2103 " <INPUT type=\"text\" id=\"suffix\" value=\"1212\"/>"
2106 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2110 labels, names, values);
2113 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionList) {
2114 std::vector<base::string16> labels, names, values;
2116 labels.push_back(ASCIIToUTF16("* First name: Bogus"));
2117 names.push_back(ASCIIToUTF16("firstname"));
2118 values.push_back(ASCIIToUTF16("John"));
2120 labels.push_back(ASCIIToUTF16("Last name:"));
2121 names.push_back(ASCIIToUTF16("lastname"));
2122 values.push_back(ASCIIToUTF16("Smith"));
2124 labels.push_back(ASCIIToUTF16("Email:"));
2125 names.push_back(ASCIIToUTF16("email"));
2126 values.push_back(ASCIIToUTF16("john@example.com"));
2129 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2144 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
2154 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2164 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
2169 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2173 labels, names, values);
2176 TEST_F(FormAutofillTest, LabelsInferredWithSameName) {
2177 std::vector<base::string16> labels, names, values;
2179 labels.push_back(ASCIIToUTF16("Address Line 1:"));
2180 names.push_back(ASCIIToUTF16("Address"));
2181 values.push_back(base::string16());
2183 labels.push_back(ASCIIToUTF16("Address Line 2:"));
2184 names.push_back(ASCIIToUTF16("Address"));
2185 values.push_back(base::string16());
2187 labels.push_back(ASCIIToUTF16("Address Line 3:"));
2188 names.push_back(ASCIIToUTF16("Address"));
2189 values.push_back(base::string16());
2192 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2194 " <INPUT type=\"text\" name=\"Address\"/>"
2196 " <INPUT type=\"text\" name=\"Address\"/>"
2198 " <INPUT type=\"text\" name=\"Address\"/>"
2199 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2201 labels, names, values);
2204 TEST_F(FormAutofillTest, LabelsInferredWithImageTags) {
2205 std::vector<base::string16> labels, names, values;
2207 labels.push_back(ASCIIToUTF16("Phone:"));
2208 names.push_back(ASCIIToUTF16("dayphone1"));
2209 values.push_back(base::string16());
2211 labels.push_back(ASCIIToUTF16("-"));
2212 names.push_back(ASCIIToUTF16("dayphone2"));
2213 values.push_back(base::string16());
2215 labels.push_back(ASCIIToUTF16("-"));
2216 names.push_back(ASCIIToUTF16("dayphone3"));
2217 values.push_back(base::string16());
2219 labels.push_back(ASCIIToUTF16("ext.:"));
2220 names.push_back(ASCIIToUTF16("dayphone4"));
2221 values.push_back(base::string16());
2223 labels.push_back(base::string16());
2224 names.push_back(ASCIIToUTF16("dummy"));
2225 values.push_back(base::string16());
2228 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2230 " <input type=\"text\" name=\"dayphone1\">"
2234 " <input type=\"text\" name=\"dayphone2\">"
2238 " <input type=\"text\" name=\"dayphone3\">"
2240 " <input type=\"text\" name=\"dayphone4\">"
2241 " <input type=\"text\" name=\"dummy\">"
2242 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
2244 labels, names, values);
2247 TEST_F(FormAutofillTest, LabelsInferredFromDivTable) {
2248 ExpectJohnSmithLabels(
2249 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2250 "<DIV>First name:<BR>"
2252 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
2255 "<DIV>Last name:<BR>"
2257 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
2262 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
2265 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
2269 TEST_F(FormAutofillTest, LabelsInferredFromDivSiblingTable) {
2270 ExpectJohnSmithLabels(
2271 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2272 "<DIV>First name:</DIV>"
2275 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
2278 "<DIV>Last name:</DIV>"
2281 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
2287 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
2290 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
2294 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionListRatherThanDivTable) {
2295 ExpectJohnSmithLabels(
2296 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2297 "<DIV>This is not a label.<BR>"
2306 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
2316 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2326 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
2331 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2338 TEST_F(FormAutofillTest, FillFormMaxLength) {
2339 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2340 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>"
2341 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>"
2342 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>"
2343 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2346 WebFrame* web_frame = GetMainFrame();
2347 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2349 FormCache form_cache;
2350 std::vector<FormData> forms;
2351 form_cache.ExtractNewForms(*web_frame, &forms);
2352 ASSERT_EQ(1U, forms.size());
2354 // Get the input element we want to find.
2355 WebElement element = web_frame->document().getElementById("firstname");
2356 WebInputElement input_element = element.to<WebInputElement>();
2358 // Find the form that contains the input element.
2360 FormFieldData field;
2361 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2364 autofill::REQUIRE_NONE));
2365 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2366 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2367 EXPECT_EQ(GURL("http://buh.com"), form.action);
2369 const std::vector<FormFieldData>& fields = form.fields;
2370 ASSERT_EQ(3U, fields.size());
2372 FormFieldData expected;
2373 expected.form_control_type = "text";
2375 expected.name = ASCIIToUTF16("firstname");
2376 expected.max_length = 5;
2377 expected.is_autofilled = false;
2378 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2380 expected.name = ASCIIToUTF16("lastname");
2381 expected.max_length = 7;
2382 expected.is_autofilled = false;
2383 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2385 expected.name = ASCIIToUTF16("email");
2386 expected.max_length = 9;
2387 expected.is_autofilled = false;
2388 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2391 form.fields[0].value = ASCIIToUTF16("Brother");
2392 form.fields[1].value = ASCIIToUTF16("Jonathan");
2393 form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
2394 form.fields[0].is_autofilled = true;
2395 form.fields[1].is_autofilled = true;
2396 form.fields[2].is_autofilled = true;
2397 FillForm(form, input_element);
2399 // Find the newly-filled form that contains the input element.
2401 FormFieldData field2;
2402 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2405 autofill::REQUIRE_NONE));
2407 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2408 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2409 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2411 const std::vector<FormFieldData>& fields2 = form2.fields;
2412 ASSERT_EQ(3U, fields2.size());
2414 expected.form_control_type = "text";
2416 expected.name = ASCIIToUTF16("firstname");
2417 expected.value = ASCIIToUTF16("Broth");
2418 expected.max_length = 5;
2419 expected.is_autofilled = true;
2420 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
2422 expected.name = ASCIIToUTF16("lastname");
2423 expected.value = ASCIIToUTF16("Jonatha");
2424 expected.max_length = 7;
2425 expected.is_autofilled = true;
2426 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
2428 expected.name = ASCIIToUTF16("email");
2429 expected.value = ASCIIToUTF16("brotherj@");
2430 expected.max_length = 9;
2431 expected.is_autofilled = true;
2432 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
2435 // This test uses negative values of the maxlength attribute for input elements.
2436 // In this case, the maxlength of the input elements is set to the default
2437 // maxlength (defined in WebKit.)
2438 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
2439 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2440 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>"
2441 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
2442 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>"
2443 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2446 WebFrame* web_frame = GetMainFrame();
2447 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2449 FormCache form_cache;
2450 std::vector<FormData> forms;
2451 form_cache.ExtractNewForms(*web_frame, &forms);
2452 ASSERT_EQ(1U, forms.size());
2454 // Get the input element we want to find.
2455 WebElement element = web_frame->document().getElementById("firstname");
2456 WebInputElement input_element = element.to<WebInputElement>();
2458 // Find the form that contains the input element.
2460 FormFieldData field;
2461 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2464 autofill::REQUIRE_NONE));
2465 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2466 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2467 EXPECT_EQ(GURL("http://buh.com"), form.action);
2469 const std::vector<FormFieldData>& fields = form.fields;
2470 ASSERT_EQ(3U, fields.size());
2472 FormFieldData expected;
2473 expected.form_control_type = "text";
2474 expected.max_length = WebInputElement::defaultMaxLength();
2476 expected.name = ASCIIToUTF16("firstname");
2477 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2479 expected.name = ASCIIToUTF16("lastname");
2480 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2482 expected.name = ASCIIToUTF16("email");
2483 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2486 form.fields[0].value = ASCIIToUTF16("Brother");
2487 form.fields[1].value = ASCIIToUTF16("Jonathan");
2488 form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
2489 FillForm(form, input_element);
2491 // Find the newly-filled form that contains the input element.
2493 FormFieldData field2;
2494 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2497 autofill::REQUIRE_NONE));
2499 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2500 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2501 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2503 const std::vector<FormFieldData>& fields2 = form2.fields;
2504 ASSERT_EQ(3U, fields2.size());
2506 expected.name = ASCIIToUTF16("firstname");
2507 expected.value = ASCIIToUTF16("Brother");
2508 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2510 expected.name = ASCIIToUTF16("lastname");
2511 expected.value = ASCIIToUTF16("Jonathan");
2512 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2514 expected.name = ASCIIToUTF16("email");
2515 expected.value = ASCIIToUTF16("brotherj@example.com");
2516 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2519 TEST_F(FormAutofillTest, FillFormEmptyName) {
2520 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2521 " <INPUT type=\"text\" id=\"firstname\"/>"
2522 " <INPUT type=\"text\" id=\"lastname\"/>"
2523 " <INPUT type=\"text\" id=\"email\"/>"
2524 " <INPUT type=\"submit\" value=\"Send\"/>"
2527 WebFrame* web_frame = GetMainFrame();
2528 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2530 FormCache form_cache;
2531 std::vector<FormData> forms;
2532 form_cache.ExtractNewForms(*web_frame, &forms);
2533 ASSERT_EQ(1U, forms.size());
2535 // Get the input element we want to find.
2536 WebElement element = web_frame->document().getElementById("firstname");
2537 WebInputElement input_element = element.to<WebInputElement>();
2539 // Find the form that contains the input element.
2541 FormFieldData field;
2542 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2545 autofill::REQUIRE_NONE));
2546 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2547 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2548 EXPECT_EQ(GURL("http://buh.com"), form.action);
2550 const std::vector<FormFieldData>& fields = form.fields;
2551 ASSERT_EQ(3U, fields.size());
2553 FormFieldData expected;
2554 expected.form_control_type = "text";
2555 expected.max_length = WebInputElement::defaultMaxLength();
2557 expected.name = ASCIIToUTF16("firstname");
2558 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2560 expected.name = ASCIIToUTF16("lastname");
2561 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2563 expected.name = ASCIIToUTF16("email");
2564 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2567 form.fields[0].value = ASCIIToUTF16("Wyatt");
2568 form.fields[1].value = ASCIIToUTF16("Earp");
2569 form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
2570 FillForm(form, input_element);
2572 // Find the newly-filled form that contains the input element.
2574 FormFieldData field2;
2575 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2578 autofill::REQUIRE_NONE));
2580 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2581 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2582 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2584 const std::vector<FormFieldData>& fields2 = form2.fields;
2585 ASSERT_EQ(3U, fields2.size());
2587 expected.form_control_type = "text";
2588 expected.max_length = WebInputElement::defaultMaxLength();
2590 expected.name = ASCIIToUTF16("firstname");
2591 expected.value = ASCIIToUTF16("Wyatt");
2592 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2594 expected.name = ASCIIToUTF16("lastname");
2595 expected.value = ASCIIToUTF16("Earp");
2596 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2598 expected.name = ASCIIToUTF16("email");
2599 expected.value = ASCIIToUTF16("wyatt@example.com");
2600 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2603 TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
2604 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">"
2605 " <INPUT type=\"text\" id=\"firstname\"/>"
2606 " <INPUT type=\"text\" id=\"middlename\"/>"
2607 " <INPUT type=\"text\" id=\"lastname\"/>"
2608 " <INPUT type=\"submit\" value=\"Send\"/>"
2610 "<FORM action=\"http://abc.com\" method=\"post\">"
2611 " <INPUT type=\"text\" id=\"apple\"/>"
2612 " <INPUT type=\"text\" id=\"banana\"/>"
2613 " <INPUT type=\"text\" id=\"cantelope\"/>"
2614 " <INPUT type=\"submit\" value=\"Send\"/>"
2617 WebFrame* web_frame = GetMainFrame();
2618 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2620 FormCache form_cache;
2621 std::vector<FormData> forms;
2622 form_cache.ExtractNewForms(*web_frame, &forms);
2623 ASSERT_EQ(2U, forms.size());
2625 // Get the input element we want to find.
2626 WebElement element = web_frame->document().getElementById("apple");
2627 WebInputElement input_element = element.to<WebInputElement>();
2629 // Find the form that contains the input element.
2631 FormFieldData field;
2632 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2635 autofill::REQUIRE_NONE));
2636 EXPECT_EQ(base::string16(), form.name);
2637 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2638 EXPECT_EQ(GURL("http://abc.com"), form.action);
2640 const std::vector<FormFieldData>& fields = form.fields;
2641 ASSERT_EQ(3U, fields.size());
2643 FormFieldData expected;
2644 expected.form_control_type = "text";
2645 expected.max_length = WebInputElement::defaultMaxLength();
2647 expected.name = ASCIIToUTF16("apple");
2648 expected.is_autofilled = false;
2649 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2651 expected.name = ASCIIToUTF16("banana");
2652 expected.is_autofilled = false;
2653 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2655 expected.name = ASCIIToUTF16("cantelope");
2656 expected.is_autofilled = false;
2657 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2660 form.fields[0].value = ASCIIToUTF16("Red");
2661 form.fields[1].value = ASCIIToUTF16("Yellow");
2662 form.fields[2].value = ASCIIToUTF16("Also Yellow");
2663 form.fields[0].is_autofilled = true;
2664 form.fields[1].is_autofilled = true;
2665 form.fields[2].is_autofilled = true;
2666 FillForm(form, input_element);
2668 // Find the newly-filled form that contains the input element.
2670 FormFieldData field2;
2671 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2674 autofill::REQUIRE_NONE));
2676 EXPECT_EQ(base::string16(), form2.name);
2677 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2678 EXPECT_EQ(GURL("http://abc.com"), form2.action);
2680 const std::vector<FormFieldData>& fields2 = form2.fields;
2681 ASSERT_EQ(3U, fields2.size());
2683 expected.name = ASCIIToUTF16("apple");
2684 expected.value = ASCIIToUTF16("Red");
2685 expected.is_autofilled = true;
2686 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
2688 expected.name = ASCIIToUTF16("banana");
2689 expected.value = ASCIIToUTF16("Yellow");
2690 expected.is_autofilled = true;
2691 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
2693 expected.name = ASCIIToUTF16("cantelope");
2694 expected.value = ASCIIToUTF16("Also Yellow");
2695 expected.is_autofilled = true;
2696 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
2699 TEST_F(FormAutofillTest, ThreePartPhone) {
2700 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2702 " <input type=\"text\" name=\"dayphone1\">"
2704 " <input type=\"text\" name=\"dayphone2\">"
2706 " <input type=\"text\" name=\"dayphone3\">"
2708 " <input type=\"text\" name=\"dayphone4\">"
2709 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
2713 WebFrame* frame = GetMainFrame();
2714 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
2716 WebVector<WebFormElement> forms;
2717 frame->document().forms(forms);
2718 ASSERT_EQ(1U, forms.size());
2721 EXPECT_TRUE(WebFormElementToFormData(forms[0],
2722 WebFormControlElement(),
2723 autofill::REQUIRE_NONE,
2724 autofill::EXTRACT_VALUE,
2727 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2728 EXPECT_EQ(GURL(frame->document().url()), form.origin);
2729 EXPECT_EQ(GURL("http://cnn.com"), form.action);
2731 const std::vector<FormFieldData>& fields = form.fields;
2732 ASSERT_EQ(4U, fields.size());
2734 FormFieldData expected;
2735 expected.form_control_type = "text";
2736 expected.max_length = WebInputElement::defaultMaxLength();
2738 expected.label = ASCIIToUTF16("Phone:");
2739 expected.name = ASCIIToUTF16("dayphone1");
2740 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2742 expected.label = ASCIIToUTF16("-");
2743 expected.name = ASCIIToUTF16("dayphone2");
2744 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2746 expected.label = ASCIIToUTF16("-");
2747 expected.name = ASCIIToUTF16("dayphone3");
2748 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2750 expected.label = ASCIIToUTF16("ext.:");
2751 expected.name = ASCIIToUTF16("dayphone4");
2752 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
2756 TEST_F(FormAutofillTest, MaxLengthFields) {
2757 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2759 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">"
2761 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">"
2763 " <input type=\"text\" maxlength=\"4\" size=\"5\""
2764 " name=\"dayphone3\">"
2766 " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">"
2767 " <input type=\"text\" name=\"default1\">"
2768 " <input type=\"text\" maxlength=\"-1\" name=\"invalid1\">"
2769 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
2772 WebFrame* frame = GetMainFrame();
2773 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
2775 WebVector<WebFormElement> forms;
2776 frame->document().forms(forms);
2777 ASSERT_EQ(1U, forms.size());
2780 EXPECT_TRUE(WebFormElementToFormData(forms[0],
2781 WebFormControlElement(),
2782 autofill::REQUIRE_NONE,
2783 autofill::EXTRACT_VALUE,
2786 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2787 EXPECT_EQ(GURL(frame->document().url()), form.origin);
2788 EXPECT_EQ(GURL("http://cnn.com"), form.action);
2790 const std::vector<FormFieldData>& fields = form.fields;
2791 ASSERT_EQ(6U, fields.size());
2793 FormFieldData expected;
2794 expected.form_control_type = "text";
2796 expected.label = ASCIIToUTF16("Phone:");
2797 expected.name = ASCIIToUTF16("dayphone1");
2798 expected.max_length = 3;
2799 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2801 expected.label = ASCIIToUTF16("-");
2802 expected.name = ASCIIToUTF16("dayphone2");
2803 expected.max_length = 3;
2804 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2806 expected.label = ASCIIToUTF16("-");
2807 expected.name = ASCIIToUTF16("dayphone3");
2808 expected.max_length = 4;
2809 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2811 expected.label = ASCIIToUTF16("ext.:");
2812 expected.name = ASCIIToUTF16("dayphone4");
2813 expected.max_length = 5;
2814 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
2816 // When unspecified |size|, default is returned.
2817 expected.label = base::string16();
2818 expected.name = ASCIIToUTF16("default1");
2819 expected.max_length = WebInputElement::defaultMaxLength();
2820 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]);
2822 // When invalid |size|, default is returned.
2823 expected.label = base::string16();
2824 expected.name = ASCIIToUTF16("invalid1");
2825 expected.max_length = WebInputElement::defaultMaxLength();
2826 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]);
2829 // This test re-creates the experience of typing in a field then selecting a
2830 // profile from the Autofill suggestions popup. The field that is being typed
2831 // into should be filled even though it's not technically empty.
2832 TEST_F(FormAutofillTest, FillFormNonEmptyField) {
2833 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2834 " <INPUT type=\"text\" id=\"firstname\"/>"
2835 " <INPUT type=\"text\" id=\"lastname\"/>"
2836 " <INPUT type=\"text\" id=\"email\"/>"
2837 " <INPUT type=\"submit\" value=\"Send\"/>"
2840 WebFrame* web_frame = GetMainFrame();
2841 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2843 FormCache form_cache;
2844 std::vector<FormData> forms;
2845 form_cache.ExtractNewForms(*web_frame, &forms);
2846 ASSERT_EQ(1U, forms.size());
2848 // Get the input element we want to find.
2849 WebElement element = web_frame->document().getElementById("firstname");
2850 WebInputElement input_element = element.to<WebInputElement>();
2852 // Simulate typing by modifying the field value.
2853 input_element.setValue(ASCIIToUTF16("Wy"));
2855 // Find the form that contains the input element.
2857 FormFieldData field;
2858 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2861 autofill::REQUIRE_NONE));
2862 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2863 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2864 EXPECT_EQ(GURL("http://buh.com"), form.action);
2866 const std::vector<FormFieldData>& fields = form.fields;
2867 ASSERT_EQ(3U, fields.size());
2869 FormFieldData expected;
2870 expected.form_control_type = "text";
2871 expected.max_length = WebInputElement::defaultMaxLength();
2873 expected.name = ASCIIToUTF16("firstname");
2874 expected.value = ASCIIToUTF16("Wy");
2875 expected.is_autofilled = false;
2876 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
2878 expected.name = ASCIIToUTF16("lastname");
2879 expected.value = base::string16();
2880 expected.is_autofilled = false;
2881 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2883 expected.name = ASCIIToUTF16("email");
2884 expected.value = base::string16();
2885 expected.is_autofilled = false;
2886 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2888 // Preview the form and verify that the cursor position has been updated.
2889 form.fields[0].value = ASCIIToUTF16("Wyatt");
2890 form.fields[1].value = ASCIIToUTF16("Earp");
2891 form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
2892 form.fields[0].is_autofilled = true;
2893 form.fields[1].is_autofilled = true;
2894 form.fields[2].is_autofilled = true;
2895 PreviewForm(form, input_element);
2896 EXPECT_EQ(2, input_element.selectionStart());
2897 EXPECT_EQ(5, input_element.selectionEnd());
2900 FillForm(form, input_element);
2902 // Find the newly-filled form that contains the input element.
2904 FormFieldData field2;
2905 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2908 autofill::REQUIRE_NONE));
2910 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2911 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2912 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2914 const std::vector<FormFieldData>& fields2 = form2.fields;
2915 ASSERT_EQ(3U, fields2.size());
2917 expected.name = ASCIIToUTF16("firstname");
2918 expected.value = ASCIIToUTF16("Wyatt");
2919 expected.is_autofilled = true;
2920 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
2922 expected.name = ASCIIToUTF16("lastname");
2923 expected.value = ASCIIToUTF16("Earp");
2924 expected.is_autofilled = true;
2925 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
2927 expected.name = ASCIIToUTF16("email");
2928 expected.value = ASCIIToUTF16("wyatt@example.com");
2929 expected.is_autofilled = true;
2930 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
2932 // Verify that the cursor position has been updated.
2933 EXPECT_EQ(5, input_element.selectionStart());
2934 EXPECT_EQ(5, input_element.selectionEnd());
2937 TEST_F(FormAutofillTest, ClearFormWithNode) {
2939 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2940 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2941 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
2942 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noAC\" value=\"one\"/>"
2943 " <INPUT type=\"text\" id=\"notenabled\" disabled=\"disabled\">"
2944 " <INPUT type=\"month\" id=\"month\" value=\"2012-11\">"
2945 " <INPUT type=\"month\" id=\"month-disabled\" value=\"2012-11\""
2946 " disabled=\"disabled\">"
2947 " <TEXTAREA id=\"textarea\">Apple.</TEXTAREA>"
2948 " <TEXTAREA id=\"textarea-disabled\" disabled=\"disabled\">"
2951 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>"
2952 " <INPUT type=\"submit\" value=\"Send\"/>"
2955 WebFrame* web_frame = GetMainFrame();
2956 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2958 FormCache form_cache;
2959 std::vector<FormData> forms;
2960 form_cache.ExtractNewForms(*web_frame, &forms);
2961 ASSERT_EQ(1U, forms.size());
2963 // Set the auto-filled attribute.
2964 WebInputElement firstname =
2965 web_frame->document().getElementById("firstname").to<WebInputElement>();
2966 firstname.setAutofilled(true);
2967 WebInputElement lastname =
2968 web_frame->document().getElementById("lastname").to<WebInputElement>();
2969 lastname.setAutofilled(true);
2970 WebInputElement month =
2971 web_frame->document().getElementById("month").to<WebInputElement>();
2972 month.setAutofilled(true);
2973 WebInputElement textarea =
2974 web_frame->document().getElementById("textarea").to<WebInputElement>();
2975 textarea.setAutofilled(true);
2977 // Set the value of the disabled text input element.
2978 WebInputElement notenabled =
2979 web_frame->document().getElementById("notenabled").to<WebInputElement>();
2980 notenabled.setValue(WebString::fromUTF8("no clear"));
2983 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
2985 // Verify that the auto-filled attribute has been turned off.
2986 EXPECT_FALSE(firstname.isAutofilled());
2988 // Verify the form is cleared.
2990 FormFieldData field2;
2991 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname,
2994 autofill::REQUIRE_NONE));
2995 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2996 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2997 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2999 const std::vector<FormFieldData>& fields2 = form2.fields;
3000 ASSERT_EQ(9U, fields2.size());
3002 FormFieldData expected;
3003 expected.form_control_type = "text";
3004 expected.max_length = WebInputElement::defaultMaxLength();
3006 expected.name = ASCIIToUTF16("firstname");
3007 expected.value = base::string16();
3008 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
3010 expected.name = ASCIIToUTF16("lastname");
3011 expected.value = base::string16();
3012 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
3014 expected.name = ASCIIToUTF16("noAC");
3015 expected.value = ASCIIToUTF16("one");
3016 expected.autocomplete_attribute = "off";
3017 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
3018 expected.autocomplete_attribute = std::string(); // reset
3020 expected.name = ASCIIToUTF16("notenabled");
3021 expected.value = ASCIIToUTF16("no clear");
3022 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]);
3024 expected.form_control_type = "month";
3025 expected.max_length = 0;
3026 expected.name = ASCIIToUTF16("month");
3027 expected.value = base::string16();
3028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]);
3030 expected.name = ASCIIToUTF16("month-disabled");
3031 expected.value = ASCIIToUTF16("2012-11");
3032 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]);
3034 expected.form_control_type = "textarea";
3035 expected.name = ASCIIToUTF16("textarea");
3036 expected.value = base::string16();
3037 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[6]);
3039 expected.name = ASCIIToUTF16("textarea-disabled");
3040 expected.value = ASCIIToUTF16(" Banana! ");
3041 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]);
3043 expected.name = ASCIIToUTF16("textarea-noAC");
3044 expected.value = ASCIIToUTF16("Carrot?");
3045 expected.autocomplete_attribute = "off";
3046 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]);
3047 expected.autocomplete_attribute = std::string(); // reset
3049 // Verify that the cursor position has been updated.
3050 EXPECT_EQ(0, firstname.selectionStart());
3051 EXPECT_EQ(0, firstname.selectionEnd());
3054 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) {
3056 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3057 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
3058 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
3059 " <SELECT id=\"state\" name=\"state\">"
3060 " <OPTION selected>?</OPTION>"
3061 " <OPTION>AA</OPTION>"
3062 " <OPTION>AE</OPTION>"
3063 " <OPTION>AK</OPTION>"
3065 " <INPUT type=\"submit\" value=\"Send\"/>"
3068 WebFrame* web_frame = GetMainFrame();
3069 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3071 FormCache form_cache;
3072 std::vector<FormData> forms;
3073 form_cache.ExtractNewForms(*web_frame, &forms);
3074 ASSERT_EQ(1U, forms.size());
3076 // Set the auto-filled attribute.
3077 WebInputElement firstname =
3078 web_frame->document().getElementById("firstname").to<WebInputElement>();
3079 firstname.setAutofilled(true);
3080 WebInputElement lastname =
3081 web_frame->document().getElementById("lastname").to<WebInputElement>();
3082 lastname.setAutofilled(true);
3083 WebInputElement state =
3084 web_frame->document().getElementById("state").to<WebInputElement>();
3085 state.setAutofilled(true);
3087 // Set the value of the select-one.
3088 WebSelectElement select_element =
3089 web_frame->document().getElementById("state").to<WebSelectElement>();
3090 select_element.setValue(WebString::fromUTF8("AK"));
3093 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
3095 // Verify that the auto-filled attribute has been turned off.
3096 EXPECT_FALSE(firstname.isAutofilled());
3098 // Verify the form is cleared.
3100 FormFieldData field2;
3101 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname,
3104 autofill::REQUIRE_NONE));
3105 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
3106 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
3107 EXPECT_EQ(GURL("http://buh.com"), form2.action);
3109 const std::vector<FormFieldData>& fields2 = form2.fields;
3110 ASSERT_EQ(3U, fields2.size());
3112 FormFieldData expected;
3114 expected.name = ASCIIToUTF16("firstname");
3115 expected.value = base::string16();
3116 expected.form_control_type = "text";
3117 expected.max_length = WebInputElement::defaultMaxLength();
3118 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
3120 expected.name = ASCIIToUTF16("lastname");
3121 expected.value = base::string16();
3122 expected.form_control_type = "text";
3123 expected.max_length = WebInputElement::defaultMaxLength();
3124 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
3126 expected.name = ASCIIToUTF16("state");
3127 expected.value = ASCIIToUTF16("?");
3128 expected.form_control_type = "select-one";
3129 expected.max_length = 0;
3130 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
3132 // Verify that the cursor position has been updated.
3133 EXPECT_EQ(0, firstname.selectionStart());
3134 EXPECT_EQ(0, firstname.selectionEnd());
3137 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
3138 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3139 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
3140 " <INPUT type=\"text\" id=\"lastname\"/>"
3141 " <INPUT type=\"text\" id=\"email\"/>"
3142 " <INPUT type=\"email\" id=\"email2\"/>"
3143 " <INPUT type=\"tel\" id=\"phone\"/>"
3144 " <INPUT type=\"submit\" value=\"Send\"/>"
3147 WebFrame* web_frame = GetMainFrame();
3148 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3150 FormCache form_cache;
3151 std::vector<FormData> forms;
3152 form_cache.ExtractNewForms(*web_frame, &forms);
3153 ASSERT_EQ(1U, forms.size());
3155 // Set the auto-filled attribute.
3156 WebInputElement firstname =
3157 web_frame->document().getElementById("firstname").to<WebInputElement>();
3158 firstname.setAutofilled(true);
3159 WebInputElement lastname =
3160 web_frame->document().getElementById("lastname").to<WebInputElement>();
3161 lastname.setAutofilled(true);
3162 WebInputElement email =
3163 web_frame->document().getElementById("email").to<WebInputElement>();
3164 email.setAutofilled(true);
3165 WebInputElement email2 =
3166 web_frame->document().getElementById("email2").to<WebInputElement>();
3167 email2.setAutofilled(true);
3168 WebInputElement phone =
3169 web_frame->document().getElementById("phone").to<WebInputElement>();
3170 phone.setAutofilled(true);
3172 // Set the suggested values on two of the elements.
3173 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
3174 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3175 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3176 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
3178 // Clear the previewed fields.
3179 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false));
3181 // Fields with empty suggestions suggestions are not modified.
3182 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
3183 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
3184 EXPECT_TRUE(firstname.isAutofilled());
3186 // Verify the previewed fields are cleared.
3187 EXPECT_TRUE(lastname.value().isEmpty());
3188 EXPECT_TRUE(lastname.suggestedValue().isEmpty());
3189 EXPECT_FALSE(lastname.isAutofilled());
3190 EXPECT_TRUE(email.value().isEmpty());
3191 EXPECT_TRUE(email.suggestedValue().isEmpty());
3192 EXPECT_FALSE(email.isAutofilled());
3193 EXPECT_TRUE(email2.value().isEmpty());
3194 EXPECT_TRUE(email2.suggestedValue().isEmpty());
3195 EXPECT_FALSE(email2.isAutofilled());
3196 EXPECT_TRUE(phone.value().isEmpty());
3197 EXPECT_TRUE(phone.suggestedValue().isEmpty());
3198 EXPECT_FALSE(phone.isAutofilled());
3200 // Verify that the cursor position has been updated.
3201 EXPECT_EQ(0, lastname.selectionStart());
3202 EXPECT_EQ(0, lastname.selectionEnd());
3205 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
3206 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3207 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
3208 " <INPUT type=\"text\" id=\"lastname\"/>"
3209 " <INPUT type=\"text\" id=\"email\"/>"
3210 " <INPUT type=\"email\" id=\"email2\"/>"
3211 " <INPUT type=\"tel\" id=\"phone\"/>"
3212 " <INPUT type=\"submit\" value=\"Send\"/>"
3215 WebFrame* web_frame = GetMainFrame();
3216 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3218 FormCache form_cache;
3219 std::vector<FormData> forms;
3220 form_cache.ExtractNewForms(*web_frame, &forms);
3221 ASSERT_EQ(1U, forms.size());
3223 // Set the auto-filled attribute.
3224 WebInputElement firstname =
3225 web_frame->document().getElementById("firstname").to<WebInputElement>();
3226 firstname.setAutofilled(true);
3227 WebInputElement lastname =
3228 web_frame->document().getElementById("lastname").to<WebInputElement>();
3229 lastname.setAutofilled(true);
3230 WebInputElement email =
3231 web_frame->document().getElementById("email").to<WebInputElement>();
3232 email.setAutofilled(true);
3233 WebInputElement email2 =
3234 web_frame->document().getElementById("email2").to<WebInputElement>();
3235 email2.setAutofilled(true);
3236 WebInputElement phone =
3237 web_frame->document().getElementById("phone").to<WebInputElement>();
3238 phone.setAutofilled(true);
3241 // Set the suggested values on all of the elements.
3242 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt"));
3243 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
3244 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3245 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3246 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
3248 // Clear the previewed fields.
3249 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false));
3251 // Fields with non-empty values are restored.
3252 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value());
3253 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
3254 EXPECT_FALSE(firstname.isAutofilled());
3255 EXPECT_EQ(1, firstname.selectionStart());
3256 EXPECT_EQ(1, firstname.selectionEnd());
3258 // Verify the previewed fields are cleared.
3259 EXPECT_TRUE(lastname.value().isEmpty());
3260 EXPECT_TRUE(lastname.suggestedValue().isEmpty());
3261 EXPECT_FALSE(lastname.isAutofilled());
3262 EXPECT_TRUE(email.value().isEmpty());
3263 EXPECT_TRUE(email.suggestedValue().isEmpty());
3264 EXPECT_FALSE(email.isAutofilled());
3265 EXPECT_TRUE(email2.value().isEmpty());
3266 EXPECT_TRUE(email2.suggestedValue().isEmpty());
3267 EXPECT_FALSE(email2.isAutofilled());
3268 EXPECT_TRUE(phone.value().isEmpty());
3269 EXPECT_TRUE(phone.suggestedValue().isEmpty());
3270 EXPECT_FALSE(phone.isAutofilled());
3273 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
3274 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3275 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
3276 " <INPUT type=\"text\" id=\"lastname\"/>"
3277 " <INPUT type=\"text\" id=\"email\"/>"
3278 " <INPUT type=\"email\" id=\"email2\"/>"
3279 " <INPUT type=\"tel\" id=\"phone\"/>"
3280 " <INPUT type=\"submit\" value=\"Send\"/>"
3283 WebFrame* web_frame = GetMainFrame();
3284 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3286 FormCache form_cache;
3287 std::vector<FormData> forms;
3288 form_cache.ExtractNewForms(*web_frame, &forms);
3289 ASSERT_EQ(1U, forms.size());
3291 // Set the auto-filled attribute.
3292 WebInputElement firstname =
3293 web_frame->document().getElementById("firstname").to<WebInputElement>();
3294 firstname.setAutofilled(true);
3295 WebInputElement lastname =
3296 web_frame->document().getElementById("lastname").to<WebInputElement>();
3297 lastname.setAutofilled(true);
3298 WebInputElement email =
3299 web_frame->document().getElementById("email").to<WebInputElement>();
3300 email.setAutofilled(true);
3301 WebInputElement email2 =
3302 web_frame->document().getElementById("email2").to<WebInputElement>();
3303 email2.setAutofilled(true);
3304 WebInputElement phone =
3305 web_frame->document().getElementById("phone").to<WebInputElement>();
3306 phone.setAutofilled(true);
3308 // Set the suggested values on all of the elements.
3309 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt"));
3310 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
3311 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3312 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3313 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
3315 // Clear the previewed fields.
3316 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true));
3318 // Fields with non-empty values are restored.
3319 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value());
3320 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
3321 EXPECT_TRUE(firstname.isAutofilled());
3322 EXPECT_EQ(1, firstname.selectionStart());
3323 EXPECT_EQ(1, firstname.selectionEnd());
3325 // Verify the previewed fields are cleared.
3326 EXPECT_TRUE(lastname.value().isEmpty());
3327 EXPECT_TRUE(lastname.suggestedValue().isEmpty());
3328 EXPECT_FALSE(lastname.isAutofilled());
3329 EXPECT_TRUE(email.value().isEmpty());
3330 EXPECT_TRUE(email.suggestedValue().isEmpty());
3331 EXPECT_FALSE(email.isAutofilled());
3332 EXPECT_TRUE(email2.value().isEmpty());
3333 EXPECT_TRUE(email2.suggestedValue().isEmpty());
3334 EXPECT_FALSE(email2.isAutofilled());
3335 EXPECT_TRUE(phone.value().isEmpty());
3336 EXPECT_TRUE(phone.suggestedValue().isEmpty());
3337 EXPECT_FALSE(phone.isAutofilled());
3340 // Autofill's "Clear Form" should clear only autofilled fields
3341 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) {
3344 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3345 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
3346 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
3347 " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>"
3348 " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>"
3349 " <INPUT type=\"submit\" value=\"Send\"/>"
3352 WebFrame* web_frame = GetMainFrame();
3353 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3355 FormCache form_cache;
3356 std::vector<FormData> forms;
3357 form_cache.ExtractNewForms(*web_frame, &forms);
3358 ASSERT_EQ(1U, forms.size());
3360 // Set the autofilled attribute.
3361 WebInputElement firstname =
3362 web_frame->document().getElementById("firstname").to<WebInputElement>();
3363 firstname.setAutofilled(false);
3364 WebInputElement lastname =
3365 web_frame->document().getElementById("lastname").to<WebInputElement>();
3366 lastname.setAutofilled(true);
3367 WebInputElement email =
3368 web_frame->document().getElementById("email").to<WebInputElement>();
3369 email.setAutofilled(true);
3370 WebInputElement phone =
3371 web_frame->document().getElementById("phone").to<WebInputElement>();
3372 phone.setAutofilled(true);
3374 // Clear the fields.
3375 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
3377 // Verify only autofilled fields are cleared.
3378 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
3379 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
3380 EXPECT_FALSE(firstname.isAutofilled());
3381 EXPECT_TRUE(lastname.value().isEmpty());
3382 EXPECT_TRUE(lastname.suggestedValue().isEmpty());
3383 EXPECT_FALSE(lastname.isAutofilled());
3384 EXPECT_TRUE(email.value().isEmpty());
3385 EXPECT_TRUE(email.suggestedValue().isEmpty());
3386 EXPECT_FALSE(email.isAutofilled());
3387 EXPECT_TRUE(phone.value().isEmpty());
3388 EXPECT_TRUE(phone.suggestedValue().isEmpty());
3389 EXPECT_FALSE(phone.isAutofilled());
3392 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) {
3393 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
3394 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
3395 " <INPUT type=\"text\" id=\"lastname\"/>"
3396 " <INPUT type=\"text\" id=\"email\"/>"
3397 " <INPUT type=\"email\" id=\"email2\"/>"
3398 " <INPUT type=\"tel\" id=\"phone\"/>"
3399 " <INPUT type=\"submit\" value=\"Send\"/>"
3402 WebFrame* web_frame = GetMainFrame();
3403 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3405 FormCache form_cache;
3406 std::vector<FormData> forms;
3407 form_cache.ExtractNewForms(*web_frame, &forms);
3408 ASSERT_EQ(1U, forms.size());
3410 WebInputElement firstname =
3411 web_frame->document().getElementById("firstname").to<WebInputElement>();
3413 // Auto-filled attribute not set yet.
3414 EXPECT_FALSE(FormWithElementIsAutofilled(firstname));
3416 // Set the auto-filled attribute.
3417 firstname.setAutofilled(true);
3419 EXPECT_TRUE(FormWithElementIsAutofilled(firstname));
3422 // If we have multiple labels per id, the labels concatenated into label string.
3423 TEST_F(FormAutofillTest, MultipleLabelsPerElement) {
3424 std::vector<base::string16> labels, names, values;
3426 labels.push_back(ASCIIToUTF16("First Name:"));
3427 names.push_back(ASCIIToUTF16("firstname"));
3428 values.push_back(ASCIIToUTF16("John"));
3430 labels.push_back(ASCIIToUTF16("Last Name:"));
3431 names.push_back(ASCIIToUTF16("lastname"));
3432 values.push_back(ASCIIToUTF16("Smith"));
3434 labels.push_back(ASCIIToUTF16("Email: xxx@yyy.com"));
3435 names.push_back(ASCIIToUTF16("email"));
3436 values.push_back(ASCIIToUTF16("john@example.com"));
3439 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
3440 " <LABEL for=\"firstname\"> First Name: </LABEL>"
3441 " <LABEL for=\"firstname\"></LABEL>"
3442 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
3443 " <LABEL for=\"lastname\"></LABEL>"
3444 " <LABEL for=\"lastname\"> Last Name: </LABEL>"
3445 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
3446 " <LABEL for=\"email\"> Email: </LABEL>"
3447 " <LABEL for=\"email\"> xxx@yyy.com </LABEL>"
3448 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
3449 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
3451 labels, names, values);
3454 TEST_F(FormAutofillTest, ClickElement) {
3455 LoadHTML("<BUTTON id=\"link\">Button</BUTTON>"
3456 "<BUTTON name=\"button\">Button</BUTTON>");
3457 WebFrame* frame = GetMainFrame();
3458 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
3460 // Successful retrieval by id.
3461 autofill::WebElementDescriptor clicker;
3462 clicker.retrieval_method = autofill::WebElementDescriptor::ID;
3463 clicker.descriptor = "link";
3464 EXPECT_TRUE(ClickElement(frame->document(), clicker));
3466 // Successful retrieval by css selector.
3467 clicker.retrieval_method = autofill::WebElementDescriptor::CSS_SELECTOR;
3468 clicker.descriptor = "button[name=\"button\"]";
3469 EXPECT_TRUE(ClickElement(frame->document(), clicker));
3471 // Unsuccessful retrieval due to invalid CSS selector.
3472 clicker.descriptor = "^*&";
3473 EXPECT_FALSE(ClickElement(frame->document(), clicker));
3475 // Unsuccessful retrieval because element does not exist.
3476 clicker.descriptor = "#junk";
3477 EXPECT_FALSE(ClickElement(frame->document(), clicker));
3480 TEST_F(FormAutofillTest, SelectOneAsText) {
3481 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
3482 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
3483 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
3484 " <SELECT id=\"country\">"
3485 " <OPTION value=\"AF\">Afghanistan</OPTION>"
3486 " <OPTION value=\"AL\">Albania</OPTION>"
3487 " <OPTION value=\"DZ\">Algeria</OPTION>"
3489 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
3492 WebFrame* frame = GetMainFrame();
3493 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
3495 // Set the value of the select-one.
3496 WebSelectElement select_element =
3497 frame->document().getElementById("country").to<WebSelectElement>();
3498 select_element.setValue(WebString::fromUTF8("AL"));
3500 WebVector<WebFormElement> forms;
3501 frame->document().forms(forms);
3502 ASSERT_EQ(1U, forms.size());
3506 // Extract the country select-one value as text.
3507 EXPECT_TRUE(WebFormElementToFormData(
3508 forms[0], WebFormControlElement(), autofill::REQUIRE_NONE,
3509 static_cast<autofill::ExtractMask>(
3510 autofill::EXTRACT_VALUE | autofill::EXTRACT_OPTION_TEXT),
3512 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
3513 EXPECT_EQ(GURL(frame->document().url()), form.origin);
3514 EXPECT_EQ(GURL("http://cnn.com"), form.action);
3516 const std::vector<FormFieldData>& fields = form.fields;
3517 ASSERT_EQ(3U, fields.size());
3519 FormFieldData expected;
3521 expected.name = ASCIIToUTF16("firstname");
3522 expected.value = ASCIIToUTF16("John");
3523 expected.form_control_type = "text";
3524 expected.max_length = WebInputElement::defaultMaxLength();
3525 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
3527 expected.name = ASCIIToUTF16("lastname");
3528 expected.value = ASCIIToUTF16("Smith");
3529 expected.form_control_type = "text";
3530 expected.max_length = WebInputElement::defaultMaxLength();
3531 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3533 expected.name = ASCIIToUTF16("country");
3534 expected.value = ASCIIToUTF16("Albania");
3535 expected.form_control_type = "select-one";
3536 expected.max_length = 0;
3537 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3539 form.fields.clear();
3540 // Extract the country select-one value as value.
3541 EXPECT_TRUE(WebFormElementToFormData(forms[0],
3542 WebFormControlElement(),
3543 autofill::REQUIRE_NONE,
3544 autofill::EXTRACT_VALUE,
3547 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
3548 EXPECT_EQ(GURL(frame->document().url()), form.origin);
3549 EXPECT_EQ(GURL("http://cnn.com"), form.action);
3551 ASSERT_EQ(3U, fields.size());
3553 expected.name = ASCIIToUTF16("firstname");
3554 expected.value = ASCIIToUTF16("John");
3555 expected.form_control_type = "text";
3556 expected.max_length = WebInputElement::defaultMaxLength();
3557 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
3559 expected.name = ASCIIToUTF16("lastname");
3560 expected.value = ASCIIToUTF16("Smith");
3561 expected.form_control_type = "text";
3562 expected.max_length = WebInputElement::defaultMaxLength();
3563 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3565 expected.name = ASCIIToUTF16("country");
3566 expected.value = ASCIIToUTF16("AL");
3567 expected.form_control_type = "select-one";
3568 expected.max_length = 0;
3569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3571 } // namespace autofill