| 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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "components/autofill/browser/wallet/full_wallet.h" | 11 #include "components/autofill/browser/wallet/full_wallet.h" |
| 12 #include "components/autofill/browser/wallet/required_action.h" | 12 #include "components/autofill/browser/wallet/required_action.h" |
| 13 #include "components/autofill/browser/wallet/wallet_test_util.h" | 13 #include "components/autofill/browser/wallet/wallet_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kFullWalletValidResponse[] = | 18 const char kFullWalletValidResponse[] = |
| 19 "{" | 19 "{" |
| 20 " \"expiration_month\":12," | 20 " \"expiration_month\":12," |
| 21 " \"expiration_year\":2012," | 21 " \"expiration_year\":3000," |
| 22 " \"iin\":\"iin\"," | 22 " \"iin\":\"iin\"," |
| 23 " \"rest\":\"rest\"," | 23 " \"rest\":\"rest\"," |
| 24 " \"billing_address\":" | 24 " \"billing_address\":" |
| 25 " {" | 25 " {" |
| 26 " \"phone_number\":\"phone_number\"," | 26 " \"phone_number\":\"phone_number\"," |
| 27 " \"postal_address\":" | 27 " \"postal_address\":" |
| 28 " {" | 28 " {" |
| 29 " \"recipient_name\":\"recipient_name\"," | 29 " \"recipient_name\":\"recipient_name\"," |
| 30 " \"address_line\":" | 30 " \"address_line\":" |
| 31 " [" | 31 " [" |
| 32 " \"address_line_1\"," | 32 " \"address_line_1\"," |
| 33 " \"address_line_2\"" | 33 " \"address_line_2\"" |
| 34 " ]," | 34 " ]," |
| 35 " \"locality_name\":\"locality_name\"," | 35 " \"locality_name\":\"locality_name\"," |
| 36 " \"administrative_area_name\":\"admin_area_name\"," | 36 " \"administrative_area_name\":\"admin_area_name\"," |
| 37 " \"postal_code_number\":\"postal_code_number\"," | 37 " \"postal_code_number\":\"postal_code_number\"," |
| 38 " \"country_name_code\":\"country_name_code\"" | 38 " \"country_name_code\":\"US\"" |
| 39 " }" | 39 " }" |
| 40 " }," | 40 " }," |
| 41 " \"shipping_address\":" | 41 " \"shipping_address\":" |
| 42 " {" | 42 " {" |
| 43 " \"id\":\"address_id\"," | 43 " \"id\":\"address_id\"," |
| 44 " \"phone_number\":\"ship_phone_number\"," | 44 " \"phone_number\":\"ship_phone_number\"," |
| 45 " \"postal_address\":" | 45 " \"postal_address\":" |
| 46 " {" | 46 " {" |
| 47 " \"recipient_name\":\"ship_recipient_name\"," | 47 " \"recipient_name\":\"ship_recipient_name\"," |
| 48 " \"address_line\":" | 48 " \"address_line\":" |
| 49 " [" | 49 " [" |
| 50 " \"ship_address_line_1\"," | 50 " \"ship_address_line_1\"," |
| 51 " \"ship_address_line_2\"" | 51 " \"ship_address_line_2\"" |
| 52 " ]," | 52 " ]," |
| 53 " \"locality_name\":\"ship_locality_name\"," | 53 " \"locality_name\":\"ship_locality_name\"," |
| 54 " \"administrative_area_name\":\"ship_admin_area_name\"," | 54 " \"administrative_area_name\":\"ship_admin_area_name\"," |
| 55 " \"postal_code_number\":\"ship_postal_code_number\"," | 55 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 56 " \"country_name_code\":\"ship_country_name_code\"" | 56 " \"country_name_code\":\"US\"" |
| 57 " }" | 57 " }" |
| 58 " }," | 58 " }," |
| 59 " \"required_action\":" | 59 " \"required_action\":" |
| 60 " [" | 60 " [" |
| 61 " ]" | 61 " ]" |
| 62 "}"; | 62 "}"; |
| 63 | 63 |
| 64 const char kFullWalletMissingExpirationMonth[] = | 64 const char kFullWalletMissingExpirationMonth[] = |
| 65 "{" | 65 "{" |
| 66 " \"expiration_year\":2012," | 66 " \"expiration_year\":2012," |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 423 |
| 424 TEST_F(FullWalletTest, CreateFullWalletWithInvalidRequiredActions) { | 424 TEST_F(FullWalletTest, CreateFullWalletWithInvalidRequiredActions) { |
| 425 SetUpDictionary(kFullWalletWithInvalidRequiredActions); | 425 SetUpDictionary(kFullWalletWithInvalidRequiredActions); |
| 426 EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); | 426 EXPECT_EQ(NULL, FullWallet::CreateFullWallet(*dict).get()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 TEST_F(FullWalletTest, CreateFullWallet) { | 429 TEST_F(FullWalletTest, CreateFullWallet) { |
| 430 SetUpDictionary(kFullWalletValidResponse); | 430 SetUpDictionary(kFullWalletValidResponse); |
| 431 std::vector<RequiredAction> required_actions; | 431 std::vector<RequiredAction> required_actions; |
| 432 FullWallet full_wallet(12, | 432 FullWallet full_wallet(12, |
| 433 2012, | 433 3000, |
| 434 "iin", | 434 "iin", |
| 435 "rest", | 435 "rest", |
| 436 GetTestAddress(), | 436 GetTestAddress(), |
| 437 GetTestNonDefaultShippingAddress(), | 437 GetTestNonDefaultShippingAddress(), |
| 438 required_actions); | 438 required_actions); |
| 439 EXPECT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); | 439 EXPECT_EQ(full_wallet, *FullWallet::CreateFullWallet(*dict)); |
| 440 } | 440 } |
| 441 | 441 |
| 442 TEST_F(FullWalletTest, EvenRestDecryptionTest) { | 442 TEST_F(FullWalletTest, EvenRestDecryptionTest) { |
| 443 std::vector<RequiredAction> required_actions; | 443 std::vector<RequiredAction> required_actions; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 470 EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad)); | 470 EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad)); |
| 471 full_wallet.set_one_time_pad(one_time_pad); | 471 full_wallet.set_one_time_pad(one_time_pad); |
| 472 EXPECT_EQ(ASCIIToUTF16("5285127687171393"), | 472 EXPECT_EQ(ASCIIToUTF16("5285127687171393"), |
| 473 full_wallet.GetInfo(CREDIT_CARD_NUMBER)); | 473 full_wallet.GetInfo(CREDIT_CARD_NUMBER)); |
| 474 EXPECT_EQ(ASCIIToUTF16("339"), | 474 EXPECT_EQ(ASCIIToUTF16("339"), |
| 475 full_wallet.GetInfo(CREDIT_CARD_VERIFICATION_CODE)); | 475 full_wallet.GetInfo(CREDIT_CARD_VERIFICATION_CODE)); |
| 476 } | 476 } |
| 477 | 477 |
| 478 } // namespace wallet | 478 } // namespace wallet |
| 479 } // namespace autofill | 479 } // namespace autofill |
| OLD | NEW |