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

Side by Side Diff: components/autofill/core/browser/autofill_profile_unittest.cc

Issue 22009003: [Autofill] Distinguish between native field types and potentially HTML field types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/guid.h" 6 #include "base/guid.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_common_test.h" 13 #include "components/autofill/core/browser/autofill_common_test.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_type.h"
15 #include "components/autofill/core/common/form_field_data.h" 16 #include "components/autofill/core/common/form_field_data.h"
16 #include "grit/component_strings.h" 17 #include "grit/component_strings.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace autofill { 20 namespace autofill {
20 21
21 namespace { 22 namespace {
22 23
23 bool UpdateProfileLabel(AutofillProfile *profile) { 24 bool UpdateProfileLabel(AutofillProfile *profile) {
24 std::vector<AutofillProfile*> profiles; 25 std::vector<AutofillProfile*> profiles;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); 338 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]);
338 339
339 // Three fields at least - no filter. 340 // Three fields at least - no filter.
340 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 3, 341 AutofillProfile::CreateInferredLabels(&profiles.get(), NULL, UNKNOWN_TYPE, 3,
341 &labels); 342 &labels);
342 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), 343 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"),
343 labels[0]); 344 labels[0]);
344 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), 345 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"),
345 labels[1]); 346 labels[1]);
346 347
347 std::vector<AutofillFieldType> suggested_fields; 348 std::vector<ServerFieldType> suggested_fields;
348 suggested_fields.push_back(ADDRESS_HOME_CITY); 349 suggested_fields.push_back(ADDRESS_HOME_CITY);
349 suggested_fields.push_back(ADDRESS_HOME_STATE); 350 suggested_fields.push_back(ADDRESS_HOME_STATE);
350 suggested_fields.push_back(ADDRESS_HOME_ZIP); 351 suggested_fields.push_back(ADDRESS_HOME_ZIP);
351 352
352 // Two fields at least, from suggested fields - no filter. 353 // Two fields at least, from suggested fields - no filter.
353 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 354 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
354 UNKNOWN_TYPE, 2, &labels); 355 UNKNOWN_TYPE, 2, &labels);
355 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); 356 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]);
356 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); 357 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]);
357 358
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 "John", "", "Doe", "doe@example.com", "", 416 "John", "", "Doe", "doe@example.com", "",
416 "88 Nowhere Ave.", "", "", "", "", "", ""); 417 "88 Nowhere Ave.", "", "", "", "", "", "");
417 profiles.push_back( 418 profiles.push_back(
418 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 419 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
419 test::SetProfileInfo(profiles[1], 420 test::SetProfileInfo(profiles[1],
420 "Johnny", "K", "Doe", "doe@example.com", "", 421 "Johnny", "K", "Doe", "doe@example.com", "",
421 "88 Nowhere Ave.", "", "", "", "", "", ""); 422 "88 Nowhere Ave.", "", "", "", "", "", "");
422 423
423 // If the only name field in the suggested fields is the excluded field, we 424 // If the only name field in the suggested fields is the excluded field, we
424 // should not fall back to the full name as a distinguishing field. 425 // should not fall back to the full name as a distinguishing field.
425 std::vector<AutofillFieldType> suggested_fields; 426 std::vector<ServerFieldType> suggested_fields;
426 suggested_fields.push_back(NAME_LAST); 427 suggested_fields.push_back(NAME_LAST);
427 suggested_fields.push_back(ADDRESS_HOME_LINE1); 428 suggested_fields.push_back(ADDRESS_HOME_LINE1);
428 suggested_fields.push_back(EMAIL_ADDRESS); 429 suggested_fields.push_back(EMAIL_ADDRESS);
429 std::vector<base::string16> labels; 430 std::vector<base::string16> labels;
430 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 431 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
431 NAME_LAST, 1, &labels); 432 NAME_LAST, 1, &labels);
432 ASSERT_EQ(2U, labels.size()); 433 ASSERT_EQ(2U, labels.size());
433 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); 434 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]);
434 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); 435 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]);
435 436
(...skipping 15 matching lines...) Expand all
451 "John", "", "Doe", "doe@example.com", "", 452 "John", "", "Doe", "doe@example.com", "",
452 "88 Nowhere Ave.", "", "", "", "", "", ""); 453 "88 Nowhere Ave.", "", "", "", "", "", "");
453 profiles.push_back( 454 profiles.push_back(
454 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); 455 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/"));
455 test::SetProfileInfo(profiles[1], 456 test::SetProfileInfo(profiles[1],
456 "John", "", "Doe", "dojo@example.com", "", 457 "John", "", "Doe", "dojo@example.com", "",
457 "88 Nowhere Ave.", "", "", "", "", "", ""); 458 "88 Nowhere Ave.", "", "", "", "", "", "");
458 459
459 // If the only name field in the suggested fields is the excluded field, we 460 // If the only name field in the suggested fields is the excluded field, we
460 // should not fall back to the full name as a distinguishing field. 461 // should not fall back to the full name as a distinguishing field.
461 std::vector<AutofillFieldType> suggested_fields; 462 std::vector<ServerFieldType> suggested_fields;
462 suggested_fields.push_back(ADDRESS_HOME_LINE1); 463 suggested_fields.push_back(ADDRESS_HOME_LINE1);
463 suggested_fields.push_back(ADDRESS_BILLING_LINE1); 464 suggested_fields.push_back(ADDRESS_BILLING_LINE1);
464 suggested_fields.push_back(EMAIL_ADDRESS); 465 suggested_fields.push_back(EMAIL_ADDRESS);
465 std::vector<base::string16> labels; 466 std::vector<base::string16> labels;
466 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields, 467 AutofillProfile::CreateInferredLabels(&profiles.get(), &suggested_fields,
467 UNKNOWN_TYPE, 2, &labels); 468 UNKNOWN_TYPE, 2, &labels);
468 ASSERT_EQ(2U, labels.size()); 469 ASSERT_EQ(2U, labels.size());
469 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); 470 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]);
470 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); 471 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]);
471 } 472 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 options[i] = ASCIIToUTF16(kCountries[i]); 781 options[i] = ASCIIToUTF16(kCountries[i]);
781 } 782 }
782 783
783 FormFieldData field; 784 FormFieldData field;
784 field.form_control_type = "select-one"; 785 field.form_control_type = "select-one";
785 field.option_values = options; 786 field.option_values = options;
786 field.option_contents = options; 787 field.option_contents = options;
787 788
788 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 789 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
789 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); 790 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA"));
790 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); 791 profile.FillSelectControl(
792 AutofillType(ADDRESS_HOME_COUNTRY), "en-US", &field);
791 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); 793 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value);
792 } 794 }
793 795
794 TEST(AutofillProfileTest, AddressCountryAbbrev) { 796 TEST(AutofillProfileTest, AddressCountryAbbrev) {
795 const char* const kCountries[] = { 797 const char* const kCountries[] = {
796 "AL", "CA" 798 "AL", "CA"
797 }; 799 };
798 std::vector<base::string16> options(arraysize(kCountries)); 800 std::vector<base::string16> options(arraysize(kCountries));
799 for (size_t i = 0; i < arraysize(kCountries); ++i) { 801 for (size_t i = 0; i < arraysize(kCountries); ++i) {
800 options[i] = ASCIIToUTF16(kCountries[i]); 802 options[i] = ASCIIToUTF16(kCountries[i]);
801 } 803 }
802 804
803 FormFieldData field; 805 FormFieldData field;
804 field.form_control_type = "select-one"; 806 field.form_control_type = "select-one";
805 field.option_values = options; 807 field.option_values = options;
806 field.option_contents = options; 808 field.option_contents = options;
807 809
808 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 810 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
809 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); 811 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA"));
810 profile.FillSelectControl(ADDRESS_HOME_COUNTRY, "en-US", &field); 812 profile.FillSelectControl(
813 AutofillType(ADDRESS_HOME_COUNTRY), "en-US", &field);
811 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); 814 EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
812 } 815 }
813 816
814 TEST(AutofillProfileTest, AddressStateFull) { 817 TEST(AutofillProfileTest, AddressStateFull) {
815 const char* const kStates[] = { 818 const char* const kStates[] = {
816 "Alabama", "California" 819 "Alabama", "California"
817 }; 820 };
818 std::vector<base::string16> options(arraysize(kStates)); 821 std::vector<base::string16> options(arraysize(kStates));
819 for (size_t i = 0; i < arraysize(kStates); ++i) { 822 for (size_t i = 0; i < arraysize(kStates); ++i) {
820 options[i] = ASCIIToUTF16(kStates[i]); 823 options[i] = ASCIIToUTF16(kStates[i]);
821 } 824 }
822 825
823 FormFieldData field; 826 FormFieldData field;
824 field.form_control_type = "select-one"; 827 field.form_control_type = "select-one";
825 field.option_values = options; 828 field.option_values = options;
826 field.option_contents = options; 829 field.option_contents = options;
827 830
828 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 831 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
829 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); 832 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
830 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); 833 profile.FillSelectControl(AutofillType(ADDRESS_HOME_STATE), "en-US", &field);
831 EXPECT_EQ(ASCIIToUTF16("California"), field.value); 834 EXPECT_EQ(ASCIIToUTF16("California"), field.value);
832 } 835 }
833 836
834 TEST(AutofillProfileTest, AddressStateAbbrev) { 837 TEST(AutofillProfileTest, AddressStateAbbrev) {
835 const char* const kStates[] = { 838 const char* const kStates[] = {
836 "AL", "CA" 839 "AL", "CA"
837 }; 840 };
838 std::vector<base::string16> options(arraysize(kStates)); 841 std::vector<base::string16> options(arraysize(kStates));
839 for (size_t i = 0; i < arraysize(kStates); ++i) { 842 for (size_t i = 0; i < arraysize(kStates); ++i) {
840 options[i] = ASCIIToUTF16(kStates[i]); 843 options[i] = ASCIIToUTF16(kStates[i]);
841 } 844 }
842 845
843 FormFieldData field; 846 FormFieldData field;
844 field.form_control_type = "select-one"; 847 field.form_control_type = "select-one";
845 field.option_values = options; 848 field.option_values = options;
846 field.option_contents = options; 849 field.option_contents = options;
847 850
848 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 851 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
849 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); 852 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California"));
850 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); 853 profile.FillSelectControl(AutofillType(ADDRESS_HOME_STATE), "en-US", &field);
851 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); 854 EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
852 } 855 }
853 856
854 TEST(AutofillProfileTest, FillByValue) { 857 TEST(AutofillProfileTest, FillByValue) {
855 const char* const kStates[] = { 858 const char* const kStates[] = {
856 "Alabama", "California" 859 "Alabama", "California"
857 }; 860 };
858 std::vector<base::string16> values(arraysize(kStates)); 861 std::vector<base::string16> values(arraysize(kStates));
859 std::vector<base::string16> contents(arraysize(kStates)); 862 std::vector<base::string16> contents(arraysize(kStates));
860 for (unsigned int i = 0; i < arraysize(kStates); ++i) { 863 for (unsigned int i = 0; i < arraysize(kStates); ++i) {
861 values[i] = ASCIIToUTF16(kStates[i]); 864 values[i] = ASCIIToUTF16(kStates[i]);
862 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i)); 865 contents[i] = ASCIIToUTF16(base::StringPrintf("%u", i));
863 } 866 }
864 867
865 FormFieldData field; 868 FormFieldData field;
866 field.form_control_type = "select-one"; 869 field.form_control_type = "select-one";
867 field.option_values = values; 870 field.option_values = values;
868 field.option_contents = contents; 871 field.option_contents = contents;
869 872
870 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 873 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
871 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); 874 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California"));
872 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); 875 profile.FillSelectControl(AutofillType(ADDRESS_HOME_STATE), "en-US", &field);
873 EXPECT_EQ(ASCIIToUTF16("California"), field.value); 876 EXPECT_EQ(ASCIIToUTF16("California"), field.value);
874 } 877 }
875 878
876 TEST(AutofillProfileTest, FillByContents) { 879 TEST(AutofillProfileTest, FillByContents) {
877 const char* const kStates[] = { 880 const char* const kStates[] = {
878 "Alabama", "California" 881 "Alabama", "California"
879 }; 882 };
880 std::vector<base::string16> values(arraysize(kStates)); 883 std::vector<base::string16> values(arraysize(kStates));
881 std::vector<base::string16> contents(arraysize(kStates)); 884 std::vector<base::string16> contents(arraysize(kStates));
882 for (unsigned int i = 0; i < arraysize(kStates); ++i) { 885 for (unsigned int i = 0; i < arraysize(kStates); ++i) {
883 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1)); 886 values[i] = ASCIIToUTF16(base::StringPrintf("%u", i + 1));
884 contents[i] = ASCIIToUTF16(kStates[i]); 887 contents[i] = ASCIIToUTF16(kStates[i]);
885 } 888 }
886 889
887 FormFieldData field; 890 FormFieldData field;
888 field.form_control_type = "select-one"; 891 field.form_control_type = "select-one";
889 field.option_values = values; 892 field.option_values = values;
890 field.option_contents = contents; 893 field.option_contents = contents;
891 894
892 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 895 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
893 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); 896 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California"));
894 profile.FillSelectControl(ADDRESS_HOME_STATE, "en-US", &field); 897 profile.FillSelectControl(AutofillType(ADDRESS_HOME_STATE), "en-US", &field);
895 EXPECT_EQ(ASCIIToUTF16("2"), field.value); 898 EXPECT_EQ(ASCIIToUTF16("2"), field.value);
896 } 899 }
897 900
898 TEST(AutofillProfileTest, IsPresentButInvalid) { 901 TEST(AutofillProfileTest, IsPresentButInvalid) {
899 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 902 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
900 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE)); 903 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_STATE));
901 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); 904 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP));
902 EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); 905 EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER));
903 906
904 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 907 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
(...skipping 14 matching lines...) Expand all
919 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)); 922 EXPECT_FALSE(profile.IsPresentButInvalid(ADDRESS_HOME_ZIP));
920 923
921 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("310")); 924 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("310"));
922 EXPECT_TRUE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); 925 EXPECT_TRUE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER));
923 926
924 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("(310) 310-6000")); 927 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("(310) 310-6000"));
925 EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER)); 928 EXPECT_FALSE(profile.IsPresentButInvalid(PHONE_HOME_WHOLE_NUMBER));
926 } 929 }
927 930
928 } // namespace autofill 931 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_profile.cc ('k') | components/autofill/core/browser/autofill_server_field_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698