Index: chrome/browser/autofill/autofill_profile_unittest.cc |
=================================================================== |
--- chrome/browser/autofill/autofill_profile_unittest.cc (revision 63786) |
+++ chrome/browser/autofill/autofill_profile_unittest.cc (working copy) |
@@ -15,77 +15,114 @@ |
namespace { |
+bool UpdateProfileLabel(AutoFillProfile *profile) { |
+ std::vector<AutoFillProfile*> profiles; |
+ profiles.push_back(profile); |
+ return AutoFillProfile::AdjustInferredLabels(&profiles); |
+} |
+ |
// Tests different possibilities for summary string generation. |
// Based on existence of first name, last name, and address line 1. |
TEST(AutoFillProfileTest, PreviewSummaryString) { |
// Case 0/null: "" |
AutoFillProfile profile0(string16(), 0); |
- string16 summary0 = profile0.PreviewSummary(); |
+ // Empty profile - nothing to update. |
+ EXPECT_FALSE(UpdateProfileLabel(&profile0)); |
+ string16 summary0 = profile0.Label(); |
EXPECT_EQ(string16(), summary0); |
- // Case 0/empty: "" |
+ // Case 0a/empty name and address, so the first two fields of the rest of the |
+ // data is used: "Hollywood, CA" |
AutoFillProfile profile00(string16(), 0); |
autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", |
"johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
"12345678910", "01987654321"); |
- string16 summary00 = profile00.PreviewSummary(); |
- EXPECT_EQ(string16(), summary00); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile00)); |
+ string16 summary00 = profile00.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary00); |
// Case 1: "<address>" |
AutoFillProfile profile1(string16(), 0); |
autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", |
"johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
"91601", "US", "12345678910", "01987654321"); |
- string16 summary1 = profile1.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St.")), summary1); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile1)); |
+ string16 summary1 = profile1.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary1); |
// Case 2: "<lastname>" |
AutoFillProfile profile2(string16(), 0); |
autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", |
"Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
"91601", "US", "12345678910", "01987654321"); |
- string16 summary2 = profile2.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Morrison")), summary2); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile2)); |
+ string16 summary2 = profile2.Label(); |
+ // Summary does include full name which is empty if the first name is empty. |
+ EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary2); |
// Case 3: "<lastname>, <address>" |
AutoFillProfile profile3(string16(), 0); |
autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", |
"Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
"Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
- string16 summary3 = profile3.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Morrison, 123 Zoo St.")), summary3); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile3)); |
+ string16 summary3 = profile3.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary3); |
// Case 4: "<firstname>" |
AutoFillProfile profile4(string16(), 0); |
autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", |
"johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
"12345678910", "01987654321"); |
- string16 summary4 = profile4.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Marion")), summary4); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile4)); |
+ string16 summary4 = profile4.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, Hollywood")), summary4); |
// Case 5: "<firstname>, <address>" |
AutoFillProfile profile5(string16(), 0); |
autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", |
"johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
"91601", "US", "12345678910", "01987654321"); |
- string16 summary5 = profile5.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Marion, 123 Zoo St.")), summary5); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile5)); |
+ string16 summary5 = profile5.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, 123 Zoo St.")), summary5); |
// Case 6: "<firstname> <lastname>" |
AutoFillProfile profile6(string16(), 0); |
autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", |
"Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
"91601", "US", "12345678910", "01987654321"); |
- string16 summary6 = profile6.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison")), summary6); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile6)); |
+ string16 summary6 = profile6.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood")), |
+ summary6); |
// Case 7: "<firstname> <lastname>, <address>" |
AutoFillProfile profile7(string16(), 0); |
autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", |
"Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
"Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
- string16 summary7 = profile7.PreviewSummary(); |
- EXPECT_EQ(string16(ASCIIToUTF16("Marion Morrison, 123 Zoo St.")), summary7); |
+ EXPECT_TRUE(UpdateProfileLabel(&profile7)); |
+ string16 summary7 = profile7.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St.")), |
+ summary7); |
+ |
+ // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for |
+ // e-mail. |
+ AutoFillProfile profile7a(string16(), 0); |
+ autofill_test::SetProfileInfo(&profile7a, "Billing", "Marion", "Mitchell", |
+ "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
+ "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
+ std::vector<AutoFillProfile*> profiles; |
+ profiles.push_back(&profile7); |
+ profiles.push_back(&profile7a); |
+ EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
+ summary7 = profile7.Label(); |
+ string16 summary7a = profile7a.Label(); |
+ EXPECT_EQ(string16(ASCIIToUTF16( |
+ "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz")), summary7); |
+ EXPECT_EQ(string16(ASCIIToUTF16( |
+ "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz")), summary7a); |
} |
TEST(AutoFillProfileTest, AdjustInferredLabels) { |