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/unregistration_request.h" | 11 #include "google_apis/gcm/engine/unregistration_request.h" |
| 12 #include "google_apis/gcm/monitoring/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_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace gcm { | 17 namespace gcm { |
17 | 18 |
18 namespace { | 19 namespace { |
19 const uint64 kAndroidId = 42UL; | 20 const uint64 kAndroidId = 42UL; |
20 const char kLoginHeader[] = "AidLogin"; | 21 const char kLoginHeader[] = "AidLogin"; |
21 const char kAppId[] = "TestAppId"; | 22 const char kAppId[] = "TestAppId"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const std::string& response_body); | 65 const std::string& response_body); |
65 void CompleteFetch(); | 66 void CompleteFetch(); |
66 | 67 |
67 protected: | 68 protected: |
68 bool callback_called_; | 69 bool callback_called_; |
69 UnregistrationRequest::Status status_; | 70 UnregistrationRequest::Status status_; |
70 scoped_ptr<UnregistrationRequest> request_; | 71 scoped_ptr<UnregistrationRequest> request_; |
71 base::MessageLoop message_loop_; | 72 base::MessageLoop message_loop_; |
72 net::TestURLFetcherFactory url_fetcher_factory_; | 73 net::TestURLFetcherFactory url_fetcher_factory_; |
73 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 74 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
| 75 GCMStatsRecorder recorder_; |
74 }; | 76 }; |
75 | 77 |
76 UnregistrationRequestTest::UnregistrationRequestTest() | 78 UnregistrationRequestTest::UnregistrationRequestTest() |
77 : callback_called_(false), | 79 : callback_called_(false), |
78 status_(UnregistrationRequest::UNREGISTRATION_STATUS_COUNT), | 80 status_(UnregistrationRequest::UNREGISTRATION_STATUS_COUNT), |
79 url_request_context_getter_(new net::TestURLRequestContextGetter( | 81 url_request_context_getter_(new net::TestURLRequestContextGetter( |
80 message_loop_.message_loop_proxy())) {} | 82 message_loop_.message_loop_proxy())) {} |
81 | 83 |
82 UnregistrationRequestTest::~UnregistrationRequestTest() {} | 84 UnregistrationRequestTest::~UnregistrationRequestTest() {} |
83 | 85 |
84 void UnregistrationRequestTest::UnregistrationCallback( | 86 void UnregistrationRequestTest::UnregistrationCallback( |
85 UnregistrationRequest::Status status) { | 87 UnregistrationRequest::Status status) { |
86 callback_called_ = true; | 88 callback_called_ = true; |
87 status_ = status; | 89 status_ = status; |
88 } | 90 } |
89 | 91 |
90 void UnregistrationRequestTest::CreateRequest() { | 92 void UnregistrationRequestTest::CreateRequest() { |
91 request_.reset(new UnregistrationRequest( | 93 request_.reset(new UnregistrationRequest( |
92 UnregistrationRequest::RequestInfo(kAndroidId, | 94 UnregistrationRequest::RequestInfo(kAndroidId, |
93 kSecurityToken, | 95 kSecurityToken, |
94 kAppId), | 96 kAppId), |
95 kDefaultBackoffPolicy, | 97 kDefaultBackoffPolicy, |
96 base::Bind(&UnregistrationRequestTest::UnregistrationCallback, | 98 base::Bind(&UnregistrationRequestTest::UnregistrationCallback, |
97 base::Unretained(this)), | 99 base::Unretained(this)), |
98 url_request_context_getter_.get())); | 100 url_request_context_getter_.get(), |
| 101 &recorder_)); |
99 } | 102 } |
100 | 103 |
101 void UnregistrationRequestTest::SetResponseStatusAndString( | 104 void UnregistrationRequestTest::SetResponseStatusAndString( |
102 net::HttpStatusCode status_code, | 105 net::HttpStatusCode status_code, |
103 const std::string& response_body) { | 106 const std::string& response_body) { |
104 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 107 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
105 ASSERT_TRUE(fetcher); | 108 ASSERT_TRUE(fetcher); |
106 fetcher->set_response_code(status_code); | 109 fetcher->set_response_code(status_code); |
107 fetcher->SetResponseString(response_body); | 110 fetcher->SetResponseString(response_body); |
108 } | 111 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 EXPECT_FALSE(callback_called_); | 282 EXPECT_FALSE(callback_called_); |
280 | 283 |
281 SetResponseStatusAndString(net::HTTP_OK, kDeletedAppId); | 284 SetResponseStatusAndString(net::HTTP_OK, kDeletedAppId); |
282 CompleteFetch(); | 285 CompleteFetch(); |
283 | 286 |
284 EXPECT_TRUE(callback_called_); | 287 EXPECT_TRUE(callback_called_); |
285 EXPECT_EQ(UnregistrationRequest::SUCCESS, status_); | 288 EXPECT_EQ(UnregistrationRequest::SUCCESS, status_); |
286 } | 289 } |
287 | 290 |
288 } // namespace gcm | 291 } // namespace gcm |
OLD | NEW |