| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 ASSERT_EQ(labels.size(), names.size()); | 189 ASSERT_EQ(labels.size(), names.size()); |
| 190 ASSERT_EQ(labels.size(), values.size()); | 190 ASSERT_EQ(labels.size(), values.size()); |
| 191 ASSERT_EQ(labels.size(), control_types.size()); | 191 ASSERT_EQ(labels.size(), control_types.size()); |
| 192 | 192 |
| 193 LoadHTML(html); | 193 LoadHTML(html); |
| 194 | 194 |
| 195 WebFrame* web_frame = GetMainFrame(); | 195 WebFrame* web_frame = GetMainFrame(); |
| 196 ASSERT_NE(nullptr, web_frame); | 196 ASSERT_NE(nullptr, web_frame); |
| 197 | 197 |
| 198 FormCache form_cache(*web_frame); | 198 FormCache form_cache(*web_frame); |
| 199 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 199 size_t unowned_form_index; |
| 200 std::vector<FormData> forms = |
| 201 form_cache.ExtractNewForms(&unowned_form_index); |
| 200 ASSERT_EQ(1U, forms.size()); | 202 ASSERT_EQ(1U, forms.size()); |
| 203 EXPECT_EQ(1U, unowned_form_index); |
| 201 | 204 |
| 202 const FormData& form = forms[0]; | 205 const FormData& form = forms[0]; |
| 203 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 206 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 204 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 207 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 205 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 208 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 206 | 209 |
| 207 const std::vector<FormFieldData>& fields = form.fields; | 210 const std::vector<FormFieldData>& fields = form.fields; |
| 208 ASSERT_EQ(labels.size(), fields.size()); | 211 ASSERT_EQ(labels.size(), fields.size()); |
| 209 for (size_t i = 0; i < labels.size(); ++i) { | 212 for (size_t i = 0; i < labels.size(); ++i) { |
| 210 int max_length = control_types[i] == "text" ? | 213 int max_length = control_types[i] == "text" ? |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 const AutofillFieldCase* field_cases, | 252 const AutofillFieldCase* field_cases, |
| 250 size_t number_of_field_cases, | 253 size_t number_of_field_cases, |
| 251 FillFormFunction fill_form_function, | 254 FillFormFunction fill_form_function, |
| 252 GetValueFunction get_value_function) { | 255 GetValueFunction get_value_function) { |
| 253 LoadHTML(html); | 256 LoadHTML(html); |
| 254 | 257 |
| 255 WebFrame* web_frame = GetMainFrame(); | 258 WebFrame* web_frame = GetMainFrame(); |
| 256 ASSERT_NE(nullptr, web_frame); | 259 ASSERT_NE(nullptr, web_frame); |
| 257 | 260 |
| 258 FormCache form_cache(*web_frame); | 261 FormCache form_cache(*web_frame); |
| 259 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 262 size_t unowned_form_index; |
| 263 std::vector<FormData> forms = |
| 264 form_cache.ExtractNewForms(&unowned_form_index); |
| 260 ASSERT_EQ(1U, forms.size()); | 265 ASSERT_EQ(1U, forms.size()); |
| 266 const size_t expected_index = unowned ? 0 : 1; |
| 267 EXPECT_EQ(expected_index, unowned_form_index); |
| 261 | 268 |
| 262 // Get the input element we want to find. | 269 // Get the input element we want to find. |
| 263 WebInputElement input_element = GetInputElementById("firstname"); | 270 WebInputElement input_element = GetInputElementById("firstname"); |
| 264 | 271 |
| 265 // Find the form that contains the input element. | 272 // Find the form that contains the input element. |
| 266 FormData form_data; | 273 FormData form_data; |
| 267 FormFieldData field; | 274 FormFieldData field; |
| 268 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 275 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 269 input_element, &form_data, &field, REQUIRE_NONE)); | 276 input_element, &form_data, &field, REQUIRE_NONE)); |
| 270 if (!unowned) { | 277 if (!unowned) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 EXPECT_EQ(0, firstname.selectionStart()); | 487 EXPECT_EQ(0, firstname.selectionStart()); |
| 481 EXPECT_EQ(19, firstname.selectionEnd()); | 488 EXPECT_EQ(19, firstname.selectionEnd()); |
| 482 } | 489 } |
| 483 | 490 |
| 484 void TestFindFormForInputElement(const char* html, bool unowned) { | 491 void TestFindFormForInputElement(const char* html, bool unowned) { |
| 485 LoadHTML(html); | 492 LoadHTML(html); |
| 486 WebFrame* web_frame = GetMainFrame(); | 493 WebFrame* web_frame = GetMainFrame(); |
| 487 ASSERT_NE(nullptr, web_frame); | 494 ASSERT_NE(nullptr, web_frame); |
| 488 | 495 |
| 489 FormCache form_cache(*web_frame); | 496 FormCache form_cache(*web_frame); |
| 490 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 497 size_t unowned_form_index; |
| 498 std::vector<FormData> forms = |
| 499 form_cache.ExtractNewForms(&unowned_form_index); |
| 491 ASSERT_EQ(1U, forms.size()); | 500 ASSERT_EQ(1U, forms.size()); |
| 501 const size_t expected_index = unowned ? 0 : 1; |
| 502 EXPECT_EQ(expected_index, unowned_form_index); |
| 492 | 503 |
| 493 // Get the input element we want to find. | 504 // Get the input element we want to find. |
| 494 WebInputElement input_element = GetInputElementById("firstname"); | 505 WebInputElement input_element = GetInputElementById("firstname"); |
| 495 | 506 |
| 496 // Find the form and verify it's the correct form. | 507 // Find the form and verify it's the correct form. |
| 497 FormData form; | 508 FormData form; |
| 498 FormFieldData field; | 509 FormFieldData field; |
| 499 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 510 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 500 input_element, &form, &field, REQUIRE_NONE)); | 511 input_element, &form, &field, REQUIRE_NONE)); |
| 501 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 512 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 expected.value = ASCIIToUTF16("1.800.555.1234"); | 571 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 561 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 572 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 562 } | 573 } |
| 563 | 574 |
| 564 void TestFindFormForTextAreaElement(const char* html, bool unowned) { | 575 void TestFindFormForTextAreaElement(const char* html, bool unowned) { |
| 565 LoadHTML(html); | 576 LoadHTML(html); |
| 566 WebFrame* web_frame = GetMainFrame(); | 577 WebFrame* web_frame = GetMainFrame(); |
| 567 ASSERT_NE(nullptr, web_frame); | 578 ASSERT_NE(nullptr, web_frame); |
| 568 | 579 |
| 569 FormCache form_cache(*web_frame); | 580 FormCache form_cache(*web_frame); |
| 570 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 581 size_t unowned_form_index; |
| 582 std::vector<FormData> forms = |
| 583 form_cache.ExtractNewForms(&unowned_form_index); |
| 571 ASSERT_EQ(1U, forms.size()); | 584 ASSERT_EQ(1U, forms.size()); |
| 585 const size_t expected_index = unowned ? 0 : 1; |
| 586 EXPECT_EQ(expected_index, unowned_form_index); |
| 572 | 587 |
| 573 // Get the textarea element we want to find. | 588 // Get the textarea element we want to find. |
| 574 WebElement element = web_frame->document().getElementById("street-address"); | 589 WebElement element = web_frame->document().getElementById("street-address"); |
| 575 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); | 590 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); |
| 576 | 591 |
| 577 // Find the form and verify it's the correct form. | 592 // Find the form and verify it's the correct form. |
| 578 FormData form; | 593 FormData form; |
| 579 FormFieldData field; | 594 FormFieldData field; |
| 580 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 595 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 581 textarea_element, &form, &field, REQUIRE_NONE)); | 596 textarea_element, &form, &field, REQUIRE_NONE)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 665 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 651 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 666 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 652 } | 667 } |
| 653 | 668 |
| 654 void TestFillFormMaxLength(const char* html, bool unowned) { | 669 void TestFillFormMaxLength(const char* html, bool unowned) { |
| 655 LoadHTML(html); | 670 LoadHTML(html); |
| 656 WebFrame* web_frame = GetMainFrame(); | 671 WebFrame* web_frame = GetMainFrame(); |
| 657 ASSERT_NE(nullptr, web_frame); | 672 ASSERT_NE(nullptr, web_frame); |
| 658 | 673 |
| 659 FormCache form_cache(*web_frame); | 674 FormCache form_cache(*web_frame); |
| 660 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 675 size_t unowned_form_index; |
| 676 std::vector<FormData> forms = |
| 677 form_cache.ExtractNewForms(&unowned_form_index); |
| 661 ASSERT_EQ(1U, forms.size()); | 678 ASSERT_EQ(1U, forms.size()); |
| 679 const size_t expected_index = unowned ? 0 : 1; |
| 680 EXPECT_EQ(expected_index, unowned_form_index); |
| 662 | 681 |
| 663 // Get the input element we want to find. | 682 // Get the input element we want to find. |
| 664 WebInputElement input_element = GetInputElementById("firstname"); | 683 WebInputElement input_element = GetInputElementById("firstname"); |
| 665 | 684 |
| 666 // Find the form that contains the input element. | 685 // Find the form that contains the input element. |
| 667 FormData form; | 686 FormData form; |
| 668 FormFieldData field; | 687 FormFieldData field; |
| 669 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 688 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 670 input_element, &form, &field, REQUIRE_NONE)); | 689 input_element, &form, &field, REQUIRE_NONE)); |
| 671 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 690 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 expected.is_autofilled = true; | 757 expected.is_autofilled = true; |
| 739 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 758 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 740 } | 759 } |
| 741 | 760 |
| 742 void TestFillFormNegativeMaxLength(const char* html, bool unowned) { | 761 void TestFillFormNegativeMaxLength(const char* html, bool unowned) { |
| 743 LoadHTML(html); | 762 LoadHTML(html); |
| 744 WebFrame* web_frame = GetMainFrame(); | 763 WebFrame* web_frame = GetMainFrame(); |
| 745 ASSERT_NE(nullptr, web_frame); | 764 ASSERT_NE(nullptr, web_frame); |
| 746 | 765 |
| 747 FormCache form_cache(*web_frame); | 766 FormCache form_cache(*web_frame); |
| 748 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 767 size_t unowned_form_index; |
| 768 std::vector<FormData> forms = |
| 769 form_cache.ExtractNewForms(&unowned_form_index); |
| 749 ASSERT_EQ(1U, forms.size()); | 770 ASSERT_EQ(1U, forms.size()); |
| 771 const size_t expected_index = unowned ? 0 : 1; |
| 772 EXPECT_EQ(expected_index, unowned_form_index); |
| 750 | 773 |
| 751 // Get the input element we want to find. | 774 // Get the input element we want to find. |
| 752 WebInputElement input_element = GetInputElementById("firstname"); | 775 WebInputElement input_element = GetInputElementById("firstname"); |
| 753 | 776 |
| 754 // Find the form that contains the input element. | 777 // Find the form that contains the input element. |
| 755 FormData form; | 778 FormData form; |
| 756 FormFieldData field; | 779 FormFieldData field; |
| 757 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 780 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 758 input_element, &form, &field, REQUIRE_NONE)); | 781 input_element, &form, &field, REQUIRE_NONE)); |
| 759 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 782 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 expected.value = ASCIIToUTF16("brotherj@example.com"); | 833 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 811 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 834 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 812 } | 835 } |
| 813 | 836 |
| 814 void TestFillFormEmptyName(const char* html, bool unowned) { | 837 void TestFillFormEmptyName(const char* html, bool unowned) { |
| 815 LoadHTML(html); | 838 LoadHTML(html); |
| 816 WebFrame* web_frame = GetMainFrame(); | 839 WebFrame* web_frame = GetMainFrame(); |
| 817 ASSERT_NE(nullptr, web_frame); | 840 ASSERT_NE(nullptr, web_frame); |
| 818 | 841 |
| 819 FormCache form_cache(*web_frame); | 842 FormCache form_cache(*web_frame); |
| 820 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 843 size_t unowned_form_index; |
| 844 std::vector<FormData> forms = |
| 845 form_cache.ExtractNewForms(&unowned_form_index); |
| 821 ASSERT_EQ(1U, forms.size()); | 846 ASSERT_EQ(1U, forms.size()); |
| 847 const size_t expected_index = unowned ? 0 : 1; |
| 848 EXPECT_EQ(expected_index, unowned_form_index); |
| 822 | 849 |
| 823 // Get the input element we want to find. | 850 // Get the input element we want to find. |
| 824 WebInputElement input_element = GetInputElementById("firstname"); | 851 WebInputElement input_element = GetInputElementById("firstname"); |
| 825 | 852 |
| 826 // Find the form that contains the input element. | 853 // Find the form that contains the input element. |
| 827 FormData form; | 854 FormData form; |
| 828 FormFieldData field; | 855 FormFieldData field; |
| 829 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 856 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 830 input_element, &form, &field, REQUIRE_NONE)); | 857 input_element, &form, &field, REQUIRE_NONE)); |
| 831 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 858 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 expected.value = ASCIIToUTF16("wyatt@example.com"); | 912 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 886 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 913 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 887 } | 914 } |
| 888 | 915 |
| 889 void TestFillFormEmptyFormNames(const char* html, bool unowned) { | 916 void TestFillFormEmptyFormNames(const char* html, bool unowned) { |
| 890 LoadHTML(html); | 917 LoadHTML(html); |
| 891 WebFrame* web_frame = GetMainFrame(); | 918 WebFrame* web_frame = GetMainFrame(); |
| 892 ASSERT_NE(nullptr, web_frame); | 919 ASSERT_NE(nullptr, web_frame); |
| 893 | 920 |
| 894 FormCache form_cache(*web_frame); | 921 FormCache form_cache(*web_frame); |
| 895 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 922 size_t unowned_form_index; |
| 923 std::vector<FormData> forms = |
| 924 form_cache.ExtractNewForms(&unowned_form_index); |
| 896 const size_t expected_size = unowned ? 1 : 2; | 925 const size_t expected_size = unowned ? 1 : 2; |
| 897 ASSERT_EQ(expected_size, forms.size()); | 926 ASSERT_EQ(expected_size, forms.size()); |
| 927 const size_t expected_index = unowned ? 0 : 2; |
| 928 EXPECT_EQ(expected_index, unowned_form_index); |
| 898 | 929 |
| 899 // Get the input element we want to find. | 930 // Get the input element we want to find. |
| 900 WebInputElement input_element = GetInputElementById("apple"); | 931 WebInputElement input_element = GetInputElementById("apple"); |
| 901 | 932 |
| 902 // Find the form that contains the input element. | 933 // Find the form that contains the input element. |
| 903 FormData form; | 934 FormData form; |
| 904 FormFieldData field; | 935 FormFieldData field; |
| 905 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 936 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
| 906 input_element, &form, &field, REQUIRE_NONE)); | 937 input_element, &form, &field, REQUIRE_NONE)); |
| 907 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 938 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 expected.is_autofilled = true; | 999 expected.is_autofilled = true; |
| 969 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); | 1000 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); |
| 970 } | 1001 } |
| 971 | 1002 |
| 972 void TestFillFormNonEmptyField(const char* html, bool unowned) { | 1003 void TestFillFormNonEmptyField(const char* html, bool unowned) { |
| 973 LoadHTML(html); | 1004 LoadHTML(html); |
| 974 WebFrame* web_frame = GetMainFrame(); | 1005 WebFrame* web_frame = GetMainFrame(); |
| 975 ASSERT_NE(nullptr, web_frame); | 1006 ASSERT_NE(nullptr, web_frame); |
| 976 | 1007 |
| 977 FormCache form_cache(*web_frame); | 1008 FormCache form_cache(*web_frame); |
| 978 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1009 size_t unowned_form_index; |
| 1010 std::vector<FormData> forms = |
| 1011 form_cache.ExtractNewForms(&unowned_form_index); |
| 979 ASSERT_EQ(1U, forms.size()); | 1012 ASSERT_EQ(1U, forms.size()); |
| 1013 const size_t expected_index = unowned ? 0 : 1; |
| 1014 EXPECT_EQ(expected_index, unowned_form_index); |
| 980 | 1015 |
| 981 // Get the input element we want to find. | 1016 // Get the input element we want to find. |
| 982 WebInputElement input_element = GetInputElementById("firstname"); | 1017 WebInputElement input_element = GetInputElementById("firstname"); |
| 983 | 1018 |
| 984 // Simulate typing by modifying the field value. | 1019 // Simulate typing by modifying the field value. |
| 985 input_element.setValue(ASCIIToUTF16("Wy")); | 1020 input_element.setValue(ASCIIToUTF16("Wy")); |
| 986 | 1021 |
| 987 // Find the form that contains the input element. | 1022 // Find the form that contains the input element. |
| 988 FormData form; | 1023 FormData form; |
| 989 FormFieldData field; | 1024 FormFieldData field; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 EXPECT_EQ(5, input_element.selectionStart()); | 1099 EXPECT_EQ(5, input_element.selectionStart()); |
| 1065 EXPECT_EQ(5, input_element.selectionEnd()); | 1100 EXPECT_EQ(5, input_element.selectionEnd()); |
| 1066 } | 1101 } |
| 1067 | 1102 |
| 1068 void TestClearFormWithNode(const char* html, bool unowned) { | 1103 void TestClearFormWithNode(const char* html, bool unowned) { |
| 1069 LoadHTML(html); | 1104 LoadHTML(html); |
| 1070 WebFrame* web_frame = GetMainFrame(); | 1105 WebFrame* web_frame = GetMainFrame(); |
| 1071 ASSERT_NE(nullptr, web_frame); | 1106 ASSERT_NE(nullptr, web_frame); |
| 1072 | 1107 |
| 1073 FormCache form_cache(*web_frame); | 1108 FormCache form_cache(*web_frame); |
| 1074 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1109 size_t unowned_form_index; |
| 1110 std::vector<FormData> forms = |
| 1111 form_cache.ExtractNewForms(&unowned_form_index); |
| 1075 ASSERT_EQ(1U, forms.size()); | 1112 ASSERT_EQ(1U, forms.size()); |
| 1113 const size_t expected_index = unowned ? 0 : 1; |
| 1114 EXPECT_EQ(expected_index, unowned_form_index); |
| 1076 | 1115 |
| 1077 // Set the auto-filled attribute. | 1116 // Set the auto-filled attribute. |
| 1078 WebInputElement firstname = GetInputElementById("firstname"); | 1117 WebInputElement firstname = GetInputElementById("firstname"); |
| 1079 firstname.setAutofilled(true); | 1118 firstname.setAutofilled(true); |
| 1080 WebInputElement lastname = GetInputElementById("lastname"); | 1119 WebInputElement lastname = GetInputElementById("lastname"); |
| 1081 lastname.setAutofilled(true); | 1120 lastname.setAutofilled(true); |
| 1082 WebInputElement month = GetInputElementById("month"); | 1121 WebInputElement month = GetInputElementById("month"); |
| 1083 month.setAutofilled(true); | 1122 month.setAutofilled(true); |
| 1084 WebInputElement textarea = GetInputElementById("textarea"); | 1123 WebInputElement textarea = GetInputElementById("textarea"); |
| 1085 textarea.setAutofilled(true); | 1124 textarea.setAutofilled(true); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 EXPECT_EQ(0, firstname.selectionEnd()); | 1199 EXPECT_EQ(0, firstname.selectionEnd()); |
| 1161 } | 1200 } |
| 1162 | 1201 |
| 1163 void TestClearFormWithNodeContainingSelectOne(const char* html, | 1202 void TestClearFormWithNodeContainingSelectOne(const char* html, |
| 1164 bool unowned) { | 1203 bool unowned) { |
| 1165 LoadHTML(html); | 1204 LoadHTML(html); |
| 1166 WebFrame* web_frame = GetMainFrame(); | 1205 WebFrame* web_frame = GetMainFrame(); |
| 1167 ASSERT_NE(nullptr, web_frame); | 1206 ASSERT_NE(nullptr, web_frame); |
| 1168 | 1207 |
| 1169 FormCache form_cache(*web_frame); | 1208 FormCache form_cache(*web_frame); |
| 1170 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1209 size_t unowned_form_index; |
| 1210 std::vector<FormData> forms = |
| 1211 form_cache.ExtractNewForms(&unowned_form_index); |
| 1171 ASSERT_EQ(1U, forms.size()); | 1212 ASSERT_EQ(1U, forms.size()); |
| 1213 const size_t expected_index = unowned ? 0 : 1; |
| 1214 EXPECT_EQ(expected_index, unowned_form_index); |
| 1172 | 1215 |
| 1173 // Set the auto-filled attribute. | 1216 // Set the auto-filled attribute. |
| 1174 WebInputElement firstname = GetInputElementById("firstname"); | 1217 WebInputElement firstname = GetInputElementById("firstname"); |
| 1175 firstname.setAutofilled(true); | 1218 firstname.setAutofilled(true); |
| 1176 WebInputElement lastname = GetInputElementById("lastname"); | 1219 WebInputElement lastname = GetInputElementById("lastname"); |
| 1177 lastname.setAutofilled(true); | 1220 lastname.setAutofilled(true); |
| 1178 | 1221 |
| 1179 // Set the value and auto-filled attribute of the state element. | 1222 // Set the value and auto-filled attribute of the state element. |
| 1180 WebSelectElement state = | 1223 WebSelectElement state = |
| 1181 web_frame->document().getElementById("state").to<WebSelectElement>(); | 1224 web_frame->document().getElementById("state").to<WebSelectElement>(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 expected.value = ASCIIToUTF16("?"); | 1263 expected.value = ASCIIToUTF16("?"); |
| 1221 expected.form_control_type = "select-one"; | 1264 expected.form_control_type = "select-one"; |
| 1222 expected.max_length = 0; | 1265 expected.max_length = 0; |
| 1223 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 1266 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1224 | 1267 |
| 1225 // Verify that the cursor position has been updated. | 1268 // Verify that the cursor position has been updated. |
| 1226 EXPECT_EQ(0, firstname.selectionStart()); | 1269 EXPECT_EQ(0, firstname.selectionStart()); |
| 1227 EXPECT_EQ(0, firstname.selectionEnd()); | 1270 EXPECT_EQ(0, firstname.selectionEnd()); |
| 1228 } | 1271 } |
| 1229 | 1272 |
| 1230 void TestClearPreviewedFormWithElement(const char* html) { | 1273 void TestClearPreviewedFormWithElement(const char* html, bool unowned) { |
| 1231 LoadHTML(html); | 1274 LoadHTML(html); |
| 1232 WebFrame* web_frame = GetMainFrame(); | 1275 WebFrame* web_frame = GetMainFrame(); |
| 1233 ASSERT_NE(nullptr, web_frame); | 1276 ASSERT_NE(nullptr, web_frame); |
| 1234 | 1277 |
| 1235 FormCache form_cache(*web_frame); | 1278 FormCache form_cache(*web_frame); |
| 1236 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1279 size_t unowned_form_index; |
| 1280 std::vector<FormData> forms = |
| 1281 form_cache.ExtractNewForms(&unowned_form_index); |
| 1237 ASSERT_EQ(1U, forms.size()); | 1282 ASSERT_EQ(1U, forms.size()); |
| 1283 const size_t expected_index = unowned ? 0 : 1; |
| 1284 EXPECT_EQ(expected_index, unowned_form_index); |
| 1238 | 1285 |
| 1239 // Set the auto-filled attribute. | 1286 // Set the auto-filled attribute. |
| 1240 WebInputElement firstname = GetInputElementById("firstname"); | 1287 WebInputElement firstname = GetInputElementById("firstname"); |
| 1241 firstname.setAutofilled(true); | 1288 firstname.setAutofilled(true); |
| 1242 WebInputElement lastname = GetInputElementById("lastname"); | 1289 WebInputElement lastname = GetInputElementById("lastname"); |
| 1243 lastname.setAutofilled(true); | 1290 lastname.setAutofilled(true); |
| 1244 WebInputElement email = GetInputElementById("email"); | 1291 WebInputElement email = GetInputElementById("email"); |
| 1245 email.setAutofilled(true); | 1292 email.setAutofilled(true); |
| 1246 WebInputElement email2 = GetInputElementById("email2"); | 1293 WebInputElement email2 = GetInputElementById("email2"); |
| 1247 email2.setAutofilled(true); | 1294 email2.setAutofilled(true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1274 EXPECT_FALSE(email2.isAutofilled()); | 1321 EXPECT_FALSE(email2.isAutofilled()); |
| 1275 EXPECT_TRUE(phone.value().isEmpty()); | 1322 EXPECT_TRUE(phone.value().isEmpty()); |
| 1276 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 1323 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1277 EXPECT_FALSE(phone.isAutofilled()); | 1324 EXPECT_FALSE(phone.isAutofilled()); |
| 1278 | 1325 |
| 1279 // Verify that the cursor position has been updated. | 1326 // Verify that the cursor position has been updated. |
| 1280 EXPECT_EQ(0, lastname.selectionStart()); | 1327 EXPECT_EQ(0, lastname.selectionStart()); |
| 1281 EXPECT_EQ(0, lastname.selectionEnd()); | 1328 EXPECT_EQ(0, lastname.selectionEnd()); |
| 1282 } | 1329 } |
| 1283 | 1330 |
| 1284 void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html) { | 1331 void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html, |
| 1332 bool unowned) { |
| 1285 LoadHTML(html); | 1333 LoadHTML(html); |
| 1286 WebFrame* web_frame = GetMainFrame(); | 1334 WebFrame* web_frame = GetMainFrame(); |
| 1287 ASSERT_NE(nullptr, web_frame); | 1335 ASSERT_NE(nullptr, web_frame); |
| 1288 | 1336 |
| 1289 FormCache form_cache(*web_frame); | 1337 FormCache form_cache(*web_frame); |
| 1290 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1338 size_t unowned_form_index; |
| 1339 std::vector<FormData> forms = |
| 1340 form_cache.ExtractNewForms(&unowned_form_index); |
| 1291 ASSERT_EQ(1U, forms.size()); | 1341 ASSERT_EQ(1U, forms.size()); |
| 1342 const size_t expected_index = unowned ? 0 : 1; |
| 1343 EXPECT_EQ(expected_index, unowned_form_index); |
| 1292 | 1344 |
| 1293 // Set the auto-filled attribute. | 1345 // Set the auto-filled attribute. |
| 1294 WebInputElement firstname = GetInputElementById("firstname"); | 1346 WebInputElement firstname = GetInputElementById("firstname"); |
| 1295 firstname.setAutofilled(true); | 1347 firstname.setAutofilled(true); |
| 1296 WebInputElement lastname = GetInputElementById("lastname"); | 1348 WebInputElement lastname = GetInputElementById("lastname"); |
| 1297 lastname.setAutofilled(true); | 1349 lastname.setAutofilled(true); |
| 1298 WebInputElement email = GetInputElementById("email"); | 1350 WebInputElement email = GetInputElementById("email"); |
| 1299 email.setAutofilled(true); | 1351 email.setAutofilled(true); |
| 1300 WebInputElement email2 = GetInputElementById("email2"); | 1352 WebInputElement email2 = GetInputElementById("email2"); |
| 1301 email2.setAutofilled(true); | 1353 email2.setAutofilled(true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1328 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 1380 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1329 EXPECT_FALSE(email.isAutofilled()); | 1381 EXPECT_FALSE(email.isAutofilled()); |
| 1330 EXPECT_TRUE(email2.value().isEmpty()); | 1382 EXPECT_TRUE(email2.value().isEmpty()); |
| 1331 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | 1383 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 1332 EXPECT_FALSE(email2.isAutofilled()); | 1384 EXPECT_FALSE(email2.isAutofilled()); |
| 1333 EXPECT_TRUE(phone.value().isEmpty()); | 1385 EXPECT_TRUE(phone.value().isEmpty()); |
| 1334 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 1386 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1335 EXPECT_FALSE(phone.isAutofilled()); | 1387 EXPECT_FALSE(phone.isAutofilled()); |
| 1336 } | 1388 } |
| 1337 | 1389 |
| 1338 void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html) { | 1390 void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html, |
| 1391 bool unowned) { |
| 1339 LoadHTML(html); | 1392 LoadHTML(html); |
| 1340 WebFrame* web_frame = GetMainFrame(); | 1393 WebFrame* web_frame = GetMainFrame(); |
| 1341 ASSERT_NE(nullptr, web_frame); | 1394 ASSERT_NE(nullptr, web_frame); |
| 1342 | 1395 |
| 1343 FormCache form_cache(*web_frame); | 1396 FormCache form_cache(*web_frame); |
| 1344 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1397 size_t unowned_form_index; |
| 1398 std::vector<FormData> forms = |
| 1399 form_cache.ExtractNewForms(&unowned_form_index); |
| 1345 ASSERT_EQ(1U, forms.size()); | 1400 ASSERT_EQ(1U, forms.size()); |
| 1401 const size_t expected_index = unowned ? 0 : 1; |
| 1402 EXPECT_EQ(expected_index, unowned_form_index); |
| 1346 | 1403 |
| 1347 // Set the auto-filled attribute. | 1404 // Set the auto-filled attribute. |
| 1348 WebInputElement firstname = GetInputElementById("firstname"); | 1405 WebInputElement firstname = GetInputElementById("firstname"); |
| 1349 firstname.setAutofilled(true); | 1406 firstname.setAutofilled(true); |
| 1350 WebInputElement lastname = GetInputElementById("lastname"); | 1407 WebInputElement lastname = GetInputElementById("lastname"); |
| 1351 lastname.setAutofilled(true); | 1408 lastname.setAutofilled(true); |
| 1352 WebInputElement email = GetInputElementById("email"); | 1409 WebInputElement email = GetInputElementById("email"); |
| 1353 email.setAutofilled(true); | 1410 email.setAutofilled(true); |
| 1354 WebInputElement email2 = GetInputElementById("email2"); | 1411 WebInputElement email2 = GetInputElementById("email2"); |
| 1355 email2.setAutofilled(true); | 1412 email2.setAutofilled(true); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1381 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 1438 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 1382 EXPECT_FALSE(email.isAutofilled()); | 1439 EXPECT_FALSE(email.isAutofilled()); |
| 1383 EXPECT_TRUE(email2.value().isEmpty()); | 1440 EXPECT_TRUE(email2.value().isEmpty()); |
| 1384 EXPECT_TRUE(email2.suggestedValue().isEmpty()); | 1441 EXPECT_TRUE(email2.suggestedValue().isEmpty()); |
| 1385 EXPECT_FALSE(email2.isAutofilled()); | 1442 EXPECT_FALSE(email2.isAutofilled()); |
| 1386 EXPECT_TRUE(phone.value().isEmpty()); | 1443 EXPECT_TRUE(phone.value().isEmpty()); |
| 1387 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 1444 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 1388 EXPECT_FALSE(phone.isAutofilled()); | 1445 EXPECT_FALSE(phone.isAutofilled()); |
| 1389 } | 1446 } |
| 1390 | 1447 |
| 1391 void TestClearOnlyAutofilledFields(const char* html) { | 1448 void TestClearOnlyAutofilledFields(const char* html, bool unowned) { |
| 1392 LoadHTML(html); | 1449 LoadHTML(html); |
| 1393 | 1450 |
| 1394 WebFrame* web_frame = GetMainFrame(); | 1451 WebFrame* web_frame = GetMainFrame(); |
| 1395 ASSERT_NE(nullptr, web_frame); | 1452 ASSERT_NE(nullptr, web_frame); |
| 1396 | 1453 |
| 1397 FormCache form_cache(*web_frame); | 1454 FormCache form_cache(*web_frame); |
| 1398 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1455 size_t unowned_form_index; |
| 1456 std::vector<FormData> forms = |
| 1457 form_cache.ExtractNewForms(&unowned_form_index); |
| 1399 ASSERT_EQ(1U, forms.size()); | 1458 ASSERT_EQ(1U, forms.size()); |
| 1459 const size_t expected_index = unowned ? 0 : 1; |
| 1460 EXPECT_EQ(expected_index, unowned_form_index); |
| 1400 | 1461 |
| 1401 // Set the autofilled attribute. | 1462 // Set the autofilled attribute. |
| 1402 WebInputElement firstname = GetInputElementById("firstname"); | 1463 WebInputElement firstname = GetInputElementById("firstname"); |
| 1403 firstname.setAutofilled(false); | 1464 firstname.setAutofilled(false); |
| 1404 WebInputElement lastname = GetInputElementById("lastname"); | 1465 WebInputElement lastname = GetInputElementById("lastname"); |
| 1405 lastname.setAutofilled(true); | 1466 lastname.setAutofilled(true); |
| 1406 WebInputElement email = GetInputElementById("email"); | 1467 WebInputElement email = GetInputElementById("email"); |
| 1407 email.setAutofilled(true); | 1468 email.setAutofilled(true); |
| 1408 WebInputElement phone = GetInputElementById("phone"); | 1469 WebInputElement phone = GetInputElementById("phone"); |
| 1409 phone.setAutofilled(true); | 1470 phone.setAutofilled(true); |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 " <INPUT type='text' id='firstname' value='Jack'/>" | 2142 " <INPUT type='text' id='firstname' value='Jack'/>" |
| 2082 " <INPUT type='text' id='lastname' value='Adams'/>" | 2143 " <INPUT type='text' id='lastname' value='Adams'/>" |
| 2083 " <INPUT type='text' id='email' value='jack@example.com'/>" | 2144 " <INPUT type='text' id='email' value='jack@example.com'/>" |
| 2084 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2145 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2085 "</FORM>"); | 2146 "</FORM>"); |
| 2086 | 2147 |
| 2087 WebFrame* web_frame = GetMainFrame(); | 2148 WebFrame* web_frame = GetMainFrame(); |
| 2088 ASSERT_NE(nullptr, web_frame); | 2149 ASSERT_NE(nullptr, web_frame); |
| 2089 | 2150 |
| 2090 FormCache form_cache(*web_frame); | 2151 FormCache form_cache(*web_frame); |
| 2091 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2152 size_t unowned_form_index; |
| 2153 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2092 ASSERT_EQ(2U, forms.size()); | 2154 ASSERT_EQ(2U, forms.size()); |
| 2155 EXPECT_EQ(2U, unowned_form_index); |
| 2093 | 2156 |
| 2094 // First form. | 2157 // First form. |
| 2095 const FormData& form = forms[0]; | 2158 const FormData& form = forms[0]; |
| 2096 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2159 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2097 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2160 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2098 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2161 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2099 | 2162 |
| 2100 const std::vector<FormFieldData>& fields = form.fields; | 2163 const std::vector<FormFieldData>& fields = form.fields; |
| 2101 ASSERT_EQ(3U, fields.size()); | 2164 ASSERT_EQ(3U, fields.size()); |
| 2102 | 2165 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 " <INPUT type='text' id='firstname' value='John'/>" | 2207 " <INPUT type='text' id='firstname' value='John'/>" |
| 2145 " <INPUT type='text' id='lastname' value='Smith'/>" | 2208 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2146 " <INPUT type='text' id='email' value='john@example.com'/>" | 2209 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 2147 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2210 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2148 "</FORM>"); | 2211 "</FORM>"); |
| 2149 | 2212 |
| 2150 WebFrame* web_frame = GetMainFrame(); | 2213 WebFrame* web_frame = GetMainFrame(); |
| 2151 ASSERT_NE(nullptr, web_frame); | 2214 ASSERT_NE(nullptr, web_frame); |
| 2152 | 2215 |
| 2153 FormCache form_cache(*web_frame); | 2216 FormCache form_cache(*web_frame); |
| 2154 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2217 size_t unowned_form_index; |
| 2218 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2155 ASSERT_EQ(1U, forms.size()); | 2219 ASSERT_EQ(1U, forms.size()); |
| 2220 EXPECT_EQ(1U, unowned_form_index); |
| 2156 | 2221 |
| 2157 // Second call should give nothing as there are no new forms. | 2222 // Second call should give nothing as there are no new forms. |
| 2158 forms = form_cache.ExtractNewForms(); | 2223 forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2159 ASSERT_TRUE(forms.empty()); | 2224 ASSERT_TRUE(forms.empty()); |
| 2225 EXPECT_EQ(0U, unowned_form_index); |
| 2160 | 2226 |
| 2161 // Append to the current form will re-extract. | 2227 // Append to the current form will re-extract. |
| 2162 ExecuteJavaScript( | 2228 ExecuteJavaScript( |
| 2163 "var newInput = document.createElement('input');" | 2229 "var newInput = document.createElement('input');" |
| 2164 "newInput.setAttribute('type', 'text');" | 2230 "newInput.setAttribute('type', 'text');" |
| 2165 "newInput.setAttribute('id', 'telephone');" | 2231 "newInput.setAttribute('id', 'telephone');" |
| 2166 "newInput.value = '12345';" | 2232 "newInput.value = '12345';" |
| 2167 "document.getElementById('testform').appendChild(newInput);"); | 2233 "document.getElementById('testform').appendChild(newInput);"); |
| 2168 msg_loop_.RunUntilIdle(); | 2234 msg_loop_.RunUntilIdle(); |
| 2169 | 2235 |
| 2170 forms = form_cache.ExtractNewForms(); | 2236 forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2171 ASSERT_EQ(1U, forms.size()); | 2237 ASSERT_EQ(1U, forms.size()); |
| 2238 EXPECT_EQ(1U, unowned_form_index); |
| 2172 | 2239 |
| 2173 const std::vector<FormFieldData>& fields = forms[0].fields; | 2240 const std::vector<FormFieldData>& fields = forms[0].fields; |
| 2174 ASSERT_EQ(4U, fields.size()); | 2241 ASSERT_EQ(4U, fields.size()); |
| 2175 | 2242 |
| 2176 FormFieldData expected; | 2243 FormFieldData expected; |
| 2177 expected.form_control_type = "text"; | 2244 expected.form_control_type = "text"; |
| 2178 expected.max_length = WebInputElement::defaultMaxLength(); | 2245 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2179 | 2246 |
| 2180 expected.name = ASCIIToUTF16("firstname"); | 2247 expected.name = ASCIIToUTF16("firstname"); |
| 2181 expected.value = ASCIIToUTF16("John"); | 2248 expected.value = ASCIIToUTF16("John"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2213 "newEmail.setAttribute('type', 'text');" | 2280 "newEmail.setAttribute('type', 'text');" |
| 2214 "newEmail.setAttribute('id', 'second_email');" | 2281 "newEmail.setAttribute('id', 'second_email');" |
| 2215 "newEmail.value = 'bobhope@example.com';" | 2282 "newEmail.value = 'bobhope@example.com';" |
| 2216 "newForm.appendChild(newFirstname);" | 2283 "newForm.appendChild(newFirstname);" |
| 2217 "newForm.appendChild(newLastname);" | 2284 "newForm.appendChild(newLastname);" |
| 2218 "newForm.appendChild(newEmail);" | 2285 "newForm.appendChild(newEmail);" |
| 2219 "document.body.appendChild(newForm);"); | 2286 "document.body.appendChild(newForm);"); |
| 2220 msg_loop_.RunUntilIdle(); | 2287 msg_loop_.RunUntilIdle(); |
| 2221 | 2288 |
| 2222 web_frame = GetMainFrame(); | 2289 web_frame = GetMainFrame(); |
| 2223 forms = form_cache.ExtractNewForms(); | 2290 forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2224 ASSERT_EQ(1U, forms.size()); | 2291 ASSERT_EQ(1U, forms.size()); |
| 2292 EXPECT_EQ(1U, unowned_form_index); |
| 2225 | 2293 |
| 2226 const std::vector<FormFieldData>& fields2 = forms[0].fields; | 2294 const std::vector<FormFieldData>& fields2 = forms[0].fields; |
| 2227 ASSERT_EQ(3U, fields2.size()); | 2295 ASSERT_EQ(3U, fields2.size()); |
| 2228 | 2296 |
| 2229 expected.name = ASCIIToUTF16("second_firstname"); | 2297 expected.name = ASCIIToUTF16("second_firstname"); |
| 2230 expected.value = ASCIIToUTF16("Bob"); | 2298 expected.value = ASCIIToUTF16("Bob"); |
| 2231 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 2299 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 2232 | 2300 |
| 2233 expected.name = ASCIIToUTF16("second_lastname"); | 2301 expected.name = ASCIIToUTF16("second_lastname"); |
| 2234 expected.value = ASCIIToUTF16("Hope"); | 2302 expected.value = ASCIIToUTF16("Hope"); |
| 2235 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 2303 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 2236 | 2304 |
| 2237 expected.name = ASCIIToUTF16("second_email"); | 2305 expected.name = ASCIIToUTF16("second_email"); |
| 2238 expected.value = ASCIIToUTF16("bobhope@example.com"); | 2306 expected.value = ASCIIToUTF16("bobhope@example.com"); |
| 2239 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2307 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2240 } | 2308 } |
| 2241 | 2309 |
| 2242 // We should not extract a form if it has too few fillable fields. | 2310 // We should not extract a form if it has too few fillable fields. |
| 2243 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { | 2311 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { |
| 2244 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2312 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2245 " <INPUT type='text' id='firstname' value='John'/>" | 2313 " <INPUT type='text' id='firstname' value='John'/>" |
| 2246 " <INPUT type='text' id='lastname' value='Smith'/>" | 2314 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2247 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2315 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2248 "</FORM>"); | 2316 "</FORM>"); |
| 2249 | 2317 |
| 2250 WebFrame* web_frame = GetMainFrame(); | 2318 WebFrame* web_frame = GetMainFrame(); |
| 2251 ASSERT_NE(nullptr, web_frame); | 2319 ASSERT_NE(nullptr, web_frame); |
| 2252 | 2320 |
| 2253 FormCache form_cache(*web_frame); | 2321 FormCache form_cache(*web_frame); |
| 2254 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2322 size_t unowned_form_index; |
| 2323 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2255 ASSERT_TRUE(forms.empty()); | 2324 ASSERT_TRUE(forms.empty()); |
| 2325 EXPECT_EQ(0U, unowned_form_index); |
| 2256 } | 2326 } |
| 2257 | 2327 |
| 2258 // We should not report additional forms for empty forms. | 2328 // We should not report additional forms for empty forms. |
| 2259 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { | 2329 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { |
| 2260 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2330 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2261 " <INPUT type='text' id='firstname' value='John'/>" | 2331 " <INPUT type='text' id='firstname' value='John'/>" |
| 2262 " <INPUT type='text' id='lastname' value='Smith'/>" | 2332 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2263 "</FORM>"); | 2333 "</FORM>"); |
| 2264 | 2334 |
| 2265 WebFrame* web_frame = GetMainFrame(); | 2335 WebFrame* web_frame = GetMainFrame(); |
| 2266 ASSERT_NE(nullptr, web_frame); | 2336 ASSERT_NE(nullptr, web_frame); |
| 2267 | 2337 |
| 2268 FormCache form_cache(*web_frame); | 2338 FormCache form_cache(*web_frame); |
| 2269 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2339 size_t unowned_form_index; |
| 2340 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2270 ASSERT_TRUE(forms.empty()); | 2341 ASSERT_TRUE(forms.empty()); |
| 2342 EXPECT_EQ(0U, unowned_form_index); |
| 2271 } | 2343 } |
| 2272 | 2344 |
| 2273 // We should not report additional forms for empty forms. | 2345 // We should not report additional forms for empty forms. |
| 2274 TEST_F(FormAutofillTest, ExtractFormsNoFields) { | 2346 TEST_F(FormAutofillTest, ExtractFormsNoFields) { |
| 2275 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2347 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2276 "</FORM>"); | 2348 "</FORM>"); |
| 2277 | 2349 |
| 2278 WebFrame* web_frame = GetMainFrame(); | 2350 WebFrame* web_frame = GetMainFrame(); |
| 2279 ASSERT_NE(nullptr, web_frame); | 2351 ASSERT_NE(nullptr, web_frame); |
| 2280 | 2352 |
| 2281 FormCache form_cache(*web_frame); | 2353 FormCache form_cache(*web_frame); |
| 2282 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2354 size_t unowned_form_index; |
| 2355 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2283 ASSERT_TRUE(forms.empty()); | 2356 ASSERT_TRUE(forms.empty()); |
| 2357 EXPECT_EQ(0U, unowned_form_index); |
| 2284 } | 2358 } |
| 2285 | 2359 |
| 2286 // We should not extract a form if it has too few fillable fields. | 2360 // We should not extract a form if it has too few fillable fields. |
| 2287 // Make sure radio and checkbox fields don't count. | 2361 // Make sure radio and checkbox fields don't count. |
| 2288 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { | 2362 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { |
| 2289 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2363 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2290 " <INPUT type='text' id='firstname' value='John'/>" | 2364 " <INPUT type='text' id='firstname' value='John'/>" |
| 2291 " <INPUT type='text' id='lastname' value='Smith'/>" | 2365 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2292 " <INPUT type='radio' id='a_radio' value='0'/>" | 2366 " <INPUT type='radio' id='a_radio' value='0'/>" |
| 2293 " <INPUT type='checkbox' id='a_check' value='1'/>" | 2367 " <INPUT type='checkbox' id='a_check' value='1'/>" |
| 2294 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2368 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2295 "</FORM>"); | 2369 "</FORM>"); |
| 2296 | 2370 |
| 2297 WebFrame* web_frame = GetMainFrame(); | 2371 WebFrame* web_frame = GetMainFrame(); |
| 2298 ASSERT_NE(nullptr, web_frame); | 2372 ASSERT_NE(nullptr, web_frame); |
| 2299 | 2373 |
| 2300 FormCache form_cache(*web_frame); | 2374 FormCache form_cache(*web_frame); |
| 2301 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2375 size_t unowned_form_index; |
| 2376 std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
| 2302 ASSERT_TRUE(forms.empty()); | 2377 ASSERT_TRUE(forms.empty()); |
| 2378 EXPECT_EQ(0U, unowned_form_index); |
| 2303 } | 2379 } |
| 2304 | 2380 |
| 2305 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { | 2381 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { |
| 2306 { | 2382 { |
| 2307 // Form is not auto-completable due to autocomplete=off. | 2383 // Form is not auto-completable due to autocomplete=off. |
| 2308 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" | 2384 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" |
| 2309 " autocomplete=off>" | 2385 " autocomplete=off>" |
| 2310 " <INPUT type='text' id='firstname' value='John'/>" | 2386 " <INPUT type='text' id='firstname' value='John'/>" |
| 2311 " <INPUT type='text' id='lastname' value='Smith'/>" | 2387 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2312 " <INPUT type='text' id='email' value='john@example.com'/>" | 2388 " <INPUT type='text' id='email' value='john@example.com'/>" |
| (...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3710 | 3786 |
| 3711 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 3787 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
| 3712 TestClearPreviewedFormWithElement( | 3788 TestClearPreviewedFormWithElement( |
| 3713 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3789 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3714 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3790 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3715 " <INPUT type='text' id='lastname'/>" | 3791 " <INPUT type='text' id='lastname'/>" |
| 3716 " <INPUT type='text' id='email'/>" | 3792 " <INPUT type='text' id='email'/>" |
| 3717 " <INPUT type='email' id='email2'/>" | 3793 " <INPUT type='email' id='email2'/>" |
| 3718 " <INPUT type='tel' id='phone'/>" | 3794 " <INPUT type='tel' id='phone'/>" |
| 3719 " <INPUT type='submit' value='Send'/>" | 3795 " <INPUT type='submit' value='Send'/>" |
| 3720 "</FORM>"); | 3796 "</FORM>", |
| 3797 false); |
| 3721 } | 3798 } |
| 3722 | 3799 |
| 3723 TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { | 3800 TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { |
| 3724 TestClearPreviewedFormWithElement( | 3801 TestClearPreviewedFormWithElement( |
| 3725 "<INPUT type='text' id='firstname' value='Wyatt'/>" | 3802 "<INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3726 "<INPUT type='text' id='lastname'/>" | 3803 "<INPUT type='text' id='lastname'/>" |
| 3727 "<INPUT type='text' id='email'/>" | 3804 "<INPUT type='text' id='email'/>" |
| 3728 "<INPUT type='email' id='email2'/>" | 3805 "<INPUT type='email' id='email2'/>" |
| 3729 "<INPUT type='tel' id='phone'/>" | 3806 "<INPUT type='tel' id='phone'/>" |
| 3730 "<INPUT type='submit' value='Send'/>"); | 3807 "<INPUT type='submit' value='Send'/>", |
| 3808 true); |
| 3731 } | 3809 } |
| 3732 | 3810 |
| 3733 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { | 3811 TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { |
| 3734 TestClearPreviewedFormWithNonEmptyInitiatingNode( | 3812 TestClearPreviewedFormWithNonEmptyInitiatingNode( |
| 3735 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3813 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3736 " <INPUT type='text' id='firstname' value='W'/>" | 3814 " <INPUT type='text' id='firstname' value='W'/>" |
| 3737 " <INPUT type='text' id='lastname'/>" | 3815 " <INPUT type='text' id='lastname'/>" |
| 3738 " <INPUT type='text' id='email'/>" | 3816 " <INPUT type='text' id='email'/>" |
| 3739 " <INPUT type='email' id='email2'/>" | 3817 " <INPUT type='email' id='email2'/>" |
| 3740 " <INPUT type='tel' id='phone'/>" | 3818 " <INPUT type='tel' id='phone'/>" |
| 3741 " <INPUT type='submit' value='Send'/>" | 3819 " <INPUT type='submit' value='Send'/>" |
| 3742 "</FORM>"); | 3820 "</FORM>", |
| 3821 false); |
| 3743 } | 3822 } |
| 3744 | 3823 |
| 3745 TEST_F(FormAutofillTest, | 3824 TEST_F(FormAutofillTest, |
| 3746 ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) { | 3825 ClearPreviewedFormWithNonEmptyInitiatingNodeForUnownedForm) { |
| 3747 TestClearPreviewedFormWithNonEmptyInitiatingNode( | 3826 TestClearPreviewedFormWithNonEmptyInitiatingNode( |
| 3748 "<INPUT type='text' id='firstname' value='W'/>" | 3827 "<INPUT type='text' id='firstname' value='W'/>" |
| 3749 "<INPUT type='text' id='lastname'/>" | 3828 "<INPUT type='text' id='lastname'/>" |
| 3750 "<INPUT type='text' id='email'/>" | 3829 "<INPUT type='text' id='email'/>" |
| 3751 "<INPUT type='email' id='email2'/>" | 3830 "<INPUT type='email' id='email2'/>" |
| 3752 "<INPUT type='tel' id='phone'/>" | 3831 "<INPUT type='tel' id='phone'/>" |
| 3753 "<INPUT type='submit' value='Send'/>"); | 3832 "<INPUT type='submit' value='Send'/>", |
| 3833 true); |
| 3754 } | 3834 } |
| 3755 | 3835 |
| 3756 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { | 3836 TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
| 3757 TestClearPreviewedFormWithAutofilledInitiatingNode( | 3837 TestClearPreviewedFormWithAutofilledInitiatingNode( |
| 3758 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3838 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3759 " <INPUT type='text' id='firstname' value='W'/>" | 3839 " <INPUT type='text' id='firstname' value='W'/>" |
| 3760 " <INPUT type='text' id='lastname'/>" | 3840 " <INPUT type='text' id='lastname'/>" |
| 3761 " <INPUT type='text' id='email'/>" | 3841 " <INPUT type='text' id='email'/>" |
| 3762 " <INPUT type='email' id='email2'/>" | 3842 " <INPUT type='email' id='email2'/>" |
| 3763 " <INPUT type='tel' id='phone'/>" | 3843 " <INPUT type='tel' id='phone'/>" |
| 3764 " <INPUT type='submit' value='Send'/>" | 3844 " <INPUT type='submit' value='Send'/>" |
| 3765 "</FORM>"); | 3845 "</FORM>", |
| 3846 false); |
| 3766 } | 3847 } |
| 3767 | 3848 |
| 3768 TEST_F(FormAutofillTest, | 3849 TEST_F(FormAutofillTest, |
| 3769 ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) { | 3850 ClearPreviewedFormWithAutofilledInitiatingNodeForUnownedForm) { |
| 3770 TestClearPreviewedFormWithAutofilledInitiatingNode( | 3851 TestClearPreviewedFormWithAutofilledInitiatingNode( |
| 3771 "<INPUT type='text' id='firstname' value='W'/>" | 3852 "<INPUT type='text' id='firstname' value='W'/>" |
| 3772 "<INPUT type='text' id='lastname'/>" | 3853 "<INPUT type='text' id='lastname'/>" |
| 3773 "<INPUT type='text' id='email'/>" | 3854 "<INPUT type='text' id='email'/>" |
| 3774 "<INPUT type='email' id='email2'/>" | 3855 "<INPUT type='email' id='email2'/>" |
| 3775 "<INPUT type='tel' id='phone'/>" | 3856 "<INPUT type='tel' id='phone'/>" |
| 3776 "<INPUT type='submit' value='Send'/>"); | 3857 "<INPUT type='submit' value='Send'/>", |
| 3858 true); |
| 3777 } | 3859 } |
| 3778 | 3860 |
| 3779 // Autofill's "Clear Form" should clear only autofilled fields | 3861 // Autofill's "Clear Form" should clear only autofilled fields |
| 3780 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { | 3862 TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
| 3781 TestClearOnlyAutofilledFields( | 3863 TestClearOnlyAutofilledFields( |
| 3782 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3864 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3783 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 3865 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3784 " <INPUT type='text' id='lastname' value='Earp'/>" | 3866 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3785 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" | 3867 " <INPUT type='email' id='email' value='wyatt@earp.com'/>" |
| 3786 " <INPUT type='tel' id='phone' value='650-777-9999'/>" | 3868 " <INPUT type='tel' id='phone' value='650-777-9999'/>" |
| 3787 " <INPUT type='submit' value='Send'/>" | 3869 " <INPUT type='submit' value='Send'/>" |
| 3788 "</FORM>"); | 3870 "</FORM>", |
| 3871 false); |
| 3789 } | 3872 } |
| 3790 | 3873 |
| 3791 TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { | 3874 TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { |
| 3792 TestClearOnlyAutofilledFields( | 3875 TestClearOnlyAutofilledFields( |
| 3793 "<INPUT type='text' id='firstname' value='Wyatt'/>" | 3876 "<INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3794 "<INPUT type='text' id='lastname' value='Earp'/>" | 3877 "<INPUT type='text' id='lastname' value='Earp'/>" |
| 3795 "<INPUT type='email' id='email' value='wyatt@earp.com'/>" | 3878 "<INPUT type='email' id='email' value='wyatt@earp.com'/>" |
| 3796 "<INPUT type='tel' id='phone' value='650-777-9999'/>" | 3879 "<INPUT type='tel' id='phone' value='650-777-9999'/>" |
| 3797 "<INPUT type='submit' value='Send'/>"); | 3880 "<INPUT type='submit' value='Send'/>", |
| 3881 true); |
| 3798 } | 3882 } |
| 3799 | 3883 |
| 3800 // If we have multiple labels per id, the labels concatenated into label string. | 3884 // If we have multiple labels per id, the labels concatenated into label string. |
| 3801 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { | 3885 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { |
| 3802 std::vector<base::string16> labels, names, values; | 3886 std::vector<base::string16> labels, names, values; |
| 3803 | 3887 |
| 3804 labels.push_back(ASCIIToUTF16("First Name:")); | 3888 labels.push_back(ASCIIToUTF16("First Name:")); |
| 3805 names.push_back(ASCIIToUTF16("firstname")); | 3889 names.push_back(ASCIIToUTF16("firstname")); |
| 3806 values.push_back(ASCIIToUTF16("John")); | 3890 values.push_back(ASCIIToUTF16("John")); |
| 3807 | 3891 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4086 ASSERT_TRUE(control_elements.empty()); | 4170 ASSERT_TRUE(control_elements.empty()); |
| 4087 ASSERT_TRUE(fieldsets.empty()); | 4171 ASSERT_TRUE(fieldsets.empty()); |
| 4088 | 4172 |
| 4089 FormData form; | 4173 FormData form; |
| 4090 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( | 4174 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( |
| 4091 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, | 4175 fieldsets, control_elements, nullptr, dummy_origin, REQUIRE_NONE, |
| 4092 extract_mask, &form, nullptr)); | 4176 extract_mask, &form, nullptr)); |
| 4093 } | 4177 } |
| 4094 | 4178 |
| 4095 } // namespace autofill | 4179 } // namespace autofill |
| OLD | NEW |