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

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

Powered by Google App Engine
This is Rietveld 408576698