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

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: Dane's review 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 const std::string& upload_data = fetcher->upload_data();
684 std::vector<std::pair<std::string, std::string> > tokens;
685 base::SplitStringIntoKeyValuePairs(upload_data, '=', '&', &tokens);
Dan Beam 2013/07/02 01:25:52 nit: \n somewhere in here
ahutter 2013/07/02 15:44:23 Done.
686 for (size_t i = 0; i < tokens.size(); ++i) {
687 const std::string& key = tokens[i].first;
688 const std::string& value = tokens[i].second;
Dan Beam 2013/07/02 01:25:52 nit: \n
ahutter 2013/07/02 15:44:23 Done.
689 if (key == "request_content_type")
690 EXPECT_EQ("application/json", value);
Dan Beam 2013/07/02 01:25:52 nit: \n
ahutter 2013/07/02 15:44:23 Done.
691 if (key == "request") {
692 EXPECT_EQ(json_payload,
693 GetData(
694 net::UnescapeURLComponent(
695 value, net::UnescapeRule::URL_SPECIAL_CHARS |
696 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE)));
697 }
698 // TODO(ahutter): Check cvn, cc_number, and that otp is non-empty.
699 }
Dan Beam 2013/07/02 01:25:52 nit: \n
ahutter 2013/07/02 15:44:23 Done.
700 fetcher->set_response_code(response_code);
701 fetcher->SetResponseString(response_body);
702 fetcher->delegate()->OnURLFetchComplete(fetcher);
786 } 703 }
787 704
788 protected: 705 protected:
789 scoped_ptr<WalletClient> wallet_client_; 706 scoped_ptr<WalletClient> wallet_client_;
790 content::TestBrowserContext browser_context_; 707 content::TestBrowserContext browser_context_;
791 MockWalletClientDelegate delegate_; 708 MockWalletClientDelegate delegate_;
792 709
793 private: 710 private:
711 std::string GetData(const std::string& upload_data) {
712 scoped_ptr<Value> root(base::JSONReader::Read(upload_data));
713
714 // If this is not a JSON dictionary, return plain text.
715 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY))
Dan Beam 2013/07/02 01:25:52 if (!root || !root->IsType(Value::TYPE_DICTIONARY)
ahutter 2013/07/02 15:44:23 Done.
716 return upload_data;
717
718 // Remove api_key entry (to prevent accidental leak), return JSON as text.
719 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get());
720 dict->Remove("api_key", NULL);
721 std::string clean_upload_data;
722 base::JSONWriter::Write(dict, &clean_upload_data);
723 return clean_upload_data;
724 }
725
794 net::TestURLFetcherFactory factory_; 726 net::TestURLFetcherFactory factory_;
795 }; 727 };
796 728
797 TEST_F(WalletClientTest, WalletError) { 729 TEST_F(WalletClientTest, WalletError) {
798 EXPECT_CALL(delegate_, OnWalletError( 730 EXPECT_CALL(delegate_, OnWalletError(
799 WalletClient::SERVICE_UNAVAILABLE)).Times(1); 731 WalletClient::SERVICE_UNAVAILABLE)).Times(1);
800 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 732 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
801 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 733 delegate_.ExpectBaselineMetrics();
802 delegate_.ExpectWalletErrorMetric( 734 delegate_.ExpectWalletErrorMetric(
803 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); 735 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE);
804 736
805 std::vector<AutocheckoutStatistic> statistics; 737 std::vector<AutocheckoutStatistic> statistics;
806 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 738 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
807 GURL(kMerchantUrl), 739 GURL(kMerchantUrl),
808 statistics, 740 statistics,
809 "google_transaction_id"); 741 "google_transaction_id");
810 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 742 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
811 kSendAutocheckoutStatusOfSuccessValidRequest, 743 kSendAutocheckoutStatusOfSuccessValidRequest,
812 kErrorResponse); 744 kErrorResponse);
813 } 745 }
814 746
815 TEST_F(WalletClientTest, WalletErrorResponseMissing) { 747 TEST_F(WalletClientTest, WalletErrorResponseMissing) {
816 EXPECT_CALL(delegate_, OnWalletError( 748 EXPECT_CALL(delegate_, OnWalletError(
817 WalletClient::UNKNOWN_ERROR)).Times(1); 749 WalletClient::UNKNOWN_ERROR)).Times(1);
818 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 750 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
819 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 751 delegate_.ExpectBaselineMetrics();
820 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR); 752 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR);
821 753
822 std::vector<AutocheckoutStatistic> statistics; 754 std::vector<AutocheckoutStatistic> statistics;
823 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 755 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
824 GURL(kMerchantUrl), 756 GURL(kMerchantUrl),
825 statistics, 757 statistics,
826 "google_transaction_id"); 758 "google_transaction_id");
827 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 759 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
828 kSendAutocheckoutStatusOfSuccessValidRequest, 760 kSendAutocheckoutStatusOfSuccessValidRequest,
829 kErrorTypeMissingInResponse); 761 kErrorTypeMissingInResponse);
830 } 762 }
831 763
832 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) { 764 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) {
833 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); 765 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
834 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 766 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
835 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 767 delegate_.ExpectBaselineMetrics();
836 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); 768 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
837 769
838 std::vector<AutocheckoutStatistic> statistics; 770 std::vector<AutocheckoutStatistic> statistics;
839 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 771 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
840 GURL(kMerchantUrl), 772 GURL(kMerchantUrl),
841 statistics, 773 statistics,
842 "google_transaction_id"); 774 "google_transaction_id");
843 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, 775 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED,
844 kSendAutocheckoutStatusOfSuccessValidRequest, 776 kSendAutocheckoutStatusOfSuccessValidRequest,
845 std::string()); 777 std::string());
846 } 778 }
847 779
848 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { 780 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) {
849 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); 781 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
850 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 782 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
851 1); 783 1);
852 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 784 delegate_.ExpectBaselineMetrics();
853 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); 785 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
854 786
855 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 787 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
856 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, 788 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED,
857 kGetWalletItemsValidRequest, 789 kGetWalletItemsValidRequest,
858 std::string()); 790 std::string());
859 } 791 }
860 792
861 TEST_F(WalletClientTest, RequestError) { 793 TEST_F(WalletClientTest, RequestError) {
862 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); 794 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1);
863 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 795 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
864 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 796 delegate_.ExpectBaselineMetrics();
865 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST); 797 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST);
866 798
867 std::vector<AutocheckoutStatistic> statistics; 799 std::vector<AutocheckoutStatistic> statistics;
868 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 800 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
869 GURL(kMerchantUrl), 801 GURL(kMerchantUrl),
870 statistics, 802 statistics,
871 "google_transaction_id"); 803 "google_transaction_id");
872 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, 804 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST,
873 kSendAutocheckoutStatusOfSuccessValidRequest, 805 kSendAutocheckoutStatusOfSuccessValidRequest,
874 std::string()); 806 std::string());
875 } 807 }
876 808
877 TEST_F(WalletClientTest, GetFullWalletSuccess) { 809 TEST_F(WalletClientTest, GetFullWalletSuccess) {
878 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 810 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
879 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 811 delegate_.ExpectBaselineMetrics();
880 812
881 WalletClient::FullWalletRequest full_wallet_request( 813 WalletClient::FullWalletRequest full_wallet_request(
882 "instrument_id", 814 "instrument_id",
883 "shipping_address_id", 815 "shipping_address_id",
884 GURL(kMerchantUrl), 816 GURL(kMerchantUrl),
885 "google_transaction_id", 817 "google_transaction_id",
886 std::vector<WalletClient::RiskCapability>()); 818 std::vector<WalletClient::RiskCapability>());
887 wallet_client_->GetFullWallet(full_wallet_request); 819 wallet_client_->GetFullWallet(full_wallet_request);
888 820
889 DoEncryptionOrEscrowRequest(net::HTTP_OK, 821 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
890 "session_material|encrypted_one_time_pad"); 822 kGetFullWalletValidRequest,
891 823 kGetFullWalletValidResponse);
892 VerifyAndFinishRequest(net::HTTP_OK,
893 kGetFullWalletValidRequest,
894 kGetFullWalletValidResponse);
895 EXPECT_EQ(1U, delegate_.full_wallets_received()); 824 EXPECT_EQ(1U, delegate_.full_wallets_received());
896 } 825 }
897 826
898 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) { 827 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) {
899 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 828 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
900 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 829 delegate_.ExpectBaselineMetrics();
901 830
902 std::vector<WalletClient::RiskCapability> risk_capabilities; 831 std::vector<WalletClient::RiskCapability> risk_capabilities;
903 risk_capabilities.push_back(WalletClient::VERIFY_CVC); 832 risk_capabilities.push_back(WalletClient::VERIFY_CVC);
904 WalletClient::FullWalletRequest full_wallet_request( 833 WalletClient::FullWalletRequest full_wallet_request(
905 "instrument_id", 834 "instrument_id",
906 "shipping_address_id", 835 "shipping_address_id",
907 GURL(kMerchantUrl), 836 GURL(kMerchantUrl),
908 "google_transaction_id", 837 "google_transaction_id",
909 risk_capabilities); 838 risk_capabilities);
910 wallet_client_->GetFullWallet(full_wallet_request); 839 wallet_client_->GetFullWallet(full_wallet_request);
911 840
912 DoEncryptionOrEscrowRequest(net::HTTP_OK, 841 VerifyAndFinishFormEncodedRequest(
913 "session_material|encrypted_one_time_pad"); 842 net::HTTP_OK,
914 843 kGetFullWalletWithRiskCapabilitesValidRequest,
915 VerifyAndFinishRequest(net::HTTP_OK, 844 kGetFullWalletValidResponse);
916 kGetFullWalletWithRiskCapabilitesValidRequest,
917 kGetFullWalletValidResponse);
918 EXPECT_EQ(1U, delegate_.full_wallets_received()); 845 EXPECT_EQ(1U, delegate_.full_wallets_received());
919 } 846 }
920 847
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 848
961 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { 849 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) {
962 EXPECT_CALL(delegate_, 850 EXPECT_CALL(delegate_,
963 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 851 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
964 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); 852 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1);
965 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 853 delegate_.ExpectBaselineMetrics();
966 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 854 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
967 855
968 WalletClient::FullWalletRequest full_wallet_request( 856 WalletClient::FullWalletRequest full_wallet_request(
969 "instrument_id", 857 "instrument_id",
970 "shipping_address_id", 858 "shipping_address_id",
971 GURL(kMerchantUrl), 859 GURL(kMerchantUrl),
972 "google_transaction_id", 860 "google_transaction_id",
973 std::vector<WalletClient::RiskCapability>()); 861 std::vector<WalletClient::RiskCapability>());
974 wallet_client_->GetFullWallet(full_wallet_request); 862 wallet_client_->GetFullWallet(full_wallet_request);
975 863
976 DoEncryptionOrEscrowRequest(net::HTTP_OK, 864 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
977 "session_material|encrypted_one_time_pad"); 865 kGetFullWalletValidRequest,
978 866 kGetFullWalletInvalidResponse);
979 VerifyAndFinishRequest(net::HTTP_OK,
980 kGetFullWalletValidRequest,
981 kGetFullWalletInvalidResponse);
982 EXPECT_EQ(0U, delegate_.full_wallets_received()); 867 EXPECT_EQ(0U, delegate_.full_wallets_received());
983 } 868 }
984 869
985 TEST_F(WalletClientTest, AcceptLegalDocuments) { 870 TEST_F(WalletClientTest, AcceptLegalDocuments) {
986 EXPECT_CALL(delegate_, OnDidAcceptLegalDocuments()).Times(1); 871 EXPECT_CALL(delegate_, OnDidAcceptLegalDocuments()).Times(1);
987 delegate_.ExpectLogWalletApiCallDuration( 872 delegate_.ExpectLogWalletApiCallDuration(
988 AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS, 873 AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS,
989 1); 874 1);
990 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 875 delegate_.ExpectBaselineMetrics();
991 876
992 ScopedVector<WalletItems::LegalDocument> docs; 877 ScopedVector<WalletItems::LegalDocument> docs;
993 base::DictionaryValue document; 878 base::DictionaryValue document;
994 document.SetString("legal_document_id", "doc_id_1"); 879 document.SetString("legal_document_id", "doc_id_1");
995 document.SetString("display_name", "doc_1"); 880 document.SetString("display_name", "doc_1");
996 docs.push_back( 881 docs.push_back(
997 WalletItems::LegalDocument::CreateLegalDocument(document).release()); 882 WalletItems::LegalDocument::CreateLegalDocument(document).release());
998 document.SetString("legal_document_id", "doc_id_2"); 883 document.SetString("legal_document_id", "doc_id_2");
999 document.SetString("display_name", "doc_2"); 884 document.SetString("display_name", "doc_2");
1000 docs.push_back( 885 docs.push_back(
1001 WalletItems::LegalDocument::CreateLegalDocument(document).release()); 886 WalletItems::LegalDocument::CreateLegalDocument(document).release());
1002 docs.push_back( 887 docs.push_back(
1003 WalletItems::LegalDocument::CreatePrivacyPolicyDocument().release()); 888 WalletItems::LegalDocument::CreatePrivacyPolicyDocument().release());
1004 wallet_client_->AcceptLegalDocuments(docs.get(), 889 wallet_client_->AcceptLegalDocuments(docs.get(),
1005 kGoogleTransactionId, 890 kGoogleTransactionId,
1006 GURL(kMerchantUrl)); 891 GURL(kMerchantUrl));
1007 VerifyAndFinishRequest(net::HTTP_OK, 892 VerifyAndFinishRequest(net::HTTP_OK,
1008 kAcceptLegalDocumentsValidRequest, 893 kAcceptLegalDocumentsValidRequest,
1009 ")}'"); // Invalid JSON. Should be ignored. 894 ")}'"); // Invalid JSON. Should be ignored.
1010 } 895 }
1011 896
1012 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) { 897 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) {
1013 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(true)).Times(1); 898 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(true)).Times(1);
1014 delegate_.ExpectLogWalletApiCallDuration( 899 delegate_.ExpectLogWalletApiCallDuration(
1015 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 900 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1016 1); 901 1);
1017 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 902 delegate_.ExpectBaselineMetrics();
1018 903
1019 wallet_client_->AuthenticateInstrument("instrument_id", 904 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1020 "cvv",
1021 "obfuscated_gaia_id");
1022 905
1023 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 906 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1024 907 kAuthenticateInstrumentValidRequest,
1025 VerifyAndFinishRequest(net::HTTP_OK, 908 kAuthenticateInstrumentSuccessResponse);
1026 kAuthenticateInstrumentValidRequest,
1027 kAuthenticateInstrumentSuccessResponse);
1028 } 909 }
1029 910
1030 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) { 911 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) {
1031 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(false)).Times(1); 912 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(false)).Times(1);
1032 delegate_.ExpectLogWalletApiCallDuration( 913 delegate_.ExpectLogWalletApiCallDuration(
1033 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 914 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1034 1); 915 1);
1035 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 916 delegate_.ExpectBaselineMetrics();
1036 917
1037 wallet_client_->AuthenticateInstrument("instrument_id", 918 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1038 "cvv",
1039 "obfuscated_gaia_id");
1040 919
1041 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 920 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1042 921 kAuthenticateInstrumentValidRequest,
1043 VerifyAndFinishRequest(net::HTTP_OK, 922 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 } 923 }
1078 924
1079 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) { 925 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) {
1080 EXPECT_CALL(delegate_, 926 EXPECT_CALL(delegate_,
1081 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 927 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1082 delegate_.ExpectLogWalletApiCallDuration( 928 delegate_.ExpectLogWalletApiCallDuration(
1083 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 929 AutofillMetrics::AUTHENTICATE_INSTRUMENT,
1084 1); 930 1);
1085 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 931 delegate_.ExpectBaselineMetrics();
1086 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 932 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1087 933
1088 wallet_client_->AuthenticateInstrument("instrument_id", 934 wallet_client_->AuthenticateInstrument("instrument_id", "cvv");
1089 "cvv",
1090 "obfuscated_gaia_id");
1091 935
1092 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 936 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1093 937 kAuthenticateInstrumentValidRequest,
1094 VerifyAndFinishRequest(net::HTTP_OK, 938 kSaveInvalidResponse);
1095 kAuthenticateInstrumentValidRequest,
1096 kSaveInvalidResponse);
1097 } 939 }
1098 940
1099 // TODO(ahutter): Add failure tests for GetWalletItems. 941 // TODO(ahutter): Add failure tests for GetWalletItems.
1100 942
1101 TEST_F(WalletClientTest, GetWalletItems) { 943 TEST_F(WalletClientTest, GetWalletItems) {
1102 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 944 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1103 1); 945 1);
1104 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 946 delegate_.ExpectBaselineMetrics();
1105 947
1106 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 948 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1107 949
1108 VerifyAndFinishRequest(net::HTTP_OK, 950 VerifyAndFinishRequest(net::HTTP_OK,
1109 kGetWalletItemsValidRequest, 951 kGetWalletItemsValidRequest,
1110 kGetWalletItemsValidResponse); 952 kGetWalletItemsValidResponse);
1111 EXPECT_EQ(1U, delegate_.wallet_items_received()); 953 EXPECT_EQ(1U, delegate_.wallet_items_received());
1112 } 954 }
1113 955
1114 TEST_F(WalletClientTest, SaveAddressSucceeded) { 956 TEST_F(WalletClientTest, SaveAddressSucceeded) {
1115 EXPECT_CALL(delegate_, 957 EXPECT_CALL(delegate_,
1116 OnDidSaveAddress("saved_address_id", 958 OnDidSaveToWallet(std::string(),
1117 std::vector<RequiredAction>(), 959 "saved_address_id",
1118 std::vector<FormFieldError>())).Times(1); 960 std::vector<RequiredAction>(),
1119 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 961 std::vector<FormFieldError>())).Times(1);
1120 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 962 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
963 delegate_.ExpectBaselineMetrics();
1121 964
1122 scoped_ptr<Address> address = GetTestSaveableAddress(); 965 scoped_ptr<Address> address = GetTestSaveableAddress();
1123 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 966 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1124 VerifyAndFinishRequest(net::HTTP_OK, 967 address.Pass(),
1125 kSaveAddressValidRequest, 968 GURL(kMerchantUrl));
1126 kSaveAddressValidResponse); 969 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
970 kSaveAddressValidRequest,
971 kSaveAddressValidResponse);
1127 } 972 }
1128 973
1129 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) { 974 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) {
1130 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 975 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1131 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 976 delegate_.ExpectBaselineMetrics();
1132 delegate_.ExpectWalletRequiredActionMetric( 977 delegate_.ExpectWalletRequiredActionMetric(
1133 AutofillMetrics::REQUIRE_PHONE_NUMBER); 978 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1134 delegate_.ExpectWalletRequiredActionMetric( 979 delegate_.ExpectWalletRequiredActionMetric(
1135 AutofillMetrics::INVALID_FORM_FIELD); 980 AutofillMetrics::INVALID_FORM_FIELD);
1136 981
1137 std::vector<RequiredAction> required_actions; 982 std::vector<RequiredAction> required_actions;
1138 required_actions.push_back(REQUIRE_PHONE_NUMBER); 983 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1139 required_actions.push_back(INVALID_FORM_FIELD); 984 required_actions.push_back(INVALID_FORM_FIELD);
1140 985
1141 std::vector<FormFieldError> form_errors; 986 std::vector<FormFieldError> form_errors;
1142 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 987 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1143 FormFieldError::SHIPPING_ADDRESS)); 988 FormFieldError::SHIPPING_ADDRESS));
1144 989
1145 EXPECT_CALL(delegate_, 990 EXPECT_CALL(delegate_,
1146 OnDidSaveAddress(std::string(), 991 OnDidSaveToWallet(std::string(),
1147 required_actions, 992 std::string(),
1148 form_errors)).Times(1); 993 required_actions,
994 form_errors)).Times(1);
1149 995
1150 scoped_ptr<Address> address = GetTestSaveableAddress(); 996 scoped_ptr<Address> address = GetTestSaveableAddress();
1151 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 997 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1152 VerifyAndFinishRequest(net::HTTP_OK, 998 address.Pass(),
1153 kSaveAddressValidRequest, 999 GURL(kMerchantUrl));
1154 kSaveAddressWithRequiredActionsValidResponse); 1000 VerifyAndFinishFormEncodedRequest(
1001 net::HTTP_OK,
1002 kSaveAddressValidRequest,
1003 kSaveAddressWithRequiredActionsValidResponse);
1155 } 1004 }
1156 1005
1157 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) { 1006 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) {
1158 EXPECT_CALL(delegate_, 1007 EXPECT_CALL(delegate_,
1159 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1008 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1160 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 1009 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1161 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1010 delegate_.ExpectBaselineMetrics();
1162 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1011 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1163 1012
1164 scoped_ptr<Address> address = GetTestSaveableAddress(); 1013 scoped_ptr<Address> address = GetTestSaveableAddress();
1165 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 1014 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1166 VerifyAndFinishRequest(net::HTTP_OK, 1015 address.Pass(),
1167 kSaveAddressValidRequest, 1016 GURL(kMerchantUrl));
1168 kSaveWithInvalidRequiredActionsResponse); 1017 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1018 kSaveAddressValidRequest,
1019 kSaveWithInvalidRequiredActionsResponse);
1169 } 1020 }
1170 1021
1171 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { 1022 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) {
1172 EXPECT_CALL(delegate_, 1023 EXPECT_CALL(delegate_,
1173 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1024 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1174 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_ADDRESS, 1); 1025 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1175 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1026 delegate_.ExpectBaselineMetrics();
1176 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1027 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1177 1028
1178 scoped_ptr<Address> address = GetTestSaveableAddress(); 1029 scoped_ptr<Address> address = GetTestSaveableAddress();
1179 wallet_client_->SaveAddress(*address, GURL(kMerchantUrl)); 1030 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1180 VerifyAndFinishRequest(net::HTTP_OK, 1031 address.Pass(),
1181 kSaveAddressValidRequest, 1032 GURL(kMerchantUrl));
1182 kSaveInvalidResponse); 1033 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1034 kSaveAddressValidRequest,
1035 kSaveInvalidResponse);
1183 } 1036 }
1184 1037
1185 TEST_F(WalletClientTest, SaveInstrumentSucceeded) { 1038 TEST_F(WalletClientTest, SaveInstrumentSucceeded) {
1186 EXPECT_CALL(delegate_, 1039 EXPECT_CALL(delegate_,
1187 OnDidSaveInstrument("instrument_id", 1040 OnDidSaveToWallet("instrument_id",
1188 std::vector<RequiredAction>(), 1041 std::string(),
1189 std::vector<FormFieldError>())).Times(1); 1042 std::vector<RequiredAction>(),
1190 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1043 std::vector<FormFieldError>())).Times(1);
1191 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1044 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1045 delegate_.ExpectBaselineMetrics();
1192 1046
1193 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1047 scoped_ptr<Instrument> instrument = GetTestInstrument();
1194 wallet_client_->SaveInstrument(*instrument, 1048 wallet_client_->SaveToWallet(instrument.Pass(),
1195 "obfuscated_gaia_id", 1049 scoped_ptr<Address>(),
1196 GURL(kMerchantUrl)); 1050 GURL(kMerchantUrl));
1197 1051
1198 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1052 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1199 1053 kSaveInstrumentValidRequest,
1200 VerifyAndFinishRequest(net::HTTP_OK, 1054 kSaveInstrumentValidResponse);
1201 kSaveInstrumentValidRequest,
1202 kSaveInstrumentValidResponse);
1203 } 1055 }
1204 1056
1205 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) { 1057 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) {
1206 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1058 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1207 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1059 delegate_.ExpectBaselineMetrics();
1208 delegate_.ExpectWalletRequiredActionMetric( 1060 delegate_.ExpectWalletRequiredActionMetric(
1209 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1061 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1210 delegate_.ExpectWalletRequiredActionMetric( 1062 delegate_.ExpectWalletRequiredActionMetric(
1211 AutofillMetrics::INVALID_FORM_FIELD); 1063 AutofillMetrics::INVALID_FORM_FIELD);
1212 1064
1213 std::vector<RequiredAction> required_actions; 1065 std::vector<RequiredAction> required_actions;
1214 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1066 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1215 required_actions.push_back(INVALID_FORM_FIELD); 1067 required_actions.push_back(INVALID_FORM_FIELD);
1216 1068
1217 std::vector<FormFieldError> form_errors; 1069 std::vector<FormFieldError> form_errors;
1218 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1070 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1219 FormFieldError::SHIPPING_ADDRESS)); 1071 FormFieldError::SHIPPING_ADDRESS));
1220 1072
1221 EXPECT_CALL(delegate_, 1073 EXPECT_CALL(delegate_,
1222 OnDidSaveInstrument(std::string(), 1074 OnDidSaveToWallet(std::string(),
1223 required_actions, 1075 std::string(),
1224 form_errors)).Times(1); 1076 required_actions,
1077 form_errors)).Times(1);
1225 1078
1226 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1079 scoped_ptr<Instrument> instrument = GetTestInstrument();
1227 wallet_client_->SaveInstrument(*instrument, 1080 wallet_client_->SaveToWallet(instrument.Pass(),
1228 "obfuscated_gaia_id", 1081 scoped_ptr<Address>(),
1229 GURL(kMerchantUrl)); 1082 GURL(kMerchantUrl));
1230 1083
1231 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1084 VerifyAndFinishFormEncodedRequest(
1232 1085 net::HTTP_OK,
1233 VerifyAndFinishRequest(net::HTTP_OK, 1086 kSaveInstrumentValidRequest,
1234 kSaveInstrumentValidRequest, 1087 kSaveInstrumentWithRequiredActionsValidResponse);
1235 kSaveInstrumentWithRequiredActionsValidResponse);
1236 } 1088 }
1237 1089
1238 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) { 1090 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) {
1239 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1091 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1240 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1092 delegate_.ExpectBaselineMetrics();
1241 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1093 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1242 1094
1243 EXPECT_CALL(delegate_, 1095 EXPECT_CALL(delegate_,
1244 OnWalletError(WalletClient::MALFORMED_RESPONSE)); 1096 OnWalletError(WalletClient::MALFORMED_RESPONSE));
1245 1097
1246 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1098 scoped_ptr<Instrument> instrument = GetTestInstrument();
1247 wallet_client_->SaveInstrument(*instrument, 1099 wallet_client_->SaveToWallet(instrument.Pass(),
1248 "obfuscated_gaia_id", 1100 scoped_ptr<Address>(),
1249 GURL(kMerchantUrl)); 1101 GURL(kMerchantUrl));
1250 1102
1251 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1103 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1252 1104 kSaveInstrumentValidRequest,
1253 VerifyAndFinishRequest(net::HTTP_OK, 1105 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 } 1106 }
1286 1107
1287 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) { 1108 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) {
1288 EXPECT_CALL(delegate_, 1109 EXPECT_CALL(delegate_,
1289 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1110 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1290 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_INSTRUMENT, 1); 1111 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1291 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1112 delegate_.ExpectBaselineMetrics();
1292 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1113 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1293 1114
1294 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1115 scoped_ptr<Instrument> instrument = GetTestInstrument();
1295 wallet_client_->SaveInstrument(*instrument, 1116 wallet_client_->SaveToWallet(instrument.Pass(),
1296 "obfuscated_gaia_id", 1117 scoped_ptr<Address>(),
1297 GURL(kMerchantUrl)); 1118 GURL(kMerchantUrl));
1298 1119
1299 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1120 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1300 1121 kSaveInstrumentValidRequest,
1301 VerifyAndFinishRequest(net::HTTP_OK, 1122 kSaveInvalidResponse);
1302 kSaveInstrumentValidRequest,
1303 kSaveInvalidResponse);
1304 } 1123 }
1305 1124
1306 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { 1125 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) {
1307 EXPECT_CALL(delegate_, 1126 EXPECT_CALL(delegate_,
1308 OnDidSaveInstrumentAndAddress( 1127 OnDidSaveToWallet("saved_instrument_id",
1309 "saved_instrument_id", 1128 "saved_address_id",
1310 "saved_address_id", 1129 std::vector<RequiredAction>(),
1311 std::vector<RequiredAction>(), 1130 std::vector<FormFieldError>())).Times(1);
1312 std::vector<FormFieldError>())).Times(1);
1313 delegate_.ExpectLogWalletApiCallDuration( 1131 delegate_.ExpectLogWalletApiCallDuration(
1314 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1132 AutofillMetrics::SAVE_TO_WALLET,
1315 1); 1133 1);
1316 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1134 delegate_.ExpectBaselineMetrics();
1317 1135
1318 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1136 scoped_ptr<Instrument> instrument = GetTestInstrument();
1319 scoped_ptr<Address> address = GetTestSaveableAddress(); 1137 scoped_ptr<Address> address = GetTestSaveableAddress();
1320 wallet_client_->SaveInstrumentAndAddress(*instrument, 1138 wallet_client_->SaveToWallet(instrument.Pass(),
1321 *address, 1139 address.Pass(),
1322 "obfuscated_gaia_id", 1140 GURL(kMerchantUrl));
1323 GURL(kMerchantUrl));
1324 1141
1325 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1142 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1326 VerifyAndFinishRequest(net::HTTP_OK, 1143 kSaveInstrumentAndAddressValidRequest,
1327 kSaveInstrumentAndAddressValidRequest, 1144 kSaveInstrumentAndAddressValidResponse);
1328 kSaveInstrumentAndAddressValidResponse);
1329 } 1145 }
1330 1146
1331 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) { 1147 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) {
1332 delegate_.ExpectLogWalletApiCallDuration( 1148 delegate_.ExpectLogWalletApiCallDuration(
1333 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1149 AutofillMetrics::SAVE_TO_WALLET,
1334 1); 1150 1);
1335 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1151 delegate_.ExpectBaselineMetrics();
1336 delegate_.ExpectWalletRequiredActionMetric( 1152 delegate_.ExpectWalletRequiredActionMetric(
1337 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1153 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1338 delegate_.ExpectWalletRequiredActionMetric( 1154 delegate_.ExpectWalletRequiredActionMetric(
1339 AutofillMetrics::INVALID_FORM_FIELD); 1155 AutofillMetrics::INVALID_FORM_FIELD);
1340 1156
1341 std::vector<RequiredAction> required_actions; 1157 std::vector<RequiredAction> required_actions;
1342 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1158 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1343 required_actions.push_back(INVALID_FORM_FIELD); 1159 required_actions.push_back(INVALID_FORM_FIELD);
1344 1160
1345 std::vector<FormFieldError> form_errors; 1161 std::vector<FormFieldError> form_errors;
1346 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1162 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1347 FormFieldError::SHIPPING_ADDRESS)); 1163 FormFieldError::SHIPPING_ADDRESS));
1348 1164
1349 EXPECT_CALL(delegate_, 1165 EXPECT_CALL(delegate_,
1350 OnDidSaveInstrumentAndAddress( 1166 OnDidSaveToWallet(std::string(),
1351 std::string(), 1167 std::string(),
1352 std::string(), 1168 required_actions,
1353 required_actions, 1169 form_errors)).Times(1);
1354 form_errors)).Times(1);
1355 1170
1356 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1171 scoped_ptr<Instrument> instrument = GetTestInstrument();
1357 scoped_ptr<Address> address = GetTestSaveableAddress(); 1172 scoped_ptr<Address> address = GetTestSaveableAddress();
1358 wallet_client_->SaveInstrumentAndAddress(*instrument, 1173 wallet_client_->SaveToWallet(instrument.Pass(),
1359 *address, 1174 address.Pass(),
1360 "obfuscated_gaia_id", 1175 GURL(kMerchantUrl));
1361 GURL(kMerchantUrl));
1362 1176
1363 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1177 VerifyAndFinishFormEncodedRequest(
1364 VerifyAndFinishRequest(
1365 net::HTTP_OK, 1178 net::HTTP_OK,
1366 kSaveInstrumentAndAddressValidRequest, 1179 kSaveInstrumentAndAddressValidRequest,
1367 kSaveInstrumentAndAddressWithRequiredActionsValidResponse); 1180 kSaveInstrumentAndAddressWithRequiredActionsValidResponse);
1368 } 1181 }
1369 1182
1370 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) { 1183 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) {
1371 EXPECT_CALL(delegate_, 1184 EXPECT_CALL(delegate_,
1372 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1185 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1373 delegate_.ExpectLogWalletApiCallDuration( 1186 delegate_.ExpectLogWalletApiCallDuration(
1374 AutofillMetrics::SAVE_INSTRUMENT_AND_ADDRESS, 1187 AutofillMetrics::SAVE_TO_WALLET,
1375 1); 1188 1);
1376 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1189 delegate_.ExpectBaselineMetrics();
1377 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1190 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1378 1191
1379 scoped_ptr<Instrument> instrument = GetTestInstrument(); 1192 scoped_ptr<Instrument> instrument = GetTestInstrument();
1380 scoped_ptr<Address> address = GetTestSaveableAddress(); 1193 scoped_ptr<Address> address = GetTestSaveableAddress();
1381 wallet_client_->SaveInstrumentAndAddress(*instrument, 1194 wallet_client_->SaveToWallet(instrument.Pass(),
1382 *address, 1195 address.Pass(),
1383 "obfuscated_gaia_id", 1196 GURL(kMerchantUrl));
1384 GURL(kMerchantUrl));
1385 1197
1386 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1198 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1387 1199 kSaveInstrumentAndAddressValidRequest,
1388 VerifyAndFinishRequest(net::HTTP_OK, 1200 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 } 1201 }
1475 1202
1476 TEST_F(WalletClientTest, UpdateAddressSucceeded) { 1203 TEST_F(WalletClientTest, UpdateAddressSucceeded) {
1477 EXPECT_CALL(delegate_, 1204 EXPECT_CALL(delegate_,
1478 OnDidUpdateAddress("shipping_address_id", 1205 OnDidSaveToWallet(std::string(),
1479 std::vector<RequiredAction>(), 1206 "shipping_address_id",
1480 std::vector<FormFieldError>())).Times(1); 1207 std::vector<RequiredAction>(),
1481 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1208 std::vector<FormFieldError>())).Times(1);
1482 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1209 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1210 delegate_.ExpectBaselineMetrics();
1483 1211
1484 scoped_ptr<Address> address = GetTestShippingAddress(); 1212 scoped_ptr<Address> address = GetTestShippingAddress();
1485 address->set_object_id("shipping_address_id"); 1213 address->set_object_id("shipping_address_id");
1486 1214
1487 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1215 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1488 VerifyAndFinishRequest(net::HTTP_OK, 1216 address.Pass(),
1489 kUpdateAddressValidRequest, 1217 GURL(kMerchantUrl));
1490 kUpdateAddressValidResponse); 1218 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1219 kUpdateAddressValidRequest,
1220 kUpdateAddressValidResponse);
1491 } 1221 }
1492 1222
1493 TEST_F(WalletClientTest, UpdateAddressWithRequiredActionsSucceeded) { 1223 TEST_F(WalletClientTest, UpdateAddressWithRequiredActionsSucceeded) {
1494 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1224 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1495 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1225 delegate_.ExpectBaselineMetrics();
1496 delegate_.ExpectWalletRequiredActionMetric( 1226 delegate_.ExpectWalletRequiredActionMetric(
1497 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1227 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1498 delegate_.ExpectWalletRequiredActionMetric( 1228 delegate_.ExpectWalletRequiredActionMetric(
1499 AutofillMetrics::INVALID_FORM_FIELD); 1229 AutofillMetrics::INVALID_FORM_FIELD);
1500 1230
1501 std::vector<RequiredAction> required_actions; 1231 std::vector<RequiredAction> required_actions;
1502 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1232 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1503 required_actions.push_back(INVALID_FORM_FIELD); 1233 required_actions.push_back(INVALID_FORM_FIELD);
1504 1234
1505 std::vector<FormFieldError> form_errors; 1235 std::vector<FormFieldError> form_errors;
1506 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1236 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1507 FormFieldError::SHIPPING_ADDRESS)); 1237 FormFieldError::SHIPPING_ADDRESS));
1508 1238
1509 EXPECT_CALL(delegate_, OnDidUpdateAddress(std::string(), 1239 EXPECT_CALL(delegate_, OnDidSaveToWallet(std::string(),
1510 required_actions, 1240 std::string(),
1511 form_errors)).Times(1); 1241 required_actions,
1242 form_errors)).Times(1);
1512 1243
1513 scoped_ptr<Address> address = GetTestShippingAddress(); 1244 scoped_ptr<Address> address = GetTestShippingAddress();
1514 address->set_object_id("shipping_address_id"); 1245 address->set_object_id("shipping_address_id");
1515 1246
1516 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1247 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1517 VerifyAndFinishRequest(net::HTTP_OK, 1248 address.Pass(),
1518 kUpdateAddressValidRequest, 1249 GURL(kMerchantUrl));
1519 kUpdateWithRequiredActionsValidResponse); 1250 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1251 kUpdateAddressValidRequest,
1252 kUpdateWithRequiredActionsValidResponse);
1520 } 1253 }
1521 1254
1522 TEST_F(WalletClientTest, UpdateAddressFailedInvalidRequiredAction) { 1255 TEST_F(WalletClientTest, UpdateAddressFailedInvalidRequiredAction) {
1523 EXPECT_CALL(delegate_, 1256 EXPECT_CALL(delegate_,
1524 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1257 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1525 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1258 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1526 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1259 delegate_.ExpectBaselineMetrics();
1527 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1260 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1528 1261
1529 scoped_ptr<Address> address = GetTestShippingAddress(); 1262 scoped_ptr<Address> address = GetTestShippingAddress();
1530 address->set_object_id("shipping_address_id"); 1263 address->set_object_id("shipping_address_id");
1531 1264
1532 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1265 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1533 VerifyAndFinishRequest(net::HTTP_OK, 1266 address.Pass(),
1534 kUpdateAddressValidRequest, 1267 GURL(kMerchantUrl));
1535 kSaveWithInvalidRequiredActionsResponse); 1268 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1269 kUpdateAddressValidRequest,
1270 kSaveWithInvalidRequiredActionsResponse);
1536 } 1271 }
1537 1272
1538 TEST_F(WalletClientTest, UpdateAddressMalformedResponse) { 1273 TEST_F(WalletClientTest, UpdateAddressMalformedResponse) {
1539 EXPECT_CALL(delegate_, 1274 EXPECT_CALL(delegate_,
1540 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1275 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1541 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_ADDRESS, 1); 1276 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1);
1542 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1277 delegate_.ExpectBaselineMetrics();
1543 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1278 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1544 1279
1545 scoped_ptr<Address> address = GetTestShippingAddress(); 1280 scoped_ptr<Address> address = GetTestShippingAddress();
1546 address->set_object_id("shipping_address_id"); 1281 address->set_object_id("shipping_address_id");
1547 1282
1548 wallet_client_->UpdateAddress(*address, GURL(kMerchantUrl)); 1283 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(),
1549 VerifyAndFinishRequest(net::HTTP_OK, 1284 address.Pass(),
1550 kUpdateAddressValidRequest, 1285 GURL(kMerchantUrl));
1551 kUpdateMalformedResponse); 1286 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1287 kUpdateAddressValidRequest,
1288 kUpdateMalformedResponse);
1552 } 1289 }
1553 1290
1554 TEST_F(WalletClientTest, UpdateInstrumentAddressSucceeded) { 1291 TEST_F(WalletClientTest, UpdateInstrumentAddressSucceeded) {
1555 EXPECT_CALL(delegate_, 1292 EXPECT_CALL(delegate_,
1556 OnDidUpdateInstrument("instrument_id", 1293 OnDidSaveToWallet("instrument_id",
1557 std::vector<RequiredAction>(), 1294 std::string(),
1558 std::vector<FormFieldError>())).Times(1); 1295 std::vector<RequiredAction>(),
1559 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1296 std::vector<FormFieldError>())).Times(1);
1297 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1560 1); 1298 1);
1561 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1299 delegate_.ExpectBaselineMetrics();
1562 1300
1563 WalletClient::UpdateInstrumentRequest update_instrument_request( 1301 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1564 "instrument_id", 1302 scoped_ptr<Address>(),
1565 GURL(kMerchantUrl)); 1303 GURL(kMerchantUrl));
1566 1304
1567 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1305 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1568 1306 kUpdateInstrumentAddressValidRequest,
1569 VerifyAndFinishRequest(net::HTTP_OK, 1307 kUpdateInstrumentValidResponse);
1570 kUpdateInstrumentAddressValidRequest,
1571 kUpdateInstrumentValidResponse);
1572 } 1308 }
1573 1309
1574 TEST_F(WalletClientTest, UpdateInstrumentExpirationDateSuceeded) { 1310 TEST_F(WalletClientTest, UpdateInstrumentExpirationDateSuceeded) {
1575 EXPECT_CALL(delegate_, 1311 EXPECT_CALL(delegate_,
1576 OnDidUpdateInstrument("instrument_id", 1312 OnDidSaveToWallet("instrument_id",
1577 std::vector<RequiredAction>(), 1313 std::string(),
1578 std::vector<FormFieldError>())).Times(1); 1314 std::vector<RequiredAction>(),
1579 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1315 std::vector<FormFieldError>())).Times(1);
1316 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1580 1); 1317 1);
1581 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1318 delegate_.ExpectBaselineMetrics();
1582 1319
1583 WalletClient::UpdateInstrumentRequest update_instrument_request( 1320 wallet_client_->SaveToWallet(GetTestExpirationDateChangeInstrument(),
1584 "instrument_id", 1321 scoped_ptr<Address>(),
1585 GURL(kMerchantUrl)); 1322 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 1323
1594 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1324 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1595 1325 kUpdateInstrumentExpirationDateValidRequest,
1596 VerifyAndFinishRequest(net::HTTP_OK, 1326 kUpdateInstrumentValidResponse);
1597 kUpdateInstrumentExpirationDateValidRequest,
1598 kUpdateInstrumentValidResponse);
1599 } 1327 }
1600 1328
1601 TEST_F(WalletClientTest, UpdateInstrumentAddressWithNameChangeSucceeded) { 1329 TEST_F(WalletClientTest, UpdateInstrumentAddressWithNameChangeSucceeded) {
1602 EXPECT_CALL(delegate_, 1330 EXPECT_CALL(delegate_,
1603 OnDidUpdateInstrument("instrument_id", 1331 OnDidSaveToWallet("instrument_id",
1604 std::vector<RequiredAction>(), 1332 std::string(),
1605 std::vector<FormFieldError>())).Times(1); 1333 std::vector<RequiredAction>(),
1606 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1334 std::vector<FormFieldError>())).Times(1);
1335 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1607 1); 1336 1);
1608 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1337 delegate_.ExpectBaselineMetrics();
1609 1338
1610 WalletClient::UpdateInstrumentRequest update_instrument_request( 1339 wallet_client_->SaveToWallet(GetTestAddressNameChangeInstrument(),
1611 "instrument_id", 1340 scoped_ptr<Address>(),
1612 GURL(kMerchantUrl)); 1341 GURL(kMerchantUrl));
1613 update_instrument_request.card_verification_number =
1614 "card_verification_number";
1615 update_instrument_request.obfuscated_gaia_id = "obfuscated_gaia_id";
1616 1342
1617 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1343 VerifyAndFinishFormEncodedRequest(
1618 1344 net::HTTP_OK,
1619 DoEncryptionOrEscrowRequest(net::HTTP_OK, "escrow_handle"); 1345 kUpdateInstrumentAddressWithNameChangeValidRequest,
1620 1346 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 } 1347 }
1651 1348
1652 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) { 1349 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) {
1653 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1350 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1654 1); 1351 1);
1655 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1352 delegate_.ExpectBaselineMetrics();
1656 delegate_.ExpectWalletRequiredActionMetric( 1353 delegate_.ExpectWalletRequiredActionMetric(
1657 AutofillMetrics::REQUIRE_PHONE_NUMBER); 1354 AutofillMetrics::REQUIRE_PHONE_NUMBER);
1658 delegate_.ExpectWalletRequiredActionMetric( 1355 delegate_.ExpectWalletRequiredActionMetric(
1659 AutofillMetrics::INVALID_FORM_FIELD); 1356 AutofillMetrics::INVALID_FORM_FIELD);
1660 1357
1661 std::vector<RequiredAction> required_actions; 1358 std::vector<RequiredAction> required_actions;
1662 required_actions.push_back(REQUIRE_PHONE_NUMBER); 1359 required_actions.push_back(REQUIRE_PHONE_NUMBER);
1663 required_actions.push_back(INVALID_FORM_FIELD); 1360 required_actions.push_back(INVALID_FORM_FIELD);
1664 1361
1665 std::vector<FormFieldError> form_errors; 1362 std::vector<FormFieldError> form_errors;
1666 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, 1363 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE,
1667 FormFieldError::SHIPPING_ADDRESS)); 1364 FormFieldError::SHIPPING_ADDRESS));
1668 1365
1669 EXPECT_CALL(delegate_, 1366 EXPECT_CALL(delegate_,
1670 OnDidUpdateInstrument(std::string(), 1367 OnDidSaveToWallet(std::string(),
1671 required_actions, 1368 std::string(),
1672 form_errors)).Times(1); 1369 required_actions,
1370 form_errors)).Times(1);
1673 1371
1674 WalletClient::UpdateInstrumentRequest update_instrument_request( 1372 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1675 "instrument_id", 1373 scoped_ptr<Address>(),
1676 GURL(kMerchantUrl)); 1374 GURL(kMerchantUrl));
1677 1375
1678 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1376 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1679 1377 kUpdateInstrumentAddressValidRequest,
1680 VerifyAndFinishRequest(net::HTTP_OK, 1378 kUpdateWithRequiredActionsValidResponse);
1681 kUpdateInstrumentAddressValidRequest,
1682 kUpdateWithRequiredActionsValidResponse);
1683 } 1379 }
1684 1380
1685 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) { 1381 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) {
1686 EXPECT_CALL(delegate_, 1382 EXPECT_CALL(delegate_,
1687 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1383 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1688 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1384 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1689 1); 1385 1);
1690 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1386 delegate_.ExpectBaselineMetrics();
1691 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1387 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1692 1388
1693 WalletClient::UpdateInstrumentRequest update_instrument_request( 1389 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1694 "instrument_id", 1390 scoped_ptr<Address>(),
1695 GURL(kMerchantUrl)); 1391 GURL(kMerchantUrl));
1696 1392
1697 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1393 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1698 1394 kUpdateInstrumentAddressValidRequest,
1699 VerifyAndFinishRequest(net::HTTP_OK, 1395 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 } 1396 }
1722 1397
1723 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) { 1398 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) {
1724 EXPECT_CALL(delegate_, 1399 EXPECT_CALL(delegate_,
1725 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); 1400 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1);
1726 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::UPDATE_INSTRUMENT, 1401 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET,
1727 1); 1402 1);
1728 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1403 delegate_.ExpectBaselineMetrics();
1729 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); 1404 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE);
1730 1405
1731 WalletClient::UpdateInstrumentRequest update_instrument_request( 1406 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(),
1732 "instrument_id", 1407 scoped_ptr<Address>(),
1733 GURL(kMerchantUrl)); 1408 GURL(kMerchantUrl));
1734 1409
1735 wallet_client_->UpdateInstrument(update_instrument_request, GetTestAddress()); 1410 VerifyAndFinishFormEncodedRequest(net::HTTP_OK,
1736 1411 kUpdateInstrumentAddressValidRequest,
1737 VerifyAndFinishRequest(net::HTTP_OK, 1412 kUpdateMalformedResponse);
1738 kUpdateInstrumentAddressValidRequest,
1739 kUpdateMalformedResponse);
1740 } 1413 }
1741 1414
1742 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { 1415 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) {
1743 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 1416 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
1744 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1417 delegate_.ExpectBaselineMetrics();
1745 1418
1746 AutocheckoutStatistic statistic; 1419 AutocheckoutStatistic statistic;
1747 statistic.page_number = 1; 1420 statistic.page_number = 1;
1748 statistic.steps.push_back(AUTOCHECKOUT_STEP_SHIPPING); 1421 statistic.steps.push_back(AUTOCHECKOUT_STEP_SHIPPING);
1749 statistic.time_taken = base::TimeDelta::FromMilliseconds(100); 1422 statistic.time_taken = base::TimeDelta::FromMilliseconds(100);
1750 std::vector<AutocheckoutStatistic> statistics; 1423 std::vector<AutocheckoutStatistic> statistics;
1751 statistics.push_back(statistic); 1424 statistics.push_back(statistic);
1752 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, 1425 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS,
1753 GURL(kMerchantUrl), 1426 GURL(kMerchantUrl),
1754 statistics, 1427 statistics,
1755 "google_transaction_id"); 1428 "google_transaction_id");
1756 VerifyAndFinishRequest(net::HTTP_OK, 1429 VerifyAndFinishRequest(net::HTTP_OK,
1757 kSendAutocheckoutStatusWithStatisticsValidRequest, 1430 kSendAutocheckoutStatusWithStatisticsValidRequest,
1758 ")]}"); // Invalid JSON. Should be ignored. 1431 ")]}"); // Invalid JSON. Should be ignored.
1759 } 1432 }
1760 1433
1761 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { 1434 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) {
1762 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); 1435 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1);
1763 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1436 delegate_.ExpectBaselineMetrics();
1764 1437
1765 std::vector<AutocheckoutStatistic> statistics; 1438 std::vector<AutocheckoutStatistic> statistics;
1766 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, 1439 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED,
1767 GURL(kMerchantUrl), 1440 GURL(kMerchantUrl),
1768 statistics, 1441 statistics,
1769 "google_transaction_id"); 1442 "google_transaction_id");
1770 VerifyAndFinishRequest(net::HTTP_OK, 1443 VerifyAndFinishRequest(net::HTTP_OK,
1771 kSendAutocheckoutStatusOfFailureValidRequest, 1444 kSendAutocheckoutStatusOfFailureValidRequest,
1772 ")]}"); // Invalid JSON. Should be ignored. 1445 ")]}"); // Invalid JSON. Should be ignored.
1773 } 1446 }
1774 1447
1775 TEST_F(WalletClientTest, HasRequestInProgress) { 1448 TEST_F(WalletClientTest, HasRequestInProgress) {
1776 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1449 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1777 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1450 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1778 1); 1451 1);
1779 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1452 delegate_.ExpectBaselineMetrics();
1780 1453
1781 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1454 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1782 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); 1455 EXPECT_TRUE(wallet_client_->HasRequestInProgress());
1783 1456
1784 VerifyAndFinishRequest(net::HTTP_OK, 1457 VerifyAndFinishRequest(net::HTTP_OK,
1785 kGetWalletItemsValidRequest, 1458 kGetWalletItemsValidRequest,
1786 kGetWalletItemsValidResponse); 1459 kGetWalletItemsValidResponse);
1787 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1460 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1788 } 1461 }
1789 1462
1790 TEST_F(WalletClientTest, PendingRequest) { 1463 TEST_F(WalletClientTest, PendingRequest) {
1791 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1464 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1792 1465
1793 // Shouldn't queue the first request. 1466 // Shouldn't queue the first request.
1794 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1467 delegate_.ExpectBaselineMetrics();
1795 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1468 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1796 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1469 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1797 testing::Mock::VerifyAndClear(delegate_.metric_logger()); 1470 testing::Mock::VerifyAndClear(delegate_.metric_logger());
1798 1471
1799 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1472 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1800 EXPECT_EQ(1U, wallet_client_->pending_requests_.size()); 1473 EXPECT_EQ(1U, wallet_client_->pending_requests_.size());
1801 1474
1802 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1475 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1803 1); 1476 1);
1804 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1477 delegate_.ExpectBaselineMetrics();
1805 VerifyAndFinishRequest(net::HTTP_OK, 1478 VerifyAndFinishRequest(net::HTTP_OK,
1806 kGetWalletItemsValidRequest, 1479 kGetWalletItemsValidRequest,
1807 kGetWalletItemsValidResponse); 1480 kGetWalletItemsValidResponse);
1808 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1481 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1809 testing::Mock::VerifyAndClear(delegate_.metric_logger()); 1482 testing::Mock::VerifyAndClear(delegate_.metric_logger());
1810 1483
1811 EXPECT_CALL(delegate_, OnWalletError( 1484 EXPECT_CALL(delegate_, OnWalletError(
1812 WalletClient::SERVICE_UNAVAILABLE)).Times(1); 1485 WalletClient::SERVICE_UNAVAILABLE)).Times(1);
1813 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1486 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1814 1); 1487 1);
1815 delegate_.ExpectWalletErrorMetric( 1488 delegate_.ExpectWalletErrorMetric(
1816 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); 1489 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE);
1817 1490
1818 // Finish the second request. 1491 // Finish the second request.
1819 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, 1492 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR,
1820 kGetWalletItemsValidRequest, 1493 kGetWalletItemsValidRequest,
1821 kErrorResponse); 1494 kErrorResponse);
1822 } 1495 }
1823 1496
1824 TEST_F(WalletClientTest, CancelRequests) { 1497 TEST_F(WalletClientTest, CancelRequests) {
1825 ASSERT_EQ(0U, wallet_client_->pending_requests_.size()); 1498 ASSERT_EQ(0U, wallet_client_->pending_requests_.size());
1826 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, 1499 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
1827 0); 1500 0);
1828 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); 1501 delegate_.ExpectBaselineMetrics();
1829 1502
1830 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1503 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1831 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1504 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1832 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); 1505 wallet_client_->GetWalletItems(GURL(kMerchantUrl));
1833 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); 1506 EXPECT_EQ(2U, wallet_client_->pending_requests_.size());
1834 1507
1835 wallet_client_->CancelRequests(); 1508 wallet_client_->CancelRequests();
1836 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); 1509 EXPECT_EQ(0U, wallet_client_->pending_requests_.size());
1837 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); 1510 EXPECT_FALSE(wallet_client_->HasRequestInProgress());
1838 } 1511 }
1839 1512
1840 } // namespace wallet 1513 } // namespace wallet
1841 } // namespace autofill 1514 } // namespace autofill
Dan Beam 2013/07/02 01:25:52 my eyes hurt, i'll come back to this later
ahutter 2013/07/02 15:44:23 :(
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698