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

Side by Side Diff: chrome/browser/autofill/autofill_common_test.cc

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(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/guid.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autofill/autofill_profile.h"
11 #include "chrome/browser/autofill/credit_card.h"
12 #include "chrome/browser/password_manager/encryptor.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "components/autofill/common/autofill_pref_names.h"
15 #include "components/autofill/common/form_field_data.h"
16 #include "components/user_prefs/user_prefs.h"
17
18 namespace autofill_test {
19
20 void CreateTestFormField(const char* label,
21 const char* name,
22 const char* value,
23 const char* type,
24 FormFieldData* field) {
25 field->label = ASCIIToUTF16(label);
26 field->name = ASCIIToUTF16(name);
27 field->value = ASCIIToUTF16(value);
28 field->form_control_type = type;
29 }
30
31 inline void check_and_set(
32 FormGroup* profile, AutofillFieldType type, const char* value) {
33 if (value)
34 profile->SetRawInfo(type, UTF8ToUTF16(value));
35 }
36
37 AutofillProfile GetFullProfile() {
38 AutofillProfile profile(base::GenerateGUID());
39 SetProfileInfo(&profile,
40 "John",
41 "H.",
42 "Doe",
43 "johndoe@hades.com",
44 "Underworld",
45 "666 Erebus St.",
46 "Apt 8",
47 "Elysium", "CA",
48 "91111",
49 "US",
50 "16502111111");
51 return profile;
52 }
53
54 void SetProfileInfo(AutofillProfile* profile,
55 const char* first_name, const char* middle_name,
56 const char* last_name, const char* email, const char* company,
57 const char* address1, const char* address2, const char* city,
58 const char* state, const char* zipcode, const char* country,
59 const char* phone) {
60 check_and_set(profile, NAME_FIRST, first_name);
61 check_and_set(profile, NAME_MIDDLE, middle_name);
62 check_and_set(profile, NAME_LAST, last_name);
63 check_and_set(profile, EMAIL_ADDRESS, email);
64 check_and_set(profile, COMPANY_NAME, company);
65 check_and_set(profile, ADDRESS_HOME_LINE1, address1);
66 check_and_set(profile, ADDRESS_HOME_LINE2, address2);
67 check_and_set(profile, ADDRESS_HOME_CITY, city);
68 check_and_set(profile, ADDRESS_HOME_STATE, state);
69 check_and_set(profile, ADDRESS_HOME_ZIP, zipcode);
70 check_and_set(profile, ADDRESS_HOME_COUNTRY, country);
71 check_and_set(profile, PHONE_HOME_WHOLE_NUMBER, phone);
72 }
73
74 void SetProfileInfoWithGuid(AutofillProfile* profile,
75 const char* guid, const char* first_name, const char* middle_name,
76 const char* last_name, const char* email, const char* company,
77 const char* address1, const char* address2, const char* city,
78 const char* state, const char* zipcode, const char* country,
79 const char* phone) {
80 if (guid)
81 profile->set_guid(guid);
82 SetProfileInfo(profile, first_name, middle_name, last_name, email,
83 company, address1, address2, city, state, zipcode, country,
84 phone);
85 }
86
87 void SetCreditCardInfo(CreditCard* credit_card,
88 const char* name_on_card, const char* card_number,
89 const char* expiration_month, const char* expiration_year) {
90 check_and_set(credit_card, CREDIT_CARD_NAME, name_on_card);
91 check_and_set(credit_card, CREDIT_CARD_NUMBER, card_number);
92 check_and_set(credit_card, CREDIT_CARD_EXP_MONTH, expiration_month);
93 check_and_set(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, expiration_year);
94 }
95
96 void DisableSystemServices(Profile* profile) {
97 // Use a mock Keychain rather than the OS one to store credit card data.
98 #if defined(OS_MACOSX)
99 Encryptor::UseMockKeychain(true);
100 #endif
101
102 // Disable auxiliary profiles for unit testing. These reach out to system
103 // services on the Mac.
104 if (profile) {
105 components::UserPrefs::Get(profile)->SetBoolean(
106 prefs::kAutofillAuxiliaryProfilesEnabled, false);
107 }
108 }
109
110 } // namespace autofill_test
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_common_test.h ('k') | chrome/browser/autofill/autofill_country.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698