OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/autofill/wallet/full_wallet.h" | 9 #include "chrome/browser/autofill/wallet/full_wallet.h" |
| 10 #include "chrome/browser/autofill/wallet/required_action.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 const char kFullWalletValidResponse[] = | 15 const char kFullWalletValidResponse[] = |
15 "{" | 16 "{" |
16 " \"expiration_month\":12," | 17 " \"expiration_month\":12," |
17 " \"expiration_year\":2012," | 18 " \"expiration_year\":2012," |
18 " \"iin\":\"iin\"," | 19 " \"iin\":\"iin\"," |
19 " \"rest\":\"rest\"," | 20 " \"rest\":\"rest\"," |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 " }," | 269 " }," |
269 " \"required_action\":" | 270 " \"required_action\":" |
270 " [" | 271 " [" |
271 " ]" | 272 " ]" |
272 "}"; | 273 "}"; |
273 | 274 |
274 const char kFullWalletWithRequiredActions[] = | 275 const char kFullWalletWithRequiredActions[] = |
275 "{" | 276 "{" |
276 " \"required_action\":" | 277 " \"required_action\":" |
277 " [" | 278 " [" |
278 " \"required_action\"" | 279 " \"UPGRADE_MIN_ADDRESS\"," |
| 280 " \"update_EXPIRATION_date\"," |
| 281 " \"INVALID_form_field\"," |
| 282 " \"cvc_risk_CHALLENGE\"" |
279 " ]" | 283 " ]" |
280 "}"; | 284 "}"; |
281 | 285 |
| 286 const char kFullWalletWithInvalidRequiredActions[] = |
| 287 "{" |
| 288 " \"required_action\":" |
| 289 " [" |
| 290 " \" setup_wallet\"," |
| 291 " \"AcCePt_ToS \"," |
| 292 " \" \\tGAIA_auth \\n\\r\"," |
| 293 " \" 忍者の正体 \"" |
| 294 " ]" |
| 295 "}"; |
| 296 |
282 const char kFullWalletMalformedBillingAddress[] = | 297 const char kFullWalletMalformedBillingAddress[] = |
283 "{" | 298 "{" |
284 " \"expiration_month\":12," | 299 " \"expiration_month\":12," |
285 " \"expiration_year\":2012," | 300 " \"expiration_year\":2012," |
286 " \"iin\":\"iin\"," | 301 " \"iin\":\"iin\"," |
287 " \"rest\":\"rest\"," | 302 " \"rest\":\"rest\"," |
288 " \"billing_address\":" | 303 " \"billing_address\":" |
289 " {" | 304 " {" |
290 " \"id\":\"id\"," | 305 " \"id\":\"id\"," |
291 " \"phone_number\":\"phone_number\"," | 306 " \"phone_number\":\"phone_number\"," |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); | 381 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
367 } | 382 } |
368 | 383 |
369 TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) { | 384 TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) { |
370 SetUpDictionary(kFullWalletMalformedBillingAddress); | 385 SetUpDictionary(kFullWalletMalformedBillingAddress); |
371 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); | 386 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
372 } | 387 } |
373 | 388 |
374 TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { | 389 TEST_F(FullWalletTest, CreateFullWalletWithRequiredActions) { |
375 SetUpDictionary(kFullWalletWithRequiredActions); | 390 SetUpDictionary(kFullWalletWithRequiredActions); |
376 std::vector<std::string> required_actions; | 391 |
377 required_actions.push_back("required_action"); | 392 std::vector<RequiredAction> required_actions; |
| 393 required_actions.push_back(UPGRADE_MIN_ADDRESS); |
| 394 required_actions.push_back(UPDATE_EXPIRATION_DATE); |
| 395 required_actions.push_back(INVALID_FORM_FIELD); |
| 396 required_actions.push_back(CVC_RISK_CHALLENGE); |
| 397 |
378 FullWallet full_wallet(-1, | 398 FullWallet full_wallet(-1, |
379 -1, | 399 -1, |
380 "", | 400 "", |
381 "", | 401 "", |
382 scoped_ptr<Address>(), | 402 scoped_ptr<Address>(), |
383 scoped_ptr<Address>(), | 403 scoped_ptr<Address>(), |
384 required_actions); | 404 required_actions); |
385 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); | 405 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); |
| 406 |
| 407 DCHECK(!required_actions.empty()); |
| 408 required_actions.pop_back(); |
| 409 FullWallet different_required_actions( |
| 410 -1, |
| 411 -1, |
| 412 "", |
| 413 "", |
| 414 scoped_ptr<Address>(), |
| 415 scoped_ptr<Address>(), |
| 416 required_actions); |
| 417 ASSERT_NE(full_wallet, different_required_actions); |
| 418 } |
| 419 |
| 420 TEST_F(FullWalletTest, CreateFullWalletWithInvalidRequiredActions) { |
| 421 SetUpDictionary(kFullWalletWithInvalidRequiredActions); |
| 422 ASSERT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
386 } | 423 } |
387 | 424 |
388 TEST_F(FullWalletTest, CreateFullWallet) { | 425 TEST_F(FullWalletTest, CreateFullWallet) { |
389 SetUpDictionary(kFullWalletValidResponse); | 426 SetUpDictionary(kFullWalletValidResponse); |
390 scoped_ptr<Address> billing_address(new Address("country_name_code", | 427 scoped_ptr<Address> billing_address(new Address("country_name_code", |
391 "recipient_name", | 428 "recipient_name", |
392 "address_line_1", | 429 "address_line_1", |
393 "address_line_2", | 430 "address_line_2", |
394 "locality_name", | 431 "locality_name", |
395 "administrative_area_name", | 432 "administrative_area_name", |
396 "postal_code_number", | 433 "postal_code_number", |
397 "phone_number", | 434 "phone_number", |
398 "id")); | 435 "id")); |
399 scoped_ptr<Address> shipping_address(new Address("ship_country_name_code", | 436 scoped_ptr<Address> shipping_address(new Address("ship_country_name_code", |
400 "ship_recipient_name", | 437 "ship_recipient_name", |
401 "ship_address_line_1", | 438 "ship_address_line_1", |
402 "ship_address_line_2", | 439 "ship_address_line_2", |
403 "ship_locality_name", | 440 "ship_locality_name", |
404 "ship_admin_area_name", | 441 "ship_admin_area_name", |
405 "ship_postal_code_number", | 442 "ship_postal_code_number", |
406 "ship_phone_number", | 443 "ship_phone_number", |
407 "ship_id")); | 444 "ship_id")); |
408 std::vector<std::string> required_actions; | 445 std::vector<RequiredAction> required_actions; |
409 FullWallet full_wallet(12, | 446 FullWallet full_wallet(12, |
410 2012, | 447 2012, |
411 "iin", | 448 "iin", |
412 "rest", | 449 "rest", |
413 billing_address.Pass(), | 450 billing_address.Pass(), |
414 shipping_address.Pass(), | 451 shipping_address.Pass(), |
415 required_actions); | 452 required_actions); |
416 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); | 453 ASSERT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); |
417 } | 454 } |
418 | 455 |
419 } // namespace wallet | 456 } // namespace wallet |
420 | 457 |
OLD | NEW |