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

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

Issue 277043002: Revert "Revert of [Autofill] Enable Autofill for dynamically created forms. (https://codereview.chr… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix form_structure_browsertests Created 6 years, 7 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
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 ASSERT_EQ(labels.size(), values.size()); 111 ASSERT_EQ(labels.size(), values.size());
112 ASSERT_EQ(labels.size(), control_types.size()); 112 ASSERT_EQ(labels.size(), control_types.size());
113 113
114 LoadHTML(html); 114 LoadHTML(html);
115 115
116 WebFrame* web_frame = GetMainFrame(); 116 WebFrame* web_frame = GetMainFrame();
117 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 117 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
118 118
119 FormCache form_cache; 119 FormCache form_cache;
120 std::vector<FormData> forms; 120 std::vector<FormData> forms;
121 form_cache.ExtractForms(*web_frame, &forms); 121 form_cache.ExtractNewForms(*web_frame, &forms);
122 ASSERT_EQ(1U, forms.size()); 122 ASSERT_EQ(1U, forms.size());
123 123
124 const FormData& form = forms[0]; 124 const FormData& form = forms[0];
125 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 125 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
126 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 126 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
127 EXPECT_EQ(GURL("http://cnn.com"), form.action); 127 EXPECT_EQ(GURL("http://cnn.com"), form.action);
128 128
129 const std::vector<FormFieldData>& fields = form.fields; 129 const std::vector<FormFieldData>& fields = form.fields;
130 ASSERT_EQ(labels.size(), fields.size()); 130 ASSERT_EQ(labels.size(), fields.size());
131 for (size_t i = 0; i < labels.size(); ++i) { 131 for (size_t i = 0; i < labels.size(); ++i) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 size_t number_of_field_cases, 171 size_t number_of_field_cases,
172 FillFormFunction fill_form_function, 172 FillFormFunction fill_form_function,
173 GetValueFunction get_value_function) { 173 GetValueFunction get_value_function) {
174 LoadHTML(html); 174 LoadHTML(html);
175 175
176 WebFrame* web_frame = GetMainFrame(); 176 WebFrame* web_frame = GetMainFrame();
177 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 177 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
178 178
179 FormCache form_cache; 179 FormCache form_cache;
180 std::vector<FormData> forms; 180 std::vector<FormData> forms;
181 form_cache.ExtractForms(*web_frame, &forms); 181 form_cache.ExtractNewForms(*web_frame, &forms);
182 ASSERT_EQ(1U, forms.size()); 182 ASSERT_EQ(1U, forms.size());
183 183
184 // Get the input element we want to find. 184 // Get the input element we want to find.
185 WebElement element = web_frame->document().getElementById("firstname"); 185 WebElement element = web_frame->document().getElementById("firstname");
186 WebInputElement input_element = element.to<WebInputElement>(); 186 WebInputElement input_element = element.to<WebInputElement>();
187 187
188 // Find the form that contains the input element. 188 // Find the form that contains the input element.
189 FormData form_data; 189 FormData form_data;
190 FormFieldData field; 190 FormFieldData field;
191 EXPECT_TRUE( 191 EXPECT_TRUE(
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>" 822 " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>"
823 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>" 823 " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>"
824 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 824 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
825 "</FORM>"); 825 "</FORM>");
826 826
827 WebFrame* web_frame = GetMainFrame(); 827 WebFrame* web_frame = GetMainFrame();
828 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 828 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
829 829
830 FormCache form_cache; 830 FormCache form_cache;
831 std::vector<FormData> forms; 831 std::vector<FormData> forms;
832 form_cache.ExtractForms(*web_frame, &forms); 832 form_cache.ExtractNewForms(*web_frame, &forms);
833 ASSERT_EQ(2U, forms.size()); 833 ASSERT_EQ(2U, forms.size());
834 834
835 // First form. 835 // First form.
836 const FormData& form = forms[0]; 836 const FormData& form = forms[0];
837 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); 837 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
838 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); 838 EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
839 EXPECT_EQ(GURL("http://cnn.com"), form.action); 839 EXPECT_EQ(GURL("http://cnn.com"), form.action);
840 840
841 const std::vector<FormFieldData>& fields = form.fields; 841 const std::vector<FormFieldData>& fields = form.fields;
842 ASSERT_EQ(3U, fields.size()); 842 ASSERT_EQ(3U, fields.size());
(...skipping 29 matching lines...) Expand all
872 872
873 expected.name = ASCIIToUTF16("lastname"); 873 expected.name = ASCIIToUTF16("lastname");
874 expected.value = ASCIIToUTF16("Adams"); 874 expected.value = ASCIIToUTF16("Adams");
875 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); 875 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
876 876
877 expected.name = ASCIIToUTF16("email"); 877 expected.name = ASCIIToUTF16("email");
878 expected.value = ASCIIToUTF16("jack@example.com"); 878 expected.value = ASCIIToUTF16("jack@example.com");
879 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); 879 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
880 } 880 }
881 881
882 TEST_F(FormAutofillTest, OnlyExtractNewForms) {
883 LoadHTML(
884 "<FORM id='testform' action='http://cnn.com' method='post'>"
885 " <INPUT type='text' id='firstname' value='John'/>"
886 " <INPUT type='text' id='lastname' value='Smith'/>"
887 " <INPUT type='text' id='email' value='john@example.com'/>"
888 " <INPUT type='submit' name='reply-send' value='Send'/>"
889 "</FORM>");
890
891 WebFrame* web_frame = GetMainFrame();
892 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
893
894 FormCache form_cache;
895 std::vector<FormData> forms;
896 form_cache.ExtractNewForms(*web_frame, &forms);
897 ASSERT_EQ(1U, forms.size());
898 forms.clear();
899
900 // Second call should give nothing as there are no new forms.
901 form_cache.ExtractNewForms(*web_frame, &forms);
902 ASSERT_EQ(0U, forms.size());
903
904 // Append to the current form will re-extract.
905 ExecuteJavaScript(
906 "var newInput = document.createElement('input');"
907 "newInput.setAttribute('type', 'text');"
908 "newInput.setAttribute('id', 'telephone');"
909 "newInput.value = '12345';"
910 "document.getElementById('testform').appendChild(newInput);");
911 msg_loop_.RunUntilIdle();
912
913 form_cache.ExtractNewForms(*web_frame, &forms);
914 ASSERT_EQ(1U, forms.size());
915
916 const std::vector<FormFieldData>& fields = forms[0].fields;
917 ASSERT_EQ(4U, fields.size());
918
919 FormFieldData expected;
920 expected.form_control_type = "text";
921 expected.max_length = WebInputElement::defaultMaxLength();
922
923 expected.name = ASCIIToUTF16("firstname");
924 expected.value = ASCIIToUTF16("John");
925 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
926
927 expected.name = ASCIIToUTF16("lastname");
928 expected.value = ASCIIToUTF16("Smith");
929 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
930
931 expected.name = ASCIIToUTF16("email");
932 expected.value = ASCIIToUTF16("john@example.com");
933 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
934
935 expected.name = ASCIIToUTF16("telephone");
936 expected.value = ASCIIToUTF16("12345");
937 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
938
939 forms.clear();
940
941 // Completely new form will also be extracted.
942 ExecuteJavaScript(
943 "var newForm=document.createElement('form');"
944 "newForm.id='new_testform';"
945 "newForm.action='http://google.com';"
946 "newForm.method='post';"
947 "var newFirstname=document.createElement('input');"
948 "newFirstname.setAttribute('type', 'text');"
949 "newFirstname.setAttribute('id', 'second_firstname');"
950 "newFirstname.value = 'Bob';"
951 "var newLastname=document.createElement('input');"
952 "newLastname.setAttribute('type', 'text');"
953 "newLastname.setAttribute('id', 'second_lastname');"
954 "newLastname.value = 'Hope';"
955 "var newEmail=document.createElement('input');"
956 "newEmail.setAttribute('type', 'text');"
957 "newEmail.setAttribute('id', 'second_email');"
958 "newEmail.value = 'bobhope@example.com';"
959 "newForm.appendChild(newFirstname);"
960 "newForm.appendChild(newLastname);"
961 "newForm.appendChild(newEmail);"
962 "document.body.appendChild(newForm);");
963 msg_loop_.RunUntilIdle();
964
965 web_frame = GetMainFrame();
966 form_cache.ExtractNewForms(*web_frame, &forms);
967 ASSERT_EQ(1U, forms.size());
968
969 const std::vector<FormFieldData>& fields2 = forms[0].fields;
970 ASSERT_EQ(3U, fields2.size());
971
972 expected.name = ASCIIToUTF16("second_firstname");
973 expected.value = ASCIIToUTF16("Bob");
974 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
975
976 expected.name = ASCIIToUTF16("second_lastname");
977 expected.value = ASCIIToUTF16("Hope");
978 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
979
980 expected.name = ASCIIToUTF16("second_email");
981 expected.value = ASCIIToUTF16("bobhope@example.com");
982 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
983 }
984
882 // We should not extract a form if it has too few fillable fields. 985 // We should not extract a form if it has too few fillable fields.
883 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { 986 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
884 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 987 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
885 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 988 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
886 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 989 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
887 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 990 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
888 "</FORM>"); 991 "</FORM>");
889 992
890 WebFrame* web_frame = GetMainFrame(); 993 WebFrame* web_frame = GetMainFrame();
891 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 994 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
892 995
893 FormCache form_cache; 996 FormCache form_cache;
894 std::vector<FormData> forms; 997 std::vector<FormData> forms;
895 form_cache.ExtractForms(*web_frame, &forms); 998 form_cache.ExtractNewForms(*web_frame, &forms);
896 EXPECT_EQ(0U, forms.size()); 999 EXPECT_EQ(0U, forms.size());
897 } 1000 }
898 1001
899 // We should not report additional forms for empty forms. 1002 // We should not report additional forms for empty forms.
900 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { 1003 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) {
901 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1004 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
902 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1005 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
903 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1006 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
904 "</FORM>"); 1007 "</FORM>");
905 1008
906 WebFrame* web_frame = GetMainFrame(); 1009 WebFrame* web_frame = GetMainFrame();
907 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1010 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
908 1011
909 FormCache form_cache; 1012 FormCache form_cache;
910 std::vector<FormData> forms; 1013 std::vector<FormData> forms;
911 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, 1014 form_cache.ExtractNewForms(*web_frame, &forms);
912 3,
913 &forms,
914 NULL);
915 EXPECT_EQ(0U, forms.size()); 1015 EXPECT_EQ(0U, forms.size());
916 EXPECT_TRUE(has_skipped_forms);
917 } 1016 }
918 1017
919 // We should not report additional forms for empty forms. 1018 // We should not report additional forms for empty forms.
920 TEST_F(FormAutofillTest, ExtractFormsNoFields) { 1019 TEST_F(FormAutofillTest, ExtractFormsNoFields) {
921 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1020 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
922 "</FORM>"); 1021 "</FORM>");
923 1022
924 WebFrame* web_frame = GetMainFrame(); 1023 WebFrame* web_frame = GetMainFrame();
925 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1024 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
926 1025
927 FormCache form_cache; 1026 FormCache form_cache;
928 std::vector<FormData> forms; 1027 std::vector<FormData> forms;
929 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, 1028 form_cache.ExtractNewForms(*web_frame, &forms);
930 3,
931 &forms,
932 NULL);
933 EXPECT_EQ(0U, forms.size()); 1029 EXPECT_EQ(0U, forms.size());
934 EXPECT_FALSE(has_skipped_forms);
935 } 1030 }
936 1031
937 // We should not extract a form if it has too few fillable fields. 1032 // We should not extract a form if it has too few fillable fields.
938 // Make sure radio and checkbox fields don't count. 1033 // Make sure radio and checkbox fields don't count.
939 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { 1034 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
940 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1035 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
941 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1036 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
942 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1037 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
943 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>" 1038 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>"
944 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>" 1039 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>"
945 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1040 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
946 "</FORM>"); 1041 "</FORM>");
947 1042
948 WebFrame* web_frame = GetMainFrame(); 1043 WebFrame* web_frame = GetMainFrame();
949 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1044 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
950 1045
951 FormCache form_cache; 1046 FormCache form_cache;
952 std::vector<FormData> forms; 1047 std::vector<FormData> forms;
953 form_cache.ExtractForms(*web_frame, &forms); 1048 form_cache.ExtractNewForms(*web_frame, &forms);
954 EXPECT_EQ(0U, forms.size()); 1049 EXPECT_EQ(0U, forms.size());
955 } 1050 }
956 1051
957 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { 1052 TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) {
958 { 1053 {
959 // Form is not auto-completable due to autocomplete=off. 1054 // Form is not auto-completable due to autocomplete=off.
960 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\"" 1055 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\""
961 " autocomplete=off>" 1056 " autocomplete=off>"
962 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" 1057 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
963 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" 1058 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 "autocomplete=\"off\" />" 1135 "autocomplete=\"off\" />"
1041 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>" 1136 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>"
1042 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1137 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1043 "</FORM>"); 1138 "</FORM>");
1044 1139
1045 WebFrame* web_frame = GetMainFrame(); 1140 WebFrame* web_frame = GetMainFrame();
1046 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1141 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1047 1142
1048 FormCache form_cache; 1143 FormCache form_cache;
1049 std::vector<FormData> forms; 1144 std::vector<FormData> forms;
1050 form_cache.ExtractForms(*web_frame, &forms); 1145 form_cache.ExtractNewForms(*web_frame, &forms);
1051 ASSERT_EQ(1U, forms.size()); 1146 ASSERT_EQ(1U, forms.size());
1052 1147
1053 // Get the input element we want to find. 1148 // Get the input element we want to find.
1054 WebElement element = web_frame->document().getElementById("firstname"); 1149 WebElement element = web_frame->document().getElementById("firstname");
1055 WebInputElement input_element = element.to<WebInputElement>(); 1150 WebInputElement input_element = element.to<WebInputElement>();
1056 1151
1057 // Find the form and verify it's the correct form. 1152 // Find the form and verify it's the correct form.
1058 FormData form; 1153 FormData form;
1059 FormFieldData field; 1154 FormFieldData field;
1060 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 1155 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 "Apt. 42" 1229 "Apt. 42"
1135 "</TEXTAREA>" 1230 "</TEXTAREA>"
1136 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 1231 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1137 "</FORM>"); 1232 "</FORM>");
1138 1233
1139 WebFrame* web_frame = GetMainFrame(); 1234 WebFrame* web_frame = GetMainFrame();
1140 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 1235 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1141 1236
1142 FormCache form_cache; 1237 FormCache form_cache;
1143 std::vector<FormData> forms; 1238 std::vector<FormData> forms;
1144 form_cache.ExtractForms(*web_frame, &forms); 1239 form_cache.ExtractNewForms(*web_frame, &forms);
1145 ASSERT_EQ(1U, forms.size()); 1240 ASSERT_EQ(1U, forms.size());
1146 1241
1147 // Get the textarea element we want to find. 1242 // Get the textarea element we want to find.
1148 WebElement element = web_frame->document().getElementById("street-address"); 1243 WebElement element = web_frame->document().getElementById("street-address");
1149 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>(); 1244 WebTextAreaElement textarea_element = element.to<WebTextAreaElement>();
1150 1245
1151 // Find the form and verify it's the correct form. 1246 // Find the form and verify it's the correct form.
1152 FormData form; 1247 FormData form;
1153 FormFieldData field; 1248 FormFieldData field;
1154 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element, 1249 EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element,
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>" 2326 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>"
2232 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>" 2327 " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>"
2233 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2328 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2234 "</FORM>"); 2329 "</FORM>");
2235 2330
2236 WebFrame* web_frame = GetMainFrame(); 2331 WebFrame* web_frame = GetMainFrame();
2237 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2332 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2238 2333
2239 FormCache form_cache; 2334 FormCache form_cache;
2240 std::vector<FormData> forms; 2335 std::vector<FormData> forms;
2241 form_cache.ExtractForms(*web_frame, &forms); 2336 form_cache.ExtractNewForms(*web_frame, &forms);
2242 ASSERT_EQ(1U, forms.size()); 2337 ASSERT_EQ(1U, forms.size());
2243 2338
2244 // Get the input element we want to find. 2339 // Get the input element we want to find.
2245 WebElement element = web_frame->document().getElementById("firstname"); 2340 WebElement element = web_frame->document().getElementById("firstname");
2246 WebInputElement input_element = element.to<WebInputElement>(); 2341 WebInputElement input_element = element.to<WebInputElement>();
2247 2342
2248 // Find the form that contains the input element. 2343 // Find the form that contains the input element.
2249 FormData form; 2344 FormData form;
2250 FormFieldData field; 2345 FormFieldData field;
2251 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2346 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" 2423 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
2329 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" 2424 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>"
2330 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 2425 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
2331 "</FORM>"); 2426 "</FORM>");
2332 2427
2333 WebFrame* web_frame = GetMainFrame(); 2428 WebFrame* web_frame = GetMainFrame();
2334 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2429 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2335 2430
2336 FormCache form_cache; 2431 FormCache form_cache;
2337 std::vector<FormData> forms; 2432 std::vector<FormData> forms;
2338 form_cache.ExtractForms(*web_frame, &forms); 2433 form_cache.ExtractNewForms(*web_frame, &forms);
2339 ASSERT_EQ(1U, forms.size()); 2434 ASSERT_EQ(1U, forms.size());
2340 2435
2341 // Get the input element we want to find. 2436 // Get the input element we want to find.
2342 WebElement element = web_frame->document().getElementById("firstname"); 2437 WebElement element = web_frame->document().getElementById("firstname");
2343 WebInputElement input_element = element.to<WebInputElement>(); 2438 WebInputElement input_element = element.to<WebInputElement>();
2344 2439
2345 // Find the form that contains the input element. 2440 // Find the form that contains the input element.
2346 FormData form; 2441 FormData form;
2347 FormFieldData field; 2442 FormFieldData field;
2348 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2443 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 " <INPUT type=\"text\" id=\"lastname\"/>" 2504 " <INPUT type=\"text\" id=\"lastname\"/>"
2410 " <INPUT type=\"text\" id=\"email\"/>" 2505 " <INPUT type=\"text\" id=\"email\"/>"
2411 " <INPUT type=\"submit\" value=\"Send\"/>" 2506 " <INPUT type=\"submit\" value=\"Send\"/>"
2412 "</FORM>"); 2507 "</FORM>");
2413 2508
2414 WebFrame* web_frame = GetMainFrame(); 2509 WebFrame* web_frame = GetMainFrame();
2415 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2510 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2416 2511
2417 FormCache form_cache; 2512 FormCache form_cache;
2418 std::vector<FormData> forms; 2513 std::vector<FormData> forms;
2419 form_cache.ExtractForms(*web_frame, &forms); 2514 form_cache.ExtractNewForms(*web_frame, &forms);
2420 ASSERT_EQ(1U, forms.size()); 2515 ASSERT_EQ(1U, forms.size());
2421 2516
2422 // Get the input element we want to find. 2517 // Get the input element we want to find.
2423 WebElement element = web_frame->document().getElementById("firstname"); 2518 WebElement element = web_frame->document().getElementById("firstname");
2424 WebInputElement input_element = element.to<WebInputElement>(); 2519 WebInputElement input_element = element.to<WebInputElement>();
2425 2520
2426 // Find the form that contains the input element. 2521 // Find the form that contains the input element.
2427 FormData form; 2522 FormData form;
2428 FormFieldData field; 2523 FormFieldData field;
2429 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2524 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 " <INPUT type=\"text\" id=\"banana\"/>" 2594 " <INPUT type=\"text\" id=\"banana\"/>"
2500 " <INPUT type=\"text\" id=\"cantelope\"/>" 2595 " <INPUT type=\"text\" id=\"cantelope\"/>"
2501 " <INPUT type=\"submit\" value=\"Send\"/>" 2596 " <INPUT type=\"submit\" value=\"Send\"/>"
2502 "</FORM>"); 2597 "</FORM>");
2503 2598
2504 WebFrame* web_frame = GetMainFrame(); 2599 WebFrame* web_frame = GetMainFrame();
2505 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2600 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2506 2601
2507 FormCache form_cache; 2602 FormCache form_cache;
2508 std::vector<FormData> forms; 2603 std::vector<FormData> forms;
2509 form_cache.ExtractForms(*web_frame, &forms); 2604 form_cache.ExtractNewForms(*web_frame, &forms);
2510 ASSERT_EQ(2U, forms.size()); 2605 ASSERT_EQ(2U, forms.size());
2511 2606
2512 // Get the input element we want to find. 2607 // Get the input element we want to find.
2513 WebElement element = web_frame->document().getElementById("apple"); 2608 WebElement element = web_frame->document().getElementById("apple");
2514 WebInputElement input_element = element.to<WebInputElement>(); 2609 WebInputElement input_element = element.to<WebInputElement>();
2515 2610
2516 // Find the form that contains the input element. 2611 // Find the form that contains the input element.
2517 FormData form; 2612 FormData form;
2518 FormFieldData field; 2613 FormFieldData field;
2519 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2614 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 " <INPUT type=\"text\" id=\"lastname\"/>" 2814 " <INPUT type=\"text\" id=\"lastname\"/>"
2720 " <INPUT type=\"text\" id=\"email\"/>" 2815 " <INPUT type=\"text\" id=\"email\"/>"
2721 " <INPUT type=\"submit\" value=\"Send\"/>" 2816 " <INPUT type=\"submit\" value=\"Send\"/>"
2722 "</FORM>"); 2817 "</FORM>");
2723 2818
2724 WebFrame* web_frame = GetMainFrame(); 2819 WebFrame* web_frame = GetMainFrame();
2725 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2820 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2726 2821
2727 FormCache form_cache; 2822 FormCache form_cache;
2728 std::vector<FormData> forms; 2823 std::vector<FormData> forms;
2729 form_cache.ExtractForms(*web_frame, &forms); 2824 form_cache.ExtractNewForms(*web_frame, &forms);
2730 ASSERT_EQ(1U, forms.size()); 2825 ASSERT_EQ(1U, forms.size());
2731 2826
2732 // Get the input element we want to find. 2827 // Get the input element we want to find.
2733 WebElement element = web_frame->document().getElementById("firstname"); 2828 WebElement element = web_frame->document().getElementById("firstname");
2734 WebInputElement input_element = element.to<WebInputElement>(); 2829 WebInputElement input_element = element.to<WebInputElement>();
2735 2830
2736 // Simulate typing by modifying the field value. 2831 // Simulate typing by modifying the field value.
2737 input_element.setValue(ASCIIToUTF16("Wy")); 2832 input_element.setValue(ASCIIToUTF16("Wy"));
2738 2833
2739 // Find the form that contains the input element. 2834 // Find the form that contains the input element.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 " </TEXTAREA>" 2926 " </TEXTAREA>"
2832 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>" 2927 " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>"
2833 " <INPUT type=\"submit\" value=\"Send\"/>" 2928 " <INPUT type=\"submit\" value=\"Send\"/>"
2834 "</FORM>"); 2929 "</FORM>");
2835 2930
2836 WebFrame* web_frame = GetMainFrame(); 2931 WebFrame* web_frame = GetMainFrame();
2837 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 2932 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2838 2933
2839 FormCache form_cache; 2934 FormCache form_cache;
2840 std::vector<FormData> forms; 2935 std::vector<FormData> forms;
2841 form_cache.ExtractForms(*web_frame, &forms); 2936 form_cache.ExtractNewForms(*web_frame, &forms);
2842 ASSERT_EQ(1U, forms.size()); 2937 ASSERT_EQ(1U, forms.size());
2843 2938
2844 // Set the auto-filled attribute on the firstname element. 2939 // Set the auto-filled attribute on the firstname element.
2845 WebInputElement firstname = 2940 WebInputElement firstname =
2846 web_frame->document().getElementById("firstname").to<WebInputElement>(); 2941 web_frame->document().getElementById("firstname").to<WebInputElement>();
2847 firstname.setAutofilled(true); 2942 firstname.setAutofilled(true);
2848 2943
2849 // Set the value of the disabled text input element. 2944 // Set the value of the disabled text input element.
2850 WebInputElement notenabled = 2945 WebInputElement notenabled =
2851 web_frame->document().getElementById("notenabled").to<WebInputElement>(); 2946 web_frame->document().getElementById("notenabled").to<WebInputElement>();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 " <OPTION>AK</OPTION>" 3030 " <OPTION>AK</OPTION>"
2936 " </SELECT>" 3031 " </SELECT>"
2937 " <INPUT type=\"submit\" value=\"Send\"/>" 3032 " <INPUT type=\"submit\" value=\"Send\"/>"
2938 "</FORM>"); 3033 "</FORM>");
2939 3034
2940 WebFrame* web_frame = GetMainFrame(); 3035 WebFrame* web_frame = GetMainFrame();
2941 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3036 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2942 3037
2943 FormCache form_cache; 3038 FormCache form_cache;
2944 std::vector<FormData> forms; 3039 std::vector<FormData> forms;
2945 form_cache.ExtractForms(*web_frame, &forms); 3040 form_cache.ExtractNewForms(*web_frame, &forms);
2946 ASSERT_EQ(1U, forms.size()); 3041 ASSERT_EQ(1U, forms.size());
2947 3042
2948 // Set the auto-filled attribute on the firstname element. 3043 // Set the auto-filled attribute on the firstname element.
2949 WebInputElement firstname = 3044 WebInputElement firstname =
2950 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3045 web_frame->document().getElementById("firstname").to<WebInputElement>();
2951 firstname.setAutofilled(true); 3046 firstname.setAutofilled(true);
2952 3047
2953 // Set the value of the select-one. 3048 // Set the value of the select-one.
2954 WebSelectElement select_element = 3049 WebSelectElement select_element =
2955 web_frame->document().getElementById("state").to<WebSelectElement>(); 3050 web_frame->document().getElementById("state").to<WebSelectElement>();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 " <INPUT type=\"email\" id=\"email2\"/>" 3103 " <INPUT type=\"email\" id=\"email2\"/>"
3009 " <INPUT type=\"tel\" id=\"phone\"/>" 3104 " <INPUT type=\"tel\" id=\"phone\"/>"
3010 " <INPUT type=\"submit\" value=\"Send\"/>" 3105 " <INPUT type=\"submit\" value=\"Send\"/>"
3011 "</FORM>"); 3106 "</FORM>");
3012 3107
3013 WebFrame* web_frame = GetMainFrame(); 3108 WebFrame* web_frame = GetMainFrame();
3014 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3109 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3015 3110
3016 FormCache form_cache; 3111 FormCache form_cache;
3017 std::vector<FormData> forms; 3112 std::vector<FormData> forms;
3018 form_cache.ExtractForms(*web_frame, &forms); 3113 form_cache.ExtractNewForms(*web_frame, &forms);
3019 ASSERT_EQ(1U, forms.size()); 3114 ASSERT_EQ(1U, forms.size());
3020 3115
3021 // Set the auto-filled attribute. 3116 // Set the auto-filled attribute.
3022 WebInputElement firstname = 3117 WebInputElement firstname =
3023 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3118 web_frame->document().getElementById("firstname").to<WebInputElement>();
3024 firstname.setAutofilled(true); 3119 firstname.setAutofilled(true);
3025 WebInputElement lastname = 3120 WebInputElement lastname =
3026 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3121 web_frame->document().getElementById("lastname").to<WebInputElement>();
3027 lastname.setAutofilled(true); 3122 lastname.setAutofilled(true);
3028 WebInputElement email = 3123 WebInputElement email =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 " <INPUT type=\"email\" id=\"email2\"/>" 3171 " <INPUT type=\"email\" id=\"email2\"/>"
3077 " <INPUT type=\"tel\" id=\"phone\"/>" 3172 " <INPUT type=\"tel\" id=\"phone\"/>"
3078 " <INPUT type=\"submit\" value=\"Send\"/>" 3173 " <INPUT type=\"submit\" value=\"Send\"/>"
3079 "</FORM>"); 3174 "</FORM>");
3080 3175
3081 WebFrame* web_frame = GetMainFrame(); 3176 WebFrame* web_frame = GetMainFrame();
3082 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3177 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3083 3178
3084 FormCache form_cache; 3179 FormCache form_cache;
3085 std::vector<FormData> forms; 3180 std::vector<FormData> forms;
3086 form_cache.ExtractForms(*web_frame, &forms); 3181 form_cache.ExtractNewForms(*web_frame, &forms);
3087 ASSERT_EQ(1U, forms.size()); 3182 ASSERT_EQ(1U, forms.size());
3088 3183
3089 // Set the auto-filled attribute. 3184 // Set the auto-filled attribute.
3090 WebInputElement firstname = 3185 WebInputElement firstname =
3091 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3186 web_frame->document().getElementById("firstname").to<WebInputElement>();
3092 firstname.setAutofilled(true); 3187 firstname.setAutofilled(true);
3093 WebInputElement lastname = 3188 WebInputElement lastname =
3094 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3189 web_frame->document().getElementById("lastname").to<WebInputElement>();
3095 lastname.setAutofilled(true); 3190 lastname.setAutofilled(true);
3096 WebInputElement email = 3191 WebInputElement email =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 " <INPUT type=\"email\" id=\"email2\"/>" 3239 " <INPUT type=\"email\" id=\"email2\"/>"
3145 " <INPUT type=\"tel\" id=\"phone\"/>" 3240 " <INPUT type=\"tel\" id=\"phone\"/>"
3146 " <INPUT type=\"submit\" value=\"Send\"/>" 3241 " <INPUT type=\"submit\" value=\"Send\"/>"
3147 "</FORM>"); 3242 "</FORM>");
3148 3243
3149 WebFrame* web_frame = GetMainFrame(); 3244 WebFrame* web_frame = GetMainFrame();
3150 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3245 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3151 3246
3152 FormCache form_cache; 3247 FormCache form_cache;
3153 std::vector<FormData> forms; 3248 std::vector<FormData> forms;
3154 form_cache.ExtractForms(*web_frame, &forms); 3249 form_cache.ExtractNewForms(*web_frame, &forms);
3155 ASSERT_EQ(1U, forms.size()); 3250 ASSERT_EQ(1U, forms.size());
3156 3251
3157 // Set the auto-filled attribute. 3252 // Set the auto-filled attribute.
3158 WebInputElement firstname = 3253 WebInputElement firstname =
3159 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3254 web_frame->document().getElementById("firstname").to<WebInputElement>();
3160 firstname.setAutofilled(true); 3255 firstname.setAutofilled(true);
3161 WebInputElement lastname = 3256 WebInputElement lastname =
3162 web_frame->document().getElementById("lastname").to<WebInputElement>(); 3257 web_frame->document().getElementById("lastname").to<WebInputElement>();
3163 lastname.setAutofilled(true); 3258 lastname.setAutofilled(true);
3164 WebInputElement email = 3259 WebInputElement email =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 " <INPUT type=\"email\" id=\"email2\"/>" 3306 " <INPUT type=\"email\" id=\"email2\"/>"
3212 " <INPUT type=\"tel\" id=\"phone\"/>" 3307 " <INPUT type=\"tel\" id=\"phone\"/>"
3213 " <INPUT type=\"submit\" value=\"Send\"/>" 3308 " <INPUT type=\"submit\" value=\"Send\"/>"
3214 "</FORM>"); 3309 "</FORM>");
3215 3310
3216 WebFrame* web_frame = GetMainFrame(); 3311 WebFrame* web_frame = GetMainFrame();
3217 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); 3312 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
3218 3313
3219 FormCache form_cache; 3314 FormCache form_cache;
3220 std::vector<FormData> forms; 3315 std::vector<FormData> forms;
3221 form_cache.ExtractForms(*web_frame, &forms); 3316 form_cache.ExtractNewForms(*web_frame, &forms);
3222 ASSERT_EQ(1U, forms.size()); 3317 ASSERT_EQ(1U, forms.size());
3223 3318
3224 WebInputElement firstname = 3319 WebInputElement firstname =
3225 web_frame->document().getElementById("firstname").to<WebInputElement>(); 3320 web_frame->document().getElementById("firstname").to<WebInputElement>();
3226 3321
3227 // Auto-filled attribute not set yet. 3322 // Auto-filled attribute not set yet.
3228 EXPECT_FALSE(FormWithElementIsAutofilled(firstname)); 3323 EXPECT_FALSE(FormWithElementIsAutofilled(firstname));
3229 3324
3230 // Set the auto-filled attribute. 3325 // Set the auto-filled attribute.
3231 firstname.setAutofilled(true); 3326 firstname.setAutofilled(true);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3377 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 3472 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3378 3473
3379 expected.name = ASCIIToUTF16("country"); 3474 expected.name = ASCIIToUTF16("country");
3380 expected.value = ASCIIToUTF16("AL"); 3475 expected.value = ASCIIToUTF16("AL");
3381 expected.form_control_type = "select-one"; 3476 expected.form_control_type = "select-one";
3382 expected.max_length = 0; 3477 expected.max_length = 0;
3383 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3478 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3384 } 3479 }
3385 3480
3386 } // namespace autofill 3481 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698