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 <stdint.h> | 5 #include <stdint.h> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 request_->Start(); | 186 request_->Start(); |
187 | 187 |
188 SetResponse(net::HTTP_OK, "token=2501"); | 188 SetResponse(net::HTTP_OK, "token=2501"); |
189 CompleteFetch(); | 189 CompleteFetch(); |
190 | 190 |
191 EXPECT_TRUE(callback_called_); | 191 EXPECT_TRUE(callback_called_); |
192 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); | 192 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); |
193 EXPECT_EQ("2501", registration_id_); | 193 EXPECT_EQ("2501", registration_id_); |
194 } | 194 } |
195 | 195 |
| 196 TEST_F(GCMRegistrationRequestTest, ResponseParsingFailed) { |
| 197 CreateRequest("sender1,sender2"); |
| 198 request_->Start(); |
| 199 |
| 200 SetResponse(net::HTTP_OK, "tok"); // Simulate truncated message. |
| 201 CompleteFetch(); |
| 202 |
| 203 EXPECT_FALSE(callback_called_); |
| 204 |
| 205 // Ensuring a retry happened and succeeds. |
| 206 SetResponse(net::HTTP_OK, "token=2501"); |
| 207 CompleteFetch(); |
| 208 |
| 209 EXPECT_TRUE(callback_called_); |
| 210 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); |
| 211 EXPECT_EQ("2501", registration_id_); |
| 212 } |
| 213 |
196 TEST_F(GCMRegistrationRequestTest, ResponseHttpStatusNotOK) { | 214 TEST_F(GCMRegistrationRequestTest, ResponseHttpStatusNotOK) { |
197 CreateRequest("sender1,sender2"); | 215 CreateRequest("sender1,sender2"); |
198 request_->Start(); | 216 request_->Start(); |
199 | 217 |
200 SetResponse(net::HTTP_UNAUTHORIZED, "token=2501"); | 218 SetResponse(net::HTTP_UNAUTHORIZED, "token=2501"); |
201 CompleteFetch(); | 219 CompleteFetch(); |
202 | 220 |
203 EXPECT_FALSE(callback_called_); | 221 EXPECT_FALSE(callback_called_); |
204 | 222 |
205 SetResponse(net::HTTP_OK, "token=2501"); | 223 SetResponse(net::HTTP_OK, "token=2501"); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 281 |
264 // Ensuring a retry happened and succeeds. | 282 // Ensuring a retry happened and succeeds. |
265 SetResponse(net::HTTP_OK, "token=2501"); | 283 SetResponse(net::HTTP_OK, "token=2501"); |
266 CompleteFetch(); | 284 CompleteFetch(); |
267 | 285 |
268 EXPECT_TRUE(callback_called_); | 286 EXPECT_TRUE(callback_called_); |
269 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); | 287 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); |
270 EXPECT_EQ("2501", registration_id_); | 288 EXPECT_EQ("2501", registration_id_); |
271 } | 289 } |
272 | 290 |
| 291 TEST_F(GCMRegistrationRequestTest, ResponseInternalServerError) { |
| 292 CreateRequest("sender1,sender2"); |
| 293 request_->Start(); |
| 294 |
| 295 SetResponse(net::HTTP_INTERNAL_SERVER_ERROR, "Error=InternalServerError"); |
| 296 CompleteFetch(); |
| 297 |
| 298 EXPECT_FALSE(callback_called_); |
| 299 |
| 300 // Ensuring a retry happened and succeeds. |
| 301 SetResponse(net::HTTP_OK, "token=2501"); |
| 302 CompleteFetch(); |
| 303 |
| 304 EXPECT_TRUE(callback_called_); |
| 305 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); |
| 306 EXPECT_EQ("2501", registration_id_); |
| 307 } |
| 308 |
273 TEST_F(GCMRegistrationRequestTest, ResponseInvalidParameters) { | 309 TEST_F(GCMRegistrationRequestTest, ResponseInvalidParameters) { |
274 CreateRequest("sender1,sender2"); | 310 CreateRequest("sender1,sender2"); |
275 request_->Start(); | 311 request_->Start(); |
276 | 312 |
277 SetResponse(net::HTTP_OK, "Error=INVALID_PARAMETERS"); | 313 SetResponse(net::HTTP_OK, "Error=INVALID_PARAMETERS"); |
278 CompleteFetch(); | 314 CompleteFetch(); |
279 | 315 |
280 EXPECT_TRUE(callback_called_); | 316 EXPECT_TRUE(callback_called_); |
281 EXPECT_EQ(RegistrationRequest::INVALID_PARAMETERS, status_); | 317 EXPECT_EQ(RegistrationRequest::INVALID_PARAMETERS, status_); |
282 EXPECT_EQ(std::string(), registration_id_); | 318 EXPECT_EQ(std::string(), registration_id_); |
(...skipping 16 matching lines...) Expand all Loading... |
299 request_->Start(); | 335 request_->Start(); |
300 | 336 |
301 SetResponse(net::HTTP_BAD_REQUEST, "Error=INVALID_SENDER"); | 337 SetResponse(net::HTTP_BAD_REQUEST, "Error=INVALID_SENDER"); |
302 CompleteFetch(); | 338 CompleteFetch(); |
303 | 339 |
304 EXPECT_TRUE(callback_called_); | 340 EXPECT_TRUE(callback_called_); |
305 EXPECT_EQ(RegistrationRequest::INVALID_SENDER, status_); | 341 EXPECT_EQ(RegistrationRequest::INVALID_SENDER, status_); |
306 EXPECT_EQ(std::string(), registration_id_); | 342 EXPECT_EQ(std::string(), registration_id_); |
307 } | 343 } |
308 | 344 |
| 345 TEST_F(GCMRegistrationRequestTest, ResponseQuotaExceeded) { |
| 346 CreateRequest("sender1"); |
| 347 request_->Start(); |
| 348 |
| 349 SetResponse(net::HTTP_SERVICE_UNAVAILABLE, "Error=QUOTA_EXCEEDED"); |
| 350 CompleteFetch(); |
| 351 |
| 352 EXPECT_TRUE(callback_called_); |
| 353 EXPECT_EQ(RegistrationRequest::QUOTA_EXCEEDED, status_); |
| 354 EXPECT_EQ(std::string(), registration_id_); |
| 355 } |
| 356 |
| 357 TEST_F(GCMRegistrationRequestTest, ResponseTooManyRegistrations) { |
| 358 CreateRequest("sender1"); |
| 359 request_->Start(); |
| 360 |
| 361 SetResponse(net::HTTP_OK, "Error=TOO_MANY_REGISTRATIONS"); |
| 362 CompleteFetch(); |
| 363 |
| 364 EXPECT_TRUE(callback_called_); |
| 365 EXPECT_EQ(RegistrationRequest::TOO_MANY_REGISTRATIONS, status_); |
| 366 EXPECT_EQ(std::string(), registration_id_); |
| 367 } |
| 368 |
309 TEST_F(GCMRegistrationRequestTest, RequestNotSuccessful) { | 369 TEST_F(GCMRegistrationRequestTest, RequestNotSuccessful) { |
310 CreateRequest("sender1,sender2"); | 370 CreateRequest("sender1,sender2"); |
311 request_->Start(); | 371 request_->Start(); |
312 | 372 |
313 SetResponse(net::HTTP_OK, "token=2501"); | 373 SetResponse(net::HTTP_OK, "token=2501"); |
314 | 374 |
315 net::TestURLFetcher* fetcher = GetFetcher(); | 375 net::TestURLFetcher* fetcher = GetFetcher(); |
316 ASSERT_TRUE(fetcher); | 376 ASSERT_TRUE(fetcher); |
317 GetFetcher()->set_status(net::URLRequestStatus::FromError(net::ERR_FAILED)); | 377 GetFetcher()->set_status(net::URLRequestStatus::FromError(net::ERR_FAILED)); |
318 | 378 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 594 |
535 SetResponse(net::HTTP_OK, "token=2501"); | 595 SetResponse(net::HTTP_OK, "token=2501"); |
536 CompleteFetch(); | 596 CompleteFetch(); |
537 | 597 |
538 EXPECT_TRUE(callback_called_); | 598 EXPECT_TRUE(callback_called_); |
539 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); | 599 EXPECT_EQ(RegistrationRequest::SUCCESS, status_); |
540 EXPECT_EQ("2501", registration_id_); | 600 EXPECT_EQ("2501", registration_id_); |
541 } | 601 } |
542 | 602 |
543 } // namespace gcm | 603 } // namespace gcm |
OLD | NEW |