Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 ASSERT_EQ(3U, form_structure->autofill_count()); | 444 ASSERT_EQ(3U, form_structure->autofill_count()); |
| 445 | 445 |
| 446 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); | 446 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); |
| 447 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); | 447 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); |
| 448 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); | 448 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); |
| 449 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | 449 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 450 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); | 450 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 451 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); | 451 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 // Verify that the heuristics are not run for non checkout synthetic forms. | |
|
Mathieu
2016/02/05 22:36:45
I would change synthetic -> formless everywhere.
sebsg
2016/02/09 01:13:57
Done.
| |
| 455 TEST_F(FormStructureTest, Heuristics_SyntheticNonCheckoutForm) { | |
| 456 scoped_ptr<FormStructure> form_structure; | |
| 457 FormData form; | |
| 458 | |
| 459 FormFieldData field; | |
| 460 field.form_control_type = "text"; | |
| 461 | |
| 462 field.label = ASCIIToUTF16("First Name:"); | |
| 463 field.name = ASCIIToUTF16("firstname"); | |
| 464 field.autocomplete_attribute = "given-name"; | |
| 465 form.fields.push_back(field); | |
| 466 | |
| 467 field.label = ASCIIToUTF16("Last Name:"); | |
| 468 field.name = ASCIIToUTF16("lastname"); | |
| 469 field.autocomplete_attribute = "family-name"; | |
| 470 form.fields.push_back(field); | |
| 471 | |
| 472 field.label = ASCIIToUTF16("Email:"); | |
| 473 field.name = ASCIIToUTF16("email"); | |
| 474 field.autocomplete_attribute = "email"; | |
| 475 form.fields.push_back(field); | |
| 476 | |
| 477 form_structure.reset(new FormStructure(form)); | |
| 478 form_structure->DetermineHeuristicTypes(); | |
| 479 EXPECT_TRUE(form_structure->IsAutofillable()); | |
| 480 | |
| 481 // Expect the correct number of fields. | |
| 482 ASSERT_EQ(3U, form_structure->field_count()); | |
| 483 ASSERT_EQ(3U, form_structure->autofill_count()); | |
| 484 | |
| 485 // The heuristic type should be good. | |
| 486 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); | |
| 487 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | |
| 488 | |
| 489 // Set the form as a synthetic non checkout form. | |
| 490 form.is_formless_checkout = false; | |
| 491 form.is_form_tag = false; | |
| 492 | |
| 493 form_structure.reset(new FormStructure(form)); | |
| 494 form_structure->DetermineHeuristicTypes(); | |
| 495 EXPECT_TRUE(form_structure->IsAutofillable()); | |
| 496 | |
| 497 // Expect the correct number of fields. | |
| 498 ASSERT_EQ(3U, form_structure->field_count()); | |
| 499 ASSERT_EQ(3U, form_structure->autofill_count()); | |
| 500 | |
| 501 // The heuristic type should be Unknown. | |
| 502 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); | |
| 503 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); | |
| 504 } | |
| 505 | |
| 454 // All fields share a common prefix which could confuse the heuristics. Test | 506 // All fields share a common prefix which could confuse the heuristics. Test |
| 455 // that the common prefix is stripped out before running heuristics. | 507 // that the common prefix is stripped out before running heuristics. |
| 456 TEST_F(FormStructureTest, StripCommonNamePrefix) { | 508 TEST_F(FormStructureTest, StripCommonNamePrefix) { |
| 457 FormData form; | 509 FormData form; |
| 458 FormFieldData field; | 510 FormFieldData field; |
| 459 field.form_control_type = "text"; | 511 field.form_control_type = "text"; |
| 460 | 512 |
| 461 field.label = ASCIIToUTF16("First Name"); | 513 field.label = ASCIIToUTF16("First Name"); |
| 462 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$firstname"); | 514 field.name = ASCIIToUTF16("ctl01$ctl00$ShippingAddressCreditPhone$firstname"); |
| 463 form.fields.push_back(field); | 515 form.fields.push_back(field); |
| (...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3441 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3493 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3442 EXPECT_EQ(ASCIIToUTF16("123456789"), prefix.as_string()); | 3494 EXPECT_EQ(ASCIIToUTF16("123456789"), prefix.as_string()); |
| 3443 | 3495 |
| 3444 // Empty vector. | 3496 // Empty vector. |
| 3445 strings.clear(); | 3497 strings.clear(); |
| 3446 prefix = FormStructure::FindLongestCommonPrefix(strings); | 3498 prefix = FormStructure::FindLongestCommonPrefix(strings); |
| 3447 EXPECT_EQ(ASCIIToUTF16(""), prefix.as_string()); | 3499 EXPECT_EQ(ASCIIToUTF16(""), prefix.as_string()); |
| 3448 } | 3500 } |
| 3449 | 3501 |
| 3450 } // namespace autofill | 3502 } // namespace autofill |
| OLD | NEW |