| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "third_party/WebKit/public/web/WebInputElement.h" | 29 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebSelectElement.h" | 31 #include "third_party/WebKit/public/web/WebSelectElement.h" |
| 32 | 32 |
| 33 using base::ASCIIToUTF16; | 33 using base::ASCIIToUTF16; |
| 34 using blink::WebDocument; | 34 using blink::WebDocument; |
| 35 using blink::WebElement; | 35 using blink::WebElement; |
| 36 using blink::WebExceptionCode; | 36 using blink::WebExceptionCode; |
| 37 using blink::WebFormControlElement; | 37 using blink::WebFormControlElement; |
| 38 using blink::WebFormElement; | 38 using blink::WebFormElement; |
| 39 using blink::WebFrame; | |
| 40 using blink::WebInputElement; | 39 using blink::WebInputElement; |
| 40 using blink::WebLocalFrame; |
| 41 using blink::WebSelectElement; | 41 using blink::WebSelectElement; |
| 42 using blink::WebString; | 42 using blink::WebString; |
| 43 using blink::WebVector; | 43 using blink::WebVector; |
| 44 | 44 |
| 45 namespace autofill { | 45 namespace autofill { |
| 46 namespace form_util { | 46 namespace form_util { |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 struct AutofillFieldCase { | 50 struct AutofillFieldCase { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 const std::vector<base::string16>& labels, | 283 const std::vector<base::string16>& labels, |
| 284 const std::vector<base::string16>& names, | 284 const std::vector<base::string16>& names, |
| 285 const std::vector<base::string16>& values, | 285 const std::vector<base::string16>& values, |
| 286 const std::vector<std::string>& control_types) { | 286 const std::vector<std::string>& control_types) { |
| 287 ASSERT_EQ(labels.size(), names.size()); | 287 ASSERT_EQ(labels.size(), names.size()); |
| 288 ASSERT_EQ(labels.size(), values.size()); | 288 ASSERT_EQ(labels.size(), values.size()); |
| 289 ASSERT_EQ(labels.size(), control_types.size()); | 289 ASSERT_EQ(labels.size(), control_types.size()); |
| 290 | 290 |
| 291 LoadHTML(html); | 291 LoadHTML(html); |
| 292 | 292 |
| 293 WebFrame* web_frame = GetMainFrame(); | 293 WebLocalFrame* web_frame = GetMainFrame(); |
| 294 ASSERT_NE(nullptr, web_frame); | 294 ASSERT_NE(nullptr, web_frame); |
| 295 | 295 |
| 296 FormCache form_cache(*web_frame); | 296 FormCache form_cache(*web_frame); |
| 297 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 297 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 298 ASSERT_EQ(1U, forms.size()); | 298 ASSERT_EQ(1U, forms.size()); |
| 299 | 299 |
| 300 const FormData& form = forms[0]; | 300 const FormData& form = forms[0]; |
| 301 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 301 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 302 EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()), | 302 EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()), |
| 303 form.origin); | 303 form.origin); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 const char* url_override, | 348 const char* url_override, |
| 349 const AutofillFieldCase* field_cases, | 349 const AutofillFieldCase* field_cases, |
| 350 size_t number_of_field_cases, | 350 size_t number_of_field_cases, |
| 351 FillFormFunction fill_form_function, | 351 FillFormFunction fill_form_function, |
| 352 GetValueFunction get_value_function) { | 352 GetValueFunction get_value_function) { |
| 353 if (url_override) | 353 if (url_override) |
| 354 LoadHTMLWithUrlOverride(html, url_override); | 354 LoadHTMLWithUrlOverride(html, url_override); |
| 355 else | 355 else |
| 356 LoadHTML(html); | 356 LoadHTML(html); |
| 357 | 357 |
| 358 WebFrame* web_frame = GetMainFrame(); | 358 WebLocalFrame* web_frame = GetMainFrame(); |
| 359 ASSERT_NE(nullptr, web_frame); | 359 ASSERT_NE(nullptr, web_frame); |
| 360 | 360 |
| 361 FormCache form_cache(*web_frame); | 361 FormCache form_cache(*web_frame); |
| 362 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 362 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 363 ASSERT_EQ(1U, forms.size()); | 363 ASSERT_EQ(1U, forms.size()); |
| 364 | 364 |
| 365 // Get the input element we want to find. | 365 // Get the input element we want to find. |
| 366 WebInputElement input_element = GetInputElementById("firstname"); | 366 WebInputElement input_element = GetInputElementById("firstname"); |
| 367 | 367 |
| 368 // Find the form that contains the input element. | 368 // Find the form that contains the input element. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 EXPECT_EQ(0, firstname.SelectionStart()); | 601 EXPECT_EQ(0, firstname.SelectionStart()); |
| 602 EXPECT_EQ(19, firstname.SelectionEnd()); | 602 EXPECT_EQ(19, firstname.SelectionEnd()); |
| 603 } | 603 } |
| 604 | 604 |
| 605 void TestUnmatchedUnownedForm(const char* html, const char* url_override) { | 605 void TestUnmatchedUnownedForm(const char* html, const char* url_override) { |
| 606 if (url_override) | 606 if (url_override) |
| 607 LoadHTMLWithUrlOverride(html, url_override); | 607 LoadHTMLWithUrlOverride(html, url_override); |
| 608 else | 608 else |
| 609 LoadHTML(html); | 609 LoadHTML(html); |
| 610 | 610 |
| 611 WebFrame* web_frame = GetMainFrame(); | 611 WebLocalFrame* web_frame = GetMainFrame(); |
| 612 ASSERT_NE(nullptr, web_frame); | 612 ASSERT_NE(nullptr, web_frame); |
| 613 | 613 |
| 614 FormCache form_cache(*web_frame); | 614 FormCache form_cache(*web_frame); |
| 615 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 615 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 616 ASSERT_EQ(0U, forms.size()); | 616 ASSERT_EQ(0U, forms.size()); |
| 617 } | 617 } |
| 618 | 618 |
| 619 void TestFindFormForInputElement(const char* html, bool unowned) { | 619 void TestFindFormForInputElement(const char* html, bool unowned) { |
| 620 LoadHTML(html); | 620 LoadHTML(html); |
| 621 WebFrame* web_frame = GetMainFrame(); | 621 WebLocalFrame* web_frame = GetMainFrame(); |
| 622 ASSERT_NE(nullptr, web_frame); | 622 ASSERT_NE(nullptr, web_frame); |
| 623 | 623 |
| 624 FormCache form_cache(*web_frame); | 624 FormCache form_cache(*web_frame); |
| 625 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 625 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 626 ASSERT_EQ(1U, forms.size()); | 626 ASSERT_EQ(1U, forms.size()); |
| 627 | 627 |
| 628 // Get the input element we want to find. | 628 // Get the input element we want to find. |
| 629 WebInputElement input_element = GetInputElementById("firstname"); | 629 WebInputElement input_element = GetInputElementById("firstname"); |
| 630 | 630 |
| 631 // Find the form and verify it's the correct form. | 631 // Find the form and verify it's the correct form. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 expected.autocomplete_attribute.clear(); | 666 expected.autocomplete_attribute.clear(); |
| 667 | 667 |
| 668 expected.name = ASCIIToUTF16("phone"); | 668 expected.name = ASCIIToUTF16("phone"); |
| 669 expected.value = ASCIIToUTF16("1.800.555.1234"); | 669 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 670 expected.label = ASCIIToUTF16("1.800.555.1234"); | 670 expected.label = ASCIIToUTF16("1.800.555.1234"); |
| 671 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 671 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void TestFindFormForTextAreaElement(const char* html, bool unowned) { | 674 void TestFindFormForTextAreaElement(const char* html, bool unowned) { |
| 675 LoadHTML(html); | 675 LoadHTML(html); |
| 676 WebFrame* web_frame = GetMainFrame(); | 676 WebLocalFrame* web_frame = GetMainFrame(); |
| 677 ASSERT_NE(nullptr, web_frame); | 677 ASSERT_NE(nullptr, web_frame); |
| 678 | 678 |
| 679 FormCache form_cache(*web_frame); | 679 FormCache form_cache(*web_frame); |
| 680 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 680 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 681 ASSERT_EQ(1U, forms.size()); | 681 ASSERT_EQ(1U, forms.size()); |
| 682 | 682 |
| 683 // Get the textarea element we want to find. | 683 // Get the textarea element we want to find. |
| 684 WebElement element = | 684 WebElement element = |
| 685 web_frame->GetDocument().GetElementById("street-address"); | 685 web_frame->GetDocument().GetElementById("street-address"); |
| 686 WebFormControlElement textarea_element = | 686 WebFormControlElement textarea_element = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | 730 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); |
| 731 expected.label.clear(); | 731 expected.label.clear(); |
| 732 expected.form_control_type = "textarea"; | 732 expected.form_control_type = "textarea"; |
| 733 expected.max_length = 0; | 733 expected.max_length = 0; |
| 734 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); | 734 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 735 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 735 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 736 } | 736 } |
| 737 | 737 |
| 738 void TestFillFormMaxLength(const char* html, bool unowned) { | 738 void TestFillFormMaxLength(const char* html, bool unowned) { |
| 739 LoadHTML(html); | 739 LoadHTML(html); |
| 740 WebFrame* web_frame = GetMainFrame(); | 740 WebLocalFrame* web_frame = GetMainFrame(); |
| 741 ASSERT_NE(nullptr, web_frame); | 741 ASSERT_NE(nullptr, web_frame); |
| 742 | 742 |
| 743 FormCache form_cache(*web_frame); | 743 FormCache form_cache(*web_frame); |
| 744 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 744 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 745 ASSERT_EQ(1U, forms.size()); | 745 ASSERT_EQ(1U, forms.size()); |
| 746 | 746 |
| 747 // Get the input element we want to find. | 747 // Get the input element we want to find. |
| 748 WebInputElement input_element = GetInputElementById("firstname"); | 748 WebInputElement input_element = GetInputElementById("firstname"); |
| 749 | 749 |
| 750 // Find the form that contains the input element. | 750 // Find the form that contains the input element. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 | 820 |
| 821 expected.name = ASCIIToUTF16("email"); | 821 expected.name = ASCIIToUTF16("email"); |
| 822 expected.value = ASCIIToUTF16("brotherj@"); | 822 expected.value = ASCIIToUTF16("brotherj@"); |
| 823 expected.max_length = 9; | 823 expected.max_length = 9; |
| 824 expected.is_autofilled = true; | 824 expected.is_autofilled = true; |
| 825 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 825 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 826 } | 826 } |
| 827 | 827 |
| 828 void TestFillFormNegativeMaxLength(const char* html, bool unowned) { | 828 void TestFillFormNegativeMaxLength(const char* html, bool unowned) { |
| 829 LoadHTML(html); | 829 LoadHTML(html); |
| 830 WebFrame* web_frame = GetMainFrame(); | 830 WebLocalFrame* web_frame = GetMainFrame(); |
| 831 ASSERT_NE(nullptr, web_frame); | 831 ASSERT_NE(nullptr, web_frame); |
| 832 | 832 |
| 833 FormCache form_cache(*web_frame); | 833 FormCache form_cache(*web_frame); |
| 834 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 834 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 835 ASSERT_EQ(1U, forms.size()); | 835 ASSERT_EQ(1U, forms.size()); |
| 836 | 836 |
| 837 // Get the input element we want to find. | 837 // Get the input element we want to find. |
| 838 WebInputElement input_element = GetInputElementById("firstname"); | 838 WebInputElement input_element = GetInputElementById("firstname"); |
| 839 | 839 |
| 840 // Find the form that contains the input element. | 840 // Find the form that contains the input element. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 expected.value = ASCIIToUTF16("Jonathan"); | 894 expected.value = ASCIIToUTF16("Jonathan"); |
| 895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 896 | 896 |
| 897 expected.name = ASCIIToUTF16("email"); | 897 expected.name = ASCIIToUTF16("email"); |
| 898 expected.value = ASCIIToUTF16("brotherj@example.com"); | 898 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 899 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 899 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 900 } | 900 } |
| 901 | 901 |
| 902 void TestFillFormEmptyName(const char* html, bool unowned) { | 902 void TestFillFormEmptyName(const char* html, bool unowned) { |
| 903 LoadHTML(html); | 903 LoadHTML(html); |
| 904 WebFrame* web_frame = GetMainFrame(); | 904 WebLocalFrame* web_frame = GetMainFrame(); |
| 905 ASSERT_NE(nullptr, web_frame); | 905 ASSERT_NE(nullptr, web_frame); |
| 906 | 906 |
| 907 FormCache form_cache(*web_frame); | 907 FormCache form_cache(*web_frame); |
| 908 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 908 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 909 ASSERT_EQ(1U, forms.size()); | 909 ASSERT_EQ(1U, forms.size()); |
| 910 | 910 |
| 911 // Get the input element we want to find. | 911 // Get the input element we want to find. |
| 912 WebInputElement input_element = GetInputElementById("firstname"); | 912 WebInputElement input_element = GetInputElementById("firstname"); |
| 913 | 913 |
| 914 // Find the form that contains the input element. | 914 // Find the form that contains the input element. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 expected.value = ASCIIToUTF16("Earp"); | 971 expected.value = ASCIIToUTF16("Earp"); |
| 972 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 972 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 973 | 973 |
| 974 expected.name = ASCIIToUTF16("email"); | 974 expected.name = ASCIIToUTF16("email"); |
| 975 expected.value = ASCIIToUTF16("wyatt@example.com"); | 975 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 976 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 976 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void TestFillFormEmptyFormNames(const char* html, bool unowned) { | 979 void TestFillFormEmptyFormNames(const char* html, bool unowned) { |
| 980 LoadHTML(html); | 980 LoadHTML(html); |
| 981 WebFrame* web_frame = GetMainFrame(); | 981 WebLocalFrame* web_frame = GetMainFrame(); |
| 982 ASSERT_NE(nullptr, web_frame); | 982 ASSERT_NE(nullptr, web_frame); |
| 983 | 983 |
| 984 FormCache form_cache(*web_frame); | 984 FormCache form_cache(*web_frame); |
| 985 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 985 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 986 const size_t expected_size = unowned ? 1 : 2; | 986 const size_t expected_size = unowned ? 1 : 2; |
| 987 ASSERT_EQ(expected_size, forms.size()); | 987 ASSERT_EQ(expected_size, forms.size()); |
| 988 | 988 |
| 989 // Get the input element we want to find. | 989 // Get the input element we want to find. |
| 990 WebInputElement input_element = GetInputElementById("apple"); | 990 WebInputElement input_element = GetInputElementById("apple"); |
| 991 | 991 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 void TestFillFormNonEmptyField(const char* html, | 1064 void TestFillFormNonEmptyField(const char* html, |
| 1065 bool unowned, | 1065 bool unowned, |
| 1066 const char* initial_lastname, | 1066 const char* initial_lastname, |
| 1067 const char* initial_email, | 1067 const char* initial_email, |
| 1068 const char* placeholder_firstname, | 1068 const char* placeholder_firstname, |
| 1069 const char* placeholder_lastname, | 1069 const char* placeholder_lastname, |
| 1070 const char* placeholder_email) { | 1070 const char* placeholder_email) { |
| 1071 LoadHTML(html); | 1071 LoadHTML(html); |
| 1072 WebFrame* web_frame = GetMainFrame(); | 1072 WebLocalFrame* web_frame = GetMainFrame(); |
| 1073 ASSERT_NE(nullptr, web_frame); | 1073 ASSERT_NE(nullptr, web_frame); |
| 1074 | 1074 |
| 1075 FormCache form_cache(*web_frame); | 1075 FormCache form_cache(*web_frame); |
| 1076 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1076 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1077 ASSERT_EQ(1U, forms.size()); | 1077 ASSERT_EQ(1U, forms.size()); |
| 1078 | 1078 |
| 1079 // Get the input element we want to find. | 1079 // Get the input element we want to find. |
| 1080 WebInputElement input_element = GetInputElementById("firstname"); | 1080 WebInputElement input_element = GetInputElementById("firstname"); |
| 1081 | 1081 |
| 1082 // Simulate typing by modifying the field value. | 1082 // Simulate typing by modifying the field value. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 expected.is_autofilled = true; | 1205 expected.is_autofilled = true; |
| 1206 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 1206 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 1207 | 1207 |
| 1208 // Verify that the cursor position has been updated. | 1208 // Verify that the cursor position has been updated. |
| 1209 EXPECT_EQ(5, input_element.SelectionStart()); | 1209 EXPECT_EQ(5, input_element.SelectionStart()); |
| 1210 EXPECT_EQ(5, input_element.SelectionEnd()); | 1210 EXPECT_EQ(5, input_element.SelectionEnd()); |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 void TestClearFormWithNode(const char* html, bool unowned) { | 1213 void TestClearFormWithNode(const char* html, bool unowned) { |
| 1214 LoadHTML(html); | 1214 LoadHTML(html); |
| 1215 WebFrame* web_frame = GetMainFrame(); | 1215 WebLocalFrame* web_frame = GetMainFrame(); |
| 1216 ASSERT_NE(nullptr, web_frame); | 1216 ASSERT_NE(nullptr, web_frame); |
| 1217 | 1217 |
| 1218 FormCache form_cache(*web_frame); | 1218 FormCache form_cache(*web_frame); |
| 1219 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1219 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1220 ASSERT_EQ(1U, forms.size()); | 1220 ASSERT_EQ(1U, forms.size()); |
| 1221 | 1221 |
| 1222 // Set the auto-filled attribute. | 1222 // Set the auto-filled attribute. |
| 1223 WebInputElement firstname = GetInputElementById("firstname"); | 1223 WebInputElement firstname = GetInputElementById("firstname"); |
| 1224 firstname.SetAutofilled(true); | 1224 firstname.SetAutofilled(true); |
| 1225 WebInputElement lastname = GetInputElementById("lastname"); | 1225 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 expected.autocomplete_attribute.clear(); | 1308 expected.autocomplete_attribute.clear(); |
| 1309 | 1309 |
| 1310 // Verify that the cursor position has been updated. | 1310 // Verify that the cursor position has been updated. |
| 1311 EXPECT_EQ(0, firstname.SelectionStart()); | 1311 EXPECT_EQ(0, firstname.SelectionStart()); |
| 1312 EXPECT_EQ(0, firstname.SelectionEnd()); | 1312 EXPECT_EQ(0, firstname.SelectionEnd()); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 void TestClearFormWithNodeContainingSelectOne(const char* html, | 1315 void TestClearFormWithNodeContainingSelectOne(const char* html, |
| 1316 bool unowned) { | 1316 bool unowned) { |
| 1317 LoadHTML(html); | 1317 LoadHTML(html); |
| 1318 WebFrame* web_frame = GetMainFrame(); | 1318 WebLocalFrame* web_frame = GetMainFrame(); |
| 1319 ASSERT_NE(nullptr, web_frame); | 1319 ASSERT_NE(nullptr, web_frame); |
| 1320 | 1320 |
| 1321 FormCache form_cache(*web_frame); | 1321 FormCache form_cache(*web_frame); |
| 1322 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1322 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1323 ASSERT_EQ(1U, forms.size()); | 1323 ASSERT_EQ(1U, forms.size()); |
| 1324 | 1324 |
| 1325 // Set the auto-filled attribute. | 1325 // Set the auto-filled attribute. |
| 1326 WebInputElement firstname = GetInputElementById("firstname"); | 1326 WebInputElement firstname = GetInputElementById("firstname"); |
| 1327 firstname.SetAutofilled(true); | 1327 firstname.SetAutofilled(true); |
| 1328 WebInputElement lastname = GetInputElementById("lastname"); | 1328 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 expected.max_length = 0; | 1376 expected.max_length = 0; |
| 1377 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 1377 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1378 | 1378 |
| 1379 // Verify that the cursor position has been updated. | 1379 // Verify that the cursor position has been updated. |
| 1380 EXPECT_EQ(0, firstname.SelectionStart()); | 1380 EXPECT_EQ(0, firstname.SelectionStart()); |
| 1381 EXPECT_EQ(0, firstname.SelectionEnd()); | 1381 EXPECT_EQ(0, firstname.SelectionEnd()); |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 void TestClearPreviewedFormWithElement(const char* html) { | 1384 void TestClearPreviewedFormWithElement(const char* html) { |
| 1385 LoadHTML(html); | 1385 LoadHTML(html); |
| 1386 WebFrame* web_frame = GetMainFrame(); | 1386 WebLocalFrame* web_frame = GetMainFrame(); |
| 1387 ASSERT_NE(nullptr, web_frame); | 1387 ASSERT_NE(nullptr, web_frame); |
| 1388 | 1388 |
| 1389 FormCache form_cache(*web_frame); | 1389 FormCache form_cache(*web_frame); |
| 1390 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1390 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1391 ASSERT_EQ(1U, forms.size()); | 1391 ASSERT_EQ(1U, forms.size()); |
| 1392 | 1392 |
| 1393 // Set the auto-filled attribute. | 1393 // Set the auto-filled attribute. |
| 1394 WebInputElement firstname = GetInputElementById("firstname"); | 1394 WebInputElement firstname = GetInputElementById("firstname"); |
| 1395 firstname.SetAutofilled(true); | 1395 firstname.SetAutofilled(true); |
| 1396 WebInputElement lastname = GetInputElementById("lastname"); | 1396 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); | 1430 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); |
| 1431 EXPECT_FALSE(phone.IsAutofilled()); | 1431 EXPECT_FALSE(phone.IsAutofilled()); |
| 1432 | 1432 |
| 1433 // Verify that the cursor position has been updated. | 1433 // Verify that the cursor position has been updated. |
| 1434 EXPECT_EQ(0, lastname.SelectionStart()); | 1434 EXPECT_EQ(0, lastname.SelectionStart()); |
| 1435 EXPECT_EQ(0, lastname.SelectionEnd()); | 1435 EXPECT_EQ(0, lastname.SelectionEnd()); |
| 1436 } | 1436 } |
| 1437 | 1437 |
| 1438 void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html) { | 1438 void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html) { |
| 1439 LoadHTML(html); | 1439 LoadHTML(html); |
| 1440 WebFrame* web_frame = GetMainFrame(); | 1440 WebLocalFrame* web_frame = GetMainFrame(); |
| 1441 ASSERT_NE(nullptr, web_frame); | 1441 ASSERT_NE(nullptr, web_frame); |
| 1442 | 1442 |
| 1443 FormCache form_cache(*web_frame); | 1443 FormCache form_cache(*web_frame); |
| 1444 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1444 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1445 ASSERT_EQ(1U, forms.size()); | 1445 ASSERT_EQ(1U, forms.size()); |
| 1446 | 1446 |
| 1447 // Set the auto-filled attribute. | 1447 // Set the auto-filled attribute. |
| 1448 WebInputElement firstname = GetInputElementById("firstname"); | 1448 WebInputElement firstname = GetInputElementById("firstname"); |
| 1449 firstname.SetAutofilled(true); | 1449 firstname.SetAutofilled(true); |
| 1450 WebInputElement lastname = GetInputElementById("lastname"); | 1450 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 EXPECT_TRUE(email2.Value().IsEmpty()); | 1483 EXPECT_TRUE(email2.Value().IsEmpty()); |
| 1484 EXPECT_TRUE(email2.SuggestedValue().IsEmpty()); | 1484 EXPECT_TRUE(email2.SuggestedValue().IsEmpty()); |
| 1485 EXPECT_FALSE(email2.IsAutofilled()); | 1485 EXPECT_FALSE(email2.IsAutofilled()); |
| 1486 EXPECT_TRUE(phone.Value().IsEmpty()); | 1486 EXPECT_TRUE(phone.Value().IsEmpty()); |
| 1487 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); | 1487 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); |
| 1488 EXPECT_FALSE(phone.IsAutofilled()); | 1488 EXPECT_FALSE(phone.IsAutofilled()); |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html) { | 1491 void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html) { |
| 1492 LoadHTML(html); | 1492 LoadHTML(html); |
| 1493 WebFrame* web_frame = GetMainFrame(); | 1493 WebLocalFrame* web_frame = GetMainFrame(); |
| 1494 ASSERT_NE(nullptr, web_frame); | 1494 ASSERT_NE(nullptr, web_frame); |
| 1495 | 1495 |
| 1496 FormCache form_cache(*web_frame); | 1496 FormCache form_cache(*web_frame); |
| 1497 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1497 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1498 ASSERT_EQ(1U, forms.size()); | 1498 ASSERT_EQ(1U, forms.size()); |
| 1499 | 1499 |
| 1500 // Set the auto-filled attribute. | 1500 // Set the auto-filled attribute. |
| 1501 WebInputElement firstname = GetInputElementById("firstname"); | 1501 WebInputElement firstname = GetInputElementById("firstname"); |
| 1502 firstname.SetAutofilled(true); | 1502 firstname.SetAutofilled(true); |
| 1503 WebInputElement lastname = GetInputElementById("lastname"); | 1503 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 EXPECT_TRUE(email2.SuggestedValue().IsEmpty()); | 1537 EXPECT_TRUE(email2.SuggestedValue().IsEmpty()); |
| 1538 EXPECT_FALSE(email2.IsAutofilled()); | 1538 EXPECT_FALSE(email2.IsAutofilled()); |
| 1539 EXPECT_TRUE(phone.Value().IsEmpty()); | 1539 EXPECT_TRUE(phone.Value().IsEmpty()); |
| 1540 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); | 1540 EXPECT_TRUE(phone.SuggestedValue().IsEmpty()); |
| 1541 EXPECT_FALSE(phone.IsAutofilled()); | 1541 EXPECT_FALSE(phone.IsAutofilled()); |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 void TestClearOnlyAutofilledFields(const char* html) { | 1544 void TestClearOnlyAutofilledFields(const char* html) { |
| 1545 LoadHTML(html); | 1545 LoadHTML(html); |
| 1546 | 1546 |
| 1547 WebFrame* web_frame = GetMainFrame(); | 1547 WebLocalFrame* web_frame = GetMainFrame(); |
| 1548 ASSERT_NE(nullptr, web_frame); | 1548 ASSERT_NE(nullptr, web_frame); |
| 1549 | 1549 |
| 1550 FormCache form_cache(*web_frame); | 1550 FormCache form_cache(*web_frame); |
| 1551 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1551 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1552 ASSERT_EQ(1U, forms.size()); | 1552 ASSERT_EQ(1U, forms.size()); |
| 1553 | 1553 |
| 1554 // Set the autofilled attribute. | 1554 // Set the autofilled attribute. |
| 1555 WebInputElement firstname = GetInputElementById("firstname"); | 1555 WebInputElement firstname = GetInputElementById("firstname"); |
| 1556 firstname.SetAutofilled(false); | 1556 firstname.SetAutofilled(false); |
| 1557 WebInputElement lastname = GetInputElementById("lastname"); | 1557 WebInputElement lastname = GetInputElementById("lastname"); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 } | 1606 } |
| 1607 | 1607 |
| 1608 private: | 1608 private: |
| 1609 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); | 1609 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); |
| 1610 }; | 1610 }; |
| 1611 | 1611 |
| 1612 // We should be able to extract a normal text field. | 1612 // We should be able to extract a normal text field. |
| 1613 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { | 1613 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { |
| 1614 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 1614 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
| 1615 | 1615 |
| 1616 WebFrame* frame = GetMainFrame(); | 1616 WebLocalFrame* frame = GetMainFrame(); |
| 1617 ASSERT_NE(nullptr, frame); | 1617 ASSERT_NE(nullptr, frame); |
| 1618 | 1618 |
| 1619 WebFormControlElement element = GetFormControlElementById("element"); | 1619 WebFormControlElement element = GetFormControlElementById("element"); |
| 1620 FormFieldData result1; | 1620 FormFieldData result1; |
| 1621 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, &result1); | 1621 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, &result1); |
| 1622 | 1622 |
| 1623 FormFieldData expected; | 1623 FormFieldData expected; |
| 1624 expected.form_control_type = "text"; | 1624 expected.form_control_type = "text"; |
| 1625 expected.max_length = WebInputElement::DefaultMaxLength(); | 1625 expected.max_length = WebInputElement::DefaultMaxLength(); |
| 1626 | 1626 |
| 1627 expected.name = ASCIIToUTF16("element"); | 1627 expected.name = ASCIIToUTF16("element"); |
| 1628 expected.value.clear(); | 1628 expected.value.clear(); |
| 1629 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 1629 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 1630 | 1630 |
| 1631 FormFieldData result2; | 1631 FormFieldData result2; |
| 1632 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result2); | 1632 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result2); |
| 1633 | 1633 |
| 1634 expected.name = ASCIIToUTF16("element"); | 1634 expected.name = ASCIIToUTF16("element"); |
| 1635 expected.value = ASCIIToUTF16("value"); | 1635 expected.value = ASCIIToUTF16("value"); |
| 1636 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | 1636 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 // We should be able to extract a text field with autocomplete="off". | 1639 // We should be able to extract a text field with autocomplete="off". |
| 1640 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { | 1640 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { |
| 1641 LoadHTML("<INPUT type='text' id='element' value='value'" | 1641 LoadHTML("<INPUT type='text' id='element' value='value'" |
| 1642 " autocomplete='off'/>"); | 1642 " autocomplete='off'/>"); |
| 1643 | 1643 |
| 1644 WebFrame* frame = GetMainFrame(); | 1644 WebLocalFrame* frame = GetMainFrame(); |
| 1645 ASSERT_NE(nullptr, frame); | 1645 ASSERT_NE(nullptr, frame); |
| 1646 | 1646 |
| 1647 WebFormControlElement element = GetFormControlElementById("element"); | 1647 WebFormControlElement element = GetFormControlElementById("element"); |
| 1648 FormFieldData result; | 1648 FormFieldData result; |
| 1649 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1649 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1650 | 1650 |
| 1651 FormFieldData expected; | 1651 FormFieldData expected; |
| 1652 expected.name = ASCIIToUTF16("element"); | 1652 expected.name = ASCIIToUTF16("element"); |
| 1653 expected.value = ASCIIToUTF16("value"); | 1653 expected.value = ASCIIToUTF16("value"); |
| 1654 expected.form_control_type = "text"; | 1654 expected.form_control_type = "text"; |
| 1655 expected.autocomplete_attribute = "off"; | 1655 expected.autocomplete_attribute = "off"; |
| 1656 expected.max_length = WebInputElement::DefaultMaxLength(); | 1656 expected.max_length = WebInputElement::DefaultMaxLength(); |
| 1657 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1657 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 // We should be able to extract a text field with maxlength specified. | 1660 // We should be able to extract a text field with maxlength specified. |
| 1661 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 1661 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
| 1662 LoadHTML("<INPUT type='text' id='element' value='value'" | 1662 LoadHTML("<INPUT type='text' id='element' value='value'" |
| 1663 " maxlength='5'/>"); | 1663 " maxlength='5'/>"); |
| 1664 | 1664 |
| 1665 WebFrame* frame = GetMainFrame(); | 1665 WebLocalFrame* frame = GetMainFrame(); |
| 1666 ASSERT_NE(nullptr, frame); | 1666 ASSERT_NE(nullptr, frame); |
| 1667 | 1667 |
| 1668 WebFormControlElement element = GetFormControlElementById("element"); | 1668 WebFormControlElement element = GetFormControlElementById("element"); |
| 1669 FormFieldData result; | 1669 FormFieldData result; |
| 1670 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1670 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1671 | 1671 |
| 1672 FormFieldData expected; | 1672 FormFieldData expected; |
| 1673 expected.name = ASCIIToUTF16("element"); | 1673 expected.name = ASCIIToUTF16("element"); |
| 1674 expected.value = ASCIIToUTF16("value"); | 1674 expected.value = ASCIIToUTF16("value"); |
| 1675 expected.form_control_type = "text"; | 1675 expected.form_control_type = "text"; |
| 1676 expected.max_length = 5; | 1676 expected.max_length = 5; |
| 1677 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1677 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1678 } | 1678 } |
| 1679 | 1679 |
| 1680 // We should be able to extract a text field that has been autofilled. | 1680 // We should be able to extract a text field that has been autofilled. |
| 1681 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 1681 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
| 1682 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 1682 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
| 1683 | 1683 |
| 1684 WebFrame* frame = GetMainFrame(); | 1684 WebLocalFrame* frame = GetMainFrame(); |
| 1685 ASSERT_NE(nullptr, frame); | 1685 ASSERT_NE(nullptr, frame); |
| 1686 | 1686 |
| 1687 WebInputElement element = GetInputElementById("element"); | 1687 WebInputElement element = GetInputElementById("element"); |
| 1688 element.SetAutofilled(true); | 1688 element.SetAutofilled(true); |
| 1689 FormFieldData result; | 1689 FormFieldData result; |
| 1690 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1690 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1691 | 1691 |
| 1692 FormFieldData expected; | 1692 FormFieldData expected; |
| 1693 expected.name = ASCIIToUTF16("element"); | 1693 expected.name = ASCIIToUTF16("element"); |
| 1694 expected.value = ASCIIToUTF16("value"); | 1694 expected.value = ASCIIToUTF16("value"); |
| 1695 expected.form_control_type = "text"; | 1695 expected.form_control_type = "text"; |
| 1696 expected.max_length = WebInputElement::DefaultMaxLength(); | 1696 expected.max_length = WebInputElement::DefaultMaxLength(); |
| 1697 expected.is_autofilled = true; | 1697 expected.is_autofilled = true; |
| 1698 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1698 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 // We should be able to extract a radio or a checkbox field that has been | 1701 // We should be able to extract a radio or a checkbox field that has been |
| 1702 // autofilled. | 1702 // autofilled. |
| 1703 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { | 1703 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
| 1704 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" | 1704 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" |
| 1705 "<INPUT type='radio' id='radio' value='male'/>"); | 1705 "<INPUT type='radio' id='radio' value='male'/>"); |
| 1706 | 1706 |
| 1707 WebFrame* frame = GetMainFrame(); | 1707 WebLocalFrame* frame = GetMainFrame(); |
| 1708 ASSERT_NE(nullptr, frame); | 1708 ASSERT_NE(nullptr, frame); |
| 1709 | 1709 |
| 1710 WebInputElement element = GetInputElementById("checkbox"); | 1710 WebInputElement element = GetInputElementById("checkbox"); |
| 1711 element.SetAutofilled(true); | 1711 element.SetAutofilled(true); |
| 1712 FormFieldData result; | 1712 FormFieldData result; |
| 1713 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1713 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1714 | 1714 |
| 1715 FormFieldData expected; | 1715 FormFieldData expected; |
| 1716 expected.name = ASCIIToUTF16("checkbox"); | 1716 expected.name = ASCIIToUTF16("checkbox"); |
| 1717 expected.value = ASCIIToUTF16("mail"); | 1717 expected.value = ASCIIToUTF16("mail"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1731 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1731 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1732 } | 1732 } |
| 1733 | 1733 |
| 1734 // We should be able to extract a <select> field. | 1734 // We should be able to extract a <select> field. |
| 1735 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 1735 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
| 1736 LoadHTML("<SELECT id='element'/>" | 1736 LoadHTML("<SELECT id='element'/>" |
| 1737 " <OPTION value='CA'>California</OPTION>" | 1737 " <OPTION value='CA'>California</OPTION>" |
| 1738 " <OPTION value='TX'>Texas</OPTION>" | 1738 " <OPTION value='TX'>Texas</OPTION>" |
| 1739 "</SELECT>"); | 1739 "</SELECT>"); |
| 1740 | 1740 |
| 1741 WebFrame* frame = GetMainFrame(); | 1741 WebLocalFrame* frame = GetMainFrame(); |
| 1742 ASSERT_NE(nullptr, frame); | 1742 ASSERT_NE(nullptr, frame); |
| 1743 | 1743 |
| 1744 WebFormControlElement element = GetFormControlElementById("element"); | 1744 WebFormControlElement element = GetFormControlElementById("element"); |
| 1745 FormFieldData result1; | 1745 FormFieldData result1; |
| 1746 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1); | 1746 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1); |
| 1747 | 1747 |
| 1748 FormFieldData expected; | 1748 FormFieldData expected; |
| 1749 expected.name = ASCIIToUTF16("element"); | 1749 expected.name = ASCIIToUTF16("element"); |
| 1750 expected.max_length = 0; | 1750 expected.max_length = 0; |
| 1751 expected.form_control_type = "select-one"; | 1751 expected.form_control_type = "select-one"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1774 } | 1774 } |
| 1775 | 1775 |
| 1776 // We copy extra attributes for the select field. | 1776 // We copy extra attributes for the select field. |
| 1777 TEST_F(FormAutofillTest, | 1777 TEST_F(FormAutofillTest, |
| 1778 WebFormControlElementToFormFieldSelect_ExtraAttributes) { | 1778 WebFormControlElementToFormFieldSelect_ExtraAttributes) { |
| 1779 LoadHTML("<SELECT id='element' autocomplete='off'/>" | 1779 LoadHTML("<SELECT id='element' autocomplete='off'/>" |
| 1780 " <OPTION value='CA'>California</OPTION>" | 1780 " <OPTION value='CA'>California</OPTION>" |
| 1781 " <OPTION value='TX'>Texas</OPTION>" | 1781 " <OPTION value='TX'>Texas</OPTION>" |
| 1782 "</SELECT>"); | 1782 "</SELECT>"); |
| 1783 | 1783 |
| 1784 WebFrame* frame = GetMainFrame(); | 1784 WebLocalFrame* frame = GetMainFrame(); |
| 1785 ASSERT_NE(nullptr, frame); | 1785 ASSERT_NE(nullptr, frame); |
| 1786 | 1786 |
| 1787 WebFormControlElement element = GetFormControlElementById("element"); | 1787 WebFormControlElement element = GetFormControlElementById("element"); |
| 1788 element.SetAutofilled(true); | 1788 element.SetAutofilled(true); |
| 1789 | 1789 |
| 1790 FormFieldData result1; | 1790 FormFieldData result1; |
| 1791 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1); | 1791 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result1); |
| 1792 | 1792 |
| 1793 FormFieldData expected; | 1793 FormFieldData expected; |
| 1794 expected.name = ASCIIToUTF16("element"); | 1794 expected.name = ASCIIToUTF16("element"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1809 // reasonable number. | 1809 // reasonable number. |
| 1810 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { | 1810 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) { |
| 1811 std::string html = "<SELECT id='element'/>"; | 1811 std::string html = "<SELECT id='element'/>"; |
| 1812 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { | 1812 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { |
| 1813 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" | 1813 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" |
| 1814 "%" PRIuS "</OPTION>", i, i); | 1814 "%" PRIuS "</OPTION>", i, i); |
| 1815 } | 1815 } |
| 1816 html += "</SELECT>"; | 1816 html += "</SELECT>"; |
| 1817 LoadHTML(html.c_str()); | 1817 LoadHTML(html.c_str()); |
| 1818 | 1818 |
| 1819 WebFrame* frame = GetMainFrame(); | 1819 WebLocalFrame* frame = GetMainFrame(); |
| 1820 ASSERT_TRUE(frame); | 1820 ASSERT_TRUE(frame); |
| 1821 | 1821 |
| 1822 WebFormControlElement element = GetFormControlElementById("element"); | 1822 WebFormControlElement element = GetFormControlElementById("element"); |
| 1823 FormFieldData result; | 1823 FormFieldData result; |
| 1824 WebFormControlElementToFormField(element, nullptr, EXTRACT_OPTIONS, &result); | 1824 WebFormControlElementToFormField(element, nullptr, EXTRACT_OPTIONS, &result); |
| 1825 | 1825 |
| 1826 EXPECT_TRUE(result.option_values.empty()); | 1826 EXPECT_TRUE(result.option_values.empty()); |
| 1827 EXPECT_TRUE(result.option_contents.empty()); | 1827 EXPECT_TRUE(result.option_contents.empty()); |
| 1828 } | 1828 } |
| 1829 | 1829 |
| 1830 // We should be able to extract a <textarea> field. | 1830 // We should be able to extract a <textarea> field. |
| 1831 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { | 1831 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { |
| 1832 LoadHTML("<TEXTAREA id='element'>" | 1832 LoadHTML("<TEXTAREA id='element'>" |
| 1833 "This element's value " | 1833 "This element's value " |
| 1834 "spans multiple lines." | 1834 "spans multiple lines." |
| 1835 "</TEXTAREA>"); | 1835 "</TEXTAREA>"); |
| 1836 | 1836 |
| 1837 WebFrame* frame = GetMainFrame(); | 1837 WebLocalFrame* frame = GetMainFrame(); |
| 1838 ASSERT_NE(nullptr, frame); | 1838 ASSERT_NE(nullptr, frame); |
| 1839 | 1839 |
| 1840 WebFormControlElement element = GetFormControlElementById("element"); | 1840 WebFormControlElement element = GetFormControlElementById("element"); |
| 1841 FormFieldData result_sans_value; | 1841 FormFieldData result_sans_value; |
| 1842 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, | 1842 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, |
| 1843 &result_sans_value); | 1843 &result_sans_value); |
| 1844 | 1844 |
| 1845 FormFieldData expected; | 1845 FormFieldData expected; |
| 1846 expected.name = ASCIIToUTF16("element"); | 1846 expected.name = ASCIIToUTF16("element"); |
| 1847 expected.max_length = 0; | 1847 expected.max_length = 0; |
| 1848 expected.form_control_type = "textarea"; | 1848 expected.form_control_type = "textarea"; |
| 1849 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 1849 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
| 1850 | 1850 |
| 1851 FormFieldData result_with_value; | 1851 FormFieldData result_with_value; |
| 1852 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, | 1852 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, |
| 1853 &result_with_value); | 1853 &result_with_value); |
| 1854 expected.value = ASCIIToUTF16("This element's value\n" | 1854 expected.value = ASCIIToUTF16("This element's value\n" |
| 1855 "spans multiple lines."); | 1855 "spans multiple lines."); |
| 1856 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 1856 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
| 1857 } | 1857 } |
| 1858 | 1858 |
| 1859 // We should be able to extract an <input type="month"> field. | 1859 // We should be able to extract an <input type="month"> field. |
| 1860 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { | 1860 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { |
| 1861 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); | 1861 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); |
| 1862 | 1862 |
| 1863 WebFrame* frame = GetMainFrame(); | 1863 WebLocalFrame* frame = GetMainFrame(); |
| 1864 ASSERT_NE(nullptr, frame); | 1864 ASSERT_NE(nullptr, frame); |
| 1865 | 1865 |
| 1866 WebFormControlElement element = GetFormControlElementById("element"); | 1866 WebFormControlElement element = GetFormControlElementById("element"); |
| 1867 FormFieldData result_sans_value; | 1867 FormFieldData result_sans_value; |
| 1868 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, | 1868 WebFormControlElementToFormField(element, nullptr, EXTRACT_NONE, |
| 1869 &result_sans_value); | 1869 &result_sans_value); |
| 1870 | 1870 |
| 1871 FormFieldData expected; | 1871 FormFieldData expected; |
| 1872 expected.name = ASCIIToUTF16("element"); | 1872 expected.name = ASCIIToUTF16("element"); |
| 1873 expected.max_length = 0; | 1873 expected.max_length = 0; |
| 1874 expected.form_control_type = "month"; | 1874 expected.form_control_type = "month"; |
| 1875 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 1875 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
| 1876 | 1876 |
| 1877 FormFieldData result_with_value; | 1877 FormFieldData result_with_value; |
| 1878 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, | 1878 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, |
| 1879 &result_with_value); | 1879 &result_with_value); |
| 1880 expected.value = ASCIIToUTF16("2011-12"); | 1880 expected.value = ASCIIToUTF16("2011-12"); |
| 1881 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 1881 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
| 1882 } | 1882 } |
| 1883 | 1883 |
| 1884 // We should not extract the value for non-text and non-select fields. | 1884 // We should not extract the value for non-text and non-select fields. |
| 1885 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 1885 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
| 1886 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1886 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 1887 " <INPUT type='hidden' id='hidden' value='apple'/>" | 1887 " <INPUT type='hidden' id='hidden' value='apple'/>" |
| 1888 " <INPUT type='submit' id='submit' value='Send'/>" | 1888 " <INPUT type='submit' id='submit' value='Send'/>" |
| 1889 "</FORM>"); | 1889 "</FORM>"); |
| 1890 | 1890 |
| 1891 WebFrame* frame = GetMainFrame(); | 1891 WebLocalFrame* frame = GetMainFrame(); |
| 1892 ASSERT_NE(nullptr, frame); | 1892 ASSERT_NE(nullptr, frame); |
| 1893 | 1893 |
| 1894 WebFormControlElement element = GetFormControlElementById("hidden"); | 1894 WebFormControlElement element = GetFormControlElementById("hidden"); |
| 1895 FormFieldData result; | 1895 FormFieldData result; |
| 1896 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1896 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1897 | 1897 |
| 1898 FormFieldData expected; | 1898 FormFieldData expected; |
| 1899 expected.max_length = 0; | 1899 expected.max_length = 0; |
| 1900 | 1900 |
| 1901 expected.name = ASCIIToUTF16("hidden"); | 1901 expected.name = ASCIIToUTF16("hidden"); |
| 1902 expected.form_control_type = "hidden"; | 1902 expected.form_control_type = "hidden"; |
| 1903 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1903 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1904 | 1904 |
| 1905 element = GetFormControlElementById("submit"); | 1905 element = GetFormControlElementById("submit"); |
| 1906 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1906 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1907 expected.name = ASCIIToUTF16("submit"); | 1907 expected.name = ASCIIToUTF16("submit"); |
| 1908 expected.form_control_type = "submit"; | 1908 expected.form_control_type = "submit"; |
| 1909 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 1909 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 1910 } | 1910 } |
| 1911 | 1911 |
| 1912 // We should be able to extract password fields. | 1912 // We should be able to extract password fields. |
| 1913 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { | 1913 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { |
| 1914 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1914 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 1915 " <INPUT type='password' id='password' value='secret'/>" | 1915 " <INPUT type='password' id='password' value='secret'/>" |
| 1916 "</FORM>"); | 1916 "</FORM>"); |
| 1917 | 1917 |
| 1918 WebFrame* frame = GetMainFrame(); | 1918 WebLocalFrame* frame = GetMainFrame(); |
| 1919 ASSERT_NE(nullptr, frame); | 1919 ASSERT_NE(nullptr, frame); |
| 1920 | 1920 |
| 1921 WebFormControlElement element = GetFormControlElementById("password"); | 1921 WebFormControlElement element = GetFormControlElementById("password"); |
| 1922 FormFieldData result; | 1922 FormFieldData result; |
| 1923 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 1923 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 1924 | 1924 |
| 1925 FormFieldData expected; | 1925 FormFieldData expected; |
| 1926 expected.max_length = WebInputElement::DefaultMaxLength(); | 1926 expected.max_length = WebInputElement::DefaultMaxLength(); |
| 1927 expected.name = ASCIIToUTF16("password"); | 1927 expected.name = ASCIIToUTF16("password"); |
| 1928 expected.form_control_type = "password"; | 1928 expected.form_control_type = "password"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1947 "</SELECT>" | 1947 "</SELECT>" |
| 1948 "<TEXTAREA id='textarea' autocomplete='street-address'>" | 1948 "<TEXTAREA id='textarea' autocomplete='street-address'>" |
| 1949 " Some multi-" | 1949 " Some multi-" |
| 1950 " lined value" | 1950 " lined value" |
| 1951 "</TEXTAREA>"; | 1951 "</TEXTAREA>"; |
| 1952 html += | 1952 html += |
| 1953 "<INPUT type='text' id='malicious' autocomplete='" + | 1953 "<INPUT type='text' id='malicious' autocomplete='" + |
| 1954 std::string(10000, 'x') + "'/>"; | 1954 std::string(10000, 'x') + "'/>"; |
| 1955 LoadHTML(html.c_str()); | 1955 LoadHTML(html.c_str()); |
| 1956 | 1956 |
| 1957 WebFrame* frame = GetMainFrame(); | 1957 WebLocalFrame* frame = GetMainFrame(); |
| 1958 ASSERT_NE(nullptr, frame); | 1958 ASSERT_NE(nullptr, frame); |
| 1959 | 1959 |
| 1960 struct TestCase { | 1960 struct TestCase { |
| 1961 const std::string element_id; | 1961 const std::string element_id; |
| 1962 const std::string form_control_type; | 1962 const std::string form_control_type; |
| 1963 const std::string autocomplete_attribute; | 1963 const std::string autocomplete_attribute; |
| 1964 }; | 1964 }; |
| 1965 TestCase test_cases[] = { | 1965 TestCase test_cases[] = { |
| 1966 // An absent attribute is equivalent to an empty one. | 1966 // An absent attribute is equivalent to an empty one. |
| 1967 { "absent", "text", "" }, | 1967 { "absent", "text", "" }, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 2010 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 2011 } | 2011 } |
| 2012 } | 2012 } |
| 2013 | 2013 |
| 2014 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { | 2014 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { |
| 2015 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" | 2015 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" |
| 2016 "<FORM>" | 2016 "<FORM>" |
| 2017 " <INPUT type='text' id='element'>" | 2017 " <INPUT type='text' id='element'>" |
| 2018 "</FORM>"); | 2018 "</FORM>"); |
| 2019 | 2019 |
| 2020 WebFrame* frame = GetMainFrame(); | 2020 WebLocalFrame* frame = GetMainFrame(); |
| 2021 ASSERT_NE(nullptr, frame); | 2021 ASSERT_NE(nullptr, frame); |
| 2022 | 2022 |
| 2023 WebFormControlElement element = GetFormControlElementById("element"); | 2023 WebFormControlElement element = GetFormControlElementById("element"); |
| 2024 | 2024 |
| 2025 FormFieldData result; | 2025 FormFieldData result; |
| 2026 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2026 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2027 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2027 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2028 } | 2028 } |
| 2029 | 2029 |
| 2030 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { | 2030 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { |
| 2031 LoadHTML("<FORM>" | 2031 LoadHTML("<FORM>" |
| 2032 " <INPUT dir='rtl' type='text' id='element'/>" | 2032 " <INPUT dir='rtl' type='text' id='element'/>" |
| 2033 "</FORM>"); | 2033 "</FORM>"); |
| 2034 | 2034 |
| 2035 WebFrame* frame = GetMainFrame(); | 2035 WebLocalFrame* frame = GetMainFrame(); |
| 2036 ASSERT_NE(nullptr, frame); | 2036 ASSERT_NE(nullptr, frame); |
| 2037 | 2037 |
| 2038 WebFormControlElement element = GetFormControlElementById("element"); | 2038 WebFormControlElement element = GetFormControlElementById("element"); |
| 2039 | 2039 |
| 2040 FormFieldData result; | 2040 FormFieldData result; |
| 2041 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2041 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2042 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2042 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { | 2045 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { |
| 2046 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" | 2046 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" |
| 2047 "<FORM>" | 2047 "<FORM>" |
| 2048 " <INPUT type='text' id='element'/>" | 2048 " <INPUT type='text' id='element'/>" |
| 2049 "</FORM>"); | 2049 "</FORM>"); |
| 2050 | 2050 |
| 2051 WebFrame* frame = GetMainFrame(); | 2051 WebLocalFrame* frame = GetMainFrame(); |
| 2052 ASSERT_NE(nullptr, frame); | 2052 ASSERT_NE(nullptr, frame); |
| 2053 | 2053 |
| 2054 WebFormControlElement element = GetFormControlElementById("element"); | 2054 WebFormControlElement element = GetFormControlElementById("element"); |
| 2055 | 2055 |
| 2056 FormFieldData result; | 2056 FormFieldData result; |
| 2057 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2057 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2058 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2058 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2059 } | 2059 } |
| 2060 | 2060 |
| 2061 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { | 2061 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { |
| 2062 LoadHTML("<FORM dir='rtl'>" | 2062 LoadHTML("<FORM dir='rtl'>" |
| 2063 " <INPUT type='text' id='element'/>" | 2063 " <INPUT type='text' id='element'/>" |
| 2064 "</FORM>"); | 2064 "</FORM>"); |
| 2065 | 2065 |
| 2066 WebFrame* frame = GetMainFrame(); | 2066 WebLocalFrame* frame = GetMainFrame(); |
| 2067 ASSERT_NE(nullptr, frame); | 2067 ASSERT_NE(nullptr, frame); |
| 2068 | 2068 |
| 2069 WebFormControlElement element = GetFormControlElementById("element"); | 2069 WebFormControlElement element = GetFormControlElementById("element"); |
| 2070 | 2070 |
| 2071 FormFieldData result; | 2071 FormFieldData result; |
| 2072 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2072 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2073 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2073 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2074 } | 2074 } |
| 2075 | 2075 |
| 2076 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { | 2076 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { |
| 2077 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" | 2077 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" |
| 2078 "<FORM dir='rtl'>" | 2078 "<FORM dir='rtl'>" |
| 2079 " <INPUT type='text' id='element'/>" | 2079 " <INPUT type='text' id='element'/>" |
| 2080 "</FORM>"); | 2080 "</FORM>"); |
| 2081 | 2081 |
| 2082 WebFrame* frame = GetMainFrame(); | 2082 WebLocalFrame* frame = GetMainFrame(); |
| 2083 ASSERT_NE(nullptr, frame); | 2083 ASSERT_NE(nullptr, frame); |
| 2084 | 2084 |
| 2085 WebFormControlElement element = GetFormControlElementById("element"); | 2085 WebFormControlElement element = GetFormControlElementById("element"); |
| 2086 | 2086 |
| 2087 FormFieldData result; | 2087 FormFieldData result; |
| 2088 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2088 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2089 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 2089 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 2090 } | 2090 } |
| 2091 | 2091 |
| 2092 TEST_F(FormAutofillTest, TextAlignOverridesDirection) { | 2092 TEST_F(FormAutofillTest, TextAlignOverridesDirection) { |
| 2093 // text-align: right | 2093 // text-align: right |
| 2094 LoadHTML("<STYLE>input{direction:ltr;text-align:right}</STYLE>" | 2094 LoadHTML("<STYLE>input{direction:ltr;text-align:right}</STYLE>" |
| 2095 "<FORM>" | 2095 "<FORM>" |
| 2096 " <INPUT type='text' id='element'/>" | 2096 " <INPUT type='text' id='element'/>" |
| 2097 "</FORM>"); | 2097 "</FORM>"); |
| 2098 | 2098 |
| 2099 WebFrame* frame = GetMainFrame(); | 2099 WebLocalFrame* frame = GetMainFrame(); |
| 2100 ASSERT_NE(nullptr, frame); | 2100 ASSERT_NE(nullptr, frame); |
| 2101 | 2101 |
| 2102 WebFormControlElement element = GetFormControlElementById("element"); | 2102 WebFormControlElement element = GetFormControlElementById("element"); |
| 2103 | 2103 |
| 2104 FormFieldData result; | 2104 FormFieldData result; |
| 2105 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2105 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2106 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2106 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2107 | 2107 |
| 2108 // text-align: left | 2108 // text-align: left |
| 2109 LoadHTML("<STYLE>input{direction:rtl;text-align:left}</STYLE>" | 2109 LoadHTML("<STYLE>input{direction:rtl;text-align:left}</STYLE>" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2120 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 2120 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 2121 } | 2121 } |
| 2122 | 2122 |
| 2123 TEST_F(FormAutofillTest, | 2123 TEST_F(FormAutofillTest, |
| 2124 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { | 2124 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { |
| 2125 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" | 2125 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" |
| 2126 "<FORM dir='rtl'>" | 2126 "<FORM dir='rtl'>" |
| 2127 " <INPUT type='text' id='element'/>" | 2127 " <INPUT type='text' id='element'/>" |
| 2128 "</FORM>"); | 2128 "</FORM>"); |
| 2129 | 2129 |
| 2130 WebFrame* frame = GetMainFrame(); | 2130 WebLocalFrame* frame = GetMainFrame(); |
| 2131 ASSERT_NE(nullptr, frame); | 2131 ASSERT_NE(nullptr, frame); |
| 2132 | 2132 |
| 2133 WebFormControlElement element = GetFormControlElementById("element"); | 2133 WebFormControlElement element = GetFormControlElementById("element"); |
| 2134 | 2134 |
| 2135 FormFieldData result; | 2135 FormFieldData result; |
| 2136 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2136 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2137 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 2137 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 2138 } | 2138 } |
| 2139 | 2139 |
| 2140 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { | 2140 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { |
| 2141 LoadHTML("<FORM style='direction:ltr'>" | 2141 LoadHTML("<FORM style='direction:ltr'>" |
| 2142 " <SPAN dir='rtl'>" | 2142 " <SPAN dir='rtl'>" |
| 2143 " <INPUT type='text' id='element'/>" | 2143 " <INPUT type='text' id='element'/>" |
| 2144 " </SPAN>" | 2144 " </SPAN>" |
| 2145 "</FORM>"); | 2145 "</FORM>"); |
| 2146 | 2146 |
| 2147 WebFrame* frame = GetMainFrame(); | 2147 WebLocalFrame* frame = GetMainFrame(); |
| 2148 ASSERT_NE(nullptr, frame); | 2148 ASSERT_NE(nullptr, frame); |
| 2149 | 2149 |
| 2150 WebFormControlElement element = GetFormControlElementById("element"); | 2150 WebFormControlElement element = GetFormControlElementById("element"); |
| 2151 | 2151 |
| 2152 FormFieldData result; | 2152 FormFieldData result; |
| 2153 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); | 2153 WebFormControlElementToFormField(element, nullptr, EXTRACT_VALUE, &result); |
| 2154 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 2154 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 2155 } | 2155 } |
| 2156 | 2156 |
| 2157 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 2157 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2173 " <LABEL for='password'>Password:</LABEL>" | 2173 " <LABEL for='password'>Password:</LABEL>" |
| 2174 " <INPUT type='password' id='password' value='secret'/>" | 2174 " <INPUT type='password' id='password' value='secret'/>" |
| 2175 " <LABEL for='month'>Card expiration:</LABEL>" | 2175 " <LABEL for='month'>Card expiration:</LABEL>" |
| 2176 " <INPUT type='month' id='month' value='2011-12'/>" | 2176 " <INPUT type='month' id='month' value='2011-12'/>" |
| 2177 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2177 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2178 // The below inputs should be ignored | 2178 // The below inputs should be ignored |
| 2179 " <LABEL for='notvisible'>Hidden:</LABEL>" | 2179 " <LABEL for='notvisible'>Hidden:</LABEL>" |
| 2180 " <INPUT type='hidden' id='notvisible' value='apple'/>" | 2180 " <INPUT type='hidden' id='notvisible' value='apple'/>" |
| 2181 "</FORM>"); | 2181 "</FORM>"); |
| 2182 | 2182 |
| 2183 WebFrame* frame = GetMainFrame(); | 2183 WebLocalFrame* frame = GetMainFrame(); |
| 2184 ASSERT_NE(nullptr, frame); | 2184 ASSERT_NE(nullptr, frame); |
| 2185 | 2185 |
| 2186 WebVector<WebFormElement> forms; | 2186 WebVector<WebFormElement> forms; |
| 2187 frame->GetDocument().Forms(forms); | 2187 frame->GetDocument().Forms(forms); |
| 2188 ASSERT_EQ(1U, forms.size()); | 2188 ASSERT_EQ(1U, forms.size()); |
| 2189 | 2189 |
| 2190 WebInputElement input_element = GetInputElementById("firstname"); | 2190 WebInputElement input_element = GetInputElementById("firstname"); |
| 2191 | 2191 |
| 2192 FormData form; | 2192 FormData form; |
| 2193 FormFieldData field; | 2193 FormFieldData field; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2246 } | 2246 } |
| 2247 | 2247 |
| 2248 TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) { | 2248 TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) { |
| 2249 LoadHTML("<form id=form>" | 2249 LoadHTML("<form id=form>" |
| 2250 " <label for='progress'>Progress:</label>" | 2250 " <label for='progress'>Progress:</label>" |
| 2251 " <progress id='progress'></progress>" | 2251 " <progress id='progress'></progress>" |
| 2252 " <label for='firstname'>First name:</label>" | 2252 " <label for='firstname'>First name:</label>" |
| 2253 " <input type='text' id='firstname' value='John'>" | 2253 " <input type='text' id='firstname' value='John'>" |
| 2254 "</form>"); | 2254 "</form>"); |
| 2255 | 2255 |
| 2256 WebFrame* frame = GetMainFrame(); | 2256 WebLocalFrame* frame = GetMainFrame(); |
| 2257 ASSERT_NE(nullptr, frame); | 2257 ASSERT_NE(nullptr, frame); |
| 2258 | 2258 |
| 2259 WebFormElement web_form = | 2259 WebFormElement web_form = |
| 2260 frame->GetDocument().GetElementById("form").To<WebFormElement>(); | 2260 frame->GetDocument().GetElementById("form").To<WebFormElement>(); |
| 2261 ASSERT_FALSE(web_form.IsNull()); | 2261 ASSERT_FALSE(web_form.IsNull()); |
| 2262 | 2262 |
| 2263 FormData form; | 2263 FormData form; |
| 2264 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2264 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2265 nullptr, EXTRACT_NONE, &form, nullptr)); | 2265 nullptr, EXTRACT_NONE, &form, nullptr)); |
| 2266 | 2266 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2280 // We should not be able to serialize a form with too many fillable fields. | 2280 // We should not be able to serialize a form with too many fillable fields. |
| 2281 TEST_F(FormAutofillTest, MAYBE_WebFormElementToFormDataTooManyFields) { | 2281 TEST_F(FormAutofillTest, MAYBE_WebFormElementToFormDataTooManyFields) { |
| 2282 std::string html = | 2282 std::string html = |
| 2283 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; | 2283 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; |
| 2284 for (size_t i = 0; i < (kMaxParseableFields + 1); ++i) { | 2284 for (size_t i = 0; i < (kMaxParseableFields + 1); ++i) { |
| 2285 html += "<INPUT type='text'/>"; | 2285 html += "<INPUT type='text'/>"; |
| 2286 } | 2286 } |
| 2287 html += "</FORM>"; | 2287 html += "</FORM>"; |
| 2288 LoadHTML(html.c_str()); | 2288 LoadHTML(html.c_str()); |
| 2289 | 2289 |
| 2290 WebFrame* frame = GetMainFrame(); | 2290 WebLocalFrame* frame = GetMainFrame(); |
| 2291 ASSERT_NE(nullptr, frame); | 2291 ASSERT_NE(nullptr, frame); |
| 2292 | 2292 |
| 2293 WebVector<WebFormElement> forms; | 2293 WebVector<WebFormElement> forms; |
| 2294 frame->GetDocument().Forms(forms); | 2294 frame->GetDocument().Forms(forms); |
| 2295 ASSERT_EQ(1U, forms.size()); | 2295 ASSERT_EQ(1U, forms.size()); |
| 2296 | 2296 |
| 2297 WebInputElement input_element = GetInputElementById("firstname"); | 2297 WebInputElement input_element = GetInputElementById("firstname"); |
| 2298 | 2298 |
| 2299 FormData form; | 2299 FormData form; |
| 2300 FormFieldData field; | 2300 FormFieldData field; |
| 2301 EXPECT_FALSE(WebFormElementToFormData(forms[0], input_element, nullptr, | 2301 EXPECT_FALSE(WebFormElementToFormData(forms[0], input_element, nullptr, |
| 2302 EXTRACT_VALUE, &form, &field)); | 2302 EXTRACT_VALUE, &form, &field)); |
| 2303 } | 2303 } |
| 2304 | 2304 |
| 2305 // Tests that the |should_autocomplete| is set to false for all the fields when | 2305 // Tests that the |should_autocomplete| is set to false for all the fields when |
| 2306 // an autocomplete='off' attribute is set for the form in HTML. | 2306 // an autocomplete='off' attribute is set for the form in HTML. |
| 2307 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnForm) { | 2307 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnForm) { |
| 2308 LoadHTML( | 2308 LoadHTML( |
| 2309 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " | 2309 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " |
| 2310 "autocomplete='off'>" | 2310 "autocomplete='off'>" |
| 2311 " <LABEL for='firstname'>First name:</LABEL>" | 2311 " <LABEL for='firstname'>First name:</LABEL>" |
| 2312 " <INPUT type='text' id='firstname' value='John'/>" | 2312 " <INPUT type='text' id='firstname' value='John'/>" |
| 2313 " <LABEL for='lastname'>Last name:</LABEL>" | 2313 " <LABEL for='lastname'>Last name:</LABEL>" |
| 2314 " <INPUT type='text' id='lastname' value='Smith'/>" | 2314 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2315 " <LABEL for='street-address'>Address:</LABEL>" | 2315 " <LABEL for='street-address'>Address:</LABEL>" |
| 2316 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" | 2316 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" |
| 2317 "</FORM>"); | 2317 "</FORM>"); |
| 2318 | 2318 |
| 2319 WebFrame* frame = GetMainFrame(); | 2319 WebLocalFrame* frame = GetMainFrame(); |
| 2320 ASSERT_NE(nullptr, frame); | 2320 ASSERT_NE(nullptr, frame); |
| 2321 | 2321 |
| 2322 WebFormElement web_form = | 2322 WebFormElement web_form = |
| 2323 frame->GetDocument().GetElementById("form").To<WebFormElement>(); | 2323 frame->GetDocument().GetElementById("form").To<WebFormElement>(); |
| 2324 ASSERT_FALSE(web_form.IsNull()); | 2324 ASSERT_FALSE(web_form.IsNull()); |
| 2325 | 2325 |
| 2326 FormData form; | 2326 FormData form; |
| 2327 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2327 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2328 nullptr, EXTRACT_NONE, &form, nullptr)); | 2328 nullptr, EXTRACT_NONE, &form, nullptr)); |
| 2329 | 2329 |
| 2330 for (const FormFieldData& field : form.fields) { | 2330 for (const FormFieldData& field : form.fields) { |
| 2331 EXPECT_FALSE(field.should_autocomplete); | 2331 EXPECT_FALSE(field.should_autocomplete); |
| 2332 } | 2332 } |
| 2333 } | 2333 } |
| 2334 | 2334 |
| 2335 // Tests that the |should_autocomplete| is set to false only for the field | 2335 // Tests that the |should_autocomplete| is set to false only for the field |
| 2336 // which has an autocomplete='off' attribute set for it in HTML. | 2336 // which has an autocomplete='off' attribute set for it in HTML. |
| 2337 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnField) { | 2337 TEST_F(FormAutofillTest, WebFormElementToFormData_AutocompleteOff_OnField) { |
| 2338 LoadHTML( | 2338 LoadHTML( |
| 2339 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post'>" | 2339 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post'>" |
| 2340 " <LABEL for='firstname'>First name:</LABEL>" | 2340 " <LABEL for='firstname'>First name:</LABEL>" |
| 2341 " <INPUT type='text' id='firstname' value='John' autocomplete='off'/>" | 2341 " <INPUT type='text' id='firstname' value='John' autocomplete='off'/>" |
| 2342 " <LABEL for='lastname'>Last name:</LABEL>" | 2342 " <LABEL for='lastname'>Last name:</LABEL>" |
| 2343 " <INPUT type='text' id='lastname' value='Smith'/>" | 2343 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2344 " <LABEL for='street-address'>Address:</LABEL>" | 2344 " <LABEL for='street-address'>Address:</LABEL>" |
| 2345 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" | 2345 " <INPUT type='text' id='addressline1' value='123 Test st.'/>" |
| 2346 "</FORM>"); | 2346 "</FORM>"); |
| 2347 | 2347 |
| 2348 WebFrame* frame = GetMainFrame(); | 2348 WebLocalFrame* frame = GetMainFrame(); |
| 2349 ASSERT_NE(nullptr, frame); | 2349 ASSERT_NE(nullptr, frame); |
| 2350 | 2350 |
| 2351 WebFormElement web_form = | 2351 WebFormElement web_form = |
| 2352 frame->GetDocument().GetElementById("form").To<WebFormElement>(); | 2352 frame->GetDocument().GetElementById("form").To<WebFormElement>(); |
| 2353 ASSERT_FALSE(web_form.IsNull()); | 2353 ASSERT_FALSE(web_form.IsNull()); |
| 2354 | 2354 |
| 2355 FormData form; | 2355 FormData form; |
| 2356 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2356 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2357 nullptr, EXTRACT_NONE, &form, nullptr)); | 2357 nullptr, EXTRACT_NONE, &form, nullptr)); |
| 2358 | 2358 |
| 2359 ASSERT_EQ(3U, form.fields.size()); | 2359 ASSERT_EQ(3U, form.fields.size()); |
| 2360 | 2360 |
| 2361 EXPECT_FALSE(form.fields[0].should_autocomplete); | 2361 EXPECT_FALSE(form.fields[0].should_autocomplete); |
| 2362 EXPECT_TRUE(form.fields[1].should_autocomplete); | 2362 EXPECT_TRUE(form.fields[1].should_autocomplete); |
| 2363 EXPECT_TRUE(form.fields[2].should_autocomplete); | 2363 EXPECT_TRUE(form.fields[2].should_autocomplete); |
| 2364 } | 2364 } |
| 2365 | 2365 |
| 2366 // Tests CSS classes are set. | 2366 // Tests CSS classes are set. |
| 2367 TEST_F(FormAutofillTest, WebFormElementToFormData_CssClasses) { | 2367 TEST_F(FormAutofillTest, WebFormElementToFormData_CssClasses) { |
| 2368 LoadHTML( | 2368 LoadHTML( |
| 2369 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " | 2369 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " |
| 2370 "autocomplete='off'>" | 2370 "autocomplete='off'>" |
| 2371 " <INPUT type='text' id='firstname' class='firstname_field' />" | 2371 " <INPUT type='text' id='firstname' class='firstname_field' />" |
| 2372 " <INPUT type='text' id='lastname' class='lastname_field' />" | 2372 " <INPUT type='text' id='lastname' class='lastname_field' />" |
| 2373 " <INPUT type='text' id='addressline1' />" | 2373 " <INPUT type='text' id='addressline1' />" |
| 2374 "</FORM>"); | 2374 "</FORM>"); |
| 2375 | 2375 |
| 2376 WebFrame* frame = GetMainFrame(); | 2376 WebLocalFrame* frame = GetMainFrame(); |
| 2377 ASSERT_NE(nullptr, frame); | 2377 ASSERT_NE(nullptr, frame); |
| 2378 | 2378 |
| 2379 WebFormElement web_form = | 2379 WebFormElement web_form = |
| 2380 frame->GetDocument().GetElementById("form").To<WebFormElement>(); | 2380 frame->GetDocument().GetElementById("form").To<WebFormElement>(); |
| 2381 ASSERT_FALSE(web_form.IsNull()); | 2381 ASSERT_FALSE(web_form.IsNull()); |
| 2382 | 2382 |
| 2383 FormData form; | 2383 FormData form; |
| 2384 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2384 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2385 nullptr, EXTRACT_NONE, &form, nullptr)); | 2385 nullptr, EXTRACT_NONE, &form, nullptr)); |
| 2386 | 2386 |
| 2387 EXPECT_EQ(3U, form.fields.size()); | 2387 EXPECT_EQ(3U, form.fields.size()); |
| 2388 EXPECT_EQ(ASCIIToUTF16("firstname_field"), form.fields[0].css_classes); | 2388 EXPECT_EQ(ASCIIToUTF16("firstname_field"), form.fields[0].css_classes); |
| 2389 EXPECT_EQ(ASCIIToUTF16("lastname_field"), form.fields[1].css_classes); | 2389 EXPECT_EQ(ASCIIToUTF16("lastname_field"), form.fields[1].css_classes); |
| 2390 EXPECT_EQ(base::string16(), form.fields[2].css_classes); | 2390 EXPECT_EQ(base::string16(), form.fields[2].css_classes); |
| 2391 } | 2391 } |
| 2392 | 2392 |
| 2393 // Tests id attributes are set. | 2393 // Tests id attributes are set. |
| 2394 TEST_F(FormAutofillTest, WebFormElementToFormData_IdAttributes) { | 2394 TEST_F(FormAutofillTest, WebFormElementToFormData_IdAttributes) { |
| 2395 LoadHTML( | 2395 LoadHTML( |
| 2396 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " | 2396 "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' " |
| 2397 "autocomplete='off'>" | 2397 "autocomplete='off'>" |
| 2398 " <INPUT type='text' name='name1' id='firstname' />" | 2398 " <INPUT type='text' name='name1' id='firstname' />" |
| 2399 " <INPUT type='text' name='name2' id='lastname' />" | 2399 " <INPUT type='text' name='name2' id='lastname' />" |
| 2400 " <INPUT type='text' name='same' id='same' />" | 2400 " <INPUT type='text' name='same' id='same' />" |
| 2401 " <INPUT type='text' id='addressline1' />" | 2401 " <INPUT type='text' id='addressline1' />" |
| 2402 "</FORM>"); | 2402 "</FORM>"); |
| 2403 | 2403 |
| 2404 WebFrame* frame = GetMainFrame(); | 2404 WebLocalFrame* frame = GetMainFrame(); |
| 2405 ASSERT_NE(nullptr, frame); | 2405 ASSERT_NE(nullptr, frame); |
| 2406 | 2406 |
| 2407 WebFormElement web_form = | 2407 WebFormElement web_form = |
| 2408 frame->GetDocument().GetElementById("form").To<WebFormElement>(); | 2408 frame->GetDocument().GetElementById("form").To<WebFormElement>(); |
| 2409 ASSERT_FALSE(web_form.IsNull()); | 2409 ASSERT_FALSE(web_form.IsNull()); |
| 2410 | 2410 |
| 2411 FormData form; | 2411 FormData form; |
| 2412 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2412 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2413 nullptr, EXTRACT_NONE, &form, nullptr)); | 2413 nullptr, EXTRACT_NONE, &form, nullptr)); |
| 2414 | 2414 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2439 " <INPUT type='text' id='email' value='john@example.com'/>" | 2439 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 2440 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2440 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2441 "</FORM>" | 2441 "</FORM>" |
| 2442 "<FORM name='TestForm2' action='http://zoo.com' method='post'>" | 2442 "<FORM name='TestForm2' action='http://zoo.com' method='post'>" |
| 2443 " <INPUT type='text' id='firstname' value='Jack'/>" | 2443 " <INPUT type='text' id='firstname' value='Jack'/>" |
| 2444 " <INPUT type='text' id='lastname' value='Adams'/>" | 2444 " <INPUT type='text' id='lastname' value='Adams'/>" |
| 2445 " <INPUT type='text' id='email' value='jack@example.com'/>" | 2445 " <INPUT type='text' id='email' value='jack@example.com'/>" |
| 2446 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2446 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2447 "</FORM>"); | 2447 "</FORM>"); |
| 2448 | 2448 |
| 2449 WebFrame* web_frame = GetMainFrame(); | 2449 WebLocalFrame* web_frame = GetMainFrame(); |
| 2450 ASSERT_NE(nullptr, web_frame); | 2450 ASSERT_NE(nullptr, web_frame); |
| 2451 | 2451 |
| 2452 FormCache form_cache(*web_frame); | 2452 FormCache form_cache(*web_frame); |
| 2453 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2453 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2454 ASSERT_EQ(2U, forms.size()); | 2454 ASSERT_EQ(2U, forms.size()); |
| 2455 | 2455 |
| 2456 // First form. | 2456 // First form. |
| 2457 const FormData& form = forms[0]; | 2457 const FormData& form = forms[0]; |
| 2458 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2458 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2459 EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()), | 2459 EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 | 2512 |
| 2513 TEST_F(FormAutofillTest, OnlyExtractNewForms) { | 2513 TEST_F(FormAutofillTest, OnlyExtractNewForms) { |
| 2514 LoadHTML( | 2514 LoadHTML( |
| 2515 "<FORM id='testform' action='http://cnn.com' method='post'>" | 2515 "<FORM id='testform' action='http://cnn.com' method='post'>" |
| 2516 " <INPUT type='text' id='firstname' value='John'/>" | 2516 " <INPUT type='text' id='firstname' value='John'/>" |
| 2517 " <INPUT type='text' id='lastname' value='Smith'/>" | 2517 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2518 " <INPUT type='text' id='email' value='john@example.com'/>" | 2518 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 2519 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2519 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2520 "</FORM>"); | 2520 "</FORM>"); |
| 2521 | 2521 |
| 2522 WebFrame* web_frame = GetMainFrame(); | 2522 WebLocalFrame* web_frame = GetMainFrame(); |
| 2523 ASSERT_NE(nullptr, web_frame); | 2523 ASSERT_NE(nullptr, web_frame); |
| 2524 | 2524 |
| 2525 FormCache form_cache(*web_frame); | 2525 FormCache form_cache(*web_frame); |
| 2526 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2526 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2527 ASSERT_EQ(1U, forms.size()); | 2527 ASSERT_EQ(1U, forms.size()); |
| 2528 | 2528 |
| 2529 // Second call should give nothing as there are no new forms. | 2529 // Second call should give nothing as there are no new forms. |
| 2530 forms = form_cache.ExtractNewForms(); | 2530 forms = form_cache.ExtractNewForms(); |
| 2531 ASSERT_TRUE(forms.empty()); | 2531 ASSERT_TRUE(forms.empty()); |
| 2532 | 2532 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 } | 2619 } |
| 2620 | 2620 |
| 2621 // We should not extract a form if it has too few fillable fields. | 2621 // We should not extract a form if it has too few fillable fields. |
| 2622 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { | 2622 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { |
| 2623 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2623 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2624 " <INPUT type='text' id='firstname' value='John'/>" | 2624 " <INPUT type='text' id='firstname' value='John'/>" |
| 2625 " <INPUT type='text' id='lastname' value='Smith'/>" | 2625 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2626 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2626 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2627 "</FORM>"); | 2627 "</FORM>"); |
| 2628 | 2628 |
| 2629 WebFrame* web_frame = GetMainFrame(); | 2629 WebLocalFrame* web_frame = GetMainFrame(); |
| 2630 ASSERT_NE(nullptr, web_frame); | 2630 ASSERT_NE(nullptr, web_frame); |
| 2631 | 2631 |
| 2632 FormCache form_cache(*web_frame); | 2632 FormCache form_cache(*web_frame); |
| 2633 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2633 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2634 ASSERT_TRUE(forms.empty()); | 2634 ASSERT_TRUE(forms.empty()); |
| 2635 } | 2635 } |
| 2636 | 2636 |
| 2637 // We should not report additional forms for empty forms. | 2637 // We should not report additional forms for empty forms. |
| 2638 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { | 2638 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { |
| 2639 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2639 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2640 " <INPUT type='text' id='firstname' value='John'/>" | 2640 " <INPUT type='text' id='firstname' value='John'/>" |
| 2641 " <INPUT type='text' id='lastname' value='Smith'/>" | 2641 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2642 "</FORM>"); | 2642 "</FORM>"); |
| 2643 | 2643 |
| 2644 WebFrame* web_frame = GetMainFrame(); | 2644 WebLocalFrame* web_frame = GetMainFrame(); |
| 2645 ASSERT_NE(nullptr, web_frame); | 2645 ASSERT_NE(nullptr, web_frame); |
| 2646 | 2646 |
| 2647 FormCache form_cache(*web_frame); | 2647 FormCache form_cache(*web_frame); |
| 2648 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2648 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2649 ASSERT_TRUE(forms.empty()); | 2649 ASSERT_TRUE(forms.empty()); |
| 2650 } | 2650 } |
| 2651 | 2651 |
| 2652 // We should not report additional forms for empty forms. | 2652 // We should not report additional forms for empty forms. |
| 2653 TEST_F(FormAutofillTest, ExtractFormsNoFields) { | 2653 TEST_F(FormAutofillTest, ExtractFormsNoFields) { |
| 2654 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2654 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2655 "</FORM>"); | 2655 "</FORM>"); |
| 2656 | 2656 |
| 2657 WebFrame* web_frame = GetMainFrame(); | 2657 WebLocalFrame* web_frame = GetMainFrame(); |
| 2658 ASSERT_NE(nullptr, web_frame); | 2658 ASSERT_NE(nullptr, web_frame); |
| 2659 | 2659 |
| 2660 FormCache form_cache(*web_frame); | 2660 FormCache form_cache(*web_frame); |
| 2661 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2661 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2662 ASSERT_TRUE(forms.empty()); | 2662 ASSERT_TRUE(forms.empty()); |
| 2663 } | 2663 } |
| 2664 | 2664 |
| 2665 // We should not extract a form if it has too few fillable fields. | 2665 // We should not extract a form if it has too few fillable fields. |
| 2666 // Make sure radio and checkbox fields don't count. | 2666 // Make sure radio and checkbox fields don't count. |
| 2667 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { | 2667 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { |
| 2668 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 2668 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
| 2669 " <INPUT type='text' id='firstname' value='John'/>" | 2669 " <INPUT type='text' id='firstname' value='John'/>" |
| 2670 " <INPUT type='text' id='lastname' value='Smith'/>" | 2670 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2671 " <INPUT type='radio' id='a_radio' value='0'/>" | 2671 " <INPUT type='radio' id='a_radio' value='0'/>" |
| 2672 " <INPUT type='checkbox' id='a_check' value='1'/>" | 2672 " <INPUT type='checkbox' id='a_check' value='1'/>" |
| 2673 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2673 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2674 "</FORM>"); | 2674 "</FORM>"); |
| 2675 | 2675 |
| 2676 WebFrame* web_frame = GetMainFrame(); | 2676 WebLocalFrame* web_frame = GetMainFrame(); |
| 2677 ASSERT_NE(nullptr, web_frame); | 2677 ASSERT_NE(nullptr, web_frame); |
| 2678 | 2678 |
| 2679 FormCache form_cache(*web_frame); | 2679 FormCache form_cache(*web_frame); |
| 2680 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 2680 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 2681 ASSERT_TRUE(forms.empty()); | 2681 ASSERT_TRUE(forms.empty()); |
| 2682 } | 2682 } |
| 2683 | 2683 |
| 2684 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { | 2684 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { |
| 2685 { | 2685 { |
| 2686 // Form is still Autofill-able despite autocomplete=off. | 2686 // Form is still Autofill-able despite autocomplete=off. |
| 2687 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" | 2687 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'" |
| 2688 " autocomplete=off>" | 2688 " autocomplete=off>" |
| 2689 " <INPUT type='text' id='firstname' value='John'/>" | 2689 " <INPUT type='text' id='firstname' value='John'/>" |
| 2690 " <INPUT type='text' id='lastname' value='Smith'/>" | 2690 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 2691 " <INPUT type='text' id='email' value='john@example.com'/>" | 2691 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 2692 " <INPUT type='submit' name='reply-send' value='Send'/>" | 2692 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 2693 "</FORM>"); | 2693 "</FORM>"); |
| 2694 | 2694 |
| 2695 WebFrame* web_frame = GetMainFrame(); | 2695 WebLocalFrame* web_frame = GetMainFrame(); |
| 2696 ASSERT_NE(nullptr, web_frame); | 2696 ASSERT_NE(nullptr, web_frame); |
| 2697 | 2697 |
| 2698 WebVector<WebFormElement> web_forms; | 2698 WebVector<WebFormElement> web_forms; |
| 2699 web_frame->GetDocument().Forms(web_forms); | 2699 web_frame->GetDocument().Forms(web_forms); |
| 2700 ASSERT_EQ(1U, web_forms.size()); | 2700 ASSERT_EQ(1U, web_forms.size()); |
| 2701 WebFormElement web_form = web_forms[0]; | 2701 WebFormElement web_form = web_forms[0]; |
| 2702 | 2702 |
| 2703 FormData form; | 2703 FormData form; |
| 2704 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), | 2704 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2705 nullptr, EXTRACT_NONE, &form, | 2705 nullptr, EXTRACT_NONE, &form, |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3975 " <input type='text' name='dayphone1'>" | 3975 " <input type='text' name='dayphone1'>" |
| 3976 " -" | 3976 " -" |
| 3977 " <input type='text' name='dayphone2'>" | 3977 " <input type='text' name='dayphone2'>" |
| 3978 " -" | 3978 " -" |
| 3979 " <input type='text' name='dayphone3'>" | 3979 " <input type='text' name='dayphone3'>" |
| 3980 " ext.:" | 3980 " ext.:" |
| 3981 " <input type='text' name='dayphone4'>" | 3981 " <input type='text' name='dayphone4'>" |
| 3982 " <input type='submit' name='reply-send' value='Send'>" | 3982 " <input type='submit' name='reply-send' value='Send'>" |
| 3983 "</FORM>"); | 3983 "</FORM>"); |
| 3984 | 3984 |
| 3985 WebFrame* frame = GetMainFrame(); | 3985 WebLocalFrame* frame = GetMainFrame(); |
| 3986 ASSERT_NE(nullptr, frame); | 3986 ASSERT_NE(nullptr, frame); |
| 3987 | 3987 |
| 3988 WebVector<WebFormElement> forms; | 3988 WebVector<WebFormElement> forms; |
| 3989 frame->GetDocument().Forms(forms); | 3989 frame->GetDocument().Forms(forms); |
| 3990 ASSERT_EQ(1U, forms.size()); | 3990 ASSERT_EQ(1U, forms.size()); |
| 3991 | 3991 |
| 3992 FormData form; | 3992 FormData form; |
| 3993 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(), | 3993 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(), |
| 3994 nullptr, EXTRACT_VALUE, &form, nullptr)); | 3994 nullptr, EXTRACT_VALUE, &form, nullptr)); |
| 3995 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 3995 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4030 " -" | 4030 " -" |
| 4031 " <input type='text' maxlength='4' size='5'" | 4031 " <input type='text' maxlength='4' size='5'" |
| 4032 " name='dayphone3'>" | 4032 " name='dayphone3'>" |
| 4033 " ext.:" | 4033 " ext.:" |
| 4034 " <input type='text' maxlength='5' name='dayphone4'>" | 4034 " <input type='text' maxlength='5' name='dayphone4'>" |
| 4035 " <input type='text' name='default1'>" | 4035 " <input type='text' name='default1'>" |
| 4036 " <input type='text' maxlength='-1' name='invalid1'>" | 4036 " <input type='text' maxlength='-1' name='invalid1'>" |
| 4037 " <input type='submit' name='reply-send' value='Send'>" | 4037 " <input type='submit' name='reply-send' value='Send'>" |
| 4038 "</FORM>"); | 4038 "</FORM>"); |
| 4039 | 4039 |
| 4040 WebFrame* frame = GetMainFrame(); | 4040 WebLocalFrame* frame = GetMainFrame(); |
| 4041 ASSERT_NE(nullptr, frame); | 4041 ASSERT_NE(nullptr, frame); |
| 4042 | 4042 |
| 4043 WebVector<WebFormElement> forms; | 4043 WebVector<WebFormElement> forms; |
| 4044 frame->GetDocument().Forms(forms); | 4044 frame->GetDocument().Forms(forms); |
| 4045 ASSERT_EQ(1U, forms.size()); | 4045 ASSERT_EQ(1U, forms.size()); |
| 4046 | 4046 |
| 4047 FormData form; | 4047 FormData form; |
| 4048 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(), | 4048 EXPECT_TRUE(WebFormElementToFormData(forms[0], WebFormControlElement(), |
| 4049 nullptr, EXTRACT_VALUE, &form, nullptr)); | 4049 nullptr, EXTRACT_VALUE, &form, nullptr)); |
| 4050 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 4050 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4330 " <LABEL for='email'> xxx@yyy.com </LABEL>" | 4330 " <LABEL for='email'> xxx@yyy.com </LABEL>" |
| 4331 " <INPUT type='text' id='email' value='john@example.com'/>" | 4331 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 4332 " <INPUT type='submit' name='reply-send' value='Send'/>" | 4332 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 4333 "</FORM>", | 4333 "</FORM>", |
| 4334 labels, names, values); | 4334 labels, names, values); |
| 4335 } | 4335 } |
| 4336 | 4336 |
| 4337 TEST_F(FormAutofillTest, ClickElement) { | 4337 TEST_F(FormAutofillTest, ClickElement) { |
| 4338 LoadHTML("<BUTTON id='link'>Button</BUTTON>" | 4338 LoadHTML("<BUTTON id='link'>Button</BUTTON>" |
| 4339 "<BUTTON name='button'>Button</BUTTON>"); | 4339 "<BUTTON name='button'>Button</BUTTON>"); |
| 4340 WebFrame* frame = GetMainFrame(); | 4340 WebLocalFrame* frame = GetMainFrame(); |
| 4341 ASSERT_NE(nullptr, frame); | 4341 ASSERT_NE(nullptr, frame); |
| 4342 | 4342 |
| 4343 // Successful retrieval by id. | 4343 // Successful retrieval by id. |
| 4344 WebElementDescriptor clicker; | 4344 WebElementDescriptor clicker; |
| 4345 clicker.retrieval_method = WebElementDescriptor::ID; | 4345 clicker.retrieval_method = WebElementDescriptor::ID; |
| 4346 clicker.descriptor = "link"; | 4346 clicker.descriptor = "link"; |
| 4347 EXPECT_TRUE(ClickElement(frame->GetDocument(), clicker)); | 4347 EXPECT_TRUE(ClickElement(frame->GetDocument(), clicker)); |
| 4348 | 4348 |
| 4349 // Successful retrieval by css selector. | 4349 // Successful retrieval by css selector. |
| 4350 clicker.retrieval_method = WebElementDescriptor::CSS_SELECTOR; | 4350 clicker.retrieval_method = WebElementDescriptor::CSS_SELECTOR; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4365 " <INPUT type='text' id='firstname' value='John'/>" | 4365 " <INPUT type='text' id='firstname' value='John'/>" |
| 4366 " <INPUT type='text' id='lastname' value='Smith'/>" | 4366 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 4367 " <SELECT id='country'>" | 4367 " <SELECT id='country'>" |
| 4368 " <OPTION value='AF'>Afghanistan</OPTION>" | 4368 " <OPTION value='AF'>Afghanistan</OPTION>" |
| 4369 " <OPTION value='AL'>Albania</OPTION>" | 4369 " <OPTION value='AL'>Albania</OPTION>" |
| 4370 " <OPTION value='DZ'>Algeria</OPTION>" | 4370 " <OPTION value='DZ'>Algeria</OPTION>" |
| 4371 " </SELECT>" | 4371 " </SELECT>" |
| 4372 " <INPUT type='submit' name='reply-send' value='Send'/>" | 4372 " <INPUT type='submit' name='reply-send' value='Send'/>" |
| 4373 "</FORM>"); | 4373 "</FORM>"); |
| 4374 | 4374 |
| 4375 WebFrame* frame = GetMainFrame(); | 4375 WebLocalFrame* frame = GetMainFrame(); |
| 4376 ASSERT_NE(nullptr, frame); | 4376 ASSERT_NE(nullptr, frame); |
| 4377 | 4377 |
| 4378 // Set the value of the select-one. | 4378 // Set the value of the select-one. |
| 4379 WebSelectElement select_element = | 4379 WebSelectElement select_element = |
| 4380 frame->GetDocument().GetElementById("country").To<WebSelectElement>(); | 4380 frame->GetDocument().GetElementById("country").To<WebSelectElement>(); |
| 4381 select_element.SetValue(WebString::FromUTF8("AL")); | 4381 select_element.SetValue(WebString::FromUTF8("AL")); |
| 4382 | 4382 |
| 4383 WebVector<WebFormElement> forms; | 4383 WebVector<WebFormElement> forms; |
| 4384 frame->GetDocument().Forms(forms); | 4384 frame->GetDocument().Forms(forms); |
| 4385 ASSERT_EQ(1U, forms.size()); | 4385 ASSERT_EQ(1U, forms.size()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4468 " <LABEL for='lastname'>Last name:</LABEL>" | 4468 " <LABEL for='lastname'>Last name:</LABEL>" |
| 4469 " <INPUT type='text' id='firstname' value='John'/>" | 4469 " <INPUT type='text' id='firstname' value='John'/>" |
| 4470 " <INPUT type='text' id='lastname' value='Smith'/>" | 4470 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 4471 " </FIELDSET>" | 4471 " </FIELDSET>" |
| 4472 " <FIELDSET>" | 4472 " <FIELDSET>" |
| 4473 " <LABEL for='email'>Email:</LABEL>" | 4473 " <LABEL for='email'>Email:</LABEL>" |
| 4474 " <INPUT type='text' id='email' value='john@example.com'/>" | 4474 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 4475 " </FIELDSET>" | 4475 " </FIELDSET>" |
| 4476 "</DIV>"); | 4476 "</DIV>"); |
| 4477 | 4477 |
| 4478 WebFrame* frame = GetMainFrame(); | 4478 WebLocalFrame* frame = GetMainFrame(); |
| 4479 ASSERT_NE(nullptr, frame); | 4479 ASSERT_NE(nullptr, frame); |
| 4480 | 4480 |
| 4481 control_elements = GetUnownedAutofillableFormFieldElements( | 4481 control_elements = GetUnownedAutofillableFormFieldElements( |
| 4482 frame->GetDocument().All(), &fieldsets); | 4482 frame->GetDocument().All(), &fieldsets); |
| 4483 ASSERT_EQ(3U, control_elements.size()); | 4483 ASSERT_EQ(3U, control_elements.size()); |
| 4484 ASSERT_EQ(2U, fieldsets.size()); | 4484 ASSERT_EQ(2U, fieldsets.size()); |
| 4485 | 4485 |
| 4486 FormData form; | 4486 FormData form; |
| 4487 EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData( | 4487 EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData( |
| 4488 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, | 4488 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4528 " <FIELDSET>" | 4528 " <FIELDSET>" |
| 4529 " <LABEL for='firstname'>First name:</LABEL>" | 4529 " <LABEL for='firstname'>First name:</LABEL>" |
| 4530 " <LABEL for='lastname'>Last name:</LABEL>" | 4530 " <LABEL for='lastname'>Last name:</LABEL>" |
| 4531 " <INPUT type='text' id='firstname' value='John'/>" | 4531 " <INPUT type='text' id='firstname' value='John'/>" |
| 4532 " <INPUT type='text' id='lastname' value='Smith'/>" | 4532 " <INPUT type='text' id='lastname' value='Smith'/>" |
| 4533 " <LABEL for='email'>Email:</LABEL>" | 4533 " <LABEL for='email'>Email:</LABEL>" |
| 4534 " </FIELDSET>" | 4534 " </FIELDSET>" |
| 4535 " <INPUT type='text' id='email' value='john@example.com'/>" | 4535 " <INPUT type='text' id='email' value='john@example.com'/>" |
| 4536 "</DIV>"); | 4536 "</DIV>"); |
| 4537 | 4537 |
| 4538 WebFrame* frame = GetMainFrame(); | 4538 WebLocalFrame* frame = GetMainFrame(); |
| 4539 ASSERT_NE(nullptr, frame); | 4539 ASSERT_NE(nullptr, frame); |
| 4540 | 4540 |
| 4541 control_elements = GetUnownedAutofillableFormFieldElements( | 4541 control_elements = GetUnownedAutofillableFormFieldElements( |
| 4542 frame->GetDocument().All(), &fieldsets); | 4542 frame->GetDocument().All(), &fieldsets); |
| 4543 ASSERT_EQ(3U, control_elements.size()); | 4543 ASSERT_EQ(3U, control_elements.size()); |
| 4544 ASSERT_EQ(1U, fieldsets.size()); | 4544 ASSERT_EQ(1U, fieldsets.size()); |
| 4545 | 4545 |
| 4546 FormData form; | 4546 FormData form; |
| 4547 EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData( | 4547 EXPECT_TRUE(UnownedCheckoutFormElementsAndFieldSetsToFormData( |
| 4548 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, | 4548 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4577 | 4577 |
| 4578 TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) { | 4578 TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) { |
| 4579 std::vector<WebElement> fieldsets; | 4579 std::vector<WebElement> fieldsets; |
| 4580 std::vector<WebFormControlElement> control_elements; | 4580 std::vector<WebFormControlElement> control_elements; |
| 4581 | 4581 |
| 4582 const ExtractMask extract_mask = | 4582 const ExtractMask extract_mask = |
| 4583 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | 4583 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); |
| 4584 | 4584 |
| 4585 LoadHTML(kFormHtml); | 4585 LoadHTML(kFormHtml); |
| 4586 | 4586 |
| 4587 WebFrame* frame = GetMainFrame(); | 4587 WebLocalFrame* frame = GetMainFrame(); |
| 4588 ASSERT_NE(nullptr, frame); | 4588 ASSERT_NE(nullptr, frame); |
| 4589 | 4589 |
| 4590 control_elements = GetUnownedAutofillableFormFieldElements( | 4590 control_elements = GetUnownedAutofillableFormFieldElements( |
| 4591 frame->GetDocument().All(), &fieldsets); | 4591 frame->GetDocument().All(), &fieldsets); |
| 4592 ASSERT_TRUE(control_elements.empty()); | 4592 ASSERT_TRUE(control_elements.empty()); |
| 4593 ASSERT_TRUE(fieldsets.empty()); | 4593 ASSERT_TRUE(fieldsets.empty()); |
| 4594 | 4594 |
| 4595 FormData form; | 4595 FormData form; |
| 4596 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( | 4596 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( |
| 4597 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, | 4597 fieldsets, control_elements, nullptr, frame->GetDocument(), extract_mask, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4649 {"<FORM name='TestForm' action='http://abc.com' method='post'>" | 4649 {"<FORM name='TestForm' action='http://abc.com' method='post'>" |
| 4650 " <INPUT type='password' id='pw'/>" | 4650 " <INPUT type='password' id='pw'/>" |
| 4651 " <INPUT type='password' id='new_pw'/>" | 4651 " <INPUT type='password' id='new_pw'/>" |
| 4652 "</FORM>", | 4652 "</FORM>", |
| 4653 true, true, false}, | 4653 true, true, false}, |
| 4654 }; | 4654 }; |
| 4655 | 4655 |
| 4656 for (auto test_case : test_cases) { | 4656 for (auto test_case : test_cases) { |
| 4657 LoadHTML(test_case.html); | 4657 LoadHTML(test_case.html); |
| 4658 | 4658 |
| 4659 WebFrame* web_frame = GetMainFrame(); | 4659 WebLocalFrame* web_frame = GetMainFrame(); |
| 4660 ASSERT_NE(nullptr, web_frame); | 4660 ASSERT_NE(nullptr, web_frame); |
| 4661 | 4661 |
| 4662 FormCache form_cache(*web_frame); | 4662 FormCache form_cache(*web_frame); |
| 4663 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 4663 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 4664 EXPECT_EQ(test_case.has_extracted_form, forms.size() == 1); | 4664 EXPECT_EQ(test_case.has_extracted_form, forms.size() == 1); |
| 4665 | 4665 |
| 4666 if (test_case.has_extracted_form) { | 4666 if (test_case.has_extracted_form) { |
| 4667 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); | 4667 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); |
| 4668 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); | 4668 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); |
| 4669 } | 4669 } |
| 4670 } | 4670 } |
| 4671 } | 4671 } |
| 4672 | 4672 |
| 4673 } // namespace form_util | 4673 } // namespace form_util |
| 4674 } // namespace autofill | 4674 } // namespace autofill |
| OLD | NEW |