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
3 // found in the LICENSE file.
5 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
10 #include "base/strings/string16.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "components/autofill/content/browser/wallet/full_wallet.h"
15 #include "components/autofill/content/browser/wallet/gaia_account.h"
16 #include "components/autofill/content/browser/wallet/instrument.h"
17 #include "components/autofill/content/browser/wallet/required_action.h"
18 #include "components/autofill/content/browser/wallet/wallet_address.h"
20 using base::ASCIIToUTF16
;
28 // "In the Year 3000." - Richie "LaBamba" Rosenberg
34 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrumentWithDetails(
35 const std::string
& id
,
36 scoped_ptr
<Address
> address
,
37 WalletItems::MaskedInstrument::Type type
,
38 WalletItems::MaskedInstrument::Status status
) {
39 return make_scoped_ptr(
40 new WalletItems::MaskedInstrument(ASCIIToUTF16("descriptive_name"),
50 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrumentWithId(
51 const std::string
& id
) {
52 return GetTestMaskedInstrumentWithDetails(
55 WalletItems::MaskedInstrument::VISA
,
56 WalletItems::MaskedInstrument::VALID
);
59 scoped_ptr
<WalletItems::MaskedInstrument
>
60 GetTestMaskedInstrumentWithIdAndAddress(
61 const std::string
& id
, scoped_ptr
<Address
> address
) {
62 return GetTestMaskedInstrumentWithDetails(
65 WalletItems::MaskedInstrument::VISA
,
66 WalletItems::MaskedInstrument::VALID
);
69 scoped_ptr
<GaiaAccount
> GetTestGaiaAccount() {
70 return GaiaAccount::CreateForTesting("user@chromium.org",
76 std::vector
<base::string16
> StreetAddress(const std::string
& line1
,
77 const std::string
& line2
) {
78 std::vector
<base::string16
> street_address
;
79 street_address
.push_back(ASCIIToUTF16(line1
));
80 street_address
.push_back(ASCIIToUTF16(line2
));
81 return street_address
;
84 scoped_ptr
<Address
> GetTestAddress() {
85 return make_scoped_ptr(
87 ASCIIToUTF16("recipient_name"),
88 StreetAddress("address_line_1", "address_line_2"),
89 ASCIIToUTF16("locality_name"),
90 ASCIIToUTF16("dependent_locality_name"),
91 ASCIIToUTF16("admin_area_name"),
92 ASCIIToUTF16("postal_code_number"),
93 ASCIIToUTF16("sorting_code"),
94 ASCIIToUTF16("phone_number"),
99 scoped_ptr
<Address
> GetTestMinimalAddress() {
100 scoped_ptr
<Address
> address
= GetTestAddress();
101 address
->set_is_complete_address(false);
102 return address
.Pass();
105 scoped_ptr
<FullWallet
> GetTestFullWallet() {
106 return GetTestFullWalletWithRequiredActions(std::vector
<RequiredAction
>());
109 scoped_ptr
<FullWallet
> GetTestFullWalletWithRequiredActions(
110 const std::vector
<RequiredAction
>& actions
) {
111 scoped_ptr
<FullWallet
> wallet(new FullWallet(FutureYear(),
116 GetTestShippingAddress(),
118 std::vector
<uint8
> one_time_pad
;
119 base::HexStringToBytes("5F04A8704183", &one_time_pad
);
120 wallet
->set_one_time_pad(one_time_pad
);
121 return wallet
.Pass();
124 scoped_ptr
<FullWallet
> GetTestFullWalletInstrumentOnly() {
125 scoped_ptr
<FullWallet
> wallet(new FullWallet(FutureYear(),
130 scoped_ptr
<Address
>(),
131 std::vector
<RequiredAction
>()));
132 std::vector
<uint8
> one_time_pad
;
133 base::HexStringToBytes("5F04A8704183", &one_time_pad
);
134 wallet
->set_one_time_pad(one_time_pad
);
135 return wallet
.Pass();
138 scoped_ptr
<Instrument
> GetTestInstrument() {
139 return make_scoped_ptr(new Instrument(ASCIIToUTF16("4444444444444448"),
147 scoped_ptr
<Instrument
> GetTestAddressUpgradeInstrument() {
148 return make_scoped_ptr(new Instrument(base::string16(),
156 scoped_ptr
<Instrument
> GetTestExpirationDateChangeInstrument() {
157 return make_scoped_ptr(new Instrument(base::string16(),
162 scoped_ptr
<Address
>()));
165 scoped_ptr
<Instrument
> GetTestAddressNameChangeInstrument() {
166 return make_scoped_ptr(new Instrument(base::string16(),
174 scoped_ptr
<WalletItems::LegalDocument
> GetTestLegalDocument() {
175 base::DictionaryValue dict
;
176 dict
.SetString("legal_document_id", "document_id");
177 dict
.SetString("display_name", "display_name");
178 return wallet::WalletItems::LegalDocument::CreateLegalDocument(dict
);
181 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrument() {
182 return GetTestMaskedInstrumentWithId("default_instrument_id");
185 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrumentExpired() {
186 return GetTestMaskedInstrumentWithDetails(
187 "default_instrument_id",
189 WalletItems::MaskedInstrument::VISA
,
190 WalletItems::MaskedInstrument::EXPIRED
);
193 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrumentInvalid() {
194 return GetTestMaskedInstrumentWithDetails(
195 "default_instrument_id",
197 WalletItems::MaskedInstrument::VISA
,
198 WalletItems::MaskedInstrument::DECLINED
);
201 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestMaskedInstrumentAmex(
202 AmexPermission amex_permission
) {
203 return GetTestMaskedInstrumentWithDetails(
204 "default_instrument_id",
206 WalletItems::MaskedInstrument::AMEX
,
207 amex_permission
== AMEX_ALLOWED
?
208 WalletItems::MaskedInstrument::VALID
:
209 WalletItems::MaskedInstrument::AMEX_NOT_SUPPORTED
);
212 scoped_ptr
<WalletItems::MaskedInstrument
> GetTestNonDefaultMaskedInstrument() {
213 return GetTestMaskedInstrumentWithId("instrument_id");
216 scoped_ptr
<Address
> GetTestSaveableAddress() {
217 return make_scoped_ptr(
219 ASCIIToUTF16("save_recipient_name"),
220 StreetAddress("save_address_line_1", "save_address_line_2"),
221 ASCIIToUTF16("save_locality_name"),
222 ASCIIToUTF16("save_dependent_locality_name"),
223 ASCIIToUTF16("save_admin_area_name"),
224 ASCIIToUTF16("save_postal_code_number"),
225 ASCIIToUTF16("save_sorting_code"),
226 ASCIIToUTF16("save_phone_number"),
228 "save_language_code"));
231 scoped_ptr
<Address
> GetTestShippingAddress() {
232 return make_scoped_ptr(
234 ASCIIToUTF16("ship_recipient_name"),
235 StreetAddress("ship_address_line_1", "ship_address_line_2"),
236 ASCIIToUTF16("ship_locality_name"),
237 ASCIIToUTF16("ship_dependent_locality_name"),
238 ASCIIToUTF16("ship_admin_area_name"),
239 ASCIIToUTF16("ship_postal_code_number"),
240 ASCIIToUTF16("ship_sorting_code"),
241 ASCIIToUTF16("ship_phone_number"),
242 "default_address_id",
243 "ship_language_code"));
246 scoped_ptr
<Address
> GetTestNonDefaultShippingAddress() {
247 scoped_ptr
<Address
> address
= GetTestShippingAddress();
248 address
->set_object_id("address_id");
249 return address
.Pass();
252 scoped_ptr
<WalletItems
> GetTestWalletItemsWithDetails(
253 const std::vector
<RequiredAction
>& required_actions
,
254 const std::string
& default_instrument_id
,
255 const std::string
& default_address_id
,
256 AmexPermission amex_permission
) {
257 return make_scoped_ptr(new wallet::WalletItems(required_actions
,
258 "google_transaction_id",
259 default_instrument_id
,
264 scoped_ptr
<WalletItems
> GetTestWalletItemsWithRequiredAction(
265 RequiredAction action
) {
266 std::vector
<RequiredAction
> required_actions(1, action
);
267 scoped_ptr
<WalletItems
> items
=
268 GetTestWalletItemsWithDetails(required_actions
,
269 "default_instrument_id",
270 "default_address_id",
273 if (action
!= GAIA_AUTH
)
274 items
->AddAccount(GetTestGaiaAccount());
279 scoped_ptr
<WalletItems
> GetTestWalletItems(AmexPermission amex_permission
) {
280 return GetTestWalletItemsWithDefaultIds("default_instrument_id",
281 "default_address_id",
285 scoped_ptr
<WalletItems
> GetTestWalletItemsWithUsers(
286 const std::vector
<std::string
>& users
, size_t active_index
) {
287 scoped_ptr
<WalletItems
> items
=
288 GetTestWalletItemsWithDetails(std::vector
<RequiredAction
>(),
289 "default_instrument_id",
290 "default_address_id",
292 for (size_t i
= 0; i
< users
.size(); ++i
) {
293 scoped_ptr
<GaiaAccount
> account(GaiaAccount::CreateForTesting(
294 users
[i
], "obfuscated_id", i
, i
== active_index
));
295 items
->AddAccount(account
.Pass());
300 scoped_ptr
<WalletItems
> GetTestWalletItemsWithDefaultIds(
301 const std::string
& default_instrument_id
,
302 const std::string
& default_address_id
,
303 AmexPermission amex_permission
) {
304 scoped_ptr
<WalletItems
> items
=
305 GetTestWalletItemsWithDetails(std::vector
<RequiredAction
>(),
306 default_instrument_id
,
309 items
->AddAccount(GetTestGaiaAccount());
313 } // namespace wallet
314 } // namespace autofill