| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| 11 #include "google_apis/gcm/engine/registration_request.h" | 11 #include "google_apis/gcm/engine/registration_request.h" |
| 12 #include "google_apis/gcm/gcm_stats_recorder.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" | 13 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
| 14 #include "net/url_request/url_request_test_util.h" | 15 #include "net/url_request/url_request_test_util.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace gcm { | 18 namespace gcm { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const uint64 kAndroidId = 42UL; | 21 const uint64 kAndroidId = 42UL; |
| 21 const char kAppId[] = "TestAppId"; | 22 const char kAppId[] = "TestAppId"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 protected: | 74 protected: |
| 74 int max_retry_count_; | 75 int max_retry_count_; |
| 75 RegistrationRequest::Status status_; | 76 RegistrationRequest::Status status_; |
| 76 std::string registration_id_; | 77 std::string registration_id_; |
| 77 bool callback_called_; | 78 bool callback_called_; |
| 78 std::map<std::string, std::string> extras_; | 79 std::map<std::string, std::string> extras_; |
| 79 scoped_ptr<RegistrationRequest> request_; | 80 scoped_ptr<RegistrationRequest> request_; |
| 80 base::MessageLoop message_loop_; | 81 base::MessageLoop message_loop_; |
| 81 net::TestURLFetcherFactory url_fetcher_factory_; | 82 net::TestURLFetcherFactory url_fetcher_factory_; |
| 82 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 83 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
| 84 gcm::GCMStatsRecorder recorder_; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 RegistrationRequestTest::RegistrationRequestTest() | 87 RegistrationRequestTest::RegistrationRequestTest() |
| 86 : max_retry_count_(2), | 88 : max_retry_count_(2), |
| 87 status_(RegistrationRequest::SUCCESS), | 89 status_(RegistrationRequest::SUCCESS), |
| 88 callback_called_(false), | 90 callback_called_(false), |
| 89 url_request_context_getter_(new net::TestURLRequestContextGetter( | 91 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 90 message_loop_.message_loop_proxy())) {} | 92 message_loop_.message_loop_proxy())) {} |
| 91 | 93 |
| 92 RegistrationRequestTest::~RegistrationRequestTest() {} | 94 RegistrationRequestTest::~RegistrationRequestTest() {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 109 |
| 108 request_.reset(new RegistrationRequest( | 110 request_.reset(new RegistrationRequest( |
| 109 RegistrationRequest::RequestInfo(kAndroidId, | 111 RegistrationRequest::RequestInfo(kAndroidId, |
| 110 kSecurityToken, | 112 kSecurityToken, |
| 111 kAppId, | 113 kAppId, |
| 112 senders), | 114 senders), |
| 113 kDefaultBackoffPolicy, | 115 kDefaultBackoffPolicy, |
| 114 base::Bind(&RegistrationRequestTest::RegistrationCallback, | 116 base::Bind(&RegistrationRequestTest::RegistrationCallback, |
| 115 base::Unretained(this)), | 117 base::Unretained(this)), |
| 116 max_retry_count_, | 118 max_retry_count_, |
| 117 url_request_context_getter_.get())); | 119 url_request_context_getter_.get(), |
| 120 &recorder_)); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void RegistrationRequestTest::SetResponseStatusAndString( | 123 void RegistrationRequestTest::SetResponseStatusAndString( |
| 121 net::HttpStatusCode status_code, | 124 net::HttpStatusCode status_code, |
| 122 const std::string& response_body) { | 125 const std::string& response_body) { |
| 123 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 126 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 124 ASSERT_TRUE(fetcher); | 127 ASSERT_TRUE(fetcher); |
| 125 fetcher->set_response_code(status_code); | 128 fetcher->set_response_code(status_code); |
| 126 fetcher->SetResponseString(response_body); | 129 fetcher->SetResponseString(response_body); |
| 127 } | 130 } |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 414 |
| 412 SetResponseStatusAndString(net::HTTP_GATEWAY_TIMEOUT, "token=2501"); | 415 SetResponseStatusAndString(net::HTTP_GATEWAY_TIMEOUT, "token=2501"); |
| 413 CompleteFetch(); | 416 CompleteFetch(); |
| 414 | 417 |
| 415 EXPECT_TRUE(callback_called_); | 418 EXPECT_TRUE(callback_called_); |
| 416 EXPECT_EQ(RegistrationRequest::REACHED_MAX_RETRIES, status_); | 419 EXPECT_EQ(RegistrationRequest::REACHED_MAX_RETRIES, status_); |
| 417 EXPECT_EQ(std::string(), registration_id_); | 420 EXPECT_EQ(std::string(), registration_id_); |
| 418 } | 421 } |
| 419 | 422 |
| 420 } // namespace gcm | 423 } // namespace gcm |
| OLD | NEW |