| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/autofill_common_test.h" | 10 #include "chrome/browser/autofill/autofill_common_test.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 EXPECT_EQ(string16(), summary0); | 32 EXPECT_EQ(string16(), summary0); |
| 33 | 33 |
| 34 // Case 0a/empty name and address, so the first two fields of the rest of the | 34 // Case 0a/empty name and address, so the first two fields of the rest of the |
| 35 // data is used: "Hollywood, CA" | 35 // data is used: "Hollywood, CA" |
| 36 AutoFillProfile profile00; | 36 AutoFillProfile profile00; |
| 37 autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", | 37 autofill_test::SetProfileInfo(&profile00, "Billing", "", "Mitchell", "", |
| 38 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", | 38 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
| 39 "12345678910", "01987654321"); | 39 "12345678910", "01987654321"); |
| 40 EXPECT_TRUE(UpdateProfileLabel(&profile00)); | 40 EXPECT_TRUE(UpdateProfileLabel(&profile00)); |
| 41 string16 summary00 = profile00.Label(); | 41 string16 summary00 = profile00.Label(); |
| 42 EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary00); | 42 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary00); |
| 43 | 43 |
| 44 // Case 1: "<address>" | 44 // Case 1: "<address>" |
| 45 AutoFillProfile profile1; | 45 AutoFillProfile profile1; |
| 46 autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", | 46 autofill_test::SetProfileInfo(&profile1, "Billing", "", "Mitchell", "", |
| 47 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 47 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 48 "91601", "US", "12345678910", "01987654321"); | 48 "91601", "US", "12345678910", "01987654321"); |
| 49 EXPECT_TRUE(UpdateProfileLabel(&profile1)); | 49 EXPECT_TRUE(UpdateProfileLabel(&profile1)); |
| 50 string16 summary1 = profile1.Label(); | 50 string16 summary1 = profile1.Label(); |
| 51 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary1); | 51 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary1); |
| 52 | 52 |
| 53 // Case 2: "<lastname>" | 53 // Case 2: "<lastname>" |
| 54 AutoFillProfile profile2; | 54 AutoFillProfile profile2; |
| 55 autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", | 55 autofill_test::SetProfileInfo(&profile2, "Billing", "", "Mitchell", |
| 56 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", | 56 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
| 57 "91601", "US", "12345678910", "01987654321"); | 57 "91601", "US", "12345678910", "01987654321"); |
| 58 EXPECT_TRUE(UpdateProfileLabel(&profile2)); | 58 EXPECT_TRUE(UpdateProfileLabel(&profile2)); |
| 59 string16 summary2 = profile2.Label(); | 59 string16 summary2 = profile2.Label(); |
| 60 // Summary does include full name which is empty if the first name is empty. | 60 // Summary does include full name which is empty if the first name is empty. |
| 61 EXPECT_EQ(string16(ASCIIToUTF16("Hollywood, CA")), summary2); | 61 EXPECT_EQ(ASCIIToUTF16("Hollywood, CA"), summary2); |
| 62 | 62 |
| 63 // Case 3: "<lastname>, <address>" | 63 // Case 3: "<lastname>, <address>" |
| 64 AutoFillProfile profile3; | 64 AutoFillProfile profile3; |
| 65 autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", | 65 autofill_test::SetProfileInfo(&profile3, "Billing", "", "Mitchell", |
| 66 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 66 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 67 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); | 67 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
| 68 EXPECT_TRUE(UpdateProfileLabel(&profile3)); | 68 EXPECT_TRUE(UpdateProfileLabel(&profile3)); |
| 69 string16 summary3 = profile3.Label(); | 69 string16 summary3 = profile3.Label(); |
| 70 EXPECT_EQ(string16(ASCIIToUTF16("123 Zoo St., Hollywood")), summary3); | 70 EXPECT_EQ(ASCIIToUTF16("123 Zoo St., Hollywood"), summary3); |
| 71 | 71 |
| 72 // Case 4: "<firstname>" | 72 // Case 4: "<firstname>" |
| 73 AutoFillProfile profile4; | 73 AutoFillProfile profile4; |
| 74 autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", | 74 autofill_test::SetProfileInfo(&profile4, "Billing", "Marion", "Mitchell", "", |
| 75 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", | 75 "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", "91601", "US", |
| 76 "12345678910", "01987654321"); | 76 "12345678910", "01987654321"); |
| 77 EXPECT_TRUE(UpdateProfileLabel(&profile4)); | 77 EXPECT_TRUE(UpdateProfileLabel(&profile4)); |
| 78 string16 summary4 = profile4.Label(); | 78 string16 summary4 = profile4.Label(); |
| 79 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, Hollywood")), summary4); | 79 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, Hollywood"), summary4); |
| 80 | 80 |
| 81 // Case 5: "<firstname>, <address>" | 81 // Case 5: "<firstname>, <address>" |
| 82 AutoFillProfile profile5; | 82 AutoFillProfile profile5; |
| 83 autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", | 83 autofill_test::SetProfileInfo(&profile5, "Billing", "Marion", "Mitchell", "", |
| 84 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 84 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 85 "91601", "US", "12345678910", "01987654321"); | 85 "91601", "US", "12345678910", "01987654321"); |
| 86 EXPECT_TRUE(UpdateProfileLabel(&profile5)); | 86 EXPECT_TRUE(UpdateProfileLabel(&profile5)); |
| 87 string16 summary5 = profile5.Label(); | 87 string16 summary5 = profile5.Label(); |
| 88 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell, 123 Zoo St.")), summary5); | 88 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell, 123 Zoo St."), summary5); |
| 89 | 89 |
| 90 // Case 6: "<firstname> <lastname>" | 90 // Case 6: "<firstname> <lastname>" |
| 91 AutoFillProfile profile6; | 91 AutoFillProfile profile6; |
| 92 autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", | 92 autofill_test::SetProfileInfo(&profile6, "Billing", "Marion", "Mitchell", |
| 93 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", | 93 "Morrison", "johnwayne@me.xyz", "Fox", "", "unit 5", "Hollywood", "CA", |
| 94 "91601", "US", "12345678910", "01987654321"); | 94 "91601", "US", "12345678910", "01987654321"); |
| 95 EXPECT_TRUE(UpdateProfileLabel(&profile6)); | 95 EXPECT_TRUE(UpdateProfileLabel(&profile6)); |
| 96 string16 summary6 = profile6.Label(); | 96 string16 summary6 = profile6.Label(); |
| 97 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood")), | 97 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, Hollywood"), |
| 98 summary6); | 98 summary6); |
| 99 | 99 |
| 100 // Case 7: "<firstname> <lastname>, <address>" | 100 // Case 7: "<firstname> <lastname>, <address>" |
| 101 AutoFillProfile profile7; | 101 AutoFillProfile profile7; |
| 102 autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", | 102 autofill_test::SetProfileInfo(&profile7, "Billing", "Marion", "Mitchell", |
| 103 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 103 "Morrison", "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 104 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); | 104 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
| 105 EXPECT_TRUE(UpdateProfileLabel(&profile7)); | 105 EXPECT_TRUE(UpdateProfileLabel(&profile7)); |
| 106 string16 summary7 = profile7.Label(); | 106 string16 summary7 = profile7.Label(); |
| 107 EXPECT_EQ(string16(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St.")), | 107 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison, 123 Zoo St."), |
| 108 summary7); | 108 summary7); |
| 109 | 109 |
| 110 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for | 110 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for |
| 111 // e-mail. | 111 // e-mail. |
| 112 AutoFillProfile profile7a; | 112 AutoFillProfile profile7a; |
| 113 autofill_test::SetProfileInfo(&profile7a, "Billing", "Marion", "Mitchell", | 113 autofill_test::SetProfileInfo(&profile7a, "Billing", "Marion", "Mitchell", |
| 114 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 114 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
| 115 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); | 115 "Hollywood", "CA", "91601", "US", "12345678910", "01987654321"); |
| 116 std::vector<AutoFillProfile*> profiles; | 116 std::vector<AutoFillProfile*> profiles; |
| 117 profiles.push_back(&profile7); | 117 profiles.push_back(&profile7); |
| 118 profiles.push_back(&profile7a); | 118 profiles.push_back(&profile7a); |
| 119 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 119 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 120 summary7 = profile7.Label(); | 120 summary7 = profile7.Label(); |
| 121 string16 summary7a = profile7a.Label(); | 121 string16 summary7a = profile7a.Label(); |
| 122 EXPECT_EQ(string16(ASCIIToUTF16( | 122 EXPECT_EQ(ASCIIToUTF16( |
| 123 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz")), summary7); | 123 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); |
| 124 EXPECT_EQ(string16(ASCIIToUTF16( | 124 EXPECT_EQ(ASCIIToUTF16( |
| 125 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz")), summary7a); | 125 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST(AutoFillProfileTest, AdjustInferredLabels) { | 128 TEST(AutoFillProfileTest, AdjustInferredLabels) { |
| 129 std::vector<AutoFillProfile*> profiles; | 129 std::vector<AutoFillProfile*> profiles; |
| 130 profiles.push_back(new AutoFillProfile); | 130 profiles.push_back(new AutoFillProfile); |
| 131 autofill_test::SetProfileInfo( | 131 autofill_test::SetProfileInfo( |
| 132 profiles[0], | 132 profiles[0], |
| 133 "", | 133 "", |
| 134 "John", | 134 "John", |
| 135 "", | 135 "", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 156 "", | 156 "", |
| 157 "Dis", "CA", | 157 "Dis", "CA", |
| 158 "91222", | 158 "91222", |
| 159 "US", | 159 "US", |
| 160 "12345678910", | 160 "12345678910", |
| 161 "01987654321"); | 161 "01987654321"); |
| 162 // As labels are empty they are adjusted the first time. | 162 // As labels are empty they are adjusted the first time. |
| 163 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 163 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 164 // No need to adjust them anymore. | 164 // No need to adjust them anymore. |
| 165 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 165 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 166 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St.")), | 166 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), |
| 167 profiles[0]->Label()); | 167 profiles[0]->Label()); |
| 168 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), | 168 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), |
| 169 profiles[1]->Label()); | 169 profiles[1]->Label()); |
| 170 | 170 |
| 171 profiles.push_back(new AutoFillProfile); | 171 profiles.push_back(new AutoFillProfile); |
| 172 autofill_test::SetProfileInfo( | 172 autofill_test::SetProfileInfo( |
| 173 profiles[2], | 173 profiles[2], |
| 174 "", | 174 "", |
| 175 "John", | 175 "John", |
| 176 "", | 176 "", |
| 177 "Doe", | 177 "Doe", |
| 178 "johndoe@tertium.com", | 178 "johndoe@tertium.com", |
| 179 "Underworld", | 179 "Underworld", |
| 180 "666 Erebus St.", | 180 "666 Erebus St.", |
| 181 "", | 181 "", |
| 182 "Elysium", "CA", | 182 "Elysium", "CA", |
| 183 "91111", | 183 "91111", |
| 184 "US", | 184 "US", |
| 185 "11111111111", | 185 "11111111111", |
| 186 "22222222222"); | 186 "22222222222"); |
| 187 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 187 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 188 | 188 |
| 189 // Profile 0 and 2 inferred label now includes an e-mail. | 189 // Profile 0 and 2 inferred label now includes an e-mail. |
| 190 EXPECT_EQ(string16( | 190 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), |
| 191 ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com")), | |
| 192 profiles[0]->Label()); | 191 profiles[0]->Label()); |
| 193 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), | 192 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), |
| 194 profiles[1]->Label()); | 193 profiles[1]->Label()); |
| 195 EXPECT_EQ(string16( | 194 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), |
| 196 ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com")), | |
| 197 profiles[2]->Label()); | 195 profiles[2]->Label()); |
| 198 | 196 |
| 199 delete profiles[2]; | 197 delete profiles[2]; |
| 200 profiles.pop_back(); | 198 profiles.pop_back(); |
| 201 | 199 |
| 202 profiles.push_back(new AutoFillProfile); | 200 profiles.push_back(new AutoFillProfile); |
| 203 autofill_test::SetProfileInfo( | 201 autofill_test::SetProfileInfo( |
| 204 profiles[2], | 202 profiles[2], |
| 205 "", | 203 "", |
| 206 "John", | 204 "John", |
| 207 "", | 205 "", |
| 208 "Doe", | 206 "Doe", |
| 209 "johndoe@hades.com", | 207 "johndoe@hades.com", |
| 210 "Underworld", | 208 "Underworld", |
| 211 "666 Erebus St.", | 209 "666 Erebus St.", |
| 212 "", | 210 "", |
| 213 "Elysium", "CA", | 211 "Elysium", "CA", |
| 214 "91111", | 212 "91111", |
| 215 "US", | 213 "US", |
| 216 "11111111111", | 214 "11111111111", |
| 217 "33333333333"); // Fax is different | 215 "33333333333"); // Fax is different |
| 218 | 216 |
| 219 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 217 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 220 | 218 |
| 221 // Profile 0 and 2 inferred label now includes a fax number. | 219 // Profile 0 and 2 inferred label now includes a fax number. |
| 222 EXPECT_EQ(string16(ASCIIToUTF16( | 220 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#22222222222"), |
| 223 "John Doe, 666 Erebus St., fax:#22222222222")), | |
| 224 profiles[0]->Label()); | 221 profiles[0]->Label()); |
| 225 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), | 222 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), |
| 226 profiles[1]->Label()); | 223 profiles[1]->Label()); |
| 227 EXPECT_EQ(string16(ASCIIToUTF16( | 224 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., fax:#33333333333"), |
| 228 "John Doe, 666 Erebus St., fax:#33333333333")), | |
| 229 profiles[2]->Label()); | 225 profiles[2]->Label()); |
| 230 | 226 |
| 231 profiles.push_back(new AutoFillProfile); | 227 profiles.push_back(new AutoFillProfile); |
| 232 autofill_test::SetProfileInfo( | 228 autofill_test::SetProfileInfo( |
| 233 profiles[3], | 229 profiles[3], |
| 234 "", | 230 "", |
| 235 "John", | 231 "John", |
| 236 "", | 232 "", |
| 237 "Doe", | 233 "Doe", |
| 238 "johndoe@hades.com", | 234 "johndoe@hades.com", |
| 239 "Underworld", | 235 "Underworld", |
| 240 "666 Erebus St.", | 236 "666 Erebus St.", |
| 241 "", | 237 "", |
| 242 "Elysium", "CA", | 238 "Elysium", "CA", |
| 243 "91111", | 239 "91111", |
| 244 "US", | 240 "US", |
| 245 "44444444444", // Phone is different for some. | 241 "44444444444", // Phone is different for some. |
| 246 "33333333333"); // Fax is different for some. | 242 "33333333333"); // Fax is different for some. |
| 247 | 243 |
| 248 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 244 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 249 | 245 |
| 250 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," | 246 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," |
| 251 " fax:#22222222222")), | 247 " fax:#22222222222"), |
| 252 profiles[0]->Label()); | 248 profiles[0]->Label()); |
| 253 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), | 249 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), |
| 254 profiles[1]->Label()); | 250 profiles[1]->Label()); |
| 255 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," | 251 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 11111111111," |
| 256 " fax:#33333333333")), | 252 " fax:#33333333333"), |
| 257 profiles[2]->Label()); | 253 profiles[2]->Label()); |
| 258 // This one differs from other ones by unique phone, so no need for extra | 254 // This one differs from other ones by unique phone, so no need for extra |
| 259 // information. | 255 // information. |
| 260 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., 44444444444")), | 256 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., 44444444444"), |
| 261 profiles[3]->Label()); | 257 profiles[3]->Label()); |
| 262 | 258 |
| 263 profiles.push_back(new AutoFillProfile); | 259 profiles.push_back(new AutoFillProfile); |
| 264 autofill_test::SetProfileInfo( | 260 autofill_test::SetProfileInfo( |
| 265 profiles[4], | 261 profiles[4], |
| 266 "", | 262 "", |
| 267 "John", | 263 "John", |
| 268 "", | 264 "", |
| 269 "Doe", | 265 "Doe", |
| 270 "johndoe@styx.com", // E-Mail is different for some. | 266 "johndoe@styx.com", // E-Mail is different for some. |
| 271 "Underworld", | 267 "Underworld", |
| 272 "666 Erebus St.", | 268 "666 Erebus St.", |
| 273 "", | 269 "", |
| 274 "Elysium", "CA", | 270 "Elysium", "CA", |
| 275 "91111", | 271 "91111", |
| 276 "US", | 272 "US", |
| 277 "44444444444", // Phone is different for some. | 273 "44444444444", // Phone is different for some. |
| 278 "33333333333"); // Fax is different for some. | 274 "33333333333"); // Fax is different for some. |
| 279 | 275 |
| 280 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 276 EXPECT_TRUE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 281 | 277 |
| 282 EXPECT_EQ(string16(ASCIIToUTF16( | 278 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," |
| 283 "John Doe, 666 Erebus St., johndoe@hades.com," | 279 " 11111111111, fax:#22222222222"), |
| 284 " 11111111111, fax:#22222222222")), | 280 profiles[0]->Label()); |
| 285 profiles[0]->Label()); | 281 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), |
| 286 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), | |
| 287 profiles[1]->Label()); | 282 profiles[1]->Label()); |
| 288 EXPECT_EQ(string16(ASCIIToUTF16( | 283 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," |
| 289 "John Doe, 666 Erebus St., johndoe@hades.com," | 284 " 11111111111, fax:#33333333333"), |
| 290 " 11111111111, fax:#33333333333")), | 285 profiles[2]->Label()); |
| 291 profiles[2]->Label()); | 286 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com," |
| 292 EXPECT_EQ(string16(ASCIIToUTF16( | 287 " 44444444444, fax:#33333333333"), |
| 293 "John Doe, 666 Erebus St., johndoe@hades.com," | 288 profiles[3]->Label()); |
| 294 " 44444444444, fax:#33333333333")), | |
| 295 profiles[3]->Label()); | |
| 296 // This one differs from other ones by unique e-mail, so no need for extra | 289 // This one differs from other ones by unique e-mail, so no need for extra |
| 297 // information. | 290 // information. |
| 298 EXPECT_EQ(string16(ASCIIToUTF16( | 291 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@styx.com"), |
| 299 "John Doe, 666 Erebus St., johndoe@styx.com")), | 292 profiles[4]->Label()); |
| 300 profiles[4]->Label()); | |
| 301 | 293 |
| 302 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); | 294 EXPECT_FALSE(AutoFillProfile::AdjustInferredLabels(&profiles)); |
| 303 | 295 |
| 304 // Clean up. | 296 // Clean up. |
| 305 STLDeleteContainerPointers(profiles.begin(), profiles.end()); | 297 STLDeleteContainerPointers(profiles.begin(), profiles.end()); |
| 306 } | 298 } |
| 307 | 299 |
| 308 TEST(AutoFillProfileTest, CreateInferredLabels) { | 300 TEST(AutoFillProfileTest, CreateInferredLabels) { |
| 309 std::vector<AutoFillProfile*> profiles; | 301 std::vector<AutoFillProfile*> profiles; |
| 310 profiles.push_back(new AutoFillProfile); | 302 profiles.push_back(new AutoFillProfile); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 334 "", | 326 "", |
| 335 "Dis", "CA", | 327 "Dis", "CA", |
| 336 "91222", | 328 "91222", |
| 337 "US", | 329 "US", |
| 338 "12345678910", | 330 "12345678910", |
| 339 "01987654321"); | 331 "01987654321"); |
| 340 std::vector<string16> labels; | 332 std::vector<string16> labels; |
| 341 // Two fields at least - no filter. | 333 // Two fields at least - no filter. |
| 342 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, UNKNOWN_TYPE, | 334 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, UNKNOWN_TYPE, |
| 343 NULL); | 335 NULL); |
| 344 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St.")), labels[0]); | 336 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); |
| 345 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore.")), labels[1]); | 337 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
| 346 | 338 |
| 347 // Three fields at least - no filter. | 339 // Three fields at least - no filter. |
| 348 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, UNKNOWN_TYPE, | 340 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, UNKNOWN_TYPE, |
| 349 NULL); | 341 NULL); |
| 350 EXPECT_EQ(string16(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium")), | 342 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), |
| 351 labels[0]); | 343 labels[0]); |
| 352 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis")), | 344 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), |
| 353 labels[1]); | 345 labels[1]); |
| 354 | 346 |
| 355 // Two fields at least - filter out the name. | 347 // Two fields at least - filter out the name. |
| 356 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, NAME_FULL, NULL); | 348 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, NAME_FULL, NULL); |
| 357 EXPECT_EQ(string16(ASCIIToUTF16("666 Erebus St., Elysium")), labels[0]); | 349 EXPECT_EQ(ASCIIToUTF16("666 Erebus St., Elysium"), labels[0]); |
| 358 EXPECT_EQ(string16(ASCIIToUTF16("123 Letha Shore., Dis")), labels[1]); | 350 EXPECT_EQ(ASCIIToUTF16("123 Letha Shore., Dis"), labels[1]); |
| 359 | 351 |
| 360 std::vector<AutoFillFieldType> suggested_fields; | 352 std::vector<AutoFillFieldType> suggested_fields; |
| 361 suggested_fields.push_back(ADDRESS_HOME_CITY); | 353 suggested_fields.push_back(ADDRESS_HOME_CITY); |
| 362 suggested_fields.push_back(ADDRESS_HOME_STATE); | 354 suggested_fields.push_back(ADDRESS_HOME_STATE); |
| 363 suggested_fields.push_back(ADDRESS_HOME_ZIP); | 355 suggested_fields.push_back(ADDRESS_HOME_ZIP); |
| 364 | 356 |
| 365 // Two fields at least, from suggested fields - no filter. | 357 // Two fields at least, from suggested fields - no filter. |
| 366 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, UNKNOWN_TYPE, | 358 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 2, UNKNOWN_TYPE, |
| 367 &suggested_fields); | 359 &suggested_fields); |
| 368 EXPECT_EQ(string16(ASCIIToUTF16("Elysium, CA")), labels[0]); | 360 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); |
| 369 EXPECT_EQ(string16(ASCIIToUTF16("Dis, CA")), labels[1]); | 361 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); |
| 370 | 362 |
| 371 // Three fields at least, from suggested fields - no filter. | 363 // Three fields at least, from suggested fields - no filter. |
| 372 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, UNKNOWN_TYPE, | 364 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, UNKNOWN_TYPE, |
| 373 &suggested_fields); | 365 &suggested_fields); |
| 374 EXPECT_EQ(string16(ASCIIToUTF16("Elysium, CA, 91111")), labels[0]); | 366 EXPECT_EQ(ASCIIToUTF16("Elysium, CA, 91111"), labels[0]); |
| 375 EXPECT_EQ(string16(ASCIIToUTF16("Dis, CA, 91222")), labels[1]); | 367 EXPECT_EQ(ASCIIToUTF16("Dis, CA, 91222"), labels[1]); |
| 376 | 368 |
| 377 // Three fields at least, from suggested fields - but filter reduces available | 369 // Three fields at least, from suggested fields - but filter reduces available |
| 378 // fields to two. | 370 // fields to two. |
| 379 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, | 371 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 3, |
| 380 ADDRESS_HOME_STATE, &suggested_fields); | 372 ADDRESS_HOME_STATE, &suggested_fields); |
| 381 EXPECT_EQ(string16(ASCIIToUTF16("Elysium, 91111")), labels[0]); | 373 EXPECT_EQ(ASCIIToUTF16("Elysium, 91111"), labels[0]); |
| 382 EXPECT_EQ(string16(ASCIIToUTF16("Dis, 91222")), labels[1]); | 374 EXPECT_EQ(ASCIIToUTF16("Dis, 91222"), labels[1]); |
| 383 | 375 |
| 384 suggested_fields.clear(); | 376 suggested_fields.clear(); |
| 385 // In our implementation we always display NAME_FULL for all NAME* fields... | 377 // In our implementation we always display NAME_FULL for all NAME* fields... |
| 386 suggested_fields.push_back(NAME_MIDDLE); | 378 suggested_fields.push_back(NAME_MIDDLE); |
| 387 // One field at least, from suggested fields - no filter. | 379 // One field at least, from suggested fields - no filter. |
| 388 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 1, UNKNOWN_TYPE, | 380 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 1, UNKNOWN_TYPE, |
| 389 &suggested_fields); | 381 &suggested_fields); |
| 390 EXPECT_EQ(string16(ASCIIToUTF16("John Doe")), labels[0]); | 382 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); |
| 391 EXPECT_EQ(string16(ASCIIToUTF16("Jane Doe")), labels[1]); | 383 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); |
| 392 | 384 |
| 393 // One field at least, from suggested fields - filter the same as suggested | 385 // One field at least, from suggested fields - filter the same as suggested |
| 394 // field. | 386 // field. |
| 395 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 1, NAME_MIDDLE, | 387 AutoFillProfile::CreateInferredLabels(&profiles, &labels, 1, NAME_MIDDLE, |
| 396 &suggested_fields); | 388 &suggested_fields); |
| 397 EXPECT_EQ(string16(ASCIIToUTF16("")), labels[0]); | 389 EXPECT_EQ(string16(), labels[0]); |
| 398 EXPECT_EQ(string16(ASCIIToUTF16("")), labels[1]); | 390 EXPECT_EQ(string16(), labels[1]); |
| 399 // Clean up. | 391 // Clean up. |
| 400 STLDeleteContainerPointers(profiles.begin(), profiles.end()); | 392 STLDeleteContainerPointers(profiles.begin(), profiles.end()); |
| 401 } | 393 } |
| 402 | 394 |
| 403 TEST(AutoFillProfileTest, IsSubsetOf) { | 395 TEST(AutoFillProfileTest, IsSubsetOf) { |
| 404 scoped_ptr<AutoFillProfile> a, b; | 396 scoped_ptr<AutoFillProfile> a, b; |
| 405 | 397 |
| 406 // |a| is a subset of |b|. | 398 // |a| is a subset of |b|. |
| 407 a.reset(new AutoFillProfile); | 399 a.reset(new AutoFillProfile); |
| 408 b.reset(new AutoFillProfile); | 400 b.reset(new AutoFillProfile); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 // Different values produce non-zero results. | 529 // Different values produce non-zero results. |
| 538 autofill_test::SetProfileInfo(&a, "label1", "Jimmy", NULL, NULL, NULL, | 530 autofill_test::SetProfileInfo(&a, "label1", "Jimmy", NULL, NULL, NULL, |
| 539 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 531 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 540 autofill_test::SetProfileInfo(&b, "label1", "Ringo", NULL, NULL, NULL, | 532 autofill_test::SetProfileInfo(&b, "label1", "Ringo", NULL, NULL, NULL, |
| 541 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 533 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 542 EXPECT_GT(0, a.Compare(b)); | 534 EXPECT_GT(0, a.Compare(b)); |
| 543 EXPECT_LT(0, b.Compare(a)); | 535 EXPECT_LT(0, b.Compare(a)); |
| 544 } | 536 } |
| 545 | 537 |
| 546 } // namespace | 538 } // namespace |
| OLD | NEW |