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

Unified Diff: components/autofill/content/browser/wallet/wallet_client_unittest.cc

Issue 522023003: handle more http error codes in wallet response (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/content/browser/wallet/wallet_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/content/browser/wallet/wallet_client_unittest.cc
diff --git a/components/autofill/content/browser/wallet/wallet_client_unittest.cc b/components/autofill/content/browser/wallet/wallet_client_unittest.cc
index 042c695e7ed4e2cefe3ee54a89bc8ad12e041af8..98b3971d63f01a5fd4704b12087dd174e404f700 100644
--- a/components/autofill/content/browser/wallet/wallet_client_unittest.cc
+++ b/components/autofill/content/browser/wallet/wallet_client_unittest.cc
@@ -281,6 +281,30 @@ const char kErrorResponse[] =
" }"
"}";
+const char kErrorResponseSpendingLimitExceeded[] =
+ "{"
+ " \"error_type\":\"APPLICATION_ERROR\","
+ " \"error_detail\":\"error_detail\","
+ " \"application_error\":\"application_error\","
+ " \"debug_data\":"
+ " {"
+ " \"debug_message\":\"debug_message\","
+ " \"stack_trace\":\"stack_trace\""
+ " },"
+ " \"application_error_data\":\"application_error_data\","
+ " \"wallet_error\":"
+ " {"
+ " \"error_type\":\"SPENDING_LIMIT_EXCEEDED\","
+ " \"error_detail\":\"error_detail\","
+ " \"message_for_user\":"
+ " {"
+ " \"text\":\"text\","
+ " \"subtext\":\"subtext\","
+ " \"details\":\"details\""
+ " }"
+ " }"
+ "}";
+
const char kErrorTypeMissingInResponse[] =
"{"
" \"error_type\":\"Not APPLICATION_ERROR\","
@@ -1755,7 +1779,8 @@ TEST_F(WalletClientTest, HasRequestInProgress) {
EXPECT_FALSE(wallet_client_->HasRequestInProgress());
}
-TEST_F(WalletClientTest, ErrorResponse) {
+// 500 (INTERNAL_SERVER_ERROR) - response json is parsed.
+TEST_F(WalletClientTest, ErrorResponse500) {
EXPECT_FALSE(wallet_client_->HasRequestInProgress());
delegate_.ExpectBaselineMetrics();
wallet_client_->GetWalletItems(base::string16(), base::string16());
@@ -1774,6 +1799,60 @@ TEST_F(WalletClientTest, ErrorResponse) {
kErrorResponse);
}
+// 403 (FORBIDDEN) - response json is parsed.
+TEST_F(WalletClientTest, ErrorResponse403) {
+ EXPECT_FALSE(wallet_client_->HasRequestInProgress());
+ delegate_.ExpectBaselineMetrics();
+ wallet_client_->GetWalletItems(base::string16(), base::string16());
+ EXPECT_TRUE(wallet_client_->HasRequestInProgress());
+ testing::Mock::VerifyAndClear(delegate_.metric_logger());
+
+ EXPECT_CALL(delegate_, OnWalletError(WalletClient::SPENDING_LIMIT_EXCEEDED))
+ .Times(1);
+ delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
+ 1);
+ delegate_.ExpectWalletErrorMetric(
+ AutofillMetrics::WALLET_SPENDING_LIMIT_EXCEEDED);
+
+ VerifyAndFinishRequest(net::HTTP_FORBIDDEN,
+ kGetWalletItemsValidRequest,
+ kErrorResponseSpendingLimitExceeded);
+}
+
+// 400 (BAD_REQUEST) - response json is ignored.
+TEST_F(WalletClientTest, ErrorResponse400) {
+ EXPECT_FALSE(wallet_client_->HasRequestInProgress());
+ delegate_.ExpectBaselineMetrics();
+ wallet_client_->GetWalletItems(base::string16(), base::string16());
+ EXPECT_TRUE(wallet_client_->HasRequestInProgress());
+ testing::Mock::VerifyAndClear(delegate_.metric_logger());
+
+ EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1);
+ delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
+ 1);
+ delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST);
+
+ VerifyAndFinishRequest(
+ net::HTTP_BAD_REQUEST, kGetWalletItemsValidRequest, kErrorResponse);
+}
+
+// Anything else - response json is ignored.
+TEST_F(WalletClientTest, ErrorResponseOther) {
+ EXPECT_FALSE(wallet_client_->HasRequestInProgress());
+ delegate_.ExpectBaselineMetrics();
+ wallet_client_->GetWalletItems(base::string16(), base::string16());
+ EXPECT_TRUE(wallet_client_->HasRequestInProgress());
+ testing::Mock::VerifyAndClear(delegate_.metric_logger());
+
+ EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1);
+ delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
+ 1);
+ delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR);
+
+ VerifyAndFinishRequest(
+ net::HTTP_NOT_FOUND, kGetWalletItemsValidRequest, kErrorResponse);
+}
+
TEST_F(WalletClientTest, CancelRequest) {
EXPECT_FALSE(wallet_client_->HasRequestInProgress());
delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS,
« no previous file with comments | « components/autofill/content/browser/wallet/wallet_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698