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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 const char* const initial_value; | 51 const char* const initial_value; |
52 const char* const autocomplete_attribute; // The autocomplete attribute of | 52 const char* const autocomplete_attribute; // The autocomplete attribute of |
53 // the element. | 53 // the element. |
54 bool should_be_autofilled; // Whether the filed should be autofilled. | 54 bool should_be_autofilled; // Whether the filed should be autofilled. |
55 const char* const autofill_value; // The value being used to fill the field. | 55 const char* const autofill_value; // The value being used to fill the field. |
56 const char* const expected_value; // The expected value after Autofill | 56 const char* const expected_value; // The expected value after Autofill |
57 // or Preview. | 57 // or Preview. |
58 }; | 58 }; |
59 | 59 |
60 static const char kFormHtml[] = | 60 static const char kFormHtml[] = |
61 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 61 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
62 " <INPUT type=\"text\" id=\"firstname\"/>" | 62 " <INPUT type='text' id='firstname'/>" |
63 " <INPUT type=\"text\" id=\"lastname\"/>" | 63 " <INPUT type='text' id='lastname'/>" |
64 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 64 " <INPUT type='hidden' id='imhidden'/>" |
65 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 65 " <INPUT type='text' id='notempty' value='Hi'/>" |
66 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" | 66 " <INPUT type='text' autocomplete='off' id='noautocomplete'/>" |
67 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" | 67 " <INPUT type='text' disabled='disabled' id='notenabled'/>" |
68 " <INPUT type=\"text\" readonly id=\"readonly\"/>" | 68 " <INPUT type='text' readonly id='readonly'/>" |
69 " <INPUT type=\"text\" style=\"visibility: hidden\"" | 69 " <INPUT type='text' style='visibility: hidden'" |
70 " id=\"invisible\"/>" | 70 " id='invisible'/>" |
71 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>" | 71 " <INPUT type='text' style='display: none' id='displaynone'/>" |
72 " <INPUT type=\"month\" id=\"month\"/>" | 72 " <INPUT type='month' id='month'/>" |
73 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>" | 73 " <INPUT type='month' id='month-nonempty' value='2011-12'/>" |
74 " <SELECT id=\"select\">" | 74 " <SELECT id='select'>" |
75 " <OPTION></OPTION>" | 75 " <OPTION></OPTION>" |
76 " <OPTION value=\"CA\">California</OPTION>" | 76 " <OPTION value='CA'>California</OPTION>" |
77 " <OPTION value=\"TX\">Texas</OPTION>" | 77 " <OPTION value='TX'>Texas</OPTION>" |
78 " </SELECT>" | 78 " </SELECT>" |
79 " <SELECT id=\"select-nonempty\">" | 79 " <SELECT id='select-nonempty'>" |
80 " <OPTION value=\"CA\" selected>California</OPTION>" | 80 " <OPTION value='CA' selected>California</OPTION>" |
81 " <OPTION value=\"TX\">Texas</OPTION>" | 81 " <OPTION value='TX'>Texas</OPTION>" |
82 " </SELECT>" | 82 " </SELECT>" |
83 " <SELECT id=\"select-unchanged\">" | 83 " <SELECT id='select-unchanged'>" |
84 " <OPTION value=\"CA\" selected>California</OPTION>" | 84 " <OPTION value='CA' selected>California</OPTION>" |
85 " <OPTION value=\"TX\">Texas</OPTION>" | 85 " <OPTION value='TX'>Texas</OPTION>" |
86 " </SELECT>" | 86 " </SELECT>" |
87 " <TEXTAREA id=\"textarea\"></TEXTAREA>" | 87 " <TEXTAREA id='textarea'></TEXTAREA>" |
88 " <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>" | 88 " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>" |
89 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 89 " <INPUT type='submit' name='reply-send' value='Send'/>" |
90 "</FORM>"; | 90 "</FORM>"; |
91 | 91 |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 namespace autofill { | 94 namespace autofill { |
95 | 95 |
96 class FormAutofillTest : public ChromeRenderViewTest { | 96 class FormAutofillTest : public ChromeRenderViewTest { |
97 public: | 97 public: |
98 FormAutofillTest() : ChromeRenderViewTest() {} | 98 FormAutofillTest() : ChromeRenderViewTest() {} |
99 virtual ~FormAutofillTest() {} | 99 virtual ~FormAutofillTest() {} |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 288 |
289 return element.to<WebInputElement>().suggestedValue(); | 289 return element.to<WebInputElement>().suggestedValue(); |
290 } | 290 } |
291 | 291 |
292 private: | 292 private: |
293 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); | 293 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); |
294 }; | 294 }; |
295 | 295 |
296 // We should be able to extract a normal text field. | 296 // We should be able to extract a normal text field. |
297 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { | 297 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { |
298 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 298 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
299 | 299 |
300 WebFrame* frame = GetMainFrame(); | 300 WebFrame* frame = GetMainFrame(); |
301 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 301 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
302 | 302 |
303 WebElement web_element = frame->document().getElementById("element"); | 303 WebElement web_element = frame->document().getElementById("element"); |
304 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 304 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
305 FormFieldData result1; | 305 FormFieldData result1; |
306 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 306 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); |
307 | 307 |
308 FormFieldData expected; | 308 FormFieldData expected; |
309 expected.form_control_type = "text"; | 309 expected.form_control_type = "text"; |
310 expected.max_length = WebInputElement::defaultMaxLength(); | 310 expected.max_length = WebInputElement::defaultMaxLength(); |
311 | 311 |
312 expected.name = ASCIIToUTF16("element"); | 312 expected.name = ASCIIToUTF16("element"); |
313 expected.value = base::string16(); | 313 expected.value = base::string16(); |
314 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 314 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
315 | 315 |
316 FormFieldData result2; | 316 FormFieldData result2; |
317 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | 317 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); |
318 | 318 |
319 expected.name = ASCIIToUTF16("element"); | 319 expected.name = ASCIIToUTF16("element"); |
320 expected.value = ASCIIToUTF16("value"); | 320 expected.value = ASCIIToUTF16("value"); |
321 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | 321 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
322 } | 322 } |
323 | 323 |
324 // We should be able to extract a text field with autocomplete="off". | 324 // We should be able to extract a text field with autocomplete="off". |
325 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { | 325 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { |
326 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 326 LoadHTML("<INPUT type='text' id='element' value='value'" |
327 " autocomplete=\"off\"/>"); | 327 " autocomplete='off'/>"); |
328 | 328 |
329 WebFrame* frame = GetMainFrame(); | 329 WebFrame* frame = GetMainFrame(); |
330 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 330 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
331 | 331 |
332 WebElement web_element = frame->document().getElementById("element"); | 332 WebElement web_element = frame->document().getElementById("element"); |
333 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 333 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
334 FormFieldData result; | 334 FormFieldData result; |
335 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 335 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
336 | 336 |
337 FormFieldData expected; | 337 FormFieldData expected; |
338 expected.name = ASCIIToUTF16("element"); | 338 expected.name = ASCIIToUTF16("element"); |
339 expected.value = ASCIIToUTF16("value"); | 339 expected.value = ASCIIToUTF16("value"); |
340 expected.form_control_type = "text"; | 340 expected.form_control_type = "text"; |
341 expected.autocomplete_attribute = "off"; | 341 expected.autocomplete_attribute = "off"; |
342 expected.max_length = WebInputElement::defaultMaxLength(); | 342 expected.max_length = WebInputElement::defaultMaxLength(); |
343 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 343 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
344 } | 344 } |
345 | 345 |
346 // We should be able to extract a text field with maxlength specified. | 346 // We should be able to extract a text field with maxlength specified. |
347 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 347 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
348 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 348 LoadHTML("<INPUT type='text' id='element' value='value'" |
349 " maxlength=\"5\"/>"); | 349 " maxlength='5'/>"); |
350 | 350 |
351 WebFrame* frame = GetMainFrame(); | 351 WebFrame* frame = GetMainFrame(); |
352 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 352 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
353 | 353 |
354 WebElement web_element = frame->document().getElementById("element"); | 354 WebElement web_element = frame->document().getElementById("element"); |
355 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 355 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
356 FormFieldData result; | 356 FormFieldData result; |
357 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 357 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
358 | 358 |
359 FormFieldData expected; | 359 FormFieldData expected; |
360 expected.name = ASCIIToUTF16("element"); | 360 expected.name = ASCIIToUTF16("element"); |
361 expected.value = ASCIIToUTF16("value"); | 361 expected.value = ASCIIToUTF16("value"); |
362 expected.form_control_type = "text"; | 362 expected.form_control_type = "text"; |
363 expected.max_length = 5; | 363 expected.max_length = 5; |
364 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 364 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
365 } | 365 } |
366 | 366 |
367 // We should be able to extract a text field that has been autofilled. | 367 // We should be able to extract a text field that has been autofilled. |
368 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 368 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
369 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 369 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
370 | 370 |
371 WebFrame* frame = GetMainFrame(); | 371 WebFrame* frame = GetMainFrame(); |
372 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 372 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
373 | 373 |
374 WebElement web_element = frame->document().getElementById("element"); | 374 WebElement web_element = frame->document().getElementById("element"); |
375 WebInputElement element = web_element.to<WebInputElement>(); | 375 WebInputElement element = web_element.to<WebInputElement>(); |
376 element.setAutofilled(true); | 376 element.setAutofilled(true); |
377 FormFieldData result; | 377 FormFieldData result; |
378 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 378 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
379 | 379 |
380 FormFieldData expected; | 380 FormFieldData expected; |
381 expected.name = ASCIIToUTF16("element"); | 381 expected.name = ASCIIToUTF16("element"); |
382 expected.value = ASCIIToUTF16("value"); | 382 expected.value = ASCIIToUTF16("value"); |
383 expected.form_control_type = "text"; | 383 expected.form_control_type = "text"; |
384 expected.max_length = WebInputElement::defaultMaxLength(); | 384 expected.max_length = WebInputElement::defaultMaxLength(); |
385 expected.is_autofilled = true; | 385 expected.is_autofilled = true; |
386 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 386 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
387 } | 387 } |
388 | 388 |
389 // We should be able to extract a radio or a checkbox field that has been | 389 // We should be able to extract a radio or a checkbox field that has been |
390 // autofilled. | 390 // autofilled. |
391 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { | 391 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
392 LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\" checked/>" | 392 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" |
393 "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>"); | 393 "<INPUT type='radio' id='radio' value='male'/>"); |
394 | 394 |
395 WebFrame* frame = GetMainFrame(); | 395 WebFrame* frame = GetMainFrame(); |
396 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 396 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
397 | 397 |
398 WebElement web_element = frame->document().getElementById("checkbox"); | 398 WebElement web_element = frame->document().getElementById("checkbox"); |
399 WebInputElement element = web_element.to<WebInputElement>(); | 399 WebInputElement element = web_element.to<WebInputElement>(); |
400 element.setAutofilled(true); | 400 element.setAutofilled(true); |
401 FormFieldData result; | 401 FormFieldData result; |
402 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 402 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
403 | 403 |
(...skipping 14 matching lines...) Expand all Loading... |
418 expected.value = ASCIIToUTF16("male"); | 418 expected.value = ASCIIToUTF16("male"); |
419 expected.form_control_type = "radio"; | 419 expected.form_control_type = "radio"; |
420 expected.is_autofilled = true; | 420 expected.is_autofilled = true; |
421 expected.is_checkable = true; | 421 expected.is_checkable = true; |
422 expected.is_checked = false; | 422 expected.is_checked = false; |
423 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 423 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
424 } | 424 } |
425 | 425 |
426 // We should be able to extract a <select> field. | 426 // We should be able to extract a <select> field. |
427 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 427 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
428 LoadHTML("<SELECT id=\"element\"/>" | 428 LoadHTML("<SELECT id='element'/>" |
429 " <OPTION value=\"CA\">California</OPTION>" | 429 " <OPTION value='CA'>California</OPTION>" |
430 " <OPTION value=\"TX\">Texas</OPTION>" | 430 " <OPTION value='TX'>Texas</OPTION>" |
431 "</SELECT>"); | 431 "</SELECT>"); |
432 | 432 |
433 WebFrame* frame = GetMainFrame(); | 433 WebFrame* frame = GetMainFrame(); |
434 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 434 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
435 | 435 |
436 WebElement web_element = frame->document().getElementById("element"); | 436 WebElement web_element = frame->document().getElementById("element"); |
437 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 437 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
438 FormFieldData result1; | 438 FormFieldData result1; |
439 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | 439 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); |
440 | 440 |
(...skipping 24 matching lines...) Expand all Loading... |
465 ASSERT_EQ(2U, result3.option_contents.size()); | 465 ASSERT_EQ(2U, result3.option_contents.size()); |
466 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); | 466 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); |
467 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 467 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
468 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 468 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
469 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 469 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
470 } | 470 } |
471 | 471 |
472 // When faced with <select> field with *many* options, we should trim them to a | 472 // When faced with <select> field with *many* options, we should trim them to a |
473 // reasonable number. | 473 // reasonable number. |
474 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { | 474 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { |
475 std::string html = "<SELECT id=\"element\"/>"; | 475 std::string html = "<SELECT id='element'/>"; |
476 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { | 476 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { |
477 html += base::StringPrintf("<OPTION value=\"%" PRIuS "\">" | 477 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" |
478 "%" PRIuS "</OPTION>", i, i); | 478 "%" PRIuS "</OPTION>", i, i); |
479 } | 479 } |
480 html += "</SELECT>"; | 480 html += "</SELECT>"; |
481 LoadHTML(html.c_str()); | 481 LoadHTML(html.c_str()); |
482 | 482 |
483 WebFrame* frame = GetMainFrame(); | 483 WebFrame* frame = GetMainFrame(); |
484 ASSERT_TRUE(frame); | 484 ASSERT_TRUE(frame); |
485 | 485 |
486 WebElement web_element = frame->document().getElementById("element"); | 486 WebElement web_element = frame->document().getElementById("element"); |
487 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 487 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
488 FormFieldData result; | 488 FormFieldData result; |
489 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result); | 489 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result); |
490 | 490 |
491 EXPECT_EQ(0U, result.option_values.size()); | 491 EXPECT_EQ(0U, result.option_values.size()); |
492 EXPECT_EQ(0U, result.option_contents.size()); | 492 EXPECT_EQ(0U, result.option_contents.size()); |
493 } | 493 } |
494 | 494 |
495 // We should be able to extract a <textarea> field. | 495 // We should be able to extract a <textarea> field. |
496 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { | 496 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { |
497 LoadHTML("<TEXTAREA id=\"element\">" | 497 LoadHTML("<TEXTAREA id='element'>" |
498 "This element's value " | 498 "This element's value " |
499 "spans multiple lines." | 499 "spans multiple lines." |
500 "</TEXTAREA>"); | 500 "</TEXTAREA>"); |
501 | 501 |
502 WebFrame* frame = GetMainFrame(); | 502 WebFrame* frame = GetMainFrame(); |
503 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 503 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
504 | 504 |
505 WebElement web_element = frame->document().getElementById("element"); | 505 WebElement web_element = frame->document().getElementById("element"); |
506 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 506 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
507 FormFieldData result_sans_value; | 507 FormFieldData result_sans_value; |
508 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 508 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, |
509 &result_sans_value); | 509 &result_sans_value); |
510 | 510 |
511 FormFieldData expected; | 511 FormFieldData expected; |
512 expected.name = ASCIIToUTF16("element"); | 512 expected.name = ASCIIToUTF16("element"); |
513 expected.max_length = 0; | 513 expected.max_length = 0; |
514 expected.form_control_type = "textarea"; | 514 expected.form_control_type = "textarea"; |
515 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 515 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
516 | 516 |
517 FormFieldData result_with_value; | 517 FormFieldData result_with_value; |
518 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 518 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, |
519 &result_with_value); | 519 &result_with_value); |
520 expected.value = ASCIIToUTF16("This element's value\n" | 520 expected.value = ASCIIToUTF16("This element's value\n" |
521 "spans multiple lines."); | 521 "spans multiple lines."); |
522 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 522 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
523 } | 523 } |
524 | 524 |
525 // We should be able to extract an <input type="month"> field. | 525 // We should be able to extract an <input type="month"> field. |
526 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { | 526 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { |
527 LoadHTML("<INPUT type=\"month\" id=\"element\" value=\"2011-12\">"); | 527 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); |
528 | 528 |
529 WebFrame* frame = GetMainFrame(); | 529 WebFrame* frame = GetMainFrame(); |
530 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 530 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
531 | 531 |
532 WebElement web_element = frame->document().getElementById("element"); | 532 WebElement web_element = frame->document().getElementById("element"); |
533 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 533 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
534 FormFieldData result_sans_value; | 534 FormFieldData result_sans_value; |
535 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 535 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, |
536 &result_sans_value); | 536 &result_sans_value); |
537 | 537 |
538 FormFieldData expected; | 538 FormFieldData expected; |
539 expected.name = ASCIIToUTF16("element"); | 539 expected.name = ASCIIToUTF16("element"); |
540 expected.max_length = 0; | 540 expected.max_length = 0; |
541 expected.form_control_type = "month"; | 541 expected.form_control_type = "month"; |
542 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 542 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
543 | 543 |
544 FormFieldData result_with_value; | 544 FormFieldData result_with_value; |
545 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 545 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, |
546 &result_with_value); | 546 &result_with_value); |
547 expected.value = ASCIIToUTF16("2011-12"); | 547 expected.value = ASCIIToUTF16("2011-12"); |
548 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 548 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
549 } | 549 } |
550 | 550 |
551 // We should not extract the value for non-text and non-select fields. | 551 // We should not extract the value for non-text and non-select fields. |
552 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 552 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
553 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 553 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
554 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" | 554 " <INPUT type='hidden' id='hidden' value='apple'/>" |
555 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" | 555 " <INPUT type='submit' id='submit' value='Send'/>" |
556 "</FORM>"); | 556 "</FORM>"); |
557 | 557 |
558 WebFrame* frame = GetMainFrame(); | 558 WebFrame* frame = GetMainFrame(); |
559 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 559 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
560 | 560 |
561 WebElement web_element = frame->document().getElementById("hidden"); | 561 WebElement web_element = frame->document().getElementById("hidden"); |
562 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 562 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
563 FormFieldData result; | 563 FormFieldData result; |
564 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 564 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
565 | 565 |
566 FormFieldData expected; | 566 FormFieldData expected; |
567 expected.max_length = 0; | 567 expected.max_length = 0; |
568 | 568 |
569 expected.name = ASCIIToUTF16("hidden"); | 569 expected.name = ASCIIToUTF16("hidden"); |
570 expected.form_control_type = "hidden"; | 570 expected.form_control_type = "hidden"; |
571 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 571 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
572 | 572 |
573 web_element = frame->document().getElementById("submit"); | 573 web_element = frame->document().getElementById("submit"); |
574 element = web_element.to<WebFormControlElement>(); | 574 element = web_element.to<WebFormControlElement>(); |
575 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 575 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
576 expected.name = ASCIIToUTF16("submit"); | 576 expected.name = ASCIIToUTF16("submit"); |
577 expected.form_control_type = "submit"; | 577 expected.form_control_type = "submit"; |
578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
579 } | 579 } |
580 | 580 |
581 // We should be able to extract password fields. | 581 // We should be able to extract password fields. |
582 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { | 582 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { |
583 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 583 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
584 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 584 " <INPUT type='password' id='password' value='secret'/>" |
585 "</FORM>"); | 585 "</FORM>"); |
586 | 586 |
587 WebFrame* frame = GetMainFrame(); | 587 WebFrame* frame = GetMainFrame(); |
588 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 588 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
589 | 589 |
590 WebElement web_element = frame->document().getElementById("password"); | 590 WebElement web_element = frame->document().getElementById("password"); |
591 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 591 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
592 FormFieldData result; | 592 FormFieldData result; |
593 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 593 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
594 | 594 |
595 FormFieldData expected; | 595 FormFieldData expected; |
596 expected.max_length = WebInputElement::defaultMaxLength(); | 596 expected.max_length = WebInputElement::defaultMaxLength(); |
597 expected.name = ASCIIToUTF16("password"); | 597 expected.name = ASCIIToUTF16("password"); |
598 expected.form_control_type = "password"; | 598 expected.form_control_type = "password"; |
599 expected.value = ASCIIToUTF16("secret"); | 599 expected.value = ASCIIToUTF16("secret"); |
600 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 600 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
601 } | 601 } |
602 | 602 |
603 // We should be able to extract the autocompletetype attribute. | 603 // We should be able to extract the autocompletetype attribute. |
604 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { | 604 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { |
605 std::string html = | 605 std::string html = |
606 "<INPUT type=\"text\" id=\"absent\"/>" | 606 "<INPUT type='text' id='absent'/>" |
607 "<INPUT type=\"text\" id=\"empty\" autocomplete=\"\"/>" | 607 "<INPUT type='text' id='empty' autocomplete=''/>" |
608 "<INPUT type=\"text\" id=\"off\" autocomplete=\"off\"/>" | 608 "<INPUT type='text' id='off' autocomplete='off'/>" |
609 "<INPUT type=\"text\" id=\"regular\" autocomplete=\"email\"/>" | 609 "<INPUT type='text' id='regular' autocomplete='email'/>" |
610 "<INPUT type=\"text\" id=\"multi-valued\" " | 610 "<INPUT type='text' id='multi-valued' " |
611 " autocomplete=\"billing email\"/>" | 611 " autocomplete='billing email'/>" |
612 "<INPUT type=\"text\" id=\"experimental\" x-autocompletetype=\"email\"/>" | 612 "<INPUT type='text' id='experimental' x-autocompletetype='email'/>" |
613 "<INPUT type=\"month\" id=\"month\" autocomplete=\"cc-exp\"/>" | 613 "<INPUT type='month' id='month' autocomplete='cc-exp'/>" |
614 "<SELECT id=\"select\" autocomplete=\"state\"/>" | 614 "<SELECT id='select' autocomplete='state'/>" |
615 " <OPTION value=\"CA\">California</OPTION>" | 615 " <OPTION value='CA'>California</OPTION>" |
616 " <OPTION value=\"TX\">Texas</OPTION>" | 616 " <OPTION value='TX'>Texas</OPTION>" |
617 "</SELECT>" | 617 "</SELECT>" |
618 "<TEXTAREA id=\"textarea\" autocomplete=\"street-address\">" | 618 "<TEXTAREA id='textarea' autocomplete='street-address'>" |
619 " Some multi-" | 619 " Some multi-" |
620 " lined value" | 620 " lined value" |
621 "</TEXTAREA>"; | 621 "</TEXTAREA>"; |
622 html += | 622 html += |
623 "<INPUT type=\"text\" id=\"malicious\" autocomplete=\"" + | 623 "<INPUT type='text' id='malicious' autocomplete='" + |
624 std::string(10000, 'x') + "\"/>"; | 624 std::string(10000, 'x') + "'/>"; |
625 LoadHTML(html.c_str()); | 625 LoadHTML(html.c_str()); |
626 | 626 |
627 WebFrame* frame = GetMainFrame(); | 627 WebFrame* frame = GetMainFrame(); |
628 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 628 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
629 | 629 |
630 struct TestCase { | 630 struct TestCase { |
631 const std::string element_id; | 631 const std::string element_id; |
632 const std::string form_control_type; | 632 const std::string form_control_type; |
633 const std::string autocomplete_attribute; | 633 const std::string autocomplete_attribute; |
634 }; | 634 }; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 794 |
795 WebElement web_element = frame->document().getElementById("element"); | 795 WebElement web_element = frame->document().getElementById("element"); |
796 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 796 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
797 | 797 |
798 FormFieldData result; | 798 FormFieldData result; |
799 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 799 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
800 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 800 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
801 } | 801 } |
802 | 802 |
803 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 803 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
804 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 804 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
805 " <LABEL for=\"firstname\">First name:</LABEL>" | 805 " <LABEL for='firstname'>First name:</LABEL>" |
806 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 806 " <INPUT type='text' id='firstname' value='John'/>" |
807 " <LABEL for=\"lastname\">Last name:</LABEL>" | 807 " <LABEL for='lastname'>Last name:</LABEL>" |
808 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 808 " <INPUT type='text' id='lastname' value='Smith'/>" |
809 " <LABEL for=\"street-address\">Address:</LABEL>" | 809 " <LABEL for='street-address'>Address:</LABEL>" |
810 " <TEXTAREA id=\"street-address\">" | 810 " <TEXTAREA id='street-address'>" |
811 "123 Fantasy Ln. " | 811 "123 Fantasy Ln. " |
812 "Apt. 42" | 812 "Apt. 42" |
813 "</TEXTAREA>" | 813 "</TEXTAREA>" |
814 " <LABEL for=\"state\">State:</LABEL>" | 814 " <LABEL for='state'>State:</LABEL>" |
815 " <SELECT id=\"state\"/>" | 815 " <SELECT id='state'/>" |
816 " <OPTION value=\"CA\">California</OPTION>" | 816 " <OPTION value='CA'>California</OPTION>" |
817 " <OPTION value=\"TX\">Texas</OPTION>" | 817 " <OPTION value='TX'>Texas</OPTION>" |
818 " </SELECT>" | 818 " </SELECT>" |
819 " <LABEL for=\"password\">Password:</LABEL>" | 819 " <LABEL for='password'>Password:</LABEL>" |
820 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 820 " <INPUT type='password' id='password' value='secret'/>" |
821 " <LABEL for=\"month\">Card expiration:</LABEL>" | 821 " <LABEL for='month'>Card expiration:</LABEL>" |
822 " <INPUT type=\"month\" id=\"month\" value=\"2011-12\"/>" | 822 " <INPUT type='month' id='month' value='2011-12'/>" |
823 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 823 " <INPUT type='submit' name='reply-send' value='Send'/>" |
824 // The below inputs should be ignored | 824 // The below inputs should be ignored |
825 " <LABEL for=\"notvisible\">Hidden:</LABEL>" | 825 " <LABEL for='notvisible'>Hidden:</LABEL>" |
826 " <INPUT type=\"hidden\" id=\"notvisible\" value=\"apple\"/>" | 826 " <INPUT type='hidden' id='notvisible' value='apple'/>" |
827 "</FORM>"); | 827 "</FORM>"); |
828 | 828 |
829 WebFrame* frame = GetMainFrame(); | 829 WebFrame* frame = GetMainFrame(); |
830 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 830 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
831 | 831 |
832 WebVector<WebFormElement> forms; | 832 WebVector<WebFormElement> forms; |
833 frame->document().forms(forms); | 833 frame->document().forms(forms); |
834 ASSERT_EQ(1U, forms.size()); | 834 ASSERT_EQ(1U, forms.size()); |
835 | 835 |
836 WebElement element = frame->document().getElementById("firstname"); | 836 WebElement element = frame->document().getElementById("firstname"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 expected.value = ASCIIToUTF16("2011-12"); | 891 expected.value = ASCIIToUTF16("2011-12"); |
892 expected.label = ASCIIToUTF16("Card expiration:"); | 892 expected.label = ASCIIToUTF16("Card expiration:"); |
893 expected.form_control_type = "month"; | 893 expected.form_control_type = "month"; |
894 expected.max_length = 0; | 894 expected.max_length = 0; |
895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); | 895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
896 } | 896 } |
897 | 897 |
898 // We should not be able to serialize a form with too many fillable fields. | 898 // We should not be able to serialize a form with too many fillable fields. |
899 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { | 899 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
900 std::string html = | 900 std::string html = |
901 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; | 901 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; |
902 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { | 902 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { |
903 html += "<INPUT type=\"text\"/>"; | 903 html += "<INPUT type='text'/>"; |
904 } | 904 } |
905 html += "</FORM>"; | 905 html += "</FORM>"; |
906 LoadHTML(html.c_str()); | 906 LoadHTML(html.c_str()); |
907 | 907 |
908 WebFrame* frame = GetMainFrame(); | 908 WebFrame* frame = GetMainFrame(); |
909 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 909 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
910 | 910 |
911 WebVector<WebFormElement> forms; | 911 WebVector<WebFormElement> forms; |
912 frame->document().forms(forms); | 912 frame->document().forms(forms); |
913 ASSERT_EQ(1U, forms.size()); | 913 ASSERT_EQ(1U, forms.size()); |
914 | 914 |
915 WebElement element = frame->document().getElementById("firstname"); | 915 WebElement element = frame->document().getElementById("firstname"); |
916 WebInputElement input_element = element.to<WebInputElement>(); | 916 WebInputElement input_element = element.to<WebInputElement>(); |
917 | 917 |
918 FormData form; | 918 FormData form; |
919 FormFieldData field; | 919 FormFieldData field; |
920 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 920 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
921 input_element, | 921 input_element, |
922 autofill::REQUIRE_NONE, | 922 autofill::REQUIRE_NONE, |
923 autofill::EXTRACT_VALUE, | 923 autofill::EXTRACT_VALUE, |
924 &form, | 924 &form, |
925 &field)); | 925 &field)); |
926 } | 926 } |
927 | 927 |
928 TEST_F(FormAutofillTest, ExtractForms) { | 928 TEST_F(FormAutofillTest, ExtractForms) { |
929 ExpectJohnSmithLabels( | 929 ExpectJohnSmithLabels( |
930 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 930 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
931 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 931 " First name: <INPUT type='text' id='firstname' value='John'/>" |
932 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 932 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" |
933 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 933 " Email: <INPUT type='text' id='email' value='john@example.com'/>" |
934 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 934 " <INPUT type='submit' name='reply-send' value='Send'/>" |
935 "</FORM>"); | 935 "</FORM>"); |
936 } | 936 } |
937 | 937 |
938 TEST_F(FormAutofillTest, ExtractMultipleForms) { | 938 TEST_F(FormAutofillTest, ExtractMultipleForms) { |
939 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 939 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
940 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 940 " <INPUT type='text' id='firstname' value='John'/>" |
941 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 941 " <INPUT type='text' id='lastname' value='Smith'/>" |
942 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 942 " <INPUT type='text' id='email' value='john@example.com'/>" |
943 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 943 " <INPUT type='submit' name='reply-send' value='Send'/>" |
944 "</FORM>" | 944 "</FORM>" |
945 "<FORM name=\"TestForm2\" action=\"http://zoo.com\" method=\"post\">" | 945 "<FORM name='TestForm2' action='http://zoo.com' method='post'>" |
946 " <INPUT type=\"text\" id=\"firstname\" value=\"Jack\"/>" | 946 " <INPUT type='text' id='firstname' value='Jack'/>" |
947 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>" | 947 " <INPUT type='text' id='lastname' value='Adams'/>" |
948 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" | 948 " <INPUT type='text' id='email' value='jack@example.com'/>" |
949 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 949 " <INPUT type='submit' name='reply-send' value='Send'/>" |
950 "</FORM>"); | 950 "</FORM>"); |
951 | 951 |
952 WebFrame* web_frame = GetMainFrame(); | 952 WebFrame* web_frame = GetMainFrame(); |
953 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 953 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
954 | 954 |
955 FormCache form_cache; | 955 FormCache form_cache; |
956 std::vector<FormData> forms; | 956 std::vector<FormData> forms; |
957 form_cache.ExtractNewForms(*web_frame, &forms); | 957 form_cache.ExtractNewForms(*web_frame, &forms); |
958 ASSERT_EQ(2U, forms.size()); | 958 ASSERT_EQ(2U, forms.size()); |
959 | 959 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 expected.value = ASCIIToUTF16("Hope"); | 1102 expected.value = ASCIIToUTF16("Hope"); |
1103 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 1103 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
1104 | 1104 |
1105 expected.name = ASCIIToUTF16("second_email"); | 1105 expected.name = ASCIIToUTF16("second_email"); |
1106 expected.value = ASCIIToUTF16("bobhope@example.com"); | 1106 expected.value = ASCIIToUTF16("bobhope@example.com"); |
1107 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 1107 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
1108 } | 1108 } |
1109 | 1109 |
1110 // We should not extract a form if it has too few fillable fields. | 1110 // We should not extract a form if it has too few fillable fields. |
1111 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { | 1111 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { |
1112 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1112 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1113 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1113 " <INPUT type='text' id='firstname' value='John'/>" |
1114 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1114 " <INPUT type='text' id='lastname' value='Smith'/>" |
1115 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1115 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1116 "</FORM>"); | 1116 "</FORM>"); |
1117 | 1117 |
1118 WebFrame* web_frame = GetMainFrame(); | 1118 WebFrame* web_frame = GetMainFrame(); |
1119 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1119 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1120 | 1120 |
1121 FormCache form_cache; | 1121 FormCache form_cache; |
1122 std::vector<FormData> forms; | 1122 std::vector<FormData> forms; |
1123 form_cache.ExtractNewForms(*web_frame, &forms); | 1123 form_cache.ExtractNewForms(*web_frame, &forms); |
1124 EXPECT_EQ(0U, forms.size()); | 1124 EXPECT_EQ(0U, forms.size()); |
1125 } | 1125 } |
1126 | 1126 |
1127 // We should not report additional forms for empty forms. | 1127 // We should not report additional forms for empty forms. |
1128 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { | 1128 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { |
1129 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1129 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1130 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1130 " <INPUT type='text' id='firstname' value='John'/>" |
1131 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1131 " <INPUT type='text' id='lastname' value='Smith'/>" |
1132 "</FORM>"); | 1132 "</FORM>"); |
1133 | 1133 |
1134 WebFrame* web_frame = GetMainFrame(); | 1134 WebFrame* web_frame = GetMainFrame(); |
1135 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1135 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1136 | 1136 |
1137 FormCache form_cache; | 1137 FormCache form_cache; |
1138 std::vector<FormData> forms; | 1138 std::vector<FormData> forms; |
1139 form_cache.ExtractNewForms(*web_frame, &forms); | 1139 form_cache.ExtractNewForms(*web_frame, &forms); |
1140 EXPECT_EQ(0U, forms.size()); | 1140 EXPECT_EQ(0U, forms.size()); |
1141 } | 1141 } |
1142 | 1142 |
1143 // We should not report additional forms for empty forms. | 1143 // We should not report additional forms for empty forms. |
1144 TEST_F(FormAutofillTest, ExtractFormsNoFields) { | 1144 TEST_F(FormAutofillTest, ExtractFormsNoFields) { |
1145 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1145 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1146 "</FORM>"); | 1146 "</FORM>"); |
1147 | 1147 |
1148 WebFrame* web_frame = GetMainFrame(); | 1148 WebFrame* web_frame = GetMainFrame(); |
1149 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1149 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1150 | 1150 |
1151 FormCache form_cache; | 1151 FormCache form_cache; |
1152 std::vector<FormData> forms; | 1152 std::vector<FormData> forms; |
1153 form_cache.ExtractNewForms(*web_frame, &forms); | 1153 form_cache.ExtractNewForms(*web_frame, &forms); |
1154 EXPECT_EQ(0U, forms.size()); | 1154 EXPECT_EQ(0U, forms.size()); |
1155 } | 1155 } |
1156 | 1156 |
1157 // We should not extract a form if it has too few fillable fields. | 1157 // We should not extract a form if it has too few fillable fields. |
1158 // Make sure radio and checkbox fields don't count. | 1158 // Make sure radio and checkbox fields don't count. |
1159 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { | 1159 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { |
1160 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1160 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1161 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1161 " <INPUT type='text' id='firstname' value='John'/>" |
1162 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1162 " <INPUT type='text' id='lastname' value='Smith'/>" |
1163 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>" | 1163 " <INPUT type='radio' id='a_radio' value='0'/>" |
1164 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>" | 1164 " <INPUT type='checkbox' id='a_check' value='1'/>" |
1165 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1165 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1166 "</FORM>"); | 1166 "</FORM>"); |
1167 | 1167 |
1168 WebFrame* web_frame = GetMainFrame(); | 1168 WebFrame* web_frame = GetMainFrame(); |
1169 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1169 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1170 | 1170 |
1171 FormCache form_cache; | 1171 FormCache form_cache; |
1172 std::vector<FormData> forms; | 1172 std::vector<FormData> forms; |
1173 form_cache.ExtractNewForms(*web_frame, &forms); | 1173 form_cache.ExtractNewForms(*web_frame, &forms); |
1174 EXPECT_EQ(0U, forms.size()); | 1174 EXPECT_EQ(0U, forms.size()); |
1175 } | 1175 } |
1176 | 1176 |
1177 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { | 1177 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { |
1178 { | 1178 { |
1179 // Form is not auto-completable due to autocomplete=off. | 1179 // Form is not auto-completable due to autocomplete=off. |
1180 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\"" | 1180 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" |
1181 " autocomplete=off>" | 1181 " autocomplete=off>" |
1182 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1182 " <INPUT type='text' id='firstname' value='John'/>" |
1183 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1183 " <INPUT type='text' id='lastname' value='Smith'/>" |
1184 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1184 " <INPUT type='text' id='email' value='john@example.com'/>" |
1185 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1185 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1186 "</FORM>"); | 1186 "</FORM>"); |
1187 | 1187 |
1188 WebFrame* web_frame = GetMainFrame(); | 1188 WebFrame* web_frame = GetMainFrame(); |
1189 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1189 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1190 | 1190 |
1191 WebVector<WebFormElement> web_forms; | 1191 WebVector<WebFormElement> web_forms; |
1192 web_frame->document().forms(web_forms); | 1192 web_frame->document().forms(web_forms); |
1193 ASSERT_EQ(1U, web_forms.size()); | 1193 ASSERT_EQ(1U, web_forms.size()); |
1194 WebFormElement web_form = web_forms[0]; | 1194 WebFormElement web_form = web_forms[0]; |
1195 | 1195 |
1196 FormData form; | 1196 FormData form; |
1197 EXPECT_TRUE(WebFormElementToFormData( | 1197 EXPECT_TRUE(WebFormElementToFormData( |
1198 web_form, WebFormControlElement(), autofill::REQUIRE_NONE, | 1198 web_form, WebFormControlElement(), autofill::REQUIRE_NONE, |
1199 autofill::EXTRACT_NONE, &form, NULL)); | 1199 autofill::EXTRACT_NONE, &form, NULL)); |
1200 EXPECT_FALSE(WebFormElementToFormData( | 1200 EXPECT_FALSE(WebFormElementToFormData( |
1201 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, | 1201 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, |
1202 autofill::EXTRACT_NONE, &form, NULL)); | 1202 autofill::EXTRACT_NONE, &form, NULL)); |
1203 } | 1203 } |
1204 | 1204 |
1205 { | 1205 { |
1206 // The firstname element is not auto-completable due to autocomplete=off. | 1206 // The firstname element is not auto-completable due to autocomplete=off. |
1207 LoadHTML("<FORM name=\"TestForm\" action=\"http://abc.com\" " | 1207 LoadHTML("<FORM name='TestForm' action='http://abc.com' " |
1208 " method=\"post\">" | 1208 " method='post'>" |
1209 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"" | 1209 " <INPUT type='text' id='firstname' value='John'" |
1210 " autocomplete=off>" | 1210 " autocomplete=off>" |
1211 " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>" | 1211 " <INPUT type='text' id='middlename' value='Jack'/>" |
1212 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1212 " <INPUT type='text' id='lastname' value='Smith'/>" |
1213 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1213 " <INPUT type='text' id='email' value='john@example.com'/>" |
1214 " <INPUT type=\"submit\" name=\"reply\" value=\"Send\"/>" | 1214 " <INPUT type='submit' name='reply' value='Send'/>" |
1215 "</FORM>"); | 1215 "</FORM>"); |
1216 | 1216 |
1217 WebFrame* web_frame = GetMainFrame(); | 1217 WebFrame* web_frame = GetMainFrame(); |
1218 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1218 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1219 | 1219 |
1220 WebVector<WebFormElement> web_forms; | 1220 WebVector<WebFormElement> web_forms; |
1221 web_frame->document().forms(web_forms); | 1221 web_frame->document().forms(web_forms); |
1222 ASSERT_EQ(1U, web_forms.size()); | 1222 ASSERT_EQ(1U, web_forms.size()); |
1223 WebFormElement web_form = web_forms[0]; | 1223 WebFormElement web_form = web_forms[0]; |
1224 | 1224 |
(...skipping 21 matching lines...) Expand all Loading... |
1246 expected.value = ASCIIToUTF16("Smith"); | 1246 expected.value = ASCIIToUTF16("Smith"); |
1247 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 1247 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
1248 | 1248 |
1249 expected.name = ASCIIToUTF16("email"); | 1249 expected.name = ASCIIToUTF16("email"); |
1250 expected.value = ASCIIToUTF16("john@example.com"); | 1250 expected.value = ASCIIToUTF16("john@example.com"); |
1251 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 1251 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
1252 } | 1252 } |
1253 } | 1253 } |
1254 | 1254 |
1255 TEST_F(FormAutofillTest, FindFormForInputElement) { | 1255 TEST_F(FormAutofillTest, FindFormForInputElement) { |
1256 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1256 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
1257 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1257 " <INPUT type='text' id='firstname' value='John'/>" |
1258 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1258 " <INPUT type='text' id='lastname' value='Smith'/>" |
1259 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"" | 1259 " <INPUT type='text' id='email' value='john@example.com'" |
1260 "autocomplete=\"off\" />" | 1260 "autocomplete='off' />" |
1261 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>" | 1261 " <INPUT type='text' id='phone' value='1.800.555.1234'/>" |
1262 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1262 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1263 "</FORM>"); | 1263 "</FORM>"); |
1264 | 1264 |
1265 WebFrame* web_frame = GetMainFrame(); | 1265 WebFrame* web_frame = GetMainFrame(); |
1266 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1266 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1267 | 1267 |
1268 FormCache form_cache; | 1268 FormCache form_cache; |
1269 std::vector<FormData> forms; | 1269 std::vector<FormData> forms; |
1270 form_cache.ExtractNewForms(*web_frame, &forms); | 1270 form_cache.ExtractNewForms(*web_frame, &forms); |
1271 ASSERT_EQ(1U, forms.size()); | 1271 ASSERT_EQ(1U, forms.size()); |
1272 | 1272 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 expected.name = ASCIIToUTF16("lastname"); | 1337 expected.name = ASCIIToUTF16("lastname"); |
1338 expected.value = ASCIIToUTF16("Smith"); | 1338 expected.value = ASCIIToUTF16("Smith"); |
1339 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 1339 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
1340 | 1340 |
1341 expected.name = ASCIIToUTF16("phone"); | 1341 expected.name = ASCIIToUTF16("phone"); |
1342 expected.value = ASCIIToUTF16("1.800.555.1234"); | 1342 expected.value = ASCIIToUTF16("1.800.555.1234"); |
1343 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 1343 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
1344 } | 1344 } |
1345 | 1345 |
1346 TEST_F(FormAutofillTest, FindFormForTextAreaElement) { | 1346 TEST_F(FormAutofillTest, FindFormForTextAreaElement) { |
1347 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1347 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
1348 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1348 " <INPUT type='text' id='firstname' value='John'/>" |
1349 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1349 " <INPUT type='text' id='lastname' value='Smith'/>" |
1350 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"" | 1350 " <INPUT type='text' id='email' value='john@example.com'" |
1351 "autocomplete=\"off\" />" | 1351 "autocomplete='off' />" |
1352 " <TEXTAREA id=\"street-address\">" | 1352 " <TEXTAREA id='street-address'>" |
1353 "123 Fantasy Ln. " | 1353 "123 Fantasy Ln. " |
1354 "Apt. 42" | 1354 "Apt. 42" |
1355 "</TEXTAREA>" | 1355 "</TEXTAREA>" |
1356 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1356 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1357 "</FORM>"); | 1357 "</FORM>"); |
1358 | 1358 |
1359 WebFrame* web_frame = GetMainFrame(); | 1359 WebFrame* web_frame = GetMainFrame(); |
1360 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1360 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
1361 | 1361 |
1362 FormCache form_cache; | 1362 FormCache form_cache; |
1363 std::vector<FormData> forms; | 1363 std::vector<FormData> forms; |
1364 form_cache.ExtractNewForms(*web_frame, &forms); | 1364 form_cache.ExtractNewForms(*web_frame, &forms); |
1365 ASSERT_EQ(1U, forms.size()); | 1365 ASSERT_EQ(1U, forms.size()); |
1366 | 1366 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 | 1589 |
1590 // Verify preview selection. | 1590 // Verify preview selection. |
1591 WebInputElement firstname = GetMainFrame()->document(). | 1591 WebInputElement firstname = GetMainFrame()->document(). |
1592 getElementById("firstname").to<WebInputElement>(); | 1592 getElementById("firstname").to<WebInputElement>(); |
1593 EXPECT_EQ(0, firstname.selectionStart()); | 1593 EXPECT_EQ(0, firstname.selectionStart()); |
1594 EXPECT_EQ(19, firstname.selectionEnd()); | 1594 EXPECT_EQ(19, firstname.selectionEnd()); |
1595 } | 1595 } |
1596 | 1596 |
1597 TEST_F(FormAutofillTest, Labels) { | 1597 TEST_F(FormAutofillTest, Labels) { |
1598 ExpectJohnSmithLabels( | 1598 ExpectJohnSmithLabels( |
1599 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1599 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1600 " <LABEL for=\"firstname\"> First name: </LABEL>" | 1600 " <LABEL for='firstname'> First name: </LABEL>" |
1601 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1601 " <INPUT type='text' id='firstname' value='John'/>" |
1602 " <LABEL for=\"lastname\"> Last name: </LABEL>" | 1602 " <LABEL for='lastname'> Last name: </LABEL>" |
1603 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1603 " <INPUT type='text' id='lastname' value='Smith'/>" |
1604 " <LABEL for=\"email\"> Email: </LABEL>" | 1604 " <LABEL for='email'> Email: </LABEL>" |
1605 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1605 " <INPUT type='text' id='email' value='john@example.com'/>" |
1606 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1606 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1607 "</FORM>"); | 1607 "</FORM>"); |
1608 } | 1608 } |
1609 | 1609 |
1610 TEST_F(FormAutofillTest, LabelsWithSpans) { | 1610 TEST_F(FormAutofillTest, LabelsWithSpans) { |
1611 ExpectJohnSmithLabels( | 1611 ExpectJohnSmithLabels( |
1612 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1612 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1613 " <LABEL for=\"firstname\"><span>First name: </span></LABEL>" | 1613 " <LABEL for='firstname'><span>First name: </span></LABEL>" |
1614 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1614 " <INPUT type='text' id='firstname' value='John'/>" |
1615 " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>" | 1615 " <LABEL for='lastname'><span>Last name: </span></LABEL>" |
1616 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1616 " <INPUT type='text' id='lastname' value='Smith'/>" |
1617 " <LABEL for=\"email\"><span>Email: </span></LABEL>" | 1617 " <LABEL for='email'><span>Email: </span></LABEL>" |
1618 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1618 " <INPUT type='text' id='email' value='john@example.com'/>" |
1619 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1619 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1620 "</FORM>"); | 1620 "</FORM>"); |
1621 } | 1621 } |
1622 | 1622 |
1623 // This test is different from FormAutofillTest.Labels in that the label | 1623 // This test is different from FormAutofillTest.Labels in that the label |
1624 // elements for= attribute is set to the name of the form control element it is | 1624 // elements for= attribute is set to the name of the form control element it is |
1625 // a label for instead of the id of the form control element. This is invalid | 1625 // a label for instead of the id of the form control element. This is invalid |
1626 // because the for= attribute must be set to the id of the form control element; | 1626 // because the for= attribute must be set to the id of the form control element; |
1627 // however, current label parsing code will extract the text from the previous | 1627 // however, current label parsing code will extract the text from the previous |
1628 // label element and apply it to the following input field. | 1628 // label element and apply it to the following input field. |
1629 TEST_F(FormAutofillTest, InvalidLabels) { | 1629 TEST_F(FormAutofillTest, InvalidLabels) { |
1630 ExpectJohnSmithLabels( | 1630 ExpectJohnSmithLabels( |
1631 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1631 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1632 " <LABEL for=\"firstname\"> First name: </LABEL>" | 1632 " <LABEL for='firstname'> First name: </LABEL>" |
1633 " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>" | 1633 " <INPUT type='text' name='firstname' value='John'/>" |
1634 " <LABEL for=\"lastname\"> Last name: </LABEL>" | 1634 " <LABEL for='lastname'> Last name: </LABEL>" |
1635 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>" | 1635 " <INPUT type='text' name='lastname' value='Smith'/>" |
1636 " <LABEL for=\"email\"> Email: </LABEL>" | 1636 " <LABEL for='email'> Email: </LABEL>" |
1637 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\"/>" | 1637 " <INPUT type='text' name='email' value='john@example.com'/>" |
1638 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1638 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1639 "</FORM>"); | 1639 "</FORM>"); |
1640 } | 1640 } |
1641 | 1641 |
1642 // This test has three form control elements, only one of which has a label | 1642 // This test has three form control elements, only one of which has a label |
1643 // element associated with it. | 1643 // element associated with it. |
1644 TEST_F(FormAutofillTest, OneLabelElement) { | 1644 TEST_F(FormAutofillTest, OneLabelElement) { |
1645 ExpectJohnSmithLabels( | 1645 ExpectJohnSmithLabels( |
1646 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1646 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1647 " First name:" | 1647 " First name:" |
1648 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1648 " <INPUT type='text' id='firstname' value='John'/>" |
1649 " <LABEL for=\"lastname\">Last name: </LABEL>" | 1649 " <LABEL for='lastname'>Last name: </LABEL>" |
1650 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1650 " <INPUT type='text' id='lastname' value='Smith'/>" |
1651 " Email:" | 1651 " Email:" |
1652 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1652 " <INPUT type='text' id='email' value='john@example.com'/>" |
1653 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1653 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1654 "</FORM>"); | 1654 "</FORM>"); |
1655 } | 1655 } |
1656 | 1656 |
1657 TEST_F(FormAutofillTest, LabelsInferredFromText) { | 1657 TEST_F(FormAutofillTest, LabelsInferredFromText) { |
1658 ExpectJohnSmithLabels( | 1658 ExpectJohnSmithLabels( |
1659 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1659 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1660 " First name:" | 1660 " First name:" |
1661 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1661 " <INPUT type='text' id='firstname' value='John'/>" |
1662 " Last name:" | 1662 " Last name:" |
1663 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1663 " <INPUT type='text' id='lastname' value='Smith'/>" |
1664 " Email:" | 1664 " Email:" |
1665 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1665 " <INPUT type='text' id='email' value='john@example.com'/>" |
1666 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1666 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1667 "</FORM>"); | 1667 "</FORM>"); |
1668 } | 1668 } |
1669 | 1669 |
1670 TEST_F(FormAutofillTest, LabelsInferredFromParagraph) { | 1670 TEST_F(FormAutofillTest, LabelsInferredFromParagraph) { |
1671 ExpectJohnSmithLabels( | 1671 ExpectJohnSmithLabels( |
1672 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1672 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1673 " <P>First name:</P><INPUT type=\"text\" " | 1673 " <P>First name:</P><INPUT type='text' " |
1674 " id=\"firstname\" value=\"John\"/>" | 1674 " id='firstname' value='John'/>" |
1675 " <P>Last name:</P>" | 1675 " <P>Last name:</P>" |
1676 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1676 " <INPUT type='text' id='lastname' value='Smith'/>" |
1677 " <P>Email:</P>" | 1677 " <P>Email:</P>" |
1678 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1678 " <INPUT type='text' id='email' value='john@example.com'/>" |
1679 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1679 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1680 "</FORM>"); | 1680 "</FORM>"); |
1681 } | 1681 } |
1682 | 1682 |
1683 TEST_F(FormAutofillTest, LabelsInferredFromBold) { | 1683 TEST_F(FormAutofillTest, LabelsInferredFromBold) { |
1684 ExpectJohnSmithLabels( | 1684 ExpectJohnSmithLabels( |
1685 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1685 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1686 " <B>First name:</B><INPUT type=\"text\" " | 1686 " <B>First name:</B><INPUT type='text' " |
1687 " id=\"firstname\" value=\"John\"/>" | 1687 " id='firstname' value='John'/>" |
1688 " <B>Last name:</B>" | 1688 " <B>Last name:</B>" |
1689 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1689 " <INPUT type='text' id='lastname' value='Smith'/>" |
1690 " <B>Email:</B>" | 1690 " <B>Email:</B>" |
1691 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1691 " <INPUT type='text' id='email' value='john@example.com'/>" |
1692 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1692 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1693 "</FORM>"); | 1693 "</FORM>"); |
1694 } | 1694 } |
1695 | 1695 |
1696 TEST_F(FormAutofillTest, LabelsInferredPriorToImgOrBr) { | 1696 TEST_F(FormAutofillTest, LabelsInferredPriorToImgOrBr) { |
1697 ExpectJohnSmithLabels( | 1697 ExpectJohnSmithLabels( |
1698 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1698 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1699 " First name:<IMG/><INPUT type=\"text\" " | 1699 " First name:<IMG/><INPUT type='text' " |
1700 " id=\"firstname\" value=\"John\"/>" | 1700 " id='firstname' value='John'/>" |
1701 " Last name:<IMG/>" | 1701 " Last name:<IMG/>" |
1702 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1702 " <INPUT type='text' id='lastname' value='Smith'/>" |
1703 " Email:<BR/>" | 1703 " Email:<BR/>" |
1704 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1704 " <INPUT type='text' id='email' value='john@example.com'/>" |
1705 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1705 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1706 "</FORM>"); | 1706 "</FORM>"); |
1707 } | 1707 } |
1708 | 1708 |
1709 TEST_F(FormAutofillTest, LabelsInferredFromTableCell) { | 1709 TEST_F(FormAutofillTest, LabelsInferredFromTableCell) { |
1710 ExpectJohnSmithLabels( | 1710 ExpectJohnSmithLabels( |
1711 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1711 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1712 "<TABLE>" | 1712 "<TABLE>" |
1713 " <TR>" | 1713 " <TR>" |
1714 " <TD>First name:</TD>" | 1714 " <TD>First name:</TD>" |
1715 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>" | 1715 " <TD><INPUT type='text' id='firstname' value='John'/></TD>" |
1716 " </TR>" | 1716 " </TR>" |
1717 " <TR>" | 1717 " <TR>" |
1718 " <TD>Last name:</TD>" | 1718 " <TD>Last name:</TD>" |
1719 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>" | 1719 " <TD><INPUT type='text' id='lastname' value='Smith'/></TD>" |
1720 " </TR>" | 1720 " </TR>" |
1721 " <TR>" | 1721 " <TR>" |
1722 " <TD>Email:</TD>" | 1722 " <TD>Email:</TD>" |
1723 " <TD><INPUT type=\"text\" id=\"email\"" | 1723 " <TD><INPUT type='text' id='email'" |
1724 " value=\"john@example.com\"/></TD>" | 1724 " value='john@example.com'/></TD>" |
1725 " </TR>" | 1725 " </TR>" |
1726 " <TR>" | 1726 " <TR>" |
1727 " <TD></TD>" | 1727 " <TD></TD>" |
1728 " <TD>" | 1728 " <TD>" |
1729 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1729 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1730 " </TD>" | 1730 " </TD>" |
1731 " </TR>" | 1731 " </TR>" |
1732 "</TABLE>" | 1732 "</TABLE>" |
1733 "</FORM>"); | 1733 "</FORM>"); |
1734 } | 1734 } |
1735 | 1735 |
1736 TEST_F(FormAutofillTest, LabelsInferredFromTableCellTH) { | 1736 TEST_F(FormAutofillTest, LabelsInferredFromTableCellTH) { |
1737 ExpectJohnSmithLabels( | 1737 ExpectJohnSmithLabels( |
1738 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1738 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1739 "<TABLE>" | 1739 "<TABLE>" |
1740 " <TR>" | 1740 " <TR>" |
1741 " <TH>First name:</TH>" | 1741 " <TH>First name:</TH>" |
1742 " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>" | 1742 " <TD><INPUT type='text' id='firstname' value='John'/></TD>" |
1743 " </TR>" | 1743 " </TR>" |
1744 " <TR>" | 1744 " <TR>" |
1745 " <TH>Last name:</TH>" | 1745 " <TH>Last name:</TH>" |
1746 " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>" | 1746 " <TD><INPUT type='text' id='lastname' value='Smith'/></TD>" |
1747 " </TR>" | 1747 " </TR>" |
1748 " <TR>" | 1748 " <TR>" |
1749 " <TH>Email:</TH>" | 1749 " <TH>Email:</TH>" |
1750 " <TD><INPUT type=\"text\" id=\"email\"" | 1750 " <TD><INPUT type='text' id='email'" |
1751 " value=\"john@example.com\"/></TD>" | 1751 " value='john@example.com'/></TD>" |
1752 " </TR>" | 1752 " </TR>" |
1753 " <TR>" | 1753 " <TR>" |
1754 " <TD></TD>" | 1754 " <TD></TD>" |
1755 " <TD>" | 1755 " <TD>" |
1756 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1756 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1757 " </TD>" | 1757 " </TD>" |
1758 " </TR>" | 1758 " </TR>" |
1759 "</TABLE>" | 1759 "</TABLE>" |
1760 "</FORM>"); | 1760 "</FORM>"); |
1761 } | 1761 } |
1762 | 1762 |
1763 TEST_F(FormAutofillTest, LabelsInferredFromTableCellNested) { | 1763 TEST_F(FormAutofillTest, LabelsInferredFromTableCellNested) { |
1764 std::vector<base::string16> labels, names, values; | 1764 std::vector<base::string16> labels, names, values; |
1765 | 1765 |
1766 labels.push_back(ASCIIToUTF16("First name: Bogus")); | 1766 labels.push_back(ASCIIToUTF16("First name: Bogus")); |
1767 names.push_back(ASCIIToUTF16("firstname")); | 1767 names.push_back(ASCIIToUTF16("firstname")); |
1768 values.push_back(ASCIIToUTF16("John")); | 1768 values.push_back(ASCIIToUTF16("John")); |
1769 | 1769 |
1770 labels.push_back(ASCIIToUTF16("Last name:")); | 1770 labels.push_back(ASCIIToUTF16("Last name:")); |
1771 names.push_back(ASCIIToUTF16("lastname")); | 1771 names.push_back(ASCIIToUTF16("lastname")); |
1772 values.push_back(ASCIIToUTF16("Smith")); | 1772 values.push_back(ASCIIToUTF16("Smith")); |
1773 | 1773 |
1774 labels.push_back(ASCIIToUTF16("Email:")); | 1774 labels.push_back(ASCIIToUTF16("Email:")); |
1775 names.push_back(ASCIIToUTF16("email")); | 1775 names.push_back(ASCIIToUTF16("email")); |
1776 values.push_back(ASCIIToUTF16("john@example.com")); | 1776 values.push_back(ASCIIToUTF16("john@example.com")); |
1777 | 1777 |
1778 ExpectLabels( | 1778 ExpectLabels( |
1779 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1779 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1780 "<TABLE>" | 1780 "<TABLE>" |
1781 " <TR>" | 1781 " <TR>" |
1782 " <TD>" | 1782 " <TD>" |
1783 " <FONT>" | 1783 " <FONT>" |
1784 " First name:" | 1784 " First name:" |
1785 " </FONT>" | 1785 " </FONT>" |
1786 " <FONT>" | 1786 " <FONT>" |
1787 " Bogus" | 1787 " Bogus" |
1788 " </FONT>" | 1788 " </FONT>" |
1789 " </TD>" | 1789 " </TD>" |
1790 " <TD>" | 1790 " <TD>" |
1791 " <FONT>" | 1791 " <FONT>" |
1792 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1792 " <INPUT type='text' id='firstname' value='John'/>" |
1793 " </FONT>" | 1793 " </FONT>" |
1794 " </TD>" | 1794 " </TD>" |
1795 " </TR>" | 1795 " </TR>" |
1796 " <TR>" | 1796 " <TR>" |
1797 " <TD>" | 1797 " <TD>" |
1798 " <FONT>" | 1798 " <FONT>" |
1799 " Last name:" | 1799 " Last name:" |
1800 " </FONT>" | 1800 " </FONT>" |
1801 " </TD>" | 1801 " </TD>" |
1802 " <TD>" | 1802 " <TD>" |
1803 " <FONT>" | 1803 " <FONT>" |
1804 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1804 " <INPUT type='text' id='lastname' value='Smith'/>" |
1805 " </FONT>" | 1805 " </FONT>" |
1806 " </TD>" | 1806 " </TD>" |
1807 " </TR>" | 1807 " </TR>" |
1808 " <TR>" | 1808 " <TR>" |
1809 " <TD>" | 1809 " <TD>" |
1810 " <FONT>" | 1810 " <FONT>" |
1811 " Email:" | 1811 " Email:" |
1812 " </FONT>" | 1812 " </FONT>" |
1813 " </TD>" | 1813 " </TD>" |
1814 " <TD>" | 1814 " <TD>" |
1815 " <FONT>" | 1815 " <FONT>" |
1816 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1816 " <INPUT type='text' id='email' value='john@example.com'/>" |
1817 " </FONT>" | 1817 " </FONT>" |
1818 " </TD>" | 1818 " </TD>" |
1819 " </TR>" | 1819 " </TR>" |
1820 " <TR>" | 1820 " <TR>" |
1821 " <TD></TD>" | 1821 " <TD></TD>" |
1822 " <TD>" | 1822 " <TD>" |
1823 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1823 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1824 " </TD>" | 1824 " </TD>" |
1825 " </TR>" | 1825 " </TR>" |
1826 "</TABLE>" | 1826 "</TABLE>" |
1827 "</FORM>", | 1827 "</FORM>", |
1828 labels, names, values); | 1828 labels, names, values); |
1829 } | 1829 } |
1830 | 1830 |
1831 TEST_F(FormAutofillTest, LabelsInferredFromTableEmptyTDs) { | 1831 TEST_F(FormAutofillTest, LabelsInferredFromTableEmptyTDs) { |
1832 std::vector<base::string16> labels, names, values; | 1832 std::vector<base::string16> labels, names, values; |
1833 | 1833 |
1834 labels.push_back(ASCIIToUTF16("* First Name")); | 1834 labels.push_back(ASCIIToUTF16("* First Name")); |
1835 names.push_back(ASCIIToUTF16("firstname")); | 1835 names.push_back(ASCIIToUTF16("firstname")); |
1836 values.push_back(ASCIIToUTF16("John")); | 1836 values.push_back(ASCIIToUTF16("John")); |
1837 | 1837 |
1838 labels.push_back(ASCIIToUTF16("* Last Name")); | 1838 labels.push_back(ASCIIToUTF16("* Last Name")); |
1839 names.push_back(ASCIIToUTF16("lastname")); | 1839 names.push_back(ASCIIToUTF16("lastname")); |
1840 values.push_back(ASCIIToUTF16("Smith")); | 1840 values.push_back(ASCIIToUTF16("Smith")); |
1841 | 1841 |
1842 labels.push_back(ASCIIToUTF16("* Email")); | 1842 labels.push_back(ASCIIToUTF16("* Email")); |
1843 names.push_back(ASCIIToUTF16("email")); | 1843 names.push_back(ASCIIToUTF16("email")); |
1844 values.push_back(ASCIIToUTF16("john@example.com")); | 1844 values.push_back(ASCIIToUTF16("john@example.com")); |
1845 | 1845 |
1846 ExpectLabels( | 1846 ExpectLabels( |
1847 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1847 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1848 "<TABLE>" | 1848 "<TABLE>" |
1849 " <TR>" | 1849 " <TR>" |
1850 " <TD>" | 1850 " <TD>" |
1851 " <SPAN>*</SPAN>" | 1851 " <SPAN>*</SPAN>" |
1852 " <B>First Name</B>" | 1852 " <B>First Name</B>" |
1853 " </TD>" | 1853 " </TD>" |
1854 " <TD></TD>" | 1854 " <TD></TD>" |
1855 " <TD>" | 1855 " <TD>" |
1856 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1856 " <INPUT type='text' id='firstname' value='John'/>" |
1857 " </TD>" | 1857 " </TD>" |
1858 " </TR>" | 1858 " </TR>" |
1859 " <TR>" | 1859 " <TR>" |
1860 " <TD>" | 1860 " <TD>" |
1861 " <SPAN>*</SPAN>" | 1861 " <SPAN>*</SPAN>" |
1862 " <B>Last Name</B>" | 1862 " <B>Last Name</B>" |
1863 " </TD>" | 1863 " </TD>" |
1864 " <TD></TD>" | 1864 " <TD></TD>" |
1865 " <TD>" | 1865 " <TD>" |
1866 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1866 " <INPUT type='text' id='lastname' value='Smith'/>" |
1867 " </TD>" | 1867 " </TD>" |
1868 " </TR>" | 1868 " </TR>" |
1869 " <TR>" | 1869 " <TR>" |
1870 " <TD>" | 1870 " <TD>" |
1871 " <SPAN>*</SPAN>" | 1871 " <SPAN>*</SPAN>" |
1872 " <B>Email</B>" | 1872 " <B>Email</B>" |
1873 " </TD>" | 1873 " </TD>" |
1874 " <TD></TD>" | 1874 " <TD></TD>" |
1875 " <TD>" | 1875 " <TD>" |
1876 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1876 " <INPUT type='text' id='email' value='john@example.com'/>" |
1877 " </TD>" | 1877 " </TD>" |
1878 " </TR>" | 1878 " </TR>" |
1879 " <TR>" | 1879 " <TR>" |
1880 " <TD></TD>" | 1880 " <TD></TD>" |
1881 " <TD>" | 1881 " <TD>" |
1882 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1882 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1883 " </TD>" | 1883 " </TD>" |
1884 " </TR>" | 1884 " </TR>" |
1885 "</TABLE>" | 1885 "</TABLE>" |
1886 "</FORM>", | 1886 "</FORM>", |
1887 labels, names, values); | 1887 labels, names, values); |
1888 } | 1888 } |
1889 | 1889 |
1890 TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) { | 1890 TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) { |
1891 std::vector<base::string16> labels, names, values; | 1891 std::vector<base::string16> labels, names, values; |
1892 | 1892 |
1893 labels.push_back(ASCIIToUTF16("* First Name")); | 1893 labels.push_back(ASCIIToUTF16("* First Name")); |
1894 names.push_back(ASCIIToUTF16("firstname")); | 1894 names.push_back(ASCIIToUTF16("firstname")); |
1895 values.push_back(ASCIIToUTF16("John")); | 1895 values.push_back(ASCIIToUTF16("John")); |
1896 | 1896 |
1897 labels.push_back(ASCIIToUTF16("* Last Name")); | 1897 labels.push_back(ASCIIToUTF16("* Last Name")); |
1898 names.push_back(ASCIIToUTF16("lastname")); | 1898 names.push_back(ASCIIToUTF16("lastname")); |
1899 values.push_back(ASCIIToUTF16("Smith")); | 1899 values.push_back(ASCIIToUTF16("Smith")); |
1900 | 1900 |
1901 labels.push_back(ASCIIToUTF16("* Email")); | 1901 labels.push_back(ASCIIToUTF16("* Email")); |
1902 names.push_back(ASCIIToUTF16("email")); | 1902 names.push_back(ASCIIToUTF16("email")); |
1903 values.push_back(ASCIIToUTF16("john@example.com")); | 1903 values.push_back(ASCIIToUTF16("john@example.com")); |
1904 | 1904 |
1905 ExpectLabels( | 1905 ExpectLabels( |
1906 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1906 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1907 "<TABLE>" | 1907 "<TABLE>" |
1908 " <TR>" | 1908 " <TR>" |
1909 " <TD>* First Name</TD>" | 1909 " <TD>* First Name</TD>" |
1910 " <TD>" | 1910 " <TD>" |
1911 " Bogus" | 1911 " Bogus" |
1912 " <INPUT type=\"hidden\"/>" | 1912 " <INPUT type='hidden'/>" |
1913 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1913 " <INPUT type='text' id='firstname' value='John'/>" |
1914 " </TD>" | 1914 " </TD>" |
1915 " </TR>" | 1915 " </TR>" |
1916 " <TR>" | 1916 " <TR>" |
1917 " <TD>* Last Name</TD>" | 1917 " <TD>* Last Name</TD>" |
1918 " <TD>" | 1918 " <TD>" |
1919 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 1919 " <INPUT type='text' id='lastname' value='Smith'/>" |
1920 " </TD>" | 1920 " </TD>" |
1921 " </TR>" | 1921 " </TR>" |
1922 " <TR>" | 1922 " <TR>" |
1923 " <TD>* Email</TD>" | 1923 " <TD>* Email</TD>" |
1924 " <TD>" | 1924 " <TD>" |
1925 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 1925 " <INPUT type='text' id='email' value='john@example.com'/>" |
1926 " </TD>" | 1926 " </TD>" |
1927 " </TR>" | 1927 " </TR>" |
1928 " <TR>" | 1928 " <TR>" |
1929 " <TD></TD>" | 1929 " <TD></TD>" |
1930 " <TD>" | 1930 " <TD>" |
1931 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1931 " <INPUT type='submit' name='reply-send' value='Send'/>" |
1932 " </TD>" | 1932 " </TD>" |
1933 " </TR>" | 1933 " </TR>" |
1934 "</TABLE>" | 1934 "</TABLE>" |
1935 "</FORM>", | 1935 "</FORM>", |
1936 labels, names, values); | 1936 labels, names, values); |
1937 } | 1937 } |
1938 | 1938 |
1939 // <script>, <noscript> and <option> tags are excluded when the labels are | 1939 // <script>, <noscript> and <option> tags are excluded when the labels are |
1940 // inferred. | 1940 // inferred. |
1941 // Also <!-- comment --> is excluded. | 1941 // Also <!-- comment --> is excluded. |
(...skipping 20 matching lines...) Expand all Loading... |
1962 names.push_back(ASCIIToUTF16("country")); | 1962 names.push_back(ASCIIToUTF16("country")); |
1963 values.push_back(ASCIIToUTF16("US")); | 1963 values.push_back(ASCIIToUTF16("US")); |
1964 control_types.push_back("select-one"); | 1964 control_types.push_back("select-one"); |
1965 | 1965 |
1966 labels.push_back(ASCIIToUTF16("* Email")); | 1966 labels.push_back(ASCIIToUTF16("* Email")); |
1967 names.push_back(ASCIIToUTF16("email")); | 1967 names.push_back(ASCIIToUTF16("email")); |
1968 values.push_back(ASCIIToUTF16("john@example.com")); | 1968 values.push_back(ASCIIToUTF16("john@example.com")); |
1969 control_types.push_back("text"); | 1969 control_types.push_back("text"); |
1970 | 1970 |
1971 ExpectLabelsAndTypes( | 1971 ExpectLabelsAndTypes( |
1972 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 1972 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1973 "<TABLE>" | 1973 "<TABLE>" |
1974 " <TR>" | 1974 " <TR>" |
1975 " <TD>" | 1975 " <TD>" |
1976 " <SPAN>*</SPAN>" | 1976 " <SPAN>*</SPAN>" |
1977 " <B>First Name</B>" | 1977 " <B>First Name</B>" |
1978 " </TD>" | 1978 " </TD>" |
1979 " <TD>" | 1979 " <TD>" |
1980 " <SCRIPT> <!-- function test() { alert('ignored as label'); } -->" | 1980 " <SCRIPT> <!-- function test() { alert('ignored as label'); } -->" |
1981 " </SCRIPT>" | 1981 " </SCRIPT>" |
1982 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 1982 " <INPUT type='text' id='firstname' value='John'/>" |
1983 " </TD>" | 1983 " </TD>" |
1984 " </TR>" | 1984 " </TR>" |
1985 " <TR>" | 1985 " <TR>" |
1986 " <TD>" | 1986 " <TD>" |
1987 " <SPAN>*</SPAN>" | 1987 " <SPAN>*</SPAN>" |
1988 " <B>Middle Name</B>" | 1988 " <B>Middle Name</B>" |
1989 " </TD>" | 1989 " </TD>" |
1990 " <TD>" | 1990 " <TD>" |
1991 " <NOSCRIPT>" | 1991 " <NOSCRIPT>" |
1992 " <P>Bad</P>" | 1992 " <P>Bad</P>" |
1993 " </NOSCRIPT>" | 1993 " </NOSCRIPT>" |
1994 " <INPUT type=\"text\" id=\"middlename\" value=\"Joe\"/>" | 1994 " <INPUT type='text' id='middlename' value='Joe'/>" |
1995 " </TD>" | 1995 " </TD>" |
1996 " </TR>" | 1996 " </TR>" |
1997 " <TR>" | 1997 " <TR>" |
1998 " <TD>" | 1998 " <TD>" |
1999 " <SPAN>*</SPAN>" | 1999 " <SPAN>*</SPAN>" |
2000 " <B>Last Name</B>" | 2000 " <B>Last Name</B>" |
2001 " </TD>" | 2001 " </TD>" |
2002 " <TD>" | 2002 " <TD>" |
2003 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2003 " <INPUT type='text' id='lastname' value='Smith'/>" |
2004 " </TD>" | 2004 " </TD>" |
2005 " </TR>" | 2005 " </TR>" |
2006 " <TR>" | 2006 " <TR>" |
2007 " <TD>" | 2007 " <TD>" |
2008 " <SPAN>*</SPAN>" | 2008 " <SPAN>*</SPAN>" |
2009 " <B>Country</B>" | 2009 " <B>Country</B>" |
2010 " </TD>" | 2010 " </TD>" |
2011 " <TD>" | 2011 " <TD>" |
2012 " <SELECT id=\"country\">" | 2012 " <SELECT id='country'>" |
2013 " <OPTION VALUE=\"US\">The value should be ignored as label." | 2013 " <OPTION VALUE='US'>The value should be ignored as label." |
2014 " </OPTION>" | 2014 " </OPTION>" |
2015 " <OPTION VALUE=\"JP\">JAPAN</OPTION>" | 2015 " <OPTION VALUE='JP'>JAPAN</OPTION>" |
2016 " </SELECT>" | 2016 " </SELECT>" |
2017 " </TD>" | 2017 " </TD>" |
2018 " </TR>" | 2018 " </TR>" |
2019 " <TR>" | 2019 " <TR>" |
2020 " <TD>" | 2020 " <TD>" |
2021 " <SPAN>*</SPAN>" | 2021 " <SPAN>*</SPAN>" |
2022 " <B>Email</B>" | 2022 " <B>Email</B>" |
2023 " </TD>" | 2023 " </TD>" |
2024 " <TD>" | 2024 " <TD>" |
2025 " <!-- This comment should be ignored as inferred label.-->" | 2025 " <!-- This comment should be ignored as inferred label.-->" |
2026 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2026 " <INPUT type='text' id='email' value='john@example.com'/>" |
2027 " </TD>" | 2027 " </TD>" |
2028 " </TR>" | 2028 " </TR>" |
2029 " <TR>" | 2029 " <TR>" |
2030 " <TD></TD>" | 2030 " <TD></TD>" |
2031 " <TD>" | 2031 " <TD>" |
2032 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2032 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2033 " </TD>" | 2033 " </TD>" |
2034 " </TR>" | 2034 " </TR>" |
2035 "</TABLE>" | 2035 "</TABLE>" |
2036 "</FORM>", | 2036 "</FORM>", |
2037 labels, names, values, control_types); | 2037 labels, names, values, control_types); |
2038 } | 2038 } |
2039 | 2039 |
2040 TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) { | 2040 TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) { |
2041 ExpectJohnSmithLabels( | 2041 ExpectJohnSmithLabels( |
2042 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2042 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2043 "<TABLE>" | 2043 "<TABLE>" |
2044 " <TR>" | 2044 " <TR>" |
2045 " <TD>" | 2045 " <TD>" |
2046 " <LABEL>First name:</LABEL>" | 2046 " <LABEL>First name:</LABEL>" |
2047 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2047 " <INPUT type='text' id='firstname' value='John'/>" |
2048 " </TD>" | 2048 " </TD>" |
2049 " </TR>" | 2049 " </TR>" |
2050 " <TR>" | 2050 " <TR>" |
2051 " <TD>" | 2051 " <TD>" |
2052 " <LABEL>Last name:</LABEL>" | 2052 " <LABEL>Last name:</LABEL>" |
2053 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2053 " <INPUT type='text' id='lastname' value='Smith'/>" |
2054 " </TD>" | 2054 " </TD>" |
2055 " </TR>" | 2055 " </TR>" |
2056 " <TR>" | 2056 " <TR>" |
2057 " <TD>" | 2057 " <TD>" |
2058 " <LABEL>Email:</LABEL>" | 2058 " <LABEL>Email:</LABEL>" |
2059 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2059 " <INPUT type='text' id='email' value='john@example.com'/>" |
2060 " </TD>" | 2060 " </TD>" |
2061 " </TR>" | 2061 " </TR>" |
2062 "</TABLE>" | 2062 "</TABLE>" |
2063 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2063 "<INPUT type='submit' name='reply-send' value='Send'/>" |
2064 "</FORM>"); | 2064 "</FORM>"); |
2065 } | 2065 } |
2066 | 2066 |
2067 TEST_F(FormAutofillTest, LabelsInferredFromTableTDInterveningElements) { | 2067 TEST_F(FormAutofillTest, LabelsInferredFromTableTDInterveningElements) { |
2068 ExpectJohnSmithLabels( | 2068 ExpectJohnSmithLabels( |
2069 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2069 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2070 "<TABLE>" | 2070 "<TABLE>" |
2071 " <TR>" | 2071 " <TR>" |
2072 " <TD>" | 2072 " <TD>" |
2073 " First name:" | 2073 " First name:" |
2074 " <BR>" | 2074 " <BR>" |
2075 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2075 " <INPUT type='text' id='firstname' value='John'/>" |
2076 " </TD>" | 2076 " </TD>" |
2077 " </TR>" | 2077 " </TR>" |
2078 " <TR>" | 2078 " <TR>" |
2079 " <TD>" | 2079 " <TD>" |
2080 " Last name:" | 2080 " Last name:" |
2081 " <BR>" | 2081 " <BR>" |
2082 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2082 " <INPUT type='text' id='lastname' value='Smith'/>" |
2083 " </TD>" | 2083 " </TD>" |
2084 " </TR>" | 2084 " </TR>" |
2085 " <TR>" | 2085 " <TR>" |
2086 " <TD>" | 2086 " <TD>" |
2087 " Email:" | 2087 " Email:" |
2088 " <BR>" | 2088 " <BR>" |
2089 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2089 " <INPUT type='text' id='email' value='john@example.com'/>" |
2090 " </TD>" | 2090 " </TD>" |
2091 " </TR>" | 2091 " </TR>" |
2092 "</TABLE>" | 2092 "</TABLE>" |
2093 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2093 "<INPUT type='submit' name='reply-send' value='Send'/>" |
2094 "</FORM>"); | 2094 "</FORM>"); |
2095 } | 2095 } |
2096 | 2096 |
2097 // Verify that we correctly infer labels when the label text spans multiple | 2097 // Verify that we correctly infer labels when the label text spans multiple |
2098 // adjacent HTML elements, not separated by whitespace. | 2098 // adjacent HTML elements, not separated by whitespace. |
2099 TEST_F(FormAutofillTest, LabelsInferredFromTableAdjacentElements) { | 2099 TEST_F(FormAutofillTest, LabelsInferredFromTableAdjacentElements) { |
2100 std::vector<base::string16> labels, names, values; | 2100 std::vector<base::string16> labels, names, values; |
2101 | 2101 |
2102 labels.push_back(ASCIIToUTF16("*First Name")); | 2102 labels.push_back(ASCIIToUTF16("*First Name")); |
2103 names.push_back(ASCIIToUTF16("firstname")); | 2103 names.push_back(ASCIIToUTF16("firstname")); |
2104 values.push_back(ASCIIToUTF16("John")); | 2104 values.push_back(ASCIIToUTF16("John")); |
2105 | 2105 |
2106 labels.push_back(ASCIIToUTF16("*Last Name")); | 2106 labels.push_back(ASCIIToUTF16("*Last Name")); |
2107 names.push_back(ASCIIToUTF16("lastname")); | 2107 names.push_back(ASCIIToUTF16("lastname")); |
2108 values.push_back(ASCIIToUTF16("Smith")); | 2108 values.push_back(ASCIIToUTF16("Smith")); |
2109 | 2109 |
2110 labels.push_back(ASCIIToUTF16("*Email")); | 2110 labels.push_back(ASCIIToUTF16("*Email")); |
2111 names.push_back(ASCIIToUTF16("email")); | 2111 names.push_back(ASCIIToUTF16("email")); |
2112 values.push_back(ASCIIToUTF16("john@example.com")); | 2112 values.push_back(ASCIIToUTF16("john@example.com")); |
2113 | 2113 |
2114 ExpectLabels( | 2114 ExpectLabels( |
2115 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2115 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2116 "<TABLE>" | 2116 "<TABLE>" |
2117 " <TR>" | 2117 " <TR>" |
2118 " <TD>" | 2118 " <TD>" |
2119 " <SPAN>*</SPAN><B>First Name</B>" | 2119 " <SPAN>*</SPAN><B>First Name</B>" |
2120 " </TD>" | 2120 " </TD>" |
2121 " <TD>" | 2121 " <TD>" |
2122 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2122 " <INPUT type='text' id='firstname' value='John'/>" |
2123 " </TD>" | 2123 " </TD>" |
2124 " </TR>" | 2124 " </TR>" |
2125 " <TR>" | 2125 " <TR>" |
2126 " <TD>" | 2126 " <TD>" |
2127 " <SPAN>*</SPAN><B>Last Name</B>" | 2127 " <SPAN>*</SPAN><B>Last Name</B>" |
2128 " </TD>" | 2128 " </TD>" |
2129 " <TD>" | 2129 " <TD>" |
2130 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2130 " <INPUT type='text' id='lastname' value='Smith'/>" |
2131 " </TD>" | 2131 " </TD>" |
2132 " </TR>" | 2132 " </TR>" |
2133 " <TR>" | 2133 " <TR>" |
2134 " <TD>" | 2134 " <TD>" |
2135 " <SPAN>*</SPAN><B>Email</B>" | 2135 " <SPAN>*</SPAN><B>Email</B>" |
2136 " </TD>" | 2136 " </TD>" |
2137 " <TD>" | 2137 " <TD>" |
2138 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2138 " <INPUT type='text' id='email' value='john@example.com'/>" |
2139 " </TD>" | 2139 " </TD>" |
2140 " </TR>" | 2140 " </TR>" |
2141 " <TR>" | 2141 " <TR>" |
2142 " <TD>" | 2142 " <TD>" |
2143 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2143 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2144 " </TD>" | 2144 " </TD>" |
2145 " </TR>" | 2145 " </TR>" |
2146 "</TABLE>" | 2146 "</TABLE>" |
2147 "</FORM>", | 2147 "</FORM>", |
2148 labels, names, values); | 2148 labels, names, values); |
2149 } | 2149 } |
2150 | 2150 |
2151 // Verify that we correctly infer labels when the label text resides in the | 2151 // Verify that we correctly infer labels when the label text resides in the |
2152 // previous row. | 2152 // previous row. |
2153 TEST_F(FormAutofillTest, LabelsInferredFromTableRow) { | 2153 TEST_F(FormAutofillTest, LabelsInferredFromTableRow) { |
2154 std::vector<base::string16> labels, names, values; | 2154 std::vector<base::string16> labels, names, values; |
2155 | 2155 |
2156 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); | 2156 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); |
2157 names.push_back(ASCIIToUTF16("firstname")); | 2157 names.push_back(ASCIIToUTF16("firstname")); |
2158 values.push_back(ASCIIToUTF16("John")); | 2158 values.push_back(ASCIIToUTF16("John")); |
2159 | 2159 |
2160 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); | 2160 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); |
2161 names.push_back(ASCIIToUTF16("lastname")); | 2161 names.push_back(ASCIIToUTF16("lastname")); |
2162 values.push_back(ASCIIToUTF16("Smith")); | 2162 values.push_back(ASCIIToUTF16("Smith")); |
2163 | 2163 |
2164 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); | 2164 labels.push_back(ASCIIToUTF16("*First Name *Last Name *Email")); |
2165 names.push_back(ASCIIToUTF16("email")); | 2165 names.push_back(ASCIIToUTF16("email")); |
2166 values.push_back(ASCIIToUTF16("john@example.com")); | 2166 values.push_back(ASCIIToUTF16("john@example.com")); |
2167 | 2167 |
2168 ExpectLabels( | 2168 ExpectLabels( |
2169 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2169 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2170 "<TABLE>" | 2170 "<TABLE>" |
2171 " <TR>" | 2171 " <TR>" |
2172 " <TD>*First Name</TD>" | 2172 " <TD>*First Name</TD>" |
2173 " <TD>*Last Name</TD>" | 2173 " <TD>*Last Name</TD>" |
2174 " <TD>*Email</TD>" | 2174 " <TD>*Email</TD>" |
2175 " </TR>" | 2175 " </TR>" |
2176 " <TR>" | 2176 " <TR>" |
2177 " <TD>" | 2177 " <TD>" |
2178 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2178 " <INPUT type='text' id='firstname' value='John'/>" |
2179 " </TD>" | 2179 " </TD>" |
2180 " <TD>" | 2180 " <TD>" |
2181 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2181 " <INPUT type='text' id='lastname' value='Smith'/>" |
2182 " </TD>" | 2182 " </TD>" |
2183 " <TD>" | 2183 " <TD>" |
2184 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2184 " <INPUT type='text' id='email' value='john@example.com'/>" |
2185 " </TD>" | 2185 " </TD>" |
2186 " </TR>" | 2186 " </TR>" |
2187 " <TR>" | 2187 " <TR>" |
2188 " <TD>" | 2188 " <TD>" |
2189 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2189 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2190 " </TD>" | 2190 " </TD>" |
2191 " </TR>" | 2191 " </TR>" |
2192 "</TABLE>", | 2192 "</TABLE>", |
2193 labels, names, values); | 2193 labels, names, values); |
2194 } | 2194 } |
2195 | 2195 |
2196 // Verify that we correctly infer labels when enclosed within a list item. | 2196 // Verify that we correctly infer labels when enclosed within a list item. |
2197 TEST_F(FormAutofillTest, LabelsInferredFromListItem) { | 2197 TEST_F(FormAutofillTest, LabelsInferredFromListItem) { |
2198 std::vector<base::string16> labels, names, values; | 2198 std::vector<base::string16> labels, names, values; |
2199 | 2199 |
2200 labels.push_back(ASCIIToUTF16("* Home Phone")); | 2200 labels.push_back(ASCIIToUTF16("* Home Phone")); |
2201 names.push_back(ASCIIToUTF16("areacode")); | 2201 names.push_back(ASCIIToUTF16("areacode")); |
2202 values.push_back(ASCIIToUTF16("415")); | 2202 values.push_back(ASCIIToUTF16("415")); |
2203 | 2203 |
2204 labels.push_back(ASCIIToUTF16("* Home Phone")); | 2204 labels.push_back(ASCIIToUTF16("* Home Phone")); |
2205 names.push_back(ASCIIToUTF16("prefix")); | 2205 names.push_back(ASCIIToUTF16("prefix")); |
2206 values.push_back(ASCIIToUTF16("555")); | 2206 values.push_back(ASCIIToUTF16("555")); |
2207 | 2207 |
2208 labels.push_back(ASCIIToUTF16("* Home Phone")); | 2208 labels.push_back(ASCIIToUTF16("* Home Phone")); |
2209 names.push_back(ASCIIToUTF16("suffix")); | 2209 names.push_back(ASCIIToUTF16("suffix")); |
2210 values.push_back(ASCIIToUTF16("1212")); | 2210 values.push_back(ASCIIToUTF16("1212")); |
2211 | 2211 |
2212 ExpectLabels( | 2212 ExpectLabels( |
2213 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2213 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2214 "<DIV>" | 2214 "<DIV>" |
2215 " <LI>" | 2215 " <LI>" |
2216 " <SPAN>Bogus</SPAN>" | 2216 " <SPAN>Bogus</SPAN>" |
2217 " </LI>" | 2217 " </LI>" |
2218 " <LI>" | 2218 " <LI>" |
2219 " <LABEL><EM>*</EM> Home Phone</LABEL>" | 2219 " <LABEL><EM>*</EM> Home Phone</LABEL>" |
2220 " <INPUT type=\"text\" id=\"areacode\" value=\"415\"/>" | 2220 " <INPUT type='text' id='areacode' value='415'/>" |
2221 " <INPUT type=\"text\" id=\"prefix\" value=\"555\"/>" | 2221 " <INPUT type='text' id='prefix' value='555'/>" |
2222 " <INPUT type=\"text\" id=\"suffix\" value=\"1212\"/>" | 2222 " <INPUT type='text' id='suffix' value='1212'/>" |
2223 " </LI>" | 2223 " </LI>" |
2224 " <LI>" | 2224 " <LI>" |
2225 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2225 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2226 " </LI>" | 2226 " </LI>" |
2227 "</DIV>" | 2227 "</DIV>" |
2228 "</FORM>", | 2228 "</FORM>", |
2229 labels, names, values); | 2229 labels, names, values); |
2230 } | 2230 } |
2231 | 2231 |
2232 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionList) { | 2232 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionList) { |
2233 std::vector<base::string16> labels, names, values; | 2233 std::vector<base::string16> labels, names, values; |
2234 | 2234 |
2235 labels.push_back(ASCIIToUTF16("* First name: Bogus")); | 2235 labels.push_back(ASCIIToUTF16("* First name: Bogus")); |
2236 names.push_back(ASCIIToUTF16("firstname")); | 2236 names.push_back(ASCIIToUTF16("firstname")); |
2237 values.push_back(ASCIIToUTF16("John")); | 2237 values.push_back(ASCIIToUTF16("John")); |
2238 | 2238 |
2239 labels.push_back(ASCIIToUTF16("Last name:")); | 2239 labels.push_back(ASCIIToUTF16("Last name:")); |
2240 names.push_back(ASCIIToUTF16("lastname")); | 2240 names.push_back(ASCIIToUTF16("lastname")); |
2241 values.push_back(ASCIIToUTF16("Smith")); | 2241 values.push_back(ASCIIToUTF16("Smith")); |
2242 | 2242 |
2243 labels.push_back(ASCIIToUTF16("Email:")); | 2243 labels.push_back(ASCIIToUTF16("Email:")); |
2244 names.push_back(ASCIIToUTF16("email")); | 2244 names.push_back(ASCIIToUTF16("email")); |
2245 values.push_back(ASCIIToUTF16("john@example.com")); | 2245 values.push_back(ASCIIToUTF16("john@example.com")); |
2246 | 2246 |
2247 ExpectLabels( | 2247 ExpectLabels( |
2248 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2248 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2249 "<DL>" | 2249 "<DL>" |
2250 " <DT>" | 2250 " <DT>" |
2251 " <SPAN>" | 2251 " <SPAN>" |
2252 " *" | 2252 " *" |
2253 " </SPAN>" | 2253 " </SPAN>" |
2254 " <SPAN>" | 2254 " <SPAN>" |
2255 " First name:" | 2255 " First name:" |
2256 " </SPAN>" | 2256 " </SPAN>" |
2257 " <SPAN>" | 2257 " <SPAN>" |
2258 " Bogus" | 2258 " Bogus" |
2259 " </SPAN>" | 2259 " </SPAN>" |
2260 " </DT>" | 2260 " </DT>" |
2261 " <DD>" | 2261 " <DD>" |
2262 " <FONT>" | 2262 " <FONT>" |
2263 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2263 " <INPUT type='text' id='firstname' value='John'/>" |
2264 " </FONT>" | 2264 " </FONT>" |
2265 " </DD>" | 2265 " </DD>" |
2266 " <DT>" | 2266 " <DT>" |
2267 " <SPAN>" | 2267 " <SPAN>" |
2268 " Last name:" | 2268 " Last name:" |
2269 " </SPAN>" | 2269 " </SPAN>" |
2270 " </DT>" | 2270 " </DT>" |
2271 " <DD>" | 2271 " <DD>" |
2272 " <FONT>" | 2272 " <FONT>" |
2273 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2273 " <INPUT type='text' id='lastname' value='Smith'/>" |
2274 " </FONT>" | 2274 " </FONT>" |
2275 " </DD>" | 2275 " </DD>" |
2276 " <DT>" | 2276 " <DT>" |
2277 " <SPAN>" | 2277 " <SPAN>" |
2278 " Email:" | 2278 " Email:" |
2279 " </SPAN>" | 2279 " </SPAN>" |
2280 " </DT>" | 2280 " </DT>" |
2281 " <DD>" | 2281 " <DD>" |
2282 " <FONT>" | 2282 " <FONT>" |
2283 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2283 " <INPUT type='text' id='email' value='john@example.com'/>" |
2284 " </FONT>" | 2284 " </FONT>" |
2285 " </DD>" | 2285 " </DD>" |
2286 " <DT></DT>" | 2286 " <DT></DT>" |
2287 " <DD>" | 2287 " <DD>" |
2288 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2288 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2289 " </DD>" | 2289 " </DD>" |
2290 "</DL>" | 2290 "</DL>" |
2291 "</FORM>", | 2291 "</FORM>", |
2292 labels, names, values); | 2292 labels, names, values); |
2293 } | 2293 } |
2294 | 2294 |
2295 TEST_F(FormAutofillTest, LabelsInferredWithSameName) { | 2295 TEST_F(FormAutofillTest, LabelsInferredWithSameName) { |
2296 std::vector<base::string16> labels, names, values; | 2296 std::vector<base::string16> labels, names, values; |
2297 | 2297 |
2298 labels.push_back(ASCIIToUTF16("Address Line 1:")); | 2298 labels.push_back(ASCIIToUTF16("Address Line 1:")); |
2299 names.push_back(ASCIIToUTF16("Address")); | 2299 names.push_back(ASCIIToUTF16("Address")); |
2300 values.push_back(base::string16()); | 2300 values.push_back(base::string16()); |
2301 | 2301 |
2302 labels.push_back(ASCIIToUTF16("Address Line 2:")); | 2302 labels.push_back(ASCIIToUTF16("Address Line 2:")); |
2303 names.push_back(ASCIIToUTF16("Address")); | 2303 names.push_back(ASCIIToUTF16("Address")); |
2304 values.push_back(base::string16()); | 2304 values.push_back(base::string16()); |
2305 | 2305 |
2306 labels.push_back(ASCIIToUTF16("Address Line 3:")); | 2306 labels.push_back(ASCIIToUTF16("Address Line 3:")); |
2307 names.push_back(ASCIIToUTF16("Address")); | 2307 names.push_back(ASCIIToUTF16("Address")); |
2308 values.push_back(base::string16()); | 2308 values.push_back(base::string16()); |
2309 | 2309 |
2310 ExpectLabels( | 2310 ExpectLabels( |
2311 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2311 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2312 " Address Line 1:" | 2312 " Address Line 1:" |
2313 " <INPUT type=\"text\" name=\"Address\"/>" | 2313 " <INPUT type='text' name='Address'/>" |
2314 " Address Line 2:" | 2314 " Address Line 2:" |
2315 " <INPUT type=\"text\" name=\"Address\"/>" | 2315 " <INPUT type='text' name='Address'/>" |
2316 " Address Line 3:" | 2316 " Address Line 3:" |
2317 " <INPUT type=\"text\" name=\"Address\"/>" | 2317 " <INPUT type='text' name='Address'/>" |
2318 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2318 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2319 "</FORM>", | 2319 "</FORM>", |
2320 labels, names, values); | 2320 labels, names, values); |
2321 } | 2321 } |
2322 | 2322 |
2323 TEST_F(FormAutofillTest, LabelsInferredWithImageTags) { | 2323 TEST_F(FormAutofillTest, LabelsInferredWithImageTags) { |
2324 std::vector<base::string16> labels, names, values; | 2324 std::vector<base::string16> labels, names, values; |
2325 | 2325 |
2326 labels.push_back(ASCIIToUTF16("Phone:")); | 2326 labels.push_back(ASCIIToUTF16("Phone:")); |
2327 names.push_back(ASCIIToUTF16("dayphone1")); | 2327 names.push_back(ASCIIToUTF16("dayphone1")); |
2328 values.push_back(base::string16()); | 2328 values.push_back(base::string16()); |
2329 | 2329 |
2330 labels.push_back(ASCIIToUTF16("-")); | 2330 labels.push_back(ASCIIToUTF16("-")); |
2331 names.push_back(ASCIIToUTF16("dayphone2")); | 2331 names.push_back(ASCIIToUTF16("dayphone2")); |
2332 values.push_back(base::string16()); | 2332 values.push_back(base::string16()); |
2333 | 2333 |
2334 labels.push_back(ASCIIToUTF16("-")); | 2334 labels.push_back(ASCIIToUTF16("-")); |
2335 names.push_back(ASCIIToUTF16("dayphone3")); | 2335 names.push_back(ASCIIToUTF16("dayphone3")); |
2336 values.push_back(base::string16()); | 2336 values.push_back(base::string16()); |
2337 | 2337 |
2338 labels.push_back(ASCIIToUTF16("ext.:")); | 2338 labels.push_back(ASCIIToUTF16("ext.:")); |
2339 names.push_back(ASCIIToUTF16("dayphone4")); | 2339 names.push_back(ASCIIToUTF16("dayphone4")); |
2340 values.push_back(base::string16()); | 2340 values.push_back(base::string16()); |
2341 | 2341 |
2342 labels.push_back(base::string16()); | 2342 labels.push_back(base::string16()); |
2343 names.push_back(ASCIIToUTF16("dummy")); | 2343 names.push_back(ASCIIToUTF16("dummy")); |
2344 values.push_back(base::string16()); | 2344 values.push_back(base::string16()); |
2345 | 2345 |
2346 ExpectLabels( | 2346 ExpectLabels( |
2347 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2347 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2348 " Phone:" | 2348 " Phone:" |
2349 " <input type=\"text\" name=\"dayphone1\">" | 2349 " <input type='text' name='dayphone1'>" |
2350 " <img/>" | 2350 " <img/>" |
2351 " -" | 2351 " -" |
2352 " <img/>" | 2352 " <img/>" |
2353 " <input type=\"text\" name=\"dayphone2\">" | 2353 " <input type='text' name='dayphone2'>" |
2354 " <img/>" | 2354 " <img/>" |
2355 " -" | 2355 " -" |
2356 " <img/>" | 2356 " <img/>" |
2357 " <input type=\"text\" name=\"dayphone3\">" | 2357 " <input type='text' name='dayphone3'>" |
2358 " ext.:" | 2358 " ext.:" |
2359 " <input type=\"text\" name=\"dayphone4\">" | 2359 " <input type='text' name='dayphone4'>" |
2360 " <input type=\"text\" name=\"dummy\">" | 2360 " <input type='text' name='dummy'>" |
2361 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2361 " <input type='submit' name='reply-send' value='Send'>" |
2362 "</FORM>", | 2362 "</FORM>", |
2363 labels, names, values); | 2363 labels, names, values); |
2364 } | 2364 } |
2365 | 2365 |
2366 TEST_F(FormAutofillTest, LabelsInferredFromDivTable) { | 2366 TEST_F(FormAutofillTest, LabelsInferredFromDivTable) { |
2367 ExpectJohnSmithLabels( | 2367 ExpectJohnSmithLabels( |
2368 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2368 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2369 "<DIV>First name:<BR>" | 2369 "<DIV>First name:<BR>" |
2370 " <SPAN>" | 2370 " <SPAN>" |
2371 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">" | 2371 " <INPUT type='text' name='firstname' value='John'>" |
2372 " </SPAN>" | 2372 " </SPAN>" |
2373 "</DIV>" | 2373 "</DIV>" |
2374 "<DIV>Last name:<BR>" | 2374 "<DIV>Last name:<BR>" |
2375 " <SPAN>" | 2375 " <SPAN>" |
2376 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">" | 2376 " <INPUT type='text' name='lastname' value='Smith'>" |
2377 " </SPAN>" | 2377 " </SPAN>" |
2378 "</DIV>" | 2378 "</DIV>" |
2379 "<DIV>Email:<BR>" | 2379 "<DIV>Email:<BR>" |
2380 " <SPAN>" | 2380 " <SPAN>" |
2381 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">" | 2381 " <INPUT type='text' name='email' value='john@example.com'>" |
2382 " </SPAN>" | 2382 " </SPAN>" |
2383 "</DIV>" | 2383 "</DIV>" |
2384 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2384 "<input type='submit' name='reply-send' value='Send'>" |
2385 "</FORM>"); | 2385 "</FORM>"); |
2386 } | 2386 } |
2387 | 2387 |
2388 TEST_F(FormAutofillTest, LabelsInferredFromDivSiblingTable) { | 2388 TEST_F(FormAutofillTest, LabelsInferredFromDivSiblingTable) { |
2389 ExpectJohnSmithLabels( | 2389 ExpectJohnSmithLabels( |
2390 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2390 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2391 "<DIV>First name:</DIV>" | 2391 "<DIV>First name:</DIV>" |
2392 "<DIV>" | 2392 "<DIV>" |
2393 " <SPAN>" | 2393 " <SPAN>" |
2394 " <INPUT type=\"text\" name=\"firstname\" value=\"John\">" | 2394 " <INPUT type='text' name='firstname' value='John'>" |
2395 " </SPAN>" | 2395 " </SPAN>" |
2396 "</DIV>" | 2396 "</DIV>" |
2397 "<DIV>Last name:</DIV>" | 2397 "<DIV>Last name:</DIV>" |
2398 "<DIV>" | 2398 "<DIV>" |
2399 " <SPAN>" | 2399 " <SPAN>" |
2400 " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">" | 2400 " <INPUT type='text' name='lastname' value='Smith'>" |
2401 " </SPAN>" | 2401 " </SPAN>" |
2402 "</DIV>" | 2402 "</DIV>" |
2403 "<DIV>Email:</DIV>" | 2403 "<DIV>Email:</DIV>" |
2404 "<DIV>" | 2404 "<DIV>" |
2405 " <SPAN>" | 2405 " <SPAN>" |
2406 " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">" | 2406 " <INPUT type='text' name='email' value='john@example.com'>" |
2407 " </SPAN>" | 2407 " </SPAN>" |
2408 "</DIV>" | 2408 "</DIV>" |
2409 "<input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2409 "<input type='submit' name='reply-send' value='Send'>" |
2410 "</FORM>"); | 2410 "</FORM>"); |
2411 } | 2411 } |
2412 | 2412 |
2413 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionListRatherThanDivTable) { | 2413 TEST_F(FormAutofillTest, LabelsInferredFromDefinitionListRatherThanDivTable) { |
2414 ExpectJohnSmithLabels( | 2414 ExpectJohnSmithLabels( |
2415 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2415 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2416 "<DIV>This is not a label.<BR>" | 2416 "<DIV>This is not a label.<BR>" |
2417 "<DL>" | 2417 "<DL>" |
2418 " <DT>" | 2418 " <DT>" |
2419 " <SPAN>" | 2419 " <SPAN>" |
2420 " First name:" | 2420 " First name:" |
2421 " </SPAN>" | 2421 " </SPAN>" |
2422 " </DT>" | 2422 " </DT>" |
2423 " <DD>" | 2423 " <DD>" |
2424 " <FONT>" | 2424 " <FONT>" |
2425 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 2425 " <INPUT type='text' id='firstname' value='John'/>" |
2426 " </FONT>" | 2426 " </FONT>" |
2427 " </DD>" | 2427 " </DD>" |
2428 " <DT>" | 2428 " <DT>" |
2429 " <SPAN>" | 2429 " <SPAN>" |
2430 " Last name:" | 2430 " Last name:" |
2431 " </SPAN>" | 2431 " </SPAN>" |
2432 " </DT>" | 2432 " </DT>" |
2433 " <DD>" | 2433 " <DD>" |
2434 " <FONT>" | 2434 " <FONT>" |
2435 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 2435 " <INPUT type='text' id='lastname' value='Smith'/>" |
2436 " </FONT>" | 2436 " </FONT>" |
2437 " </DD>" | 2437 " </DD>" |
2438 " <DT>" | 2438 " <DT>" |
2439 " <SPAN>" | 2439 " <SPAN>" |
2440 " Email:" | 2440 " Email:" |
2441 " </SPAN>" | 2441 " </SPAN>" |
2442 " </DT>" | 2442 " </DT>" |
2443 " <DD>" | 2443 " <DD>" |
2444 " <FONT>" | 2444 " <FONT>" |
2445 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 2445 " <INPUT type='text' id='email' value='john@example.com'/>" |
2446 " </FONT>" | 2446 " </FONT>" |
2447 " </DD>" | 2447 " </DD>" |
2448 " <DT></DT>" | 2448 " <DT></DT>" |
2449 " <DD>" | 2449 " <DD>" |
2450 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2450 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2451 " </DD>" | 2451 " </DD>" |
2452 "</DL>" | 2452 "</DL>" |
2453 "</DIV>" | 2453 "</DIV>" |
2454 "</FORM>"); | 2454 "</FORM>"); |
2455 } | 2455 } |
2456 | 2456 |
2457 TEST_F(FormAutofillTest, FillFormMaxLength) { | 2457 TEST_F(FormAutofillTest, FillFormMaxLength) { |
2458 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2458 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
2459 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>" | 2459 " <INPUT type='text' id='firstname' maxlength='5'/>" |
2460 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>" | 2460 " <INPUT type='text' id='lastname' maxlength='7'/>" |
2461 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>" | 2461 " <INPUT type='text' id='email' maxlength='9'/>" |
2462 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2462 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2463 "</FORM>"); | 2463 "</FORM>"); |
2464 | 2464 |
2465 WebFrame* web_frame = GetMainFrame(); | 2465 WebFrame* web_frame = GetMainFrame(); |
2466 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2466 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2467 | 2467 |
2468 FormCache form_cache; | 2468 FormCache form_cache; |
2469 std::vector<FormData> forms; | 2469 std::vector<FormData> forms; |
2470 form_cache.ExtractNewForms(*web_frame, &forms); | 2470 form_cache.ExtractNewForms(*web_frame, &forms); |
2471 ASSERT_EQ(1U, forms.size()); | 2471 ASSERT_EQ(1U, forms.size()); |
2472 | 2472 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2548 expected.value = ASCIIToUTF16("brotherj@"); | 2548 expected.value = ASCIIToUTF16("brotherj@"); |
2549 expected.max_length = 9; | 2549 expected.max_length = 9; |
2550 expected.is_autofilled = true; | 2550 expected.is_autofilled = true; |
2551 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2551 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
2552 } | 2552 } |
2553 | 2553 |
2554 // This test uses negative values of the maxlength attribute for input elements. | 2554 // This test uses negative values of the maxlength attribute for input elements. |
2555 // In this case, the maxlength of the input elements is set to the default | 2555 // In this case, the maxlength of the input elements is set to the default |
2556 // maxlength (defined in WebKit.) | 2556 // maxlength (defined in WebKit.) |
2557 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { | 2557 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { |
2558 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2558 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
2559 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" | 2559 " <INPUT type='text' id='firstname' maxlength='-1'/>" |
2560 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" | 2560 " <INPUT type='text' id='lastname' maxlength='-10'/>" |
2561 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" | 2561 " <INPUT type='text' id='email' maxlength='-13'/>" |
2562 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 2562 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2563 "</FORM>"); | 2563 "</FORM>"); |
2564 | 2564 |
2565 WebFrame* web_frame = GetMainFrame(); | 2565 WebFrame* web_frame = GetMainFrame(); |
2566 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2566 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2567 | 2567 |
2568 FormCache form_cache; | 2568 FormCache form_cache; |
2569 std::vector<FormData> forms; | 2569 std::vector<FormData> forms; |
2570 form_cache.ExtractNewForms(*web_frame, &forms); | 2570 form_cache.ExtractNewForms(*web_frame, &forms); |
2571 ASSERT_EQ(1U, forms.size()); | 2571 ASSERT_EQ(1U, forms.size()); |
2572 | 2572 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 expected.name = ASCIIToUTF16("lastname"); | 2629 expected.name = ASCIIToUTF16("lastname"); |
2630 expected.value = ASCIIToUTF16("Jonathan"); | 2630 expected.value = ASCIIToUTF16("Jonathan"); |
2631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2632 | 2632 |
2633 expected.name = ASCIIToUTF16("email"); | 2633 expected.name = ASCIIToUTF16("email"); |
2634 expected.value = ASCIIToUTF16("brotherj@example.com"); | 2634 expected.value = ASCIIToUTF16("brotherj@example.com"); |
2635 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2635 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2636 } | 2636 } |
2637 | 2637 |
2638 TEST_F(FormAutofillTest, FillFormEmptyName) { | 2638 TEST_F(FormAutofillTest, FillFormEmptyName) { |
2639 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2639 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
2640 " <INPUT type=\"text\" id=\"firstname\"/>" | 2640 " <INPUT type='text' id='firstname'/>" |
2641 " <INPUT type=\"text\" id=\"lastname\"/>" | 2641 " <INPUT type='text' id='lastname'/>" |
2642 " <INPUT type=\"text\" id=\"email\"/>" | 2642 " <INPUT type='text' id='email'/>" |
2643 " <INPUT type=\"submit\" value=\"Send\"/>" | 2643 " <INPUT type='submit' value='Send'/>" |
2644 "</FORM>"); | 2644 "</FORM>"); |
2645 | 2645 |
2646 WebFrame* web_frame = GetMainFrame(); | 2646 WebFrame* web_frame = GetMainFrame(); |
2647 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2647 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2648 | 2648 |
2649 FormCache form_cache; | 2649 FormCache form_cache; |
2650 std::vector<FormData> forms; | 2650 std::vector<FormData> forms; |
2651 form_cache.ExtractNewForms(*web_frame, &forms); | 2651 form_cache.ExtractNewForms(*web_frame, &forms); |
2652 ASSERT_EQ(1U, forms.size()); | 2652 ASSERT_EQ(1U, forms.size()); |
2653 | 2653 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 expected.name = ASCIIToUTF16("lastname"); | 2713 expected.name = ASCIIToUTF16("lastname"); |
2714 expected.value = ASCIIToUTF16("Earp"); | 2714 expected.value = ASCIIToUTF16("Earp"); |
2715 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2715 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2716 | 2716 |
2717 expected.name = ASCIIToUTF16("email"); | 2717 expected.name = ASCIIToUTF16("email"); |
2718 expected.value = ASCIIToUTF16("wyatt@example.com"); | 2718 expected.value = ASCIIToUTF16("wyatt@example.com"); |
2719 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2719 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2720 } | 2720 } |
2721 | 2721 |
2722 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { | 2722 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { |
2723 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" | 2723 LoadHTML("<FORM action='http://buh.com' method='post'>" |
2724 " <INPUT type=\"text\" id=\"firstname\"/>" | 2724 " <INPUT type='text' id='firstname'/>" |
2725 " <INPUT type=\"text\" id=\"middlename\"/>" | 2725 " <INPUT type='text' id='middlename'/>" |
2726 " <INPUT type=\"text\" id=\"lastname\"/>" | 2726 " <INPUT type='text' id='lastname'/>" |
2727 " <INPUT type=\"submit\" value=\"Send\"/>" | 2727 " <INPUT type='submit' value='Send'/>" |
2728 "</FORM>" | 2728 "</FORM>" |
2729 "<FORM action=\"http://abc.com\" method=\"post\">" | 2729 "<FORM action='http://abc.com' method='post'>" |
2730 " <INPUT type=\"text\" id=\"apple\"/>" | 2730 " <INPUT type='text' id='apple'/>" |
2731 " <INPUT type=\"text\" id=\"banana\"/>" | 2731 " <INPUT type='text' id='banana'/>" |
2732 " <INPUT type=\"text\" id=\"cantelope\"/>" | 2732 " <INPUT type='text' id='cantelope'/>" |
2733 " <INPUT type=\"submit\" value=\"Send\"/>" | 2733 " <INPUT type='submit' value='Send'/>" |
2734 "</FORM>"); | 2734 "</FORM>"); |
2735 | 2735 |
2736 WebFrame* web_frame = GetMainFrame(); | 2736 WebFrame* web_frame = GetMainFrame(); |
2737 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2737 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2738 | 2738 |
2739 FormCache form_cache; | 2739 FormCache form_cache; |
2740 std::vector<FormData> forms; | 2740 std::vector<FormData> forms; |
2741 form_cache.ExtractNewForms(*web_frame, &forms); | 2741 form_cache.ExtractNewForms(*web_frame, &forms); |
2742 ASSERT_EQ(2U, forms.size()); | 2742 ASSERT_EQ(2U, forms.size()); |
2743 | 2743 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2809 expected.is_autofilled = true; | 2809 expected.is_autofilled = true; |
2810 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 2810 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
2811 | 2811 |
2812 expected.name = ASCIIToUTF16("cantelope"); | 2812 expected.name = ASCIIToUTF16("cantelope"); |
2813 expected.value = ASCIIToUTF16("Also Yellow"); | 2813 expected.value = ASCIIToUTF16("Also Yellow"); |
2814 expected.is_autofilled = true; | 2814 expected.is_autofilled = true; |
2815 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2815 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
2816 } | 2816 } |
2817 | 2817 |
2818 TEST_F(FormAutofillTest, ThreePartPhone) { | 2818 TEST_F(FormAutofillTest, ThreePartPhone) { |
2819 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2819 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2820 " Phone:" | 2820 " Phone:" |
2821 " <input type=\"text\" name=\"dayphone1\">" | 2821 " <input type='text' name='dayphone1'>" |
2822 " -" | 2822 " -" |
2823 " <input type=\"text\" name=\"dayphone2\">" | 2823 " <input type='text' name='dayphone2'>" |
2824 " -" | 2824 " -" |
2825 " <input type=\"text\" name=\"dayphone3\">" | 2825 " <input type='text' name='dayphone3'>" |
2826 " ext.:" | 2826 " ext.:" |
2827 " <input type=\"text\" name=\"dayphone4\">" | 2827 " <input type='text' name='dayphone4'>" |
2828 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2828 " <input type='submit' name='reply-send' value='Send'>" |
2829 "</FORM>"); | 2829 "</FORM>"); |
2830 | 2830 |
2831 | 2831 |
2832 WebFrame* frame = GetMainFrame(); | 2832 WebFrame* frame = GetMainFrame(); |
2833 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 2833 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
2834 | 2834 |
2835 WebVector<WebFormElement> forms; | 2835 WebVector<WebFormElement> forms; |
2836 frame->document().forms(forms); | 2836 frame->document().forms(forms); |
2837 ASSERT_EQ(1U, forms.size()); | 2837 ASSERT_EQ(1U, forms.size()); |
2838 | 2838 |
(...skipping 27 matching lines...) Expand all Loading... |
2866 expected.name = ASCIIToUTF16("dayphone3"); | 2866 expected.name = ASCIIToUTF16("dayphone3"); |
2867 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2867 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2868 | 2868 |
2869 expected.label = ASCIIToUTF16("ext.:"); | 2869 expected.label = ASCIIToUTF16("ext.:"); |
2870 expected.name = ASCIIToUTF16("dayphone4"); | 2870 expected.name = ASCIIToUTF16("dayphone4"); |
2871 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 2871 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
2872 } | 2872 } |
2873 | 2873 |
2874 | 2874 |
2875 TEST_F(FormAutofillTest, MaxLengthFields) { | 2875 TEST_F(FormAutofillTest, MaxLengthFields) { |
2876 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2876 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2877 " Phone:" | 2877 " Phone:" |
2878 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" | 2878 " <input type='text' maxlength='3' name='dayphone1'>" |
2879 " -" | 2879 " -" |
2880 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" | 2880 " <input type='text' maxlength='3' name='dayphone2'>" |
2881 " -" | 2881 " -" |
2882 " <input type=\"text\" maxlength=\"4\" size=\"5\"" | 2882 " <input type='text' maxlength='4' size='5'" |
2883 " name=\"dayphone3\">" | 2883 " name='dayphone3'>" |
2884 " ext.:" | 2884 " ext.:" |
2885 " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">" | 2885 " <input type='text' maxlength='5' name='dayphone4'>" |
2886 " <input type=\"text\" name=\"default1\">" | 2886 " <input type='text' name='default1'>" |
2887 " <input type=\"text\" maxlength=\"-1\" name=\"invalid1\">" | 2887 " <input type='text' maxlength='-1' name='invalid1'>" |
2888 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2888 " <input type='submit' name='reply-send' value='Send'>" |
2889 "</FORM>"); | 2889 "</FORM>"); |
2890 | 2890 |
2891 WebFrame* frame = GetMainFrame(); | 2891 WebFrame* frame = GetMainFrame(); |
2892 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 2892 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
2893 | 2893 |
2894 WebVector<WebFormElement> forms; | 2894 WebVector<WebFormElement> forms; |
2895 frame->document().forms(forms); | 2895 frame->document().forms(forms); |
2896 ASSERT_EQ(1U, forms.size()); | 2896 ASSERT_EQ(1U, forms.size()); |
2897 | 2897 |
2898 FormData form; | 2898 FormData form; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2942 expected.label = base::string16(); | 2942 expected.label = base::string16(); |
2943 expected.name = ASCIIToUTF16("invalid1"); | 2943 expected.name = ASCIIToUTF16("invalid1"); |
2944 expected.max_length = WebInputElement::defaultMaxLength(); | 2944 expected.max_length = WebInputElement::defaultMaxLength(); |
2945 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); | 2945 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
2946 } | 2946 } |
2947 | 2947 |
2948 // This test re-creates the experience of typing in a field then selecting a | 2948 // This test re-creates the experience of typing in a field then selecting a |
2949 // profile from the Autofill suggestions popup. The field that is being typed | 2949 // profile from the Autofill suggestions popup. The field that is being typed |
2950 // into should be filled even though it's not technically empty. | 2950 // into should be filled even though it's not technically empty. |
2951 TEST_F(FormAutofillTest, FillFormNonEmptyField) { | 2951 TEST_F(FormAutofillTest, FillFormNonEmptyField) { |
2952 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2952 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
2953 " <INPUT type=\"text\" id=\"firstname\"/>" | 2953 " <INPUT type='text' id='firstname'/>" |
2954 " <INPUT type=\"text\" id=\"lastname\"/>" | 2954 " <INPUT type='text' id='lastname'/>" |
2955 " <INPUT type=\"text\" id=\"email\"/>" | 2955 " <INPUT type='text' id='email'/>" |
2956 " <INPUT type=\"submit\" value=\"Send\"/>" | 2956 " <INPUT type='submit' value='Send'/>" |
2957 "</FORM>"); | 2957 "</FORM>"); |
2958 | 2958 |
2959 WebFrame* web_frame = GetMainFrame(); | 2959 WebFrame* web_frame = GetMainFrame(); |
2960 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2960 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2961 | 2961 |
2962 FormCache form_cache; | 2962 FormCache form_cache; |
2963 std::vector<FormData> forms; | 2963 std::vector<FormData> forms; |
2964 form_cache.ExtractNewForms(*web_frame, &forms); | 2964 form_cache.ExtractNewForms(*web_frame, &forms); |
2965 ASSERT_EQ(1U, forms.size()); | 2965 ASSERT_EQ(1U, forms.size()); |
2966 | 2966 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3048 expected.is_autofilled = true; | 3048 expected.is_autofilled = true; |
3049 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 3049 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
3050 | 3050 |
3051 // Verify that the cursor position has been updated. | 3051 // Verify that the cursor position has been updated. |
3052 EXPECT_EQ(5, input_element.selectionStart()); | 3052 EXPECT_EQ(5, input_element.selectionStart()); |
3053 EXPECT_EQ(5, input_element.selectionEnd()); | 3053 EXPECT_EQ(5, input_element.selectionEnd()); |
3054 } | 3054 } |
3055 | 3055 |
3056 TEST_F(FormAutofillTest, ClearFormWithNode) { | 3056 TEST_F(FormAutofillTest, ClearFormWithNode) { |
3057 LoadHTML( | 3057 LoadHTML( |
3058 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3058 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
3059 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3059 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
3060 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" | 3060 " <INPUT type='text' id='lastname' value='Earp'/>" |
3061 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noAC\" value=\"one\"/>" | 3061 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" |
3062 " <INPUT type=\"text\" id=\"notenabled\" disabled=\"disabled\">" | 3062 " <INPUT type='text' id='notenabled' disabled='disabled'>" |
3063 " <INPUT type=\"month\" id=\"month\" value=\"2012-11\">" | 3063 " <INPUT type='month' id='month' value='2012-11'>" |
3064 " <INPUT type=\"month\" id=\"month-disabled\" value=\"2012-11\"" | 3064 " <INPUT type='month' id='month-disabled' value='2012-11'" |
3065 " disabled=\"disabled\">" | 3065 " disabled='disabled'>" |
3066 " <TEXTAREA id=\"textarea\">Apple.</TEXTAREA>" | 3066 " <TEXTAREA id='textarea'>Apple.</TEXTAREA>" |
3067 " <TEXTAREA id=\"textarea-disabled\" disabled=\"disabled\">" | 3067 " <TEXTAREA id='textarea-disabled' disabled='disabled'>" |
3068 " Banana!" | 3068 " Banana!" |
3069 " </TEXTAREA>" | 3069 " </TEXTAREA>" |
3070 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>" | 3070 " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>" |
3071 " <INPUT type=\"submit\" value=\"Send\"/>" | 3071 " <INPUT type='submit' value='Send'/>" |
3072 "</FORM>"); | 3072 "</FORM>"); |
3073 | 3073 |
3074 WebFrame* web_frame = GetMainFrame(); | 3074 WebFrame* web_frame = GetMainFrame(); |
3075 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3075 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3076 | 3076 |
3077 FormCache form_cache; | 3077 FormCache form_cache; |
3078 std::vector<FormData> forms; | 3078 std::vector<FormData> forms; |
3079 form_cache.ExtractNewForms(*web_frame, &forms); | 3079 form_cache.ExtractNewForms(*web_frame, &forms); |
3080 ASSERT_EQ(1U, forms.size()); | 3080 ASSERT_EQ(1U, forms.size()); |
3081 | 3081 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3165 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); | 3165 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); |
3166 expected.autocomplete_attribute = std::string(); // reset | 3166 expected.autocomplete_attribute = std::string(); // reset |
3167 | 3167 |
3168 // Verify that the cursor position has been updated. | 3168 // Verify that the cursor position has been updated. |
3169 EXPECT_EQ(0, firstname.selectionStart()); | 3169 EXPECT_EQ(0, firstname.selectionStart()); |
3170 EXPECT_EQ(0, firstname.selectionEnd()); | 3170 EXPECT_EQ(0, firstname.selectionEnd()); |
3171 } | 3171 } |
3172 | 3172 |
3173 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { | 3173 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
3174 LoadHTML( | 3174 LoadHTML( |
3175 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3175 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
3176 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3176 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
3177 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" | 3177 " <INPUT type='text' id='lastname' value='Earp'/>" |
3178 " <SELECT id=\"state\" name=\"state\">" | 3178 " <SELECT id='state' name='state'>" |
3179 " <OPTION selected>?</OPTION>" | 3179 " <OPTION selected>?</OPTION>" |
3180 " <OPTION>AA</OPTION>" | 3180 " <OPTION>AA</OPTION>" |
3181 " <OPTION>AE</OPTION>" | 3181 " <OPTION>AE</OPTION>" |
3182 " <OPTION>AK</OPTION>" | 3182 " <OPTION>AK</OPTION>" |
3183 " </SELECT>" | 3183 " </SELECT>" |
3184 " <INPUT type=\"submit\" value=\"Send\"/>" | 3184 " <INPUT type='submit' value='Send'/>" |
3185 "</FORM>"); | 3185 "</FORM>"); |
3186 | 3186 |
3187 WebFrame* web_frame = GetMainFrame(); | 3187 WebFrame* web_frame = GetMainFrame(); |
3188 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3188 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3189 | 3189 |
3190 FormCache form_cache; | 3190 FormCache form_cache; |
3191 std::vector<FormData> forms; | 3191 std::vector<FormData> forms; |
3192 form_cache.ExtractNewForms(*web_frame, &forms); | 3192 form_cache.ExtractNewForms(*web_frame, &forms); |
3193 ASSERT_EQ(1U, forms.size()); | 3193 ASSERT_EQ(1U, forms.size()); |
3194 | 3194 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3247 expected.form_control_type = "select-one"; | 3247 expected.form_control_type = "select-one"; |
3248 expected.max_length = 0; | 3248 expected.max_length = 0; |
3249 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 3249 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
3250 | 3250 |
3251 // Verify that the cursor position has been updated. | 3251 // Verify that the cursor position has been updated. |
3252 EXPECT_EQ(0, firstname.selectionStart()); | 3252 EXPECT_EQ(0, firstname.selectionStart()); |
3253 EXPECT_EQ(0, firstname.selectionEnd()); | 3253 EXPECT_EQ(0, firstname.selectionEnd()); |
3254 } | 3254 } |
3255 | 3255 |
3256 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 3256 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
3257 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3257 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
3258 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3258 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
3259 " <INPUT type=\"text\" id=\"lastname\"/>" | 3259 " <INPUT type='text' id='lastname'/>" |
3260 " <INPUT type=\"text\" id=\"email\"/>" | 3260 " <INPUT type='text' id='email'/>" |
3261 " <INPUT type=\"email\" id=\"email2\"/>" | 3261 " <INPUT type='email' id='email2'/>" |
3262 " <INPUT type=\"tel\" id=\"phone\"/>" | 3262 " <INPUT type='tel' id='phone'/>" |
3263 " <INPUT type=\"submit\" value=\"Send\"/>" | 3263 " <INPUT type='submit' value='Send'/>" |
3264 "</FORM>"); | 3264 "</FORM>"); |
3265 | 3265 |
3266 WebFrame* web_frame = GetMainFrame(); | 3266 WebFrame* web_frame = GetMainFrame(); |
3267 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3267 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3268 | 3268 |
3269 FormCache form_cache; | 3269 FormCache form_cache; |
3270 std::vector<FormData> forms; | 3270 std::vector<FormData> forms; |
3271 form_cache.ExtractNewForms(*web_frame, &forms); | 3271 form_cache.ExtractNewForms(*web_frame, &forms); |
3272 ASSERT_EQ(1U, forms.size()); | 3272 ASSERT_EQ(1U, forms.size()); |
3273 | 3273 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3315 EXPECT_TRUE(phone.value().isEmpty()); | 3315 EXPECT_TRUE(phone.value().isEmpty()); |
3316 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3316 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
3317 EXPECT_FALSE(phone.isAutofilled()); | 3317 EXPECT_FALSE(phone.isAutofilled()); |
3318 | 3318 |
3319 // Verify that the cursor position has been updated. | 3319 // Verify that the cursor position has been updated. |
3320 EXPECT_EQ(0, lastname.selectionStart()); | 3320 EXPECT_EQ(0, lastname.selectionStart()); |
3321 EXPECT_EQ(0, lastname.selectionEnd()); | 3321 EXPECT_EQ(0, lastname.selectionEnd()); |
3322 } | 3322 } |
3323 | 3323 |
3324 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { | 3324 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { |
3325 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3325 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
3326 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>" | 3326 " <INPUT type='text' id='firstname' value='W'/>" |
3327 " <INPUT type=\"text\" id=\"lastname\"/>" | 3327 " <INPUT type='text' id='lastname'/>" |
3328 " <INPUT type=\"text\" id=\"email\"/>" | 3328 " <INPUT type='text' id='email'/>" |
3329 " <INPUT type=\"email\" id=\"email2\"/>" | 3329 " <INPUT type='email' id='email2'/>" |
3330 " <INPUT type=\"tel\" id=\"phone\"/>" | 3330 " <INPUT type='tel' id='phone'/>" |
3331 " <INPUT type=\"submit\" value=\"Send\"/>" | 3331 " <INPUT type='submit' value='Send'/>" |
3332 "</FORM>"); | 3332 "</FORM>"); |
3333 | 3333 |
3334 WebFrame* web_frame = GetMainFrame(); | 3334 WebFrame* web_frame = GetMainFrame(); |
3335 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3335 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3336 | 3336 |
3337 FormCache form_cache; | 3337 FormCache form_cache; |
3338 std::vector<FormData> forms; | 3338 std::vector<FormData> forms; |
3339 form_cache.ExtractNewForms(*web_frame, &forms); | 3339 form_cache.ExtractNewForms(*web_frame, &forms); |
3340 ASSERT_EQ(1U, forms.size()); | 3340 ASSERT_EQ(1U, forms.size()); |
3341 | 3341 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 EXPECT_FALSE(email.isAutofilled()); | 3383 EXPECT_FALSE(email.isAutofilled()); |
3384 EXPECT_TRUE(email2.value().isEmpty()); | 3384 EXPECT_TRUE(email2.value().isEmpty()); |
3385 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | 3385 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
3386 EXPECT_FALSE(email2.isAutofilled()); | 3386 EXPECT_FALSE(email2.isAutofilled()); |
3387 EXPECT_TRUE(phone.value().isEmpty()); | 3387 EXPECT_TRUE(phone.value().isEmpty()); |
3388 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3388 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
3389 EXPECT_FALSE(phone.isAutofilled()); | 3389 EXPECT_FALSE(phone.isAutofilled()); |
3390 } | 3390 } |
3391 | 3391 |
3392 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { | 3392 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
3393 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3393 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
3394 " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>" | 3394 " <INPUT type='text' id='firstname' value='W'/>" |
3395 " <INPUT type=\"text\" id=\"lastname\"/>" | 3395 " <INPUT type='text' id='lastname'/>" |
3396 " <INPUT type=\"text\" id=\"email\"/>" | 3396 " <INPUT type='text' id='email'/>" |
3397 " <INPUT type=\"email\" id=\"email2\"/>" | 3397 " <INPUT type='email' id='email2'/>" |
3398 " <INPUT type=\"tel\" id=\"phone\"/>" | 3398 " <INPUT type='tel' id='phone'/>" |
3399 " <INPUT type=\"submit\" value=\"Send\"/>" | 3399 " <INPUT type='submit' value='Send'/>" |
3400 "</FORM>"); | 3400 "</FORM>"); |
3401 | 3401 |
3402 WebFrame* web_frame = GetMainFrame(); | 3402 WebFrame* web_frame = GetMainFrame(); |
3403 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3403 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3404 | 3404 |
3405 FormCache form_cache; | 3405 FormCache form_cache; |
3406 std::vector<FormData> forms; | 3406 std::vector<FormData> forms; |
3407 form_cache.ExtractNewForms(*web_frame, &forms); | 3407 form_cache.ExtractNewForms(*web_frame, &forms); |
3408 ASSERT_EQ(1U, forms.size()); | 3408 ASSERT_EQ(1U, forms.size()); |
3409 | 3409 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3453 EXPECT_FALSE(email2.isAutofilled()); | 3453 EXPECT_FALSE(email2.isAutofilled()); |
3454 EXPECT_TRUE(phone.value().isEmpty()); | 3454 EXPECT_TRUE(phone.value().isEmpty()); |
3455 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3455 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
3456 EXPECT_FALSE(phone.isAutofilled()); | 3456 EXPECT_FALSE(phone.isAutofilled()); |
3457 } | 3457 } |
3458 | 3458 |
3459 // Autofill's "Clear Form" should clear only autofilled fields | 3459 // Autofill's "Clear Form" should clear only autofilled fields |
3460 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { | 3460 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
3461 // Load the form. | 3461 // Load the form. |
3462 LoadHTML( | 3462 LoadHTML( |
3463 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3463 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
3464 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3464 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
3465 " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>" | 3465 " <INPUT type='text' id='lastname' value='Earp'/>" |
3466 " <INPUT type=\"email\" id=\"email\" value=\"wyatt@earp.com\"/>" | 3466 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" |
3467 " <INPUT type=\"tel\" id=\"phone\" value=\"650-777-9999\"/>" | 3467 " <INPUT type='tel' id='phone' value='650-777-9999'/>" |
3468 " <INPUT type=\"submit\" value=\"Send\"/>" | 3468 " <INPUT type='submit' value='Send'/>" |
3469 "</FORM>"); | 3469 "</FORM>"); |
3470 | 3470 |
3471 WebFrame* web_frame = GetMainFrame(); | 3471 WebFrame* web_frame = GetMainFrame(); |
3472 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3472 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3473 | 3473 |
3474 FormCache form_cache; | 3474 FormCache form_cache; |
3475 std::vector<FormData> forms; | 3475 std::vector<FormData> forms; |
3476 form_cache.ExtractNewForms(*web_frame, &forms); | 3476 form_cache.ExtractNewForms(*web_frame, &forms); |
3477 ASSERT_EQ(1U, forms.size()); | 3477 ASSERT_EQ(1U, forms.size()); |
3478 | 3478 |
(...skipping 23 matching lines...) Expand all Loading... |
3502 EXPECT_FALSE(lastname.isAutofilled()); | 3502 EXPECT_FALSE(lastname.isAutofilled()); |
3503 EXPECT_TRUE(email.value().isEmpty()); | 3503 EXPECT_TRUE(email.value().isEmpty()); |
3504 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 3504 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
3505 EXPECT_FALSE(email.isAutofilled()); | 3505 EXPECT_FALSE(email.isAutofilled()); |
3506 EXPECT_TRUE(phone.value().isEmpty()); | 3506 EXPECT_TRUE(phone.value().isEmpty()); |
3507 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3507 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
3508 EXPECT_FALSE(phone.isAutofilled()); | 3508 EXPECT_FALSE(phone.isAutofilled()); |
3509 } | 3509 } |
3510 | 3510 |
3511 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { | 3511 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { |
3512 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 3512 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" |
3513 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 3513 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
3514 " <INPUT type=\"text\" id=\"lastname\"/>" | 3514 " <INPUT type='text' id='lastname'/>" |
3515 " <INPUT type=\"text\" id=\"email\"/>" | 3515 " <INPUT type='text' id='email'/>" |
3516 " <INPUT type=\"email\" id=\"email2\"/>" | 3516 " <INPUT type='email' id='email2'/>" |
3517 " <INPUT type=\"tel\" id=\"phone\"/>" | 3517 " <INPUT type='tel' id='phone'/>" |
3518 " <INPUT type=\"submit\" value=\"Send\"/>" | 3518 " <INPUT type='submit' value='Send'/>" |
3519 "</FORM>"); | 3519 "</FORM>"); |
3520 | 3520 |
3521 WebFrame* web_frame = GetMainFrame(); | 3521 WebFrame* web_frame = GetMainFrame(); |
3522 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 3522 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
3523 | 3523 |
3524 FormCache form_cache; | 3524 FormCache form_cache; |
3525 std::vector<FormData> forms; | 3525 std::vector<FormData> forms; |
3526 form_cache.ExtractNewForms(*web_frame, &forms); | 3526 form_cache.ExtractNewForms(*web_frame, &forms); |
3527 ASSERT_EQ(1U, forms.size()); | 3527 ASSERT_EQ(1U, forms.size()); |
3528 | 3528 |
(...skipping 19 matching lines...) Expand all Loading... |
3548 | 3548 |
3549 labels.push_back(ASCIIToUTF16("Last Name:")); | 3549 labels.push_back(ASCIIToUTF16("Last Name:")); |
3550 names.push_back(ASCIIToUTF16("lastname")); | 3550 names.push_back(ASCIIToUTF16("lastname")); |
3551 values.push_back(ASCIIToUTF16("Smith")); | 3551 values.push_back(ASCIIToUTF16("Smith")); |
3552 | 3552 |
3553 labels.push_back(ASCIIToUTF16("Email: xxx@yyy.com")); | 3553 labels.push_back(ASCIIToUTF16("Email: xxx@yyy.com")); |
3554 names.push_back(ASCIIToUTF16("email")); | 3554 names.push_back(ASCIIToUTF16("email")); |
3555 values.push_back(ASCIIToUTF16("john@example.com")); | 3555 values.push_back(ASCIIToUTF16("john@example.com")); |
3556 | 3556 |
3557 ExpectLabels( | 3557 ExpectLabels( |
3558 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 3558 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
3559 " <LABEL for=\"firstname\"> First Name: </LABEL>" | 3559 " <LABEL for='firstname'> First Name: </LABEL>" |
3560 " <LABEL for=\"firstname\"></LABEL>" | 3560 " <LABEL for='firstname'></LABEL>" |
3561 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 3561 " <INPUT type='text' id='firstname' value='John'/>" |
3562 " <LABEL for=\"lastname\"></LABEL>" | 3562 " <LABEL for='lastname'></LABEL>" |
3563 " <LABEL for=\"lastname\"> Last Name: </LABEL>" | 3563 " <LABEL for='lastname'> Last Name: </LABEL>" |
3564 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 3564 " <INPUT type='text' id='lastname' value='Smith'/>" |
3565 " <LABEL for=\"email\"> Email: </LABEL>" | 3565 " <LABEL for='email'> Email: </LABEL>" |
3566 " <LABEL for=\"email\"> xxx@yyy.com </LABEL>" | 3566 " <LABEL for='email'> xxx@yyy.com </LABEL>" |
3567 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 3567 " <INPUT type='text' id='email' value='john@example.com'/>" |
3568 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 3568 " <INPUT type='submit' name='reply-send' value='Send'/>" |
3569 "</FORM>", | 3569 "</FORM>", |
3570 labels, names, values); | 3570 labels, names, values); |
3571 } | 3571 } |
3572 | 3572 |
3573 TEST_F(FormAutofillTest, ClickElement) { | 3573 TEST_F(FormAutofillTest, ClickElement) { |
3574 LoadHTML("<BUTTON id=\"link\">Button</BUTTON>" | 3574 LoadHTML("<BUTTON id='link'>Button</BUTTON>" |
3575 "<BUTTON name=\"button\">Button</BUTTON>"); | 3575 "<BUTTON name='button'>Button</BUTTON>"); |
3576 WebFrame* frame = GetMainFrame(); | 3576 WebFrame* frame = GetMainFrame(); |
3577 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 3577 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
3578 | 3578 |
3579 // Successful retrieval by id. | 3579 // Successful retrieval by id. |
3580 autofill::WebElementDescriptor clicker; | 3580 autofill::WebElementDescriptor clicker; |
3581 clicker.retrieval_method = autofill::WebElementDescriptor::ID; | 3581 clicker.retrieval_method = autofill::WebElementDescriptor::ID; |
3582 clicker.descriptor = "link"; | 3582 clicker.descriptor = "link"; |
3583 EXPECT_TRUE(ClickElement(frame->document(), clicker)); | 3583 EXPECT_TRUE(ClickElement(frame->document(), clicker)); |
3584 | 3584 |
3585 // Successful retrieval by css selector. | 3585 // Successful retrieval by css selector. |
3586 clicker.retrieval_method = autofill::WebElementDescriptor::CSS_SELECTOR; | 3586 clicker.retrieval_method = autofill::WebElementDescriptor::CSS_SELECTOR; |
3587 clicker.descriptor = "button[name=\"button\"]"; | 3587 clicker.descriptor = "button[name='button']"; |
3588 EXPECT_TRUE(ClickElement(frame->document(), clicker)); | 3588 EXPECT_TRUE(ClickElement(frame->document(), clicker)); |
3589 | 3589 |
3590 // Unsuccessful retrieval due to invalid CSS selector. | 3590 // Unsuccessful retrieval due to invalid CSS selector. |
3591 clicker.descriptor = "^*&"; | 3591 clicker.descriptor = "^*&"; |
3592 EXPECT_FALSE(ClickElement(frame->document(), clicker)); | 3592 EXPECT_FALSE(ClickElement(frame->document(), clicker)); |
3593 | 3593 |
3594 // Unsuccessful retrieval because element does not exist. | 3594 // Unsuccessful retrieval because element does not exist. |
3595 clicker.descriptor = "#junk"; | 3595 clicker.descriptor = "#junk"; |
3596 EXPECT_FALSE(ClickElement(frame->document(), clicker)); | 3596 EXPECT_FALSE(ClickElement(frame->document(), clicker)); |
3597 } | 3597 } |
3598 | 3598 |
3599 TEST_F(FormAutofillTest, SelectOneAsText) { | 3599 TEST_F(FormAutofillTest, SelectOneAsText) { |
3600 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 3600 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
3601 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 3601 " <INPUT type='text' id='firstname' value='John'/>" |
3602 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 3602 " <INPUT type='text' id='lastname' value='Smith'/>" |
3603 " <SELECT id=\"country\">" | 3603 " <SELECT id='country'>" |
3604 " <OPTION value=\"AF\">Afghanistan</OPTION>" | 3604 " <OPTION value='AF'>Afghanistan</OPTION>" |
3605 " <OPTION value=\"AL\">Albania</OPTION>" | 3605 " <OPTION value='AL'>Albania</OPTION>" |
3606 " <OPTION value=\"DZ\">Algeria</OPTION>" | 3606 " <OPTION value='DZ'>Algeria</OPTION>" |
3607 " </SELECT>" | 3607 " </SELECT>" |
3608 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 3608 " <INPUT type='submit' name='reply-send' value='Send'/>" |
3609 "</FORM>"); | 3609 "</FORM>"); |
3610 | 3610 |
3611 WebFrame* frame = GetMainFrame(); | 3611 WebFrame* frame = GetMainFrame(); |
3612 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 3612 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
3613 | 3613 |
3614 // Set the value of the select-one. | 3614 // Set the value of the select-one. |
3615 WebSelectElement select_element = | 3615 WebSelectElement select_element = |
3616 frame->document().getElementById("country").to<WebSelectElement>(); | 3616 frame->document().getElementById("country").to<WebSelectElement>(); |
3617 select_element.setValue(WebString::fromUTF8("AL")); | 3617 select_element.setValue(WebString::fromUTF8("AL")); |
3618 | 3618 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3681 expected.max_length = WebInputElement::defaultMaxLength(); | 3681 expected.max_length = WebInputElement::defaultMaxLength(); |
3682 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3682 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3683 | 3683 |
3684 expected.name = ASCIIToUTF16("country"); | 3684 expected.name = ASCIIToUTF16("country"); |
3685 expected.value = ASCIIToUTF16("AL"); | 3685 expected.value = ASCIIToUTF16("AL"); |
3686 expected.form_control_type = "select-one"; | 3686 expected.form_control_type = "select-one"; |
3687 expected.max_length = 0; | 3687 expected.max_length = 0; |
3688 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3688 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3689 } | 3689 } |
3690 } // namespace autofill | 3690 } // namespace autofill |
OLD | NEW |