OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
13 #include "components/autofill/browser/autofill_metrics.h" | 13 #include "components/autofill/browser/autofill_metrics.h" |
14 #include "components/autofill/browser/wallet/cart.h" | |
15 #include "components/autofill/browser/wallet/full_wallet.h" | 14 #include "components/autofill/browser/wallet/full_wallet.h" |
16 #include "components/autofill/browser/wallet/instrument.h" | 15 #include "components/autofill/browser/wallet/instrument.h" |
17 #include "components/autofill/browser/wallet/wallet_client.h" | 16 #include "components/autofill/browser/wallet/wallet_client.h" |
18 #include "components/autofill/browser/wallet/wallet_client_delegate.h" | 17 #include "components/autofill/browser/wallet/wallet_client_delegate.h" |
19 #include "components/autofill/browser/wallet/wallet_items.h" | 18 #include "components/autofill/browser/wallet/wallet_items.h" |
20 #include "components/autofill/browser/wallet/wallet_test_util.h" | 19 #include "components/autofill/browser/wallet/wallet_test_util.h" |
21 #include "components/autofill/common/autocheckout_status.h" | 20 #include "components/autofill/common/autocheckout_status.h" |
22 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
23 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 286 |
288 const char kAuthenticateInstrumentValidRequest[] = | 287 const char kAuthenticateInstrumentValidRequest[] = |
289 "{" | 288 "{" |
290 "\"instrument_escrow_handle\":\"escrow_handle\"," | 289 "\"instrument_escrow_handle\":\"escrow_handle\"," |
291 "\"instrument_id\":\"instrument_id\"," | 290 "\"instrument_id\":\"instrument_id\"," |
292 "\"risk_params\":\"risky business\"" | 291 "\"risk_params\":\"risky business\"" |
293 "}"; | 292 "}"; |
294 | 293 |
295 const char kGetFullWalletValidRequest[] = | 294 const char kGetFullWalletValidRequest[] = |
296 "{" | 295 "{" |
297 "\"cart\":" | |
298 "{" | |
299 "\"currency_code\":\"currency_code\"," | |
300 "\"total_price\":\"total_price\"" | |
301 "}," | |
302 "\"encrypted_otp\":\"encrypted_one_time_pad\"," | 296 "\"encrypted_otp\":\"encrypted_one_time_pad\"," |
303 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | 297 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," |
304 "\"google_transaction_id\":\"google_transaction_id\"," | 298 "\"google_transaction_id\":\"google_transaction_id\"," |
305 "\"merchant_domain\":\"https://example.com/\"," | 299 "\"merchant_domain\":\"https://example.com/\"," |
306 "\"risk_params\":\"risky business\"," | 300 "\"risk_params\":\"risky business\"," |
307 "\"selected_address_id\":\"shipping_address_id\"," | 301 "\"selected_address_id\":\"shipping_address_id\"," |
308 "\"selected_instrument_id\":\"instrument_id\"," | 302 "\"selected_instrument_id\":\"instrument_id\"," |
309 "\"session_material\":\"session_material\"," | 303 "\"session_material\":\"session_material\"," |
310 "\"supported_risk_challenge\":" | 304 "\"supported_risk_challenge\":" |
311 "[" | 305 "[" |
312 "]" | 306 "]" |
313 "}"; | 307 "}"; |
314 | 308 |
315 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = | 309 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = |
316 "{" | 310 "{" |
317 "\"cart\":" | |
318 "{" | |
319 "\"currency_code\":\"currency_code\"," | |
320 "\"total_price\":\"total_price\"" | |
321 "}," | |
322 "\"encrypted_otp\":\"encrypted_one_time_pad\"," | 311 "\"encrypted_otp\":\"encrypted_one_time_pad\"," |
323 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | 312 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," |
324 "\"google_transaction_id\":\"google_transaction_id\"," | 313 "\"google_transaction_id\":\"google_transaction_id\"," |
325 "\"merchant_domain\":\"https://example.com/\"," | 314 "\"merchant_domain\":\"https://example.com/\"," |
326 "\"risk_params\":\"risky business\"," | 315 "\"risk_params\":\"risky business\"," |
327 "\"selected_address_id\":\"shipping_address_id\"," | 316 "\"selected_address_id\":\"shipping_address_id\"," |
328 "\"selected_instrument_id\":\"instrument_id\"," | 317 "\"selected_instrument_id\":\"instrument_id\"," |
329 "\"session_material\":\"session_material\"," | 318 "\"session_material\":\"session_material\"," |
330 "\"supported_risk_challenge\":" | 319 "\"supported_risk_challenge\":" |
331 "[" | 320 "[" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 "google_transaction_id"); | 826 "google_transaction_id"); |
838 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, | 827 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, |
839 kSendAutocheckoutStatusOfSuccessValidRequest, | 828 kSendAutocheckoutStatusOfSuccessValidRequest, |
840 std::string()); | 829 std::string()); |
841 } | 830 } |
842 | 831 |
843 TEST_F(WalletClientTest, GetFullWalletSuccess) { | 832 TEST_F(WalletClientTest, GetFullWalletSuccess) { |
844 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); | 833 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); |
845 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); | 834 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); |
846 | 835 |
847 Cart cart("total_price", "currency_code"); | |
848 WalletClient::FullWalletRequest full_wallet_request( | 836 WalletClient::FullWalletRequest full_wallet_request( |
849 "instrument_id", | 837 "instrument_id", |
850 "shipping_address_id", | 838 "shipping_address_id", |
851 GURL(kMerchantUrl), | 839 GURL(kMerchantUrl), |
852 cart, | |
853 "google_transaction_id", | 840 "google_transaction_id", |
854 std::vector<WalletClient::RiskCapability>()); | 841 std::vector<WalletClient::RiskCapability>()); |
855 wallet_client_->GetFullWallet(full_wallet_request); | 842 wallet_client_->GetFullWallet(full_wallet_request); |
856 | 843 |
857 DoEncryptionOrEscrowRequest(net::HTTP_OK, | 844 DoEncryptionOrEscrowRequest(net::HTTP_OK, |
858 "session_material|encrypted_one_time_pad"); | 845 "session_material|encrypted_one_time_pad"); |
859 | 846 |
860 VerifyAndFinishRequest(net::HTTP_OK, | 847 VerifyAndFinishRequest(net::HTTP_OK, |
861 kGetFullWalletValidRequest, | 848 kGetFullWalletValidRequest, |
862 kGetFullWalletValidResponse); | 849 kGetFullWalletValidResponse); |
863 EXPECT_EQ(1U, delegate_.full_wallets_received()); | 850 EXPECT_EQ(1U, delegate_.full_wallets_received()); |
864 } | 851 } |
865 | 852 |
866 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) { | 853 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) { |
867 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); | 854 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); |
868 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); | 855 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); |
869 | 856 |
870 std::vector<WalletClient::RiskCapability> risk_capabilities; | 857 std::vector<WalletClient::RiskCapability> risk_capabilities; |
871 risk_capabilities.push_back(WalletClient::VERIFY_CVC); | 858 risk_capabilities.push_back(WalletClient::VERIFY_CVC); |
872 Cart cart("total_price", "currency_code"); | |
873 WalletClient::FullWalletRequest full_wallet_request( | 859 WalletClient::FullWalletRequest full_wallet_request( |
874 "instrument_id", | 860 "instrument_id", |
875 "shipping_address_id", | 861 "shipping_address_id", |
876 GURL(kMerchantUrl), | 862 GURL(kMerchantUrl), |
877 cart, | |
878 "google_transaction_id", | 863 "google_transaction_id", |
879 risk_capabilities); | 864 risk_capabilities); |
880 wallet_client_->GetFullWallet(full_wallet_request); | 865 wallet_client_->GetFullWallet(full_wallet_request); |
881 | 866 |
882 DoEncryptionOrEscrowRequest(net::HTTP_OK, | 867 DoEncryptionOrEscrowRequest(net::HTTP_OK, |
883 "session_material|encrypted_one_time_pad"); | 868 "session_material|encrypted_one_time_pad"); |
884 | 869 |
885 VerifyAndFinishRequest(net::HTTP_OK, | 870 VerifyAndFinishRequest(net::HTTP_OK, |
886 kGetFullWalletWithRiskCapabilitesValidRequest, | 871 kGetFullWalletWithRiskCapabilitesValidRequest, |
887 kGetFullWalletValidResponse); | 872 kGetFullWalletValidResponse); |
888 EXPECT_EQ(1U, delegate_.full_wallets_received()); | 873 EXPECT_EQ(1U, delegate_.full_wallets_received()); |
889 } | 874 } |
890 | 875 |
891 TEST_F(WalletClientTest, GetFullWalletEncryptionDown) { | 876 TEST_F(WalletClientTest, GetFullWalletEncryptionDown) { |
892 EXPECT_CALL(delegate_, | 877 EXPECT_CALL(delegate_, |
893 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); | 878 OnNetworkError(net::HTTP_INTERNAL_SERVER_ERROR)).Times(1); |
894 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0); | 879 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0); |
895 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST); | 880 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST); |
896 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); | 881 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); |
897 | 882 |
898 Cart cart("total_price", "currency_code"); | |
899 WalletClient::FullWalletRequest full_wallet_request( | 883 WalletClient::FullWalletRequest full_wallet_request( |
900 "instrument_id", | 884 "instrument_id", |
901 "shipping_address_id", | 885 "shipping_address_id", |
902 GURL(kMerchantUrl), | 886 GURL(kMerchantUrl), |
903 cart, | |
904 "google_transaction_id", | 887 "google_transaction_id", |
905 std::vector<WalletClient::RiskCapability>()); | 888 std::vector<WalletClient::RiskCapability>()); |
906 wallet_client_->GetFullWallet(full_wallet_request); | 889 wallet_client_->GetFullWallet(full_wallet_request); |
907 | 890 |
908 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); | 891 DoEncryptionOrEscrowRequest(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); |
909 | 892 |
910 EXPECT_EQ(0U, delegate_.full_wallets_received()); | 893 EXPECT_EQ(0U, delegate_.full_wallets_received()); |
911 } | 894 } |
912 | 895 |
913 TEST_F(WalletClientTest, GetFullWalletEncryptionMalformed) { | 896 TEST_F(WalletClientTest, GetFullWalletEncryptionMalformed) { |
914 EXPECT_CALL(delegate_, OnMalformedResponse()).Times(1); | 897 EXPECT_CALL(delegate_, OnMalformedResponse()).Times(1); |
915 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0); | 898 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 0); |
916 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST); | 899 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, NO_WALLET_REQUEST); |
917 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); | 900 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); |
918 | 901 |
919 Cart cart("total_price", "currency_code"); | |
920 WalletClient::FullWalletRequest full_wallet_request( | 902 WalletClient::FullWalletRequest full_wallet_request( |
921 "instrument_id", | 903 "instrument_id", |
922 "shipping_address_id", | 904 "shipping_address_id", |
923 GURL(kMerchantUrl), | 905 GURL(kMerchantUrl), |
924 cart, | |
925 "google_transaction_id", | 906 "google_transaction_id", |
926 std::vector<WalletClient::RiskCapability>()); | 907 std::vector<WalletClient::RiskCapability>()); |
927 wallet_client_->GetFullWallet(full_wallet_request); | 908 wallet_client_->GetFullWallet(full_wallet_request); |
928 | 909 |
929 DoEncryptionOrEscrowRequest(net::HTTP_OK, | 910 DoEncryptionOrEscrowRequest(net::HTTP_OK, |
930 "session_material:encrypted_one_time_pad"); | 911 "session_material:encrypted_one_time_pad"); |
931 | 912 |
932 EXPECT_EQ(0U, delegate_.full_wallets_received()); | 913 EXPECT_EQ(0U, delegate_.full_wallets_received()); |
933 } | 914 } |
934 | 915 |
935 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { | 916 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { |
936 EXPECT_CALL(delegate_, OnMalformedResponse()).Times(1); | 917 EXPECT_CALL(delegate_, OnMalformedResponse()).Times(1); |
937 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); | 918 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_FULL_WALLET, 1); |
938 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); | 919 delegate_.ExpectBaselineMetrics(HAS_ESCROW_REQUEST, HAS_WALLET_REQUEST); |
939 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); | 920 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_MALFORMED_RESPONSE); |
940 | 921 |
941 Cart cart("total_price", "currency_code"); | |
942 WalletClient::FullWalletRequest full_wallet_request( | 922 WalletClient::FullWalletRequest full_wallet_request( |
943 "instrument_id", | 923 "instrument_id", |
944 "shipping_address_id", | 924 "shipping_address_id", |
945 GURL(kMerchantUrl), | 925 GURL(kMerchantUrl), |
946 cart, | |
947 "google_transaction_id", | 926 "google_transaction_id", |
948 std::vector<WalletClient::RiskCapability>()); | 927 std::vector<WalletClient::RiskCapability>()); |
949 wallet_client_->GetFullWallet(full_wallet_request); | 928 wallet_client_->GetFullWallet(full_wallet_request); |
950 | 929 |
951 DoEncryptionOrEscrowRequest(net::HTTP_OK, | 930 DoEncryptionOrEscrowRequest(net::HTTP_OK, |
952 "session_material|encrypted_one_time_pad"); | 931 "session_material|encrypted_one_time_pad"); |
953 | 932 |
954 VerifyAndFinishRequest(net::HTTP_OK, | 933 VerifyAndFinishRequest(net::HTTP_OK, |
955 kGetFullWalletValidRequest, | 934 kGetFullWalletValidRequest, |
956 kGetFullWalletInvalidResponse); | 935 kGetFullWalletInvalidResponse); |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1733 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
1755 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1734 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
1756 | 1735 |
1757 wallet_client_->CancelRequests(); | 1736 wallet_client_->CancelRequests(); |
1758 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1737 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
1759 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1738 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1760 } | 1739 } |
1761 | 1740 |
1762 } // namespace wallet | 1741 } // namespace wallet |
1763 } // namespace autofill | 1742 } // namespace autofill |
OLD | NEW |