| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/autofill/content/browser/wallet/wallet_address.h" | 10 #include "components/autofill/content/browser/wallet/wallet_address.h" |
| 11 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
| 11 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
| 12 #include "components/autofill/core/browser/autofill_test_utils.h" | 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 using base::ASCIIToUTF16; | 16 using base::ASCIIToUTF16; |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kAddressMissingObjectId[] = | 20 const char kAddressMissingObjectId[] = |
| 20 "{" | 21 "{" |
| 21 " \"phone_number\":\"phone_number\"," | 22 " \"phone_number\":\"phone_number\"," |
| 22 " \"postal_address\":" | 23 " \"postal_address\":" |
| 23 " {" | 24 " {" |
| 24 " \"recipient_name\":\"recipient_name\"," | 25 " \"recipient_name\":\"recipient_name\"," |
| 25 " \"address_line\":" | 26 " \"address_line\":" |
| 26 " [" | 27 " [" |
| 27 " \"address_line_1\"," | 28 " \"address_line_1\"," |
| 28 " \"address_line_2\"" | 29 " \"address_line_2\"" |
| 29 " ]," | 30 " ]," |
| 30 " \"locality_name\":\"locality_name\"," | 31 " \"locality_name\":\"locality_name\"," |
| 32 " \"dependent_locality_name\":\"dependent_locality_name\"," |
| 31 " \"administrative_area_name\":\"administrative_area_name\"," | 33 " \"administrative_area_name\":\"administrative_area_name\"," |
| 32 " \"postal_code_number\":\"postal_code_number\"," | 34 " \"postal_code_number\":\"postal_code_number\"," |
| 35 " \"sorting_code\":\"sorting_code\"," |
| 33 " \"country_name_code\":\"US\"" | 36 " \"country_name_code\":\"US\"" |
| 34 " }" | 37 " }" |
| 35 "}"; | 38 "}"; |
| 36 | 39 |
| 37 const char kAddressMissingCountryNameCode[] = | 40 const char kAddressMissingCountryNameCode[] = |
| 38 "{" | 41 "{" |
| 39 " \"id\":\"id\"," | 42 " \"id\":\"id\"," |
| 40 " \"phone_number\":\"phone_number\"," | 43 " \"phone_number\":\"phone_number\"," |
| 41 " \"postal_address\":" | 44 " \"postal_address\":" |
| 42 " {" | 45 " {" |
| 43 " \"recipient_name\":\"recipient_name\"," | 46 " \"recipient_name\":\"recipient_name\"," |
| 44 " \"address_line\":" | 47 " \"address_line\":" |
| 45 " [" | 48 " [" |
| 46 " \"address_line_1\"," | 49 " \"address_line_1\"," |
| 47 " \"address_line_2\"" | 50 " \"address_line_2\"" |
| 48 " ]," | 51 " ]," |
| 49 " \"locality_name\":\"locality_name\"," | 52 " \"locality_name\":\"locality_name\"," |
| 53 " \"dependent_locality_name\":\"dependent_locality_name\"," |
| 50 " \"administrative_area_name\":\"administrative_area_name\"," | 54 " \"administrative_area_name\":\"administrative_area_name\"," |
| 51 " \"postal_code_number\":\"postal_code_number\"" | 55 " \"postal_code_number\":\"postal_code_number\"," |
| 56 " \"sorting_code\":\"sorting_code\"" |
| 52 " }" | 57 " }" |
| 53 "}"; | 58 "}"; |
| 54 | 59 |
| 55 const char kAddressMissingRecipientName[] = | 60 const char kAddressMissingRecipientName[] = |
| 56 "{" | 61 "{" |
| 57 " \"id\":\"id\"," | 62 " \"id\":\"id\"," |
| 58 " \"phone_number\":\"phone_number\"," | 63 " \"phone_number\":\"phone_number\"," |
| 59 " \"postal_address\":" | 64 " \"postal_address\":" |
| 60 " {" | 65 " {" |
| 61 " \"address_line\":" | 66 " \"address_line\":" |
| 62 " [" | 67 " [" |
| 63 " \"address_line_1\"," | 68 " \"address_line_1\"," |
| 64 " \"address_line_2\"" | 69 " \"address_line_2\"" |
| 65 " ]," | 70 " ]," |
| 66 " \"locality_name\":\"locality_name\"," | 71 " \"locality_name\":\"locality_name\"," |
| 72 " \"dependent_locality_name\":\"dependent_locality_name\"," |
| 67 " \"administrative_area_name\":\"administrative_area_name\"," | 73 " \"administrative_area_name\":\"administrative_area_name\"," |
| 68 " \"postal_code_number\":\"postal_code_number\"," | 74 " \"postal_code_number\":\"postal_code_number\"," |
| 75 " \"sorting_code\":\"sorting_code\"," |
| 69 " \"country_name_code\":\"US\"" | 76 " \"country_name_code\":\"US\"" |
| 70 " }" | 77 " }" |
| 71 "}"; | 78 "}"; |
| 72 | 79 |
| 73 const char kAddressMissingPostalCodeNumber[] = | 80 const char kAddressMissingPostalCodeNumber[] = |
| 74 "{" | 81 "{" |
| 75 " \"id\":\"id\"," | 82 " \"id\":\"id\"," |
| 76 " \"phone_number\":\"phone_number\"," | 83 " \"phone_number\":\"phone_number\"," |
| 77 " \"postal_address\":" | 84 " \"postal_address\":" |
| 78 " {" | 85 " {" |
| 79 " \"recipient_name\":\"recipient_name\"," | 86 " \"recipient_name\":\"recipient_name\"," |
| 80 " \"address_line\":" | 87 " \"address_line\":" |
| 81 " [" | 88 " [" |
| 82 " \"address_line_1\"," | 89 " \"address_line_1\"," |
| 83 " \"address_line_2\"" | 90 " \"address_line_2\"" |
| 84 " ]," | 91 " ]," |
| 85 " \"locality_name\":\"locality_name\"," | 92 " \"locality_name\":\"locality_name\"," |
| 93 " \"dependent_locality_name\":\"dependent_locality_name\"," |
| 86 " \"administrative_area_name\":\"administrative_area_name\"," | 94 " \"administrative_area_name\":\"administrative_area_name\"," |
| 95 " \"sorting_code\":\"sorting_code\"," |
| 87 " \"country_name_code\":\"US\"" | 96 " \"country_name_code\":\"US\"" |
| 88 " }" | 97 " }" |
| 89 "}"; | 98 "}"; |
| 90 | 99 |
| 91 const char kValidAddress[] = | 100 const char kValidAddress[] = |
| 92 "{" | 101 "{" |
| 93 " \"id\":\"id\"," | 102 " \"id\":\"id\"," |
| 94 " \"phone_number\":\"phone_number\"," | 103 " \"phone_number\":\"phone_number\"," |
| 95 " \"is_minimal_address\":true," | 104 " \"is_minimal_address\":true," |
| 96 " \"postal_address\":" | 105 " \"postal_address\":" |
| 97 " {" | 106 " {" |
| 98 " \"recipient_name\":\"recipient_name\"," | 107 " \"recipient_name\":\"recipient_name\"," |
| 99 " \"address_line\":" | 108 " \"address_line\":" |
| 100 " [" | 109 " [" |
| 101 " \"address_line_1\"," | 110 " \"address_line_1\"," |
| 102 " \"address_line_2\"" | 111 " \"address_line_2\"" |
| 103 " ]," | 112 " ]," |
| 104 " \"locality_name\":\"locality_name\"," | 113 " \"locality_name\":\"locality_name\"," |
| 114 " \"dependent_locality_name\":\"dependent_locality_name\"," |
| 105 " \"administrative_area_name\":\"administrative_area_name\"," | 115 " \"administrative_area_name\":\"administrative_area_name\"," |
| 106 " \"country_name_code\":\"US\"," | 116 " \"country_name_code\":\"US\"," |
| 107 " \"postal_code_number\":\"postal_code_number\"" | 117 " \"postal_code_number\":\"postal_code_number\"," |
| 118 " \"sorting_code\":\"sorting_code\"" |
| 108 " }" | 119 " }" |
| 109 "}"; | 120 "}"; |
| 110 | 121 |
| 111 const char kClientAddressMissingCountryCode[] = | 122 const char kClientAddressMissingCountryCode[] = |
| 112 "{" | 123 "{" |
| 113 " \"name\":\"name\"," | 124 " \"name\":\"name\"," |
| 114 " \"address1\":\"address1\"," | 125 " \"address1\":\"address1\"," |
| 115 " \"address2\":\"address2\"," | 126 " \"address2\":\"address2\"," |
| 116 " \"city\":\"city\"," | 127 " \"city\":\"city\"," |
| 117 " \"state\":\"state\"," | 128 " \"state\":\"state\"," |
| 118 " \"postal_code\":\"postal_code\"," | 129 " \"postal_code\":\"postal_code\"," |
| 130 " \"sorting_code\":\"sorting_code\"," |
| 119 " \"phone_number\":\"phone_number\"" | 131 " \"phone_number\":\"phone_number\"" |
| 120 "}"; | 132 "}"; |
| 121 | 133 |
| 122 const char kClientAddressMissingPostalCode[] = | 134 const char kClientAddressMissingPostalCode[] = |
| 123 "{" | 135 "{" |
| 124 " \"name\":\"name\"," | 136 " \"name\":\"name\"," |
| 125 " \"address1\":\"address1\"," | 137 " \"address1\":\"address1\"," |
| 126 " \"address2\":\"address2\"," | 138 " \"address2\":\"address2\"," |
| 127 " \"city\":\"city\"," | 139 " \"city\":\"city\"," |
| 128 " \"state\":\"state\"," | 140 " \"state\":\"state\"," |
| 129 " \"phone_number\":\"phone_number\"," | 141 " \"phone_number\":\"phone_number\"," |
| 130 " \"country_code\":\"US\"" | 142 " \"country_code\":\"US\"" |
| 131 "}"; | 143 "}"; |
| 132 | 144 |
| 133 const char kClientAddressMissingName[] = | 145 const char kClientAddressMissingName[] = |
| 134 "{" | 146 "{" |
| 135 " \"address1\":\"address1\"," | 147 " \"address1\":\"address1\"," |
| 136 " \"address2\":\"address2\"," | 148 " \"address2\":\"address2\"," |
| 137 " \"city\":\"city\"," | 149 " \"city\":\"city\"," |
| 138 " \"state\":\"state\"," | 150 " \"state\":\"state\"," |
| 139 " \"postal_code\":\"postal_code\"," | 151 " \"postal_code\":\"postal_code\"," |
| 152 " \"sorting_code\":\"sorting_code\"," |
| 140 " \"phone_number\":\"phone_number\"," | 153 " \"phone_number\":\"phone_number\"," |
| 141 " \"country_code\":\"US\"" | 154 " \"country_code\":\"US\"" |
| 142 "}"; | 155 "}"; |
| 143 | 156 |
| 144 const char kClientValidAddress[] = | 157 const char kClientValidAddress[] = |
| 145 "{" | 158 "{" |
| 146 " \"name\":\"name\"," | 159 " \"name\":\"name\"," |
| 147 " \"address1\":\"address1\"," | 160 " \"address1\":\"address1\"," |
| 148 " \"address2\":\"address2\"," | 161 " \"address2\":\"address2\"," |
| 149 " \"city\":\"city\"," | 162 " \"city\":\"city\"," |
| 163 " \"dependent_locality_name\":\"district\"," |
| 150 " \"state\":\"state\"," | 164 " \"state\":\"state\"," |
| 151 " \"postal_code\":\"postal_code\"," | 165 " \"postal_code\":\"postal_code\"," |
| 166 " \"sorting_code\":\"sorting_code\"," |
| 152 " \"phone_number\":\"phone_number\"," | 167 " \"phone_number\":\"phone_number\"," |
| 153 " \"country_code\":\"US\"," | 168 " \"country_code\":\"US\"," |
| 154 " \"type\":\"FULL\"" | 169 " \"type\":\"FULL\"" |
| 155 "}"; | 170 "}"; |
| 156 | 171 |
| 157 } // anonymous namespace | 172 } // anonymous namespace |
| 158 | 173 |
| 159 namespace autofill { | 174 namespace autofill { |
| 160 namespace wallet { | 175 namespace wallet { |
| 161 | 176 |
| 162 class WalletAddressTest : public testing::Test { | 177 class WalletAddressTest : public testing::Test { |
| 163 public: | 178 public: |
| 164 WalletAddressTest() {} | 179 WalletAddressTest() {} |
| 165 protected: | 180 protected: |
| 166 void SetUpDictionary(const std::string& json) { | 181 void SetUpDictionary(const std::string& json) { |
| 167 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 182 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
| 168 DCHECK(value.get()); | 183 DCHECK(value.get()); |
| 169 DCHECK(value->IsType(base::Value::TYPE_DICTIONARY)); | 184 DCHECK(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 170 dict_.reset(static_cast<base::DictionaryValue*>(value.release())); | 185 dict_.reset(static_cast<base::DictionaryValue*>(value.release())); |
| 171 } | 186 } |
| 187 |
| 172 scoped_ptr<const base::DictionaryValue> dict_; | 188 scoped_ptr<const base::DictionaryValue> dict_; |
| 173 }; | 189 }; |
| 174 | 190 |
| 175 TEST_F(WalletAddressTest, AddressEqualsIgnoreID) { | 191 TEST_F(WalletAddressTest, AddressEqualsIgnoreID) { |
| 176 Address address1("US", | 192 Address address1("US", |
| 177 ASCIIToUTF16("recipient_name"), | 193 ASCIIToUTF16("recipient_name"), |
| 178 ASCIIToUTF16("address_line_1"), | 194 StreetAddress("address_line_1", "address_line_2"), |
| 179 ASCIIToUTF16("address_line_2"), | |
| 180 ASCIIToUTF16("locality_name"), | 195 ASCIIToUTF16("locality_name"), |
| 196 ASCIIToUTF16("dependent_locality_name"), |
| 181 ASCIIToUTF16("administrative_area_name"), | 197 ASCIIToUTF16("administrative_area_name"), |
| 182 ASCIIToUTF16("postal_code_number"), | 198 ASCIIToUTF16("postal_code_number"), |
| 199 ASCIIToUTF16("sorting_code"), |
| 183 ASCIIToUTF16("phone_number"), | 200 ASCIIToUTF16("phone_number"), |
| 184 "id1"); | 201 "id1"); |
| 185 // Same as address1, only id is different. | 202 // Same as address1, only id is different. |
| 186 Address address2("US", | 203 Address address2("US", |
| 187 ASCIIToUTF16("recipient_name"), | 204 ASCIIToUTF16("recipient_name"), |
| 188 ASCIIToUTF16("address_line_1"), | 205 StreetAddress("address_line_1", "address_line_2"), |
| 189 ASCIIToUTF16("address_line_2"), | |
| 190 ASCIIToUTF16("locality_name"), | 206 ASCIIToUTF16("locality_name"), |
| 207 ASCIIToUTF16("dependent_locality_name"), |
| 191 ASCIIToUTF16("administrative_area_name"), | 208 ASCIIToUTF16("administrative_area_name"), |
| 192 ASCIIToUTF16("postal_code_number"), | 209 ASCIIToUTF16("postal_code_number"), |
| 210 ASCIIToUTF16("sorting_code"), |
| 193 ASCIIToUTF16("phone_number"), | 211 ASCIIToUTF16("phone_number"), |
| 194 "id2"); | 212 "id2"); |
| 195 // Has same id as address1, but name is different. | 213 // Has same id as address1, but name is different. |
| 196 Address address3("US", | 214 Address address3("US", |
| 197 ASCIIToUTF16("a_different_name"), | 215 ASCIIToUTF16("a_different_name"), |
| 198 ASCIIToUTF16("address_line_1"), | 216 StreetAddress("address_line_1", "address_line_2"), |
| 199 ASCIIToUTF16("address_line_2"), | |
| 200 ASCIIToUTF16("locality_name"), | 217 ASCIIToUTF16("locality_name"), |
| 218 ASCIIToUTF16("dependent_locality_name"), |
| 201 ASCIIToUTF16("administrative_area_name"), | 219 ASCIIToUTF16("administrative_area_name"), |
| 220 ASCIIToUTF16("phone_number"), |
| 202 ASCIIToUTF16("postal_code_number"), | 221 ASCIIToUTF16("postal_code_number"), |
| 203 ASCIIToUTF16("phone_number"), | 222 ASCIIToUTF16("sorting_code"), |
| 204 "id1"); | 223 "id1"); |
| 205 // Same as address1, but no id. | 224 // Same as address1, but no id. |
| 206 Address address4("US", | 225 Address address4("US", |
| 207 ASCIIToUTF16("recipient_name"), | 226 ASCIIToUTF16("recipient_name"), |
| 208 ASCIIToUTF16("address_line_1"), | 227 StreetAddress("address_line_1", "address_line_2"), |
| 209 ASCIIToUTF16("address_line_2"), | |
| 210 ASCIIToUTF16("locality_name"), | 228 ASCIIToUTF16("locality_name"), |
| 229 ASCIIToUTF16("dependent_locality_name"), |
| 211 ASCIIToUTF16("administrative_area_name"), | 230 ASCIIToUTF16("administrative_area_name"), |
| 212 ASCIIToUTF16("postal_code_number"), | 231 ASCIIToUTF16("postal_code_number"), |
| 232 ASCIIToUTF16("sorting_code"), |
| 213 ASCIIToUTF16("phone_number"), | 233 ASCIIToUTF16("phone_number"), |
| 214 std::string()); | 234 std::string()); |
| 215 | 235 |
| 216 // Compare the address has id field to itself. | 236 // Compare the address has id field to itself. |
| 217 EXPECT_EQ(address1, address1); | 237 EXPECT_EQ(address1, address1); |
| 218 EXPECT_TRUE(address1.EqualsIgnoreID(address1)); | 238 EXPECT_TRUE(address1.EqualsIgnoreID(address1)); |
| 219 | 239 |
| 220 // Compare the address has no id field to itself | 240 // Compare the address has no id field to itself |
| 221 EXPECT_EQ(address4, address4); | 241 EXPECT_EQ(address4, address4); |
| 222 EXPECT_TRUE(address4.EqualsIgnoreID(address4)); | 242 EXPECT_TRUE(address4.EqualsIgnoreID(address4)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 234 // Compare two same addresses, one has id, the other doesn't. | 254 // Compare two same addresses, one has id, the other doesn't. |
| 235 EXPECT_NE(address1, address4); | 255 EXPECT_NE(address1, address4); |
| 236 EXPECT_TRUE(address1.EqualsIgnoreID(address4)); | 256 EXPECT_TRUE(address1.EqualsIgnoreID(address4)); |
| 237 EXPECT_TRUE(address4.EqualsIgnoreID(address1)); | 257 EXPECT_TRUE(address4.EqualsIgnoreID(address1)); |
| 238 } | 258 } |
| 239 | 259 |
| 240 TEST_F(WalletAddressTest, CreateAddressMissingObjectId) { | 260 TEST_F(WalletAddressTest, CreateAddressMissingObjectId) { |
| 241 SetUpDictionary(kAddressMissingObjectId); | 261 SetUpDictionary(kAddressMissingObjectId); |
| 242 Address address("US", | 262 Address address("US", |
| 243 ASCIIToUTF16("recipient_name"), | 263 ASCIIToUTF16("recipient_name"), |
| 244 ASCIIToUTF16("address_line_1"), | 264 StreetAddress("address_line_1", "address_line_2"), |
| 245 ASCIIToUTF16("address_line_2"), | |
| 246 ASCIIToUTF16("locality_name"), | 265 ASCIIToUTF16("locality_name"), |
| 266 ASCIIToUTF16("dependent_locality_name"), |
| 247 ASCIIToUTF16("administrative_area_name"), | 267 ASCIIToUTF16("administrative_area_name"), |
| 248 ASCIIToUTF16("postal_code_number"), | 268 ASCIIToUTF16("postal_code_number"), |
| 269 ASCIIToUTF16("sorting_code"), |
| 249 ASCIIToUTF16("phone_number"), | 270 ASCIIToUTF16("phone_number"), |
| 250 std::string()); | 271 std::string()); |
| 251 EXPECT_EQ(address, *Address::CreateAddress(*dict_)); | 272 EXPECT_EQ(address, *Address::CreateAddress(*dict_)); |
| 252 } | 273 } |
| 253 | 274 |
| 254 TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) { | 275 TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) { |
| 255 SetUpDictionary(kAddressMissingObjectId); | 276 SetUpDictionary(kAddressMissingObjectId); |
| 256 EXPECT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); | 277 EXPECT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); |
| 257 } | 278 } |
| 258 | 279 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 271 TEST_F(WalletAddressTest, CreateAddressMissingPostalCodeNumber) { | 292 TEST_F(WalletAddressTest, CreateAddressMissingPostalCodeNumber) { |
| 272 SetUpDictionary(kAddressMissingPostalCodeNumber); | 293 SetUpDictionary(kAddressMissingPostalCodeNumber); |
| 273 EXPECT_EQ(NULL, Address::CreateAddress(*dict_).get()); | 294 EXPECT_EQ(NULL, Address::CreateAddress(*dict_).get()); |
| 274 EXPECT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); | 295 EXPECT_EQ(NULL, Address::CreateAddressWithID(*dict_).get()); |
| 275 } | 296 } |
| 276 | 297 |
| 277 TEST_F(WalletAddressTest, CreateAddressWithID) { | 298 TEST_F(WalletAddressTest, CreateAddressWithID) { |
| 278 SetUpDictionary(kValidAddress); | 299 SetUpDictionary(kValidAddress); |
| 279 Address address("US", | 300 Address address("US", |
| 280 ASCIIToUTF16("recipient_name"), | 301 ASCIIToUTF16("recipient_name"), |
| 281 ASCIIToUTF16("address_line_1"), | 302 StreetAddress("address_line_1", "address_line_2"), |
| 282 ASCIIToUTF16("address_line_2"), | |
| 283 ASCIIToUTF16("locality_name"), | 303 ASCIIToUTF16("locality_name"), |
| 304 ASCIIToUTF16("dependent_locality_name"), |
| 284 ASCIIToUTF16("administrative_area_name"), | 305 ASCIIToUTF16("administrative_area_name"), |
| 285 ASCIIToUTF16("postal_code_number"), | 306 ASCIIToUTF16("postal_code_number"), |
| 307 ASCIIToUTF16("sorting_code"), |
| 286 ASCIIToUTF16("phone_number"), | 308 ASCIIToUTF16("phone_number"), |
| 287 "id"); | 309 "id"); |
| 288 address.set_is_complete_address(false); | 310 address.set_is_complete_address(false); |
| 289 EXPECT_EQ(address, *Address::CreateAddress(*dict_)); | 311 EXPECT_EQ(address, *Address::CreateAddress(*dict_)); |
| 290 EXPECT_EQ(address, *Address::CreateAddressWithID(*dict_)); | 312 EXPECT_EQ(address, *Address::CreateAddressWithID(*dict_)); |
| 291 } | 313 } |
| 292 | 314 |
| 293 TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) { | 315 TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) { |
| 294 SetUpDictionary(kClientAddressMissingCountryCode); | 316 SetUpDictionary(kClientAddressMissingCountryCode); |
| 295 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); | 317 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); |
| 296 } | 318 } |
| 297 | 319 |
| 298 TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) { | 320 TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) { |
| 299 SetUpDictionary(kClientAddressMissingName); | 321 SetUpDictionary(kClientAddressMissingName); |
| 300 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); | 322 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); |
| 301 } | 323 } |
| 302 | 324 |
| 303 TEST_F(WalletAddressTest, CreateDisplayAddressMissingPostalCode) { | 325 TEST_F(WalletAddressTest, CreateDisplayAddressMissingPostalCode) { |
| 304 SetUpDictionary(kClientAddressMissingPostalCode); | 326 SetUpDictionary(kClientAddressMissingPostalCode); |
| 305 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); | 327 EXPECT_EQ(NULL, Address::CreateDisplayAddress(*dict_).get()); |
| 306 } | 328 } |
| 307 | 329 |
| 308 TEST_F(WalletAddressTest, CreateDisplayAddress) { | 330 TEST_F(WalletAddressTest, CreateDisplayAddress) { |
| 309 SetUpDictionary(kClientValidAddress); | 331 SetUpDictionary(kClientValidAddress); |
| 310 Address address("US", | 332 Address address("US", |
| 311 ASCIIToUTF16("name"), | 333 ASCIIToUTF16("name"), |
| 312 ASCIIToUTF16("address1"), | 334 StreetAddress("address1", "address2"), |
| 313 ASCIIToUTF16("address2"), | |
| 314 ASCIIToUTF16("city"), | 335 ASCIIToUTF16("city"), |
| 336 ASCIIToUTF16("district"), |
| 315 ASCIIToUTF16("state"), | 337 ASCIIToUTF16("state"), |
| 316 ASCIIToUTF16("postal_code"), | 338 ASCIIToUTF16("postal_code"), |
| 339 ASCIIToUTF16("sorting_code"), |
| 317 ASCIIToUTF16("phone_number"), | 340 ASCIIToUTF16("phone_number"), |
| 318 std::string()); | 341 std::string()); |
| 319 EXPECT_EQ(address, *Address::CreateDisplayAddress(*dict_)); | 342 EXPECT_EQ(address, *Address::CreateDisplayAddress(*dict_)); |
| 320 } | 343 } |
| 321 | 344 |
| 322 TEST_F(WalletAddressTest, ToDictionaryWithoutID) { | 345 TEST_F(WalletAddressTest, ToDictionaryWithoutID) { |
| 323 base::DictionaryValue expected; | 346 base::DictionaryValue expected; |
| 324 expected.SetString("country_name_code", | 347 expected.SetString("country_name_code", |
| 325 "US"); | 348 "US"); |
| 326 expected.SetString("recipient_name", | 349 expected.SetString("recipient_name", |
| 327 "recipient_name"); | 350 "recipient_name"); |
| 328 expected.SetString("locality_name", | 351 expected.SetString("locality_name", |
| 329 "locality_name"); | 352 "locality_name"); |
| 353 expected.SetString("dependent_locality_name", |
| 354 "dependent_locality_name"); |
| 330 expected.SetString("administrative_area_name", | 355 expected.SetString("administrative_area_name", |
| 331 "administrative_area_name"); | 356 "administrative_area_name"); |
| 332 expected.SetString("postal_code_number", | 357 expected.SetString("postal_code_number", |
| 333 "postal_code_number"); | 358 "postal_code_number"); |
| 359 expected.SetString("sorting_code", |
| 360 "sorting_code"); |
| 334 base::ListValue* address_lines = new base::ListValue(); | 361 base::ListValue* address_lines = new base::ListValue(); |
| 335 address_lines->AppendString("address_line_1"); | 362 address_lines->AppendString("address_line_1"); |
| 336 address_lines->AppendString("address_line_2"); | 363 address_lines->AppendString("address_line_2"); |
| 337 expected.Set("address_line", address_lines); | 364 expected.Set("address_line", address_lines); |
| 338 | 365 |
| 339 Address address("US", | 366 Address address("US", |
| 340 ASCIIToUTF16("recipient_name"), | 367 ASCIIToUTF16("recipient_name"), |
| 341 ASCIIToUTF16("address_line_1"), | 368 StreetAddress("address_line_1", "address_line_2"), |
| 342 ASCIIToUTF16("address_line_2"), | |
| 343 ASCIIToUTF16("locality_name"), | 369 ASCIIToUTF16("locality_name"), |
| 370 ASCIIToUTF16("dependent_locality_name"), |
| 344 ASCIIToUTF16("administrative_area_name"), | 371 ASCIIToUTF16("administrative_area_name"), |
| 345 ASCIIToUTF16("postal_code_number"), | 372 ASCIIToUTF16("postal_code_number"), |
| 373 ASCIIToUTF16("sorting_code"), |
| 346 ASCIIToUTF16("phone_number"), | 374 ASCIIToUTF16("phone_number"), |
| 347 std::string()); | 375 std::string()); |
| 348 | |
| 349 EXPECT_TRUE(expected.Equals(address.ToDictionaryWithoutID().get())); | |
| 350 } | 376 } |
| 351 | 377 |
| 352 TEST_F(WalletAddressTest, ToDictionaryWithID) { | 378 TEST_F(WalletAddressTest, ToDictionaryWithID) { |
| 353 base::DictionaryValue expected; | 379 base::DictionaryValue expected; |
| 354 expected.SetString("id", "id"); | 380 expected.SetString("id", "id"); |
| 355 expected.SetString("phone_number", "phone_number"); | 381 expected.SetString("phone_number", "phone_number"); |
| 356 expected.SetString("postal_address.country_name_code", | 382 expected.SetString("postal_address.country_name_code", |
| 357 "US"); | 383 "US"); |
| 358 expected.SetString("postal_address.recipient_name", | 384 expected.SetString("postal_address.recipient_name", |
| 359 "recipient_name"); | 385 "recipient_name"); |
| 360 expected.SetString("postal_address.locality_name", | 386 expected.SetString("postal_address.locality_name", |
| 361 "locality_name"); | 387 "locality_name"); |
| 388 expected.SetString("postal_address.dependent_locality_name", |
| 389 "dependent_locality_name"); |
| 362 expected.SetString("postal_address.administrative_area_name", | 390 expected.SetString("postal_address.administrative_area_name", |
| 363 "administrative_area_name"); | 391 "administrative_area_name"); |
| 364 expected.SetString("postal_address.postal_code_number", | 392 expected.SetString("postal_address.postal_code_number", |
| 365 "postal_code_number"); | 393 "postal_code_number"); |
| 394 expected.SetString("postal_address.sorting_code", |
| 395 "sorting_code"); |
| 366 base::ListValue* address_lines = new base::ListValue(); | 396 base::ListValue* address_lines = new base::ListValue(); |
| 367 address_lines->AppendString("address_line_1"); | 397 address_lines->AppendString("address_line_1"); |
| 368 address_lines->AppendString("address_line_2"); | 398 address_lines->AppendString("address_line_2"); |
| 369 expected.Set("postal_address.address_line", address_lines); | 399 expected.Set("postal_address.address_line", address_lines); |
| 370 | 400 |
| 371 Address address("US", | 401 Address address("US", |
| 372 ASCIIToUTF16("recipient_name"), | 402 ASCIIToUTF16("recipient_name"), |
| 373 ASCIIToUTF16("address_line_1"), | 403 StreetAddress("address_line_1", "address_line_2"), |
| 374 ASCIIToUTF16("address_line_2"), | |
| 375 ASCIIToUTF16("locality_name"), | 404 ASCIIToUTF16("locality_name"), |
| 405 ASCIIToUTF16("dependent_locality_name"), |
| 376 ASCIIToUTF16("administrative_area_name"), | 406 ASCIIToUTF16("administrative_area_name"), |
| 377 ASCIIToUTF16("postal_code_number"), | 407 ASCIIToUTF16("postal_code_number"), |
| 408 ASCIIToUTF16("sorting_code"), |
| 378 ASCIIToUTF16("phone_number"), | 409 ASCIIToUTF16("phone_number"), |
| 379 "id"); | 410 "id"); |
| 380 | 411 |
| 381 EXPECT_TRUE(expected.Equals(address.ToDictionaryWithID().get())); | 412 EXPECT_TRUE(expected.Equals(address.ToDictionaryWithID().get())); |
| 382 } | 413 } |
| 383 | 414 |
| 384 // Verifies that WalletAddress::GetInfo() can correctly return both country | 415 // Verifies that WalletAddress::GetInfo() can correctly return both country |
| 385 // codes and localized country names. | 416 // codes and localized country names. |
| 386 TEST_F(WalletAddressTest, GetCountryInfo) { | 417 TEST_F(WalletAddressTest, GetCountryInfo) { |
| 387 Address address("FR", | 418 Address address("FR", |
| 388 ASCIIToUTF16("recipient_name"), | 419 ASCIIToUTF16("recipient_name"), |
| 389 ASCIIToUTF16("address_line_1"), | 420 StreetAddress("address_line_1", "address_line_2"), |
| 390 ASCIIToUTF16("address_line_2"), | |
| 391 ASCIIToUTF16("locality_name"), | 421 ASCIIToUTF16("locality_name"), |
| 422 ASCIIToUTF16("dependent_locality_name"), |
| 392 ASCIIToUTF16("administrative_area_name"), | 423 ASCIIToUTF16("administrative_area_name"), |
| 393 ASCIIToUTF16("postal_code_number"), | 424 ASCIIToUTF16("postal_code_number"), |
| 425 ASCIIToUTF16("sorting_code"), |
| 394 ASCIIToUTF16("phone_number"), | 426 ASCIIToUTF16("phone_number"), |
| 395 "id1"); | 427 "id1"); |
| 396 | 428 |
| 397 AutofillType type = AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE); | 429 AutofillType type = AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE); |
| 398 EXPECT_EQ(ASCIIToUTF16("FR"), address.GetInfo(type, "en-US")); | 430 EXPECT_EQ(ASCIIToUTF16("FR"), address.GetInfo(type, "en-US")); |
| 399 | 431 |
| 400 type = AutofillType(HTML_TYPE_COUNTRY_NAME, HTML_MODE_NONE); | 432 type = AutofillType(HTML_TYPE_COUNTRY_NAME, HTML_MODE_NONE); |
| 401 EXPECT_EQ(ASCIIToUTF16("France"), address.GetInfo(type, "en-US")); | 433 EXPECT_EQ(ASCIIToUTF16("France"), address.GetInfo(type, "en-US")); |
| 402 | 434 |
| 403 type = AutofillType(ADDRESS_HOME_COUNTRY); | 435 type = AutofillType(ADDRESS_HOME_COUNTRY); |
| 404 EXPECT_EQ(ASCIIToUTF16("France"), address.GetInfo(type, "en-US")); | 436 EXPECT_EQ(ASCIIToUTF16("France"), address.GetInfo(type, "en-US")); |
| 405 } | 437 } |
| 406 | 438 |
| 407 // Verifies that WalletAddress::GetInfo() can correctly return a concatenated | 439 // Verifies that WalletAddress::GetInfo() can correctly return a concatenated |
| 408 // full street address. | 440 // full street address. |
| 409 TEST_F(WalletAddressTest, GetStreetAddress) { | 441 TEST_F(WalletAddressTest, GetStreetAddress) { |
| 442 std::vector<base::string16> street_address = StreetAddress( |
| 443 "address_line_1", "address_line_2"); |
| 410 // Address has both lines 1 and 2. | 444 // Address has both lines 1 and 2. |
| 411 Address address1("FR", | 445 Address address1("FR", |
| 412 ASCIIToUTF16("recipient_name"), | 446 ASCIIToUTF16("recipient_name"), |
| 413 ASCIIToUTF16("address_line_1"), | 447 street_address, |
| 414 ASCIIToUTF16("address_line_2"), | |
| 415 ASCIIToUTF16("locality_name"), | 448 ASCIIToUTF16("locality_name"), |
| 449 ASCIIToUTF16("dependent_locality_name"), |
| 416 ASCIIToUTF16("administrative_area_name"), | 450 ASCIIToUTF16("administrative_area_name"), |
| 417 ASCIIToUTF16("postal_code_number"), | 451 ASCIIToUTF16("postal_code_number"), |
| 452 ASCIIToUTF16("sorting_code"), |
| 418 ASCIIToUTF16("phone_number"), | 453 ASCIIToUTF16("phone_number"), |
| 419 "id1"); | 454 "id1"); |
| 420 AutofillType type = AutofillType(HTML_TYPE_STREET_ADDRESS, HTML_MODE_NONE); | 455 AutofillType type = AutofillType(HTML_TYPE_STREET_ADDRESS, HTML_MODE_NONE); |
| 421 EXPECT_EQ(ASCIIToUTF16("address_line_1\naddress_line_2"), | 456 EXPECT_EQ(ASCIIToUTF16("address_line_1\naddress_line_2"), |
| 422 address1.GetInfo(type, "en-US")); | 457 address1.GetInfo(type, "en-US")); |
| 423 | 458 |
| 424 // Address has only line 1. | 459 // Address has only line 1. |
| 460 street_address.resize(1); |
| 425 Address address2("FR", | 461 Address address2("FR", |
| 426 ASCIIToUTF16("recipient_name"), | 462 ASCIIToUTF16("recipient_name"), |
| 427 ASCIIToUTF16("address_line_1"), | 463 street_address, |
| 428 base::string16(), | |
| 429 ASCIIToUTF16("locality_name"), | 464 ASCIIToUTF16("locality_name"), |
| 465 ASCIIToUTF16("dependent_locality_name"), |
| 430 ASCIIToUTF16("administrative_area_name"), | 466 ASCIIToUTF16("administrative_area_name"), |
| 431 ASCIIToUTF16("postal_code_number"), | 467 ASCIIToUTF16("postal_code_number"), |
| 468 ASCIIToUTF16("sorting_code"), |
| 432 ASCIIToUTF16("phone_number"), | 469 ASCIIToUTF16("phone_number"), |
| 433 "id1"); | 470 "id1"); |
| 434 EXPECT_EQ(ASCIIToUTF16("address_line_1"), address2.GetInfo(type, "en-US")); | 471 EXPECT_EQ(ASCIIToUTF16("address_line_1"), address2.GetInfo(type, "en-US")); |
| 435 | 472 |
| 436 // Address has no address lines. | 473 // Address has no address lines. |
| 474 street_address.clear(); |
| 437 Address address3("FR", | 475 Address address3("FR", |
| 438 ASCIIToUTF16("recipient_name"), | 476 ASCIIToUTF16("recipient_name"), |
| 439 base::string16(), | 477 street_address, |
| 440 base::string16(), | |
| 441 ASCIIToUTF16("locality_name"), | 478 ASCIIToUTF16("locality_name"), |
| 479 ASCIIToUTF16("dependent_locality_name"), |
| 442 ASCIIToUTF16("administrative_area_name"), | 480 ASCIIToUTF16("administrative_area_name"), |
| 443 ASCIIToUTF16("postal_code_number"), | 481 ASCIIToUTF16("postal_code_number"), |
| 482 ASCIIToUTF16("sorting_code"), |
| 444 ASCIIToUTF16("phone_number"), | 483 ASCIIToUTF16("phone_number"), |
| 445 "id1"); | 484 "id1"); |
| 446 EXPECT_EQ(base::string16(), address3.GetInfo(type, "en-US")); | 485 EXPECT_EQ(base::string16(), address3.GetInfo(type, "en-US")); |
| 447 } | 486 } |
| 448 | 487 |
| 449 } // namespace wallet | 488 } // namespace wallet |
| 450 } // namespace autofill | 489 } // namespace autofill |
| OLD | NEW |