OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "base/json/json_reader.h" |
| 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/autofill/wallet/full_wallet.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const char kFullWalletValidResponse[] = |
| 15 "{" |
| 16 " \"expiration_month\":12," |
| 17 " \"expiration_year\":2012," |
| 18 " \"iin\":\"iin\"," |
| 19 " \"rest\":\"rest\"," |
| 20 " \"billing_address\":" |
| 21 " {" |
| 22 " \"id\":\"id\"," |
| 23 " \"phone_number\":\"phone_number\"," |
| 24 " \"postal_address\":" |
| 25 " {" |
| 26 " \"recipient_name\":\"recipient_name\"," |
| 27 " \"address_line\":" |
| 28 " [" |
| 29 " \"address_line_1\"," |
| 30 " \"address_line_2\"" |
| 31 " ]," |
| 32 " \"locality_name\":\"locality_name\"," |
| 33 " \"administrative_area_name\":\"administrative_area_name\"," |
| 34 " \"postal_code_number\":\"postal_code_number\"," |
| 35 " \"country_name_code\":\"country_name_code\"" |
| 36 " }" |
| 37 " }," |
| 38 " \"shipping_address\":" |
| 39 " {" |
| 40 " \"id\":\"ship_id\"," |
| 41 " \"phone_number\":\"ship_phone_number\"," |
| 42 " \"postal_address\":" |
| 43 " {" |
| 44 " \"recipient_name\":\"ship_recipient_name\"," |
| 45 " \"address_line\":" |
| 46 " [" |
| 47 " \"ship_address_line_1\"," |
| 48 " \"ship_address_line_2\"" |
| 49 " ]," |
| 50 " \"locality_name\":\"ship_locality_name\"," |
| 51 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 52 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 53 " \"country_name_code\":\"ship_country_name_code\"" |
| 54 " }" |
| 55 " }," |
| 56 " \"required_action\":" |
| 57 " [" |
| 58 " ]" |
| 59 "}"; |
| 60 |
| 61 const char kFullWalletMissingExpirationMonth[] = |
| 62 "{" |
| 63 " \"expiration_year\":2012," |
| 64 " \"iin\":\"iin\"," |
| 65 " \"rest\":\"rest\"," |
| 66 " \"billing_address\":" |
| 67 " {" |
| 68 " \"id\":\"id\"," |
| 69 " \"phone_number\":\"phone_number\"," |
| 70 " \"postal_address\":" |
| 71 " {" |
| 72 " \"recipient_name\":\"recipient_name\"," |
| 73 " \"address_line\":" |
| 74 " [" |
| 75 " \"address_line_1\"," |
| 76 " \"address_line_2\"" |
| 77 " ]," |
| 78 " \"locality_name\":\"locality_name\"," |
| 79 " \"administrative_area_name\":\"administrative_area_name\"," |
| 80 " \"postal_code_number\":\"postal_code_number\"," |
| 81 " \"country_name_code\":\"country_name_code\"" |
| 82 " }" |
| 83 " }," |
| 84 " \"shipping_address\":" |
| 85 " {" |
| 86 " \"id\":\"ship_id\"," |
| 87 " \"phone_number\":\"ship_phone_number\"," |
| 88 " \"postal_address\":" |
| 89 " {" |
| 90 " \"recipient_name\":\"ship_recipient_name\"," |
| 91 " \"address_line\":" |
| 92 " [" |
| 93 " \"ship_address_line_1\"," |
| 94 " \"ship_address_line_2\"" |
| 95 " ]," |
| 96 " \"locality_name\":\"ship_locality_name\"," |
| 97 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 98 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 99 " \"country_name_code\":\"ship_country_name_code\"" |
| 100 " }" |
| 101 " }," |
| 102 " \"required_action\":" |
| 103 " [" |
| 104 " ]" |
| 105 "}"; |
| 106 |
| 107 const char kFullWalletMissingExpirationYear[] = |
| 108 "{" |
| 109 " \"expiration_month\":12," |
| 110 " \"iin\":\"iin\"," |
| 111 " \"rest\":\"rest\"," |
| 112 " \"billing_address\":" |
| 113 " {" |
| 114 " \"id\":\"id\"," |
| 115 " \"phone_number\":\"phone_number\"," |
| 116 " \"postal_address\":" |
| 117 " {" |
| 118 " \"recipient_name\":\"recipient_name\"," |
| 119 " \"address_line\":" |
| 120 " [" |
| 121 " \"address_line_1\"," |
| 122 " \"address_line_2\"" |
| 123 " ]," |
| 124 " \"locality_name\":\"locality_name\"," |
| 125 " \"administrative_area_name\":\"administrative_area_name\"," |
| 126 " \"postal_code_number\":\"postal_code_number\"," |
| 127 " \"country_name_code\":\"country_name_code\"" |
| 128 " }" |
| 129 " }," |
| 130 " \"shipping_address\":" |
| 131 " {" |
| 132 " \"id\":\"ship_id\"," |
| 133 " \"phone_number\":\"ship_phone_number\"," |
| 134 " \"postal_address\":" |
| 135 " {" |
| 136 " \"recipient_name\":\"ship_recipient_name\"," |
| 137 " \"address_line\":" |
| 138 " [" |
| 139 " \"ship_address_line_1\"," |
| 140 " \"ship_address_line_2\"" |
| 141 " ]," |
| 142 " \"locality_name\":\"ship_locality_name\"," |
| 143 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 144 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 145 " \"country_name_code\":\"ship_country_name_code\"" |
| 146 " }" |
| 147 " }," |
| 148 " \"required_action\":" |
| 149 " [" |
| 150 " ]" |
| 151 "}"; |
| 152 |
| 153 const char kFullWalletMissingIin[] = |
| 154 "{" |
| 155 " \"expiration_month\":12," |
| 156 " \"expiration_year\":2012," |
| 157 " \"rest\":\"rest\"," |
| 158 " \"billing_address\":" |
| 159 " {" |
| 160 " \"id\":\"id\"," |
| 161 " \"phone_number\":\"phone_number\"," |
| 162 " \"postal_address\":" |
| 163 " {" |
| 164 " \"recipient_name\":\"recipient_name\"," |
| 165 " \"address_line\":" |
| 166 " [" |
| 167 " \"address_line_1\"," |
| 168 " \"address_line_2\"" |
| 169 " ]," |
| 170 " \"locality_name\":\"locality_name\"," |
| 171 " \"administrative_area_name\":\"administrative_area_name\"," |
| 172 " \"postal_code_number\":\"postal_code_number\"," |
| 173 " \"country_name_code\":\"country_name_code\"" |
| 174 " }" |
| 175 " }," |
| 176 " \"shipping_address\":" |
| 177 " {" |
| 178 " \"id\":\"ship_id\"," |
| 179 " \"phone_number\":\"ship_phone_number\"," |
| 180 " \"postal_address\":" |
| 181 " {" |
| 182 " \"recipient_name\":\"ship_recipient_name\"," |
| 183 " \"address_line\":" |
| 184 " [" |
| 185 " \"ship_address_line_1\"," |
| 186 " \"ship_address_line_2\"" |
| 187 " ]," |
| 188 " \"locality_name\":\"ship_locality_name\"," |
| 189 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 190 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 191 " \"country_name_code\":\"ship_country_name_code\"" |
| 192 " }" |
| 193 " }," |
| 194 " \"required_action\":" |
| 195 " [" |
| 196 " ]" |
| 197 "}"; |
| 198 |
| 199 const char kFullWalletMissingRest[] = |
| 200 "{" |
| 201 " \"expiration_month\":12," |
| 202 " \"expiration_year\":2012," |
| 203 " \"iin\":\"iin\"," |
| 204 " \"billing_address\":" |
| 205 " {" |
| 206 " \"id\":\"id\"," |
| 207 " \"phone_number\":\"phone_number\"," |
| 208 " \"postal_address\":" |
| 209 " {" |
| 210 " \"recipient_name\":\"recipient_name\"," |
| 211 " \"address_line\":" |
| 212 " [" |
| 213 " \"address_line_1\"," |
| 214 " \"address_line_2\"" |
| 215 " ]," |
| 216 " \"locality_name\":\"locality_name\"," |
| 217 " \"administrative_area_name\":\"administrative_area_name\"," |
| 218 " \"postal_code_number\":\"postal_code_number\"," |
| 219 " \"country_name_code\":\"country_name_code\"" |
| 220 " }" |
| 221 " }," |
| 222 " \"shipping_address\":" |
| 223 " {" |
| 224 " \"id\":\"ship_id\"," |
| 225 " \"phone_number\":\"ship_phone_number\"," |
| 226 " \"postal_address\":" |
| 227 " {" |
| 228 " \"recipient_name\":\"ship_recipient_name\"," |
| 229 " \"address_line\":" |
| 230 " [" |
| 231 " \"ship_address_line_1\"," |
| 232 " \"ship_address_line_2\"" |
| 233 " ]," |
| 234 " \"locality_name\":\"ship_locality_name\"," |
| 235 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 236 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 237 " \"country_name_code\":\"ship_country_name_code\"" |
| 238 " }" |
| 239 " }," |
| 240 " \"required_action\":" |
| 241 " [" |
| 242 " ]" |
| 243 "}"; |
| 244 |
| 245 const char kFullWalletMissingBillingAddress[] = |
| 246 "{" |
| 247 " \"expiration_month\":12," |
| 248 " \"expiration_year\":2012," |
| 249 " \"iin\":\"iin\"," |
| 250 " \"rest\":\"rest\"," |
| 251 " \"shipping_address\":" |
| 252 " {" |
| 253 " \"id\":\"ship_id\"," |
| 254 " \"phone_number\":\"ship_phone_number\"," |
| 255 " \"postal_address\":" |
| 256 " {" |
| 257 " \"recipient_name\":\"ship_recipient_name\"," |
| 258 " \"address_line\":" |
| 259 " [" |
| 260 " \"ship_address_line_1\"," |
| 261 " \"ship_address_line_2\"" |
| 262 " ]," |
| 263 " \"locality_name\":\"ship_locality_name\"," |
| 264 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 265 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 266 " \"country_name_code\":\"ship_country_name_code\"" |
| 267 " }" |
| 268 " }," |
| 269 " \"required_action\":" |
| 270 " [" |
| 271 " ]" |
| 272 "}"; |
| 273 |
| 274 const char kFullWalletWithRequiredActions[] = |
| 275 "{" |
| 276 " \"required_action\":" |
| 277 " [" |
| 278 " \"required_action\"" |
| 279 " ]" |
| 280 "}"; |
| 281 |
| 282 const char kFullWalletMalformedBillingAddress[] = |
| 283 "{" |
| 284 " \"expiration_month\":12," |
| 285 " \"expiration_year\":2012," |
| 286 " \"iin\":\"iin\"," |
| 287 " \"rest\":\"rest\"," |
| 288 " \"billing_address\":" |
| 289 " {" |
| 290 " \"id\":\"id\"," |
| 291 " \"phone_number\":\"phone_number\"," |
| 292 " \"postal_address\":" |
| 293 " {" |
| 294 " \"recipient_name\":\"recipient_name\"," |
| 295 " \"address_line\":" |
| 296 " [" |
| 297 " \"address_line_1\"," |
| 298 " \"address_line_2\"" |
| 299 " ]," |
| 300 " \"locality_name\":\"locality_name\"," |
| 301 " \"administrative_area_name\":\"administrative_area_name\"" |
| 302 " }" |
| 303 " }," |
| 304 " \"shipping_address\":" |
| 305 " {" |
| 306 " \"id\":\"ship_id\"," |
| 307 " \"phone_number\":\"ship_phone_number\"," |
| 308 " \"postal_address\":" |
| 309 " {" |
| 310 " \"recipient_name\":\"ship_recipient_name\"," |
| 311 " \"address_line\":" |
| 312 " [" |
| 313 " \"ship_address_line_1\"," |
| 314 " \"ship_address_line_2\"" |
| 315 " ]," |
| 316 " \"locality_name\":\"ship_locality_name\"," |
| 317 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 318 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 319 " \"country_name_code\":\"ship_country_name_code\"" |
| 320 " }" |
| 321 " }," |
| 322 " \"required_action\":" |
| 323 " [" |
| 324 " ]" |
| 325 "}"; |
| 326 |
| 327 } // anonymous namespace |
| 328 |
| 329 namespace wallet { |
| 330 |
| 331 class FullWalletTest : public testing::Test { |
| 332 public: |
| 333 FullWalletTest() {} |
| 334 protected: |
| 335 void SetUpDictionary(const std::string& json) { |
| 336 scoped_ptr<Value> value(base::JSONReader::Read(json)); |
| 337 DCHECK(value.get()); |
| 338 DCHECK(value->IsType(Value::TYPE_DICTIONARY)); |
| 339 dict.reset(static_cast<DictionaryValue*>(value.release())); |
| 340 } |
| 341 scoped_ptr<DictionaryValue> dict; |
| 342 }; |
| 343 |
| 344 TEST_F(FullWalletTest, CreateFullWalletMissingExpirationMonth) { |
| 345 SetUpDictionary(kFullWalletMissingExpirationMonth); |
| 346 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 347 } |
| 348 |
| 349 TEST_F(FullWalletTest, CreateFullWalletMissingExpirationYear) { |
| 350 SetUpDictionary(kFullWalletMissingExpirationYear); |
| 351 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 352 } |
| 353 |
| 354 TEST_F(FullWalletTest, CreateFullWalletMissingIin) { |
| 355 SetUpDictionary(kFullWalletMissingIin); |
| 356 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 357 } |
| 358 |
| 359 TEST_F(FullWalletTest, CreateFullWalletMissingRest) { |
| 360 SetUpDictionary(kFullWalletMissingRest); |
| 361 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 362 } |
| 363 |
| 364 TEST_F(FullWalletTest, CreateFullWalletMissingBillingAddress) { |
| 365 SetUpDictionary(kFullWalletMissingBillingAddress); |
| 366 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 367 } |
| 368 |
| 369 TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) { |
| 370 SetUpDictionary(kFullWalletMalformedBillingAddress); |
| 371 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 372 } |
| 373 |
| 374 TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { |
| 375 SetUpDictionary(kFullWalletWithRequiredActions); |
| 376 std::vector<std::string> required_actions; |
| 377 required_actions.push_back("required_action"); |
| 378 FullWallet full_wallet(-1, |
| 379 -1, |
| 380 "", |
| 381 "", |
| 382 scoped_ptr<Address>(), |
| 383 scoped_ptr<Address>(), |
| 384 required_actions); |
| 385 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); |
| 386 } |
| 387 |
| 388 TEST_F(FullWalletTest, CreateFullWallet) { |
| 389 SetUpDictionary(kFullWalletValidResponse); |
| 390 scoped_ptr<Address> billing_address(new Address("country_name_code", |
| 391 "recipient_name", |
| 392 "address_line_1", |
| 393 "address_line_2", |
| 394 "locality_name", |
| 395 "administrative_area_name", |
| 396 "postal_code_number", |
| 397 "phone_number", |
| 398 "id")); |
| 399 scoped_ptr<Address> shipping_address(new Address("ship_country_name_code", |
| 400 "ship_recipient_name", |
| 401 "ship_address_line_1", |
| 402 "ship_address_line_2", |
| 403 "ship_locality_name", |
| 404 "ship_admin_area_name", |
| 405 "ship_postal_code_number", |
| 406 "ship_phone_number", |
| 407 "ship_id")); |
| 408 std::vector<std::string> required_actions; |
| 409 FullWallet full_wallet(12, |
| 410 2012, |
| 411 "iin", |
| 412 "rest", |
| 413 billing_address.Pass(), |
| 414 shipping_address.Pass(), |
| 415 required_actions); |
| 416 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); |
| 417 } |
| 418 |
| 419 } // namespace wallet |
| 420 |
OLD | NEW |