| 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/json/json_writer.h" | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/string_util.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/browser/autofill/wallet/cart.h" | |
| 13 #include "chrome/browser/autofill/wallet/full_wallet.h" | |
| 14 #include "chrome/browser/autofill/wallet/instrument.h" | |
| 15 #include "chrome/browser/autofill/wallet/wallet_client.h" | |
| 16 #include "chrome/browser/autofill/wallet/wallet_client_observer.h" | |
| 17 #include "chrome/browser/autofill/wallet/wallet_items.h" | |
| 18 #include "chrome/browser/autofill/wallet/wallet_test_util.h" | |
| 19 #include "chrome/test/base/testing_profile.h" | |
| 20 #include "components/autofill/common/autocheckout_status.h" | |
| 21 #include "content/public/test/test_browser_thread.h" | |
| 22 #include "googleurl/src/gurl.h" | |
| 23 #include "net/base/net_errors.h" | |
| 24 #include "net/http/http_status_code.h" | |
| 25 #include "net/url_request/test_url_fetcher_factory.h" | |
| 26 #include "net/url_request/url_fetcher_delegate.h" | |
| 27 #include "net/url_request/url_request_status.h" | |
| 28 #include "testing/gmock/include/gmock/gmock.h" | |
| 29 #include "testing/gtest/include/gtest/gtest.h" | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 const char kGoogleTransactionId[] = "google-transaction-id"; | |
| 34 const char kMerchantUrl[] = "https://example.com/path?key=value"; | |
| 35 | |
| 36 const char kGetFullWalletValidResponse[] = | |
| 37 "{" | |
| 38 " \"expiration_month\":12," | |
| 39 " \"expiration_year\":2012," | |
| 40 " \"iin\":\"iin\"," | |
| 41 " \"rest\":\"rest\"," | |
| 42 " \"billing_address\":" | |
| 43 " {" | |
| 44 " \"id\":\"id\"," | |
| 45 " \"phone_number\":\"phone_number\"," | |
| 46 " \"postal_address\":" | |
| 47 " {" | |
| 48 " \"recipient_name\":\"recipient_name\"," | |
| 49 " \"address_line\":" | |
| 50 " [" | |
| 51 " \"address_line_1\"," | |
| 52 " \"address_line_2\"" | |
| 53 " ]," | |
| 54 " \"locality_name\":\"locality_name\"," | |
| 55 " \"administrative_area_name\":\"administrative_area_name\"," | |
| 56 " \"postal_code_number\":\"postal_code_number\"," | |
| 57 " \"country_name_code\":\"country_name_code\"" | |
| 58 " }" | |
| 59 " }," | |
| 60 " \"shipping_address\":" | |
| 61 " {" | |
| 62 " \"id\":\"ship_id\"," | |
| 63 " \"phone_number\":\"ship_phone_number\"," | |
| 64 " \"postal_address\":" | |
| 65 " {" | |
| 66 " \"recipient_name\":\"ship_recipient_name\"," | |
| 67 " \"address_line\":" | |
| 68 " [" | |
| 69 " \"ship_address_line_1\"," | |
| 70 " \"ship_address_line_2\"" | |
| 71 " ]," | |
| 72 " \"locality_name\":\"ship_locality_name\"," | |
| 73 " \"administrative_area_name\":\"ship_administrative_area_name\"," | |
| 74 " \"postal_code_number\":\"ship_postal_code_number\"," | |
| 75 " \"country_name_code\":\"ship_country_name_code\"" | |
| 76 " }" | |
| 77 " }," | |
| 78 " \"required_action\":" | |
| 79 " [" | |
| 80 " ]" | |
| 81 "}"; | |
| 82 | |
| 83 const char kGetFullWalletInvalidResponse[] = | |
| 84 "{" | |
| 85 " \"garbage\":123" | |
| 86 "}"; | |
| 87 | |
| 88 const char kGetWalletItemsValidResponse[] = | |
| 89 "{" | |
| 90 " \"required_action\":" | |
| 91 " [" | |
| 92 " ]," | |
| 93 " \"google_transaction_id\":\"google_transaction_id\"," | |
| 94 " \"instrument\":" | |
| 95 " [" | |
| 96 " {" | |
| 97 " \"descriptive_name\":\"descriptive_name\"," | |
| 98 " \"type\":\"VISA\"," | |
| 99 " \"supported_currency\":\"currency_code\"," | |
| 100 " \"last_four_digits\":\"last_four_digits\"," | |
| 101 " \"expiration_month\":12," | |
| 102 " \"expiration_year\":2012," | |
| 103 " \"brand\":\"monkeys\"," | |
| 104 " \"billing_address\":" | |
| 105 " {" | |
| 106 " \"name\":\"name\"," | |
| 107 " \"address1\":\"address1\"," | |
| 108 " \"address2\":\"address2\"," | |
| 109 " \"city\":\"city\"," | |
| 110 " \"state\":\"state\"," | |
| 111 " \"postal_code\":\"postal_code\"," | |
| 112 " \"phone_number\":\"phone_number\"," | |
| 113 " \"country_code\":\"country_code\"" | |
| 114 " }," | |
| 115 " \"status\":\"VALID\"," | |
| 116 " \"object_id\":\"default_instrument_id\"" | |
| 117 " }" | |
| 118 " ]," | |
| 119 " \"default_instrument_id\":\"default_instrument_id\"," | |
| 120 " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," | |
| 121 " \"address\":" | |
| 122 " [" | |
| 123 " ]," | |
| 124 " \"default_address_id\":\"default_address_id\"," | |
| 125 " \"required_legal_document\":" | |
| 126 " [" | |
| 127 " ]" | |
| 128 "}"; | |
| 129 | |
| 130 const char kSaveAddressValidResponse[] = | |
| 131 "{" | |
| 132 " \"shipping_address_id\":\"shipping_address_id\"" | |
| 133 "}"; | |
| 134 | |
| 135 const char kSaveAddressWithRequiredActionsValidResponse[] = | |
| 136 "{" | |
| 137 " \"required_action\":" | |
| 138 " [" | |
| 139 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 140 " \"INVALID_form_field\"" | |
| 141 " ]" | |
| 142 "}"; | |
| 143 | |
| 144 const char kSaveWithInvalidRequiredActionsResponse[] = | |
| 145 "{" | |
| 146 " \"required_action\":" | |
| 147 " [" | |
| 148 " \" setup_wallet\"," | |
| 149 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 150 " \"INVALID_form_field\"" | |
| 151 " ]" | |
| 152 "}"; | |
| 153 | |
| 154 const char kSaveInvalidResponse[] = | |
| 155 "{" | |
| 156 " \"garbage\":123" | |
| 157 "}"; | |
| 158 | |
| 159 const char kSaveInstrumentValidResponse[] = | |
| 160 "{" | |
| 161 " \"instrument_id\":\"instrument_id\"" | |
| 162 "}"; | |
| 163 | |
| 164 const char kSaveInstrumentWithRequiredActionsValidResponse[] = | |
| 165 "{" | |
| 166 " \"required_action\":" | |
| 167 " [" | |
| 168 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 169 " \"INVALID_form_field\"" | |
| 170 " ]" | |
| 171 "}"; | |
| 172 | |
| 173 const char kSaveInstrumentAndAddressValidResponse[] = | |
| 174 "{" | |
| 175 " \"shipping_address_id\":\"shipping_address_id\"," | |
| 176 " \"instrument_id\":\"instrument_id\"" | |
| 177 "}"; | |
| 178 | |
| 179 const char kSaveInstrumentAndAddressWithRequiredActionsValidResponse[] = | |
| 180 "{" | |
| 181 " \"required_action\":" | |
| 182 " [" | |
| 183 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 184 " \"INVALID_form_field\"" | |
| 185 " ]" | |
| 186 "}"; | |
| 187 | |
| 188 const char kSaveInstrumentAndAddressMissingAddressResponse[] = | |
| 189 "{" | |
| 190 " \"instrument_id\":\"instrument_id\"" | |
| 191 "}"; | |
| 192 | |
| 193 const char kSaveInstrumentAndAddressMissingInstrumentResponse[] = | |
| 194 "{" | |
| 195 " \"shipping_address_id\":\"shipping_address_id\"" | |
| 196 "}"; | |
| 197 | |
| 198 const char kUpdateInstrumentValidResponse[] = | |
| 199 "{" | |
| 200 " \"instrument_id\":\"instrument_id\"" | |
| 201 "}"; | |
| 202 | |
| 203 const char kUpdateInstrumentWithRequiredActionsValidResponse[] = | |
| 204 "{" | |
| 205 " \"required_action\":" | |
| 206 " [" | |
| 207 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 208 " \"INVALID_form_field\"" | |
| 209 " ]" | |
| 210 "}"; | |
| 211 | |
| 212 const char kUpdateInstrumentMalformedResponse[] = | |
| 213 "{" | |
| 214 " \"cheese\":\"monkeys\"" | |
| 215 "}"; | |
| 216 | |
| 217 const char kAuthenticateInstrumentFailureResponse[] = | |
| 218 "{" | |
| 219 " \"auth_result\":\"anything else\"" | |
| 220 "}"; | |
| 221 | |
| 222 const char kAuthenticateInstrumentSuccessResponse[] = | |
| 223 "{" | |
| 224 " \"auth_result\":\"SUCCESS\"" | |
| 225 "}"; | |
| 226 | |
| 227 // The JSON below is used to test against the request payload being sent to | |
| 228 // Online Wallet. It's indented differently since JSONWriter creates compact | |
| 229 // JSON from DictionaryValues. | |
| 230 | |
| 231 const char kAcceptLegalDocumentsValidRequest[] = | |
| 232 "{" | |
| 233 "\"accepted_legal_document\":" | |
| 234 "[" | |
| 235 "\"doc_1\"," | |
| 236 "\"doc_2\"" | |
| 237 "]," | |
| 238 "\"google_transaction_id\":\"google-transaction-id\"," | |
| 239 "\"merchant_domain\":\"https://example.com/\"" | |
| 240 "}"; | |
| 241 | |
| 242 const char kAuthenticateInstrumentValidRequest[] = | |
| 243 "{" | |
| 244 "\"instrument_escrow_handle\":\"escrow_handle\"," | |
| 245 "\"instrument_id\":\"instrument_id\"," | |
| 246 "\"risk_params\":\"\"" | |
| 247 "}"; | |
| 248 | |
| 249 const char kGetFullWalletValidRequest[] = | |
| 250 "{" | |
| 251 "\"cart\":" | |
| 252 "{" | |
| 253 "\"currency_code\":\"currency_code\"," | |
| 254 "\"total_price\":\"currency_code\"" | |
| 255 "}," | |
| 256 "\"encrypted_otp\":\"encrypted_one_time_pad\"," | |
| 257 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | |
| 258 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 259 "\"merchant_domain\":\"https://example.com/\"," | |
| 260 "\"risk_params\":\"\"," | |
| 261 "\"selected_address_id\":\"shipping_address_id\"," | |
| 262 "\"selected_instrument_id\":\"instrument_id\"," | |
| 263 "\"session_material\":\"session_material\"" | |
| 264 "}"; | |
| 265 | |
| 266 const char kGetWalletItemsValidRequest[] = | |
| 267 "{" | |
| 268 "\"merchant_domain\":\"https://example.com/\"," | |
| 269 "\"risk_params\":\"\"" | |
| 270 "}"; | |
| 271 | |
| 272 const char kSaveAddressValidRequest[] = | |
| 273 "{" | |
| 274 "\"merchant_domain\":\"https://example.com/\"," | |
| 275 "\"risk_params\":\"\"," | |
| 276 "\"shipping_address\":" | |
| 277 "{" | |
| 278 "\"phone_number\":\"ship_phone_number\"," | |
| 279 "\"postal_address\":" | |
| 280 "{" | |
| 281 "\"address_line\":" | |
| 282 "[" | |
| 283 "\"ship_address_line_1\"," | |
| 284 "\"ship_address_line_2\"" | |
| 285 "]," | |
| 286 "\"administrative_area_name\":\"ship_admin_area_name\"," | |
| 287 "\"country_name_code\":\"ship_country_name_code\"," | |
| 288 "\"locality_name\":\"ship_locality_name\"," | |
| 289 "\"postal_code_number\":\"ship_postal_code_number\"," | |
| 290 "\"recipient_name\":\"ship_recipient_name\"" | |
| 291 "}" | |
| 292 "}" | |
| 293 "}"; | |
| 294 | |
| 295 const char kSaveInstrumentValidRequest[] = | |
| 296 "{" | |
| 297 "\"instrument\":" | |
| 298 "{" | |
| 299 "\"credit_card\":" | |
| 300 "{" | |
| 301 "\"address\":" | |
| 302 "{" | |
| 303 "\"address_line\":" | |
| 304 "[" | |
| 305 "\"address_line_1\"," | |
| 306 "\"address_line_2\"" | |
| 307 "]," | |
| 308 "\"administrative_area_name\":\"admin_area_name\"," | |
| 309 "\"country_name_code\":\"country_name_code\"," | |
| 310 "\"locality_name\":\"locality_name\"," | |
| 311 "\"postal_code_number\":\"postal_code_number\"," | |
| 312 "\"recipient_name\":\"recipient_name\"" | |
| 313 "}," | |
| 314 "\"exp_month\":12," | |
| 315 "\"exp_year\":2012," | |
| 316 "\"fop_type\":\"VISA\"," | |
| 317 "\"last_4_digits\":\"4448\"" | |
| 318 "}," | |
| 319 "\"type\":\"CREDIT_CARD\"" | |
| 320 "}," | |
| 321 "\"instrument_escrow_handle\":\"escrow_handle\"," | |
| 322 "\"instrument_phone_number\":\"phone_number\"," | |
| 323 "\"merchant_domain\":\"https://example.com/\"," | |
| 324 "\"risk_params\":\"\"" | |
| 325 "}"; | |
| 326 | |
| 327 const char kSaveInstrumentAndAddressValidRequest[] = | |
| 328 "{" | |
| 329 "\"instrument\":" | |
| 330 "{" | |
| 331 "\"credit_card\":" | |
| 332 "{" | |
| 333 "\"address\":" | |
| 334 "{" | |
| 335 "\"address_line\":" | |
| 336 "[" | |
| 337 "\"address_line_1\"," | |
| 338 "\"address_line_2\"" | |
| 339 "]," | |
| 340 "\"administrative_area_name\":\"admin_area_name\"," | |
| 341 "\"country_name_code\":\"country_name_code\"," | |
| 342 "\"locality_name\":\"locality_name\"," | |
| 343 "\"postal_code_number\":\"postal_code_number\"," | |
| 344 "\"recipient_name\":\"recipient_name\"" | |
| 345 "}," | |
| 346 "\"exp_month\":12," | |
| 347 "\"exp_year\":2012," | |
| 348 "\"fop_type\":\"VISA\"," | |
| 349 "\"last_4_digits\":\"4448\"" | |
| 350 "}," | |
| 351 "\"type\":\"CREDIT_CARD\"" | |
| 352 "}," | |
| 353 "\"instrument_escrow_handle\":\"escrow_handle\"," | |
| 354 "\"instrument_phone_number\":\"phone_number\"," | |
| 355 "\"merchant_domain\":\"https://example.com/\"," | |
| 356 "\"risk_params\":\"\"," | |
| 357 "\"shipping_address\":" | |
| 358 "{" | |
| 359 "\"phone_number\":\"ship_phone_number\"," | |
| 360 "\"postal_address\":" | |
| 361 "{" | |
| 362 "\"address_line\":" | |
| 363 "[" | |
| 364 "\"ship_address_line_1\"," | |
| 365 "\"ship_address_line_2\"" | |
| 366 "]," | |
| 367 "\"administrative_area_name\":\"ship_admin_area_name\"," | |
| 368 "\"country_name_code\":\"ship_country_name_code\"," | |
| 369 "\"locality_name\":\"ship_locality_name\"," | |
| 370 "\"postal_code_number\":\"ship_postal_code_number\"," | |
| 371 "\"recipient_name\":\"ship_recipient_name\"" | |
| 372 "}" | |
| 373 "}" | |
| 374 "}"; | |
| 375 | |
| 376 const char kSendAutocheckoutStatusOfSuccessValidRequest[] = | |
| 377 "{" | |
| 378 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 379 "\"merchant_domain\":\"https://example.com/\"," | |
| 380 "\"success\":true" | |
| 381 "}"; | |
| 382 | |
| 383 const char kSendAutocheckoutStatusOfFailureValidRequest[] = | |
| 384 "{" | |
| 385 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 386 "\"merchant_domain\":\"https://example.com/\"," | |
| 387 "\"reason\":\"CANNOT_PROCEED\"," | |
| 388 "\"success\":false" | |
| 389 "}"; | |
| 390 | |
| 391 const char kUpdateInstrumentValidRequest[] = | |
| 392 "{" | |
| 393 "\"instrument_phone_number\":\"phone_number\"," | |
| 394 "\"merchant_domain\":\"https://example.com/\"," | |
| 395 "\"risk_params\":\"\"," | |
| 396 "\"upgraded_billing_address\":" | |
| 397 "{" | |
| 398 "\"address_line\":" | |
| 399 "[" | |
| 400 "\"address_line_1\"," | |
| 401 "\"address_line_2\"" | |
| 402 "]," | |
| 403 "\"administrative_area_name\":\"admin_area_name\"," | |
| 404 "\"country_name_code\":\"country_name_code\"," | |
| 405 "\"locality_name\":\"locality_name\"," | |
| 406 "\"postal_code_number\":\"postal_code_number\"," | |
| 407 "\"recipient_name\":\"recipient_name\"" | |
| 408 "}," | |
| 409 "\"upgraded_instrument_id\":\"instrument_id\"" | |
| 410 "}"; | |
| 411 | |
| 412 } // namespace | |
| 413 | |
| 414 namespace autofill { | |
| 415 namespace wallet { | |
| 416 | |
| 417 class WalletClientTest : public testing::Test { | |
| 418 public: | |
| 419 WalletClientTest() : io_thread_(content::BrowserThread::IO) {} | |
| 420 | |
| 421 virtual void SetUp() { | |
| 422 io_thread_.StartIOThread(); | |
| 423 profile_.CreateRequestContext(); | |
| 424 } | |
| 425 | |
| 426 virtual void TearDown() { | |
| 427 profile_.ResetRequestContext(); | |
| 428 io_thread_.Stop(); | |
| 429 } | |
| 430 | |
| 431 std::string GetData(net::TestURLFetcher* fetcher) { | |
| 432 std::string data = fetcher->upload_data(); | |
| 433 scoped_ptr<Value> root(base::JSONReader::Read(data)); | |
| 434 | |
| 435 // If this is not a JSON dictionary, return plain text. | |
| 436 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) | |
| 437 return data; | |
| 438 | |
| 439 // Remove api_key entry (to prevent accidental leak), return JSON as text. | |
| 440 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get()); | |
| 441 dict->Remove("api_key", NULL); | |
| 442 base::JSONWriter::Write(dict, &data); | |
| 443 return data; | |
| 444 } | |
| 445 | |
| 446 void VerifyAndFinishRequest(const net::TestURLFetcherFactory& fetcher_factory, | |
| 447 net::HttpStatusCode response_code, | |
| 448 const std::string& request_body, | |
| 449 const std::string& response_body) { | |
| 450 net::TestURLFetcher* fetcher = fetcher_factory.GetFetcherByID(0); | |
| 451 ASSERT_TRUE(fetcher); | |
| 452 EXPECT_EQ(request_body, GetData(fetcher)); | |
| 453 fetcher->set_response_code(response_code); | |
| 454 fetcher->SetResponseString(response_body); | |
| 455 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 456 } | |
| 457 protected: | |
| 458 TestingProfile profile_; | |
| 459 | |
| 460 private: | |
| 461 // The profile's request context must be released on the IO thread. | |
| 462 content::TestBrowserThread io_thread_; | |
| 463 }; | |
| 464 | |
| 465 class MockWalletClientObserver : public WalletClientObserver { | |
| 466 public: | |
| 467 MockWalletClientObserver() | |
| 468 : full_wallets_received_(0), wallet_items_received_(0) {} | |
| 469 ~MockWalletClientObserver() {} | |
| 470 | |
| 471 MOCK_METHOD0(OnDidAcceptLegalDocuments, void()); | |
| 472 MOCK_METHOD1(OnDidAuthenticateInstrument, void(bool success)); | |
| 473 MOCK_METHOD2(OnDidSaveAddress, | |
| 474 void(const std::string& address_id, | |
| 475 const std::vector<RequiredAction>& required_actions)); | |
| 476 MOCK_METHOD2(OnDidSaveInstrument, | |
| 477 void(const std::string& instrument_id, | |
| 478 const std::vector<RequiredAction>& required_actions)); | |
| 479 MOCK_METHOD3(OnDidSaveInstrumentAndAddress, | |
| 480 void(const std::string& instrument_id, | |
| 481 const std::string& shipping_address_id, | |
| 482 const std::vector<RequiredAction>& required_actions)); | |
| 483 MOCK_METHOD0(OnDidSendAutocheckoutStatus, void()); | |
| 484 MOCK_METHOD2(OnDidUpdateInstrument, | |
| 485 void(const std::string& instrument_id, | |
| 486 const std::vector<RequiredAction>& required_actions)); | |
| 487 MOCK_METHOD0(OnWalletError, void()); | |
| 488 MOCK_METHOD0(OnMalformedResponse, void()); | |
| 489 MOCK_METHOD1(OnNetworkError, void(int response_code)); | |
| 490 | |
| 491 virtual void OnDidGetFullWallet(scoped_ptr<FullWallet> full_wallet) OVERRIDE { | |
| 492 EXPECT_TRUE(full_wallet); | |
| 493 ++full_wallets_received_; | |
| 494 } | |
| 495 virtual void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items) | |
| 496 OVERRIDE { | |
| 497 EXPECT_TRUE(wallet_items); | |
| 498 ++wallet_items_received_; | |
| 499 } | |
| 500 size_t full_wallets_received() const { return full_wallets_received_; } | |
| 501 size_t wallet_items_received() const { return wallet_items_received_; } | |
| 502 | |
| 503 private: | |
| 504 size_t full_wallets_received_; | |
| 505 size_t wallet_items_received_; | |
| 506 }; | |
| 507 | |
| 508 // TODO(ahutter): Implement API compatibility tests. See | |
| 509 // http://crbug.com/164465. | |
| 510 | |
| 511 // TODO(ahutter): Improve this when the error body is captured. See | |
| 512 // http://crbug.com/164410. | |
| 513 TEST_F(WalletClientTest, WalletErrorOnExpectedVoidResponse) { | |
| 514 MockWalletClientObserver observer; | |
| 515 EXPECT_CALL(observer, OnWalletError()).Times(1); | |
| 516 | |
| 517 net::TestURLFetcherFactory factory; | |
| 518 | |
| 519 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 520 wallet_client.SendAutocheckoutStatus(autofill::SUCCESS, | |
| 521 GURL(kMerchantUrl), | |
| 522 ""); | |
| 523 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 524 ASSERT_TRUE(fetcher); | |
| 525 fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 526 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 527 } | |
| 528 | |
| 529 // TODO(ahutter): Improve this when the error body is captured. See | |
| 530 // http://crbug.com/164410. | |
| 531 TEST_F(WalletClientTest, WalletErrorOnExpectedResponse) { | |
| 532 MockWalletClientObserver observer; | |
| 533 EXPECT_CALL(observer, OnWalletError()).Times(1); | |
| 534 | |
| 535 net::TestURLFetcherFactory factory; | |
| 536 | |
| 537 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 538 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 539 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 540 ASSERT_TRUE(fetcher); | |
| 541 fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 542 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 543 } | |
| 544 | |
| 545 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) { | |
| 546 MockWalletClientObserver observer; | |
| 547 EXPECT_CALL(observer, OnNetworkError(net::HTTP_UNAUTHORIZED)).Times(1); | |
| 548 | |
| 549 net::TestURLFetcherFactory factory; | |
| 550 | |
| 551 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 552 wallet_client.SendAutocheckoutStatus(autofill::SUCCESS, | |
| 553 GURL(kMerchantUrl), | |
| 554 ""); | |
| 555 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 556 ASSERT_TRUE(fetcher); | |
| 557 fetcher->set_response_code(net::HTTP_UNAUTHORIZED); | |
| 558 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 559 } | |
| 560 | |
| 561 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { | |
| 562 MockWalletClientObserver observer; | |
| 563 EXPECT_CALL(observer, OnNetworkError(net::HTTP_UNAUTHORIZED)).Times(1); | |
| 564 | |
| 565 net::TestURLFetcherFactory factory; | |
| 566 | |
| 567 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 568 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 569 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 570 ASSERT_TRUE(fetcher); | |
| 571 fetcher->set_response_code(net::HTTP_UNAUTHORIZED); | |
| 572 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 573 } | |
| 574 | |
| 575 TEST_F(WalletClientTest, RequestError) { | |
| 576 MockWalletClientObserver observer; | |
| 577 EXPECT_CALL(observer, OnWalletError()).Times(1); | |
| 578 | |
| 579 net::TestURLFetcherFactory factory; | |
| 580 | |
| 581 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 582 wallet_client.SendAutocheckoutStatus(autofill::SUCCESS, | |
| 583 GURL(kMerchantUrl), | |
| 584 ""); | |
| 585 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 586 ASSERT_TRUE(fetcher); | |
| 587 fetcher->set_response_code(net::HTTP_BAD_REQUEST); | |
| 588 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 589 } | |
| 590 | |
| 591 TEST_F(WalletClientTest, GetFullWalletSuccess) { | |
| 592 MockWalletClientObserver observer; | |
| 593 net::TestURLFetcherFactory factory; | |
| 594 | |
| 595 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 596 Cart cart("currency_code", "currency_code"); | |
| 597 wallet_client.GetFullWallet("instrument_id", | |
| 598 "shipping_address_id", | |
| 599 GURL(kMerchantUrl), | |
| 600 cart, | |
| 601 "google_transaction_id", | |
| 602 DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 603 | |
| 604 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 605 ASSERT_TRUE(encryption_fetcher); | |
| 606 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 607 encryption_fetcher->SetResponseString( | |
| 608 "session_material|encrypted_one_time_pad"); | |
| 609 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 610 | |
| 611 VerifyAndFinishRequest(factory, | |
| 612 net::HTTP_OK, | |
| 613 kGetFullWalletValidRequest, | |
| 614 kGetFullWalletValidResponse); | |
| 615 EXPECT_EQ(1U, observer.full_wallets_received()); | |
| 616 } | |
| 617 | |
| 618 TEST_F(WalletClientTest, GetFullWalletEncryptionDown) { | |
| 619 MockWalletClientObserver observer; | |
| 620 EXPECT_CALL(observer, | |
| 621 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); | |
| 622 | |
| 623 net::TestURLFetcherFactory factory; | |
| 624 | |
| 625 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 626 Cart cart("currency_code", "currency_code"); | |
| 627 wallet_client.GetFullWallet("instrument_id", | |
| 628 "shipping_address_id", | |
| 629 GURL(kMerchantUrl), | |
| 630 cart, | |
| 631 "google_transaction_id", | |
| 632 DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 633 | |
| 634 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 635 ASSERT_TRUE(encryption_fetcher); | |
| 636 encryption_fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 637 encryption_fetcher->SetResponseString(std::string()); | |
| 638 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 639 | |
| 640 EXPECT_EQ(0U, observer.full_wallets_received()); | |
| 641 } | |
| 642 | |
| 643 TEST_F(WalletClientTest, GetFullWalletEncryptionMalformed) { | |
| 644 MockWalletClientObserver observer; | |
| 645 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 646 | |
| 647 net::TestURLFetcherFactory factory; | |
| 648 | |
| 649 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 650 Cart cart("currency_code", "currency_code"); | |
| 651 wallet_client.GetFullWallet("instrument_id", | |
| 652 "shipping_address_id", | |
| 653 GURL(kMerchantUrl), | |
| 654 cart, | |
| 655 "google_transaction_id", | |
| 656 DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 657 | |
| 658 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 659 ASSERT_TRUE(encryption_fetcher); | |
| 660 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 661 encryption_fetcher->SetResponseString( | |
| 662 "session_material:encrypted_one_time_pad"); | |
| 663 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 664 | |
| 665 EXPECT_EQ(0U, observer.full_wallets_received()); | |
| 666 } | |
| 667 | |
| 668 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { | |
| 669 MockWalletClientObserver observer; | |
| 670 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 671 | |
| 672 net::TestURLFetcherFactory factory; | |
| 673 | |
| 674 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 675 Cart cart("currency_code", "currency_code"); | |
| 676 wallet_client.GetFullWallet("instrument_id", | |
| 677 "shipping_address_id", | |
| 678 GURL(kMerchantUrl), | |
| 679 cart, | |
| 680 "google_transaction_id", | |
| 681 DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 682 | |
| 683 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 684 ASSERT_TRUE(encryption_fetcher); | |
| 685 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 686 encryption_fetcher->SetResponseString( | |
| 687 "session_material|encrypted_one_time_pad"); | |
| 688 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 689 | |
| 690 VerifyAndFinishRequest(factory, | |
| 691 net::HTTP_OK, | |
| 692 kGetFullWalletValidRequest, | |
| 693 kGetFullWalletInvalidResponse); | |
| 694 EXPECT_EQ(0U, observer.full_wallets_received()); | |
| 695 } | |
| 696 | |
| 697 TEST_F(WalletClientTest, AcceptLegalDocuments) { | |
| 698 MockWalletClientObserver observer; | |
| 699 EXPECT_CALL(observer, OnDidAcceptLegalDocuments()).Times(1); | |
| 700 | |
| 701 net::TestURLFetcherFactory factory; | |
| 702 | |
| 703 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 704 std::vector<std::string> doc_ids; | |
| 705 doc_ids.push_back("doc_1"); | |
| 706 doc_ids.push_back("doc_2"); | |
| 707 wallet_client.AcceptLegalDocuments(doc_ids, | |
| 708 kGoogleTransactionId, | |
| 709 GURL(kMerchantUrl)); | |
| 710 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 711 ASSERT_TRUE(fetcher); | |
| 712 EXPECT_EQ(kAcceptLegalDocumentsValidRequest, GetData(fetcher)); | |
| 713 fetcher->SetResponseString(")]}'"); // Invalid JSON. Should be ignored. | |
| 714 fetcher->set_response_code(net::HTTP_OK); | |
| 715 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 716 } | |
| 717 | |
| 718 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) { | |
| 719 MockWalletClientObserver observer; | |
| 720 EXPECT_CALL(observer, OnDidAuthenticateInstrument(true)).Times(1); | |
| 721 | |
| 722 net::TestURLFetcherFactory factory; | |
| 723 | |
| 724 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 725 wallet_client.AuthenticateInstrument("instrument_id", | |
| 726 "cvv", | |
| 727 "obfuscated_gaia_id"); | |
| 728 | |
| 729 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 730 ASSERT_TRUE(encryption_fetcher); | |
| 731 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 732 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 733 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 734 | |
| 735 VerifyAndFinishRequest(factory, | |
| 736 net::HTTP_OK, | |
| 737 kAuthenticateInstrumentValidRequest, | |
| 738 kAuthenticateInstrumentSuccessResponse); | |
| 739 } | |
| 740 | |
| 741 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) { | |
| 742 MockWalletClientObserver observer; | |
| 743 EXPECT_CALL(observer, OnDidAuthenticateInstrument(false)).Times(1); | |
| 744 | |
| 745 net::TestURLFetcherFactory factory; | |
| 746 | |
| 747 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 748 wallet_client.AuthenticateInstrument("instrument_id", | |
| 749 "cvv", | |
| 750 "obfuscated_gaia_id"); | |
| 751 | |
| 752 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 753 ASSERT_TRUE(encryption_fetcher); | |
| 754 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 755 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 756 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 757 | |
| 758 VerifyAndFinishRequest(factory, | |
| 759 net::HTTP_OK, | |
| 760 kAuthenticateInstrumentValidRequest, | |
| 761 kAuthenticateInstrumentFailureResponse); | |
| 762 } | |
| 763 | |
| 764 TEST_F(WalletClientTest, AuthenticateInstrumentEscrowDown) { | |
| 765 MockWalletClientObserver observer; | |
| 766 EXPECT_CALL(observer, | |
| 767 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); | |
| 768 | |
| 769 net::TestURLFetcherFactory factory; | |
| 770 | |
| 771 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 772 wallet_client.AuthenticateInstrument("instrument_id", | |
| 773 "cvv", | |
| 774 "obfuscated_gaia_id"); | |
| 775 | |
| 776 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 777 ASSERT_TRUE(encryption_fetcher); | |
| 778 encryption_fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 779 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 780 } | |
| 781 | |
| 782 TEST_F(WalletClientTest, AuthenticateInstrumentEscrowMalformed) { | |
| 783 MockWalletClientObserver observer; | |
| 784 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 785 | |
| 786 net::TestURLFetcherFactory factory; | |
| 787 | |
| 788 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 789 wallet_client.AuthenticateInstrument("instrument_id", | |
| 790 "cvv", | |
| 791 "obfuscated_gaia_id"); | |
| 792 | |
| 793 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 794 ASSERT_TRUE(encryption_fetcher); | |
| 795 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 796 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 797 } | |
| 798 | |
| 799 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) { | |
| 800 MockWalletClientObserver observer; | |
| 801 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 802 | |
| 803 net::TestURLFetcherFactory factory; | |
| 804 | |
| 805 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 806 wallet_client.AuthenticateInstrument("instrument_id", | |
| 807 "cvv", | |
| 808 "obfuscated_gaia_id"); | |
| 809 | |
| 810 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 811 ASSERT_TRUE(encryption_fetcher); | |
| 812 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 813 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 814 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 815 | |
| 816 VerifyAndFinishRequest(factory, | |
| 817 net::HTTP_OK, | |
| 818 kAuthenticateInstrumentValidRequest, | |
| 819 kSaveInvalidResponse); | |
| 820 } | |
| 821 | |
| 822 // TODO(ahutter): Add failure tests for GetWalletItems. | |
| 823 | |
| 824 TEST_F(WalletClientTest, GetWalletItems) { | |
| 825 MockWalletClientObserver observer; | |
| 826 net::TestURLFetcherFactory factory; | |
| 827 | |
| 828 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 829 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 830 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 831 ASSERT_TRUE(fetcher); | |
| 832 EXPECT_EQ(kGetWalletItemsValidRequest, GetData(fetcher)); | |
| 833 fetcher->set_response_code(net::HTTP_OK); | |
| 834 fetcher->SetResponseString(kGetWalletItemsValidResponse); | |
| 835 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 836 | |
| 837 EXPECT_EQ(1U, observer.wallet_items_received()); | |
| 838 } | |
| 839 | |
| 840 TEST_F(WalletClientTest, SaveAddressSucceeded) { | |
| 841 MockWalletClientObserver observer; | |
| 842 EXPECT_CALL(observer, | |
| 843 OnDidSaveAddress("shipping_address_id", | |
| 844 std::vector<RequiredAction>())).Times(1); | |
| 845 | |
| 846 net::TestURLFetcherFactory factory; | |
| 847 | |
| 848 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 849 | |
| 850 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 851 wallet_client.SaveAddress(*address, GURL(kMerchantUrl)); | |
| 852 VerifyAndFinishRequest(factory, | |
| 853 net::HTTP_OK, | |
| 854 kSaveAddressValidRequest, | |
| 855 kSaveAddressValidResponse); | |
| 856 } | |
| 857 | |
| 858 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) { | |
| 859 MockWalletClientObserver observer; | |
| 860 | |
| 861 std::vector<RequiredAction> required_actions; | |
| 862 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 863 required_actions.push_back(INVALID_FORM_FIELD); | |
| 864 | |
| 865 EXPECT_CALL(observer, | |
| 866 OnDidSaveAddress(std::string(), | |
| 867 required_actions)).Times(1); | |
| 868 | |
| 869 net::TestURLFetcherFactory factory; | |
| 870 | |
| 871 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 872 | |
| 873 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 874 wallet_client.SaveAddress(*address, GURL(kMerchantUrl)); | |
| 875 VerifyAndFinishRequest(factory, | |
| 876 net::HTTP_OK, | |
| 877 kSaveAddressValidRequest, | |
| 878 kSaveAddressWithRequiredActionsValidResponse); | |
| 879 } | |
| 880 | |
| 881 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) { | |
| 882 MockWalletClientObserver observer; | |
| 883 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 884 | |
| 885 net::TestURLFetcherFactory factory; | |
| 886 | |
| 887 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 888 | |
| 889 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 890 wallet_client.SaveAddress(*address, GURL(kMerchantUrl)); | |
| 891 VerifyAndFinishRequest(factory, | |
| 892 net::HTTP_OK, | |
| 893 kSaveAddressValidRequest, | |
| 894 kSaveWithInvalidRequiredActionsResponse); | |
| 895 } | |
| 896 | |
| 897 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { | |
| 898 MockWalletClientObserver observer; | |
| 899 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 900 | |
| 901 net::TestURLFetcherFactory factory; | |
| 902 | |
| 903 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 904 | |
| 905 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 906 wallet_client.SaveAddress(*address, GURL(kMerchantUrl)); | |
| 907 VerifyAndFinishRequest(factory, | |
| 908 net::HTTP_OK, | |
| 909 kSaveAddressValidRequest, | |
| 910 kSaveInvalidResponse); | |
| 911 } | |
| 912 | |
| 913 TEST_F(WalletClientTest, SaveInstrumentSucceeded) { | |
| 914 MockWalletClientObserver observer; | |
| 915 EXPECT_CALL(observer, | |
| 916 OnDidSaveInstrument("instrument_id", | |
| 917 std::vector<RequiredAction>())).Times(1); | |
| 918 | |
| 919 net::TestURLFetcherFactory factory; | |
| 920 | |
| 921 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 922 | |
| 923 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 924 wallet_client.SaveInstrument(*instrument, | |
| 925 "obfuscated_gaia_id", | |
| 926 GURL(kMerchantUrl)); | |
| 927 | |
| 928 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 929 ASSERT_TRUE(encryption_fetcher); | |
| 930 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 931 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 932 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 933 | |
| 934 VerifyAndFinishRequest(factory, | |
| 935 net::HTTP_OK, | |
| 936 kSaveInstrumentValidRequest, | |
| 937 kSaveInstrumentValidResponse); | |
| 938 } | |
| 939 | |
| 940 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) { | |
| 941 MockWalletClientObserver observer; | |
| 942 | |
| 943 std::vector<RequiredAction> required_actions; | |
| 944 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 945 required_actions.push_back(INVALID_FORM_FIELD); | |
| 946 | |
| 947 EXPECT_CALL(observer, | |
| 948 OnDidSaveInstrument(std::string(), | |
| 949 required_actions)).Times(1); | |
| 950 | |
| 951 net::TestURLFetcherFactory factory; | |
| 952 | |
| 953 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 954 | |
| 955 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 956 wallet_client.SaveInstrument(*instrument, | |
| 957 "obfuscated_gaia_id", | |
| 958 GURL(kMerchantUrl)); | |
| 959 | |
| 960 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 961 ASSERT_TRUE(encryption_fetcher); | |
| 962 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 963 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 964 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 965 | |
| 966 VerifyAndFinishRequest(factory, | |
| 967 net::HTTP_OK, | |
| 968 kSaveInstrumentValidRequest, | |
| 969 kSaveInstrumentWithRequiredActionsValidResponse); | |
| 970 } | |
| 971 | |
| 972 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) { | |
| 973 MockWalletClientObserver observer; | |
| 974 | |
| 975 EXPECT_CALL(observer, OnMalformedResponse()); | |
| 976 | |
| 977 net::TestURLFetcherFactory factory; | |
| 978 | |
| 979 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 980 | |
| 981 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 982 wallet_client.SaveInstrument(*instrument, | |
| 983 "obfuscated_gaia_id", | |
| 984 GURL(kMerchantUrl)); | |
| 985 | |
| 986 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 987 ASSERT_TRUE(encryption_fetcher); | |
| 988 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 989 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 990 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 991 | |
| 992 VerifyAndFinishRequest(factory, | |
| 993 net::HTTP_OK, | |
| 994 kSaveInstrumentValidRequest, | |
| 995 kSaveWithInvalidRequiredActionsResponse); | |
| 996 } | |
| 997 | |
| 998 TEST_F(WalletClientTest, SaveInstrumentEscrowDown) { | |
| 999 MockWalletClientObserver observer; | |
| 1000 EXPECT_CALL(observer, | |
| 1001 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); | |
| 1002 | |
| 1003 net::TestURLFetcherFactory factory; | |
| 1004 | |
| 1005 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1006 | |
| 1007 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1008 wallet_client.SaveInstrument(*instrument, | |
| 1009 "obfuscated_gaia_id", | |
| 1010 GURL(kMerchantUrl)); | |
| 1011 | |
| 1012 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1013 ASSERT_TRUE(encryption_fetcher); | |
| 1014 encryption_fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 1015 encryption_fetcher->SetResponseString(std::string()); | |
| 1016 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1017 } | |
| 1018 | |
| 1019 TEST_F(WalletClientTest, SaveInstrumentEscrowMalformed) { | |
| 1020 MockWalletClientObserver observer; | |
| 1021 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1022 | |
| 1023 net::TestURLFetcherFactory factory; | |
| 1024 | |
| 1025 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1026 | |
| 1027 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1028 wallet_client.SaveInstrument(*instrument, | |
| 1029 "obfuscated_gaia_id", | |
| 1030 GURL(kMerchantUrl)); | |
| 1031 | |
| 1032 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1033 ASSERT_TRUE(encryption_fetcher); | |
| 1034 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1035 encryption_fetcher->SetResponseString(std::string()); | |
| 1036 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1037 } | |
| 1038 | |
| 1039 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) { | |
| 1040 MockWalletClientObserver observer; | |
| 1041 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1042 | |
| 1043 net::TestURLFetcherFactory factory; | |
| 1044 | |
| 1045 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1046 | |
| 1047 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1048 wallet_client.SaveInstrument(*instrument, | |
| 1049 "obfuscated_gaia_id", | |
| 1050 GURL(kMerchantUrl)); | |
| 1051 | |
| 1052 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1053 ASSERT_TRUE(encryption_fetcher); | |
| 1054 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1055 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1056 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1057 | |
| 1058 VerifyAndFinishRequest(factory, | |
| 1059 net::HTTP_OK, | |
| 1060 kSaveInstrumentValidRequest, | |
| 1061 kSaveInvalidResponse); | |
| 1062 } | |
| 1063 | |
| 1064 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { | |
| 1065 MockWalletClientObserver observer; | |
| 1066 EXPECT_CALL(observer, | |
| 1067 OnDidSaveInstrumentAndAddress( | |
| 1068 "instrument_id", | |
| 1069 "shipping_address_id", | |
| 1070 std::vector<RequiredAction>())).Times(1); | |
| 1071 | |
| 1072 net::TestURLFetcherFactory factory; | |
| 1073 | |
| 1074 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1075 | |
| 1076 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1077 | |
| 1078 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1079 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1080 *address, | |
| 1081 "obfuscated_gaia_id", | |
| 1082 GURL(kMerchantUrl)); | |
| 1083 | |
| 1084 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1085 ASSERT_TRUE(encryption_fetcher); | |
| 1086 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1087 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1088 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1089 VerifyAndFinishRequest(factory, | |
| 1090 net::HTTP_OK, | |
| 1091 kSaveInstrumentAndAddressValidRequest, | |
| 1092 kSaveInstrumentAndAddressValidResponse); | |
| 1093 } | |
| 1094 | |
| 1095 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) { | |
| 1096 MockWalletClientObserver observer; | |
| 1097 | |
| 1098 std::vector<RequiredAction> required_actions; | |
| 1099 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1100 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1101 | |
| 1102 EXPECT_CALL(observer, | |
| 1103 OnDidSaveInstrumentAndAddress( | |
| 1104 std::string(), | |
| 1105 std::string(), | |
| 1106 required_actions)).Times(1); | |
| 1107 | |
| 1108 net::TestURLFetcherFactory factory; | |
| 1109 | |
| 1110 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1111 | |
| 1112 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1113 | |
| 1114 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1115 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1116 *address, | |
| 1117 "obfuscated_gaia_id", | |
| 1118 GURL(kMerchantUrl)); | |
| 1119 | |
| 1120 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1121 ASSERT_TRUE(encryption_fetcher); | |
| 1122 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1123 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1124 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1125 VerifyAndFinishRequest( | |
| 1126 factory, | |
| 1127 net::HTTP_OK, | |
| 1128 kSaveInstrumentAndAddressValidRequest, | |
| 1129 kSaveInstrumentAndAddressWithRequiredActionsValidResponse); | |
| 1130 } | |
| 1131 | |
| 1132 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) { | |
| 1133 MockWalletClientObserver observer; | |
| 1134 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1135 | |
| 1136 net::TestURLFetcherFactory factory; | |
| 1137 | |
| 1138 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1139 | |
| 1140 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1141 | |
| 1142 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1143 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1144 *address, | |
| 1145 "obfuscated_gaia_id", | |
| 1146 GURL(kMerchantUrl)); | |
| 1147 | |
| 1148 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1149 ASSERT_TRUE(encryption_fetcher); | |
| 1150 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1151 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1152 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1153 | |
| 1154 VerifyAndFinishRequest(factory, | |
| 1155 net::HTTP_OK, | |
| 1156 kSaveInstrumentAndAddressValidRequest, | |
| 1157 kSaveWithInvalidRequiredActionsResponse); | |
| 1158 } | |
| 1159 | |
| 1160 TEST_F(WalletClientTest, SaveInstrumentAndAddressEscrowDown) { | |
| 1161 MockWalletClientObserver observer; | |
| 1162 EXPECT_CALL(observer, | |
| 1163 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); | |
| 1164 | |
| 1165 net::TestURLFetcherFactory factory; | |
| 1166 | |
| 1167 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1168 | |
| 1169 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1170 | |
| 1171 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1172 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1173 *address, | |
| 1174 "obfuscated_gaia_id", | |
| 1175 GURL(kMerchantUrl)); | |
| 1176 | |
| 1177 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1178 ASSERT_TRUE(encryption_fetcher); | |
| 1179 encryption_fetcher->set_response_code(net::HTTP_INTERNAL_SERVER_ERROR); | |
| 1180 encryption_fetcher->SetResponseString(std::string()); | |
| 1181 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1182 } | |
| 1183 | |
| 1184 TEST_F(WalletClientTest, SaveInstrumentAndAddressEscrowMalformed) { | |
| 1185 MockWalletClientObserver observer; | |
| 1186 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1187 | |
| 1188 net::TestURLFetcherFactory factory; | |
| 1189 | |
| 1190 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1191 | |
| 1192 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1193 | |
| 1194 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1195 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1196 *address, | |
| 1197 "obfuscated_gaia_id", | |
| 1198 GURL(kMerchantUrl)); | |
| 1199 | |
| 1200 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1201 ASSERT_TRUE(encryption_fetcher); | |
| 1202 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1203 encryption_fetcher->SetResponseString(std::string()); | |
| 1204 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1205 } | |
| 1206 | |
| 1207 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedAddressMissing) { | |
| 1208 MockWalletClientObserver observer; | |
| 1209 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1210 | |
| 1211 net::TestURLFetcherFactory factory; | |
| 1212 | |
| 1213 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1214 | |
| 1215 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1216 | |
| 1217 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1218 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1219 *address, | |
| 1220 "obfuscated_gaia_id", | |
| 1221 GURL(kMerchantUrl)); | |
| 1222 | |
| 1223 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1224 ASSERT_TRUE(encryption_fetcher); | |
| 1225 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1226 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1227 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1228 | |
| 1229 VerifyAndFinishRequest(factory, | |
| 1230 net::HTTP_OK, | |
| 1231 kSaveInstrumentAndAddressValidRequest, | |
| 1232 kSaveInstrumentAndAddressMissingAddressResponse); | |
| 1233 } | |
| 1234 | |
| 1235 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInstrumentMissing) { | |
| 1236 MockWalletClientObserver observer; | |
| 1237 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1238 | |
| 1239 net::TestURLFetcherFactory factory; | |
| 1240 | |
| 1241 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1242 | |
| 1243 scoped_ptr<Address> address = GetTestShippingAddress(); | |
| 1244 | |
| 1245 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1246 wallet_client.SaveInstrumentAndAddress(*instrument, | |
| 1247 *address, | |
| 1248 "obfuscated_gaia_id", | |
| 1249 GURL(kMerchantUrl)); | |
| 1250 | |
| 1251 net::TestURLFetcher* encryption_fetcher = factory.GetFetcherByID(1); | |
| 1252 ASSERT_TRUE(encryption_fetcher); | |
| 1253 encryption_fetcher->set_response_code(net::HTTP_OK); | |
| 1254 encryption_fetcher->SetResponseString("escrow_handle"); | |
| 1255 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher); | |
| 1256 | |
| 1257 VerifyAndFinishRequest(factory, | |
| 1258 net::HTTP_OK, | |
| 1259 kSaveInstrumentAndAddressValidRequest, | |
| 1260 kSaveInstrumentAndAddressMissingInstrumentResponse); | |
| 1261 } | |
| 1262 | |
| 1263 TEST_F(WalletClientTest, UpdateInstrumentSucceeded) { | |
| 1264 MockWalletClientObserver observer; | |
| 1265 EXPECT_CALL(observer, | |
| 1266 OnDidUpdateInstrument("instrument_id", | |
| 1267 std::vector<RequiredAction>())).Times(1); | |
| 1268 | |
| 1269 net::TestURLFetcherFactory factory; | |
| 1270 | |
| 1271 scoped_ptr<Address> address = GetTestAddress(); | |
| 1272 | |
| 1273 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1274 wallet_client.UpdateInstrument("instrument_id", | |
| 1275 *address, | |
| 1276 GURL(kMerchantUrl)); | |
| 1277 VerifyAndFinishRequest(factory, | |
| 1278 net::HTTP_OK, | |
| 1279 kUpdateInstrumentValidRequest, | |
| 1280 kUpdateInstrumentValidResponse); | |
| 1281 } | |
| 1282 | |
| 1283 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) { | |
| 1284 MockWalletClientObserver observer; | |
| 1285 | |
| 1286 std::vector<RequiredAction> required_actions; | |
| 1287 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1288 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1289 | |
| 1290 EXPECT_CALL(observer, | |
| 1291 OnDidUpdateInstrument(std::string(), | |
| 1292 required_actions)).Times(1); | |
| 1293 | |
| 1294 net::TestURLFetcherFactory factory; | |
| 1295 | |
| 1296 scoped_ptr<Address> address = GetTestAddress(); | |
| 1297 | |
| 1298 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1299 wallet_client.UpdateInstrument("instrument_id", | |
| 1300 *address, | |
| 1301 GURL(kMerchantUrl)); | |
| 1302 VerifyAndFinishRequest(factory, | |
| 1303 net::HTTP_OK, | |
| 1304 kUpdateInstrumentValidRequest, | |
| 1305 kUpdateInstrumentWithRequiredActionsValidResponse); | |
| 1306 } | |
| 1307 | |
| 1308 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) { | |
| 1309 MockWalletClientObserver observer; | |
| 1310 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1311 | |
| 1312 net::TestURLFetcherFactory factory; | |
| 1313 | |
| 1314 scoped_ptr<Address> address = GetTestAddress(); | |
| 1315 | |
| 1316 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1317 wallet_client.UpdateInstrument("instrument_id", | |
| 1318 *address, | |
| 1319 GURL(kMerchantUrl)); | |
| 1320 VerifyAndFinishRequest(factory, | |
| 1321 net::HTTP_OK, | |
| 1322 kUpdateInstrumentValidRequest, | |
| 1323 kSaveWithInvalidRequiredActionsResponse); | |
| 1324 } | |
| 1325 | |
| 1326 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) { | |
| 1327 MockWalletClientObserver observer; | |
| 1328 EXPECT_CALL(observer, OnMalformedResponse()).Times(1); | |
| 1329 | |
| 1330 net::TestURLFetcherFactory factory; | |
| 1331 | |
| 1332 scoped_ptr<Address> address = GetTestAddress(); | |
| 1333 | |
| 1334 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1335 wallet_client.UpdateInstrument("instrument_id", | |
| 1336 *address, | |
| 1337 GURL(kMerchantUrl)); | |
| 1338 VerifyAndFinishRequest(factory, | |
| 1339 net::HTTP_OK, | |
| 1340 kUpdateInstrumentValidRequest, | |
| 1341 kUpdateInstrumentMalformedResponse); | |
| 1342 } | |
| 1343 | |
| 1344 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { | |
| 1345 MockWalletClientObserver observer; | |
| 1346 EXPECT_CALL(observer, OnDidSendAutocheckoutStatus()).Times(1); | |
| 1347 | |
| 1348 net::TestURLFetcherFactory factory; | |
| 1349 | |
| 1350 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1351 wallet_client.SendAutocheckoutStatus(autofill::SUCCESS, | |
| 1352 GURL(kMerchantUrl), | |
| 1353 "google_transaction_id"); | |
| 1354 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 1355 ASSERT_TRUE(fetcher); | |
| 1356 EXPECT_EQ(kSendAutocheckoutStatusOfSuccessValidRequest, GetData(fetcher)); | |
| 1357 fetcher->SetResponseString(")]}'"); // Invalid JSON. Should be ignored. | |
| 1358 fetcher->set_response_code(net::HTTP_OK); | |
| 1359 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 1360 } | |
| 1361 | |
| 1362 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { | |
| 1363 MockWalletClientObserver observer; | |
| 1364 EXPECT_CALL(observer, OnDidSendAutocheckoutStatus()).Times(1); | |
| 1365 | |
| 1366 net::TestURLFetcherFactory factory; | |
| 1367 | |
| 1368 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1369 wallet_client.SendAutocheckoutStatus(autofill::CANNOT_PROCEED, | |
| 1370 GURL(kMerchantUrl), | |
| 1371 "google_transaction_id"); | |
| 1372 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
| 1373 ASSERT_TRUE(fetcher); | |
| 1374 EXPECT_EQ(kSendAutocheckoutStatusOfFailureValidRequest, GetData(fetcher)); | |
| 1375 fetcher->set_response_code(net::HTTP_OK); | |
| 1376 fetcher->SetResponseString(")]}'"); // Invalid JSON. Should be ignored. | |
| 1377 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 1378 } | |
| 1379 | |
| 1380 TEST_F(WalletClientTest, HasRequestInProgress) { | |
| 1381 MockWalletClientObserver observer; | |
| 1382 net::TestURLFetcherFactory factory; | |
| 1383 | |
| 1384 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1385 EXPECT_FALSE(wallet_client.HasRequestInProgress()); | |
| 1386 | |
| 1387 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1388 EXPECT_TRUE(wallet_client.HasRequestInProgress()); | |
| 1389 | |
| 1390 VerifyAndFinishRequest(factory, | |
| 1391 net::HTTP_OK, | |
| 1392 kGetWalletItemsValidRequest, | |
| 1393 kGetWalletItemsValidResponse); | |
| 1394 EXPECT_FALSE(wallet_client.HasRequestInProgress()); | |
| 1395 } | |
| 1396 | |
| 1397 TEST_F(WalletClientTest, PendingRequest) { | |
| 1398 MockWalletClientObserver observer; | |
| 1399 net::TestURLFetcherFactory factory; | |
| 1400 | |
| 1401 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1402 ASSERT_EQ(0U, wallet_client.pending_requests_.size()); | |
| 1403 | |
| 1404 // Shouldn't queue the first request. | |
| 1405 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1406 EXPECT_EQ(0U, wallet_client.pending_requests_.size()); | |
| 1407 | |
| 1408 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1409 EXPECT_EQ(1U, wallet_client.pending_requests_.size()); | |
| 1410 | |
| 1411 VerifyAndFinishRequest(factory, | |
| 1412 net::HTTP_OK, | |
| 1413 kGetWalletItemsValidRequest, | |
| 1414 kGetWalletItemsValidResponse); | |
| 1415 EXPECT_EQ(0U, wallet_client.pending_requests_.size()); | |
| 1416 | |
| 1417 EXPECT_CALL(observer, OnWalletError()).Times(1); | |
| 1418 VerifyAndFinishRequest(factory, | |
| 1419 net::HTTP_INTERNAL_SERVER_ERROR, | |
| 1420 kGetWalletItemsValidRequest, | |
| 1421 std::string()); | |
| 1422 } | |
| 1423 | |
| 1424 TEST_F(WalletClientTest, CancelPendingRequests) { | |
| 1425 MockWalletClientObserver observer; | |
| 1426 net::TestURLFetcherFactory factory; | |
| 1427 | |
| 1428 WalletClient wallet_client(profile_.GetRequestContext(), &observer); | |
| 1429 ASSERT_EQ(0U, wallet_client.pending_requests_.size()); | |
| 1430 | |
| 1431 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1432 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1433 wallet_client.GetWalletItems(GURL(kMerchantUrl)); | |
| 1434 EXPECT_EQ(2U, wallet_client.pending_requests_.size()); | |
| 1435 | |
| 1436 wallet_client.CancelPendingRequests(); | |
| 1437 EXPECT_EQ(0U, wallet_client.pending_requests_.size()); | |
| 1438 } | |
| 1439 | |
| 1440 } // namespace wallet | |
| 1441 } // namespace autofill | |
| OLD | NEW |