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/wallet_address.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace { |
| 12 static const char kAddressMissingObjectId[] = |
| 13 "{" |
| 14 " \"phone_number\":\"phone_number\"," |
| 15 " \"postal_address\":" |
| 16 " {" |
| 17 " \"recipient_name\":\"recipient_name\"," |
| 18 " \"address_line\":" |
| 19 " [" |
| 20 " \"address_line_1\"," |
| 21 " \"address_line_2\"" |
| 22 " ]," |
| 23 " \"locality_name\":\"locality_name\"," |
| 24 " \"administrative_area_name\":\"administrative_area_name\"," |
| 25 " \"postal_code_number\":\"postal_code_number\"," |
| 26 " \"country_name_code\":\"country_name_code\"" |
| 27 " }" |
| 28 "}"; |
| 29 |
| 30 static const char kAddressMissingCountryNameCode[] = |
| 31 "{" |
| 32 " \"id\":\"id\"," |
| 33 " \"phone_number\":\"phone_number\"," |
| 34 " \"postal_address\":" |
| 35 " {" |
| 36 " \"recipient_name\":\"recipient_name\"," |
| 37 " \"address_line\":" |
| 38 " [" |
| 39 " \"address_line_1\"," |
| 40 " \"address_line_2\"" |
| 41 " ]," |
| 42 " \"locality_name\":\"locality_name\"," |
| 43 " \"administrative_area_name\":\"administrative_area_name\"," |
| 44 " \"postal_code_number\":\"postal_code_number\"" |
| 45 " }" |
| 46 "}"; |
| 47 |
| 48 static const char kAddressMissingRecipientName[] = |
| 49 "{" |
| 50 " \"id\":\"id\"," |
| 51 " \"phone_number\":\"phone_number\"," |
| 52 " \"postal_address\":" |
| 53 " {" |
| 54 " \"address_line\":" |
| 55 " [" |
| 56 " \"address_line_1\"," |
| 57 " \"address_line_2\"" |
| 58 " ]," |
| 59 " \"locality_name\":\"locality_name\"," |
| 60 " \"administrative_area_name\":\"administrative_area_name\"," |
| 61 " \"postal_code_number\":\"postal_code_number\"," |
| 62 " \"country_name_code\":\"country_name_code\"" |
| 63 " }" |
| 64 "}"; |
| 65 |
| 66 static const char kAddressMissingPostalCodeNumber[] = |
| 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 " \"country_name_code\":\"country_name_code\"" |
| 81 " }" |
| 82 "}"; |
| 83 |
| 84 static const char kValidAddress[] = |
| 85 "{" |
| 86 " \"id\":\"id\"," |
| 87 " \"phone_number\":\"phone_number\"," |
| 88 " \"postal_address\":" |
| 89 " {" |
| 90 " \"recipient_name\":\"recipient_name\"," |
| 91 " \"address_line\":" |
| 92 " [" |
| 93 " \"address_line_1\"," |
| 94 " \"address_line_2\"" |
| 95 " ]," |
| 96 " \"locality_name\":\"locality_name\"," |
| 97 " \"administrative_area_name\":\"administrative_area_name\"," |
| 98 " \"country_name_code\":\"country_name_code\"," |
| 99 " \"postal_code_number\":\"postal_code_number\"" |
| 100 " }" |
| 101 "}"; |
| 102 |
| 103 static const char kClientAddressMissingCountryCode[] = |
| 104 "{" |
| 105 " \"name\":\"name\"," |
| 106 " \"address1\":\"address1\"," |
| 107 " \"address2\":\"address2\"," |
| 108 " \"city\":\"city\"," |
| 109 " \"state\":\"state\"," |
| 110 " \"postal_code\":\"postal_code\"," |
| 111 " \"phone_number\":\"phone_number\"" |
| 112 "}"; |
| 113 |
| 114 static const char kClientAddressMissingPostalCode[] = |
| 115 "{" |
| 116 " \"name\":\"name\"," |
| 117 " \"address1\":\"address1\"," |
| 118 " \"address2\":\"address2\"," |
| 119 " \"city\":\"city\"," |
| 120 " \"state\":\"state\"," |
| 121 " \"phone_number\":\"phone_number\"," |
| 122 " \"country_code\":\"country_code\"" |
| 123 "}"; |
| 124 |
| 125 static const char kClientAddressMissingName[] = |
| 126 "{" |
| 127 " \"address1\":\"address1\"," |
| 128 " \"address2\":\"address2\"," |
| 129 " \"city\":\"city\"," |
| 130 " \"state\":\"state\"," |
| 131 " \"postal_code\":\"postal_code\"," |
| 132 " \"phone_number\":\"phone_number\"," |
| 133 " \"country_code\":\"country_code\"" |
| 134 "}"; |
| 135 |
| 136 static const char kClientValidAddress[] = |
| 137 "{" |
| 138 " \"name\":\"name\"," |
| 139 " \"address1\":\"address1\"," |
| 140 " \"address2\":\"address2\"," |
| 141 " \"city\":\"city\"," |
| 142 " \"state\":\"state\"," |
| 143 " \"postal_code\":\"postal_code\"," |
| 144 " \"phone_number\":\"phone_number\"," |
| 145 " \"country_code\":\"country_code\"" |
| 146 "}"; |
| 147 |
| 148 } // end anonymous namespace |
| 149 |
| 150 namespace wallet { |
| 151 |
| 152 class WalletAddressTest : public testing::Test { |
| 153 public: |
| 154 WalletAddressTest() {} |
| 155 virtual void SetUp() { |
| 156 dict.reset(); |
| 157 } |
| 158 protected: |
| 159 void SetUpDictionary(const std::string& json) { |
| 160 scoped_ptr<Value> value(base::JSONReader::Read(json)); |
| 161 if (value.get() && value->IsType(Value::TYPE_DICTIONARY)) { |
| 162 dict.reset(static_cast<DictionaryValue*>(value.release())); |
| 163 } |
| 164 } |
| 165 scoped_ptr<DictionaryValue> dict; |
| 166 }; |
| 167 |
| 168 TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingObjectId) { |
| 169 SetUpDictionary(kAddressMissingObjectId); |
| 170 ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get())); |
| 171 } |
| 172 |
| 173 TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingCountryNameCode) { |
| 174 SetUpDictionary(kAddressMissingCountryNameCode); |
| 175 ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get())); |
| 176 } |
| 177 |
| 178 TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingRecipientName) { |
| 179 SetUpDictionary(kAddressMissingRecipientName); |
| 180 ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get())); |
| 181 } |
| 182 |
| 183 TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingPostalCodeNumber) { |
| 184 SetUpDictionary(kAddressMissingPostalCodeNumber); |
| 185 ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get())); |
| 186 } |
| 187 |
| 188 TEST_F(WalletAddressTest, CreateFromIdedDictionary) { |
| 189 SetUpDictionary(kValidAddress); |
| 190 Address address("country_name_code", |
| 191 "recipient_name", |
| 192 "address_line_1", |
| 193 "address_line_2", |
| 194 "locality_name", |
| 195 "administrative_area_name", |
| 196 "postal_code_number", |
| 197 "phone_number", |
| 198 "id"); |
| 199 ASSERT_EQ(address, *Address::CreateFromIdedDictionary(dict.get())); |
| 200 } |
| 201 |
| 202 TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingCountryNameCode) { |
| 203 SetUpDictionary(kClientAddressMissingCountryCode); |
| 204 ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get())); |
| 205 } |
| 206 |
| 207 TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingName) { |
| 208 SetUpDictionary(kClientAddressMissingName); |
| 209 ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get())); |
| 210 } |
| 211 |
| 212 TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingPostalCode) { |
| 213 SetUpDictionary(kClientAddressMissingPostalCode); |
| 214 ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get())); |
| 215 } |
| 216 |
| 217 TEST_F(WalletAddressTest, CreateFromDisplayDictionary) { |
| 218 SetUpDictionary(kClientValidAddress); |
| 219 Address address("country_code", |
| 220 "name", |
| 221 "address1", |
| 222 "address2", |
| 223 "city", |
| 224 "state", |
| 225 "postal_code", |
| 226 "phone_number", |
| 227 ""); |
| 228 ASSERT_EQ(address, *Address::CreateFromDisplayDictionary(dict.get())); |
| 229 } |
| 230 |
| 231 } // end wallet namespace |
OLD | NEW |