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

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

Issue 7978048: Don't ask the browser for Autofill suggestions for non-autofillable form fields. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 20 matching lines...) Expand all
31 using WebKit::WebFormElement; 31 using WebKit::WebFormElement;
32 using WebKit::WebFrame; 32 using WebKit::WebFrame;
33 using WebKit::WebInputElement; 33 using WebKit::WebInputElement;
34 using WebKit::WebSelectElement; 34 using WebKit::WebSelectElement;
35 using WebKit::WebNode; 35 using WebKit::WebNode;
36 using WebKit::WebString; 36 using WebKit::WebString;
37 using WebKit::WebVector; 37 using WebKit::WebVector;
38 38
39 using autofill::ClearPreviewedFormWithElement; 39 using autofill::ClearPreviewedFormWithElement;
40 using autofill::FillForm; 40 using autofill::FillForm;
41 using autofill::FindFormAndFieldForFormControlElement; 41 using autofill::FindFormAndFieldForInputElement;
42 using autofill::FormWithElementIsAutofilled; 42 using autofill::FormWithElementIsAutofilled;
43 using autofill::FormCache; 43 using autofill::FormCache;
44 using autofill::PreviewForm; 44 using autofill::PreviewForm;
45 using autofill::WebFormControlElementToFormField; 45 using autofill::WebFormControlElementToFormField;
46 46
47 using webkit_glue::FormData; 47 using webkit_glue::FormData;
48 using webkit_glue::FormField; 48 using webkit_glue::FormField;
49 49
50 class FormManagerTest : public RenderViewTest { 50 class FormAutofillTest : public RenderViewTest {
51 public: 51 public:
52 FormManagerTest() : RenderViewTest() {} 52 FormAutofillTest() : RenderViewTest() {}
53 virtual ~FormManagerTest() {} 53 virtual ~FormAutofillTest() {}
54 54
55 void ExpectLabels(const char* html, 55 void ExpectLabels(const char* html,
56 const std::vector<string16>& labels, 56 const std::vector<string16>& labels,
57 const std::vector<string16>& names, 57 const std::vector<string16>& names,
58 const std::vector<string16>& values) { 58 const std::vector<string16>& values) {
59 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); 59 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text"));
60 ExpectLabelsAndTypes(html, labels, names, values, control_types); 60 ExpectLabelsAndTypes(html, labels, names, values, control_types);
61 } 61 }
62 62
63 void ExpectLabelsAndTypes(const char* html, 63 void ExpectLabelsAndTypes(const char* html,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 values.push_back(ASCIIToUTF16("Smith")); 112 values.push_back(ASCIIToUTF16("Smith"));
113 113
114 labels.push_back(ASCIIToUTF16("Email:")); 114 labels.push_back(ASCIIToUTF16("Email:"));
115 names.push_back(ASCIIToUTF16("email")); 115 names.push_back(ASCIIToUTF16("email"));
116 values.push_back(ASCIIToUTF16("john@example.com")); 116 values.push_back(ASCIIToUTF16("john@example.com"));
117 117
118 ExpectLabels(html, labels, names, values); 118 ExpectLabels(html, labels, names, values);
119 } 119 }
120 120
121 private: 121 private:
122 DISALLOW_COPY_AND_ASSIGN(FormManagerTest); 122 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest);
123 }; 123 };
124 124
125 // We should be able to extract a normal text field. 125 // We should be able to extract a normal text field.
126 TEST_F(FormManagerTest, WebFormControlElementToFormField) { 126 TEST_F(FormAutofillTest, WebFormControlElementToFormField) {
127 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); 127 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
128 128
129 WebFrame* frame = GetMainFrame(); 129 WebFrame* frame = GetMainFrame();
130 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 130 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
131 131
132 WebElement web_element = frame->document().getElementById("element"); 132 WebElement web_element = frame->document().getElementById("element");
133 WebFormControlElement element = web_element.to<WebFormControlElement>(); 133 WebFormControlElement element = web_element.to<WebFormControlElement>();
134 FormField result1; 134 FormField result1;
135 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); 135 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1);
136 136
137 FormField expected; 137 FormField expected;
138 expected.form_control_type = ASCIIToUTF16("text"); 138 expected.form_control_type = ASCIIToUTF16("text");
139 expected.max_length = WebInputElement::defaultMaxLength(); 139 expected.max_length = WebInputElement::defaultMaxLength();
140 140
141 expected.name = ASCIIToUTF16("element"); 141 expected.name = ASCIIToUTF16("element");
142 expected.value = string16(); 142 expected.value = string16();
143 EXPECT_FORM_FIELD_EQUALS(expected, result1); 143 EXPECT_FORM_FIELD_EQUALS(expected, result1);
144 144
145 FormField result2; 145 FormField result2;
146 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); 146 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2);
147 147
148 expected.name = ASCIIToUTF16("element"); 148 expected.name = ASCIIToUTF16("element");
149 expected.value = ASCIIToUTF16("value"); 149 expected.value = ASCIIToUTF16("value");
150 EXPECT_FORM_FIELD_EQUALS(expected, result2); 150 EXPECT_FORM_FIELD_EQUALS(expected, result2);
151 } 151 }
152 152
153 // We should be able to extract a text field with autocomplete="off". 153 // We should be able to extract a text field with autocomplete="off".
154 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompleteOff) { 154 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) {
155 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" 155 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
156 " autocomplete=\"off\"/>"); 156 " autocomplete=\"off\"/>");
157 157
158 WebFrame* frame = GetMainFrame(); 158 WebFrame* frame = GetMainFrame();
159 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 159 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
160 160
161 WebElement web_element = frame->document().getElementById("element"); 161 WebElement web_element = frame->document().getElementById("element");
162 WebFormControlElement element = web_element.to<WebFormControlElement>(); 162 WebFormControlElement element = web_element.to<WebFormControlElement>();
163 FormField result; 163 FormField result;
164 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); 164 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
165 165
166 FormField expected; 166 FormField expected;
167 expected.name = ASCIIToUTF16("element"); 167 expected.name = ASCIIToUTF16("element");
168 expected.value = ASCIIToUTF16("value"); 168 expected.value = ASCIIToUTF16("value");
169 expected.form_control_type = ASCIIToUTF16("text"); 169 expected.form_control_type = ASCIIToUTF16("text");
170 expected.max_length = WebInputElement::defaultMaxLength(); 170 expected.max_length = WebInputElement::defaultMaxLength();
171 EXPECT_FORM_FIELD_EQUALS(expected, result); 171 EXPECT_FORM_FIELD_EQUALS(expected, result);
172 } 172 }
173 173
174 // We should be able to extract a text field with maxlength specified. 174 // We should be able to extract a text field with maxlength specified.
175 TEST_F(FormManagerTest, WebFormControlElementToFormFieldMaxLength) { 175 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) {
176 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" 176 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
177 " maxlength=\"5\"/>"); 177 " maxlength=\"5\"/>");
178 178
179 WebFrame* frame = GetMainFrame(); 179 WebFrame* frame = GetMainFrame();
180 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 180 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
181 181
182 WebElement web_element = frame->document().getElementById("element"); 182 WebElement web_element = frame->document().getElementById("element");
183 WebFormControlElement element = web_element.to<WebFormControlElement>(); 183 WebFormControlElement element = web_element.to<WebFormControlElement>();
184 FormField result; 184 FormField result;
185 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); 185 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
186 186
187 FormField expected; 187 FormField expected;
188 expected.name = ASCIIToUTF16("element"); 188 expected.name = ASCIIToUTF16("element");
189 expected.value = ASCIIToUTF16("value"); 189 expected.value = ASCIIToUTF16("value");
190 expected.form_control_type = ASCIIToUTF16("text"); 190 expected.form_control_type = ASCIIToUTF16("text");
191 expected.max_length = 5; 191 expected.max_length = 5;
192 EXPECT_FORM_FIELD_EQUALS(expected, result); 192 EXPECT_FORM_FIELD_EQUALS(expected, result);
193 } 193 }
194 194
195 // We should be able to extract a text field that has been autofilled. 195 // We should be able to extract a text field that has been autofilled.
196 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutofilled) { 196 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) {
197 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); 197 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
198 198
199 WebFrame* frame = GetMainFrame(); 199 WebFrame* frame = GetMainFrame();
200 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 200 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
201 201
202 WebElement web_element = frame->document().getElementById("element"); 202 WebElement web_element = frame->document().getElementById("element");
203 WebInputElement element = web_element.to<WebInputElement>(); 203 WebInputElement element = web_element.to<WebInputElement>();
204 element.setAutofilled(true); 204 element.setAutofilled(true);
205 FormField result; 205 FormField result;
206 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); 206 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
207 207
208 FormField expected; 208 FormField expected;
209 expected.name = ASCIIToUTF16("element"); 209 expected.name = ASCIIToUTF16("element");
210 expected.value = ASCIIToUTF16("value"); 210 expected.value = ASCIIToUTF16("value");
211 expected.form_control_type = ASCIIToUTF16("text"); 211 expected.form_control_type = ASCIIToUTF16("text");
212 expected.max_length = WebInputElement::defaultMaxLength(); 212 expected.max_length = WebInputElement::defaultMaxLength();
213 expected.is_autofilled = true; 213 expected.is_autofilled = true;
214 EXPECT_FORM_FIELD_EQUALS(expected, result); 214 EXPECT_FORM_FIELD_EQUALS(expected, result);
215 } 215 }
216 216
217 // We should be able to extract a <select> field. 217 // We should be able to extract a <select> field.
218 TEST_F(FormManagerTest, WebFormControlElementToFormFieldSelect) { 218 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) {
219 LoadHTML("<SELECT id=\"element\"/>" 219 LoadHTML("<SELECT id=\"element\"/>"
220 " <OPTION value=\"CA\">California</OPTION>" 220 " <OPTION value=\"CA\">California</OPTION>"
221 " <OPTION value=\"TX\">Texas</OPTION>" 221 " <OPTION value=\"TX\">Texas</OPTION>"
222 "</SELECT>"); 222 "</SELECT>");
223 223
224 WebFrame* frame = GetMainFrame(); 224 WebFrame* frame = GetMainFrame();
225 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 225 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
226 226
227 WebElement web_element = frame->document().getElementById("element"); 227 WebElement web_element = frame->document().getElementById("element");
228 WebFormControlElement element = web_element.to<WebFormControlElement>(); 228 WebFormControlElement element = web_element.to<WebFormControlElement>();
(...skipping 25 matching lines...) Expand all
254 254
255 ASSERT_EQ(2U, result3.option_values.size()); 255 ASSERT_EQ(2U, result3.option_values.size());
256 ASSERT_EQ(2U, result3.option_contents.size()); 256 ASSERT_EQ(2U, result3.option_contents.size());
257 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); 257 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]);
258 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); 258 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]);
259 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); 259 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]);
260 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); 260 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]);
261 } 261 }
262 262
263 // We should not extract the value for non-text and non-select fields. 263 // We should not extract the value for non-text and non-select fields.
264 TEST_F(FormManagerTest, WebFormControlElementToFormFieldInvalidType) { 264 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) {
265 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 265 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
266 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" 266 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>"
267 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" 267 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>"
268 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" 268 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>"
269 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" 269 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>"
270 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" 270 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>"
271 "</FORM>"); 271 "</FORM>");
272 272
273 WebFrame* frame = GetMainFrame(); 273 WebFrame* frame = GetMainFrame();
274 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 274 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 309
310 web_element = frame->document().getElementById("submit"); 310 web_element = frame->document().getElementById("submit");
311 element = web_element.to<WebFormControlElement>(); 311 element = web_element.to<WebFormControlElement>();
312 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); 312 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
313 expected.name = ASCIIToUTF16("submit"); 313 expected.name = ASCIIToUTF16("submit");
314 expected.form_control_type = ASCIIToUTF16("submit"); 314 expected.form_control_type = ASCIIToUTF16("submit");
315 EXPECT_FORM_FIELD_EQUALS(expected, result); 315 EXPECT_FORM_FIELD_EQUALS(expected, result);
316 } 316 }
317 317
318 // We should be able to extract the autocompletetype attribute. 318 // We should be able to extract the autocompletetype attribute.
319 TEST_F(FormManagerTest, WebFormControlElementToFormFieldAutocompletetype) { 319 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) {
320 std::string html = 320 std::string html =
321 "<INPUT type=\"text\" id=\"absent\"/>" 321 "<INPUT type=\"text\" id=\"absent\"/>"
322 "<INPUT type=\"text\" id=\"empty\" x-autocompletetype=\"\"/>" 322 "<INPUT type=\"text\" id=\"empty\" x-autocompletetype=\"\"/>"
323 "<INPUT type=\"text\" id=\"whitespace\" x-autocompletetype=\" \"/>" 323 "<INPUT type=\"text\" id=\"whitespace\" x-autocompletetype=\" \"/>"
324 "<INPUT type=\"text\" id=\"regular\" x-autocompletetype=\"email\"/>" 324 "<INPUT type=\"text\" id=\"regular\" x-autocompletetype=\"email\"/>"
325 "<INPUT type=\"text\" id=\"multi-valued\" " 325 "<INPUT type=\"text\" id=\"multi-valued\" "
326 " x-autocompletetype=\"x-confirm-email email\"/>" 326 " x-autocompletetype=\"x-confirm-email email\"/>"
327 "<INPUT type=\"text\" id=\"unprefixed\" autocompletetype=\"email\"/>" 327 "<INPUT type=\"text\" id=\"unprefixed\" autocompletetype=\"email\"/>"
328 "<SELECT id=\"select\" x-autocompletetype=\"state\"/>" 328 "<SELECT id=\"select\" x-autocompletetype=\"state\"/>"
329 " <OPTION value=\"CA\">California</OPTION>" 329 " <OPTION value=\"CA\">California</OPTION>"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 element = web_element.to<WebFormControlElement>(); 422 element = web_element.to<WebFormControlElement>();
423 FormField result8; 423 FormField result8;
424 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result8); 424 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result8);
425 expected.name = ASCIIToUTF16("malicious"); 425 expected.name = ASCIIToUTF16("malicious");
426 expected.form_control_type = ASCIIToUTF16("text"); 426 expected.form_control_type = ASCIIToUTF16("text");
427 expected.autocomplete_type = ASCIIToUTF16("x-max-data-length-exceeded"); 427 expected.autocomplete_type = ASCIIToUTF16("x-max-data-length-exceeded");
428 expected.max_length = WebInputElement::defaultMaxLength(); 428 expected.max_length = WebInputElement::defaultMaxLength();
429 EXPECT_FORM_FIELD_EQUALS(expected, result8); 429 EXPECT_FORM_FIELD_EQUALS(expected, result8);
430 } 430 }
431 431
432 TEST_F(FormManagerTest, WebFormElementToFormData) { 432 TEST_F(FormAutofillTest, WebFormElementToFormData) {
433 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 433 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
434 " <LABEL for=\"firstname\">First name:</LABEL>" 434 " <LABEL for=\"firstname\">First name:</LABEL>"
435 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 435 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
436 " <LABEL for=\"lastname\">Last name:</LABEL>" 436 " <LABEL for=\"lastname\">Last name:</LABEL>"
437 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 437 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
438 " <LABEL for=\"state\">State:</LABEL>" 438 " <LABEL for=\"state\">State:</LABEL>"
439 " <SELECT id=\"state\"/>" 439 " <SELECT id=\"state\"/>"
440 " <OPTION value=\"CA\">California</OPTION>" 440 " <OPTION value=\"CA\">California</OPTION>"
441 " <OPTION value=\"TX\">Texas</OPTION>" 441 " <OPTION value=\"TX\">Texas</OPTION>"
442 " </SELECT>" 442 " </SELECT>"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 489 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
490 490
491 expected.name = ASCIIToUTF16("state"); 491 expected.name = ASCIIToUTF16("state");
492 expected.value = ASCIIToUTF16("CA"); 492 expected.value = ASCIIToUTF16("CA");
493 expected.label = ASCIIToUTF16("State:"); 493 expected.label = ASCIIToUTF16("State:");
494 expected.form_control_type = ASCIIToUTF16("select-one"); 494 expected.form_control_type = ASCIIToUTF16("select-one");
495 expected.max_length = 0; 495 expected.max_length = 0;
496 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 496 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
497 } 497 }
498 498
499 TEST_F(FormManagerTest, ExtractForms) { 499 TEST_F(FormAutofillTest, ExtractForms) {
500 ExpectJohnSmithLabels( 500 ExpectJohnSmithLabels(
501 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 501 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
502 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 502 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
503 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 503 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
504 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 504 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
505 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 505 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
506 "</FORM>"); 506 "</FORM>");
507 } 507 }
508 508
509 TEST_F(FormManagerTest, ExtractMultipleForms) { 509 TEST_F(FormAutofillTest, ExtractMultipleForms) {
510 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 510 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
511 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 511 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
512 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 512 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
513 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 513 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
514 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 514 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
515 "</FORM>" 515 "</FORM>"
516 "<FORM name=\"TestForm2\" action=\"http://zoo.com\" method=\"post\">" 516 "<FORM name=\"TestForm2\" action=\"http://zoo.com\" method=\"post\">"
517 " <INPUT type=\"text\" id=\"firstname\" value=\"Jack\"/>" 517 " <INPUT type=\"text\" id=\"firstname\" value=\"Jack\"/>"
518 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>" 518 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>"
519 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" 519 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 expected.name = ASCIIToUTF16("lastname"); 569 expected.name = ASCIIToUTF16("lastname");
570 expected.value = ASCIIToUTF16("Adams"); 570 expected.value = ASCIIToUTF16("Adams");
571 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); 571 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]);
572 572
573 expected.name = ASCIIToUTF16("email"); 573 expected.name = ASCIIToUTF16("email");
574 expected.value = ASCIIToUTF16("jack@example.com"); 574 expected.value = ASCIIToUTF16("jack@example.com");
575 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); 575 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
576 } 576 }
577 577
578 // We should not extract a form if it has too few fillable fields. 578 // We should not extract a form if it has too few fillable fields.
579 TEST_F(FormManagerTest, ExtractFormsTooFewFields) { 579 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
580 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 580 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
581 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 581 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
582 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 582 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
583 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 583 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
584 "</FORM>"); 584 "</FORM>");
585 585
586 WebFrame* web_frame = GetMainFrame(); 586 WebFrame* web_frame = GetMainFrame();
587 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 587 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
588 588
589 FormCache form_cache; 589 FormCache form_cache;
590 std::vector<FormData> forms; 590 std::vector<FormData> forms;
591 form_cache.ExtractForms(*web_frame, &forms); 591 form_cache.ExtractForms(*web_frame, &forms);
592 EXPECT_EQ(0U, forms.size()); 592 EXPECT_EQ(0U, forms.size());
593 } 593 }
594 594
595 TEST_F(FormManagerTest, WebFormElementToFormDataAutocomplete) { 595 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) {
596 { 596 {
597 // Form is not auto-completable due to autocomplete=off. 597 // Form is not auto-completable due to autocomplete=off.
598 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\"" 598 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\""
599 " autocomplete=off>" 599 " autocomplete=off>"
600 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 600 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
601 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 601 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
602 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 602 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
603 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 603 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
604 "</FORM>"); 604 "</FORM>");
605 605
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 expected.name = ASCIIToUTF16("lastname"); 663 expected.name = ASCIIToUTF16("lastname");
664 expected.value = ASCIIToUTF16("Smith"); 664 expected.value = ASCIIToUTF16("Smith");
665 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 665 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
666 666
667 expected.name = ASCIIToUTF16("email"); 667 expected.name = ASCIIToUTF16("email");
668 expected.value = ASCIIToUTF16("john@example.com"); 668 expected.value = ASCIIToUTF16("john@example.com");
669 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 669 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
670 } 670 }
671 } 671 }
672 672
673 TEST_F(FormManagerTest, FindForm) { 673 TEST_F(FormAutofillTest, FindForm) {
674 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 674 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
675 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 675 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
676 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 676 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
677 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 677 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\""
678 "autocomplete=\"off\" />"
679 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>"
678 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 680 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
679 "</FORM>"); 681 "</FORM>");
680 682
681 WebFrame* web_frame = GetMainFrame(); 683 WebFrame* web_frame = GetMainFrame();
682 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 684 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
683 685
684 FormCache form_cache; 686 FormCache form_cache;
685 std::vector<FormData> forms; 687 std::vector<FormData> forms;
686 form_cache.ExtractForms(*web_frame, &forms); 688 form_cache.ExtractForms(*web_frame, &forms);
687 ASSERT_EQ(1U, forms.size()); 689 ASSERT_EQ(1U, forms.size());
688 690
689 // Get the input element we want to find. 691 // Get the input element we want to find.
690 WebElement element = web_frame->document().getElementById("firstname"); 692 WebElement element = web_frame->document().getElementById("firstname");
691 WebInputElement input_element = element.to<WebInputElement>(); 693 WebInputElement input_element = element.to<WebInputElement>();
692 694
693 // Find the form and verify it's the correct form. 695 // Find the form and verify it's the correct form.
694 FormData form; 696 FormData form;
695 FormField field; 697 FormField field;
696 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 698 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
697 &field)); 699 autofill::REQUIRE_NONE));
698 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 700 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
699 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 701 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
700 EXPECT_EQ(GURL("http://buh.com"), form.action); 702 EXPECT_EQ(GURL("http://buh.com"), form.action);
701 703
702 const std::vector<FormField>& fields = form.fields; 704 const std::vector<FormField>& fields = form.fields;
703 ASSERT_EQ(3U, fields.size()); 705 ASSERT_EQ(4U, fields.size());
704 706
705 FormField expected; 707 FormField expected;
706 expected.form_control_type = ASCIIToUTF16("text"); 708 expected.form_control_type = ASCIIToUTF16("text");
707 expected.max_length = WebInputElement::defaultMaxLength(); 709 expected.max_length = WebInputElement::defaultMaxLength();
708 710
709 expected.name = ASCIIToUTF16("firstname"); 711 expected.name = ASCIIToUTF16("firstname");
710 expected.value = ASCIIToUTF16("John"); 712 expected.value = ASCIIToUTF16("John");
711 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); 713 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]);
712 EXPECT_FORM_FIELD_EQUALS(expected, field); 714 EXPECT_FORM_FIELD_EQUALS(expected, field);
713 715
714 expected.name = ASCIIToUTF16("lastname"); 716 expected.name = ASCIIToUTF16("lastname");
715 expected.value = ASCIIToUTF16("Smith"); 717 expected.value = ASCIIToUTF16("Smith");
716 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 718 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
717 719
718 expected.name = ASCIIToUTF16("email"); 720 expected.name = ASCIIToUTF16("email");
719 expected.value = ASCIIToUTF16("john@example.com"); 721 expected.value = ASCIIToUTF16("john@example.com");
720 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 722 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
723
724 expected.name = ASCIIToUTF16("phone");
725 expected.value = ASCIIToUTF16("1.800.555.1234");
726 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]);
727
728 // Try again, but require autocomplete.
729 FormData form2;
730 FormField field2;
731 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
732 autofill::REQUIRE_AUTOCOMPLETE));
733 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
734 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
735 EXPECT_EQ(GURL("http://buh.com"), form2.action);
736
737 const std::vector<FormField>& fields2 = form2.fields;
738 ASSERT_EQ(3U, fields2.size());
739
740 expected.form_control_type = ASCIIToUTF16("text");
741 expected.max_length = WebInputElement::defaultMaxLength();
742
743 expected.name = ASCIIToUTF16("firstname");
744 expected.value = ASCIIToUTF16("John");
745 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]);
746 EXPECT_FORM_FIELD_EQUALS(expected, field);
747
748 expected.name = ASCIIToUTF16("lastname");
749 expected.value = ASCIIToUTF16("Smith");
750 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]);
751
752 expected.name = ASCIIToUTF16("phone");
753 expected.value = ASCIIToUTF16("1.800.555.1234");
754 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
721 } 755 }
722 756
723 TEST_F(FormManagerTest, FillForm) { 757 TEST_F(FormAutofillTest, FillForm) {
724 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 758 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
725 " <INPUT type=\"text\" id=\"firstname\"/>" 759 " <INPUT type=\"text\" id=\"firstname\"/>"
726 " <INPUT type=\"text\" id=\"lastname\"/>" 760 " <INPUT type=\"text\" id=\"lastname\"/>"
727 " <INPUT type=\"hidden\" id=\"imhidden\"/>" 761 " <INPUT type=\"hidden\" id=\"imhidden\"/>"
728 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" 762 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>"
729 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" 763 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>"
730 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" 764 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>"
731 " <INPUT type=\"text\" readonly id=\"readonly\"/>" 765 " <INPUT type=\"text\" readonly id=\"readonly\"/>"
732 " <INPUT type=\"text\" style=\"visibility: hidden\"" 766 " <INPUT type=\"text\" style=\"visibility: hidden\""
733 " id=\"invisible\"/>" 767 " id=\"invisible\"/>"
734 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>" 768 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>"
735 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 769 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
736 "</FORM>"); 770 "</FORM>");
737 771
738 WebFrame* web_frame = GetMainFrame(); 772 WebFrame* web_frame = GetMainFrame();
739 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 773 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
740 774
741 FormCache form_cache; 775 FormCache form_cache;
742 std::vector<FormData> forms; 776 std::vector<FormData> forms;
743 form_cache.ExtractForms(*web_frame, &forms); 777 form_cache.ExtractForms(*web_frame, &forms);
744 ASSERT_EQ(1U, forms.size()); 778 ASSERT_EQ(1U, forms.size());
745 779
746 // Get the input element we want to find. 780 // Get the input element we want to find.
747 WebElement element = web_frame->document().getElementById("firstname"); 781 WebElement element = web_frame->document().getElementById("firstname");
748 WebInputElement input_element = element.to<WebInputElement>(); 782 WebInputElement input_element = element.to<WebInputElement>();
749 783
750 // Find the form that contains the input element. 784 // Find the form that contains the input element.
751 FormData form; 785 FormData form;
752 FormField field; 786 FormField field;
753 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 787 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
754 &field)); 788 autofill::REQUIRE_NONE));
755 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 789 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
756 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 790 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
757 EXPECT_EQ(GURL("http://buh.com"), form.action); 791 EXPECT_EQ(GURL("http://buh.com"), form.action);
758 792
759 const std::vector<FormField>& fields = form.fields; 793 const std::vector<FormField>& fields = form.fields;
760 ASSERT_EQ(8U, fields.size()); 794 ASSERT_EQ(8U, fields.size());
761 795
762 FormField expected; 796 FormField expected;
763 expected.form_control_type = ASCIIToUTF16("text"); 797 expected.form_control_type = ASCIIToUTF16("text");
764 expected.max_length = WebInputElement::defaultMaxLength(); 798 expected.max_length = WebInputElement::defaultMaxLength();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 EXPECT_FALSE(invisible.isAutofilled()); 884 EXPECT_FALSE(invisible.isAutofilled());
851 EXPECT_TRUE(invisible.value().isEmpty()); 885 EXPECT_TRUE(invisible.value().isEmpty());
852 886
853 // |display:none| fields are not filled. 887 // |display:none| fields are not filled.
854 WebInputElement display_none = 888 WebInputElement display_none =
855 document.getElementById("displaynone").to<WebInputElement>(); 889 document.getElementById("displaynone").to<WebInputElement>();
856 EXPECT_FALSE(display_none.isAutofilled()); 890 EXPECT_FALSE(display_none.isAutofilled());
857 EXPECT_TRUE(display_none.value().isEmpty()); 891 EXPECT_TRUE(display_none.value().isEmpty());
858 } 892 }
859 893
860 TEST_F(FormManagerTest, PreviewForm) { 894 TEST_F(FormAutofillTest, PreviewForm) {
861 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 895 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
862 " <INPUT type=\"text\" id=\"firstname\"/>" 896 " <INPUT type=\"text\" id=\"firstname\"/>"
863 " <INPUT type=\"text\" id=\"lastname\"/>" 897 " <INPUT type=\"text\" id=\"lastname\"/>"
864 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" 898 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>"
865 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" 899 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>"
866 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" 900 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>"
867 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 901 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
868 "</FORM>"); 902 "</FORM>");
869 903
870 WebFrame* web_frame = GetMainFrame(); 904 WebFrame* web_frame = GetMainFrame();
871 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 905 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
872 906
873 FormCache form_cache; 907 FormCache form_cache;
874 std::vector<FormData> forms; 908 std::vector<FormData> forms;
875 form_cache.ExtractForms(*web_frame, &forms); 909 form_cache.ExtractForms(*web_frame, &forms);
876 ASSERT_EQ(1U, forms.size()); 910 ASSERT_EQ(1U, forms.size());
877 911
878 // Get the input element we want to find. 912 // Get the input element we want to find.
879 WebElement element = web_frame->document().getElementById("firstname"); 913 WebElement element = web_frame->document().getElementById("firstname");
880 WebInputElement input_element = element.to<WebInputElement>(); 914 WebInputElement input_element = element.to<WebInputElement>();
881 915
882 // Find the form that contains the input element. 916 // Find the form that contains the input element.
883 FormData form; 917 FormData form;
884 FormField field; 918 FormField field;
885 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 919 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
886 &field)); 920 autofill::REQUIRE_NONE));
887 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 921 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
888 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 922 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
889 EXPECT_EQ(GURL("http://buh.com"), form.action); 923 EXPECT_EQ(GURL("http://buh.com"), form.action);
890 924
891 const std::vector<FormField>& fields = form.fields; 925 const std::vector<FormField>& fields = form.fields;
892 ASSERT_EQ(5U, fields.size()); 926 ASSERT_EQ(5U, fields.size());
893 927
894 FormField expected; 928 FormField expected;
895 expected.form_control_type = ASCIIToUTF16("text"); 929 expected.form_control_type = ASCIIToUTF16("text");
896 expected.max_length = WebInputElement::defaultMaxLength(); 930 expected.max_length = WebInputElement::defaultMaxLength();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 EXPECT_FALSE(noautocomplete.isAutofilled()); 983 EXPECT_FALSE(noautocomplete.isAutofilled());
950 EXPECT_TRUE(noautocomplete.suggestedValue().isEmpty()); 984 EXPECT_TRUE(noautocomplete.suggestedValue().isEmpty());
951 985
952 // Disabled fields are not previewed. 986 // Disabled fields are not previewed.
953 WebInputElement notenabled = 987 WebInputElement notenabled =
954 document.getElementById("notenabled").to<WebInputElement>(); 988 document.getElementById("notenabled").to<WebInputElement>();
955 EXPECT_FALSE(notenabled.isAutofilled()); 989 EXPECT_FALSE(notenabled.isAutofilled());
956 EXPECT_TRUE(notenabled.suggestedValue().isEmpty()); 990 EXPECT_TRUE(notenabled.suggestedValue().isEmpty());
957 } 991 }
958 992
959 TEST_F(FormManagerTest, Labels) { 993 TEST_F(FormAutofillTest, Labels) {
960 ExpectJohnSmithLabels( 994 ExpectJohnSmithLabels(
961 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 995 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
962 " <LABEL for=\"firstname\"> First name: </LABEL>" 996 " <LABEL for=\"firstname\"> First name: </LABEL>"
963 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 997 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
964 " <LABEL for=\"lastname\"> Last name: </LABEL>" 998 " <LABEL for=\"lastname\"> Last name: </LABEL>"
965 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 999 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
966 " <LABEL for=\"email\"> Email: </LABEL>" 1000 " <LABEL for=\"email\"> Email: </LABEL>"
967 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1001 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
968 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1002 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
969 "</FORM>"); 1003 "</FORM>");
970 } 1004 }
971 1005
972 TEST_F(FormManagerTest, LabelsWithSpans) { 1006 TEST_F(FormAutofillTest, LabelsWithSpans) {
973 ExpectJohnSmithLabels( 1007 ExpectJohnSmithLabels(
974 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1008 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
975 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>" 1009 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>"
976 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1010 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
977 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>" 1011 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>"
978 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1012 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
979 " <LABEL for=\"email\"><span>Email: </span></LABEL>" 1013 " <LABEL for=\"email\"><span>Email: </span></LABEL>"
980 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1014 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
981 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1015 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
982 "</FORM>"); 1016 "</FORM>");
983 } 1017 }
984 1018
985 // This test is different from FormManagerTest.Labels in that the label elements 1019 // This test is different from FormAutofillTest.Labels in that the label
986 // for= attribute is set to the name of the form control element it is a label 1020 // elements for= attribute is set to the name of the form control element it is
987 // for instead of the id of the form control element. This is invalid because 1021 // a label for instead of the id of the form control element. This is invalid
988 // the for= attribute must be set to the id of the form control element; 1022 // because the for= attribute must be set to the id of the form control element;
989 // however, current label parsing code will extract the text from the previous 1023 // however, current label parsing code will extract the text from the previous
990 // label element and apply it to the following input field. 1024 // label element and apply it to the following input field.
991 TEST_F(FormManagerTest, InvalidLabels) { 1025 TEST_F(FormAutofillTest, InvalidLabels) {
992 ExpectJohnSmithLabels( 1026 ExpectJohnSmithLabels(
993 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1027 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
994 " <LABEL for=\"firstname\"> First name: </LABEL>" 1028 " <LABEL for=\"firstname\"> First name: </LABEL>"
995 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>" 1029 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>"
996 " <LABEL for=\"lastname\"> Last name: </LABEL>" 1030 " <LABEL for=\"lastname\"> Last name: </LABEL>"
997 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>" 1031 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>"
998 " <LABEL for=\"email\"> Email: </LABEL>" 1032 " <LABEL for=\"email\"> Email: </LABEL>"
999 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\"/>" 1033 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\"/>"
1000 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1034 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1001 "</FORM>"); 1035 "</FORM>");
1002 } 1036 }
1003 1037
1004 // This test has three form control elements, only one of which has a label 1038 // This test has three form control elements, only one of which has a label
1005 // element associated with it. 1039 // element associated with it.
1006 TEST_F(FormManagerTest, OneLabelElement) { 1040 TEST_F(FormAutofillTest, OneLabelElement) {
1007 ExpectJohnSmithLabels( 1041 ExpectJohnSmithLabels(
1008 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1042 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1009 " First name:" 1043 " First name:"
1010 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1044 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1011 " <LABEL for=\"lastname\">Last name: </LABEL>" 1045 " <LABEL for=\"lastname\">Last name: </LABEL>"
1012 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1046 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1013 " Email:" 1047 " Email:"
1014 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1048 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1015 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1049 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1016 "</FORM>"); 1050 "</FORM>");
1017 } 1051 }
1018 1052
1019 TEST_F(FormManagerTest, LabelsInferredFromText) { 1053 TEST_F(FormAutofillTest, LabelsInferredFromText) {
1020 ExpectJohnSmithLabels( 1054 ExpectJohnSmithLabels(
1021 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1055 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1022 " First name:" 1056 " First name:"
1023 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1057 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1024 " Last name:" 1058 " Last name:"
1025 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1059 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1026 " Email:" 1060 " Email:"
1027 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1061 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1028 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1062 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1029 "</FORM>"); 1063 "</FORM>");
1030 } 1064 }
1031 1065
1032 TEST_F(FormManagerTest, LabelsInferredFromParagraph) { 1066 TEST_F(FormAutofillTest, LabelsInferredFromParagraph) {
1033 ExpectJohnSmithLabels( 1067 ExpectJohnSmithLabels(
1034 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1068 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1035 " <P>First name:</P><INPUT type=\"text\" " 1069 " <P>First name:</P><INPUT type=\"text\" "
1036 " id=\"firstname\" value=\"John\"/>" 1070 " id=\"firstname\" value=\"John\"/>"
1037 " <P>Last name:</P>" 1071 " <P>Last name:</P>"
1038 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1072 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1039 " <P>Email:</P>" 1073 " <P>Email:</P>"
1040 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1074 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1041 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1075 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1042 "</FORM>"); 1076 "</FORM>");
1043 } 1077 }
1044 1078
1045 TEST_F(FormManagerTest, LabelsInferredFromBold) { 1079 TEST_F(FormAutofillTest, LabelsInferredFromBold) {
1046 ExpectJohnSmithLabels( 1080 ExpectJohnSmithLabels(
1047 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1081 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1048 " <B>First name:</B><INPUT type=\"text\" " 1082 " <B>First name:</B><INPUT type=\"text\" "
1049 " id=\"firstname\" value=\"John\"/>" 1083 " id=\"firstname\" value=\"John\"/>"
1050 " <B>Last name:</B>" 1084 " <B>Last name:</B>"
1051 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1085 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1052 " <B>Email:</B>" 1086 " <B>Email:</B>"
1053 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1087 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1054 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1088 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1055 "</FORM>"); 1089 "</FORM>");
1056 } 1090 }
1057 1091
1058 TEST_F(FormManagerTest, LabelsInferredPriorToImgOrBr) { 1092 TEST_F(FormAutofillTest, LabelsInferredPriorToImgOrBr) {
1059 ExpectJohnSmithLabels( 1093 ExpectJohnSmithLabels(
1060 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1094 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1061 " First name:<IMG/><INPUT type=\"text\" " 1095 " First name:<IMG/><INPUT type=\"text\" "
1062 " id=\"firstname\" value=\"John\"/>" 1096 " id=\"firstname\" value=\"John\"/>"
1063 " Last name:<IMG/>" 1097 " Last name:<IMG/>"
1064 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1098 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1065 " Email:<BR/>" 1099 " Email:<BR/>"
1066 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1100 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1067 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1101 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1068 "</FORM>"); 1102 "</FORM>");
1069 } 1103 }
1070 1104
1071 TEST_F(FormManagerTest, LabelsInferredFromTableCell) { 1105 TEST_F(FormAutofillTest, LabelsInferredFromTableCell) {
1072 ExpectJohnSmithLabels( 1106 ExpectJohnSmithLabels(
1073 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1107 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1074 "<TABLE>" 1108 "<TABLE>"
1075 " <TR>" 1109 " <TR>"
1076 " <TD>First name:</TD>" 1110 " <TD>First name:</TD>"
1077 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>" 1111 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
1078 " </TR>" 1112 " </TR>"
1079 " <TR>" 1113 " <TR>"
1080 " <TD>Last name:</TD>" 1114 " <TD>Last name:</TD>"
1081 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>" 1115 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
1082 " </TR>" 1116 " </TR>"
1083 " <TR>" 1117 " <TR>"
1084 " <TD>Email:</TD>" 1118 " <TD>Email:</TD>"
1085 " <TD><INPUT type=\"text\" id=\"email\"" 1119 " <TD><INPUT type=\"text\" id=\"email\""
1086 " value=\"john@example.com\"/></TD>" 1120 " value=\"john@example.com\"/></TD>"
1087 " </TR>" 1121 " </TR>"
1088 " <TR>" 1122 " <TR>"
1089 " <TD></TD>" 1123 " <TD></TD>"
1090 " <TD>" 1124 " <TD>"
1091 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1125 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1092 " </TD>" 1126 " </TD>"
1093 " </TR>" 1127 " </TR>"
1094 "</TABLE>" 1128 "</TABLE>"
1095 "</FORM>"); 1129 "</FORM>");
1096 } 1130 }
1097 1131
1098 TEST_F(FormManagerTest, LabelsInferredFromTableCellTH) { 1132 TEST_F(FormAutofillTest, LabelsInferredFromTableCellTH) {
1099 ExpectJohnSmithLabels( 1133 ExpectJohnSmithLabels(
1100 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1134 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1101 "<TABLE>" 1135 "<TABLE>"
1102 " <TR>" 1136 " <TR>"
1103 " <TH>First name:</TH>" 1137 " <TH>First name:</TH>"
1104 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>" 1138 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
1105 " </TR>" 1139 " </TR>"
1106 " <TR>" 1140 " <TR>"
1107 " <TH>Last name:</TH>" 1141 " <TH>Last name:</TH>"
1108 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>" 1142 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
1109 " </TR>" 1143 " </TR>"
1110 " <TR>" 1144 " <TR>"
1111 " <TH>Email:</TH>" 1145 " <TH>Email:</TH>"
1112 " <TD><INPUT type=\"text\" id=\"email\"" 1146 " <TD><INPUT type=\"text\" id=\"email\""
1113 " value=\"john@example.com\"/></TD>" 1147 " value=\"john@example.com\"/></TD>"
1114 " </TR>" 1148 " </TR>"
1115 " <TR>" 1149 " <TR>"
1116 " <TD></TD>" 1150 " <TD></TD>"
1117 " <TD>" 1151 " <TD>"
1118 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1152 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1119 " </TD>" 1153 " </TD>"
1120 " </TR>" 1154 " </TR>"
1121 "</TABLE>" 1155 "</TABLE>"
1122 "</FORM>"); 1156 "</FORM>");
1123 } 1157 }
1124 1158
1125 TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) { 1159 TEST_F(FormAutofillTest, LabelsInferredFromTableCellNested) {
1126 std::vector<string16> labels, names, values; 1160 std::vector<string16> labels, names, values;
1127 1161
1128 labels.push_back(ASCIIToUTF16("First name: Bogus")); 1162 labels.push_back(ASCIIToUTF16("First name: Bogus"));
1129 names.push_back(ASCIIToUTF16("firstname")); 1163 names.push_back(ASCIIToUTF16("firstname"));
1130 values.push_back(ASCIIToUTF16("John")); 1164 values.push_back(ASCIIToUTF16("John"));
1131 1165
1132 labels.push_back(ASCIIToUTF16("Last name:")); 1166 labels.push_back(ASCIIToUTF16("Last name:"));
1133 names.push_back(ASCIIToUTF16("lastname")); 1167 names.push_back(ASCIIToUTF16("lastname"));
1134 values.push_back(ASCIIToUTF16("Smith")); 1168 values.push_back(ASCIIToUTF16("Smith"));
1135 1169
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 " <TD></TD>" 1217 " <TD></TD>"
1184 " <TD>" 1218 " <TD>"
1185 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1219 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1186 " </TD>" 1220 " </TD>"
1187 " </TR>" 1221 " </TR>"
1188 "</TABLE>" 1222 "</TABLE>"
1189 "</FORM>", 1223 "</FORM>",
1190 labels, names, values); 1224 labels, names, values);
1191 } 1225 }
1192 1226
1193 TEST_F(FormManagerTest, LabelsInferredFromTableEmptyTDs) { 1227 TEST_F(FormAutofillTest, LabelsInferredFromTableEmptyTDs) {
1194 std::vector<string16> labels, names, values; 1228 std::vector<string16> labels, names, values;
1195 1229
1196 labels.push_back(ASCIIToUTF16("* First Name")); 1230 labels.push_back(ASCIIToUTF16("* First Name"));
1197 names.push_back(ASCIIToUTF16("firstname")); 1231 names.push_back(ASCIIToUTF16("firstname"));
1198 values.push_back(ASCIIToUTF16("John")); 1232 values.push_back(ASCIIToUTF16("John"));
1199 1233
1200 labels.push_back(ASCIIToUTF16("* Last Name")); 1234 labels.push_back(ASCIIToUTF16("* Last Name"));
1201 names.push_back(ASCIIToUTF16("lastname")); 1235 names.push_back(ASCIIToUTF16("lastname"));
1202 values.push_back(ASCIIToUTF16("Smith")); 1236 values.push_back(ASCIIToUTF16("Smith"));
1203 1237
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 " <TD></TD>" 1276 " <TD></TD>"
1243 " <TD>" 1277 " <TD>"
1244 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1278 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1245 " </TD>" 1279 " </TD>"
1246 " </TR>" 1280 " </TR>"
1247 "</TABLE>" 1281 "</TABLE>"
1248 "</FORM>", 1282 "</FORM>",
1249 labels, names, values); 1283 labels, names, values);
1250 } 1284 }
1251 1285
1252 TEST_F(FormManagerTest, LabelsInferredFromPreviousTD) { 1286 TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) {
1253 std::vector<string16> labels, names, values; 1287 std::vector<string16> labels, names, values;
1254 1288
1255 labels.push_back(ASCIIToUTF16("* First Name")); 1289 labels.push_back(ASCIIToUTF16("* First Name"));
1256 names.push_back(ASCIIToUTF16("firstname")); 1290 names.push_back(ASCIIToUTF16("firstname"));
1257 values.push_back(ASCIIToUTF16("John")); 1291 values.push_back(ASCIIToUTF16("John"));
1258 1292
1259 labels.push_back(ASCIIToUTF16("* Last Name")); 1293 labels.push_back(ASCIIToUTF16("* Last Name"));
1260 names.push_back(ASCIIToUTF16("lastname")); 1294 names.push_back(ASCIIToUTF16("lastname"));
1261 values.push_back(ASCIIToUTF16("Smith")); 1295 values.push_back(ASCIIToUTF16("Smith"));
1262 1296
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 " </TD>" 1328 " </TD>"
1295 " </TR>" 1329 " </TR>"
1296 "</TABLE>" 1330 "</TABLE>"
1297 "</FORM>", 1331 "</FORM>",
1298 labels, names, values); 1332 labels, names, values);
1299 } 1333 }
1300 1334
1301 // <script>, <noscript> and <option> tags are excluded when the labels are 1335 // <script>, <noscript> and <option> tags are excluded when the labels are
1302 // inferred. 1336 // inferred.
1303 // Also <!-- comment --> is excluded. 1337 // Also <!-- comment --> is excluded.
1304 TEST_F(FormManagerTest, LabelsInferredFromTableWithSpecialElements) { 1338 TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) {
1305 std::vector<string16> labels, names, values, control_types; 1339 std::vector<string16> labels, names, values, control_types;
1306 1340
1307 labels.push_back(ASCIIToUTF16("* First Name")); 1341 labels.push_back(ASCIIToUTF16("* First Name"));
1308 names.push_back(ASCIIToUTF16("firstname")); 1342 names.push_back(ASCIIToUTF16("firstname"));
1309 values.push_back(ASCIIToUTF16("John")); 1343 values.push_back(ASCIIToUTF16("John"));
1310 control_types.push_back(ASCIIToUTF16("text")); 1344 control_types.push_back(ASCIIToUTF16("text"));
1311 1345
1312 labels.push_back(ASCIIToUTF16("* Middle Name")); 1346 labels.push_back(ASCIIToUTF16("* Middle Name"));
1313 names.push_back(ASCIIToUTF16("middlename")); 1347 names.push_back(ASCIIToUTF16("middlename"));
1314 values.push_back(ASCIIToUTF16("Joe")); 1348 values.push_back(ASCIIToUTF16("Joe"));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 " <TD></TD>" 1425 " <TD></TD>"
1392 " <TD>" 1426 " <TD>"
1393 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1427 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1394 " </TD>" 1428 " </TD>"
1395 " </TR>" 1429 " </TR>"
1396 "</TABLE>" 1430 "</TABLE>"
1397 "</FORM>", 1431 "</FORM>",
1398 labels, names, values, control_types); 1432 labels, names, values, control_types);
1399 } 1433 }
1400 1434
1401 TEST_F(FormManagerTest, LabelsInferredFromTableLabels) { 1435 TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) {
1402 ExpectJohnSmithLabels( 1436 ExpectJohnSmithLabels(
1403 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1437 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1404 "<TABLE>" 1438 "<TABLE>"
1405 " <TR>" 1439 " <TR>"
1406 " <TD>" 1440 " <TD>"
1407 " <LABEL>First name:</LABEL>" 1441 " <LABEL>First name:</LABEL>"
1408 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1442 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1409 " </TD>" 1443 " </TD>"
1410 " </TR>" 1444 " </TR>"
1411 " <TR>" 1445 " <TR>"
1412 " <TD>" 1446 " <TD>"
1413 " <LABEL>Last name:</LABEL>" 1447 " <LABEL>Last name:</LABEL>"
1414 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1448 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1415 " </TD>" 1449 " </TD>"
1416 " </TR>" 1450 " </TR>"
1417 " <TR>" 1451 " <TR>"
1418 " <TD>" 1452 " <TD>"
1419 " <LABEL>Email:</LABEL>" 1453 " <LABEL>Email:</LABEL>"
1420 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1454 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1421 " </TD>" 1455 " </TD>"
1422 " </TR>" 1456 " </TR>"
1423 "</TABLE>" 1457 "</TABLE>"
1424 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1458 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1425 "</FORM>"); 1459 "</FORM>");
1426 } 1460 }
1427 1461
1428 TEST_F(FormManagerTest, LabelsInferredFromTableTDInterveningElements) { 1462 TEST_F(FormAutofillTest, LabelsInferredFromTableTDInterveningElements) {
1429 ExpectJohnSmithLabels( 1463 ExpectJohnSmithLabels(
1430 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1464 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1431 "<TABLE>" 1465 "<TABLE>"
1432 " <TR>" 1466 " <TR>"
1433 " <TD>" 1467 " <TD>"
1434 " First name:" 1468 " First name:"
1435 " <BR>" 1469 " <BR>"
1436 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1470 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1437 " </TD>" 1471 " </TD>"
1438 " </TR>" 1472 " </TR>"
(...skipping 11 matching lines...) Expand all
1450 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 1484 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
1451 " </TD>" 1485 " </TD>"
1452 " </TR>" 1486 " </TR>"
1453 "</TABLE>" 1487 "</TABLE>"
1454 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1488 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1455 "</FORM>"); 1489 "</FORM>");
1456 } 1490 }
1457 1491
1458 // Verify that we correctly infer labels when the label text spans multiple 1492 // Verify that we correctly infer labels when the label text spans multiple
1459 // adjacent HTML elements, not separated by whitespace. 1493 // adjacent HTML elements, not separated by whitespace.
1460 TEST_F(FormManagerTest, LabelsInferredFromTableAdjacentElements) { 1494 TEST_F(FormAutofillTest, LabelsInferredFromTableAdjacentElements) {
1461 std::vector<string16> labels, names, values; 1495 std::vector<string16> labels, names, values;
1462 1496
1463 labels.push_back(ASCIIToUTF16("*First Name")); 1497 labels.push_back(ASCIIToUTF16("*First Name"));
1464 names.push_back(ASCIIToUTF16("firstname")); 1498 names.push_back(ASCIIToUTF16("firstname"));
1465 values.push_back(ASCIIToUTF16("John")); 1499 values.push_back(ASCIIToUTF16("John"));
1466 1500
1467 labels.push_back(ASCIIToUTF16("*Last Name")); 1501 labels.push_back(ASCIIToUTF16("*Last Name"));
1468 names.push_back(ASCIIToUTF16("lastname")); 1502 names.push_back(ASCIIToUTF16("lastname"));
1469 values.push_back(ASCIIToUTF16("Smith")); 1503 values.push_back(ASCIIToUTF16("Smith"));
1470 1504
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1538 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1505 " </TD>" 1539 " </TD>"
1506 " </TR>" 1540 " </TR>"
1507 "</TABLE>" 1541 "</TABLE>"
1508 "</FORM>", 1542 "</FORM>",
1509 labels, names, values); 1543 labels, names, values);
1510 } 1544 }
1511 1545
1512 // Verify that we correctly infer labels when the label text resides in the 1546 // Verify that we correctly infer labels when the label text resides in the
1513 // previous row. 1547 // previous row.
1514 TEST_F(FormManagerTest, LabelsInferredFromTableRow) { 1548 TEST_F(FormAutofillTest, LabelsInferredFromTableRow) {
1515 std::vector<string16> labels, names, values; 1549 std::vector<string16> labels, names, values;
1516 1550
1517 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); 1551 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email"));
1518 names.push_back(ASCIIToUTF16("firstname")); 1552 names.push_back(ASCIIToUTF16("firstname"));
1519 values.push_back(ASCIIToUTF16("John")); 1553 values.push_back(ASCIIToUTF16("John"));
1520 1554
1521 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); 1555 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email"));
1522 names.push_back(ASCIIToUTF16("lastname")); 1556 names.push_back(ASCIIToUTF16("lastname"));
1523 values.push_back(ASCIIToUTF16("Smith")); 1557 values.push_back(ASCIIToUTF16("Smith"));
1524 1558
(...skipping 23 matching lines...) Expand all
1548 " <TR>" 1582 " <TR>"
1549 " <TD>" 1583 " <TD>"
1550 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1584 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1551 " </TD>" 1585 " </TD>"
1552 " </TR>" 1586 " </TR>"
1553 "</TABLE>", 1587 "</TABLE>",
1554 labels, names, values); 1588 labels, names, values);
1555 } 1589 }
1556 1590
1557 // Verify that we correctly infer labels when enclosed within a list item. 1591 // Verify that we correctly infer labels when enclosed within a list item.
1558 TEST_F(FormManagerTest, LabelsInferredFromListItem) { 1592 TEST_F(FormAutofillTest, LabelsInferredFromListItem) {
1559 std::vector<string16> labels, names, values; 1593 std::vector<string16> labels, names, values;
1560 1594
1561 labels.push_back(ASCIIToUTF16("* Home Phone")); 1595 labels.push_back(ASCIIToUTF16("* Home Phone"));
1562 names.push_back(ASCIIToUTF16("areacode")); 1596 names.push_back(ASCIIToUTF16("areacode"));
1563 values.push_back(ASCIIToUTF16("415")); 1597 values.push_back(ASCIIToUTF16("415"));
1564 1598
1565 labels.push_back(ASCIIToUTF16("* Home Phone")); 1599 labels.push_back(ASCIIToUTF16("* Home Phone"));
1566 names.push_back(ASCIIToUTF16("prefix")); 1600 names.push_back(ASCIIToUTF16("prefix"));
1567 values.push_back(ASCIIToUTF16("555")); 1601 values.push_back(ASCIIToUTF16("555"));
1568 1602
(...skipping 14 matching lines...) Expand all
1583 " <INPUT type=\"text\" id=\"suffix\" value=\"1212\"/>" 1617 " <INPUT type=\"text\" id=\"suffix\" value=\"1212\"/>"
1584 " </LI>" 1618 " </LI>"
1585 " <LI>" 1619 " <LI>"
1586 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1620 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1587 " </LI>" 1621 " </LI>"
1588 "</DIV>" 1622 "</DIV>"
1589 "</FORM>", 1623 "</FORM>",
1590 labels, names, values); 1624 labels, names, values);
1591 } 1625 }
1592 1626
1593 TEST_F(FormManagerTest, LabelsInferredFromDefinitionList) { 1627 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionList) {
1594 std::vector<string16> labels, names, values; 1628 std::vector<string16> labels, names, values;
1595 1629
1596 labels.push_back(ASCIIToUTF16("* First name: Bogus")); 1630 labels.push_back(ASCIIToUTF16("* First name: Bogus"));
1597 names.push_back(ASCIIToUTF16("firstname")); 1631 names.push_back(ASCIIToUTF16("firstname"));
1598 values.push_back(ASCIIToUTF16("John")); 1632 values.push_back(ASCIIToUTF16("John"));
1599 1633
1600 labels.push_back(ASCIIToUTF16("Last name:")); 1634 labels.push_back(ASCIIToUTF16("Last name:"));
1601 names.push_back(ASCIIToUTF16("lastname")); 1635 names.push_back(ASCIIToUTF16("lastname"));
1602 values.push_back(ASCIIToUTF16("Smith")); 1636 values.push_back(ASCIIToUTF16("Smith"));
1603 1637
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 " </DD>" 1680 " </DD>"
1647 " <DT></DT>" 1681 " <DT></DT>"
1648 " <DD>" 1682 " <DD>"
1649 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1683 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1650 " </DD>" 1684 " </DD>"
1651 "</DL>" 1685 "</DL>"
1652 "</FORM>", 1686 "</FORM>",
1653 labels, names, values); 1687 labels, names, values);
1654 } 1688 }
1655 1689
1656 TEST_F(FormManagerTest, LabelsInferredWithSameName) { 1690 TEST_F(FormAutofillTest, LabelsInferredWithSameName) {
1657 std::vector<string16> labels, names, values; 1691 std::vector<string16> labels, names, values;
1658 1692
1659 labels.push_back(ASCIIToUTF16("Address Line 1:")); 1693 labels.push_back(ASCIIToUTF16("Address Line 1:"));
1660 names.push_back(ASCIIToUTF16("Address")); 1694 names.push_back(ASCIIToUTF16("Address"));
1661 values.push_back(string16()); 1695 values.push_back(string16());
1662 1696
1663 labels.push_back(ASCIIToUTF16("Address Line 2:")); 1697 labels.push_back(ASCIIToUTF16("Address Line 2:"));
1664 names.push_back(ASCIIToUTF16("Address")); 1698 names.push_back(ASCIIToUTF16("Address"));
1665 values.push_back(string16()); 1699 values.push_back(string16());
1666 1700
1667 labels.push_back(ASCIIToUTF16("Address Line 3:")); 1701 labels.push_back(ASCIIToUTF16("Address Line 3:"));
1668 names.push_back(ASCIIToUTF16("Address")); 1702 names.push_back(ASCIIToUTF16("Address"));
1669 values.push_back(string16()); 1703 values.push_back(string16());
1670 1704
1671 ExpectLabels( 1705 ExpectLabels(
1672 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1706 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1673 " Address Line 1:" 1707 " Address Line 1:"
1674 " <INPUT type=\"text\" name=\"Address\"/>" 1708 " <INPUT type=\"text\" name=\"Address\"/>"
1675 " Address Line 2:" 1709 " Address Line 2:"
1676 " <INPUT type=\"text\" name=\"Address\"/>" 1710 " <INPUT type=\"text\" name=\"Address\"/>"
1677 " Address Line 3:" 1711 " Address Line 3:"
1678 " <INPUT type=\"text\" name=\"Address\"/>" 1712 " <INPUT type=\"text\" name=\"Address\"/>"
1679 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1713 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1680 "</FORM>", 1714 "</FORM>",
1681 labels, names, values); 1715 labels, names, values);
1682 } 1716 }
1683 1717
1684 TEST_F(FormManagerTest, LabelsInferredWithImageTags) { 1718 TEST_F(FormAutofillTest, LabelsInferredWithImageTags) {
1685 std::vector<string16> labels, names, values; 1719 std::vector<string16> labels, names, values;
1686 1720
1687 labels.push_back(ASCIIToUTF16("Phone:")); 1721 labels.push_back(ASCIIToUTF16("Phone:"));
1688 names.push_back(ASCIIToUTF16("dayphone1")); 1722 names.push_back(ASCIIToUTF16("dayphone1"));
1689 values.push_back(string16()); 1723 values.push_back(string16());
1690 1724
1691 labels.push_back(ASCIIToUTF16("-")); 1725 labels.push_back(ASCIIToUTF16("-"));
1692 names.push_back(ASCIIToUTF16("dayphone2")); 1726 names.push_back(ASCIIToUTF16("dayphone2"));
1693 values.push_back(string16()); 1727 values.push_back(string16());
1694 1728
(...skipping 22 matching lines...) Expand all
1717 " <img/>" 1751 " <img/>"
1718 " <input type=\"text\" name=\"dayphone3\">" 1752 " <input type=\"text\" name=\"dayphone3\">"
1719 " ext.:" 1753 " ext.:"
1720 " <input type=\"text\" name=\"dayphone4\">" 1754 " <input type=\"text\" name=\"dayphone4\">"
1721 " <input type=\"text\" name=\"dummy\">" 1755 " <input type=\"text\" name=\"dummy\">"
1722 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" 1756 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
1723 "</FORM>", 1757 "</FORM>",
1724 labels, names, values); 1758 labels, names, values);
1725 } 1759 }
1726 1760
1727 TEST_F(FormManagerTest, LabelsInferredFromDivTable) { 1761 TEST_F(FormAutofillTest, LabelsInferredFromDivTable) {
1728 ExpectJohnSmithLabels( 1762 ExpectJohnSmithLabels(
1729 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1763 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1730 "<DIV>First name:<BR>" 1764 "<DIV>First name:<BR>"
1731 " <SPAN>" 1765 " <SPAN>"
1732 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">" 1766 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
1733 " </SPAN>" 1767 " </SPAN>"
1734 "</DIV>" 1768 "</DIV>"
1735 "<DIV>Last name:<BR>" 1769 "<DIV>Last name:<BR>"
1736 " <SPAN>" 1770 " <SPAN>"
1737 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">" 1771 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
1738 " </SPAN>" 1772 " </SPAN>"
1739 "</DIV>" 1773 "</DIV>"
1740 "<DIV>Email:<BR>" 1774 "<DIV>Email:<BR>"
1741 " <SPAN>" 1775 " <SPAN>"
1742 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">" 1776 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
1743 " </SPAN>" 1777 " </SPAN>"
1744 "</DIV>" 1778 "</DIV>"
1745 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">" 1779 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
1746 "</FORM>"); 1780 "</FORM>");
1747 } 1781 }
1748 1782
1749 TEST_F(FormManagerTest, LabelsInferredFromDivSiblingTable) { 1783 TEST_F(FormAutofillTest, LabelsInferredFromDivSiblingTable) {
1750 ExpectJohnSmithLabels( 1784 ExpectJohnSmithLabels(
1751 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1785 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1752 "<DIV>First name:</DIV>" 1786 "<DIV>First name:</DIV>"
1753 "<DIV>" 1787 "<DIV>"
1754 " <SPAN>" 1788 " <SPAN>"
1755 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">" 1789 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
1756 " </SPAN>" 1790 " </SPAN>"
1757 "</DIV>" 1791 "</DIV>"
1758 "<DIV>Last name:</DIV>" 1792 "<DIV>Last name:</DIV>"
1759 "<DIV>" 1793 "<DIV>"
1760 " <SPAN>" 1794 " <SPAN>"
1761 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">" 1795 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
1762 " </SPAN>" 1796 " </SPAN>"
1763 "</DIV>" 1797 "</DIV>"
1764 "<DIV>Email:</DIV>" 1798 "<DIV>Email:</DIV>"
1765 "<DIV>" 1799 "<DIV>"
1766 " <SPAN>" 1800 " <SPAN>"
1767 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">" 1801 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
1768 " </SPAN>" 1802 " </SPAN>"
1769 "</DIV>" 1803 "</DIV>"
1770 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">" 1804 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
1771 "</FORM>"); 1805 "</FORM>");
1772 } 1806 }
1773 1807
1774 TEST_F(FormManagerTest, LabelsInferredFromDefinitionListRatherThanDivTable) { 1808 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionListRatherThanDivTable) {
1775 ExpectJohnSmithLabels( 1809 ExpectJohnSmithLabels(
1776 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1810 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1777 "<DIV>This is not a label.<BR>" 1811 "<DIV>This is not a label.<BR>"
1778 "<DL>" 1812 "<DL>"
1779 " <DT>" 1813 " <DT>"
1780 " <SPAN>" 1814 " <SPAN>"
1781 " First name:" 1815 " First name:"
1782 " </SPAN>" 1816 " </SPAN>"
1783 " </DT>" 1817 " </DT>"
1784 " <DD>" 1818 " <DD>"
(...skipping 23 matching lines...) Expand all
1808 " </DD>" 1842 " </DD>"
1809 " <DT></DT>" 1843 " <DT></DT>"
1810 " <DD>" 1844 " <DD>"
1811 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1845 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1812 " </DD>" 1846 " </DD>"
1813 "</DL>" 1847 "</DL>"
1814 "</DIV>" 1848 "</DIV>"
1815 "</FORM>"); 1849 "</FORM>");
1816 } 1850 }
1817 1851
1818 TEST_F(FormManagerTest, FillFormMaxLength) { 1852 TEST_F(FormAutofillTest, FillFormMaxLength) {
1819 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1853 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1820 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>" 1854 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>"
1821 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>" 1855 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>"
1822 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>" 1856 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>"
1823 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1857 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1824 "</FORM>"); 1858 "</FORM>");
1825 1859
1826 WebFrame* web_frame = GetMainFrame(); 1860 WebFrame* web_frame = GetMainFrame();
1827 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1861 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1828 1862
1829 FormCache form_cache; 1863 FormCache form_cache;
1830 std::vector<FormData> forms; 1864 std::vector<FormData> forms;
1831 form_cache.ExtractForms(*web_frame, &forms); 1865 form_cache.ExtractForms(*web_frame, &forms);
1832 ASSERT_EQ(1U, forms.size()); 1866 ASSERT_EQ(1U, forms.size());
1833 1867
1834 // Get the input element we want to find. 1868 // Get the input element we want to find.
1835 WebElement element = web_frame->document().getElementById("firstname"); 1869 WebElement element = web_frame->document().getElementById("firstname");
1836 WebInputElement input_element = element.to<WebInputElement>(); 1870 WebInputElement input_element = element.to<WebInputElement>();
1837 1871
1838 // Find the form that contains the input element. 1872 // Find the form that contains the input element.
1839 FormData form; 1873 FormData form;
1840 FormField field; 1874 FormField field;
1841 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 1875 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
1842 &field)); 1876 autofill::REQUIRE_NONE));
1843 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 1877 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1844 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 1878 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1845 EXPECT_EQ(GURL("http://buh.com"), form.action); 1879 EXPECT_EQ(GURL("http://buh.com"), form.action);
1846 1880
1847 const std::vector<FormField>& fields = form.fields; 1881 const std::vector<FormField>& fields = form.fields;
1848 ASSERT_EQ(3U, fields.size()); 1882 ASSERT_EQ(3U, fields.size());
1849 1883
1850 FormField expected; 1884 FormField expected;
1851 expected.form_control_type = ASCIIToUTF16("text"); 1885 expected.form_control_type = ASCIIToUTF16("text");
1852 1886
(...skipping 14 matching lines...) Expand all
1867 1901
1868 // Fill the form. 1902 // Fill the form.
1869 form.fields[0].value = ASCIIToUTF16("Brother"); 1903 form.fields[0].value = ASCIIToUTF16("Brother");
1870 form.fields[1].value = ASCIIToUTF16("Jonathan"); 1904 form.fields[1].value = ASCIIToUTF16("Jonathan");
1871 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); 1905 form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
1872 FillForm(form, input_element); 1906 FillForm(form, input_element);
1873 1907
1874 // Find the newly-filled form that contains the input element. 1908 // Find the newly-filled form that contains the input element.
1875 FormData form2; 1909 FormData form2;
1876 FormField field2; 1910 FormField field2;
1877 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form2, 1911 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
1878 &field2)); 1912 autofill::REQUIRE_NONE));
1879 1913
1880 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 1914 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1881 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 1915 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
1882 EXPECT_EQ(GURL("http://buh.com"), form2.action); 1916 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1883 1917
1884 const std::vector<FormField>& fields2 = form2.fields; 1918 const std::vector<FormField>& fields2 = form2.fields;
1885 ASSERT_EQ(3U, fields2.size()); 1919 ASSERT_EQ(3U, fields2.size());
1886 1920
1887 expected.form_control_type = ASCIIToUTF16("text"); 1921 expected.form_control_type = ASCIIToUTF16("text");
1888 1922
(...skipping 12 matching lines...) Expand all
1901 expected.name = ASCIIToUTF16("email"); 1935 expected.name = ASCIIToUTF16("email");
1902 expected.value = ASCIIToUTF16("brotherj@"); 1936 expected.value = ASCIIToUTF16("brotherj@");
1903 expected.max_length = 9; 1937 expected.max_length = 9;
1904 expected.is_autofilled = true; 1938 expected.is_autofilled = true;
1905 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); 1939 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
1906 } 1940 }
1907 1941
1908 // This test uses negative values of the maxlength attribute for input elements. 1942 // This test uses negative values of the maxlength attribute for input elements.
1909 // In this case, the maxlength of the input elements is set to the default 1943 // In this case, the maxlength of the input elements is set to the default
1910 // maxlength (defined in WebKit.) 1944 // maxlength (defined in WebKit.)
1911 TEST_F(FormManagerTest, FillFormNegativeMaxLength) { 1945 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
1912 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 1946 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1913 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" 1947 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>"
1914 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" 1948 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
1915 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" 1949 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>"
1916 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1950 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1917 "</FORM>"); 1951 "</FORM>");
1918 1952
1919 WebFrame* web_frame = GetMainFrame(); 1953 WebFrame* web_frame = GetMainFrame();
1920 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1954 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1921 1955
1922 FormCache form_cache; 1956 FormCache form_cache;
1923 std::vector<FormData> forms; 1957 std::vector<FormData> forms;
1924 form_cache.ExtractForms(*web_frame, &forms); 1958 form_cache.ExtractForms(*web_frame, &forms);
1925 ASSERT_EQ(1U, forms.size()); 1959 ASSERT_EQ(1U, forms.size());
1926 1960
1927 // Get the input element we want to find. 1961 // Get the input element we want to find.
1928 WebElement element = web_frame->document().getElementById("firstname"); 1962 WebElement element = web_frame->document().getElementById("firstname");
1929 WebInputElement input_element = element.to<WebInputElement>(); 1963 WebInputElement input_element = element.to<WebInputElement>();
1930 1964
1931 // Find the form that contains the input element. 1965 // Find the form that contains the input element.
1932 FormData form; 1966 FormData form;
1933 FormField field; 1967 FormField field;
1934 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 1968 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
1935 &field)); 1969 autofill::REQUIRE_NONE));
1936 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 1970 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1937 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 1971 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
1938 EXPECT_EQ(GURL("http://buh.com"), form.action); 1972 EXPECT_EQ(GURL("http://buh.com"), form.action);
1939 1973
1940 const std::vector<FormField>& fields = form.fields; 1974 const std::vector<FormField>& fields = form.fields;
1941 ASSERT_EQ(3U, fields.size()); 1975 ASSERT_EQ(3U, fields.size());
1942 1976
1943 FormField expected; 1977 FormField expected;
1944 expected.form_control_type = ASCIIToUTF16("text"); 1978 expected.form_control_type = ASCIIToUTF16("text");
1945 expected.max_length = WebInputElement::defaultMaxLength(); 1979 expected.max_length = WebInputElement::defaultMaxLength();
1946 1980
1947 expected.name = ASCIIToUTF16("firstname"); 1981 expected.name = ASCIIToUTF16("firstname");
1948 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); 1982 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]);
1949 1983
1950 expected.name = ASCIIToUTF16("lastname"); 1984 expected.name = ASCIIToUTF16("lastname");
1951 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 1985 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
1952 1986
1953 expected.name = ASCIIToUTF16("email"); 1987 expected.name = ASCIIToUTF16("email");
1954 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 1988 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
1955 1989
1956 // Fill the form. 1990 // Fill the form.
1957 form.fields[0].value = ASCIIToUTF16("Brother"); 1991 form.fields[0].value = ASCIIToUTF16("Brother");
1958 form.fields[1].value = ASCIIToUTF16("Jonathan"); 1992 form.fields[1].value = ASCIIToUTF16("Jonathan");
1959 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); 1993 form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
1960 FillForm(form, input_element); 1994 FillForm(form, input_element);
1961 1995
1962 // Find the newly-filled form that contains the input element. 1996 // Find the newly-filled form that contains the input element.
1963 FormData form2; 1997 FormData form2;
1964 FormField field2; 1998 FormField field2;
1965 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form2, 1999 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
1966 &field2)); 2000 autofill::REQUIRE_NONE));
1967 2001
1968 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 2002 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
1969 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2003 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
1970 EXPECT_EQ(GURL("http://buh.com"), form2.action); 2004 EXPECT_EQ(GURL("http://buh.com"), form2.action);
1971 2005
1972 const std::vector<FormField>& fields2 = form2.fields; 2006 const std::vector<FormField>& fields2 = form2.fields;
1973 ASSERT_EQ(3U, fields2.size()); 2007 ASSERT_EQ(3U, fields2.size());
1974 2008
1975 expected.name = ASCIIToUTF16("firstname"); 2009 expected.name = ASCIIToUTF16("firstname");
1976 expected.value = ASCIIToUTF16("Brother"); 2010 expected.value = ASCIIToUTF16("Brother");
1977 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); 2011 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]);
1978 2012
1979 expected.name = ASCIIToUTF16("lastname"); 2013 expected.name = ASCIIToUTF16("lastname");
1980 expected.value = ASCIIToUTF16("Jonathan"); 2014 expected.value = ASCIIToUTF16("Jonathan");
1981 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 2015 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
1982 2016
1983 expected.name = ASCIIToUTF16("email"); 2017 expected.name = ASCIIToUTF16("email");
1984 expected.value = ASCIIToUTF16("brotherj@example.com"); 2018 expected.value = ASCIIToUTF16("brotherj@example.com");
1985 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 2019 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
1986 } 2020 }
1987 2021
1988 TEST_F(FormManagerTest, FillFormEmptyName) { 2022 TEST_F(FormAutofillTest, FillFormEmptyName) {
1989 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2023 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
1990 " <INPUT type=\"text\" id=\"firstname\"/>" 2024 " <INPUT type=\"text\" id=\"firstname\"/>"
1991 " <INPUT type=\"text\" id=\"lastname\"/>" 2025 " <INPUT type=\"text\" id=\"lastname\"/>"
1992 " <INPUT type=\"text\" id=\"email\"/>" 2026 " <INPUT type=\"text\" id=\"email\"/>"
1993 " <INPUT type=\"submit\" value=\"Send\"/>" 2027 " <INPUT type=\"submit\" value=\"Send\"/>"
1994 "</FORM>"); 2028 "</FORM>");
1995 2029
1996 WebFrame* web_frame = GetMainFrame(); 2030 WebFrame* web_frame = GetMainFrame();
1997 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2031 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1998 2032
1999 FormCache form_cache; 2033 FormCache form_cache;
2000 std::vector<FormData> forms; 2034 std::vector<FormData> forms;
2001 form_cache.ExtractForms(*web_frame, &forms); 2035 form_cache.ExtractForms(*web_frame, &forms);
2002 ASSERT_EQ(1U, forms.size()); 2036 ASSERT_EQ(1U, forms.size());
2003 2037
2004 // Get the input element we want to find. 2038 // Get the input element we want to find.
2005 WebElement element = web_frame->document().getElementById("firstname"); 2039 WebElement element = web_frame->document().getElementById("firstname");
2006 WebInputElement input_element = element.to<WebInputElement>(); 2040 WebInputElement input_element = element.to<WebInputElement>();
2007 2041
2008 // Find the form that contains the input element. 2042 // Find the form that contains the input element.
2009 FormData form; 2043 FormData form;
2010 FormField field; 2044 FormField field;
2011 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 2045 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
2012 &field)); 2046 autofill::REQUIRE_NONE));
2013 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 2047 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2014 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 2048 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2015 EXPECT_EQ(GURL("http://buh.com"), form.action); 2049 EXPECT_EQ(GURL("http://buh.com"), form.action);
2016 2050
2017 const std::vector<FormField>& fields = form.fields; 2051 const std::vector<FormField>& fields = form.fields;
2018 ASSERT_EQ(3U, fields.size()); 2052 ASSERT_EQ(3U, fields.size());
2019 2053
2020 FormField expected; 2054 FormField expected;
2021 expected.form_control_type = ASCIIToUTF16("text"); 2055 expected.form_control_type = ASCIIToUTF16("text");
2022 expected.max_length = WebInputElement::defaultMaxLength(); 2056 expected.max_length = WebInputElement::defaultMaxLength();
2023 2057
2024 expected.name = ASCIIToUTF16("firstname"); 2058 expected.name = ASCIIToUTF16("firstname");
2025 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); 2059 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]);
2026 2060
2027 expected.name = ASCIIToUTF16("lastname"); 2061 expected.name = ASCIIToUTF16("lastname");
2028 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 2062 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
2029 2063
2030 expected.name = ASCIIToUTF16("email"); 2064 expected.name = ASCIIToUTF16("email");
2031 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 2065 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
2032 2066
2033 // Fill the form. 2067 // Fill the form.
2034 form.fields[0].value = ASCIIToUTF16("Wyatt"); 2068 form.fields[0].value = ASCIIToUTF16("Wyatt");
2035 form.fields[1].value = ASCIIToUTF16("Earp"); 2069 form.fields[1].value = ASCIIToUTF16("Earp");
2036 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); 2070 form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
2037 FillForm(form, input_element); 2071 FillForm(form, input_element);
2038 2072
2039 // Find the newly-filled form that contains the input element. 2073 // Find the newly-filled form that contains the input element.
2040 FormData form2; 2074 FormData form2;
2041 FormField field2; 2075 FormField field2;
2042 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form2, 2076 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
2043 &field2)); 2077 autofill::REQUIRE_NONE));
2044 2078
2045 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 2079 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2046 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2080 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2047 EXPECT_EQ(GURL("http://buh.com"), form2.action); 2081 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2048 2082
2049 const std::vector<FormField>& fields2 = form2.fields; 2083 const std::vector<FormField>& fields2 = form2.fields;
2050 ASSERT_EQ(3U, fields2.size()); 2084 ASSERT_EQ(3U, fields2.size());
2051 2085
2052 expected.form_control_type = ASCIIToUTF16("text"); 2086 expected.form_control_type = ASCIIToUTF16("text");
2053 expected.max_length = WebInputElement::defaultMaxLength(); 2087 expected.max_length = WebInputElement::defaultMaxLength();
2054 2088
2055 expected.name = ASCIIToUTF16("firstname"); 2089 expected.name = ASCIIToUTF16("firstname");
2056 expected.value = ASCIIToUTF16("Wyatt"); 2090 expected.value = ASCIIToUTF16("Wyatt");
2057 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); 2091 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]);
2058 2092
2059 expected.name = ASCIIToUTF16("lastname"); 2093 expected.name = ASCIIToUTF16("lastname");
2060 expected.value = ASCIIToUTF16("Earp"); 2094 expected.value = ASCIIToUTF16("Earp");
2061 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 2095 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
2062 2096
2063 expected.name = ASCIIToUTF16("email"); 2097 expected.name = ASCIIToUTF16("email");
2064 expected.value = ASCIIToUTF16("wyatt@example.com"); 2098 expected.value = ASCIIToUTF16("wyatt@example.com");
2065 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 2099 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
2066 } 2100 }
2067 2101
2068 TEST_F(FormManagerTest, FillFormEmptyFormNames) { 2102 TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
2069 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" 2103 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">"
2070 " <INPUT type=\"text\" id=\"firstname\"/>" 2104 " <INPUT type=\"text\" id=\"firstname\"/>"
2071 " <INPUT type=\"text\" id=\"middlename\"/>" 2105 " <INPUT type=\"text\" id=\"middlename\"/>"
2072 " <INPUT type=\"text\" id=\"lastname\"/>" 2106 " <INPUT type=\"text\" id=\"lastname\"/>"
2073 " <INPUT type=\"submit\" value=\"Send\"/>" 2107 " <INPUT type=\"submit\" value=\"Send\"/>"
2074 "</FORM>" 2108 "</FORM>"
2075 "<FORM action=\"http://abc.com\" method=\"post\">" 2109 "<FORM action=\"http://abc.com\" method=\"post\">"
2076 " <INPUT type=\"text\" id=\"apple\"/>" 2110 " <INPUT type=\"text\" id=\"apple\"/>"
2077 " <INPUT type=\"text\" id=\"banana\"/>" 2111 " <INPUT type=\"text\" id=\"banana\"/>"
2078 " <INPUT type=\"text\" id=\"cantelope\"/>" 2112 " <INPUT type=\"text\" id=\"cantelope\"/>"
2079 " <INPUT type=\"submit\" value=\"Send\"/>" 2113 " <INPUT type=\"submit\" value=\"Send\"/>"
2080 "</FORM>"); 2114 "</FORM>");
2081 2115
2082 WebFrame* web_frame = GetMainFrame(); 2116 WebFrame* web_frame = GetMainFrame();
2083 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2117 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2084 2118
2085 FormCache form_cache; 2119 FormCache form_cache;
2086 std::vector<FormData> forms; 2120 std::vector<FormData> forms;
2087 form_cache.ExtractForms(*web_frame, &forms); 2121 form_cache.ExtractForms(*web_frame, &forms);
2088 ASSERT_EQ(2U, forms.size()); 2122 ASSERT_EQ(2U, forms.size());
2089 2123
2090 // Get the input element we want to find. 2124 // Get the input element we want to find.
2091 WebElement element = web_frame->document().getElementById("apple"); 2125 WebElement element = web_frame->document().getElementById("apple");
2092 WebInputElement input_element = element.to<WebInputElement>(); 2126 WebInputElement input_element = element.to<WebInputElement>();
2093 2127
2094 // Find the form that contains the input element. 2128 // Find the form that contains the input element.
2095 FormData form; 2129 FormData form;
2096 FormField field; 2130 FormField field;
2097 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 2131 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
2098 &field)); 2132 autofill::REQUIRE_NONE));
2099 EXPECT_EQ(string16(), form.name); 2133 EXPECT_EQ(string16(), form.name);
2100 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 2134 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2101 EXPECT_EQ(GURL("http://abc.com"), form.action); 2135 EXPECT_EQ(GURL("http://abc.com"), form.action);
2102 2136
2103 const std::vector<FormField>& fields = form.fields; 2137 const std::vector<FormField>& fields = form.fields;
2104 ASSERT_EQ(3U, fields.size()); 2138 ASSERT_EQ(3U, fields.size());
2105 2139
2106 FormField expected; 2140 FormField expected;
2107 expected.form_control_type = ASCIIToUTF16("text"); 2141 expected.form_control_type = ASCIIToUTF16("text");
2108 expected.max_length = WebInputElement::defaultMaxLength(); 2142 expected.max_length = WebInputElement::defaultMaxLength();
(...skipping 12 matching lines...) Expand all
2121 2155
2122 // Fill the form. 2156 // Fill the form.
2123 form.fields[0].value = ASCIIToUTF16("Red"); 2157 form.fields[0].value = ASCIIToUTF16("Red");
2124 form.fields[1].value = ASCIIToUTF16("Yellow"); 2158 form.fields[1].value = ASCIIToUTF16("Yellow");
2125 form.fields[2].value = ASCIIToUTF16("Also Yellow"); 2159 form.fields[2].value = ASCIIToUTF16("Also Yellow");
2126 FillForm(form, input_element); 2160 FillForm(form, input_element);
2127 2161
2128 // Find the newly-filled form that contains the input element. 2162 // Find the newly-filled form that contains the input element.
2129 FormData form2; 2163 FormData form2;
2130 FormField field2; 2164 FormField field2;
2131 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form2, 2165 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
2132 &field2)); 2166 autofill::REQUIRE_NONE));
2133 2167
2134 EXPECT_EQ(string16(), form2.name); 2168 EXPECT_EQ(string16(), form2.name);
2135 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2169 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2136 EXPECT_EQ(GURL("http://abc.com"), form2.action); 2170 EXPECT_EQ(GURL("http://abc.com"), form2.action);
2137 2171
2138 const std::vector<FormField>& fields2 = form2.fields; 2172 const std::vector<FormField>& fields2 = form2.fields;
2139 ASSERT_EQ(3U, fields2.size()); 2173 ASSERT_EQ(3U, fields2.size());
2140 2174
2141 expected.name = ASCIIToUTF16("apple"); 2175 expected.name = ASCIIToUTF16("apple");
2142 expected.value = ASCIIToUTF16("Red"); 2176 expected.value = ASCIIToUTF16("Red");
2143 expected.is_autofilled = true; 2177 expected.is_autofilled = true;
2144 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); 2178 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]);
2145 2179
2146 expected.name = ASCIIToUTF16("banana"); 2180 expected.name = ASCIIToUTF16("banana");
2147 expected.value = ASCIIToUTF16("Yellow"); 2181 expected.value = ASCIIToUTF16("Yellow");
2148 expected.is_autofilled = true; 2182 expected.is_autofilled = true;
2149 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); 2183 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]);
2150 2184
2151 expected.name = ASCIIToUTF16("cantelope"); 2185 expected.name = ASCIIToUTF16("cantelope");
2152 expected.value = ASCIIToUTF16("Also Yellow"); 2186 expected.value = ASCIIToUTF16("Also Yellow");
2153 expected.is_autofilled = true; 2187 expected.is_autofilled = true;
2154 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); 2188 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
2155 } 2189 }
2156 2190
2157 TEST_F(FormManagerTest, ThreePartPhone) { 2191 TEST_F(FormAutofillTest, ThreePartPhone) {
2158 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 2192 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2159 " Phone:" 2193 " Phone:"
2160 " <input type=\"text\" name=\"dayphone1\">" 2194 " <input type=\"text\" name=\"dayphone1\">"
2161 " -" 2195 " -"
2162 " <input type=\"text\" name=\"dayphone2\">" 2196 " <input type=\"text\" name=\"dayphone2\">"
2163 " -" 2197 " -"
2164 " <input type=\"text\" name=\"dayphone3\">" 2198 " <input type=\"text\" name=\"dayphone3\">"
2165 " ext.:" 2199 " ext.:"
2166 " <input type=\"text\" name=\"dayphone4\">" 2200 " <input type=\"text\" name=\"dayphone4\">"
2167 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" 2201 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 expected.label = ASCIIToUTF16("-"); 2238 expected.label = ASCIIToUTF16("-");
2205 expected.name = ASCIIToUTF16("dayphone3"); 2239 expected.name = ASCIIToUTF16("dayphone3");
2206 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 2240 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
2207 2241
2208 expected.label = ASCIIToUTF16("ext.:"); 2242 expected.label = ASCIIToUTF16("ext.:");
2209 expected.name = ASCIIToUTF16("dayphone4"); 2243 expected.name = ASCIIToUTF16("dayphone4");
2210 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); 2244 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]);
2211 } 2245 }
2212 2246
2213 2247
2214 TEST_F(FormManagerTest, MaxLengthFields) { 2248 TEST_F(FormAutofillTest, MaxLengthFields) {
2215 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 2249 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2216 " Phone:" 2250 " Phone:"
2217 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" 2251 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">"
2218 " -" 2252 " -"
2219 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" 2253 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">"
2220 " -" 2254 " -"
2221 " <input type=\"text\" maxlength=\"4\" size=\"5\"" 2255 " <input type=\"text\" maxlength=\"4\" size=\"5\""
2222 " name=\"dayphone3\">" 2256 " name=\"dayphone3\">"
2223 " ext.:" 2257 " ext.:"
2224 " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">" 2258 " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 // When invalid |size|, default is returned. 2314 // When invalid |size|, default is returned.
2281 expected.label = string16(); 2315 expected.label = string16();
2282 expected.name = ASCIIToUTF16("invalid1"); 2316 expected.name = ASCIIToUTF16("invalid1");
2283 expected.max_length = WebInputElement::defaultMaxLength(); 2317 expected.max_length = WebInputElement::defaultMaxLength();
2284 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); 2318 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]);
2285 } 2319 }
2286 2320
2287 // This test re-creates the experience of typing in a field then selecting a 2321 // This test re-creates the experience of typing in a field then selecting a
2288 // profile from the Autofill suggestions popup. The field that is being typed 2322 // profile from the Autofill suggestions popup. The field that is being typed
2289 // into should be filled even though it's not technically empty. 2323 // into should be filled even though it's not technically empty.
2290 TEST_F(FormManagerTest, FillFormNonEmptyField) { 2324 TEST_F(FormAutofillTest, FillFormNonEmptyField) {
2291 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2325 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2292 " <INPUT type=\"text\" id=\"firstname\"/>" 2326 " <INPUT type=\"text\" id=\"firstname\"/>"
2293 " <INPUT type=\"text\" id=\"lastname\"/>" 2327 " <INPUT type=\"text\" id=\"lastname\"/>"
2294 " <INPUT type=\"text\" id=\"email\"/>" 2328 " <INPUT type=\"text\" id=\"email\"/>"
2295 " <INPUT type=\"submit\" value=\"Send\"/>" 2329 " <INPUT type=\"submit\" value=\"Send\"/>"
2296 "</FORM>"); 2330 "</FORM>");
2297 2331
2298 WebFrame* web_frame = GetMainFrame(); 2332 WebFrame* web_frame = GetMainFrame();
2299 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2333 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2300 2334
2301 FormCache form_cache; 2335 FormCache form_cache;
2302 std::vector<FormData> forms; 2336 std::vector<FormData> forms;
2303 form_cache.ExtractForms(*web_frame, &forms); 2337 form_cache.ExtractForms(*web_frame, &forms);
2304 ASSERT_EQ(1U, forms.size()); 2338 ASSERT_EQ(1U, forms.size());
2305 2339
2306 // Get the input element we want to find. 2340 // Get the input element we want to find.
2307 WebElement element = web_frame->document().getElementById("firstname"); 2341 WebElement element = web_frame->document().getElementById("firstname");
2308 WebInputElement input_element = element.to<WebInputElement>(); 2342 WebInputElement input_element = element.to<WebInputElement>();
2309 2343
2310 // Simulate typing by modifying the field value. 2344 // Simulate typing by modifying the field value.
2311 input_element.setValue(ASCIIToUTF16("Wy")); 2345 input_element.setValue(ASCIIToUTF16("Wy"));
2312 2346
2313 // Find the form that contains the input element. 2347 // Find the form that contains the input element.
2314 FormData form; 2348 FormData form;
2315 FormField field; 2349 FormField field;
2316 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form, 2350 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
2317 &field)); 2351 autofill::REQUIRE_NONE));
2318 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 2352 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
2319 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 2353 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
2320 EXPECT_EQ(GURL("http://buh.com"), form.action); 2354 EXPECT_EQ(GURL("http://buh.com"), form.action);
2321 2355
2322 const std::vector<FormField>& fields = form.fields; 2356 const std::vector<FormField>& fields = form.fields;
2323 ASSERT_EQ(3U, fields.size()); 2357 ASSERT_EQ(3U, fields.size());
2324 2358
2325 FormField expected; 2359 FormField expected;
2326 expected.form_control_type = ASCIIToUTF16("text"); 2360 expected.form_control_type = ASCIIToUTF16("text");
2327 expected.max_length = WebInputElement::defaultMaxLength(); 2361 expected.max_length = WebInputElement::defaultMaxLength();
(...skipping 20 matching lines...) Expand all
2348 PreviewForm(form, input_element); 2382 PreviewForm(form, input_element);
2349 EXPECT_EQ(2, input_element.selectionStart()); 2383 EXPECT_EQ(2, input_element.selectionStart());
2350 EXPECT_EQ(5, input_element.selectionEnd()); 2384 EXPECT_EQ(5, input_element.selectionEnd());
2351 2385
2352 // Fill the form. 2386 // Fill the form.
2353 FillForm(form, input_element); 2387 FillForm(form, input_element);
2354 2388
2355 // Find the newly-filled form that contains the input element. 2389 // Find the newly-filled form that contains the input element.
2356 FormData form2; 2390 FormData form2;
2357 FormField field2; 2391 FormField field2;
2358 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form2, 2392 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
2359 &field2)); 2393 autofill::REQUIRE_NONE));
2360 2394
2361 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 2395 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2362 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2396 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2363 EXPECT_EQ(GURL("http://buh.com"), form2.action); 2397 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2364 2398
2365 const std::vector<FormField>& fields2 = form2.fields; 2399 const std::vector<FormField>& fields2 = form2.fields;
2366 ASSERT_EQ(3U, fields2.size()); 2400 ASSERT_EQ(3U, fields2.size());
2367 2401
2368 expected.name = ASCIIToUTF16("firstname"); 2402 expected.name = ASCIIToUTF16("firstname");
2369 expected.value = ASCIIToUTF16("Wyatt"); 2403 expected.value = ASCIIToUTF16("Wyatt");
2370 expected.is_autofilled = true; 2404 expected.is_autofilled = true;
2371 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); 2405 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]);
2372 2406
2373 expected.name = ASCIIToUTF16("lastname"); 2407 expected.name = ASCIIToUTF16("lastname");
2374 expected.value = ASCIIToUTF16("Earp"); 2408 expected.value = ASCIIToUTF16("Earp");
2375 expected.is_autofilled = true; 2409 expected.is_autofilled = true;
2376 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); 2410 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]);
2377 2411
2378 expected.name = ASCIIToUTF16("email"); 2412 expected.name = ASCIIToUTF16("email");
2379 expected.value = ASCIIToUTF16("wyatt@example.com"); 2413 expected.value = ASCIIToUTF16("wyatt@example.com");
2380 expected.is_autofilled = true; 2414 expected.is_autofilled = true;
2381 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); 2415 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
2382 2416
2383 // Verify that the cursor position has been updated. 2417 // Verify that the cursor position has been updated.
2384 EXPECT_EQ(5, input_element.selectionStart()); 2418 EXPECT_EQ(5, input_element.selectionStart());
2385 EXPECT_EQ(5, input_element.selectionEnd()); 2419 EXPECT_EQ(5, input_element.selectionEnd());
2386 } 2420 }
2387 2421
2388 TEST_F(FormManagerTest, ClearFormWithNode) { 2422 TEST_F(FormAutofillTest, ClearFormWithNode) {
2389 LoadHTML( 2423 LoadHTML(
2390 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2424 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2391 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" 2425 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2392 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" 2426 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
2393 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noAC\" value=\"one\"/>" 2427 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noAC\" value=\"one\"/>"
2394 " <INPUT type=\"text\" id=\"notenabled\" disabled=\"disabled\">" 2428 " <INPUT type=\"text\" id=\"notenabled\" disabled=\"disabled\">"
2395 " <INPUT type=\"submit\" value=\"Send\"/>" 2429 " <INPUT type=\"submit\" value=\"Send\"/>"
2396 "</FORM>"); 2430 "</FORM>");
2397 2431
2398 WebFrame* web_frame = GetMainFrame(); 2432 WebFrame* web_frame = GetMainFrame();
(...skipping 16 matching lines...) Expand all
2415 2449
2416 // Clear the form. 2450 // Clear the form.
2417 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); 2451 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
2418 2452
2419 // Verify that the auto-filled attribute has been turned off. 2453 // Verify that the auto-filled attribute has been turned off.
2420 EXPECT_FALSE(firstname.isAutofilled()); 2454 EXPECT_FALSE(firstname.isAutofilled());
2421 2455
2422 // Verify the form is cleared. 2456 // Verify the form is cleared.
2423 FormData form2; 2457 FormData form2;
2424 FormField field2; 2458 FormField field2;
2425 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, &form2, 2459 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2,
2426 &field2)); 2460 autofill::REQUIRE_NONE));
2427 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 2461 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2428 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2462 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2429 EXPECT_EQ(GURL("http://buh.com"), form2.action); 2463 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2430 2464
2431 const std::vector<FormField>& fields2 = form2.fields; 2465 const std::vector<FormField>& fields2 = form2.fields;
2432 ASSERT_EQ(4U, fields2.size()); 2466 ASSERT_EQ(4U, fields2.size());
2433 2467
2434 FormField expected; 2468 FormField expected;
2435 expected.form_control_type = ASCIIToUTF16("text"); 2469 expected.form_control_type = ASCIIToUTF16("text");
2436 expected.max_length = WebInputElement::defaultMaxLength(); 2470 expected.max_length = WebInputElement::defaultMaxLength();
(...skipping 12 matching lines...) Expand all
2449 2483
2450 expected.name = ASCIIToUTF16("notenabled"); 2484 expected.name = ASCIIToUTF16("notenabled");
2451 expected.value = ASCIIToUTF16("no clear"); 2485 expected.value = ASCIIToUTF16("no clear");
2452 EXPECT_FORM_FIELD_EQUALS(expected, fields2[3]); 2486 EXPECT_FORM_FIELD_EQUALS(expected, fields2[3]);
2453 2487
2454 // Verify that the cursor position has been updated. 2488 // Verify that the cursor position has been updated.
2455 EXPECT_EQ(0, firstname.selectionStart()); 2489 EXPECT_EQ(0, firstname.selectionStart());
2456 EXPECT_EQ(0, firstname.selectionEnd()); 2490 EXPECT_EQ(0, firstname.selectionEnd());
2457 } 2491 }
2458 2492
2459 TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) { 2493 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) {
2460 LoadHTML( 2494 LoadHTML(
2461 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2495 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2462 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" 2496 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2463 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" 2497 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
2464 " <SELECT id=\"state\" name=\"state\">" 2498 " <SELECT id=\"state\" name=\"state\">"
2465 " <OPTION selected>?</OPTION>" 2499 " <OPTION selected>?</OPTION>"
2466 " <OPTION>AA</OPTION>" 2500 " <OPTION>AA</OPTION>"
2467 " <OPTION>AE</OPTION>" 2501 " <OPTION>AE</OPTION>"
2468 " <OPTION>AK</OPTION>" 2502 " <OPTION>AK</OPTION>"
2469 " </SELECT>" 2503 " </SELECT>"
(...skipping 20 matching lines...) Expand all
2490 2524
2491 // Clear the form. 2525 // Clear the form.
2492 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); 2526 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
2493 2527
2494 // Verify that the auto-filled attribute has been turned off. 2528 // Verify that the auto-filled attribute has been turned off.
2495 EXPECT_FALSE(firstname.isAutofilled()); 2529 EXPECT_FALSE(firstname.isAutofilled());
2496 2530
2497 // Verify the form is cleared. 2531 // Verify the form is cleared.
2498 FormData form2; 2532 FormData form2;
2499 FormField field2; 2533 FormField field2;
2500 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, &form2, 2534 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2,
2501 &field2)); 2535 autofill::REQUIRE_NONE));
2502 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); 2536 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
2503 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); 2537 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
2504 EXPECT_EQ(GURL("http://buh.com"), form2.action); 2538 EXPECT_EQ(GURL("http://buh.com"), form2.action);
2505 2539
2506 const std::vector<FormField>& fields2 = form2.fields; 2540 const std::vector<FormField>& fields2 = form2.fields;
2507 ASSERT_EQ(3U, fields2.size()); 2541 ASSERT_EQ(3U, fields2.size());
2508 2542
2509 FormField expected; 2543 FormField expected;
2510 2544
2511 expected.name = ASCIIToUTF16("firstname"); 2545 expected.name = ASCIIToUTF16("firstname");
(...skipping 12 matching lines...) Expand all
2524 expected.value = ASCIIToUTF16("?"); 2558 expected.value = ASCIIToUTF16("?");
2525 expected.form_control_type = ASCIIToUTF16("select-one"); 2559 expected.form_control_type = ASCIIToUTF16("select-one");
2526 expected.max_length = 0; 2560 expected.max_length = 0;
2527 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); 2561 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]);
2528 2562
2529 // Verify that the cursor position has been updated. 2563 // Verify that the cursor position has been updated.
2530 EXPECT_EQ(0, firstname.selectionStart()); 2564 EXPECT_EQ(0, firstname.selectionStart());
2531 EXPECT_EQ(0, firstname.selectionEnd()); 2565 EXPECT_EQ(0, firstname.selectionEnd());
2532 } 2566 }
2533 2567
2534 TEST_F(FormManagerTest, ClearPreviewedFormWithElement) { 2568 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
2535 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2569 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2536 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" 2570 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2537 " <INPUT type=\"text\" id=\"lastname\"/>" 2571 " <INPUT type=\"text\" id=\"lastname\"/>"
2538 " <INPUT type=\"text\" id=\"email\"/>" 2572 " <INPUT type=\"text\" id=\"email\"/>"
2539 " <INPUT type=\"email\" id=\"email2\"/>" 2573 " <INPUT type=\"email\" id=\"email2\"/>"
2540 " <INPUT type=\"tel\" id=\"phone\"/>" 2574 " <INPUT type=\"tel\" id=\"phone\"/>"
2541 " <INPUT type=\"submit\" value=\"Send\"/>" 2575 " <INPUT type=\"submit\" value=\"Send\"/>"
2542 "</FORM>"); 2576 "</FORM>");
2543 2577
2544 WebFrame* web_frame = GetMainFrame(); 2578 WebFrame* web_frame = GetMainFrame();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 EXPECT_FALSE(email2.isAutofilled()); 2626 EXPECT_FALSE(email2.isAutofilled());
2593 EXPECT_TRUE(phone.value().isEmpty()); 2627 EXPECT_TRUE(phone.value().isEmpty());
2594 EXPECT_TRUE(phone.suggestedValue().isEmpty()); 2628 EXPECT_TRUE(phone.suggestedValue().isEmpty());
2595 EXPECT_FALSE(phone.isAutofilled()); 2629 EXPECT_FALSE(phone.isAutofilled());
2596 2630
2597 // Verify that the cursor position has been updated. 2631 // Verify that the cursor position has been updated.
2598 EXPECT_EQ(0, lastname.selectionStart()); 2632 EXPECT_EQ(0, lastname.selectionStart());
2599 EXPECT_EQ(0, lastname.selectionEnd()); 2633 EXPECT_EQ(0, lastname.selectionEnd());
2600 } 2634 }
2601 2635
2602 TEST_F(FormManagerTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { 2636 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
2603 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2637 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2604 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>" 2638 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
2605 " <INPUT type=\"text\" id=\"lastname\"/>" 2639 " <INPUT type=\"text\" id=\"lastname\"/>"
2606 " <INPUT type=\"text\" id=\"email\"/>" 2640 " <INPUT type=\"text\" id=\"email\"/>"
2607 " <INPUT type=\"email\" id=\"email2\"/>" 2641 " <INPUT type=\"email\" id=\"email2\"/>"
2608 " <INPUT type=\"tel\" id=\"phone\"/>" 2642 " <INPUT type=\"tel\" id=\"phone\"/>"
2609 " <INPUT type=\"submit\" value=\"Send\"/>" 2643 " <INPUT type=\"submit\" value=\"Send\"/>"
2610 "</FORM>"); 2644 "</FORM>");
2611 2645
2612 WebFrame* web_frame = GetMainFrame(); 2646 WebFrame* web_frame = GetMainFrame();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 EXPECT_TRUE(email.suggestedValue().isEmpty()); 2694 EXPECT_TRUE(email.suggestedValue().isEmpty());
2661 EXPECT_FALSE(email.isAutofilled()); 2695 EXPECT_FALSE(email.isAutofilled());
2662 EXPECT_TRUE(email2.value().isEmpty()); 2696 EXPECT_TRUE(email2.value().isEmpty());
2663 EXPECT_TRUE(email2.suggestedValue().isEmpty()); 2697 EXPECT_TRUE(email2.suggestedValue().isEmpty());
2664 EXPECT_FALSE(email2.isAutofilled()); 2698 EXPECT_FALSE(email2.isAutofilled());
2665 EXPECT_TRUE(phone.value().isEmpty()); 2699 EXPECT_TRUE(phone.value().isEmpty());
2666 EXPECT_TRUE(phone.suggestedValue().isEmpty()); 2700 EXPECT_TRUE(phone.suggestedValue().isEmpty());
2667 EXPECT_FALSE(phone.isAutofilled()); 2701 EXPECT_FALSE(phone.isAutofilled());
2668 } 2702 }
2669 2703
2670 TEST_F(FormManagerTest, ClearPreviewedFormWithAutofilledInitiatingNode) { 2704 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
2671 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2705 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2672 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>" 2706 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
2673 " <INPUT type=\"text\" id=\"lastname\"/>" 2707 " <INPUT type=\"text\" id=\"lastname\"/>"
2674 " <INPUT type=\"text\" id=\"email\"/>" 2708 " <INPUT type=\"text\" id=\"email\"/>"
2675 " <INPUT type=\"email\" id=\"email2\"/>" 2709 " <INPUT type=\"email\" id=\"email2\"/>"
2676 " <INPUT type=\"tel\" id=\"phone\"/>" 2710 " <INPUT type=\"tel\" id=\"phone\"/>"
2677 " <INPUT type=\"submit\" value=\"Send\"/>" 2711 " <INPUT type=\"submit\" value=\"Send\"/>"
2678 "</FORM>"); 2712 "</FORM>");
2679 2713
2680 WebFrame* web_frame = GetMainFrame(); 2714 WebFrame* web_frame = GetMainFrame();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 EXPECT_TRUE(email.suggestedValue().isEmpty()); 2761 EXPECT_TRUE(email.suggestedValue().isEmpty());
2728 EXPECT_FALSE(email.isAutofilled()); 2762 EXPECT_FALSE(email.isAutofilled());
2729 EXPECT_TRUE(email2.value().isEmpty()); 2763 EXPECT_TRUE(email2.value().isEmpty());
2730 EXPECT_TRUE(email2.suggestedValue().isEmpty()); 2764 EXPECT_TRUE(email2.suggestedValue().isEmpty());
2731 EXPECT_FALSE(email2.isAutofilled()); 2765 EXPECT_FALSE(email2.isAutofilled());
2732 EXPECT_TRUE(phone.value().isEmpty()); 2766 EXPECT_TRUE(phone.value().isEmpty());
2733 EXPECT_TRUE(phone.suggestedValue().isEmpty()); 2767 EXPECT_TRUE(phone.suggestedValue().isEmpty());
2734 EXPECT_FALSE(phone.isAutofilled()); 2768 EXPECT_FALSE(phone.isAutofilled());
2735 } 2769 }
2736 2770
2737 TEST_F(FormManagerTest, FormWithNodeIsAutofilled) { 2771 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) {
2738 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 2772 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2739 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" 2773 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2740 " <INPUT type=\"text\" id=\"lastname\"/>" 2774 " <INPUT type=\"text\" id=\"lastname\"/>"
2741 " <INPUT type=\"text\" id=\"email\"/>" 2775 " <INPUT type=\"text\" id=\"email\"/>"
2742 " <INPUT type=\"email\" id=\"email2\"/>" 2776 " <INPUT type=\"email\" id=\"email2\"/>"
2743 " <INPUT type=\"tel\" id=\"phone\"/>" 2777 " <INPUT type=\"tel\" id=\"phone\"/>"
2744 " <INPUT type=\"submit\" value=\"Send\"/>" 2778 " <INPUT type=\"submit\" value=\"Send\"/>"
2745 "</FORM>"); 2779 "</FORM>");
2746 2780
2747 WebFrame* web_frame = GetMainFrame(); 2781 WebFrame* web_frame = GetMainFrame();
(...skipping 10 matching lines...) Expand all
2758 // Auto-filled attribute not set yet. 2792 // Auto-filled attribute not set yet.
2759 EXPECT_FALSE(FormWithElementIsAutofilled(firstname)); 2793 EXPECT_FALSE(FormWithElementIsAutofilled(firstname));
2760 2794
2761 // Set the auto-filled attribute. 2795 // Set the auto-filled attribute.
2762 firstname.setAutofilled(true); 2796 firstname.setAutofilled(true);
2763 2797
2764 EXPECT_TRUE(FormWithElementIsAutofilled(firstname)); 2798 EXPECT_TRUE(FormWithElementIsAutofilled(firstname));
2765 } 2799 }
2766 2800
2767 // If we have multiple labels per id, the labels concatenated into label string. 2801 // If we have multiple labels per id, the labels concatenated into label string.
2768 TEST_F(FormManagerTest, MultipleLabelsPerElement) { 2802 TEST_F(FormAutofillTest, MultipleLabelsPerElement) {
2769 std::vector<string16> labels, names, values; 2803 std::vector<string16> labels, names, values;
2770 2804
2771 labels.push_back(ASCIIToUTF16("First Name:")); 2805 labels.push_back(ASCIIToUTF16("First Name:"));
2772 names.push_back(ASCIIToUTF16("firstname")); 2806 names.push_back(ASCIIToUTF16("firstname"));
2773 values.push_back(ASCIIToUTF16("John")); 2807 values.push_back(ASCIIToUTF16("John"));
2774 2808
2775 labels.push_back(ASCIIToUTF16("Last Name:")); 2809 labels.push_back(ASCIIToUTF16("Last Name:"));
2776 names.push_back(ASCIIToUTF16("lastname")); 2810 names.push_back(ASCIIToUTF16("lastname"));
2777 values.push_back(ASCIIToUTF16("Smith")); 2811 values.push_back(ASCIIToUTF16("Smith"));
2778 2812
(...skipping 10 matching lines...) Expand all
2789 " <LABEL for=\"lastname\"> Last Name: </LABEL>" 2823 " <LABEL for=\"lastname\"> Last Name: </LABEL>"
2790 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 2824 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2791 " <LABEL for=\"email\"> Email: </LABEL>" 2825 " <LABEL for=\"email\"> Email: </LABEL>"
2792 " <LABEL for=\"email\"> xxx@yyy.com </LABEL>" 2826 " <LABEL for=\"email\"> xxx@yyy.com </LABEL>"
2793 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" 2827 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
2794 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2828 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2795 "</FORM>", 2829 "</FORM>",
2796 labels, names, values); 2830 labels, names, values);
2797 } 2831 }
2798 2832
2799 TEST_F(FormManagerTest, SelectOneAsText) { 2833 TEST_F(FormAutofillTest, SelectOneAsText) {
2800 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 2834 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
2801 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 2835 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
2802 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 2836 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
2803 " <SELECT id=\"country\">" 2837 " <SELECT id=\"country\">"
2804 " <OPTION value=\"AF\">Afghanistan</OPTION>" 2838 " <OPTION value=\"AF\">Afghanistan</OPTION>"
2805 " <OPTION value=\"AL\">Albania</OPTION>" 2839 " <OPTION value=\"AL\">Albania</OPTION>"
2806 " <OPTION value=\"DZ\">Algeria</OPTION>" 2840 " <OPTION value=\"DZ\">Algeria</OPTION>"
2807 " </SELECT>" 2841 " </SELECT>"
2808 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2842 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2809 "</FORM>"); 2843 "</FORM>");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 expected.form_control_type = ASCIIToUTF16("text"); 2914 expected.form_control_type = ASCIIToUTF16("text");
2881 expected.max_length = WebInputElement::defaultMaxLength(); 2915 expected.max_length = WebInputElement::defaultMaxLength();
2882 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); 2916 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]);
2883 2917
2884 expected.name = ASCIIToUTF16("country"); 2918 expected.name = ASCIIToUTF16("country");
2885 expected.value = ASCIIToUTF16("AL"); 2919 expected.value = ASCIIToUTF16("AL");
2886 expected.form_control_type = ASCIIToUTF16("select-one"); 2920 expected.form_control_type = ASCIIToUTF16("select-one");
2887 expected.max_length = 0; 2921 expected.max_length = 0;
2888 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); 2922 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]);
2889 } 2923 }
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/autofill_browsertest.cc ('k') | chrome/renderer/autofill/form_autofill_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698