| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/autofill/autofill_common_test.h" | |
| 6 | |
| 7 #include "base/prefs/pref_service.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/autofill/autofill_profile.h" | |
| 10 #include "chrome/browser/autofill/credit_card.h" | |
| 11 #include "chrome/browser/password_manager/encryptor.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "components/autofill/common/autofill_pref_names.h" | |
| 14 #include "components/autofill/common/form_field_data.h" | |
| 15 #include "components/user_prefs/user_prefs.h" | |
| 16 | |
| 17 namespace autofill_test { | |
| 18 | |
| 19 void CreateTestFormField(const char* label, | |
| 20 const char* name, | |
| 21 const char* value, | |
| 22 const char* type, | |
| 23 FormFieldData* field) { | |
| 24 field->label = ASCIIToUTF16(label); | |
| 25 field->name = ASCIIToUTF16(name); | |
| 26 field->value = ASCIIToUTF16(value); | |
| 27 field->form_control_type = type; | |
| 28 } | |
| 29 | |
| 30 inline void check_and_set( | |
| 31 FormGroup* profile, AutofillFieldType type, const char* value) { | |
| 32 if (value) | |
| 33 profile->SetRawInfo(type, UTF8ToUTF16(value)); | |
| 34 } | |
| 35 | |
| 36 void SetProfileInfo(AutofillProfile* profile, | |
| 37 const char* first_name, const char* middle_name, | |
| 38 const char* last_name, const char* email, const char* company, | |
| 39 const char* address1, const char* address2, const char* city, | |
| 40 const char* state, const char* zipcode, const char* country, | |
| 41 const char* phone) { | |
| 42 check_and_set(profile, NAME_FIRST, first_name); | |
| 43 check_and_set(profile, NAME_MIDDLE, middle_name); | |
| 44 check_and_set(profile, NAME_LAST, last_name); | |
| 45 check_and_set(profile, EMAIL_ADDRESS, email); | |
| 46 check_and_set(profile, COMPANY_NAME, company); | |
| 47 check_and_set(profile, ADDRESS_HOME_LINE1, address1); | |
| 48 check_and_set(profile, ADDRESS_HOME_LINE2, address2); | |
| 49 check_and_set(profile, ADDRESS_HOME_CITY, city); | |
| 50 check_and_set(profile, ADDRESS_HOME_STATE, state); | |
| 51 check_and_set(profile, ADDRESS_HOME_ZIP, zipcode); | |
| 52 check_and_set(profile, ADDRESS_HOME_COUNTRY, country); | |
| 53 check_and_set(profile, PHONE_HOME_WHOLE_NUMBER, phone); | |
| 54 } | |
| 55 | |
| 56 void SetProfileInfoWithGuid(AutofillProfile* profile, | |
| 57 const char* guid, const char* first_name, const char* middle_name, | |
| 58 const char* last_name, const char* email, const char* company, | |
| 59 const char* address1, const char* address2, const char* city, | |
| 60 const char* state, const char* zipcode, const char* country, | |
| 61 const char* phone) { | |
| 62 if (guid) | |
| 63 profile->set_guid(guid); | |
| 64 SetProfileInfo(profile, first_name, middle_name, last_name, email, | |
| 65 company, address1, address2, city, state, zipcode, country, | |
| 66 phone); | |
| 67 } | |
| 68 | |
| 69 void SetCreditCardInfo(CreditCard* credit_card, | |
| 70 const char* name_on_card, const char* card_number, | |
| 71 const char* expiration_month, const char* expiration_year) { | |
| 72 check_and_set(credit_card, CREDIT_CARD_NAME, name_on_card); | |
| 73 check_and_set(credit_card, CREDIT_CARD_NUMBER, card_number); | |
| 74 check_and_set(credit_card, CREDIT_CARD_EXP_MONTH, expiration_month); | |
| 75 check_and_set(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, expiration_year); | |
| 76 } | |
| 77 | |
| 78 void DisableSystemServices(Profile* profile) { | |
| 79 // Use a mock Keychain rather than the OS one to store credit card data. | |
| 80 #if defined(OS_MACOSX) | |
| 81 Encryptor::UseMockKeychain(true); | |
| 82 #endif | |
| 83 | |
| 84 // Disable auxiliary profiles for unit testing. These reach out to system | |
| 85 // services on the Mac. | |
| 86 if (profile) { | |
| 87 components::UserPrefs::Get(profile)->SetBoolean( | |
| 88 prefs::kAutofillAuxiliaryProfilesEnabled, false); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 } // namespace autofill_test | |
| OLD | NEW |