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

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

Powered by Google App Engine
This is Rietveld 408576698