Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: components/autofill/content/browser/wallet/wallet_client_unittest.cc

Issue 17970003: New encryption/escrow endpoints for Wallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No !! Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "components/autofill/content/browser/autocheckout_steps.h" 13 #include "components/autofill/content/browser/autocheckout_steps.h"
13 #include "components/autofill/content/browser/wallet/full_wallet.h" 14 #include "components/autofill/content/browser/wallet/full_wallet.h"
14 #include "components/autofill/content/browser/wallet/instrument.h" 15 #include "components/autofill/content/browser/wallet/instrument.h"
15 #include "components/autofill/content/browser/wallet/wallet_client.h" 16 #include "components/autofill/content/browser/wallet/wallet_client.h"
16 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" 17 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h"
17 #include "components/autofill/content/browser/wallet/wallet_items.h" 18 #include "components/autofill/content/browser/wallet/wallet_items.h"
18 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 19 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
19 #include "components/autofill/core/browser/autofill_metrics.h" 20 #include "components/autofill/core/browser/autofill_metrics.h"
20 #include "components/autofill/core/common/autocheckout_status.h" 21 #include "components/autofill/core/common/autocheckout_status.h"
21 #include "content/public/test/test_browser_context.h" 22 #include "content/public/test/test_browser_context.h"
22 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
23 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
25 #include "net/base/escape.h"
24 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
25 #include "net/http/http_status_code.h" 27 #include "net/http/http_status_code.h"
26 #include "net/url_request/test_url_fetcher_factory.h" 28 #include "net/url_request/test_url_fetcher_factory.h"
27 #include "net/url_request/url_fetcher_delegate.h" 29 #include "net/url_request/url_fetcher_delegate.h"
28 #include "net/url_request/url_request_status.h" 30 #include "net/url_request/url_request_status.h"
29 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
31 33
32 namespace autofill { 34 namespace autofill {
33 namespace wallet { 35 namespace wallet {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 " \"type\":\"INVALID_POSTAL_CODE\"" 205 " \"type\":\"INVALID_POSTAL_CODE\""
204 " }" 206 " }"
205 " ]," 207 " ],"
206 " \"required_action\":" 208 " \"required_action\":"
207 " [" 209 " ["
208 " \" \\treqUIRE_PhOnE_number \\n\\r\"," 210 " \" \\treqUIRE_PhOnE_number \\n\\r\","
209 " \"INVALID_form_field\"" 211 " \"INVALID_form_field\""
210 " ]" 212 " ]"
211 "}"; 213 "}";
212 214
213 const char kSaveInstrumentAndAddressMissingAddressResponse[] =
214 "{"
215 " \"instrument_id\":\"instrument_id\""
216 "}";
217
218 const char kSaveInstrumentAndAddressMissingInstrumentResponse[] =
219 "{"
220 " \"shipping_address_id\":\"saved_address_id\""
221 "}";
222
223 const char kUpdateInstrumentValidResponse[] = 215 const char kUpdateInstrumentValidResponse[] =
224 "{" 216 "{"
225 " \"instrument_id\":\"instrument_id\"" 217 " \"instrument_id\":\"instrument_id\""
226 "}"; 218 "}";
227 219
228 const char kUpdateAddressValidResponse[] = 220 const char kUpdateAddressValidResponse[] =
229 "{" 221 "{"
230 " \"shipping_address_id\":\"shipping_address_id\"" 222 " \"shipping_address_id\":\"shipping_address_id\""
231 "}"; 223 "}";
232 224
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 "[" 300 "["
309 "\"doc_id_1\"," 301 "\"doc_id_1\","
310 "\"doc_id_2\"" 302 "\"doc_id_2\""
311 "]," 303 "],"
312 "\"google_transaction_id\":\"google-transaction-id\"," 304 "\"google_transaction_id\":\"google-transaction-id\","
313 "\"merchant_domain\":\"https://example.com/\"" 305 "\"merchant_domain\":\"https://example.com/\""
314 "}"; 306 "}";
315 307
316 const char kAuthenticateInstrumentValidRequest[] = 308 const char kAuthenticateInstrumentValidRequest[] =
317 "{" 309 "{"
318 "\"instrument_escrow_handle\":\"escrow_handle\","
319 "\"instrument_id\":\"instrument_id\"," 310 "\"instrument_id\":\"instrument_id\","
320 "\"risk_params\":\"risky business\"" 311 "\"risk_params\":\"risky business\""
321 "}"; 312 "}";
322 313
323 const char kGetFullWalletValidRequest[] = 314 const char kGetFullWalletValidRequest[] =
324 "{" 315 "{"
325 "\"encrypted_otp\":\"encrypted_one_time_pad\","
326 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," 316 "\"feature\":\"REQUEST_AUTOCOMPLETE\","
327 "\"google_transaction_id\":\"google_transaction_id\"," 317 "\"google_transaction_id\":\"google_transaction_id\","
328 "\"merchant_domain\":\"https://example.com/\"," 318 "\"merchant_domain\":\"https://example.com/\","
329 "\"risk_params\":\"risky business\"," 319 "\"risk_params\":\"risky business\","
330 "\"selected_address_id\":\"shipping_address_id\"," 320 "\"selected_address_id\":\"shipping_address_id\","
331 "\"selected_instrument_id\":\"instrument_id\"," 321 "\"selected_instrument_id\":\"instrument_id\","
332 "\"session_material\":\"session_material\","
333 "\"supported_risk_challenge\":" 322 "\"supported_risk_challenge\":"
334 "[" 323 "["
335 "]" 324 "]"
336 "}"; 325 "}";
337 326
338 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = 327 const char kGetFullWalletWithRiskCapabilitesValidRequest[] =
339 "{" 328 "{"
340 "\"encrypted_otp\":\"encrypted_one_time_pad\","
341 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," 329 "\"feature\":\"REQUEST_AUTOCOMPLETE\","
342 "\"google_transaction_id\":\"google_transaction_id\"," 330 "\"google_transaction_id\":\"google_transaction_id\","
343 "\"merchant_domain\":\"https://example.com/\"," 331 "\"merchant_domain\":\"https://example.com/\","
344 "\"risk_params\":\"risky business\"," 332 "\"risk_params\":\"risky business\","
345 "\"selected_address_id\":\"shipping_address_id\"," 333 "\"selected_address_id\":\"shipping_address_id\","
346 "\"selected_instrument_id\":\"instrument_id\"," 334 "\"selected_instrument_id\":\"instrument_id\","
347 "\"session_material\":\"session_material\","
348 "\"supported_risk_challenge\":" 335 "\"supported_risk_challenge\":"
349 "[" 336 "["
350 "\"VERIFY_CVC\"" 337 "\"VERIFY_CVC\""
351 "]" 338 "]"
352 "}"; 339 "}";
353 340
354 const char kGetWalletItemsValidRequest[] = 341 const char kGetWalletItemsValidRequest[] =
355 "{" 342 "{"
356 "\"merchant_domain\":\"https://example.com/\"" 343 "\"merchant_domain\":\"https://example.com/\""
357 "}"; 344 "}";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 "\"postal_code_number\":\"postal_code_number\"," 385 "\"postal_code_number\":\"postal_code_number\","
399 "\"recipient_name\":\"recipient_name\"" 386 "\"recipient_name\":\"recipient_name\""
400 "}," 387 "},"
401 "\"exp_month\":12," 388 "\"exp_month\":12,"
402 "\"exp_year\":3000," 389 "\"exp_year\":3000,"
403 "\"fop_type\":\"VISA\"," 390 "\"fop_type\":\"VISA\","
404 "\"last_4_digits\":\"4448\"" 391 "\"last_4_digits\":\"4448\""
405 "}," 392 "},"
406 "\"type\":\"CREDIT_CARD\"" 393 "\"type\":\"CREDIT_CARD\""
407 "}," 394 "},"
408 "\"instrument_escrow_handle\":\"escrow_handle\","
409 "\"instrument_phone_number\":\"phone_number\"," 395 "\"instrument_phone_number\":\"phone_number\","
410 "\"merchant_domain\":\"https://example.com/\"," 396 "\"merchant_domain\":\"https://example.com/\","
411 "\"risk_params\":\"risky business\"" 397 "\"risk_params\":\"risky business\""
412 "}"; 398 "}";
413 399
414 const char kSaveInstrumentAndAddressValidRequest[] = 400 const char kSaveInstrumentAndAddressValidRequest[] =
415 "{" 401 "{"
416 "\"instrument\":" 402 "\"instrument\":"
417 "{" 403 "{"
418 "\"credit_card\":" 404 "\"credit_card\":"
(...skipping 11 matching lines...) Expand all
430 "\"postal_code_number\":\"postal_code_number\"," 416 "\"postal_code_number\":\"postal_code_number\","
431 "\"recipient_name\":\"recipient_name\"" 417 "\"recipient_name\":\"recipient_name\""
432 "}," 418 "},"
433 "\"exp_month\":12," 419 "\"exp_month\":12,"
434 "\"exp_year\":3000," 420 "\"exp_year\":3000,"
435 "\"fop_type\":\"VISA\"," 421 "\"fop_type\":\"VISA\","
436 "\"last_4_digits\":\"4448\"" 422 "\"last_4_digits\":\"4448\""
437 "}," 423 "},"
438 "\"type\":\"CREDIT_CARD\"" 424 "\"type\":\"CREDIT_CARD\""
439 "}," 425 "},"
440 "\"instrument_escrow_handle\":\"escrow_handle\","
441 "\"instrument_phone_number\":\"phone_number\"," 426 "\"instrument_phone_number\":\"phone_number\","
442 "\"merchant_domain\":\"https://example.com/\"," 427 "\"merchant_domain\":\"https://example.com/\","
443 "\"risk_params\":\"risky business\"," 428 "\"risk_params\":\"risky business\","
444 "\"shipping_address\":" 429 "\"shipping_address\":"
445 "{" 430 "{"
446 "\"phone_number\":\"save_phone_number\"," 431 "\"phone_number\":\"save_phone_number\","
447 "\"postal_address\":" 432 "\"postal_address\":"
448 "{" 433 "{"
449 "\"address_line\":" 434 "\"address_line\":"
450 "[" 435 "["
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 "\"country_name_code\":\"US\"," 509 "\"country_name_code\":\"US\","
525 "\"locality_name\":\"locality_name\"," 510 "\"locality_name\":\"locality_name\","
526 "\"postal_code_number\":\"postal_code_number\"," 511 "\"postal_code_number\":\"postal_code_number\","
527 "\"recipient_name\":\"recipient_name\"" 512 "\"recipient_name\":\"recipient_name\""
528 "}," 513 "},"
529 "\"upgraded_instrument_id\":\"instrument_id\"" 514 "\"upgraded_instrument_id\":\"instrument_id\""
530 "}"; 515 "}";
531 516
532 const char kUpdateInstrumentAddressWithNameChangeValidRequest[] = 517 const char kUpdateInstrumentAddressWithNameChangeValidRequest[] =
533 "{" 518 "{"
534 "\"instrument_escrow_handle\":\"escrow_handle\","
535 "\"instrument_phone_number\":\"phone_number\"," 519 "\"instrument_phone_number\":\"phone_number\","
536 "\"merchant_domain\":\"https://example.com/\"," 520 "\"merchant_domain\":\"https://example.com/\","
537 "\"risk_params\":\"risky business\"," 521 "\"risk_params\":\"risky business\","
538 "\"upgraded_billing_address\":"
539 "{"
540 "\"address_line\":"
541 "["
542 "\"address_line_1\","
543 "\"address_line_2\""
544 "],"
545 "\"administrative_area_name\":\"admin_area_name\","
546 "\"country_name_code\":\"US\","
547 "\"locality_name\":\"locality_name\","
548 "\"postal_code_number\":\"postal_code_number\","
549 "\"recipient_name\":\"recipient_name\""
550 "},"
551 "\"upgraded_instrument_id\":\"instrument_id\""
552 "}";
553
554 const char kUpdateInstrumentAddressAndExpirationDateValidRequest[] =
555 "{"
556 "\"instrument\":"
557 "{"
558 "\"credit_card\":"
559 "{"
560 "\"exp_month\":12,"
561 "\"exp_year\":2015"
562 "},"
563 "\"type\":\"CREDIT_CARD\""
564 "},"
565 "\"instrument_escrow_handle\":\"escrow_handle\","
566 "\"instrument_phone_number\":\"phone_number\","
567 "\"merchant_domain\":\"https://example.com/\","
568 "\"risk_params\":\"risky business\","
569 "\"upgraded_billing_address\":" 522 "\"upgraded_billing_address\":"
570 "{" 523 "{"
571 "\"address_line\":" 524 "\"address_line\":"
572 "[" 525 "["
573 "\"address_line_1\"," 526 "\"address_line_1\","
574 "\"address_line_2\"" 527 "\"address_line_2\""
575 "]," 528 "],"
576 "\"administrative_area_name\":\"admin_area_name\"," 529 "\"administrative_area_name\":\"admin_area_name\","
577 "\"country_name_code\":\"US\"," 530 "\"country_name_code\":\"US\","
578 "\"locality_name\":\"locality_name\"," 531 "\"locality_name\":\"locality_name\","
579 "\"postal_code_number\":\"postal_code_number\"," 532 "\"postal_code_number\":\"postal_code_number\","
580 "\"recipient_name\":\"recipient_name\"" 533 "\"recipient_name\":\"recipient_name\""
581 "}," 534 "},"
582 "\"upgraded_instrument_id\":\"instrument_id\"" 535 "\"upgraded_instrument_id\":\"instrument_id\""
583 "}"; 536 "}";
584 537
585 const char kUpdateInstrumentExpirationDateValidRequest[] = 538 const char kUpdateInstrumentExpirationDateValidRequest[] =
586 "{" 539 "{"
587 "\"instrument\":" 540 "\"instrument\":"
588 "{" 541 "{"
589 "\"credit_card\":" 542 "\"credit_card\":"
590 "{" 543 "{"
591 "\"exp_month\":12," 544 "\"exp_month\":12,"
592 "\"exp_year\":2015" 545 "\"exp_year\":3000"
593 "}," 546 "},"
594 "\"type\":\"CREDIT_CARD\"" 547 "\"type\":\"CREDIT_CARD\""
595 "}," 548 "},"
596 "\"instrument_escrow_handle\":\"escrow_handle\","
597 "\"merchant_domain\":\"https://example.com/\"," 549 "\"merchant_domain\":\"https://example.com/\","
598 "\"risk_params\":\"risky business\"," 550 "\"risk_params\":\"risky business\","
599 "\"upgraded_instrument_id\":\"instrument_id\"" 551 "\"upgraded_instrument_id\":\"instrument_id\""
600 "}"; 552 "}";
601 553
602 class MockAutofillMetrics : public AutofillMetrics { 554 class MockAutofillMetrics : public AutofillMetrics {
603 public: 555 public:
604 MockAutofillMetrics() {} 556 MockAutofillMetrics() {}
605 MOCK_CONST_METHOD2(LogWalletApiCallDuration, 557 MOCK_CONST_METHOD2(LogWalletApiCallDuration,
606 void(WalletApiCallMetric metric, 558 void(WalletApiCallMetric metric,
607 const base::TimeDelta& duration)); 559 const base::TimeDelta& duration));
608 MOCK_CONST_METHOD2(LogWalletErrorMetric, 560 MOCK_CONST_METHOD2(LogWalletErrorMetric,
609 void(DialogType dialog_type, WalletErrorMetric metric)); 561 void(DialogType dialog_type, WalletErrorMetric metric));
610 MOCK_CONST_METHOD2(LogWalletRequiredActionMetric, 562 MOCK_CONST_METHOD2(LogWalletRequiredActionMetric,
611 void(DialogType dialog_type, 563 void(DialogType dialog_type,
612 WalletRequiredActionMetric action)); 564 WalletRequiredActionMetric action));
613 private: 565 private:
614 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); 566 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
615 }; 567 };
616 568
617 enum EscrowRequestPresence {
618 HAS_ESCROW_REQUEST,
619 NO_ESCROW_REQUEST,
620 };
621
622 enum WalletRequestPresence {
623 HAS_WALLET_REQUEST,
624 NO_WALLET_REQUEST,
625 };
626
627 class MockWalletClientDelegate : public WalletClientDelegate { 569 class MockWalletClientDelegate : public WalletClientDelegate {
628 public: 570 public:
629 MockWalletClientDelegate() 571 MockWalletClientDelegate()
630 : full_wallets_received_(0), wallet_items_received_(0) {} 572 : full_wallets_received_(0), wallet_items_received_(0) {}
631 ~MockWalletClientDelegate() {} 573 ~MockWalletClientDelegate() {}
632 574
633 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 575 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
634 return metric_logger_; 576 return metric_logger_;
635 } 577 }
636 578
(...skipping 20 matching lines...) Expand all
657 } 599 }
658 600
659 void ExpectWalletRequiredActionMetric( 601 void ExpectWalletRequiredActionMetric(
660 AutofillMetrics::WalletRequiredActionMetric metric) { 602 AutofillMetrics::WalletRequiredActionMetric metric) {
661 EXPECT_CALL( 603 EXPECT_CALL(
662 metric_logger_, 604 metric_logger_,
663 LogWalletRequiredActionMetric( 605 LogWalletRequiredActionMetric(
664 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric)).Times(1); 606 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric)).Times(1);
665 } 607 }
666 608
667 void ExpectBaselineMetrics(EscrowRequestPresence escrow_request_presence, 609 void ExpectBaselineMetrics() {
668 WalletRequestPresence wallet_request_presence) {
669 int num_requests = 0;
670 if (escrow_request_presence == HAS_ESCROW_REQUEST)
671 ++num_requests;
672 if (wallet_request_presence == HAS_WALLET_REQUEST)
673 ++num_requests;
674
675 EXPECT_GT(num_requests, 0);
676
677 EXPECT_CALL( 610 EXPECT_CALL(
678 metric_logger_, 611 metric_logger_,
679 LogWalletErrorMetric( 612 LogWalletErrorMetric(
680 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 613 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
681 AutofillMetrics::WALLET_ERROR_BASELINE_ISSUED_REQUEST)) 614 AutofillMetrics::WALLET_ERROR_BASELINE_ISSUED_REQUEST))
682 .Times(num_requests); 615 .Times(1);
683 616 ExpectWalletRequiredActionMetric(
684 if (wallet_request_presence == HAS_WALLET_REQUEST) { 617 AutofillMetrics::WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST);
685 ExpectWalletRequiredActionMetric(
686 AutofillMetrics::WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST);
687 }
688 } 618 }
689 619
690 MockAutofillMetrics* metric_logger() { 620 MockAutofillMetrics* metric_logger() {
691 return &metric_logger_; 621 return &metric_logger_;
692 } 622 }
693 623
694 MOCK_METHOD0(OnDidAcceptLegalDocuments, void()); 624 MOCK_METHOD0(OnDidAcceptLegalDocuments, void());
695 MOCK_METHOD1(OnDidAuthenticateInstrument, void(bool success)); 625 MOCK_METHOD1(OnDidAuthenticateInstrument, void(bool success));
696 MOCK_METHOD3(OnDidSaveAddress, 626 MOCK_METHOD4(OnDidSaveToWallet,
697 void(const std::string& address_id,
698 const std::vector<RequiredAction>& required_actions,
699 const std::vector<FormFieldError>& form_field_errors));
700 MOCK_METHOD3(OnDidSaveInstrument,
701 void(const std::string& instrument_id,
702 const std::vector<RequiredAction>& required_actions,
703 const std::vector<FormFieldError>& form_field_errors));
704 MOCK_METHOD4(OnDidSaveInstrumentAndAddress,
705 void(const std::string& instrument_id, 627 void(const std::string& instrument_id,
706 const std::string& shipping_address_id, 628 const std::string& shipping_address_id,
707 const std::vector<RequiredAction>& required_actions, 629 const std::vector<RequiredAction>& required_actions,
708 const std::vector<FormFieldError>& form_field_errors)); 630 const std::vector<FormFieldError>& form_field_errors));
709 MOCK_METHOD3(OnDidUpdateAddress,
710 void(const std::string& address_id,
711 const std::vector<RequiredAction>& required_actions,
712 const std::vector<FormFieldError>& form_field_errors));
713 MOCK_METHOD3(OnDidUpdateInstrument,
714 void(const std::string& instrument_id,
715 const std::vector<RequiredAction>& required_actions,
716 const std::vector<FormFieldError>& form_field_errors));
717 MOCK_METHOD1(OnWalletError, void(WalletClient::ErrorType error_type)); 631 MOCK_METHOD1(OnWalletError, void(WalletClient::ErrorType error_type));
718 632
719 virtual void OnDidGetFullWallet(scoped_ptr<FullWallet> full_wallet) OVERRIDE { 633 virtual void OnDidGetFullWallet(scoped_ptr<FullWallet> full_wallet) OVERRIDE {
720 EXPECT_TRUE(full_wallet); 634 EXPECT_TRUE(full_wallet);
721 ++full_wallets_received_; 635 ++full_wallets_received_;
722 } 636 }
723 virtual void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items) 637 virtual void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items)
724 OVERRIDE { 638 OVERRIDE {
725 EXPECT_TRUE(wallet_items); 639 EXPECT_TRUE(wallet_items);
726 ++wallet_items_received_; 640 ++wallet_items_received_;
(...skipping 16 matching lines...) Expand all
743 657
744 virtual void SetUp() OVERRIDE { 658 virtual void SetUp() OVERRIDE {
745 wallet_client_.reset( 659 wallet_client_.reset(
746 new WalletClient(browser_context_.GetRequestContext(), &delegate_)); 660 new WalletClient(browser_context_.GetRequestContext(), &delegate_));
747 } 661 }
748 662
749 virtual void TearDown() OVERRIDE { 663 virtual void TearDown() OVERRIDE {
750 wallet_client_.reset(); 664 wallet_client_.reset();
751 } 665 }
752 666
753 std::string GetData(net::TestURLFetcher* fetcher) {
754 std::string data = fetcher->upload_data();
755 scoped_ptr<Value> root(base::JSONReader::Read(data));
756
757 // If this is not a JSON dictionary, return plain text.
758 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY))
759 return data;
760
761 // Remove api_key entry (to prevent accidental leak), return JSON as text.
762 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get());
763 dict->Remove("api_key", NULL);
764 base::JSONWriter::Write(dict, &data);
765 return data;
766 }
767
768 void DoEncryptionOrEscrowRequest(net::HttpStatusCode response_code,
769 const std::string& response_body) {
770 net::TestURLFetcher* encryption_fetcher = factory_.GetFetcherByID(1);
771 ASSERT_TRUE(encryption_fetcher);
772 encryption_fetcher->set_response_code(response_code);
773 encryption_fetcher->SetResponseString(response_body);
774 encryption_fetcher->delegate()->OnURLFetchComplete(encryption_fetcher);
775 }
776
777 void VerifyAndFinishRequest(net::HttpStatusCode response_code, 667 void VerifyAndFinishRequest(net::HttpStatusCode response_code,
778 const std::string& request_body, 668 const std::string& request_body,
779 const std::string& response_body) { 669 const std::string& response_body) {
780 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); 670 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
781 ASSERT_TRUE(fetcher); 671 ASSERT_TRUE(fetcher);
782 EXPECT_EQ(request_body, GetData(fetcher)); 672 EXPECT_EQ(request_body, GetData(fetcher->upload_data()));
783 fetcher->set_response_code(response_code); 673 fetcher->set_response_code(response_code);
784 fetcher->SetResponseString(response_body); 674 fetcher->SetResponseString(response_body);
785 fetcher->delegate()->OnURLFetchComplete(fetcher); 675 fetcher->delegate()->OnURLFetchComplete(fetcher);
676 }
677
678 void VerifyAndFinishFormEncodedRequest(net::HttpStatusCode response_code,
679 const std::string& json_payload,
680 const std::string& response_body) {
681 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
682 ASSERT_TRUE(fetcher);
683
684 const std::string& upload_data = fetcher->upload_data();
685 std::vector<std::pair<std::string, std::string> > tokens;
686 base::SplitStringIntoKeyValuePairs(upload_data, '=', '&', &tokens);
687
688 for (size_t i = 0; i < tokens.size(); ++i) {
689 const std::string& key = tokens[i].first;
690 const std::string& value = tokens[i].second;
691
692 if (key == "request_content_type")
693 EXPECT_EQ("application/json", value);
694
695 if (key == "request") {
696 EXPECT_EQ(json_payload,
697 GetData(
698 net::UnescapeURLComponent(
699 value, net::UnescapeRule::URL_SPECIAL_CHARS |
700 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE)));
701 }
702 // TODO(ahutter): Check cvn, cc_number, and that otp is non-empty.
Dan Beam 2013/07/02 21:03:11 nit: Check that cvn, cc_number, and otp are non-em
ahutter 2013/07/02 21:15:56 Done.
703 }
704
705 fetcher->set_response_code(response_code);
706 fetcher->SetResponseString(response_body);
707 fetcher->delegate()->OnURLFetchComplete(fetcher);
786 } 708 }
787 709
788 protected: 710 protected:
789 scoped_ptr<WalletClient> wallet_client_; 711 scoped_ptr<WalletClient> wallet_client_;
790 content::TestBrowserContext browser_context_; 712 content::TestBrowserContext browser_context_;
791 MockWalletClientDelegate delegate_; 713 MockWalletClientDelegate delegate_;
792 714
793 private: 715 private:
716 std::string GetData(const std::string& upload_data) {
717 scoped_ptr<Value> root(base::JSONReader::Read(upload_data));
718
719 // If this is not a JSON dictionary, return plain text.
720 if (!root || !root->IsType(Value::TYPE_DICTIONARY))
721 return upload_data;
722
723 // Remove api_key entry (to prevent accidental leak), return JSON as text.
724 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get());
725 dict->Remove("api_key", NULL);
726 std::string clean_upload_data;
727 base::JSONWriter::Write(dict, &clean_upload_data);
728 return clean_upload_data;
729 }
730
794 net::TestURLFetcherFactory factory_; 731 net::TestURLFetcherFactory factory_;
795 }; 732 };
796 733
797 TEST_F(WalletClientTest, WalletError) { 734 TEST_F(WalletClientTest, WalletError) {
798 EXPECT_CALL(delegate_, OnWalletError( 735 EXPECT_CALL(delegate_, OnWalletError(
799 WalletClient::SERVICE_UNAVAILABLE)).Times(1); 736 WalletClient::SERVICE_UNAVAILABLE)).Times(1);
800 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 737 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
801 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 738 delegate_.ExpectBaselineMetrics();
802 delegate_.ExpectWalletErrorMetric( 739 delegate_.ExpectWalletErrorMetric(
803 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); 740 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE);
804 741
805 std::vector<AutocheckoutStatistic> statistics; 742 std::vector<AutocheckoutStatistic> statistics;
806 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 743 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
807 GURL(kMerchantUrl), 744 GURL(kMerchantUrl),
808 statistics, 745 statistics,
809 "google_transaction_id"); 746 "google_transaction_id");
810 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 747 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
811 kSendAutocheckoutStatusOfSuccessValidRequest, 748 kSendAutocheckoutStatusOfSuccessValidRequest,
812 kErrorResponse); 749 kErrorResponse);
813 } 750 }
814 751
815 TEST_F(WalletClientTest, WalletErrorResponseMissing) { 752 TEST_F(WalletClientTest, WalletErrorResponseMissing) {
816 EXPECT_CALL(delegate_, OnWalletError( 753 EXPECT_CALL(delegate_, OnWalletError(
817 WalletClient::UNKNOWN_ERROR)).Times(1); 754 WalletClient::UNKNOWN_ERROR)).Times(1);
818 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 755 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
819 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 756 delegate_.ExpectBaselineMetrics();
820 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR); 757 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR);
821 758
822 std::vector<AutocheckoutStatistic> statistics; 759 std::vector<AutocheckoutStatistic> statistics;
823 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 760 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
824 GURL(kMerchantUrl), 761 GURL(kMerchantUrl),
825 statistics, 762 statistics,
826 "google_transaction_id"); 763 "google_transaction_id");
827 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 764 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
828 kSendAutocheckoutStatusOfSuccessValidRequest, 765 kSendAutocheckoutStatusOfSuccessValidRequest,
829 kErrorTypeMissingInResponse); 766 kErrorTypeMissingInResponse);
830 } 767 }
831 768
832 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) { 769 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) {
833 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); 770 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
834 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 771 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
835 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 772 delegate_.ExpectBaselineMetrics();
836 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); 773 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
837 774
838 std::vector<AutocheckoutStatistic> statistics; 775 std::vector<AutocheckoutStatistic> statistics;
839 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 776 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
840 GURL(kMerchantUrl), 777 GURL(kMerchantUrl),
841 statistics, 778 statistics,
842 "google_transaction_id"); 779 "google_transaction_id");
843 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, 780 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED,
844 kSendAutocheckoutStatusOfSuccessValidRequest, 781 kSendAutocheckoutStatusOfSuccessValidRequest,
845 std::string()); 782 std::string());
846 } 783 }
847 784
848 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { 785 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) {
849 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); 786 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
850 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 787 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
851 1); 788 1);
852 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 789 delegate_.ExpectBaselineMetrics();
853 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); 790 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
854 791
855 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 792 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
856 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, 793 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED,
857 kGetWalletItemsValidRequest, 794 kGetWalletItemsValidRequest,
858 std::string()); 795 std::string());
859 } 796 }
860 797
861 TEST_F(WalletClientTest, RequestError) { 798 TEST_F(WalletClientTest, RequestError) {
862 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); 799 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1);
863 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 800 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
864 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 801 delegate_.ExpectBaselineMetrics();
865 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST); 802 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST);
866 803
867 std::vector<AutocheckoutStatistic> statistics; 804 std::vector<AutocheckoutStatistic> statistics;
868 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 805 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
869 GURL(kMerchantUrl), 806 GURL(kMerchantUrl),
870 statistics, 807 statistics,
871 "google_transaction_id"); 808 "google_transaction_id");
872 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, 809 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST,
873 kSendAutocheckoutStatusOfSuccessValidRequest, 810 kSendAutocheckoutStatusOfSuccessValidRequest,
874 std::string()); 811 std::string());
875 } 812 }
876 813
877 TEST_F(WalletClientTest, GetFullWalletSuccess) { 814 TEST_F(WalletClientTest, GetFullWalletSuccess) {
878 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 815 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
879 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 816 delegate_.ExpectBaselineMetrics();
880 817
881 WalletClient::FullWalletRequest full_wallet_request( 818 WalletClient::FullWalletRequest full_wallet_request(
882 "instrument_id", 819 "instrument_id",
883 "shipping_address_id", 820 "shipping_address_id",
884 GURL(kMerchantUrl), 821 GURL(kMerchantUrl),
885 "google_transaction_id", 822 "google_transaction_id",
886 std::vector<WalletClient::RiskCapability>()); 823 std::vector<WalletClient::RiskCapability>());
887 wallet_client_->GetFullWallet(full_wallet_request); 824 wallet_client_->GetFullWallet(full_wallet_request);
888 825
889 DoEncryptionOrEscrowRequest(net::HTTP_OK, 826 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
890 "session_material|encrypted_one_time_pad"); 827 kGetFullWalletValidRequest,
891 828 kGetFullWalletValidResponse);
892 VerifyAndFinishRequest(net::HTTP_OK,
893 kGetFullWalletValidRequest,
894 kGetFullWalletValidResponse);
895 EXPECT_EQ(1U, delegate_.full_wallets_received()); 829 EXPECT_EQ(1U, delegate_.full_wallets_received());
896 } 830 }
897 831
898 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) { 832 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) {
899 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 833 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
900 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 834 delegate_.ExpectBaselineMetrics();
901 835
902 std::vector<WalletClient::RiskCapability> risk_capabilities; 836 std::vector<WalletClient::RiskCapability> risk_capabilities;
903 risk_capabilities.push_back(WalletClient::VERIFY_CVC); 837 risk_capabilities.push_back(WalletClient::VERIFY_CVC);
904 WalletClient::FullWalletRequest full_wallet_request( 838 WalletClient::FullWalletRequest full_wallet_request(
905 "instrument_id", 839 "instrument_id",
906 "shipping_address_id", 840 "shipping_address_id",
907 GURL(kMerchantUrl), 841 GURL(kMerchantUrl),
908 "google_transaction_id", 842 "google_transaction_id",
909 risk_capabilities); 843 risk_capabilities);
910 wallet_client_->GetFullWallet(full_wallet_request); 844 wallet_client_->GetFullWallet(full_wallet_request);
911 845
912 DoEncryptionOrEscrowRequest(net::HTTP_OK, 846 VerifyAndFinishFormEncodedRequest(
913 "session_material|encrypted_one_time_pad"); 847 net::HTTP_OK,
914 848 kGetFullWalletWithRiskCapabilitesValidRequest,
915 VerifyAndFinishRequest(net::HTTP_OK, 849 kGetFullWalletValidResponse);
916 kGetFullWalletWithRiskCapabilitesValidRequest,
917 kGetFullWalletValidResponse);
918 EXPECT_EQ(1U, delegate_.full_wallets_received()); 850 EXPECT_EQ(1U, delegate_.full_wallets_received());
919 } 851 }
920 852
921 TEST_F(WalletClientTest, GetFullWalletEncryptionDown) {
922 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
923 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0);
924 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
925 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
926
927 WalletClient::FullWalletRequest full_wallet_request(
928 "instrument_id",
929 "shipping_address_id",
930 GURL(kMerchantUrl),
931 "google_transaction_id",
932 std::vector<WalletClient::RiskCapability>());
933 wallet_client_->GetFullWallet(full_wallet_request);
934
935 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string());
936
937 EXPECT_EQ(0U, delegate_.full_wallets_received());
938 }
939
940 TEST_F(WalletClientTest, GetFullWalletEncryptionMalformed) {
941 EXPECT_CALL(delegate_,
942 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
943 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0);
944 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
945 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
946
947 WalletClient::FullWalletRequest full_wallet_request(
948 "instrument_id",
949 "shipping_address_id",
950 GURL(kMerchantUrl),
951 "google_transaction_id",
952 std::vector<WalletClient::RiskCapability>());
953 wallet_client_->GetFullWallet(full_wallet_request);
954
955 DoEncryptionOrEscrowRequest(net::HTTP_OK,
956 "session_material:encrypted_one_time_pad");
957
958 EXPECT_EQ(0U, delegate_.full_wallets_received());
959 }
960 853
961 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { 854 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) {
962 EXPECT_CALL(delegate_, 855 EXPECT_CALL(delegate_,
963 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 856 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
964 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 857 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
965 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 858 delegate_.ExpectBaselineMetrics();
966 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 859 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
967 860
968 WalletClient::FullWalletRequest full_wallet_request( 861 WalletClient::FullWalletRequest full_wallet_request(
969 "instrument_id", 862 "instrument_id",
970 "shipping_address_id", 863 "shipping_address_id",
971 GURL(kMerchantUrl), 864 GURL(kMerchantUrl),
972 "google_transaction_id", 865 "google_transaction_id",
973 std::vector<WalletClient::RiskCapability>()); 866 std::vector<WalletClient::RiskCapability>());
974 wallet_client_->GetFullWallet(full_wallet_request); 867 wallet_client_->GetFullWallet(full_wallet_request);
975 868
976 DoEncryptionOrEscrowRequest(net::HTTP_OK, 869 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
977 "session_material|encrypted_one_time_pad"); 870 kGetFullWalletValidRequest,
978 871 kGetFullWalletInvalidResponse);
979 VerifyAndFinishRequest(net::HTTP_OK,
980 kGetFullWalletValidRequest,
981 kGetFullWalletInvalidResponse);
982 EXPECT_EQ(0U, delegate_.full_wallets_received()); 872 EXPECT_EQ(0U, delegate_.full_wallets_received());
983 } 873 }
984 874
985 TEST_F(WalletClientTest, AcceptLegalDocuments) { 875 TEST_F(WalletClientTest, AcceptLegalDocuments) {
986 EXPECT_CALL(delegate_, OnDidAcceptLegalDocuments()).Times(1); 876 EXPECT_CALL(delegate_, OnDidAcceptLegalDocuments()).Times(1);
987 delegate_.ExpectLogWalletApiCallDuration( 877 delegate_.ExpectLogWalletApiCallDuration(
988 AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS, 878 AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS,
989 1); 879 1);
990 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 880 delegate_.ExpectBaselineMetrics();
991 881
992 ScopedVector<WalletItems::LegalDocument> docs; 882 ScopedVector<WalletItems::LegalDocument> docs;
993 base::DictionaryValue document; 883 base::DictionaryValue document;
994 document.SetString("legal_document_id", "doc_id_1"); 884 document.SetString("legal_document_id", "doc_id_1");
995 document.SetString("display_name", "doc_1"); 885 document.SetString("display_name", "doc_1");
996 docs.push_back( 886 docs.push_back(
997 WalletItems::LegalDocument::CreateLegalDocument(document).release()); 887 WalletItems::LegalDocument::CreateLegalDocument(document).release());
998 document.SetString("legal_document_id", "doc_id_2"); 888 document.SetString("legal_document_id", "doc_id_2");
999 document.SetString("display_name", "doc_2"); 889 document.SetString("display_name", "doc_2");
1000 docs.push_back( 890 docs.push_back(
1001 WalletItems::LegalDocument::CreateLegalDocument(document).release()); 891 WalletItems::LegalDocument::CreateLegalDocument(document).release());
1002 docs.push_back( 892 docs.push_back(
1003 WalletItems::LegalDocument::CreatePrivacyPolicyDocument().release()); 893 WalletItems::LegalDocument::CreatePrivacyPolicyDocument().release());
1004 wallet_client_->AcceptLegalDocuments(docs.get(), 894 wallet_client_->AcceptLegalDocuments(docs.get(),
1005 kGoogleTransactionId, 895 kGoogleTransactionId,
1006 GURL(kMerchantUrl)); 896 GURL(kMerchantUrl));
1007 VerifyAndFinishRequest(net::HTTP_OK, 897 VerifyAndFinishRequest(net::HTTP_OK,
1008 kAcceptLegalDocumentsValidRequest, 898 kAcceptLegalDocumentsValidRequest,
1009 ")}'"); // Invalid JSON. Should be ignored. 899 ")}'"); // Invalid JSON. Should be ignored.
1010 } 900 }
1011 901
1012 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) { 902 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) {
1013 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(true)).Times(1); 903 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(true)).Times(1);
1014 delegate_.ExpectLogWalletApiCallDuration( 904 delegate_.ExpectLogWalletApiCallDuration(
1015 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 905 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1016 1); 906 1);
1017 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 907 delegate_.ExpectBaselineMetrics();
1018 908
1019 wallet_client_->AuthenticateInstrument("instrument_id", 909 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1020 "cvv",
1021 "obfuscated_gaia_id");
1022 910
1023 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 911 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1024 912 kAuthenticateInstrumentValidRequest,
1025 VerifyAndFinishRequest(net::HTTP_OK, 913 kAuthenticateInstrumentSuccessResponse);
1026 kAuthenticateInstrumentValidRequest,
1027 kAuthenticateInstrumentSuccessResponse);
1028 } 914 }
1029 915
1030 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) { 916 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) {
1031 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(false)).Times(1); 917 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(false)).Times(1);
1032 delegate_.ExpectLogWalletApiCallDuration( 918 delegate_.ExpectLogWalletApiCallDuration(
1033 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 919 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1034 1); 920 1);
1035 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 921 delegate_.ExpectBaselineMetrics();
1036 922
1037 wallet_client_->AuthenticateInstrument("instrument_id", 923 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1038 "cvv",
1039 "obfuscated_gaia_id");
1040 924
1041 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 925 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1042 926 kAuthenticateInstrumentValidRequest,
1043 VerifyAndFinishRequest(net::HTTP_OK, 927 kAuthenticateInstrumentFailureResponse);
1044 kAuthenticateInstrumentValidRequest,
1045 kAuthenticateInstrumentFailureResponse);
1046 }
1047
1048 TEST_F(WalletClientTest, AuthenticateInstrumentEscrowDown) {
1049 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
1050 delegate_.ExpectLogWalletApiCallDuration(
1051 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1052 0);
1053 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1054 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
1055
1056 wallet_client_->AuthenticateInstrument("instrument_id",
1057 "cvv",
1058 "obfuscated_gaia_id");
1059
1060 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string());
1061 }
1062
1063 TEST_F(WalletClientTest, AuthenticateInstrumentEscrowMalformed) {
1064 EXPECT_CALL(delegate_,
1065 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1066 delegate_.ExpectLogWalletApiCallDuration(
1067 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1068 0);
1069 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1070 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1071
1072 wallet_client_->AuthenticateInstrument("instrument_id",
1073 "cvv",
1074 "obfuscated_gaia_id");
1075
1076 DoEncryptionOrEscrowRequest(net::HTTP_OK, std::string());
1077 } 928 }
1078 929
1079 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) { 930 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) {
1080 EXPECT_CALL(delegate_, 931 EXPECT_CALL(delegate_,
1081 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 932 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1082 delegate_.ExpectLogWalletApiCallDuration( 933 delegate_.ExpectLogWalletApiCallDuration(
1083 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 934 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1084 1); 935 1);
1085 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 936 delegate_.ExpectBaselineMetrics();
1086 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 937 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1087 938
1088 wallet_client_->AuthenticateInstrument("instrument_id", 939 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1089 "cvv",
1090 "obfuscated_gaia_id");
1091 940
1092 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 941 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1093 942 kAuthenticateInstrumentValidRequest,
1094 VerifyAndFinishRequest(net::HTTP_OK, 943 kSaveInvalidResponse);
1095 kAuthenticateInstrumentValidRequest,
1096 kSaveInvalidResponse);
1097 } 944 }
1098 945
1099 // TODO(ahutter): Add failure tests for GetWalletItems. 946 // TODO(ahutter): Add failure tests for GetWalletItems.
1100 947
1101 TEST_F(WalletClientTest, GetWalletItems) { 948 TEST_F(WalletClientTest, GetWalletItems) {
1102 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 949 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1103 1); 950 1);
1104 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 951 delegate_.ExpectBaselineMetrics();
1105 952
1106 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 953 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1107 954
1108 VerifyAndFinishRequest(net::HTTP_OK, 955 VerifyAndFinishRequest(net::HTTP_OK,
1109 kGetWalletItemsValidRequest, 956 kGetWalletItemsValidRequest,
1110 kGetWalletItemsValidResponse); 957 kGetWalletItemsValidResponse);
1111 EXPECT_EQ(1U, delegate_.wallet_items_received()); 958 EXPECT_EQ(1U, delegate_.wallet_items_received());
1112 } 959 }
1113 960
1114 TEST_F(WalletClientTest, SaveAddressSucceeded) { 961 TEST_F(WalletClientTest, SaveAddressSucceeded) {
1115 EXPECT_CALL(delegate_, 962 EXPECT_CALL(delegate_,
1116 OnDidSaveAddress("saved_address_id", 963 OnDidSaveToWallet(std::string(),
1117 std::vector<RequiredAction>(), 964 "saved_address_id",
1118 std::vector<FormFieldError>())).Times(1); 965 std::vector<RequiredAction>(),
1119 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 966 std::vector<FormFieldError>())).Times(1);
1120 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 967 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
968 delegate_.ExpectBaselineMetrics();
1121 969
1122 scoped_ptr<Address> address = GetTestSaveableAddress(); 970 scoped_ptr<Address> address = GetTestSaveableAddress();
1123 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 971 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1124 VerifyAndFinishRequest(net::HTTP_OK, 972 address.Pass(),
1125 kSaveAddressValidRequest, 973 GURL(kMerchantUrl));
1126 kSaveAddressValidResponse); 974 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
975 kSaveAddressValidRequest,
976 kSaveAddressValidResponse);
1127 } 977 }
1128 978
1129 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) { 979 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) {
1130 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 980 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1131 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 981 delegate_.ExpectBaselineMetrics();
1132 delegate_.ExpectWalletRequiredActionMetric( 982 delegate_.ExpectWalletRequiredActionMetric(
1133 AutofillMetrics::REQUIRE_PHONE_NUMBER); 983 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1134 delegate_.ExpectWalletRequiredActionMetric( 984 delegate_.ExpectWalletRequiredActionMetric(
1135 AutofillMetrics::INVALID_FORM_FIELD); 985 AutofillMetrics::INVALID_FORM_FIELD);
1136 986
1137 std::vector<RequiredAction> required_actions; 987 std::vector<RequiredAction> required_actions;
1138 required_actions.push_back(REQUIRE_PHONE_NUMBER); 988 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1139 required_actions.push_back(INVALID_FORM_FIELD); 989 required_actions.push_back(INVALID_FORM_FIELD);
1140 990
1141 std::vector<FormFieldError> form_errors; 991 std::vector<FormFieldError> form_errors;
1142 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 992 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1143 FormFieldError::SHIPPING_ADDRESS)); 993 FormFieldError::SHIPPING_ADDRESS));
1144 994
1145 EXPECT_CALL(delegate_, 995 EXPECT_CALL(delegate_,
1146 OnDidSaveAddress(std::string(), 996 OnDidSaveToWallet(std::string(),
1147 required_actions, 997 std::string(),
1148 form_errors)).Times(1); 998 required_actions,
999 form_errors)).Times(1);
1149 1000
1150 scoped_ptr<Address> address = GetTestSaveableAddress(); 1001 scoped_ptr<Address> address = GetTestSaveableAddress();
1151 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 1002 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1152 VerifyAndFinishRequest(net::HTTP_OK, 1003 address.Pass(),
1153 kSaveAddressValidRequest, 1004 GURL(kMerchantUrl));
1154 kSaveAddressWithRequiredActionsValidResponse); 1005 VerifyAndFinishFormEncodedRequest(
1006 net::HTTP_OK,
1007 kSaveAddressValidRequest,
1008 kSaveAddressWithRequiredActionsValidResponse);
1155 } 1009 }
1156 1010
1157 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) { 1011 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) {
1158 EXPECT_CALL(delegate_, 1012 EXPECT_CALL(delegate_,
1159 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1013 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1160 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 1014 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1161 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1015 delegate_.ExpectBaselineMetrics();
1162 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1016 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1163 1017
1164 scoped_ptr<Address> address = GetTestSaveableAddress(); 1018 scoped_ptr<Address> address = GetTestSaveableAddress();
1165 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 1019 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1166 VerifyAndFinishRequest(net::HTTP_OK, 1020 address.Pass(),
1167 kSaveAddressValidRequest, 1021 GURL(kMerchantUrl));
1168 kSaveWithInvalidRequiredActionsResponse); 1022 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1023 kSaveAddressValidRequest,
1024 kSaveWithInvalidRequiredActionsResponse);
1169 } 1025 }
1170 1026
1171 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { 1027 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) {
1172 EXPECT_CALL(delegate_, 1028 EXPECT_CALL(delegate_,
1173 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1029 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1174 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 1030 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1175 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1031 delegate_.ExpectBaselineMetrics();
1176 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1032 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1177 1033
1178 scoped_ptr<Address> address = GetTestSaveableAddress(); 1034 scoped_ptr<Address> address = GetTestSaveableAddress();
1179 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 1035 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1180 VerifyAndFinishRequest(net::HTTP_OK, 1036 address.Pass(),
1181 kSaveAddressValidRequest, 1037 GURL(kMerchantUrl));
1182 kSaveInvalidResponse); 1038 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1039 kSaveAddressValidRequest,
1040 kSaveInvalidResponse);
1183 } 1041 }
1184 1042
1185 TEST_F(WalletClientTest, SaveInstrumentSucceeded) { 1043 TEST_F(WalletClientTest, SaveInstrumentSucceeded) {
1186 EXPECT_CALL(delegate_, 1044 EXPECT_CALL(delegate_,
1187 OnDidSaveInstrument("instrument_id", 1045 OnDidSaveToWallet("instrument_id",
1188 std::vector<RequiredAction>(), 1046 std::string(),
1189 std::vector<FormFieldError>())).Times(1); 1047 std::vector<RequiredAction>(),
1190 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1048 std::vector<FormFieldError>())).Times(1);
1191 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1049 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1050 delegate_.ExpectBaselineMetrics();
1192 1051
1193 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1052 scoped_ptr<Instrument> instrument = GetTestInstrument();
1194 wallet_client_->SaveInstrument(*instrument, 1053 wallet_client_->SaveToWallet(instrument.Pass(),
1195 "obfuscated_gaia_id", 1054 scoped_ptr<Address>(),
1196 GURL(kMerchantUrl)); 1055 GURL(kMerchantUrl));
1197 1056
1198 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1057 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1199 1058 kSaveInstrumentValidRequest,
1200 VerifyAndFinishRequest(net::HTTP_OK, 1059 kSaveInstrumentValidResponse);
1201 kSaveInstrumentValidRequest,
1202 kSaveInstrumentValidResponse);
1203 } 1060 }
1204 1061
1205 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) { 1062 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) {
1206 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1063 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1207 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1064 delegate_.ExpectBaselineMetrics();
1208 delegate_.ExpectWalletRequiredActionMetric( 1065 delegate_.ExpectWalletRequiredActionMetric(
1209 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1066 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1210 delegate_.ExpectWalletRequiredActionMetric( 1067 delegate_.ExpectWalletRequiredActionMetric(
1211 AutofillMetrics::INVALID_FORM_FIELD); 1068 AutofillMetrics::INVALID_FORM_FIELD);
1212 1069
1213 std::vector<RequiredAction> required_actions; 1070 std::vector<RequiredAction> required_actions;
1214 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1071 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1215 required_actions.push_back(INVALID_FORM_FIELD); 1072 required_actions.push_back(INVALID_FORM_FIELD);
1216 1073
1217 std::vector<FormFieldError> form_errors; 1074 std::vector<FormFieldError> form_errors;
1218 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1075 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1219 FormFieldError::SHIPPING_ADDRESS)); 1076 FormFieldError::SHIPPING_ADDRESS));
1220 1077
1221 EXPECT_CALL(delegate_, 1078 EXPECT_CALL(delegate_,
1222 OnDidSaveInstrument(std::string(), 1079 OnDidSaveToWallet(std::string(),
1223 required_actions, 1080 std::string(),
1224 form_errors)).Times(1); 1081 required_actions,
1082 form_errors)).Times(1);
1225 1083
1226 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1084 scoped_ptr<Instrument> instrument = GetTestInstrument();
1227 wallet_client_->SaveInstrument(*instrument, 1085 wallet_client_->SaveToWallet(instrument.Pass(),
1228 "obfuscated_gaia_id", 1086 scoped_ptr<Address>(),
1229 GURL(kMerchantUrl)); 1087 GURL(kMerchantUrl));
1230 1088
1231 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1089 VerifyAndFinishFormEncodedRequest(
1232 1090 net::HTTP_OK,
1233 VerifyAndFinishRequest(net::HTTP_OK, 1091 kSaveInstrumentValidRequest,
1234 kSaveInstrumentValidRequest, 1092 kSaveInstrumentWithRequiredActionsValidResponse);
1235 kSaveInstrumentWithRequiredActionsValidResponse);
1236 } 1093 }
1237 1094
1238 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) { 1095 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) {
1239 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1096 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1240 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1097 delegate_.ExpectBaselineMetrics();
1241 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1098 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1242 1099
1243 EXPECT_CALL(delegate_, 1100 EXPECT_CALL(delegate_,
1244 OnWalletError(WalletClient::MALFORMED_RESPONSE)); 1101 OnWalletError(WalletClient::MALFORMED_RESPONSE));
1245 1102
1246 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1103 scoped_ptr<Instrument> instrument = GetTestInstrument();
1247 wallet_client_->SaveInstrument(*instrument, 1104 wallet_client_->SaveToWallet(instrument.Pass(),
1248 "obfuscated_gaia_id", 1105 scoped_ptr<Address>(),
1249 GURL(kMerchantUrl)); 1106 GURL(kMerchantUrl));
1250 1107
1251 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1108 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1252 1109 kSaveInstrumentValidRequest,
1253 VerifyAndFinishRequest(net::HTTP_OK, 1110 kSaveWithInvalidRequiredActionsResponse);
1254 kSaveInstrumentValidRequest,
1255 kSaveWithInvalidRequiredActionsResponse);
1256 }
1257
1258 TEST_F(WalletClientTest, SaveInstrumentEscrowDown) {
1259 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
1260 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 0);
1261 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1262 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
1263
1264 scoped_ptr<Instrument> instrument = GetTestInstrument();
1265 wallet_client_->SaveInstrument(*instrument,
1266 "obfuscated_gaia_id",
1267 GURL(kMerchantUrl));
1268
1269 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string());
1270 }
1271
1272 TEST_F(WalletClientTest, SaveInstrumentEscrowMalformed) {
1273 EXPECT_CALL(delegate_,
1274 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1275 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 0);
1276 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1277 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1278
1279 scoped_ptr<Instrument> instrument = GetTestInstrument();
1280 wallet_client_->SaveInstrument(*instrument,
1281 "obfuscated_gaia_id",
1282 GURL(kMerchantUrl));
1283
1284 DoEncryptionOrEscrowRequest(net::HTTP_OK, std::string());
1285 } 1111 }
1286 1112
1287 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) { 1113 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) {
1288 EXPECT_CALL(delegate_, 1114 EXPECT_CALL(delegate_,
1289 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1115 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1290 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1116 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1291 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1117 delegate_.ExpectBaselineMetrics();
1292 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1118 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1293 1119
1294 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1120 scoped_ptr<Instrument> instrument = GetTestInstrument();
1295 wallet_client_->SaveInstrument(*instrument, 1121 wallet_client_->SaveToWallet(instrument.Pass(),
1296 "obfuscated_gaia_id", 1122 scoped_ptr<Address>(),
1297 GURL(kMerchantUrl)); 1123 GURL(kMerchantUrl));
1298 1124
1299 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1125 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1300 1126 kSaveInstrumentValidRequest,
1301 VerifyAndFinishRequest(net::HTTP_OK, 1127 kSaveInvalidResponse);
1302 kSaveInstrumentValidRequest,
1303 kSaveInvalidResponse);
1304 } 1128 }
1305 1129
1306 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { 1130 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) {
1307 EXPECT_CALL(delegate_, 1131 EXPECT_CALL(delegate_,
1308 OnDidSaveInstrumentAndAddress( 1132 OnDidSaveToWallet("saved_instrument_id",
1309 "saved_instrument_id", 1133 "saved_address_id",
1310 "saved_address_id", 1134 std::vector<RequiredAction>(),
1311 std::vector<RequiredAction>(), 1135 std::vector<FormFieldError>())).Times(1);
1312 std::vector<FormFieldError>())).Times(1);
1313 delegate_.ExpectLogWalletApiCallDuration( 1136 delegate_.ExpectLogWalletApiCallDuration(
1314 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1137 AutofillMetrics::SAVE_TO_WALLET,
1315 1); 1138 1);
1316 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1139 delegate_.ExpectBaselineMetrics();
1317 1140
1318 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1141 scoped_ptr<Instrument> instrument = GetTestInstrument();
1319 scoped_ptr<Address> address = GetTestSaveableAddress(); 1142 scoped_ptr<Address> address = GetTestSaveableAddress();
1320 wallet_client_->SaveInstrumentAndAddress(*instrument, 1143 wallet_client_->SaveToWallet(instrument.Pass(),
1321 *address, 1144 address.Pass(),
1322 "obfuscated_gaia_id", 1145 GURL(kMerchantUrl));
1323 GURL(kMerchantUrl));
1324 1146
1325 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1147 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1326 VerifyAndFinishRequest(net::HTTP_OK, 1148 kSaveInstrumentAndAddressValidRequest,
1327 kSaveInstrumentAndAddressValidRequest, 1149 kSaveInstrumentAndAddressValidResponse);
1328 kSaveInstrumentAndAddressValidResponse);
1329 } 1150 }
1330 1151
1331 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) { 1152 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) {
1332 delegate_.ExpectLogWalletApiCallDuration( 1153 delegate_.ExpectLogWalletApiCallDuration(
1333 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1154 AutofillMetrics::SAVE_TO_WALLET,
1334 1); 1155 1);
1335 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1156 delegate_.ExpectBaselineMetrics();
1336 delegate_.ExpectWalletRequiredActionMetric( 1157 delegate_.ExpectWalletRequiredActionMetric(
1337 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1158 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1338 delegate_.ExpectWalletRequiredActionMetric( 1159 delegate_.ExpectWalletRequiredActionMetric(
1339 AutofillMetrics::INVALID_FORM_FIELD); 1160 AutofillMetrics::INVALID_FORM_FIELD);
1340 1161
1341 std::vector<RequiredAction> required_actions; 1162 std::vector<RequiredAction> required_actions;
1342 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1163 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1343 required_actions.push_back(INVALID_FORM_FIELD); 1164 required_actions.push_back(INVALID_FORM_FIELD);
1344 1165
1345 std::vector<FormFieldError> form_errors; 1166 std::vector<FormFieldError> form_errors;
1346 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1167 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1347 FormFieldError::SHIPPING_ADDRESS)); 1168 FormFieldError::SHIPPING_ADDRESS));
1348 1169
1349 EXPECT_CALL(delegate_, 1170 EXPECT_CALL(delegate_,
1350 OnDidSaveInstrumentAndAddress( 1171 OnDidSaveToWallet(std::string(),
1351 std::string(), 1172 std::string(),
1352 std::string(), 1173 required_actions,
1353 required_actions, 1174 form_errors)).Times(1);
1354 form_errors)).Times(1);
1355 1175
1356 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1176 scoped_ptr<Instrument> instrument = GetTestInstrument();
1357 scoped_ptr<Address> address = GetTestSaveableAddress(); 1177 scoped_ptr<Address> address = GetTestSaveableAddress();
1358 wallet_client_->SaveInstrumentAndAddress(*instrument, 1178 wallet_client_->SaveToWallet(instrument.Pass(),
1359 *address, 1179 address.Pass(),
1360 "obfuscated_gaia_id", 1180 GURL(kMerchantUrl));
1361 GURL(kMerchantUrl));
1362 1181
1363 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1182 VerifyAndFinishFormEncodedRequest(
1364 VerifyAndFinishRequest(
1365 net::HTTP_OK, 1183 net::HTTP_OK,
1366 kSaveInstrumentAndAddressValidRequest, 1184 kSaveInstrumentAndAddressValidRequest,
1367 kSaveInstrumentAndAddressWithRequiredActionsValidResponse); 1185 kSaveInstrumentAndAddressWithRequiredActionsValidResponse);
1368 } 1186 }
1369 1187
1370 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) { 1188 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) {
1371 EXPECT_CALL(delegate_, 1189 EXPECT_CALL(delegate_,
1372 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1190 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1373 delegate_.ExpectLogWalletApiCallDuration( 1191 delegate_.ExpectLogWalletApiCallDuration(
1374 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1192 AutofillMetrics::SAVE_TO_WALLET,
1375 1); 1193 1);
1376 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1194 delegate_.ExpectBaselineMetrics();
1377 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1195 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1378 1196
1379 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1197 scoped_ptr<Instrument> instrument = GetTestInstrument();
1380 scoped_ptr<Address> address = GetTestSaveableAddress(); 1198 scoped_ptr<Address> address = GetTestSaveableAddress();
1381 wallet_client_->SaveInstrumentAndAddress(*instrument, 1199 wallet_client_->SaveToWallet(instrument.Pass(),
1382 *address, 1200 address.Pass(),
1383 "obfuscated_gaia_id", 1201 GURL(kMerchantUrl));
1384 GURL(kMerchantUrl));
1385 1202
1386 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1203 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1387 1204 kSaveInstrumentAndAddressValidRequest,
1388 VerifyAndFinishRequest(net::HTTP_OK, 1205 kSaveWithInvalidRequiredActionsResponse);
1389 kSaveInstrumentAndAddressValidRequest,
1390 kSaveWithInvalidRequiredActionsResponse);
1391 }
1392
1393 TEST_F(WalletClientTest, SaveInstrumentAndAddressEscrowDown) {
1394 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
1395 delegate_.ExpectLogWalletApiCallDuration(
1396 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS,
1397 0);
1398 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1399 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
1400
1401 scoped_ptr<Instrument> instrument = GetTestInstrument();
1402 scoped_ptr<Address> address = GetTestSaveableAddress();
1403 wallet_client_->SaveInstrumentAndAddress(*instrument,
1404 *address,
1405 "obfuscated_gaia_id",
1406 GURL(kMerchantUrl));
1407
1408 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string());
1409 }
1410
1411 TEST_F(WalletClientTest, SaveInstrumentAndAddressEscrowMalformed) {
1412 EXPECT_CALL(delegate_,
1413 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1414 delegate_.ExpectLogWalletApiCallDuration(
1415 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS,
1416 0);
1417 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1418 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1419
1420 scoped_ptr<Instrument> instrument = GetTestInstrument();
1421 scoped_ptr<Address> address = GetTestSaveableAddress();
1422 wallet_client_->SaveInstrumentAndAddress(*instrument,
1423 *address,
1424 "obfuscated_gaia_id",
1425 GURL(kMerchantUrl));
1426
1427 DoEncryptionOrEscrowRequest(net::HTTP_OK, std::string());
1428 }
1429
1430 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedAddressMissing) {
1431 EXPECT_CALL(delegate_,
1432 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1433 delegate_.ExpectLogWalletApiCallDuration(
1434 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS,
1435 1);
1436 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST);
1437 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1438
1439 scoped_ptr<Instrument> instrument = GetTestInstrument();
1440 scoped_ptr<Address> address = GetTestSaveableAddress();
1441 wallet_client_->SaveInstrumentAndAddress(*instrument,
1442 *address,
1443 "obfuscated_gaia_id",
1444 GURL(kMerchantUrl));
1445
1446 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle");
1447
1448 VerifyAndFinishRequest(net::HTTP_OK,
1449 kSaveInstrumentAndAddressValidRequest,
1450 kSaveInstrumentAndAddressMissingAddressResponse);
1451 }
1452
1453 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInstrumentMissing) {
1454 EXPECT_CALL(delegate_,
1455 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1456 delegate_.ExpectLogWalletApiCallDuration(
1457 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS,
1458 1);
1459 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST);
1460 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1461
1462 scoped_ptr<Instrument> instrument = GetTestInstrument();
1463 scoped_ptr<Address> address = GetTestSaveableAddress();
1464 wallet_client_->SaveInstrumentAndAddress(*instrument,
1465 *address,
1466 "obfuscated_gaia_id",
1467 GURL(kMerchantUrl));
1468
1469 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle");
1470
1471 VerifyAndFinishRequest(net::HTTP_OK,
1472 kSaveInstrumentAndAddressValidRequest,
1473 kSaveInstrumentAndAddressMissingInstrumentResponse);
1474 } 1206 }
1475 1207
1476 TEST_F(WalletClientTest, UpdateAddressSucceeded) { 1208 TEST_F(WalletClientTest, UpdateAddressSucceeded) {
1477 EXPECT_CALL(delegate_, 1209 EXPECT_CALL(delegate_,
1478 OnDidUpdateAddress("shipping_address_id", 1210 OnDidSaveToWallet(std::string(),
1479 std::vector<RequiredAction>(), 1211 "shipping_address_id",
1480 std::vector<FormFieldError>())).Times(1); 1212 std::vector<RequiredAction>(),
1481 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1213 std::vector<FormFieldError>())).Times(1);
1482 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1214 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1215 delegate_.ExpectBaselineMetrics();
1483 1216
1484 scoped_ptr<Address> address = GetTestShippingAddress(); 1217 scoped_ptr<Address> address = GetTestShippingAddress();
1485 address->set_object_id("shipping_address_id"); 1218 address->set_object_id("shipping_address_id");
1486 1219
1487 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1220 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1488 VerifyAndFinishRequest(net::HTTP_OK, 1221 address.Pass(),
1489 kUpdateAddressValidRequest, 1222 GURL(kMerchantUrl));
1490 kUpdateAddressValidResponse); 1223 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1224 kUpdateAddressValidRequest,
1225 kUpdateAddressValidResponse);
1491 } 1226 }
1492 1227
1493 TEST_F(WalletClientTest, UpdateAddressWithRequiredActionsSucceeded) { 1228 TEST_F(WalletClientTest, UpdateAddressWithRequiredActionsSucceeded) {
1494 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1229 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1495 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1230 delegate_.ExpectBaselineMetrics();
1496 delegate_.ExpectWalletRequiredActionMetric( 1231 delegate_.ExpectWalletRequiredActionMetric(
1497 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1232 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1498 delegate_.ExpectWalletRequiredActionMetric( 1233 delegate_.ExpectWalletRequiredActionMetric(
1499 AutofillMetrics::INVALID_FORM_FIELD); 1234 AutofillMetrics::INVALID_FORM_FIELD);
1500 1235
1501 std::vector<RequiredAction> required_actions; 1236 std::vector<RequiredAction> required_actions;
1502 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1237 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1503 required_actions.push_back(INVALID_FORM_FIELD); 1238 required_actions.push_back(INVALID_FORM_FIELD);
1504 1239
1505 std::vector<FormFieldError> form_errors; 1240 std::vector<FormFieldError> form_errors;
1506 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1241 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1507 FormFieldError::SHIPPING_ADDRESS)); 1242 FormFieldError::SHIPPING_ADDRESS));
1508 1243
1509 EXPECT_CALL(delegate_, OnDidUpdateAddress(std::string(), 1244 EXPECT_CALL(delegate_, OnDidSaveToWallet(std::string(),
1510 required_actions, 1245 std::string(),
1511 form_errors)).Times(1); 1246 required_actions,
1247 form_errors)).Times(1);
1512 1248
1513 scoped_ptr<Address> address = GetTestShippingAddress(); 1249 scoped_ptr<Address> address = GetTestShippingAddress();
1514 address->set_object_id("shipping_address_id"); 1250 address->set_object_id("shipping_address_id");
1515 1251
1516 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1252 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1517 VerifyAndFinishRequest(net::HTTP_OK, 1253 address.Pass(),
1518 kUpdateAddressValidRequest, 1254 GURL(kMerchantUrl));
1519 kUpdateWithRequiredActionsValidResponse); 1255 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1256 kUpdateAddressValidRequest,
1257 kUpdateWithRequiredActionsValidResponse);
1520 } 1258 }
1521 1259
1522 TEST_F(WalletClientTest, UpdateAddressFailedInvalidRequiredAction) { 1260 TEST_F(WalletClientTest, UpdateAddressFailedInvalidRequiredAction) {
1523 EXPECT_CALL(delegate_, 1261 EXPECT_CALL(delegate_,
1524 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1262 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1525 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1263 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1526 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1264 delegate_.ExpectBaselineMetrics();
1527 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1265 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1528 1266
1529 scoped_ptr<Address> address = GetTestShippingAddress(); 1267 scoped_ptr<Address> address = GetTestShippingAddress();
1530 address->set_object_id("shipping_address_id"); 1268 address->set_object_id("shipping_address_id");
1531 1269
1532 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1270 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1533 VerifyAndFinishRequest(net::HTTP_OK, 1271 address.Pass(),
1534 kUpdateAddressValidRequest, 1272 GURL(kMerchantUrl));
1535 kSaveWithInvalidRequiredActionsResponse); 1273 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1274 kUpdateAddressValidRequest,
1275 kSaveWithInvalidRequiredActionsResponse);
1536 } 1276 }
1537 1277
1538 TEST_F(WalletClientTest, UpdateAddressMalformedResponse) { 1278 TEST_F(WalletClientTest, UpdateAddressMalformedResponse) {
1539 EXPECT_CALL(delegate_, 1279 EXPECT_CALL(delegate_,
1540 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1280 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1541 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1281 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1542 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1282 delegate_.ExpectBaselineMetrics();
1543 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1283 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1544 1284
1545 scoped_ptr<Address> address = GetTestShippingAddress(); 1285 scoped_ptr<Address> address = GetTestShippingAddress();
1546 address->set_object_id("shipping_address_id"); 1286 address->set_object_id("shipping_address_id");
1547 1287
1548 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1288 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1549 VerifyAndFinishRequest(net::HTTP_OK, 1289 address.Pass(),
1550 kUpdateAddressValidRequest, 1290 GURL(kMerchantUrl));
1551 kUpdateMalformedResponse); 1291 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1292 kUpdateAddressValidRequest,
1293 kUpdateMalformedResponse);
1552 } 1294 }
1553 1295
1554 TEST_F(WalletClientTest, UpdateInstrumentAddressSucceeded) { 1296 TEST_F(WalletClientTest, UpdateInstrumentAddressSucceeded) {
1555 EXPECT_CALL(delegate_, 1297 EXPECT_CALL(delegate_,
1556 OnDidUpdateInstrument("instrument_id", 1298 OnDidSaveToWallet("instrument_id",
1557 std::vector<RequiredAction>(), 1299 std::string(),
1558 std::vector<FormFieldError>())).Times(1); 1300 std::vector<RequiredAction>(),
1559 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1301 std::vector<FormFieldError>())).Times(1);
1302 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1560 1); 1303 1);
1561 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1304 delegate_.ExpectBaselineMetrics();
1562 1305
1563 WalletClient::UpdateInstrumentRequest update_instrument_request( 1306 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1564 "instrument_id", 1307 scoped_ptr<Address>(),
1565 GURL(kMerchantUrl)); 1308 GURL(kMerchantUrl));
1566 1309
1567 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1310 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1568 1311 kUpdateInstrumentAddressValidRequest,
1569 VerifyAndFinishRequest(net::HTTP_OK, 1312 kUpdateInstrumentValidResponse);
1570 kUpdateInstrumentAddressValidRequest,
1571 kUpdateInstrumentValidResponse);
1572 } 1313 }
1573 1314
1574 TEST_F(WalletClientTest, UpdateInstrumentExpirationDateSuceeded) { 1315 TEST_F(WalletClientTest, UpdateInstrumentExpirationDateSuceeded) {
1575 EXPECT_CALL(delegate_, 1316 EXPECT_CALL(delegate_,
1576 OnDidUpdateInstrument("instrument_id", 1317 OnDidSaveToWallet("instrument_id",
1577 std::vector<RequiredAction>(), 1318 std::string(),
1578 std::vector<FormFieldError>())).Times(1); 1319 std::vector<RequiredAction>(),
1579 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1320 std::vector<FormFieldError>())).Times(1);
1321 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1580 1); 1322 1);
1581 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1323 delegate_.ExpectBaselineMetrics();
1582 1324
1583 WalletClient::UpdateInstrumentRequest update_instrument_request( 1325 wallet_client_->SaveToWallet(GetTestExpirationDateChangeInstrument(),
1584 "instrument_id", 1326 scoped_ptr<Address>(),
1585 GURL(kMerchantUrl)); 1327 GURL(kMerchantUrl));
1586 update_instrument_request.expiration_month = 12;
1587 update_instrument_request.expiration_year = 2015;
1588 update_instrument_request.card_verification_number =
1589 "card_verification_number";
1590 update_instrument_request.obfuscated_gaia_id = "obfuscated_gaia_id";
1591 wallet_client_->UpdateInstrument(update_instrument_request,
1592 scoped_ptr<Address>());
1593 1328
1594 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1329 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1595 1330 kUpdateInstrumentExpirationDateValidRequest,
1596 VerifyAndFinishRequest(net::HTTP_OK, 1331 kUpdateInstrumentValidResponse);
1597 kUpdateInstrumentExpirationDateValidRequest,
1598 kUpdateInstrumentValidResponse);
1599 } 1332 }
1600 1333
1601 TEST_F(WalletClientTest, UpdateInstrumentAddressWithNameChangeSucceeded) { 1334 TEST_F(WalletClientTest, UpdateInstrumentAddressWithNameChangeSucceeded) {
1602 EXPECT_CALL(delegate_, 1335 EXPECT_CALL(delegate_,
1603 OnDidUpdateInstrument("instrument_id", 1336 OnDidSaveToWallet("instrument_id",
1604 std::vector<RequiredAction>(), 1337 std::string(),
1605 std::vector<FormFieldError>())).Times(1); 1338 std::vector<RequiredAction>(),
1606 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1339 std::vector<FormFieldError>())).Times(1);
1340 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1607 1); 1341 1);
1608 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1342 delegate_.ExpectBaselineMetrics();
1609 1343
1610 WalletClient::UpdateInstrumentRequest update_instrument_request( 1344 wallet_client_->SaveToWallet(GetTestAddressNameChangeInstrument(),
1611 "instrument_id", 1345 scoped_ptr<Address>(),
1612 GURL(kMerchantUrl)); 1346 GURL(kMerchantUrl));
1613 update_instrument_request.card_verification_number =
1614 "card_verification_number";
1615 update_instrument_request.obfuscated_gaia_id = "obfuscated_gaia_id";
1616 1347
1617 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1348 VerifyAndFinishFormEncodedRequest(
1618 1349 net::HTTP_OK,
1619 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1350 kUpdateInstrumentAddressWithNameChangeValidRequest,
1620 1351 kUpdateInstrumentValidResponse);
1621 VerifyAndFinishRequest(net::HTTP_OK,
1622 kUpdateInstrumentAddressWithNameChangeValidRequest,
1623 kUpdateInstrumentValidResponse);
1624 }
1625
1626 TEST_F(WalletClientTest, UpdateInstrumentAddressAndExpirationDateSucceeded) {
1627 EXPECT_CALL(delegate_,
1628 OnDidUpdateInstrument("instrument_id",
1629 std::vector<RequiredAction>(),
1630 std::vector<FormFieldError>())).Times(1);
1631 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT,
1632 1);
1633 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST);
1634
1635 WalletClient::UpdateInstrumentRequest update_instrument_request(
1636 "instrument_id",
1637 GURL(kMerchantUrl));
1638 update_instrument_request.expiration_month = 12;
1639 update_instrument_request.expiration_year = 2015;
1640 update_instrument_request.card_verification_number =
1641 "card_verification_number";
1642 update_instrument_request.obfuscated_gaia_id = "obfuscated_gaia_id";
1643 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress());
1644
1645 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle");
1646
1647 VerifyAndFinishRequest(net::HTTP_OK,
1648 kUpdateInstrumentAddressAndExpirationDateValidRequest,
1649 kUpdateInstrumentValidResponse);
1650 } 1352 }
1651 1353
1652 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) { 1354 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) {
1653 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1355 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1654 1); 1356 1);
1655 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1357 delegate_.ExpectBaselineMetrics();
1656 delegate_.ExpectWalletRequiredActionMetric( 1358 delegate_.ExpectWalletRequiredActionMetric(
1657 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1359 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1658 delegate_.ExpectWalletRequiredActionMetric( 1360 delegate_.ExpectWalletRequiredActionMetric(
1659 AutofillMetrics::INVALID_FORM_FIELD); 1361 AutofillMetrics::INVALID_FORM_FIELD);
1660 1362
1661 std::vector<RequiredAction> required_actions; 1363 std::vector<RequiredAction> required_actions;
1662 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1364 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1663 required_actions.push_back(INVALID_FORM_FIELD); 1365 required_actions.push_back(INVALID_FORM_FIELD);
1664 1366
1665 std::vector<FormFieldError> form_errors; 1367 std::vector<FormFieldError> form_errors;
1666 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1368 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1667 FormFieldError::SHIPPING_ADDRESS)); 1369 FormFieldError::SHIPPING_ADDRESS));
1668 1370
1669 EXPECT_CALL(delegate_, 1371 EXPECT_CALL(delegate_,
1670 OnDidUpdateInstrument(std::string(), 1372 OnDidSaveToWallet(std::string(),
1671 required_actions, 1373 std::string(),
1672 form_errors)).Times(1); 1374 required_actions,
1375 form_errors)).Times(1);
1673 1376
1674 WalletClient::UpdateInstrumentRequest update_instrument_request( 1377 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1675 "instrument_id", 1378 scoped_ptr<Address>(),
1676 GURL(kMerchantUrl)); 1379 GURL(kMerchantUrl));
1677 1380
1678 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1381 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1679 1382 kUpdateInstrumentAddressValidRequest,
1680 VerifyAndFinishRequest(net::HTTP_OK, 1383 kUpdateWithRequiredActionsValidResponse);
1681 kUpdateInstrumentAddressValidRequest,
1682 kUpdateWithRequiredActionsValidResponse);
1683 } 1384 }
1684 1385
1685 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) { 1386 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) {
1686 EXPECT_CALL(delegate_, 1387 EXPECT_CALL(delegate_,
1687 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1388 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1688 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1389 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1689 1); 1390 1);
1690 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1391 delegate_.ExpectBaselineMetrics();
1691 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1392 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1692 1393
1693 WalletClient::UpdateInstrumentRequest update_instrument_request( 1394 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1694 "instrument_id", 1395 scoped_ptr<Address>(),
1695 GURL(kMerchantUrl)); 1396 GURL(kMerchantUrl));
1696 1397
1697 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1398 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1698 1399 kUpdateInstrumentAddressValidRequest,
1699 VerifyAndFinishRequest(net::HTTP_OK, 1400 kSaveWithInvalidRequiredActionsResponse);
1700 kUpdateInstrumentAddressValidRequest,
1701 kSaveWithInvalidRequiredActionsResponse);
1702 }
1703
1704 TEST_F(WalletClientTest, UpdateInstrumentEscrowFailed) {
1705 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
1706 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT,
1707 0);
1708 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST);
1709 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
1710
1711 WalletClient::UpdateInstrumentRequest update_instrument_request(
1712 "instrument_id",
1713 GURL(kMerchantUrl));
1714 update_instrument_request.card_verification_number =
1715 "card_verification_number";
1716 update_instrument_request.obfuscated_gaia_id = "obfuscated_gaia_id";
1717
1718 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress());
1719
1720 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string());
1721 } 1401 }
1722 1402
1723 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) { 1403 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) {
1724 EXPECT_CALL(delegate_, 1404 EXPECT_CALL(delegate_,
1725 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1405 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1726 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1406 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1727 1); 1407 1);
1728 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1408 delegate_.ExpectBaselineMetrics();
1729 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1409 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1730 1410
1731 WalletClient::UpdateInstrumentRequest update_instrument_request( 1411 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1732 "instrument_id", 1412 scoped_ptr<Address>(),
1733 GURL(kMerchantUrl)); 1413 GURL(kMerchantUrl));
1734 1414
1735 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1415 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1736 1416 kUpdateInstrumentAddressValidRequest,
1737 VerifyAndFinishRequest(net::HTTP_OK, 1417 kUpdateMalformedResponse);
1738 kUpdateInstrumentAddressValidRequest,
1739 kUpdateMalformedResponse);
1740 } 1418 }
1741 1419
1742 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { 1420 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) {
1743 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 1421 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
1744 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1422 delegate_.ExpectBaselineMetrics();
1745 1423
1746 AutocheckoutStatistic statistic; 1424 AutocheckoutStatistic statistic;
1747 statistic.page_number = 1; 1425 statistic.page_number = 1;
1748 statistic.steps.push_back(AUTOCHECKOUT_STEP_SHIPPING); 1426 statistic.steps.push_back(AUTOCHECKOUT_STEP_SHIPPING);
1749 statistic.time_taken = base::TimeDelta::FromMilliseconds(100); 1427 statistic.time_taken = base::TimeDelta::FromMilliseconds(100);
1750 std::vector<AutocheckoutStatistic> statistics; 1428 std::vector<AutocheckoutStatistic> statistics;
1751 statistics.push_back(statistic); 1429 statistics.push_back(statistic);
1752 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 1430 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
1753 GURL(kMerchantUrl), 1431 GURL(kMerchantUrl),
1754 statistics, 1432 statistics,
1755 "google_transaction_id"); 1433 "google_transaction_id");
1756 VerifyAndFinishRequest(net::HTTP_OK, 1434 VerifyAndFinishRequest(net::HTTP_OK,
1757 kSendAutocheckoutStatusWithStatisticsValidRequest, 1435 kSendAutocheckoutStatusWithStatisticsValidRequest,
1758 ")]}"); // Invalid JSON. Should be ignored. 1436 ")]}"); // Invalid JSON. Should be ignored.
1759 } 1437 }
1760 1438
1761 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { 1439 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) {
1762 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 1440 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
1763 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1441 delegate_.ExpectBaselineMetrics();
1764 1442
1765 std::vector<AutocheckoutStatistic> statistics; 1443 std::vector<AutocheckoutStatistic> statistics;
1766 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, 1444 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED,
1767 GURL(kMerchantUrl), 1445 GURL(kMerchantUrl),
1768 statistics, 1446 statistics,
1769 "google_transaction_id"); 1447 "google_transaction_id");
1770 VerifyAndFinishRequest(net::HTTP_OK, 1448 VerifyAndFinishRequest(net::HTTP_OK,
1771 kSendAutocheckoutStatusOfFailureValidRequest, 1449 kSendAutocheckoutStatusOfFailureValidRequest,
1772 ")]}"); // Invalid JSON. Should be ignored. 1450 ")]}"); // Invalid JSON. Should be ignored.
1773 } 1451 }
1774 1452
1775 TEST_F(WalletClientTest, HasRequestInProgress) { 1453 TEST_F(WalletClientTest, HasRequestInProgress) {
1776 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1454 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1777 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1455 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1778 1); 1456 1);
1779 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1457 delegate_.ExpectBaselineMetrics();
1780 1458
1781 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1459 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1782 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); 1460 EXPECT_TRUE(wallet_client_->HasRequestInProgress());
1783 1461
1784 VerifyAndFinishRequest(net::HTTP_OK, 1462 VerifyAndFinishRequest(net::HTTP_OK,
1785 kGetWalletItemsValidRequest, 1463 kGetWalletItemsValidRequest,
1786 kGetWalletItemsValidResponse); 1464 kGetWalletItemsValidResponse);
1787 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1465 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1788 } 1466 }
1789 1467
1790 TEST_F(WalletClientTest, PendingRequest) { 1468 TEST_F(WalletClientTest, PendingRequest) {
1791 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1469 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1792 1470
1793 // Shouldn't queue the first request. 1471 // Shouldn't queue the first request.
1794 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1472 delegate_.ExpectBaselineMetrics();
1795 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1473 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1796 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1474 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1797 testing::Mock::VerifyAndClear(delegate_.metric_logger()); 1475 testing::Mock::VerifyAndClear(delegate_.metric_logger());
1798 1476
1799 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1477 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1800 EXPECT_EQ(1U, wallet_client_->pending_requests_.size()); 1478 EXPECT_EQ(1U, wallet_client_->pending_requests_.size());
1801 1479
1802 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1480 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1803 1); 1481 1);
1804 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1482 delegate_.ExpectBaselineMetrics();
1805 VerifyAndFinishRequest(net::HTTP_OK, 1483 VerifyAndFinishRequest(net::HTTP_OK,
1806 kGetWalletItemsValidRequest, 1484 kGetWalletItemsValidRequest,
1807 kGetWalletItemsValidResponse); 1485 kGetWalletItemsValidResponse);
1808 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1486 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1809 testing::Mock::VerifyAndClear(delegate_.metric_logger()); 1487 testing::Mock::VerifyAndClear(delegate_.metric_logger());
1810 1488
1811 EXPECT_CALL(delegate_, OnWalletError( 1489 EXPECT_CALL(delegate_, OnWalletError(
1812 WalletClient::SERVICE_UNAVAILABLE)).Times(1); 1490 WalletClient::SERVICE_UNAVAILABLE)).Times(1);
1813 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1491 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1814 1); 1492 1);
1815 delegate_.ExpectWalletErrorMetric( 1493 delegate_.ExpectWalletErrorMetric(
1816 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); 1494 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE);
1817 1495
1818 // Finish the second request. 1496 // Finish the second request.
1819 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 1497 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
1820 kGetWalletItemsValidRequest, 1498 kGetWalletItemsValidRequest,
1821 kErrorResponse); 1499 kErrorResponse);
1822 } 1500 }
1823 1501
1824 TEST_F(WalletClientTest, CancelRequests) { 1502 TEST_F(WalletClientTest, CancelRequests) {
1825 ASSERT_EQ(0U, wallet_client_->pending_requests_.size()); 1503 ASSERT_EQ(0U, wallet_client_->pending_requests_.size());
1826 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1504 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1827 0); 1505 0);
1828 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1506 delegate_.ExpectBaselineMetrics();
1829 1507
1830 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1508 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1831 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1509 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1832 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1510 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1833 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); 1511 EXPECT_EQ(2U, wallet_client_->pending_requests_.size());
1834 1512
1835 wallet_client_->CancelRequests(); 1513 wallet_client_->CancelRequests();
1836 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1514 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1837 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1515 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1838 } 1516 }
1839 1517
1840 } // namespace wallet 1518 } // namespace wallet
1841 } // namespace autofill 1519 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698