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