| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/json/json_reader.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "base/values.h" | |
| 9 #include "components/autofill/content/browser/wallet/gaia_account.h" | |
| 10 #include "components/autofill/content/browser/wallet/required_action.h" | |
| 11 #include "components/autofill/content/browser/wallet/wallet_items.h" | |
| 12 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 #include "url/gurl.h" | |
| 15 | |
| 16 using base::ASCIIToUTF16; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char kMaskedInstrument[] = | |
| 21 "{" | |
| 22 " \"descriptive_name\":\"descriptive_name\"," | |
| 23 " \"type\":\"VISA\"," | |
| 24 " \"last_four_digits\":\"last_four_digits\"," | |
| 25 " \"expiration_month\":12," | |
| 26 " \"expiration_year\":2012," | |
| 27 " \"billing_address\":" | |
| 28 " {" | |
| 29 " \"name\":\"name\"," | |
| 30 " \"address1\":\"address1\"," | |
| 31 " \"address2\":\"address2\"," | |
| 32 " \"city\":\"city\"," | |
| 33 " \"dependent_locality_name\":\"burough\"," | |
| 34 " \"state\":\"state\"," | |
| 35 " \"postal_code\":\"postal_code\"," | |
| 36 " \"sorting_code\":\"sorting_code\"," | |
| 37 " \"phone_number\":\"phone_number\"," | |
| 38 " \"country_code\":\"US\"," | |
| 39 " \"type\":\"FULL\"," | |
| 40 " \"language_code\":\"language_code\"" | |
| 41 " }," | |
| 42 " \"status\":\"VALID\"," | |
| 43 " \"object_id\":\"object_id\"" | |
| 44 "}"; | |
| 45 | |
| 46 const char kMaskedInstrumentMissingStatus[] = | |
| 47 "{" | |
| 48 " \"descriptive_name\":\"descriptive_name\"," | |
| 49 " \"type\":\"VISA\"," | |
| 50 " \"last_four_digits\":\"last_four_digits\"," | |
| 51 " \"expiration_month\":12," | |
| 52 " \"expiration_year\":2012," | |
| 53 " \"billing_address\":" | |
| 54 " {" | |
| 55 " \"name\":\"name\"," | |
| 56 " \"address1\":\"address1\"," | |
| 57 " \"address2\":\"address2\"," | |
| 58 " \"city\":\"city\"," | |
| 59 " \"dependent_locality_name\":\"burough\"," | |
| 60 " \"state\":\"state\"," | |
| 61 " \"postal_code\":\"postal_code\"," | |
| 62 " \"sorting_code\":\"sorting_code\"," | |
| 63 " \"phone_number\":\"phone_number\"," | |
| 64 " \"country_code\":\"US\"," | |
| 65 " \"language_code\":\"language_code\"" | |
| 66 " }," | |
| 67 " \"object_id\":\"object_id\"," | |
| 68 " \"amex_disallowed\":true" | |
| 69 "}"; | |
| 70 | |
| 71 const char kMaskedInstrumentMissingType[] = | |
| 72 "{" | |
| 73 " \"descriptive_name\":\"descriptive_name\"," | |
| 74 " \"last_four_digits\":\"last_four_digits\"," | |
| 75 " \"expiration_month\":12," | |
| 76 " \"expiration_year\":2012," | |
| 77 " \"billing_address\":" | |
| 78 " {" | |
| 79 " \"name\":\"name\"," | |
| 80 " \"address1\":\"address1\"," | |
| 81 " \"address2\":\"address2\"," | |
| 82 " \"city\":\"city\"," | |
| 83 " \"dependent_locality_name\":\"burough\"," | |
| 84 " \"state\":\"state\"," | |
| 85 " \"postal_code\":\"postal_code\"," | |
| 86 " \"sorting_code\":\"sorting_code\"," | |
| 87 " \"phone_number\":\"phone_number\"," | |
| 88 " \"country_code\":\"US\"," | |
| 89 " \"language_code\":\"language_code\"" | |
| 90 " }," | |
| 91 " \"status\":\"VALID\"," | |
| 92 " \"object_id\":\"object_id\"" | |
| 93 "}"; | |
| 94 | |
| 95 const char kMaskedInstrumentMissingLastFourDigits[] = | |
| 96 "{" | |
| 97 " \"descriptive_name\":\"descriptive_name\"," | |
| 98 " \"type\":\"VISA\"," | |
| 99 " \"expiration_month\":12," | |
| 100 " \"expiration_year\":2012," | |
| 101 " \"billing_address\":" | |
| 102 " {" | |
| 103 " \"name\":\"name\"," | |
| 104 " \"address1\":\"address1\"," | |
| 105 " \"address2\":\"address2\"," | |
| 106 " \"city\":\"city\"," | |
| 107 " \"dependent_locality_name\":\"burough\"," | |
| 108 " \"state\":\"state\"," | |
| 109 " \"postal_code\":\"postal_code\"," | |
| 110 " \"sorting_code\":\"sorting_code\"," | |
| 111 " \"phone_number\":\"phone_number\"," | |
| 112 " \"country_code\":\"US\"," | |
| 113 " \"language_code\":\"language_code\"" | |
| 114 " }," | |
| 115 " \"status\":\"VALID\"," | |
| 116 " \"object_id\":\"object_id\"" | |
| 117 "}"; | |
| 118 | |
| 119 const char kMaskedInstrumentMissingAddress[] = | |
| 120 "{" | |
| 121 " \"descriptive_name\":\"descriptive_name\"," | |
| 122 " \"type\":\"VISA\"," | |
| 123 " \"last_four_digits\":\"last_four_digits\"," | |
| 124 " \"expiration_month\":12," | |
| 125 " \"expiration_year\":2012," | |
| 126 " \"status\":\"VALID\"," | |
| 127 " \"object_id\":\"object_id\"" | |
| 128 "}"; | |
| 129 | |
| 130 const char kMaskedInstrumentMalformedAddress[] = | |
| 131 "{" | |
| 132 " \"descriptive_name\":\"descriptive_name\"," | |
| 133 " \"type\":\"VISA\"," | |
| 134 " \"last_four_digits\":\"last_four_digits\"," | |
| 135 " \"expiration_month\":12," | |
| 136 " \"expiration_year\":2012," | |
| 137 " \"billing_address\":" | |
| 138 " {" | |
| 139 " \"address1\":\"address1\"," | |
| 140 " \"address2\":\"address2\"," | |
| 141 " \"city\":\"city\"," | |
| 142 " \"dependent_locality_name\":\"burough\"," | |
| 143 " \"state\":\"state\"," | |
| 144 " \"phone_number\":\"phone_number\"," | |
| 145 " \"country_code\":\"US\"" | |
| 146 " }," | |
| 147 " \"status\":\"VALID\"," | |
| 148 " \"object_id\":\"object_id\"" | |
| 149 "}"; | |
| 150 | |
| 151 const char kMaskedInstrumentMissingObjectId[] = | |
| 152 "{" | |
| 153 " \"descriptive_name\":\"descriptive_name\"," | |
| 154 " \"type\":\"VISA\"," | |
| 155 " \"last_four_digits\":\"last_four_digits\"," | |
| 156 " \"expiration_month\":12," | |
| 157 " \"expiration_year\":2012," | |
| 158 " \"billing_address\":" | |
| 159 " {" | |
| 160 " \"name\":\"name\"," | |
| 161 " \"address1\":\"address1\"," | |
| 162 " \"address2\":\"address2\"," | |
| 163 " \"city\":\"city\"," | |
| 164 " \"dependent_locality_name\":\"burough\"," | |
| 165 " \"state\":\"state\"," | |
| 166 " \"postal_code\":\"postal_code\"," | |
| 167 " \"phone_number\":\"phone_number\"," | |
| 168 " \"country_code\":\"US\"," | |
| 169 " \"language_code\":\"language_code\"" | |
| 170 " }," | |
| 171 " \"status\":\"VALID\"" | |
| 172 "}"; | |
| 173 | |
| 174 const char kLegalDocument[] = | |
| 175 "{" | |
| 176 " \"legal_document_id\":\"doc_id\"," | |
| 177 " \"display_name\":\"display_name\"," | |
| 178 " \"url\":\"https://example.com\"" | |
| 179 "}"; | |
| 180 | |
| 181 const char kLegalDocumentMissingDocumentId[] = | |
| 182 "{" | |
| 183 " \"display_name\":\"display_name\"," | |
| 184 " \"url\":\"https://example.com\"" | |
| 185 "}"; | |
| 186 | |
| 187 const char kLegalDocumentMissingDisplayName[] = | |
| 188 "{" | |
| 189 " \"legal_document_id\":\"doc_id\"," | |
| 190 " \"url\":\"https://example.com\"" | |
| 191 "}"; | |
| 192 | |
| 193 const char kWalletItemsWithRequiredActions[] = | |
| 194 "{" | |
| 195 " \"required_action\":" | |
| 196 " [" | |
| 197 " \" setup_wallet\"," | |
| 198 " \" CHOOse_ANother_INSTRUMENT_OR_ADDRESS\"," | |
| 199 " \"AcCePt_ToS \"," | |
| 200 " \" \\tGAIA_auth \\n\\r\"," | |
| 201 " \"UPDATE_expiration_date\"," | |
| 202 " \"UPGRADE_min_ADDRESS \"," | |
| 203 " \" pAsSiVe_GAIA_auth \"," | |
| 204 " \" REQUIRE_PHONE_NUMBER\\t \"" | |
| 205 " ]" | |
| 206 "}"; | |
| 207 | |
| 208 const char kWalletItemsWithInvalidRequiredActions[] = | |
| 209 "{" | |
| 210 " \"required_action\":" | |
| 211 " [" | |
| 212 " \"verify_CVV\"," | |
| 213 " \"invalid_FORM_FIELD\"," | |
| 214 " \" 忍者の正体 \"" | |
| 215 " ]" | |
| 216 "}"; | |
| 217 | |
| 218 const char kWalletItemsMissingGoogleTransactionId[] = | |
| 219 "{" | |
| 220 " \"required_action\":" | |
| 221 " [" | |
| 222 " ]," | |
| 223 " \"instrument\":" | |
| 224 " [" | |
| 225 " {" | |
| 226 " \"descriptive_name\":\"descriptive_name\"," | |
| 227 " \"type\":\"VISA\"," | |
| 228 " \"last_four_digits\":\"last_four_digits\"," | |
| 229 " \"expiration_month\":12," | |
| 230 " \"expiration_year\":2012," | |
| 231 " \"billing_address\":" | |
| 232 " {" | |
| 233 " \"name\":\"name\"," | |
| 234 " \"address1\":\"address1\"," | |
| 235 " \"address2\":\"address2\"," | |
| 236 " \"city\":\"city\"," | |
| 237 " \"state\":\"state\"," | |
| 238 " \"postal_code\":\"postal_code\"," | |
| 239 " \"phone_number\":\"phone_number\"," | |
| 240 " \"country_code\":\"US\"," | |
| 241 " \"language_code\":\"language_code\"" | |
| 242 " }," | |
| 243 " \"status\":\"VALID\"," | |
| 244 " \"object_id\":\"object_id\"" | |
| 245 " }" | |
| 246 " ]," | |
| 247 " \"default_instrument_id\":\"default_instrument_id\"," | |
| 248 " \"address\":" | |
| 249 " [" | |
| 250 " {" | |
| 251 " \"id\":\"id\"," | |
| 252 " \"phone_number\":\"phone_number\"," | |
| 253 " \"postal_address\":" | |
| 254 " {" | |
| 255 " \"recipient_name\":\"recipient_name\"," | |
| 256 " \"address_line\":" | |
| 257 " [" | |
| 258 " \"address_line_1\"," | |
| 259 " \"address_line_2\"" | |
| 260 " ]," | |
| 261 " \"locality_name\":\"locality_name\"," | |
| 262 " \"administrative_area_name\":\"administrative_area_name\"," | |
| 263 " \"postal_code_number\":\"postal_code_number\"," | |
| 264 " \"country_name_code\":\"US\"," | |
| 265 " \"language_code\":\"language_code\"" | |
| 266 " }" | |
| 267 " }" | |
| 268 " ]," | |
| 269 " \"default_address_id\":\"default_address_id\"," | |
| 270 " \"amex_disallowed\":true," | |
| 271 " \"required_legal_document\":" | |
| 272 " [" | |
| 273 " {" | |
| 274 " \"legal_document_id\":\"doc_id\"," | |
| 275 " \"display_name\":\"display_name\"," | |
| 276 " \"url\":\"https://example.com\"" | |
| 277 " }" | |
| 278 " ]" | |
| 279 "}"; | |
| 280 | |
| 281 const char kWalletItems[] = | |
| 282 "{" | |
| 283 " \"required_action\":" | |
| 284 " [" | |
| 285 " ]," | |
| 286 " \"google_transaction_id\":\"google_transaction_id\"," | |
| 287 " \"instrument\":" | |
| 288 " [" | |
| 289 " {" | |
| 290 " \"descriptive_name\":\"descriptive_name\"," | |
| 291 " \"type\":\"VISA\"," | |
| 292 " \"last_four_digits\":\"last_four_digits\"," | |
| 293 " \"expiration_month\":12," | |
| 294 " \"expiration_year\":2012," | |
| 295 " \"billing_address\":" | |
| 296 " {" | |
| 297 " \"name\":\"name\"," | |
| 298 " \"address1\":\"address1\"," | |
| 299 " \"address2\":\"address2\"," | |
| 300 " \"city\":\"city\"," | |
| 301 " \"dependent_locality_name\":\"burough\"," | |
| 302 " \"state\":\"state\"," | |
| 303 " \"postal_code\":\"postal_code\"," | |
| 304 " \"sorting_code\":\"sorting_code\"," | |
| 305 " \"phone_number\":\"phone_number\"," | |
| 306 " \"country_code\":\"US\"," | |
| 307 " \"type\":\"FULL\"," | |
| 308 " \"language_code\":\"language_code\"" | |
| 309 " }," | |
| 310 " \"status\":\"VALID\"," | |
| 311 " \"object_id\":\"object_id\"" | |
| 312 " }" | |
| 313 " ]," | |
| 314 " \"default_instrument_id\":\"default_instrument_id\"," | |
| 315 " \"address\":" | |
| 316 " [" | |
| 317 " {" | |
| 318 " \"id\":\"id\"," | |
| 319 " \"phone_number\":\"phone_number\"," | |
| 320 " \"postal_address\":" | |
| 321 " {" | |
| 322 " \"recipient_name\":\"recipient_name\"," | |
| 323 " \"address_line\":" | |
| 324 " [" | |
| 325 " \"address_line_1\"," | |
| 326 " \"address_line_2\"" | |
| 327 " ]," | |
| 328 " \"locality_name\":\"locality_name\"," | |
| 329 " \"dependent_locality_name\":\"dependent_locality_name\"," | |
| 330 " \"administrative_area_name\":\"administrative_area_name\"," | |
| 331 " \"postal_code_number\":\"postal_code_number\"," | |
| 332 " \"sorting_code\":\"sorting_code\"," | |
| 333 " \"country_name_code\":\"US\"," | |
| 334 " \"language_code\":\"language_code\"" | |
| 335 " }" | |
| 336 " }" | |
| 337 " ]," | |
| 338 " \"default_address_id\":\"default_address_id\"," | |
| 339 " \"obfuscated_gaia_id\":\"ignore_this_value\"," | |
| 340 " \"amex_disallowed\":true," | |
| 341 " \"gaia_profile\":" | |
| 342 " [" | |
| 343 " {" | |
| 344 " \"buyer_email\":\"user@chromium.org\"," | |
| 345 " \"gaia_index\":0," | |
| 346 " \"gaia_id\":\"123456789\"," | |
| 347 " \"buyer_name\":\"Joe Usecase\"," | |
| 348 " \"is_active\":true," | |
| 349 " \"avatar_url_27x27\":\"https://lh3.googleusercontent.com/27.jpg\"," | |
| 350 " \"avatar_url_54x54\":\"https://lh3.googleusercontent.com/54.jpg\"," | |
| 351 " \"avatar_url_48x48\":\"https://lh3.googleusercontent.com/48.jpg\"," | |
| 352 " \"avatar_url_96x96\":\"https://lh3.googleusercontent.com/96.jpg\"" | |
| 353 " }," | |
| 354 " {" | |
| 355 " \"buyer_email\":\"user2@chromium.org\"," | |
| 356 " \"gaia_index\":1," | |
| 357 " \"gaia_id\":\"obfuscated_gaia_id\"," | |
| 358 " \"buyer_name\":\"Jill Usecase\"," | |
| 359 " \"is_active\":false," | |
| 360 " \"avatar_url_27x27\":\"https://lh3.googleusercontent.com/27.jpg\"," | |
| 361 " \"avatar_url_54x54\":\"https://lh3.googleusercontent.com/54.jpg\"," | |
| 362 " \"avatar_url_48x48\":\"https://lh3.googleusercontent.com/48.jpg\"," | |
| 363 " \"avatar_url_96x96\":\"https://lh3.googleusercontent.com/96.jpg\"" | |
| 364 " }" | |
| 365 " ]," | |
| 366 " \"allowed_shipping_spec_by_country\":" | |
| 367 " [" | |
| 368 " {\"country_code\":\"AC\"}," | |
| 369 " {\"country_code\":\"AD\"}," | |
| 370 " {\"country_code\":\"US\"}" | |
| 371 " ]"; | |
| 372 | |
| 373 const char kRequiredLegalDocument[] = | |
| 374 " ," | |
| 375 " \"required_legal_document\":" | |
| 376 " [" | |
| 377 " {" | |
| 378 " \"legal_document_id\":\"doc_id\"," | |
| 379 " \"display_name\":\"display_name\"," | |
| 380 " \"url\":\"https://example.com\"" | |
| 381 " }" | |
| 382 " ]"; | |
| 383 | |
| 384 const char kCloseJson[] = "}"; | |
| 385 | |
| 386 } // anonymous namespace | |
| 387 | |
| 388 namespace autofill { | |
| 389 namespace wallet { | |
| 390 | |
| 391 class WalletItemsTest : public testing::Test { | |
| 392 public: | |
| 393 WalletItemsTest() {} | |
| 394 protected: | |
| 395 void SetUpDictionary(const std::string& json) { | |
| 396 scoped_ptr<base::Value> value = base::JSONReader::Read(json); | |
| 397 ASSERT_TRUE(value.get()); | |
| 398 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | |
| 399 dict.reset(static_cast<base::DictionaryValue*>(value.release())); | |
| 400 } | |
| 401 scoped_ptr<base::DictionaryValue> dict; | |
| 402 }; | |
| 403 | |
| 404 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingStatus) { | |
| 405 SetUpDictionary(kMaskedInstrumentMissingStatus); | |
| 406 EXPECT_EQ(NULL, | |
| 407 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 408 } | |
| 409 | |
| 410 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingType) { | |
| 411 SetUpDictionary(kMaskedInstrumentMissingType); | |
| 412 EXPECT_EQ(NULL, | |
| 413 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 414 } | |
| 415 | |
| 416 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingLastFourDigits) { | |
| 417 SetUpDictionary(kMaskedInstrumentMissingLastFourDigits); | |
| 418 EXPECT_EQ(NULL, | |
| 419 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 420 } | |
| 421 | |
| 422 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingAddress) { | |
| 423 SetUpDictionary(kMaskedInstrumentMissingAddress); | |
| 424 EXPECT_EQ(NULL, | |
| 425 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 426 } | |
| 427 | |
| 428 TEST_F(WalletItemsTest, CreateMaskedInstrumentMalformedAddress) { | |
| 429 SetUpDictionary(kMaskedInstrumentMalformedAddress); | |
| 430 EXPECT_EQ(NULL, | |
| 431 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 432 } | |
| 433 | |
| 434 TEST_F(WalletItemsTest, CreateMaskedInstrumentMissingObjectId) { | |
| 435 SetUpDictionary(kMaskedInstrumentMissingObjectId); | |
| 436 EXPECT_EQ(NULL, | |
| 437 WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict).get()); | |
| 438 } | |
| 439 | |
| 440 TEST_F(WalletItemsTest, CreateMaskedInstrument) { | |
| 441 SetUpDictionary(kMaskedInstrument); | |
| 442 scoped_ptr<Address> address( | |
| 443 new Address("US", | |
| 444 ASCIIToUTF16("name"), | |
| 445 StreetAddress("address1", "address2"), | |
| 446 ASCIIToUTF16("city"), | |
| 447 ASCIIToUTF16("burough"), | |
| 448 ASCIIToUTF16("state"), | |
| 449 ASCIIToUTF16("postal_code"), | |
| 450 ASCIIToUTF16("sorting_code"), | |
| 451 ASCIIToUTF16("phone_number"), | |
| 452 std::string(), | |
| 453 "language_code")); | |
| 454 WalletItems::MaskedInstrument masked_instrument( | |
| 455 ASCIIToUTF16("descriptive_name"), | |
| 456 WalletItems::MaskedInstrument::VISA, | |
| 457 ASCIIToUTF16("last_four_digits"), | |
| 458 12, | |
| 459 2012, | |
| 460 address.Pass(), | |
| 461 WalletItems::MaskedInstrument::VALID, | |
| 462 "object_id"); | |
| 463 EXPECT_EQ(masked_instrument, | |
| 464 *WalletItems::MaskedInstrument::CreateMaskedInstrument(*dict)); | |
| 465 } | |
| 466 | |
| 467 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDocId) { | |
| 468 SetUpDictionary(kLegalDocumentMissingDocumentId); | |
| 469 EXPECT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); | |
| 470 } | |
| 471 | |
| 472 TEST_F(WalletItemsTest, CreateLegalDocumentMissingDisplayName) { | |
| 473 SetUpDictionary(kLegalDocumentMissingDisplayName); | |
| 474 EXPECT_EQ(NULL, WalletItems::LegalDocument::CreateLegalDocument(*dict).get()); | |
| 475 } | |
| 476 | |
| 477 TEST_F(WalletItemsTest, CreateLegalDocument) { | |
| 478 SetUpDictionary(kLegalDocument); | |
| 479 WalletItems::LegalDocument expected("doc_id", GURL("https://example.com"), | |
| 480 ASCIIToUTF16("display_name")); | |
| 481 EXPECT_EQ(expected, | |
| 482 *WalletItems::LegalDocument::CreateLegalDocument(*dict)); | |
| 483 } | |
| 484 | |
| 485 TEST_F(WalletItemsTest, LegalDocumentEmptyId) { | |
| 486 WalletItems::LegalDocument legal_doc( | |
| 487 std::string(), GURL("https://example.com"), ASCIIToUTF16("display_name")); | |
| 488 EXPECT_TRUE(legal_doc.id().empty()); | |
| 489 } | |
| 490 | |
| 491 TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { | |
| 492 SetUpDictionary(kWalletItemsWithRequiredActions); | |
| 493 | |
| 494 std::vector<RequiredAction> required_actions; | |
| 495 required_actions.push_back(SETUP_WALLET); | |
| 496 required_actions.push_back(CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS); | |
| 497 required_actions.push_back(ACCEPT_TOS); | |
| 498 required_actions.push_back(GAIA_AUTH); | |
| 499 required_actions.push_back(UPDATE_EXPIRATION_DATE); | |
| 500 required_actions.push_back(UPGRADE_MIN_ADDRESS); | |
| 501 required_actions.push_back(PASSIVE_GAIA_AUTH); | |
| 502 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 503 | |
| 504 WalletItems expected(required_actions, | |
| 505 std::string(), | |
| 506 std::string(), | |
| 507 std::string(), | |
| 508 AMEX_DISALLOWED); | |
| 509 EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); | |
| 510 | |
| 511 ASSERT_FALSE(required_actions.empty()); | |
| 512 required_actions.pop_back(); | |
| 513 WalletItems different_required_actions(required_actions, | |
| 514 std::string(), | |
| 515 std::string(), | |
| 516 std::string(), | |
| 517 AMEX_DISALLOWED); | |
| 518 EXPECT_NE(expected, different_required_actions); | |
| 519 } | |
| 520 | |
| 521 TEST_F(WalletItemsTest, CreateWalletItemsWithInvalidRequiredActions) { | |
| 522 SetUpDictionary(kWalletItemsWithInvalidRequiredActions); | |
| 523 EXPECT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); | |
| 524 } | |
| 525 | |
| 526 TEST_F(WalletItemsTest, CreateWalletItemsMissingGoogleTransactionId) { | |
| 527 SetUpDictionary(kWalletItemsMissingGoogleTransactionId); | |
| 528 EXPECT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get()); | |
| 529 } | |
| 530 | |
| 531 TEST_F(WalletItemsTest, CreateWalletItemsMissingAmexDisallowed) { | |
| 532 SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); | |
| 533 EXPECT_TRUE(dict->Remove("amex_disallowed", NULL)); | |
| 534 base::string16 amex_number = ASCIIToUTF16("378282246310005"); | |
| 535 base::string16 message; | |
| 536 EXPECT_FALSE(WalletItems::CreateWalletItems(*dict)->SupportsCard(amex_number, | |
| 537 &message)); | |
| 538 EXPECT_FALSE(message.empty()); | |
| 539 } | |
| 540 | |
| 541 TEST_F(WalletItemsTest, CreateWalletItems) { | |
| 542 SetUpDictionary(std::string(kWalletItems) + std::string(kCloseJson)); | |
| 543 std::vector<RequiredAction> required_actions; | |
| 544 WalletItems expected(required_actions, | |
| 545 "google_transaction_id", | |
| 546 "default_instrument_id", | |
| 547 "default_address_id", | |
| 548 AMEX_DISALLOWED); | |
| 549 | |
| 550 scoped_ptr<GaiaAccount> user1(GaiaAccount::CreateForTesting( | |
| 551 "user@chromium.org", | |
| 552 "123456789", | |
| 553 0, | |
| 554 true)); | |
| 555 expected.AddAccount(user1.Pass()); | |
| 556 scoped_ptr<GaiaAccount> user2(GaiaAccount::CreateForTesting( | |
| 557 "user2@chromium.org", | |
| 558 "obfuscated_gaia_id", | |
| 559 1, | |
| 560 false)); | |
| 561 expected.AddAccount(user2.Pass()); | |
| 562 EXPECT_EQ("123456789", expected.ObfuscatedGaiaId()); | |
| 563 | |
| 564 scoped_ptr<Address> billing_address( | |
| 565 new Address("US", | |
| 566 ASCIIToUTF16("name"), | |
| 567 StreetAddress("address1", "address2"), | |
| 568 ASCIIToUTF16("city"), | |
| 569 ASCIIToUTF16("burough"), | |
| 570 ASCIIToUTF16("state"), | |
| 571 ASCIIToUTF16("postal_code"), | |
| 572 ASCIIToUTF16("sorting_code"), | |
| 573 ASCIIToUTF16("phone_number"), | |
| 574 std::string(), | |
| 575 "language_code")); | |
| 576 scoped_ptr<WalletItems::MaskedInstrument> masked_instrument( | |
| 577 new WalletItems::MaskedInstrument(ASCIIToUTF16("descriptive_name"), | |
| 578 WalletItems::MaskedInstrument::VISA, | |
| 579 ASCIIToUTF16("last_four_digits"), | |
| 580 12, | |
| 581 2012, | |
| 582 billing_address.Pass(), | |
| 583 WalletItems::MaskedInstrument::VALID, | |
| 584 "object_id")); | |
| 585 expected.AddInstrument(masked_instrument.Pass()); | |
| 586 | |
| 587 scoped_ptr<Address> shipping_address( | |
| 588 new Address("US", | |
| 589 ASCIIToUTF16("recipient_name"), | |
| 590 StreetAddress("address_line_1", "address_line_2"), | |
| 591 ASCIIToUTF16("locality_name"), | |
| 592 ASCIIToUTF16("dependent_locality_name"), | |
| 593 ASCIIToUTF16("administrative_area_name"), | |
| 594 ASCIIToUTF16("postal_code_number"), | |
| 595 ASCIIToUTF16("sorting_code"), | |
| 596 ASCIIToUTF16("phone_number"), | |
| 597 "id", | |
| 598 "language_code")); | |
| 599 expected.AddAddress(shipping_address.Pass()); | |
| 600 | |
| 601 expected.AddAllowedShippingCountry("AC"); | |
| 602 expected.AddAllowedShippingCountry("AD"); | |
| 603 expected.AddAllowedShippingCountry("US"); | |
| 604 | |
| 605 EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); | |
| 606 | |
| 607 // Now try with a legal document as well. | |
| 608 SetUpDictionary(std::string(kWalletItems) + | |
| 609 std::string(kRequiredLegalDocument) + | |
| 610 std::string(kCloseJson)); | |
| 611 scoped_ptr<WalletItems::LegalDocument> legal_document( | |
| 612 new WalletItems::LegalDocument("doc_id", GURL("https://example.com"), | |
| 613 ASCIIToUTF16("display_name"))); | |
| 614 expected.AddLegalDocument(legal_document.Pass()); | |
| 615 expected.AddLegalDocument( | |
| 616 WalletItems::LegalDocument::CreatePrivacyPolicyDocument()); | |
| 617 | |
| 618 EXPECT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); | |
| 619 } | |
| 620 | |
| 621 } // namespace wallet | |
| 622 } // namespace autofill | |
| OLD | NEW |