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/memory/scoped_ptr.h" |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/autofill/wallet/full_wallet.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 static const char kFullWalletValidResponse[] = |
| 14 "{" |
| 15 " \"expiration_month\":12," |
| 16 " \"expiration_year\":2012," |
| 17 " \"iin\":\"iin\"," |
| 18 " \"rest\":\"rest\"," |
| 19 " \"billing_address\":" |
| 20 " {" |
| 21 " \"id\":\"id\"," |
| 22 " \"phone_number\":\"phone_number\"," |
| 23 " \"postal_address\":" |
| 24 " {" |
| 25 " \"recipient_name\":\"recipient_name\"," |
| 26 " \"address_line\":" |
| 27 " [" |
| 28 " \"address_line_1\"," |
| 29 " \"address_line_2\"" |
| 30 " ]," |
| 31 " \"locality_name\":\"locality_name\"," |
| 32 " \"administrative_area_name\":\"administrative_area_name\"," |
| 33 " \"postal_code_number\":\"postal_code_number\"," |
| 34 " \"country_name_code\":\"country_name_code\"" |
| 35 " }" |
| 36 " }," |
| 37 " \"shipping_address\":" |
| 38 " {" |
| 39 " \"id\":\"ship_id\"," |
| 40 " \"phone_number\":\"ship_phone_number\"," |
| 41 " \"postal_address\":" |
| 42 " {" |
| 43 " \"recipient_name\":\"ship_recipient_name\"," |
| 44 " \"address_line\":" |
| 45 " [" |
| 46 " \"ship_address_line_1\"," |
| 47 " \"ship_address_line_2\"" |
| 48 " ]," |
| 49 " \"locality_name\":\"ship_locality_name\"," |
| 50 " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| 51 " \"postal_code_number\":\"ship_postal_code_number\"," |
| 52 " \"country_name_code\":\"ship_country_name_code\"" |
| 53 " }" |
| 54 " }," |
| 55 " \"required_action\":" |
| 56 " [" |
| 57 " ]" |
| 58 "}"; |
| 59 |
| 60 } // end anonymous namespace |
| 61 |
| 62 namespace wallet { |
| 63 |
| 64 class FullWalletTest : public testing::Test { |
| 65 public: |
| 66 FullWalletTest() {} |
| 67 virtual void SetUp() { |
| 68 dict.reset(); |
| 69 } |
| 70 protected: |
| 71 void SetUpDictionary(const std::string& json) { |
| 72 scoped_ptr<Value> value(base::JSONReader::Read(json)); |
| 73 if (value.get() && value->IsType(Value::TYPE_DICTIONARY)) { |
| 74 dict.reset(static_cast<DictionaryValue*>(value.release())); |
| 75 } |
| 76 } |
| 77 scoped_ptr<DictionaryValue> dict; |
| 78 }; |
| 79 |
| 80 TEST_F(FullWalletTest, FromDictionary) { |
| 81 SetUpDictionary(kFullWalletValidResponse); |
| 82 Address* billing_address = new Address("country_name_code", |
| 83 "recipient_name", |
| 84 "address_line_1", |
| 85 "address_line_2", |
| 86 "locality_name", |
| 87 "administrative_area_name", |
| 88 "postal_code_number", |
| 89 "phone_number", |
| 90 "id"); |
| 91 Address* shipping_address = new Address("ship_country_name_code", |
| 92 "ship_recipient_name", |
| 93 "ship_address_line_1", |
| 94 "ship_address_line_2", |
| 95 "ship_locality_name", |
| 96 "ship_administrative_area_name", |
| 97 "ship_postal_code_number", |
| 98 "ship_phone_number", |
| 99 "ship_id"); |
| 100 std::vector<std::string> required_actions; |
| 101 FullWallet fullWallet(12, |
| 102 2012, |
| 103 "iin", |
| 104 "rest", |
| 105 billing_address, |
| 106 shipping_address, |
| 107 required_actions); |
| 108 ASSERT_EQ(fullWallet, *FullWallet::FromDictionary(dict.get()).get()); |
| 109 } |
| 110 |
| 111 } // end wallet namespace |
OLD | NEW |