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

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

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 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 "components/autofill/browser/autofill_common_test.h"
6
7 #include "base/guid.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/autofill/browser/autofill_profile.h"
12 #include "components/autofill/browser/credit_card.h"
13 #include "components/autofill/core/common/autofill_pref_names.h"
14 #include "components/autofill/core/common/form_field_data.h"
15 #include "components/user_prefs/user_prefs.h"
16 #include "components/webdata/encryptor/encryptor.h"
17
18 namespace autofill {
19 namespace test {
20
21 namespace {
22
23 const char kSettingsOrigin[] = "Chrome settings";
24
25 } // namespace
26
27 void CreateTestFormField(const char* label,
28 const char* name,
29 const char* value,
30 const char* type,
31 FormFieldData* field) {
32 field->label = ASCIIToUTF16(label);
33 field->name = ASCIIToUTF16(name);
34 field->value = ASCIIToUTF16(value);
35 field->form_control_type = type;
36 }
37
38 inline void check_and_set(
39 FormGroup* profile, AutofillFieldType type, const char* value) {
40 if (value)
41 profile->SetRawInfo(type, UTF8ToUTF16(value));
42 }
43
44 AutofillProfile GetFullProfile() {
45 AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/");
46 SetProfileInfo(&profile,
47 "John",
48 "H.",
49 "Doe",
50 "johndoe@hades.com",
51 "Underworld",
52 "666 Erebus St.",
53 "Apt 8",
54 "Elysium", "CA",
55 "91111",
56 "US",
57 "16502111111");
58 return profile;
59 }
60
61 AutofillProfile GetFullProfile2() {
62 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/");
63 SetProfileInfo(&profile,
64 "Jane",
65 "A.",
66 "Smith",
67 "jsmith@example.com",
68 "ACME",
69 "123 Main Street",
70 "Unit 1",
71 "Greensdale", "MI",
72 "48838",
73 "US",
74 "13105557889");
75 return profile;
76 }
77
78 AutofillProfile GetVerifiedProfile() {
79 AutofillProfile profile(GetFullProfile());
80 profile.set_origin(kSettingsOrigin);
81 return profile;
82 }
83
84 AutofillProfile GetVerifiedProfile2() {
85 AutofillProfile profile(GetFullProfile2());
86 profile.set_origin(kSettingsOrigin);
87 return profile;
88 }
89
90 CreditCard GetCreditCard() {
91 CreditCard credit_card(base::GenerateGUID(), "http://www.example.com");
92 SetCreditCardInfo(
93 &credit_card, "Test User", "4111111111111111" /* Visa */, "11", "2017");
94 return credit_card;
95 }
96
97 CreditCard GetVerifiedCreditCard() {
98 CreditCard credit_card(GetCreditCard());
99 credit_card.set_origin(kSettingsOrigin);
100 return credit_card;
101 }
102
103 void SetProfileInfo(AutofillProfile* profile,
104 const char* first_name, const char* middle_name,
105 const char* last_name, const char* email, const char* company,
106 const char* address1, const char* address2, const char* city,
107 const char* state, const char* zipcode, const char* country,
108 const char* phone) {
109 check_and_set(profile, NAME_FIRST, first_name);
110 check_and_set(profile, NAME_MIDDLE, middle_name);
111 check_and_set(profile, NAME_LAST, last_name);
112 check_and_set(profile, EMAIL_ADDRESS, email);
113 check_and_set(profile, COMPANY_NAME, company);
114 check_and_set(profile, ADDRESS_HOME_LINE1, address1);
115 check_and_set(profile, ADDRESS_HOME_LINE2, address2);
116 check_and_set(profile, ADDRESS_HOME_CITY, city);
117 check_and_set(profile, ADDRESS_HOME_STATE, state);
118 check_and_set(profile, ADDRESS_HOME_ZIP, zipcode);
119 check_and_set(profile, ADDRESS_HOME_COUNTRY, country);
120 check_and_set(profile, PHONE_HOME_WHOLE_NUMBER, phone);
121 }
122
123 void SetProfileInfoWithGuid(AutofillProfile* profile,
124 const char* guid, const char* first_name, const char* middle_name,
125 const char* last_name, const char* email, const char* company,
126 const char* address1, const char* address2, const char* city,
127 const char* state, const char* zipcode, const char* country,
128 const char* phone) {
129 if (guid)
130 profile->set_guid(guid);
131 SetProfileInfo(profile, first_name, middle_name, last_name, email,
132 company, address1, address2, city, state, zipcode, country,
133 phone);
134 }
135
136 void SetCreditCardInfo(CreditCard* credit_card,
137 const char* name_on_card, const char* card_number,
138 const char* expiration_month, const char* expiration_year) {
139 check_and_set(credit_card, CREDIT_CARD_NAME, name_on_card);
140 check_and_set(credit_card, CREDIT_CARD_NUMBER, card_number);
141 check_and_set(credit_card, CREDIT_CARD_EXP_MONTH, expiration_month);
142 check_and_set(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, expiration_year);
143 }
144
145 void DisableSystemServices(Profile* profile) {
146 // Use a mock Keychain rather than the OS one to store credit card data.
147 #if defined(OS_MACOSX)
148 Encryptor::UseMockKeychain(true);
149 #endif
150
151 // Disable auxiliary profiles for unit testing. These reach out to system
152 // services on the Mac.
153 if (profile) {
154 user_prefs::UserPrefs::Get(profile)->SetBoolean(
155 prefs::kAutofillAuxiliaryProfilesEnabled, false);
156 }
157 }
158
159 } // namespace test
160 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_common_test.h ('k') | components/autofill/browser/autofill_country.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698