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" | 10 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 form.fields.push_back(field); | 435 form.fields.push_back(field); |
436 | 436 |
437 form_structure.reset(new FormStructure(form, std::string())); | 437 form_structure.reset(new FormStructure(form, std::string())); |
438 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 438 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
439 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 439 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
440 | 440 |
441 // Expect the correct number of fields. | 441 // Expect the correct number of fields. |
442 ASSERT_EQ(3U, form_structure->field_count()); | 442 ASSERT_EQ(3U, form_structure->field_count()); |
443 ASSERT_EQ(3U, form_structure->autofill_count()); | 443 ASSERT_EQ(3U, form_structure->autofill_count()); |
444 | 444 |
445 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type()); | 445 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); |
446 EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type()); | 446 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); |
447 EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type()); | 447 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); |
| 448 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); |
| 449 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); |
| 450 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); |
448 } | 451 } |
449 | 452 |
450 // Verify that we can correctly process the 'autocomplete' attribute for phone | 453 // Verify that we can correctly process the 'autocomplete' attribute for phone |
451 // number types (especially phone prefixes and suffixes). | 454 // number types (especially phone prefixes and suffixes). |
452 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { | 455 TEST(FormStructureTest, HeuristicsAutocompleteAttributePhoneTypes) { |
453 scoped_ptr<FormStructure> form_structure; | 456 scoped_ptr<FormStructure> form_structure; |
454 FormData form; | 457 FormData form; |
455 form.method = ASCIIToUTF16("post"); | 458 form.method = ASCIIToUTF16("post"); |
456 | 459 |
457 FormFieldData field; | 460 FormFieldData field; |
(...skipping 15 matching lines...) Expand all Loading... |
473 form.fields.push_back(field); | 476 form.fields.push_back(field); |
474 | 477 |
475 form_structure.reset(new FormStructure(form, std::string())); | 478 form_structure.reset(new FormStructure(form, std::string())); |
476 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 479 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
477 EXPECT_TRUE(form_structure->IsAutofillable(true)); | 480 EXPECT_TRUE(form_structure->IsAutofillable(true)); |
478 | 481 |
479 // Expect the correct number of fields. | 482 // Expect the correct number of fields. |
480 ASSERT_EQ(3U, form_structure->field_count()); | 483 ASSERT_EQ(3U, form_structure->field_count()); |
481 EXPECT_EQ(3U, form_structure->autofill_count()); | 484 EXPECT_EQ(3U, form_structure->autofill_count()); |
482 | 485 |
483 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(0)->heuristic_type()); | 486 EXPECT_EQ(HTML_TYPE_TEL_LOCAL, form_structure->field(0)->html_type()); |
484 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); | 487 EXPECT_EQ(AutofillField::IGNORED, form_structure->field(0)->phone_part()); |
485 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(1)->heuristic_type()); | 488 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_PREFIX, form_structure->field(1)->html_type()); |
486 EXPECT_EQ(AutofillField::PHONE_PREFIX, | 489 EXPECT_EQ(AutofillField::PHONE_PREFIX, |
487 form_structure->field(1)->phone_part()); | 490 form_structure->field(1)->phone_part()); |
488 EXPECT_EQ(PHONE_HOME_NUMBER, form_structure->field(2)->heuristic_type()); | 491 EXPECT_EQ(HTML_TYPE_TEL_LOCAL_SUFFIX, form_structure->field(2)->html_type()); |
489 EXPECT_EQ(AutofillField::PHONE_SUFFIX, | 492 EXPECT_EQ(AutofillField::PHONE_SUFFIX, |
490 form_structure->field(2)->phone_part()); | 493 form_structure->field(2)->phone_part()); |
491 } | 494 } |
492 | 495 |
493 // If at least one field includes type hints in the 'autocomplete' attribute, we | 496 // If at least one field includes type hints in the 'autocomplete' attribute, we |
494 // should not try to apply any other heuristics. | 497 // should not try to apply any other heuristics. |
495 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { | 498 TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) { |
496 scoped_ptr<FormStructure> form_structure; | 499 scoped_ptr<FormStructure> form_structure; |
497 FormData form; | 500 FormData form; |
498 form.method = ASCIIToUTF16("post"); | 501 form.method = ASCIIToUTF16("post"); |
(...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 "<autofillqueryresponse><field autofilltype=\"3\" />" | 2457 "<autofillqueryresponse><field autofilltype=\"3\" />" |
2455 "<field autofilltype=\"9\" /></autofillqueryresponse>"; | 2458 "<field autofilltype=\"9\" /></autofillqueryresponse>"; |
2456 FormStructure::ParseQueryResponse(kServerResponse, forms.get(), | 2459 FormStructure::ParseQueryResponse(kServerResponse, forms.get(), |
2457 &page_meta_data, TestAutofillMetrics()); | 2460 &page_meta_data, TestAutofillMetrics()); |
2458 ASSERT_EQ(NAME_FIRST, forms[0]->field(0)->server_type()); | 2461 ASSERT_EQ(NAME_FIRST, forms[0]->field(0)->server_type()); |
2459 ASSERT_EQ(NO_SERVER_DATA, forms[0]->field(1)->server_type()); | 2462 ASSERT_EQ(NO_SERVER_DATA, forms[0]->field(1)->server_type()); |
2460 ASSERT_EQ(EMAIL_ADDRESS, forms[0]->field(2)->server_type()); | 2463 ASSERT_EQ(EMAIL_ADDRESS, forms[0]->field(2)->server_type()); |
2461 } | 2464 } |
2462 | 2465 |
2463 } // namespace autofill | 2466 } // namespace autofill |
OLD | NEW |