Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 242613006: [Autofill] Enable Autofill for dynamically created forms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 ASSERT_EQ(labels.size(), values.size()); 110 ASSERT_EQ(labels.size(), values.size());
111 ASSERT_EQ(labels.size(), control_types.size()); 111 ASSERT_EQ(labels.size(), control_types.size());
112 112
113 LoadHTML(html); 113 LoadHTML(html);
114 114
115 WebFrame* web_frame = GetMainFrame(); 115 WebFrame* web_frame = GetMainFrame();
116 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 116 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
117 117
118 FormCache form_cache; 118 FormCache form_cache;
119 std::vector<FormData> forms; 119 std::vector<FormData> forms;
120 form_cache.ExtractForms(*web_frame, &forms); 120 form_cache.ExtractNewForms(*web_frame, &forms);
121 ASSERT_EQ(1U, forms.size()); 121 ASSERT_EQ(1U, forms.size());
122 122
123 const FormData& form = forms[0]; 123 const FormData& form = forms[0];
124 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 124 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
125 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 125 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
126 EXPECT_EQ(GURL("http://cnn.com"), form.action); 126 EXPECT_EQ(GURL("http://cnn.com"), form.action);
127 127
128 const std::vector<FormFieldData>& fields = form.fields; 128 const std::vector<FormFieldData>& fields = form.fields;
129 ASSERT_EQ(labels.size(), fields.size()); 129 ASSERT_EQ(labels.size(), fields.size());
130 for (size_t i = 0; i < labels.size(); ++i) { 130 for (size_t i = 0; i < labels.size(); ++i) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 size_t number_of_field_cases, 170 size_t number_of_field_cases,
171 FillFormFunction fill_form_function, 171 FillFormFunction fill_form_function,
172 GetValueFunction get_value_function) { 172 GetValueFunction get_value_function) {
173 LoadHTML(html); 173 LoadHTML(html);
174 174
175 WebFrame* web_frame = GetMainFrame(); 175 WebFrame* web_frame = GetMainFrame();
176 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 176 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
177 177
178 FormCache form_cache; 178 FormCache form_cache;
179 std::vector<FormData> forms; 179 std::vector<FormData> forms;
180 form_cache.ExtractForms(*web_frame, &forms); 180 form_cache.ExtractNewForms(*web_frame, &forms);
181 ASSERT_EQ(1U, forms.size()); 181 ASSERT_EQ(1U, forms.size());
182 182
183 // Get the input element we want to find. 183 // Get the input element we want to find.
184 WebElement element = web_frame->document().getElementById("firstname"); 184 WebElement element = web_frame->document().getElementById("firstname");
185 WebInputElement input_element = element.to<WebInputElement>(); 185 WebInputElement input_element = element.to<WebInputElement>();
186 186
187 // Find the form that contains the input element. 187 // Find the form that contains the input element.
188 FormData form_data; 188 FormData form_data;
189 FormFieldData field; 189 FormFieldData field;
190 EXPECT_TRUE( 190 EXPECT_TRUE(
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>" 798 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>"
799 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" 799 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>"
800 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 800 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
801 "</FORM>"); 801 "</FORM>");
802 802
803 WebFrame* web_frame = GetMainFrame(); 803 WebFrame* web_frame = GetMainFrame();
804 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 804 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
805 805
806 FormCache form_cache; 806 FormCache form_cache;
807 std::vector<FormData> forms; 807 std::vector<FormData> forms;
808 form_cache.ExtractForms(*web_frame, &forms); 808 form_cache.ExtractNewForms(*web_frame, &forms);
809 ASSERT_EQ(2U, forms.size()); 809 ASSERT_EQ(2U, forms.size());
810 810
811 // First form. 811 // First form.
812 const FormData& form = forms[0]; 812 const FormData& form = forms[0];
813 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 813 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
814 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 814 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
815 EXPECT_EQ(GURL("http://cnn.com"), form.action); 815 EXPECT_EQ(GURL("http://cnn.com"), form.action);
816 816
817 const std::vector<FormFieldData>& fields = form.fields; 817 const std::vector<FormFieldData>& fields = form.fields;
818 ASSERT_EQ(3U, fields.size()); 818 ASSERT_EQ(3U, fields.size());
(...skipping 29 matching lines...) Expand all
848 848
849 expected.name = ASCIIToUTF16("lastname"); 849 expected.name = ASCIIToUTF16("lastname");
850 expected.value = ASCIIToUTF16("Adams"); 850 expected.value = ASCIIToUTF16("Adams");
851 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); 851 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
852 852
853 expected.name = ASCIIToUTF16("email"); 853 expected.name = ASCIIToUTF16("email");
854 expected.value = ASCIIToUTF16("jack@example.com"); 854 expected.value = ASCIIToUTF16("jack@example.com");
855 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); 855 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
856 } 856 }
857 857
858 TEST_F(FormAutofillTest, OnlyExtractNewForms) {
859 LoadHTML(
860 "<FORM id='testform' action='http://cnn.com' method='post'>"
861 " <INPUT type='text' id='firstname' value='John'/>"
862 " <INPUT type='text' id='lastname' value='Smith'/>"
863 " <INPUT type='text' id='email' value='john@example.com'/>"
864 " <INPUT type='submit' name='reply-send' value='Send'/>"
865 "</FORM>");
866
867 WebFrame* web_frame = GetMainFrame();
868 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
869
870 FormCache form_cache;
871 std::vector<FormData> forms;
872 form_cache.ExtractNewForms(*web_frame, &forms);
873 ASSERT_EQ(1U, forms.size());
874 forms.clear();
875
876 // Second call should give nothing as there are no new forms.
877 form_cache.ExtractNewForms(*web_frame, &forms);
878 ASSERT_EQ(0U, forms.size());
879
880 // Append to the current form will re-extract.
881 ExecuteJavaScript(
882 "var newInput=document.createElement('input');"
Ilya Sherman 2014/04/23 05:51:36 nit: Please add spaces around the equals sign.
Garrett Casto 2014/04/23 21:51:14 Done.
883 "newInput.setAttribute('type', 'text');"
884 "newInput.setAttribute('id', 'telephone');"
885 "newInput.value = '12345';"
886 "document.getElementById('testform').appendChild(newInput);");
887 msg_loop_.RunUntilIdle();
888
889 form_cache.ExtractNewForms(*web_frame, &forms);
890 ASSERT_EQ(1U, forms.size());
891
892 const std::vector<FormFieldData>& fields = forms[0].fields;
893 ASSERT_EQ(4U, fields.size());
894
895 FormFieldData expected;
896 expected.form_control_type = "text";
897 expected.max_length = WebInputElement::defaultMaxLength();
898
899 expected.name = ASCIIToUTF16("firstname");
900 expected.value = ASCIIToUTF16("John");
901 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
902
903 expected.name = ASCIIToUTF16("lastname");
904 expected.value = ASCIIToUTF16("Smith");
905 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
906
907 expected.name = ASCIIToUTF16("email");
908 expected.value = ASCIIToUTF16("john@example.com");
909 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
910
911 expected.name = ASCIIToUTF16("telephone");
912 expected.value = ASCIIToUTF16("12345");
913 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
914
915 forms.clear();
916
917 // Completely new form will also be extracted.
918 ExecuteJavaScript(
919 "var newForm=document.createElement('form');"
920 "newForm.id='new_testform';"
921 "newForm.action='http://google.com';"
922 "newForm.method='post';"
923 "var newFirstname=document.createElement('input');"
924 "newFirstname.setAttribute('type', 'text');"
925 "newFirstname.setAttribute('id', 'second_firstname');"
926 "newFirstname.value = 'Bob';"
927 "var newLastname=document.createElement('input');"
928 "newLastname.setAttribute('type', 'text');"
929 "newLastname.setAttribute('id', 'second_lastname');"
930 "newLastname.value = 'Hope';"
931 "var newEmail=document.createElement('input');"
932 "newEmail.setAttribute('type', 'text');"
933 "newEmail.setAttribute('id', 'second_email');"
934 "newEmail.value = 'bobhope@example.com';"
935 "newForm.appendChild(newFirstname);"
936 "newForm.appendChild(newLastname);"
937 "newForm.appendChild(newEmail);"
938 "document.body.appendChild(newForm);");
939 msg_loop_.RunUntilIdle();
940
941 web_frame = GetMainFrame();
942 form_cache.ExtractNewForms(*web_frame, &forms);
943 ASSERT_EQ(1U, forms.size());
944
945 const std::vector<FormFieldData>& fields2 = forms[0].fields;
946 ASSERT_EQ(3U, fields2.size());
947
948 expected.name = ASCIIToUTF16("second_firstname");
949 expected.value = ASCIIToUTF16("Bob");
950 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
951
952 expected.name = ASCIIToUTF16("second_lastname");
953 expected.value = ASCIIToUTF16("Hope");
954 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
955
956 expected.name = ASCIIToUTF16("second_email");
957 expected.value = ASCIIToUTF16("bobhope@example.com");
958 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
959 }
960
858 // We should not extract a form if it has too few fillable fields. 961 // We should not extract a form if it has too few fillable fields.
859 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { 962 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
860 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 963 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
861 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 964 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
862 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 965 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
863 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 966 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
864 "</FORM>"); 967 "</FORM>");
865 968
866 WebFrame* web_frame = GetMainFrame(); 969 WebFrame* web_frame = GetMainFrame();
867 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 970 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
868 971
869 FormCache form_cache; 972 FormCache form_cache;
870 std::vector<FormData> forms; 973 std::vector<FormData> forms;
871 form_cache.ExtractForms(*web_frame, &forms); 974 form_cache.ExtractNewForms(*web_frame, &forms);
872 EXPECT_EQ(0U, forms.size()); 975 EXPECT_EQ(0U, forms.size());
873 } 976 }
874 977
875 // We should not report additional forms for empty forms. 978 // We should not report additional forms for empty forms.
876 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { 979 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) {
877 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 980 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
878 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 981 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
879 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 982 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
880 "</FORM>"); 983 "</FORM>");
881 984
882 WebFrame* web_frame = GetMainFrame(); 985 WebFrame* web_frame = GetMainFrame();
883 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 986 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
884 987
885 FormCache form_cache; 988 FormCache form_cache;
886 std::vector<FormData> forms; 989 std::vector<FormData> forms;
887 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, 990 form_cache.ExtractNewForms(*web_frame, &forms);
888 3,
889 &forms,
890 NULL);
891 EXPECT_EQ(0U, forms.size()); 991 EXPECT_EQ(0U, forms.size());
892 EXPECT_TRUE(has_skipped_forms);
893 } 992 }
894 993
895 // We should not report additional forms for empty forms. 994 // We should not report additional forms for empty forms.
896 TEST_F(FormAutofillTest, ExtractFormsNoFields) { 995 TEST_F(FormAutofillTest, ExtractFormsNoFields) {
897 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 996 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
898 "</FORM>"); 997 "</FORM>");
899 998
900 WebFrame* web_frame = GetMainFrame(); 999 WebFrame* web_frame = GetMainFrame();
901 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1000 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
902 1001
903 FormCache form_cache; 1002 FormCache form_cache;
904 std::vector<FormData> forms; 1003 std::vector<FormData> forms;
905 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, 1004 form_cache.ExtractNewForms(*web_frame, &forms);
906 3,
907 &forms,
908 NULL);
909 EXPECT_EQ(0U, forms.size()); 1005 EXPECT_EQ(0U, forms.size());
910 EXPECT_FALSE(has_skipped_forms);
911 } 1006 }
912 1007
913 // We should not extract a form if it has too few fillable fields. 1008 // We should not extract a form if it has too few fillable fields.
914 // Make sure radio and checkbox fields don't count. 1009 // Make sure radio and checkbox fields don't count.
915 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { 1010 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
916 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1011 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
917 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1012 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
918 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1013 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
919 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>" 1014 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>"
920 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>" 1015 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>"
921 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1016 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
922 "</FORM>"); 1017 "</FORM>");
923 1018
924 WebFrame* web_frame = GetMainFrame(); 1019 WebFrame* web_frame = GetMainFrame();
925 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1020 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
926 1021
927 FormCache form_cache; 1022 FormCache form_cache;
928 std::vector<FormData> forms; 1023 std::vector<FormData> forms;
929 form_cache.ExtractForms(*web_frame, &forms); 1024 form_cache.ExtractNewForms(*web_frame, &forms);
930 EXPECT_EQ(0U, forms.size()); 1025 EXPECT_EQ(0U, forms.size());
931 } 1026 }
932 1027
933 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { 1028 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) {
934 { 1029 {
935 // Form is not auto-completable due to autocomplete=off. 1030 // Form is not auto-completable due to autocomplete=off.
936 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\"" 1031 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\""
937 " autocomplete=off>" 1032 " autocomplete=off>"
938 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1033 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
939 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1034 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 "autocomplete=\"off\" />" 1111 "autocomplete=\"off\" />"
1017 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>" 1112 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>"
1018 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1113 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1019 "</FORM>"); 1114 "</FORM>");
1020 1115
1021 WebFrame* web_frame = GetMainFrame(); 1116 WebFrame* web_frame = GetMainFrame();
1022 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1117 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1023 1118
1024 FormCache form_cache; 1119 FormCache form_cache;
1025 std::vector<FormData> forms; 1120 std::vector<FormData> forms;
1026 form_cache.ExtractForms(*web_frame, &forms); 1121 form_cache.ExtractNewForms(*web_frame, &forms);
1027 ASSERT_EQ(1U, forms.size()); 1122 ASSERT_EQ(1U, forms.size());
1028 1123
1029 // Get the input element we want to find. 1124 // Get the input element we want to find.
1030 WebElement element = web_frame->document().getElementById("firstname"); 1125 WebElement element = web_frame->document().getElementById("firstname");
1031 WebInputElement input_element = element.to<WebInputElement>(); 1126 WebInputElement input_element = element.to<WebInputElement>();
1032 1127
1033 // Find the form and verify it's the correct form. 1128 // Find the form and verify it's the correct form.
1034 FormData form; 1129 FormData form;
1035 FormFieldData field; 1130 FormFieldData field;
1036 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 1131 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 "Apt. 42" 1205 "Apt. 42"
1111 "</TEXTAREA>" 1206 "</TEXTAREA>"
1112 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1207 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1113 "</FORM>"); 1208 "</FORM>");
1114 1209
1115 WebFrame* web_frame = GetMainFrame(); 1210 WebFrame* web_frame = GetMainFrame();
1116 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1211 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1117 1212
1118 FormCache form_cache; 1213 FormCache form_cache;
1119 std::vector<FormData> forms; 1214 std::vector<FormData> forms;
1120 form_cache.ExtractForms(*web_frame, &forms); 1215 form_cache.ExtractNewForms(*web_frame, &forms);
1121 ASSERT_EQ(1U, forms.size()); 1216 ASSERT_EQ(1U, forms.size());
1122 1217
1123 // Get the textarea element we want to find. 1218 // Get the textarea element we want to find.
1124 WebElement element = web_frame->document().getElementById("street-address"); 1219 WebElement element = web_frame->document().getElementById("street-address");
1125 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); 1220 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>();
1126 1221
1127 // Find the form and verify it's the correct form. 1222 // Find the form and verify it's the correct form.
1128 FormData form; 1223 FormData form;
1129 FormFieldData field; 1224 FormFieldData field;
1130 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element, 1225 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element,
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>" 2302 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>"
2208 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>" 2303 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>"
2209 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2304 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2210 "</FORM>"); 2305 "</FORM>");
2211 2306
2212 WebFrame* web_frame = GetMainFrame(); 2307 WebFrame* web_frame = GetMainFrame();
2213 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2308 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2214 2309
2215 FormCache form_cache; 2310 FormCache form_cache;
2216 std::vector<FormData> forms; 2311 std::vector<FormData> forms;
2217 form_cache.ExtractForms(*web_frame, &forms); 2312 form_cache.ExtractNewForms(*web_frame, &forms);
2218 ASSERT_EQ(1U, forms.size()); 2313 ASSERT_EQ(1U, forms.size());
2219 2314
2220 // Get the input element we want to find. 2315 // Get the input element we want to find.
2221 WebElement element = web_frame->document().getElementById("firstname"); 2316 WebElement element = web_frame->document().getElementById("firstname");
2222 WebInputElement input_element = element.to<WebInputElement>(); 2317 WebInputElement input_element = element.to<WebInputElement>();
2223 2318
2224 // Find the form that contains the input element. 2319 // Find the form that contains the input element.
2225 FormData form; 2320 FormData form;
2226 FormFieldData field; 2321 FormFieldData field;
2227 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2322 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" 2399 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
2305 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" 2400 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>"
2306 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2401 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2307 "</FORM>"); 2402 "</FORM>");
2308 2403
2309 WebFrame* web_frame = GetMainFrame(); 2404 WebFrame* web_frame = GetMainFrame();
2310 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2405 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2311 2406
2312 FormCache form_cache; 2407 FormCache form_cache;
2313 std::vector<FormData> forms; 2408 std::vector<FormData> forms;
2314 form_cache.ExtractForms(*web_frame, &forms); 2409 form_cache.ExtractNewForms(*web_frame, &forms);
2315 ASSERT_EQ(1U, forms.size()); 2410 ASSERT_EQ(1U, forms.size());
2316 2411
2317 // Get the input element we want to find. 2412 // Get the input element we want to find.
2318 WebElement element = web_frame->document().getElementById("firstname"); 2413 WebElement element = web_frame->document().getElementById("firstname");
2319 WebInputElement input_element = element.to<WebInputElement>(); 2414 WebInputElement input_element = element.to<WebInputElement>();
2320 2415
2321 // Find the form that contains the input element. 2416 // Find the form that contains the input element.
2322 FormData form; 2417 FormData form;
2323 FormFieldData field; 2418 FormFieldData field;
2324 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2419 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 " <INPUT type=\"text\" id=\"lastname\"/>" 2480 " <INPUT type=\"text\" id=\"lastname\"/>"
2386 " <INPUT type=\"text\" id=\"email\"/>" 2481 " <INPUT type=\"text\" id=\"email\"/>"
2387 " <INPUT type=\"submit\" value=\"Send\"/>" 2482 " <INPUT type=\"submit\" value=\"Send\"/>"
2388 "</FORM>"); 2483 "</FORM>");
2389 2484
2390 WebFrame* web_frame = GetMainFrame(); 2485 WebFrame* web_frame = GetMainFrame();
2391 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2486 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2392 2487
2393 FormCache form_cache; 2488 FormCache form_cache;
2394 std::vector<FormData> forms; 2489 std::vector<FormData> forms;
2395 form_cache.ExtractForms(*web_frame, &forms); 2490 form_cache.ExtractNewForms(*web_frame, &forms);
2396 ASSERT_EQ(1U, forms.size()); 2491 ASSERT_EQ(1U, forms.size());
2397 2492
2398 // Get the input element we want to find. 2493 // Get the input element we want to find.
2399 WebElement element = web_frame->document().getElementById("firstname"); 2494 WebElement element = web_frame->document().getElementById("firstname");
2400 WebInputElement input_element = element.to<WebInputElement>(); 2495 WebInputElement input_element = element.to<WebInputElement>();
2401 2496
2402 // Find the form that contains the input element. 2497 // Find the form that contains the input element.
2403 FormData form; 2498 FormData form;
2404 FormFieldData field; 2499 FormFieldData field;
2405 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2500 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 " <INPUT type=\"text\" id=\"banana\"/>" 2570 " <INPUT type=\"text\" id=\"banana\"/>"
2476 " <INPUT type=\"text\" id=\"cantelope\"/>" 2571 " <INPUT type=\"text\" id=\"cantelope\"/>"
2477 " <INPUT type=\"submit\" value=\"Send\"/>" 2572 " <INPUT type=\"submit\" value=\"Send\"/>"
2478 "</FORM>"); 2573 "</FORM>");
2479 2574
2480 WebFrame* web_frame = GetMainFrame(); 2575 WebFrame* web_frame = GetMainFrame();
2481 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2576 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2482 2577
2483 FormCache form_cache; 2578 FormCache form_cache;
2484 std::vector<FormData> forms; 2579 std::vector<FormData> forms;
2485 form_cache.ExtractForms(*web_frame, &forms); 2580 form_cache.ExtractNewForms(*web_frame, &forms);
2486 ASSERT_EQ(2U, forms.size()); 2581 ASSERT_EQ(2U, forms.size());
2487 2582
2488 // Get the input element we want to find. 2583 // Get the input element we want to find.
2489 WebElement element = web_frame->document().getElementById("apple"); 2584 WebElement element = web_frame->document().getElementById("apple");
2490 WebInputElement input_element = element.to<WebInputElement>(); 2585 WebInputElement input_element = element.to<WebInputElement>();
2491 2586
2492 // Find the form that contains the input element. 2587 // Find the form that contains the input element.
2493 FormData form; 2588 FormData form;
2494 FormFieldData field; 2589 FormFieldData field;
2495 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2590 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 " <INPUT type=\"text\" id=\"lastname\"/>" 2790 " <INPUT type=\"text\" id=\"lastname\"/>"
2696 " <INPUT type=\"text\" id=\"email\"/>" 2791 " <INPUT type=\"text\" id=\"email\"/>"
2697 " <INPUT type=\"submit\" value=\"Send\"/>" 2792 " <INPUT type=\"submit\" value=\"Send\"/>"
2698 "</FORM>"); 2793 "</FORM>");
2699 2794
2700 WebFrame* web_frame = GetMainFrame(); 2795 WebFrame* web_frame = GetMainFrame();
2701 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2796 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2702 2797
2703 FormCache form_cache; 2798 FormCache form_cache;
2704 std::vector<FormData> forms; 2799 std::vector<FormData> forms;
2705 form_cache.ExtractForms(*web_frame, &forms); 2800 form_cache.ExtractNewForms(*web_frame, &forms);
2706 ASSERT_EQ(1U, forms.size()); 2801 ASSERT_EQ(1U, forms.size());
2707 2802
2708 // Get the input element we want to find. 2803 // Get the input element we want to find.
2709 WebElement element = web_frame->document().getElementById("firstname"); 2804 WebElement element = web_frame->document().getElementById("firstname");
2710 WebInputElement input_element = element.to<WebInputElement>(); 2805 WebInputElement input_element = element.to<WebInputElement>();
2711 2806
2712 // Simulate typing by modifying the field value. 2807 // Simulate typing by modifying the field value.
2713 input_element.setValue(ASCIIToUTF16("Wy")); 2808 input_element.setValue(ASCIIToUTF16("Wy"));
2714 2809
2715 // Find the form that contains the input element. 2810 // Find the form that contains the input element.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2807 " </TEXTAREA>" 2902 " </TEXTAREA>"
2808 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>" 2903 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>"
2809 " <INPUT type=\"submit\" value=\"Send\"/>" 2904 " <INPUT type=\"submit\" value=\"Send\"/>"
2810 "</FORM>"); 2905 "</FORM>");
2811 2906
2812 WebFrame* web_frame = GetMainFrame(); 2907 WebFrame* web_frame = GetMainFrame();
2813 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2908 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2814 2909
2815 FormCache form_cache; 2910 FormCache form_cache;
2816 std::vector<FormData> forms; 2911 std::vector<FormData> forms;
2817 form_cache.ExtractForms(*web_frame, &forms); 2912 form_cache.ExtractNewForms(*web_frame, &forms);
2818 ASSERT_EQ(1U, forms.size()); 2913 ASSERT_EQ(1U, forms.size());
2819 2914
2820 // Set the auto-filled attribute on the firstname element. 2915 // Set the auto-filled attribute on the firstname element.
2821 WebInputElement firstname = 2916 WebInputElement firstname =
2822 web_frame->document().getElementById("firstname").to<WebInputElement>(); 2917 web_frame->document().getElementById("firstname").to<WebInputElement>();
2823 firstname.setAutofilled(true); 2918 firstname.setAutofilled(true);
2824 2919
2825 // Set the value of the disabled text input element. 2920 // Set the value of the disabled text input element.
2826 WebInputElement notenabled = 2921 WebInputElement notenabled =
2827 web_frame->document().getElementById("notenabled").to<WebInputElement>(); 2922 web_frame->document().getElementById("notenabled").to<WebInputElement>();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 " <OPTION>AK</OPTION>" 3006 " <OPTION>AK</OPTION>"
2912 " </SELECT>" 3007 " </SELECT>"
2913 " <INPUT type=\"submit\" value=\"Send\"/>" 3008 " <INPUT type=\"submit\" value=\"Send\"/>"
2914 "</FORM>"); 3009 "</FORM>");
2915 3010
2916 WebFrame* web_frame = GetMainFrame(); 3011 WebFrame* web_frame = GetMainFrame();
2917 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3012 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2918 3013
2919 FormCache form_cache; 3014 FormCache form_cache;
2920 std::vector<FormData> forms; 3015 std::vector<FormData> forms;
2921 form_cache.ExtractForms(*web_frame, &forms); 3016 form_cache.ExtractNewForms(*web_frame, &forms);
2922 ASSERT_EQ(1U, forms.size()); 3017 ASSERT_EQ(1U, forms.size());
2923 3018
2924 // Set the auto-filled attribute on the firstname element. 3019 // Set the auto-filled attribute on the firstname element.
2925 WebInputElement firstname = 3020 WebInputElement firstname =
2926 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3021 web_frame->document().getElementById("firstname").to<WebInputElement>();
2927 firstname.setAutofilled(true); 3022 firstname.setAutofilled(true);
2928 3023
2929 // Set the value of the select-one. 3024 // Set the value of the select-one.
2930 WebSelectElement select_element = 3025 WebSelectElement select_element =
2931 web_frame->document().getElementById("state").to<WebSelectElement>(); 3026 web_frame->document().getElementById("state").to<WebSelectElement>();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2984 " <INPUT type=\"email\" id=\"email2\"/>" 3079 " <INPUT type=\"email\" id=\"email2\"/>"
2985 " <INPUT type=\"tel\" id=\"phone\"/>" 3080 " <INPUT type=\"tel\" id=\"phone\"/>"
2986 " <INPUT type=\"submit\" value=\"Send\"/>" 3081 " <INPUT type=\"submit\" value=\"Send\"/>"
2987 "</FORM>"); 3082 "</FORM>");
2988 3083
2989 WebFrame* web_frame = GetMainFrame(); 3084 WebFrame* web_frame = GetMainFrame();
2990 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3085 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2991 3086
2992 FormCache form_cache; 3087 FormCache form_cache;
2993 std::vector<FormData> forms; 3088 std::vector<FormData> forms;
2994 form_cache.ExtractForms(*web_frame, &forms); 3089 form_cache.ExtractNewForms(*web_frame, &forms);
2995 ASSERT_EQ(1U, forms.size()); 3090 ASSERT_EQ(1U, forms.size());
2996 3091
2997 // Set the auto-filled attribute. 3092 // Set the auto-filled attribute.
2998 WebInputElement firstname = 3093 WebInputElement firstname =
2999 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3094 web_frame->document().getElementById("firstname").to<WebInputElement>();
3000 firstname.setAutofilled(true); 3095 firstname.setAutofilled(true);
3001 WebInputElement lastname = 3096 WebInputElement lastname =
3002 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3097 web_frame->document().getElementById("lastname").to<WebInputElement>();
3003 lastname.setAutofilled(true); 3098 lastname.setAutofilled(true);
3004 WebInputElement email = 3099 WebInputElement email =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 " <INPUT type=\"email\" id=\"email2\"/>" 3147 " <INPUT type=\"email\" id=\"email2\"/>"
3053 " <INPUT type=\"tel\" id=\"phone\"/>" 3148 " <INPUT type=\"tel\" id=\"phone\"/>"
3054 " <INPUT type=\"submit\" value=\"Send\"/>" 3149 " <INPUT type=\"submit\" value=\"Send\"/>"
3055 "</FORM>"); 3150 "</FORM>");
3056 3151
3057 WebFrame* web_frame = GetMainFrame(); 3152 WebFrame* web_frame = GetMainFrame();
3058 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3153 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3059 3154
3060 FormCache form_cache; 3155 FormCache form_cache;
3061 std::vector<FormData> forms; 3156 std::vector<FormData> forms;
3062 form_cache.ExtractForms(*web_frame, &forms); 3157 form_cache.ExtractNewForms(*web_frame, &forms);
3063 ASSERT_EQ(1U, forms.size()); 3158 ASSERT_EQ(1U, forms.size());
3064 3159
3065 // Set the auto-filled attribute. 3160 // Set the auto-filled attribute.
3066 WebInputElement firstname = 3161 WebInputElement firstname =
3067 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3162 web_frame->document().getElementById("firstname").to<WebInputElement>();
3068 firstname.setAutofilled(true); 3163 firstname.setAutofilled(true);
3069 WebInputElement lastname = 3164 WebInputElement lastname =
3070 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3165 web_frame->document().getElementById("lastname").to<WebInputElement>();
3071 lastname.setAutofilled(true); 3166 lastname.setAutofilled(true);
3072 WebInputElement email = 3167 WebInputElement email =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3120 " <INPUT type=\"email\" id=\"email2\"/>" 3215 " <INPUT type=\"email\" id=\"email2\"/>"
3121 " <INPUT type=\"tel\" id=\"phone\"/>" 3216 " <INPUT type=\"tel\" id=\"phone\"/>"
3122 " <INPUT type=\"submit\" value=\"Send\"/>" 3217 " <INPUT type=\"submit\" value=\"Send\"/>"
3123 "</FORM>"); 3218 "</FORM>");
3124 3219
3125 WebFrame* web_frame = GetMainFrame(); 3220 WebFrame* web_frame = GetMainFrame();
3126 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3221 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3127 3222
3128 FormCache form_cache; 3223 FormCache form_cache;
3129 std::vector<FormData> forms; 3224 std::vector<FormData> forms;
3130 form_cache.ExtractForms(*web_frame, &forms); 3225 form_cache.ExtractNewForms(*web_frame, &forms);
3131 ASSERT_EQ(1U, forms.size()); 3226 ASSERT_EQ(1U, forms.size());
3132 3227
3133 // Set the auto-filled attribute. 3228 // Set the auto-filled attribute.
3134 WebInputElement firstname = 3229 WebInputElement firstname =
3135 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3230 web_frame->document().getElementById("firstname").to<WebInputElement>();
3136 firstname.setAutofilled(true); 3231 firstname.setAutofilled(true);
3137 WebInputElement lastname = 3232 WebInputElement lastname =
3138 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3233 web_frame->document().getElementById("lastname").to<WebInputElement>();
3139 lastname.setAutofilled(true); 3234 lastname.setAutofilled(true);
3140 WebInputElement email = 3235 WebInputElement email =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3187 " <INPUT type=\"email\" id=\"email2\"/>" 3282 " <INPUT type=\"email\" id=\"email2\"/>"
3188 " <INPUT type=\"tel\" id=\"phone\"/>" 3283 " <INPUT type=\"tel\" id=\"phone\"/>"
3189 " <INPUT type=\"submit\" value=\"Send\"/>" 3284 " <INPUT type=\"submit\" value=\"Send\"/>"
3190 "</FORM>"); 3285 "</FORM>");
3191 3286
3192 WebFrame* web_frame = GetMainFrame(); 3287 WebFrame* web_frame = GetMainFrame();
3193 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3288 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3194 3289
3195 FormCache form_cache; 3290 FormCache form_cache;
3196 std::vector<FormData> forms; 3291 std::vector<FormData> forms;
3197 form_cache.ExtractForms(*web_frame, &forms); 3292 form_cache.ExtractNewForms(*web_frame, &forms);
3198 ASSERT_EQ(1U, forms.size()); 3293 ASSERT_EQ(1U, forms.size());
3199 3294
3200 WebInputElement firstname = 3295 WebInputElement firstname =
3201 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3296 web_frame->document().getElementById("firstname").to<WebInputElement>();
3202 3297
3203 // Auto-filled attribute not set yet. 3298 // Auto-filled attribute not set yet.
3204 EXPECT_FALSE(FormWithElementIsAutofilled(firstname)); 3299 EXPECT_FALSE(FormWithElementIsAutofilled(firstname));
3205 3300
3206 // Set the auto-filled attribute. 3301 // Set the auto-filled attribute.
3207 firstname.setAutofilled(true); 3302 firstname.setAutofilled(true);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3353 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 3448 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3354 3449
3355 expected.name = ASCIIToUTF16("country"); 3450 expected.name = ASCIIToUTF16("country");
3356 expected.value = ASCIIToUTF16("AL"); 3451 expected.value = ASCIIToUTF16("AL");
3357 expected.form_control_type = "select-one"; 3452 expected.form_control_type = "select-one";
3358 expected.max_length = 0; 3453 expected.max_length = 0;
3359 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3454 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3360 } 3455 }
3361 3456
3362 } // namespace autofill 3457 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698