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

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

Powered by Google App Engine
This is Rietveld 408576698