OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 class FormAutofillTest : public ChromeRenderViewTest { | 47 class FormAutofillTest : public ChromeRenderViewTest { |
48 public: | 48 public: |
49 FormAutofillTest() : ChromeRenderViewTest() {} | 49 FormAutofillTest() : ChromeRenderViewTest() {} |
50 virtual ~FormAutofillTest() {} | 50 virtual ~FormAutofillTest() {} |
51 | 51 |
52 void ExpectLabels(const char* html, | 52 void ExpectLabels(const char* html, |
53 const std::vector<string16>& labels, | 53 const std::vector<string16>& labels, |
54 const std::vector<string16>& names, | 54 const std::vector<string16>& names, |
55 const std::vector<string16>& values) { | 55 const std::vector<string16>& values) { |
56 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); | 56 std::vector<std::string> control_types(labels.size(), "text"); |
57 ExpectLabelsAndTypes(html, labels, names, values, control_types); | 57 ExpectLabelsAndTypes(html, labels, names, values, control_types); |
58 } | 58 } |
59 | 59 |
60 void ExpectLabelsAndTypes(const char* html, | 60 void ExpectLabelsAndTypes(const char* html, |
61 const std::vector<string16>& labels, | 61 const std::vector<string16>& labels, |
62 const std::vector<string16>& names, | 62 const std::vector<string16>& names, |
63 const std::vector<string16>& values, | 63 const std::vector<string16>& values, |
64 const std::vector<string16>& control_types) { | 64 const std::vector<std::string>& control_types) { |
65 ASSERT_EQ(labels.size(), names.size()); | 65 ASSERT_EQ(labels.size(), names.size()); |
66 ASSERT_EQ(labels.size(), values.size()); | 66 ASSERT_EQ(labels.size(), values.size()); |
67 ASSERT_EQ(labels.size(), control_types.size()); | 67 ASSERT_EQ(labels.size(), control_types.size()); |
68 | 68 |
69 LoadHTML(html); | 69 LoadHTML(html); |
70 | 70 |
71 WebFrame* web_frame = GetMainFrame(); | 71 WebFrame* web_frame = GetMainFrame(); |
72 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 72 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
73 | 73 |
74 FormCache form_cache; | 74 FormCache form_cache; |
75 std::vector<FormData> forms; | 75 std::vector<FormData> forms; |
76 form_cache.ExtractForms(*web_frame, &forms); | 76 form_cache.ExtractForms(*web_frame, &forms); |
77 ASSERT_EQ(1U, forms.size()); | 77 ASSERT_EQ(1U, forms.size()); |
78 | 78 |
79 const FormData& form = forms[0]; | 79 const FormData& form = forms[0]; |
80 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 80 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
81 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 81 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
82 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 82 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
83 | 83 |
84 const std::vector<FormFieldData>& fields = form.fields; | 84 const std::vector<FormFieldData>& fields = form.fields; |
85 ASSERT_EQ(labels.size(), fields.size()); | 85 ASSERT_EQ(labels.size(), fields.size()); |
86 for (size_t i = 0; i < labels.size(); ++i) { | 86 for (size_t i = 0; i < labels.size(); ++i) { |
87 int max_length = control_types[i] == ASCIIToUTF16("text") ? | 87 int max_length = control_types[i] == "text" ? |
88 WebInputElement::defaultMaxLength() : 0; | 88 WebInputElement::defaultMaxLength() : 0; |
89 FormFieldData expected; | 89 FormFieldData expected; |
90 expected.label = labels[i]; | 90 expected.label = labels[i]; |
91 expected.name = names[i]; | 91 expected.name = names[i]; |
92 expected.value = values[i]; | 92 expected.value = values[i]; |
93 expected.form_control_type = control_types[i]; | 93 expected.form_control_type = control_types[i]; |
94 expected.max_length = max_length; | 94 expected.max_length = max_length; |
95 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); | 95 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); |
96 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); | 96 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); |
97 } | 97 } |
(...skipping 27 matching lines...) Expand all Loading... |
125 | 125 |
126 WebFrame* frame = GetMainFrame(); | 126 WebFrame* frame = GetMainFrame(); |
127 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 127 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
128 | 128 |
129 WebElement web_element = frame->document().getElementById("element"); | 129 WebElement web_element = frame->document().getElementById("element"); |
130 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 130 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
131 FormFieldData result1; | 131 FormFieldData result1; |
132 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 132 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); |
133 | 133 |
134 FormFieldData expected; | 134 FormFieldData expected; |
135 expected.form_control_type = ASCIIToUTF16("text"); | 135 expected.form_control_type = "text"; |
136 expected.max_length = WebInputElement::defaultMaxLength(); | 136 expected.max_length = WebInputElement::defaultMaxLength(); |
137 | 137 |
138 expected.name = ASCIIToUTF16("element"); | 138 expected.name = ASCIIToUTF16("element"); |
139 expected.value = string16(); | 139 expected.value = string16(); |
140 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 140 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
141 | 141 |
142 FormFieldData result2; | 142 FormFieldData result2; |
143 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | 143 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); |
144 | 144 |
145 expected.name = ASCIIToUTF16("element"); | 145 expected.name = ASCIIToUTF16("element"); |
(...skipping 10 matching lines...) Expand all Loading... |
156 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 156 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
157 | 157 |
158 WebElement web_element = frame->document().getElementById("element"); | 158 WebElement web_element = frame->document().getElementById("element"); |
159 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 159 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
160 FormFieldData result; | 160 FormFieldData result; |
161 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 161 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
162 | 162 |
163 FormFieldData expected; | 163 FormFieldData expected; |
164 expected.name = ASCIIToUTF16("element"); | 164 expected.name = ASCIIToUTF16("element"); |
165 expected.value = ASCIIToUTF16("value"); | 165 expected.value = ASCIIToUTF16("value"); |
166 expected.form_control_type = ASCIIToUTF16("text"); | 166 expected.form_control_type = "text"; |
| 167 expected.autocomplete_attribute = "off"; |
167 expected.max_length = WebInputElement::defaultMaxLength(); | 168 expected.max_length = WebInputElement::defaultMaxLength(); |
168 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 169 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
169 } | 170 } |
170 | 171 |
171 // We should be able to extract a text field with maxlength specified. | 172 // We should be able to extract a text field with maxlength specified. |
172 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 173 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
173 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 174 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
174 " maxlength=\"5\"/>"); | 175 " maxlength=\"5\"/>"); |
175 | 176 |
176 WebFrame* frame = GetMainFrame(); | 177 WebFrame* frame = GetMainFrame(); |
177 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 178 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
178 | 179 |
179 WebElement web_element = frame->document().getElementById("element"); | 180 WebElement web_element = frame->document().getElementById("element"); |
180 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 181 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
181 FormFieldData result; | 182 FormFieldData result; |
182 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 183 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
183 | 184 |
184 FormFieldData expected; | 185 FormFieldData expected; |
185 expected.name = ASCIIToUTF16("element"); | 186 expected.name = ASCIIToUTF16("element"); |
186 expected.value = ASCIIToUTF16("value"); | 187 expected.value = ASCIIToUTF16("value"); |
187 expected.form_control_type = ASCIIToUTF16("text"); | 188 expected.form_control_type = "text"; |
188 expected.max_length = 5; | 189 expected.max_length = 5; |
189 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 190 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
190 } | 191 } |
191 | 192 |
192 // We should be able to extract a text field that has been autofilled. | 193 // We should be able to extract a text field that has been autofilled. |
193 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 194 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
194 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 195 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
195 | 196 |
196 WebFrame* frame = GetMainFrame(); | 197 WebFrame* frame = GetMainFrame(); |
197 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 198 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
198 | 199 |
199 WebElement web_element = frame->document().getElementById("element"); | 200 WebElement web_element = frame->document().getElementById("element"); |
200 WebInputElement element = web_element.to<WebInputElement>(); | 201 WebInputElement element = web_element.to<WebInputElement>(); |
201 element.setAutofilled(true); | 202 element.setAutofilled(true); |
202 FormFieldData result; | 203 FormFieldData result; |
203 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 204 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
204 | 205 |
205 FormFieldData expected; | 206 FormFieldData expected; |
206 expected.name = ASCIIToUTF16("element"); | 207 expected.name = ASCIIToUTF16("element"); |
207 expected.value = ASCIIToUTF16("value"); | 208 expected.value = ASCIIToUTF16("value"); |
208 expected.form_control_type = ASCIIToUTF16("text"); | 209 expected.form_control_type = "text"; |
209 expected.max_length = WebInputElement::defaultMaxLength(); | 210 expected.max_length = WebInputElement::defaultMaxLength(); |
210 expected.is_autofilled = true; | 211 expected.is_autofilled = true; |
211 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 212 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
212 } | 213 } |
213 | 214 |
214 // We should be able to extract a <select> field. | 215 // We should be able to extract a <select> field. |
215 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 216 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
216 LoadHTML("<SELECT id=\"element\"/>" | 217 LoadHTML("<SELECT id=\"element\"/>" |
217 " <OPTION value=\"CA\">California</OPTION>" | 218 " <OPTION value=\"CA\">California</OPTION>" |
218 " <OPTION value=\"TX\">Texas</OPTION>" | 219 " <OPTION value=\"TX\">Texas</OPTION>" |
219 "</SELECT>"); | 220 "</SELECT>"); |
220 | 221 |
221 WebFrame* frame = GetMainFrame(); | 222 WebFrame* frame = GetMainFrame(); |
222 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 223 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
223 | 224 |
224 WebElement web_element = frame->document().getElementById("element"); | 225 WebElement web_element = frame->document().getElementById("element"); |
225 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 226 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
226 FormFieldData result1; | 227 FormFieldData result1; |
227 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | 228 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); |
228 | 229 |
229 FormFieldData expected; | 230 FormFieldData expected; |
230 expected.name = ASCIIToUTF16("element"); | 231 expected.name = ASCIIToUTF16("element"); |
231 expected.max_length = 0; | 232 expected.max_length = 0; |
232 expected.form_control_type = ASCIIToUTF16("select-one"); | 233 expected.form_control_type = "select-one"; |
233 | 234 |
234 expected.value = ASCIIToUTF16("CA"); | 235 expected.value = ASCIIToUTF16("CA"); |
235 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 236 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
236 | 237 |
237 FormFieldData result2; | 238 FormFieldData result2; |
238 WebFormControlElementToFormField( | 239 WebFormControlElementToFormField( |
239 element, | 240 element, |
240 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE | | 241 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE | |
241 autofill::EXTRACT_OPTION_TEXT), | 242 autofill::EXTRACT_OPTION_TEXT), |
242 &result2); | 243 &result2); |
(...skipping 29 matching lines...) Expand all Loading... |
272 | 273 |
273 WebElement web_element = frame->document().getElementById("hidden"); | 274 WebElement web_element = frame->document().getElementById("hidden"); |
274 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 275 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
275 FormFieldData result; | 276 FormFieldData result; |
276 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 277 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
277 | 278 |
278 FormFieldData expected; | 279 FormFieldData expected; |
279 expected.max_length = 0; | 280 expected.max_length = 0; |
280 | 281 |
281 expected.name = ASCIIToUTF16("hidden"); | 282 expected.name = ASCIIToUTF16("hidden"); |
282 expected.form_control_type = ASCIIToUTF16("hidden"); | 283 expected.form_control_type = "hidden"; |
283 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 284 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
284 | 285 |
285 web_element = frame->document().getElementById("password"); | 286 web_element = frame->document().getElementById("password"); |
286 element = web_element.to<WebFormControlElement>(); | 287 element = web_element.to<WebFormControlElement>(); |
287 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 288 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
288 expected.name = ASCIIToUTF16("password"); | 289 expected.name = ASCIIToUTF16("password"); |
289 expected.form_control_type = ASCIIToUTF16("password"); | 290 expected.form_control_type = "password"; |
290 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 291 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
291 | 292 |
292 web_element = frame->document().getElementById("checkbox"); | 293 web_element = frame->document().getElementById("checkbox"); |
293 element = web_element.to<WebFormControlElement>(); | 294 element = web_element.to<WebFormControlElement>(); |
294 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 295 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
295 expected.name = ASCIIToUTF16("checkbox"); | 296 expected.name = ASCIIToUTF16("checkbox"); |
296 expected.form_control_type = ASCIIToUTF16("checkbox"); | 297 expected.form_control_type = "checkbox"; |
297 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 298 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
298 | 299 |
299 web_element = frame->document().getElementById("radio"); | 300 web_element = frame->document().getElementById("radio"); |
300 element = web_element.to<WebFormControlElement>(); | 301 element = web_element.to<WebFormControlElement>(); |
301 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 302 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
302 expected.name = ASCIIToUTF16("radio"); | 303 expected.name = ASCIIToUTF16("radio"); |
303 expected.form_control_type = ASCIIToUTF16("radio"); | 304 expected.form_control_type = "radio"; |
304 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 305 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
305 | 306 |
306 | 307 |
307 web_element = frame->document().getElementById("submit"); | 308 web_element = frame->document().getElementById("submit"); |
308 element = web_element.to<WebFormControlElement>(); | 309 element = web_element.to<WebFormControlElement>(); |
309 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 310 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
310 expected.name = ASCIIToUTF16("submit"); | 311 expected.name = ASCIIToUTF16("submit"); |
311 expected.form_control_type = ASCIIToUTF16("submit"); | 312 expected.form_control_type = "submit"; |
312 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 313 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
313 } | 314 } |
314 | 315 |
315 // We should be able to extract the autocompletetype attribute. | 316 // We should be able to extract the autocompletetype attribute. |
316 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { | 317 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { |
317 std::string html = | 318 std::string html = |
318 "<INPUT type=\"text\" id=\"absent\"/>" | 319 "<INPUT type=\"text\" id=\"absent\"/>" |
319 "<INPUT type=\"text\" id=\"empty\" x-autocompletetype=\"\"/>" | 320 "<INPUT type=\"text\" id=\"empty\" autocomplete=\"\"/>" |
320 "<INPUT type=\"text\" id=\"whitespace\" x-autocompletetype=\" \"/>" | 321 "<INPUT type=\"text\" id=\"off\" autocomplete=\"off\"/>" |
321 "<INPUT type=\"text\" id=\"regular\" x-autocompletetype=\"email\"/>" | 322 "<INPUT type=\"text\" id=\"regular\" autocomplete=\"email\"/>" |
322 "<INPUT type=\"text\" id=\"multi-valued\" " | 323 "<INPUT type=\"text\" id=\"multi-valued\" " |
323 " x-autocompletetype=\"x-confirm-email email\"/>" | 324 " autocomplete=\"billing email\"/>" |
324 "<INPUT type=\"text\" id=\"unprefixed\" autocompletetype=\"email\"/>" | 325 "<INPUT type=\"text\" id=\"experimental\" x-autocompletetype=\"email\"/>" |
325 "<SELECT id=\"select\" x-autocompletetype=\"state\"/>" | 326 "<SELECT id=\"select\" autocomplete=\"state\"/>" |
326 " <OPTION value=\"CA\">California</OPTION>" | 327 " <OPTION value=\"CA\">California</OPTION>" |
327 " <OPTION value=\"TX\">Texas</OPTION>" | 328 " <OPTION value=\"TX\">Texas</OPTION>" |
328 "</SELECT>"; | 329 "</SELECT>"; |
329 html += | 330 html += |
330 "<INPUT type=\"text\" id=\"malicious\" x-autocompletetype=\"" + | 331 "<INPUT type=\"text\" id=\"malicious\" autocomplete=\"" + |
331 std::string(10000, 'x') + "\"/>"; | 332 std::string(10000, 'x') + "\"/>"; |
332 LoadHTML(html.c_str()); | 333 LoadHTML(html.c_str()); |
333 | 334 |
334 WebFrame* frame = GetMainFrame(); | 335 WebFrame* frame = GetMainFrame(); |
335 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 336 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
336 | 337 |
337 // An absent attribute is equivalent to an empty one. | 338 struct TestCase { |
338 WebElement web_element = frame->document().getElementById("absent"); | 339 const std::string element_id; |
339 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 340 const std::string form_control_type; |
340 FormFieldData result1; | 341 const std::string autocomplete_attribute; |
341 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 342 }; |
| 343 TestCase test_cases[] = { |
| 344 // An absent attribute is equivalent to an empty one. |
| 345 { "absent", "text", "" }, |
| 346 // Make sure there are no issues parsing an empty attribute. |
| 347 { "empty", "text", "" }, |
| 348 // Make sure there are no issues parsing an attribute value that isn't a |
| 349 // type hint. |
| 350 { "off", "text", "off" }, |
| 351 // Common case: exactly one type specified. |
| 352 { "regular", "text", "email" }, |
| 353 // Verify that we correctly extract multiple tokens as well. |
| 354 { "multi-valued", "text", "billing email" }, |
| 355 // We previously extracted this data from the experimental |
| 356 // 'x-autocompletetype' attribute. Now that the field type hints are part |
| 357 // of the spec under the autocomplete attribute, we no longer support the |
| 358 // experimental version. |
| 359 { "experimental", "text", "" }, |
| 360 // <select> elements should behave no differently from text fields here. |
| 361 { "select", "select-one", "state" }, |
| 362 // Very long attribute values should be replaced by a default string, to |
| 363 // prevent malicious websites from DOSing the browser process. |
| 364 { "malicious", "text", "x-max-data-length-exceeded" }, |
| 365 }; |
342 | 366 |
343 FormFieldData expected; | 367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
344 expected.name = ASCIIToUTF16("absent"); | 368 WebElement web_element = frame->document().getElementById( |
345 expected.form_control_type = ASCIIToUTF16("text"); | 369 ASCIIToUTF16(test_cases[i].element_id)); |
346 expected.autocomplete_type = string16(); | 370 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
347 expected.max_length = WebInputElement::defaultMaxLength(); | 371 FormFieldData result; |
348 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 372 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result); |
349 | 373 |
350 web_element = frame->document().getElementById("empty"); | 374 FormFieldData expected; |
351 element = web_element.to<WebFormControlElement>(); | 375 expected.name = ASCIIToUTF16(test_cases[i].element_id); |
352 FormFieldData result2; | 376 expected.form_control_type = test_cases[i].form_control_type; |
353 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result2); | 377 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; |
354 expected.name = ASCIIToUTF16("empty"); | 378 if (test_cases[i].form_control_type == "text") |
355 expected.form_control_type = ASCIIToUTF16("text"); | 379 expected.max_length = WebInputElement::defaultMaxLength(); |
356 expected.autocomplete_type = string16(); | 380 else |
357 expected.max_length = WebInputElement::defaultMaxLength(); | 381 expected.max_length = 0; |
358 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | |
359 | 382 |
360 // The renderer should trim whitespace. | 383 SCOPED_TRACE(test_cases[i].element_id); |
361 web_element = frame->document().getElementById("whitespace"); | 384 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
362 element = web_element.to<WebFormControlElement>(); | 385 } |
363 FormFieldData result3; | |
364 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result3); | |
365 expected.name = ASCIIToUTF16("whitespace"); | |
366 expected.form_control_type = ASCIIToUTF16("text"); | |
367 expected.autocomplete_type = string16(); | |
368 expected.max_length = WebInputElement::defaultMaxLength(); | |
369 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); | |
370 | |
371 // Common case: exactly one type specified. | |
372 web_element = frame->document().getElementById("regular"); | |
373 element = web_element.to<WebFormControlElement>(); | |
374 FormFieldData result4; | |
375 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result4); | |
376 expected.name = ASCIIToUTF16("regular"); | |
377 expected.form_control_type = ASCIIToUTF16("text"); | |
378 expected.autocomplete_type = ASCIIToUTF16("email"); | |
379 expected.max_length = WebInputElement::defaultMaxLength(); | |
380 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result4); | |
381 | |
382 // Verify that we correctly extract fallback types as well. | |
383 web_element = frame->document().getElementById("multi-valued"); | |
384 element = web_element.to<WebFormControlElement>(); | |
385 FormFieldData result5; | |
386 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result5); | |
387 expected.name = ASCIIToUTF16("multi-valued"); | |
388 expected.form_control_type = ASCIIToUTF16("text"); | |
389 expected.autocomplete_type = ASCIIToUTF16("x-confirm-email email"); | |
390 expected.max_length = WebInputElement::defaultMaxLength(); | |
391 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result5); | |
392 | |
393 // The attribute is not yet part of the HTML standard, so we only recognize | |
394 // the prefixed version -- 'x-autocompletetype' -- and not the unprefixed one. | |
395 web_element = frame->document().getElementById("unprefixed"); | |
396 element = web_element.to<WebFormControlElement>(); | |
397 FormFieldData result6; | |
398 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result6); | |
399 expected.name = ASCIIToUTF16("unprefixed"); | |
400 expected.form_control_type = ASCIIToUTF16("text"); | |
401 expected.autocomplete_type = string16(); | |
402 expected.max_length = WebInputElement::defaultMaxLength(); | |
403 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result6); | |
404 | |
405 // <select> elements should behave no differently from text fields here. | |
406 web_element = frame->document().getElementById("select"); | |
407 element = web_element.to<WebFormControlElement>(); | |
408 FormFieldData result7; | |
409 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result7); | |
410 expected.name = ASCIIToUTF16("select"); | |
411 expected.form_control_type = ASCIIToUTF16("select-one"); | |
412 expected.autocomplete_type = ASCIIToUTF16("state"); | |
413 expected.max_length = 0; | |
414 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result7); | |
415 | |
416 // Very long attribute values should be replaced by a default string, to | |
417 // prevent malicious websites from DOSing the browser process. | |
418 web_element = frame->document().getElementById("malicious"); | |
419 element = web_element.to<WebFormControlElement>(); | |
420 FormFieldData result8; | |
421 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result8); | |
422 expected.name = ASCIIToUTF16("malicious"); | |
423 expected.form_control_type = ASCIIToUTF16("text"); | |
424 expected.autocomplete_type = ASCIIToUTF16("x-max-data-length-exceeded"); | |
425 expected.max_length = WebInputElement::defaultMaxLength(); | |
426 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result8); | |
427 } | 386 } |
428 | 387 |
429 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 388 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
430 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 389 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
431 " <LABEL for=\"firstname\">First name:</LABEL>" | 390 " <LABEL for=\"firstname\">First name:</LABEL>" |
432 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 391 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
433 " <LABEL for=\"lastname\">Last name:</LABEL>" | 392 " <LABEL for=\"lastname\">Last name:</LABEL>" |
434 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 393 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
435 " <LABEL for=\"state\">State:</LABEL>" | 394 " <LABEL for=\"state\">State:</LABEL>" |
436 " <SELECT id=\"state\"/>" | 395 " <SELECT id=\"state\"/>" |
(...skipping 30 matching lines...) Expand all Loading... |
467 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 426 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
468 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 427 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
469 | 428 |
470 const std::vector<FormFieldData>& fields = form.fields; | 429 const std::vector<FormFieldData>& fields = form.fields; |
471 ASSERT_EQ(3U, fields.size()); | 430 ASSERT_EQ(3U, fields.size()); |
472 | 431 |
473 FormFieldData expected; | 432 FormFieldData expected; |
474 expected.name = ASCIIToUTF16("firstname"); | 433 expected.name = ASCIIToUTF16("firstname"); |
475 expected.value = ASCIIToUTF16("John"); | 434 expected.value = ASCIIToUTF16("John"); |
476 expected.label = ASCIIToUTF16("First name:"); | 435 expected.label = ASCIIToUTF16("First name:"); |
477 expected.form_control_type = ASCIIToUTF16("text"); | 436 expected.form_control_type = "text"; |
478 expected.max_length = WebInputElement::defaultMaxLength(); | 437 expected.max_length = WebInputElement::defaultMaxLength(); |
479 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 438 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
480 | 439 |
481 expected.name = ASCIIToUTF16("lastname"); | 440 expected.name = ASCIIToUTF16("lastname"); |
482 expected.value = ASCIIToUTF16("Smith"); | 441 expected.value = ASCIIToUTF16("Smith"); |
483 expected.label = ASCIIToUTF16("Last name:"); | 442 expected.label = ASCIIToUTF16("Last name:"); |
484 expected.form_control_type = ASCIIToUTF16("text"); | 443 expected.form_control_type = "text"; |
485 expected.max_length = WebInputElement::defaultMaxLength(); | 444 expected.max_length = WebInputElement::defaultMaxLength(); |
486 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 445 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
487 | 446 |
488 expected.name = ASCIIToUTF16("state"); | 447 expected.name = ASCIIToUTF16("state"); |
489 expected.value = ASCIIToUTF16("CA"); | 448 expected.value = ASCIIToUTF16("CA"); |
490 expected.label = ASCIIToUTF16("State:"); | 449 expected.label = ASCIIToUTF16("State:"); |
491 expected.form_control_type = ASCIIToUTF16("select-one"); | 450 expected.form_control_type = "select-one"; |
492 expected.max_length = 0; | 451 expected.max_length = 0; |
493 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 452 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
494 } | 453 } |
495 | 454 |
496 // We should not be able to serialize a form with too many fillable fields. | 455 // We should not be able to serialize a form with too many fillable fields. |
497 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { | 456 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
498 std::string html = | 457 std::string html = |
499 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; | 458 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; |
500 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { | 459 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { |
501 html += "<INPUT type=\"text\"/>"; | 460 html += "<INPUT type=\"text\"/>"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 // First form. | 517 // First form. |
559 const FormData& form = forms[0]; | 518 const FormData& form = forms[0]; |
560 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 519 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
561 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 520 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
562 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 521 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
563 | 522 |
564 const std::vector<FormFieldData>& fields = form.fields; | 523 const std::vector<FormFieldData>& fields = form.fields; |
565 ASSERT_EQ(3U, fields.size()); | 524 ASSERT_EQ(3U, fields.size()); |
566 | 525 |
567 FormFieldData expected; | 526 FormFieldData expected; |
568 expected.form_control_type = ASCIIToUTF16("text"); | 527 expected.form_control_type = "text"; |
569 expected.max_length = WebInputElement::defaultMaxLength(); | 528 expected.max_length = WebInputElement::defaultMaxLength(); |
570 | 529 |
571 expected.name = ASCIIToUTF16("firstname"); | 530 expected.name = ASCIIToUTF16("firstname"); |
572 expected.value = ASCIIToUTF16("John"); | 531 expected.value = ASCIIToUTF16("John"); |
573 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 532 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
574 | 533 |
575 expected.name = ASCIIToUTF16("lastname"); | 534 expected.name = ASCIIToUTF16("lastname"); |
576 expected.value = ASCIIToUTF16("Smith"); | 535 expected.value = ASCIIToUTF16("Smith"); |
577 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 536 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
578 | 537 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 autofill::EXTRACT_VALUE, &form, NULL)); | 632 autofill::EXTRACT_VALUE, &form, NULL)); |
674 | 633 |
675 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 634 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
676 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 635 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
677 EXPECT_EQ(GURL("http://abc.com"), form.action); | 636 EXPECT_EQ(GURL("http://abc.com"), form.action); |
678 | 637 |
679 const std::vector<FormFieldData>& fields = form.fields; | 638 const std::vector<FormFieldData>& fields = form.fields; |
680 ASSERT_EQ(3U, fields.size()); | 639 ASSERT_EQ(3U, fields.size()); |
681 | 640 |
682 FormFieldData expected; | 641 FormFieldData expected; |
683 expected.form_control_type = ASCIIToUTF16("text"); | 642 expected.form_control_type = "text"; |
684 expected.max_length = WebInputElement::defaultMaxLength(); | 643 expected.max_length = WebInputElement::defaultMaxLength(); |
685 | 644 |
686 expected.name = ASCIIToUTF16("middlename"); | 645 expected.name = ASCIIToUTF16("middlename"); |
687 expected.value = ASCIIToUTF16("Jack"); | 646 expected.value = ASCIIToUTF16("Jack"); |
688 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 647 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
689 | 648 |
690 expected.name = ASCIIToUTF16("lastname"); | 649 expected.name = ASCIIToUTF16("lastname"); |
691 expected.value = ASCIIToUTF16("Smith"); | 650 expected.value = ASCIIToUTF16("Smith"); |
692 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 651 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
693 | 652 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 684 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
726 autofill::REQUIRE_NONE)); | 685 autofill::REQUIRE_NONE)); |
727 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 686 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
728 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 687 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
729 EXPECT_EQ(GURL("http://buh.com"), form.action); | 688 EXPECT_EQ(GURL("http://buh.com"), form.action); |
730 | 689 |
731 const std::vector<FormFieldData>& fields = form.fields; | 690 const std::vector<FormFieldData>& fields = form.fields; |
732 ASSERT_EQ(4U, fields.size()); | 691 ASSERT_EQ(4U, fields.size()); |
733 | 692 |
734 FormFieldData expected; | 693 FormFieldData expected; |
735 expected.form_control_type = ASCIIToUTF16("text"); | 694 expected.form_control_type = "text"; |
736 expected.max_length = WebInputElement::defaultMaxLength(); | 695 expected.max_length = WebInputElement::defaultMaxLength(); |
737 | 696 |
738 expected.name = ASCIIToUTF16("firstname"); | 697 expected.name = ASCIIToUTF16("firstname"); |
739 expected.value = ASCIIToUTF16("John"); | 698 expected.value = ASCIIToUTF16("John"); |
740 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 699 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
741 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 700 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
742 | 701 |
743 expected.name = ASCIIToUTF16("lastname"); | 702 expected.name = ASCIIToUTF16("lastname"); |
744 expected.value = ASCIIToUTF16("Smith"); | 703 expected.value = ASCIIToUTF16("Smith"); |
745 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 704 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
746 | 705 |
747 expected.name = ASCIIToUTF16("email"); | 706 expected.name = ASCIIToUTF16("email"); |
748 expected.value = ASCIIToUTF16("john@example.com"); | 707 expected.value = ASCIIToUTF16("john@example.com"); |
| 708 expected.autocomplete_attribute = "off"; |
749 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 709 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 710 expected.autocomplete_attribute = std::string(); // reset |
750 | 711 |
751 expected.name = ASCIIToUTF16("phone"); | 712 expected.name = ASCIIToUTF16("phone"); |
752 expected.value = ASCIIToUTF16("1.800.555.1234"); | 713 expected.value = ASCIIToUTF16("1.800.555.1234"); |
753 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 714 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
754 | 715 |
755 // Try again, but require autocomplete. | 716 // Try again, but require autocomplete. |
756 FormData form2; | 717 FormData form2; |
757 FormFieldData field2; | 718 FormFieldData field2; |
758 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 719 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
759 autofill::REQUIRE_AUTOCOMPLETE)); | 720 autofill::REQUIRE_AUTOCOMPLETE)); |
760 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 721 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
761 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 722 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
762 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 723 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
763 | 724 |
764 const std::vector<FormFieldData>& fields2 = form2.fields; | 725 const std::vector<FormFieldData>& fields2 = form2.fields; |
765 ASSERT_EQ(3U, fields2.size()); | 726 ASSERT_EQ(3U, fields2.size()); |
766 | 727 |
767 expected.form_control_type = ASCIIToUTF16("text"); | 728 expected.form_control_type = "text"; |
768 expected.max_length = WebInputElement::defaultMaxLength(); | 729 expected.max_length = WebInputElement::defaultMaxLength(); |
769 | 730 |
770 expected.name = ASCIIToUTF16("firstname"); | 731 expected.name = ASCIIToUTF16("firstname"); |
771 expected.value = ASCIIToUTF16("John"); | 732 expected.value = ASCIIToUTF16("John"); |
772 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 733 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
773 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 734 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
774 | 735 |
775 expected.name = ASCIIToUTF16("lastname"); | 736 expected.name = ASCIIToUTF16("lastname"); |
776 expected.value = ASCIIToUTF16("Smith"); | 737 expected.value = ASCIIToUTF16("Smith"); |
777 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 738 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 775 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
815 autofill::REQUIRE_AUTOCOMPLETE)); | 776 autofill::REQUIRE_AUTOCOMPLETE)); |
816 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 777 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
817 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 778 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
818 EXPECT_EQ(GURL("http://buh.com"), form.action); | 779 EXPECT_EQ(GURL("http://buh.com"), form.action); |
819 | 780 |
820 const std::vector<FormFieldData>& fields = form.fields; | 781 const std::vector<FormFieldData>& fields = form.fields; |
821 ASSERT_EQ(7U, fields.size()); | 782 ASSERT_EQ(7U, fields.size()); |
822 | 783 |
823 FormFieldData expected; | 784 FormFieldData expected; |
824 expected.form_control_type = ASCIIToUTF16("text"); | 785 expected.form_control_type = "text"; |
825 expected.max_length = WebInputElement::defaultMaxLength(); | 786 expected.max_length = WebInputElement::defaultMaxLength(); |
826 | 787 |
827 expected.name = ASCIIToUTF16("firstname"); | 788 expected.name = ASCIIToUTF16("firstname"); |
828 expected.value = string16(); | 789 expected.value = string16(); |
829 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 790 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
830 | 791 |
831 expected.name = ASCIIToUTF16("lastname"); | 792 expected.name = ASCIIToUTF16("lastname"); |
832 expected.value = string16(); | 793 expected.value = string16(); |
833 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 794 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
834 | 795 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 902 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
942 autofill::REQUIRE_AUTOCOMPLETE)); | 903 autofill::REQUIRE_AUTOCOMPLETE)); |
943 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 904 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
944 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 905 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
945 EXPECT_EQ(GURL("http://buh.com"), form.action); | 906 EXPECT_EQ(GURL("http://buh.com"), form.action); |
946 | 907 |
947 const std::vector<FormFieldData>& fields = form.fields; | 908 const std::vector<FormFieldData>& fields = form.fields; |
948 ASSERT_EQ(4U, fields.size()); | 909 ASSERT_EQ(4U, fields.size()); |
949 | 910 |
950 FormFieldData expected; | 911 FormFieldData expected; |
951 expected.form_control_type = ASCIIToUTF16("text"); | 912 expected.form_control_type = "text"; |
952 expected.max_length = WebInputElement::defaultMaxLength(); | 913 expected.max_length = WebInputElement::defaultMaxLength(); |
953 | 914 |
954 expected.name = ASCIIToUTF16("firstname"); | 915 expected.name = ASCIIToUTF16("firstname"); |
955 expected.value = string16(); | 916 expected.value = string16(); |
956 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 917 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
957 | 918 |
958 expected.name = ASCIIToUTF16("lastname"); | 919 expected.name = ASCIIToUTF16("lastname"); |
959 expected.value = string16(); | 920 expected.value = string16(); |
960 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 921 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
961 | 922 |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 " </TR>" | 1307 " </TR>" |
1347 "</TABLE>" | 1308 "</TABLE>" |
1348 "</FORM>", | 1309 "</FORM>", |
1349 labels, names, values); | 1310 labels, names, values); |
1350 } | 1311 } |
1351 | 1312 |
1352 // <script>, <noscript> and <option> tags are excluded when the labels are | 1313 // <script>, <noscript> and <option> tags are excluded when the labels are |
1353 // inferred. | 1314 // inferred. |
1354 // Also <!-- comment --> is excluded. | 1315 // Also <!-- comment --> is excluded. |
1355 TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) { | 1316 TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) { |
1356 std::vector<string16> labels, names, values, control_types; | 1317 std::vector<string16> labels, names, values; |
| 1318 std::vector<std::string> control_types; |
1357 | 1319 |
1358 labels.push_back(ASCIIToUTF16("* First Name")); | 1320 labels.push_back(ASCIIToUTF16("* First Name")); |
1359 names.push_back(ASCIIToUTF16("firstname")); | 1321 names.push_back(ASCIIToUTF16("firstname")); |
1360 values.push_back(ASCIIToUTF16("John")); | 1322 values.push_back(ASCIIToUTF16("John")); |
1361 control_types.push_back(ASCIIToUTF16("text")); | 1323 control_types.push_back("text"); |
1362 | 1324 |
1363 labels.push_back(ASCIIToUTF16("* Middle Name")); | 1325 labels.push_back(ASCIIToUTF16("* Middle Name")); |
1364 names.push_back(ASCIIToUTF16("middlename")); | 1326 names.push_back(ASCIIToUTF16("middlename")); |
1365 values.push_back(ASCIIToUTF16("Joe")); | 1327 values.push_back(ASCIIToUTF16("Joe")); |
1366 control_types.push_back(ASCIIToUTF16("text")); | 1328 control_types.push_back("text"); |
1367 | 1329 |
1368 labels.push_back(ASCIIToUTF16("* Last Name")); | 1330 labels.push_back(ASCIIToUTF16("* Last Name")); |
1369 names.push_back(ASCIIToUTF16("lastname")); | 1331 names.push_back(ASCIIToUTF16("lastname")); |
1370 values.push_back(ASCIIToUTF16("Smith")); | 1332 values.push_back(ASCIIToUTF16("Smith")); |
1371 control_types.push_back(ASCIIToUTF16("text")); | 1333 control_types.push_back("text"); |
1372 | 1334 |
1373 labels.push_back(ASCIIToUTF16("* Country")); | 1335 labels.push_back(ASCIIToUTF16("* Country")); |
1374 names.push_back(ASCIIToUTF16("country")); | 1336 names.push_back(ASCIIToUTF16("country")); |
1375 values.push_back(ASCIIToUTF16("US")); | 1337 values.push_back(ASCIIToUTF16("US")); |
1376 control_types.push_back(ASCIIToUTF16("select-one")); | 1338 control_types.push_back("select-one"); |
1377 | 1339 |
1378 labels.push_back(ASCIIToUTF16("* Email")); | 1340 labels.push_back(ASCIIToUTF16("* Email")); |
1379 names.push_back(ASCIIToUTF16("email")); | 1341 names.push_back(ASCIIToUTF16("email")); |
1380 values.push_back(ASCIIToUTF16("john@example.com")); | 1342 values.push_back(ASCIIToUTF16("john@example.com")); |
1381 control_types.push_back(ASCIIToUTF16("text")); | 1343 control_types.push_back("text"); |
1382 | 1344 |
1383 ExpectLabelsAndTypes( | 1345 ExpectLabelsAndTypes( |
1384 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1346 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
1385 "<TABLE>" | 1347 "<TABLE>" |
1386 " <TR>" | 1348 " <TR>" |
1387 " <TD>" | 1349 " <TD>" |
1388 " <SPAN>*</SPAN>" | 1350 " <SPAN>*</SPAN>" |
1389 " <B>First Name</B>" | 1351 " <B>First Name</B>" |
1390 " </TD>" | 1352 " </TD>" |
1391 " <TD>" | 1353 " <TD>" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 1854 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
1893 autofill::REQUIRE_NONE)); | 1855 autofill::REQUIRE_NONE)); |
1894 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1856 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1895 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1857 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
1896 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1858 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1897 | 1859 |
1898 const std::vector<FormFieldData>& fields = form.fields; | 1860 const std::vector<FormFieldData>& fields = form.fields; |
1899 ASSERT_EQ(3U, fields.size()); | 1861 ASSERT_EQ(3U, fields.size()); |
1900 | 1862 |
1901 FormFieldData expected; | 1863 FormFieldData expected; |
1902 expected.form_control_type = ASCIIToUTF16("text"); | 1864 expected.form_control_type = "text"; |
1903 | 1865 |
1904 expected.name = ASCIIToUTF16("firstname"); | 1866 expected.name = ASCIIToUTF16("firstname"); |
1905 expected.max_length = 5; | 1867 expected.max_length = 5; |
1906 expected.is_autofilled = false; | 1868 expected.is_autofilled = false; |
1907 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 1869 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
1908 | 1870 |
1909 expected.name = ASCIIToUTF16("lastname"); | 1871 expected.name = ASCIIToUTF16("lastname"); |
1910 expected.max_length = 7; | 1872 expected.max_length = 7; |
1911 expected.is_autofilled = false; | 1873 expected.is_autofilled = false; |
1912 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 1874 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
(...skipping 15 matching lines...) Expand all Loading... |
1928 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 1890 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
1929 autofill::REQUIRE_NONE)); | 1891 autofill::REQUIRE_NONE)); |
1930 | 1892 |
1931 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1893 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1932 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1894 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
1933 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1895 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1934 | 1896 |
1935 const std::vector<FormFieldData>& fields2 = form2.fields; | 1897 const std::vector<FormFieldData>& fields2 = form2.fields; |
1936 ASSERT_EQ(3U, fields2.size()); | 1898 ASSERT_EQ(3U, fields2.size()); |
1937 | 1899 |
1938 expected.form_control_type = ASCIIToUTF16("text"); | 1900 expected.form_control_type = "text"; |
1939 | 1901 |
1940 expected.name = ASCIIToUTF16("firstname"); | 1902 expected.name = ASCIIToUTF16("firstname"); |
1941 expected.value = ASCIIToUTF16("Broth"); | 1903 expected.value = ASCIIToUTF16("Broth"); |
1942 expected.max_length = 5; | 1904 expected.max_length = 5; |
1943 expected.is_autofilled = true; | 1905 expected.is_autofilled = true; |
1944 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 1906 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
1945 | 1907 |
1946 expected.name = ASCIIToUTF16("lastname"); | 1908 expected.name = ASCIIToUTF16("lastname"); |
1947 expected.value = ASCIIToUTF16("Jonatha"); | 1909 expected.value = ASCIIToUTF16("Jonatha"); |
1948 expected.max_length = 7; | 1910 expected.max_length = 7; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 1947 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
1986 autofill::REQUIRE_NONE)); | 1948 autofill::REQUIRE_NONE)); |
1987 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1949 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1988 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1950 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
1989 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1951 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1990 | 1952 |
1991 const std::vector<FormFieldData>& fields = form.fields; | 1953 const std::vector<FormFieldData>& fields = form.fields; |
1992 ASSERT_EQ(3U, fields.size()); | 1954 ASSERT_EQ(3U, fields.size()); |
1993 | 1955 |
1994 FormFieldData expected; | 1956 FormFieldData expected; |
1995 expected.form_control_type = ASCIIToUTF16("text"); | 1957 expected.form_control_type = "text"; |
1996 expected.max_length = WebInputElement::defaultMaxLength(); | 1958 expected.max_length = WebInputElement::defaultMaxLength(); |
1997 | 1959 |
1998 expected.name = ASCIIToUTF16("firstname"); | 1960 expected.name = ASCIIToUTF16("firstname"); |
1999 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 1961 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2000 | 1962 |
2001 expected.name = ASCIIToUTF16("lastname"); | 1963 expected.name = ASCIIToUTF16("lastname"); |
2002 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 1964 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2003 | 1965 |
2004 expected.name = ASCIIToUTF16("email"); | 1966 expected.name = ASCIIToUTF16("email"); |
2005 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 1967 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2024 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
2063 autofill::REQUIRE_NONE)); | 2025 autofill::REQUIRE_NONE)); |
2064 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2026 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2065 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2027 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
2066 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2028 EXPECT_EQ(GURL("http://buh.com"), form.action); |
2067 | 2029 |
2068 const std::vector<FormFieldData>& fields = form.fields; | 2030 const std::vector<FormFieldData>& fields = form.fields; |
2069 ASSERT_EQ(3U, fields.size()); | 2031 ASSERT_EQ(3U, fields.size()); |
2070 | 2032 |
2071 FormFieldData expected; | 2033 FormFieldData expected; |
2072 expected.form_control_type = ASCIIToUTF16("text"); | 2034 expected.form_control_type = "text"; |
2073 expected.max_length = WebInputElement::defaultMaxLength(); | 2035 expected.max_length = WebInputElement::defaultMaxLength(); |
2074 | 2036 |
2075 expected.name = ASCIIToUTF16("firstname"); | 2037 expected.name = ASCIIToUTF16("firstname"); |
2076 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2038 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2077 | 2039 |
2078 expected.name = ASCIIToUTF16("lastname"); | 2040 expected.name = ASCIIToUTF16("lastname"); |
2079 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2041 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2080 | 2042 |
2081 expected.name = ASCIIToUTF16("email"); | 2043 expected.name = ASCIIToUTF16("email"); |
2082 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2044 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
(...skipping 10 matching lines...) Expand all Loading... |
2093 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 2055 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
2094 autofill::REQUIRE_NONE)); | 2056 autofill::REQUIRE_NONE)); |
2095 | 2057 |
2096 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2058 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
2097 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2059 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
2098 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2060 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2099 | 2061 |
2100 const std::vector<FormFieldData>& fields2 = form2.fields; | 2062 const std::vector<FormFieldData>& fields2 = form2.fields; |
2101 ASSERT_EQ(3U, fields2.size()); | 2063 ASSERT_EQ(3U, fields2.size()); |
2102 | 2064 |
2103 expected.form_control_type = ASCIIToUTF16("text"); | 2065 expected.form_control_type = "text"; |
2104 expected.max_length = WebInputElement::defaultMaxLength(); | 2066 expected.max_length = WebInputElement::defaultMaxLength(); |
2105 | 2067 |
2106 expected.name = ASCIIToUTF16("firstname"); | 2068 expected.name = ASCIIToUTF16("firstname"); |
2107 expected.value = ASCIIToUTF16("Wyatt"); | 2069 expected.value = ASCIIToUTF16("Wyatt"); |
2108 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2070 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2109 | 2071 |
2110 expected.name = ASCIIToUTF16("lastname"); | 2072 expected.name = ASCIIToUTF16("lastname"); |
2111 expected.value = ASCIIToUTF16("Earp"); | 2073 expected.value = ASCIIToUTF16("Earp"); |
2112 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2074 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2113 | 2075 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2110 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
2149 autofill::REQUIRE_NONE)); | 2111 autofill::REQUIRE_NONE)); |
2150 EXPECT_EQ(string16(), form.name); | 2112 EXPECT_EQ(string16(), form.name); |
2151 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2113 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
2152 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2114 EXPECT_EQ(GURL("http://abc.com"), form.action); |
2153 | 2115 |
2154 const std::vector<FormFieldData>& fields = form.fields; | 2116 const std::vector<FormFieldData>& fields = form.fields; |
2155 ASSERT_EQ(3U, fields.size()); | 2117 ASSERT_EQ(3U, fields.size()); |
2156 | 2118 |
2157 FormFieldData expected; | 2119 FormFieldData expected; |
2158 expected.form_control_type = ASCIIToUTF16("text"); | 2120 expected.form_control_type = "text"; |
2159 expected.max_length = WebInputElement::defaultMaxLength(); | 2121 expected.max_length = WebInputElement::defaultMaxLength(); |
2160 | 2122 |
2161 expected.name = ASCIIToUTF16("apple"); | 2123 expected.name = ASCIIToUTF16("apple"); |
2162 expected.is_autofilled = false; | 2124 expected.is_autofilled = false; |
2163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2164 | 2126 |
2165 expected.name = ASCIIToUTF16("banana"); | 2127 expected.name = ASCIIToUTF16("banana"); |
2166 expected.is_autofilled = false; | 2128 expected.is_autofilled = false; |
2167 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2129 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2168 | 2130 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 &form, | 2196 &form, |
2235 NULL)); | 2197 NULL)); |
2236 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2198 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2237 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2199 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
2238 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2200 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2239 | 2201 |
2240 const std::vector<FormFieldData>& fields = form.fields; | 2202 const std::vector<FormFieldData>& fields = form.fields; |
2241 ASSERT_EQ(4U, fields.size()); | 2203 ASSERT_EQ(4U, fields.size()); |
2242 | 2204 |
2243 FormFieldData expected; | 2205 FormFieldData expected; |
2244 expected.form_control_type = ASCIIToUTF16("text"); | 2206 expected.form_control_type = "text"; |
2245 expected.max_length = WebInputElement::defaultMaxLength(); | 2207 expected.max_length = WebInputElement::defaultMaxLength(); |
2246 | 2208 |
2247 expected.label = ASCIIToUTF16("Phone:"); | 2209 expected.label = ASCIIToUTF16("Phone:"); |
2248 expected.name = ASCIIToUTF16("dayphone1"); | 2210 expected.name = ASCIIToUTF16("dayphone1"); |
2249 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2211 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2250 | 2212 |
2251 expected.label = ASCIIToUTF16("-"); | 2213 expected.label = ASCIIToUTF16("-"); |
2252 expected.name = ASCIIToUTF16("dayphone2"); | 2214 expected.name = ASCIIToUTF16("dayphone2"); |
2253 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2215 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2254 | 2216 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 &form, | 2255 &form, |
2294 NULL)); | 2256 NULL)); |
2295 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2257 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2296 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2258 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
2297 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2259 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2298 | 2260 |
2299 const std::vector<FormFieldData>& fields = form.fields; | 2261 const std::vector<FormFieldData>& fields = form.fields; |
2300 ASSERT_EQ(6U, fields.size()); | 2262 ASSERT_EQ(6U, fields.size()); |
2301 | 2263 |
2302 FormFieldData expected; | 2264 FormFieldData expected; |
2303 expected.form_control_type = ASCIIToUTF16("text"); | 2265 expected.form_control_type = "text"; |
2304 | 2266 |
2305 expected.label = ASCIIToUTF16("Phone:"); | 2267 expected.label = ASCIIToUTF16("Phone:"); |
2306 expected.name = ASCIIToUTF16("dayphone1"); | 2268 expected.name = ASCIIToUTF16("dayphone1"); |
2307 expected.max_length = 3; | 2269 expected.max_length = 3; |
2308 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2270 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2309 | 2271 |
2310 expected.label = ASCIIToUTF16("-"); | 2272 expected.label = ASCIIToUTF16("-"); |
2311 expected.name = ASCIIToUTF16("dayphone2"); | 2273 expected.name = ASCIIToUTF16("dayphone2"); |
2312 expected.max_length = 3; | 2274 expected.max_length = 3; |
2313 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2275 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2329 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
2368 autofill::REQUIRE_NONE)); | 2330 autofill::REQUIRE_NONE)); |
2369 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2331 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2370 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2332 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
2371 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2333 EXPECT_EQ(GURL("http://buh.com"), form.action); |
2372 | 2334 |
2373 const std::vector<FormFieldData>& fields = form.fields; | 2335 const std::vector<FormFieldData>& fields = form.fields; |
2374 ASSERT_EQ(3U, fields.size()); | 2336 ASSERT_EQ(3U, fields.size()); |
2375 | 2337 |
2376 FormFieldData expected; | 2338 FormFieldData expected; |
2377 expected.form_control_type = ASCIIToUTF16("text"); | 2339 expected.form_control_type = "text"; |
2378 expected.max_length = WebInputElement::defaultMaxLength(); | 2340 expected.max_length = WebInputElement::defaultMaxLength(); |
2379 | 2341 |
2380 expected.name = ASCIIToUTF16("firstname"); | 2342 expected.name = ASCIIToUTF16("firstname"); |
2381 expected.value = ASCIIToUTF16("Wy"); | 2343 expected.value = ASCIIToUTF16("Wy"); |
2382 expected.is_autofilled = false; | 2344 expected.is_autofilled = false; |
2383 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2345 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2384 | 2346 |
2385 expected.name = ASCIIToUTF16("lastname"); | 2347 expected.name = ASCIIToUTF16("lastname"); |
2386 expected.value = string16(); | 2348 expected.value = string16(); |
2387 expected.is_autofilled = false; | 2349 expected.is_autofilled = false; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2476 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, | 2438 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, |
2477 autofill::REQUIRE_NONE)); | 2439 autofill::REQUIRE_NONE)); |
2478 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2440 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
2479 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2441 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
2480 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2442 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2481 | 2443 |
2482 const std::vector<FormFieldData>& fields2 = form2.fields; | 2444 const std::vector<FormFieldData>& fields2 = form2.fields; |
2483 ASSERT_EQ(4U, fields2.size()); | 2445 ASSERT_EQ(4U, fields2.size()); |
2484 | 2446 |
2485 FormFieldData expected; | 2447 FormFieldData expected; |
2486 expected.form_control_type = ASCIIToUTF16("text"); | 2448 expected.form_control_type = "text"; |
2487 expected.max_length = WebInputElement::defaultMaxLength(); | 2449 expected.max_length = WebInputElement::defaultMaxLength(); |
2488 | 2450 |
2489 expected.name = ASCIIToUTF16("firstname"); | 2451 expected.name = ASCIIToUTF16("firstname"); |
2490 expected.value = string16(); | 2452 expected.value = string16(); |
2491 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 2453 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
2492 | 2454 |
2493 expected.name = ASCIIToUTF16("lastname"); | 2455 expected.name = ASCIIToUTF16("lastname"); |
2494 expected.value = string16(); | 2456 expected.value = string16(); |
2495 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 2457 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
2496 | 2458 |
2497 expected.name = ASCIIToUTF16("noAC"); | 2459 expected.name = ASCIIToUTF16("noAC"); |
2498 expected.value = string16(); | 2460 expected.value = string16(); |
| 2461 expected.autocomplete_attribute = "off"; |
2499 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2462 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2463 expected.autocomplete_attribute = std::string(); // reset |
2500 | 2464 |
2501 expected.name = ASCIIToUTF16("notenabled"); | 2465 expected.name = ASCIIToUTF16("notenabled"); |
2502 expected.value = ASCIIToUTF16("no clear"); | 2466 expected.value = ASCIIToUTF16("no clear"); |
2503 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); | 2467 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); |
2504 | 2468 |
2505 // Verify that the cursor position has been updated. | 2469 // Verify that the cursor position has been updated. |
2506 EXPECT_EQ(0, firstname.selectionStart()); | 2470 EXPECT_EQ(0, firstname.selectionStart()); |
2507 EXPECT_EQ(0, firstname.selectionEnd()); | 2471 EXPECT_EQ(0, firstname.selectionEnd()); |
2508 } | 2472 } |
2509 | 2473 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2518 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
2555 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2519 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
2556 | 2520 |
2557 const std::vector<FormFieldData>& fields2 = form2.fields; | 2521 const std::vector<FormFieldData>& fields2 = form2.fields; |
2558 ASSERT_EQ(3U, fields2.size()); | 2522 ASSERT_EQ(3U, fields2.size()); |
2559 | 2523 |
2560 FormFieldData expected; | 2524 FormFieldData expected; |
2561 | 2525 |
2562 expected.name = ASCIIToUTF16("firstname"); | 2526 expected.name = ASCIIToUTF16("firstname"); |
2563 expected.value = string16(); | 2527 expected.value = string16(); |
2564 expected.form_control_type = ASCIIToUTF16("text"); | 2528 expected.form_control_type = "text"; |
2565 expected.max_length = WebInputElement::defaultMaxLength(); | 2529 expected.max_length = WebInputElement::defaultMaxLength(); |
2566 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 2530 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
2567 | 2531 |
2568 expected.name = ASCIIToUTF16("lastname"); | 2532 expected.name = ASCIIToUTF16("lastname"); |
2569 expected.value = string16(); | 2533 expected.value = string16(); |
2570 expected.form_control_type = ASCIIToUTF16("text"); | 2534 expected.form_control_type = "text"; |
2571 expected.max_length = WebInputElement::defaultMaxLength(); | 2535 expected.max_length = WebInputElement::defaultMaxLength(); |
2572 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 2536 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
2573 | 2537 |
2574 expected.name = ASCIIToUTF16("state"); | 2538 expected.name = ASCIIToUTF16("state"); |
2575 expected.value = ASCIIToUTF16("?"); | 2539 expected.value = ASCIIToUTF16("?"); |
2576 expected.form_control_type = ASCIIToUTF16("select-one"); | 2540 expected.form_control_type = "select-one"; |
2577 expected.max_length = 0; | 2541 expected.max_length = 0; |
2578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2542 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
2579 | 2543 |
2580 // Verify that the cursor position has been updated. | 2544 // Verify that the cursor position has been updated. |
2581 EXPECT_EQ(0, firstname.selectionStart()); | 2545 EXPECT_EQ(0, firstname.selectionStart()); |
2582 EXPECT_EQ(0, firstname.selectionEnd()); | 2546 EXPECT_EQ(0, firstname.selectionEnd()); |
2583 } | 2547 } |
2584 | 2548 |
2585 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 2549 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
2586 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2550 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2847 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
2884 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2848 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2885 | 2849 |
2886 const std::vector<FormFieldData>& fields = form.fields; | 2850 const std::vector<FormFieldData>& fields = form.fields; |
2887 ASSERT_EQ(3U, fields.size()); | 2851 ASSERT_EQ(3U, fields.size()); |
2888 | 2852 |
2889 FormFieldData expected; | 2853 FormFieldData expected; |
2890 | 2854 |
2891 expected.name = ASCIIToUTF16("firstname"); | 2855 expected.name = ASCIIToUTF16("firstname"); |
2892 expected.value = ASCIIToUTF16("John"); | 2856 expected.value = ASCIIToUTF16("John"); |
2893 expected.form_control_type = ASCIIToUTF16("text"); | 2857 expected.form_control_type = "text"; |
2894 expected.max_length = WebInputElement::defaultMaxLength(); | 2858 expected.max_length = WebInputElement::defaultMaxLength(); |
2895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2859 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2896 | 2860 |
2897 expected.name = ASCIIToUTF16("lastname"); | 2861 expected.name = ASCIIToUTF16("lastname"); |
2898 expected.value = ASCIIToUTF16("Smith"); | 2862 expected.value = ASCIIToUTF16("Smith"); |
2899 expected.form_control_type = ASCIIToUTF16("text"); | 2863 expected.form_control_type = "text"; |
2900 expected.max_length = WebInputElement::defaultMaxLength(); | 2864 expected.max_length = WebInputElement::defaultMaxLength(); |
2901 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2865 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2902 | 2866 |
2903 expected.name = ASCIIToUTF16("country"); | 2867 expected.name = ASCIIToUTF16("country"); |
2904 expected.value = ASCIIToUTF16("Albania"); | 2868 expected.value = ASCIIToUTF16("Albania"); |
2905 expected.form_control_type = ASCIIToUTF16("select-one"); | 2869 expected.form_control_type = "select-one"; |
2906 expected.max_length = 0; | 2870 expected.max_length = 0; |
2907 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2871 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2908 | 2872 |
2909 form.fields.clear(); | 2873 form.fields.clear(); |
2910 // Extract the country select-one value as value. | 2874 // Extract the country select-one value as value. |
2911 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 2875 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
2912 WebFormControlElement(), | 2876 WebFormControlElement(), |
2913 autofill::REQUIRE_NONE, | 2877 autofill::REQUIRE_NONE, |
2914 autofill::EXTRACT_VALUE, | 2878 autofill::EXTRACT_VALUE, |
2915 &form, | 2879 &form, |
2916 NULL)); | 2880 NULL)); |
2917 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2881 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2918 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2882 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
2919 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2883 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
2920 | 2884 |
2921 ASSERT_EQ(3U, fields.size()); | 2885 ASSERT_EQ(3U, fields.size()); |
2922 | 2886 |
2923 expected.name = ASCIIToUTF16("firstname"); | 2887 expected.name = ASCIIToUTF16("firstname"); |
2924 expected.value = ASCIIToUTF16("John"); | 2888 expected.value = ASCIIToUTF16("John"); |
2925 expected.form_control_type = ASCIIToUTF16("text"); | 2889 expected.form_control_type = "text"; |
2926 expected.max_length = WebInputElement::defaultMaxLength(); | 2890 expected.max_length = WebInputElement::defaultMaxLength(); |
2927 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 2891 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
2928 | 2892 |
2929 expected.name = ASCIIToUTF16("lastname"); | 2893 expected.name = ASCIIToUTF16("lastname"); |
2930 expected.value = ASCIIToUTF16("Smith"); | 2894 expected.value = ASCIIToUTF16("Smith"); |
2931 expected.form_control_type = ASCIIToUTF16("text"); | 2895 expected.form_control_type = "text"; |
2932 expected.max_length = WebInputElement::defaultMaxLength(); | 2896 expected.max_length = WebInputElement::defaultMaxLength(); |
2933 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2897 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2934 | 2898 |
2935 expected.name = ASCIIToUTF16("country"); | 2899 expected.name = ASCIIToUTF16("country"); |
2936 expected.value = ASCIIToUTF16("AL"); | 2900 expected.value = ASCIIToUTF16("AL"); |
2937 expected.form_control_type = ASCIIToUTF16("select-one"); | 2901 expected.form_control_type = "select-one"; |
2938 expected.max_length = 0; | 2902 expected.max_length = 0; |
2939 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2903 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2940 } | 2904 } |
OLD | NEW |