OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" | |
11 #include "components/autofill/core/browser/autofill_metrics.h" | 10 #include "components/autofill/core/browser/autofill_metrics.h" |
12 #include "components/autofill/core/common/form_data.h" | 11 #include "components/autofill/core/common/form_data.h" |
13 #include "components/autofill/core/common/form_field_data.h" | 12 #include "components/autofill/core/common/form_field_data.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebInputElement.h" | 14 #include "third_party/WebKit/public/web/WebInputElement.h" |
16 #include "url/gurl.h" | 15 #include "url/gurl.h" |
17 | 16 |
18 using WebKit::WebInputElement; | 17 using WebKit::WebInputElement; |
19 | 18 |
20 namespace autofill { | 19 namespace autofill { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 form.fields.push_back(field); | 84 form.fields.push_back(field); |
86 | 85 |
87 field.label = ASCIIToUTF16("address1"); | 86 field.label = ASCIIToUTF16("address1"); |
88 field.name = ASCIIToUTF16("address1"); | 87 field.name = ASCIIToUTF16("address1"); |
89 field.form_control_type = "text"; | 88 field.form_control_type = "text"; |
90 field.should_autocomplete = false; | 89 field.should_autocomplete = false; |
91 form.fields.push_back(field); | 90 form.fields.push_back(field); |
92 | 91 |
93 // The render process sends all fields to browser including fields with | 92 // The render process sends all fields to browser including fields with |
94 // autocomplete=off | 93 // autocomplete=off |
95 form_structure.reset(new FormStructure(form, std::string())); | 94 form_structure.reset(new FormStructure(form)); |
96 EXPECT_EQ(4U, form_structure->field_count()); | |
97 | |
98 // We expect the same count when autocheckout is enabled. | |
99 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
100 EXPECT_EQ(4U, form_structure->field_count()); | 95 EXPECT_EQ(4U, form_structure->field_count()); |
101 } | 96 } |
102 | 97 |
103 TEST(FormStructureTest, AutofillCount) { | 98 TEST(FormStructureTest, AutofillCount) { |
104 scoped_ptr<FormStructure> form_structure; | 99 scoped_ptr<FormStructure> form_structure; |
105 FormData form; | 100 FormData form; |
106 form.method = ASCIIToUTF16("post"); | 101 form.method = ASCIIToUTF16("post"); |
107 | 102 |
108 FormFieldData field; | 103 FormFieldData field; |
109 field.label = ASCIIToUTF16("username"); | 104 field.label = ASCIIToUTF16("username"); |
(...skipping 10 matching lines...) Expand all Loading... |
120 field.name = ASCIIToUTF16("state"); | 115 field.name = ASCIIToUTF16("state"); |
121 field.form_control_type = "select-one"; | 116 field.form_control_type = "select-one"; |
122 form.fields.push_back(field); | 117 form.fields.push_back(field); |
123 | 118 |
124 field.label = base::string16(); | 119 field.label = base::string16(); |
125 field.name = ASCIIToUTF16("Submit"); | 120 field.name = ASCIIToUTF16("Submit"); |
126 field.form_control_type = "submit"; | 121 field.form_control_type = "submit"; |
127 form.fields.push_back(field); | 122 form.fields.push_back(field); |
128 | 123 |
129 // Only text and select fields that are heuristically matched are counted. | 124 // Only text and select fields that are heuristically matched are counted. |
130 form_structure.reset(new FormStructure(form, std::string())); | 125 form_structure.reset(new FormStructure(form)); |
131 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 126 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
132 EXPECT_EQ(1U, form_structure->autofill_count()); | 127 EXPECT_EQ(1U, form_structure->autofill_count()); |
133 | 128 |
134 // Add a field with should_autocomplete=false. | 129 // Add a field with should_autocomplete=false. |
135 field.label = ASCIIToUTF16("address1"); | 130 field.label = ASCIIToUTF16("address1"); |
136 field.name = ASCIIToUTF16("address1"); | 131 field.name = ASCIIToUTF16("address1"); |
137 field.form_control_type = "text"; | 132 field.form_control_type = "text"; |
138 field.should_autocomplete = false; | 133 field.should_autocomplete = false; |
139 form.fields.push_back(field); | 134 form.fields.push_back(field); |
140 | 135 |
141 form_structure.reset(new FormStructure(form, std::string())); | 136 form_structure.reset(new FormStructure(form)); |
142 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 137 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
143 // DetermineHeuristicTypes also assign field type for fields with | 138 // DetermineHeuristicTypes also assign field type for fields with |
144 // autocomplete=off thus autofill_count includes them. This is a bug, | 139 // autocomplete=off thus autofill_count includes them. This is a bug, |
145 // and they should not be counted. See http://crbug.com/176432 for details. | 140 // and they should not be counted. See http://crbug.com/176432 for details. |
146 // TODO(benquan): change it to EXPECT_EQ(1U, ... when the bug is fixed. | 141 // TODO(benquan): change it to EXPECT_EQ(1U, ... when the bug is fixed. |
147 EXPECT_EQ(2U, form_structure->autofill_count()); | 142 EXPECT_EQ(2U, form_structure->autofill_count()); |
148 | |
149 // All fields should be counted when Autocheckout is enabled. | |
150 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
151 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | |
152 EXPECT_EQ(2U, form_structure->autofill_count()); | |
153 } | 143 } |
154 | 144 |
155 TEST(FormStructureTest, SourceURL) { | 145 TEST(FormStructureTest, SourceURL) { |
156 FormData form; | 146 FormData form; |
157 form.origin = GURL("http://www.foo.com/"); | 147 form.origin = GURL("http://www.foo.com/"); |
158 form.method = ASCIIToUTF16("post"); | 148 form.method = ASCIIToUTF16("post"); |
159 FormStructure form_structure(form, std::string()); | 149 FormStructure form_structure(form); |
160 | 150 |
161 EXPECT_EQ(form.origin, form_structure.source_url()); | 151 EXPECT_EQ(form.origin, form_structure.source_url()); |
162 } | 152 } |
163 | 153 |
164 TEST(FormStructureTest, IsAutofillable) { | 154 TEST(FormStructureTest, IsAutofillable) { |
165 scoped_ptr<FormStructure> form_structure; | 155 scoped_ptr<FormStructure> form_structure; |
166 FormData form; | 156 FormData form; |
167 | 157 |
168 // We need at least three text fields to be auto-fillable. | 158 // We need at least three text fields to be auto-fillable. |
169 form.method = ASCIIToUTF16("post"); | 159 form.method = ASCIIToUTF16("post"); |
170 | 160 |
171 FormFieldData field; | 161 FormFieldData field; |
172 // When autocheckout is enabled, we enable autofill even the form has | |
173 // no fields | |
174 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
175 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | |
176 EXPECT_TRUE(form_structure->IsAutofillable(true)); | |
177 | 162 |
178 field.label = ASCIIToUTF16("username"); | 163 field.label = ASCIIToUTF16("username"); |
179 field.name = ASCIIToUTF16("username"); | 164 field.name = ASCIIToUTF16("username"); |
180 field.form_control_type = "text"; | 165 field.form_control_type = "text"; |
181 form.fields.push_back(field); | 166 form.fields.push_back(field); |
182 | 167 |
183 field.label = ASCIIToUTF16("password"); | 168 field.label = ASCIIToUTF16("password"); |
184 field.name = ASCIIToUTF16("password"); | 169 field.name = ASCIIToUTF16("password"); |
185 field.form_control_type = "password"; | 170 field.form_control_type = "password"; |
186 form.fields.push_back(field); | 171 form.fields.push_back(field); |
187 | 172 |
188 field.label = base::string16(); | 173 field.label = base::string16(); |
189 field.name = ASCIIToUTF16("Submit"); | 174 field.name = ASCIIToUTF16("Submit"); |
190 field.form_control_type = "submit"; | 175 field.form_control_type = "submit"; |
191 form.fields.push_back(field); | 176 form.fields.push_back(field); |
192 | 177 |
193 form_structure.reset(new FormStructure(form, std::string())); | 178 form_structure.reset(new FormStructure(form)); |
194 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 179 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
195 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 180 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
196 | 181 |
197 // We do not limit to three text fields when autocheckout is enabled. | |
198 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
199 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | |
200 EXPECT_TRUE(form_structure->IsAutofillable(true)); | |
201 | |
202 // We now have three text fields, but only two auto-fillable fields. | 182 // We now have three text fields, but only two auto-fillable fields. |
203 field.label = ASCIIToUTF16("First Name"); | 183 field.label = ASCIIToUTF16("First Name"); |
204 field.name = ASCIIToUTF16("firstname"); | 184 field.name = ASCIIToUTF16("firstname"); |
205 field.form_control_type = "text"; | 185 field.form_control_type = "text"; |
206 form.fields.push_back(field); | 186 form.fields.push_back(field); |
207 | 187 |
208 field.label = ASCIIToUTF16("Last Name"); | 188 field.label = ASCIIToUTF16("Last Name"); |
209 field.name = ASCIIToUTF16("lastname"); | 189 field.name = ASCIIToUTF16("lastname"); |
210 field.form_control_type = "text"; | 190 field.form_control_type = "text"; |
211 form.fields.push_back(field); | 191 form.fields.push_back(field); |
212 | 192 |
213 form_structure.reset(new FormStructure(form, std::string())); | 193 form_structure.reset(new FormStructure(form)); |
214 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 194 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
215 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 195 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
216 | 196 |
217 // We now have three auto-fillable fields. | 197 // We now have three auto-fillable fields. |
218 field.label = ASCIIToUTF16("Email"); | 198 field.label = ASCIIToUTF16("Email"); |
219 field.name = ASCIIToUTF16("email"); | 199 field.name = ASCIIToUTF16("email"); |
220 field.form_control_type = "email"; | 200 field.form_control_type = "email"; |
221 form.fields.push_back(field); | 201 form.fields.push_back(field); |
222 | 202 |
223 form_structure.reset(new FormStructure(form, std::string())); | 203 form_structure.reset(new FormStructure(form)); |
224 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 204 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
225 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 205 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
226 | 206 |
227 // The method must be 'post', though we can intentionally ignore this | 207 // The method must be 'post', though we can intentionally ignore this |
228 // criterion for the sake of providing a helpful warning message to the user. | 208 // criterion for the sake of providing a helpful warning message to the user. |
229 form.method = ASCIIToUTF16("get"); | 209 form.method = ASCIIToUTF16("get"); |
230 form_structure.reset(new FormStructure(form, std::string())); | 210 form_structure.reset(new FormStructure(form)); |
231 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 211 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
232 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 212 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
233 EXPECT_TRUE(form_structure->IsAutofillable(false)); | 213 EXPECT_TRUE(form_structure->IsAutofillable(false)); |
234 | 214 |
235 // The target cannot include http(s)://*/search... | 215 // The target cannot include http(s)://*/search... |
236 form.method = ASCIIToUTF16("post"); | 216 form.method = ASCIIToUTF16("post"); |
237 form.action = GURL("http://google.com/search?q=hello"); | 217 form.action = GURL("http://google.com/search?q=hello"); |
238 form_structure.reset(new FormStructure(form, std::string())); | 218 form_structure.reset(new FormStructure(form)); |
239 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 219 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
240 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 220 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
241 | 221 |
242 // But search can be in the URL. | 222 // But search can be in the URL. |
243 form.action = GURL("http://search.com/?q=hello"); | 223 form.action = GURL("http://search.com/?q=hello"); |
244 form_structure.reset(new FormStructure(form, std::string())); | 224 form_structure.reset(new FormStructure(form)); |
245 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 225 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
246 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 226 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
247 } | 227 } |
248 | 228 |
249 TEST(FormStructureTest, ShouldBeParsed) { | 229 TEST(FormStructureTest, ShouldBeParsed) { |
250 scoped_ptr<FormStructure> form_structure; | 230 scoped_ptr<FormStructure> form_structure; |
251 FormData form; | 231 FormData form; |
252 | 232 |
253 // We need at least three text fields to be parseable. | 233 // We need at least three text fields to be parseable. |
254 form.method = ASCIIToUTF16("post"); | 234 form.method = ASCIIToUTF16("post"); |
255 | 235 |
256 FormFieldData field; | 236 FormFieldData field; |
257 field.label = ASCIIToUTF16("username"); | 237 field.label = ASCIIToUTF16("username"); |
258 field.name = ASCIIToUTF16("username"); | 238 field.name = ASCIIToUTF16("username"); |
259 field.form_control_type = "text"; | 239 field.form_control_type = "text"; |
260 form.fields.push_back(field); | 240 form.fields.push_back(field); |
261 | 241 |
262 FormFieldData checkable_field; | 242 FormFieldData checkable_field; |
263 checkable_field.is_checkable = true; | 243 checkable_field.is_checkable = true; |
264 checkable_field.name = ASCIIToUTF16("radiobtn"); | 244 checkable_field.name = ASCIIToUTF16("radiobtn"); |
265 checkable_field.form_control_type = "radio"; | 245 checkable_field.form_control_type = "radio"; |
266 form.fields.push_back(checkable_field); | 246 form.fields.push_back(checkable_field); |
267 | 247 |
268 checkable_field.name = ASCIIToUTF16("checkbox"); | 248 checkable_field.name = ASCIIToUTF16("checkbox"); |
269 checkable_field.form_control_type = "checkbox"; | 249 checkable_field.form_control_type = "checkbox"; |
270 form.fields.push_back(checkable_field); | 250 form.fields.push_back(checkable_field); |
271 | 251 |
272 // We have only one text field, should not be parsed. | 252 // We have only one text field, should not be parsed. |
273 form_structure.reset(new FormStructure(form, std::string())); | 253 form_structure.reset(new FormStructure(form)); |
274 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 254 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
275 | 255 |
276 // The form should be parsed for autocheckout even it has less than three | |
277 // text fields. | |
278 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
279 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | |
280 | |
281 // We now have three text fields, though only two are auto-fillable. | 256 // We now have three text fields, though only two are auto-fillable. |
282 field.label = ASCIIToUTF16("First Name"); | 257 field.label = ASCIIToUTF16("First Name"); |
283 field.name = ASCIIToUTF16("firstname"); | 258 field.name = ASCIIToUTF16("firstname"); |
284 field.form_control_type = "text"; | 259 field.form_control_type = "text"; |
285 form.fields.push_back(field); | 260 form.fields.push_back(field); |
286 | 261 |
287 field.label = ASCIIToUTF16("Last Name"); | 262 field.label = ASCIIToUTF16("Last Name"); |
288 field.name = ASCIIToUTF16("lastname"); | 263 field.name = ASCIIToUTF16("lastname"); |
289 field.form_control_type = "text"; | 264 field.form_control_type = "text"; |
290 form.fields.push_back(field); | 265 form.fields.push_back(field); |
291 | 266 |
292 form_structure.reset(new FormStructure(form, std::string())); | 267 form_structure.reset(new FormStructure(form)); |
293 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 268 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
294 | 269 |
295 // The method must be 'post', though we can intentionally ignore this | 270 // The method must be 'post', though we can intentionally ignore this |
296 // criterion for the sake of providing a helpful warning message to the user. | 271 // criterion for the sake of providing a helpful warning message to the user. |
297 form.method = ASCIIToUTF16("get"); | 272 form.method = ASCIIToUTF16("get"); |
298 form_structure.reset(new FormStructure(form, std::string())); | 273 form_structure.reset(new FormStructure(form)); |
299 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 274 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
300 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); | 275 EXPECT_TRUE(form_structure->ShouldBeParsed(false)); |
301 | 276 |
302 // The target cannot include http(s)://*/search... | 277 // The target cannot include http(s)://*/search... |
303 form.method = ASCIIToUTF16("post"); | 278 form.method = ASCIIToUTF16("post"); |
304 form.action = GURL("http://google.com/search?q=hello"); | 279 form.action = GURL("http://google.com/search?q=hello"); |
305 form_structure.reset(new FormStructure(form, std::string())); | 280 form_structure.reset(new FormStructure(form)); |
306 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 281 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
307 | 282 |
308 // But search can be in the URL. | 283 // But search can be in the URL. |
309 form.action = GURL("http://search.com/?q=hello"); | 284 form.action = GURL("http://search.com/?q=hello"); |
310 form_structure.reset(new FormStructure(form, std::string())); | 285 form_structure.reset(new FormStructure(form)); |
311 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 286 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
312 | 287 |
313 // The form need only have three fields, but at least one must be a text | 288 // The form need only have three fields, but at least one must be a text |
314 // field. | 289 // field. |
315 form.fields.clear(); | 290 form.fields.clear(); |
316 | 291 |
317 field.label = ASCIIToUTF16("Email"); | 292 field.label = ASCIIToUTF16("Email"); |
318 field.name = ASCIIToUTF16("email"); | 293 field.name = ASCIIToUTF16("email"); |
319 field.form_control_type = "email"; | 294 field.form_control_type = "email"; |
320 form.fields.push_back(field); | 295 form.fields.push_back(field); |
321 | 296 |
322 field.label = ASCIIToUTF16("State"); | 297 field.label = ASCIIToUTF16("State"); |
323 field.name = ASCIIToUTF16("state"); | 298 field.name = ASCIIToUTF16("state"); |
324 field.form_control_type = "select-one"; | 299 field.form_control_type = "select-one"; |
325 form.fields.push_back(field); | 300 form.fields.push_back(field); |
326 | 301 |
327 field.label = ASCIIToUTF16("Country"); | 302 field.label = ASCIIToUTF16("Country"); |
328 field.name = ASCIIToUTF16("country"); | 303 field.name = ASCIIToUTF16("country"); |
329 field.form_control_type = "select-one"; | 304 field.form_control_type = "select-one"; |
330 form.fields.push_back(field); | 305 form.fields.push_back(field); |
331 | 306 |
332 form_structure.reset(new FormStructure(form, std::string())); | 307 form_structure.reset(new FormStructure(form)); |
333 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | 308 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); |
334 | 309 |
335 form.fields[0].form_control_type = "select-one"; | 310 form.fields[0].form_control_type = "select-one"; |
336 // Now, no text fields. | 311 // Now, no text fields. |
337 form_structure.reset(new FormStructure(form, std::string())); | 312 form_structure.reset(new FormStructure(form)); |
338 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); | 313 EXPECT_FALSE(form_structure->ShouldBeParsed(true)); |
339 | |
340 // It should be parsed when autocheckout is enabled. | |
341 form_structure.reset(new FormStructure(form, "http://fake_url")); | |
342 EXPECT_TRUE(form_structure->ShouldBeParsed(true)); | |
343 } | 314 } |
344 | 315 |
345 TEST(FormStructureTest, HeuristicsContactInfo) { | 316 TEST(FormStructureTest, HeuristicsContactInfo) { |
346 scoped_ptr<FormStructure> form_structure; | 317 scoped_ptr<FormStructure> form_structure; |
347 FormData form; | 318 FormData form; |
348 form.method = ASCIIToUTF16("post"); | 319 form.method = ASCIIToUTF16("post"); |
349 | 320 |
350 FormFieldData field; | 321 FormFieldData field; |
351 field.form_control_type = "text"; | 322 field.form_control_type = "text"; |
352 | 323 |
(...skipping 23 matching lines...) Expand all Loading... |
376 | 347 |
377 field.label = ASCIIToUTF16("Zip code"); | 348 field.label = ASCIIToUTF16("Zip code"); |
378 field.name = ASCIIToUTF16("zipcode"); | 349 field.name = ASCIIToUTF16("zipcode"); |
379 form.fields.push_back(field); | 350 form.fields.push_back(field); |
380 | 351 |
381 field.label = base::string16(); | 352 field.label = base::string16(); |
382 field.name = ASCIIToUTF16("Submit"); | 353 field.name = ASCIIToUTF16("Submit"); |
383 field.form_control_type = "submit"; | 354 field.form_control_type = "submit"; |
384 form.fields.push_back(field); | 355 form.fields.push_back(field); |
385 | 356 |
386 form_structure.reset(new FormStructure(form, std::string())); | 357 form_structure.reset(new FormStructure(form)); |
387 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 358 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
388 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 359 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
389 | 360 |
390 // Expect the correct number of fields. | 361 // Expect the correct number of fields. |
391 ASSERT_EQ(8U, form_structure->field_count()); | 362 ASSERT_EQ(8U, form_structure->field_count()); |
392 ASSERT_EQ(7U, form_structure->autofill_count()); | 363 ASSERT_EQ(7U, form_structure->autofill_count()); |
393 | 364 |
394 // First name. | 365 // First name. |
395 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 366 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
396 // Last name. | 367 // Last name. |
(...skipping 30 matching lines...) Expand all Loading... |
427 field.label = base::string16(); | 398 field.label = base::string16(); |
428 field.name = ASCIIToUTF16("field2"); | 399 field.name = ASCIIToUTF16("field2"); |
429 field.autocomplete_attribute = "family-name"; | 400 field.autocomplete_attribute = "family-name"; |
430 form.fields.push_back(field); | 401 form.fields.push_back(field); |
431 | 402 |
432 field.label = base::string16(); | 403 field.label = base::string16(); |
433 field.name = ASCIIToUTF16("field3"); | 404 field.name = ASCIIToUTF16("field3"); |
434 field.autocomplete_attribute = "email"; | 405 field.autocomplete_attribute = "email"; |
435 form.fields.push_back(field); | 406 form.fields.push_back(field); |
436 | 407 |
437 form_structure.reset(new FormStructure(form, std::string())); | 408 form_structure.reset(new FormStructure(form)); |
438 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 409 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
439 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 410 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
440 | 411 |
441 // Expect the correct number of fields. | 412 // Expect the correct number of fields. |
442 ASSERT_EQ(3U, form_structure->field_count()); | 413 ASSERT_EQ(3U, form_structure->field_count()); |
443 ASSERT_EQ(3U, form_structure->autofill_count()); | 414 ASSERT_EQ(3U, form_structure->autofill_count()); |
444 | 415 |
445 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); | 416 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); |
446 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); | 417 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); |
447 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); | 418 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); |
(...skipping 20 matching lines...) Expand all Loading... |
468 field.label = base::string16(); | 439 field.label = base::string16(); |
469 field.name = ASCIIToUTF16("field2"); | 440 field.name = ASCIIToUTF16("field2"); |
470 field.autocomplete_attribute = "tel-local-prefix"; | 441 field.autocomplete_attribute = "tel-local-prefix"; |
471 form.fields.push_back(field); | 442 form.fields.push_back(field); |
472 | 443 |
473 field.label = base::string16(); | 444 field.label = base::string16(); |
474 field.name = ASCIIToUTF16("field3"); | 445 field.name = ASCIIToUTF16("field3"); |
475 field.autocomplete_attribute = "tel-local-suffix"; | 446 field.autocomplete_attribute = "tel-local-suffix"; |
476 form.fields.push_back(field); | 447 form.fields.push_back(field); |
477 | 448 |
478 form_structure.reset(new FormStructure(form, std::string())); | 449 form_structure.reset(new FormStructure(form)); |
479 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 450 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
480 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 451 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
481 | 452 |
482 // Expect the correct number of fields. | 453 // Expect the correct number of fields. |
483 ASSERT_EQ(3U, form_structure->field_count()); | 454 ASSERT_EQ(3U, form_structure->field_count()); |
484 EXPECT_EQ(3U, form_structure->autofill_count()); | 455 EXPECT_EQ(3U, form_structure->autofill_count()); |
485 | 456 |
486 EXPECT_EQ(HTML_TYPE_TEL_LOCAL, form_structure->field(0)->html_type()); | 457 EXPECT_EQ(HTML_TYPE_TEL_LOCAL, form_structure->field(0)->html_type()); |
487 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); | 458 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); |
488 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); | 459 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); |
(...skipping 20 matching lines...) Expand all Loading... |
509 form.fields.push_back(field); | 480 form.fields.push_back(field); |
510 | 481 |
511 field.label = ASCIIToUTF16("Last Name"); | 482 field.label = ASCIIToUTF16("Last Name"); |
512 field.name = ASCIIToUTF16("lastname"); | 483 field.name = ASCIIToUTF16("lastname"); |
513 form.fields.push_back(field); | 484 form.fields.push_back(field); |
514 | 485 |
515 field.label = ASCIIToUTF16("Email"); | 486 field.label = ASCIIToUTF16("Email"); |
516 field.name = ASCIIToUTF16("email"); | 487 field.name = ASCIIToUTF16("email"); |
517 form.fields.push_back(field); | 488 form.fields.push_back(field); |
518 | 489 |
519 form_structure.reset(new FormStructure(form, std::string())); | 490 form_structure.reset(new FormStructure(form)); |
520 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 491 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
521 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 492 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
522 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); | 493 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); |
523 | 494 |
524 ASSERT_EQ(3U, form_structure->field_count()); | 495 ASSERT_EQ(3U, form_structure->field_count()); |
525 ASSERT_EQ(3U, form_structure->autofill_count()); | 496 ASSERT_EQ(3U, form_structure->autofill_count()); |
526 | 497 |
527 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 498 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
528 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 499 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
529 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 500 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); |
530 | 501 |
531 // Now update the first form field to include an 'autocomplete' attribute. | 502 // Now update the first form field to include an 'autocomplete' attribute. |
532 form.fields.front().autocomplete_attribute = "x-other"; | 503 form.fields.front().autocomplete_attribute = "x-other"; |
533 form_structure.reset(new FormStructure(form, std::string())); | 504 form_structure.reset(new FormStructure(form)); |
534 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 505 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
535 EXPECT_FALSE(form_structure->IsAutofillable(true)); | 506 EXPECT_FALSE(form_structure->IsAutofillable(true)); |
536 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); | 507 EXPECT_FALSE(form_structure->ShouldBeCrowdsourced()); |
537 | 508 |
538 ASSERT_EQ(3U, form_structure->field_count()); | 509 ASSERT_EQ(3U, form_structure->field_count()); |
539 ASSERT_EQ(0U, form_structure->autofill_count()); | 510 ASSERT_EQ(0U, form_structure->autofill_count()); |
540 | 511 |
541 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 512 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
542 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 513 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
543 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 514 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
544 | |
545 // When Autocheckout is enabled, we should ignore 'autocomplete' attribute | |
546 // when deciding to crowdsource. | |
547 form_structure.reset(new FormStructure(form, "http://fake.url")); | |
548 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | |
549 EXPECT_TRUE(form_structure->IsAutofillable(true)); | |
550 EXPECT_TRUE(form_structure->ShouldBeCrowdsourced()); | |
551 | |
552 ASSERT_EQ(3U, form_structure->field_count()); | |
553 ASSERT_EQ(0U, form_structure->autofill_count()); | |
554 | |
555 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | |
556 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | |
557 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | |
558 } | 515 } |
559 | 516 |
560 // Verify that we can correctly process sections listed in the |autocomplete| | 517 // Verify that we can correctly process sections listed in the |autocomplete| |
561 // attribute. | 518 // attribute. |
562 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { | 519 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) { |
563 FormData form; | 520 FormData form; |
564 form.method = ASCIIToUTF16("post"); | 521 form.method = ASCIIToUTF16("post"); |
565 | 522 |
566 FormFieldData field; | 523 FormFieldData field; |
567 field.form_control_type = "text"; | 524 field.form_control_type = "text"; |
(...skipping 29 matching lines...) Expand all Loading... |
597 // different sections. This is only an interesting test due to how we | 554 // different sections. This is only an interesting test due to how we |
598 // implement implicit section names from attributes like "shipping email"; see | 555 // implement implicit section names from attributes like "shipping email"; see |
599 // the implementation for more details. | 556 // the implementation for more details. |
600 field.autocomplete_attribute = "section--shipping email"; | 557 field.autocomplete_attribute = "section--shipping email"; |
601 form.fields.push_back(field); | 558 form.fields.push_back(field); |
602 | 559 |
603 // Credit card fields are implicitly in a separate section from other fields. | 560 // Credit card fields are implicitly in a separate section from other fields. |
604 field.autocomplete_attribute = "section-foo cc-number"; | 561 field.autocomplete_attribute = "section-foo cc-number"; |
605 form.fields.push_back(field); | 562 form.fields.push_back(field); |
606 | 563 |
607 FormStructure form_structure(form, std::string()); | 564 FormStructure form_structure(form); |
608 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 565 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
609 EXPECT_TRUE(form_structure.IsAutofillable(true)); | 566 EXPECT_TRUE(form_structure.IsAutofillable(true)); |
610 | 567 |
611 // Expect the correct number of fields. | 568 // Expect the correct number of fields. |
612 ASSERT_EQ(9U, form_structure.field_count()); | 569 ASSERT_EQ(9U, form_structure.field_count()); |
613 EXPECT_EQ(9U, form_structure.autofill_count()); | 570 EXPECT_EQ(9U, form_structure.autofill_count()); |
614 | 571 |
615 // All of the fields in this form should be parsed as belonging to different | 572 // All of the fields in this form should be parsed as belonging to different |
616 // sections. | 573 // sections. |
617 std::set<std::string> section_names; | 574 std::set<std::string> section_names; |
(...skipping 24 matching lines...) Expand all Loading... |
642 // Invalid tokens should prevent us from setting a section name. | 599 // Invalid tokens should prevent us from setting a section name. |
643 field.autocomplete_attribute = "garbage section-foo email"; | 600 field.autocomplete_attribute = "garbage section-foo email"; |
644 form.fields.push_back(field); | 601 form.fields.push_back(field); |
645 field.autocomplete_attribute = "garbage section-bar email"; | 602 field.autocomplete_attribute = "garbage section-bar email"; |
646 form.fields.push_back(field); | 603 form.fields.push_back(field); |
647 field.autocomplete_attribute = "garbage shipping email"; | 604 field.autocomplete_attribute = "garbage shipping email"; |
648 form.fields.push_back(field); | 605 form.fields.push_back(field); |
649 field.autocomplete_attribute = "garbage billing email"; | 606 field.autocomplete_attribute = "garbage billing email"; |
650 form.fields.push_back(field); | 607 form.fields.push_back(field); |
651 | 608 |
652 FormStructure form_structure(form, std::string()); | 609 FormStructure form_structure(form); |
653 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 610 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
654 | 611 |
655 // Expect the correct number of fields. | 612 // Expect the correct number of fields. |
656 ASSERT_EQ(6U, form_structure.field_count()); | 613 ASSERT_EQ(6U, form_structure.field_count()); |
657 EXPECT_EQ(2U, form_structure.autofill_count()); | 614 EXPECT_EQ(2U, form_structure.autofill_count()); |
658 | 615 |
659 // All of the fields in this form should be parsed as belonging to the same | 616 // All of the fields in this form should be parsed as belonging to the same |
660 // section. | 617 // section. |
661 std::set<std::string> section_names; | 618 std::set<std::string> section_names; |
662 for (size_t i = 0; i < 6; ++i) { | 619 for (size_t i = 0; i < 6; ++i) { |
663 section_names.insert(form_structure.field(i)->section()); | 620 section_names.insert(form_structure.field(i)->section()); |
664 } | 621 } |
665 EXPECT_EQ(1U, section_names.size()); | 622 EXPECT_EQ(1U, section_names.size()); |
666 } | 623 } |
667 | 624 |
668 // Verify that we can correctly process repeated sections listed in the | 625 // Verify that we can correctly process repeated sections listed in the |
669 // |autocomplete| attribute. | 626 // |autocomplete| attribute. |
670 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { | 627 TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSectionsRepeated) { |
671 FormData form; | 628 FormData form; |
672 form.method = ASCIIToUTF16("post"); | 629 form.method = ASCIIToUTF16("post"); |
673 | 630 |
674 FormFieldData field; | 631 FormFieldData field; |
675 field.form_control_type = "text"; | 632 field.form_control_type = "text"; |
676 | 633 |
677 field.autocomplete_attribute = "section-foo email"; | 634 field.autocomplete_attribute = "section-foo email"; |
678 form.fields.push_back(field); | 635 form.fields.push_back(field); |
679 field.autocomplete_attribute = "section-foo address-line1"; | 636 field.autocomplete_attribute = "section-foo address-line1"; |
680 form.fields.push_back(field); | 637 form.fields.push_back(field); |
681 | 638 |
682 FormStructure form_structure(form, std::string()); | 639 FormStructure form_structure(form); |
683 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 640 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
684 | 641 |
685 // Expect the correct number of fields. | 642 // Expect the correct number of fields. |
686 ASSERT_EQ(2U, form_structure.field_count()); | 643 ASSERT_EQ(2U, form_structure.field_count()); |
687 EXPECT_EQ(2U, form_structure.autofill_count()); | 644 EXPECT_EQ(2U, form_structure.autofill_count()); |
688 | 645 |
689 // All of the fields in this form should be parsed as belonging to the same | 646 // All of the fields in this form should be parsed as belonging to the same |
690 // section. | 647 // section. |
691 std::set<std::string> section_names; | 648 std::set<std::string> section_names; |
692 for (size_t i = 0; i < 2; ++i) { | 649 for (size_t i = 0; i < 2; ++i) { |
(...skipping 17 matching lines...) Expand all Loading... |
710 field.name = base::string16(); | 667 field.name = base::string16(); |
711 field.autocomplete_attribute = "section-foo email"; | 668 field.autocomplete_attribute = "section-foo email"; |
712 form.fields.push_back(field); | 669 form.fields.push_back(field); |
713 field.name = base::string16(); | 670 field.name = base::string16(); |
714 field.autocomplete_attribute = "name"; | 671 field.autocomplete_attribute = "name"; |
715 form.fields.push_back(field); | 672 form.fields.push_back(field); |
716 field.name = ASCIIToUTF16("two"); | 673 field.name = ASCIIToUTF16("two"); |
717 field.autocomplete_attribute = "address-line1"; | 674 field.autocomplete_attribute = "address-line1"; |
718 form.fields.push_back(field); | 675 form.fields.push_back(field); |
719 | 676 |
720 FormStructure form_structure(form, std::string()); | 677 FormStructure form_structure(form); |
721 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); | 678 form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
722 | 679 |
723 // Expect the correct number of fields. | 680 // Expect the correct number of fields. |
724 ASSERT_EQ(4U, form_structure.field_count()); | 681 ASSERT_EQ(4U, form_structure.field_count()); |
725 EXPECT_EQ(4U, form_structure.autofill_count()); | 682 EXPECT_EQ(4U, form_structure.autofill_count()); |
726 | 683 |
727 // Normally, the two separate address fields would cause us to detect two | 684 // Normally, the two separate address fields would cause us to detect two |
728 // separate sections; but because there is an author-specified section in this | 685 // separate sections; but because there is an author-specified section in this |
729 // form, we do not apply these usual heuristics. | 686 // form, we do not apply these usual heuristics. |
730 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); | 687 EXPECT_EQ(ASCIIToUTF16("one"), form_structure.field(0)->name); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 | 732 |
776 field.label = ASCIIToUTF16("Phone Number:"); | 733 field.label = ASCIIToUTF16("Phone Number:"); |
777 field.name = ASCIIToUTF16("BillTo.Phone"); | 734 field.name = ASCIIToUTF16("BillTo.Phone"); |
778 form.fields.push_back(field); | 735 form.fields.push_back(field); |
779 | 736 |
780 field.label = base::string16(); | 737 field.label = base::string16(); |
781 field.name = ASCIIToUTF16("Submit"); | 738 field.name = ASCIIToUTF16("Submit"); |
782 field.form_control_type = "submit"; | 739 field.form_control_type = "submit"; |
783 form.fields.push_back(field); | 740 form.fields.push_back(field); |
784 | 741 |
785 form_structure.reset(new FormStructure(form, std::string())); | 742 form_structure.reset(new FormStructure(form)); |
786 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 743 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
787 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 744 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
788 ASSERT_EQ(10U, form_structure->field_count()); | 745 ASSERT_EQ(10U, form_structure->field_count()); |
789 ASSERT_EQ(9U, form_structure->autofill_count()); | 746 ASSERT_EQ(9U, form_structure->autofill_count()); |
790 | 747 |
791 // First name. | 748 // First name. |
792 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 749 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
793 // Last name. | 750 // Last name. |
794 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 751 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
795 // Address. | 752 // Address. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 field.label = ASCIIToUTF16("Zip Code"); | 800 field.label = ASCIIToUTF16("Zip Code"); |
844 field.name = ASCIIToUTF16("Home.PostalCode"); | 801 field.name = ASCIIToUTF16("Home.PostalCode"); |
845 form.fields.push_back(field); | 802 form.fields.push_back(field); |
846 | 803 |
847 field.label = base::string16(); | 804 field.label = base::string16(); |
848 field.name = ASCIIToUTF16("Submit"); | 805 field.name = ASCIIToUTF16("Submit"); |
849 field.value = ASCIIToUTF16("continue"); | 806 field.value = ASCIIToUTF16("continue"); |
850 field.form_control_type = "submit"; | 807 field.form_control_type = "submit"; |
851 form.fields.push_back(field); | 808 form.fields.push_back(field); |
852 | 809 |
853 form_structure.reset(new FormStructure(form, std::string())); | 810 form_structure.reset(new FormStructure(form)); |
854 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 811 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
855 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 812 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
856 ASSERT_EQ(7U, form_structure->field_count()); | 813 ASSERT_EQ(7U, form_structure->field_count()); |
857 ASSERT_EQ(6U, form_structure->autofill_count()); | 814 ASSERT_EQ(6U, form_structure->autofill_count()); |
858 | 815 |
859 // Email. | 816 // Email. |
860 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); | 817 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(0)->heuristic_type()); |
861 // Full name. | 818 // Full name. |
862 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); | 819 EXPECT_EQ(NAME_FULL, form_structure->field(1)->heuristic_type()); |
863 // Company | 820 // Company |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 866 |
910 field.label = ASCIIToUTF16("Zip code"); | 867 field.label = ASCIIToUTF16("Zip code"); |
911 field.name = base::string16(); | 868 field.name = base::string16(); |
912 form.fields.push_back(field); | 869 form.fields.push_back(field); |
913 | 870 |
914 field.label = base::string16(); | 871 field.label = base::string16(); |
915 field.name = ASCIIToUTF16("Submit"); | 872 field.name = ASCIIToUTF16("Submit"); |
916 field.form_control_type = "submit"; | 873 field.form_control_type = "submit"; |
917 form.fields.push_back(field); | 874 form.fields.push_back(field); |
918 | 875 |
919 form_structure.reset(new FormStructure(form, std::string())); | 876 form_structure.reset(new FormStructure(form)); |
920 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 877 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
921 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 878 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
922 ASSERT_EQ(8U, form_structure->field_count()); | 879 ASSERT_EQ(8U, form_structure->field_count()); |
923 ASSERT_EQ(7U, form_structure->autofill_count()); | 880 ASSERT_EQ(7U, form_structure->autofill_count()); |
924 | 881 |
925 // First name. | 882 // First name. |
926 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 883 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
927 // Last name. | 884 // Last name. |
928 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 885 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
929 // Email. | 886 // Email. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 | 924 |
968 field.label = ASCIIToUTF16("Verification"); | 925 field.label = ASCIIToUTF16("Verification"); |
969 field.name = ASCIIToUTF16("verification"); | 926 field.name = ASCIIToUTF16("verification"); |
970 form.fields.push_back(field); | 927 form.fields.push_back(field); |
971 | 928 |
972 field.label = base::string16(); | 929 field.label = base::string16(); |
973 field.name = ASCIIToUTF16("Submit"); | 930 field.name = ASCIIToUTF16("Submit"); |
974 field.form_control_type = "submit"; | 931 field.form_control_type = "submit"; |
975 form.fields.push_back(field); | 932 form.fields.push_back(field); |
976 | 933 |
977 form_structure.reset(new FormStructure(form, std::string())); | 934 form_structure.reset(new FormStructure(form)); |
978 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 935 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
979 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 936 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
980 ASSERT_EQ(6U, form_structure->field_count()); | 937 ASSERT_EQ(6U, form_structure->field_count()); |
981 ASSERT_EQ(5U, form_structure->autofill_count()); | 938 ASSERT_EQ(5U, form_structure->autofill_count()); |
982 | 939 |
983 // Credit card name. | 940 // Credit card name. |
984 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 941 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
985 // Credit card number. | 942 // Credit card number. |
986 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); | 943 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(1)->heuristic_type()); |
987 // Credit card expiration month. | 944 // Credit card expiration month. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 | 985 |
1029 field.label = ASCIIToUTF16("Verification"); | 986 field.label = ASCIIToUTF16("Verification"); |
1030 field.name = ASCIIToUTF16("verification"); | 987 field.name = ASCIIToUTF16("verification"); |
1031 form.fields.push_back(field); | 988 form.fields.push_back(field); |
1032 | 989 |
1033 field.label = base::string16(); | 990 field.label = base::string16(); |
1034 field.name = ASCIIToUTF16("Submit"); | 991 field.name = ASCIIToUTF16("Submit"); |
1035 field.form_control_type = "submit"; | 992 field.form_control_type = "submit"; |
1036 form.fields.push_back(field); | 993 form.fields.push_back(field); |
1037 | 994 |
1038 form_structure.reset(new FormStructure(form, std::string())); | 995 form_structure.reset(new FormStructure(form)); |
1039 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 996 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1040 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 997 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1041 ASSERT_EQ(7U, form_structure->field_count()); | 998 ASSERT_EQ(7U, form_structure->field_count()); |
1042 ASSERT_EQ(5U, form_structure->autofill_count()); | 999 ASSERT_EQ(5U, form_structure->autofill_count()); |
1043 | 1000 |
1044 // Credit card name. | 1001 // Credit card name. |
1045 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1002 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
1046 // Credit card type. This is an unknown type but related to the credit card. | 1003 // Credit card type. This is an unknown type but related to the credit card. |
1047 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 1004 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
1048 // Credit card number. | 1005 // Credit card number. |
(...skipping 27 matching lines...) Expand all Loading... |
1076 form.fields.push_back(field); | 1033 form.fields.push_back(field); |
1077 | 1034 |
1078 field.label = ASCIIToUTF16("Address Line3"); | 1035 field.label = ASCIIToUTF16("Address Line3"); |
1079 field.name = ASCIIToUTF16("Address"); | 1036 field.name = ASCIIToUTF16("Address"); |
1080 form.fields.push_back(field); | 1037 form.fields.push_back(field); |
1081 | 1038 |
1082 field.label = ASCIIToUTF16("City"); | 1039 field.label = ASCIIToUTF16("City"); |
1083 field.name = ASCIIToUTF16("city"); | 1040 field.name = ASCIIToUTF16("city"); |
1084 form.fields.push_back(field); | 1041 form.fields.push_back(field); |
1085 | 1042 |
1086 form_structure.reset(new FormStructure(form, std::string())); | 1043 form_structure.reset(new FormStructure(form)); |
1087 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1044 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1088 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1045 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1089 ASSERT_EQ(4U, form_structure->field_count()); | 1046 ASSERT_EQ(4U, form_structure->field_count()); |
1090 ASSERT_EQ(3U, form_structure->autofill_count()); | 1047 ASSERT_EQ(3U, form_structure->autofill_count()); |
1091 | 1048 |
1092 // Address Line 1. | 1049 // Address Line 1. |
1093 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1050 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1094 // Address Line 2. | 1051 // Address Line 2. |
1095 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1052 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1096 // Address Line 3. | 1053 // Address Line 3. |
(...skipping 21 matching lines...) Expand all Loading... |
1118 form.fields.push_back(field); | 1075 form.fields.push_back(field); |
1119 | 1076 |
1120 field.label = ASCIIToUTF16("Address Line1"); | 1077 field.label = ASCIIToUTF16("Address Line1"); |
1121 field.name = ASCIIToUTF16("billing.address.addressLine1"); | 1078 field.name = ASCIIToUTF16("billing.address.addressLine1"); |
1122 form.fields.push_back(field); | 1079 form.fields.push_back(field); |
1123 | 1080 |
1124 field.label = ASCIIToUTF16("Address Line2"); | 1081 field.label = ASCIIToUTF16("Address Line2"); |
1125 field.name = ASCIIToUTF16("billing.address.addressLine2"); | 1082 field.name = ASCIIToUTF16("billing.address.addressLine2"); |
1126 form.fields.push_back(field); | 1083 form.fields.push_back(field); |
1127 | 1084 |
1128 form_structure.reset(new FormStructure(form, std::string())); | 1085 form_structure.reset(new FormStructure(form)); |
1129 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1086 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1130 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1087 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1131 ASSERT_EQ(4U, form_structure->field_count()); | 1088 ASSERT_EQ(4U, form_structure->field_count()); |
1132 ASSERT_EQ(4U, form_structure->autofill_count()); | 1089 ASSERT_EQ(4U, form_structure->autofill_count()); |
1133 | 1090 |
1134 // Address Line 1. | 1091 // Address Line 1. |
1135 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1092 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1136 // Address Line 2. | 1093 // Address Line 2. |
1137 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1094 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1138 // Address Line 1. | 1095 // Address Line 1. |
(...skipping 20 matching lines...) Expand all Loading... |
1159 form.fields.push_back(field); | 1116 form.fields.push_back(field); |
1160 | 1117 |
1161 field.label = ASCIIToUTF16("Address Line3"); | 1118 field.label = ASCIIToUTF16("Address Line3"); |
1162 field.name = ASCIIToUTF16("billing.address.addressLine3"); | 1119 field.name = ASCIIToUTF16("billing.address.addressLine3"); |
1163 form.fields.push_back(field); | 1120 form.fields.push_back(field); |
1164 | 1121 |
1165 field.label = ASCIIToUTF16("Address Line4"); | 1122 field.label = ASCIIToUTF16("Address Line4"); |
1166 field.name = ASCIIToUTF16("billing.address.addressLine4"); | 1123 field.name = ASCIIToUTF16("billing.address.addressLine4"); |
1167 form.fields.push_back(field); | 1124 form.fields.push_back(field); |
1168 | 1125 |
1169 form_structure.reset(new FormStructure(form, std::string())); | 1126 form_structure.reset(new FormStructure(form)); |
1170 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1127 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1171 ASSERT_EQ(4U, form_structure->field_count()); | 1128 ASSERT_EQ(4U, form_structure->field_count()); |
1172 ASSERT_EQ(2U, form_structure->autofill_count()); | 1129 ASSERT_EQ(2U, form_structure->autofill_count()); |
1173 | 1130 |
1174 // Address Line 1. | 1131 // Address Line 1. |
1175 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1132 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1176 // Address Line 2. | 1133 // Address Line 2. |
1177 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1134 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1178 // Address Line 3 (ignored). | 1135 // Address Line 3 (ignored). |
1179 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 1136 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
(...skipping 23 matching lines...) Expand all Loading... |
1203 form.fields.push_back(field); | 1160 form.fields.push_back(field); |
1204 | 1161 |
1205 field.label = ASCIIToUTF16("Street address second line"); | 1162 field.label = ASCIIToUTF16("Street address second line"); |
1206 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); | 1163 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_ads2"); |
1207 form.fields.push_back(field); | 1164 form.fields.push_back(field); |
1208 | 1165 |
1209 field.label = ASCIIToUTF16("City:"); | 1166 field.label = ASCIIToUTF16("City:"); |
1210 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); | 1167 field.name = ASCIIToUTF16("FOPIH_RgWebCC_0_IHAddress_adct"); |
1211 form.fields.push_back(field); | 1168 form.fields.push_back(field); |
1212 | 1169 |
1213 form_structure.reset(new FormStructure(form, std::string())); | 1170 form_structure.reset(new FormStructure(form)); |
1214 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1171 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1215 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1172 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1216 ASSERT_EQ(4U, form_structure->field_count()); | 1173 ASSERT_EQ(4U, form_structure->field_count()); |
1217 EXPECT_EQ(3U, form_structure->autofill_count()); | 1174 EXPECT_EQ(3U, form_structure->autofill_count()); |
1218 | 1175 |
1219 // Address Line 1. | 1176 // Address Line 1. |
1220 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1177 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1221 // Suite / Apt. | 1178 // Suite / Apt. |
1222 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1179 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1223 // Address Line 3. | 1180 // Address Line 3. |
(...skipping 18 matching lines...) Expand all Loading... |
1242 form.fields.push_back(field); | 1199 form.fields.push_back(field); |
1243 | 1200 |
1244 field.label = ASCIIToUTF16("Floor number, suite number, etc"); | 1201 field.label = ASCIIToUTF16("Floor number, suite number, etc"); |
1245 field.name = ASCIIToUTF16("address2"); | 1202 field.name = ASCIIToUTF16("address2"); |
1246 form.fields.push_back(field); | 1203 form.fields.push_back(field); |
1247 | 1204 |
1248 field.label = ASCIIToUTF16("City:"); | 1205 field.label = ASCIIToUTF16("City:"); |
1249 field.name = ASCIIToUTF16("city"); | 1206 field.name = ASCIIToUTF16("city"); |
1250 form.fields.push_back(field); | 1207 form.fields.push_back(field); |
1251 | 1208 |
1252 form_structure.reset(new FormStructure(form, std::string())); | 1209 form_structure.reset(new FormStructure(form)); |
1253 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1210 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1254 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1211 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1255 ASSERT_EQ(3U, form_structure->field_count()); | 1212 ASSERT_EQ(3U, form_structure->field_count()); |
1256 ASSERT_EQ(3U, form_structure->autofill_count()); | 1213 ASSERT_EQ(3U, form_structure->autofill_count()); |
1257 | 1214 |
1258 // Address Line 1. | 1215 // Address Line 1. |
1259 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1216 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1260 // Address Line 2. | 1217 // Address Line 2. |
1261 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1218 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1262 // City. | 1219 // City. |
(...skipping 13 matching lines...) Expand all Loading... |
1276 form.fields.push_back(field); | 1233 form.fields.push_back(field); |
1277 | 1234 |
1278 field.label = ASCIIToUTF16("Address Line2"); | 1235 field.label = ASCIIToUTF16("Address Line2"); |
1279 field.name = ASCIIToUTF16("Address"); | 1236 field.name = ASCIIToUTF16("Address"); |
1280 form.fields.push_back(field); | 1237 form.fields.push_back(field); |
1281 | 1238 |
1282 field.label = ASCIIToUTF16("State/Province/Region"); | 1239 field.label = ASCIIToUTF16("State/Province/Region"); |
1283 field.name = ASCIIToUTF16("State"); | 1240 field.name = ASCIIToUTF16("State"); |
1284 form.fields.push_back(field); | 1241 form.fields.push_back(field); |
1285 | 1242 |
1286 form_structure.reset(new FormStructure(form, std::string())); | 1243 form_structure.reset(new FormStructure(form)); |
1287 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1244 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1288 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1245 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1289 ASSERT_EQ(3U, form_structure->field_count()); | 1246 ASSERT_EQ(3U, form_structure->field_count()); |
1290 ASSERT_EQ(3U, form_structure->autofill_count()); | 1247 ASSERT_EQ(3U, form_structure->autofill_count()); |
1291 | 1248 |
1292 // Address Line 1. | 1249 // Address Line 1. |
1293 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); | 1250 EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(0)->heuristic_type()); |
1294 // Address Line 2. | 1251 // Address Line 2. |
1295 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); | 1252 EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(1)->heuristic_type()); |
1296 // State. | 1253 // State. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 form.fields.push_back(field); | 1300 form.fields.push_back(field); |
1344 | 1301 |
1345 field.label = ASCIIToUTF16("Phone*:"); | 1302 field.label = ASCIIToUTF16("Phone*:"); |
1346 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); | 1303 field.name = ASCIIToUTF16("editBillingAddress$phoneBox"); |
1347 form.fields.push_back(field); | 1304 form.fields.push_back(field); |
1348 | 1305 |
1349 field.label = ASCIIToUTF16("Email Address*:"); | 1306 field.label = ASCIIToUTF16("Email Address*:"); |
1350 field.name = ASCIIToUTF16("email$emailBox"); | 1307 field.name = ASCIIToUTF16("email$emailBox"); |
1351 form.fields.push_back(field); | 1308 form.fields.push_back(field); |
1352 | 1309 |
1353 form_structure.reset(new FormStructure(form, std::string())); | 1310 form_structure.reset(new FormStructure(form)); |
1354 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1311 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1355 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1312 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1356 ASSERT_EQ(11U, form_structure->field_count()); | 1313 ASSERT_EQ(11U, form_structure->field_count()); |
1357 ASSERT_EQ(11U, form_structure->autofill_count()); | 1314 ASSERT_EQ(11U, form_structure->autofill_count()); |
1358 | 1315 |
1359 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 1316 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); |
1360 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 1317 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); |
1361 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); | 1318 EXPECT_EQ(COMPANY_NAME, form_structure->field(2)->heuristic_type()); |
1362 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); | 1319 EXPECT_EQ(ADDRESS_BILLING_LINE1, form_structure->field(3)->heuristic_type()); |
1363 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); | 1320 EXPECT_EQ(ADDRESS_BILLING_LINE2, form_structure->field(4)->heuristic_type()); |
(...skipping 30 matching lines...) Expand all Loading... |
1394 field.max_length = 4; // Size of suffix is 4. If unlimited size is | 1351 field.max_length = 4; // Size of suffix is 4. If unlimited size is |
1395 // passed, phone will be parsed as | 1352 // passed, phone will be parsed as |
1396 // <country code> - <area code> - <phone>. | 1353 // <country code> - <area code> - <phone>. |
1397 form.fields.push_back(field); | 1354 form.fields.push_back(field); |
1398 | 1355 |
1399 field.label = ASCIIToUTF16("ext.:"); | 1356 field.label = ASCIIToUTF16("ext.:"); |
1400 field.name = ASCIIToUTF16("dayphone4"); | 1357 field.name = ASCIIToUTF16("dayphone4"); |
1401 field.max_length = 0; | 1358 field.max_length = 0; |
1402 form.fields.push_back(field); | 1359 form.fields.push_back(field); |
1403 | 1360 |
1404 form_structure.reset(new FormStructure(form, std::string())); | 1361 form_structure.reset(new FormStructure(form)); |
1405 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1362 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1406 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1363 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1407 ASSERT_EQ(4U, form_structure->field_count()); | 1364 ASSERT_EQ(4U, form_structure->field_count()); |
1408 ASSERT_EQ(3U, form_structure->autofill_count()); | 1365 ASSERT_EQ(3U, form_structure->autofill_count()); |
1409 | 1366 |
1410 // Area code. | 1367 // Area code. |
1411 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); | 1368 EXPECT_EQ(PHONE_HOME_CITY_CODE, form_structure->field(0)->heuristic_type()); |
1412 // Phone number suffix. | 1369 // Phone number suffix. |
1413 EXPECT_EQ(PHONE_HOME_NUMBER, | 1370 EXPECT_EQ(PHONE_HOME_NUMBER, |
1414 form_structure->field(1)->heuristic_type()); | 1371 form_structure->field(1)->heuristic_type()); |
(...skipping 25 matching lines...) Expand all Loading... |
1440 form.fields.push_back(field); | 1397 form.fields.push_back(field); |
1441 | 1398 |
1442 field.label = ASCIIToUTF16("Expiration Date"); | 1399 field.label = ASCIIToUTF16("Expiration Date"); |
1443 field.name = ASCIIToUTF16("expiration_month"); | 1400 field.name = ASCIIToUTF16("expiration_month"); |
1444 form.fields.push_back(field); | 1401 form.fields.push_back(field); |
1445 | 1402 |
1446 field.label = ASCIIToUTF16("Expiration Year"); | 1403 field.label = ASCIIToUTF16("Expiration Year"); |
1447 field.name = ASCIIToUTF16("expiration_year"); | 1404 field.name = ASCIIToUTF16("expiration_year"); |
1448 form.fields.push_back(field); | 1405 form.fields.push_back(field); |
1449 | 1406 |
1450 form_structure.reset(new FormStructure(form, std::string())); | 1407 form_structure.reset(new FormStructure(form)); |
1451 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1408 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1452 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1409 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1453 | 1410 |
1454 // Expect the correct number of fields. | 1411 // Expect the correct number of fields. |
1455 ASSERT_EQ(5U, form_structure->field_count()); | 1412 ASSERT_EQ(5U, form_structure->field_count()); |
1456 EXPECT_EQ(5U, form_structure->autofill_count()); | 1413 EXPECT_EQ(5U, form_structure->autofill_count()); |
1457 | 1414 |
1458 // Name on Card. | 1415 // Name on Card. |
1459 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); | 1416 EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type()); |
1460 // Address. | 1417 // Address. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 form.fields.push_back(field); | 1450 form.fields.push_back(field); |
1494 | 1451 |
1495 field.label = base::string16(); | 1452 field.label = base::string16(); |
1496 field.name = ASCIIToUTF16("ccexpiresyear"); | 1453 field.name = ASCIIToUTF16("ccexpiresyear"); |
1497 form.fields.push_back(field); | 1454 form.fields.push_back(field); |
1498 | 1455 |
1499 field.label = ASCIIToUTF16("cvc number"); | 1456 field.label = ASCIIToUTF16("cvc number"); |
1500 field.name = ASCIIToUTF16("csc"); | 1457 field.name = ASCIIToUTF16("csc"); |
1501 form.fields.push_back(field); | 1458 form.fields.push_back(field); |
1502 | 1459 |
1503 form_structure.reset(new FormStructure(form, std::string())); | 1460 form_structure.reset(new FormStructure(form)); |
1504 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1461 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1505 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 1462 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
1506 | 1463 |
1507 // Expect the correct number of fields. | 1464 // Expect the correct number of fields. |
1508 ASSERT_EQ(6U, form_structure->field_count()); | 1465 ASSERT_EQ(6U, form_structure->field_count()); |
1509 ASSERT_EQ(5U, form_structure->autofill_count()); | 1466 ASSERT_EQ(5U, form_structure->autofill_count()); |
1510 | 1467 |
1511 // Card Number. | 1468 // Card Number. |
1512 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); | 1469 EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(0)->heuristic_type()); |
1513 // First name, taken as name on card. | 1470 // First name, taken as name on card. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 form.fields.push_back(field); | 1509 form.fields.push_back(field); |
1553 | 1510 |
1554 // Add checkable field. | 1511 // Add checkable field. |
1555 FormFieldData checkable_field; | 1512 FormFieldData checkable_field; |
1556 checkable_field.is_checkable = true; | 1513 checkable_field.is_checkable = true; |
1557 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1514 checkable_field.label = ASCIIToUTF16("Checkable1"); |
1558 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1515 checkable_field.name = ASCIIToUTF16("Checkable1"); |
1559 form.fields.push_back(checkable_field); | 1516 form.fields.push_back(checkable_field); |
1560 | 1517 |
1561 ScopedVector<FormStructure> forms; | 1518 ScopedVector<FormStructure> forms; |
1562 forms.push_back(new FormStructure(form, std::string())); | 1519 forms.push_back(new FormStructure(form)); |
1563 std::vector<std::string> encoded_signatures; | 1520 std::vector<std::string> encoded_signatures; |
1564 std::string encoded_xml; | 1521 std::string encoded_xml; |
1565 const char * const kSignature1 = "11337937696949187602"; | 1522 const char * const kSignature1 = "11337937696949187602"; |
1566 const char * const kResponse1 = | 1523 const char * const kResponse1 = |
1567 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1524 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
1568 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1525 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
1569 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" | 1526 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" |
1570 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1527 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
1571 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" | 1528 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" |
1572 "</autofillquery>"; | 1529 "</autofillquery>"; |
1573 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1530 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
1574 &encoded_signatures, | 1531 &encoded_signatures, |
1575 &encoded_xml)); | 1532 &encoded_xml)); |
1576 ASSERT_EQ(1U, encoded_signatures.size()); | 1533 ASSERT_EQ(1U, encoded_signatures.size()); |
1577 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1534 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1578 EXPECT_EQ(kResponse1, encoded_xml); | 1535 EXPECT_EQ(kResponse1, encoded_xml); |
1579 | 1536 |
1580 // Add the same form, only one will be encoded, so EncodeQueryRequest() should | 1537 // Add the same form, only one will be encoded, so EncodeQueryRequest() should |
1581 // return the same data. | 1538 // return the same data. |
1582 forms.push_back(new FormStructure(form, std::string())); | 1539 forms.push_back(new FormStructure(form)); |
1583 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1540 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
1584 &encoded_signatures, | 1541 &encoded_signatures, |
1585 &encoded_xml)); | 1542 &encoded_xml)); |
1586 ASSERT_EQ(1U, encoded_signatures.size()); | 1543 ASSERT_EQ(1U, encoded_signatures.size()); |
1587 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1544 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1588 EXPECT_EQ(kResponse1, encoded_xml); | 1545 EXPECT_EQ(kResponse1, encoded_xml); |
1589 // Add 5 address fields - this should be still a valid form. | 1546 // Add 5 address fields - this should be still a valid form. |
1590 for (size_t i = 0; i < 5; ++i) { | 1547 for (size_t i = 0; i < 5; ++i) { |
1591 field.label = ASCIIToUTF16("Address"); | 1548 field.label = ASCIIToUTF16("Address"); |
1592 field.name = ASCIIToUTF16("address"); | 1549 field.name = ASCIIToUTF16("address"); |
1593 form.fields.push_back(field); | 1550 form.fields.push_back(field); |
1594 } | 1551 } |
1595 | 1552 |
1596 forms.push_back(new FormStructure(form, std::string())); | 1553 forms.push_back(new FormStructure(form)); |
1597 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1554 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
1598 &encoded_signatures, | 1555 &encoded_signatures, |
1599 &encoded_xml)); | 1556 &encoded_xml)); |
1600 ASSERT_EQ(2U, encoded_signatures.size()); | 1557 ASSERT_EQ(2U, encoded_signatures.size()); |
1601 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1558 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1602 const char * const kSignature2 = "8308881815906226214"; | 1559 const char * const kSignature2 = "8308881815906226214"; |
1603 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1560 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
1604 const char * const kResponse2 = | 1561 const char * const kResponse2 = |
1605 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1562 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
1606 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1563 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
(...skipping 10 matching lines...) Expand all Loading... |
1617 | 1574 |
1618 FormData malformed_form(form); | 1575 FormData malformed_form(form); |
1619 // Add 50 address fields - the form is not valid anymore, but previous ones | 1576 // Add 50 address fields - the form is not valid anymore, but previous ones |
1620 // are. The result should be the same as in previous test. | 1577 // are. The result should be the same as in previous test. |
1621 for (size_t i = 0; i < 50; ++i) { | 1578 for (size_t i = 0; i < 50; ++i) { |
1622 field.label = ASCIIToUTF16("Address"); | 1579 field.label = ASCIIToUTF16("Address"); |
1623 field.name = ASCIIToUTF16("address"); | 1580 field.name = ASCIIToUTF16("address"); |
1624 malformed_form.fields.push_back(field); | 1581 malformed_form.fields.push_back(field); |
1625 } | 1582 } |
1626 | 1583 |
1627 forms.push_back(new FormStructure(malformed_form, std::string())); | 1584 forms.push_back(new FormStructure(malformed_form)); |
1628 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1585 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
1629 &encoded_signatures, | 1586 &encoded_signatures, |
1630 &encoded_xml)); | 1587 &encoded_xml)); |
1631 ASSERT_EQ(2U, encoded_signatures.size()); | 1588 ASSERT_EQ(2U, encoded_signatures.size()); |
1632 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1589 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1633 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1590 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
1634 EXPECT_EQ(kResponse2, encoded_xml); | 1591 EXPECT_EQ(kResponse2, encoded_xml); |
1635 | 1592 |
1636 // Check that we fail if there are only bad form(s). | 1593 // Check that we fail if there are only bad form(s). |
1637 ScopedVector<FormStructure> bad_forms; | 1594 ScopedVector<FormStructure> bad_forms; |
1638 bad_forms.push_back(new FormStructure(malformed_form, std::string())); | 1595 bad_forms.push_back(new FormStructure(malformed_form)); |
1639 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1596 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
1640 &encoded_signatures, | 1597 &encoded_signatures, |
1641 &encoded_xml)); | 1598 &encoded_xml)); |
1642 EXPECT_EQ(0U, encoded_signatures.size()); | 1599 EXPECT_EQ(0U, encoded_signatures.size()); |
1643 EXPECT_EQ("", encoded_xml); | 1600 EXPECT_EQ("", encoded_xml); |
1644 | |
1645 // Check the behaviour with autocheckout enabled. | |
1646 ScopedVector<FormStructure> checkable_forms; | |
1647 checkable_forms.push_back( | |
1648 new FormStructure(form, "https://www.sample1.com/query/path")); | |
1649 | |
1650 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | |
1651 &encoded_signatures, | |
1652 &encoded_xml)); | |
1653 const char * const kSignature3 = "7747357776717901584"; | |
1654 const char * const kResponse3 = | |
1655 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | |
1656 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"a,e\" " | |
1657 "urlprefixsignature=\"7648393911063090788\">" | |
1658 "<form signature=\"7747357776717901584\">" | |
1659 "<field signature=\"412125936\"/>" | |
1660 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | |
1661 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | |
1662 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | |
1663 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | |
1664 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | |
1665 "</autofillquery>"; | |
1666 ASSERT_EQ(1U, encoded_signatures.size()); | |
1667 EXPECT_EQ(kSignature3, encoded_signatures[0]); | |
1668 EXPECT_EQ(kResponse3, encoded_xml); | |
1669 } | 1601 } |
1670 | 1602 |
1671 TEST(FormStructureTest, EncodeUploadRequest) { | 1603 TEST(FormStructureTest, EncodeUploadRequest) { |
1672 scoped_ptr<FormStructure> form_structure; | 1604 scoped_ptr<FormStructure> form_structure; |
1673 std::vector<ServerFieldTypeSet> possible_field_types; | 1605 std::vector<ServerFieldTypeSet> possible_field_types; |
1674 FormData form; | 1606 FormData form; |
1675 form.method = ASCIIToUTF16("post"); | 1607 form.method = ASCIIToUTF16("post"); |
1676 form_structure.reset(new FormStructure(form, std::string())); | 1608 form_structure.reset(new FormStructure(form)); |
1677 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1609 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1678 | 1610 |
1679 FormFieldData field; | 1611 FormFieldData field; |
1680 field.form_control_type = "text"; | 1612 field.form_control_type = "text"; |
1681 | 1613 |
1682 field.label = ASCIIToUTF16("First Name"); | 1614 field.label = ASCIIToUTF16("First Name"); |
1683 field.name = ASCIIToUTF16("firstname"); | 1615 field.name = ASCIIToUTF16("firstname"); |
1684 form.fields.push_back(field); | 1616 form.fields.push_back(field); |
1685 possible_field_types.push_back(ServerFieldTypeSet()); | 1617 possible_field_types.push_back(ServerFieldTypeSet()); |
1686 possible_field_types.back().insert(NAME_FIRST); | 1618 possible_field_types.back().insert(NAME_FIRST); |
(...skipping 27 matching lines...) Expand all Loading... |
1714 | 1646 |
1715 // Add checkable field. | 1647 // Add checkable field. |
1716 FormFieldData checkable_field; | 1648 FormFieldData checkable_field; |
1717 checkable_field.is_checkable = true; | 1649 checkable_field.is_checkable = true; |
1718 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1650 checkable_field.label = ASCIIToUTF16("Checkable1"); |
1719 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1651 checkable_field.name = ASCIIToUTF16("Checkable1"); |
1720 form.fields.push_back(checkable_field); | 1652 form.fields.push_back(checkable_field); |
1721 possible_field_types.push_back(ServerFieldTypeSet()); | 1653 possible_field_types.push_back(ServerFieldTypeSet()); |
1722 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 1654 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
1723 | 1655 |
1724 form_structure.reset(new FormStructure(form, std::string())); | 1656 form_structure.reset(new FormStructure(form)); |
1725 | 1657 |
1726 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1658 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
1727 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1659 for (size_t i = 0; i < form_structure->field_count(); ++i) |
1728 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1660 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
1729 | 1661 |
1730 ServerFieldTypeSet available_field_types; | 1662 ServerFieldTypeSet available_field_types; |
1731 available_field_types.insert(NAME_FIRST); | 1663 available_field_types.insert(NAME_FIRST); |
1732 available_field_types.insert(NAME_LAST); | 1664 available_field_types.insert(NAME_LAST); |
1733 available_field_types.insert(ADDRESS_HOME_LINE1); | 1665 available_field_types.insert(ADDRESS_HOME_LINE1); |
1734 available_field_types.insert(ADDRESS_HOME_LINE2); | 1666 available_field_types.insert(ADDRESS_HOME_LINE2); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 field.name = ASCIIToUTF16("address"); | 1704 field.name = ASCIIToUTF16("address"); |
1773 field.form_control_type = "text"; | 1705 field.form_control_type = "text"; |
1774 form.fields.push_back(field); | 1706 form.fields.push_back(field); |
1775 possible_field_types.push_back(ServerFieldTypeSet()); | 1707 possible_field_types.push_back(ServerFieldTypeSet()); |
1776 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1708 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
1777 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1709 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
1778 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1710 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
1779 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1711 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
1780 } | 1712 } |
1781 | 1713 |
1782 form_structure.reset(new FormStructure(form, std::string())); | 1714 form_structure.reset(new FormStructure(form)); |
1783 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1715 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
1784 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1716 for (size_t i = 0; i < form_structure->field_count(); ++i) |
1785 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1717 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
1786 | 1718 |
1787 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 1719 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
1788 &encoded_xml)); | 1720 &encoded_xml)); |
1789 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 1721 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
1790 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " | 1722 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\" " |
1791 "formsignature=\"7816485729218079147\" autofillused=\"false\" " | 1723 "formsignature=\"7816485729218079147\" autofillused=\"false\" " |
1792 "datapresent=\"144200030e\">" | 1724 "datapresent=\"144200030e\">" |
(...skipping 18 matching lines...) Expand all Loading... |
1811 field.label = ASCIIToUTF16("Address"); | 1743 field.label = ASCIIToUTF16("Address"); |
1812 field.name = ASCIIToUTF16("address"); | 1744 field.name = ASCIIToUTF16("address"); |
1813 field.form_control_type = "text"; | 1745 field.form_control_type = "text"; |
1814 form.fields.push_back(field); | 1746 form.fields.push_back(field); |
1815 possible_field_types.push_back(ServerFieldTypeSet()); | 1747 possible_field_types.push_back(ServerFieldTypeSet()); |
1816 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1748 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
1817 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1749 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
1818 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1750 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
1819 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1751 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
1820 } | 1752 } |
1821 form_structure.reset(new FormStructure(form, std::string())); | 1753 form_structure.reset(new FormStructure(form)); |
1822 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1754 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
1823 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1755 for (size_t i = 0; i < form_structure->field_count(); ++i) |
1824 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1756 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
1825 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, | 1757 EXPECT_FALSE(form_structure->EncodeUploadRequest(available_field_types, false, |
1826 &encoded_xml)); | 1758 &encoded_xml)); |
1827 } | 1759 } |
1828 | 1760 |
1829 TEST(FormStructureTest, EncodeFieldAssignments) { | 1761 TEST(FormStructureTest, EncodeFieldAssignments) { |
1830 scoped_ptr<FormStructure> form_structure; | 1762 scoped_ptr<FormStructure> form_structure; |
1831 std::vector<ServerFieldTypeSet> possible_field_types; | 1763 std::vector<ServerFieldTypeSet> possible_field_types; |
1832 FormData form; | 1764 FormData form; |
1833 form.method = ASCIIToUTF16("post"); | 1765 form.method = ASCIIToUTF16("post"); |
1834 form_structure.reset(new FormStructure(form, std::string())); | 1766 form_structure.reset(new FormStructure(form)); |
1835 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1767 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1836 | 1768 |
1837 FormFieldData field; | 1769 FormFieldData field; |
1838 field.form_control_type = "text"; | 1770 field.form_control_type = "text"; |
1839 | 1771 |
1840 field.label = ASCIIToUTF16("First Name"); | 1772 field.label = ASCIIToUTF16("First Name"); |
1841 field.name = ASCIIToUTF16("firstname"); | 1773 field.name = ASCIIToUTF16("firstname"); |
1842 form.fields.push_back(field); | 1774 form.fields.push_back(field); |
1843 possible_field_types.push_back(ServerFieldTypeSet()); | 1775 possible_field_types.push_back(ServerFieldTypeSet()); |
1844 possible_field_types.back().insert(NAME_FIRST); | 1776 possible_field_types.back().insert(NAME_FIRST); |
(...skipping 27 matching lines...) Expand all Loading... |
1872 | 1804 |
1873 // Add checkable field. | 1805 // Add checkable field. |
1874 FormFieldData checkable_field; | 1806 FormFieldData checkable_field; |
1875 checkable_field.is_checkable = true; | 1807 checkable_field.is_checkable = true; |
1876 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1808 checkable_field.label = ASCIIToUTF16("Checkable1"); |
1877 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1809 checkable_field.name = ASCIIToUTF16("Checkable1"); |
1878 form.fields.push_back(checkable_field); | 1810 form.fields.push_back(checkable_field); |
1879 possible_field_types.push_back(ServerFieldTypeSet()); | 1811 possible_field_types.push_back(ServerFieldTypeSet()); |
1880 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); | 1812 possible_field_types.back().insert(ADDRESS_HOME_COUNTRY); |
1881 | 1813 |
1882 form_structure.reset(new FormStructure(form, std::string())); | 1814 form_structure.reset(new FormStructure(form)); |
1883 | 1815 |
1884 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1816 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
1885 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1817 for (size_t i = 0; i < form_structure->field_count(); ++i) |
1886 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1818 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
1887 | 1819 |
1888 ServerFieldTypeSet available_field_types; | 1820 ServerFieldTypeSet available_field_types; |
1889 available_field_types.insert(NAME_FIRST); | 1821 available_field_types.insert(NAME_FIRST); |
1890 available_field_types.insert(NAME_LAST); | 1822 available_field_types.insert(NAME_LAST); |
1891 available_field_types.insert(ADDRESS_HOME_LINE1); | 1823 available_field_types.insert(ADDRESS_HOME_LINE1); |
1892 available_field_types.insert(ADDRESS_HOME_LINE2); | 1824 available_field_types.insert(ADDRESS_HOME_LINE2); |
(...skipping 24 matching lines...) Expand all Loading... |
1917 field.name = ASCIIToUTF16("address"); | 1849 field.name = ASCIIToUTF16("address"); |
1918 field.form_control_type = "text"; | 1850 field.form_control_type = "text"; |
1919 form.fields.push_back(field); | 1851 form.fields.push_back(field); |
1920 possible_field_types.push_back(ServerFieldTypeSet()); | 1852 possible_field_types.push_back(ServerFieldTypeSet()); |
1921 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 1853 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
1922 possible_field_types.back().insert(ADDRESS_HOME_LINE2); | 1854 possible_field_types.back().insert(ADDRESS_HOME_LINE2); |
1923 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); | 1855 possible_field_types.back().insert(ADDRESS_BILLING_LINE1); |
1924 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); | 1856 possible_field_types.back().insert(ADDRESS_BILLING_LINE2); |
1925 } | 1857 } |
1926 | 1858 |
1927 form_structure.reset(new FormStructure(form, std::string())); | 1859 form_structure.reset(new FormStructure(form)); |
1928 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); | 1860 ASSERT_EQ(form_structure->field_count(), possible_field_types.size()); |
1929 for (size_t i = 0; i < form_structure->field_count(); ++i) | 1861 for (size_t i = 0; i < form_structure->field_count(); ++i) |
1930 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 1862 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
1931 | 1863 |
1932 EXPECT_TRUE(form_structure->EncodeFieldAssignments( | 1864 EXPECT_TRUE(form_structure->EncodeFieldAssignments( |
1933 available_field_types, &encoded_xml)); | 1865 available_field_types, &encoded_xml)); |
1934 EXPECT_EQ( | 1866 EXPECT_EQ( |
1935 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 1867 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
1936 "<fieldassignments formsignature=\"7816485729218079147\">" | 1868 "<fieldassignments formsignature=\"7816485729218079147\">" |
1937 "<fields fieldid=\"3763331450\" fieldtype=\"3\" name=\"firstname\"/>" | 1869 "<fields fieldid=\"3763331450\" fieldtype=\"3\" name=\"firstname\"/>" |
(...skipping 28 matching lines...) Expand all Loading... |
1966 form.fields.push_back(field); | 1898 form.fields.push_back(field); |
1967 | 1899 |
1968 field.label = ASCIIToUTF16("Last Name"); | 1900 field.label = ASCIIToUTF16("Last Name"); |
1969 field.name = ASCIIToUTF16("last"); | 1901 field.name = ASCIIToUTF16("last"); |
1970 form.fields.push_back(field); | 1902 form.fields.push_back(field); |
1971 | 1903 |
1972 field.label = ASCIIToUTF16("Email"); | 1904 field.label = ASCIIToUTF16("Email"); |
1973 field.name = ASCIIToUTF16("email"); | 1905 field.name = ASCIIToUTF16("email"); |
1974 form.fields.push_back(field); | 1906 form.fields.push_back(field); |
1975 | 1907 |
1976 FormStructure form_structure(form, std::string()); | 1908 FormStructure form_structure(form); |
1977 | 1909 |
1978 ServerFieldTypeSet unknown_type; | 1910 ServerFieldTypeSet unknown_type; |
1979 unknown_type.insert(UNKNOWN_TYPE); | 1911 unknown_type.insert(UNKNOWN_TYPE); |
1980 for (size_t i = 0; i < form_structure.field_count(); ++i) | 1912 for (size_t i = 0; i < form_structure.field_count(); ++i) |
1981 form_structure.field(i)->set_possible_types(unknown_type); | 1913 form_structure.field(i)->set_possible_types(unknown_type); |
1982 | 1914 |
1983 // No available types. | 1915 // No available types. |
1984 // datapresent should be "" == trimmmed(0x0000000000000000) == | 1916 // datapresent should be "" == trimmmed(0x0000000000000000) == |
1985 // 0b0000000000000000000000000000000000000000000000000000000000000000 | 1917 // 0b0000000000000000000000000000000000000000000000000000000000000000 |
1986 ServerFieldTypeSet available_field_types; | 1918 ServerFieldTypeSet available_field_types; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 form.fields.push_back(field); | 2164 form.fields.push_back(field); |
2233 possible_field_types.push_back(ServerFieldTypeSet()); | 2165 possible_field_types.push_back(ServerFieldTypeSet()); |
2234 possible_field_types.back().insert(NAME_LAST); | 2166 possible_field_types.back().insert(NAME_LAST); |
2235 | 2167 |
2236 field.label = ASCIIToUTF16("Address"); | 2168 field.label = ASCIIToUTF16("Address"); |
2237 field.name = ASCIIToUTF16("address"); | 2169 field.name = ASCIIToUTF16("address"); |
2238 form.fields.push_back(field); | 2170 form.fields.push_back(field); |
2239 possible_field_types.push_back(ServerFieldTypeSet()); | 2171 possible_field_types.push_back(ServerFieldTypeSet()); |
2240 possible_field_types.back().insert(ADDRESS_HOME_LINE1); | 2172 possible_field_types.back().insert(ADDRESS_HOME_LINE1); |
2241 | 2173 |
2242 form_structure.reset(new FormStructure(form, std::string())); | 2174 form_structure.reset(new FormStructure(form)); |
2243 | 2175 |
2244 for (size_t i = 0; i < form_structure->field_count(); ++i) | 2176 for (size_t i = 0; i < form_structure->field_count(); ++i) |
2245 form_structure->field(i)->set_possible_types(possible_field_types[i]); | 2177 form_structure->field(i)->set_possible_types(possible_field_types[i]); |
2246 std::string encoded_xml; | 2178 std::string encoded_xml; |
2247 | 2179 |
2248 // Now we matched both fields singularly. | 2180 // Now we matched both fields singularly. |
2249 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, | 2181 EXPECT_TRUE(form_structure->EncodeUploadRequest(available_field_types, false, |
2250 &encoded_xml)); | 2182 &encoded_xml)); |
2251 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" | 2183 EXPECT_EQ("<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>" |
2252 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" | 2184 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 field.label = ASCIIToUTF16("First Name"); | 2260 field.label = ASCIIToUTF16("First Name"); |
2329 field.name = ASCIIToUTF16("first"); | 2261 field.name = ASCIIToUTF16("first"); |
2330 form.fields.push_back(field); | 2262 form.fields.push_back(field); |
2331 | 2263 |
2332 // Password fields shouldn't affect the signature. | 2264 // Password fields shouldn't affect the signature. |
2333 field.label = ASCIIToUTF16("Password"); | 2265 field.label = ASCIIToUTF16("Password"); |
2334 field.name = ASCIIToUTF16("password"); | 2266 field.name = ASCIIToUTF16("password"); |
2335 field.form_control_type = "password"; | 2267 field.form_control_type = "password"; |
2336 form.fields.push_back(field); | 2268 form.fields.push_back(field); |
2337 | 2269 |
2338 form_structure.reset(new FormStructure(form, std::string())); | 2270 form_structure.reset(new FormStructure(form)); |
2339 | 2271 |
2340 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2272 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2341 std::string("://&&email&first")), | 2273 std::string("://&&email&first")), |
2342 form_structure->FormSignature()); | 2274 form_structure->FormSignature()); |
2343 | 2275 |
2344 form.origin = GURL(std::string("http://www.facebook.com")); | 2276 form.origin = GURL(std::string("http://www.facebook.com")); |
2345 form_structure.reset(new FormStructure(form, std::string())); | 2277 form_structure.reset(new FormStructure(form)); |
2346 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2278 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2347 std::string("http://www.facebook.com&&email&first")), | 2279 std::string("http://www.facebook.com&&email&first")), |
2348 form_structure->FormSignature()); | 2280 form_structure->FormSignature()); |
2349 | 2281 |
2350 form.action = GURL(std::string("https://login.facebook.com/path")); | 2282 form.action = GURL(std::string("https://login.facebook.com/path")); |
2351 form_structure.reset(new FormStructure(form, std::string())); | 2283 form_structure.reset(new FormStructure(form)); |
2352 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2284 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2353 std::string("https://login.facebook.com&&email&first")), | 2285 std::string("https://login.facebook.com&&email&first")), |
2354 form_structure->FormSignature()); | 2286 form_structure->FormSignature()); |
2355 | 2287 |
2356 form.name = ASCIIToUTF16("login_form"); | 2288 form.name = ASCIIToUTF16("login_form"); |
2357 form_structure.reset(new FormStructure(form, std::string())); | 2289 form_structure.reset(new FormStructure(form)); |
2358 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2290 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2359 std::string("https://login.facebook.com&login_form&email&first")), | 2291 std::string("https://login.facebook.com&login_form&email&first")), |
2360 form_structure->FormSignature()); | 2292 form_structure->FormSignature()); |
2361 | 2293 |
2362 field.label = ASCIIToUTF16("Random Field label"); | 2294 field.label = ASCIIToUTF16("Random Field label"); |
2363 field.name = ASCIIToUTF16("random1234"); | 2295 field.name = ASCIIToUTF16("random1234"); |
2364 field.form_control_type = "text"; | 2296 field.form_control_type = "text"; |
2365 form.fields.push_back(field); | 2297 form.fields.push_back(field); |
2366 field.label = ASCIIToUTF16("Random Field label2"); | 2298 field.label = ASCIIToUTF16("Random Field label2"); |
2367 field.name = ASCIIToUTF16("random12345"); | 2299 field.name = ASCIIToUTF16("random12345"); |
2368 form.fields.push_back(field); | 2300 form.fields.push_back(field); |
2369 field.label = ASCIIToUTF16("Random Field label3"); | 2301 field.label = ASCIIToUTF16("Random Field label3"); |
2370 field.name = ASCIIToUTF16("1random12345678"); | 2302 field.name = ASCIIToUTF16("1random12345678"); |
2371 form.fields.push_back(field); | 2303 form.fields.push_back(field); |
2372 field.label = ASCIIToUTF16("Random Field label3"); | 2304 field.label = ASCIIToUTF16("Random Field label3"); |
2373 field.name = ASCIIToUTF16("12345random"); | 2305 field.name = ASCIIToUTF16("12345random"); |
2374 form.fields.push_back(field); | 2306 form.fields.push_back(field); |
2375 form_structure.reset(new FormStructure(form, std::string())); | 2307 form_structure.reset(new FormStructure(form)); |
2376 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2308 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2377 std::string("https://login.facebook.com&login_form&email&first&" | 2309 std::string("https://login.facebook.com&login_form&email&first&" |
2378 "random1234&random&1random&random")), | 2310 "random1234&random&1random&random")), |
2379 form_structure->FormSignature()); | 2311 form_structure->FormSignature()); |
2380 | 2312 |
2381 } | 2313 } |
2382 | 2314 |
2383 TEST(FormStructureTest, ToFormData) { | 2315 TEST(FormStructureTest, ToFormData) { |
2384 FormData form; | 2316 FormData form; |
2385 form.name = ASCIIToUTF16("the-name"); | 2317 form.name = ASCIIToUTF16("the-name"); |
(...skipping 10 matching lines...) Expand all Loading... |
2396 field.label = ASCIIToUTF16("password"); | 2328 field.label = ASCIIToUTF16("password"); |
2397 field.name = ASCIIToUTF16("password"); | 2329 field.name = ASCIIToUTF16("password"); |
2398 field.form_control_type = "password"; | 2330 field.form_control_type = "password"; |
2399 form.fields.push_back(field); | 2331 form.fields.push_back(field); |
2400 | 2332 |
2401 field.label = base::string16(); | 2333 field.label = base::string16(); |
2402 field.name = ASCIIToUTF16("Submit"); | 2334 field.name = ASCIIToUTF16("Submit"); |
2403 field.form_control_type = "submit"; | 2335 field.form_control_type = "submit"; |
2404 form.fields.push_back(field); | 2336 form.fields.push_back(field); |
2405 | 2337 |
2406 EXPECT_EQ(form, FormStructure(form, std::string()).ToFormData()); | 2338 EXPECT_EQ(form, FormStructure(form).ToFormData()); |
2407 | 2339 |
2408 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2340 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
2409 // false. This forces a future author that changes this to update this test. | 2341 // false. This forces a future author that changes this to update this test. |
2410 form.user_submitted = true; | 2342 form.user_submitted = true; |
2411 EXPECT_NE(form, FormStructure(form, std::string()).ToFormData()); | 2343 EXPECT_NE(form, FormStructure(form).ToFormData()); |
2412 } | 2344 } |
2413 | 2345 |
2414 TEST(FormStructureTest, SkipFieldTest) { | 2346 TEST(FormStructureTest, SkipFieldTest) { |
2415 FormData form; | 2347 FormData form; |
2416 form.name = ASCIIToUTF16("the-name"); | 2348 form.name = ASCIIToUTF16("the-name"); |
2417 form.method = ASCIIToUTF16("POST"); | 2349 form.method = ASCIIToUTF16("POST"); |
2418 form.origin = GURL("http://cool.com"); | 2350 form.origin = GURL("http://cool.com"); |
2419 form.action = form.origin.Resolve("/login"); | 2351 form.action = form.origin.Resolve("/login"); |
2420 | 2352 |
2421 FormFieldData field; | 2353 FormFieldData field; |
2422 field.label = ASCIIToUTF16("username"); | 2354 field.label = ASCIIToUTF16("username"); |
2423 field.name = ASCIIToUTF16("username"); | 2355 field.name = ASCIIToUTF16("username"); |
2424 field.form_control_type = "text"; | 2356 field.form_control_type = "text"; |
2425 form.fields.push_back(field); | 2357 form.fields.push_back(field); |
2426 | 2358 |
2427 field.label = ASCIIToUTF16("password"); | 2359 field.label = ASCIIToUTF16("password"); |
2428 field.name = ASCIIToUTF16("password"); | 2360 field.name = ASCIIToUTF16("password"); |
2429 field.form_control_type = "password"; | 2361 field.form_control_type = "password"; |
2430 form.fields.push_back(field); | 2362 form.fields.push_back(field); |
2431 | 2363 |
2432 field.label = base::string16(); | 2364 field.label = base::string16(); |
2433 field.name = ASCIIToUTF16("email"); | 2365 field.name = ASCIIToUTF16("email"); |
2434 field.form_control_type = "text"; | 2366 field.form_control_type = "text"; |
2435 form.fields.push_back(field); | 2367 form.fields.push_back(field); |
2436 | 2368 |
2437 ScopedVector<FormStructure> forms; | 2369 ScopedVector<FormStructure> forms; |
2438 forms.push_back(new FormStructure(form, std::string())); | 2370 forms.push_back(new FormStructure(form)); |
2439 std::vector<std::string> encoded_signatures; | 2371 std::vector<std::string> encoded_signatures; |
2440 std::string encoded_xml; | 2372 std::string encoded_xml; |
2441 | 2373 |
2442 const char * const kSignature = "18006745212084723782"; | 2374 const char * const kSignature = "18006745212084723782"; |
2443 const char * const kResponse = | 2375 const char * const kResponse = |
2444 "<\?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | 2376 "<\?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " |
2445 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 2377 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
2446 "signature=\"18006745212084723782\"><field signature=\"239111655\"/>" | 2378 "signature=\"18006745212084723782\"><field signature=\"239111655\"/>" |
2447 "<field signature=\"420638584\"/></form></autofillquery>"; | 2379 "<field signature=\"420638584\"/></form></autofillquery>"; |
2448 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 2380 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
2449 &encoded_signatures, | 2381 &encoded_signatures, |
2450 &encoded_xml)); | 2382 &encoded_xml)); |
2451 ASSERT_EQ(1U, encoded_signatures.size()); | 2383 ASSERT_EQ(1U, encoded_signatures.size()); |
2452 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2384 EXPECT_EQ(kSignature, encoded_signatures[0]); |
2453 EXPECT_EQ(kResponse, encoded_xml); | 2385 EXPECT_EQ(kResponse, encoded_xml); |
2454 | |
2455 AutocheckoutPageMetaData page_meta_data; | |
2456 const char * const kServerResponse = | |
2457 "<autofillqueryresponse><field autofilltype=\"3\" />" | |
2458 "<field autofilltype=\"9\" /></autofillqueryresponse>"; | |
2459 FormStructure::ParseQueryResponse(kServerResponse, forms.get(), | |
2460 &page_meta_data, TestAutofillMetrics()); | |
2461 ASSERT_EQ(NAME_FIRST, forms[0]->field(0)->server_type()); | |
2462 ASSERT_EQ(NO_SERVER_DATA, forms[0]->field(1)->server_type()); | |
2463 ASSERT_EQ(EMAIL_ADDRESS, forms[0]->field(2)->server_type()); | |
2464 } | 2386 } |
2465 | 2387 |
2466 } // namespace autofill | 2388 } // namespace autofill |
OLD | NEW |