Chromium Code Reviews| 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 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1050 expected.value = ASCIIToUTF16("Yellow"); | 1050 expected.value = ASCIIToUTF16("Yellow"); |
| 1051 expected.is_autofilled = true; | 1051 expected.is_autofilled = true; |
| 1052 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 1]); | 1052 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 1]); |
| 1053 | 1053 |
| 1054 expected.name = ASCIIToUTF16("cantelope"); | 1054 expected.name = ASCIIToUTF16("cantelope"); |
| 1055 expected.value = ASCIIToUTF16("Also Yellow"); | 1055 expected.value = ASCIIToUTF16("Also Yellow"); |
| 1056 expected.is_autofilled = true; | 1056 expected.is_autofilled = true; |
| 1057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); | 1057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[unowned_offset + 2]); |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 void TestFillFormNonEmptyField(const char* html, bool unowned) { | 1060 void TestFillFormNonEmptyField(const char* html, |
| 1061 bool unowned, | |
| 1062 const char* initial_lastname, | |
| 1063 const char* initial_email) { | |
| 1061 LoadHTML(html); | 1064 LoadHTML(html); |
| 1062 WebFrame* web_frame = GetMainFrame(); | 1065 WebFrame* web_frame = GetMainFrame(); |
| 1063 ASSERT_NE(nullptr, web_frame); | 1066 ASSERT_NE(nullptr, web_frame); |
| 1064 | 1067 |
| 1065 FormCache form_cache(*web_frame); | 1068 FormCache form_cache(*web_frame); |
| 1066 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1069 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 1067 ASSERT_EQ(1U, forms.size()); | 1070 ASSERT_EQ(1U, forms.size()); |
| 1068 | 1071 |
| 1069 // Get the input element we want to find. | 1072 // Get the input element we want to find. |
| 1070 WebInputElement input_element = GetInputElementById("firstname"); | 1073 WebInputElement input_element = GetInputElementById("firstname"); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1090 FormFieldData expected; | 1093 FormFieldData expected; |
| 1091 expected.form_control_type = "text"; | 1094 expected.form_control_type = "text"; |
| 1092 expected.max_length = WebInputElement::defaultMaxLength(); | 1095 expected.max_length = WebInputElement::defaultMaxLength(); |
| 1093 | 1096 |
| 1094 expected.name = ASCIIToUTF16("firstname"); | 1097 expected.name = ASCIIToUTF16("firstname"); |
| 1095 expected.value = ASCIIToUTF16("Wy"); | 1098 expected.value = ASCIIToUTF16("Wy"); |
| 1096 expected.is_autofilled = false; | 1099 expected.is_autofilled = false; |
| 1097 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); | 1100 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1098 | 1101 |
| 1099 expected.name = ASCIIToUTF16("lastname"); | 1102 expected.name = ASCIIToUTF16("lastname"); |
| 1100 expected.value.clear(); | 1103 if (initial_lastname) { |
| 1104 expected.label = ASCIIToUTF16(initial_lastname); | |
| 1105 expected.value = ASCIIToUTF16(initial_lastname); | |
| 1106 } else { | |
| 1107 expected.label.clear(); | |
| 1108 expected.value.clear(); | |
| 1109 } | |
| 1101 expected.is_autofilled = false; | 1110 expected.is_autofilled = false; |
| 1102 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 1111 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1103 | 1112 |
| 1104 expected.name = ASCIIToUTF16("email"); | 1113 expected.name = ASCIIToUTF16("email"); |
| 1105 expected.value.clear(); | 1114 if (initial_email) { |
| 1115 expected.label = ASCIIToUTF16(initial_email); | |
| 1116 expected.value = ASCIIToUTF16(initial_email); | |
| 1117 } else { | |
| 1118 expected.label.clear(); | |
| 1119 expected.value.clear(); | |
| 1120 } | |
| 1106 expected.is_autofilled = false; | 1121 expected.is_autofilled = false; |
| 1107 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 1122 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1108 | 1123 |
| 1109 // Preview the form and verify that the cursor position has been updated. | 1124 // Preview the form and verify that the cursor position has been updated. |
| 1110 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 1125 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 1111 form.fields[1].value = ASCIIToUTF16("Earp"); | 1126 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 1112 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 1127 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 1113 form.fields[0].is_autofilled = true; | 1128 form.fields[0].is_autofilled = true; |
| 1114 form.fields[1].is_autofilled = true; | 1129 form.fields[1].is_autofilled = true; |
| 1115 form.fields[2].is_autofilled = true; | 1130 form.fields[2].is_autofilled = true; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1130 if (!unowned) { | 1145 if (!unowned) { |
| 1131 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1146 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1132 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1147 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1133 } | 1148 } |
| 1134 | 1149 |
| 1135 const std::vector<FormFieldData>& fields2 = form2.fields; | 1150 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 1136 ASSERT_EQ(3U, fields2.size()); | 1151 ASSERT_EQ(3U, fields2.size()); |
| 1137 | 1152 |
| 1138 expected.name = ASCIIToUTF16("firstname"); | 1153 expected.name = ASCIIToUTF16("firstname"); |
| 1139 expected.value = ASCIIToUTF16("Wyatt"); | 1154 expected.value = ASCIIToUTF16("Wyatt"); |
| 1155 expected.label.clear(); | |
| 1140 expected.is_autofilled = true; | 1156 expected.is_autofilled = true; |
| 1141 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 1157 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 1142 | 1158 |
| 1143 expected.name = ASCIIToUTF16("lastname"); | 1159 expected.name = ASCIIToUTF16("lastname"); |
| 1144 expected.value = ASCIIToUTF16("Earp"); | 1160 expected.value = ASCIIToUTF16("Earp"); |
| 1161 expected.label.clear(); | |
| 1145 expected.is_autofilled = true; | 1162 expected.is_autofilled = true; |
| 1146 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 1163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 1147 | 1164 |
| 1148 expected.name = ASCIIToUTF16("email"); | 1165 expected.name = ASCIIToUTF16("email"); |
| 1149 expected.value = ASCIIToUTF16("wyatt@example.com"); | 1166 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 1167 expected.label.clear(); | |
| 1150 expected.is_autofilled = true; | 1168 expected.is_autofilled = true; |
| 1151 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 1169 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 1152 | 1170 |
| 1153 // Verify that the cursor position has been updated. | 1171 // Verify that the cursor position has been updated. |
| 1154 EXPECT_EQ(5, input_element.selectionStart()); | 1172 EXPECT_EQ(5, input_element.selectionStart()); |
| 1155 EXPECT_EQ(5, input_element.selectionEnd()); | 1173 EXPECT_EQ(5, input_element.selectionEnd()); |
| 1156 } | 1174 } |
| 1157 | 1175 |
| 1158 void TestClearFormWithNode(const char* html, bool unowned) { | 1176 void TestClearFormWithNode(const char* html, bool unowned) { |
| 1159 LoadHTML(html); | 1177 LoadHTML(html); |
| (...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3952 // profile from the Autofill suggestions popup. The field that is being typed | 3970 // profile from the Autofill suggestions popup. The field that is being typed |
| 3953 // into should be filled even though it's not technically empty. | 3971 // into should be filled even though it's not technically empty. |
| 3954 TEST_F(FormAutofillTest, FillFormNonEmptyField) { | 3972 TEST_F(FormAutofillTest, FillFormNonEmptyField) { |
| 3955 TestFillFormNonEmptyField( | 3973 TestFillFormNonEmptyField( |
| 3956 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3974 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3957 " <INPUT type='text' id='firstname'/>" | 3975 " <INPUT type='text' id='firstname'/>" |
| 3958 " <INPUT type='text' id='lastname'/>" | 3976 " <INPUT type='text' id='lastname'/>" |
| 3959 " <INPUT type='text' id='email'/>" | 3977 " <INPUT type='text' id='email'/>" |
| 3960 " <INPUT type='submit' value='Send'/>" | 3978 " <INPUT type='submit' value='Send'/>" |
| 3961 "</FORM>", | 3979 "</FORM>", |
| 3962 false); | 3980 false, nullptr, nullptr); |
| 3981 } | |
| 3982 | |
| 3983 TEST_F(FormAutofillTest, FillFormNonEmptyFieldsWithDefaultValues) { | |
| 3984 TestFillFormNonEmptyField( | |
| 3985 "<FORM name='TestForm' action='http://buh.com' method='post'>" | |
|
vabr (Chromium)
2016/02/16 18:12:32
Bösen & Heinke? :)
Mathieu
2016/02/16 20:03:45
wasn't sure if that was a serious comment, so I ch
vabr (Chromium)
2016/02/17 09:21:38
I was merely curious, what made you chose Bösen &
| |
| 3986 " <INPUT type='text' id='firstname' value='Enter first name'/>" | |
| 3987 " <INPUT type='text' id='lastname' value='Enter last name'/>" | |
| 3988 " <INPUT type='text' id='email' value='Enter email'/>" | |
| 3989 " <INPUT type='submit' value='Send'/>" | |
| 3990 "</FORM>", | |
| 3991 false, "Enter last name", "Enter email"); | |
| 3963 } | 3992 } |
| 3964 | 3993 |
| 3965 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) { | 3994 TEST_F(FormAutofillTest, FillFormNonEmptyFieldForUnownedForm) { |
| 3966 TestFillFormNonEmptyField( | 3995 TestFillFormNonEmptyField( |
| 3967 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>" | 3996 "<HEAD><TITLE>delivery recipient info</TITLE></HEAD>" |
| 3968 "<INPUT type='text' id='firstname'/>" | 3997 "<INPUT type='text' id='firstname'/>" |
| 3969 "<INPUT type='text' id='lastname'/>" | 3998 "<INPUT type='text' id='lastname'/>" |
| 3970 "<INPUT type='text' id='email'/>" | 3999 "<INPUT type='text' id='email'/>" |
| 3971 "<INPUT type='submit' value='Send'/>", | 4000 "<INPUT type='submit' value='Send'/>", |
| 3972 true); | 4001 true, nullptr, nullptr); |
| 3973 } | 4002 } |
| 3974 | 4003 |
| 3975 TEST_F(FormAutofillTest, ClearFormWithNode) { | 4004 TEST_F(FormAutofillTest, ClearFormWithNode) { |
| 3976 TestClearFormWithNode( | 4005 TestClearFormWithNode( |
| 3977 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 4006 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 3978 " <INPUT type='text' id='firstname' value='Wyatt'/>" | 4007 " <INPUT type='text' id='firstname' value='Wyatt'/>" |
| 3979 " <INPUT type='text' id='lastname' value='Earp'/>" | 4008 " <INPUT type='text' id='lastname' value='Earp'/>" |
| 3980 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" | 4009 " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>" |
| 3981 " <INPUT type='text' id='notenabled' disabled='disabled'>" | 4010 " <INPUT type='text' id='notenabled' disabled='disabled'>" |
| 3982 " <INPUT type='month' id='month' value='2012-11'>" | 4011 " <INPUT type='month' id='month' value='2012-11'>" |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4502 | 4531 |
| 4503 if (test_case.has_extracted_form) { | 4532 if (test_case.has_extracted_form) { |
| 4504 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); | 4533 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); |
| 4505 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); | 4534 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); |
| 4506 } | 4535 } |
| 4507 } | 4536 } |
| 4508 } | 4537 } |
| 4509 | 4538 |
| 4510 } // namespace form_util | 4539 } // namespace form_util |
| 4511 } // namespace autofill | 4540 } // namespace autofill |
| OLD | NEW |