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

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: Fixed metrics tests Created 4 years, 11 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
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 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 "12345678901");
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 3209
3210 // Set up the test credit cards. 3210 // Set up the test credit cards.
3211 std::vector<CreditCard> credit_cards; 3211 std::vector<CreditCard> credit_cards;
3212 CreditCard credit_card; 3212 CreditCard credit_card;
3213 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456", 3213 test::SetCreditCardInfo(&credit_card, "Elvis Presley", "4234-5678-9012-3456",
3214 "04", "2012"); 3214 "04", "2012");
3215 credit_card.set_guid("00000000-0000-0000-0000-000000000003"); 3215 credit_card.set_guid("00000000-0000-0000-0000-000000000003");
3216 credit_cards.push_back(credit_card); 3216 credit_cards.push_back(credit_card);
3217 3217
3218 typedef struct { 3218 typedef struct {
3219 std::string input_value; // The value to input in the field. 3219 std::string input_value; // The value to input in the field.
3220 ServerFieldType field_type; // The expected field type to be determined. 3220 ServerFieldType field_type; // The expected field type to be determined.
3221 } TestCase; 3221 } TestCase;
3222 3222
3223 TestCase test_cases[] = { 3223 TestCase test_cases[] = {
3224 // Profile fields matches. 3224 // Profile fields matches.
3225 {"Elvis", NAME_FIRST}, 3225 {"Elvis", NAME_FIRST},
3226 {"Aaron", NAME_MIDDLE}, 3226 {"Aaron", NAME_MIDDLE},
3227 {"A", NAME_MIDDLE_INITIAL}, 3227 {"A", NAME_MIDDLE_INITIAL},
3228 {"Presley", NAME_LAST}, 3228 {"Presley", NAME_LAST},
3229 {"Elvis Aaron Presley", NAME_FULL}, 3229 {"Elvis Aaron Presley", NAME_FULL},
3230 {"theking@gmail.com", EMAIL_ADDRESS}, 3230 {"theking@gmail.com", EMAIL_ADDRESS},
3231 {"RCA", COMPANY_NAME}, 3231 {"RCA", COMPANY_NAME},
3232 {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1}, 3232 {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
3233 {"Apt. 10", ADDRESS_HOME_LINE2}, 3233 {"Apt. 10", ADDRESS_HOME_LINE2},
3234 {"Memphis", ADDRESS_HOME_CITY}, 3234 {"Memphis", ADDRESS_HOME_CITY},
3235 {"Tennessee", ADDRESS_HOME_STATE}, 3235 {"Tennessee", ADDRESS_HOME_STATE},
3236 {"38116", ADDRESS_HOME_ZIP}, 3236 {"38116", ADDRESS_HOME_ZIP},
3237 {"USA", ADDRESS_HOME_COUNTRY}, 3237 {"USA", ADDRESS_HOME_COUNTRY},
3238 {"United States", ADDRESS_HOME_COUNTRY}, 3238 {"United States", ADDRESS_HOME_COUNTRY},
3239 {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER}, 3239 {"12345678901", PHONE_HOME_WHOLE_NUMBER},
3240 {"2345678901", PHONE_HOME_CITY_AND_NUMBER}, 3240 {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER},
3241 {"1", PHONE_HOME_COUNTRY_CODE}, 3241 {"(234)567-8901", PHONE_HOME_CITY_AND_NUMBER},
3242 {"234", PHONE_HOME_CITY_CODE}, 3242 {"2345678901", PHONE_HOME_CITY_AND_NUMBER},
3243 {"5678901", PHONE_HOME_NUMBER}, 3243 {"1", PHONE_HOME_COUNTRY_CODE},
3244 {"567", PHONE_HOME_NUMBER}, 3244 {"234", PHONE_HOME_CITY_CODE},
3245 {"8901", PHONE_HOME_NUMBER}, 3245 {"5678901", PHONE_HOME_NUMBER},
3246 {"567", PHONE_HOME_NUMBER},
3247 {"8901", PHONE_HOME_NUMBER},
3246 3248
3247 // Make sure matches for a second profile work. 3249 // Make sure matches for a second profile work.
3248 {"Charles Holley", NAME_FULL}, 3250 {"Charles Holley", NAME_FULL},
3249 3251
3250 // Credit card fields matches. 3252 // Credit card fields matches.
3251 {"Elvis Presley", CREDIT_CARD_NAME}, 3253 {"Elvis Presley", CREDIT_CARD_NAME},
3252 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER}, 3254 {"4234-5678-9012-3456", CREDIT_CARD_NUMBER},
3253 {"04", CREDIT_CARD_EXP_MONTH}, 3255 {"04", CREDIT_CARD_EXP_MONTH},
3254 {"April", CREDIT_CARD_EXP_MONTH}, 3256 {"April", CREDIT_CARD_EXP_MONTH},
3255 {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR}, 3257 {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR},
3256 {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR}, 3258 {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR},
3257 {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 3259 {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
3258 3260
3259 // Make sure whitespaces are trimmed properly. 3261 // Make sure whitespaces are trimmed properly.
3260 {"", EMPTY_TYPE}, 3262 {"", EMPTY_TYPE},
3261 {" ", EMPTY_TYPE}, 3263 {" ", EMPTY_TYPE},
3262 {" Elvis", NAME_FIRST}, 3264 {" Elvis", NAME_FIRST},
3263 {"Elvis ", NAME_FIRST}, 3265 {"Elvis ", NAME_FIRST},
3264 3266
3265 // Make sure fields that differ by case match. 3267 // Make sure fields that differ by case match.
3266 {"elvis ", NAME_FIRST}, 3268 {"elvis ", NAME_FIRST},
3267 {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY}, 3269 {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY},
3268 3270
3269 // Make sure fields that differ by punctuation match. 3271 // Make sure fields that differ by punctuation match.
3270 {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1}, 3272 {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1},
3271 {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1}, 3273 {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
3272 3274
3273 // Make sure unsupported variants do not match. 3275 // Special phone number case. A profile with no country code should only
3274 {"Elvis Aaron", UNKNOWN_TYPE}, 3276 // match PHONE_HOME_CITY_AND_NUMBER.
3275 {"Mr. Presley", UNKNOWN_TYPE}, 3277 {"5142821292", PHONE_HOME_CITY_AND_NUMBER},
3276 {"3734 Elvis Presley", UNKNOWN_TYPE}, 3278
3277 {"TN", UNKNOWN_TYPE}, 3279 // Make sure unsupported variants do not match.
3278 {"38116-1023", UNKNOWN_TYPE}, 3280 {"Elvis Aaron", UNKNOWN_TYPE},
3279 {"5", UNKNOWN_TYPE}, 3281 {"Mr. Presley", UNKNOWN_TYPE},
3280 {"56", UNKNOWN_TYPE}, 3282 {"3734 Elvis Presley", UNKNOWN_TYPE},
3281 {"901", UNKNOWN_TYPE}}; 3283 {"TN", UNKNOWN_TYPE},
3284 {"38116-1023", UNKNOWN_TYPE},
3285 {"5", UNKNOWN_TYPE},
3286 {"56", UNKNOWN_TYPE},
3287 {"901", UNKNOWN_TYPE}};
3282 3288
3283 for (TestCase test_case : test_cases) { 3289 for (TestCase test_case : test_cases) {
3284 FormData form; 3290 FormData form;
3285 form.name = ASCIIToUTF16("MyForm"); 3291 form.name = ASCIIToUTF16("MyForm");
3286 form.origin = GURL("http://myform.com/form.html"); 3292 form.origin = GURL("http://myform.com/form.html");
3287 form.action = GURL("http://myform.com/submit.html"); 3293 form.action = GURL("http://myform.com/submit.html");
3288 3294
3289 FormFieldData field; 3295 FormFieldData field;
3290 ServerFieldTypeSet types; 3296 ServerFieldTypeSet types;
3291 test::CreateTestFormField("", "1", "", "text", &field); 3297 test::CreateTestFormField("", "1", "", "text", &field);
3292 field.value = ASCIIToUTF16(test_case.input_value); 3298 field.value = ASCIIToUTF16(test_case.input_value);
3293 types.clear(); 3299 types.clear();
3294 types.insert(test_case.field_type); 3300 types.insert(test_case.field_type);
3295 form.fields.push_back(field); 3301 form.fields.push_back(field);
3296 3302
3297 FormStructure form_structure(form); 3303 FormStructure form_structure(form);
3298 3304
3299 AutofillManager::DeterminePossibleFieldTypesForUpload( 3305 AutofillManager::DeterminePossibleFieldTypesForUpload(
3300 profiles, credit_cards, "en-us", &form_structure); 3306 profiles, credit_cards, "en-us", &form_structure);
3301 3307
3302 ASSERT_EQ(1U, form_structure.field_count()); 3308 ASSERT_EQ(1U, form_structure.field_count());
3303 ServerFieldTypeSet possible_types = 3309 ServerFieldTypeSet possible_types =
3304 form_structure.field(0)->possible_types(); 3310 form_structure.field(0)->possible_types();
3311 EXPECT_EQ(1U, possible_types.size());
3312
3305 EXPECT_NE(possible_types.end(), possible_types.find(test_case.field_type)); 3313 EXPECT_NE(possible_types.end(), possible_types.find(test_case.field_type));
3306 } 3314 }
3307 } 3315 }
3308 3316
3309 // Tests that DeterminePossibleFieldTypesForUpload is called when a form is 3317 // Tests that DeterminePossibleFieldTypesForUpload is called when a form is
3310 // submitted. 3318 // submitted.
3311 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload_IsTriggered) { 3319 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload_IsTriggered) {
3312 FormData form; 3320 FormData form;
3313 form.name = ASCIIToUTF16("MyForm"); 3321 form.name = ASCIIToUTF16("MyForm");
3314 form.origin = GURL("http://myform.com/form.html"); 3322 form.origin = GURL("http://myform.com/form.html");
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
4213 FormsSeen(mixed_forms); 4221 FormsSeen(mixed_forms);
4214 4222
4215 // Suggestions should always be displayed. 4223 // Suggestions should always be displayed.
4216 for (const FormFieldData& field : mixed_form.fields) { 4224 for (const FormFieldData& field : mixed_form.fields) {
4217 GetAutofillSuggestions(mixed_form, field); 4225 GetAutofillSuggestions(mixed_form, field);
4218 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 4226 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4219 } 4227 }
4220 } 4228 }
4221 4229
4222 } // namespace autofill 4230 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698