| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "google_apis/gcm/engine/checkin_request.h" | 8 #include "google_apis/gcm/engine/checkin_request.h" |
| 9 #include "google_apis/gcm/protocol/checkin.pb.h" | 9 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 10 #include "net/base/backoff_entry.h" | 10 #include "net/base/backoff_entry.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 VALID_RESPONSE, // Both android_id and security_token set in response. | 58 VALID_RESPONSE, // Both android_id and security_token set in response. |
| 59 MISSING_ANDROID_ID, // android_id is missing. | 59 MISSING_ANDROID_ID, // android_id is missing. |
| 60 MISSING_SECURITY_TOKEN, // security_token is missing. | 60 MISSING_SECURITY_TOKEN, // security_token is missing. |
| 61 ANDROID_ID_IS_ZER0, // android_id is 0. | 61 ANDROID_ID_IS_ZER0, // android_id is 0. |
| 62 SECURITY_TOKEN_IS_ZERO // security_token is 0. | 62 SECURITY_TOKEN_IS_ZERO // security_token is 0. |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 CheckinRequestTest(); | 65 CheckinRequestTest(); |
| 66 virtual ~CheckinRequestTest(); | 66 virtual ~CheckinRequestTest(); |
| 67 | 67 |
| 68 void FetcherCallback(uint64 android_id, uint64 security_token); | 68 void FetcherCallback( |
| 69 const checkin_proto::AndroidCheckinResponse& response); |
| 69 | 70 |
| 70 void CreateRequest(uint64 android_id, uint64 security_token); | 71 void CreateRequest(uint64 android_id, uint64 security_token); |
| 71 | 72 |
| 72 void SetResponseStatusAndString( | 73 void SetResponseStatusAndString( |
| 73 net::HttpStatusCode status_code, | 74 net::HttpStatusCode status_code, |
| 74 const std::string& response_data); | 75 const std::string& response_data); |
| 75 | 76 |
| 76 void CompleteFetch(); | 77 void CompleteFetch(); |
| 77 | 78 |
| 78 void SetResponse(ResponseScenario response_scenario); | 79 void SetResponse(ResponseScenario response_scenario); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 android_id_(kBlankAndroidId), | 96 android_id_(kBlankAndroidId), |
| 96 security_token_(kBlankSecurityToken), | 97 security_token_(kBlankSecurityToken), |
| 97 checkin_device_type_(0), | 98 checkin_device_type_(0), |
| 98 url_request_context_getter_(new net::TestURLRequestContextGetter( | 99 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 99 message_loop_.message_loop_proxy())) { | 100 message_loop_.message_loop_proxy())) { |
| 100 account_ids_.push_back("account_id"); | 101 account_ids_.push_back("account_id"); |
| 101 } | 102 } |
| 102 | 103 |
| 103 CheckinRequestTest::~CheckinRequestTest() {} | 104 CheckinRequestTest::~CheckinRequestTest() {} |
| 104 | 105 |
| 105 void CheckinRequestTest::FetcherCallback(uint64 android_id, | 106 void CheckinRequestTest::FetcherCallback( |
| 106 uint64 security_token) { | 107 const checkin_proto::AndroidCheckinResponse& checkin_response) { |
| 107 callback_called_ = true; | 108 callback_called_ = true; |
| 108 android_id_ = android_id; | 109 if (checkin_response.has_android_id()) |
| 109 security_token_ = security_token; | 110 android_id_ = checkin_response.android_id(); |
| 111 if (checkin_response.has_security_token()) |
| 112 security_token_ = checkin_response.security_token(); |
| 110 } | 113 } |
| 111 | 114 |
| 112 void CheckinRequestTest::CreateRequest(uint64 android_id, | 115 void CheckinRequestTest::CreateRequest(uint64 android_id, |
| 113 uint64 security_token) { | 116 uint64 security_token) { |
| 114 // First setup a chrome_build protobuf. | 117 // First setup a chrome_build protobuf. |
| 115 chrome_build_proto_.set_platform( | 118 chrome_build_proto_.set_platform( |
| 116 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); | 119 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); |
| 117 chrome_build_proto_.set_channel( | 120 chrome_build_proto_.set_channel( |
| 118 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); | 121 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); |
| 119 chrome_build_proto_.set_chrome_version(kChromeVersion); | 122 chrome_build_proto_.set_chrome_version(kChromeVersion); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 uint64 android_id = response_scenario == ANDROID_ID_IS_ZER0 ? 0 : kAndroidId; | 162 uint64 android_id = response_scenario == ANDROID_ID_IS_ZER0 ? 0 : kAndroidId; |
| 160 uint64 security_token = | 163 uint64 security_token = |
| 161 response_scenario == SECURITY_TOKEN_IS_ZERO ? 0 : kSecurityToken; | 164 response_scenario == SECURITY_TOKEN_IS_ZERO ? 0 : kSecurityToken; |
| 162 | 165 |
| 163 if (response_scenario != MISSING_ANDROID_ID) | 166 if (response_scenario != MISSING_ANDROID_ID) |
| 164 response.set_android_id(android_id); | 167 response.set_android_id(android_id); |
| 165 | 168 |
| 166 if (response_scenario != MISSING_SECURITY_TOKEN) | 169 if (response_scenario != MISSING_SECURITY_TOKEN) |
| 167 response.set_security_token(security_token); | 170 response.set_security_token(security_token); |
| 168 | 171 |
| 172 checkin_proto::GservicesSetting* g_services_setting = response.add_setting(); |
| 173 g_services_setting->set_name("checkin_interval"); |
| 174 g_services_setting->set_value("3600"); |
| 175 |
| 169 std::string response_string; | 176 std::string response_string; |
| 170 response.SerializeToString(&response_string); | 177 response.SerializeToString(&response_string); |
| 171 SetResponseStatusAndString(net::HTTP_OK, response_string); | 178 SetResponseStatusAndString(net::HTTP_OK, response_string); |
| 172 } | 179 } |
| 173 | 180 |
| 174 TEST_F(CheckinRequestTest, FetcherData) { | 181 TEST_F(CheckinRequestTest, FetcherData) { |
| 175 CreateRequest(kAndroidId, kSecurityToken); | 182 CreateRequest(kAndroidId, kSecurityToken); |
| 176 request_->Start(); | 183 request_->Start(); |
| 177 | 184 |
| 178 // Get data sent by request. | 185 // Get data sent by request. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 244 } |
| 238 | 245 |
| 239 TEST_F(CheckinRequestTest, ResponseHttpStatusUnauthorized) { | 246 TEST_F(CheckinRequestTest, ResponseHttpStatusUnauthorized) { |
| 240 CreateRequest(0u, 0u); | 247 CreateRequest(0u, 0u); |
| 241 request_->Start(); | 248 request_->Start(); |
| 242 | 249 |
| 243 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, std::string()); | 250 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, std::string()); |
| 244 CompleteFetch(); | 251 CompleteFetch(); |
| 245 | 252 |
| 246 EXPECT_TRUE(callback_called_); | 253 EXPECT_TRUE(callback_called_); |
| 247 EXPECT_EQ(0u, android_id_); | 254 EXPECT_EQ(kBlankAndroidId, android_id_); |
| 248 EXPECT_EQ(0u, security_token_); | 255 EXPECT_EQ(kBlankSecurityToken, security_token_); |
| 249 } | 256 } |
| 250 | 257 |
| 251 TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { | 258 TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { |
| 252 CreateRequest(0u, 0u); | 259 CreateRequest(0u, 0u); |
| 253 request_->Start(); | 260 request_->Start(); |
| 254 | 261 |
| 255 SetResponseStatusAndString(net::HTTP_BAD_REQUEST, std::string()); | 262 SetResponseStatusAndString(net::HTTP_BAD_REQUEST, std::string()); |
| 256 CompleteFetch(); | 263 CompleteFetch(); |
| 257 | 264 |
| 258 EXPECT_TRUE(callback_called_); | 265 EXPECT_TRUE(callback_called_); |
| 259 EXPECT_EQ(0u, android_id_); | 266 EXPECT_EQ(kBlankAndroidId, android_id_); |
| 260 EXPECT_EQ(0u, security_token_); | 267 EXPECT_EQ(kBlankSecurityToken, security_token_); |
| 261 } | 268 } |
| 262 | 269 |
| 263 TEST_F(CheckinRequestTest, ResponseHttpStatusNotOK) { | 270 TEST_F(CheckinRequestTest, ResponseHttpStatusNotOK) { |
| 264 CreateRequest(0u, 0u); | 271 CreateRequest(0u, 0u); |
| 265 request_->Start(); | 272 request_->Start(); |
| 266 | 273 |
| 267 SetResponseStatusAndString(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); | 274 SetResponseStatusAndString(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); |
| 268 CompleteFetch(); | 275 CompleteFetch(); |
| 269 | 276 |
| 270 EXPECT_FALSE(callback_called_); | 277 EXPECT_FALSE(callback_called_); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 370 |
| 364 SetResponse(VALID_RESPONSE); | 371 SetResponse(VALID_RESPONSE); |
| 365 CompleteFetch(); | 372 CompleteFetch(); |
| 366 | 373 |
| 367 EXPECT_TRUE(callback_called_); | 374 EXPECT_TRUE(callback_called_); |
| 368 EXPECT_EQ(kAndroidId, android_id_); | 375 EXPECT_EQ(kAndroidId, android_id_); |
| 369 EXPECT_EQ(kSecurityToken, security_token_); | 376 EXPECT_EQ(kSecurityToken, security_token_); |
| 370 } | 377 } |
| 371 | 378 |
| 372 } // namespace gcm | 379 } // namespace gcm |
| OLD | NEW |