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. 4 5 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 6 7 #include <string> 8 #include <vector> 9 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/instrument.h" 16 #include "components/autofill/content/browser/wallet/required_action.h" 17 #include "components/autofill/content/browser/wallet/wallet_address.h" 18 19 namespace autofill { 20 namespace wallet { 21 22 namespace { 23 24 int FutureYear() { 25 // "In the Year 3000." - Richie "LaBamba" Rosenberg 26 return 3000; 27 } 28 29 } // namespace 30 31 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentWithDetails( 32 const std::string& id, 33 scoped_ptr<Address> address, 34 WalletItems::MaskedInstrument::Type type, 35 WalletItems::MaskedInstrument::Status status) { 36 return scoped_ptr<WalletItems::MaskedInstrument>( 37 new WalletItems::MaskedInstrument(ASCIIToUTF16("descriptive_name"), 38 type, 39 std::vector<base::string16>(), 40 ASCIIToUTF16("1111"), 41 12, 42 FutureYear(), 43 address.Pass(), 44 status, 45 id)); 46 } 47 48 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentWithId( 49 const std::string& id) { 50 return GetTestMaskedInstrumentWithDetails( 51 id, 52 GetTestAddress(), 53 WalletItems::MaskedInstrument::VISA, 54 WalletItems::MaskedInstrument::VALID); 55 } 56 57 scoped_ptr<WalletItems::MaskedInstrument> 58 GetTestMaskedInstrumentWithIdAndAddress( 59 const std::string& id, scoped_ptr<Address> address) { 60 return GetTestMaskedInstrumentWithDetails( 61 id, 62 address.Pass(), 63 WalletItems::MaskedInstrument::VISA, 64 WalletItems::MaskedInstrument::VALID); 65 } 66 67 scoped_ptr<Address> GetTestAddress() { 68 return scoped_ptr<Address>(new Address("US", 69 ASCIIToUTF16("recipient_name"), 70 ASCIIToUTF16("address_line_1"), 71 ASCIIToUTF16("address_line_2"), 72 ASCIIToUTF16("locality_name"), 73 ASCIIToUTF16("admin_area_name"), 74 ASCIIToUTF16("postal_code_number"), 75 ASCIIToUTF16("phone_number"), 76 std::string())); 77 } 78 79 scoped_ptr<Address> GetTestMinimalAddress() { 80 scoped_ptr<Address> address = GetTestAddress(); 81 address->set_is_complete_address(false); 82 return address.Pass(); 83 } 84 85 scoped_ptr<FullWallet> GetTestFullWallet() { 86 scoped_ptr<FullWallet> wallet(new FullWallet(FutureYear(), 87 12, 88 "528512", 89 "5ec4feecf9d6", 90 GetTestAddress(), 91 GetTestShippingAddress(), 92 std::vector<RequiredAction>())); 93 std::vector<uint8> one_time_pad; 94 base::HexStringToBytes("5F04A8704183", &one_time_pad); 95 wallet->set_one_time_pad(one_time_pad); 96 return wallet.Pass(); 97 } 98 99 scoped_ptr<FullWallet> GetTestFullWalletInstrumentOnly() { 100 scoped_ptr<FullWallet> wallet(new FullWallet(FutureYear(), 101 12, 102 "528512", 103 "5ec4feecf9d6", 104 GetTestAddress(), 105 scoped_ptr<Address>(), 106 std::vector<RequiredAction>())); 107 std::vector<uint8> one_time_pad; 108 base::HexStringToBytes("5F04A8704183", &one_time_pad); 109 wallet->set_one_time_pad(one_time_pad); 110 return wallet.Pass(); 111 } 112 113 scoped_ptr<Instrument> GetTestInstrument() { 114 return scoped_ptr<Instrument>(new Instrument(ASCIIToUTF16("4444444444444448"), 115 ASCIIToUTF16("123"), 116 12, 117 FutureYear(), 118 Instrument::VISA, 119 GetTestAddress())); 120 } 121 122 scoped_ptr<Instrument> GetTestAddressUpgradeInstrument() { 123 scoped_ptr<Instrument> instrument(new Instrument(base::string16(), 124 base::string16(), 125 0, 126 0, 127 Instrument::UNKNOWN, 128 GetTestAddress())); 129 instrument->set_object_id("instrument_id"); 130 return instrument.Pass(); 131 } 132 133 scoped_ptr<Instrument> GetTestExpirationDateChangeInstrument() { 134 scoped_ptr<Instrument> instrument(new Instrument(base::string16(), 135 ASCIIToUTF16("123"), 136 12, 137 FutureYear(), 138 Instrument::UNKNOWN, 139 scoped_ptr<Address>())); 140 instrument->set_object_id("instrument_id"); 141 return instrument.Pass(); 142 } 143 144 scoped_ptr<Instrument> GetTestAddressNameChangeInstrument() { 145 scoped_ptr<Instrument> instrument(new Instrument(base::string16(), 146 ASCIIToUTF16("123"), 147 0, 148 0, 149 Instrument::UNKNOWN, 150 GetTestAddress())); 151 instrument->set_object_id("instrument_id"); 152 return instrument.Pass(); 153 } 154 155 scoped_ptr<WalletItems::LegalDocument> GetTestLegalDocument() { 156 base::DictionaryValue dict; 157 dict.SetString("legal_document_id", "document_id"); 158 dict.SetString("display_name", "display_name"); 159 return wallet::WalletItems::LegalDocument::CreateLegalDocument(dict); 160 } 161 162 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrument() { 163 return GetTestMaskedInstrumentWithId("default_instrument_id"); 164 } 165 166 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentExpired() { 167 return GetTestMaskedInstrumentWithDetails( 168 "default_instrument_id", 169 GetTestAddress(), 170 WalletItems::MaskedInstrument::VISA, 171 WalletItems::MaskedInstrument::EXPIRED); 172 } 173 174 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentInvalid() { 175 return GetTestMaskedInstrumentWithDetails( 176 "default_instrument_id", 177 GetTestAddress(), 178 WalletItems::MaskedInstrument::VISA, 179 WalletItems::MaskedInstrument::DECLINED); 180 } 181 182 scoped_ptr<WalletItems::MaskedInstrument> GetTestMaskedInstrumentAmex() { 183 return GetTestMaskedInstrumentWithDetails( 184 "default_instrument_id", 185 GetTestAddress(), 186 WalletItems::MaskedInstrument::AMEX, 187 // Amex cards are marked with status AMEX_NOT_SUPPORTED by the server. 188 WalletItems::MaskedInstrument::AMEX_NOT_SUPPORTED); 189 } 190 191 scoped_ptr<WalletItems::MaskedInstrument> GetTestNonDefaultMaskedInstrument() { 192 return GetTestMaskedInstrumentWithId("instrument_id"); 193 } 194 195 scoped_ptr<Address> GetTestSaveableAddress() { 196 return scoped_ptr<Address>(new Address( 197 "US", 198 ASCIIToUTF16("save_recipient_name"), 199 ASCIIToUTF16("save_address_line_1"), 200 ASCIIToUTF16("save_address_line_2"), 201 ASCIIToUTF16("save_locality_name"), 202 ASCIIToUTF16("save_admin_area_name"), 203 ASCIIToUTF16("save_postal_code_number"), 204 ASCIIToUTF16("save_phone_number"), 205 std::string())); 206 } 207 208 scoped_ptr<Address> GetTestShippingAddress() { 209 return scoped_ptr<Address>(new Address( 210 "US", 211 ASCIIToUTF16("ship_recipient_name"), 212 ASCIIToUTF16("ship_address_line_1"), 213 ASCIIToUTF16("ship_address_line_2"), 214 ASCIIToUTF16("ship_locality_name"), 215 ASCIIToUTF16("ship_admin_area_name"), 216 ASCIIToUTF16("ship_postal_code_number"), 217 ASCIIToUTF16("ship_phone_number"), 218 "default_address_id")); 219 } 220 221 scoped_ptr<Address> GetTestNonDefaultShippingAddress() { 222 scoped_ptr<Address> address = GetTestShippingAddress(); 223 address->set_object_id("address_id"); 224 return address.Pass(); 225 } 226 227 scoped_ptr<WalletItems> GetTestWalletItems() { 228 return scoped_ptr<WalletItems>( 229 new wallet::WalletItems(std::vector<RequiredAction>(), 230 "google_transaction_id", 231 "default_instrument_id", 232 "default_address_id", 233 "obfuscated_gaia_id")); 234 } 235 236 } // namespace wallet 237 } // namespace autofill 238