OLD | NEW |
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_split.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 "}" | 446 "}" |
447 "}"; | 447 "}"; |
448 | 448 |
449 const char kSendAutocheckoutStatusOfSuccessValidRequest[] = | 449 const char kSendAutocheckoutStatusOfSuccessValidRequest[] = |
450 "{" | 450 "{" |
451 "\"google_transaction_id\":\"google_transaction_id\"," | 451 "\"google_transaction_id\":\"google_transaction_id\"," |
452 "\"merchant_domain\":\"https://example.com/\"," | 452 "\"merchant_domain\":\"https://example.com/\"," |
453 "\"success\":true" | 453 "\"success\":true" |
454 "}"; | 454 "}"; |
455 | 455 |
456 const char kSendAutocheckoutStatusWithStatisticsValidRequest[] = | |
457 "{" | |
458 "\"google_transaction_id\":\"google_transaction_id\"," | |
459 "\"merchant_domain\":\"https://example.com/\"," | |
460 "\"steps\":[{\"step_description\":\"1_AUTOCHECKOUT_STEP_SHIPPING\"" | |
461 ",\"time_taken\":100}]," | |
462 "\"success\":true" | |
463 "}"; | |
464 | |
465 const char kSendAutocheckoutStatusOfFailureValidRequest[] = | 456 const char kSendAutocheckoutStatusOfFailureValidRequest[] = |
466 "{" | 457 "{" |
467 "\"google_transaction_id\":\"google_transaction_id\"," | 458 "\"google_transaction_id\":\"google_transaction_id\"," |
468 "\"merchant_domain\":\"https://example.com/\"," | 459 "\"merchant_domain\":\"https://example.com/\"," |
469 "\"reason\":\"CANNOT_PROCEED\"," | 460 "\"reason\":\"CANNOT_PROCEED\"," |
470 "\"success\":false" | 461 "\"success\":false" |
471 "}"; | 462 "}"; |
472 | 463 |
473 const char kUpdateAddressValidRequest[] = | 464 const char kUpdateAddressValidRequest[] = |
474 "{" | 465 "{" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 }; | 768 }; |
778 | 769 |
779 TEST_F(WalletClientTest, WalletError) { | 770 TEST_F(WalletClientTest, WalletError) { |
780 EXPECT_CALL(delegate_, OnWalletError( | 771 EXPECT_CALL(delegate_, OnWalletError( |
781 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 772 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
782 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 773 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
783 delegate_.ExpectBaselineMetrics(); | 774 delegate_.ExpectBaselineMetrics(); |
784 delegate_.ExpectWalletErrorMetric( | 775 delegate_.ExpectWalletErrorMetric( |
785 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 776 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
786 | 777 |
787 std::vector<AutocheckoutStatistic> statistics; | |
788 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 778 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
789 GURL(kMerchantUrl), | 779 GURL(kMerchantUrl), |
790 statistics, | |
791 "google_transaction_id"); | 780 "google_transaction_id"); |
792 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | 781 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, |
793 kSendAutocheckoutStatusOfSuccessValidRequest, | 782 kSendAutocheckoutStatusOfSuccessValidRequest, |
794 kErrorResponse); | 783 kErrorResponse); |
795 } | 784 } |
796 | 785 |
797 TEST_F(WalletClientTest, WalletErrorResponseMissing) { | 786 TEST_F(WalletClientTest, WalletErrorResponseMissing) { |
798 EXPECT_CALL(delegate_, OnWalletError( | 787 EXPECT_CALL(delegate_, OnWalletError( |
799 WalletClient::UNKNOWN_ERROR)).Times(1); | 788 WalletClient::UNKNOWN_ERROR)).Times(1); |
800 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 789 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
801 delegate_.ExpectBaselineMetrics(); | 790 delegate_.ExpectBaselineMetrics(); |
802 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR); | 791 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_UNKNOWN_ERROR); |
803 | 792 |
804 std::vector<AutocheckoutStatistic> statistics; | |
805 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 793 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
806 GURL(kMerchantUrl), | 794 GURL(kMerchantUrl), |
807 statistics, | |
808 "google_transaction_id"); | 795 "google_transaction_id"); |
809 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | 796 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, |
810 kSendAutocheckoutStatusOfSuccessValidRequest, | 797 kSendAutocheckoutStatusOfSuccessValidRequest, |
811 kErrorTypeMissingInResponse); | 798 kErrorTypeMissingInResponse); |
812 } | 799 } |
813 | 800 |
814 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) { | 801 TEST_F(WalletClientTest, NetworkFailureOnExpectedVoidResponse) { |
815 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); | 802 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); |
816 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 803 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
817 delegate_.ExpectBaselineMetrics(); | 804 delegate_.ExpectBaselineMetrics(); |
818 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); | 805 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); |
819 | 806 |
820 std::vector<AutocheckoutStatistic> statistics; | |
821 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 807 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
822 GURL(kMerchantUrl), | 808 GURL(kMerchantUrl), |
823 statistics, | |
824 "google_transaction_id"); | 809 "google_transaction_id"); |
825 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, | 810 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, |
826 kSendAutocheckoutStatusOfSuccessValidRequest, | 811 kSendAutocheckoutStatusOfSuccessValidRequest, |
827 std::string()); | 812 std::string()); |
828 } | 813 } |
829 | 814 |
830 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { | 815 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { |
831 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); | 816 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); |
832 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 817 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
833 1); | 818 1); |
834 delegate_.ExpectBaselineMetrics(); | 819 delegate_.ExpectBaselineMetrics(); |
835 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); | 820 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); |
836 | 821 |
837 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 822 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
838 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, | 823 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, |
839 kGetWalletItemsValidRequest, | 824 kGetWalletItemsValidRequest, |
840 std::string()); | 825 std::string()); |
841 } | 826 } |
842 | 827 |
843 TEST_F(WalletClientTest, RequestError) { | 828 TEST_F(WalletClientTest, RequestError) { |
844 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); | 829 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); |
845 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 830 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
846 delegate_.ExpectBaselineMetrics(); | 831 delegate_.ExpectBaselineMetrics(); |
847 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST); | 832 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST); |
848 | 833 |
849 std::vector<AutocheckoutStatistic> statistics; | |
850 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 834 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
851 GURL(kMerchantUrl), | 835 GURL(kMerchantUrl), |
852 statistics, | |
853 "google_transaction_id"); | 836 "google_transaction_id"); |
854 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, | 837 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, |
855 kSendAutocheckoutStatusOfSuccessValidRequest, | 838 kSendAutocheckoutStatusOfSuccessValidRequest, |
856 std::string()); | 839 std::string()); |
857 } | 840 } |
858 | 841 |
859 TEST_F(WalletClientTest, GetFullWalletSuccess) { | 842 TEST_F(WalletClientTest, GetFullWalletSuccess) { |
860 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); | 843 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); |
861 delegate_.ExpectBaselineMetrics(); | 844 delegate_.ExpectBaselineMetrics(); |
862 | 845 |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 | 1456 |
1474 VerifyAndFinishRequest(net::HTTP_OK, | 1457 VerifyAndFinishRequest(net::HTTP_OK, |
1475 kUpdateInstrumentAddressValidRequest, | 1458 kUpdateInstrumentAddressValidRequest, |
1476 kUpdateMalformedResponse); | 1459 kUpdateMalformedResponse); |
1477 } | 1460 } |
1478 | 1461 |
1479 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { | 1462 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { |
1480 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 1463 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
1481 delegate_.ExpectBaselineMetrics(); | 1464 delegate_.ExpectBaselineMetrics(); |
1482 | 1465 |
1483 AutocheckoutStatistic statistic; | |
1484 statistic.page_number = 1; | |
1485 statistic.steps.push_back(AUTOCHECKOUT_STEP_SHIPPING); | |
1486 statistic.time_taken = base::TimeDelta::FromMilliseconds(100); | |
1487 std::vector<AutocheckoutStatistic> statistics; | |
1488 statistics.push_back(statistic); | |
1489 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 1466 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
1490 GURL(kMerchantUrl), | 1467 GURL(kMerchantUrl), |
1491 statistics, | |
1492 "google_transaction_id"); | 1468 "google_transaction_id"); |
1493 VerifyAndFinishRequest(net::HTTP_OK, | 1469 VerifyAndFinishRequest(net::HTTP_OK, |
1494 kSendAutocheckoutStatusWithStatisticsValidRequest, | 1470 kSendAutocheckoutStatusOfSuccessValidRequest, |
1495 ")]}"); // Invalid JSON. Should be ignored. | 1471 ")]}"); // Invalid JSON. Should be ignored. |
1496 } | 1472 } |
1497 | 1473 |
1498 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { | 1474 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { |
1499 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 1475 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
1500 delegate_.ExpectBaselineMetrics(); | 1476 delegate_.ExpectBaselineMetrics(); |
1501 | 1477 |
1502 std::vector<AutocheckoutStatistic> statistics; | |
1503 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, | 1478 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, |
1504 GURL(kMerchantUrl), | 1479 GURL(kMerchantUrl), |
1505 statistics, | |
1506 "google_transaction_id"); | 1480 "google_transaction_id"); |
1507 VerifyAndFinishRequest(net::HTTP_OK, | 1481 VerifyAndFinishRequest(net::HTTP_OK, |
1508 kSendAutocheckoutStatusOfFailureValidRequest, | 1482 kSendAutocheckoutStatusOfFailureValidRequest, |
1509 ")]}"); // Invalid JSON. Should be ignored. | 1483 ")]}"); // Invalid JSON. Should be ignored. |
1510 } | 1484 } |
1511 | 1485 |
1512 TEST_F(WalletClientTest, HasRequestInProgress) { | 1486 TEST_F(WalletClientTest, HasRequestInProgress) { |
1513 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1487 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1514 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1488 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1515 1); | 1489 1); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1543 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
1570 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1544 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
1571 | 1545 |
1572 wallet_client_->CancelRequests(); | 1546 wallet_client_->CancelRequests(); |
1573 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1547 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
1574 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1548 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1575 } | 1549 } |
1576 | 1550 |
1577 } // namespace wallet | 1551 } // namespace wallet |
1578 } // namespace autofill | 1552 } // namespace autofill |
OLD | NEW |