summaryrefslogtreecommitdiffstats
path: root/google_apis/gcm/engine
diff options
context:
space:
mode:
authorjianli <jianli@chromium.org>2015-06-23 14:46:48 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-23 21:47:18 +0000
commit70715cc36015379ea9da83c19076bba5476a02d5 (patch)
tree97ed488e2fda0084161fc1f699779cb8287edd82 /google_apis/gcm/engine
parentd908bf574d0dc0417c2fe32b4300319c6d531f6f (diff)
downloadchromium_src-70715cc36015379ea9da83c19076bba5476a02d5.zip
chromium_src-70715cc36015379ea9da83c19076bba5476a02d5.tar.gz
chromium_src-70715cc36015379ea9da83c19076bba5476a02d5.tar.bz2
Some error handling for instanceID.deleteToken
Support the following error checks: 1) Check if the token to be deleted exist in the cache first. 2) Check error in DeleteToken response. BUG=501627 TEST=new tests Review URL: https://codereview.chromium.org/1191653012 Cr-Commit-Position: refs/heads/master@{#335762}
Diffstat (limited to 'google_apis/gcm/engine')
-rw-r--r--google_apis/gcm/engine/instance_id_delete_token_request_handler.cc10
-rw-r--r--google_apis/gcm/engine/unregistration_request_unittest.cc22
2 files changed, 32 insertions, 0 deletions
diff --git a/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc b/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc
index 82de88a..530d785 100644
--- a/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc
+++ b/google_apis/gcm/engine/instance_id_delete_token_request_handler.cc
@@ -23,6 +23,8 @@ const char kScopeKey[] = "scope";
// Response constants.
const char kTokenPrefix[] = "token=";
+const char kErrorPrefix[] = "Error=";
+const char kInvalidParameters[] = "INVALID_PARAMETERS";
} // namespace
@@ -61,6 +63,14 @@ InstanceIDDeleteTokenRequestHandler::ParseResponse(
return UnregistrationRequest::NO_RESPONSE_BODY;
}
+ if (response.find(kErrorPrefix) != std::string::npos) {
+ std::string error = response.substr(
+ response.find(kErrorPrefix) + arraysize(kErrorPrefix) - 1);
+ return error == kInvalidParameters ?
+ UnregistrationRequest::INVALID_PARAMETERS :
+ UnregistrationRequest::UNKNOWN_ERROR;
+ }
+
if (response.find(kTokenPrefix) == std::string::npos)
return UnregistrationRequest::RESPONSE_PARSING_FAILED;
diff --git a/google_apis/gcm/engine/unregistration_request_unittest.cc b/google_apis/gcm/engine/unregistration_request_unittest.cc
index 3f58788..757f46d 100644
--- a/google_apis/gcm/engine/unregistration_request_unittest.cc
+++ b/google_apis/gcm/engine/unregistration_request_unittest.cc
@@ -478,4 +478,26 @@ TEST_F(InstaceIDDeleteTokenRequestTest, ResponseHttpStatusNotOK) {
EXPECT_EQ(UnregistrationRequest::SUCCESS, status_);
}
+TEST_F(InstaceIDDeleteTokenRequestTest, InvalidParametersError) {
+ CreateRequest(kInstanceId, kDeveloperId, kScope);
+ request_->Start();
+
+ SetResponseStatusAndString(net::HTTP_OK, "Error=INVALID_PARAMETERS");
+ CompleteFetch();
+
+ EXPECT_TRUE(callback_called_);
+ EXPECT_EQ(UnregistrationRequest::INVALID_PARAMETERS, status_);
+}
+
+TEST_F(InstaceIDDeleteTokenRequestTest, UnkwnownError) {
+ CreateRequest(kInstanceId, kDeveloperId, kScope);
+ request_->Start();
+
+ SetResponseStatusAndString(net::HTTP_OK, "Error=XXX");
+ CompleteFetch();
+
+ EXPECT_TRUE(callback_called_);
+ EXPECT_EQ(UnregistrationRequest::UNKNOWN_ERROR, status_);
+}
+
} // namespace gcm