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

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

Issue 1623803002: [Autofill] Fix phone upload bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 10 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
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3191 } 3191 }
3192 3192
3193 // Tests that DeterminePossibleFieldTypesForUpload makes accurate matches. 3193 // Tests that DeterminePossibleFieldTypesForUpload makes accurate matches.
3194 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { 3194 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
3195 // Set up the test profiles. 3195 // Set up the test profiles.
3196 std::vector<AutofillProfile> profiles; 3196 std::vector<AutofillProfile> profiles;
3197 AutofillProfile profile; 3197 AutofillProfile profile;
3198 test::SetProfileInfo(&profile, "Elvis", "Aaron", "Presley", 3198 test::SetProfileInfo(&profile, "Elvis", "Aaron", "Presley",
3199 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.", 3199 "theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.",
3200 "Apt. 10", "Memphis", "Tennessee", "38116", "US", 3200 "Apt. 10", "Memphis", "Tennessee", "38116", "US",
3201 "12345678901"); 3201 "+1 (234) 567-8901");
3202 profile.set_guid("00000000-0000-0000-0000-000000000001"); 3202 profile.set_guid("00000000-0000-0000-0000-000000000001");
3203 profiles.push_back(profile); 3203 profiles.push_back(profile);
3204 test::SetProfileInfo(&profile, "Charles", "", "Holley", "buddy@gmail.com", 3204 test::SetProfileInfo(&profile, "Charles", "", "Holley", "buddy@gmail.com",
3205 "Decca", "123 Apple St.", "unit 6", "Lubbock", "Texas", 3205 "Decca", "123 Apple St.", "unit 6", "Lubbock", "Texas",
3206 "79401", "US", "23456789012"); 3206 "79401", "US", "5142821292");
3207 profile.set_guid("00000000-0000-0000-0000-000000000002"); 3207 profile.set_guid("00000000-0000-0000-0000-000000000002");
3208 profiles.push_back(profile); 3208 profiles.push_back(profile);
3209 test::SetProfileInfo(&profile, "Charles", "", "Baudelaire",
3210 "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare",
3211 "Apt. 10", "Paris", "Ile de France", "75008", "FR",
3212 "+33 2 49 19 70 70");
3213 profile.set_guid("00000000-0000-0000-0000-000000000001");
3214 profiles.push_back(profile);
3209 3215
3210 // Set up the test credit cards. 3216 // Set up the test credit cards.
3211 std::vector<CreditCard> credit_cards; 3217 std::vector<CreditCard> credit_cards;
3212 CreditCard credit_card; 3218 CreditCard credit_card;
3213 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", 3219 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456",
3214 "04", "2012"); 3220 "04", "2012");
3215 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 3221 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
3216 credit_cards.push_back(credit_card); 3222 credit_cards.push_back(credit_card);
3217 3223
3218 typedef struct { 3224 typedef struct {
3219 std::string input_value; // The value to input in the field. 3225 std::string input_value; // The value to input in the field.
3220 ServerFieldType field_type; // The expected field type to be determined. 3226 ServerFieldType field_type; // The expected field type to be determined.
3221 } TestCase; 3227 } TestCase;
3222 3228
3223 TestCase test_cases[] = { 3229 TestCase test_cases[] = {
3224 // Profile fields matches. 3230 // Profile fields matches.
3225 {"Elvis", NAME_FIRST}, 3231 {"Elvis", NAME_FIRST},
3226 {"Aaron", NAME_MIDDLE}, 3232 {"Aaron", NAME_MIDDLE},
3227 {"A", NAME_MIDDLE_INITIAL}, 3233 {"A", NAME_MIDDLE_INITIAL},
3228 {"Presley", NAME_LAST}, 3234 {"Presley", NAME_LAST},
3229 {"Elvis Aaron Presley", NAME_FULL}, 3235 {"Elvis Aaron Presley", NAME_FULL},
3230 {"theking@gmail.com", EMAIL_ADDRESS}, 3236 {"theking@gmail.com", EMAIL_ADDRESS},
3231 {"RCA", COMPANY_NAME}, 3237 {"RCA", COMPANY_NAME},
3232 {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1}, 3238 {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
3233 {"Apt. 10", ADDRESS_HOME_LINE2}, 3239 {"Apt. 10", ADDRESS_HOME_LINE2},
3234 {"Memphis", ADDRESS_HOME_CITY}, 3240 {"Memphis", ADDRESS_HOME_CITY},
3235 {"Tennessee", ADDRESS_HOME_STATE}, 3241 {"Tennessee", ADDRESS_HOME_STATE},
3236 {"38116", ADDRESS_HOME_ZIP}, 3242 {"38116", ADDRESS_HOME_ZIP},
3237 {"USA", ADDRESS_HOME_COUNTRY}, 3243 {"USA", ADDRESS_HOME_COUNTRY},
3238 {"United States", ADDRESS_HOME_COUNTRY}, 3244 {"United States", ADDRESS_HOME_COUNTRY},
3239 {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER}, 3245 {"12345678901", PHONE_HOME_WHOLE_NUMBER},
3240 {"2345678901", PHONE_HOME_CITY_AND_NUMBER}, 3246 {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER},
3241 {"1", PHONE_HOME_COUNTRY_CODE}, 3247 {"(234)567-8901", PHONE_HOME_CITY_AND_NUMBER},
3242 {"234", PHONE_HOME_CITY_CODE}, 3248 {"2345678901", PHONE_HOME_CITY_AND_NUMBER},
3243 {"5678901", PHONE_HOME_NUMBER}, 3249 {"1", PHONE_HOME_COUNTRY_CODE},
3244 {"567", PHONE_HOME_NUMBER}, 3250 {"234", PHONE_HOME_CITY_CODE},
3245 {"8901", PHONE_HOME_NUMBER}, 3251 {"5678901", PHONE_HOME_NUMBER},
3252 {"567", PHONE_HOME_NUMBER},
3253 {"8901", PHONE_HOME_NUMBER},
3246 3254
3247 // Make sure matches for a second profile work. 3255 // Test an european profile.
3248 {"Charles Holley", NAME_FULL}, 3256 {"Paris", ADDRESS_HOME_CITY},
3257 {"Ile de France", ADDRESS_HOME_STATE},
3258 {"75008", ADDRESS_HOME_ZIP},
3259 {"FR", ADDRESS_HOME_COUNTRY},
3260 {"France", ADDRESS_HOME_COUNTRY},
3261 {"33249197070", PHONE_HOME_WHOLE_NUMBER},
3262 {"+33 2 49 19 70 70", PHONE_HOME_WHOLE_NUMBER},
3263 {"2 49 19 70 70", PHONE_HOME_CITY_AND_NUMBER},
3264 {"249197070", PHONE_HOME_CITY_AND_NUMBER},
3265 {"33", PHONE_HOME_COUNTRY_CODE},
3266 {"2", PHONE_HOME_CITY_CODE},
3249 3267
3250 // Credit card fields matches. 3268 // Credit card fields matches.
3251 {"Elvis Presley", CREDIT_CARD_NAME}, 3269 {"Elvis Presley", CREDIT_CARD_NAME},
3252 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER}, 3270 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER},
3253 {"04", CREDIT_CARD_EXP_MONTH}, 3271 {"04", CREDIT_CARD_EXP_MONTH},
3254 {"April", CREDIT_CARD_EXP_MONTH}, 3272 {"April", CREDIT_CARD_EXP_MONTH},
3255 {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR}, 3273 {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR},
3256 {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR}, 3274 {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR},
3257 {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 3275 {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
3258 3276
3259 // Make sure whitespaces are trimmed properly. 3277 // Make sure whitespaces are trimmed properly.
3260 {"", EMPTY_TYPE}, 3278 {"", EMPTY_TYPE},
3261 {" ", EMPTY_TYPE}, 3279 {" ", EMPTY_TYPE},
3262 {" Elvis", NAME_FIRST}, 3280 {" Elvis", NAME_FIRST},
3263 {"Elvis ", NAME_FIRST}, 3281 {"Elvis ", NAME_FIRST},
3264 3282
3265 // Make sure fields that differ by case match. 3283 // Make sure fields that differ by case match.
3266 {"elvis ", NAME_FIRST}, 3284 {"elvis ", NAME_FIRST},
3267 {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY}, 3285 {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY},
3268 3286
3269 // Make sure fields that differ by punctuation match. 3287 // Make sure fields that differ by punctuation match.
3270 {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1}, 3288 {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1},
3271 {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1}, 3289 {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
3272 3290
3273 // Make sure unsupported variants do not match. 3291 // Special phone number case. A profile with no country code should only
3274 {"Elvis Aaron", UNKNOWN_TYPE}, 3292 // match PHONE_HOME_CITY_AND_NUMBER.
3275 {"Mr. Presley", UNKNOWN_TYPE}, 3293 {"5142821292", PHONE_HOME_CITY_AND_NUMBER},
3276 {"3734 Elvis Presley", UNKNOWN_TYPE}, 3294
3277 {"TN", UNKNOWN_TYPE}, 3295 // Make sure unsupported variants do not match.
3278 {"38116-1023", UNKNOWN_TYPE}, 3296 {"Elvis Aaron", UNKNOWN_TYPE},
3279 {"5", UNKNOWN_TYPE}, 3297 {"Mr. Presley", UNKNOWN_TYPE},
3280 {"56", UNKNOWN_TYPE}, 3298 {"3734 Elvis Presley", UNKNOWN_TYPE},
3281 {"901", UNKNOWN_TYPE}}; 3299 {"TN", UNKNOWN_TYPE},
3300 {"38116-1023", UNKNOWN_TYPE},
3301 {"5", UNKNOWN_TYPE},
3302 {"56", UNKNOWN_TYPE},
3303 {"901", UNKNOWN_TYPE}};
3282 3304
3283 for (TestCase test_case : test_cases) { 3305 for (TestCase test_case : test_cases) {
3284 FormData form; 3306 FormData form;
3285 form.name = ASCIIToUTF16("MyForm"); 3307 form.name = ASCIIToUTF16("MyForm");
3286 form.origin = GURL("http://myform.com/form.html"); 3308 form.origin = GURL("http://myform.com/form.html");
3287 form.action = GURL("http://myform.com/submit.html"); 3309 form.action = GURL("http://myform.com/submit.html");
3288 3310
3289 FormFieldData field; 3311 FormFieldData field;
3290 ServerFieldTypeSet types; 3312 ServerFieldTypeSet types;
3291 test::CreateTestFormField("", "1", "", "text", &field); 3313 test::CreateTestFormField("", "1", "", "text", &field);
3292 field.value = ASCIIToUTF16(test_case.input_value); 3314 field.value = ASCIIToUTF16(test_case.input_value);
3293 types.clear(); 3315 types.clear();
3294 types.insert(test_case.field_type); 3316 types.insert(test_case.field_type);
3295 form.fields.push_back(field); 3317 form.fields.push_back(field);
3296 3318
3297 FormStructure form_structure(form); 3319 FormStructure form_structure(form);
3298 3320
3299 AutofillManager::DeterminePossibleFieldTypesForUpload( 3321 AutofillManager::DeterminePossibleFieldTypesForUpload(
3300 profiles, credit_cards, "en-us", &form_structure); 3322 profiles, credit_cards, "en-us", &form_structure);
3301 3323
3302 ASSERT_EQ(1U, form_structure.field_count()); 3324 ASSERT_EQ(1U, form_structure.field_count());
3303 ServerFieldTypeSet possible_types = 3325 ServerFieldTypeSet possible_types =
3304 form_structure.field(0)->possible_types(); 3326 form_structure.field(0)->possible_types();
3327 EXPECT_EQ(1U, possible_types.size());
3328
3305 EXPECT_NE(possible_types.end(), possible_types.find(test_case.field_type)); 3329 EXPECT_NE(possible_types.end(), possible_types.find(test_case.field_type));
3306 } 3330 }
3307 } 3331 }
3308 3332
3309 // Tests that DeterminePossibleFieldTypesForUpload is called when a form is 3333 // Tests that DeterminePossibleFieldTypesForUpload is called when a form is
3310 // submitted. 3334 // submitted.
3311 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload_IsTriggered) { 3335 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload_IsTriggered) {
3312 FormData form; 3336 FormData form;
3313 form.name = ASCIIToUTF16("MyForm"); 3337 form.name = ASCIIToUTF16("MyForm");
3314 form.origin = GURL("http://myform.com/form.html"); 3338 form.origin = GURL("http://myform.com/form.html");
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
4213 FormsSeen(mixed_forms); 4237 FormsSeen(mixed_forms);
4214 4238
4215 // Suggestions should always be displayed. 4239 // Suggestions should always be displayed.
4216 for (const FormFieldData& field : mixed_form.fields) { 4240 for (const FormFieldData& field : mixed_form.fields) {
4217 GetAutofillSuggestions(mixed_form, field); 4241 GetAutofillSuggestions(mixed_form, field);
4218 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 4242 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4219 } 4243 }
4220 } 4244 }
4221 4245
4222 } // namespace autofill 4246 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698