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/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 FormCache form_cache(*web_frame); | 258 FormCache form_cache(*web_frame); |
259 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 259 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
260 ASSERT_EQ(1U, forms.size()); | 260 ASSERT_EQ(1U, forms.size()); |
261 | 261 |
262 // Get the input element we want to find. | 262 // Get the input element we want to find. |
263 WebInputElement input_element = GetInputElementById("firstname"); | 263 WebInputElement input_element = GetInputElementById("firstname"); |
264 | 264 |
265 // Find the form that contains the input element. | 265 // Find the form that contains the input element. |
266 FormData form_data; | 266 FormData form_data; |
267 FormFieldData field; | 267 FormFieldData field; |
268 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 268 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, &form_data, |
269 input_element, &form_data, &field, REQUIRE_NONE)); | 269 &field)); |
270 if (!unowned) { | 270 if (!unowned) { |
271 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); | 271 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); |
272 EXPECT_EQ(GURL("http://buh.com"), form_data.action); | 272 EXPECT_EQ(GURL("http://buh.com"), form_data.action); |
273 } | 273 } |
274 | 274 |
275 const std::vector<FormFieldData>& fields = form_data.fields; | 275 const std::vector<FormFieldData>& fields = form_data.fields; |
276 ASSERT_EQ(number_of_field_cases, fields.size()); | 276 ASSERT_EQ(number_of_field_cases, fields.size()); |
277 | 277 |
278 FormFieldData expected; | 278 FormFieldData expected; |
279 // Verify field's initial value. | 279 // Verify field's initial value. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 FormCache form_cache(*web_frame); | 489 FormCache form_cache(*web_frame); |
490 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 490 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
491 ASSERT_EQ(1U, forms.size()); | 491 ASSERT_EQ(1U, forms.size()); |
492 | 492 |
493 // Get the input element we want to find. | 493 // Get the input element we want to find. |
494 WebInputElement input_element = GetInputElementById("firstname"); | 494 WebInputElement input_element = GetInputElementById("firstname"); |
495 | 495 |
496 // Find the form and verify it's the correct form. | 496 // Find the form and verify it's the correct form. |
497 FormData form; | 497 FormData form; |
498 FormFieldData field; | 498 FormFieldData field; |
499 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 499 EXPECT_TRUE( |
500 input_element, &form, &field, REQUIRE_NONE)); | 500 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
501 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 501 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
502 if (!unowned) { | 502 if (!unowned) { |
503 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 503 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
504 EXPECT_EQ(GURL("http://buh.com"), form.action); | 504 EXPECT_EQ(GURL("http://buh.com"), form.action); |
505 } | 505 } |
506 | 506 |
507 const std::vector<FormFieldData>& fields = form.fields; | 507 const std::vector<FormFieldData>& fields = form.fields; |
508 ASSERT_EQ(4U, fields.size()); | 508 ASSERT_EQ(4U, fields.size()); |
509 | 509 |
510 FormFieldData expected; | 510 FormFieldData expected; |
(...skipping 11 matching lines...) Expand all Loading... |
522 | 522 |
523 expected.name = ASCIIToUTF16("email"); | 523 expected.name = ASCIIToUTF16("email"); |
524 expected.value = ASCIIToUTF16("john@example.com"); | 524 expected.value = ASCIIToUTF16("john@example.com"); |
525 expected.autocomplete_attribute = "off"; | 525 expected.autocomplete_attribute = "off"; |
526 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 526 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
527 expected.autocomplete_attribute.clear(); | 527 expected.autocomplete_attribute.clear(); |
528 | 528 |
529 expected.name = ASCIIToUTF16("phone"); | 529 expected.name = ASCIIToUTF16("phone"); |
530 expected.value = ASCIIToUTF16("1.800.555.1234"); | 530 expected.value = ASCIIToUTF16("1.800.555.1234"); |
531 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 531 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
532 | |
533 // Try again, but require autocomplete. | |
534 FormData form2; | |
535 FormFieldData field2; | |
536 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | |
537 input_element, &form2, &field2, REQUIRE_AUTOCOMPLETE)); | |
538 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
539 if (!unowned) { | |
540 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
541 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
542 } | |
543 | |
544 const std::vector<FormFieldData>& fields2 = form2.fields; | |
545 ASSERT_EQ(3U, fields2.size()); | |
546 | |
547 expected.form_control_type = "text"; | |
548 expected.max_length = WebInputElement::defaultMaxLength(); | |
549 | |
550 expected.name = ASCIIToUTF16("firstname"); | |
551 expected.value = ASCIIToUTF16("John"); | |
552 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
553 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
554 | |
555 expected.name = ASCIIToUTF16("lastname"); | |
556 expected.value = ASCIIToUTF16("Smith"); | |
557 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
558 | |
559 expected.name = ASCIIToUTF16("phone"); | |
560 expected.value = ASCIIToUTF16("1.800.555.1234"); | |
561 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
562 } | 532 } |
563 | 533 |
564 void TestFindFormForTextAreaElement(const char* html, bool unowned) { | 534 void TestFindFormForTextAreaElement(const char* html, bool unowned) { |
565 LoadHTML(html); | 535 LoadHTML(html); |
566 WebFrame* web_frame = GetMainFrame(); | 536 WebFrame* web_frame = GetMainFrame(); |
567 ASSERT_NE(nullptr, web_frame); | 537 ASSERT_NE(nullptr, web_frame); |
568 | 538 |
569 FormCache form_cache(*web_frame); | 539 FormCache form_cache(*web_frame); |
570 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 540 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
571 ASSERT_EQ(1U, forms.size()); | 541 ASSERT_EQ(1U, forms.size()); |
572 | 542 |
573 // Get the textarea element we want to find. | 543 // Get the textarea element we want to find. |
574 WebElement element = web_frame->document().getElementById("street-address"); | 544 WebElement element = web_frame->document().getElementById("street-address"); |
575 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); | 545 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); |
576 | 546 |
577 // Find the form and verify it's the correct form. | 547 // Find the form and verify it's the correct form. |
578 FormData form; | 548 FormData form; |
579 FormFieldData field; | 549 FormFieldData field; |
580 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 550 EXPECT_TRUE( |
581 textarea_element, &form, &field, REQUIRE_NONE)); | 551 FindFormAndFieldForFormControlElement(textarea_element, &form, &field)); |
582 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 552 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
583 if (!unowned) { | 553 if (!unowned) { |
584 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 554 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
585 EXPECT_EQ(GURL("http://buh.com"), form.action); | 555 EXPECT_EQ(GURL("http://buh.com"), form.action); |
586 } | 556 } |
587 | 557 |
588 const std::vector<FormFieldData>& fields = form.fields; | 558 const std::vector<FormFieldData>& fields = form.fields; |
589 ASSERT_EQ(4U, fields.size()); | 559 ASSERT_EQ(4U, fields.size()); |
590 | 560 |
591 FormFieldData expected; | 561 FormFieldData expected; |
(...skipping 17 matching lines...) Expand all Loading... |
609 expected.max_length = WebInputElement::defaultMaxLength(); | 579 expected.max_length = WebInputElement::defaultMaxLength(); |
610 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 580 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
611 expected.autocomplete_attribute.clear(); | 581 expected.autocomplete_attribute.clear(); |
612 | 582 |
613 expected.name = ASCIIToUTF16("street-address"); | 583 expected.name = ASCIIToUTF16("street-address"); |
614 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | 584 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); |
615 expected.form_control_type = "textarea"; | 585 expected.form_control_type = "textarea"; |
616 expected.max_length = 0; | 586 expected.max_length = 0; |
617 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 587 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
618 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 588 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
619 | |
620 // Try again, but require autocomplete. | |
621 FormData form2; | |
622 FormFieldData field2; | |
623 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | |
624 textarea_element, &form2, &field2, REQUIRE_AUTOCOMPLETE)); | |
625 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | |
626 if (!unowned) { | |
627 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | |
628 EXPECT_EQ(GURL("http://buh.com"), form2.action); | |
629 } | |
630 | |
631 const std::vector<FormFieldData>& fields2 = form2.fields; | |
632 ASSERT_EQ(3U, fields2.size()); | |
633 | |
634 expected.name = ASCIIToUTF16("firstname"); | |
635 expected.value = ASCIIToUTF16("John"); | |
636 expected.form_control_type = "text"; | |
637 expected.max_length = WebInputElement::defaultMaxLength(); | |
638 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | |
639 | |
640 expected.name = ASCIIToUTF16("lastname"); | |
641 expected.value = ASCIIToUTF16("Smith"); | |
642 expected.form_control_type = "text"; | |
643 expected.max_length = WebInputElement::defaultMaxLength(); | |
644 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | |
645 | |
646 expected.name = ASCIIToUTF16("street-address"); | |
647 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | |
648 expected.form_control_type = "textarea"; | |
649 expected.max_length = 0; | |
650 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | |
651 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | |
652 } | 589 } |
653 | 590 |
654 void TestFillFormMaxLength(const char* html, bool unowned) { | 591 void TestFillFormMaxLength(const char* html, bool unowned) { |
655 LoadHTML(html); | 592 LoadHTML(html); |
656 WebFrame* web_frame = GetMainFrame(); | 593 WebFrame* web_frame = GetMainFrame(); |
657 ASSERT_NE(nullptr, web_frame); | 594 ASSERT_NE(nullptr, web_frame); |
658 | 595 |
659 FormCache form_cache(*web_frame); | 596 FormCache form_cache(*web_frame); |
660 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 597 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
661 ASSERT_EQ(1U, forms.size()); | 598 ASSERT_EQ(1U, forms.size()); |
662 | 599 |
663 // Get the input element we want to find. | 600 // Get the input element we want to find. |
664 WebInputElement input_element = GetInputElementById("firstname"); | 601 WebInputElement input_element = GetInputElementById("firstname"); |
665 | 602 |
666 // Find the form that contains the input element. | 603 // Find the form that contains the input element. |
667 FormData form; | 604 FormData form; |
668 FormFieldData field; | 605 FormFieldData field; |
669 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 606 EXPECT_TRUE( |
670 input_element, &form, &field, REQUIRE_NONE)); | 607 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
671 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 608 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
672 if (!unowned) { | 609 if (!unowned) { |
673 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 610 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
674 EXPECT_EQ(GURL("http://buh.com"), form.action); | 611 EXPECT_EQ(GURL("http://buh.com"), form.action); |
675 } | 612 } |
676 | 613 |
677 const std::vector<FormFieldData>& fields = form.fields; | 614 const std::vector<FormFieldData>& fields = form.fields; |
678 ASSERT_EQ(3U, fields.size()); | 615 ASSERT_EQ(3U, fields.size()); |
679 | 616 |
680 FormFieldData expected; | 617 FormFieldData expected; |
(...skipping 19 matching lines...) Expand all Loading... |
700 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 637 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
701 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 638 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
702 form.fields[0].is_autofilled = true; | 639 form.fields[0].is_autofilled = true; |
703 form.fields[1].is_autofilled = true; | 640 form.fields[1].is_autofilled = true; |
704 form.fields[2].is_autofilled = true; | 641 form.fields[2].is_autofilled = true; |
705 FillForm(form, input_element); | 642 FillForm(form, input_element); |
706 | 643 |
707 // Find the newly-filled form that contains the input element. | 644 // Find the newly-filled form that contains the input element. |
708 FormData form2; | 645 FormData form2; |
709 FormFieldData field2; | 646 FormFieldData field2; |
710 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 647 EXPECT_TRUE( |
711 input_element, &form2, &field2, REQUIRE_NONE)); | 648 FindFormAndFieldForFormControlElement(input_element, &form2, &field2)); |
712 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 649 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
713 if (!unowned) { | 650 if (!unowned) { |
714 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 651 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
715 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 652 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
716 } | 653 } |
717 | 654 |
718 const std::vector<FormFieldData>& fields2 = form2.fields; | 655 const std::vector<FormFieldData>& fields2 = form2.fields; |
719 ASSERT_EQ(3U, fields2.size()); | 656 ASSERT_EQ(3U, fields2.size()); |
720 | 657 |
721 expected.form_control_type = "text"; | 658 expected.form_control_type = "text"; |
(...skipping 25 matching lines...) Expand all Loading... |
747 FormCache form_cache(*web_frame); | 684 FormCache form_cache(*web_frame); |
748 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 685 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
749 ASSERT_EQ(1U, forms.size()); | 686 ASSERT_EQ(1U, forms.size()); |
750 | 687 |
751 // Get the input element we want to find. | 688 // Get the input element we want to find. |
752 WebInputElement input_element = GetInputElementById("firstname"); | 689 WebInputElement input_element = GetInputElementById("firstname"); |
753 | 690 |
754 // Find the form that contains the input element. | 691 // Find the form that contains the input element. |
755 FormData form; | 692 FormData form; |
756 FormFieldData field; | 693 FormFieldData field; |
757 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 694 EXPECT_TRUE( |
758 input_element, &form, &field, REQUIRE_NONE)); | 695 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
759 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 696 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
760 if (!unowned) { | 697 if (!unowned) { |
761 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 698 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
762 EXPECT_EQ(GURL("http://buh.com"), form.action); | 699 EXPECT_EQ(GURL("http://buh.com"), form.action); |
763 } | 700 } |
764 | 701 |
765 const std::vector<FormFieldData>& fields = form.fields; | 702 const std::vector<FormFieldData>& fields = form.fields; |
766 ASSERT_EQ(3U, fields.size()); | 703 ASSERT_EQ(3U, fields.size()); |
767 | 704 |
768 FormFieldData expected; | 705 FormFieldData expected; |
(...skipping 11 matching lines...) Expand all Loading... |
780 | 717 |
781 // Fill the form. | 718 // Fill the form. |
782 form.fields[0].value = ASCIIToUTF16("Brother"); | 719 form.fields[0].value = ASCIIToUTF16("Brother"); |
783 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 720 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
784 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 721 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
785 FillForm(form, input_element); | 722 FillForm(form, input_element); |
786 | 723 |
787 // Find the newly-filled form that contains the input element. | 724 // Find the newly-filled form that contains the input element. |
788 FormData form2; | 725 FormData form2; |
789 FormFieldData field2; | 726 FormFieldData field2; |
790 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 727 EXPECT_TRUE( |
791 input_element, &form2, &field2, REQUIRE_NONE)); | 728 FindFormAndFieldForFormControlElement(input_element, &form2, &field2)); |
792 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 729 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
793 if (!unowned) { | 730 if (!unowned) { |
794 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 731 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
795 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 732 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
796 } | 733 } |
797 | 734 |
798 const std::vector<FormFieldData>& fields2 = form2.fields; | 735 const std::vector<FormFieldData>& fields2 = form2.fields; |
799 ASSERT_EQ(3U, fields2.size()); | 736 ASSERT_EQ(3U, fields2.size()); |
800 | 737 |
801 expected.name = ASCIIToUTF16("firstname"); | 738 expected.name = ASCIIToUTF16("firstname"); |
(...skipping 17 matching lines...) Expand all Loading... |
819 FormCache form_cache(*web_frame); | 756 FormCache form_cache(*web_frame); |
820 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 757 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
821 ASSERT_EQ(1U, forms.size()); | 758 ASSERT_EQ(1U, forms.size()); |
822 | 759 |
823 // Get the input element we want to find. | 760 // Get the input element we want to find. |
824 WebInputElement input_element = GetInputElementById("firstname"); | 761 WebInputElement input_element = GetInputElementById("firstname"); |
825 | 762 |
826 // Find the form that contains the input element. | 763 // Find the form that contains the input element. |
827 FormData form; | 764 FormData form; |
828 FormFieldData field; | 765 FormFieldData field; |
829 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 766 EXPECT_TRUE( |
830 input_element, &form, &field, REQUIRE_NONE)); | 767 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
831 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 768 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
832 if (!unowned) { | 769 if (!unowned) { |
833 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 770 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
834 EXPECT_EQ(GURL("http://buh.com"), form.action); | 771 EXPECT_EQ(GURL("http://buh.com"), form.action); |
835 } | 772 } |
836 | 773 |
837 const std::vector<FormFieldData>& fields = form.fields; | 774 const std::vector<FormFieldData>& fields = form.fields; |
838 ASSERT_EQ(3U, fields.size()); | 775 ASSERT_EQ(3U, fields.size()); |
839 | 776 |
840 FormFieldData expected; | 777 FormFieldData expected; |
(...skipping 11 matching lines...) Expand all Loading... |
852 | 789 |
853 // Fill the form. | 790 // Fill the form. |
854 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 791 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
855 form.fields[1].value = ASCIIToUTF16("Earp"); | 792 form.fields[1].value = ASCIIToUTF16("Earp"); |
856 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 793 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
857 FillForm(form, input_element); | 794 FillForm(form, input_element); |
858 | 795 |
859 // Find the newly-filled form that contains the input element. | 796 // Find the newly-filled form that contains the input element. |
860 FormData form2; | 797 FormData form2; |
861 FormFieldData field2; | 798 FormFieldData field2; |
862 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 799 EXPECT_TRUE( |
863 input_element, &form2, &field2, REQUIRE_NONE)); | 800 FindFormAndFieldForFormControlElement(input_element, &form2, &field2)); |
864 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 801 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
865 if (!unowned) { | 802 if (!unowned) { |
866 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 803 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
867 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 804 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
868 } | 805 } |
869 | 806 |
870 const std::vector<FormFieldData>& fields2 = form2.fields; | 807 const std::vector<FormFieldData>& fields2 = form2.fields; |
871 ASSERT_EQ(3U, fields2.size()); | 808 ASSERT_EQ(3U, fields2.size()); |
872 | 809 |
873 expected.form_control_type = "text"; | 810 expected.form_control_type = "text"; |
(...skipping 21 matching lines...) Expand all Loading... |
895 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 832 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
896 const size_t expected_size = unowned ? 1 : 2; | 833 const size_t expected_size = unowned ? 1 : 2; |
897 ASSERT_EQ(expected_size, forms.size()); | 834 ASSERT_EQ(expected_size, forms.size()); |
898 | 835 |
899 // Get the input element we want to find. | 836 // Get the input element we want to find. |
900 WebInputElement input_element = GetInputElementById("apple"); | 837 WebInputElement input_element = GetInputElementById("apple"); |
901 | 838 |
902 // Find the form that contains the input element. | 839 // Find the form that contains the input element. |
903 FormData form; | 840 FormData form; |
904 FormFieldData field; | 841 FormFieldData field; |
905 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 842 EXPECT_TRUE( |
906 input_element, &form, &field, REQUIRE_NONE)); | 843 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
907 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 844 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
908 if (!unowned) { | 845 if (!unowned) { |
909 EXPECT_TRUE(form.name.empty()); | 846 EXPECT_TRUE(form.name.empty()); |
910 EXPECT_EQ(GURL("http://abc.com"), form.action); | 847 EXPECT_EQ(GURL("http://abc.com"), form.action); |
911 } | 848 } |
912 | 849 |
913 const std::vector<FormFieldData>& fields = form.fields; | 850 const std::vector<FormFieldData>& fields = form.fields; |
914 const size_t unowned_offset = unowned ? 3 : 0; | 851 const size_t unowned_offset = unowned ? 3 : 0; |
915 ASSERT_EQ(unowned_offset + 3, fields.size()); | 852 ASSERT_EQ(unowned_offset + 3, fields.size()); |
916 | 853 |
(...skipping 18 matching lines...) Expand all Loading... |
935 form.fields[unowned_offset + 1].value = ASCIIToUTF16("Yellow"); | 872 form.fields[unowned_offset + 1].value = ASCIIToUTF16("Yellow"); |
936 form.fields[unowned_offset + 2].value = ASCIIToUTF16("Also Yellow"); | 873 form.fields[unowned_offset + 2].value = ASCIIToUTF16("Also Yellow"); |
937 form.fields[unowned_offset + 0].is_autofilled = true; | 874 form.fields[unowned_offset + 0].is_autofilled = true; |
938 form.fields[unowned_offset + 1].is_autofilled = true; | 875 form.fields[unowned_offset + 1].is_autofilled = true; |
939 form.fields[unowned_offset + 2].is_autofilled = true; | 876 form.fields[unowned_offset + 2].is_autofilled = true; |
940 FillForm(form, input_element); | 877 FillForm(form, input_element); |
941 | 878 |
942 // Find the newly-filled form that contains the input element. | 879 // Find the newly-filled form that contains the input element. |
943 FormData form2; | 880 FormData form2; |
944 FormFieldData field2; | 881 FormFieldData field2; |
945 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 882 EXPECT_TRUE( |
946 input_element, &form2, &field2, REQUIRE_NONE)); | 883 FindFormAndFieldForFormControlElement(input_element, &form2, &field2)); |
947 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 884 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
948 if (!unowned) { | 885 if (!unowned) { |
949 EXPECT_TRUE(form2.name.empty()); | 886 EXPECT_TRUE(form2.name.empty()); |
950 EXPECT_EQ(GURL("http://abc.com"), form2.action); | 887 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
951 } | 888 } |
952 | 889 |
953 const std::vector<FormFieldData>& fields2 = form2.fields; | 890 const std::vector<FormFieldData>& fields2 = form2.fields; |
954 ASSERT_EQ(unowned_offset + 3, fields2.size()); | 891 ASSERT_EQ(unowned_offset + 3, fields2.size()); |
955 | 892 |
956 expected.name = ASCIIToUTF16("apple"); | 893 expected.name = ASCIIToUTF16("apple"); |
(...skipping 23 matching lines...) Expand all Loading... |
980 | 917 |
981 // Get the input element we want to find. | 918 // Get the input element we want to find. |
982 WebInputElement input_element = GetInputElementById("firstname"); | 919 WebInputElement input_element = GetInputElementById("firstname"); |
983 | 920 |
984 // Simulate typing by modifying the field value. | 921 // Simulate typing by modifying the field value. |
985 input_element.setValue(ASCIIToUTF16("Wy")); | 922 input_element.setValue(ASCIIToUTF16("Wy")); |
986 | 923 |
987 // Find the form that contains the input element. | 924 // Find the form that contains the input element. |
988 FormData form; | 925 FormData form; |
989 FormFieldData field; | 926 FormFieldData field; |
990 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 927 EXPECT_TRUE( |
991 input_element, &form, &field, REQUIRE_NONE)); | 928 FindFormAndFieldForFormControlElement(input_element, &form, &field)); |
992 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 929 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
993 if (!unowned) { | 930 if (!unowned) { |
994 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 931 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
995 EXPECT_EQ(GURL("http://buh.com"), form.action); | 932 EXPECT_EQ(GURL("http://buh.com"), form.action); |
996 } | 933 } |
997 | 934 |
998 const std::vector<FormFieldData>& fields = form.fields; | 935 const std::vector<FormFieldData>& fields = form.fields; |
999 ASSERT_EQ(3U, fields.size()); | 936 ASSERT_EQ(3U, fields.size()); |
1000 | 937 |
1001 FormFieldData expected; | 938 FormFieldData expected; |
(...skipping 25 matching lines...) Expand all Loading... |
1027 PreviewForm(form, input_element); | 964 PreviewForm(form, input_element); |
1028 EXPECT_EQ(2, input_element.selectionStart()); | 965 EXPECT_EQ(2, input_element.selectionStart()); |
1029 EXPECT_EQ(5, input_element.selectionEnd()); | 966 EXPECT_EQ(5, input_element.selectionEnd()); |
1030 | 967 |
1031 // Fill the form. | 968 // Fill the form. |
1032 FillForm(form, input_element); | 969 FillForm(form, input_element); |
1033 | 970 |
1034 // Find the newly-filled form that contains the input element. | 971 // Find the newly-filled form that contains the input element. |
1035 FormData form2; | 972 FormData form2; |
1036 FormFieldData field2; | 973 FormFieldData field2; |
1037 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 974 EXPECT_TRUE( |
1038 input_element, &form2, &field2, REQUIRE_NONE)); | 975 FindFormAndFieldForFormControlElement(input_element, &form2, &field2)); |
1039 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 976 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
1040 if (!unowned) { | 977 if (!unowned) { |
1041 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 978 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1042 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 979 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1043 } | 980 } |
1044 | 981 |
1045 const std::vector<FormFieldData>& fields2 = form2.fields; | 982 const std::vector<FormFieldData>& fields2 = form2.fields; |
1046 ASSERT_EQ(3U, fields2.size()); | 983 ASSERT_EQ(3U, fields2.size()); |
1047 | 984 |
1048 expected.name = ASCIIToUTF16("firstname"); | 985 expected.name = ASCIIToUTF16("firstname"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 | 1027 |
1091 // Clear the form. | 1028 // Clear the form. |
1092 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 1029 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
1093 | 1030 |
1094 // Verify that the auto-filled attribute has been turned off. | 1031 // Verify that the auto-filled attribute has been turned off. |
1095 EXPECT_FALSE(firstname.isAutofilled()); | 1032 EXPECT_FALSE(firstname.isAutofilled()); |
1096 | 1033 |
1097 // Verify the form is cleared. | 1034 // Verify the form is cleared. |
1098 FormData form; | 1035 FormData form; |
1099 FormFieldData field; | 1036 FormFieldData field; |
1100 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 1037 EXPECT_TRUE( |
1101 firstname, &form, &field, REQUIRE_NONE)); | 1038 FindFormAndFieldForFormControlElement(firstname, &form, &field)); |
1102 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1039 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
1103 if (!unowned) { | 1040 if (!unowned) { |
1104 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1041 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1105 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1042 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1106 } | 1043 } |
1107 | 1044 |
1108 const std::vector<FormFieldData>& fields = form.fields; | 1045 const std::vector<FormFieldData>& fields = form.fields; |
1109 ASSERT_EQ(9U, fields.size()); | 1046 ASSERT_EQ(9U, fields.size()); |
1110 | 1047 |
1111 FormFieldData expected; | 1048 FormFieldData expected; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 | 1121 |
1185 // Clear the form. | 1122 // Clear the form. |
1186 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 1123 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
1187 | 1124 |
1188 // Verify that the auto-filled attribute has been turned off. | 1125 // Verify that the auto-filled attribute has been turned off. |
1189 EXPECT_FALSE(firstname.isAutofilled()); | 1126 EXPECT_FALSE(firstname.isAutofilled()); |
1190 | 1127 |
1191 // Verify the form is cleared. | 1128 // Verify the form is cleared. |
1192 FormData form; | 1129 FormData form; |
1193 FormFieldData field; | 1130 FormFieldData field; |
1194 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 1131 EXPECT_TRUE( |
1195 firstname, &form, &field, REQUIRE_NONE)); | 1132 FindFormAndFieldForFormControlElement(firstname, &form, &field)); |
1196 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1133 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
1197 if (!unowned) { | 1134 if (!unowned) { |
1198 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1135 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1199 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1136 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1200 } | 1137 } |
1201 | 1138 |
1202 const std::vector<FormFieldData>& fields = form.fields; | 1139 const std::vector<FormFieldData>& fields = form.fields; |
1203 ASSERT_EQ(3U, fields.size()); | 1140 ASSERT_EQ(3U, fields.size()); |
1204 | 1141 |
1205 FormFieldData expected; | 1142 FormFieldData expected; |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 WebVector<WebFormElement> forms; | 1906 WebVector<WebFormElement> forms; |
1970 frame->document().forms(forms); | 1907 frame->document().forms(forms); |
1971 ASSERT_EQ(1U, forms.size()); | 1908 ASSERT_EQ(1U, forms.size()); |
1972 | 1909 |
1973 WebInputElement input_element = GetInputElementById("firstname"); | 1910 WebInputElement input_element = GetInputElementById("firstname"); |
1974 | 1911 |
1975 FormData form; | 1912 FormData form; |
1976 FormFieldData field; | 1913 FormFieldData field; |
1977 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 1914 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
1978 input_element, | 1915 input_element, |
1979 REQUIRE_NONE, | |
1980 EXTRACT_VALUE, | 1916 EXTRACT_VALUE, |
1981 &form, | 1917 &form, |
1982 &field)); | 1918 &field)); |
1983 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1919 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1984 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 1920 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
1985 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 1921 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
1986 | 1922 |
1987 const std::vector<FormFieldData>& fields = form.fields; | 1923 const std::vector<FormFieldData>& fields = form.fields; |
1988 ASSERT_EQ(6U, fields.size()); | 1924 ASSERT_EQ(6U, fields.size()); |
1989 | 1925 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2047 WebVector<WebFormElement> forms; | 1983 WebVector<WebFormElement> forms; |
2048 frame->document().forms(forms); | 1984 frame->document().forms(forms); |
2049 ASSERT_EQ(1U, forms.size()); | 1985 ASSERT_EQ(1U, forms.size()); |
2050 | 1986 |
2051 WebInputElement input_element = GetInputElementById("firstname"); | 1987 WebInputElement input_element = GetInputElementById("firstname"); |
2052 | 1988 |
2053 FormData form; | 1989 FormData form; |
2054 FormFieldData field; | 1990 FormFieldData field; |
2055 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 1991 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
2056 input_element, | 1992 input_element, |
2057 REQUIRE_NONE, | |
2058 EXTRACT_VALUE, | 1993 EXTRACT_VALUE, |
2059 &form, | 1994 &form, |
2060 &field)); | 1995 &field)); |
2061 } | 1996 } |
2062 | 1997 |
2063 TEST_F(FormAutofillTest, ExtractForms) { | 1998 TEST_F(FormAutofillTest, ExtractForms) { |
2064 ExpectJohnSmithLabels( | 1999 ExpectJohnSmithLabels( |
2065 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2000 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
2066 " First name: <INPUT type='text' id='firstname' value='John'/>" | 2001 " First name: <INPUT type='text' id='firstname' value='John'/>" |
2067 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" | 2002 " Last name: <INPUT type='text' id='lastname' value='Smith'/>" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 WebFrame* web_frame = GetMainFrame(); | 2232 WebFrame* web_frame = GetMainFrame(); |
2298 ASSERT_NE(nullptr, web_frame); | 2233 ASSERT_NE(nullptr, web_frame); |
2299 | 2234 |
2300 FormCache form_cache(*web_frame); | 2235 FormCache form_cache(*web_frame); |
2301 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2236 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
2302 ASSERT_TRUE(forms.empty()); | 2237 ASSERT_TRUE(forms.empty()); |
2303 } | 2238 } |
2304 | 2239 |
2305 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { | 2240 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { |
2306 { | 2241 { |
2307 // Form is not auto-completable due to autocomplete=off. | 2242 // Form is still Autofill-able despite autocomplete=off. |
2308 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" | 2243 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" |
2309 " autocomplete=off>" | 2244 " autocomplete=off>" |
2310 " <INPUT type='text' id='firstname' value='John'/>" | 2245 " <INPUT type='text' id='firstname' value='John'/>" |
2311 " <INPUT type='text' id='lastname' value='Smith'/>" | 2246 " <INPUT type='text' id='lastname' value='Smith'/>" |
2312 " <INPUT type='text' id='email' value='john@example.com'/>" | 2247 " <INPUT type='text' id='email' value='john@example.com'/>" |
2313 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2248 " <INPUT type='submit' name='reply-send' value='Send'/>" |
2314 "</FORM>"); | 2249 "</FORM>"); |
2315 | 2250 |
2316 WebFrame* web_frame = GetMainFrame(); | 2251 WebFrame* web_frame = GetMainFrame(); |
2317 ASSERT_NE(nullptr, web_frame); | 2252 ASSERT_NE(nullptr, web_frame); |
2318 | 2253 |
2319 WebVector<WebFormElement> web_forms; | 2254 WebVector<WebFormElement> web_forms; |
2320 web_frame->document().forms(web_forms); | 2255 web_frame->document().forms(web_forms); |
2321 ASSERT_EQ(1U, web_forms.size()); | 2256 ASSERT_EQ(1U, web_forms.size()); |
2322 WebFormElement web_form = web_forms[0]; | 2257 WebFormElement web_form = web_forms[0]; |
2323 | 2258 |
2324 FormData form; | 2259 FormData form; |
2325 EXPECT_TRUE(WebFormElementToFormData( | 2260 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
2326 web_form, WebFormControlElement(), REQUIRE_NONE, EXTRACT_NONE, &form, | 2261 EXTRACT_NONE, &form, nullptr)); |
2327 nullptr)); | |
2328 EXPECT_FALSE(WebFormElementToFormData( | |
2329 web_form, WebFormControlElement(), REQUIRE_AUTOCOMPLETE, EXTRACT_NONE, | |
2330 &form, nullptr)); | |
2331 } | |
2332 | |
2333 { | |
2334 // The firstname element is not auto-completable due to autocomplete=off. | |
2335 LoadHTML("<FORM name='TestForm' action='http://abc.com' " | |
2336 " method='post'>" | |
2337 " <INPUT type='text' id='firstname' value='John'" | |
2338 " autocomplete=off>" | |
2339 " <INPUT type='text' id='middlename' value='Jack'/>" | |
2340 " <INPUT type='text' id='lastname' value='Smith'/>" | |
2341 " <INPUT type='text' id='email' value='john@example.com'/>" | |
2342 " <INPUT type='submit' name='reply' value='Send'/>" | |
2343 "</FORM>"); | |
2344 | |
2345 WebFrame* web_frame = GetMainFrame(); | |
2346 ASSERT_NE(nullptr, web_frame); | |
2347 | |
2348 WebVector<WebFormElement> web_forms; | |
2349 web_frame->document().forms(web_forms); | |
2350 ASSERT_EQ(1U, web_forms.size()); | |
2351 WebFormElement web_form = web_forms[0]; | |
2352 | |
2353 FormData form; | |
2354 EXPECT_TRUE(WebFormElementToFormData( | |
2355 web_form, WebFormControlElement(), REQUIRE_AUTOCOMPLETE, EXTRACT_VALUE, | |
2356 &form, nullptr)); | |
2357 | |
2358 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | |
2359 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | |
2360 EXPECT_EQ(GURL("http://abc.com"), form.action); | |
2361 | |
2362 const std::vector<FormFieldData>& fields = form.fields; | |
2363 ASSERT_EQ(3U, fields.size()); | |
2364 | |
2365 FormFieldData expected; | |
2366 expected.form_control_type = "text"; | |
2367 expected.max_length = WebInputElement::defaultMaxLength(); | |
2368 | |
2369 expected.name = ASCIIToUTF16("middlename"); | |
2370 expected.value = ASCIIToUTF16("Jack"); | |
2371 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | |
2372 | |
2373 expected.name = ASCIIToUTF16("lastname"); | |
2374 expected.value = ASCIIToUTF16("Smith"); | |
2375 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | |
2376 | |
2377 expected.name = ASCIIToUTF16("email"); | |
2378 expected.value = ASCIIToUTF16("john@example.com"); | |
2379 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | |
2380 } | 2262 } |
2381 } | 2263 } |
2382 | 2264 |
2383 TEST_F(FormAutofillTest, FindFormForInputElement) { | 2265 TEST_F(FormAutofillTest, FindFormForInputElement) { |
2384 TestFindFormForInputElement( | 2266 TestFindFormForInputElement( |
2385 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 2267 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
2386 " <INPUT type='text' id='firstname' value='John'/>" | 2268 " <INPUT type='text' id='firstname' value='John'/>" |
2387 " <INPUT type='text' id='lastname' value='Smith'/>" | 2269 " <INPUT type='text' id='lastname' value='Smith'/>" |
2388 " <INPUT type='text' id='email' value='john@example.com'" | 2270 " <INPUT type='text' id='email' value='john@example.com'" |
2389 "autocomplete='off' />" | 2271 "autocomplete='off' />" |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3585 WebFrame* frame = GetMainFrame(); | 3467 WebFrame* frame = GetMainFrame(); |
3586 ASSERT_NE(nullptr, frame); | 3468 ASSERT_NE(nullptr, frame); |
3587 | 3469 |
3588 WebVector<WebFormElement> forms; | 3470 WebVector<WebFormElement> forms; |
3589 frame->document().forms(forms); | 3471 frame->document().forms(forms); |
3590 ASSERT_EQ(1U, forms.size()); | 3472 ASSERT_EQ(1U, forms.size()); |
3591 | 3473 |
3592 FormData form; | 3474 FormData form; |
3593 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3475 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
3594 WebFormControlElement(), | 3476 WebFormControlElement(), |
3595 REQUIRE_NONE, | |
3596 EXTRACT_VALUE, | 3477 EXTRACT_VALUE, |
3597 &form, | 3478 &form, |
3598 nullptr)); | 3479 nullptr)); |
3599 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3480 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
3600 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3481 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
3601 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3482 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
3602 | 3483 |
3603 const std::vector<FormFieldData>& fields = form.fields; | 3484 const std::vector<FormFieldData>& fields = form.fields; |
3604 ASSERT_EQ(4U, fields.size()); | 3485 ASSERT_EQ(4U, fields.size()); |
3605 | 3486 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3644 WebFrame* frame = GetMainFrame(); | 3525 WebFrame* frame = GetMainFrame(); |
3645 ASSERT_NE(nullptr, frame); | 3526 ASSERT_NE(nullptr, frame); |
3646 | 3527 |
3647 WebVector<WebFormElement> forms; | 3528 WebVector<WebFormElement> forms; |
3648 frame->document().forms(forms); | 3529 frame->document().forms(forms); |
3649 ASSERT_EQ(1U, forms.size()); | 3530 ASSERT_EQ(1U, forms.size()); |
3650 | 3531 |
3651 FormData form; | 3532 FormData form; |
3652 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3533 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
3653 WebFormControlElement(), | 3534 WebFormControlElement(), |
3654 REQUIRE_NONE, | |
3655 EXTRACT_VALUE, | 3535 EXTRACT_VALUE, |
3656 &form, | 3536 &form, |
3657 nullptr)); | 3537 nullptr)); |
3658 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3538 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
3659 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3539 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
3660 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3540 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
3661 | 3541 |
3662 const std::vector<FormFieldData>& fields = form.fields; | 3542 const std::vector<FormFieldData>& fields = form.fields; |
3663 ASSERT_EQ(6U, fields.size()); | 3543 ASSERT_EQ(6U, fields.size()); |
3664 | 3544 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3957 select_element.setValue(WebString::fromUTF8("AL")); | 3837 select_element.setValue(WebString::fromUTF8("AL")); |
3958 | 3838 |
3959 WebVector<WebFormElement> forms; | 3839 WebVector<WebFormElement> forms; |
3960 frame->document().forms(forms); | 3840 frame->document().forms(forms); |
3961 ASSERT_EQ(1U, forms.size()); | 3841 ASSERT_EQ(1U, forms.size()); |
3962 | 3842 |
3963 FormData form; | 3843 FormData form; |
3964 | 3844 |
3965 // Extract the country select-one value as text. | 3845 // Extract the country select-one value as text. |
3966 EXPECT_TRUE(WebFormElementToFormData( | 3846 EXPECT_TRUE(WebFormElementToFormData( |
3967 forms[0], WebFormControlElement(), REQUIRE_NONE, | 3847 forms[0], WebFormControlElement(), |
3968 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), | 3848 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTION_TEXT), &form, |
3969 &form, nullptr)); | 3849 nullptr)); |
3970 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3850 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
3971 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3851 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
3972 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3852 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
3973 | 3853 |
3974 const std::vector<FormFieldData>& fields = form.fields; | 3854 const std::vector<FormFieldData>& fields = form.fields; |
3975 ASSERT_EQ(3U, fields.size()); | 3855 ASSERT_EQ(3U, fields.size()); |
3976 | 3856 |
3977 FormFieldData expected; | 3857 FormFieldData expected; |
3978 | 3858 |
3979 expected.name = ASCIIToUTF16("firstname"); | 3859 expected.name = ASCIIToUTF16("firstname"); |
(...skipping 11 matching lines...) Expand all Loading... |
3991 expected.name = ASCIIToUTF16("country"); | 3871 expected.name = ASCIIToUTF16("country"); |
3992 expected.value = ASCIIToUTF16("Albania"); | 3872 expected.value = ASCIIToUTF16("Albania"); |
3993 expected.form_control_type = "select-one"; | 3873 expected.form_control_type = "select-one"; |
3994 expected.max_length = 0; | 3874 expected.max_length = 0; |
3995 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3875 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3996 | 3876 |
3997 form.fields.clear(); | 3877 form.fields.clear(); |
3998 // Extract the country select-one value as value. | 3878 // Extract the country select-one value as value. |
3999 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 3879 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
4000 WebFormControlElement(), | 3880 WebFormControlElement(), |
4001 REQUIRE_NONE, | |
4002 EXTRACT_VALUE, | 3881 EXTRACT_VALUE, |
4003 &form, | 3882 &form, |
4004 nullptr)); | 3883 nullptr)); |
4005 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3884 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
4006 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 3885 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
4007 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 3886 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
4008 | 3887 |
4009 ASSERT_EQ(3U, fields.size()); | 3888 ASSERT_EQ(3U, fields.size()); |
4010 | 3889 |
4011 expected.name = ASCIIToUTF16("firstname"); | 3890 expected.name = ASCIIToUTF16("firstname"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4052 WebFrame* frame = GetMainFrame(); | 3931 WebFrame* frame = GetMainFrame(); |
4053 ASSERT_NE(nullptr, frame); | 3932 ASSERT_NE(nullptr, frame); |
4054 | 3933 |
4055 control_elements = GetUnownedAutofillableFormFieldElements( | 3934 control_elements = GetUnownedAutofillableFormFieldElements( |
4056 frame->document().all(), &fieldsets); | 3935 frame->document().all(), &fieldsets); |
4057 ASSERT_EQ(3U, control_elements.size()); | 3936 ASSERT_EQ(3U, control_elements.size()); |
4058 ASSERT_EQ(2U, fieldsets.size()); | 3937 ASSERT_EQ(2U, fieldsets.size()); |
4059 | 3938 |
4060 FormData form; | 3939 FormData form; |
4061 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( | 3940 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( |
4062 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, | 3941 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form, |
4063 extract_mask, &form, nullptr)); | 3942 nullptr)); |
4064 | 3943 |
4065 EXPECT_TRUE(form.name.empty()); | 3944 EXPECT_TRUE(form.name.empty()); |
4066 EXPECT_EQ(dummy_origin, form.origin); | 3945 EXPECT_EQ(dummy_origin, form.origin); |
4067 EXPECT_FALSE(form.action.is_valid()); | 3946 EXPECT_FALSE(form.action.is_valid()); |
4068 | 3947 |
4069 const std::vector<FormFieldData>& fields = form.fields; | 3948 const std::vector<FormFieldData>& fields = form.fields; |
4070 ASSERT_EQ(3U, fields.size()); | 3949 ASSERT_EQ(3U, fields.size()); |
4071 | 3950 |
4072 FormFieldData expected; | 3951 FormFieldData expected; |
4073 expected.form_control_type = "text"; | 3952 expected.form_control_type = "text"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4112 WebFrame* frame = GetMainFrame(); | 3991 WebFrame* frame = GetMainFrame(); |
4113 ASSERT_NE(nullptr, frame); | 3992 ASSERT_NE(nullptr, frame); |
4114 | 3993 |
4115 control_elements = GetUnownedAutofillableFormFieldElements( | 3994 control_elements = GetUnownedAutofillableFormFieldElements( |
4116 frame->document().all(), &fieldsets); | 3995 frame->document().all(), &fieldsets); |
4117 ASSERT_EQ(3U, control_elements.size()); | 3996 ASSERT_EQ(3U, control_elements.size()); |
4118 ASSERT_EQ(1U, fieldsets.size()); | 3997 ASSERT_EQ(1U, fieldsets.size()); |
4119 | 3998 |
4120 FormData form; | 3999 FormData form; |
4121 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( | 4000 EXPECT_TRUE(UnownedFormElementsAndFieldSetsToFormData( |
4122 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, | 4001 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form, |
4123 extract_mask, &form, nullptr)); | 4002 nullptr)); |
4124 | 4003 |
4125 EXPECT_TRUE(form.name.empty()); | 4004 EXPECT_TRUE(form.name.empty()); |
4126 EXPECT_EQ(dummy_origin, form.origin); | 4005 EXPECT_EQ(dummy_origin, form.origin); |
4127 EXPECT_FALSE(form.action.is_valid()); | 4006 EXPECT_FALSE(form.action.is_valid()); |
4128 | 4007 |
4129 const std::vector<FormFieldData>& fields = form.fields; | 4008 const std::vector<FormFieldData>& fields = form.fields; |
4130 ASSERT_EQ(3U, fields.size()); | 4009 ASSERT_EQ(3U, fields.size()); |
4131 | 4010 |
4132 FormFieldData expected; | 4011 FormFieldData expected; |
4133 expected.form_control_type = "text"; | 4012 expected.form_control_type = "text"; |
(...skipping 28 matching lines...) Expand all Loading... |
4162 WebFrame* frame = GetMainFrame(); | 4041 WebFrame* frame = GetMainFrame(); |
4163 ASSERT_NE(nullptr, frame); | 4042 ASSERT_NE(nullptr, frame); |
4164 | 4043 |
4165 control_elements = GetUnownedAutofillableFormFieldElements( | 4044 control_elements = GetUnownedAutofillableFormFieldElements( |
4166 frame->document().all(), &fieldsets); | 4045 frame->document().all(), &fieldsets); |
4167 ASSERT_TRUE(control_elements.empty()); | 4046 ASSERT_TRUE(control_elements.empty()); |
4168 ASSERT_TRUE(fieldsets.empty()); | 4047 ASSERT_TRUE(fieldsets.empty()); |
4169 | 4048 |
4170 FormData form; | 4049 FormData form; |
4171 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( | 4050 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( |
4172 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, | 4051 fieldsets, control_elements, nullptr, dummy_origin, extract_mask, &form, |
4173 extract_mask, &form, nullptr)); | 4052 nullptr)); |
4174 } | 4053 } |
4175 | 4054 |
4176 } // namespace autofill | 4055 } // namespace autofill |
OLD | NEW |