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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 240 } |
238 | 241 |
239 TEST_F(CheckinRequestTest, ResponseHttpStatusUnauthorized) { | 242 TEST_F(CheckinRequestTest, ResponseHttpStatusUnauthorized) { |
240 CreateRequest(0u, 0u); | 243 CreateRequest(0u, 0u); |
241 request_->Start(); | 244 request_->Start(); |
242 | 245 |
243 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, std::string()); | 246 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, std::string()); |
244 CompleteFetch(); | 247 CompleteFetch(); |
245 | 248 |
246 EXPECT_TRUE(callback_called_); | 249 EXPECT_TRUE(callback_called_); |
247 EXPECT_EQ(0u, android_id_); | 250 EXPECT_EQ(kBlankAndroidId, android_id_); |
248 EXPECT_EQ(0u, security_token_); | 251 EXPECT_EQ(kBlankSecurityToken, security_token_); |
249 } | 252 } |
250 | 253 |
251 TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { | 254 TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { |
252 CreateRequest(0u, 0u); | 255 CreateRequest(0u, 0u); |
253 request_->Start(); | 256 request_->Start(); |
254 | 257 |
255 SetResponseStatusAndString(net::HTTP_BAD_REQUEST, std::string()); | 258 SetResponseStatusAndString(net::HTTP_BAD_REQUEST, std::string()); |
256 CompleteFetch(); | 259 CompleteFetch(); |
257 | 260 |
258 EXPECT_TRUE(callback_called_); | 261 EXPECT_TRUE(callback_called_); |
259 EXPECT_EQ(0u, android_id_); | 262 EXPECT_EQ(kBlankAndroidId, android_id_); |
260 EXPECT_EQ(0u, security_token_); | 263 EXPECT_EQ(kBlankSecurityToken, security_token_); |
261 } | 264 } |
262 | 265 |
263 TEST_F(CheckinRequestTest, ResponseHttpStatusNotOK) { | 266 TEST_F(CheckinRequestTest, ResponseHttpStatusNotOK) { |
264 CreateRequest(0u, 0u); | 267 CreateRequest(0u, 0u); |
265 request_->Start(); | 268 request_->Start(); |
266 | 269 |
267 SetResponseStatusAndString(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); | 270 SetResponseStatusAndString(net::HTTP_INTERNAL_SERVER_ERROR, std::string()); |
268 CompleteFetch(); | 271 CompleteFetch(); |
269 | 272 |
270 EXPECT_FALSE(callback_called_); | 273 EXPECT_FALSE(callback_called_); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 366 |
364 SetResponse(VALID_RESPONSE); | 367 SetResponse(VALID_RESPONSE); |
365 CompleteFetch(); | 368 CompleteFetch(); |
366 | 369 |
367 EXPECT_TRUE(callback_called_); | 370 EXPECT_TRUE(callback_called_); |
368 EXPECT_EQ(kAndroidId, android_id_); | 371 EXPECT_EQ(kAndroidId, android_id_); |
369 EXPECT_EQ(kSecurityToken, security_token_); | 372 EXPECT_EQ(kSecurityToken, security_token_); |
370 } | 373 } |
371 | 374 |
372 } // namespace gcm | 375 } // namespace gcm |
OLD | NEW |